大江湖-分析篇-战斗

分析篇-战斗

摘要

​本文对战斗实现进行分析,主要涉及以下内容

  • 战斗地图与角色
  • 技能与 buff 机制
  • NPC 战斗 AI
​​

战斗地图

地图分层

与场景大地图相比,战斗地图多了几层

attackselectrange 层

负责展示攻击范围,生成 AtkSelRangePrefab​后将 sortingOrder​设置到这一层

 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
// Assets\Scripts\Assembly-CSharp\BattleObject.cs
protected void Awake()
{
     this.m_SortingOrder_1 = Enumerable.FirstOrDefault<TilemapRenderer>(UnityEngine.Object.FindObjectsOfType<TilemapRenderer>(), delegate (TilemapRenderer s) {
        return s.name == "attackselectrange";
    }).sortingOrder;
}

public void ShowAttackSelectRange(Vector3Int attackPos)
{
    this.ClearAttackSelectRange(true);
 
    foreach (KeyValuePair<Vector3Int, int> pair in dictionary)
    {
        if (!this.battlecontroller.obstacle.Contains(pair.Key))
        {
            this.attackSelectRange.Add(pair.Key, pair.Value);
        }
    }
    foreach (KeyValuePair<Vector3Int, int> pair2 in this.attackSelectRange)
    {
        if (this.m_AttackType[3] == "2")
        {
            this.AtkSelRange = UnityEngine.Object.Instantiate<GameObject>(SharedData.Instance(false).HealSelRangePrefab, this.battlecontroller.map.transform);
        }
        else
        {
            this.AtkSelRange = UnityEngine.Object.Instantiate<GameObject>(SharedData.Instance(false).AtkSelRangePrefab, this.battlecontroller.map.transform);
        }
        this.AtkSelRange.transform.localPosition = new Vector3((float) (0x19 + (pair2.Key.x * 50)), (float) (-25 - (pair2.Key.y * 50)));
        this.AtkSelRangeObject.Add(this.AtkSelRange);
        this.AtkSelRange.GetComponentInChildren<SpriteRenderer>().sortingOrder = (this.m_SortingOrder_1 > 0) ? this.m_SortingOrder_1 : 0;
    }
}

BattleInterBG 层

BattleInterBG​是一个 1X1​的图片,这一层没有看出作用

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// Assets\Scripts\Assembly-CSharp\BattleController.cs
public SpriteRenderer m_BattleInterBG;

private void Awake() {
    this.m_BattleInterBG = this.map.transform.Find("BattleInterBG").GetComponent<SpriteRenderer>();
}

private void Start()
{
    this.m_BattleInterBG.sortingOrder = Enumerable.FirstOrDefault<TilemapRenderer>(UnityEngine.Object.FindObjectsOfType<TilemapRenderer>(), delegate (TilemapRenderer s) {
        return s.name == "BattleInterBG";
    }).sortingOrder;
}

role 层

role​层主要放置环境特效、角色和敌人的位置,朝向

0%