소스 검색

feat: update offline gameplay for v261205

Add full-district water flow, undead nameplate markers, and NPC colour configuration. Fix the offline thunder district check and update the game version label.
detopoi 1 일 전
부모
커밋
b93885a123

+ 27 - 0
client_local/const/color.py

@@ -13,6 +13,33 @@ CHARACTER_PURPLE = (160, 32, 255)
 CHARACTER_BLACK = (96, 96, 96)
 CHARACTER_WHITE = (128, 128, 128)
 
+CHARACTER_COLORS = {
+    "Red": CHARACTER_RED,
+    "Blue": CHARACTER_BLUE,
+    "SkyBlue": CHARACTER_SKYBLUE,
+    "Yellow": CHARACTER_YELLOW,
+    "Green": CHARACTER_GREEN,
+    "ForestGreen": CHARACTER_FORESTGREEN,
+    "GrassGreen": CHARACTER_GRASSGREEN,
+    "Withered": CHARACTER_WITHERED,
+    "Orange": CHARACTER_ORANGE,
+    "Pink": CHARACTER_PINK,
+    "SakuraPink": CHARACTER_SAKURAPINK,
+    "Purple": CHARACTER_PURPLE,
+    "Black": CHARACTER_BLACK,
+    "White": CHARACTER_WHITE,
+}
+
+
+def resolve_character_colour(colour, default):
+    if isinstance(colour, str):
+        return CHARACTER_COLORS.get(colour, default)
+    if isinstance(colour, (list, tuple)) and len(colour) == 3:
+        if all(type(channel) is int and 0 <= channel <= 255 for channel in colour):
+            return tuple(colour)
+    return default
+
+
 COLOR_WHITE = (255, 255, 255)
 COLOR_RED = (255, 0, 0)
 COLOR_GREEN = (0, 255, 0)

+ 1 - 7
client_local/control.py

@@ -258,13 +258,7 @@ class Control:
 
     def set_level(self, your_name, map_name, hero_name, character_color, is_reset=False, transport_amount=0, transport_remain=0):
         # 改变当前关卡
-        character_colors = {
-            "Red": C.CHARACTER_RED, "Blue": C.CHARACTER_BLUE, "SkyBlue": C.CHARACTER_SKYBLUE, "Yellow": C.CHARACTER_YELLOW, "Green": C.CHARACTER_GREEN,
-            "Orange": C.CHARACTER_ORANGE, "Pink": C.CHARACTER_PINK, "SakuraPink": C.CHARACTER_SAKURAPINK, "Purple": C.CHARACTER_PURPLE,
-            "Black": C.CHARACTER_BLACK, "White": C.CHARACTER_WHITE, "ForestGreen": C.CHARACTER_FORESTGREEN, "GrassGreen": C.CHARACTER_GRASSGREEN,
-            "Withered": C.CHARACTER_WITHERED
-        }
-        character_color = character_colors[character_color]
+        character_color = C.CHARACTER_COLORS[character_color]
         # 保留我的技能剩余数
         me = Hero(hero_name, (0, 0), character_color)
         if self.me is not None and not is_reset:

+ 5 - 4
client_local/skill/level_skill.py

@@ -51,20 +51,21 @@ class Level3x3Thunder(Skill):
 
         if self.flag_thunder_explode and self.current_time - self.skill_time_init >= 1500:
             self.flag_thunder_explode = False
-            me = level.current_level.me
+            cl = level.current_level
+            me = cl.me
             for x in range(self.target[0] - 1, self.target[0] + 2):
                 for y in range(self.target[1] - 1, self.target[1] + 2):
                     an_effect = EffectInstance("thunder_explode", self.user, False, self.user.effects_front)
                     an_effect.x_pos = x * G.GAME_SQUARE + G.HALF_GAME_SQUARE
                     an_effect.y_pos = y * G.GAME_SQUARE + G.HALF_GAME_SQUARE
                     self.effect_instances.append(an_effect)
-                    if (x, y) in level.current_level.obstacle_instances.keys():  # 尝试摧毁障碍
-                        level.current_level.obstacle_instances[(x, y)].die()
+                    if (x, y) in cl.obstacle_instances:  # 尝试摧毁障碍
+                        cl.obstacle_instances[(x, y)].die()
                     if me.x == x and me.y == y:
                         me.try_damage(self.damage)
                         me.rooted_for(500)
                         sound_player.play("cry")
-            if level.current_level.in_district:
+            if cl.district_idx > 0 and not cl.district_all_finished and me.district_locked:
                 for npc in self.to:
                     if abs(npc.x-self.target[0]) <= 1 and abs(npc.y-self.target[1]) <= 1:
                         npc.try_damage(self.damage*10)

+ 107 - 21
client_local/skill/parametric2_skill.py

@@ -1,7 +1,7 @@
 import random
 import pygame.time
 from collections import deque, Counter
-from math import sqrt, pi, sin, cos, inf
+from math import sqrt, pi, sin, cos, inf, isfinite
 
 from client_local.const import color as C
 from client_local.const import game as G
@@ -626,6 +626,28 @@ class CustomSwallowAttack(Skill):
         super().kill()
 
 
+_WATER_FLOW_PUSH_DIRECTION = {"R": 1, "U": 2, "L": 3, "D": 4}
+
+
+def _apply_water_flow_hit(flow, x, y):
+    bombs = level.current_level.get_bomb_instance(x, y)
+    if bombs:
+        bomb_hit = bombs[0]
+        if flow.explode:
+            bomb_hit.explode()
+        if flow.push_bomb:
+            bomb_hit.floating_direction = flow.direction
+            bomb_hit.floating_speed = flow.speed
+            bomb_hit.floating = True
+        return True, False
+    if (flow.to.x, flow.to.y) == (x, y):
+        flow.to.try_damage(flow.damage)
+        if flow.push_player:
+            flow.to.water_push_for(_WATER_FLOW_PUSH_DIRECTION[flow.direction], flow.speed, 500)
+        return False, True
+    return False, False
+
+
 # 非直接使用的水拳([伤害, 时长ms, 速度, 中心(怪物1/玩家2), 相对初始坐标, 方向, 贴图("water"或"air"), 是否引爆糖泡, 是否推糖泡, 是否推玩家, 是否触碰就消失])
 class CustomSourceWaterFlowEffect(Skill):
 
@@ -644,7 +666,6 @@ class CustomSourceWaterFlowEffect(Skill):
             self.eff_names = {"R": "air_knife_r", "U": "air_knife_u", "L": "air_knife_l", "D": "air_knife_d"}
         self.old_time = pygame.time.get_ticks()
         self.counter = 0
-        self.bomb_direction = {"R": 1, "U": 2, "L": 3, "D": 4}
         self.to = level.current_level.me
 
     def load(self):
@@ -680,25 +701,10 @@ class CustomSourceWaterFlowEffect(Skill):
                 self.knife_effect.y_pos + delta_time * self.direction_to_adder[self.direction][1]
             )
             self.old_time = self.current_time
-            bombs = level.current_level.get_bomb_instance(self.knife_effect.x, self.knife_effect.y)
-            if len(bombs) > 0:
-                if self.explode:
-                    bombs[0].explode()
-                if self.push_bomb:
-                    bombs[0].floating_direction = self.direction
-                    bombs[0].floating_speed = self.speed
-                    bombs[0].floating = True
-                if self.early_stop:
-                    self.end = False
-            if len(bombs) == 0:
-                # print(self.to.x, self.to.y, self.knife_effect.x, self.knife_effect.y)
-                # print(self.to.x_pos, self.to.y_pos, self.knife_effect.x_pos, self.knife_effect.y_pos)
-                if self.to.x == self.knife_effect.x and self.to.y == self.knife_effect.y:
-                    self.to.try_damage(self.damage)
-                    if self.push_player:
-                        self.to.water_push_for(self.bomb_direction[self.direction], self.speed, 500)
-                    if self.early_stop:
-                        self.end = False
+            hit_bomb, hit_player = _apply_water_flow_hit(self, self.knife_effect.x, self.knife_effect.y)
+            if self.early_stop and (hit_bomb or hit_player):
+                self.end = False
+            if not hit_bomb:
                 self.counter += 1
             if self.counter > self.time:
                 self.end = False
@@ -753,6 +759,86 @@ class CustomGroupSourceWaterFlow(Skill):
                 CustomSourceWaterFlowEffect(self.user, [self.damage, self.time, self.speed, self.start_coords[i], self.dirct[i], self.effect_type, self.explode, self.push_bomb, self.push_player, self.early_stop], self.skill_instances)
 
 
+# {"damage": 400, "speed": 9, "direction": "U/D/L/R", "effect": "water", "explode_bomb": false, "push_bomb": true, "push_player": true, "early_stop": false}
+class CustomFullSourceWaterFlow(Skill):
+    """从当前区域的一条边发出水流,逐格扫到对边。"""
+
+    def __init__(self, user, to, params, skill_instances):
+        self.damage = int(params["damage"])
+        self.speed = float(params["speed"])
+        self.direction = params["direction"]
+        self.effect_type = params.get("effect", "water")
+        self.explode = params.get("explode_bomb", False)
+        self.push_bomb = params.get("push_bomb", True)
+        self.push_player = params.get("push_player", True)
+        self.early_stop = params.get("early_stop", False)
+        if self.direction not in _WATER_FLOW_PUSH_DIRECTION:
+            raise ValueError("direction 应为 U、D、L 或 R")
+        if self.effect_type not in ("water", "air"):
+            raise ValueError("effect 应为 water 或 air")
+        if not isfinite(self.speed) or self.speed <= 0:
+            raise ValueError("speed 应为正数")
+
+        cl = level.current_level
+        square = cl.district_square_grid
+        if cl.district_idx == 0 or cl.district_all_finished or not square:
+            return
+        x1, x2 = max(0, square["x1"]), min(cl.map_x - 1, square["x2"])
+        y1, y2 = max(0, square["y1"]), min(cl.map_y - 1, square["y2"])
+        if x1 > x2 or y1 > y2:
+            return
+
+        self.district_idx = cl.district_idx
+        self.horizontal = self.direction in ("L", "R")
+        first, last = (x1, x2) if self.horizontal else (y1, y2)
+        lane_first, lane_last = (y1, y2) if self.horizontal else (x1, x2)
+        self.step = 1 if self.direction in ("R", "D") else -1
+        self.start_tile = first if self.step == 1 else last
+        self.tile_count = last - first + 1
+        self.lanes = dict.fromkeys(range(lane_first, lane_last + 1))
+        self.started_at = None
+        self.last_offset = 0
+        super().__init__(user, to, skill_instances)
+
+    def update(self):
+        super().update()
+        cl = level.current_level
+        if cl.district_idx != self.district_idx or cl.district_all_finished:
+            self.kill()
+            return
+
+        tile_size = G.GAME_SQUARE
+        start_px = self.start_tile * tile_size + (tile_size - 1 if self.step == -1 else 0)
+        if self.started_at is None:
+            self.started_at = self.current_time
+            effect_name = f"{self.effect_type}_knife_{self.direction.lower()}"
+            for lane in self.lanes:
+                effect = EffectInstance(effect_name, self.user, False, cl.effects_front)
+                self.effect_instances.append(effect)
+                self.lanes[lane] = effect
+
+        distance = (self.current_time - self.started_at) * self.speed / 25
+        offset = min(int(distance // tile_size), self.tile_count - 1)
+        axis_px = start_px + self.step * min(distance, self.tile_count * tile_size - 1)
+        for lane, effect in list(self.lanes.items()):
+            # 帧间扫过的格子也要结算,避免高速水流跳过碰撞。
+            for tile_offset in range(self.last_offset, offset + 1):
+                axis_tile = self.start_tile + self.step * tile_offset
+                x, y = (axis_tile, lane) if self.horizontal else (lane, axis_tile)
+                hit_bomb, hit_player = _apply_water_flow_hit(self, x, y)
+                if self.early_stop and (hit_bomb or hit_player):
+                    effect.state = EffectState.DEAD
+                    del self.lanes[lane]
+                    break
+            else:
+                lane_px = lane * tile_size + G.HALF_GAME_SQUARE
+                x_pos, y_pos = (axis_px, lane_px) if self.horizontal else (lane_px, axis_px)
+                effect.set_xy_pos(x_pos, y_pos - 10)
+        self.last_offset = offset
+        if not self.lanes or distance >= self.tile_count * tile_size:
+            self.kill()
+
+
 
 
 

+ 1 - 0
client_local/skill/skill_map.py

@@ -303,6 +303,7 @@ skill_map = {
     "CustomWaterBubbleDistanceAttack": {"skill": CustomWaterBubbleDistanceAttack, "target": "me", "param": True, "effect": "self"},
     "CustomSwallowAttack": {"skill": CustomSwallowAttack, "target": "me", "param": True, "effect": "cl", "passive": True},
     "CustomGroupSourceWaterFlow": {"skill": CustomGroupSourceWaterFlow, "target": "me", "param": True, "effect": "cl"},
+    "CustomFullSourceWaterFlow": {"skill": CustomFullSourceWaterFlow, "target": "me", "param": True, "effect": "cl"},
     "CustomGroupDirectionLaserFireBall": {"skill": CustomGroupDirectionLaserFireBall, "target": "me", "param": True, "effect": "cl"},
     "CustomSelfDefenseEnhance": {"skill": CustomSelfDefenseEnhance, "target": None, "param": True, "effect": "self"},
     "CustomWaterDamageHeal": {"skill": CustomWaterDamageHeal, "target": None, "param": True, "effect": "self"},

+ 2 - 1
client_local/sprite/ghost.py

@@ -28,7 +28,8 @@ class Ghost(Player):
 
     def load_ghost(self, npc_name, color):
         self.npc_json = load_json("game/npc/" + npc_name + ".json")
-        self.character = self.load_character(self.npc_json["character"], color, dict(), True)
+        self.color = C.resolve_character_colour(self.npc_json.get("colour"), color)
+        self.character = self.load_character(self.npc_json["character"], self.color, dict(), True)
         self.ghost_time_init = pygame.time.get_ticks()
         self.remain_time = 1 if self.time <= 0 else self.time
 

+ 34 - 2
client_local/sprite/npc.py

@@ -28,6 +28,29 @@ monster_stats_file_path = os.path.join(qqtpve_folder, "monster_stats.json")  # 
 name_card_img_dict = dict()
 
 
+def _create_undead_icon():
+    icon = pygame.Surface((23, 25), pygame.SRCALPHA)
+    outline = (28, 14, 39)
+    edge = (148, 92, 181)
+    face = (90, 49, 116)
+    sockets = (23, 12, 34)
+    pygame.draw.polygon(icon, edge, ((7, 0), (15, 0), (20, 3), (22, 7), (22, 14),
+                                    (19, 17), (17, 18), (17, 22), (15, 24), (7, 24),
+                                    (5, 22), (5, 18), (3, 17), (0, 14), (0, 7), (2, 4)))
+    pygame.draw.polygon(icon, outline, ((7, 1), (15, 1), (19, 4), (21, 7), (21, 14),
+                                       (18, 16), (16, 17), (16, 22), (15, 23), (7, 23),
+                                       (6, 22), (6, 17), (4, 16), (1, 14), (1, 7), (3, 4)))
+    pygame.draw.polygon(icon, face, ((7, 3), (15, 3), (19, 7), (19, 13), (16, 15),
+                                    (14, 18), (14, 21), (8, 21), (8, 18), (6, 15), (3, 13), (3, 7)))
+    pygame.draw.lines(icon, (121, 72, 151), False, ((4, 7), (7, 4), (13, 4)))
+    pygame.draw.polygon(icon, sockets, ((4, 9), (9, 10), (9, 13), (7, 14), (4, 12)))
+    pygame.draw.polygon(icon, sockets, ((18, 9), (13, 10), (13, 13), (15, 14), (18, 12)))
+    pygame.draw.polygon(icon, sockets, ((11, 13), (9, 16), (13, 16)))
+    for x in (9, 12):
+        pygame.draw.line(icon, outline, (x, 19), (x, 22))
+    return pygame.transform.smoothscale(icon, (21, 23))
+
+
 def init_name_card_img_dict():
     global name_card_img_dict
     if name_card_img_dict != dict():
@@ -41,6 +64,7 @@ def init_name_card_img_dict():
         "red_long":    load_png("res/img/ui/game/misc169_long.png").convert_alpha(),
         "purple_long": load_png("res/img/ui/game/misc170_long.png").convert_alpha(),
         "green_long":  load_png("res/img/ui/game/misc172_long.png").convert_alpha(),
+        "undead": _create_undead_icon(),
     }
 
 
@@ -251,8 +275,9 @@ class Npc(Player, Throwable):
         self.chs_name_text_shadow = self.chs_name_font.render(self.chs_name, True, (0, 0, 0))
         self.chs_name_text_half_width = self.chs_name_text.get_width() // 2
         self._name_display_cache_key = (self.chs_name_font, self.chs_name)
+        self.color = C.resolve_character_colour(self.npc_json.get("colour"), color)
         self.character = self.load_character(
-            self.npc_json["character"], color, self.load_decorations()
+            self.npc_json["character"], self.color, self.load_decorations()
         )
         self.npc_time_init = pygame.time.get_ticks()
 
@@ -749,8 +774,15 @@ class Npc(Player, Throwable):
     def draw(self, screen: pygame.Surface):
         super().draw(screen)
         if G.DISPLAY_NPC_NAME_CARD and self.chs_name_show:
+            name_x, name_y = self.x_pos - self.name_bg_x_offset, self.y_pos - 100
             self.chs_name_bg.set_alpha(self.temporary_alpha)
-            screen.blit(self.chs_name_bg, (self.x_pos - self.name_bg_x_offset, self.y_pos - 100))
+            screen.blit(self.chs_name_bg, (name_x, name_y))
+            if (self.contact <= 0 and self.defense < 0
+                    and ("LandQuake" in self.skill_names or "SuperLandQuake" in self.skill_names)):
+                icon = name_card_img_dict["undead"]
+                icon.set_alpha(self.temporary_alpha)
+                screen.blit(icon, (name_x - icon.get_width() - 1,
+                                   name_y + (self.chs_name_bg.get_height() - icon.get_height()) // 2))
             self.chs_name_text_shadow.set_alpha(self.temporary_alpha)
             screen.blit(self.chs_name_text_shadow, (self.x_pos + 3 - self.chs_name_text_half_width, self.y_pos - 95))
             self.chs_name_text.set_alpha(self.temporary_alpha)

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

@@ -15,7 +15,7 @@ class GameTop(UIInstance):
     def __init__(self):
         super().__init__("game", "gameTop")
         self.font = pygame.font.Font(FONT_PATH, 16)
-        self.rend = self.font.render("v20261128", True, (0, 196, 255))
+        self.rend = self.font.render("v20261205", True, (0, 196, 255))
 
     def draw(self, screen: pygame.Surface):
         super().draw(screen)