feat: add thanos into the handling
This commit is contained in:
@ -141,7 +141,7 @@ class GameLogic {
|
||||
}
|
||||
case TimeStone -> {
|
||||
Character origin = (Character)state.entities.findEntity(data.originEntity);
|
||||
int ap = origin.ap.max - origin.ap.getValue();
|
||||
int ap = origin.ap.getMax() - origin.ap.getValue();
|
||||
if(ap < 0) {
|
||||
result.add(new EventBuilder(EventType.ConsumedAPEvent)
|
||||
.withTargetEntity(data.originEntity)
|
||||
@ -149,7 +149,7 @@ class GameLogic {
|
||||
.withAmount(ap)
|
||||
.buildEntityEvent());
|
||||
}
|
||||
int mp = origin.mp.max - origin.mp.getValue();
|
||||
int mp = origin.mp.getMax() - origin.mp.getValue();
|
||||
if(mp < 0) {
|
||||
result.add(new EventBuilder(EventType.ConsumedMPEvent)
|
||||
.withTargetEntity(data.originEntity)
|
||||
@ -163,7 +163,7 @@ class GameLogic {
|
||||
result.add(new EventBuilder(EventType.HealedEvent)
|
||||
.withTargetEntity(data.targetEntity)
|
||||
.withTargetField(data.targetField)
|
||||
.withAmount(target.hp.max)
|
||||
.withAmount(target.hp.getMax())
|
||||
.buildEntityEvent());
|
||||
}
|
||||
}
|
||||
@ -364,7 +364,7 @@ class GameLogic {
|
||||
*/
|
||||
private static Character getCharacter(GameState state, IntVector2 position, EntityID entityID) throws InvalidRequestException {
|
||||
Entity entity = state.entities.findEntity(entityID);
|
||||
if(entity == null || entity.getPosition() != position || !(entity instanceof Character)) {
|
||||
if(entity == null || entity.getPosition() != position || !(entity instanceof Character) || entity.id.type == EntityType.NPC) {
|
||||
throw new InvalidRequestException();
|
||||
}
|
||||
try {
|
||||
@ -629,6 +629,10 @@ class GameLogic {
|
||||
ArrayList<EntityID> alive = new ArrayList<>();
|
||||
|
||||
for (EntityID id: state.turnOrder) {
|
||||
if(id.type == EntityType.NPC) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Character character = ((Character)state.entities.findEntity(id));
|
||||
|
||||
if(character.hp.getValue() > 0){
|
||||
@ -682,7 +686,9 @@ class GameLogic {
|
||||
result.addAll(handleStan(state, revived));
|
||||
}
|
||||
|
||||
//TODO: add handling for thanos
|
||||
if(state.roundNumber == state.partyConfig.maxRounds + 1) {
|
||||
result.addAll(spawnThanos(state));
|
||||
}
|
||||
|
||||
Collections.shuffle(state.turnOrder);
|
||||
|
||||
@ -783,11 +789,11 @@ class GameLogic {
|
||||
if(character.hp.getValue() == 0) {
|
||||
revived.add(character.id);
|
||||
}
|
||||
if(character.hp.getValue() != character.hp.max) {
|
||||
if(character.hp.getValue() != character.hp.getMax()) {
|
||||
result.add(new EventBuilder(EventType.HealedEvent)
|
||||
.withTargetEntity(character.id)
|
||||
.withTargetField(character.getPosition())
|
||||
.withAmount(character.hp.max - character.hp.getValue())
|
||||
.withAmount(character.hp.getMax() - character.hp.getValue())
|
||||
.buildEntityEvent());
|
||||
}
|
||||
}
|
||||
@ -801,6 +807,49 @@ class GameLogic {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns Thanos at the beginning of the first overtime round.
|
||||
* @param state The game state to work on
|
||||
* @return The list of resulting {@link Event}s
|
||||
*/
|
||||
public static ArrayList<Event> spawnThanos(GameState state) {
|
||||
ArrayList<Event> result = new ArrayList<>();
|
||||
|
||||
ArrayList<IntVector2> free = getFreeFields(state);
|
||||
IntVector2 position = free.get(rand.nextInt(free.size()));
|
||||
|
||||
int maxMP = -1;
|
||||
for(EntityID id: state.turnOrder) {
|
||||
Character character = (Character)state.entities.findEntity(id);
|
||||
|
||||
if(character.mp.getValue() > maxMP) {
|
||||
maxMP = character.mp.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
EntityID thanos = new EntityID(EntityType.NPC, 2);
|
||||
result.add(new EventBuilder(EventType.SpawnEntityEvent)
|
||||
.withEntity(new Character(thanos, position, "Thanos", 1, maxMP, 0, 0, 0, 0))
|
||||
.buildEntityEvent());
|
||||
|
||||
state.turnOrder.add(thanos);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles Thanos' AI.
|
||||
* @param state The game state to work on
|
||||
* @return The list of resulting {@link Event}s
|
||||
*/
|
||||
public static ArrayList<Event> handleThanos(GameState state, Character thanos) {
|
||||
ArrayList<Event> result = new ArrayList<>();
|
||||
|
||||
//TODO: implement thanos ai
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles everything that happens at the beginning of a turn.
|
||||
* @param state The game state to work on
|
||||
@ -812,19 +861,24 @@ class GameLogic {
|
||||
state.turnNumber++;
|
||||
|
||||
Character activeCharacter = (Character)state.entities.findEntity(state.activeCharacter);
|
||||
boolean isThanos = state.activeCharacter.type == EntityType.NPC && state.activeCharacter.id == 2;
|
||||
|
||||
if(activeCharacter.ap.getValue() != activeCharacter.ap.max) {
|
||||
if(isThanos && state.roundNumber > state.partyConfig.maxRounds + 1) {
|
||||
activeCharacter.mp.setMax(activeCharacter.mp.getMax() + 1);//TODO: use event for this...
|
||||
}
|
||||
|
||||
if(activeCharacter.ap.getValue() != activeCharacter.ap.getMax()) {
|
||||
result.add(new EventBuilder(EventType.ConsumedAPEvent)
|
||||
.withTargetEntity(state.activeCharacter)
|
||||
.withTargetField(activeCharacter.getPosition())
|
||||
.withAmount(activeCharacter.ap.getValue() - activeCharacter.ap.max)
|
||||
.withAmount(activeCharacter.ap.getValue() - activeCharacter.ap.getMax())
|
||||
.buildGameEvent());
|
||||
}
|
||||
if(activeCharacter.mp.getValue() != activeCharacter.mp.max) {
|
||||
if(activeCharacter.mp.getValue() != activeCharacter.mp.getMax()) {
|
||||
result.add(new EventBuilder(EventType.ConsumedMPEvent)
|
||||
.withTargetEntity(state.activeCharacter)
|
||||
.withTargetField(activeCharacter.getPosition())
|
||||
.withAmount(activeCharacter.mp.getValue() - activeCharacter.mp.max)
|
||||
.withAmount(activeCharacter.mp.getValue() - activeCharacter.mp.getMax())
|
||||
.buildGameEvent());
|
||||
}
|
||||
result.add(new EventBuilder(EventType.TurnEvent)
|
||||
@ -832,6 +886,10 @@ class GameLogic {
|
||||
.withNextCharacter(state.activeCharacter)
|
||||
.buildGameEvent());
|
||||
|
||||
if(isThanos) {
|
||||
result.addAll(handleThanos(state, activeCharacter));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user