parametric3_skill.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import random
  2. import pygame.time
  3. from collections import deque, Counter
  4. from math import sqrt, pi, sin, cos
  5. from client_local.const import color as C
  6. from client_local.const import game as G
  7. from client_local.effect.effect_instance import EffectInstance, EffectState
  8. from client_local.level import level
  9. from client_local.skill.skill import Skill, IceSlow, GotPoisonSmoke50x3, GotPoisonSmoke80x2
  10. from client_local.sound import sound_player
  11. from client_local.algo import aStar
  12. from client_local.skill.skill import Skill
  13. from client_local.skill.skill import *
  14. from client_local.effect.effect_instance import EffectState, EffectInstance
  15. from client_local.frame import bomb
  16. from client_local.frame import obstacle
  17. from client_local.level import level
  18. from client_local.sound import sound_player
  19. from client_local.music import music_loader
  20. from client_local.sprite.bomb_instance import BombInstance, BombInstanceBlack, BombInstanceGold
  21. from client_local.sprite import obstacle_instance as oi
  22. def custom_operator(x, operation, y):
  23. if operation == "+":
  24. return x + y
  25. elif operation == "-":
  26. return x - y
  27. elif operation == "*":
  28. return x * y
  29. elif operation == r"//":
  30. return x // y
  31. elif operation == "%":
  32. return x % y
  33. def custom_condition(x, condition, y):
  34. if condition == "=":
  35. return x == y
  36. elif condition == ">":
  37. return x > y
  38. elif condition == "<":
  39. return x < y
  40. # 自定义关卡全局变量操作 "params": {"variable_name": "hello", "operation": "+", "amount": 1}
  41. # 支持 "=" "+" "-" "*" "//" "%"
  42. class CustomLevelVariableOperation(Skill):
  43. def __init__(self, user, to, params, skill_instances):
  44. super().__init__(user, to, skill_instances)
  45. self.params = params
  46. self.variable = params.get("variable_name", "")
  47. self.operation = params.get("operation", "*")
  48. self.amount = params.get("amount", 1)
  49. def update(self):
  50. super().update()
  51. if self.user.remain_blood <= 0:
  52. self.kill()
  53. return
  54. if self.operation == "=":
  55. level.current_level.set_level_variables(self.variable, self.amount)
  56. else:
  57. value = level.current_level.get_level_variables(self.variable, None)
  58. if value is None:
  59. value = 0
  60. level.current_level.set_level_variables(
  61. self.variable, custom_operator(value, self.operation, self.amount)
  62. )
  63. self.kill()
  64. # 自定义满足一定条件就放技能 "params": {"skill_name": "Skill1", "params": [], "variable": "v1", "operation": ">", "amount": 1}
  65. # 支持 "=" ">" "<"
  66. # "amount" 为 string 则为变量, 否则为数值
  67. class CustomConditionBasedSkill(Skill):
  68. def __init__(self, user, to, params, skill_instances):
  69. super().__init__(user, to, skill_instances)
  70. self.skill_name = params.get("skill_name", "")
  71. self.params = params.get("params", [])
  72. self.variable = params.get("variable", "")
  73. self.variable_amount = level.current_level.get_level_variables(self.variable, 1)
  74. self.operation = params.get("operation", "")
  75. self.amount = params.get("amount", 1)
  76. if isinstance(self.amount, str):
  77. self.amount = level.current_level.get_level_variables(self.amount, 1)
  78. def update(self):
  79. super().update()
  80. if self.user.remain_blood <= 0:
  81. self.kill()
  82. return
  83. if custom_condition(self.variable_amount, self.operation, self.amount):
  84. self.user.using_skill_map(self.skill_name, self.params, 0)
  85. self.kill()
  86. # 自定义满足一定条件就放的一次性被动技能 "params": {"skill_name": "Skill1", "params": [], "variable": "v1", "operation": ">", "amount": 1}
  87. # 支持 "=" ">" "<"
  88. # "amount" 为 string 则为变量, 否则为数值
  89. class CustomSingleTriggeredConditionBasedSkill(Skill):
  90. def __init__(self, user, to, params, skill_instances):
  91. super().__init__(user, to, skill_instances)
  92. self.skill_name = params.get("skill_name", "")
  93. self.params = params.get("params", [])
  94. self.variable = params.get("variable", "")
  95. self.variable_amount = level.current_level.get_level_variables(self.variable, 1)
  96. self.operation = params.get("operation", "")
  97. self.amount = params.get("amount", 1)
  98. if isinstance(self.amount, str):
  99. self.amount = level.current_level.get_level_variables(self.amount, 1)
  100. def update(self):
  101. super().update()
  102. if self.user.remain_blood <= 0:
  103. self.kill()
  104. return
  105. if custom_condition(self.variable_amount, self.operation, self.amount):
  106. self.user.using_skill_map(self.skill_name, self.params, 0)
  107. self.kill()
  108. # 自定义第一次小于等于一定百分比血量就放技能 "params": {"skill_name": "Skill1", "params": [], "percent": 0.1}
  109. class CustomMonsterBloodBasedSkill(Skill):
  110. def __init__(self, user, to, params, skill_instances):
  111. super().__init__(user, to, skill_instances)
  112. self.skill_name = params.get("skill_name", "")
  113. self.params = params.get("params", [])
  114. self.percent = params.get("percent", 0.5)
  115. self.threshold = (self.user.remain_blood - self.user.fake_blood) * self.percent
  116. def update(self):
  117. super().update()
  118. if self.user.remain_blood <= 0:
  119. self.kill()
  120. return
  121. if self.user.remain_blood <= self.threshold:
  122. self.user.using_skill_map(self.skill_name, self.params, 0)
  123. self.kill()
  124. # 自定义满足一定百分比血量就放技能 "params": {"skill_name": "Skill1", "params": [], "percent": 0.1, "operation": ">"}
  125. class CustomAnyTimeMonsterBloodBasedSkill(Skill):
  126. def __init__(self, user, to, params, skill_instances):
  127. super().__init__(user, to, skill_instances)
  128. self.skill_name = params.get("skill_name", "")
  129. self.params = params.get("params", [])
  130. self.percent = params.get("percent", 0.5)
  131. self.operation = params.get("operation", ">")
  132. self.threshold = (self.user.remain_blood - self.user.fake_blood) * self.percent
  133. def update(self):
  134. super().update()
  135. if self.user.remain_blood <= 0:
  136. self.kill()
  137. return
  138. if custom_condition(self.user.remain_blood, self.operation, self.threshold):
  139. self.user.using_skill_map(self.skill_name, self.params, 0)
  140. self.kill()
  141. return
  142. # 一串技能 "params": {"skill_names": ["Skill1","Skill2"], "params": [[],[]], "times": [0, 0]}
  143. # 其中必须按时间顺序来L t1 <= t2 <= ...
  144. class CustomSequentialSkill(Skill):
  145. def __init__(self, user, to, params, skill_instances):
  146. super().__init__(user, to, skill_instances)
  147. self.skill_names = params.get("skill_names", [])
  148. self.params = params.get("params", [])
  149. self.times = params.get("times", [])
  150. self.skill_num = len(self.skill_names)
  151. self.current_skill_idx = 0
  152. def update(self):
  153. super().update()
  154. if self.user.remain_blood <= 0:
  155. self.kill()
  156. return
  157. if self.current_skill_idx >= self.skill_num:
  158. self.kill()
  159. return
  160. if self.current_time - self.skill_time_init > self.times[self.current_skill_idx]:
  161. self.user.using_skill_map(self.skill_names[self.current_skill_idx], self.params[self.current_skill_idx], 0)
  162. self.current_skill_idx += 1