少年修仙传客户端代码仓库
client_Hale
2019-03-06 5ff8bc18c68f47078a70e19c10ced834e9b9b296
6317 【前端】【2.0】场景化单机战斗 NPCAI
4个文件已添加
283 ■■■■■ 已修改文件
Fight/Actor/AI/AI_Npc_200.cs 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Fight/Actor/AI/AI_Npc_200.cs.meta 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Fight/GameActor/HeroRoundGird.cs 246 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Fight/GameActor/HeroRoundGird.cs.meta 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Fight/Actor/AI/AI_Npc_200.cs
New file
@@ -0,0 +1,13 @@
using UnityEngine;
public class AI_Npc_200 : SampleAI
{
    public AI_Npc_200(GA_NpcClientFightNorm owner, Vector3 bornPosition) : base(owner, bornPosition)
    {
    }
    protected override void OnUpdate()
    {
    }
}
Fight/Actor/AI/AI_Npc_200.cs.meta
New file
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2114dca02aee99b46af602a6576d0fbe
timeCreated: 1551842944
licenseType: Pro
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
Fight/GameActor/HeroRoundGird.cs
New file
@@ -0,0 +1,246 @@
using UnityEngine;
using System.Collections.Generic;
public class HeroRoundGird
{
    public class GirdNode
    {
        public int index;
        public int column;
        public int row;
    }
    private List<GirdNode> m_1 = new List<GirdNode>();
    private List<GirdNode> m_2 = new List<GirdNode>();
    private List<GirdNode> m_3 = new List<GirdNode>();
    private List<GirdNode> m_4 = new List<GirdNode>();
    private Dictionary<int, GirdNode> m_NodeDict = new Dictionary<int, GirdNode>();
    private Dictionary<int, bool> m_NodeEmpty = new Dictionary<int, bool>();
    private float m_Width = 0.5f;
    private float m_Height = 0.5f;
    private int m_Row;
    private int m_Column;
    private float m_OffsetX;
    private float m_OffsetY;
    private float m_Sin45 = .7071f;
    private int m_Half;
    public void Init(int row, int column)
    {
        m_Row = row;
        m_Column = column;
        m_Half = m_Row / 2;
        int _count = m_Half * m_Half;
        for (int i = m_Half; i < m_Row; ++i)
        {
            for (int j = m_Half; j < m_Column; ++j)
            {
                var _node = new GirdNode
                {
                    index = i * m_Column + j,
                    column = j,
                    row = i
                };
                m_1.Add(_node);
                m_NodeDict[_node.index] = _node;
                m_NodeEmpty[_node.index] = true;
            };
        }
        m_1.Sort(_Sort);
        for (int i = m_Half; i < m_Row; ++i)
        {
            for (int j = 0; j < m_Half; ++j)
            {
                var _node = new GirdNode
                {
                    index = i * m_Column + j,
                    column = j,
                    row = i
                };
                m_2.Add(_node);
                m_NodeDict[_node.index] = _node;
                m_NodeEmpty[_node.index] = true;
            }
        }
        m_2.Sort(_Sort);
        for (int i = 0; i < m_Half; ++i)
        {
            for (int j = 0; j < m_Half; ++j)
            {
                var _node = new GirdNode
                {
                    index = i * m_Column + j,
                    column = j,
                    row = i
                };
                m_2.Add(_node);
                m_NodeDict[_node.index] = _node;
                m_NodeEmpty[_node.index] = true;
            }
        }
        m_3.Sort(_Sort);
        for (int i = 0; i < m_Half; ++i)
        {
            for (int j = m_Half; j < m_Column; ++j)
            {
                var _node = new GirdNode
                {
                    index = i * m_Column + j,
                    column = j,
                    row = i
                };
                m_2.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 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;
    }
    public GirdNode Request(Vector3 pos, float limitDis)
    {
        var _hero = PlayerDatas.Instance.hero;
        if (_hero == null)
        {
            return null;
        }
        // 获取行列
        float _x = pos.x + m_OffsetX;
        float _y = pos.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);
        // 距离满足的情况下, 则计算索引
        float _currentDistance = MathUtility.DistanceSqrtXZ(pos, _hero.Pos);
        if (_currentDistance < limitDis * limitDis)
        {
            if (_index >= 0 && _index < m_NodeDict.Count)
            {
                if (m_NodeEmpty[_index])
                {
                    return m_NodeDict[_index];
                }
                else
                {
                    Debug.LogFormat("<color=yellow>监测点: {0}, 索引 {1} 已经被占用...</color>", pos, _index);
                }
            }
            else
            {
                Debug.LogFormat("<color=yellow>监测点: {0}, 索引 {1} 非法...</color>", pos, _index);
            }
        }
        else
        {
            Debug.LogFormat("<color=yellow>监测点: {0}, 距离超出限定距离...</color>", pos, _index);
        }
        byte _quadrant = 0;
        if (pos.x >= _hero.Pos.x && pos.z >= _hero.Pos.z)
        {
            _quadrant = 0;
        }
        else if (pos.x <= _hero.Pos.x && pos.z >= _hero.Pos.z)
        {
            _quadrant = 1;
        }
        else if (pos.x <= _hero.Pos.x && pos.z <= _hero.Pos.z)
        {
            _quadrant = 2;
        }
        else
        {
            _quadrant = 3;
        }
        Debug.LogFormat("监测点: {0}, 相对于玩家处于第 {2} 象限.", pos, (_quadrant + 1));
        float _sideLength = limitDis * m_Sin45;
        switch (_quadrant)
        {
            case 0:
                //   □ │ ■
                //  ───┼───
                //   □ │ □
                for (int i = 0; i < m_1.Count; ++i)
                {
                    if (m_NodeEmpty[m_1[i].index])
                    {
                        m_NodeEmpty[m_1[i].index] = false;
                        return m_1[i];
                    }
                }
                break;
            case 1:
                //   ■ │ □
                //  ───┼───
                //   □ │ □
                for (int i = 0; i < m_2.Count; ++i)
                {
                    if (m_NodeEmpty[m_2[i].index])
                    {
                        m_NodeEmpty[m_2[i].index] = false;
                        return m_2[i];
                    }
                }
                break;
            case 2:
                //   □ │ □
                //  ───┼───
                //   ■ │ □
                for (int i = 0; i < m_3.Count; ++i)
                {
                    if (m_NodeEmpty[m_3[i].index])
                    {
                        m_NodeEmpty[m_3[i].index] = false;
                        return m_3[i];
                    }
                }
                break;
            case 3:
                //   □ │ □
                //  ───┼───
                //   □ │ ■
                for (int i = 0; i < m_4.Count; ++i)
                {
                    if (m_NodeEmpty[m_4[i].index])
                    {
                        m_NodeEmpty[m_4[i].index] = false;
                        return m_4[i];
                    }
                }
                break;
        }
        return null;
    }
    public void Release(int id)
    {
    }
}
Fight/GameActor/HeroRoundGird.cs.meta
New file
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d5b7cc734faa41a4b9319fc8ad226cdd
timeCreated: 1551852723
licenseType: Pro
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant: