| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- 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
|