feat: add handling and checking for MindStone

This commit is contained in:
punchready 2021-05-18 13:21:36 +02:00
parent 4b69cca440
commit 729a1d4a71
2 changed files with 26 additions and 7 deletions

View File

@ -13,20 +13,19 @@ public enum StoneType {
SoulStone(5); SoulStone(5);
private final int id; private final int id;
private final static HashMap<Integer, StoneType> map; private final static HashMap<Integer, StoneType> map = new HashMap<>();
private StoneType(int id) { StoneType(int id) {
this.id = id; this.id = id;
} }
static { static {
map = new HashMap<>(); for (StoneType stoneType: StoneType.values()) {
for (StoneType stoneType : StoneType.values()) {
map.put(stoneType.id, stoneType); map.put(stoneType.id, stoneType);
} }
} }
public static StoneType valueOf (int stoneType) { public static StoneType valueOf(int stoneType) {
return map.get(stoneType); return map.get(stoneType);
} }

View File

@ -94,7 +94,24 @@ class GameLogic {
.buildCharacterEvent()); .buildCharacterEvent());
} }
case MindStone -> { case MindStone -> {
//TODO: mind stone effect ??????? EntityType target = data.originEntity.type == EntityType.P1 ? EntityType.P2 : EntityType.P1;
Line2D line = new Line2D.Float(data.originField.getX(), data.originField.getY(), data.targetField.getX(), data.targetField.getY());
for(int i = data.originField.getX(); i <= data.targetField.getX(); i++) {
for(int j = data.originField.getY(); j <= data.targetField.getY(); j++) {
var cell = new Rectangle.Float(i - 0.5f, j - 0.5f, 1, 1);
if(line.intersects(cell)) {
for(Entity entity: state.entities.findByPosition(data.targetField)) {
if(entity.id.isSameType(target)) {
result.add(new EventBuilder(EventType.TakenDamageEvent)
.withTargetEntity(entity.id)
.withTargetField(new IntVector2(i, j))
.withAmount(data.value)
.buildEntityEvent());
}
}
}
}
}
} }
case RealityStone -> { case RealityStone -> {
if(data.originEntity == data.targetEntity) { // => place stone if(data.originEntity == data.targetEntity) { // => place stone
@ -266,7 +283,10 @@ class GameLogic {
} }
} }
case MindStone -> { case MindStone -> {
//TODO: mind stone requirements (config, etc) ??????? if(data.originField == data.targetField) {
throw new InvalidRequestException();
}
//TODO: mind stone damage check (config) ???????
} }
case RealityStone -> { case RealityStone -> {
if(data.originEntity == data.targetEntity) { // => place stone if(data.originEntity == data.targetEntity) { // => place stone