78 lines
2.6 KiB
Java
78 lines
2.6 KiB
Java
package uulm.teamname.marvelous.gamelibrary.events;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
|
import uulm.teamname.marvelous.gamelibrary.entities.Entity;
|
|
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
|
|
|
|
import java.util.Objects;
|
|
|
|
/** Represents an entity event for: {@link EventType#DestroyedEntityEvent}, {@link EventType#TakenDamageEvent}, {@link EventType#ConsumedAPEvent}, {@link EventType#ConsumedMPEvent}, {@link EventType#SpawnEntityEvent}, {@link EventType#HealedEvent}. */
|
|
public class EntityEvent extends Event {
|
|
public EntityID targetEntity = null;
|
|
public IntVector2 targetField = null;
|
|
public Integer amount = null;
|
|
public Entity entity = null;
|
|
|
|
@Override
|
|
public boolean check() {
|
|
if(!super.check()) {
|
|
return false;
|
|
}
|
|
|
|
switch(type) {
|
|
// DestroyedEntityEvent takes an ID and a field, and destroys the entity if the field is correct
|
|
case DestroyedEntityEvent:
|
|
if (this.targetField == null || this.targetEntity == null) {
|
|
return false;
|
|
}
|
|
break;
|
|
|
|
// TakenDamage, ConsumedAP / MP and Healed all need a targetField, targetEntity and Amount.
|
|
case TakenDamageEvent:
|
|
case ConsumedAPEvent:
|
|
case ConsumedMPEvent:
|
|
case HealedEvent:
|
|
if (this.targetField == null ||
|
|
this.targetEntity == null ||
|
|
this.amount == null) {
|
|
return false;
|
|
}
|
|
break;
|
|
|
|
// SpawnEntity needs an entity, of course.
|
|
case SpawnEntityEvent:
|
|
if (this.entity == null) {
|
|
return false;
|
|
}
|
|
break;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (this == o) return true;
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
if (!super.equals(o)) return false;
|
|
EntityEvent that = (EntityEvent) o;
|
|
return Objects.equals(targetEntity, that.targetEntity) && Objects.equals(targetField, that.targetField) && Objects.equals(amount, that.amount);
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(super.hashCode(), targetEntity, targetField, amount);
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "EntityEvent{" +
|
|
"eventType=" + this.type +
|
|
", targetEntity=" + targetEntity +
|
|
", targetField=" + targetField +
|
|
", amount=" + amount +
|
|
", entity=" + entity +
|
|
'}';
|
|
}
|
|
}
|