using UnityEngine;
|
using TableConfig;
|
using Snxxz.UI;
|
using System.Collections.Generic;
|
using System.Collections;
|
|
public class GA_NpcFunc : GActorNpcNoFight
|
{
|
protected HeadUpName m_HeadUpName;
|
// 用于触发点击的组件
|
protected NPCInteractProcessor m_NPCInteractProcessor;
|
private H0406_tagNPCAppear m_H0406;
|
private HeadUpQuestSign m_MissionSign;
|
|
protected override void OnInit(GameNetPackBasic package)
|
{
|
m_H0406 = package as H0406_tagNPCAppear;
|
|
if (m_H0406 == null)
|
{
|
Debug.LogErrorFormat("Npc 执行初始化时, 传入的包错误...{0}", package.GetType());
|
}
|
|
// 初始化坐标
|
AdjustPos(m_H0406.PosX, m_H0406.PosY);
|
|
ActorInfo.serverBornPos = new Vector2(m_H0406.PosX, m_H0406.PosY);
|
ActorInfo.PlayerName = NpcConfig.charName;
|
|
// 功能NPC需要读取配置朝向
|
GAStaticDefine.NPCLocation _npcLocation;
|
if (GAStaticDefine.TryGetMapNPCLocation(NpcConfig.NPCID, out _npcLocation))
|
{
|
Rotation = MathUtility.GetClientRotationFromAngle(_npcLocation.face);
|
}
|
else
|
{
|
Rotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 360), 0);
|
}
|
|
if (CanBeSelected())
|
{
|
m_NPCInteractProcessor = Root.AddMissingComponent<NPCInteractProcessor>();
|
m_NPCInteractProcessor.npcIntergactEvent += OnClick;
|
}
|
|
GAStaticDefine.NpcID2ServerInstID[NpcConfig.NPCID] = ServerInstID;
|
|
PlayerTaskDatas.Event_TaskResponse += OnTaskRefresh;
|
|
RequestMissionSign();
|
|
bool _needHide = (NpcConfig.Show == 0);
|
|
PlayerTaskDatas _model = ModelCenter.Instance.GetModel<PlayerTaskDatas>();
|
if (_model.NPCShowDic.ContainsKey(NpcConfig.NPCID)
|
&& _model.NPCShowDic[NpcConfig.NPCID] == 1)
|
{
|
_needHide = false;
|
}
|
|
if (_needHide)
|
{
|
Pos = Constants.Special_Hide_Position;
|
}
|
}
|
|
protected override void OnUnit()
|
{
|
if (m_NPCInteractProcessor)
|
{
|
m_NPCInteractProcessor.npcIntergactEvent -= OnClick;
|
Object.Destroy(m_NPCInteractProcessor);
|
m_NPCInteractProcessor = null;
|
}
|
PlayerTaskDatas.Event_TaskResponse -= OnTaskRefresh;
|
m_H0406 = null;
|
|
ReleaseMissionSign();
|
|
base.OnUnit();
|
}
|
|
protected virtual void OnTaskRefresh(int _nowNPCid, int _nPCLamp, Dictionary<int, int> _dic)
|
{
|
if (_nowNPCid == NpcConfig.NPCID)
|
{
|
RequestMissionSign();
|
}
|
}
|
|
public override void OnClick()
|
{
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
_hero.LockTarget = this;
|
_hero.SelectTarget = this;
|
|
// 这里判断是否要走向此对象
|
float _distSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, Pos);
|
if (_distSqrt > Mathf.Pow(GeneralDefine.CloseNpcDist + NpcConfig.ModelRadius + 0.4f, 2))
|
{
|
MapTransferUtility.Instance.MoveToNPC(NpcConfig.NPCID, (int)ServerInstID);
|
}
|
else
|
{
|
if (NpcConfig.AutomaticFace == 1)
|
{
|
Vector3 _forward = MathUtility.ForwardXZ(_hero.Pos, Pos);
|
Forward = _forward;
|
}
|
NPCInteractProcessor.InvokeEvent(E_NpcType.Func, NpcConfig.NPCID, ServerInstID);
|
}
|
}
|
|
protected override void OnLateUpdate() { }
|
protected override void OnFixedUpdate() { }
|
protected override void OnUpdate() { }
|
|
public sealed override void Die() { }
|
public sealed override void Hurt() { }
|
public sealed override void HurtDown() { }
|
|
public sealed override void RequestLifeBar() { }
|
public sealed override void ReleaseLifeBar() { }
|
|
public override void RequestName()
|
{
|
ReleaseName();
|
|
if (!MP_Name)
|
{
|
return;
|
}
|
|
HeadUpName.Pattern _pattern = HeadUpName.Pattern.FunctionNPC;
|
|
var _bossInfoConfig = BossInfoConfig.GetBossInfoByStoneId(NpcConfig.NPCID);
|
if (_bossInfoConfig != null)
|
{
|
_pattern = HeadUpName.Pattern.NpcReborn;
|
}
|
|
m_HeadUpName = HeadUpName.RequireHeadUpName(_pattern, MP_Name, 0, CameraController.Instance.CameraObject);
|
|
if (_bossInfoConfig != null)
|
{
|
m_HeadUpName.SetNpcReborn(_bossInfoConfig.NPCID);
|
}
|
else
|
{
|
m_HeadUpName.SetNPCName(NpcConfig.NPCID);
|
}
|
}
|
|
public sealed override void ReleaseName()
|
{
|
if (m_HeadUpName)
|
{
|
m_HeadUpName.target = null;
|
HeadUpName.Recycle(m_HeadUpName);
|
m_HeadUpName = null;
|
}
|
}
|
|
PlayerTaskDatas m_TaskModel;
|
PlayerTaskDatas taskmodel
|
{
|
get
|
{
|
return m_TaskModel ?? (m_TaskModel = ModelCenter.Instance.GetModel<PlayerTaskDatas>());
|
}
|
}
|
|
public void RequestMissionSign()
|
{
|
ReleaseMissionSign();
|
int _status = taskmodel.StatusLightQuery(NpcConfig.NPCID);
|
if (_status >= 0)
|
{
|
HeadUpQuestSign.Pattern _pattern = (HeadUpQuestSign.Pattern)_status;
|
m_MissionSign = HeadUpQuestSign.RequireHeadUpQuestSign(_pattern, MP_Name, 0, CameraController.Instance.CameraObject);
|
}
|
}
|
|
public void ReleaseMissionSign()
|
{
|
if (m_MissionSign)
|
{
|
HeadUpQuestSign.Recycle(m_MissionSign);
|
m_MissionSign = null;
|
}
|
}
|
|
public override void OnSelect()
|
{
|
if (NpcConfig.NPCID != 10204200)
|
{
|
SelectionManager.Request(SelectionManager.E_Type.Green, this, NpcConfig.ModelRadius * 2);
|
}
|
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
Vector3 _forward = MathUtility.ForwardXZ(Pos, _hero.Pos);
|
_hero.Forward = _forward;
|
|
if (NpcConfig.AutomaticFace == 1)
|
{
|
_forward = MathUtility.ForwardXZ(_hero.Pos, Pos);
|
Forward = _forward;
|
}
|
}
|
|
public override void OnUnSelect()
|
{
|
SelectionManager.Release(SelectionManager.E_Type.Green);
|
}
|
|
public override bool CanBeSelected()
|
{
|
return true;
|
}
|
|
private static Dictionary<int, bool> s_VisibleNpcFunc = new Dictionary<int, bool>();
|
|
public static void SetNpcFuncVisible(int npcID, bool visible,
|
float delayTime = 0,
|
UnityEngine.Events.UnityAction<Vector3> callback1 = null,
|
float timeBeforeDisappare = 0)
|
{
|
if (delayTime == 0)
|
{
|
SetNpcFuncVisibleFunc(npcID, visible);
|
}
|
else
|
{
|
SnxxzGame.Instance.StartCoroutine(DelaySetVisible(npcID, visible, delayTime, timeBeforeDisappare, callback1));
|
}
|
}
|
|
private static IEnumerator DelaySetVisible(int npcID,
|
bool visible,
|
float delayTime,
|
float timeCallback,
|
UnityEngine.Events.UnityAction<Vector3> callback)
|
{
|
float _waitTime = delayTime - timeCallback;
|
|
yield return new WaitForSeconds(timeCallback);
|
|
GActor _disappearTarget = null;
|
|
s_VisibleNpcFunc[npcID] = visible;
|
List<GActor> _actorList = GAMgr.Instance.GetGroupList(E_ActorGroup.Collect);
|
if (_actorList != null)
|
{
|
GActorNpcNoFight _target = null;
|
|
for (int i = 0; i < _actorList.Count; ++i)
|
{
|
_target = _actorList[i] as GActorNpcNoFight;
|
|
if (_target.NpcConfig.NPCID == npcID)
|
{
|
if (visible)
|
{
|
_target.AdjustPos((ushort)_target.ActorInfo.serverBornPos.x, (ushort)_target.ActorInfo.serverBornPos.y);
|
}
|
else
|
{
|
if (callback != null)
|
{
|
callback(_target.Pos);
|
}
|
|
_disappearTarget = _target;
|
}
|
}
|
}
|
}
|
|
if (_disappearTarget == null)
|
{
|
_actorList = GAMgr.Instance.GetGroupList(E_ActorGroup.FuncNpc);
|
|
if (_actorList != null)
|
{
|
GActorNpcNoFight _target = null;
|
|
for (int i = 0; i < _actorList.Count; ++i)
|
{
|
_target = _actorList[i] as GActorNpcNoFight;
|
|
if (_target.NpcConfig.NPCID == npcID)
|
{
|
if (visible)
|
{
|
_target.AdjustPos((ushort)_target.ActorInfo.serverBornPos.x, (ushort)_target.ActorInfo.serverBornPos.y);
|
}
|
else
|
{
|
if (callback != null)
|
{
|
callback(_target.Pos);
|
}
|
_disappearTarget = _target;
|
}
|
break;
|
}
|
}
|
}
|
}
|
|
if (_disappearTarget != null)
|
{
|
yield return new WaitForSeconds(_waitTime);
|
_disappearTarget.Pos = Constants.Special_Hide_Position;
|
}
|
|
}
|
|
private static void SetNpcFuncVisibleFunc(int npcID, bool visible)
|
{
|
s_VisibleNpcFunc[npcID] = visible;
|
List<GActor> _actorList = GAMgr.Instance.GetGroupList(E_ActorGroup.Collect);
|
if (_actorList != null)
|
{
|
GActorNpcNoFight _target = null;
|
|
for (int i = 0; i < _actorList.Count; ++i)
|
{
|
_target = _actorList[i] as GActorNpcNoFight;
|
|
if (_target.NpcConfig.NPCID == npcID)
|
{
|
if (visible)
|
{
|
_target.AdjustPos((ushort)_target.ActorInfo.serverBornPos.x, (ushort)_target.ActorInfo.serverBornPos.y);
|
}
|
else
|
{
|
_target.Pos = Constants.Special_Hide_Position;
|
}
|
return;
|
}
|
}
|
}
|
|
_actorList = GAMgr.Instance.GetGroupList(E_ActorGroup.FuncNpc);
|
|
if (_actorList != null)
|
{
|
GActorNpcNoFight _target = null;
|
|
for (int i = 0; i < _actorList.Count; ++i)
|
{
|
_target = _actorList[i] as GActorNpcNoFight;
|
|
if (_target.NpcConfig.NPCID == npcID)
|
{
|
if (visible)
|
{
|
_target.AdjustPos((ushort)_target.ActorInfo.serverBornPos.x, (ushort)_target.ActorInfo.serverBornPos.y);
|
}
|
else
|
{
|
_target.Pos = Constants.Special_Hide_Position;
|
}
|
break;
|
}
|
}
|
}
|
}
|
}
|