From 6b31d101dbeea82728cb5227adce030e3d3de08e Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Wed, 6 Nov 2024 21:29:38 +0800 Subject: [PATCH 1/2] prevent townPriceModifier NPE --- .../forge/adventure/character/ShopActor.java | 36 ++++-- .../adventure/data/AdventureEventData.java | 77 ++++++------ .../adventure/player/AdventurePlayer.java | 33 ++--- .../src/forge/adventure/scene/EventScene.java | 116 ++++++++---------- .../src/forge/adventure/scene/InnScene.java | 4 +- .../src/forge/adventure/scene/ShopScene.java | 5 +- .../util/AdventureEventController.java | 2 +- 7 files changed, 139 insertions(+), 134 deletions(-) diff --git a/forge-gui-mobile/src/forge/adventure/character/ShopActor.java b/forge-gui-mobile/src/forge/adventure/character/ShopActor.java index eb426c31e13..260cbc133e9 100644 --- a/forge-gui-mobile/src/forge/adventure/character/ShopActor.java +++ b/forge-gui-mobile/src/forge/adventure/character/ShopActor.java @@ -3,6 +3,7 @@ package forge.adventure.character; import com.badlogic.gdx.utils.Array; import forge.Forge; import forge.adventure.data.ShopData; +import forge.adventure.pointofintrest.PointOfInterestChanges; import forge.adventure.scene.RewardScene; import forge.adventure.stage.MapStage; import forge.adventure.util.Reward; @@ -11,31 +12,33 @@ import forge.adventure.util.Reward; /** * Map actor that will open the Shop on collision */ -public class ShopActor extends MapActor{ +public class ShopActor extends MapActor { private final MapStage stage; private ShopData shopData; Array rewardData; - public ShopActor(MapStage stage, int id, Array rewardData, ShopData data) - { + public ShopActor(MapStage stage, int id, Array rewardData, ShopData data) { super(id); this.stage = stage; this.shopData = data; this.rewardData = rewardData; } - public float getPriceModifier() { return ( stage.getChanges().getShopPriceModifier(objectId) * stage.getChanges().getTownPriceModifier() ); } - public MapStage getMapStage() - { + public float getPriceModifier() { + PointOfInterestChanges changes = stage.getChanges(); + float townPricemodifier = changes == null ? 1f : changes.getTownPriceModifier(); + float shopPriceModifier = changes == null ? 1f : changes.getShopPriceModifier(objectId); + return shopPriceModifier * townPricemodifier; + } + + public MapStage getMapStage() { return stage; } @Override - public void onPlayerCollide() - { - + public void onPlayerCollide() { stage.getPlayerSprite().stop(); - RewardScene.instance().loadRewards(rewardData, RewardScene.Type.Shop,this); + RewardScene.instance().loadRewards(rewardData, RewardScene.Type.Shop, this); Forge.switchScene(RewardScene.instance()); } @@ -61,8 +64,15 @@ public class ShopActor extends MapActor{ return getRestockPrice() > 0; } - public ShopData getShopData() { return shopData; } + public ShopData getShopData() { + return shopData; + } - public void setRewardData(Array data) { rewardData = data; } - public Array getRewardData() { return rewardData;} + public void setRewardData(Array data) { + rewardData = data; + } + + public Array getRewardData() { + return rewardData; + } } diff --git a/forge-gui-mobile/src/forge/adventure/data/AdventureEventData.java b/forge-gui-mobile/src/forge/adventure/data/AdventureEventData.java index b94266a1237..4ed13ca8c8e 100644 --- a/forge-gui-mobile/src/forge/adventure/data/AdventureEventData.java +++ b/forge-gui-mobile/src/forge/adventure/data/AdventureEventData.java @@ -92,6 +92,7 @@ public class AdventureEventData implements Serializable { random = (eventSeed > 0 ? new Random(eventSeed) : new Random()); return random; } + public AdventureEventData(Long seed, AdventureEventController.EventFormat selectedFormat) { setEventSeed(seed); eventStatus = AdventureEventController.EventStatus.Available; @@ -106,7 +107,7 @@ public class AdventureEventData implements Serializable { //Below all to be fully generated in later release rewardPacks = getRewardPacks(3); generateParticipants(7); - if (cardBlock != null){ + if (cardBlock != null) { packConfiguration = getBoosterConfiguration(cardBlock); rewards = new AdventureEventData.AdventureEventReward[4]; @@ -127,8 +128,7 @@ public class AdventureEventData implements Serializable { r2.itemRewards = new String[]{"Challenge Coin"}; rewards[2] = r2; } - } - else if (format.equals(AdventureEventController.EventFormat.Jumpstart)) { + } else if (format.equals(AdventureEventController.EventFormat.Jumpstart)) { int numPacksToPickFrom = 6; generateParticipants(7); @@ -139,7 +139,7 @@ public class AdventureEventData implements Serializable { jumpstartBoosters = AdventureEventController.instance().getJumpstartBoosters(cardBlock, numPacksToPickFrom); - packConfiguration = new String[] {cardBlock.getLandSet().getCode(), cardBlock.getLandSet().getCode(), cardBlock.getLandSet().getCode()}; + packConfiguration = new String[]{cardBlock.getLandSet().getCode(), cardBlock.getLandSet().getCode(), cardBlock.getLandSet().getCode()}; for (AdventureEventParticipant participant : participants) { List availableOptions = AdventureEventController.instance().getJumpstartBoosters(cardBlock, numPacksToPickFrom); @@ -172,9 +172,8 @@ public class AdventureEventData implements Serializable { } if (themeAdded.isEmpty()) { done = true; - } - else { - chosenPacks.addAll(themeMap.get(themeAdded).subList(0, Math.min(themeMap.get(themeAdded).size(),packConfiguration.length - chosenPacks.size()))); + } else { + chosenPacks.addAll(themeMap.get(themeAdded).subList(0, Math.min(themeMap.get(themeAdded).size(), packConfiguration.length - chosenPacks.size()))); availableOptions.removeAll(themeMap.get(themeAdded)); themeMap.remove(themeAdded); themeAdded = ""; @@ -184,13 +183,20 @@ public class AdventureEventData implements Serializable { //2. Fill remaining slots with colors already picked whenever possible Map> colorMap = new HashMap<>(); for (Deck option : availableOptions) { - if (option.getTags().contains("black")) colorMap.getOrDefault("black", new ArrayList()).add(option); - if (option.getTags().contains("blue")) colorMap.getOrDefault("blue", new ArrayList()).add(option); - if (option.getTags().contains("green")) colorMap.getOrDefault("green", new ArrayList()).add(option); - if (option.getTags().contains("red")) colorMap.getOrDefault("red", new ArrayList()).add(option); - if (option.getTags().contains("white")) colorMap.getOrDefault("white", new ArrayList()).add(option); - if (option.getTags().contains("multicolor")) colorMap.getOrDefault("multicolor", new ArrayList()).add(option); - if (option.getTags().contains("colorless")) colorMap.getOrDefault("colorless", new ArrayList()).add(option); + if (option.getTags().contains("black")) + colorMap.getOrDefault("black", new ArrayList()).add(option); + if (option.getTags().contains("blue")) + colorMap.getOrDefault("blue", new ArrayList()).add(option); + if (option.getTags().contains("green")) + colorMap.getOrDefault("green", new ArrayList()).add(option); + if (option.getTags().contains("red")) + colorMap.getOrDefault("red", new ArrayList()).add(option); + if (option.getTags().contains("white")) + colorMap.getOrDefault("white", new ArrayList()).add(option); + if (option.getTags().contains("multicolor")) + colorMap.getOrDefault("multicolor", new ArrayList()).add(option); + if (option.getTags().contains("colorless")) + colorMap.getOrDefault("colorless", new ArrayList()).add(option); } done = false; @@ -218,19 +224,18 @@ public class AdventureEventData implements Serializable { } } } - //3. If no matching color found and need more packs, add any available at random. - if (packConfiguration.length > chosenPacks.size() && colorAdded.isEmpty() && !availableOptions.isEmpty()){ - chosenPacks.add(Aggregates.removeRandom(availableOptions)); - colorAdded = ""; - } - else { - done = colorAdded.isEmpty() || packConfiguration.length <= chosenPacks.size(); - colorAdded = ""; - } + //3. If no matching color found and need more packs, add any available at random. + if (packConfiguration.length > chosenPacks.size() && colorAdded.isEmpty() && !availableOptions.isEmpty()) { + chosenPacks.add(Aggregates.removeRandom(availableOptions)); + colorAdded = ""; + } else { + done = colorAdded.isEmpty() || packConfiguration.length <= chosenPacks.size(); + colorAdded = ""; + } } participant.registeredDeck = new Deck(); - for (Deck chosen : chosenPacks){ + for (Deck chosen : chosenPacks) { participant.registeredDeck.getMain().addAllFlat(chosen.getMain().toFlatList()); } } @@ -404,7 +409,7 @@ public class AdventureEventData implements Serializable { legalBlocks.removeIf(q -> q.getName().equals(restricted)); } } - return legalBlocks.isEmpty()?null:Aggregates.random(legalBlocks); + return legalBlocks.isEmpty() ? null : Aggregates.random(legalBlocks); } @@ -505,9 +510,7 @@ public class AdventureEventData implements Serializable { draftedDeck.setComment("Prize for placing 1st overall in draft event"); rewards[3].cardRewards = new Deck[]{draftedDeck}; - } - - else if (format == AdventureEventController.EventFormat.Jumpstart) { + } else if (format == AdventureEventController.EventFormat.Jumpstart) { rewards[3] = new AdventureEventReward(); rewards[3].minWins = 0; @@ -538,7 +541,7 @@ public class AdventureEventData implements Serializable { data.itemName = item; ret.addAll(data.generate(false, true)); } - for (RewardData data : r.rewards) { + for (RewardData data : r.rewards) { ret.addAll(data.generate(false, true)); } } @@ -570,12 +573,13 @@ public class AdventureEventData implements Serializable { } public String getDescription(PointOfInterestChanges changes) { + float townPriceModifier = changes == null ? 1f : changes.getTownPriceModifier(); if (format.equals(AdventureEventController.EventFormat.Draft)) { description = "Event Type: Booster Draft\n"; description += "Block: " + getCardBlock() + "\n"; description += "Boosters: " + String.join(", ", packConfiguration) + "\n"; description += "Competition Style: " + participants.length + " players, matches played as best of " + eventRules.gamesPerMatch + ", " + (getPairingDescription()) + "\n\n"; - description += String.format("Entry Fee (incl. reputation)\nGold %d[][+Gold][BLACK]\nMana Shards %d[][+Shards][BLACK]\n", Math.round(eventRules.goldToEnter * changes.getTownPriceModifier()), Math.round(eventRules.shardsToEnter * changes.getTownPriceModifier())); + description += String.format("Entry Fee (incl. reputation)\nGold %d[][+Gold][BLACK]\nMana Shards %d[][+Shards][BLACK]\n", Math.round(eventRules.goldToEnter * townPriceModifier), Math.round(eventRules.shardsToEnter * townPriceModifier)); if (eventRules.acceptsBronzeChallengeCoin) { description += "Bronze Challenge Coin [][+BronzeChallengeCoin][BLACK]\n\n"; } else if (eventRules.acceptsSilverChallengeCoin) { @@ -586,12 +590,11 @@ public class AdventureEventData implements Serializable { description += "\n"; } description += String.format("Prizes\nChampion: Keep drafted deck\n2+ round wins: Challenge Coin \n1+ round wins: %s Booster, %s Booster\n0 round wins: %s Booster", rewardPacks[0].getComment(), rewardPacks[1].getComment(), rewardPacks[2].getComment()); - } - else if (format.equals(AdventureEventController.EventFormat.Jumpstart)) { + } else if (format.equals(AdventureEventController.EventFormat.Jumpstart)) { description = "Event Type: Jumpstart\n"; description += "Block: " + getCardBlock() + "\n"; description += "Competition Style: " + participants.length + " players, matches played as best of " + eventRules.gamesPerMatch + ", " + (getPairingDescription()) + "\n\n"; - description += String.format("Entry Fee (incl. reputation)\nGold %d[][+Gold][BLACK]\nMana Shards %d[][+Shards][BLACK]\n", Math.round(eventRules.goldToEnter * changes.getTownPriceModifier()), Math.round(eventRules.shardsToEnter * changes.getTownPriceModifier())); + description += String.format("Entry Fee (incl. reputation)\nGold %d[][+Gold][BLACK]\nMana Shards %d[][+Shards][BLACK]\n", Math.round(eventRules.goldToEnter * townPriceModifier), Math.round(eventRules.shardsToEnter * townPriceModifier)); if (eventRules.acceptsBronzeChallengeCoin) { description += "Bronze Challenge Coin [][+BronzeChallengeCoin][BLACK]\n\n"; } else if (eventRules.acceptsSilverChallengeCoin) { @@ -645,7 +648,7 @@ public class AdventureEventData implements Serializable { public Image getAvatar() { if (sprite == null) { EnemyData data = WorldData.getEnemy(enemyDataName); - if (data == null){ + if (data == null) { //enemyDataName was not found, replace with something valid. enemyDataName = Aggregates.random(WorldData.getAllEnemies()).getName(); } @@ -683,10 +686,12 @@ public class AdventureEventData implements Serializable { public Deck getDeck() { return registeredDeck == null ? Current.player().getSelectedDeck() : registeredDeck; } + @Override public String getName() { return Current.player().getName(); } + @Override public Image getAvatar() { return new Image(Current.player().avatar()); @@ -717,12 +722,12 @@ public class AdventureEventData implements Serializable { this(format, PairingStyle.SingleElimination, localPriceModifier); } - public AdventureEventRules(AdventureEventController.EventFormat format, PairingStyle pairingStyle, float localPriceModifier){ + public AdventureEventRules(AdventureEventController.EventFormat format, PairingStyle pairingStyle, float localPriceModifier) { int baseGoldEntry = 99999; int baseShardEntry = 9999; this.pairingStyle = pairingStyle; - switch (format){ + switch (format) { case Constructed: acceptsSilverChallengeCoin = true; acceptsChallengeCoin = false; diff --git a/forge-gui-mobile/src/forge/adventure/player/AdventurePlayer.java b/forge-gui-mobile/src/forge/adventure/player/AdventurePlayer.java index b3caed12c6a..0b8df107dbc 100644 --- a/forge-gui-mobile/src/forge/adventure/player/AdventurePlayer.java +++ b/forge-gui-mobile/src/forge/adventure/player/AdventurePlayer.java @@ -350,8 +350,7 @@ public class AdventurePlayer implements Serializable, SaveFileContent { setColorIdentity(temp); else colorIdentity = ColorSet.ALL_COLORS; - } - else + } else colorIdentity = ColorSet.ALL_COLORS; gold = data.readInt("gold"); @@ -467,19 +466,19 @@ public class AdventurePlayer implements Serializable, SaveFileContent { if (data.containsKey("newCards")) { InventoryItem[] items = (InventoryItem[]) data.readObject("newCards"); - for (InventoryItem item : items){ - newCards.add((PaperCard)item); + for (InventoryItem item : items) { + newCards.add((PaperCard) item); } } if (data.containsKey("noSellCards")) { PaperCard[] items = (PaperCard[]) data.readObject("noSellCards"); - for (PaperCard item : items){ + for (PaperCard item : items) { noSellCards.add(item); } } if (data.containsKey("autoSellCards")) { PaperCard[] items = (PaperCard[]) data.readObject("autoSellCards"); - for (PaperCard item : items){ + for (PaperCard item : items) { autoSellCards.add(item); } } @@ -598,6 +597,7 @@ public class AdventurePlayer implements Serializable, SaveFileContent { public TextureRegion avatar() { return HeroListData.instance().getAvatar(heroRace, isFemale, avatarIndex); } + public String raceName() { return HeroListData.instance().getRaces().get(Current.player().heroRace); } @@ -607,6 +607,7 @@ public class AdventurePlayer implements Serializable, SaveFileContent { return MapStage.getInstance(); return WorldStage.getInstance(); } + public void addStatusMessage(String iconName, String message, Integer itemCount, float x, float y) { String symbol = itemCount == null || itemCount < 0 ? "" : " +"; String icon = iconName == null ? "" : "[+" + iconName + "]"; @@ -614,12 +615,13 @@ public class AdventurePlayer implements Serializable, SaveFileContent { TextraLabel actor = Controls.newTextraLabel("[%95]" + icon + "[WHITE]" + symbol + count + " " + message); actor.setPosition(x, y); actor.addAction(Actions.sequence( - Actions.parallel(Actions.moveBy(0f, 5f, 3f), Actions.fadeIn(2f)), - Actions.hide(), - Actions.removeActor()) + Actions.parallel(Actions.moveBy(0f, 5f, 3f), Actions.fadeIn(2f)), + Actions.hide(), + Actions.removeActor()) ); getCurrentGameStage().addActor(actor); } + public void addCard(PaperCard card) { cards.add(card); newCards.add(card); @@ -631,8 +633,8 @@ public class AdventurePlayer implements Serializable, SaveFileContent { cards.add(reward.getCard()); newCards.add(reward.getCard()); if (reward.isAutoSell()) { - autoSellCards.add(reward.getCard()); - refreshEditor(); + autoSellCards.add(reward.getCard()); + refreshEditor(); } else if (reward.isNoSell()) { noSellCards.add(reward.getCard()); refreshEditor(); @@ -847,9 +849,9 @@ public class AdventurePlayer implements Serializable, SaveFileContent { for (String name : equippedItems.values()) { ItemData data = ItemData.getItem(name); if (data != null - && ("Boots".equalsIgnoreCase(data.equipmentSlot) - || "Body".equalsIgnoreCase(data.equipmentSlot) - || "Neck".equalsIgnoreCase(data.equipmentSlot))) { + && ("Boots".equalsIgnoreCase(data.equipmentSlot) + || "Body".equalsIgnoreCase(data.equipmentSlot) + || "Neck".equalsIgnoreCase(data.equipmentSlot))) { armor.add(data); } } @@ -903,7 +905,8 @@ public class AdventurePlayer implements Serializable, SaveFileContent { } public int cardSellPrice(PaperCard card) { - return (int) (CardUtil.getCardPrice(card) * difficultyData.sellFactor * (2.0f - currentLocationChanges.getTownPriceModifier())); + float townPriceModifier = currentLocationChanges == null ? 1f : currentLocationChanges.getTownPriceModifier(); + return (int) (CardUtil.getCardPrice(card) * difficultyData.sellFactor * (2.0f - townPriceModifier)); } public void sellCard(PaperCard card, Integer result) { diff --git a/forge-gui-mobile/src/forge/adventure/scene/EventScene.java b/forge-gui-mobile/src/forge/adventure/scene/EventScene.java index b0afb0269ce..ea26ce4b344 100644 --- a/forge-gui-mobile/src/forge/adventure/scene/EventScene.java +++ b/forge-gui-mobile/src/forge/adventure/scene/EventScene.java @@ -57,29 +57,30 @@ public class EventScene extends MenuScene implements IAfterMatch { private EventScene() { super(Forge.isLandscapeMode() ? "ui/event.json" : "ui/event_portrait.json"); - //todo: add translation + // TODO: Add translation + float townPriceModifier = changes == null ? 1f : changes.getTownPriceModifier(); DialogData introDialog = new DialogData(); introDialog.text = "Enter this event?"; DialogData enterWithCoin = new DialogData(); DialogData enterWithShards = new DialogData(); - enterWithShards.name = String.format("Spend %d [+shards]", Math.round(currentEvent.eventRules.shardsToEnter* changes.getTownPriceModifier())); + enterWithShards.name = String.format("Spend %d [+shards]", Math.round(currentEvent.eventRules.shardsToEnter * townPriceModifier)); DialogData enterWithGold = new DialogData(); - enterWithGold.name = String.format("Spend %d [+gold]", Math.round(currentEvent.eventRules.goldToEnter * changes.getTownPriceModifier())); + enterWithGold.name = String.format("Spend %d [+gold]", Math.round(currentEvent.eventRules.goldToEnter * townPriceModifier)); DialogData.ConditionData hasGold = new DialogData.ConditionData(); - hasGold.hasGold = Math.round(currentEvent.eventRules.goldToEnter * changes.getTownPriceModifier()); + hasGold.hasGold = Math.round(currentEvent.eventRules.goldToEnter * townPriceModifier); enterWithGold.condition = new DialogData.ConditionData[]{hasGold}; DialogData.ConditionData hasShards = new DialogData.ConditionData(); - hasShards.hasShards = Math.round(currentEvent.eventRules.shardsToEnter * changes.getTownPriceModifier()); + hasShards.hasShards = Math.round(currentEvent.eventRules.shardsToEnter * townPriceModifier); enterWithShards.condition = new DialogData.ConditionData[]{hasShards}; if (currentEvent.eventRules.acceptsChallengeCoin) { enterWithCoin.name = "Redeem a Challenge Coin [+ChallengeCoin]"; DialogData.ConditionData hasCoin = new DialogData.ConditionData(); - hasCoin.item="Challenge Coin"; + hasCoin.item = "Challenge Coin"; enterWithCoin.condition = new DialogData.ConditionData[]{hasCoin}; DialogData.ActionData giveCoin = new DialogData.ActionData(); @@ -88,7 +89,7 @@ public class EventScene extends MenuScene implements IAfterMatch { } else if (currentEvent.eventRules.acceptsSilverChallengeCoin) { enterWithCoin.name = "Redeem a Challenge Coin [+SilverChallengeCoin]"; DialogData.ConditionData hasCoin = new DialogData.ConditionData(); - hasCoin.item="Silver Challenge Coin"; + hasCoin.item = "Silver Challenge Coin"; enterWithCoin.condition = new DialogData.ConditionData[]{hasCoin}; DialogData.ActionData giveCoin = new DialogData.ActionData(); @@ -97,30 +98,28 @@ public class EventScene extends MenuScene implements IAfterMatch { } else if (currentEvent.eventRules.acceptsBronzeChallengeCoin) { enterWithCoin.name = "Redeem a Challenge Coin [+BronzeChallengeCoin]"; DialogData.ConditionData hasCoin = new DialogData.ConditionData(); - hasCoin.item="Bronze Challenge Coin"; + hasCoin.item = "Bronze Challenge Coin"; enterWithCoin.condition = new DialogData.ConditionData[]{hasCoin}; DialogData.ActionData giveCoin = new DialogData.ActionData(); giveCoin.removeItem = hasCoin.item; enterWithCoin.action = new DialogData.ActionData[]{giveCoin}; - } - else { + } else { DialogData.ConditionData alwaysFalse = new DialogData.ConditionData(); alwaysFalse.item = "NonexistentItem"; enterWithCoin.condition = new DialogData.ConditionData[]{alwaysFalse}; } DialogData.ActionData spendGold = new DialogData.ActionData(); - spendGold.addGold=-Math.round(currentEvent.eventRules.goldToEnter * changes.getTownPriceModifier()); + spendGold.addGold = -Math.round(currentEvent.eventRules.goldToEnter * townPriceModifier); enterWithGold.action = new DialogData.ActionData[]{spendGold}; DialogData.ActionData spendShards = new DialogData.ActionData(); - spendShards.addShards =-Math.round(currentEvent.eventRules.shardsToEnter * changes.getTownPriceModifier()); + spendShards.addShards = -Math.round(currentEvent.eventRules.shardsToEnter * townPriceModifier); enterWithShards.action = new DialogData.ActionData[]{spendShards}; - DialogData decline = new DialogData(); //todo: add translation decline.name = "Do not enter event"; @@ -194,8 +193,7 @@ public class EventScene extends MenuScene implements IAfterMatch { if (currentEvent.format == AdventureEventController.EventFormat.Draft && currentEvent.eventStatus == Ready) { DraftScene.instance().loadEvent(currentEvent); Forge.switchScene(DraftScene.instance()); - } - else if (currentEvent.format == AdventureEventController.EventFormat.Jumpstart && currentEvent.eventStatus == Ready) { + } else if (currentEvent.format == AdventureEventController.EventFormat.Jumpstart && currentEvent.eventStatus == Ready) { DeckEditScene.getInstance().loadEvent(currentEvent); Forge.switchScene(DeckEditScene.getInstance()); } @@ -214,7 +212,7 @@ public class EventScene extends MenuScene implements IAfterMatch { ScrollPane blessing = ui.findActor("blessingInfo"); blessing.setActor(blessingScroll); - blessingScroll.setWidth(blessing.getWidth()-5); + blessingScroll.setWidth(blessing.getWidth() - 5); blessing.layout(); window.add(root); @@ -225,19 +223,18 @@ public class EventScene extends MenuScene implements IAfterMatch { refresh(); } - private void refresh(){ - if (metaDraftTable.isVisible()){ + private void refresh() { + if (metaDraftTable.isVisible()) { scrollContainer = metaDraftTable; headerTable.clear(); //todo: add translation headerTable.add("Pack Selection"); - if (currentEvent.eventStatus == Entered){ + if (currentEvent.eventStatus == Entered) { loadMetaDraft(); } - } - else { + } else { scrollContainer = new Table(Controls.getSkin()); scrollContainer.row(); @@ -340,7 +337,7 @@ public class EventScene extends MenuScene implements IAfterMatch { performTouch(scroller); //todo: add translations - switch (currentEvent.eventStatus){ + switch (currentEvent.eventStatus) { case Available: nextPage.setDisabled(true); previousPage.setDisabled(true); @@ -354,10 +351,9 @@ public class EventScene extends MenuScene implements IAfterMatch { previousPage.setDisabled(true); editDeck.setDisabled(true); editDeck.setVisible(false); - if (currentEvent.getDraft() != null){ + if (currentEvent.getDraft() != null) { advance.setText("Enter Draft"); - } - else{ + } else { advance.setText("Select Deck"); } advance.setVisible(true); @@ -371,7 +367,7 @@ public class EventScene extends MenuScene implements IAfterMatch { previousPage.setDisabled(false); break; case Started: - advance.setText("Play round " +currentEvent.currentRound); + advance.setText("Play round " + currentEvent.currentRound); advance.setVisible(true); editDeck.setDisabled(true); editDeck.setVisible(false); @@ -406,23 +402,21 @@ public class EventScene extends MenuScene implements IAfterMatch { // if (object == null) object = new EventScene(); if (lastGameScene != null) - object.lastGameScene=lastGameScene; + object.lastGameScene = lastGameScene; return object; } private void nextPage(boolean reverse) { //todo: add translations headerTable.clear(); - if (!reverse && ++pageIndex >= eventPages.length){ + if (!reverse && ++pageIndex >= eventPages.length) { pageIndex = 0; - } - else if (reverse && --pageIndex < 0) { + } else if (reverse && --pageIndex < 0) { pageIndex = eventPages.length - 1; } - if (pageIndex == 0){ + if (pageIndex == 0) { headerTable.add("Event Standings").expand(); - } - else{ + } else { headerTable.add("Round " + (pageIndex) + " of " + (eventPages.length - 1)); } @@ -443,29 +437,29 @@ public class EventScene extends MenuScene implements IAfterMatch { } performTouch(scrollPaneOfActor(scrollContainer)); //can use mouse wheel if available to scroll - if (currentEvent.eventStatus == Entered){ + if (currentEvent.eventStatus == Entered) { loadMetaDraft(); } refresh(); } - public void editDeck(){ - if (currentEvent.eventStatus == Ready){ + public void editDeck() { + if (currentEvent.eventStatus == Ready) { DraftScene.instance().loadEvent(currentEvent); Forge.switchScene(DraftScene.instance()); } } public void advance() { - switch (currentEvent.eventStatus){ + switch (currentEvent.eventStatus) { case Available: activate(entryDialog); //Entry fee pop-up break; case Entered: //Start draft or select deck //Show progress / wait indicator? Draft can take a while to generate - switch (currentEvent.format){ + switch (currentEvent.format) { case Draft: DraftScene.instance().loadEvent(currentEvent); Forge.switchScene(DraftScene.instance()); @@ -495,12 +489,12 @@ public class EventScene extends MenuScene implements IAfterMatch { } @Override - public boolean back(){ - if (currentEvent.eventStatus.equals(Awarded)){ + public boolean back() { + if (currentEvent.eventStatus.equals(Awarded)) { AdventureEventController.instance().finalizeEvent(currentEvent); currentEvent = null; } - Forge.switchScene(lastGameScene==null?GameScene.instance():lastGameScene); + Forge.switchScene(lastGameScene == null ? GameScene.instance() : lastGameScene); return true; } @@ -512,7 +506,7 @@ public class EventScene extends MenuScene implements IAfterMatch { if (match.p2 == null) { //shouldn't happen under current setup, but this would be a bye match.winner = match.p1; - match.p1.wins +=1; + match.p1.wins += 1; } if (match.p1 instanceof AdventureEventData.AdventureEventHuman) { @@ -526,12 +520,11 @@ public class EventScene extends MenuScene implements IAfterMatch { continue; } else { //Todo: Actually run match simulation here - if(MyRandom.percentTrue(50)){ + if (MyRandom.percentTrue(50)) { match.p1.wins++; match.p2.losses++; match.winner = match.p1; - } - else{ + } else { match.p1.losses++; match.p2.wins++; match.winner = match.p2; @@ -542,8 +535,7 @@ public class EventScene extends MenuScene implements IAfterMatch { if (humanMatch != null && humanMatch.round != currentEvent.currentRound) humanMatch = null; - if (humanMatch != null) - { + if (humanMatch != null) { DuelScene duelScene = DuelScene.instance(); EnemySprite enemy = humanMatch.p2.getSprite(); currentEvent.nextOpponent = humanMatch.p2; @@ -551,9 +543,7 @@ public class EventScene extends MenuScene implements IAfterMatch { duelScene.initDuels(WorldStage.getInstance().getPlayerSprite(), enemy, false, currentEvent); Forge.switchScene(duelScene); }, Forge.takeScreenshot(), true, false, false, false, "", Current.player().avatar(), enemy.getAtlasPath(), Current.player().getName(), enemy.getName(), humanMatch.p1.getRecord(), humanMatch.p2.getRecord()))); - } - else - { + } else { finishRound(); } advance.setDisabled(false); @@ -577,8 +567,7 @@ public class EventScene extends MenuScene implements IAfterMatch { if (winner) { //AdventureQuestController.instance().updateQuestsWin(currentMob,enemies); //AdventureQuestController.instance().showQuestDialogs(MapStage.this); - } - else{ + } else { // AdventureQuestController.instance().updateQuestsLose(currentMob); // AdventureQuestController.instance().showQuestDialogs(MapStage.this); } @@ -586,23 +575,22 @@ public class EventScene extends MenuScene implements IAfterMatch { finishRound(); } - public void finishRound(){ - if (currentEvent.currentRound == currentEvent.rounds){ + public void finishRound() { + if (currentEvent.currentRound == currentEvent.rounds) { finishEvent(); - } - else currentEvent.currentRound += 1; + } else currentEvent.currentRound += 1; refresh(); } - public void finishEvent(){ + public void finishEvent() { currentEvent.eventStatus = AdventureEventController.EventStatus.Completed; } - public void loadMetaDraft(){ + public void loadMetaDraft() { metaDraftTable.setVisible(true); metaDraftTable.clear(); - for (Deck deckOption : currentEvent.jumpstartBoosters) { + for (Deck deckOption : currentEvent.jumpstartBoosters) { if (metaDraftTable.hasChildren()) metaDraftTable.row(); @@ -629,11 +617,9 @@ public class EventScene extends MenuScene implements IAfterMatch { public void clicked(InputEvent event, float x, float y) { selectButton.clearListeners(); deckOption.getTags().add("Selected"); - if (!selectedJumpstartPackIsLast(deckOption)) - { + if (!selectedJumpstartPackIsLast(deckOption)) { loadMetaDraft(); - } - else { + } else { metaDraftTable.setVisible(false); } } @@ -646,11 +632,11 @@ public class EventScene extends MenuScene implements IAfterMatch { eventPages[0] = metaDraftTable; } - private boolean selectedJumpstartPackIsLast(Deck selectedPack){ + private boolean selectedJumpstartPackIsLast(Deck selectedPack) { int packsToPick = 3; int packsPicked = 0; Deck currentPicks = new Deck(); - for (Deck deckOption : currentEvent.jumpstartBoosters) { + for (Deck deckOption : currentEvent.jumpstartBoosters) { if (deckOption.getTags().contains("Selected")) { packsPicked++; currentPicks.getMain().addAll(deckOption.getAllCardsInASinglePool()); diff --git a/forge-gui-mobile/src/forge/adventure/scene/InnScene.java b/forge-gui-mobile/src/forge/adventure/scene/InnScene.java index 2915ae64f88..3b2b391b10f 100644 --- a/forge-gui-mobile/src/forge/adventure/scene/InnScene.java +++ b/forge-gui-mobile/src/forge/adventure/scene/InnScene.java @@ -101,8 +101,8 @@ public class InnScene extends UIScene { } private void refreshStatus(){ - - tempHealthCost = Math.round(Current.player().falseLifeCost() * changes.getTownPriceModifier()); + float townPriceModifier = changes == null ? 1f : changes.getTownPriceModifier(); + tempHealthCost = Math.round(Current.player().falseLifeCost() * townPriceModifier); boolean purchaseable = Current.player().getMaxLife() == Current.player().getLife() && tempHealthCost <= Current.player().getGold(); diff --git a/forge-gui-mobile/src/forge/adventure/scene/ShopScene.java b/forge-gui-mobile/src/forge/adventure/scene/ShopScene.java index 71e39a05666..f85c2309df2 100644 --- a/forge-gui-mobile/src/forge/adventure/scene/ShopScene.java +++ b/forge-gui-mobile/src/forge/adventure/scene/ShopScene.java @@ -48,15 +48,16 @@ public class ShopScene extends ForgeScene { } public void doAutosell() { - boolean promptToConfirmSale = false; //Todo: config option + boolean promptToConfirmSale = false; // TODO: config option if (promptToConfirmSale) { + float townPriceModifier = changes == null ? 1f : changes.getTownPriceModifier(); int profit = 0; int cards = 0; for (PaperCard cardToSell: Current.player().autoSellCards.toFlatList()) { cards++; profit += getCardPrice(cardToSell); } - if (!confirmAutosell(profit, cards, changes.getTownPriceModifier())) { + if (!confirmAutosell(profit, cards, townPriceModifier)) { return; } } diff --git a/forge-gui-mobile/src/forge/adventure/util/AdventureEventController.java b/forge-gui-mobile/src/forge/adventure/util/AdventureEventController.java index df9ba97a9f5..190d5ee7eb5 100644 --- a/forge-gui-mobile/src/forge/adventure/util/AdventureEventController.java +++ b/forge-gui-mobile/src/forge/adventure/util/AdventureEventController.java @@ -115,7 +115,7 @@ public class AdventureEventController implements Serializable { } e.sourceID = pointID; e.eventOrigin = eventOrigin; - e.eventRules = new AdventureEventData.AdventureEventRules(e.format, changes.getTownPriceModifier()); + e.eventRules = new AdventureEventData.AdventureEventRules(e.format, changes == null ? 1f : changes.getTownPriceModifier()); e.style = style; switch (style){ From a8bc8d42e1daa0734429d3735e780835f89d909a Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Wed, 6 Nov 2024 21:30:43 +0800 Subject: [PATCH 2/2] format --- .../util/AdventureEventController.java | 55 ++++++++----------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/forge-gui-mobile/src/forge/adventure/util/AdventureEventController.java b/forge-gui-mobile/src/forge/adventure/util/AdventureEventController.java index 190d5ee7eb5..a44aee75d04 100644 --- a/forge-gui-mobile/src/forge/adventure/util/AdventureEventController.java +++ b/forge-gui-mobile/src/forge/adventure/util/AdventureEventController.java @@ -26,20 +26,20 @@ public class AdventureEventController implements Serializable { } - public enum EventFormat{ + public enum EventFormat { Draft, Sealed, Jumpstart, Constructed } - public enum EventStyle{ + public enum EventStyle { Bracket, RoundRobin, Swiss } - public enum EventStatus{ + public enum EventStatus { Available, //New event Entered, //Entry fee paid, deck not locked in Ready, //Deck is registered but can still be edited @@ -58,58 +58,53 @@ public class AdventureEventController implements Serializable { return object; } - private AdventureEventController(){ + private AdventureEventController() { } private transient Array allEvents = new Array<>(); private Map nextEventDate = new HashMap<>(); - public AdventureEventController(AdventureEventController other){ + public AdventureEventController(AdventureEventController other) { if (object == null) { object = this; - } - else{ + } else { System.out.println("Could not initialize AdventureEventController. An instance already exists and cannot be merged."); } } - public static void clear(){ + public static void clear() { object = null; } - public AdventureEventData createEvent(EventStyle style, String pointID, int eventOrigin, PointOfInterestChanges changes) - { - if (nextEventDate.containsKey(pointID) && nextEventDate.get(pointID) >= LocalDate.now().toEpochDay()){ + public AdventureEventData createEvent(EventStyle style, String pointID, int eventOrigin, PointOfInterestChanges changes) { + if (nextEventDate.containsKey(pointID) && nextEventDate.get(pointID) >= LocalDate.now().toEpochDay()) { //No event currently available here return null; } long eventSeed; long timeSeed = LocalDate.now().toEpochDay(); - long placeSeed = Long.parseLong(pointID.replaceAll("[^0-9]","")); + long placeSeed = Long.parseLong(pointID.replaceAll("[^0-9]", "")); long room = Long.MAX_VALUE - placeSeed; - if (timeSeed > room){ + if (timeSeed > room) { //ensuring we don't ever hit an overflow eventSeed = Long.MIN_VALUE + timeSeed - room; - } - else - { + } else { eventSeed = timeSeed + placeSeed; } Random random = new Random(eventSeed); - AdventureEventData e ; + AdventureEventData e; - if (random.nextInt(10) <=2){ + if (random.nextInt(10) <= 2) { e = new AdventureEventData(eventSeed, EventFormat.Jumpstart); - } - else{ + } else { e = new AdventureEventData(eventSeed, EventFormat.Draft); } - if (e.cardBlock == null){ + if (e.cardBlock == null) { //covers cases where (somehow) editions that do not match the event style have been picked up return null; } @@ -118,13 +113,13 @@ public class AdventureEventController implements Serializable { e.eventRules = new AdventureEventData.AdventureEventRules(e.format, changes == null ? 1f : changes.getTownPriceModifier()); e.style = style; - switch (style){ + switch (style) { case Swiss: case Bracket: e.rounds = (e.participants.length / 2) - 1; break; case RoundRobin: - e.rounds = e.participants.length - 1 ; + e.rounds = e.participants.length - 1; break; } @@ -143,12 +138,11 @@ public class AdventureEventController implements Serializable { return output; } - public List getJumpstartBoosters(CardBlock block, int count){ + public List getJumpstartBoosters(CardBlock block, int count) { //Get all candidates then remove at random until no more than count are included //This will prevent duplicate choices within a round of a Jumpstart draft List packsAsDecks = new ArrayList<>(); - for(SealedTemplate template : StaticData.instance().getSpecialBoosters()) - { + for (SealedTemplate template : StaticData.instance().getSpecialBoosters()) { if (!template.getEdition().contains(block.getLandSet().getCode())) continue; UnOpenedProduct toOpen = new UnOpenedProduct(template); @@ -158,7 +152,7 @@ public class AdventureEventController implements Serializable { int size = contents.getMain().toFlatList().size(); - if ( size < 18 || size > 25) + if (size < 18 || size > 25) continue; contents.setName(template.getEdition()); @@ -171,7 +165,7 @@ public class AdventureEventController implements Serializable { int multi = 0; int colorless = 0; - for (PaperCard card: contents.getMain().toFlatList()) { + for (PaperCard card : contents.getMain().toFlatList()) { int colors = 0; if (card.getRules().getColorIdentity().hasBlack()) { black++; @@ -195,8 +189,7 @@ public class AdventureEventController implements Serializable { } if (colors == 0 && !card.getRules().getType().isLand()) { colorless++; - } - else if (colors > 1) { + } else if (colors > 1) { multi++; } } @@ -219,7 +212,7 @@ public class AdventureEventController implements Serializable { packsAsDecks.add(contents); } - while (packsAsDecks.size() > count){ + while (packsAsDecks.size() > count) { Aggregates.removeRandom(packsAsDecks); }