import random import json from json import JSONDecodeError from game.algo import aStar from game.skill.skill import Skill from game.effect.effect_instance import EffectState, EffectInstance from game.frame import bomb from game.level import level from game.sound import sound_player from game.sprite.bomb_instance import BombInstance, BombInstanceBlack, BombInstanceGold from math import sqrt import pygame.time from game.const import game as G from game.effect.effect_instance import EffectInstance, EffectState from game.level import level from game.skill.skill import Skill, IceSlow, GotPoisonSmoke50x3, GotPoisonSmoke80x2 from game.skill.machine_skill import Reverse5s from game.skill.obstacle_skill import NPC_Obstacle3x3Explode from game.sound import sound_player from game.level import level import logging from datetime import datetime # 配置logging基础配置并设置日志级别为INFO # logging.basicConfig(filename='OBSTACLE_SKILL.log', level=logging.INFO) def shortest_path(start, end): x1, y1 = start x2, y2 = end path = [start] while x1 != x2: if random.randint(1, 100) > 50 and y1 != y2: if y1 < y2: y1 += 1 else: y1 -= 1 path.append((x1, y1)) if x1 < x2: x1 += 1 else: x1 -= 1 path.append((x1, y1)) while y1 != y2: if y1 < y2: y1 += 1 else: y1 -= 1 path.append((x1, y1)) return path # print(shortest_path((17,5),(8,1))) # 追踪落雷带1s晕 class ChasingThunder700(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True self.enough_energy = True self.chasing_list = [] self.flag_thunder_down_list = [] self.flag_thunder_explode_list = [] def load(self): super().load() def update(self): super().update() if self.user.remain_blood <= 0.1: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if self.current_time - self.skill_time_init > len(self.chasing_list) * 250 + 600: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() for i in range(1, len(self.chasing_list)): if self.current_time - self.skill_time_init > 250 * i and self.flag_thunder_down_list[i] and self.enough_energy: self.flag_thunder_down_list[i] = False if self.current_time - self.skill_time_init > 250 * i + 200 and self.flag_thunder_explode_list[i] and self.enough_energy: self.flag_thunder_explode_list[i] = False for e in self.effect_instances: e.state = EffectState.DEAD me = level.current_level.me if i == len(self.chasing_list) - 1: for x in range(-1, 2): for y in range(-1, 2): an_effect = EffectInstance("thunder_explode", self.user, False, self.user.effects_front) an_effect.x_pos = (self.chasing_list[i][0] + x) * G.GAME_SQUARE + G.HALF_GAME_SQUARE an_effect.y_pos = (self.chasing_list[i][1] + y) * G.GAME_SQUARE + G.HALF_GAME_SQUARE self.effect_instances.append(an_effect) if me.x == self.chasing_list[i][0] + x and me.y == self.chasing_list[i][1] + y: self.to.try_damage(700) self.to.rooted_for(1000) sound_player.play("cry") else: an_effect = EffectInstance("thunder_explode", self.user, False, self.user.effects_front) an_effect.x_pos = self.chasing_list[i][0] * G.GAME_SQUARE + G.HALF_GAME_SQUARE an_effect.y_pos = self.chasing_list[i][1] * G.GAME_SQUARE + G.HALF_GAME_SQUARE self.effect_instances.append(an_effect) if me.x == self.chasing_list[i][0] and me.y == self.chasing_list[i][1]: self.to.try_damage(700) self.to.rooted_for(1000) sound_player.play("cry") sound_player.play("crash") if i + 1 <= len(self.chasing_list) - 1: an_effect = EffectInstance("thunder_trap", self.user, False, level.current_level.effects_behind) an_effect.set_xy(self.chasing_list[i + 1][0], self.chasing_list[i + 1][1]) self.effect_instances.append(an_effect) if i + 1 <= len(self.chasing_list) - 2: an_effect = EffectInstance("thunder_trap", self.user, False, level.current_level.effects_behind) an_effect.set_xy(self.chasing_list[i + 2][0], self.chasing_list[i + 2][1]) self.effect_instances.append(an_effect) if self.loaded: # 耗电判定(2格能量) if self.user.has_energy: if self.user.energy_amount < 3: self.enough_energy = False for e in self.effect_instances: e.state = EffectState.DEAD self.kill() else: self.user.energy_amount -= 3 if self.enough_energy: me = level.current_level.me self.chasing_list = shortest_path((self.user_x, self.user_y), (me.x, me.y)) self.flag_thunder_down_list = [True] * len(self.chasing_list) self.flag_thunder_explode_list = [True] * len(self.chasing_list) self.loaded = False self.user.rooted_for(500) self.user.align_xy() sound_player.play("launch") self.effect_instances.append(EffectInstance("thunder_charge", self.user, False, self.user.effects_front)) an_effect = EffectInstance("thunder_trap", self.user, False, level.current_level.effects_behind) an_effect.set_xy(self.user_x, self.user_y) self.effect_instances.append(an_effect) # v=0 class SpeedZero(Skill): def __init__(self, user, to, skill_instances): self.accelerate = True super().__init__(user, to, skill_instances) def load(self): super().load() def update(self): super().update() if self.accelerate == True: self.user.speed = 0 # 0.004代码速度=0.1游戏速度 self.accelerate = False self.kill() # 落雷带1s晕 class ColumnThunder700(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True self.enough_energy = True self.target_list = [] self.flag_thunder_down = True self.flag_thunder_explode = True def load(self): super().load() def update(self): super().update() if self.user.remain_blood <= 0.1: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if self.current_time - self.skill_time_init > 1200: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if self.current_time - self.skill_time_init > 700 and self.flag_thunder_explode and self.enough_energy: for i in range(1, len(self.target_list)): self.flag_thunder_explode = False for e in self.effect_instances: e.state = EffectState.DEAD me = level.current_level.me for point in self.target_list: an_effect = EffectInstance("thunder_explode", self.user, False, self.user.effects_front) an_effect.x_pos = (point[0]) * G.GAME_SQUARE + G.HALF_GAME_SQUARE an_effect.y_pos = (point[1]) * G.GAME_SQUARE + G.HALF_GAME_SQUARE self.effect_instances.append(an_effect) if me.x == point[0] and me.y == point[1]: self.to.try_damage(700) self.to.rooted_for(1000) sound_player.play("cry") sound_player.play("crash") if self.loaded: # 耗电判定(3格能量) if self.user.has_energy: if self.user.energy_amount < 4: self.enough_energy = False for e in self.effect_instances: e.state = EffectState.DEAD self.kill() else: self.user.energy_amount -= 4 if self.enough_energy: me = level.current_level.me for i in range(11): if 0 <= me.y - 5 + i <= G.CURRENT_MAP_HEIGHT - 1: self.target_list.append((me.x, me.y - 5 + i)) self.loaded = False self.user.rooted_for(1000) self.user.align_xy() sound_player.play("launch") self.effect_instances.append(EffectInstance("thunder_charge", self.user, False, self.user.effects_front)) for point in self.target_list: an_effect = EffectInstance("thunder_trap", self.user, False, level.current_level.effects_behind) an_effect.set_xy(point[0], point[1]) self.effect_instances.append(an_effect) # 落雷带1s晕 class RowThunder700(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True self.enough_energy = True self.target_list = [] self.flag_thunder_down = True self.flag_thunder_explode = True def load(self): super().load() def update(self): super().update() if self.user.remain_blood <= 0.1: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if self.current_time - self.skill_time_init > 1200: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if self.current_time - self.skill_time_init > 700 and self.flag_thunder_explode and self.enough_energy: for i in range(1, len(self.target_list)): self.flag_thunder_explode = False for e in self.effect_instances: e.state = EffectState.DEAD me = level.current_level.me for point in self.target_list: an_effect = EffectInstance("thunder_explode", self.user, False, self.user.effects_front) an_effect.x_pos = (point[0]) * G.GAME_SQUARE + G.HALF_GAME_SQUARE an_effect.y_pos = (point[1]) * G.GAME_SQUARE + G.HALF_GAME_SQUARE self.effect_instances.append(an_effect) if me.x == point[0] and me.y == point[1]: self.to.try_damage(700) self.to.rooted_for(1000) sound_player.play("cry") sound_player.play("crash") if self.loaded: # 耗电判定(3格能量) if self.user.has_energy: if self.user.energy_amount < 4: self.enough_energy = False for e in self.effect_instances: e.state = EffectState.DEAD self.kill() else: self.user.energy_amount -= 4 if self.enough_energy: me = level.current_level.me for i in range(11): if 0 <= me.x - 5 + i <= G.CURRENT_MAP_WIDTH - 1: self.target_list.append((me.x - 5 + i, me.y)) self.loaded = False self.user.rooted_for(1000) self.user.align_xy() sound_player.play("launch") self.effect_instances.append(EffectInstance("thunder_charge", self.user, False, self.user.effects_front)) for point in self.target_list: an_effect = EffectInstance("thunder_trap", self.user, False, level.current_level.effects_behind) an_effect.set_xy(point[0], point[1]) self.effect_instances.append(an_effect) # 充能1格 class Energy_Charge_1(Skill): def __init__(self, user, to, skill_instances): self.charge = False super().__init__(user, to, skill_instances) def load(self): super().load() def update(self): super().update() if self.charge == False and self.user.has_energy and self.user.energy_amount + 1 <= self.user.max_energy_amount: self.user.energy_amount += 1 self.charge = True self.kill() # 放能1格 class Energy_Discharge_1(Skill): def __init__(self, user, to, skill_instances): self.charge = False super().__init__(user, to, skill_instances) def load(self): super().load() def update(self): super().update() if self.charge == False and self.user.has_energy and self.user.energy_amount - 1 >= 0: self.user.energy_amount -= 1 self.charge = True self.kill() # 放能 class Energy_Clear(Skill): def __init__(self, user, to, skill_instances): self.charge = False super().__init__(user, to, skill_instances) def load(self): super().load() def update(self): super().update() if self.charge == False and self.user.has_energy: self.user.energy_amount = 0 self.charge = True self.kill() # 600慢速全路径不引爆飞火 class SlowFireBall(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True self.enough_energy = True self.knife_charge = True # 火苗充能 self.knife_begin = True # 火苗飞出 self.knife_end = True # 火苗到达 self.to_xy = None # 火苗目标 self.delta_x = 0 # 火苗x增量 self.delta_y = 0 # 火苗y增量 self.delta_len = 0 # 火苗运行长度 self.old_time = pygame.time.get_ticks() self.effect_fire = None self.damage_blood = 600 self.path_points = [] # 新增:火苗经过的所有点 def update(self): super().update() if self.current_time - self.skill_time_init > 8000: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if not self.knife_begin and self.knife_end: e = self.effect_fire if self.delta_len != 0: delta_time = self.current_time - self.old_time # 计算两次调用update的间隔 new_x = e.x_pos + 0.12 * delta_time * self.delta_x / self.delta_len new_y = e.y_pos + 0.12 * delta_time * self.delta_y / self.delta_len e.set_xy_pos(new_x, new_y) self.old_time = self.current_time if (e.x_pos - self.to.x_pos)**2 + (e.y_pos - self.to.y_pos)**2 <= 20*20*1.5: self.knife_end = False for e in self.effect_instances: e.state = EffectState.DEAD self.to.try_damage(self.damage_blood) self.kill() sound_player.play("crash") if self.delta_len==0: if (e.x_pos - self.to.x_pos)**2 + (e.y_pos - self.to.y_pos)**2 <= 20*20*1.5: self.knife_end = False self.to.try_damage(self.damage_blood) sound_player.play("crash") for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if not self.knife_charge and self.knife_begin: self.knife_begin = False if self.user.remain_blood == 0: self.kill() return self.old_time = self.current_time self.delta_x = self.to_xy[0] - self.user_x self.delta_y = self.to_xy[1] - self.user_y self.delta_len = sqrt(self.delta_x * self.delta_x + self.delta_y * self.delta_y) if self.delta_x > 0: self.effect_fire = EffectInstance("fire_ball", self.user, False, level.current_level.effects_front) else: self.effect_fire = EffectInstance("fire_ball", self.user, False, level.current_level.effects_front) self.effect_instances.append(self.effect_fire) if self.current_time - self.skill_time_init > 1000 and self.knife_charge: self.knife_charge = False self.user.rooted -= 1 if self.loaded: # 耗电判定(2格能量) if self.user.has_energy: if self.user.energy_amount < 2: self.enough_energy = False for e in self.effect_instances: e.state = EffectState.DEAD self.kill() else: self.user.energy_amount -= 2 if self.enough_energy: self.loaded = False self.user.rooted += 1 self.user.align_xy() sound_player.play("launch") self.to_xy = (self.to.x, self.to.y) # 600随机慢速全路径不引爆飞火 class RandomSlowFireBall(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True self.enough_energy = True self.knife_charge = True # 火苗充能 self.knife_begin = True # 火苗飞出 self.knife_end = True # 火苗到达 self.to_xy = None # 火苗目标 self.rx = 0 self.ry = 0 self.delta_x = 0 # 火苗x增量 self.delta_y = 0 # 火苗y增量 self.delta_len = 0 # 火苗运行长度 self.old_time = pygame.time.get_ticks() self.effect_fire = None self.damage_blood = 600 self.path_points = [] # 新增:火苗经过的所有点 def update(self): super().update() if self.current_time - self.skill_time_init > 8000: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if not self.knife_begin and self.knife_end: e = self.effect_fire if self.delta_len != 0: delta_time = self.current_time - self.old_time # 计算两次调用update的间隔 new_x = e.x_pos + 0.12 * delta_time * self.delta_x / self.delta_len new_y = e.y_pos + 0.12 * delta_time * self.delta_y / self.delta_len e.set_xy_pos(new_x, new_y) self.old_time = self.current_time if (e.x_pos - self.to.x_pos)**2 + (e.y_pos - self.to.y_pos)**2 <= 20*20*1.5: self.knife_end = False for e in self.effect_instances: e.state = EffectState.DEAD self.to.try_damage(self.damage_blood) self.kill() sound_player.play("crash") if self.delta_len==0: if (e.x_pos - self.to.x_pos)**2 + (e.y_pos - self.to.y_pos)**2 <= 20*20*1.5: self.knife_end = False self.to.try_damage(self.damage_blood) sound_player.play("crash") for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if not self.knife_charge and self.knife_begin: self.knife_begin = False if self.user.remain_blood == 0: self.kill() return self.old_time = self.current_time self.delta_x = self.to_xy[0] - self.user_x self.delta_y = self.to_xy[1] - self.user_y self.delta_len = sqrt(self.delta_x * self.delta_x + self.delta_y * self.delta_y) if self.delta_x > 0: self.effect_fire = EffectInstance("fire_ball", self.user, False, level.current_level.effects_front) else: self.effect_fire = EffectInstance("fire_ball", self.user, False, level.current_level.effects_front) self.effect_instances.append(self.effect_fire) if self.current_time - self.skill_time_init > 1000 and self.knife_charge: self.knife_charge = False self.user.rooted -= 1 if self.loaded: # 耗电判定(3格能量) if self.user.has_energy: if self.user.energy_amount < 2: self.enough_energy = False for e in self.effect_instances: e.state = EffectState.DEAD self.kill() else: self.user.energy_amount -= 2 if self.enough_energy: self.loaded = False self.user.rooted += 1 self.user.align_xy() sound_player.play("launch") self.rx = min(G.CURRENT_MAP_WIDTH-1,max(0,self.to.x+random.randint(-2,3))) self.ry = min(G.CURRENT_MAP_HEIGHT-1,max(0,self.to.y+random.randint(-2,3))) self.to_xy = (self.rx, self.ry) # 能量鸡蛋 class EnergyEgg300(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True # 0ms self.enough_energy = True self.damage_blood = 0 self.thunder_trap = True self.to_already_on = False self.isexplode = False self.explodetime = 0 self.thunder_down = True # 250ms self.thunder_explode = True # 500ms self.to_xy = None # 火焰提示时玩家的xy self.hit = False # 是否命中玩家 self.startexplode = False def update(self): super().update() if self.current_time - self.skill_time_init > 60000: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if self.current_time - self.skill_time_init > 0 and self.thunder_trap: if self.user.has_energy: if self.user.energy_amount < 3: self.enough_energy = False for e in self.effect_instances: e.state = EffectState.DEAD self.kill() else: self.user.energy_amount -= 3 if self.enough_energy: self.thunder_trap = False # self.user.rooted -= 1 self.effect_instances.append( EffectInstance("thunder_trap", self.user, False, level.current_level.effects_behind) ) if self.to.x == self.user_x and self.to.y == self.user_y: self.to_already_on = True if self.current_time - self.skill_time_init <= 100: if self.user.remain_blood == 0: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() return if self.current_time - self.skill_time_init > 100: # 判断玩家是否踩中陷阱 if self.to.x == self.user_x and self.to.y == self.user_y: if not self.to_already_on: EffectInstance("thunder_fixed", self.to, False, level.current_level.effects_behind) self.to_xy = (self.to.x, self.to.y) self.to_already_on = True self.startexplode = True else: self.to_already_on = False if self.startexplode and not self.isexplode: self.explodetime = self.current_time self.isexplode = True if self.isexplode and self.current_time - self.explodetime > 1000: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if self.isexplode and self.current_time - self.explodetime > 200 and self.thunder_explode: self.thunder_explode = False an_effect = EffectInstance("thunder_explode", self.to, False, level.current_level.effects_behind) an_effect.set_xy(self.to_xy[0], self.to_xy[1]) self.effect_instances.append(an_effect) if self.hit: self.dizzy_rooted_effect = EffectInstance("reverse", self.to, True, self.to.effects_front) self.to.try_damage(300) self.to.rooted_for(3000) # self.kill() if self.isexplode and self.current_time - self.explodetime > 162 and self.thunder_down: self.thunder_down = False for e in self.effect_instances: e.state = EffectState.DEAD an_effect = EffectInstance("thunder_down", self.to, False, level.current_level.effects_behind) an_effect.set_xy(self.to_xy[0], self.to_xy[1]) self.effect_instances.append(an_effect) # 判断是否击中玩家 if self.to_xy[0] == self.to.x and self.to_xy[1] == self.to.y: self.hit = True if self.isexplode and self.loaded: self.loaded = False sound_player.play("launch") # self.user.align_xy() self.effect_instances.append( EffectInstance("thunder_trap", self.to, False, self.to.effects_behind) ) # 3x3反向300伤 class TimeExplodePlus(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True self.enough_energy = True self.dizzy_explode = True # 眩晕爆炸 self.dizzy_rooted_effect = None # 眩晕定身特效 def load(self): super().load() def update(self): super().update() if self.current_time - self.skill_time_init > 5001: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if self.current_time - self.skill_time_init > 10 and self.dizzy_explode and not self.loaded: # 眩晕爆炸 self.dizzy_explode = False # 检查死亡 if self.user.remain_blood == 0: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() return if abs(self.user_y - self.to.y) < 2 and abs(self.user_x - self.to.x) < 2: self.effect_instances.append( EffectInstance("reverse", self.to, True, self.to.effects_front) ) Reverse5s(self.user, self.to, self.to.skill_instances) self.to.try_damage(300) sound_player.play("cry") if self.loaded: # 耗电判定(2格能量) if self.user.has_energy: if self.user.energy_amount < 2: self.enough_energy = False for e in self.effect_instances: e.state = EffectState.DEAD self.kill() else: self.user.energy_amount -= 2 if self.enough_energy: # npc施法阵与眩晕范围提示 self.loaded = False # self.user.align_xy() self.effect_instances.append( EffectInstance("thunder_fixed", self.user, False, level.current_level.effects_behind) ) sound_player.play("explode2") # 5x5范围内充电1格 class Energy5x5Charge1(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True self.trigger = True self.assistance_list = [] def load(self): super().load() self.assistance_list = [] self.trigger = True for npc in self.to: if npc.has_energy and abs(self.user.x - npc.x) <= 2 and abs(self.user.y - npc.y) <= 2: self.assistance_list.append(npc) if len(self.assistance_list) > 0: for npc in self.assistance_list: if npc.energy_amount + 1 <= npc.max_energy_amount: npc.energy_amount += 1 self.effect_instances.append(EffectInstance("blue_dots", npc, True, self.user.effects_behind)) def update(self): super().update() if self.current_time - self.skill_time_init > 500: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() return # 5x5范围内抽取能量3格 class Energy5x5Absorb3(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True self.trigger = True self.assistance_list = [] def load(self): super().load() self.assistance_list = [] self.trigger = True for npc in self.to: if npc.has_energy and abs(self.user.x - npc.x) <= 2 and abs(self.user.y - npc.y) <= 2: self.assistance_list.append(npc) if len(self.assistance_list) > 0: self.effect_instances.append(EffectInstance("blue_dots", self.user, True, self.user.effects_behind)) for npc in self.assistance_list: if npc.energy_amount > 0: if npc.energy_amount - 3 >= 0: npc.energy_amount -= 3 self.user.energy_amount += 3 else: self.user.energy_amount += npc.energy_amount npc.energy_amount = 0 def update(self): super().update() if self.current_time - self.skill_time_init > 500: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() return # 5x5范围内充电5格 class Energy5x5Charge5(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True self.trigger = True self.assistance_list = [] def load(self): super().load() self.assistance_list = [] self.trigger = True for npc in self.to: if npc.has_energy and abs(self.user.x - npc.x) <= 2 and abs(self.user.y - npc.y) <= 2: self.assistance_list.append(npc) if len(self.assistance_list) > 0: self.effect_instances.append(EffectInstance("blue_dots", self.user, True, self.user.effects_behind)) for npc in self.assistance_list: if npc.energy_amount < npc.max_energy_amount: if npc.energy_amount + 5 <= npc.max_energy_amount: npc.energy_amount += 5 else: npc.energy_amount = npc.max_energy_amount def update(self): super().update() if self.current_time - self.skill_time_init > 500: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() return # 7x7范围内充电5格 class Energy7x7Charge5(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True self.trigger = True self.assistance_list = [] def load(self): super().load() self.assistance_list = [] self.trigger = True for npc in self.to: if npc.has_energy and abs(self.user.x - npc.x) <= 3 and abs(self.user.y - npc.y) <= 3: self.assistance_list.append(npc) if len(self.assistance_list) > 0: self.effect_instances.append(EffectInstance("blue_dots", self.user, True, self.user.effects_behind)) for npc in self.assistance_list: if npc.energy_amount < npc.max_energy_amount: if npc.energy_amount + 5 <= npc.max_energy_amount: npc.energy_amount += 5 else: npc.energy_amount = npc.max_energy_amount def update(self): super().update() if self.current_time - self.skill_time_init > 500: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() return # 没电了(<1)就自杀 class PowerOFF(Skill): def __init__(self, user, to, skill_instances): self.charge = False self.explode = False self.yes_exp = False self.trigger = False self.trigger_time = 0 self.is_dying = False self.flag_thunder_explode = True # 400ms self.target = None self.explode = False self.explode_time = 0 self.dmg = 500 super().__init__(user, to, skill_instances) def load(self): super().load() def update(self): super().update() if not self.charge: # if self.user.has_energy and self.user.energy_amount <= max(1,int(self.user.max_energy_amount/20)): if self.user.has_energy and self.user.energy_amount < 1: self.user.speed = 0 self.charge = True self.explode = True self.user.energy_amount = 0 self.user.remain_blood = 1 self.yes_exp = True # DeadExplode(self.user, self.to, self.skill_instances) # self.kill() if self.yes_exp: if not self.trigger: self.trigger = True self.trigger_time = self.current_time sound_player.play("explode") self.user.rooted_for(10000) if self.trigger and self.trigger_time>0 and not self.is_dying: self.is_dying = True if self.flag_thunder_explode: self.flag_thunder_explode = False self.target = self.to NPC_Obstacle3x3Explode(level.current_level.me, self.user, level.current_level.skill_instances) for t in self.target: if abs(t.x-self.user.x) <= 1 and abs(t.y-self.user.y) <= 1: t.try_damage(5000) t.rooted_for(1000) try: if t.has_energy: t.energy_amount -= min(max(5,int(t.max_energy_amount/(20-random.randint(0,10)))), t.energy_amount) except: pass if abs(level.current_level.me.x-self.user.x)<=1 and abs(level.current_level.me.y-self.user.y)<=1: level.current_level.me.try_damage(400) level.current_level.me.rooted_for(1000) sound_player.play("cry") self.explode = True self.explode_time = self.current_time self.user.try_damage(1000000000000000000000000000000000) self.user.die() self.user.remain_blood = 0 self.kill() if self.explode and self.current_time - self.explode_time >= 300: self.kill() return if self.explode or not self.user.has_energy: if self.user.remain_blood > 0: self.user.energy_amount = 0 self.kill() # 生命低于100000就自爆 class DeadExplode(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.trigger = False self.trigger_time = 0 self.is_dying = False self.flag_thunder_explode = True # 400ms self.target = None self.explode = False self.explode_time = 0 self.dmg = 500 def load(self): super().load() self.user.fake_blood = 100000 self.user.blood += 100000 self.user.remain_blood += 100000 def update(self): super().update() if self.user.remain_blood <= 100000 and not self.trigger: self.trigger = True self.trigger_time = self.current_time sound_player.play("explode") self.user.rooted_for(10000) if self.trigger and self.trigger_time>0 and self.current_time - self.trigger_time>=50 and not self.is_dying: self.is_dying = True if self.flag_thunder_explode: self.flag_thunder_explode = False self.target = self.to NPC_Obstacle3x3Explode(level.current_level.me, self.user, level.current_level.skill_instances) for t in self.target: if abs(t.x-self.user.x) <= 1 and abs(t.y-self.user.y) <= 1: t.try_damage(5000) t.rooted_for(1000) try: if t.has_energy: t.energy_amount -= min(max(5,int(t.max_energy_amount/(20-random.randint(0,10)))), t.energy_amount) except: pass if abs(level.current_level.me.x-self.user.x)<=1 and abs(level.current_level.me.y-self.user.y)<=1: level.current_level.me.try_damage(400) level.current_level.me.rooted_for(1000) sound_player.play("cry") self.explode = True self.explode_time = self.current_time self.user.try_damage(1000000000000000000000000000000000) self.user.die() self.user.remain_blood = 0 self.kill() if self.explode and self.current_time - self.explode_time >= 300: self.kill() return class LaserSword5x5(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True self.used = False self.laser = False def update(self): if not self.loaded and not self.used: self.used = True # 激光版 if self.laser: self.effect_instances.append( EffectInstance("laser_sword", self.user, True, self.user.effects_front) ) for to in self.to: if abs(to.x - self.user.x) < 3 and abs(to.y - self.user.y) < 3 and (abs(to.x - self.user.x) + abs(to.y - self.user.y) != 4): to.try_damage(600) EffectInstance("thunder_explode", to, True, to.effects_front) sound_player.play("cry") for x in range(self.user.x - 2, self.user.x + 3): for y in range(self.user.y - 2, self.user.y + 3): if abs(x-self.user.x)+abs(y-self.user.y) != 4: # 引爆糖泡 bombs = level.current_level.get_bomb_instance(x, y) if len(bombs) > 0: bombs[0].explode() if (x, y) in level.current_level.obstacle_instances.keys(): # 尝试摧毁障碍 level.current_level.obstacle_instances[(x, y)].die() level.current_level.obstacle_instances_need_to_update = True # 普通版 else: self.effect_instances.append( EffectInstance("sword", self.user, True, self.user.effects_front) ) for to in self.to: if abs(to.x - self.user.x) < 3 and abs(to.y - self.user.y) < 3 and (abs(to.x - self.user.x) + abs(to.y - self.user.y) != 4): to.try_damage(400) EffectInstance("thunder_explode", to, True, to.effects_front) if self.current_time - self.skill_time_init > 500: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if self.loaded: self.loaded = False # 耗电判定(7格能量) if self.user.has_energy: if self.user.energy_amount < 7: self.laser = False else: self.laser = True self.user.energy_amount -= 7 else: self.laser = True # 电磁护盾(电量≥一半时触发,防御两倍) class PowerShield2(Skill): def __init__(self, user, to, skill_instances): self.defense_add = 0 self.defend = False self.effect_shield = None # 盾动画 super().__init__(user, to, skill_instances) def load(self): super().load() self.defense_add = self.user.defense def update(self): super().update() if not self.defend: if self.user.energy_amount >= 0.5 * self.user.max_energy_amount: self.defend = True sound_player.play("launch") self.user.defense += self.defense_add self.effect_shield = EffectInstance("yellow_circle", self.user, True, self.user.effects_behind) if self.defend: if self.user.energy_amount < 0.5 * self.user.max_energy_amount: self.defend = False self.user.defense -= self.defense_add if self.effect_shield is not None: self.effect_shield.state = EffectState.DEAD if self.user.remain_blood == 0: if self.effect_shield is not None: self.effect_shield.state = EffectState.DEAD self.kill() # 无保护膜怪 class RemoveProtect(Skill): def __init__(self, user, skill_instances): super().__init__(user, None, skill_instances) def load(self): super().load() self.user.witch_protected_remove = True def update(self): super().update() if self.current_time - self.skill_time_init > 1000: self.kill() # 冲刺 class ShortRush(Skill): def __init__(self, user, skill_instances): super().__init__(user, None, skill_instances) self.loaded = True self.enough_energy = True self.istriggered = False self.isstart = False self.eff_names = {"R": "air_knife_r", "U": "air_knife_u", "L": "air_knife_l", "D": "air_knife_d"} def load(self): super().load() self.user.fast_slide_speed = max(0.3, 0.5*(self.user.speed/2.4)) def update(self): super().update() if not self.istriggered and self.enough_energy and not self.loaded: sound_player.play("launch") self.user.align_xy() self.user.rooted_for(1200) for x in range(0, 1): for y in range(0, 1): an_effect = EffectInstance("dizzy_explode", self.user, False, level.current_level.effects_front) an_effect.set_xy(self.user.x + x, self.user.y + y) self.effect_instances.append(an_effect) self.istriggered = True if not self.isstart and self.current_time - self.skill_time_init > 500: self.user.sliding_direction = self.user.orientation self.user.slide_for(700) self.effect_instances.append(EffectInstance(self.eff_names[self.user.sliding_direction], self.user, True, self.user.effects_front)) self.isstart = True sound_player.play("explode2") sound_player.play("cry") if self.current_time - self.skill_time_init > 1200: for e in self.effect_instances: e.state = EffectState.DEAD self.user.recal_chasing_monster = True self.kill() if self.loaded: # 耗电判定(3格能量) if self.user.has_energy: if self.user.energy_amount < 3: self.enough_energy = False for e in self.effect_instances: e.state = EffectState.DEAD self.kill() else: self.user.energy_amount -= 3 if self.enough_energy: # npc施法阵与眩晕范围提示 self.loaded = False # 冲刺 class VeryShortRush(Skill): def __init__(self, user, skill_instances): super().__init__(user, None, skill_instances) self.loaded = True self.enough_energy = True self.istriggered = False self.isstart = False self.eff_names = {"R": "air_knife_r", "U": "air_knife_u", "L": "air_knife_l", "D": "air_knife_d"} def load(self): super().load() self.user.fast_slide_speed = max(0.3, 0.5*(self.user.speed/2.4)) def update(self): super().update() if not self.istriggered and self.enough_energy and not self.loaded: sound_player.play("launch") self.user.align_xy() self.user.rooted_for(700) for x in range(0, 1): for y in range(0, 1): an_effect = EffectInstance("dizzy_explode", self.user, False, level.current_level.effects_front) an_effect.set_xy(self.user.x + x, self.user.y + y) self.effect_instances.append(an_effect) self.istriggered = True if not self.isstart and self.current_time - self.skill_time_init > 300: self.user.sliding_direction = self.user.orientation self.user.slide_for(400) self.effect_instances.append(EffectInstance(self.eff_names[self.user.sliding_direction], self.user, True, self.user.effects_front)) self.isstart = True sound_player.play("explode2") sound_player.play("cry") if self.current_time - self.skill_time_init > 700: for e in self.effect_instances: e.state = EffectState.DEAD self.user.recal_chasing_monster = True self.kill() if self.loaded: # 耗电判定(3格能量) if self.user.has_energy: if self.user.energy_amount < 3: self.enough_energy = False for e in self.effect_instances: e.state = EffectState.DEAD self.kill() else: self.user.energy_amount -= 3 if self.enough_energy: # npc施法阵与眩晕范围提示 self.loaded = False class RevengeSmoke7x7D600(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True self.dashing_begin_time = 0 # 起始时刻 self.is_dashing = False # 是否正在 self.dashing_time = 1000 # 持续时间 def update(self): super().update() if self.loaded: self.loaded = False if self.user.remain_blood <= 0: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if self.user.get_damage_frame: self.is_dashing = True self.effect_clear() self.dashing_begin_time = self.current_time sound_player.play("crash") for point in [(-3,0),(-2,0),(-1,0),(0,0),(1,0),(2,0),(3,0),(0,-3),(0,-2),(0,-1),(0,1),(0,2),(0,3)]: target_xy = (self.user.x+point[0], self.user.y+point[1]) an_effect = EffectInstance("poison_explode_once", self.to, False, level.current_level.effects_front) an_effect.set_xy(*target_xy) # 判断击中 if (self.to.x, self.to.y) == target_xy: EffectInstance("dizzy_explode", self.to, True, self.to.effects_behind) self.to.try_damage(600) sound_player.play("cry") if self.current_time - self.dashing_begin_time > self.dashing_time and self.is_dashing: self.is_dashing = False for e in self.effect_instances: e.state = EffectState.DEAD # (10%生命值+100)*3毒(非直接使用的技能) class GotPoisonSmoke10xHP_100x3(Skill): # defuff 毒-3*10%*HP def __init__(self, user, skill_instances): super().__init__(user, None, skill_instances) self.first_hurt = True self.second_hurt = True self.third_hurt = True def update(self): super().update() cl = level.current_level if self.first_hurt: self.first_hurt = False self.effect_instances.append( EffectInstance("red_dots", self.user, True, self.user.effects_front) ) self.user.try_damage(int(cl.me.remain_blood / 10)+100) sound_player.play("cry") if self.current_time - self.skill_time_init > 4000 and self.second_hurt: self.second_hurt = False self.user.try_damage(int(cl.me.remain_blood / 10)+100) sound_player.play("cry") if self.current_time - self.skill_time_init > 8000 and self.third_hurt: self.third_hurt = False self.user.try_damage(int(cl.me.remain_blood / 10)+100) sound_player.play("cry") if self.current_time - self.skill_time_init > 10000: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() # (5%生命值)*5毒(非直接使用的技能) class GotDevilPoisonSmoke5xHPx5(Skill): def __init__(self, user, skill_instances): super().__init__(user, None, skill_instances) self.first_hurt = True self.second_hurt = True self.third_hurt = True self.fourth_hurt = True self.fifth_hurt = True def update(self): super().update() cl = level.current_level if self.first_hurt: self.first_hurt = False self.effect_instances.append(EffectInstance("blue_dots", self.user, True, self.user.effects_front)) sound_player.play("explode2") self.user.try_devil_damage(int(cl.me.remain_blood / 20)) if self.current_time - self.skill_time_init > 1000 and self.second_hurt: self.second_hurt = False self.user.try_devil_damage(int(cl.me.remain_blood / 20)) if self.current_time - self.skill_time_init > 2000 and self.third_hurt: self.third_hurt = False self.user.try_devil_damage(int(cl.me.remain_blood / 20)) if self.current_time - self.skill_time_init > 3000 and self.fourth_hurt: self.fourth_hurt = False self.user.try_devil_damage(int(cl.me.remain_blood / 20)) if self.current_time - self.skill_time_init > 4000 and self.fifth_hurt: self.fifth_hurt = False self.user.try_devil_damage(int(cl.me.remain_blood / 20)) if self.current_time - self.skill_time_init > 5000: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() class RevengePoison1x1(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.dashing_begin_time = 0 # 起始时刻 self.is_dashing = False # 是否正在 self.poison_list = [] def update(self): super().update() if self.current_time - self.skill_time_init > 3000000: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() return if (self.to.x, self.to.y) in self.poison_list: # 踩中毒雾 GotPoisonSmoke10xHP_100x3(self.to, self.to.skill_instances) sound_player.play("explode2") for e in self.effect_instances: if e.x==self.to.x and e.y==self.to.y: e.state = EffectState.DEAD self.poison_list.remove((self.to.x, self.to.y)) if self.user.get_damage_frame and not self.is_dashing: self.is_dashing = True self.poison_list.append((self.user.x,self.user.y)) self.effect_instances.append( EffectInstance("poison_explode", self.user, False, level.current_level.effects_front) ) self.is_dashing = False class MinionChase2sLater(Skill): # 自身跳向玩家2s前所在的格子 def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.to_xy = None self.recording = True self.jumping = True def load(self): super().load() self.user.rooted_for(2000) sound_player.play("launch") self.effect_instances.append(EffectInstance("launch", self.user, False, self.user.effects_behind)) def update(self): super().update() if self.current_time - self.skill_time_init > 2600: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() if self.current_time - self.skill_time_init > 2000 and self.jumping: self.jumping = False try: self.user.throw_to(self.to_xy[0], self.to_xy[1], self.get_directions(), True) except: pass if self.current_time - self.skill_time_init > 0 and self.recording: self.recording = False self.to_xy = (self.to.x, self.to.y) def get_directions(self): user_p = [self.user.x, self.user.y] if user_p[0] == self.to_xy[0]: if user_p[1] > self.to_xy[1]: return "U" else: return "D" if self.to_xy[0] > user_p[0]: return "R" else: return "L" # 每受伤放3x3debuff毒 class DebuffPoisonBlood3x3(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.poison_xy = (self.user.x,self.user.y) def update(self): super().update() if self.user.get_damage_frame: self.poison_xy = (self.user.x,self.user.y) for x in range(-1, 2): for y in range(-1, 2): if (self.poison_xy[0] + x, self.poison_xy[1] + y) not in level.current_level.poison_dic.keys(): an_effect = EffectInstance("dark_trap", self.user, False, level.current_level.effects_behind) an_effect.set_xy(self.poison_xy[0] + x, self.poison_xy[1] + y) self.effect_instances.append(an_effect) level.current_level.poison_dic[(self.poison_xy[0] + x, self.poison_xy[1] + y)] = (300,3,300,0,an_effect) class LifeLongReverse(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True self.reversing = True self.reverse_effect = None def update(self): super().update() if self.user.remain_blood <= 0: self.reverse_effect.state = EffectState.DEAD self.to.reverse -= 100000 self.to.reverse_begin = 0 self.to.reverse_duration = 0 self.kill() if self.current_time - self.skill_time_init > 1000 and self.reversing: self.reversing = False self.user.rooted -= 1 self.reverse_effect = EffectInstance("reverse_long", self.to, True, self.to.effects_front) self.effect_instances.append(self.reverse_effect) self.to.reverse += 100000 self.to.reverse_begin = pygame.time.get_ticks() self.to.reverse_duration = 1000000000000000000 if self.loaded: self.loaded = False self.user.rooted += 1 self.user.align_xy() self.effect_instances.append( EffectInstance("poison_charge", self.user, True, self.user.effects_front) ) class ClearReverse(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = True def update(self): super().update() if self.loaded: self.loaded = False self.to.reverse = 0 self.to.reverse_begin = 0 self.to.reverse_duration = 0 self.kill() # 毒陷阱 class PoisonTrap1x1DHPx5x5(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.to_already_on = False self.loaded = True def update(self): super().update() if self.current_time - self.skill_time_init > 60000: for e in self.effect_instances: e.state = EffectState.DEAD self.kill() return if not self.loaded: if self.to.x == self.user_x and self.to.y == self.user_y: if not self.to_already_on: GotDevilPoisonSmoke5xHPx5(self.to, self.to.skill_instances) sound_player.play("cry") for e in self.effect_instances: e.state = EffectState.DEAD self.kill() else: self.to_already_on = False if self.loaded: self.loaded = False self.effect_instances.append( EffectInstance("radio_trap", self.user, False, level.current_level.effects_front) ) if self.to.x == self.user_x and self.to.y == self.user_y: self.to_already_on = True # 毒史莱姆专属被动,减速减防回血 class SlowRecoveryWeak(Skill): # 近身自身缓速 def __init__(self, user, to, skill_instances): self.defense_add: int = 0 # 防御增量 self.is_stopdefense = False self.stop_time = 0 self.effect_shield = None # 盾动画 super().__init__(user, to, skill_instances) def load(self): super().load() self.defense_add = -8000 # 计算防御增量 self.user.slime = True def update(self): super().update() if self.user.slow != 0: if not self.is_stopdefense: # 如果当前没有防御 self.stop_time = self.current_time self.is_stopdefense = True self.user.defense += self.defense_add self.effect_shield = EffectInstance("recovery", self.user, True, self.user.effects_front) if self.current_time - self.stop_time>= 500: self.user.heal(100) self.stop_time = self.current_time else: if self.current_time - self.stop_time >= 500: if self.is_stopdefense: # 如果当前在防御 self.is_stopdefense = False self.user.defense -= self.defense_add if self.effect_shield is not None: self.effect_shield.state = EffectState.DEAD # 停止追踪玩家,回到3秒前所在位置,持续2秒 class RunBack(Skill): # 近身自身缓速 def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.back_point = (1,1) self.loaded = False self.chase = False self.end = False def load(self): super().load() def update(self): super().update() if not self.loaded: self.loaded = True self.back_point = (self.user.x, self.user.y) if self.current_time - self.skill_time_init > 3000 and not self.chase: self.chase = True self.user.free_chasing = True self.user.chasing_point = self.back_point if (self.current_time - self.skill_time_init > 5000) and not self.end: self.end = True self.user.free_chasing = False self.kill() # 停止追踪玩家,回到3秒前所在位置,持续1秒 class RunBackShort(Skill): # 近身自身缓速 def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.back_point = (1,1) self.loaded = False self.chase = False self.end = False def load(self): super().load() def update(self): super().update() if not self.loaded: self.loaded = True self.back_point = (self.user.x, self.user.y) if self.current_time - self.skill_time_init > 3000 and not self.chase: self.chase = True self.user.free_chasing = True self.user.chasing_point = self.back_point if (self.current_time - self.skill_time_init > 4000) and not self.end: self.end = True self.user.free_chasing = False self.kill() # 追踪玩家2秒前所在位置,持续1秒 class RunPlayerBack(Skill): # 近身自身缓速 def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.back_point = (1,1) self.loaded = False self.chase = False self.end = False def load(self): super().load() def update(self): super().update() if not self.loaded: self.loaded = True self.back_point = (self.to.x, self.to.y) if self.current_time - self.skill_time_init > 2000 and not self.chase: self.chase = True self.user.free_chasing = True self.user.chasing_point = self.back_point if (self.current_time - self.skill_time_init > 3000) and not self.end: self.end = True self.user.free_chasing = False self.kill() # 有电时进入隐身状态,受到伤害或近身玩家时暂时现身3s class PermanentlyHiddenWithPower(Skill): def __init__(self, user, to, skill_instances): self.alpha = 255 # 不透明度0-255 self.is_hidden = True # True 隐身 / False 恢复 self.show_begin = -32768 # 临时现身 super().__init__(user, to, skill_instances) def load(self): super().load() def update(self): super().update() if self.to.remain_blood <= 0: self.alpha = self.user.temporary_alpha = 255 return if self.user.get_damage_frame: self.show_begin = self.current_time # 判定是否该隐身 if self.user.has_energy: self.is_hidden = (self.current_time - self.show_begin > 3000) and (self.user.energy_amount > 0) # 造成伤害3s内现身 else: self.is_hidden = (self.current_time - self.show_begin > 3000) # 造成伤害3s内现身 if self.is_hidden and self.alpha > 0: self.alpha = max(0, self.alpha - 32) elif not self.is_hidden and self.alpha < 255: self.alpha = min(255, self.alpha + 32) self.user.temporary_alpha = self.alpha # 秒杀玩家 class KillPlayer(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = False def load(self): super().load() def update(self): super().update() if not self.loaded: self.loaded = True self.to.try_damage(10000000000000000000000000000000000) self.kill() # 增加近身 class KillContact(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = False def load(self): super().load() def update(self): super().update() if not self.loaded: self.loaded = True self.user.contact += 1000000000000000000000000000 self.kill() # 和玩家交换位置 class SwapPosition(Skill): def __init__(self, user, to, skill_instances): super().__init__(user, to, skill_instances) self.loaded = False self.pos_m = None self.pos_p = None def load(self): super().load() def update(self): super().update() if not self.loaded: self.loaded = True self.pos_m = (self.user.x, self.user.y) self.pos_p = (self.to.x, self.to.y) self.user.set_xy(self.user.x+1, self.user.y+1) self.to.set_xy(self.pos_m[0], self.pos_m[1]) self.user.set_xy(self.pos_p[0], self.pos_p[1]) level.current_level.scroll_map() self.kill()