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

Method doDraw

forge-game/src/main/java/forge/game/player/Player.java:1184–1274  ·  view source on GitHub ↗

@return a CardCollectionView of cards actually drawn

(Map<Player, CardCollection> revealed, SpellAbility sa, Map<AbilityKey, Object> params, PlayerZone hand)

Source from the content-addressed store, hash-verified

1182 * @return a CardCollectionView of cards actually drawn
1183 */
1184 private CardCollectionView doDraw(Map<Player, CardCollection> revealed, SpellAbility sa, Map<AbilityKey, Object> params, PlayerZone hand) {
1185 final CardCollection drawn = new CardCollection();
1186 final PlayerZone library = getZone(ZoneType.Library);
1187
1188 SpellAbility cause = sa;
1189 if (cause != null && cause.isReplacementAbility()) {
1190 cause = (SpellAbility) cause.getReplacingObject(AbilityKey.Cause);
1191 }
1192
1193 final boolean gameStarted = game.getAge().ordinal() > GameStage.Mulligan.ordinal();
1194
1195 if (gameStarted) {
1196 Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(this);
1197 repParams.put(AbilityKey.Cause, cause);
1198 repParams.put(AbilityKey.ExtraDraws, numExtraDrawnThisTurn);
1199 if (params != null) {
1200 repParams.putAll(params);
1201 }
1202 if (game.getReplacementHandler().run(ReplacementType.Draw, repParams) != ReplacementResult.NotReplaced) {
1203 return drawn;
1204 }
1205 }
1206
1207 if (!library.isEmpty()) {
1208 Card c;
1209
1210 if (hasKeyword("You draw cards from the bottom of your library instead of the top of your library.")) {
1211 c = library.get(library.size() - 1);
1212 } else {
1213 c = library.get(0);
1214 }
1215
1216 List<Player> pList = Lists.newArrayList();
1217 for (Player p : getAllOtherPlayers()) {
1218 if (c.mayPlayerLook(p)) {
1219 pList.add(p);
1220 }
1221 }
1222
1223 c = game.getAction().moveTo(hand, c, cause, params);
1224 drawn.add(c);
1225
1226 // CR 121.6c additional actions can't be performed when draw gets replaced
1227 // but "drawn this way" effects should still count them
1228 if (cause != null && "AllReplaced".equals(cause.getParam("RememberDrawn"))) {
1229 cause.getHostCard().addRemembered(drawn);
1230 }
1231
1232 for (Player p : pList) {
1233 if (!revealed.containsKey(p)) {
1234 revealed.put(p, new CardCollection());
1235 }
1236 revealed.get(p).add(c);
1237 }
1238
1239 if (gameStarted) {
1240 setLastDrawnCard(c);
1241 c.setDrawnThisTurn(true);

Callers 1

drawCardsMethod · 0.95

Calls 15

getZoneMethod · 0.95
isReplacementAbilityMethod · 0.95
getReplacingObjectMethod · 0.95
mapFromAffectedMethod · 0.95
hasKeywordMethod · 0.95
getAllOtherPlayersMethod · 0.95
mayPlayerLookMethod · 0.95
setLastDrawnCardMethod · 0.95
setDrawnThisTurnMethod · 0.95
mapFromPlayerMethod · 0.95
getPaidForSAMethod · 0.95
getRootAbilityMethod · 0.95

Tested by

no test coverage detected