fix: improve turn handling and fix typing issues

This commit is contained in:
punchready 2021-06-04 07:47:20 +02:00
parent 23a8bcdeb4
commit 0eaa0c5ea1
2 changed files with 28 additions and 28 deletions

View File

@ -496,7 +496,7 @@ public class GameLogic {
state.entities.removeEntity(((EntityEvent)event).targetEntity); state.entities.removeEntity(((EntityEvent)event).targetEntity);
} }
case TakenDamageEvent -> { case TakenDamageEvent -> {
CharacterEvent data = (CharacterEvent)event; EntityEvent data = (EntityEvent)event;
Character target = (Character)state.entities.findEntity(data.targetEntity); Character target = (Character)state.entities.findEntity(data.targetEntity);
target.hp.decreaseValue(data.amount); target.hp.decreaseValue(data.amount);
@ -534,7 +534,7 @@ public class GameLogic {
state.turnOrder = new ArrayList<>(); state.turnOrder = new ArrayList<>();
for(EntityID turn: data.characterOrder) { for(EntityID turn: data.characterOrder) {
if(turn.type != EntityType.NPC) { if(turn.type != EntityType.NPC || turn.id == NPCType.Thanos.getID()) {
state.turnOrder.add(turn); state.turnOrder.add(turn);
} }
} }
@ -569,7 +569,7 @@ public class GameLogic {
} }
} }
case HealedEvent -> { case HealedEvent -> {
CharacterEvent data = (CharacterEvent)event; EntityEvent data = (EntityEvent)event;
((Character)state.entities.findEntity(data.targetEntity)).hp.increaseValue(data.amount); ((Character)state.entities.findEntity(data.targetEntity)).hp.increaseValue(data.amount);
} }
@ -784,6 +784,7 @@ public class GameLogic {
*/ */
protected static ArrayList<Event> checkTurnEnd(GameState state) { protected static ArrayList<Event> checkTurnEnd(GameState state) {
if( if(
(state.activeCharacter.type == EntityType.NPC && state.activeCharacter.id == NPCType.Thanos.getID()) ||
((Character) state.entities.findEntity(state.activeCharacter)).ap.getValue() <= 0 && ((Character) state.entities.findEntity(state.activeCharacter)).ap.getValue() <= 0 &&
((Character) state.entities.findEntity(state.activeCharacter)).mp.getValue() <= 0 ((Character) state.entities.findEntity(state.activeCharacter)).mp.getValue() <= 0
) { ) {
@ -809,21 +810,24 @@ public class GameLogic {
* @return The list of resulting {@link Event Events} * @return The list of resulting {@link Event Events}
*/ */
private static ArrayList<Event> handleTurnEnd(GameState state) { private static ArrayList<Event> handleTurnEnd(GameState state) {
System.out.println("Turn ended");
ArrayList<Event> result = new ArrayList<>(); ArrayList<Event> result = new ArrayList<>();
ArrayList<EntityID> alive = new ArrayList<>(); boolean anyAlive = false;
ArrayList<EntityID> turns = new ArrayList<>();
for (EntityID id: state.turnOrder) { for (EntityID id: state.turnOrder) {
if(id.type == EntityType.NPC) { if(id.type == EntityType.NPC) {
if(id.id == NPCType.Thanos.getID()) {
turns.add(id);
}
continue; continue;
} }
Character character = ((Character)state.entities.findEntity(id)); Character character = ((Character)state.entities.findEntity(id));
if(character.isAlive()){ if(character.isAlive()){
alive.add(id); anyAlive = true;
turns.add(id);
}else { // send empty turn for knocked out characters }else { // send empty turn for knocked out characters
result.add(new EventBuilder(EventType.TurnEvent) result.add(new EventBuilder(EventType.TurnEvent)
.withTurnCount(state.turnOrder.size()) .withTurnCount(state.turnOrder.size())
@ -837,7 +841,7 @@ public class GameLogic {
} }
} }
if(alive.isEmpty()) { if(!anyAlive) {
EntityType winner = state.winConditions.getWinner(); EntityType winner = state.winConditions.getWinner();
if(winner == EntityType.None) { if(winner == EntityType.None) {
winner = rand.nextBoolean() ? EntityType.P1 : EntityType.P2; winner = rand.nextBoolean() ? EntityType.P1 : EntityType.P2;
@ -846,11 +850,11 @@ public class GameLogic {
return result; return result;
} }
int index = alive.indexOf(state.activeCharacter); int index = turns.indexOf(state.activeCharacter);
if(index == alive.size() - 1) { if(index == turns.size() - 1) {
result.addAll(handleRoundStart(state)); result.addAll(handleRoundStart(state));
}else { }else {
state.activeCharacter = alive.get(index + 1); state.activeCharacter = turns.get(index + 1);
} }
result.addAll(handleTurnStart(state)); result.addAll(handleTurnStart(state));
@ -888,7 +892,6 @@ public class GameLogic {
} }
if(state.roundNumber == state.partyConfig.maxRounds + 1) { if(state.roundNumber == state.partyConfig.maxRounds + 1) {
turns.add(new EntityID(EntityType.NPC, NPCType.Thanos.getID()));
result.addAll(spawnThanos(state)); result.addAll(spawnThanos(state));
} }
@ -911,8 +914,6 @@ public class GameLogic {
// RoundSetupEvent has to be sent first, but the contents of it are determined later... // RoundSetupEvent has to be sent first, but the contents of it are determined later...
((GameEvent)result.get(0)).characterOrder = turns.toArray(new EntityID[0]); ((GameEvent)result.get(0)).characterOrder = turns.toArray(new EntityID[0]);
System.out.println(turns);
return result; return result;
} }
@ -922,8 +923,6 @@ public class GameLogic {
* @return The list of resulting {@link Event Events} * @return The list of resulting {@link Event Events}
*/ */
private static ArrayList<Event> handleGoose(GameState state) { private static ArrayList<Event> handleGoose(GameState state) {
System.out.println("Handling goose");
ArrayList<Event> result = new ArrayList<>(); ArrayList<Event> result = new ArrayList<>();
ArrayList<StoneType> inventory = new ArrayList<>(state.unvomitedStones); ArrayList<StoneType> inventory = new ArrayList<>(state.unvomitedStones);
@ -967,8 +966,6 @@ public class GameLogic {
* @return The list of resulting {@link Event Events} * @return The list of resulting {@link Event Events}
*/ */
private static ArrayList<Event> handleStan(GameState state, HashSet<EntityID> revived) { private static ArrayList<Event> handleStan(GameState state, HashSet<EntityID> revived) {
System.out.println("Handling stan");
ArrayList<Event> result = new ArrayList<>(); ArrayList<Event> result = new ArrayList<>();
ArrayList<Character> characters = new ArrayList<>(); ArrayList<Character> characters = new ArrayList<>();
@ -1033,8 +1030,6 @@ public class GameLogic {
* @return The list of resulting {@link Event Events} * @return The list of resulting {@link Event Events}
*/ */
private static ArrayList<Event> spawnThanos(GameState state) { private static ArrayList<Event> spawnThanos(GameState state) {
System.out.println("Spawning thanos");
ArrayList<Event> result = new ArrayList<>(); ArrayList<Event> result = new ArrayList<>();
ArrayList<IntVector2> free = getFreeFields(state); ArrayList<IntVector2> free = getFreeFields(state);
@ -1050,11 +1045,13 @@ public class GameLogic {
} }
EntityID thanos = new EntityID(EntityType.NPC, NPCType.Thanos.getID()); EntityID thanos = new EntityID(EntityType.NPC, NPCType.Thanos.getID());
NPC thanosNPC = new NPC(thanos, position, maxMP);
result.add(new EventBuilder(EventType.SpawnEntityEvent) result.add(new EventBuilder(EventType.SpawnEntityEvent)
.withEntity(new NPC(thanos, position, maxMP)) .withEntity(thanosNPC)
.buildEntityEvent()); .buildEntityEvent());
state.turnOrder.add(thanos); state.turnOrder.add(thanos);
state.entities.addEntity(thanosNPC);
return result; return result;
} }
@ -1065,8 +1062,6 @@ public class GameLogic {
* @return The list of resulting {@link Event Events} * @return The list of resulting {@link Event Events}
*/ */
private static ArrayList<Event> handleThanos(GameState state, NPC thanos) { private static ArrayList<Event> handleThanos(GameState state, NPC thanos) {
System.out.println("Handling thanos");
ArrayList<Event> result = new ArrayList<>(); ArrayList<Event> result = new ArrayList<>();
result.add(new EventBuilder(EventType.TurnEvent) result.add(new EventBuilder(EventType.TurnEvent)
@ -1132,7 +1127,7 @@ public class GameLogic {
.withTargetEntity(thanos.id) .withTargetEntity(thanos.id)
.withTargetField(pos) .withTargetField(pos)
.withAmount(1) .withAmount(1)
.buildCharacterEvent()); .buildEntityEvent());
if(pos.equals(picked)) { if(pos.equals(picked)) {
for(Entity entity: state.entities.findByPosition(pos)) { for(Entity entity: state.entities.findByPosition(pos)) {
@ -1164,7 +1159,7 @@ public class GameLogic {
}else { }else {
for(EntityID id: state.turnOrder) { for(EntityID id: state.turnOrder) {
if(id.equals(thanos.id)) { if(id.type == EntityType.NPC) {
continue; continue;
} }
if(rand.nextBoolean()) { if(rand.nextBoolean()) {
@ -1186,8 +1181,6 @@ public class GameLogic {
* @return The list of resulting {@link Event Events} * @return The list of resulting {@link Event Events}
*/ */
private static ArrayList<Event> handleTurnStart(GameState state) { private static ArrayList<Event> handleTurnStart(GameState state) {
System.out.println("Turn of " + state.activeCharacter + " started");
ArrayList<Event> result = new ArrayList<>(); ArrayList<Event> result = new ArrayList<>();
if(state.activeCharacter.type == EntityType.NPC && state.activeCharacter.id == NPCType.Thanos.getID()) { if(state.activeCharacter.type == EntityType.NPC && state.activeCharacter.id == NPCType.Thanos.getID()) {
@ -1211,6 +1204,8 @@ public class GameLogic {
* @return The list of resulting {@link Event Events} * @return The list of resulting {@link Event Events}
*/ */
private static ArrayList<Event> handlePlayerWin(GameState state, EntityType winner) { private static ArrayList<Event> handlePlayerWin(GameState state, EntityType winner) {
System.out.println("Player " + winner + " won");
ArrayList<Event> result = new ArrayList<>(); ArrayList<Event> result = new ArrayList<>();
result.add(new EventBuilder(EventType.WinEvent) result.add(new EventBuilder(EventType.WinEvent)

View File

@ -4,6 +4,7 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig; import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
import uulm.teamname.marvelous.gamelibrary.config.PartyConfig; import uulm.teamname.marvelous.gamelibrary.config.PartyConfig;
import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig; import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig;
import uulm.teamname.marvelous.gamelibrary.entities.Character;
import uulm.teamname.marvelous.gamelibrary.entities.Entity; import uulm.teamname.marvelous.gamelibrary.entities.Entity;
import uulm.teamname.marvelous.gamelibrary.entities.EntityID; import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
import uulm.teamname.marvelous.gamelibrary.entities.StoneType; import uulm.teamname.marvelous.gamelibrary.entities.StoneType;
@ -143,7 +144,11 @@ class GameState {
} }
} }
case P1, P2 -> { case P1, P2 -> {
sb.append("X "); if(((Character)entities.get(0)).isAlive()) {
sb.append("X ");
}else {
sb.append("x ");
}
} }
case Rocks -> { case Rocks -> {
sb.append("O "); sb.append("O ");