Przeglądaj źródła

(250720) 追加地震技能; 追加通关特效; 新增部分技能

detopoi 1 rok temu
rodzic
commit
4afc9bbcb8

+ 0 - 1
client_local/const/game.py

@@ -84,7 +84,6 @@ H_INCREMENT = 0
 
 
 
-
 # 记录玩家状态
 IN_BUBBLE = False
 CLEAR_BUBBLE = False

+ 71 - 3
client_local/level/level.py

@@ -30,12 +30,14 @@ from client_local.ui.game.score_board import ScoreBoard, Timer
 from client_local.ui.game.status_bar import StatusBar
 from client_local.ui.game.message_input import InputEntry, InputLevel
 from client_local.file_loader.fileLoader import load_json, load_png
+from client_local.skill.skill import WinEffect
 from client_local.skill.level_skill import Level3x3RandomThunder, DebuffPoisonGrid
 from datetime import datetime
 
 
 current_level = None
 level_font = pygame.font.Font("res/font/simsun.ttc", 16)
+Y_SCALE_FACTOR = 1  # 用于地震效果,画面会按比例以中间为基准进行上下偏移实现压缩效果
 
 max_alpha = 255  # 最大透明度
 circleMasks = {}
@@ -187,6 +189,17 @@ def caesar_encrypt(text, k=3):
     return encrypted_text
 
 
+class MainArea(pygame.Surface):
+    def __init__(self, size, flags=0):
+        super().__init__(size, flags)
+
+    def blit(self, source, dest, area=None, special_flags=0):
+        relative_y = dest[1] - current_level.scroll_y_pos - G.MAIN_AREA_Y_POS//2
+        scale_bias_value = relative_y * (1 - Y_SCALE_FACTOR)
+        dest = (dest[0], int(dest[1] - scale_bias_value))
+        super().blit(source, dest, area, special_flags)
+
+
 class Level:
 
     def __init__(self, your_name: str, map_name: str, me: Hero, music_volume, accumulation_time, game=None):
@@ -222,6 +235,12 @@ class Level:
         self.map_music_volume = music_volume  # 关卡背景音乐音量大小
         self.finish_at = None  # 地图过关点(x, y)
 
+        self.earth_quake_init_tick = 0  # 地震初始化tick
+        self.earth_quake_left_times = 0  # 地震剩余次数
+        self.earth_quake_strength = 0  # 地震强度
+        self.earth_quake_times = 0  # 地震次数
+        self.earth_quake_decrease = True  # 地震强度是否递减
+
         self.current_time = pygame.time.get_ticks()
         self.floor_image = None  # 游戏主区域的地板背景
         self.flame_instances = None  # FlameInstance对象列表
@@ -236,7 +255,7 @@ class Level:
         self.block_flame = None  # 三维NumPy对象,阻挡糖跑
         self.slide_orientation = dict()  # (x, y) --> (m, n) m网格传送带方向 0无 1右 2上 3左 4下 n速度
         self.grid_damage_blood = dict()  # 网格伤害血量
-        self.grid_damage_time = dict()  # 网格伤害时刻 只有糖泡爆炸时才会增加
+        self.grid_damage_time = defaultdict(None)  # 网格伤害时刻 只有糖泡爆炸时才会增加
         self.grid_damage_multiples = dict()  # 伤害次数(倍数)
         # self.grid_damage_orientations = dict()  # 网格伤害方向
         self.grid_damage_orientations = defaultdict(set)
@@ -252,6 +271,7 @@ class Level:
         self.left_black = None  # 屏幕右侧黑条
 
         self.grid_bomb_time_at = dict()  # 糖泡伤害时刻
+        self.level_variables = dict()
 
         self.blood_bar = None
         self.status_bar = None
@@ -275,6 +295,7 @@ class Level:
         self.custom_next_map = None
         self.portal = dict()
         self.portal_set = []
+        self.has_achievemeny_check = False
 
         self.special_music_volume = 1  # 若需放大音乐
 
@@ -336,6 +357,12 @@ class Level:
         # 紫色毒陷阱判断
         DebuffPoisonGrid(self.me, self.npcs, self.skill_instances)
 
+    def set_level_variables(self, name, value):
+        self.level_variables[name] = value
+
+    def get_level_variables(self, name, default_value):
+        return self.level_variables.get(name, default_value)
+
     def load_map_json(self):
         # 加载关卡json文件
         map_json = load_json("game/map/" + self.map_name + ".json")
@@ -385,7 +412,7 @@ class Level:
         self.district_square = {"x1": 0, "x2": 0, "y1": 0, "y2": 0}
         if "finish" in self.map_json["basic"].keys():
             self.finish_at = (self.map_json["basic"]["finish"][0], self.map_json["basic"]["finish"][1])
-        self.main_area = pygame.Surface((self.map_x_pos, self.map_y_pos)).convert()
+        self.main_area = MainArea((self.map_x_pos, self.map_y_pos)).convert()
         self.left_black = pygame.Surface((1, 600))
 
         if "haunted" in self.map_json["basic"].keys():
@@ -458,6 +485,35 @@ class Level:
         self.blood_bar.set_name(self.your_name)
         self.ui_instances_top.append(self.blood_bar)
 
+    def earth_quake_effect(self, strength=0.1, times=3, duration_per_time=200, decrease=True):
+        '''屏幕震动效果,强度表示移动像素数量,times表示震动次数,duration_per_time表示每次震动持续时间'''
+        self.earth_quake_strength = strength
+        self.earth_quake_times = times
+        self.earth_quake_duration_per_time = duration_per_time
+        self.earth_quake_time = pygame.time.get_ticks()
+        self.earth_quake_decrease = decrease
+
+    def run_earth_quake_effect(self, screen: pygame.Surface = None):
+        '''运行屏幕震动效果'''
+        global Y_SCALE_FACTOR
+        if self.earth_quake_strength <= 0 or self.earth_quake_times <= 0:
+            Y_SCALE_FACTOR = 1
+            return
+        now = pygame.time.get_ticks()
+        if now - self.earth_quake_time >= self.earth_quake_duration_per_time:
+            self.earth_quake_times -= 1
+            self.earth_quake_time = now
+            if self.earth_quake_decrease:
+                self.earth_quake_strength = self.earth_quake_strength * 0.5
+            if self.earth_quake_times <= 0:
+                self.earth_quake_strength = 0
+                return
+        # 计算偏移量(抛物线计算当前高度)
+        t = (now - self.earth_quake_time) / self.earth_quake_duration_per_time
+        Y_SCALE_FACTOR = 1 - self.earth_quake_strength * t * (1 - t)
+        MAX_BIAS = G.MAIN_AREA_Y_POS * (1-Y_SCALE_FACTOR)//2
+        screen.fill((0, 0, 0, 0), rect=(0, 21, G.MAIN_AREA_X_POS, MAX_BIAS))
+
     def load_floor(self):
         # 加载地板floor
         self.floor_image = pygame.Surface((self.map_x_pos, self.map_y_pos), flags=pygame.HWSURFACE)
@@ -552,6 +608,7 @@ class Level:
         if self.check_achievement() and G.CURRENT_LEVEL == G.TOTAL_LEVEL and not G.HAS_RECORD:
             G.HAS_RECORD = True
             sound_player.playWin("PlayerWin")
+            WinEffect(self.me, self.me, "big", self.skill_instances)
             # 构建保存文件的路径
             user_documents_folder = os.path.expanduser("~\\Documents")  # 获取用户的"文档"文件夹路径
             qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE")  # 构建QQTPVE文件夹路径
@@ -612,6 +669,9 @@ class Level:
                 G.MONSTER_RECORD_LIST = []
             except:
                 G.MONSTER_RECORD_LIST = []
+        else:
+            if G.CURRENT_LEVEL == G.TOTAL_LEVEL:
+                WinEffect(self.me, self.me, "normal", self.skill_instances)
 
     def load_district_and_enemies(self):
         if len(self.npcs) > 0:  # npc还没有被杀光
@@ -621,7 +681,9 @@ class Level:
             self.district_square = {"x1": 0, "x2": 0, "y1": 0, "y2": 0}
             self.district_square_grid = {"x1": 0, "x2": 0, "y1": 0, "y2": 0}
             self.district_all_finished = True
-            self.check_game_achievement()
+            if not self.has_achievemeny_check:
+                self.has_achievemeny_check = True
+                self.check_game_achievement()
             return
         self.district_idx += 1
         a_district = self.map_json["districts"][self.district_idx - 1]
@@ -664,6 +726,7 @@ class Level:
     def update(self, screen: pygame.Surface):
         # a = pygame.time.get_ticks()
         self.current_time = pygame.time.get_ticks()
+        self.run_earth_quake_effect(screen)  # 运行屏幕震动效果
 
         # 刷新帧率
         self.display_frame_rate(self.current_time, screen)
@@ -758,6 +821,11 @@ class Level:
         for u in self.ui_instances_bot:
             u.update()
 
+        if Y_SCALE_FACTOR != 1:
+            MAX_BIAS = G.MAIN_AREA_Y_POS * (1-Y_SCALE_FACTOR)//2
+            # 上下MAX_BIAS区域填充(0,0,0,0)
+            self.main_area.fill((255, 255, 255, 0), (self.scroll_x_pos, self.scroll_y_pos + 21, G.MAIN_AREA_X_POS, MAX_BIAS))
+
         # 显示地板
         self.main_area.blit(
             self.floor_image,

+ 70 - 0
client_local/skill/parametric2_skill.py

@@ -1978,6 +1978,76 @@ class CustomLightShield(Skill):
 
 
 
+class CustomMapEarthQuake(Skill):
+
+    def __init__(self, user=None, to=None, params=None, skill_instances=None):
+        super().__init__(user, to, skill_instances)
+        if params is None:
+            params = dict()
+        strength = params.get("strength", 0.1)
+        duration_per_time = params.get("duration_per_time", 200)
+        times = params.get("times", 3)
+        decrease = params.get("decrease", True)
+        direction = params.get("direction", 0)
+        level.current_level.earth_quake_effect(
+            strength=strength, duration_per_time=duration_per_time, times=times, decrease=decrease, direction=direction
+        )
+
+
+
+
+
+
+# 耗电原地召唤怪,"params": {"spawn_list": [充电召唤列表], "energy_cost": 3}
+class CustomPointSpawnWithNameAndCharge(Skill):
+
+    def __init__(self, user, to, params, skill_instances):
+        super().__init__(user, to, skill_instances)
+        self.spawns = params.get("spawn_list", ["JourneyBatMinion"])
+        self.energy_cost = params.get("energy_cost", 0)
+        self.loaded = True
+        self.loaded_eff = None
+        self.spawned = False
+        self.spawn_time = 0
+        self.enough_energy = False
+
+    def load(self):
+        super().load()
+
+    def update(self):
+        super().update()
+        if self.loaded:
+            self.loaded = False
+
+            if self.user.has_energy:
+                if self.user.energy_amount < self.energy_cost:
+                    for e in self.effect_instances:
+                        e.state = EffectState.DEAD
+                    self.kill()
+                    return
+                else:
+                    self.user.energy_amount -= self.energy_cost
+                    self.enough_energy = True
+
+        if not self.loaded and self.enough_energy and self.spawn_time == 0:
+            self.spawn_time = self.current_time
+            self.loaded_eff = EffectInstance("launch2", self.user, False, self.user.effects_behind)
+            self.user.rooted += 1
+            sound_player.play("launch")
+            self.spawned = True
+
+        if self.current_time - self.spawn_time > 800 and self.spawned:
+            self.spawned = False
+            self.user.rooted -= 1
+            self.loaded_eff.state = EffectState.DEAD
+            cl = level.current_level
+            for monster in self.spawns:
+                an_npc = cl.get_an_npc(monster, (self.user.x, self.user.y))
+                cl.npcs.append(an_npc)
+            self.kill()
+
+
+
 
 
 

+ 188 - 0
client_local/skill/parametric3_skill.py

@@ -0,0 +1,188 @@
+import random
+import pygame.time
+from collections import deque, Counter
+from math import sqrt, pi, sin, cos
+
+from client_local.const import color as C
+from client_local.const import game as G
+from client_local.effect.effect_instance import EffectInstance, EffectState
+from client_local.level import level
+from client_local.skill.skill import Skill, IceSlow, GotPoisonSmoke50x3, GotPoisonSmoke80x2
+from client_local.sound import sound_player
+from client_local.algo import aStar
+from client_local.skill.skill import Skill
+from client_local.skill.skill import *
+from client_local.effect.effect_instance import EffectState, EffectInstance
+from client_local.frame import bomb
+from client_local.frame import obstacle
+from client_local.level import level
+from client_local.sound import sound_player
+from client_local.music import music_loader
+from client_local.sprite.bomb_instance import BombInstance, BombInstanceBlack, BombInstanceGold
+from client_local.sprite import obstacle_instance as oi
+
+
+def custom_operator(x, operation, y):
+    if operation == "+":
+        return x + y
+    elif operation == "-":
+        return x - y
+    elif operation == "*":
+        return x * y
+    elif operation == r"//":
+        return x // y
+    elif operation == "%":
+        return x % y
+
+
+def custom_condition(x, condition, y):
+    if condition == "=":
+        return x == y
+    elif condition == ">":
+        return x > y
+    elif condition == "<":
+        return x < y
+
+
+# 自定义关卡全局变量操作   "params": {"variable_name": "hello", "operation": "+", "amount": 1}
+# 支持 "=" "+" "-" "*" "//" "%"
+class CustomLevelVariableOperation(Skill):
+
+    def __init__(self, user, to, params, skill_instances):
+        super().__init__(user, to, skill_instances)
+        self.params = params
+        self.variable = params.get("variable_name", "")
+        self.operation = params.get("operation", "*")
+        self.amount = params.get("amount", 1)
+
+    def update(self):
+        super().update()
+        if self.user.remain_blood <= 0:
+            self.kill()
+            return
+        if self.operation == "=":
+            level.current_level.set_level_variables(self.variable, self.amount)
+        else:
+            value = level.current_level.get_level_variables(self.variable, None)
+            if value is not None:
+                level.current_level.set_level_variables(
+                    self.variable, custom_operator(value, self.operation, self.amount)
+                )
+        self.kill()
+
+
+# 自定义满足一定条件就放技能   "params": {"skill_name": "Skill1", "params": [], "variable": "v1", "operation": ">", "amount": 1}
+# 支持 "=" ">" "<"
+# "amount" 为 string 则为变量, 否则为数值
+class CustomConditionBasedSkill(Skill):
+
+    def __init__(self, user, to, params, skill_instances):
+        super().__init__(user, to, skill_instances)
+        self.skill_name = params.get("skill_name", "")
+        self.params = params.get("params", [])
+        self.variable = params.get("variable", "")
+        self.variable_amount = level.current_level.get_level_variables(self.variable, 1)
+        self.operation = params.get("operation", "")
+        self.amount = params.get("amount", 1)
+        if isinstance(self.amount, str):
+            self.amount = level.current_level.get_level_variables(self.amount, 1)
+
+    def update(self):
+        super().update()
+        if self.user.remain_blood <= 0:
+            self.kill()
+            return
+        if custom_condition(self.variable_amount, self.operation, self.amount):
+            self.user.using_skill_map(self.skill_name, self.params, 0)
+        self.kill()
+
+
+# 自定义第一次小于等于一定百分比血量就放技能   "params": {"skill_name": "Skill1", "params": [], "percent": 0.1}
+class CustomMonsterBloodBasedSkill(Skill):
+
+    def __init__(self, user, to, params, skill_instances):
+        super().__init__(user, to, skill_instances)
+        self.skill_name = params.get("skill_name", "")
+        self.params = params.get("params", [])
+        self.percent = params.get("percent", 0.5)
+        self.threshold = (self.user.remain_blood - self.user.fake_blood) * self.percent
+
+    def update(self):
+        super().update()
+        if self.user.remain_blood <= 0:
+            self.kill()
+            return
+        if self.user.remain_blood <= self.threshold:
+            self.user.using_skill_map(self.skill_name, self.params, 0)
+            self.kill()
+
+
+# 自定义满足一定百分比血量就放技能   "params": {"skill_name": "Skill1", "params": [], "percent": 0.1, "operation": ">"}
+class CustomAnyTimeMonsterBloodBasedSkill(Skill):
+
+    def __init__(self, user, to, params, skill_instances):
+        super().__init__(user, to, skill_instances)
+        self.skill_name = params.get("skill_name", "")
+        self.params = params.get("params", [])
+        self.percent = params.get("percent", 0.5)
+        self.operation = params.get("operation", ">")
+        self.threshold = (self.user.remain_blood - self.user.fake_blood) * self.percent
+
+    def update(self):
+        super().update()
+        if self.user.remain_blood <= 0:
+            self.kill()
+            return
+        if custom_condition(self.user.remain_blood, self.operation, self.threshold):
+            self.user.using_skill_map(self.skill_name, self.params, 0)
+        self.kill()
+        return
+
+
+# 一串技能  "params": {"skill_names": ["Skill1","Skill2"], "params": [[],[]], "times": [0, 0]}
+# 其中必须按时间顺序来L t1 <= t2 <= ...
+class CustomSequentialSkill(Skill):
+
+    def __init__(self, user, to, params, skill_instances):
+        super().__init__(user, to, skill_instances)
+        self.skill_names = params.get("skill_names", [])
+        self.params = params.get("params", [])
+        self.times = params.get("times", [])
+        self.skill_num = len(self.skill_names)
+        self.current_skill_idx = 0
+
+    def update(self):
+        super().update()
+        if self.user.remain_blood <= 0:
+            self.kill()
+            return
+        if self.current_skill_idx >= self.skill_num:
+            self.kill()
+            return
+        if self.current_time - self.skill_time_init > self.times[self.current_skill_idx]:
+            self.user.using_skill_map(self.skill_names[self.current_skill_idx], self.params[self.current_skill_idx], 0)
+            self.current_skill_idx += 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 37 - 0
client_local/skill/skill.py

@@ -1599,3 +1599,40 @@ class PlayerDistantFire5x5(Skill):
 
 
 
+
+class WinEffect(Skill):
+
+    def __init__(self, user, to, params, skill_instances):
+        super().__init__(user, to, skill_instances)
+        if params == "super":
+            effect = 'winEffectSuper'
+        elif params == "big":
+            effect = 'winEffectBig'
+        else:
+            effect = 'winEffect'
+        self.effectObj = EffectInstance(effect, self.user, False, level.current_level.effects_screen)
+        self.effect_instances.append(self.effectObj)
+        self.speed = 0.2  # 15格/s
+        self.init_x_pos = min(G.MAIN_AREA_X_POS, level.current_level.map_x_pos + 20)//2
+        self.init_y_pos = 100
+        self.running = True
+
+    def update(self):
+        super().update()
+        if self.current_time - self.skill_time_init >= 10000:
+            self.kill()
+
+        if self.running:
+            time_passed = self.current_time - self.skill_time_init
+            self.effectObj.set_xy_pos(self.init_x_pos, self.init_y_pos + time_passed * self.speed)
+            if self.effectObj.y_pos >= G.MAIN_AREA_Y_POS//2:
+                self.running = False
+
+
+
+
+
+
+
+
+

+ 9 - 0
client_local/skill/skill_map.py

@@ -9,6 +9,7 @@ from client_local.skill.special_magic_skill import *
 from client_local.skill.machine_skill import *
 from client_local.skill.cool_machine_skill import *
 from client_local.skill.parametric2_skill import *
+from client_local.skill.parametric3_skill import *
 
 
 skill_map = {
@@ -308,6 +309,14 @@ skill_map = {
     "CustomLightRangeRecovery": {"skill": CustomLightRangeRecovery, "target": "npcs", "param": True, "effect": "cl"},
     "CustomMoveToTarget": {"skill": CustomMoveToTarget, "target": "npcs", "param": True, "effect": "cl"},
     "CustomLightShield": {"skill": CustomLightShield, "target": "me", "param": True, "effect": "cl"},
+    "CustomMapEarthQuake": {"skill": CustomMapEarthQuake, "target": None, "param": True, "effect": "cl"},
+    "CustomPointSpawnWithNameAndCharge": {"skill": CustomPointSpawnWithNameAndCharge, "target": "me", "param": True, "effect": "cl"},
+
+    "CustomLevelVariableOperation": {"skill": CustomLevelVariableOperation, "target": "me", "param": True, "effect": "self"},
+    "CustomConditionBasedSkill": {"skill": CustomConditionBasedSkill, "target": "me", "param": True, "effect": "self"},
+    "CustomMonsterBloodBasedSkill": {"skill": CustomMonsterBloodBasedSkill, "target": "me", "param": True, "effect": "self"},
+    "CustomAnyTimeMonsterBloodBasedSkill": {"skill": CustomAnyTimeMonsterBloodBasedSkill, "target": "me", "param": True, "effect": "self"},
+    "CustomSequentialSkill": {"skill": CustomSequentialSkill, "target": "me", "param": True, "effect": "self"},
 
     "Canyon_RevengeDash": {"skill": Canyon_RevengeDash, "target": None, "param": None, "effect": "self"},
     "Canyon_Skill21044": {"skill": Canyon_Skill21044, "target": "me", "param": None, "effect": "self"},