|
@@ -1,34 +1,66 @@
|
|
|
-import json
|
|
|
|
|
-import random
|
|
|
|
|
-import os
|
|
|
|
|
import pygame
|
|
import pygame
|
|
|
-
|
|
|
|
|
-from client_local.algo import aStar
|
|
|
|
|
|
|
+import random
|
|
|
from client_local.const import color as C
|
|
from client_local.const import color as C
|
|
|
-from client_local.const import game as G
|
|
|
|
|
-from client_local.frame import bomb, item
|
|
|
|
|
-from client_local.level import level
|
|
|
|
|
-from client_local.sound import sound_player
|
|
|
|
|
-from client_local.sprite.bomb_instance import BombInstance
|
|
|
|
|
-from client_local.sprite.ghost import Ghost
|
|
|
|
|
-from client_local.sprite.hero import Hero
|
|
|
|
|
from client_local.sprite.item_instance import ItemInstance
|
|
from client_local.sprite.item_instance import ItemInstance
|
|
|
from client_local.sprite.player import Player, PlayerState
|
|
from client_local.sprite.player import Player, PlayerState
|
|
|
from client_local.sprite.throwable import Throwable
|
|
from client_local.sprite.throwable import Throwable
|
|
|
|
|
+from client_local.sprite import updatable
|
|
|
|
|
+from client_local.skill.skill import *
|
|
|
from client_local.file_loader.fileLoader import load_json, load_png
|
|
from client_local.file_loader.fileLoader import load_json, load_png
|
|
|
-import logging
|
|
|
|
|
-from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
+pet_name_map = {}
|
|
|
|
|
+for petID in range(1, 125):
|
|
|
|
|
+ pet_name_map[f'pet{petID}'] = {'character': f'pet{petID}'}
|
|
|
|
|
|
|
|
|
|
+pet_name_map_ex = {
|
|
|
|
|
+ '酷比': {'character':'pet1'},
|
|
|
|
|
+ '酷比(大)': {'character':'pet2'},
|
|
|
|
|
+ '米多': {'character':'pet3'},
|
|
|
|
|
+ '米多(大)': {'character':'pet4'},
|
|
|
|
|
+ '恶魔': {'character':'pet5'},
|
|
|
|
|
+ '恶魔(大)': {'character':'pet6'},
|
|
|
|
|
+ '布鲁斯': {'character':'pet7'},
|
|
|
|
|
+ '布鲁斯(大)': {'character':'pet8'},
|
|
|
|
|
+ '小菜娃': {'chs_name':'小菜娃','character':'pet14'},
|
|
|
|
|
+ '龙猫': {'chs_name':'龙猫','character':'pet94'},
|
|
|
|
|
+ '神龙': {'chs_name':'神龙','character':'pet48'},
|
|
|
|
|
+ '流光龙': {'chs_name':'流光龙','character':'pet16'},
|
|
|
|
|
+ '帝黑星': {'chs_name':'帝黑星','character':'pet106'},
|
|
|
|
|
+ '九尾狐(粉)': {'chs_name':'九尾狐','character':'pet112'},
|
|
|
|
|
+ '九尾狐(蓝)': {'chs_name':'九尾狐','character':'pet113'},
|
|
|
|
|
+ '彩雀': {'chs_name':'彩雀','character':'pet63'},
|
|
|
|
|
+ '彩雀(大)': {'chs_name': '彩雀', 'character': 'pet64'},
|
|
|
|
|
+ '嫦娥': {'chs_name':'嫦娥','character':'pet61'},
|
|
|
|
|
+ '嫦娥玉兔': {'chs_name':'嫦娥玉兔','character':'pet62'},
|
|
|
|
|
+ '树苗': {'chs_name':'树苗','character':'pet103'},
|
|
|
|
|
+ '大树': {'chs_name':'大树','character':'pet104'},
|
|
|
|
|
+ '乖乖虎': {'chs_name':'乖乖虎','character':'pet70'},
|
|
|
|
|
+ '新年兔子': {'chs_name':'新年兔子','character':'pet92'},
|
|
|
|
|
+ '哆来咪海豚': {'chs_name':'哆来咪海豚','character':'pet108'},
|
|
|
|
|
+ '小萝莉': {'chs_name':'小萝莉','character':'pet79'},
|
|
|
|
|
+ '小萝莉(大)': {'chs_name':'小萝莉','character':'pet80'},
|
|
|
|
|
+ '暗夜使者': {'chs_name':'暗夜使者','character':'pet58b'},
|
|
|
|
|
+ '飞骷髅': {'chs_name':'飞骷髅','character':'pet77'},
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+for pet_name in pet_name_map_ex:
|
|
|
|
|
+ petID = pet_name_map_ex[pet_name]['character']
|
|
|
|
|
+ if petID in pet_name_map:
|
|
|
|
|
+ pet_name_map.pop(petID)
|
|
|
|
|
+pet_name_map_ex.update(pet_name_map) # 合并两个字典
|
|
|
|
|
+pet_name_map = pet_name_map_ex # 使用合并后的字典
|
|
|
|
|
|
|
|
|
|
|
|
|
class Pet(Player, Throwable):
|
|
class Pet(Player, Throwable):
|
|
|
|
|
|
|
|
- def __init__(self, npc_name, xy, color=C.CHARACTER_RED):
|
|
|
|
|
- super(Pet, self).__init__(npc_name, xy, color)
|
|
|
|
|
|
|
+ def __init__(self, pet_name, xy, color=C.CHARACTER_RED, owner=None, num=1):
|
|
|
|
|
+ super(Pet, self).__init__(pet_name, xy, color)
|
|
|
|
|
+ from client_local.sprite.hero import Hero
|
|
|
|
|
+ self.npc_time_init = None
|
|
|
|
|
+ self.owner: Hero = owner
|
|
|
self.npc_json = None
|
|
self.npc_json = None
|
|
|
self.chs_name = None # Npc中文名
|
|
self.chs_name = None # Npc中文名
|
|
|
- self.stats_name = npc_name
|
|
|
|
|
|
|
+ self.pet_name = pet_name
|
|
|
self.idx_motion = {0: "R", 1: "U", 2: "L", 3: "D"}
|
|
self.idx_motion = {0: "R", 1: "U", 2: "L", 3: "D"}
|
|
|
self.contact = 0 # Npc接触伤害
|
|
self.contact = 0 # Npc接触伤害
|
|
|
self.resent_dist = None # Npc仇恨范围(几格以内)
|
|
self.resent_dist = None # Npc仇恨范围(几格以内)
|
|
@@ -36,180 +68,231 @@ class Pet(Player, Throwable):
|
|
|
self.mocking = False # Npc受到嘲笑药水的作用暂时仇恨
|
|
self.mocking = False # Npc受到嘲笑药水的作用暂时仇恨
|
|
|
self.friendly = False # Npc受到玫瑰药水的作用暂时解除仇恨
|
|
self.friendly = False # Npc受到玫瑰药水的作用暂时解除仇恨
|
|
|
self.refresh = 0
|
|
self.refresh = 0
|
|
|
-
|
|
|
|
|
- self.is_ghost = True # 幽灵模式
|
|
|
|
|
- self.fake_blood = 0
|
|
|
|
|
- self.energy_amount = 0 # 充能格数
|
|
|
|
|
- self.max_energy_amount = 0
|
|
|
|
|
- self.has_energy = False
|
|
|
|
|
self.wall_walking = True # 穿墙
|
|
self.wall_walking = True # 穿墙
|
|
|
- self.flying = True # 飞行(免疫墙体减速)
|
|
|
|
|
- self.sliding = False # 踩技能滑行中
|
|
|
|
|
- self.sliding_direction = None # 踩技能后滑的方向
|
|
|
|
|
- self.witch_protected_remove = False # 巫师无防护状态
|
|
|
|
|
- self.fire_load_time = 0
|
|
|
|
|
- self.slime = False
|
|
|
|
|
- self.last_in_water = 0
|
|
|
|
|
- self.slime_time = 0
|
|
|
|
|
- self.free_chasing = False
|
|
|
|
|
- self.chasing_point = (1,1)
|
|
|
|
|
- self.imitating = False
|
|
|
|
|
- self.combo_num = 1
|
|
|
|
|
- self.is_combo_target = False
|
|
|
|
|
- self.bomb_shield_num = 0 # 防糖泡电磁护盾
|
|
|
|
|
- self.bomb_shield_protect = False
|
|
|
|
|
- self.is_target = False
|
|
|
|
|
- self.light = 0 # 鬼屋模式发光大小 0不发光,1发光20像素,2发光40像素 最大9
|
|
|
|
|
- self.sharing_damage = False
|
|
|
|
|
-
|
|
|
|
|
- self.obstacle_can_push = False
|
|
|
|
|
- self.npc_time_init = None # Npc初始化时刻
|
|
|
|
|
- self.wander_random = 10 # Npc在无仇恨时的闲逛时间
|
|
|
|
|
- self.district_locked = True
|
|
|
|
|
- self.chase_path = None # Npc追踪路径
|
|
|
|
|
- self.npc_skill_time = pygame.time.get_ticks() # npc施放技能时的时刻 设为成员变量是为了统一多个技能的时间
|
|
|
|
|
- self.chs_name_bg = load_png("res/img/ui/game/misc172.png") # Npc姓名牌背景
|
|
|
|
|
- self.blood_bar = None
|
|
|
|
|
- self.blood_bar_pos = 0
|
|
|
|
|
- self.profile = None
|
|
|
|
|
- self.chain = False
|
|
|
|
|
- self.chase_rad = 2
|
|
|
|
|
-
|
|
|
|
|
- self.chs_name_font = pygame.font.Font("res/font/simsun.ttc", 13) # Npc姓名牌字体
|
|
|
|
|
- self.chs_name_text = None # Npc姓名牌前景文字
|
|
|
|
|
- self.chs_name_text_shadow = None # Npc姓名牌背景文字
|
|
|
|
|
- self.chs_name_text_half_width = None # Npc姓名牌文字的半宽 用于居中显示文字
|
|
|
|
|
- self.chs_name_show = True # 是否显示名牌
|
|
|
|
|
- self.bomb_skin = bomb.get_bomb("bomb1")
|
|
|
|
|
- self.gifts = None # 爆装备
|
|
|
|
|
- self.death = None # 死亡状态
|
|
|
|
|
- self.last_motion = 0
|
|
|
|
|
- self.last_random = 10
|
|
|
|
|
- self.energy_num = None
|
|
|
|
|
- self.load_npc(npc_name, color)
|
|
|
|
|
-
|
|
|
|
|
- def load_npc(self, npc_name, color):
|
|
|
|
|
- # 加载npc的json文件
|
|
|
|
|
- self.npc_json = load_json("game/pet/" + npc_name + ".json")
|
|
|
|
|
- self.chs_name = self.npc_json["chs_name"]
|
|
|
|
|
- self.blood = self.npc_json["blood"]
|
|
|
|
|
- self.light = self.npc_json.get("light",self.light)
|
|
|
|
|
- if "self_damage_blood" in self.npc_json.keys():
|
|
|
|
|
- self.self_damage_blood = self.npc_json["self_damage_blood"]
|
|
|
|
|
- self.speed = (max(2.5, self.npc_json["speed"]) * G.GAME_SQUARE) / 1000
|
|
|
|
|
- self.contact = self.npc_json["contact"]
|
|
|
|
|
- self.defense = self.npc_json["defense"]
|
|
|
|
|
-
|
|
|
|
|
- if "slime" in self.npc_json.keys():
|
|
|
|
|
- self.slime = self.npc_json["slime"]
|
|
|
|
|
- if "gifts" in self.npc_json.keys():
|
|
|
|
|
- self.gifts = self.npc_json["gifts"]
|
|
|
|
|
- if "death" in self.npc_json.keys():
|
|
|
|
|
- self.death = self.npc_json["death"]
|
|
|
|
|
- if "show_name" in self.npc_json.keys():
|
|
|
|
|
- self.chs_name_show = self.npc_json["show_name"]
|
|
|
|
|
- if "light" in self.npc_json.keys():
|
|
|
|
|
- self.light = self.npc_json["light"]
|
|
|
|
|
- if "chain" in self.npc_json.keys():
|
|
|
|
|
- self.chain = self.npc_json["chain"]
|
|
|
|
|
- if "chase_rad" in self.npc_json.keys():
|
|
|
|
|
- self.chase_rad = self.npc_json["chase_rad"]
|
|
|
|
|
-
|
|
|
|
|
- self.resent_dist = self.npc_json["resent_dist"] * G.GAME_SQUARE # 仇恨距离(像素)
|
|
|
|
|
- for n, s in enumerate(self.npc_json["skills"]):
|
|
|
|
|
- self.skill_names.append(s["name"])
|
|
|
|
|
- self.skill_init_times.append(s["init"])
|
|
|
|
|
- self.skill_intervals.append(s["interval"])
|
|
|
|
|
- self.skill_remains.append(s["max"])
|
|
|
|
|
- self.skill_params.append(s["params"] if "params" in s else [])
|
|
|
|
|
- self.skill_params_order.append(n)
|
|
|
|
|
- self.skill_spawns.append(s["spawns"] if "spawns" in s else [])
|
|
|
|
|
- self.skill_spawn_order.append(s["spawn_order"] if "spawn_order" in s else n)
|
|
|
|
|
-
|
|
|
|
|
- self.remain_blood = self.blood
|
|
|
|
|
- self.chase_path = dict()
|
|
|
|
|
- self.chs_name_text = self.chs_name_font.render(self.chs_name, True, (255, 128, 192))
|
|
|
|
|
- self.chs_name_text_shadow = self.chs_name_font.render(self.chs_name, True, (0, 0, 0))
|
|
|
|
|
- self.chs_name_text_half_width = self.chs_name_text.get_width() // 2
|
|
|
|
|
- self.character = self.load_character(self.npc_json["character"], color, dict())
|
|
|
|
|
- self.npc_time_init = pygame.time.get_ticks()
|
|
|
|
|
|
|
+ self.force_moving = False # 联机强制移动
|
|
|
|
|
+ self.force_move_init_time = 0 # 联机强制移动开始时间
|
|
|
|
|
+ self.force_move_pos = (0, 0) # 联机强制移动目标位置
|
|
|
|
|
+ self.force_move_duration = 0 # 联机强制移动持续时间
|
|
|
|
|
+ self.force_move_init_xy_pos = (0, 0) # 联机强制移动开始位置
|
|
|
|
|
+ self.light = 1 # 鬼屋模式发光大小 0不发光,1发光20像素,2发光40像素 最大9
|
|
|
|
|
+ if owner is not None:
|
|
|
|
|
+ self.x_pos = owner.x_pos
|
|
|
|
|
+ self.y_pos = owner.y_pos
|
|
|
|
|
+ self.random_move()
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.x_pos = xy[0] * 40 + 20
|
|
|
|
|
+ self.y_pos = xy[1] * 40 + 20
|
|
|
|
|
+ self.force_move_pos = (self.x_pos, self.y_pos)
|
|
|
|
|
+ self.load_pet(pet_name, color)
|
|
|
|
|
+ self.create_time = pygame.time.get_ticks()
|
|
|
|
|
+ if num > 1:
|
|
|
|
|
+ self.petObj = Pet(self.pet_name, xy, color, owner=self, num=num-1)
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.petObj = None
|
|
|
|
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
|
|
+ return f'PET {self.chs_name}'
|
|
|
|
|
|
|
|
- def update(self):
|
|
|
|
|
- super().update()
|
|
|
|
|
- current_time = pygame.time.get_ticks()
|
|
|
|
|
- # self.update_npc_blood_display(current_time)
|
|
|
|
|
- self.chase_hero()
|
|
|
|
|
- # self.try_using_skills()
|
|
|
|
|
|
|
+ def __str__(self):
|
|
|
|
|
+ return f'PET {self.chs_name}'
|
|
|
|
|
|
|
|
- def update_npc_blood_display(self, current_time):
|
|
|
|
|
- if G.DISPLAY_NPC_NAME_CARD and G.DISPLAY_NPC_BLOOD:
|
|
|
|
|
- self.chs_name_text = self.chs_name_font.render(str(self.remain_blood-self.fake_blood), True, (255, 128, 192))
|
|
|
|
|
- self.chs_name_text_shadow = self.chs_name_font.render(str(self.remain_blood-self.fake_blood), True, (0, 0, 0))
|
|
|
|
|
- self.chs_name_text_half_width = self.chs_name_text.get_width() // 2
|
|
|
|
|
|
|
+ def update_orientation_online(self, orientation):
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ def add_one(self):
|
|
|
|
|
+ if self.petObj:
|
|
|
|
|
+ self.petObj.add_one()
|
|
|
else:
|
|
else:
|
|
|
- self.chs_name_text = self.chs_name_font.render(self.chs_name, True, (255, 128, 192))
|
|
|
|
|
- self.chs_name_text_shadow = self.chs_name_font.render(self.chs_name, True, (0, 0, 0))
|
|
|
|
|
- self.chs_name_text_half_width = self.chs_name_text.get_width() // 2
|
|
|
|
|
-
|
|
|
|
|
- def chase_hero(self):
|
|
|
|
|
- me = (level.current_level.me.x, level.current_level.me.y)
|
|
|
|
|
- if abs(self.x - me[0]) + abs(self.y - me[1]) <= self.chase_rad:
|
|
|
|
|
- self.set_motion()
|
|
|
|
|
|
|
+ self.petObj = Pet(self.pet_name, (self.x, self.y), self.color, owner=self)
|
|
|
|
|
+
|
|
|
|
|
+ def set_num(self, num=5):
|
|
|
|
|
+ current_num = self.get_num()
|
|
|
|
|
+ if current_num < num:
|
|
|
|
|
+ for i in range(num-current_num):
|
|
|
|
|
+ self.add_one()
|
|
|
|
|
+ elif current_num > num:
|
|
|
|
|
+ petObj = self
|
|
|
|
|
+ for i in range(num-1):
|
|
|
|
|
+ petObj = petObj.petObj
|
|
|
|
|
+ petObj.petObj = None
|
|
|
|
|
+
|
|
|
|
|
+ def get_num(self):
|
|
|
|
|
+ if self.petObj:
|
|
|
|
|
+ return 1 + self.petObj.get_num()
|
|
|
|
|
+ else:
|
|
|
|
|
+ return 1
|
|
|
|
|
+
|
|
|
|
|
+ def load_pet(self, pet_name, color):
|
|
|
|
|
+ # 加载npc的json文件
|
|
|
|
|
+ try:
|
|
|
|
|
+ self.blood = 1000
|
|
|
|
|
+ self.remain_blood = self.blood
|
|
|
|
|
+ character_name = pet_name_map.get(pet_name, {}).get('character', pet_name)
|
|
|
|
|
+ self.chs_name = pet_name
|
|
|
|
|
+ self.character = self.load_character(character_name, color, dict())
|
|
|
|
|
+ self.npc_time_init = pygame.time.get_ticks()
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ print(e)
|
|
|
|
|
+
|
|
|
|
|
+ def random_move(self):
|
|
|
|
|
+ if self.owner is None:
|
|
|
|
|
+ return
|
|
|
|
|
+ if self.owner.state == PlayerState.LOSE:
|
|
|
|
|
+ return
|
|
|
|
|
+ new_x = self.owner.x_pos + random.randint(-20, 20)
|
|
|
|
|
+ new_y = self.owner.y_pos + random.randint(-20, 20)
|
|
|
|
|
+ if self.owner.walking:
|
|
|
|
|
+ if self.owner.orientation == 'D':
|
|
|
|
|
+ new_y -= 20
|
|
|
|
|
+ elif self.owner.orientation == 'U':
|
|
|
|
|
+ new_y += 20
|
|
|
|
|
+ elif self.owner.orientation == 'L':
|
|
|
|
|
+ new_x += 20
|
|
|
|
|
+ elif self.owner.orientation == 'R':
|
|
|
|
|
+ new_x -= 20
|
|
|
|
|
+
|
|
|
|
|
+ delta_x = new_x - self.x_pos
|
|
|
|
|
+ delta_y = new_y - self.y_pos
|
|
|
|
|
+ # 根据delta设定移动方向 LDRU
|
|
|
|
|
+ if abs(delta_x) > abs(delta_y):
|
|
|
|
|
+ if delta_x > 0:
|
|
|
|
|
+ self.orientation = 'R'
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.orientation = 'L'
|
|
|
|
|
+ else:
|
|
|
|
|
+ if delta_y > 0:
|
|
|
|
|
+ self.orientation = 'D'
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.orientation = 'U'
|
|
|
|
|
+ self.set_motion(self.orientation)
|
|
|
|
|
+
|
|
|
|
|
+ self.move_to(new_x, new_y, duration=300)
|
|
|
|
|
+
|
|
|
|
|
+ def move_to(self, x_pos, y_pos, duration=None):
|
|
|
|
|
+ # 强制移动到指定位置, duration为持续时间(ms)
|
|
|
|
|
+ self.force_movement() # 先处理强制移动
|
|
|
|
|
+ if self.force_move_pos == (x_pos, y_pos):
|
|
|
|
|
+ # 未改变目标位置
|
|
|
|
|
+ if not self.force_moving:
|
|
|
|
|
+ self.force_moving = True
|
|
|
|
|
+ return
|
|
|
|
|
+ self.force_moving = True
|
|
|
|
|
+ self.force_move_init_time = pygame.time.get_ticks()
|
|
|
|
|
+ self.force_move_duration = duration
|
|
|
|
|
+ self.force_move_init_xy_pos = (self.x_pos, self.y_pos)
|
|
|
|
|
+ self.force_move_pos = (x_pos, y_pos)
|
|
|
|
|
+
|
|
|
|
|
+ def force_movement(self):
|
|
|
|
|
+ if not self.force_moving:
|
|
|
|
|
+ return
|
|
|
|
|
+ current_time = pygame.time.get_ticks()
|
|
|
|
|
+ if current_time - self.force_move_init_time > self.force_move_duration:
|
|
|
|
|
+ self.force_moving = False
|
|
|
|
|
+ self.x_pos, self.y_pos = self.force_move_pos
|
|
|
|
|
+ self.x, self.y = updatable.current_grid(self.x_pos, self.y_pos)
|
|
|
return
|
|
return
|
|
|
- now = (self.x, self.y)
|
|
|
|
|
- # 追踪玩家
|
|
|
|
|
- self.chase_path = aStar.cal_path(
|
|
|
|
|
- now, me,
|
|
|
|
|
- (level.current_level.district_square_grid["x1"], level.current_level.district_square_grid["y1"]),
|
|
|
|
|
- (level.current_level.district_square_grid["x2"], level.current_level.district_square_grid["y2"]),
|
|
|
|
|
- is_ghost=self.is_ghost
|
|
|
|
|
- )
|
|
|
|
|
- if now in self.chase_path.keys():
|
|
|
|
|
- next = self.chase_path[now]
|
|
|
|
|
- if next is None:
|
|
|
|
|
- self.set_motion()
|
|
|
|
|
- elif next[0] > self.x:
|
|
|
|
|
- self.set_motion("R")
|
|
|
|
|
- elif next[1] < self.y:
|
|
|
|
|
- self.set_motion("U")
|
|
|
|
|
- elif next[0] < self.x:
|
|
|
|
|
- self.set_motion("L")
|
|
|
|
|
- elif next[1] > self.y:
|
|
|
|
|
- self.set_motion("D")
|
|
|
|
|
else:
|
|
else:
|
|
|
- self.set_motion()
|
|
|
|
|
|
|
+ # 计算距离
|
|
|
|
|
+ x1, y1 = self.force_move_init_xy_pos
|
|
|
|
|
+ x2, y2 = self.force_move_pos
|
|
|
|
|
+ dx = x2-x1
|
|
|
|
|
+ dy = y2-y1
|
|
|
|
|
+ # 计算速度
|
|
|
|
|
+ speed_x = dx/self.force_move_duration
|
|
|
|
|
+ speed_y = dy/self.force_move_duration
|
|
|
|
|
+ # 计算当前位置
|
|
|
|
|
+ self.x_pos = x1+speed_x*(current_time-self.force_move_init_time)
|
|
|
|
|
+ self.y_pos = y1+speed_y*(current_time-self.force_move_init_time)
|
|
|
|
|
+ self.x, self.y = updatable.current_grid(self.x_pos, self.y_pos)
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ def update(self):
|
|
|
|
|
+ try:
|
|
|
|
|
+ from client_local.level.level import current_level
|
|
|
|
|
+ if self.owner is not None:
|
|
|
|
|
+ x_pos, y_pos = self.force_move_pos
|
|
|
|
|
+ dist_to_owner = abs(x_pos - self.owner.x_pos) + abs(y_pos - self.owner.y_pos)
|
|
|
|
|
+ import random
|
|
|
|
|
+ if dist_to_owner > 60:
|
|
|
|
|
+ self.random_move()
|
|
|
|
|
+ self.temporary_alpha = self.owner.temporary_alpha
|
|
|
|
|
+ if self.force_moving:
|
|
|
|
|
+ self.walking = True
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.walking = False
|
|
|
|
|
+
|
|
|
|
|
+ # 检查的是否在砖块里
|
|
|
|
|
+ xy = self.x, self.y
|
|
|
|
|
+ if current_level is not None and current_level.obstacle_instances.get(xy):
|
|
|
|
|
+ self.temporary_alpha = min(128, self.temporary_alpha) # 砖块内透明度为128
|
|
|
|
|
+
|
|
|
|
|
+ current_time = pygame.time.get_ticks()
|
|
|
|
|
+ if self.state == PlayerState.NORMAL:
|
|
|
|
|
+ self.update_footprints(current_time)
|
|
|
|
|
+ self.stimulate_x_y_changed_trigger()
|
|
|
|
|
+ self.update_frame(current_time)
|
|
|
|
|
+ self.force_movement() # 处理强制移动
|
|
|
|
|
+ self.if_obstacle_trigger()
|
|
|
|
|
+
|
|
|
|
|
+ if self.state == PlayerState.LOSE:
|
|
|
|
|
+ self.update_frame_dead(current_time)
|
|
|
|
|
+ self.update_skills()
|
|
|
|
|
+ self.update_effects()
|
|
|
|
|
+ self.get_damage_frame = False # 复原伤害帧
|
|
|
|
|
+ self.get_damage_amount = 0
|
|
|
|
|
+ self.grid_damage(current_time)
|
|
|
|
|
+ self.stimulate_character_frame_trigger()
|
|
|
|
|
+ self.update_time_old = current_time
|
|
|
|
|
+ if self.petObj:
|
|
|
|
|
+ current_level.pets.append(self.petObj)
|
|
|
|
|
+ self.petObj.update()
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ print(e)
|
|
|
|
|
+
|
|
|
|
|
+ def update_npc_blood_display(self, current_time):
|
|
|
|
|
+ return
|
|
|
|
|
|
|
|
def half_body_damage(self, point, cl, current_time):
|
|
def half_body_damage(self, point, cl, current_time):
|
|
|
- self.try_damage(cl.grid_damage_blood[point])
|
|
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ def contact_damage(self):
|
|
|
|
|
+ return
|
|
|
|
|
|
|
|
def die(self):
|
|
def die(self):
|
|
|
- super().die()
|
|
|
|
|
- sound_player.play("npc_dead")
|
|
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ def gene_gifts(self):
|
|
|
|
|
+ return # 客户端不控制掉落
|
|
|
|
|
+
|
|
|
|
|
+ def gene_ghost(self):
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ def collide_wall(self):
|
|
|
|
|
+ return
|
|
|
|
|
|
|
|
def try_push(self, direction, offset=(0, 0)):
|
|
def try_push(self, direction, offset=(0, 0)):
|
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
def try_using_skills(self):
|
|
def try_using_skills(self):
|
|
|
- pass
|
|
|
|
|
|
|
+ return
|
|
|
|
|
|
|
|
- def use_skill(self, idx: int):
|
|
|
|
|
- cl = level.current_level
|
|
|
|
|
- if self.npc_skill_time < self.skill_init_times[idx] or self.skill_remains[idx] == 0:
|
|
|
|
|
- # 未到初始时间 或技能冷却中 或次数已用完(-1则可以无限使用)
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ def use_skill(self, idx: int, fake=False):
|
|
|
|
|
+ return True
|
|
|
|
|
+
|
|
|
|
|
+ def set_bomb(self):
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ def set_general_bomb(self, power, damage):
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ def set_custom_bomb(self, x, y, power, damage):
|
|
|
|
|
+ return
|
|
|
|
|
|
|
|
def set_restoration(self, to_x, to_y):
|
|
def set_restoration(self, to_x, to_y):
|
|
|
self.x = to_x
|
|
self.x = to_x
|
|
|
self.y = to_y
|
|
self.y = to_y
|
|
|
|
|
|
|
|
def draw(self, screen: pygame.Surface):
|
|
def draw(self, screen: pygame.Surface):
|
|
|
- super().draw(screen)
|
|
|
|
|
- if G.DISPLAY_NPC_NAME_CARD and self.chs_name_show:
|
|
|
|
|
- self.chs_name_text_shadow.set_alpha(self.temporary_alpha)
|
|
|
|
|
- screen.blit(self.chs_name_text_shadow, (self.x_pos + 3 - self.chs_name_text_half_width, self.y_pos - 75))
|
|
|
|
|
- self.chs_name_text.set_alpha(self.temporary_alpha)
|
|
|
|
|
- screen.blit(self.chs_name_text, (self.x_pos + 2 - self.chs_name_text_half_width, self.y_pos - 75))
|
|
|
|
|
- if self.chain:
|
|
|
|
|
- pygame.draw.line(screen, (155, 155, 155), (level.current_level.me.x_pos, level.current_level.me.y_pos), (self.x_pos, self.y_pos), 1)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ display = super().draw(screen)
|
|
|
|
|
+ # if display and self.temporary_alpha > 200:
|
|
|
|
|
+ # self.speech_bubble.draw(screen)
|