@Override public boolean fire(EntityEngine entityEngine, int sender, int receiver, Object data) { // TODO: Maybe change how data is passed to events if ((data == null) || !(data instanceof Intersection)) { Gdx.app.log("Event", "Player collision event expected an intersection instance"); return false; } Intersection intersection = (Intersection) data; EntityManager entityManager = entityEngine.getEntityManager(); // Don't be harmed by own bullet if (entityManager.entityHasComponent(sender, BulletComponent.class)) { BulletComponent bulletComponent = entityManager.getComponent(sender, BulletComponent.class); if (bulletComponent.shooterId == receiver) { return false; } } CollisionEvents.handlePickup(entityEngine, sender, receiver); CollisionEvents.handleKnockback(entityManager, sender, receiver, intersection); CollisionEvents.handleDamage(entityEngine, sender, receiver); return false; }
/* * (non-Javadoc) * * @see com.tealduck.game.pickup.Pickup#applyToEntity(com.tealduck.game.engine.EntityManager, int) * * Only applicable if the entity has a weapon component. */ @Override public boolean applyToEntity(EntityManager entityManager, int entity) { if (entityManager.entityHasComponent(entity, WeaponComponent.class)) { WeaponComponent weaponComponent = entityManager.getComponent(entity, WeaponComponent.class); weaponComponent.addAmmo(ammo); return true; } return false; }