def equip(self, wearer): old_equipment = wearer.get_equipped_in_slot(self.slot) if old_equipment is not None: old_equipment.equipment.dequip(wearer) self.is_equipped = True game.log(wearer.name, 'equipped a', self.owner.name) return True
def use(self, wearer, target): if wearer and wearer.container: wearer.container.inventory.remove(self.owner) a = target.destructible.heal(self.amount) if a > 0: game.log('the', self.owner.name, 'heals', target.name, 'by', a, 'hp') return True else: game.log('the', self.owner.name, 'has no visible effect!') return True
def __init__(self, x, y, power, wearer=None, name=None, self_remove=False): _at = hit.Attacker(power) nam = 'projectile' if name: nam = name Entity.__init__(self, x, y, name=nam, char='*', blocks=False, attacker=_at) t = self.attacker.attack_tile(x, y) if t: game.log('the', self.name, 'hits the',t.init_name+'!') if t.destructible.is_dead() and wearer: game.log(wearer.name, 'killed the', t.init_name+'!') self.attacker = None self.remove = self_remove
def drop(self, wearer): if not wearer.container: return False if self.owner.equipment and self.owner.equipment.is_equipped: game.log(wearer.name, "can't drop something equipped!") game.log_turn() return False game.log(wearer.name, 'dropped a', self.owner.name) wearer.container.inventory.remove(self.owner) game.actors.append(self.owner) self.owner.x = wearer.x self.owner.y = wearer.y return True
def use(self, wearer, target): d = game.player.ai.choose_direction() if d is None: return False target_x = wearer.x + (d[0] * self.throw) target_y = wearer.y + (d[1] * self.throw) for x in range(target_x-self.radius+1, target_x+self.radius): for y in range(target_y-self.radius+1, target_y+self.radius): if not map.is_wall(x, y) and map.get_distance_coord(target_x, target_y, x, y) < self.radius: s = ent.Smoke(x, y, tcod.random_get_int(0, 0, game.NORMAL_SPEED*5)) game.actors.append(s) map.fov_recompute(game.player.x, game.player.y) game.log(wearer.name,"threw the", self.owner.name) game.log("a really dense gas expands quickly! vision is difficult") if wearer and wearer.container: wearer.container.inventory.remove(self.owner) return True
def update(self): dx = 0 dy = 0 if game.key.vk == tcod.KEY_RIGHT: dx = +1 elif game.key.vk == tcod.KEY_LEFT: dx = -1 elif game.key.vk == tcod.KEY_UP: dy = -1 elif game.key.vk == tcod.KEY_DOWN: dy = +1 else: self.handle_action_key(game.key.c) #process attacks or movement if dx != 0 or dy != 0: e = map.get_actor_alive(self.owner.x+dx, self.owner.y+dy) if e and e.blocks and e.destructible: nam = e.name self.owner.attacker.attack(e) if tcod.random_get_int(0,0,10)<1 and e.body: game.log(self.owner.name, 'hit the', nam, 'in the', enum.rand_body_part(e)) else: game.log(self.owner.name, 'hit the', nam) if e.destructible.is_dead(): game.log(self.owner.name, 'killed the', nam+'!') game.game_state = enum.GameS.NEW_TURN # elif game.player.move(dx, dy): game.game_state = enum.GameS.NEW_TURN #
def seek_and_destroy(self, target): if target: dx = target.x - self.owner.x dy = target.y - self.owner.y distance = map.get_distance(self.owner, target) if distance > 0: dx = int(round(dx / distance)) dy = int(round(dy / distance)) d = tcod.random_get_int(0,0,1) #make them zombies move orthogonally f**k if d == 0: if dx != 0: dy = 0 else: dx = 0 self.owner.move(dx, dy) e = map.get_actor_alive(self.owner.x+dx, self.owner.y+dy) if e and map.is_fov(self.owner.x, self.owner.y): self.owner.attacker.attack(e) if e is game.player: game.log('the', self.owner.name, 'hits!') elif e.destructible: game.log('a', self.owner.name, 'hits the', e.name)
def use(self, wearer, target): d = game.player.ai.choose_direction() if d is None: return False dist = self.length + wearer.power / 3 tx = wearer.x# + d[0] ty = wearer.y# + d[1] while dist: dist -= 1 tx += d[0] ty += d[1] a = map.get_actor_alive(tx, ty) if (a and a is not wearer) or map.is_blocked(tx, ty): dist = 0 target_x = tx#wearer.x + (d[0] * self.throw) target_y = ty#wearer.y + (d[1] * self.throw) game.log(wearer.name,"threw the", self.owner.name+'!') game.log_turn() game.log('BOOOM!!') game.log_turn() did_hole = False for x in range(target_x-self.radius+1, target_x+self.radius): for y in range(target_y-self.radius+1, target_y+self.radius): if map.is_diggable(x, y): map.set_wall(x, y, False, False) did_hole = True if not map.is_wall(x, y): if map.get_distance_coord(target_x, target_y, x, y) < self.radius: s = ent.Smoke(x, y, tcod.random_get_int(0, 0, game.NORMAL_SPEED*5), was_visible=not map.is_wall(x,y)) game.actors.append(s) s = ent.Projectile(x, y, self.damage, wearer, name='explosion', self_remove=True) game.actors.append(s) if did_hole: game.log("the", self.owner.name, 'made a huge hole in the walls!') map.fov_recompute(game.player.x, game.player.y) if wearer and wearer.container: wearer.container.inventory.remove(self.owner) pass return True
def use(self, wearer, target): if not wearer.ai: return False d = wearer.ai.choose_direction() if d is None: return False dx = wearer.x + d[0] dy = wearer.y + d[1] if map.is_wall(dx, dy): if map.is_diggable(dx, dy): map.set_wall(dx, dy, False, False) game.log('with great effort,', wearer.name, 'dig into the solid rock') wearer.action_points -= game.NORMAL_SPEED*10 else: game.log('this rock is too hard for', wearer.name, 'to dig..') else: game.log(wearer.name, "can't dig here") return True
def handle_action_key(self, key): #debug ''' if key == ord(">"): game.game_state = enum.GameS.STAIRS_DOWN game.log("you descend into the darkness..") if key == ord("<"): game.game_state = enum.GameS.STAIRS_UP game.log("you climb up the stairs..") '''#stairs if key == ord(">"): if self.owner.x == game.stairs_down.x and self.owner.y == game.stairs_down.y: game.game_state = enum.GameS.STAIRS_DOWN game.log("you descend into the darkness..") else: game.log("you can't go down here") game.log_turn() if key == ord("<"): if self.owner.x == game.stairs_up.x and self.owner.y == game.stairs_up.y: game.game_state = enum.GameS.STAIRS_UP game.log("you climb up..") else: game.log("you can't go up here") game.log_turn() #repeat if key == ord("x") and self.last_command: found = False for item in self.owner.container.inventory: if item == self.last_command: found = True if found: self.last_command.pickable.use(self.owner, self.owner) game.game_state = enum.GameS.NEW_TURN else: self.last_command = None game.log("you don't have that object anymore..") game.log_turn() #inventory if key == ord("i"): gui.draw_inventory(0, self.owner.container.inventory, 'inventory') item = self.choose_from_inventory(self.owner.container.inventory) if item is not None: if item.pickable.use(self.owner, self.owner): game.game_state = enum.GameS.NEW_TURN self.last_command = item else: game.log("that's a silly thing to use") game.log_turn() #drop items if key == ord("d"): gui.draw_inventory(0, self.owner.container.inventory, 'drop an object') item = self.choose_from_inventory(self.owner.container.inventory) if item is not None: if item.pickable.drop(self.owner): game.game_state = enum.GameS.NEW_TURN #equip / dequip stuff if key == ord("e"): gui.draw_equipment(0, self.owner.container.inventory, 'equipment') item = self.choose_from_inventory(self.owner.container.inventory) if item is not None and item.equipment: item.equipment.toggle_equip(self.owner) #game.log('ai player - equip', item.name) game.game_state = enum.GameS.NEW_TURN #grab elif key == ord("g"): self.owner.send_front() e = map.get_actor_pickable(self.owner.x, self.owner.y) if e and e.pickable: if e.pickable.pick(self.owner): game.log('you pick a', e.name) game.game_state = enum.GameS.NEW_TURN # else: game.log("you can't carry more") game.log_turn() #look elif key == ord(";"): self.owner.send_front() #will be checked the last e = map.get_actor(self.owner.x, self.owner.y) if e and e is not self.owner: game.log('you see a', e.name, 'here') else: game.log("there's nothing of interest here") game.game_state = enum.GameS.NEW_TURN # self.owner.action_points -= 100
def dequip(self, wearer): if self.is_equipped: self.is_equipped = False game.log(wearer.name, 'took off a', self.owner.name) return True