-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathDuel.cs
188 lines (170 loc) · 6.74 KB
/
Duel.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
using System.Collections.Generic;
using YGOSharp.OCGWrapper.Enums;
namespace WindBot.Game
{
public class Duel
{
public bool IsFirst { get; set; }
public bool IsNewRule { get; set; }
public bool IsNewRule2020 { get; set; }
public ClientField[] Fields { get; private set; }
public int Turn { get; set; }
public int Player { get; set; }
public DuelPhase Phase { get; set; }
public MainPhase MainPhase { get; set; }
public BattlePhase BattlePhase { get; set; }
public int LastChainPlayer { get; set; }
public CardLocation LastChainLocation { get; set; }
public IList<ClientCard> CurrentChain { get; set; }
public IList<ClientCard> ChainTargets { get; set; }
public IList<ClientCard> LastChainTargets { get; set; }
public IList<ClientCard> ChainTargetOnly { get; set; }
public int LastSummonPlayer { get; set; }
public IList<ClientCard> SummoningCards { get; set; }
public IList<ClientCard> LastSummonedCards { get; set; }
public int SolvingChainIndex { get; set; }
public IList<int> NegatedChainIndexList { get; set; }
public Duel()
{
Fields = new ClientField[2];
Fields[0] = new ClientField();
Fields[1] = new ClientField();
LastChainPlayer = -1;
LastChainLocation = 0;
CurrentChain = new List<ClientCard>();
ChainTargets = new List<ClientCard>();
LastChainTargets = new List<ClientCard>();
ChainTargetOnly = new List<ClientCard>();
LastSummonPlayer = -1;
SummoningCards = new List<ClientCard>();
LastSummonedCards = new List<ClientCard>();
SolvingChainIndex = 0;
NegatedChainIndexList = new List<int>();
}
public ClientCard GetCard(int player, CardLocation loc, int seq)
{
return GetCard(player, (int)loc, seq, 0);
}
public ClientCard GetCard(int player, int loc, int seq, int subSeq)
{
if (player < 0 || player > 1)
return null;
bool isXyz = (loc & 0x80) != 0;
CardLocation location = (CardLocation)(loc & 0x7f);
IList<ClientCard> cards = null;
switch (location)
{
case CardLocation.Deck:
cards = Fields[player].Deck;
break;
case CardLocation.Hand:
cards = Fields[player].Hand;
break;
case CardLocation.MonsterZone:
cards = Fields[player].MonsterZone;
break;
case CardLocation.SpellZone:
cards = Fields[player].SpellZone;
break;
case CardLocation.Grave:
cards = Fields[player].Graveyard;
break;
case CardLocation.Removed:
cards = Fields[player].Banished;
break;
case CardLocation.Extra:
cards = Fields[player].ExtraDeck;
break;
}
if (cards == null)
return null;
if (seq >= cards.Count)
return null;
if (isXyz)
{
ClientCard card = cards[seq];
if (card == null || subSeq >= card.Overlays.Count)
return null;
return new ClientCard(card.Overlays[subSeq], CardLocation.Overlay, 0, 0);
}
return cards[seq];
}
public void AddCard(CardLocation loc, int cardId, int player, int seq, int pos)
{
ClientCard card = new ClientCard(cardId, loc, seq, pos);
AddCard(loc, card, player, seq, pos, cardId);
}
public void AddCard(CardLocation loc, ClientCard card, int player, int seq, int pos, int id)
{
card.Location = loc;
card.Sequence = seq;
card.Position = pos;
card.Controller = player;
card.SetId(id);
switch (loc)
{
case CardLocation.Hand:
Fields[player].Hand.Add(card);
break;
case CardLocation.Grave:
Fields[player].Graveyard.Add(card);
break;
case CardLocation.Removed:
Fields[player].Banished.Add(card);
break;
case CardLocation.MonsterZone:
Fields[player].MonsterZone[seq] = card;
break;
case CardLocation.SpellZone:
Fields[player].SpellZone[seq] = card;
break;
case CardLocation.Deck:
Fields[player].Deck.Add(card);
break;
case CardLocation.Extra:
Fields[player].ExtraDeck.Add(card);
break;
}
}
public void RemoveCard(CardLocation loc, ClientCard card, int player, int seq)
{
switch (loc)
{
case CardLocation.Hand:
Fields[player].Hand.Remove(card);
break;
case CardLocation.Grave:
Fields[player].Graveyard.Remove(card);
break;
case CardLocation.Removed:
Fields[player].Banished.Remove(card);
break;
case CardLocation.MonsterZone:
Fields[player].MonsterZone[seq] = null;
break;
case CardLocation.SpellZone:
Fields[player].SpellZone[seq] = null;
break;
case CardLocation.Deck:
Fields[player].Deck.Remove(card);
break;
case CardLocation.Extra:
Fields[player].ExtraDeck.Remove(card);
break;
}
}
public int GetLocalPlayer(int player)
{
return IsFirst ? player : 1 - player;
}
public ClientCard GetCurrentSolvingChainCard()
{
if (SolvingChainIndex == 0 || SolvingChainIndex > CurrentChain.Count) return null;
return CurrentChain[SolvingChainIndex - 1];
}
public bool IsCurrentSolvingChainNegated()
{
return SolvingChainIndex > 0 && NegatedChainIndexList.Contains(SolvingChainIndex);
}
}
}