forked from mblaine/PkMn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActiveMonster.cs
251 lines (222 loc) · 8.18 KB
/
ActiveMonster.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
using System;
using System.Collections.Generic;
using System.Linq;
using PkMn.Model;
using PkMn.Model.Enums;
using PkMn.Model.MoveEffects;
namespace PkMn.Instance
{
public class ActiveMonster
{
public Trainer Trainer;
protected Monster monster;
public Monster Monster
{
get
{
return monster;
}
set
{
monster = value;
if (monster != null)
{
if (monster.Status == StatusCondition.BadlyPoisoned)
monster.Status = StatusCondition.Poison;
Reset();
Recalc();
HPOnSwitchIn = monster.CurrentHP;
}
}
}
public BattleStats StatStages;
public BattleStats EffectiveStats;
public int MoveIndex;
public int BadlyPoisonedCount;
public int ConfusedCount;
public int DisabledMoveIndex;
public int DisabledCount;
public bool IsSemiInvulnerable;
public bool Flinched;
public bool MoveCancelled;
public bool IsSeeded;
public Move QueuedMove;
public int QueuedMoveLimit;
public int QueuedMoveDamage;
public bool ClearQueuedAfterTurn;
public Element Type1Override;
public Element Type2Override;
public Stats StatsOverride;
public Move[] MovesOverride;
public int[] CurrentPPOverride;
public Species SpeciesOverride;
public Move MoveOverrideTemporary;
public Move LastMoveUsed;
public int AccumulatedDamage;
public int? SubstituteHP;
public int DefenseMultiplier;
public int SpecialDefenseMultiplier;
public bool ProtectStages;
public int HPOnSwitchIn;
public Move SelectedMove
{
get
{
if (Monster == null)
return null;
if (MoveOverrideTemporary != null)
return MoveOverrideTemporary;
if (QueuedMove != null)
return QueuedMove;
if (MoveIndex < 0 || MoveIndex > 3)
return null;
return Moves[MoveIndex];
}
}
public bool IsConfused
{
get
{
return ConfusedCount > 0;
}
}
public Element Type1 { get { return Type1Override ?? Monster.Species.Type1; } }
public Element Type2 { get { return Type1Override != null ? Type2Override : (Type2Override ?? Monster.Species.Type2); } }
public Stats Stats { get { return StatsOverride ?? Monster.Stats; } }
public int[] CurrentPP { get { return CurrentPPOverride ?? Monster.CurrentPP; } }
public Species Species { get { return SpeciesOverride ?? Monster.Species; } }
public Move[] Moves
{
get
{
if (MovesOverride == null)
return Monster.Moves;
else if (MovesOverride.Length == 1)
return Monster.Moves.Select(m => m != null && m.Effects.Any(e => e.Type == MoveEffectType.Copy && ((CopyEffect)e).What == "move") ? MovesOverride[0] : m).ToArray();
else
return MovesOverride;
}
}
public bool HasSelectableMove
{
get
{
KeyValuePair<Move, int>[] moves = Moves.Zip(CurrentPP, (move, pp) => new KeyValuePair<Move, int>(move, pp)).ToArray();
for (int i = 0; i < moves.Length; i++)
if (moves[i].Key != null && moves[i].Value > 0 && i != DisabledMoveIndex)
return true;
return false;
}
}
public bool CancelOpponentsMove
{
get
{
Move m = QueuedMove ?? MoveOverrideTemporary ?? null;
if (m == null)
return false;
return m.Effects.Any(e => e.Type == MoveEffectType.CancelEnemyMove);
}
}
public bool AnyMonstersRemaining
{
get
{
return Trainer.Party.Any(p => p != null && p.CurrentHP > 0);
}
}
public ActiveMonster(Trainer trainer, Monster monster = null)
{
Trainer = trainer;
Monster = monster;
}
public void Reset()
{
StatStages = new BattleStats();
EffectiveStats = new BattleStats();
IsSemiInvulnerable = false;
Flinched = false;
MoveCancelled = false;
ConfusedCount = 0;
BadlyPoisonedCount = 1;
MoveIndex = -1;
DisabledMoveIndex = -1;
DisabledCount = 0;
QueuedMove = null;
QueuedMoveLimit = -1;
QueuedMoveDamage = -1;
Type1Override = null;
Type2Override = null;
StatsOverride = null;
MovesOverride = null;
CurrentPPOverride = null;
MoveOverrideTemporary = null;
SpeciesOverride = null;
LastMoveUsed = null;
AccumulatedDamage = 0;
DefenseMultiplier = 1;
SpecialDefenseMultiplier = 1;
ProtectStages = false;
IsSeeded = false;
SubstituteHP = null;
ClearQueuedAfterTurn = false;
}
public void Recalc(StatType? stat = null)
{
if (stat != null)
{
if(stat == StatType.Evade || stat == StatType.Accuracy)
EffectiveStats[(StatType)stat] = RecalcStat(100, StatStages[(StatType)stat]);
else if (stat != StatType.CritRatio)
EffectiveStats[(StatType)stat] = RecalcStat(Stats[(StatType)stat], StatStages[(StatType)stat]);
}
else
{
EffectiveStats.Attack = RecalcStat(Stats.Attack, StatStages.Attack);
EffectiveStats.Defense = RecalcStat(Stats.Defense, StatStages.Defense);
EffectiveStats.Special = RecalcStat(Stats.Special, StatStages.Special);
EffectiveStats.Speed = RecalcStat(Stats.Speed, StatStages.Speed);
EffectiveStats.Attack = RecalcStat(Stats.Attack, StatStages.Attack);
EffectiveStats.Evade = RecalcStat(100, StatStages.Evade);
EffectiveStats.Accuracy = RecalcStat(100, StatStages.Accuracy);
if(Monster.Status == StatusCondition.Paralysis)
EffectiveStats.Speed = (int)(((decimal)EffectiveStats.Speed) * 0.25m);
if(Monster.Status == StatusCondition.Burn)
EffectiveStats.Attack = (int)(((decimal)EffectiveStats.Attack) * 0.5m);
}
}
protected int RecalcStat(int value, int stage)
{
int ret;
if (stage >= 0)
ret = (int)(value * (1m + 0.5m * stage));
else
ret = (int)(value * (2m / (2m + Math.Abs(stage))));
if (ret < 1)
return 1;
else if (ret > 999)
return 999;
else
return ret;
}
public void DeductPP()
{
if (!Trainer.IsPlayer)
return;
if (MoveOverrideTemporary == null && MoveIndex >= 0 && MoveIndex < 4)
{
if (!Moves[MoveIndex].Effects.Any(e => e.Type == MoveEffectType.NeverDeductPP))
{
if (CurrentPPOverride != null)
CurrentPPOverride[MoveIndex]--;
else
Monster.CurrentPP[MoveIndex]--;
}
}
}
public override string ToString()
{
return Monster.ToString();
}
}
}