using UnityEngine;
|
|
using vnxbqy.UI;
|
using System.Collections.Generic;
|
using System.Collections;
|
|
public class GA_NpcFunc : GActorNpcNoFight
|
{
|
protected HeadUpName m_HeadUpName;
|
// 用于触发点击的组件
|
protected NPCInteractProcessor m_NPCInteractProcessor;
|
protected H0406_tagNPCAppear m_H0406;
|
private HeadUpQuestSign m_MissionSign;
|
|
private int m_WeaponID;
|
private int m_SecondaryID;
|
private int m_WingID;
|
private int m_HorseID;
|
|
private GameObject m_WeaponModel;
|
private GameObject m_SecondaryModel;
|
private GameObject m_WingModel;
|
private GameObject m_HorseModel;
|
|
protected override void OnInit(GameNetPackBasic package)
|
{
|
base.OnInit(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;
|
|
var _npcID = NpcConfig.NPCID;
|
TaskModel.Event_TaskResponse += OnTaskRefresh;
|
bool _needHide = (NpcConfig.Show == 0);
|
|
TaskModel _model = ModelCenter.Instance.GetModel<TaskModel>();
|
|
if (_npcID == 10404101)
|
{
|
_npcID = 10404100;
|
}
|
|
if (_model.NPCShowDic.ContainsKey(_npcID))
|
{
|
if (_model.NPCShowDic[_npcID] == 1)
|
{
|
_needHide = false;
|
#if UNITY_EDITOR
|
string _content = string.Format("{0} / {1} => 因为任务决定的, 不需要隐藏", ServerInstID, _npcID);
|
RuntimeLogUtility.AddLog(_content, ServerInstID, true);
|
#endif
|
}
|
else if (_model.NPCShowDic[_npcID] == 0)
|
{
|
_needHide = true;
|
#if UNITY_EDITOR
|
string _content = string.Format("{0} / {1} => 因为任务决定的, 需要隐藏", ServerInstID, _npcID);
|
RuntimeLogUtility.AddLog(_content, ServerInstID, true);
|
#endif
|
}
|
}
|
|
// 这里针对指定的NPC特殊矫正位置
|
if (GeneralDefine.NpcPosOffset.ContainsKey(NpcConfig.NPCID))
|
{
|
Pos = GeneralDefine.NpcPosOffset[NpcConfig.NPCID];
|
//Debug.Log("矫正位置: " + Pos);
|
}
|
|
if (_needHide)
|
{
|
#if UNITY_EDITOR
|
string _content = string.Format("{0} / {1} => 需要隐藏", ServerInstID, _npcID);
|
RuntimeLogUtility.AddLog(_content, ServerInstID, true);
|
#endif
|
Pos = Constants.Special_Hide_Position;
|
}
|
else
|
{
|
#if UNITY_EDITOR
|
string _content = string.Format("{0} / {1} => 不需要隐藏", ServerInstID, _npcID);
|
RuntimeLogUtility.AddLog(_content, ServerInstID, true);
|
#endif
|
}
|
}
|
|
private SFXController m_ReikiEffect;
|
|
protected override void OnMainModelLoaded()
|
{
|
RequestMissionSign();
|
|
if (string.IsNullOrEmpty(NpcConfig.Equips))
|
{
|
return;
|
}
|
|
string[] _ids = NpcConfig.Equips.Split('|');
|
int _weaponId = int.Parse(_ids[0]);
|
int _secondaryId = _ids.Length > 1 ? int.Parse(_ids[1]) : -1;
|
int _horseId = _ids.Length > 2 ? int.Parse(_ids[2]) : -1;
|
int _wingId = _ids.Length > 3 ? int.Parse(_ids[3]) : -1;
|
int _effectId = _ids.Length > 4 ? int.Parse(_ids[4]) : -1;
|
|
// Debug.LogFormat("weapon: {0}, secondary: {1}, horse: {2}, wing: {3}", _weaponId, _secondaryId, _horseId, _weaponId);
|
|
if (_weaponId > 0)
|
{
|
SetEquipWeapon(_weaponId);
|
}
|
|
if (_secondaryId > 0)
|
{
|
SetEquipSecondary(_secondaryId);
|
}
|
|
if (_wingId > 0)
|
{
|
SetEquipWing(_wingId);
|
}
|
|
if (_horseId > 0)
|
{
|
SetEquipHorse(_horseId);
|
}
|
|
if (_effectId != -1)
|
{
|
if (m_ReikiEffect)
|
{
|
SFXPlayUtility.Instance.Release(m_ReikiEffect);
|
m_ReikiEffect = null;
|
}
|
m_ReikiEffect = SFXPlayUtility.Instance.PlayBattleEffect(_effectId, Root, 1);
|
}
|
|
}
|
|
private void SetEquipHorse(int horseID)
|
{
|
if (horseID > 0)
|
{
|
m_HorseID = horseID;
|
var _horseConfig = HorseConfig.Get(horseID);
|
InstanceResourcesLoader.AsyncLoadModelRes(_horseConfig.Model, OnHorseLoaded);
|
}
|
}
|
|
private void SetEquipSecondary(int resID)
|
{
|
if (resID > 0)
|
{
|
m_SecondaryID = resID;
|
InstanceResourcesLoader.AsyncLoadModelRes(resID, OnSecondaryLoaded);
|
}
|
}
|
|
private void SetEquipWeapon(int resID)
|
{
|
if (resID > 0)
|
{
|
m_WeaponID = resID;
|
InstanceResourcesLoader.AsyncLoadModelRes(resID, OnWeaponLoaded);
|
}
|
}
|
|
private void SetEquipWing(int resID)
|
{
|
if (resID > 0)
|
{
|
m_WingID = resID;
|
InstanceResourcesLoader.AsyncLoadModelRes(resID, OnWingLoaded);
|
}
|
}
|
|
private void OnHorseLoaded(bool result, UnityEngine.Object prefab)
|
{
|
if (IsUnInit)
|
{
|
return;
|
}
|
if (!result || !prefab)
|
{
|
return;
|
}
|
|
var _horseConfig = HorseConfig.Get(m_HorseID);
|
var _modelResConfig = ModelResConfig.Get(_horseConfig.Model);
|
|
m_HorseModel = GameObjectPoolManager.Instance.RequestGameObject(prefab as GameObject);
|
if (!m_HorseModel)
|
{
|
return;
|
}
|
|
var _animator = m_HorseModel.GetComponent<Animator>();
|
if (_animator)
|
{
|
_animator.runtimeAnimatorController = AnimatorControllerLoader.LoadMobController(AnimatorControllerLoader.controllerSuffix,
|
_modelResConfig.ResourcesName);
|
_animator.enabled = true;
|
}
|
|
if (m_HorseModel)
|
{
|
m_HorseModel.transform.SetParent(m_Root);
|
m_HorseModel.transform.localPosition = Vector3.zero;
|
m_HorseModel.transform.localRotation = Quaternion.identity;
|
|
var _horseBindNode = m_HorseModel.transform.GetChildTransformDeeply(_modelResConfig.BindPoint);
|
|
if (_horseBindNode)
|
{
|
m_Model.transform.SetParent(_horseBindNode);
|
m_Model.transform.localPosition = Vector3.zero;
|
m_Model.transform.localEulerAngles = new Vector3(90, 0, 0);
|
_animator = m_Model.GetComponent<Animator>();
|
if (_animator)
|
{
|
_animator.SetInteger(GAStaticDefine.Param_Action, GAStaticDefine.Act_HorseIdle);
|
switch (_horseConfig.ActionType)
|
{
|
case 0:
|
_animator.Play(GAStaticDefine.State_HorseIdleHash);
|
break;
|
case 1:
|
_animator.Play(GAStaticDefine.State_HorseIdle1Hash);
|
break;
|
case 2:
|
_animator.Play(GAStaticDefine.State_HorseIdle2Hash);
|
break;
|
case 3:
|
_animator.Play(GAStaticDefine.State_HorseIdle3Hash);
|
break;
|
case 4:
|
_animator.Play(GAStaticDefine.State_HorseIdle4Hash);
|
break;
|
}
|
}
|
}
|
}
|
}
|
|
private void OnWingLoaded(bool result, UnityEngine.Object prefab)
|
{
|
if (IsUnInit)
|
{
|
return;
|
}
|
if (!result || !prefab)
|
{
|
return;
|
}
|
|
m_WingModel = GameObjectPoolManager.Instance.RequestGameObject(prefab as GameObject);
|
if (!m_WingModel)
|
{
|
return;
|
}
|
var _animator = m_WingModel.GetComponent<Animator>();
|
if (_animator)
|
{
|
_animator.enabled = true;
|
}
|
Transform _bindNode = m_Model.transform.GetChildTransformDeeply(GAStaticDefine.WingBindBoneName);
|
if (_bindNode)
|
{
|
m_WingModel.transform.SetParent(_bindNode);
|
m_WingModel.transform.localPosition = Vector3.zero;
|
m_WingModel.transform.localRotation = Quaternion.identity;
|
}
|
|
ModelResConfig _resConfig = ModelResConfig.Get(m_WingID);
|
m_WingModel.transform.localScale = _resConfig.Scale;
|
}
|
|
private void OnSecondaryLoaded(bool result, UnityEngine.Object prefab)
|
{
|
if (IsUnInit)
|
{
|
return;
|
}
|
if (!result || !prefab)
|
{
|
return;
|
}
|
|
m_SecondaryModel = GameObjectPoolManager.Instance.RequestGameObject(prefab as GameObject);
|
if (!m_SecondaryModel)
|
{
|
return;
|
}
|
var _animator = m_SecondaryModel.GetComponent<Animator>();
|
if (_animator)
|
{
|
_animator.enabled = true;
|
}
|
int _job = NpcConfig.MODE.Contains("A_Zs") ? 1 : 2;
|
Transform _bindNode = m_Model.transform.GetChildTransformDeeply(GAStaticDefine.SecondaryBindBoneName[_job - 1]);
|
if (_bindNode)
|
{
|
m_SecondaryModel.transform.SetParent(_bindNode);
|
m_SecondaryModel.transform.localPosition = Vector3.zero;
|
m_SecondaryModel.transform.localRotation = Quaternion.identity;
|
}
|
}
|
|
private void OnWeaponLoaded(bool result, UnityEngine.Object prefab)
|
{
|
if (IsUnInit)
|
{
|
return;
|
}
|
if (!result || !prefab)
|
{
|
return;
|
}
|
m_WeaponModel = GameObjectPoolManager.Instance.RequestGameObject(prefab as GameObject);
|
if (!m_WeaponModel)
|
{
|
return;
|
}
|
var _animator = m_WeaponModel.GetComponent<Animator>();
|
if (_animator)
|
{
|
_animator.enabled = true;
|
}
|
Transform _bindNode = m_Model.transform.GetChildTransformDeeply(GAStaticDefine.WeaponBindBoneName);
|
if (_bindNode)
|
{
|
m_WeaponModel.transform.SetParent(_bindNode);
|
m_WeaponModel.transform.localPosition = Vector3.zero;
|
m_WeaponModel.transform.localRotation = Quaternion.identity;
|
}
|
}
|
|
protected override void OnUnit()
|
{
|
if (m_ReikiEffect)
|
{
|
SFXPlayUtility.Instance.Release(m_ReikiEffect);
|
m_ReikiEffect = null;
|
}
|
|
if (m_WeaponModel)
|
{
|
var _prefab = InstanceResourcesLoader.LoadModelRes(m_WeaponID);
|
if (_prefab)
|
{
|
GameObjectPoolManager.Instance.ReleaseGameObject(_prefab, m_WeaponModel);
|
m_WeaponModel = null;
|
m_WeaponID = 0;
|
}
|
}
|
|
if (m_SecondaryModel)
|
{
|
var _prefab = InstanceResourcesLoader.LoadModelRes(m_SecondaryID);
|
if (_prefab)
|
{
|
GameObjectPoolManager.Instance.ReleaseGameObject(_prefab, m_SecondaryModel);
|
m_SecondaryModel = null;
|
m_SecondaryID = 0;
|
}
|
}
|
|
if (m_WingModel)
|
{
|
var _animator = m_WingModel.GetComponent<Animator>();
|
if (_animator)
|
{
|
_animator.enabled = false;
|
}
|
var _prefab = InstanceResourcesLoader.LoadModelRes(m_WingID);
|
if (_prefab)
|
{
|
GameObjectPoolManager.Instance.ReleaseGameObject(_prefab, m_WingModel);
|
m_WingModel = null;
|
m_WingID = 0;
|
}
|
}
|
|
if (m_HorseModel)
|
{
|
var _animator = m_HorseModel.GetComponent<Animator>();
|
if (_animator)
|
{
|
_animator.enabled = false;
|
}
|
var _horseConfig = HorseConfig.Get(m_HorseID);
|
var _modelResConfig = ModelResConfig.Get(_horseConfig.Model);
|
var _prefab = InstanceResourcesLoader.LoadModelRes(_modelResConfig.ID);
|
if (_prefab)
|
{
|
GameObjectPoolManager.Instance.ReleaseGameObject(_prefab, m_HorseModel);
|
m_HorseModel = null;
|
m_HorseID = 0;
|
}
|
}
|
|
if (m_NPCInteractProcessor)
|
{
|
m_NPCInteractProcessor.npcIntergactEvent -= OnClick;
|
Object.Destroy(m_NPCInteractProcessor);
|
m_NPCInteractProcessor = null;
|
}
|
TaskModel.Event_TaskResponse -= OnTaskRefresh;
|
m_H0406 = null;
|
|
ReleaseMissionSign();
|
|
base.OnUnit();
|
|
IsUnInit = true;
|
}
|
|
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;
|
|
// 这里判断是否要走向此对象
|
float _distSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, Pos);
|
|
if (PlayerDatas.Instance.baseData.MapID != 31340)
|
{
|
_hero.LockTarget = this;
|
_hero.SelectTarget = this;
|
}
|
else
|
{
|
if (_distSqrt < Mathf.Pow(GeneralDefine.CloseNpcDist + NpcConfig.ModelRadius + 0.4f, 2))
|
{
|
_hero.LockTarget = this;
|
_hero.SelectTarget = this;
|
}
|
}
|
|
if (_distSqrt > Mathf.Pow(GeneralDefine.CloseNpcDist + NpcConfig.ModelRadius + 0.4f, 2))
|
{
|
// MapTransferUtility.Instance.MoveToNPC(NpcConfig.NPCID, (int)ServerInstID);
|
_hero.MoveToPosition(Pos, 1);
|
}
|
else
|
{
|
if (NpcConfig.AutomaticFace == 1)
|
{
|
Vector3 _forward = MathUtility.ForwardXZ(_hero.Pos, Pos);
|
Forward = _forward;
|
}
|
|
HandleOnClick();
|
}
|
}
|
|
protected virtual void HandleOnClick()
|
{
|
NPCInteractProcessor.InvokeEvent(E_NpcType.Func, NpcConfig.NPCID, ServerInstID);
|
}
|
|
protected override void OnLateUpdate() { }
|
|
private float m_PlayDanceTime;
|
|
protected override void OnFixedUpdate()
|
{
|
if (m_HorseModel)
|
{
|
if (Time.realtimeSinceStartup - m_PlayDanceTime > 10)
|
{
|
m_PlayDanceTime = Time.realtimeSinceStartup;
|
NextAction = GAStaticDefine.Act_HorseIdleTransfer;
|
}
|
}
|
}
|
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;
|
}
|
}
|
|
TaskModel m_TaskModel;
|
TaskModel taskmodel
|
{
|
get
|
{
|
return m_TaskModel ?? (m_TaskModel = ModelCenter.Instance.GetModel<TaskModel>());
|
}
|
}
|
|
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);
|
|
if (NpcConfig.NPCID != GeneralDefine.GatherSoulDZ)
|
{
|
_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;
|
}
|
}
|
}
|
}
|
}
|