From 01ae0de6f30d475490eefd2cb854e60ad846e947 Mon Sep 17 00:00:00 2001 From: Lenheart <947330670@qq.com> Date: Fri, 13 Dec 2024 20:48:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=20GameObject=20=20=E6=96=B0=E5=A2=9E=20Chara?= =?UTF-8?q?cterObject=20=E6=9B=B4=E6=8D=A2=E6=97=B6=E8=A3=85=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Object/ActiveObject/ActiveObjectClass.nut | 3 +- .../ActiveObject/CharacterObjectClass.nut | 292 +++--------------- .../ActiveObject/CharacterObjectClass_AI.nut | 2 +- .../ActiveObject/MonsterObjectClass.nut | 2 +- .../ActiveObject/PassiveObjectClass.nut | 2 +- .../Object/ActiveObject/StaticObjectClass.nut | 2 +- 6 files changed, 44 insertions(+), 259 deletions(-) diff --git a/sqr/User/Object/ActiveObject/ActiveObjectClass.nut b/sqr/User/Object/ActiveObject/ActiveObjectClass.nut index fa525ef..4bdb39b 100644 --- a/sqr/User/Object/ActiveObject/ActiveObjectClass.nut +++ b/sqr/User/Object/ActiveObject/ActiveObjectClass.nut @@ -4,7 +4,8 @@ 创建日期:2024-11-29 23:05 文件用途:动态Obj对象 */ -class ActiveObject extends BaseObject { + +class GameObject.ActiveObject extends GameObject.BaseClass { diff --git a/sqr/User/Object/ActiveObject/CharacterObjectClass.nut b/sqr/User/Object/ActiveObject/CharacterObjectClass.nut index 4111162..4e62120 100644 --- a/sqr/User/Object/ActiveObject/CharacterObjectClass.nut +++ b/sqr/User/Object/ActiveObject/CharacterObjectClass.nut @@ -4,60 +4,21 @@ 创建日期:2024-05-11 21:03 文件用途:角色类 */ -class Character extends ActiveObject { +class GameObject.Character extends GameObject.ActiveObject { hair = null; //头部 - cap = null; //帽子 + hat = null; //帽子 face = null; //脸部 - neck = null; //胸部 + breast = null; //胸部 coat = null; //上衣 skin = null; //皮肤 - belt = null; //腰部 + waist = null; //腰部 pants = null; //下装 shoes = null; //鞋子 weapon = null; //武器 - //当前动画组 - CurrentAni = null; - - //等待Ani - WaitingAni = null; - //移动Ani - MoveAni = null; - //蹲下Ani - SitAni = null; - //受伤Ani - DamageAni1 = null; - DamageAni2 = null; - //倒地Ani - DownAni = null; - //被击后退Ani - OverturnAni = null; - //跳跃Ani - JumoAni = null; - //跳跃攻击Ani - JumpAttackAni = null; - //站立Ani - RestAni = null; - //引导Ani - ThrowAni1_1 = null; - ThrowAni1_2 = null; - ThrowAni2_1 = null; - ThrowAni2_2 = null; - ThrowAni3_1 = null; - ThrowAni3_2 = null; - ThrowAni4_1 = null; - ThrowAni4_2 = null; - //奔跑Ani - DashAni = null; - //奔跑攻击Ani - DashAttackAni = null; - //拾取Ani - GetItemAni = null; - //释放BUFFAni - BuffAni = null; - //普通攻击Ani - AttackAni = null; + //动画对象管理器 + AnimationManager = null; //属性对象 Attribute = null; @@ -70,9 +31,10 @@ class Character extends ActiveObject { Info = sq_DeepCopy(AssetManager.CharacterInfoList[Idx]); base.Init(Info); - - //初始化基础Ani - InitBaseAni(); + //构造角色动画对象 + AnimationManager = Character_Animation(); + Addchild(AnimationManager); + AnimationManager.Init(); //构造属性对象 // Attribute = AttributeClass(); @@ -115,221 +77,43 @@ class Character extends ActiveObject { //设置Ani function SetAnimation(Ani) { - //因为是Ani组所以要foreach调用 - //如果已经有Ani了 - if (CurrentAni) { - foreach(AniObj in CurrentAni) { - Removechild(AniObj); - } - } - if (type(Ani) == "integer") { - //TODO 进阶ANI - } else { - CurrentAni = Ani; - } - //重置Ani 并添加子对象 - foreach(AniObj in CurrentAni) { - AniObj.Reset(); - Addchild(AniObj); - } + //如果存在动画管理器则设置 + if (AnimationManager) AnimationManager.SetAnimation(Ani); } - function FormatAvatarAniImgPath(AniInfo, FormatValue1, FormatValue2) { - for (local i = 0; i< AniInfo.Frame.len(); i++) { - AniInfo.Frame[i].Img_Path = format(AniInfo.Frame[i].Img_Path, FormatValue1, FormatValue2); + //切换装备 + function ChangeEquipment(Equ) { + //如果当前装备槽已经有装备则移除 + if (this[Equ.SlotType]) { + this[Equ.SlotType].OnWearEnd(); + this[Equ.SlotType] = null; } - return AniInfo; - } + //将装备对象赋值给对应装备槽 + this[Equ.SlotType] = Equ; + this[Equ.SlotType].OnWearStart(); - function ReadAndSetAni(AniObj, Src) { - //如果有这个标签Ani则初始化 - if (Info.rawin(Src)) Src = Info[Src]; - else return; - - //如果Ani组不存在就初始化数组 - if (this[AniObj] == null) this[AniObj] = []; - - - foreach(Type in getconsttable().AvatarType) { - //如果有时装就初始化Ani - //除了皮肤 在没有的情况下初始化0 - if (Type == "skin") { - local SkinAni; - if (this[Type] == null) { - local BufInfo = sq_DeepCopy(ScriptData.GetAni(Src)); - local Ao = { - ImgVariation = [0, 0], - ImgFormat = function(ImgPath) { - if (ImgVariation[0] > 0) { - local Pos = ImgPath.find("%04d"); - ImgPath = ImgPath.slice(0, Pos) + "%02d%02d" + ImgPath.slice(Pos + 4); - return format(ImgPath, ImgVariation[0], ImgVariation[1]); - } else { - return format(ImgPath, ImgVariation[1]); - } - } - } - SkinAni = Animation(BufInfo, Ao); - } else { - local AvaInfo = AssetManager.GetEquipment(this[Type]); - local JobInfo = AvaInfo["Ani_" + Info["job"]]; - local BufInfo = sq_DeepCopy(ScriptData.GetAni(Src)); - local Ao = { - ImgVariation = JobInfo["variation"], - ImgFormat = function(ImgPath) { - if (ImgVariation[0] > 0) { - local Pos = ImgPath.find("%04d"); - ImgPath = ImgPath.slice(0, Pos) + "%02d%02d" + ImgPath.slice(Pos + 4); - return format(ImgPath, ImgVariation[0], ImgVariation[1]); - } else { - return format(ImgPath, ImgVariation[1]); - } - } - } - SkinAni = Animation(BufInfo, Ao); - } - //如果是皮肤Ani 绑定状态机 确保唯一性 - SkinAni.BindenvStateMachine(StateMachine); - //将Ani类型设置为皮肤 - SkinAni.Type = "skin"; - //加入组 - this[AniObj].append(SkinAni); - } else { - //先判断类型 - if (this[Type] != null) { - local AvaInfo = AssetManager.GetEquipment(this[Type]); - if (AvaInfo) { - local JobInfo = AvaInfo["Ani_" + Info["job"]]; - foreach(_index, value in JobInfo["layer_variation"]) { - local BufInfo = sq_DeepCopy(ScriptData.GetAni(AvaInfo["DirPath"] + value["Path"] + Src.slice(Src.lastfind("/")))); - local Ao = { - ImgVariation = JobInfo["variation"], - ImgFormat = function(ImgPath) { - return format(ImgPath, ImgVariation[0], ImgVariation[1]); - } - } - local AniBuf = Animation(BufInfo, Ao); - //设置Ani类型 - AniBuf.Type = Type; - AniBuf.SetZOrder(value["Zorder"]); - this[AniObj].append(AniBuf); - } - } - } - } + //如果是武器或者时装则同步动画 + if (Equ.SlotType == "weapon" || Equ.Type == "avatar") { + AnimationManager.Init(Equ.SlotType); } } - - function ReadAndSetAttackAni() { - local AttackAniArrSrc = Info["attack_motion"]; - AttackAni = array(AttackAniArrSrc.len()); - foreach(_Index, Path in AttackAniArrSrc) { - local Src = Path; - AttackAni[_Index] = []; - foreach(Type in getconsttable().AvatarType) { - //如果有时装就初始化Ani - //除了皮肤 在没有的情况下初始化0 - if (Type == "skin") { - local SkinAni; - if (this[Type] == null) { - local BufInfo = sq_DeepCopy(ScriptData.GetAni(Src)); - local Ao = { - ImgVariation = [0, 0], - ImgFormat = function(ImgPath) { - if (ImgVariation[0] > 0) { - local Pos = ImgPath.find("%04d"); - ImgPath = ImgPath.slice(0, Pos) + "%02d%02d" + ImgPath.slice(Pos + 4); - return format(ImgPath, ImgVariation[0], ImgVariation[1]); - } else { - return format(ImgPath, ImgVariation[1]); - } - } - } - SkinAni = Animation(BufInfo, Ao); - } else { - local AvaInfo = AssetManager.GetEquipment(this[Type]); - local JobInfo = AvaInfo["Ani_" + Info["job"]]; - local BufInfo = sq_DeepCopy(ScriptData.GetAni(Src)); - local Ao = { - ImgVariation = JobInfo["variation"], - ImgFormat = function(ImgPath) { - return format(ImgPath, ImgVariation[0], ImgVariation[1]); - } - } - SkinAni = Animation(BufInfo, Ao); - } - //如果是皮肤Ani 绑定状态机 确保唯一性 - SkinAni.BindenvStateMachine(StateMachine); - //将Ani类型设置为皮肤 - SkinAni.Type = "skin"; - //加入组 - AttackAni[_Index].append(SkinAni); - } else { - if (this[Type] != null) { - - local AvaInfo = AssetManager.GetEquipment(this[Type]); - local JobInfo = AvaInfo["Ani_" + Info["job"]]; - foreach(_index, value in JobInfo["layer_variation"]) { - local BufInfo = sq_DeepCopy(ScriptData.GetAni(AvaInfo["DirPath"] + value["Path"] + Src.slice(Src.lastfind("/")))); - local Ao = { - ImgVariation = JobInfo["variation"], - ImgFormat = function(ImgPath) { - return format(ImgPath, ImgVariation[0], ImgVariation[1]); - } - } - local AniBuf = Animation(BufInfo, Ao); - //设置Ani类型 - AniBuf.Type = Type; - AniBuf.SetZOrder(value["Zorder"]); - AttackAni[_Index].append(AniBuf); - } - } - } - } + //切换装备列表 + function ChangeEquipmentList(EquList) { + foreach(Equ in EquList) { + ChangeEquipment(Equ); } } +} - function InitBaseAni() { - //读取并设置 等待Ani - ReadAndSetAni("WaitingAni", "waiting motion"); - //读取并设置 移动Ani - ReadAndSetAni("MoveAni", "move motion"); - //读取并设置 蹲下Ani - ReadAndSetAni("SitAni", "sit motion"); - //读取并设置 受伤Ani - ReadAndSetAni("DamageAni1", "damage motion 1"); - //读取并设置 受伤Ani - ReadAndSetAni("DamageAni2", "damage motion 2"); - //读取并设置 倒地Ani - ReadAndSetAni("DownAni", "down motion"); - //读取并设置 被击后退Ani - ReadAndSetAni("OverturnAni", "overturn motion"); - //读取并设置 跳跃Ani - ReadAndSetAni("JumoAni", "jump motion"); - //读取并设置 跳跃攻击Ani - ReadAndSetAni("JumpAttackAni", "jumpattack motion"); - //读取并设置 站立Ani - ReadAndSetAni("RestAni", "rest motion"); - //读取并设置 引导Ani - ReadAndSetAni("ThrowAni1_1", "throw motion 1-1"); - ReadAndSetAni("ThrowAni1_2", "throw motion 1-2"); - ReadAndSetAni("ThrowAni2_1", "throw motion 2-1"); - ReadAndSetAni("ThrowAni2_2", "throw motion 2-2"); - ReadAndSetAni("ThrowAni3_1", "throw motion 3-1"); - ReadAndSetAni("ThrowAni3_2", "throw motion 3-2"); - ReadAndSetAni("ThrowAni4_1", "throw motion 4-1"); - ReadAndSetAni("ThrowAni4_2", "throw motion 4-2"); - //读取并设置 奔跑Ani - ReadAndSetAni("DashAni", "dash motion"); - //读取并设置 奔跑攻击Ani - ReadAndSetAni("DashAttackAni", "dashattack motion"); - //读取并设置 拾取Ani - ReadAndSetAni("GetItemAni", "getitem motion"); - //读取并设置 释放BUFFAni - ReadAndSetAni("BuffAni", "buff motion"); - //读取并设置 AttackAni - ReadAndSetAttackAni(); - +//通过职业和装备列表来构造一个角色 +GameObject.CreateCharacter <- function(Job = 0, EquIdList = []) { + //构造角色 + local Character = GameObject.Character(); + Character.Init(Job); + foreach(EquId in EquIdList) { + local EquObj = GameItem.Equipment(EquId); + Character.ChangeEquipment(EquObj); } + return Character; } \ No newline at end of file diff --git a/sqr/User/Object/ActiveObject/CharacterObjectClass_AI.nut b/sqr/User/Object/ActiveObject/CharacterObjectClass_AI.nut index bd89076..9f1a64f 100644 --- a/sqr/User/Object/ActiveObject/CharacterObjectClass_AI.nut +++ b/sqr/User/Object/ActiveObject/CharacterObjectClass_AI.nut @@ -4,7 +4,7 @@ 创建日期:2024-05-14 10:05 文件用途:APC */ -class AICharacter extends Character { +class GameObject.AICharacter extends GameObject.Character { //职业 Job = null; diff --git a/sqr/User/Object/ActiveObject/MonsterObjectClass.nut b/sqr/User/Object/ActiveObject/MonsterObjectClass.nut index b6de9a6..cefe11c 100644 --- a/sqr/User/Object/ActiveObject/MonsterObjectClass.nut +++ b/sqr/User/Object/ActiveObject/MonsterObjectClass.nut @@ -4,7 +4,7 @@ 创建日期:2024-05-10 19:40 文件用途:怪物对象类 */ -class Monster extends ActiveObject { +class GameObject.Monster extends GameObject.ActiveObject { Attackinfo = null; //怪物Id diff --git a/sqr/User/Object/ActiveObject/PassiveObjectClass.nut b/sqr/User/Object/ActiveObject/PassiveObjectClass.nut index e343d18..e17eff2 100644 --- a/sqr/User/Object/ActiveObject/PassiveObjectClass.nut +++ b/sqr/User/Object/ActiveObject/PassiveObjectClass.nut @@ -4,7 +4,7 @@ 创建日期:2024-05-11 09:14 文件用途:被动对象 */ -class PassiveObject extends ActiveObject { +class GameObject.PassiveObject extends GameObject.ActiveObject { OnCreateFunction = null; OnProcFunction = null; diff --git a/sqr/User/Object/ActiveObject/StaticObjectClass.nut b/sqr/User/Object/ActiveObject/StaticObjectClass.nut index 4b0e606..c46d64a 100644 --- a/sqr/User/Object/ActiveObject/StaticObjectClass.nut +++ b/sqr/User/Object/ActiveObject/StaticObjectClass.nut @@ -4,7 +4,7 @@ 创建日期:2024-05-09 22:28 文件用途:静态Obj对象 */ -class StaticObject extends BaseObject { +class GameObject.StaticObject extends GameObject.BaseClass { AniObject = null;