using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
public class PersonalEnemy
|
{
|
public struct BindInfo
|
{
|
public uint npcID;
|
public Vector3 pos;
|
public E_ActorGroup g;
|
public GA_PlayerClient.PlayerInfo playerInfo;
|
}
|
|
public static Dictionary<uint, uint> m_CBinSdDict = new Dictionary<uint, uint>();
|
public static Dictionary<uint, uint> m_SBindCDict = new Dictionary<uint, uint>();
|
|
private static Dictionary<uint, List<BindInfo>> BindInfoDict = new Dictionary<uint, List<BindInfo>>();
|
|
public static UnityEngine.Events.UnityAction<GA_NpcClientFightNorm> OnNpcAppear;
|
public static UnityEngine.Events.UnityAction<GA_PVPClientPlayer> OnPlayerAppear;
|
public static UnityEngine.Events.UnityAction<GA_ILClientPlayer> OnILPlayerAppear;
|
public static UnityEngine.Events.UnityAction<GA_Player> OnMirrorPlayerAppear;
|
public static void UnInit()
|
{
|
m_CBinSdDict.Clear();
|
m_SBindCDict.Clear();
|
BindInfoDict.Clear();
|
}
|
|
public static uint GetPersionEnemySID(uint sid)
|
{
|
uint _objID = 0;
|
if (m_CBinSdDict.TryGetValue(sid, out _objID))
|
{
|
return _objID;
|
}
|
return 0;
|
}
|
|
public static void Create(uint npcID, Vector3 position, GA_PlayerClient.PlayerInfo info,bool isCreate = true)
|
{
|
var _bindInfo = new BindInfo
|
{
|
npcID = npcID,
|
pos = position,
|
playerInfo = info
|
};
|
|
if (!BindInfoDict.ContainsKey(npcID))
|
{
|
BindInfoDict.Add(npcID, new List<BindInfo>());
|
}
|
|
BindInfoDict[npcID].Add(_bindInfo);
|
|
if(isCreate)
|
{
|
var _package = new CB40C_tagCMSummonPriWoodPile();
|
_package.NPCID = npcID;
|
_package.Count = 1;
|
_package.HP = (uint)(info.hp % Constants.ExpPointValue);
|
_package.HPEx = (uint)(info.hp / Constants.ExpPointValue);
|
GameNetSystem.Instance.SendInfo(_package);
|
}
|
else
|
{
|
var _npcPlayer = new H0406_tagNPCAppear();
|
_npcPlayer.NPCID = npcID;
|
_npcPlayer.MaxHP = (uint)(info.hp % Constants.ExpPointValue);
|
_npcPlayer.NPCHP = (uint)(info.hp % Constants.ExpPointValue);
|
_npcPlayer.NPCHPEx = (uint)(info.hp / Constants.ExpPointValue);
|
_npcPlayer.MaxHPEx = (uint)(info.hp / Constants.ExpPointValue);
|
_npcPlayer.ObjID = 99999;
|
_npcPlayer.Speed = 300;
|
GameNetSystem.Instance.PushPackage(_npcPlayer, ServerType.Main);
|
}
|
|
}
|
|
public static void Create(uint npcID, E_ActorGroup group, Vector3 position,
|
uint hp = 0, uint hpex = 0)
|
{
|
var _bindInfo = new BindInfo
|
{
|
npcID = npcID,
|
g = group,
|
pos = position
|
};
|
|
if (!BindInfoDict.ContainsKey(npcID))
|
{
|
BindInfoDict.Add(npcID, new List<BindInfo>());
|
}
|
|
BindInfoDict[npcID].Add(_bindInfo);
|
|
var _package = new CB40C_tagCMSummonPriWoodPile();
|
_package.NPCID = npcID;
|
_package.Count = 1;
|
if (hp == 0 && hpex == 0)
|
{
|
var _npcConfig = NPCConfig.Get((int)npcID);
|
_package.HP = (uint)_npcConfig.DHP;
|
_package.HPEx = (uint)_npcConfig.MaxHPEx;
|
}
|
else
|
{
|
_package.HP = hp;
|
_package.HPEx = hpex;
|
}
|
GameNetSystem.Instance.SendInfo(_package);
|
}
|
|
public static void ReleaseAll()
|
{
|
foreach (var _csid in m_CBinSdDict.Keys)
|
{
|
var _p = new CB40F_tagCMRecyclePriWoodPile();
|
_p.ObjID = m_CBinSdDict[_csid];
|
GameNetSystem.Instance.SendInfo(_p);
|
var _actor = GAMgr.Instance.GetBySID(_csid);
|
if (_actor != null)
|
{
|
GAMgr.Instance.ServerDie(_actor.ServerInstID);
|
GAMgr.Instance.Release(_actor);
|
}
|
}
|
m_CBinSdDict.Clear();
|
m_SBindCDict.Clear();
|
BindInfoDict.Clear();
|
}
|
|
public static void Release(GA_NpcClientFightNorm npc)
|
{
|
uint _psid = 0;
|
if (m_CBinSdDict.TryGetValue(npc.ServerInstID, out _psid))
|
{
|
var _p = new CB40F_tagCMRecyclePriWoodPile();
|
_p.ObjID = _psid;
|
GameNetSystem.Instance.SendInfo(_p);
|
m_CBinSdDict.Remove(npc.ServerInstID);
|
if (m_SBindCDict.ContainsKey(_psid))
|
{
|
m_SBindCDict.Remove(_psid);
|
}
|
}
|
GAMgr.Instance.ServerDie(npc.ServerInstID);
|
GAMgr.Instance.Release(npc);
|
}
|
|
public static void ReleasePlayer(GA_PVPClientPlayer player)
|
{
|
uint _psid = 0;
|
if (m_CBinSdDict.TryGetValue(player.ServerInstID, out _psid))
|
{
|
var _p = new CB40F_tagCMRecyclePriWoodPile();
|
_p.ObjID = _psid;
|
GameNetSystem.Instance.SendInfo(_p);
|
m_CBinSdDict.Remove(player.ServerInstID);
|
if (m_SBindCDict.ContainsKey(_psid))
|
{
|
m_SBindCDict.Remove(_psid);
|
}
|
}
|
GAMgr.Instance.ServerDie(player.ServerInstID);
|
GAMgr.Instance.Release(player);
|
}
|
//ÊÍ·ÅILPlayer
|
public static void ReleaseILPlayer(GA_ILClientPlayer player,bool isDead = true)
|
{
|
uint _psid = 0;
|
if (m_CBinSdDict.TryGetValue(player.ServerInstID, out _psid))
|
{
|
var _p = new CB40F_tagCMRecyclePriWoodPile();
|
_p.ObjID = _psid;
|
GameNetSystem.Instance.SendInfo(_p);
|
m_CBinSdDict.Remove(player.ServerInstID);
|
if (m_SBindCDict.ContainsKey(_psid))
|
{
|
m_SBindCDict.Remove(_psid);
|
}
|
}
|
if(isDead)
|
{
|
GAMgr.Instance.ServerDie(player.ServerInstID);
|
}
|
else
|
{
|
GAMgr.Instance.ServerDieFail(player.ServerInstID);
|
}
|
|
GAMgr.Instance.Release(player);
|
}
|
|
public static void Bind(GA_Player player)
|
{
|
if (ArenaManager.isArenaClient || CrossServerUtility.IsCrossServerOneVsOne())
|
{
|
if (OnMirrorPlayerAppear != null)
|
{
|
OnMirrorPlayerAppear(player);
|
}
|
}
|
}
|
|
public static void Bind(H0406_tagNPCAppear h0406)
|
{
|
Vector3 _pos = PlayerDatas.Instance.hero.Pos;
|
GA_PlayerClient.PlayerInfo playerInfo = default(GA_PlayerClient.PlayerInfo);
|
if (BindInfoDict.ContainsKey(h0406.NPCID) && BindInfoDict[h0406.NPCID].Count > 0)
|
{
|
_pos = BindInfoDict[h0406.NPCID][0].pos;
|
playerInfo = BindInfoDict[h0406.NPCID][0].playerInfo;
|
BindInfoDict[h0406.NPCID].RemoveAt(0);
|
}
|
|
var _config = NPCConfig.Get((int)h0406.NPCID);
|
GA_NpcClientFightNorm _npc = null;
|
GA_PVPClientPlayer _player = null;
|
GA_ILClientPlayer _ILplayer = null;
|
if (_config.NPCType == (int)E_NpcType.PersonalEnemyPVP)
|
{
|
if(ArenaManager.IsArenaClientNotMirrorFight)
|
{
|
_ILplayer = GAMgr.Instance.ReqClntPlayer<GA_ILClientPlayer>(playerInfo, E_ActorGroup.Player);
|
if (_ILplayer != null)
|
{
|
m_CBinSdDict[_ILplayer.ServerInstID] = h0406.ObjID;
|
m_SBindCDict[h0406.ObjID] = _ILplayer.ServerInstID;
|
_ILplayer.ActorInfo.Hp = h0406.NPCHP + h0406.NPCHPEx * Constants.ExpPointValue;
|
_ILplayer.ActorInfo.MaxHp = h0406.MaxHP + h0406.MaxHPEx * Constants.ExpPointValue;
|
_ILplayer.ActorInfo.moveSpeed = 500f / 150;
|
_ILplayer.ActorInfo.LV = playerInfo.level;
|
}
|
if (OnILPlayerAppear != null)
|
{
|
OnILPlayerAppear(_ILplayer);
|
}
|
}
|
else
|
{
|
_player = GAMgr.Instance.ReqClntPlayer<GA_PVPClientPlayer>(playerInfo, E_ActorGroup.Player);
|
if (_player != null)
|
{
|
m_CBinSdDict[_player.ServerInstID] = h0406.ObjID;
|
m_SBindCDict[h0406.ObjID] = _player.ServerInstID;
|
_player.ActorInfo.Hp = h0406.NPCHP + h0406.NPCHPEx * Constants.ExpPointValue;
|
_player.ActorInfo.MaxHp = h0406.MaxHP + h0406.MaxHPEx * Constants.ExpPointValue;
|
_player.ActorInfo.moveSpeed = 500f / 150;
|
_player.ActorInfo.LV = playerInfo.level;
|
}
|
if (OnPlayerAppear != null)
|
{
|
OnPlayerAppear(_player);
|
}
|
}
|
|
}
|
else if (_config.NPCType == (int)E_NpcType.PersonalEnemy)
|
{
|
if (_config.IsBoss != (int)E_MonsterType.Normal
|
&& _config.IsBoss != (int)E_MonsterType.Elite)
|
{
|
_npc = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightBoss>(h0406.NPCID, E_ActorGroup.Enemy);
|
}
|
else
|
{
|
_npc = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightNorm>(h0406.NPCID, E_ActorGroup.Enemy);
|
}
|
|
if (_npc != null)
|
{
|
var _vaildPos = _pos;
|
GActor.TryGetValidPos(_pos, ref _vaildPos);
|
_npc.BornPos = _npc.Pos = _vaildPos;
|
m_CBinSdDict[_npc.ServerInstID] = h0406.ObjID;
|
m_SBindCDict[h0406.ObjID] = _npc.ServerInstID;
|
_npc.ActorInfo.Hp = h0406.NPCHP + h0406.NPCHPEx * Constants.ExpPointValue;
|
_npc.ActorInfo.MaxHp = h0406.MaxHP + h0406.MaxHPEx * Constants.ExpPointValue;
|
_npc.ActorInfo.moveSpeed = 500f / h0406.Speed;
|
_npc.ActorInfo.LV = h0406.CurLV;
|
_npc.RefreshLifeBar(_npc.ActorInfo.RealHp);
|
if (OnNpcAppear != null)
|
{
|
OnNpcAppear(_npc);
|
}
|
}
|
}
|
}
|
|
public static void Bind(H0408_tagPlayerSummonNPCAppear h0408)
|
{
|
Vector3 _pos = PlayerDatas.Instance.hero.Pos;
|
if (BindInfoDict.ContainsKey(h0408.NPCID) && BindInfoDict[h0408.NPCID].Count > 0)
|
{
|
_pos = BindInfoDict[h0408.NPCID][0].pos;
|
BindInfoDict[h0408.NPCID].RemoveAt(0);
|
}
|
|
var _config = NPCConfig.Get((int)h0408.NPCID);
|
GA_NpcClientFightNorm _npc = null;
|
if (_config.IsBoss != (int)E_MonsterType.Normal
|
&& _config.IsBoss != (int)E_MonsterType.Elite)
|
{
|
_npc = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightBoss>(h0408.NPCID, E_ActorGroup.Enemy);
|
}
|
else
|
{
|
_npc = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightNorm>(h0408.NPCID, E_ActorGroup.Enemy);
|
}
|
|
if (_npc != null)
|
{
|
var _vaildPos = _pos;
|
GActor.TryGetValidPos(_pos, ref _vaildPos);
|
_npc.BornPos = _npc.Pos = _vaildPos;
|
m_CBinSdDict[_npc.ServerInstID] = h0408.ObjID;
|
m_SBindCDict[h0408.ObjID] = _npc.ServerInstID;
|
_npc.ActorInfo.Hp = h0408.HP + h0408.HPEx * Constants.ExpPointValue;
|
_npc.ActorInfo.MaxHp = h0408.MaxHP + h0408.MaxHPEx * Constants.ExpPointValue;
|
_npc.ActorInfo.moveSpeed = 500f / h0408.Speed;
|
if (OnNpcAppear != null)
|
{
|
OnNpcAppear(_npc);
|
}
|
}
|
}
|
|
}
|