소스 검색

(250622) 修复寻路缓存bug; 微调CustomMoveToTarget

detopoi 1 년 전
부모
커밋
84657e6e07
4개의 변경된 파일과 9개의 추가작업 그리고 7개의 파일을 삭제
  1. 3 3
      client_local/algo/aStar.py
  2. 1 1
      client_local/skill/parametric2_skill.py
  3. 4 2
      client_local/sprite/npc.py
  4. 1 1
      client_local/ui/game/game_top.py

+ 3 - 3
client_local/algo/aStar.py

@@ -156,7 +156,7 @@ def cal_path_new(npc_grid, hero_grid, limit1, limit2, is_ghost=False):
 
 def cal_path(npc_grid, hero_grid, limit1, limit2, is_ghost=False, path_cache=None):
     if path_cache is None:
-        path_cache = {}  # 初始化缓存表,若未传入则创建一个新的缓存表
+        path_cache = dict()  # 初始化缓存表,若未传入则创建一个新的缓存表
     # limit1 区域左上角
     # limit2 区域右下角
     frontier = PriorityQueue()
@@ -186,9 +186,9 @@ def cal_path(npc_grid, hero_grid, limit1, limit2, is_ghost=False, path_cache=Non
                         combined_path = reverse(came_from, _next, npc_grid)
                         combined_path.update(cached_path)
                         if not combined_path:
-                            return {}
+                            return dict()
                         return combined_path
                     else:
-                        return {}
+                        return dict()
 
     return reverse(came_from, hero_grid, npc_grid)

+ 1 - 1
client_local/skill/parametric2_skill.py

@@ -1883,7 +1883,7 @@ class CustomMoveToTarget(Skill):
             for npc in self.to:
                 if npc.stats_name == self.target:
                     dist = abs(npc.x - level.current_level.me.x) + abs(npc.y - level.current_level.me.y)
-                    if dist <= self.final_dist:
+                    if dist < self.final_dist:
                         self.final_target = npc
                         self.final_dist = dist
             if self.final_target is not None:

+ 4 - 2
client_local/sprite/npc.py

@@ -287,7 +287,7 @@ class Npc(Player, Throwable):
                 level.current_level.recal_npc_paths = True
 
     def chase_hero(self):
-        if not self.resentful and not self.mocking or self.friendly or self.imitating or (self.speed == 0 and self.original_speed == 0):
+        if (not self.resentful and not self.mocking) or self.friendly or self.imitating or (self.speed == 0 and self.original_speed == 0):
             return
         me = (level.current_level.me.x, level.current_level.me.y)
         if self.free_chasing:
@@ -303,13 +303,15 @@ class Npc(Player, Throwable):
         # 如果重新计算路径标志为True则重新追踪玩家
         if level.current_level.recal_npc_paths:
             if now not in path_map.keys():
-                self.chase_path = path_map[now] = aStar.cal_path(
+                self.chase_path = aStar.cal_path(
                     now, me,
                     (level.current_level.district_square_grid["x1"], level.current_level.district_square_grid["y1"]),
                     (level.current_level.district_square_grid["x2"], level.current_level.district_square_grid["y2"]),
                     is_ghost=self.is_ghost,
                     path_cache=path_map
                 )
+                if self.chase_path != {}:
+                    path_map[now] = self.chase_path
             else:
                 self.chase_path = path_map[now]
         if now in self.chase_path.keys():

+ 1 - 1
client_local/ui/game/game_top.py

@@ -7,7 +7,7 @@ class GameTop(UIInstance):
     def __init__(self):
         super().__init__("game", "gameTop")
         self.font = pygame.font.Font("res/font/simsun.ttc", 16)
-        self.rend = self.font.render("v20250618", True, (0, 196, 255))
+        self.rend = self.font.render("v20250622", True, (0, 196, 255))
 
     def draw(self, screen: pygame.Surface):
         super().draw(screen)