fix: improve turn handling and fix typing issues
This commit is contained in:
parent
23a8bcdeb4
commit
0eaa0c5ea1
@ -496,7 +496,7 @@ public class GameLogic {
|
||||
state.entities.removeEntity(((EntityEvent)event).targetEntity);
|
||||
}
|
||||
case TakenDamageEvent -> {
|
||||
CharacterEvent data = (CharacterEvent)event;
|
||||
EntityEvent data = (EntityEvent)event;
|
||||
|
||||
Character target = (Character)state.entities.findEntity(data.targetEntity);
|
||||
target.hp.decreaseValue(data.amount);
|
||||
@ -534,7 +534,7 @@ public class GameLogic {
|
||||
|
||||
state.turnOrder = new ArrayList<>();
|
||||
for(EntityID turn: data.characterOrder) {
|
||||
if(turn.type != EntityType.NPC) {
|
||||
if(turn.type != EntityType.NPC || turn.id == NPCType.Thanos.getID()) {
|
||||
state.turnOrder.add(turn);
|
||||
}
|
||||
}
|
||||
@ -569,7 +569,7 @@ public class GameLogic {
|
||||
}
|
||||
}
|
||||
case HealedEvent -> {
|
||||
CharacterEvent data = (CharacterEvent)event;
|
||||
EntityEvent data = (EntityEvent)event;
|
||||
|
||||
((Character)state.entities.findEntity(data.targetEntity)).hp.increaseValue(data.amount);
|
||||
}
|
||||
@ -784,6 +784,7 @@ public class GameLogic {
|
||||
*/
|
||||
protected static ArrayList<Event> checkTurnEnd(GameState state) {
|
||||
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)).mp.getValue() <= 0
|
||||
) {
|
||||
@ -809,21 +810,24 @@ public class GameLogic {
|
||||
* @return The list of resulting {@link Event Events}
|
||||
*/
|
||||
private static ArrayList<Event> handleTurnEnd(GameState state) {
|
||||
System.out.println("Turn ended");
|
||||
|
||||
ArrayList<Event> result = new ArrayList<>();
|
||||
|
||||
ArrayList<EntityID> alive = new ArrayList<>();
|
||||
boolean anyAlive = false;
|
||||
ArrayList<EntityID> turns = new ArrayList<>();
|
||||
|
||||
for (EntityID id: state.turnOrder) {
|
||||
if(id.type == EntityType.NPC) {
|
||||
if(id.id == NPCType.Thanos.getID()) {
|
||||
turns.add(id);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Character character = ((Character)state.entities.findEntity(id));
|
||||
|
||||
if(character.isAlive()){
|
||||
alive.add(id);
|
||||
anyAlive = true;
|
||||
turns.add(id);
|
||||
}else { // send empty turn for knocked out characters
|
||||
result.add(new EventBuilder(EventType.TurnEvent)
|
||||
.withTurnCount(state.turnOrder.size())
|
||||
@ -837,7 +841,7 @@ public class GameLogic {
|
||||
}
|
||||
}
|
||||
|
||||
if(alive.isEmpty()) {
|
||||
if(!anyAlive) {
|
||||
EntityType winner = state.winConditions.getWinner();
|
||||
if(winner == EntityType.None) {
|
||||
winner = rand.nextBoolean() ? EntityType.P1 : EntityType.P2;
|
||||
@ -846,11 +850,11 @@ public class GameLogic {
|
||||
return result;
|
||||
}
|
||||
|
||||
int index = alive.indexOf(state.activeCharacter);
|
||||
if(index == alive.size() - 1) {
|
||||
int index = turns.indexOf(state.activeCharacter);
|
||||
if(index == turns.size() - 1) {
|
||||
result.addAll(handleRoundStart(state));
|
||||
}else {
|
||||
state.activeCharacter = alive.get(index + 1);
|
||||
state.activeCharacter = turns.get(index + 1);
|
||||
}
|
||||
|
||||
result.addAll(handleTurnStart(state));
|
||||
@ -888,7 +892,6 @@ public class GameLogic {
|
||||
}
|
||||
|
||||
if(state.roundNumber == state.partyConfig.maxRounds + 1) {
|
||||
turns.add(new EntityID(EntityType.NPC, NPCType.Thanos.getID()));
|
||||
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...
|
||||
((GameEvent)result.get(0)).characterOrder = turns.toArray(new EntityID[0]);
|
||||
|
||||
System.out.println(turns);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -922,8 +923,6 @@ public class GameLogic {
|
||||
* @return The list of resulting {@link Event Events}
|
||||
*/
|
||||
private static ArrayList<Event> handleGoose(GameState state) {
|
||||
System.out.println("Handling goose");
|
||||
|
||||
ArrayList<Event> result = new ArrayList<>();
|
||||
|
||||
ArrayList<StoneType> inventory = new ArrayList<>(state.unvomitedStones);
|
||||
@ -967,8 +966,6 @@ public class GameLogic {
|
||||
* @return The list of resulting {@link Event Events}
|
||||
*/
|
||||
private static ArrayList<Event> handleStan(GameState state, HashSet<EntityID> revived) {
|
||||
System.out.println("Handling stan");
|
||||
|
||||
ArrayList<Event> result = new ArrayList<>();
|
||||
|
||||
ArrayList<Character> characters = new ArrayList<>();
|
||||
@ -1033,8 +1030,6 @@ public class GameLogic {
|
||||
* @return The list of resulting {@link Event Events}
|
||||
*/
|
||||
private static ArrayList<Event> spawnThanos(GameState state) {
|
||||
System.out.println("Spawning thanos");
|
||||
|
||||
ArrayList<Event> result = new ArrayList<>();
|
||||
|
||||
ArrayList<IntVector2> free = getFreeFields(state);
|
||||
@ -1050,11 +1045,13 @@ public class GameLogic {
|
||||
}
|
||||
|
||||
EntityID thanos = new EntityID(EntityType.NPC, NPCType.Thanos.getID());
|
||||
NPC thanosNPC = new NPC(thanos, position, maxMP);
|
||||
result.add(new EventBuilder(EventType.SpawnEntityEvent)
|
||||
.withEntity(new NPC(thanos, position, maxMP))
|
||||
.withEntity(thanosNPC)
|
||||
.buildEntityEvent());
|
||||
|
||||
state.turnOrder.add(thanos);
|
||||
state.entities.addEntity(thanosNPC);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1065,8 +1062,6 @@ public class GameLogic {
|
||||
* @return The list of resulting {@link Event Events}
|
||||
*/
|
||||
private static ArrayList<Event> handleThanos(GameState state, NPC thanos) {
|
||||
System.out.println("Handling thanos");
|
||||
|
||||
ArrayList<Event> result = new ArrayList<>();
|
||||
|
||||
result.add(new EventBuilder(EventType.TurnEvent)
|
||||
@ -1132,7 +1127,7 @@ public class GameLogic {
|
||||
.withTargetEntity(thanos.id)
|
||||
.withTargetField(pos)
|
||||
.withAmount(1)
|
||||
.buildCharacterEvent());
|
||||
.buildEntityEvent());
|
||||
|
||||
if(pos.equals(picked)) {
|
||||
for(Entity entity: state.entities.findByPosition(pos)) {
|
||||
@ -1164,7 +1159,7 @@ public class GameLogic {
|
||||
}else {
|
||||
|
||||
for(EntityID id: state.turnOrder) {
|
||||
if(id.equals(thanos.id)) {
|
||||
if(id.type == EntityType.NPC) {
|
||||
continue;
|
||||
}
|
||||
if(rand.nextBoolean()) {
|
||||
@ -1186,8 +1181,6 @@ public class GameLogic {
|
||||
* @return The list of resulting {@link Event Events}
|
||||
*/
|
||||
private static ArrayList<Event> handleTurnStart(GameState state) {
|
||||
System.out.println("Turn of " + state.activeCharacter + " started");
|
||||
|
||||
ArrayList<Event> result = new ArrayList<>();
|
||||
|
||||
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}
|
||||
*/
|
||||
private static ArrayList<Event> handlePlayerWin(GameState state, EntityType winner) {
|
||||
System.out.println("Player " + winner + " won");
|
||||
|
||||
ArrayList<Event> result = new ArrayList<>();
|
||||
|
||||
result.add(new EventBuilder(EventType.WinEvent)
|
||||
|
@ -4,6 +4,7 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||
import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
|
||||
import uulm.teamname.marvelous.gamelibrary.config.PartyConfig;
|
||||
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.EntityID;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.StoneType;
|
||||
@ -143,7 +144,11 @@ class GameState {
|
||||
}
|
||||
}
|
||||
case P1, P2 -> {
|
||||
sb.append("X ");
|
||||
if(((Character)entities.get(0)).isAlive()) {
|
||||
sb.append("X ");
|
||||
}else {
|
||||
sb.append("x ");
|
||||
}
|
||||
}
|
||||
case Rocks -> {
|
||||
sb.append("O ");
|
||||
|
Loading…
Reference in New Issue
Block a user