2015-05-10 21:26:12 +02:00
|
|
|
package com.saltosion.gladiator.listeners;
|
2015-05-10 20:07:37 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import com.badlogic.ashley.core.ComponentMapper;
|
|
|
|
import com.badlogic.ashley.core.Entity;
|
|
|
|
import com.saltosion.gladiator.components.CCombat;
|
2015-05-10 22:01:38 +02:00
|
|
|
import com.saltosion.gladiator.systems.CombatSystem;
|
2015-05-10 20:07:37 +02:00
|
|
|
import com.saltosion.gladiator.util.Direction;
|
|
|
|
|
|
|
|
public class SwingHitboxListener implements CollisionListener {
|
|
|
|
|
|
|
|
private ArrayList<Entity> hitEntities = new ArrayList<Entity>();
|
|
|
|
private ComponentMapper<CCombat> cm = ComponentMapper.getFor(CCombat.class);
|
|
|
|
private Entity source;
|
|
|
|
|
|
|
|
public SwingHitboxListener(Entity source) {
|
|
|
|
this.source = source;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void collision(Direction side, Entity host, Entity other) {
|
|
|
|
if (other.equals(source) || hitEntities.contains(other)) {
|
|
|
|
return; // These entities don't need to take damage
|
|
|
|
}
|
|
|
|
hitEntities.add(other);
|
|
|
|
|
|
|
|
CCombat otherCombat = cm.get(other);
|
|
|
|
if (otherCombat == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-10 22:01:38 +02:00
|
|
|
int damage = cm.get(source).getDamage();
|
|
|
|
CombatSystem.dealDamage(source, other, damage);
|
2015-05-10 20:07:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|