Merge pull request #1212 from Card-Forge/autoHealWhenEnteringTowns

Auto heal when entering towns
This commit is contained in:
Anthony Calosa
2022-08-13 18:15:37 +08:00
committed by GitHub
14 changed files with 107 additions and 31 deletions

View File

@@ -16,10 +16,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Clipboard; import com.badlogic.gdx.utils.Clipboard;
import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.ScreenUtils;
import forge.adventure.scene.ForgeScene; import forge.adventure.scene.*;
import forge.adventure.scene.GameScene;
import forge.adventure.scene.Scene;
import forge.adventure.scene.SceneType;
import forge.adventure.stage.MapStage; import forge.adventure.stage.MapStage;
import forge.adventure.util.Config; import forge.adventure.util.Config;
import forge.animation.ForgeAnimation; import forge.animation.ForgeAnimation;
@@ -52,10 +49,7 @@ import forge.toolbox.*;
import forge.util.*; import forge.util.*;
import java.io.File; import java.io.File;
import java.util.ArrayDeque; import java.util.*;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
public class Forge implements ApplicationListener { public class Forge implements ApplicationListener {
public static final String CURRENT_VERSION = "1.6.53.001"; public static final String CURRENT_VERSION = "1.6.53.001";
@@ -404,13 +398,13 @@ public class Forge implements ApplicationListener {
if (GuiBase.isAndroid()) if (GuiBase.isAndroid())
return; return;
if (isMobileAdventureMode) { if (isMobileAdventureMode) {
if (cursorA0 != null && name == "0") { if (cursorA0 != null && Objects.equals(name, "0")) {
setGdxCursor(cursorA0); setGdxCursor(cursorA0);
return; return;
} else if (cursorA1 != null && name == "1") { } else if (cursorA1 != null && Objects.equals(name, "1")) {
setGdxCursor(cursorA1); setGdxCursor(cursorA1);
return; return;
} else if (cursorA2 != null && name == "2") { } else if (cursorA2 != null && Objects.equals(name, "2")) {
setGdxCursor(cursorA2); setGdxCursor(cursorA2);
return; return;
} }
@@ -974,7 +968,6 @@ public class Forge implements ApplicationListener {
} }
} }
/** Retrieve assets. /** Retrieve assets.
* @param other if set to true returns otherAssets otherwise returns cardAssets
*/ */
public static Assets getAssets() { public static Assets getAssets() {
return ((Forge)Gdx.app.getApplicationListener()).assets; return ((Forge)Gdx.app.getApplicationListener()).assets;
@@ -990,6 +983,7 @@ public class Forge implements ApplicationListener {
if (newScene instanceof GameScene) if (newScene instanceof GameScene)
MapStage.getInstance().clearIsInMap(); MapStage.getInstance().clearIsInMap();
currentScene = newScene; currentScene = newScene;
currentScene.enter(); currentScene.enter();
return true; return true;
} }

View File

@@ -425,13 +425,33 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
o.run(); o.run();
} }
public void heal(int amount) { public boolean fullHeal() {
life = Math.min(life + amount, maxLife); if (life < maxLife) {
onLifeTotalChangeList.emit(); life = Math.max(maxLife, life);
onLifeTotalChangeList.emit();
return true;
}
return false;
} }
public void fullHeal() { public void potionOfFalseLife() {
life = maxLife; if (gold >= falseLifeCost() && life == maxLife) {
life = maxLife + 2;
gold -= falseLifeCost();
onLifeTotalChangeList.emit();
onGoldChangeList.emit();
} else {
System.out.println("Can't afford cost of false life " + falseLifeCost());
System.out.println("Only has this much gold " + gold);
}
}
public int falseLifeCost() {
return 200 + (int)(50 * getStatistic().winLossRatio());
}
public void heal(int amount) {
life = Math.min(life + amount, maxLife);
onLifeTotalChangeList.emit(); onLifeTotalChangeList.emit();
} }
public void defeated() { public void defeated() {

View File

@@ -2,6 +2,7 @@ package forge.adventure.scene;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import forge.Forge; import forge.Forge;
import forge.adventure.stage.GameHUD; import forge.adventure.stage.GameHUD;
@@ -11,7 +12,8 @@ import forge.adventure.util.Current;
* Scene for the Inn in towns * Scene for the Inn in towns
*/ */
public class InnScene extends UIScene { public class InnScene extends UIScene {
TextButton heal, sell, leave; TextButton tempHitPointCost, sell, leave;
Label tempHitPoints;
Image healIcon, sellIcon, leaveIcon; Image healIcon, sellIcon, leaveIcon;
public InnScene() { public InnScene() {
@@ -23,8 +25,8 @@ public class InnScene extends UIScene {
Forge.switchToLast(); Forge.switchToLast();
} }
public void heal() { public void potionOfFalseLife() {
Current.player().fullHeal(); Current.player().potionOfFalseLife();
} }
@Override @Override
@@ -41,10 +43,10 @@ public class InnScene extends UIScene {
InnScene.this.done(); InnScene.this.done();
} }
}); });
ui.onButtonPress("heal", new Runnable() { ui.onButtonPress("tempHitPointCost", new Runnable() {
@Override @Override
public void run() { public void run() {
InnScene.this.heal(); InnScene.this.potionOfFalseLife();
} }
}); });
ui.onButtonPress("sell", new Runnable() { ui.onButtonPress("sell", new Runnable() {
@@ -57,13 +59,26 @@ public class InnScene extends UIScene {
leave.getLabel().setText(Forge.getLocalizer().getMessage("lblLeave")); leave.getLabel().setText(Forge.getLocalizer().getMessage("lblLeave"));
sell = ui.findActor("sell"); sell = ui.findActor("sell");
sell.getLabel().setText(Forge.getLocalizer().getMessage("lblSell")); sell.getLabel().setText(Forge.getLocalizer().getMessage("lblSell"));
heal = ui.findActor("heal");
heal.getLabel().setText(Forge.getLocalizer().getMessage("lblHeal")); tempHitPoints = ui.findActor("tempHitPoints");
tempHitPoints.setText(Forge.getLocalizer().getMessageorUseDefault("lblTempHitPoints", "Temporary Hit Points"));
leaveIcon = ui.findActor("leaveIcon"); leaveIcon = ui.findActor("leaveIcon");
healIcon = ui.findActor("healIcon"); healIcon = ui.findActor("healIcon");
sellIcon = ui.findActor("sellIcon"); sellIcon = ui.findActor("sellIcon");
}
@Override
public void render() {
super.render();
int tempHealthCost = Current.player().falseLifeCost();
boolean purchaseable = Current.player().getMaxLife() == Current.player().getLife() &&
tempHealthCost <= Current.player().getGold();
tempHitPointCost = ui.findActor("tempHitPointCost");
tempHitPointCost.setDisabled(!purchaseable);
tempHitPointCost.getLabel().setText("$" + tempHealthCost);
} }
private void sell() { private void sell() {

View File

@@ -8,8 +8,11 @@ import forge.adventure.pointofintrest.PointOfInterest;
import forge.adventure.stage.MapStage; import forge.adventure.stage.MapStage;
import forge.adventure.stage.PointOfInterestMapRenderer; import forge.adventure.stage.PointOfInterestMapRenderer;
import forge.adventure.util.Config; import forge.adventure.util.Config;
import forge.adventure.util.Current;
import forge.adventure.util.TemplateTmxMapLoader; import forge.adventure.util.TemplateTmxMapLoader;
import forge.adventure.world.WorldSave; import forge.adventure.world.WorldSave;
import forge.sound.SoundEffectType;
import forge.sound.SoundSystem;
/** /**
* Scene that will render tiled maps. * Scene that will render tiled maps.
@@ -19,6 +22,7 @@ public class TileMapScene extends HudScene {
TiledMap map; TiledMap map;
PointOfInterestMapRenderer tiledMapRenderer; PointOfInterestMapRenderer tiledMapRenderer;
private String nextMap; private String nextMap;
private boolean autoheal = false;
private float cameraWidth = 0f, cameraHeight = 0f; private float cameraWidth = 0f, cameraHeight = 0f;
public TileMapScene() { public TileMapScene() {
@@ -46,6 +50,10 @@ public class TileMapScene extends HudScene {
} }
stage.act(Gdx.graphics.getDeltaTime()); stage.act(Gdx.graphics.getDeltaTime());
hud.act(Gdx.graphics.getDeltaTime()); hud.act(Gdx.graphics.getDeltaTime());
if (autoheal) { //todo add simple bg animation or effect
SoundSystem.instance.play(SoundEffectType.Enchantment, false);
autoheal = false;
}
} }
@Override @Override
@@ -80,6 +88,11 @@ public class TileMapScene extends HudScene {
@Override @Override
public void enter() { public void enter() {
super.enter(); super.enter();
if (inTown()) {
// auto heal
if (Current.player().fullHeal())
autoheal = true; // to play sound/effect on act
}
} }
public void load(PointOfInterest point) { public void load(PointOfInterest point) {

View File

@@ -236,7 +236,16 @@ public class GameHUD extends Stage {
miniMapPlayer.setPosition(miniMap.getX() + xPosMini - miniMapPlayer.getWidth()/2, miniMap.getY() + yPosMini - miniMapPlayer.getHeight()/2); miniMapPlayer.setPosition(miniMap.getX() + xPosMini - miniMapPlayer.getWidth()/2, miniMap.getY() + yPosMini - miniMapPlayer.getHeight()/2);
if (GuiBase.isAndroid()) // prevent drawing on top of console if (GuiBase.isAndroid()) // prevent drawing on top of console
miniMapPlayer.setVisible(!console.isVisible()&&miniMap.isVisible()); miniMapPlayer.setVisible(!console.isVisible()&&miniMap.isVisible());
//colored lifepoints
if (Current.player().getLife() >= Current.player().getMaxLife()) {
//color green if max life
lifePoints.setColor(Color.GREEN);
} else if (Current.player().getLife() <= 5) {
//color red if critical
lifePoints.setColor(Color.RED);
} else {
lifePoints.setColor(Color.WHITE);
}
} }
Texture miniMapTexture; Texture miniMapTexture;

View File

@@ -20,13 +20,22 @@
}, },
{ {
"type": "TextButton", "type": "TextButton",
"name": "heal", "name": "tempHitPointCost",
"text": "Heal", "text": "Cost",
"width": 100, "width": 100,
"height": 30, "height": 30,
"x": 60, "x": 60,
"y": 200 "y": 200
}, },
{
"type": "Label",
"name": "tempHitPoints",
"font": "default",
"width": 100,
"height": 30,
"x": 60,
"y": 180
},
{ {
"type": "Image", "type": "Image",
"name": "sellIcon", "name": "sellIcon",

View File

@@ -20,13 +20,22 @@
}, },
{ {
"type": "TextButton", "type": "TextButton",
"name": "heal", "name": "tempHitPointCost",
"text": "Heal", "text": "Cost",
"width": 100, "width": 100,
"height": 30, "height": 30,
"x": 165, "x": 165,
"y": 105 "y": 105
}, },
{
"type": "Label",
"name": "tempHitPoints",
"font": "default",
"width": 100,
"height": 30,
"x": 165,
"y": 85
},
{ {
"type": "Image", "type": "Image",
"name": "sellIcon", "name": "sellIcon",

View File

@@ -2897,3 +2897,4 @@ lblWinProper=Sieg
lblLossProper=Niederlage lblLossProper=Niederlage
lblWinLossRatio=Sieg/Niederlage-Quote lblWinLossRatio=Sieg/Niederlage-Quote
lblHeal=Heilen lblHeal=Heilen
lblTempHitPoints=Temporäre Trefferpunkte

View File

@@ -2899,4 +2899,5 @@ lblEdit=Edit
lblWinProper=Win lblWinProper=Win
lblLossProper=Loss lblLossProper=Loss
lblWinLossRatio=Win Loss Ratio lblWinLossRatio=Win Loss Ratio
lblHeal=Heal lblHeal=Heal
lblTempHitPoints=Temporary Hit Points

View File

@@ -2899,4 +2899,5 @@ lblEdit=Editar
lblWinProper=Ganar lblWinProper=Ganar
lblLossProper=Pérdida lblLossProper=Pérdida
lblWinLossRatio=Relación de pérdidas lblWinLossRatio=Relación de pérdidas
lblHeal=Curar lblHeal=Curar
lblTempHitPoints=Puntos de golpe temporales

View File

@@ -2903,3 +2903,4 @@ lblWinProper=Vincita
lblLossProper=Perdita lblLossProper=Perdita
lblWinLossRatio=Rapporto per perdite vincenti lblWinLossRatio=Rapporto per perdite vincenti
lblHeal=Guarire lblHeal=Guarire
lblTempHitPoints=Punti ferita temporanei

View File

@@ -2899,3 +2899,4 @@ lblWinProper=勝つ
lblLossProper=損失 lblLossProper=損失
lblWinLossRatio=損失率を獲得しました lblWinLossRatio=損失率を獲得しました
lblHeal=癒し lblHeal=癒し
lblTempHitPoints=一時的なヒットポイント

View File

@@ -2989,3 +2989,4 @@ lblWinProper=Vitória
lblLossProper=Derrota lblLossProper=Derrota
lblWinLossRatio=Taxa de Vitória Derrota lblWinLossRatio=Taxa de Vitória Derrota
lblHeal=Curar lblHeal=Curar
lblTempHitPoints=Pontos de vida temporários

View File

@@ -2882,3 +2882,4 @@ lblWinProper=赢
lblLossProper=失利 lblLossProper=失利
lblWinLossRatio=赢得损失比率 lblWinLossRatio=赢得损失比率
lblHeal=愈合 lblHeal=愈合
lblTempHitPoints=临时生命值