/* 文件名:CharacterObjectClass.nut 路径:User/GameClass/ObjectClass/CharacterObjectClass.nut 创建日期:2024-05-11 21:03 文件用途:角色类 */ class GameObject.Character extends GameObject.ActiveObject { hair = null; //头部 hat = null; //帽子 face = null; //脸部 breast = null; //胸部 coat = null; //上衣 skin = null; //皮肤 waist = null; //腰部 pants = null; //下装 shoes = null; //鞋子 weapon = null; //武器 aurora = null; //光环 //动画对象管理器 AnimationManager = null; //传送阵Flag TransmitFlag = false; //属性对象 Attribute = null; //名字 Name = "无名字"; //职业编号 Job = 0; //cid Cid = -1; //控制器 Controller = null; function _typeof() { return "character"; } function Init(Idx) { //初始化动画组 CurrentAni = []; //设置职业编号 this.Job = Idx; //获取角色职业信息 Info = sq_DeepCopy(AssetManager.CharacterInfoList[Idx]); base.Init(Info); //构造角色动画对象 AnimationManager = Character_Animation(); Addchild(AnimationManager); AnimationManager.Init(); foreach(EquId in Info.default_avatar) { local EquObj = GameItem.Equipment(EquId); ChangeEquipment(EquObj); } //构造属性对象 // Attribute = AttributeClass(); //分配控制器 Controller = Object_Controller(this); } function SyncObjectBox() { //同步受击框 和 攻击框 DamageBox = null; AttackBox = null; //皮肤同步受击框 武器同步攻击框 foreach(AniObj in CurrentAni) { if (AniObj.Type == "skin") { local Info = AniObj.GetCurrentFrameInfo(); if (Info.DamageBox.len() > 0) { DamageBox = []; foreach(Box in Info.DamageBox) { local NewBox = [Box[0] + X, Box[1] + Y, Box[2] + Z, Box[3] + X, Box[4] + Y, Box[5] + Z]; DamageBox.append(NewBox); } } } else if (AniObj.Type == "weapon") { local Info = AniObj.GetCurrentFrameInfo(); if (Info.AttackBox.len() > 0) { AttackBox = []; foreach(Box in Info.AttackBox) { local NewBox = [Box[0] + X, Box[1] + Y, Box[2] + Z, Box[3] + X, Box[4] + Y, Box[5] + Z]; AttackBox.append(NewBox); } } } } } // function OnUpdate(dt) { // //原始逻辑 // base.OnUpdate(dt); // } //设置Ani function SetAnimation(Ani) { //如果存在动画管理器则设置 if (AnimationManager) AnimationManager.SetAnimation(Ani); } //切换装备 function ChangeEquipment(Equ) { //如果当前装备槽已经有装备则移除 if (this[Equ.SlotType]) { this[Equ.SlotType].OnWearEnd(); this[Equ.SlotType] = null; } //将装备对象赋值给对应装备槽 this[Equ.SlotType] = Equ; this[Equ.SlotType].OnWearStart(); //如果是武器或者时装则同步动画 if (Equ.SlotType == "weapon" || Equ.Type == "avatar") { AnimationManager.Init(Equ.SlotType); } else if (Equ.Type == "aurora") { AnimationManager.InitAuroa(); } } //切换装备列表 function ChangeEquipmentList(EquList) { foreach(Equ in EquList) { ChangeEquipment(Equ); } } //设置名字 function SetName(Name) { this.Name = Name; AnimationManager.SetName(Name); base.SetName(Name); } //移动速度 Move_Speed = 500; //移动逻辑 function Move(Dt, X, Y) { if (!Parent) return; //在城镇里 if (typeof Parent == "townmap") { if (X == 0 && Y == 0) { //设置回站立动画 if (AnimationManager.CurrentAni != AnimationManager.RestAni) { AnimationManager.SetAnimation("RestAni"); } } else { //设置移动动画 if (AnimationManager.CurrentAni != AnimationManager.MoveAni) { AnimationManager.SetAnimation("MoveAni"); } //设置人物朝向 if (X > 0) SetDirection(DIRECTION.RIGHT); else if (X< 0) SetDirection(DIRECTION.LEFT); MoveBy(Dt * X * Move_Speed * 0.001, Dt * Y * Move_Speed * 0.001 * 0.71, 0); } } } //更新 function OnUpdate(Dt) { base.OnUpdate(Dt); //控制器逻辑更新 Controller.OnUpdate(Dt); } } //通过职业和装备列表来构造一个角色 GameObject.CreateCharacter <- function(Job = 0, EquIdList = []) { //构造角色 local Character = GameObject.Character(); Character.Init(Job); foreach(EquId in EquIdList) { if (EquId > 0) { local EquObj = GameItem.Equipment(EquId); Character.ChangeEquipment(EquObj); } } return Character; }