use of eidolons.entity.obj.BattleFieldObject in project Eidolons by IDemiurge.
the class StackingRule method actionMissed.
public static void actionMissed(DC_ActiveObj action) {
if (RuleMaster.isRuleOn(RULE.MISSED_ATTACK_REDIRECTION))
return;
Ref ref = action.getRef();
Obj target = ref.getTargetObj();
List<BattleFieldObject> units = action.getGame().getObjectsAt(action.getOwnerObj().getCoordinates());
units.addAll(action.getGame().getObjectsAt(target.getCoordinates()));
units.remove(action.getOwnerObj());
units.remove(target);
if (units.isEmpty()) {
return;
}
Map<BattleFieldObject, Integer> map = new HashMap<>();
for (BattleFieldObject unit : units) {
map.put(unit, unit.getIntParam(PARAMS.GIRTH));
}
BattleFieldObject randomTarget = new RandomWizard<BattleFieldObject>().getObjectByWeight(map);
ref.setTarget(randomTarget.getId());
// action.addProperty(G_PROPS.DYNAMIC_BOOLS,
// DYNAMIC_BOOLS.MISSED_ALREADY); //NO RESTRAINTS! :)
action.activatedOn(ref);
}
use of eidolons.entity.obj.BattleFieldObject in project Eidolons by IDemiurge.
the class StackingRule method canBeMovedOnto.
private boolean canBeMovedOnto(Integer maxSpaceTakenPercentage, Entity unit, Coordinates c, Integer z, List<? extends Entity> otherUnits) {
HashMap<Coordinates, Boolean> bools = cache.get(unit);
boolean result = false;
if (maxSpaceTakenPercentage == 100) {
if (bools != null) {
if (bools.containsKey(c)) {
return bools.get(c);
}
} else {
bools = new HashMap<>();
cache.put(unit, bools);
}
}
// get all units on the cell
DequeImpl<? extends Entity> units = new DequeImpl<>(otherUnits);
for (BattleFieldObject u : game.getObjectsOnCoordinate(z, c, false, false, false)) {
if (!units.contains(u)) {
if (!u.isAnnihilated())
// continue; TODO why was Type necessary?
units.addCast(!u.isDead() ? u.getType() : u);
if (u.isWall())
if (!u.isDead())
return false;
}
}
// check if '1 unit per cell' is on
if (maxSpaceTakenPercentage <= 0) {
if (!units.isEmpty()) {
return false;
}
}
if (unit == null) {
unit = DataManager.getType(HeroCreator.BASE_HERO, DC_TYPE.CHARS);
}
Obj cell;
if (!game.isSimulation()) {
cell = game.getCellByCoordinate(c);
} else {
cell = new DC_Cell(c, game);
}
if (cell == null) {
return false;
}
if (z == null) {
if (unit instanceof Unit) {
Unit heroObj = (Unit) unit;
z = heroObj.getZ();
}
}
// TODO ???
if (game.isSimulation()) {
if (units.size() > 1) {
return false;
}
}
// no passable/overlaying!
int space = StringMaster.getInteger(PARAMS.SPACE.getDefaultValue());
if (c != null) {
if (!game.isSimulation()) {
space = cell.getIntParam(PARAMS.SPACE);
}
}
int girth = 0;
for (Entity u : units) {
if (u == unit) {
continue;
}
// }
if (UnitAnalyzer.isWall(u)) {
// if (!UnitAnalyzer.isFlying(unit)) {
return false;
// }
}
if (u.isDead())
girth += u.getIntParam(PARAMS.GIRTH) / 3;
else
girth += u.getIntParam(PARAMS.GIRTH);
// TODO if (DoorMaster.isDoor((BattleFieldObject) u)) {
//
// }
// main.system.auxiliary.LogMaster.log(1, "****************** " +
// u.getName()
// + "'s Girth " + u.getIntParam(PARAMS.GIRTH));
}
// [QUICK FIX]
if (unit.getIntParam(PARAMS.GIRTH) == 0) {
girth += StringMaster.getInteger(PARAMS.GIRTH.getDefaultValue());
} else {
girth += unit.getIntParam(PARAMS.GIRTH);
}
// main.system.auxiliary.LogMaster.log(1, "****************** " + space
// + " Space vs " + girth
// + " Girth on " + c + " for " + unit);
space = space * maxSpaceTakenPercentage / 100;
if (space >= girth) {
result = true;
} else {
if (unit.getIntParam(PARAMS.GIRTH) > space) {
if (units.isEmpty()) {
result = true;
}
}
}
if (// only cache for default cases!
maxSpaceTakenPercentage == 100) {
bools.put(c, result);
}
return result;
}
use of eidolons.entity.obj.BattleFieldObject in project Eidolons by IDemiurge.
the class FloatingTextMaster method createFloatingText.
public void createFloatingText(TEXT_CASES CASE, String arg, Entity entity) {
FloatingText text;
try {
text = getFloatingText(entity, CASE, arg);
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
return;
}
if (entity instanceof BattleFieldObject) {
Vector2 v = GridMaster.getCenteredPos(((BattleFieldObject) entity).getCoordinates());
text.setPosition(v);
} else {
if (entity instanceof DC_ActiveObj) {
Vector2 v = GridMaster.getCenteredPos(((DC_ActiveObj) entity).getOwnerObj().getCoordinates());
text.setPosition(v);
}
}
GuiEventManager.trigger(GuiEventType.ADD_FLOATING_TEXT, text);
}
use of eidolons.entity.obj.BattleFieldObject in project Eidolons by IDemiurge.
the class LightMap method updateMap.
// public void updateMap(Map<DC_HeroObj, BaseView> units) {
public void updateMap() {
new ConeLight(rayHandler, 3, GdxColorMaster.ENEMY_COLOR, 200, 350, 350, 200, 100);
LogMaster.log(LogMaster.VISIBILITY_DEBUG, "UpdateMap method was called");
valid = false;
if (bodyMap != null) {
bodyMap.clear();
}
if (fireLightProtMap != null) {
for (Map.Entry<Integer, FireLightProt> entry : fireLightProtMap.entrySet()) {
entry.getValue().dispose();
}
fireLightProtMap.clear();
}
Array<Body> bodies = new Array<>();
world.getBodies(bodies);
for (int i = 0; i < bodies.size; i++) {
world.destroyBody(bodies.get(i));
}
fireLightProtMap = new HashMap<>();
bodyMap = new HashMap<>();
this.units = DC_Game.game.getBfObjects();
for (int i = 0; i < units.size(); i++) {
BodyDef bdef = new BodyDef();
bdef.type = BodyDef.BodyType.KinematicBody;
Body body = world.createBody(bdef);
// ILLUMINATION
lightParam = PARAMS.LIGHT_EMISSION;
darkParam = PARAMS.CONCEALMENT;
BattleFieldObject unit = units.get(i);
int lightStrength = unit.getIntParam(lightParam) - unit.getIntParam(darkParam);
if (lightStrength > 0) {
// emitters.add(unit);
body.setTransform(units.get(i).getX() * cellWidth + cellWidth / 2, this.rows * cellHeight - units.get(i).getY() * cellHeight + cellHeight / 2, 0);
PolygonShape shape = new PolygonShape();
shape.setAsBox(cellWidth / 2, cellHeight / 2);
FixtureDef fdef = new FixtureDef();
fdef.shape = shape;
body.createFixture(fdef);
FireLightProt fireLightProt = new FireLightProt(world, rayHandler, unit.getX() * cellWidth + cellWidth / 2, unit.getY() * cellHeight + cellHeight / 2, lightStrength * LIGHT_MULTIPLIER, 360, SECOND);
fireLightProt.attachToBody(body);
fireLightProtMap.put(i, fireLightProt);
valid = true;
} else {
body.setTransform(units.get(i).getX() * cellWidth + cellWidth / 2, this.rows * cellHeight - units.get(i).getY() * cellHeight + cellHeight / 2, 0);
PolygonShape shape = new PolygonShape();
shape.setAsBox(cellWidth / 2, cellHeight / 2);
FixtureDef fdef = new FixtureDef();
fdef.shape = shape;
body.createFixture(fdef);
}
bodyMap.put(units.get(i), body);
}
}
use of eidolons.entity.obj.BattleFieldObject in project Eidolons by IDemiurge.
the class HitAnim method resetSprites.
@Override
protected void resetSprites() {
sprites.clear();
spriteType = getSpriteType((BattleFieldObject) getRef().getTargetObj());
hitType = getHitType(getActive(), spriteType);
String spritePath = StrPathBuilder.build(getHitSpritesPath(), spriteType.name(), hitType.spritePath) + ".txt";
// + ".png";
// SpriteAnimation sprite = SpriteAnimationFactory.getSpriteAnimation(spritePath);
// scale?
SmartTextureAtlas atlas = SmartTextureAtlas.getAtlas(PathFinder.getImagePath() + spritePath);
if (atlas == null)
return;
Array<AtlasRegion> regions = atlas.getRegions();
SpriteAnimation sprite = SpriteAnimationFactory.getSpriteAnimation(regions, getDuration() / regions.size, 1);
if (getRef().getTargetObj() instanceof Unit)
sprite.setColor(getColorForSprite((Unit) getRef().getTargetObj()));
sprites.add(sprite);
}
Aggregations