Add Spell Smith Insurance (reject smithing for 10% cost)

This commit is contained in:
Chris H
2024-10-05 21:37:42 -04:00
parent 69d8bf52d3
commit dd60a84f40
3 changed files with 122 additions and 17 deletions

View File

@@ -39,7 +39,7 @@ public class SpellSmithScene extends UIScene {
private List<PaperCard> cardPool = new ArrayList<>();
private TextraLabel playerGold, playerShards, poolSize;
private final TextraButton pullUsingGold, pullUsingShards;
private final TextraButton pullUsingGold, pullUsingShards, acceptReward, declineReward, exitSmith;
private final ScrollPane rewardDummy;
private RewardActor rewardActor;
SelectBox<CardEdition> editionList;
@@ -47,6 +47,7 @@ public class SpellSmithScene extends UIScene {
final private HashMap<String, TextraButton> rarityButtons = new HashMap<>();
final private HashMap<String, TextraButton> costButtons = new HashMap<>();
final private HashMap<String, TextraButton> colorButtons = new HashMap<>();
//Filter variables.
private String edition = "";
private String rarity = "";
@@ -57,20 +58,28 @@ public class SpellSmithScene extends UIScene {
private int currentPrice = 0;
private int currentShardPrice = 0;
private List<CardEdition> editions = null;
private Reward currentReward = null;
private boolean paidInShards = false;
private SpellSmithScene() {
super(Forge.isLandscapeMode() ? "ui/spellsmith.json" : "ui/spellsmith_portrait.json");
editionList = ui.findActor("BSelectPlane");
rewardDummy = ui.findActor("RewardDummy");
rewardDummy.setVisible(false);
pullUsingGold = ui.findActor("pullUsingGold");
pullUsingGold.setDisabled(true);
pullUsingShards = ui.findActor("pullUsingShards");
pullUsingShards.setDisabled(true);
exitSmith = ui.findActor("done");
acceptReward = ui.findActor("accept");
acceptReward.setVisible(false);
declineReward = ui.findActor("decline");
declineReward.setVisible(false);
playerGold = Controls.newAccountingLabel(ui.findActor("playerGold"), false);
playerShards = Controls.newAccountingLabel(ui.findActor("playerShards"), true);
poolSize = ui.findActor("poolSize");
@@ -114,6 +123,8 @@ public class SpellSmithScene extends UIScene {
}
}
ui.onButtonPress("accept", SpellSmithScene.this::acceptSmithing);
ui.onButtonPress("decline", SpellSmithScene.this::declineSmithing);
ui.onButtonPress("done", SpellSmithScene.this::done);
ui.onButtonPress("pullUsingGold", () -> SpellSmithScene.this.pullCard(false));
ui.onButtonPress("pullUsingShards", () -> SpellSmithScene.this.pullCard(true));
@@ -122,6 +133,7 @@ public class SpellSmithScene extends UIScene {
filterResults();
});
}
private void reset() {
edition = "";
cost_low = -1;
@@ -160,6 +172,10 @@ public class SpellSmithScene extends UIScene {
}
public boolean done() {
if (currentReward != null) {
acceptSmithing();
}
if (rewardActor != null) rewardActor.remove();
cardPool.clear(); //Get rid of cardPool, filtering is fast enough to justify keeping it cached.
Forge.switchToLast();
@@ -380,29 +396,74 @@ public class SpellSmithScene extends UIScene {
}
public void pullCard(boolean usingShards) {
paidInShards = usingShards;
PaperCard P = cardPool.get(MyRandom.getRandom().nextInt(cardPool.size())); //Don't use the standard RNG.
Reward R = null;
currentReward = null;
if (Config.instance().getSettingData().useAllCardVariants) {
if (!edition.isEmpty()) {
R = new Reward(CardUtil.getCardByNameAndEdition(P.getCardName(), edition));
currentReward = new Reward(CardUtil.getCardByNameAndEdition(P.getCardName(), edition));
} else {
R = new Reward(CardUtil.getCardByName(P.getCardName())); // grab any random variant if no set preference is specified
currentReward = new Reward(CardUtil.getCardByName(P.getCardName())); // grab any random variant if no set preference is specified
}
} else {
R = new Reward(P);
currentReward = new Reward(P);
}
Current.player().addReward(R);
if (usingShards) {
if (rewardActor != null) rewardActor.remove();
rewardActor = new RewardActor(currentReward, true, null, true);
rewardActor.flip(); //Make it flip so it draws visual attention, why not.
rewardActor.setBounds(rewardDummy.getX(), rewardDummy.getY(), rewardDummy.getWidth(), rewardDummy.getHeight());
stage.addActor(rewardActor);
acceptReward.setVisible(true);
declineReward.setVisible(true);
exitSmith.setDisabled(true);
disablePullButtons();
}
private void acceptSmithing() {
if (paidInShards) {
Current.player().takeShards(currentShardPrice);
} else {
Current.player().takeGold(currentPrice);
}
if (Current.player().getGold() < currentPrice) pullUsingGold.setDisabled(true);
if (Current.player().getShards() < currentShardPrice) pullUsingShards.setDisabled(true);
Current.player().addReward(currentReward);
clearReward();
updatePullButtons();
}
private void declineSmithing() {
// Decline the smith reward for 10% of original price
float priceAdjustment = .10f;
if (paidInShards) {
Current.player().takeShards((int)(currentShardPrice * priceAdjustment));
} else {
Current.player().takeGold((int)(currentPrice * priceAdjustment));
}
clearReward();
updatePullButtons();
}
private void clearReward() {
if (rewardActor != null) rewardActor.remove();
rewardActor = new RewardActor(R, true, null, true);
rewardActor.flip(); //Make it flip so it draws visual attention, why not.
rewardActor.setBounds(rewardDummy.getX(), rewardDummy.getY(), rewardDummy.getWidth(), rewardDummy.getHeight());
stage.addActor(rewardActor);
currentReward = null;
}
private void updatePullButtons() {
pullUsingGold.setDisabled(Current.player().getGold() < currentPrice);
pullUsingShards.setDisabled(Current.player().getShards() < currentShardPrice);
acceptReward.setVisible(false);
declineReward.setVisible(false);
exitSmith.setDisabled(false);
}
private void disablePullButtons() {
pullUsingGold.setDisabled(true);
pullUsingShards.setDisabled(true);
}
}

View File

@@ -169,12 +169,34 @@
"y": 5,
"width": 90,
"height": 20
},
{
"type": "TextButton",
"selectable": true,
"name": "accept",
"text": "Take",
"binding": "Use",
"x": 343,
"y": 173,
"width": 60,
"height": 20
},
{
"type": "TextButton",
"selectable": true,
"name": "decline",
"text": "Refund",
"binding": "Back",
"x": 405,
"y": 173,
"width": 60,
"height": 20
},
{
"type": "Label",
"name": "poolSize",
"x": 360,
"y": 180,
"y": 192,
"width": 90,
"height": 20
},

View File

@@ -174,12 +174,34 @@
"y": 75,
"width": 90,
"height": 20
},
{
"type": "TextButton",
"selectable": true,
"name": "accept",
"text": "Take",
"binding": "Use",
"x": 2,
"y": 142,
"width": 60,
"height": 20
},
{
"type": "TextButton",
"selectable": true,
"name": "decline",
"text": "Refund",
"binding": "Back",
"x": 70,
"y": 142,
"width": 60,
"height": 20
},
{
"type": "Label",
"name": "poolSize",
"x": 16,
"y": 150,
"y": 163,
"width": 97,
"height": 20
},