Beispiel #1
0
 def mech(self):
     # TODO polish things here (find-lose system)
     if self.state == 'observe':
         found = self.find_player()
         if not found:
             self.awareness = 1
             self.do_random_move()
     elif self.state == 'attack' and not self.lose_player():
         self.call_for_help(self.player)
         direction_on_target = self.find_direction_on_player()
         if self.ap >= self.bow.cost and direction_on_target:
             self.last_happend = '\n' + self.show() + self.bow.use(
                 direction_on_target)
         elif direction_on_target:
             self.do_move_to(
                 [anti_dir(direction_on_target).go(self.position)])
             self.last_happend = '\n' + self.show(
             ) + " отходит от игрока для выстрела"
         else:
             possible_position = []
             for direction in DIRS.values():
                 p = self.player.position
                 for _ in self.bow.range:
                     p = direction.go(p)
                     if self.world.if_square_is(p, walkable_for_monsters):
                         possible_position.append(p)
                     else:
                         break
             if len(possible_position) > 0:
                 self.last_happend = ''
                 self.do_move_to(possible_position)
             else:
                 self.last_happend = ''
                 self.do_move_to([self.player.position])
     elif self.state == "observe":
         self.state = "observe"
         self.awareness = 2
         self.last_happend = "\n" + self.show() + " потерял игрока из виду"
     else:
         self.ap = 0
Beispiel #2
0
 def use(self, direction):
     self.user.ap -= self.cost
     p = direction.go(self.user.position)
     dirs = {d for d in DIRS.values() if d != anti_dir(direction)}
     queue = [p]
     visited = set()
     log_message = ""
     # FIXME Something still wrong, one mob hit twice
     while len(queue) > 0:
         a = queue.pop(0)
         if a in visited:
             continue
         visited.add(a)
         if self.user.world.if_mob_is(a, self.user.opponents):
             log_message += "\n" + self.user.hit(self.user.world.mobs[a],
                                                 self)
         queue.extend([
             d.go(a) for d in dirs
             if distance(d.go(a), self.user.position) <= self.range_
             and d.go(a) not in visited
         ])
     if len(log_message) == 0:
         return " никуда не попал хлыстом"
     return " своим хлыстом:" + log_message
Beispiel #3
0
 def find_direction_on_player(self):
     for direction in DIRS.values():
         if self.world.has_player_at(direction.go(self.position)):
             return direction
Beispiel #4
0
 def do_random_move(self):
     possibles = [d.go(self.position) for d in DIRS.values() if self.world.can_move(self, d.go(self.position))]
     if len(possibles) != 0:
         return self.do_move(random.choice(possibles))
     else:
         return " не может двигаться"