| Core/GameEngine/SnxxzGame.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| Fight/Actor/AI/AI_BossDSX.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| Fight/Actor/AI/AI_Npc_200.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| Fight/Actor/AI/SampleAI.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| Fight/Actor/HeroBehaviour.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| Fight/GameActor/GA_NpcClientFightNorm.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| Fight/GameActor/HeroRoundGird.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| Utility/RuntimeLogUtility.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
Core/GameEngine/SnxxzGame.cs
@@ -22,6 +22,7 @@ SpGetBehaviour.Init(); BossAreaMark.Init(); HeroNearDeathBehaviour.Init(); HeroRoundGird.Instance.Init(40, 40); } private void Update() Fight/Actor/AI/AI_BossDSX.cs
@@ -280,7 +280,7 @@ MoveToTarget(); break; case E_AIStatus.MoveToBornPosMin: case E_AIStatus.MoveToBornPos: MoveToBornPosMin(); @@ -346,7 +346,7 @@ _temp = WindowCenter.Instance.uiRoot.baseCanvas.Find("MainInterfaceWin/JoyStick"); _temp.gameObject.SetActive(false); m_Step = 12; m_TimeCount = 0; @@ -379,7 +379,7 @@ } PlayerDatas.Instance.hero.CastSkill(190); if (m_UIEffect) { EffectMgr.Instance.RecyleUIEffect(m_UIEffect.effect, m_UIEffect.gameObject); Fight/Actor/AI/AI_Npc_200.cs
@@ -4,10 +4,246 @@ { public AI_Npc_200(GA_NpcClientFightNorm owner, Vector3 bornPosition) : base(owner, bornPosition) { m_SleepTime = 1; } protected override void OnUpdate() { // ai休眠时间 if (Time.realtimeSinceStartup - m_LastThinkTime < m_SleepTime) { return; } _Thinking(); switch (m_AIStatus) { case E_AIStatus.Patrol: _Patrol(); break; case E_AIStatus.Attack: _Attack(); break; case E_AIStatus.MoveToBornPos: MoveToBornPos(); break; } } private void MoveToBornPos() { var _dis = MathUtility.DistanceSqrtXZ(m_Owner.Pos, BornPos); if (_dis > 0.1f) { m_Owner.MoveToPosition(BornPos); } else { m_AIStatus = E_AIStatus.Patrol; } } private byte atkStep; private Vector3 atkPos; private void _Attack() { GA_Hero _hero = PlayerDatas.Instance.hero; float _dis; // 是否正在释放技能 if (m_Owner.SkillMgr.CurCastSkill != null) { if (m_Owner.SkillMgr.CurCastSkill.SkillCompelete == false) { if (m_Owner.IsIdle()) { m_Owner.SkillMgr.CurCastSkill.SkillCompelete = true; } return; } if (m_Owner.SkillMgr.CurCastSkill.SkillPreparing) { return; } if (m_Owner.NextAction == GAStaticDefine.Act_Warn) { return; } } switch (atkStep) { case 0: var _skill = m_Owner.SkillMgr.Get(m_BaseAtkSkillID); _dis = _skill.skillInfo.config.AtkDist * .5f; if (m_Owner.posIndex != -1) { HeroRoundGird.Instance.Release(m_Owner.posIndex); m_Owner.posIndex = -1; } var _node = HeroRoundGird.Instance.Request(m_Owner.ServerInstID, m_Owner.Pos, _dis); if (_node != null) { atkPos = HeroRoundGird.Instance.GetRealPos(_node); m_Owner.posIndex = _node.index; } _dis = MathUtility.DistanceSqrtXZ(atkPos, m_Owner.Pos); if (_dis < 0.2f) { atkStep = 1; } else { atkStep = 2; } break; case 2: _dis = MathUtility.DistanceSqrtXZ(atkPos, m_Owner.Pos); if (_dis < 0.2f) { atkStep = 0; } else { m_Owner.MoveToPosition(atkPos); } break; case 1: if (Time.realtimeSinceStartup - m_LastAttackTime < m_Owner.NpcConfig.AtkInterval * Constants.F_GAMMA) { return; } m_Owner.CastSkill(m_BaseAtkSkillID); atkStep = 0; m_LastAttackTime = Time.realtimeSinceStartup; break; } } private byte patrolStep; private float patrolWaitTime; private float patrolWaitRandomTime; private Vector3 randomPos; private void _Patrol() { switch (patrolStep) { case 0: patrolWaitRandomTime = Random.Range(2f, 4f); patrolWaitTime = Time.realtimeSinceStartup; patrolStep = 1; break; case 1: if (Time.realtimeSinceStartup - patrolWaitTime > patrolWaitRandomTime) { patrolStep = 2; patrolWaitTime = Time.realtimeSinceStartup; randomPos = BornPos + new Vector3(Random.Range(-2f, 2f), 0, Random.Range(-2f, 2f)); GActor.TryGetValidPos(randomPos, ref randomPos); m_Owner.MoveToPosition(randomPos); } break; case 2: if (Time.realtimeSinceStartup - patrolWaitTime > 2) { patrolStep = 1; } break; } } private void _Thinking() { if (m_AIStatus == E_AIStatus.MoveToBornPos) { return; } float _compareDis; // 思考 var _hero = PlayerDatas.Instance.hero; if (_hero == null || _hero.ActorInfo.serverDie) { // 主角不存在或者死亡了 // 在出生点附近 _compareDis = MathUtility.DistanceSqrtXZ(BornPos, m_Owner.Pos); if (_compareDis < 4) { m_AIStatus = E_AIStatus.Patrol; } // 巡逻 // 不在出生点附近 else { // 回到出生点 m_AIStatus = E_AIStatus.MoveToBornPos; } } else { _compareDis = MathUtility.DistanceSqrtXZ(m_Owner.Pos, BornPos); if (_compareDis > m_KeepBornDistSqrt) { m_AIStatus = E_AIStatus.MoveToBornPos; } else { // 玩家在可见范围内 _compareDis = MathUtility.DistanceSqrtXZ(m_Owner.Pos, _hero.Pos); if (_compareDis < m_KeepBornDistSqrt) { // 标识是否执行攻击逻辑 bool _doAttack = false; // 自己是主动怪 if (m_Owner.NpcConfig.AtkType == 0) { _doAttack = true; } else { if (m_Owner.heroAttacked) { _doAttack = true; } } if (_doAttack) { m_AIStatus = E_AIStatus.Attack; } else { // 主角不存在或者死亡了 // 在出生点附近 _compareDis = MathUtility.DistanceSqrtXZ(BornPos, m_Owner.Pos); if (_compareDis < 4) { m_AIStatus = E_AIStatus.Patrol; } // 巡逻 // 不在出生点附近 else { // 回到出生点 m_AIStatus = E_AIStatus.MoveToBornPos; } } } else { m_AIStatus = E_AIStatus.Patrol; } } } } } Fight/Actor/AI/SampleAI.cs
@@ -8,7 +8,7 @@ Patrol,// 巡逻 MoveToTarget,// 向目标移动 Attack,// 攻击 MoveToBornPosMin,// 向出生点一段距离 MoveToBornPos,// 向出生点移动 } public Vector3 BornPos; @@ -202,7 +202,7 @@ if (_distSqrt < 2) { m_MinPos = m_Owner.Pos + (BornPos - m_Owner.Pos).normalized * 2f; m_AIStatus = E_AIStatus.MoveToBornPosMin; m_AIStatus = E_AIStatus.MoveToBornPos; return; } } Fight/Actor/HeroBehaviour.cs
@@ -875,6 +875,11 @@ _hurtObject.HurtHP = _hurtValue; _hurtObject.AttackType = _attackType; var _clientNpc = _target as GA_NpcClientFightNorm; if (_clientNpc != null) { _clientNpc.heroAttacked = true; } skill.hurtClntFightNpcList.Add(_hurtObject); @@ -894,8 +899,8 @@ m_Hero.SelectTarget = null; } var _clientNpc = _target as GA_NpcClientFightNorm; if (_clientNpc.belongEventID != -1) if (_clientNpc != null && _clientNpc.belongEventID != -1) { ClientSceneManager.Instance.NpcDead(_clientNpc.belongEventID, _clientNpc); } Fight/GameActor/GA_NpcClientFightNorm.cs
@@ -50,6 +50,12 @@ protected SampleAI m_AIHandler; /// <summary> /// 是否被英雄攻击了 /// </summary> public bool heroAttacked; public int posIndex = -1; protected override void OnInit(GameNetPackBasic package) { base.OnInit(package); @@ -73,10 +79,12 @@ // 战斗类型的怪物随机朝向 Rotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 360), 0); if (NpcConfig.IsBoss <= 1 && NpcConfig.AIType != 201) if (NpcConfig.IsBoss <= 1 && NpcConfig.AIType == 1) { m_AIHandler = new AI_Normal(this, BornPos); m_AIHandler = new AI_Npc_200(this, BornPos); } heroAttacked = false; } public override void OnClick() @@ -137,7 +145,11 @@ } belongEventID = -1; if (posIndex != -1) { HeroRoundGird.Instance.Release(posIndex); posIndex = -1; } base.OnUnit(); } Fight/GameActor/HeroRoundGird.cs
@@ -1,13 +1,15 @@ using UnityEngine; using System.Collections.Generic; public class HeroRoundGird public class HeroRoundGird : Singleton<HeroRoundGird> { public class GirdNode { public int index; public int column; public int row; public float dis; public uint ownerSID; } private List<GirdNode> m_1 = new List<GirdNode>(); @@ -25,13 +27,59 @@ private float m_Sin45 = .7071f; private int m_Half; public Vector3 GetRealPos(GirdNode node) { var _hero = PlayerDatas.Instance.hero; if (_hero != null) { return new Vector3(node.column * m_Width, 0, node.row * m_Height) + _hero.Pos - new Vector3(m_Half * m_Width, 0, m_Half * m_Height); } return Vector3.zero; } public GirdNode Get(int row, int column) { var _index = row * m_Column + column; if (m_NodeDict.ContainsKey(_index)) { return m_NodeDict[_index]; } return null; } public void UnInit() { m_1.Clear(); m_2.Clear(); m_3.Clear(); m_4.Clear(); m_NodeDict.Clear(); m_NodeEmpty.Clear(); } private bool m_Inited = false; public void Init(int row, int column) { if (m_Inited) { return; } m_Inited = true; m_1.Clear(); m_2.Clear(); m_3.Clear(); m_4.Clear(); m_Row = row; m_Column = column; m_Half = m_Row / 2; int _count = m_Half * m_Half; m_OffsetX = column * m_Width * .5f; m_OffsetY = row * m_Height * .5f; for (int i = m_Half; i < m_Row; ++i) { @@ -41,8 +89,9 @@ { index = i * m_Column + j, column = j, row = i row = i, }; _node.dis = GetDistance(_node); m_1.Add(_node); m_NodeDict[_node.index] = _node; m_NodeEmpty[_node.index] = true; @@ -59,6 +108,7 @@ column = j, row = i }; _node.dis = GetDistance(_node); m_2.Add(_node); m_NodeDict[_node.index] = _node; m_NodeEmpty[_node.index] = true; @@ -75,7 +125,8 @@ column = j, row = i }; m_2.Add(_node); _node.dis = GetDistance(_node); m_3.Add(_node); m_NodeDict[_node.index] = _node; m_NodeEmpty[_node.index] = true; } @@ -91,81 +142,99 @@ column = j, row = i }; m_2.Add(_node); _node.dis = GetDistance(_node); m_4.Add(_node); m_NodeDict[_node.index] = _node; m_NodeEmpty[_node.index] = true; } } m_4.Sort(_Sort); m_OffsetX = -column * m_Width * .5f; m_OffsetY = -row * m_Height * .5f; } private float GetDistance(GirdNode n) { var _r = (n.row - m_Half) * m_Height; var _c = (n.column - m_Half) * m_Width; return Mathf.Sqrt(_c * _c + _r * _r); } private int _Sort(GirdNode a, GirdNode b) { var _r = a.row - m_Half; var _c = a.column - m_Half; var _d1 = _c * _c + _r + _r; _r = b.row - m_Half; _c = b.column - m_Half; var _d2 = _c * _c + _r + _r; return _d2 > _d1 ? -1 : 1; if (a.dis > b.dis) { return -1; } else if (a.dis < b.dis) { return 1; } return 0; } public GirdNode Request(Vector3 pos, float limitDis) public GirdNode Request(uint sid, Vector3 pos, float limitDis) { var _hero = PlayerDatas.Instance.hero; if (_hero == null) { return null; } Vector3 _chkCenter = _hero.Pos; // 获取行列 float _x = pos.x + m_OffsetX; float _y = pos.z + m_OffsetY; float _x = pos.x - _chkCenter.x + m_OffsetX; float _y = pos.z - _chkCenter.z + m_OffsetY; int _column = (int)(_x / m_Width); int _row = (int)(_y / m_Height); int _index = _row * _column; Debug.LogFormat("监测点: {0}, 所处行: {1}, 列: {2}, 当前对应索引 {3}", pos, _row, _column, _index); // Debug.LogFormat("计算得出: row: {1}, column: {0}", _row, _column); int _index = _row * m_Column + _column; // Debug.LogFormat("监测点: {0}, 所处行: {1}, 列: {2}, 当前对应索引 {3}", pos, _row, _column, _index); // 距离满足的情况下, 则计算索引 float _currentDistance = MathUtility.DistanceSqrtXZ(pos, _hero.Pos); float _currentDistance = MathUtility.DistanceSqrtXZ(pos, _chkCenter); if (_currentDistance < limitDis * limitDis) { if (_index >= 0 && _index < m_NodeDict.Count) { if (m_NodeEmpty[_index]) { m_NodeEmpty[_index] = false; m_NodeDict[_index].ownerSID = sid; return m_NodeDict[_index]; } else { Debug.LogFormat("<color=yellow>监测点: {0}, 索引 {1} 已经被占用...</color>", pos, _index); if (m_NodeDict[_index].ownerSID == sid) { return m_NodeDict[_index]; } // Debug.LogFormat("<color=yellow>监测点: {0}, 索引 {1} 已经被占用...</color>", pos, _index); } } else { Debug.LogFormat("<color=yellow>监测点: {0}, 索引 {1} 非法...</color>", pos, _index); // Debug.LogFormat("<color=yellow>监测点: {0}, 索引 {1} 非法...</color>", pos, _index); } } else { Debug.LogFormat("<color=yellow>监测点: {0}, 距离超出限定距离...</color>", pos, _index); // Debug.LogFormat("<color=yellow>监测点: {0}, 距离超出限定距离...</color>", pos, _index); } byte _quadrant = 0; if (pos.x >= _hero.Pos.x && pos.z >= _hero.Pos.z) if (pos.x >= _chkCenter.x && pos.z >= _chkCenter.z) { _quadrant = 0; } else if (pos.x <= _hero.Pos.x && pos.z >= _hero.Pos.z) else if (pos.x <= _chkCenter.x && pos.z >= _chkCenter.z) { _quadrant = 1; } else if (pos.x <= _hero.Pos.x && pos.z <= _hero.Pos.z) else if (pos.x <= _chkCenter.x && pos.z <= _chkCenter.z) { _quadrant = 2; } @@ -174,9 +243,9 @@ _quadrant = 3; } Debug.LogFormat("监测点: {0}, 相对于玩家处于第 {2} 象限.", pos, (_quadrant + 1)); // Debug.LogFormat("监测点: {0}, 相对于玩家处于第 {1} 象限.", pos, (_quadrant + 1)); float _sideLength = limitDis * m_Sin45; GirdNode _node; switch (_quadrant) { @@ -186,10 +255,23 @@ // □ │ □ for (int i = 0; i < m_1.Count; ++i) { if (m_NodeEmpty[m_1[i].index]) _node = m_1[i]; if (_node.dis >= limitDis) { m_NodeEmpty[m_1[i].index] = false; return m_1[i]; continue; } if (m_NodeEmpty[_node.index]) { _node.ownerSID = sid; m_NodeEmpty[_node.index] = false; return _node; } else { if (m_NodeDict[_node.index].ownerSID == sid) { return m_NodeDict[_node.index]; } } } @@ -200,10 +282,23 @@ // □ │ □ for (int i = 0; i < m_2.Count; ++i) { if (m_NodeEmpty[m_2[i].index]) _node = m_2[i]; if (_node.dis >= limitDis) { m_NodeEmpty[m_2[i].index] = false; return m_2[i]; continue; } if (m_NodeEmpty[_node.index]) { _node.ownerSID = sid; m_NodeEmpty[_node.index] = false; return _node; } else { if (m_NodeDict[_node.index].ownerSID == sid) { return m_NodeDict[_node.index]; } } } @@ -214,10 +309,23 @@ // ■ │ □ for (int i = 0; i < m_3.Count; ++i) { if (m_NodeEmpty[m_3[i].index]) _node = m_3[i]; if (_node.dis >= limitDis) { m_NodeEmpty[m_3[i].index] = false; return m_3[i]; continue; } if (m_NodeEmpty[_node.index]) { _node.ownerSID = sid; m_NodeEmpty[_node.index] = false; return _node; } else { if (m_NodeDict[_node.index].ownerSID == sid) { return m_NodeDict[_node.index]; } } } break; @@ -227,10 +335,23 @@ // □ │ ■ for (int i = 0; i < m_4.Count; ++i) { if (m_NodeEmpty[m_4[i].index]) _node = m_4[i]; if (_node.dis >= limitDis) { m_NodeEmpty[m_4[i].index] = false; return m_4[i]; continue; } if (m_NodeEmpty[_node.index]) { _node.ownerSID = sid; m_NodeEmpty[_node.index] = false; return _node; } else { if (m_NodeDict[_node.index].ownerSID == sid) { return m_NodeDict[_node.index]; } } } break; @@ -241,6 +362,11 @@ public void Release(int id) { if (!m_NodeEmpty.ContainsKey(id)) { return; } m_NodeEmpty[id] = true; m_NodeDict[id].ownerSID = 0; } } Utility/RuntimeLogUtility.cs
@@ -237,38 +237,42 @@ if (GUILayout.Button("创建PVP敌方")) { GActorPlayerBase.PlayerInfo _playerInfo = new GActorPlayerBase.PlayerInfo(); _playerInfo.maxHp = (uint)PlayerDatas.Instance.extersion.MaxMP; _playerInfo.hp = _playerInfo.maxHp; _playerInfo.level = 200; _playerInfo.job = 1; _playerInfo.name = "机器人"; var _npc = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightNorm>(10101003, E_ActorGroup.Enemy); _npc.BornPos = _npc.Pos = PlayerDatas.Instance.hero.Pos; _npc.ActorInfo.ResetHp(9999999, -1, 9999999); _playerInfo.itemDatas = new GActorPlayerBase.CEquipInfo[4]; // GActorPlayerBase.PlayerInfo _playerInfo = new GActorPlayerBase.PlayerInfo(); // _playerInfo.maxHp = (uint)PlayerDatas.Instance.extersion.MaxMP; // _playerInfo.hp = _playerInfo.maxHp; // _playerInfo.level = 200; // _playerInfo.job = 1; // _playerInfo.name = "机器人"; // 10484, 10481, 10482, 3713 _playerInfo.itemDatas[0] = new GActorPlayerBase.CEquipInfo { id = 10484, place = (int)RoleEquipType.Clothes }; _playerInfo.itemDatas[1] = new GActorPlayerBase.CEquipInfo { id = 10481, place = (int)RoleEquipType.Weapon }; _playerInfo.itemDatas[2] = new GActorPlayerBase.CEquipInfo { id = 10482, place = (int)RoleEquipType.Weapon2 }; _playerInfo.itemDatas[3] = new GActorPlayerBase.CEquipInfo { id = 3713, place = (int)RoleEquipType.Wing }; // _playerInfo.itemDatas = new GActorPlayerBase.CEquipInfo[4]; GAMgr.Instance.ReqClntPlayer<GA_PVPClientPlayer>(_playerInfo, E_ActorGroup.Player); // // 10484, 10481, 10482, 3713 // _playerInfo.itemDatas[0] = new GActorPlayerBase.CEquipInfo // { // id = 10484, // place = (int)RoleEquipType.Clothes // }; // _playerInfo.itemDatas[1] = new GActorPlayerBase.CEquipInfo // { // id = 10481, // place = (int)RoleEquipType.Weapon // }; // _playerInfo.itemDatas[2] = new GActorPlayerBase.CEquipInfo // { // id = 10482, // place = (int)RoleEquipType.Weapon2 // }; // _playerInfo.itemDatas[3] = new GActorPlayerBase.CEquipInfo // { // id = 3713, // place = (int)RoleEquipType.Wing // }; // GAMgr.Instance.ReqClntPlayer<GA_PVPClientPlayer>(_playerInfo, E_ActorGroup.Player); } if (GUILayout.Button("重置PVP敌方"))