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 None: value = 0 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": [], "variable": "v1", "operation": ">", "amount": 1} # 支持 "=" ">" "<" # "amount" 为 string 则为变量, 否则为数值 class CustomSingleTriggeredConditionBasedSkill(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.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.blood - self.user.fake_blood) * self.percent def update(self): super().update() if self.user.remain_blood <= 0: self.kill() return # print(custom_condition(self.user.remain_blood, self.operation, self.threshold), self.user.remain_blood, self.operation, self.threshold) 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 # 单个无限次数周期技能 # "params": {"skill_name": "SkillXXX", "params": [], "init": 3000, "interval": 5000} class CustomEndlessPeriodicSingleSkill(Skill): def __init__(self, user, to, params, skill_instances): super().__init__(user, to, skill_instances) self.skill_name = params.get("skill_name", None) self.params = params.get("params", []) self.init = params.get("init", 0) self.interval = params.get("interval", 10000) self.current_skill_idx = 0 def update(self): super().update() if self.user.remain_blood <= 0: self.kill() return if self.current_time - self.skill_time_init > self.init + self.current_skill_idx * self.interval: self.user.using_skill_map(self.skill_name, self.params, 0) self.current_skill_idx += 1