MCPcopy Create free account
hub / github.com/Card-Forge/forge / initFromGame

Method initFromGame

forge-game/src/main/java/forge/game/GameState.java:158–231  ·  view source on GitHub ↗
(Game game)

Source from the content-addressed store, hash-verified

156 }
157
158 public void initFromGame(Game game) {
159 playerStates.clear();
160 for (Player player : game.getPlayers()) {
161 PlayerState p = new PlayerState();
162 p.life = player.getLife();
163 p.landsPlayed = player.getLandsPlayedThisTurn();
164 p.landsPlayedLastTurn = player.getLandsPlayedLastTurn();
165 p.counters = countersToString(player.getCounters());
166 p.manaPool = processManaPool(player.getManaPool());
167 p.numRingTemptedYou = player.getNumRingTemptedYou();
168 p.speed = player.getSpeed();
169 playerStates.add(p);
170 }
171
172 tChangePlayer = "p" + game.getPlayers().indexOf(game.getPhaseHandler().getPlayerTurn());
173 tChangePhase = game.getPhaseHandler().getPhase().toString();
174 turn = game.getPhaseHandler().getTurn();
175
176 // Mark the cards that need their ID remembered for various reasons
177 cardsReferencedByID.clear();
178 for (ZoneType zone : ZONES.keySet()) {
179 for (Card card : game.getCardsIncludePhasingIn(zone)) {
180 if (card.getExiledWith() != null) {
181 // Remember the ID of the card that exiled this card
182 cardsReferencedByID.add(card.getExiledWith());
183 }
184 if (zone == ZoneType.Battlefield) {
185 if (!card.getAllAttachedCards().isEmpty()) {
186 // Remember the ID of cards that have attachments
187 cardsReferencedByID.add(card);
188 }
189 }
190 for (Object o : card.getRemembered()) {
191 // Remember the IDs of remembered cards
192 if (o instanceof Card) {
193 cardsReferencedByID.add((Card)o);
194 }
195 }
196 for (Card i : card.getImprintedCards()) {
197 // Remember the IDs of imprinted cards
198 cardsReferencedByID.add(i);
199 }
200 for (Card i : card.getChosenCards()) {
201 // Remember the IDs of chosen cards
202 cardsReferencedByID.add(i);
203 }
204 if (game.getCombat() != null && game.getCombat().isAttacking(card)) {
205 // Remember the IDs of attacked planeswalkers
206 GameEntity def = game.getCombat().getDefenderByAttacker(card);
207 if (def instanceof Card) {
208 cardsReferencedByID.add((Card)def);
209 }
210 }
211 }
212 }
213
214 for (ZoneType zone : ZONES.keySet()) {
215 // Init texts to empty, so that restoring will clear the state

Callers 2

dumpGameStateMethod · 0.95
updatePhaseMethod · 0.80

Calls 15

countersToStringMethod · 0.95
processManaPoolMethod · 0.95
addCardMethod · 0.95
getManaPoolMethod · 0.80
getNumRingTemptedYouMethod · 0.80
getPhaseHandlerMethod · 0.80
getDefenderByAttackerMethod · 0.80
addMethod · 0.65
indexOfMethod · 0.65

Tested by

no test coverage detected