fix: make characters drop their inventory on knockout

This commit is contained in:
punchready 2021-06-03 03:06:21 +02:00
parent 7cd99495ba
commit 00eb5e21f3
2 changed files with 28 additions and 0 deletions

View File

@ -104,6 +104,13 @@ public class Inventory implements Iterable<StoneType> {
content.clear();
}
/**
* Removes all stones from the Inventory.
*/
public void clear() {
content.clear();
}
/** Iterates over the inventory. */
@Override
public Iterator<StoneType> iterator() {

View File

@ -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<StoneType> stones = Arrays.asList(target.inventory.getStonesAsArray());
target.inventory.clear();
Collections.shuffle(stones); // required by documents
for(StoneType stone: stones) {
ArrayList<IntVector2> 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;