少年修仙传客户端代码仓库
client_linchunjie
2018-09-14 a0ede150686a218c92b901b1f20aef12a9913890
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System.Collections.Generic;
using UnityEngine;
 
public enum E_HeroAIType
{
    None,
    NormalAuto,
    D2_LockMissionTarget,
    D3_BackToStartPos,
    D4_QLZF,
    D5_Hlyy,
    D6_RandomPoint,
    D7_ZMSL,
    KillUntilDie = 99,
}
 
public class HeroAIHandler
{
    private Dictionary<byte, HeroAI_Base> m_AIDict = null;
    public Dictionary<byte, HeroAI_Data> aiData = null;
    private List<byte> m_AIList = null;
 
    private HeroAI_Base m_Default = null;
    private HeroAI_Base m_Current = null;
    public E_HeroAIType currentType;
 
    public int PriorityNpcID;
 
    public HeroAIHandler()
    {
        m_AIList = new List<byte>();
        m_AIDict = new Dictionary<byte, HeroAI_Base>();
        aiData = new Dictionary<byte, HeroAI_Data>();
 
        m_AIList.Add((byte)E_HeroAIType.KillUntilDie);
        m_AIDict.Add((byte)E_HeroAIType.KillUntilDie,
                      new HeroAI_KillUntilDie());
        aiData.Add((byte)E_HeroAIType.KillUntilDie,
                    new KillUntilDieData());
 
        m_AIList.Add((byte)E_HeroAIType.NormalAuto);
        m_AIDict.Add((byte)E_HeroAIType.NormalAuto,
                      new HeroAI_NormalAuto());
 
        m_AIList.Add((byte)E_HeroAIType.D2_LockMissionTarget);
        m_AIDict.Add((byte)E_HeroAIType.D2_LockMissionTarget,
                      new HeroAI_D2_LockMissionTarget());
 
        m_AIList.Add((byte)E_HeroAIType.D3_BackToStartPos);
        m_AIDict.Add((byte)E_HeroAIType.D3_BackToStartPos,
                      new HeroAI_D3_BackToStartPos());
 
        m_AIList.Add((byte)E_HeroAIType.D4_QLZF);
        m_AIDict.Add((byte)E_HeroAIType.D4_QLZF,
                      new HeroAI_D4_Qlzf());
 
        m_AIList.Add((byte)E_HeroAIType.D5_Hlyy);
        m_AIDict.Add((byte)E_HeroAIType.D5_Hlyy,
                      new HeroAI_D5_Hlyy());
 
        m_AIList.Add((byte)E_HeroAIType.D6_RandomPoint);
        m_AIDict.Add((byte)E_HeroAIType.D6_RandomPoint,
                      new HeroAI_D6_NearestPoint());
 
        m_AIList.Add((byte)E_HeroAIType.D7_ZMSL);
        m_AIDict.Add((byte)E_HeroAIType.D7_ZMSL,
                      new HeroAI_D7_Hlyy());
 
        currentType = E_HeroAIType.None;
    }
 
    public void Update()
    {
        HeroAI_Base _chk = null;
        byte _aiType;
 
        if (m_Current != null)
        {
            // 当前状态更新
            m_Current.Update();
 
            // 如果当前状态结束
            if (!m_Current.IsOver())
            {
                return;
            }
 
            // 已经执行完毕, 退出状态
            m_Current.Exit();
            m_Current = null;
            currentType = E_HeroAIType.None;
        }
 
        // 遍历所有状态, 决定此次进入哪个状态
        for (int i = 0; i < m_AIList.Count; ++i)
        {
            _aiType = m_AIList[i];
            _chk = m_AIDict[_aiType];
 
            if (m_Current != _chk)
            {
                // 判断每个AI状态是否达到进入条件
                if (m_AIDict[_aiType].Condition())
                {
                    // 是否存在旧的状态
                    if (m_Current != null)
                    {
                        // 执行退出
                        m_Current.Exit();
                    }
 
                    // 设置当前状态
                    m_Current = m_AIDict[_aiType];
                    // 进入
                    m_Current.Enter();
 
                    break;
                }
            }
        }
    }
 
    public bool IsAuto()
    {
        return currentType >= E_HeroAIType.NormalAuto
            && currentType < E_HeroAIType.KillUntilDie;
    }
 
    public bool IsPause()
    {
        if (!IsAuto())
        {
            return false;
        }
 
        HeroAI_Auto _auto = m_Current as HeroAI_Auto;
 
        if (_auto == null
        || !_auto.IsPause())
        {
            return false;
        }
 
        return true;
    }
}