Merge pull request #6002 from kevlahnota/master2

add resetPlayerLocation on defeat
This commit is contained in:
kevlahnota
2024-08-29 11:28:55 +08:00
committed by GitHub
17 changed files with 77 additions and 40 deletions

View File

@@ -153,7 +153,7 @@ public class GuiMobile implements IGuiBase {
@Override
public void showImageDialog(final ISkinImage image, final String message, final String title) {
if (Forge.isMobileAdventureMode) {
FThreads.invokeInEdtNowOrLater(() -> MapStage.getInstance().showImageDialog("Achievement Earned\n"+message, (FBufferedImage)image));
FThreads.invokeInEdtNowOrLater(() -> MapStage.getInstance().showImageDialog("Achievement Earned\n"+message, (FBufferedImage)image, null));
return;
}
new WaitCallback<Integer>() {

View File

@@ -43,7 +43,7 @@ public class EntryActor extends MapActor{
{
if(targetMap==null||targetMap.isEmpty())
{
stage.exitDungeon();
stage.exitDungeon(false);
}
else
{

View File

@@ -39,7 +39,7 @@ public class PortalActor extends EntryActor {
}
if (currentAnimationType == PortalAnimationTypes.Active) {
if (targetMap == null || targetMap.isEmpty()) {
stage.exitDungeon();
stage.exitDungeon(false);
} else {
if (targetMap.equals(currentMap)) {
stage.spawn(entryTargetObject);

View File

@@ -737,11 +737,10 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
public boolean defeated() {
gold = (int) (gold - (gold * difficultyData.goldLoss));
int newLife = (int) (life - (maxLife * difficultyData.lifeLoss));
life = Math.max(1, newLife);
life = (int) (life - (maxLife * difficultyData.lifeLoss));
onLifeTotalChangeList.emit();
onGoldChangeList.emit();
return newLife < 1;
return life < 1;
//If true, the player would have had 0 or less, and thus is actually "defeated" if the caller cares about it
}

View File

@@ -193,7 +193,7 @@ public class ConsoleCommandInterpreter {
});
registerCommand(new String[]{"leave"}, s -> {
if (!MapStage.getInstance().isInMap()) return "not on a map";
MapStage.getInstance().exitDungeon();
MapStage.getInstance().exitDungeon(false);
return "Got out";
});
registerCommand(new String[]{"debug", "collision"}, s -> {

View File

@@ -882,7 +882,7 @@ public class GameHUD extends Stage {
@Override
public boolean act(float v) {
if (exitDungeon) {
MapStage.getInstance().exitDungeon();
MapStage.getInstance().exitDungeon(false);
setDisabled(exitToWorldMapActor, true, "[%120][+ExitToWorldMap]", "\uFF0F");
setDisabled(bookmarkActor, true, "[%120][+Bookmark]", "\uFF0F");
}

View File

@@ -34,6 +34,7 @@ import forge.adventure.scene.Scene;
import forge.adventure.scene.StartScene;
import forge.adventure.scene.TileMapScene;
import forge.adventure.util.Controls;
import forge.adventure.util.Current;
import forge.adventure.util.KeyBinding;
import forge.adventure.util.MapDialog;
import forge.adventure.util.Paths;
@@ -46,7 +47,9 @@ import forge.card.ColorSet;
import forge.deck.Deck;
import forge.deck.DeckProxy;
import forge.game.GameType;
import forge.gui.FThreads;
import forge.gui.GuiBase;
import forge.screens.TransitionScreen;
import forge.util.MyRandom;
import java.util.HashMap;
@@ -144,12 +147,12 @@ public abstract class GameStage extends Stage {
showDialog();
}
public void showImageDialog(String message, FBufferedImage fb) {
public void showImageDialog(String message, FBufferedImage fb, Runnable runnable) {
dialog.getContentTable().clear();
dialog.getButtonTable().clear();
dialog.clearListeners();
if (fb.getTexture() != null) {
if (fb != null && fb.getTexture() != null) {
TextureRegion tr = new TextureRegion(fb.getTexture());
tr.flip(true, true);
Image image = new Image(tr);
@@ -166,9 +169,13 @@ public abstract class GameStage extends Stage {
Timer.schedule(new Timer.Task() {
@Override
public void run() {
fb.dispose();
if (fb != null)
fb.dispose();
}
}, 0.5f);
if (runnable != null) {
runnable.run();
}
})).width(240f);
dialog.setKeepWithinStage(true);
setDialogStage(GameHUD.getInstance());
@@ -634,4 +641,17 @@ public abstract class GameStage extends Stage {
teleported(position);
}
public void resetPlayerLocation()
{
PointOfInterest poi = Current.world().findPointsOfInterest("Spawn");
if (poi != null) {
showImageDialog(Forge.getLocalizer().getMessage("lblYouDied", Current.player().getName()), null,
() -> FThreads.invokeInEdtNowOrLater(() -> Forge.setTransitionScreen(new TransitionScreen(() -> {
WorldStage.getInstance().setPosition(new Vector2(poi.getPosition().x - 16f, poi.getPosition().y + 16f));
WorldStage.getInstance().loadPOI(poi);
Forge.clearTransitionScreen();
}, null, false, true, false, false))));
}//Spawn shouldn't be null
}
}

View File

@@ -605,7 +605,7 @@ public class MapStage extends GameStage {
}));
break;
case "exit":
addMapActor(obj, new OnCollide(MapStage.this::exitDungeon));
addMapActor(obj, new OnCollide(() -> MapStage.this.exitDungeon(false)));
break;
case "dialog":
if (obj instanceof TiledMapTileMapObject) {
@@ -749,13 +749,15 @@ public class MapStage extends GameStage {
}
}
public boolean exitDungeon() {
public boolean exitDungeon(boolean defeated) {
WorldSave.getCurrentSave().autoSave();
AdventureQuestController.instance().updateQuestsLeave();
clearIsInMap();
AdventureQuestController.instance().showQuestDialogs(this);
isLoadingMatch = false;
effect = null; //Reset dungeon effects.
if (defeated)
WorldStage.getInstance().resetPlayerLocation();
Forge.switchScene(GameScene.instance());
return true;
}
@@ -799,18 +801,18 @@ public class MapStage extends GameStage {
AdventureQuestController.instance().updateQuestsLose(currentMob);
AdventureQuestController.instance().showQuestDialogs(MapStage.this);
boolean defeated = Current.player().defeated();
if (canFailDungeon && defeated) {
//If hardcore mode is added, check and redirect to game over screen here
dungeonFailedDialog();
exitDungeon();
}
//If hardcore mode is added, check and redirect to game over screen here
if (canFailDungeon && !defeated)
dungeonFailedDialog(true);
else
exitDungeon(defeated);
MapStage.this.stop();
currentMob = null;
});
}
}
private void dungeonFailedDialog() {
private void dungeonFailedDialog(boolean exit) {
dialog.getButtonTable().clear();
dialog.getContentTable().clear();
dialog.clearListeners();
@@ -829,7 +831,8 @@ public class MapStage extends GameStage {
public void clicked(InputEvent event, float x, float y) {
L.skipToTheEnd();
super.clicked(event, x, y);
//exitDungeon();
if (exit)
exitDungeon(false);
}
});
dialog.getButtonTable().add(ok).width(240f);

View File

@@ -188,11 +188,14 @@ public class WorldStage extends GameStage implements SaveFileContent {
currentMob.setAnimation(CharacterSprite.AnimationTypes.Attack);
startPause(0.5f, () -> {
currentMob.resetCollisionHeight();
Current.player().defeated();
boolean defeated = Current.player().defeated();
AdventureQuestController.instance().updateQuestsLose(currentMob);
AdventureQuestController.instance().showQuestDialogs(MapStage.getInstance());
WorldStage.this.removeEnemy(currentMob);
currentMob = null;
if (defeated) {
WorldStage.getInstance().resetPlayerLocation();
}
});
}
}
@@ -209,17 +212,9 @@ public class WorldStage extends GameStage implements SaveFileContent {
if (point == collidingPoint) {
continue;
}
try {
WorldSave.getCurrentSave().autoSave();
TileMapScene.instance().load(point.getPointOfInterest());
stop();
TileMapScene.instance().setFromWorldMap(true);
Forge.switchScene(TileMapScene.instance());
point.getMapSprite().checkOut();
} catch (Exception e) {
System.err.println("Error loading map...");
e.printStackTrace();
}
WorldSave.getCurrentSave().autoSave();
loadPOI(point.getPointOfInterest());
point.getMapSprite().checkOut();
} else {
if (point == collidingPoint) {
collidingPoint = null;
@@ -229,6 +224,18 @@ public class WorldStage extends GameStage implements SaveFileContent {
}
}
public void loadPOI(PointOfInterest poi) {
try {
TileMapScene.instance().load(poi);
stop();
TileMapScene.instance().setFromWorldMap(true);
Forge.switchScene(TileMapScene.instance());
} catch (Exception e) {
System.err.println("Error loading map...");
e.printStackTrace();
}
}
@Override
public boolean isColliding(Rectangle boundingRect) {
if (currentModifications.containsKey(PlayerModification.Fly))

View File

@@ -3419,4 +3419,5 @@ AdvBossIntro31=Was wird als nächstes passieren?
AdvBossIntro32=Nicht blinzeln!
AdvBossIntro33=Hier kann man nicht verlieren!
AdvBossIntro34=Es gibt kein Zurück!
AdvBossIntro35=Jetzt geht es um alles oder nichts!
AdvBossIntro35=Jetzt geht es um alles oder nichts!
lblYouDied={0}, du bist gestorben!!!

View File

@@ -3152,4 +3152,5 @@ AdvBossIntro31=What will happen next?
AdvBossIntro32=Don't blink!
AdvBossIntro33=You can't lose here!
AdvBossIntro34=There's no turning back!
AdvBossIntro35=It's all or nothing now!
AdvBossIntro35=It's all or nothing now!
lblYouDied={0}, You Died!!!

View File

@@ -3433,4 +3433,5 @@ AdvBossIntro31=¿Qué pasará después?
AdvBossIntro32=¡No parpadees!
AdvBossIntro33=¡No puedes perder aquí!
AdvBossIntro34=¡No hay marcha atrás!
AdvBossIntro35=¡Ahora es todo o nada!
AdvBossIntro35=¡Ahora es todo o nada!
lblYouDied={0}, ¡¡¡Moriste!!!

View File

@@ -3427,4 +3427,5 @@ AdvBossIntro31=Que va-t-il se passer ensuite?
AdvBossIntro32=Ne clignez pas des yeux !
AdvBossIntro33=Vous ne pouvez pas perdre ici !
AdvBossIntro34=Il n'y a pas de retour en arrière!
AdvBossIntro35=C'est tout ou rien maintenant !
AdvBossIntro35=C'est tout ou rien maintenant !
lblYouDied={0}, tu es mort !!!

View File

@@ -3425,4 +3425,5 @@ AdvBossIntro31=Cosa succederà dopo?
AdvBossIntro32=Non sbattere le palpebre!
AdvBossIntro33=Non puoi perdere qui!
AdvBossIntro34=Non si può tornare indietro!
AdvBossIntro35=Adesso è tutto o niente!
AdvBossIntro35=Adesso è tutto o niente!
lblYouDied={0}, sei morto!!!

View File

@@ -3421,4 +3421,5 @@ AdvBossIntro31=次は何が起こるのだろう?
AdvBossIntro32=瞬きしないでください!
AdvBossIntro33=ここで負けるわけにはいかない!
AdvBossIntro34=もう後戻りはできない!
AdvBossIntro35=もう、オール・オア・ナッシングだ!
AdvBossIntro35=もう、オール・オア・ナッシングだ!
lblYouDied={0}、死んだ!!!

View File

@@ -3511,4 +3511,5 @@ AdvBossIntro31=O que vai acontecer à seguir?
AdvBossIntro32=Não pisque!
AdvBossIntro33=Você não pode perder aqui!
AdvBossIntro34=Não há como voltar atrás!
AdvBossIntro35=É tudo ou nada agora!
AdvBossIntro35=É tudo ou nada agora!
lblYouDied={0}, você morreu!!!

View File

@@ -3412,4 +3412,5 @@ AdvBossIntro31=接下来会发生什么?
AdvBossIntro32=别眨眼!
AdvBossIntro33=在这里你不能输!
AdvBossIntro34=没有回头路了!
AdvBossIntro35=现在要么全有要么全无!
AdvBossIntro35=现在要么全有要么全无!
lblYouDied={0},你死了!!!