def equip(v): t = target(v, cls=entity.Weapon, inv=True) if t: pc.equip(t) event.log("player.action.equip") else: badcmd("Equip what?\n")
def attack(v): t = target(v, cls=entity.Character) if t: pc.attack(t) event.log("player.action.attack") else: badcmd("Who?\n")
def drop(v): if pc.weapon and pc.weapon.name.upper() == v: pc.unequip() t = target(v, inv=True) if t: pc.drop(t) event.log("player.action.drop") else: badcmd("Drop what?\n")
def get(v): t = target(v, cls=entity.Item) if t: pc.get(t) here.remove(t) pcprint("You pick up {}\n".format(t)) event.log("player.action.get") else: if v: badcmd("I don't see {} here\n".format(v)) else: badcmd("There's nothing to get\n")
def secure(): global unlocked global unlockTime if unlocked: now = time.time() # if time is up and door is closed re-lock if now - unlockTime > 5 and state.doorClosed: # add config for time lock.set_value(0) led.set_value(0) unlocked = False event.log('Access secured')
def parse(): evenParity = data >> 25 & 1 evenHalf = data >> 13 & 4095 oddHalf = data >> 1 & 4095 oddParity = data & 1 # if parity is valid, get the numbers if parity(evenHalf, 0) == evenParity and parity(oddHalf, 1) == oddParity: facility = data >> 17 & 255 number = data >> 1 & 65535 return Card(number, facility) else: event.log('Wiegand reading error')
def check(): # door check if door.get_value() == 0: doorTemp = True else: doorTemp = False if state.doorClosed != doorTemp: state.doorClosed = doorTemp event.log('Contact closed' if state.doorClosed else 'Contact opened', 'DOOR') # aux check if aux.get_value() == 0: auxTemp = True else: auxTemp = False if state.auxClosed != auxTemp: state.auxClosed = auxTemp event.log('Contact closed' if state.auxClosed else 'Contact opened', 'AUX')
def unequip(v): if pc.weapon: pc.unequip() event.log("player.action.unequip") else: badcmd("You're not holding a weapon\n")
def drop(self, item): for i,v in enumerate(self.inv): if item.uuid == v.uuid: del self.inv[i] event.log("character.inventory.drop", item=item, pos=self.pos) return
def drop_all(self): self.unequip() for i in self.inv: event.log("character.inventory.drop", item=i, pos=self.pos) self.inv = []
def die(self, kwargs): if not self.dead: self.drop_all() print("{} died!".format(self.name)) self.dead = True event.log("character.death", sub=self.uuid, last_hit=self.last_hit)
try: while True: # 3ms delay affects everything following response = wiegand.read() if isinstance(response, int): code = numpad.press(response) # button else: code = response # card (or None) # check the code if code != None: if auth.verify(code): # unlock entry.allow() event.log('Access granted', code) else: entry.deny() event.log('Access denied', code) code = None # check sensors sensors.check() # cleanup entry.secure() except KeyboardInterrupt: # Ctrl+Z breaks this config.chip.close()