From 00eb5e21f33e07c19133b3e650c41bae4374e39c Mon Sep 17 00:00:00 2001 From: punchready Date: Thu, 3 Jun 2021 03:06:21 +0200 Subject: [PATCH] fix: make characters drop their inventory on knockout --- .../gamelibrary/entities/Inventory.java | 7 +++++++ .../gamelibrary/gamelogic/GameLogic.java | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Inventory.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Inventory.java index 98f9d80..20947e5 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Inventory.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Inventory.java @@ -104,6 +104,13 @@ public class Inventory implements Iterable { content.clear(); } + /** + * Removes all stones from the Inventory. + */ + public void clear() { + content.clear(); + } + /** Iterates over the inventory. */ @Override public Iterator iterator() { diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java index 8bb7aed..586522c 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -13,7 +13,9 @@ import uulm.teamname.marvelous.gamelibrary.requests.RequestType; import java.awt.*; import java.awt.geom.Line2D; import java.awt.geom.Point2D; +import java.lang.reflect.Array; import java.util.*; +import java.util.List; /** Contains game logic handling. */ public class GameLogic { @@ -322,6 +324,25 @@ public class GameLogic { .withTargetField(data.targetField) .withAmount(data.value) .buildEntityEvent()); + + Character target = (Character)state.entities.findEntity(data.targetEntity); + if(target.hp.getValue() <= data.value) { + + List stones = Arrays.asList(target.inventory.getStonesAsArray()); + target.inventory.clear(); + Collections.shuffle(stones); // required by documents + + for(StoneType stone: stones) { + ArrayList options = getFreeNeighbour(state, target.getPosition()); + result.add(new EventBuilder(EventType.SpawnEntityEvent) + .withEntity(new InfinityStone( + new EntityID(EntityType.InfinityStones, stone.getID()), + options.get(rand.nextInt(options.size())), + stone + )) + .buildEntityEvent()); + } + } } case MoveRequest -> { CharacterRequest data = (CharacterRequest)request;