feat: add stone cooldown handling

This commit is contained in:
punchready 2021-05-27 17:26:46 +02:00
parent 0f50efa121
commit 3522cee9a4
2 changed files with 10 additions and 0 deletions

View File

@ -101,6 +101,7 @@ public class GameInstance {
* @param events The events to emit * @param events The events to emit
*/ */
private void emit(Event... events) { private void emit(Event... events) {
manager.applyEvents(events);
emitter.update(events); emitter.update(events);
} }
} }

View File

@ -288,6 +288,10 @@ class GameLogic {
requireAP(origin, 1); requireAP(origin, 1);
requireInfinityStone(origin, data.stoneType); requireInfinityStone(origin, data.stoneType);
if(state.stoneCooldown.onCooldown(data.stoneType)) {
throw new InvalidRequestException();
}
switch(((CharacterRequest) request).stoneType) { switch(((CharacterRequest) request).stoneType) {
case SpaceStone -> { case SpaceStone -> {
verifyCoordinates(state, data.targetField); verifyCoordinates(state, data.targetField);
@ -507,6 +511,9 @@ class GameLogic {
case MoveEvent -> { case MoveEvent -> {
(state.entities.findEntity(((CharacterEvent)event).originEntity)).setPosition(((CharacterEvent)event).targetField); (state.entities.findEntity(((CharacterEvent)event).originEntity)).setPosition(((CharacterEvent)event).targetField);
} }
case UseInfinityStoneEvent -> {
state.stoneCooldown.setCooldown(((CharacterEvent)event).stoneType, 10); //TODO: use stone cooldown from config
}
case ExchangeInfinityStoneEvent -> { case ExchangeInfinityStoneEvent -> {
((Character)state.entities.findEntity(((CharacterEvent)event).originEntity)).inventory.removeStone(((CharacterEvent)event).stoneType); ((Character)state.entities.findEntity(((CharacterEvent)event).originEntity)).inventory.removeStone(((CharacterEvent)event).stoneType);
((Character)state.entities.findEntity(((CharacterEvent)event).targetEntity)).inventory.addStone(((CharacterEvent)event).stoneType); ((Character)state.entities.findEntity(((CharacterEvent)event).targetEntity)).inventory.addStone(((CharacterEvent)event).stoneType);
@ -598,6 +605,8 @@ class GameLogic {
} }
} }
state.stoneCooldown.update();
result.add(new EventBuilder(EventType.RoundSetupEvent) result.add(new EventBuilder(EventType.RoundSetupEvent)
.withRoundCount(state.roundNumber) .withRoundCount(state.roundNumber)
.withCharacterOrder(state.turnOrder.toArray(new EntityID[0])) .withCharacterOrder(state.turnOrder.toArray(new EntityID[0]))