-
Notifications
You must be signed in to change notification settings - Fork 15
/
Ruler.cs
157 lines (133 loc) · 4.27 KB
/
Ruler.cs
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
147
148
149
150
151
152
153
154
155
156
157
using HREngine.API;
using HREngine.API.Utilities;
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
namespace HREngine.Bots
{
public class Ruler
{
public enum RuleEntity
{
Enemy,
EnemyMinionField,
Player,
PlayerMinionField
}
public enum RuleMethod
{
GetHealth,
GetAttack,
GetMana,
GetByMinHealth,
GetByMaxHealth,
GetByMinAttack,
GetByMaxAttack,
HasTaunt,
HasCharge,
HasFreeze,
HasCardOnField,
GetNumCardsOnHand,
GetNumCardsOnField,
HasCardOnHand
}
public enum RuleOperator
{
Equal,
LessThan,
LessOrEqualThan,
Greater,
GreaterOrEuqalThan,
NotEqual
}
public static bool isAllowdByRule(string cardID, int target, Playfield p)
{
bool retval = true;
//todo get rule from id
HREngine.Private.HREngineRules hrrules = GetRulesForCard(cardID);
HREngine.Private.RuleCollection playrules = hrrules.PlayRule;
foreach (HREngine.Private.Rule rule in playrules.Rules)
{
}
return retval;
}
public static bool isPlayRuleOK(HREngine.Private.Rule rule, Playfield p)
{
bool retval = true;
RuleEntity entity = (RuleEntity)rule.Entity;
RuleMethod method = (RuleMethod)rule.Method;
// wrong target
if (entity == RuleEntity.PlayerMinionField)
{
List<int> values = new List<int>();
foreach (Minion m in p.ownMinions)
{
if (method == RuleMethod.GetAttack)
{
values.Add(m.Angr);
}
if (method == RuleMethod.GetHealth)
{
values.Add(m.Hp);
}
if (method == RuleMethod.GetMana)
{
values.Add(m.Hp);
}
}
}
if (entity == RuleEntity.EnemyMinionField) return false;
return retval;
}
public static bool HasRule(String CardID)
{
string strFilePath = String.Format("{0}{1}.xml",
HRSettings.Get.CustomRuleFilePath,
CardID.ToUpper());
return File.Exists(strFilePath);
}
public static bool HasRule(HRCard Card)
{
return HasRule(Card.GetEntity().GetCardId());
}
public static bool HasRule(HREntity Card)
{
return HasRule(Card.GetCardId());
}
public static HREngine.Private.HREngineRules GetRulesForCard(String CardID)
{
if (!HasRule(CardID))
return null;
try
{
string strFilePath = String.Format("{0}{1}.xml",
HRSettings.Get.CustomRuleFilePath,
CardID.ToUpper());
byte[] buffer = File.ReadAllBytes(strFilePath);
if (buffer.Length > 0)
{
XmlSerializer serialzer = new XmlSerializer(typeof(HREngine.Private.HREngineRules));
object result = serialzer.Deserialize(new MemoryStream(buffer));
if (result != null)
return (HREngine.Private.HREngineRules)result;
}
}
catch (Exception e)
{
Helpfunctions.Instance.ErrorLog("Exception when deserialize XML Rule.");
Helpfunctions.Instance.ErrorLog(e.Message);
}
return null;
}
public static HREngine.Private.HREngineRules GetRulesForCard(HRCard Card)
{
return GetRulesForCard(Card.GetEntity().GetCardId());
}
public static HREngine.Private.HREngineRules GetRulesForCard(HREntity Card)
{
return GetRulesForCard(Card.GetCardId());
}
}
}