using Axibug; using Axibug.Event; using Axibug.Runtime; using System; using UnityEngine; namespace Game { public class BattleNoMono : NoMono { public UnitPool _HpDamagePool; #region 生命周期 public BattleNoMono(string Name, Transform trans = null) : base(Name, trans) { //注册回调 AddEvent(E_LIFE_MONO_CYCLE.Update | E_LIFE_MONO_CYCLE.FixUpdate); AppEntry.Event.Subscribe(AttackHitEventArgs.EventId, OnAttackHitEventArgs); _HpDamagePool = new UnitPool(GamePlayEntry.UI.m_NodeScreen); } public override void Update() { } public override void FixedUpdate() { } public override void OnApplicationPause() { } public override void OnApplicationQuit() { } #endregion private void OnAttackHitEventArgs(object sender, LogicEventArgs e) { AttackHitEventArgs msg = (AttackHitEventArgs)e; if (msg == null) throw new GameException("AttackHitEventArgs is null"); RoleBase Attacker = GamePlayEntry.RoleMgr.FindRole(msg.Attacker_Type, msg.Attacker_RoleID); if (Attacker == null) { AxibugLog.Error("Attacker 为空"); return; } RoleBase UnderAttack = GamePlayEntry.RoleMgr.FindRole(msg.UnderAtk_Type, msg.UnderAtk_RoleID); if (UnderAttack == null) { AxibugLog.Error("UnderAttack 为空"); return; } DoAttack(Attacker, UnderAttack); } private void DoAttack(RoleBase Attacker,RoleBase UnderAttack,int AttackId = 0) { bool CanAttack = false; AxibugLog.Debug($"产生一次攻击,攻击者{Attacker.name} 受击者{UnderAttack.name}"); //人打怪 if (Attacker.RoleType == E_NODE_TYPE.N_MAINPLAYER && UnderAttack.RoleType == E_NODE_TYPE.N_MONSTER) { //TODO 受击朝向 //摄像机震动 AppEntry.Event.Fire(null, CameraShakeEventArgs.Create(1)); CanAttack = true; int Damage = 40; if (GamePlayEntry.MainPlayer.Player.IsFastSkillMode) Damage = 200; SetDamage(UnderAttack, Damage, out bool IsDead); GamePlayEntry.Tips.ShowHint($"产生一次攻击,攻击者{Attacker.name} 受击者{UnderAttack.name},造成伤害{Damage}", eHintType.Warn); } //怪打人 else if (Attacker.RoleType == E_NODE_TYPE.N_MONSTER && UnderAttack.RoleType == E_NODE_TYPE.N_MAINPLAYER) { //TODO 受击朝向 //摄像机震动 AppEntry.Event.Fire(null, CameraShakeEventArgs.Create(1)); CanAttack = true; int Damage = 40; SetDamage(UnderAttack, Damage,out bool IsDead); } if (CanAttack) { //TODO } } /// /// 受击 /// /// /// private void SetDamage(RoleBase UnderAttack, int DamageHP,out bool IsDead) { IsDead = false; //TODO 可能需要把伤害做成复合数据,扣除多项属性 UnderAttack.BaseData.life.curHP -= DamageHP; UnderAttack.BaseData.life.curHP = Math.Max(UnderAttack.BaseData.life.curHP, 0); ShowDamageTipsUI(UnderAttack, DamageHP); AppEntry.Event.Fire(null, HPMPChangeEventArgs.Create(UnderAttack.RoleType, UnderAttack.RoleID)); if (UnderAttack.BaseData.life.curHP > 0) UnderAttack.Anime.PlayHit(); else { IsDead = true; //死亡 UnderAttack.Anime.PlayDead(); GamePlayEntry.Tips.ShowHint($"受击者{UnderAttack.name},死亡", eHintType.Warn); AppEntry.Event.Fire(null, RoleDeadEventArgs.Create(UnderAttack.RoleType, UnderAttack.RoleID)); } } private void ShowDamageTipsUI(RoleBase role,int DamageHP) { if (DamageHP > 0) { HPDamageShowUnit damage = _HpDamagePool.GetAnyHide(); damage.SetData(role.ModelTransfrom, "-" + DamageHP); } } } }