fix: make characters drop their inventory on knockout
This commit is contained in:
parent
7cd99495ba
commit
00eb5e21f3
@ -104,6 +104,13 @@ public class Inventory implements Iterable<StoneType> {
|
|||||||
content.clear();
|
content.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all stones from the Inventory.
|
||||||
|
*/
|
||||||
|
public void clear() {
|
||||||
|
content.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/** Iterates over the inventory. */
|
/** Iterates over the inventory. */
|
||||||
@Override
|
@Override
|
||||||
public Iterator<StoneType> iterator() {
|
public Iterator<StoneType> iterator() {
|
||||||
|
@ -13,7 +13,9 @@ import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.geom.Line2D;
|
import java.awt.geom.Line2D;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/** Contains game logic handling. */
|
/** Contains game logic handling. */
|
||||||
public class GameLogic {
|
public class GameLogic {
|
||||||
@ -322,6 +324,25 @@ public class GameLogic {
|
|||||||
.withTargetField(data.targetField)
|
.withTargetField(data.targetField)
|
||||||
.withAmount(data.value)
|
.withAmount(data.value)
|
||||||
.buildEntityEvent());
|
.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 -> {
|
case MoveRequest -> {
|
||||||
CharacterRequest data = (CharacterRequest)request;
|
CharacterRequest data = (CharacterRequest)request;
|
||||||
|
Loading…
Reference in New Issue
Block a user