|
|
@@ -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()
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|