120 lines
3.7 KiB
C#
120 lines
3.7 KiB
C#
using Axibug;
|
|
using Axibug.Event;
|
|
using Axibug.Resources;
|
|
using Axibug.Runtime;
|
|
using Codice.CM.WorkspaceServer.DataStore;
|
|
using Game.Config;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace Game
|
|
{
|
|
public class BattleMgrComponent : GameComponent
|
|
{
|
|
private void Start()
|
|
{
|
|
AppEntry.Event.Subscribe(AttackHitEventArgs.EventId, OnAttackHitEventArgs);
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 受击
|
|
/// </summary>
|
|
/// <param name="role"></param>
|
|
/// <param name="Damage"></param>
|
|
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);
|
|
|
|
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));
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|