using UnityEngine;
|
using System.Collections;
|
using vnxbqy.UI;
|
|
public class GA_NpcFightNorm : GActorNpcFight
|
{
|
protected HeadUpName m_HeadUpName;
|
protected LifeBar m_LifeBar;
|
|
// 用于触发点击的组件
|
private NPCInteractProcessor m_NPCInteractProcessor;
|
|
protected override void OnInit(GameNetPackBasic package)
|
{
|
var _h0406 = package as H0406_tagNPCAppear;
|
NpcConfig = NPCConfig.Get((int)_h0406.NPCID);
|
|
if (NpcConfig == null)
|
{
|
// 报错
|
return;
|
}
|
|
// 可选择对象创建碰撞区
|
if (CanBeSelected())
|
{
|
m_NPCInteractProcessor = Root.AddMissingComponent<NPCInteractProcessor>();
|
m_NPCInteractProcessor.npcIntergactEvent -= OnClick;
|
m_NPCInteractProcessor.npcIntergactEvent += OnClick;
|
}
|
|
|
if (_h0406 == null)
|
{
|
Debug.LogErrorFormat("Npc 执行初始化时, 传入的包错误...{0}", package.GetType());
|
}
|
|
ActorInfo.LV = _h0406.CurLV;
|
ActorInfo.PlayerName = NpcConfig.charName;
|
ActorInfo.faction = NpcConfig.Country;
|
ActorInfo.Hp = _h0406.NPCHP + _h0406.NPCHPEx * Constants.ExpPointValue;
|
ActorInfo.MaxHp = _h0406.MaxHP + _h0406.MaxHPEx * Constants.ExpPointValue;
|
ActorInfo.realm = (uint)NpcConfig.Realm;
|
|
// 初始化移动速度
|
ActorInfo.moveSpeed = 500f / _h0406.Speed;
|
ActorInfo.serverBornPos = new Vector2(_h0406.PosX, _h0406.PosY);
|
|
if (NpcConfig.NPCID == 32502001
|
|| NpcConfig.Dig == 1)// 针对守护笼子的临时骚操作
|
{
|
float _x = _h0406.PosX * .5f;
|
float _z = _h0406.PosY * .5f;
|
Pos = new Vector3(_x, PlayerDatas.Instance.hero.Pos.y, _z);
|
}
|
else
|
{
|
bool _force = NpcConfig.NPCID != 33409001 && NpcConfig.NPCID != 33409002;
|
// 初始化坐标
|
AdjustPos(_h0406.PosX, _h0406.PosY, _force);
|
}
|
|
// 这里针对指定的NPC特殊矫正位置
|
if (GeneralDefine.NpcPosOffset.ContainsKey(NpcConfig.NPCID))
|
{
|
Pos = new Vector3(GeneralDefine.NpcPosOffset[NpcConfig.NPCID].x,
|
Pos.y,
|
GeneralDefine.NpcPosOffset[NpcConfig.NPCID].z);
|
//Debug.Log("矫正位置: " + Pos);
|
}
|
|
GAStaticDefine.NPCLocation _npcLocation;
|
if ((NpcConfig.NPCID == 31704001
|
|| NpcConfig.NPCID == 31704002
|
|| NpcConfig.NPCID == 31704003)
|
&& GAStaticDefine.TryGetMapNPCLocation(NpcConfig.NPCID, out _npcLocation))
|
{
|
Rotation = MathUtility.GetClientRotationFromAngle(_npcLocation.face);
|
}
|
else
|
{
|
Rotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 360), 0);
|
}
|
|
base.OnInit(package);
|
}
|
|
protected override void OnMainModelLoaded()
|
{
|
base.OnMainModelLoaded();
|
|
if (NpcConfig.IsBoss < 2
|
&& SystemSetting.Instance.GetSystemSettingSwitch(SystemSwitch.HideMonster))
|
{
|
//默认20%的概率
|
var show = Random.Range(1, 5);
|
if (show != 2)
|
{
|
ShowOrHideModel(false);
|
}
|
}
|
|
if (m_Model)
|
{
|
if (NpcConfig.NPCID == 33409001)
|
{
|
m_Model.transform.localPosition = new Vector3(0, 0.132f, 0);
|
var _dz = m_Model.transform.Find("Prefab_Race_L007");
|
if (_dz)
|
{
|
_dz.localPosition = new Vector3(0, -0.132f, 0);
|
}
|
}
|
else if (NpcConfig.NPCID == 33409002)
|
{
|
m_Model.transform.localPosition = new Vector3(0, 0.142f, 0);
|
var _dz = m_Model.transform.Find("Prefab_Race_L007");
|
if (_dz)
|
{
|
_dz.localPosition = new Vector3(0, -0.142f, 0);
|
}
|
}
|
}
|
|
if (PlayerDatas.Instance.baseData.MapID == 31340)
|
{
|
RequestLifeBar();
|
}
|
}
|
|
public override void RequestShadow()
|
{
|
if (NpcConfig.NPCID != 33409001 && NpcConfig.NPCID != 33409002)
|
{
|
base.RequestShadow();
|
}
|
}
|
|
public override void OnClick()
|
{
|
if (ActorInfo.serverDie
|
|| BossShowModel.Instance.BossShowing
|
|| StatusMgr.Instance.IsInvisible(ServerInstID))
|
{
|
return;
|
}
|
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
|
// 当前锁定的目标已经是此对象
|
if (_hero.LockTarget == this && CanAtked())
|
{
|
// 开启攻击至死AI
|
_hero.Behaviour.StartKillUntilDieAI();
|
}
|
else
|
{
|
// 设置锁定目标为此对象
|
_hero.LockTarget = this;
|
_hero.SelectTarget = this;
|
GA_Hero.CallLockTargetChanged(ServerInstID);
|
}
|
}
|
|
protected override void OnUnit()
|
{
|
if (m_NPCInteractProcessor)
|
{
|
m_NPCInteractProcessor.npcIntergactEvent -= OnClick;
|
m_NPCInteractProcessor = null;
|
}
|
|
base.OnUnit();
|
}
|
|
protected override void OnFixedUpdate()
|
{
|
base.OnFixedUpdate();
|
|
if (!ActorInfo.serverDie)
|
{
|
UpdateTimeDialogueBubble();
|
}
|
}
|
|
protected override void OnLateUpdate()
|
{
|
}
|
|
protected override void OnUpdate()
|
{
|
base.OnUpdate();
|
}
|
|
public override void RequestLifeBar()
|
{
|
ReleaseLifeBar();
|
|
// 聚魂副本守卫不显示血条
|
if (NpcConfig.NPCID == 33409001 || NpcConfig.NPCID == 33409002)
|
{
|
return;
|
}
|
|
m_LifeBar = LifeBar.RequireLifeBar(MP_Name, 0, CameraController.Instance.CameraObject);
|
m_LifeBar.neverHide = true;
|
m_LifeBar.Set(ActorInfo.RealHp, ActorInfo.RealMaxHp);
|
}
|
|
public override void RefreshLifeBar(ulong value)
|
{
|
if (m_LifeBar)
|
{
|
m_LifeBar.Show(ActorInfo.RealHp, ActorInfo.RealMaxHp);
|
}
|
}
|
|
public override void ReleaseLifeBar()
|
{
|
if (m_LifeBar != null)
|
{
|
m_LifeBar.target = null;
|
//m_LifeBar.neverHide = false;
|
LifeBar.Recycle(m_LifeBar);
|
m_LifeBar = null;
|
}
|
}
|
|
public override void ReleaseName()
|
{
|
if (m_HeadUpName != null)
|
{
|
m_HeadUpName.target = null;
|
HeadUpName.Recycle(m_HeadUpName);
|
m_HeadUpName = null;
|
}
|
}
|
|
public override void RequestName()
|
{
|
ReleaseName();
|
|
// 聚魂副本守卫不显示名字
|
if (PlayerDatas.Instance.baseData.MapID == 31340)
|
{
|
return;
|
}
|
|
HeadUpName.Pattern _pattern = HeadUpName.Pattern.Monster;
|
m_HeadUpName = HeadUpName.RequireHeadUpName(_pattern, MP_Name, 0, CameraController.Instance.CameraObject);
|
m_HeadUpName.SetMonsterInfo(NpcConfig.NPCID, ActorInfo.LV);
|
}
|
|
public override void RequestDialogueBubble()
|
{
|
if (m_DialogAppear)
|
{
|
NPCDialogueBubble.Recyle(m_DialogAppear);
|
}
|
}
|
|
protected override void UpdateTimeDialogueBubble()
|
{
|
if (!MP_Name)
|
{
|
return;
|
}
|
// 瞎BB逻辑
|
if (Time.realtimeSinceStartup - m_LastTalkTime > 5)
|
{
|
if (m_DialogTiming != null)
|
{
|
NPCDialogueBubble.Recyle(m_DialogTiming);
|
}
|
m_DialogTiming = NPCDialogueBubble.TimingShow(NpcConfig.NPCID, MP_Name, CameraController.Instance.CameraObject);
|
m_LastTalkTime = Time.realtimeSinceStartup;
|
}
|
}
|
|
public override bool CanBeSelected()
|
{
|
if (NpcConfig.NPCType == (int)E_NpcType.BreakableObj || NpcConfig.NPCType == (int)E_NpcType.Ghost)
|
{
|
return false;
|
}
|
|
if (StatusMgr.Instance.IsInvisible(ServerInstID))
|
{
|
return false;
|
}
|
|
if (PlayerDatas.Instance.baseData.faction == 0)
|
{
|
if (NpcConfig.Country == 1 && NpcConfig.NPCID != 33409001 && NpcConfig.NPCID != 33409002)
|
{
|
return false;
|
}
|
}
|
else if (PlayerDatas.Instance.baseData.faction == NpcConfig.Country)
|
{
|
return false;
|
}
|
|
//return NpcConfig.NPCType != (int)E_NpcType.BreakableObj
|
// && (NpcConfig.Country != 1 || NpcConfig.NPCID == 33409001 || NpcConfig.NPCID == 33409002)
|
// && !StatusMgr.Instance.IsInvisible(ServerInstID)
|
// && NpcConfig.NPCType != (int)E_NpcType.Ghost;
|
|
return true;
|
}
|
|
public override void OnSelect()
|
{
|
if (NpcConfig.NPCID == 33409001)
|
{
|
SelectionManager.RequestJH_Red(this);
|
}
|
else if (NpcConfig.NPCID == 33409002)
|
{
|
SelectionManager.RequestJH_Blue(this);
|
}
|
else
|
{
|
SelectionManager.Request(SelectionManager.E_Type.Red, this, NpcConfig.ModelRadius * 2);
|
}
|
|
RequestName();
|
RequestLifeBar();
|
}
|
|
public override void OnUnSelect()
|
{
|
if (NpcConfig.NPCID == 33409001 || NpcConfig.NPCID == 33409002)
|
{
|
SelectionManager.ClearJHSfx();
|
}
|
else
|
{
|
SelectionManager.Release(SelectionManager.E_Type.Red);
|
}
|
|
if (!ActorInfo.serverDie)
|
{
|
ReleaseName();
|
if (PlayerDatas.Instance.baseData.MapID != 31340)
|
{
|
ReleaseLifeBar();
|
}
|
}
|
}
|
|
public override bool CanPushedBack()
|
{
|
return NpcConfig.weight != 0
|
&& (IsHurt() || IsIdle());
|
}
|
|
public override bool CanHurted()
|
{
|
return NpcConfig.hurtFeedback == 1
|
&& (IsIdle() || IsRun() || IsHurt())
|
&& !SkillMgr.DoingPrepareSkill
|
&& (SkillMgr.CurCastSkill == null
|
|| SkillMgr.CurCastSkill.SkillCompelete);
|
}
|
|
public override bool CanDieFly()
|
{
|
return NpcConfig.NPCType != (int)E_NpcType.BreakableObj;
|
}
|
|
public override bool CanAtked()
|
{
|
// 判断是否相同阵营
|
bool _sameFaction = NpcConfig.Country != 0
|
&& NpcConfig.Country == PlayerDatas.Instance.baseData.faction;
|
|
return !_sameFaction
|
&& NpcConfig.NPCType != (int)E_NpcType.Func
|
&& NpcConfig.NPCType != (int)E_NpcType.Collect
|
&& NpcConfig.NPCType != (int)E_NpcType.Pet
|
&& !ActorInfo.serverDie
|
&& NpcConfig.NPCType != (int)E_NpcType.FightAssist;
|
}
|
|
public override bool CanAtkedRotate()
|
{
|
return NpcConfig.NPCType != (int)E_NpcType.BreakableObj
|
&& NpcConfig.AIType != 201
|
&& NpcConfig.AIType != 49
|
&& NpcConfig.AIType != 50
|
&& !IsRun()
|
&& !SkillMgr.DoingPrepareSkill
|
&& (SkillMgr.CurCastSkill == null
|
|| SkillMgr.CurCastSkill.SkillCompelete)
|
&& (Time.time - m_LastCantAtkedTime > NpcConfig.AtkInterval * Constants.F_GAMMA + 1f);
|
}
|
}
|