summaryrefslogtreecommitdiff
path: root/Assets/Scripts/AbilitySystem/Conditions/ConditionCommandSeq.cs
blob: 71a7dbf3c5fdfab743a0f3a168100283afd0e557 (plain)
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 一个command序列,用来触发连击
/// </summary>
public class ConditionCommandSeq : ConditionBase
{
	List<GamepadButton> m_CommandSeq = new List<GamepadButton>();
	float m_DeltaTime = 0;
	List<int> m_LastCmdID = new List<int>();

	List<int> id = new List<int>();

	public ConditionCommandSeq(List<GamepadButton> commandSeq, float maxDeltaTime)
    {
		m_CommandSeq.AddRange(commandSeq);
		m_DeltaTime = maxDeltaTime;
    }

    public override bool Evaluate()
    {
		List<Command> commandRecord = InputManager.Instance.CommandRecord;
		if (commandRecord == null || commandRecord.Count < m_CommandSeq.Count)
			return false;
		id.Clear();
		for (int i = 1; i < m_CommandSeq.Count; ++i)
		{
			GamepadButton button = m_CommandSeq[i];
			GamepadButton preButton = m_CommandSeq[i-1];
			int j = commandRecord.Count - m_CommandSeq.Count + i;
			Command cmd = commandRecord[j];
			Command preCmd = commandRecord[j-1];
			if (preCmd.code != preButton || cmd.code != button)
				return false;
			if (cmd.time - preCmd.time > m_DeltaTime)
				return false;
			id.Add(preCmd.id);
			if (j == commandRecord.Count - 1)
				id.Add(cmd.id);
		}

		//for (int i = 0; i < id.Count; ++i)
		//{
		//	if (m_LastCmdID.Contains(id[i]))
		//		return false;
		//}
		//m_LastCmdID.Clear();
		//m_LastCmdID.AddRange(id);

		return true;
    }
}