use of de.gurkenlabs.litiengine.entities.Trigger in project litiengine by gurkenlabs.
the class TriggerTests method testInteractTrigger.
@Test
public void testInteractTrigger() {
Trigger trigger = new Trigger(TriggerActivation.INTERACT, "testrigger", "testmessage");
IEntity entity = mock(IEntity.class);
when(entity.getMapId()).thenReturn(123);
IEntity target = mock(IEntity.class);
when(target.getMapId()).thenReturn(456);
when(target.sendMessage(any(Object.class), any(String.class))).thenReturn("answer");
trigger.addTarget(456);
IEnvironment env = mock(IEnvironment.class);
Game.loadEnvironment(env);
Game.init(Game.COMMADLINE_ARG_NOGUI);
when(env.get(456)).thenReturn(target);
assertFalse(trigger.isActivated());
trigger.sendMessage(entity, Trigger.INTERACT_MESSAGE);
assertTrue(trigger.isActivated());
verify(target, times(1)).sendMessage(trigger, trigger.getMessage());
}
use of de.gurkenlabs.litiengine.entities.Trigger in project litiengine by gurkenlabs.
the class Environment method remove.
@Override
public void remove(final IEntity entity) {
if (entity == null) {
return;
}
if (this.entities.get(entity.getRenderType()) != null) {
this.entities.get(entity.getRenderType()).entrySet().removeIf(e -> e.getValue().getMapId() == entity.getMapId());
}
for (String tag : entity.getTags()) {
if (this.entitiesByTag.containsKey(tag)) {
this.entitiesByTag.get(tag).remove(entity);
if (this.entitiesByTag.get(tag).isEmpty()) {
this.entitiesByTag.remove(tag);
}
}
}
if (entity instanceof Emitter) {
Emitter emitter = (Emitter) entity;
this.groundRenderable.remove(emitter.getGroundRenderable());
this.overlayRenderable.remove(emitter.getOverlayRenderable());
this.emitters.remove(emitter);
}
if (entity instanceof MapArea) {
this.mapAreas.remove(entity);
}
if (entity instanceof Prop) {
this.props.remove(entity);
}
if (entity instanceof Creature) {
this.creatures.remove(entity);
}
if (entity instanceof CollisionBox) {
this.colliders.remove(entity);
this.staticShadows.removeIf(x -> x.getOrigin() != null && x.getOrigin().equals(entity));
}
if (entity instanceof LightSource) {
this.lightSources.remove(entity);
this.updateColorLayers(entity);
}
if (entity instanceof Trigger) {
this.triggers.remove(entity);
}
if (entity instanceof Spawnpoint) {
this.spawnPoints.remove(entity);
}
if (entity instanceof StaticShadow) {
this.staticShadows.remove(entity);
this.updateColorLayers(entity);
}
if (entity instanceof IMobileEntity) {
this.mobileEntities.values().remove(entity);
}
if (entity instanceof ICombatEntity) {
this.combatEntities.values().remove(entity);
}
this.unload(entity);
for (Consumer<IEntity> cons : this.entityRemovedConsumers) {
cons.accept(entity);
}
}
Aggregations