Cleaning out playing event action.

This commit is contained in:
marcins78
2013-01-07 11:31:19 +00:00
parent 18ef4c9911
commit c7383efbe8
16 changed files with 218 additions and 26 deletions

View File

@@ -151,8 +151,7 @@ public class PlayEventAction extends AbstractCostToEffectAction implements Disco
if (!_cardDiscarded && !_skipDiscardCard) {
_cardDiscarded = true;
if (_eventPlayed.getZone() != null)
game.getGameState().removeCardsFromZone(_eventPlayed.getOwner(), Collections.singleton(_eventPlayed));
game.getGameState().removeCardsFromZone(_eventPlayed.getOwner(), Collections.singleton(_eventPlayed));
game.getGameState().addCardToZone(game, _eventPlayed, Zone.DISCARD);
}

View File

@@ -7,8 +7,6 @@ import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.effects.PlayCardEffect;
import java.util.Collections;
public class PlayEventEffect extends PlayCardEffect {
private PhysicalCard _cardPlayed;
private PlayEventResult _playEventResult;
@@ -25,8 +23,6 @@ public class PlayEventEffect extends PlayCardEffect {
@Override
protected FullEffectResult playEffectReturningResult(LotroGame game) {
if (_cardPlayed.getZone() != null)
game.getGameState().removeCardsFromZone(_cardPlayed.getOwner(), Collections.singleton(_cardPlayed));
game.getActionsEnvironment().emitEffectResult(_playEventResult);
return new FullEffectResult(true);
}

View File

@@ -2,10 +2,13 @@ package com.gempukku.lotro.cards.effects;
import com.gempukku.lotro.cards.actions.PlayEventAction;
import com.gempukku.lotro.common.Zone;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.GameUtils;
import com.gempukku.lotro.logic.timing.AbstractEffect;
import java.util.Collections;
public class PutPlayedEventIntoHandEffect extends AbstractEffect {
private PlayEventAction _action;
@@ -31,9 +34,11 @@ public class PutPlayedEventIntoHandEffect extends AbstractEffect {
@Override
protected FullEffectResult playEffectReturningResult(LotroGame game) {
if (isPlayableInFull(game)) {
game.getGameState().sendMessage(_action.getPerformingPlayer() + " puts " + GameUtils.getCardLink(_action.getEventPlayed()) + " into hand");
PhysicalCard eventPlayed = _action.getEventPlayed();
game.getGameState().sendMessage(_action.getPerformingPlayer() + " puts " + GameUtils.getCardLink(eventPlayed) + " into hand");
_action.skipDiscardPart();
game.getGameState().addCardToZone(game, _action.getEventPlayed(), Zone.HAND);
game.getGameState().removeCardsFromZone(eventPlayed.getOwner(), Collections.singletonList(eventPlayed));
game.getGameState().addCardToZone(game, eventPlayed, Zone.HAND);
return new FullEffectResult(true);
}
return new FullEffectResult(false);

View File

@@ -2,10 +2,13 @@ package com.gempukku.lotro.cards.effects;
import com.gempukku.lotro.cards.actions.PlayEventAction;
import com.gempukku.lotro.common.Zone;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.GameUtils;
import com.gempukku.lotro.logic.timing.AbstractEffect;
import java.util.Collections;
public class PutPlayedEventOnBottomOfDeckEffect extends AbstractEffect {
private PlayEventAction _action;
@@ -31,9 +34,11 @@ public class PutPlayedEventOnBottomOfDeckEffect extends AbstractEffect {
@Override
protected FullEffectResult playEffectReturningResult(LotroGame game) {
if (isPlayableInFull(game)) {
game.getGameState().sendMessage(_action.getPerformingPlayer() + " puts " + GameUtils.getCardLink(_action.getEventPlayed()) + " on bottom of his/her deck");
PhysicalCard eventPlayed = _action.getEventPlayed();
game.getGameState().sendMessage(_action.getPerformingPlayer() + " puts " + GameUtils.getCardLink(eventPlayed) + " on bottom of his/her deck");
_action.skipDiscardPart();
game.getGameState().putCardOnBottomOfDeck(_action.getEventPlayed());
game.getGameState().removeCardsFromZone(eventPlayed.getOwner(), Collections.singletonList(eventPlayed));
game.getGameState().putCardOnBottomOfDeck(eventPlayed);
return new FullEffectResult(true);
}
return new FullEffectResult(false);

View File

@@ -2,10 +2,13 @@ package com.gempukku.lotro.cards.effects;
import com.gempukku.lotro.cards.actions.PlayEventAction;
import com.gempukku.lotro.common.Zone;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.GameUtils;
import com.gempukku.lotro.logic.timing.AbstractEffect;
import java.util.Collections;
public class PutPlayedEventOnTopOfDeckEffect extends AbstractEffect {
private PlayEventAction _action;
@@ -31,9 +34,11 @@ public class PutPlayedEventOnTopOfDeckEffect extends AbstractEffect {
@Override
protected FullEffectResult playEffectReturningResult(LotroGame game) {
if (isPlayableInFull(game)) {
game.getGameState().sendMessage(_action.getPerformingPlayer() + " puts " + GameUtils.getCardLink(_action.getEventPlayed()) + " on top of his/her deck");
PhysicalCard eventPlayed = _action.getEventPlayed();
game.getGameState().sendMessage(_action.getPerformingPlayer() + " puts " + GameUtils.getCardLink(eventPlayed) + " on top of his/her deck");
_action.skipDiscardPart();
game.getGameState().putCardOnTopOfDeck(_action.getEventPlayed());
game.getGameState().removeCardsFromZone(eventPlayed.getOwner(), Collections.singletonList(eventPlayed));
game.getGameState().putCardOnTopOfDeck(eventPlayed);
return new FullEffectResult(true);
}
return new FullEffectResult(false);

View File

@@ -2,10 +2,13 @@ package com.gempukku.lotro.cards.effects;
import com.gempukku.lotro.cards.actions.PlayEventAction;
import com.gempukku.lotro.common.Zone;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.GameUtils;
import com.gempukku.lotro.logic.timing.AbstractEffect;
import java.util.Collections;
public class RemovePlayedEventFromGameEffect extends AbstractEffect {
private PlayEventAction _action;
@@ -31,9 +34,11 @@ public class RemovePlayedEventFromGameEffect extends AbstractEffect {
@Override
protected FullEffectResult playEffectReturningResult(LotroGame game) {
if (isPlayableInFull(game)) {
game.getGameState().sendMessage(_action.getPerformingPlayer() + " removes " + GameUtils.getCardLink(_action.getEventPlayed()) + " from the game");
PhysicalCard eventPlayed = _action.getEventPlayed();
game.getGameState().sendMessage(_action.getPerformingPlayer() + " removes " + GameUtils.getCardLink(eventPlayed) + " from the game");
_action.skipDiscardPart();
game.getGameState().addCardToZone(game, _action.getEventPlayed(), Zone.REMOVED);
game.getGameState().removeCardsFromZone(eventPlayed.getOwner(), Collections.singletonList(eventPlayed));
game.getGameState().addCardToZone(game, eventPlayed, Zone.REMOVED);
return new FullEffectResult(true);
}
return new FullEffectResult(false);

View File

@@ -7,6 +7,8 @@ import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.GameUtils;
import com.gempukku.lotro.logic.timing.AbstractEffect;
import java.util.Collections;
public class StackPlayedEventOnACardEffect extends AbstractEffect {
private PlayEventAction _action;
private PhysicalCard _stackOn;
@@ -34,9 +36,11 @@ public class StackPlayedEventOnACardEffect extends AbstractEffect {
@Override
protected FullEffectResult playEffectReturningResult(LotroGame game) {
if (isPlayableInFull(game)) {
game.getGameState().sendMessage(_action.getPerformingPlayer() + " stacks " + GameUtils.getCardLink(_action.getEventPlayed()) + " on "+GameUtils.getCardLink(_stackOn));
PhysicalCard eventPlayed = _action.getEventPlayed();
game.getGameState().sendMessage(_action.getPerformingPlayer() + " stacks " + GameUtils.getCardLink(eventPlayed) + " on " + GameUtils.getCardLink(_stackOn));
_action.skipDiscardPart();
game.getGameState().stackCard(game, _action.getEventPlayed(), _stackOn);
game.getGameState().removeCardsFromZone(eventPlayed.getOwner(), Collections.singletonList(eventPlayed));
game.getGameState().stackCard(game, eventPlayed, _stackOn);
return new FullEffectResult(true);
}
return new FullEffectResult(false);

View File

@@ -54,10 +54,15 @@ public class ConstructedLeagueData implements LeagueData {
public int process(CollectionsManager collectionsManager, List<PlayerStanding> leagueStandings, int oldStatus, int currentTime) {
int status = oldStatus;
if (status == 0) {
int maxGamesCount = 0;
for (LeagueSerieData sery : _series) {
maxGamesCount+=sery.getMaxMatches();
}
LeagueSerieData lastSerie = _series.get(_series.size() - 1);
if (currentTime > DateUtils.offsetDate(lastSerie.getEnd(), 1)) {
for (PlayerStanding leagueStanding : leagueStandings) {
CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), _prizeMultiplier);
CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), leagueStanding.getGamesPlayed(), maxGamesCount, _prizeMultiplier);
if (leaguePrize != null)
collectionsManager.addItemsToPlayerCollection(true, "End of league prizes", leagueStanding.getPlayerName(), _prizeCollectionType, leaguePrize.getAll().values());
}

View File

@@ -0,0 +1,4 @@
package com.gempukku.lotro.league;
public class ConstructedLeaguePrizes {
}

View File

@@ -7,5 +7,5 @@ public interface LeaguePrizes {
public CardCollection getPrizeForLeagueMatchLoser(int winCountThisSerie, int totalGamesPlayedThisSerie);
public CardCollection getPrizeForLeague(int position, int playersCount, float multiplier);
public CardCollection getPrizeForLeague(int position, int playersCount, int gamesPlayed, int maxGamesPlayed, float multiplier);
}

View File

@@ -58,10 +58,15 @@ public class NewConstructedLeagueData implements LeagueData {
public int process(CollectionsManager collectionsManager, List<PlayerStanding> leagueStandings, int oldStatus, int currentTime) {
int status = oldStatus;
if (status == 0) {
int maxGamesPlayed = 0;
for (LeagueSerieData sery : _series) {
maxGamesPlayed+=sery.getMaxMatches();
}
LeagueSerieData lastSerie = _series.get(_series.size() - 1);
if (currentTime > DateUtils.offsetDate(lastSerie.getEnd(), 1)) {
for (PlayerStanding leagueStanding : leagueStandings) {
CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), _prizeMultiplier);
CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), leagueStanding.getGamesPlayed(), maxGamesPlayed, _prizeMultiplier);
if (leaguePrize != null)
collectionsManager.addItemsToPlayerCollection(true, "End of league prizes", leagueStanding.getPlayerName(), _prizeCollectionType, leaguePrize.getAll().values());
}

View File

@@ -57,7 +57,7 @@ public class NewLeaguePrizes implements LeaguePrizes {
return null;
}
public CardCollection getPrizeForLeague(int position, int playersCount, float multiplier) {
public CardCollection getPrizeForLeague(int position, int playersCount, int gamesPlayed, int maxGamesPlayed, float multiplier) {
DefaultCardCollection leaguePrize = new DefaultCardCollection();
int count = (int) Math.floor((2 * playersCount + 24) / (position + 9) - 2.4);
if (count > 0) {

View File

@@ -19,7 +19,7 @@ public class NewSealedLeagueData implements LeagueData {
private List<LeagueSerieData> _series;
private CollectionType _collectionType;
private CollectionType _prizeCollectionType = CollectionType.MY_CARDS;
private NewLeaguePrizes _leaguePrizes;
private LeaguePrizes _leaguePrizes;
private SealedLeagueProduct _leagueProduct;
public NewSealedLeagueData(String parameters) {
@@ -80,11 +80,15 @@ public class NewSealedLeagueData implements LeagueData {
}
}
int maxGamesTotal = 0;
for (LeagueSerieData sery : _series)
maxGamesTotal+=sery.getMaxMatches();
if (status == _series.size()) {
LeagueSerieData lastSerie = _series.get(_series.size() - 1);
if (currentTime > DateUtils.offsetDate(lastSerie.getEnd(), 1)) {
for (PlayerStanding leagueStanding : leagueStandings) {
CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), 1f);
CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), leagueStanding.getGamesPlayed(), maxGamesTotal, 1f);
if (leaguePrize != null)
collectionsManager.addItemsToPlayerCollection(true, "End of league prizes", leagueStanding.getPlayerName(), _prizeCollectionType, leaguePrize.getAll().values());
}

View File

@@ -81,10 +81,15 @@ public class SealedLeagueData implements LeagueData {
}
if (status == _series.size()) {
int maxGamesPlayed = 0;
for (LeagueSerieData sery : _series) {
maxGamesPlayed+=sery.getMaxMatches();
}
LeagueSerieData lastSerie = _series.get(_series.size() - 1);
if (currentTime > DateUtils.offsetDate(lastSerie.getEnd(), 1)) {
for (PlayerStanding leagueStanding : leagueStandings) {
CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), 1f);
CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), leagueStanding.getGamesPlayed(), maxGamesPlayed, 1f);
if (leaguePrize != null)
collectionsManager.addItemsToPlayerCollection(true, "End of league prizes", leagueStanding.getPlayerName(), _prizeCollectionType, leaguePrize.getAll().values());
}

View File

@@ -0,0 +1,146 @@
package com.gempukku.lotro.league;
import com.gempukku.lotro.cards.packs.RarityReader;
import com.gempukku.lotro.cards.packs.SetRarity;
import com.gempukku.lotro.game.CardCollection;
import com.gempukku.lotro.game.DefaultCardCollection;
import java.util.*;
public class SealedLeaguePrizes implements LeaguePrizes {
private List<String> _commons = new ArrayList<String>();
private List<String> _uncommons = new ArrayList<String>();
private List<String> _promos = new ArrayList<String>();
private List<String> _rares = new ArrayList<String>();
public SealedLeaguePrizes() {
RarityReader rarityReader = new RarityReader();
for (int i = 0; i <= 19; i++) {
SetRarity setRarity = rarityReader.getSetRarity(String.valueOf(i));
_commons.addAll(setRarity.getCardsOfRarity("C"));
_uncommons.addAll(setRarity.getCardsOfRarity("U"));
_promos.addAll(setRarity.getCardsOfRarity("P"));
_rares.addAll(setRarity.getCardsOfRarity("R"));
}
}
public CardCollection getPrizeForLeagueMatchWinner(int winCountThisSerie, int totalGamesPlayedThisSerie) {
DefaultCardCollection winnerPrize = new DefaultCardCollection();
if (winCountThisSerie == 1 || winCountThisSerie == 3 || winCountThisSerie == 5 || winCountThisSerie == 8
|| winCountThisSerie == 10 || winCountThisSerie == 12)
winnerPrize.addItem("(S)Booster Choice", 1);
else {
if (winCountThisSerie == 2)
winnerPrize.addItem(getRandom(_commons) + "*", 1);
else if (winCountThisSerie == 4)
winnerPrize.addItem(getRandom(_promos), 1);
else if (winCountThisSerie == 6)
winnerPrize.addItem(getRandom(_promos) + "*", 1);
else if (winCountThisSerie == 7)
winnerPrize.addItem(getRandom(_uncommons) + "*", 1);
else if (winCountThisSerie == 9) {
winnerPrize.addItem(getRandom(_promos), 1);
winnerPrize.addItem(getRandom(_commons) + "*", 1);
} else if (winCountThisSerie == 11)
winnerPrize.addItem(getRandom(_promos), 1);
else if (winCountThisSerie == 13) {
winnerPrize.addItem(getRandom(_promos)+"*", 1);
winnerPrize.addItem(getRandom(_rares)+"*", 1);
}
}
return winnerPrize;
}
public CardCollection getPrizeForLeagueMatchLoser(int winCountThisSerie, int totalGamesPlayedThisSerie) {
return null;
}
public CardCollection getPrizeForLeague(int position, int playersCount, int gamesPlayed, int maxGamesPlayed, float multiplier) {
if (gamesPlayed*4>=maxGamesPlayed) {
DefaultCardCollection leaguePrize = new DefaultCardCollection();
leaguePrize.addItem("(S)Booster Choice", getBoosterCount(position));
leaguePrize.addItem("(S)Tengwar", getTengwarCount(position));
addPrizes(leaguePrize, getRandomFoil(_promos, getFoilCount(position)));
addPrizes(leaguePrize, getRandom(_promos, getPromoCount(position)));
if (leaguePrize.getAll().size() == 0)
return null;
return leaguePrize;
} else {
return null;
}
}
private int getFoilCount(int position) {
if (position<=3)
return 4-position;
else
return 0;
}
private int getPromoCount(int position) {
if (position<=4)
return position-1;
else if (position<=8)
return 2;
else if (position<=16)
return 1;
else
return 0;
}
private int getTengwarCount(int position) {
if (position<=4)
return 5-position;
else
return 0;
}
private int getBoosterCount(int position) {
if (position == 1)
return 60;
else if (position == 2)
return 55;
else if (position == 3)
return 50;
else if (position == 4)
return 45;
else if (position<=8)
return 40;
else if (position<=16)
return 35;
else if (position<=32)
return 20;
else if (position<=64)
return 10;
else if (position<=128)
return 5;
else
return 0;
}
private void addPrizes(DefaultCardCollection leaguePrize, List<String> cards) {
for (String card : cards)
leaguePrize.addItem(card, 1);
}
private String getRandom(List<String> list) {
return list.get(new Random().nextInt(list.size()));
}
private List<String> getRandom(List<String> list, int count) {
List<String> result = new LinkedList<String>(list);
Collections.shuffle(result);
return result.subList(0, count);
}
private List<String> getRandomFoil(List<String> list, int count) {
List<String> result = new LinkedList<String>();
for (String element : list)
result.add(element + "*");
Collections.shuffle(result);
return result.subList(0, count);
}
}

View File

@@ -18,9 +18,13 @@ public class LeaguePrizesTest {
@Test
public void testLeaguePrize() {
LeaguePrizes leaguePrizes = new NewLeaguePrizes();
CardCollection prize = leaguePrizes.getPrizeForLeague(1, 100, 2f);
for (Map.Entry<String, CardCollection.Item> stringIntegerEntry : prize.getAll().entrySet()) {
System.out.println(stringIntegerEntry.getKey() + ": " + stringIntegerEntry.getValue().getCount());
for (int i = 1; i <= 32; i++) {
System.out.println("Place "+i);
CardCollection prize = leaguePrizes.getPrizeForLeague(i, 60, 1, 2, 2f);
if (prize != null)
for (Map.Entry<String, CardCollection.Item> stringIntegerEntry : prize.getAll().entrySet()) {
System.out.println(stringIntegerEntry.getKey() + ": " + stringIntegerEntry.getValue().getCount());
}
}
}
}