parametric3_skill.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import random
  2. import pygame.time
  3. from collections import deque, Counter
  4. from math import sqrt, pi, sin, cos
  5. from game.const import color as C
  6. from game.const import game as G
  7. from game.effect.effect_instance import EffectInstance, EffectState
  8. from game.level import level
  9. from game.skill.skill import Skill, IceSlow, GotPoisonSmoke50x3, GotPoisonSmoke80x2
  10. from game.sound import sound_player
  11. from game.algo import aStar
  12. from game.skill.skill import Skill
  13. from game.skill.skill import *
  14. from game.effect.effect_instance import EffectState, EffectInstance
  15. from game.frame import bomb
  16. from game.frame import obstacle
  17. from game.level import level
  18. from game.sound import sound_player
  19. from game.music import music_loader
  20. from game.sprite.bomb_instance import BombInstance, BombInstanceBlack, BombInstanceGold
  21. from game.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 not None:
  59. level.current_level.set_level_variables(
  60. self.variable, custom_operator(value, self.operation, self.amount)
  61. )
  62. self.kill()
  63. # 自定义满足一定条件就放技能 "params": {"skill_name": "Skill1", "params": [], "variable": "v1", "operation": ">", "amount": 1}
  64. # 支持 "=" ">" "<"
  65. # "amount" 为 string 则为变量, 否则为数值
  66. class CustomConditionBasedSkill(Skill):
  67. def __init__(self, user, to, params, skill_instances):
  68. super().__init__(user, to, skill_instances)
  69. self.skill_name = params.get("skill_name", "")
  70. self.params = params.get("params", [])
  71. self.variable = params.get("variable", "")
  72. self.variable_amount = level.current_level.get_level_variables(self.variable, 1)
  73. self.operation = params.get("operation", "")
  74. self.amount = params.get("amount", 1)
  75. if isinstance(self.amount, str):
  76. self.amount = level.current_level.get_level_variables(self.amount, 1)
  77. def update(self):
  78. super().update()
  79. if self.user.remain_blood <= 0:
  80. self.kill()
  81. return
  82. if custom_condition(self.variable_amount, self.operation, self.amount):
  83. self.user.using_skill_map(self.skill_name, self.params, 0)
  84. self.kill()
  85. # 自定义第一次小于等于一定百分比血量就放技能 "params": {"skill_name": "Skill1", "params": [], "percent": 0.1}
  86. class CustomMonsterBloodBasedSkill(Skill):
  87. def __init__(self, user, to, params, skill_instances):
  88. super().__init__(user, to, skill_instances)
  89. self.skill_name = params.get("skill_name", "")
  90. self.params = params.get("params", [])
  91. self.percent = params.get("percent", 0.5)
  92. self.threshold = (self.user.remain_blood - self.user.fake_blood) * self.percent
  93. def update(self):
  94. super().update()
  95. if self.user.remain_blood <= 0:
  96. self.kill()
  97. return
  98. if self.user.remain_blood <= self.threshold:
  99. self.user.using_skill_map(self.skill_name, self.params, 0)
  100. self.kill()
  101. # 自定义满足一定百分比血量就放技能 "params": {"skill_name": "Skill1", "params": [], "percent": 0.1, "operation": ">"}
  102. class CustomAnyTimeMonsterBloodBasedSkill(Skill):
  103. def __init__(self, user, to, params, skill_instances):
  104. super().__init__(user, to, skill_instances)
  105. self.skill_name = params.get("skill_name", "")
  106. self.params = params.get("params", [])
  107. self.percent = params.get("percent", 0.5)
  108. self.operation = params.get("operation", ">")
  109. self.threshold = (self.user.remain_blood - self.user.fake_blood) * self.percent
  110. def update(self):
  111. super().update()
  112. if self.user.remain_blood <= 0:
  113. self.kill()
  114. return
  115. if custom_condition(self.user.remain_blood, self.operation, self.threshold):
  116. self.user.using_skill_map(self.skill_name, self.params, 0)
  117. self.kill()
  118. return
  119. # 一串技能 "params": {"skill_names": ["Skill1","Skill2"], "params": [[],[]], "times": [0, 0]}
  120. # 其中必须按时间顺序来L t1 <= t2 <= ...
  121. class CustomSequentialSkill(Skill):
  122. def __init__(self, user, to, params, skill_instances):
  123. super().__init__(user, to, skill_instances)
  124. self.skill_names = params.get("skill_names", [])
  125. self.params = params.get("params", [])
  126. self.times = params.get("times", [])
  127. self.skill_num = len(self.skill_names)
  128. self.current_skill_idx = 0
  129. def update(self):
  130. super().update()
  131. if self.user.remain_blood <= 0:
  132. self.kill()
  133. return
  134. if self.current_skill_idx >= self.skill_num:
  135. self.kill()
  136. return
  137. if self.current_time - self.skill_time_init > self.times[self.current_skill_idx]:
  138. self.user.using_skill_map(self.skill_names[self.current_skill_idx], self.params[self.current_skill_idx], 0)
  139. self.current_skill_idx += 1