use of main.entity.obj.Obj in project Eidolons by IDemiurge.
the class ClearShotCondition method check.
@Override
public boolean check(Ref ref) {
Obj obj = game.getObjectById(ref.getId(str2));
if (!(obj instanceof DC_Obj)) {
return false;
}
DC_Obj target = (DC_Obj) game.getObjectById(ref.getId(str2));
if (target == null) {
return false;
}
Coordinates c2 = target.getCoordinates();
if (c2 == null)
return false;
BattleFieldObject source = (BattleFieldObject) game.getObjectById(ref.getId(str1));
if (source == null)
return false;
if (c2.equals(source.getCoordinates()))
return true;
if (target.isOverlaying()) {
if (target instanceof BattleFieldObject) {
DIRECTION d = ((BattleFieldObject) target).getDirection();
DIRECTION d1 = DirectionMaster.getRelativeDirection(target, source);
if (d != null) {
if (d1 != d) {
if (Math.abs(d.getDegrees() - d1.getDegrees()) > 90)
return false;
}
}
}
}
wallObstruction = false;
Coordinates c1 = source.getCoordinates();
boolean toCheck = true;
boolean result = true;
if (PositionMaster.inLine(c1, c2)) {
result = PositionMaster.noObstaclesInLine(source, target, game.getBattleField().getGrid());
toCheck = false;
if (!result)
return cacheResult(source, target, result);
} else {
// TODO TRANSPARENT FOR VISION!
if (PositionMaster.inLineDiagonally(c1, c2)) {
result = PositionMaster.noObstaclesInDiagonal(c1, c2, game.getBattleField().getGrid(), source);
if (!result)
return cacheResult(source, target, result);
List<Coordinates> list = new ArrayList<>();
if (!c2.isAdjacent(source.getCoordinates())) {
DIRECTION direction = DirectionMaster.getRelativeDirection(source, target);
list = (DC_PositionMaster.getLine(false, direction, source.getCoordinates(), // PositionMaster.getDistance(source,
Math.abs(source.getX() - target.getX())));
} else {
list.add(target.getCoordinates());
}
for (Coordinates c : list) {
if (checkWallObstruction(source, target, c))
return cacheResult(source, target, false);
}
return cacheResult(source, target, true);
}
}
if (!result)
return cacheResult(source, target, result);
if (!toCheck)
return cacheResult(source, target, result);
result = checkClearShot(source, target);
return cacheResult(source, target, result);
}
use of main.entity.obj.Obj in project Eidolons by IDemiurge.
the class DungeonBuilder method initDynamicObjData.
protected void initDynamicObjData(Location location, DungeonPlan plan) {
int z = location.getIntParam(G_PARAMS.Z_LEVEL);
for (MapBlock b : plan.getBlocks()) {
ArrayList<Obj> objects = new ArrayList<>(b.getObjects());
for (Obj obj : objects) {
// TODO of course - the issue was that I added an object to
// block too! ... init?
BattleFieldObject unit = (BattleFieldObject) obj;
if (z != 0) {
unit.setZ(z);
}
}
}
for (MapZone zone : plan.getZones()) {
ObjType wallType = DataManager.getType(zone.getFillerType(), DC_TYPE.BF_OBJ);
if (wallType == null)
continue;
List<Coordinates> list = zone.getCoordinates();
for (MapBlock b : zone.getBlocks()) {
list.removeAll(b.getCoordinates());
}
for (Coordinates c : list) {
getGame().getManager().getObjCreator().createUnit(wallType, c.x, c.y, Player.NEUTRAL, new Ref(game));
}
}
for (Obj obj : plan.getWallObjects()) {
BattleFieldObject unit = (BattleFieldObject) obj;
if (z != 0) {
unit.setZ(z);
}
}
if (plan.getDirectionMap() != null) {
try {
DC_ObjInitializer.initDirectionMap(z, plan.getDirectionMap());
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
}
if (plan.getFlipMap() != null) {
try {
DC_ObjInitializer.initFlipMap(z, plan.getFlipMap());
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
}
}
use of main.entity.obj.Obj in project Eidolons by IDemiurge.
the class MapBlock method getXml.
public String getXml() {
resetObjects();
xml = "";
xml += XML_Converter.openXmlFormatted(getShortName());
xml += XML_Converter.wrapLeaf(LocationBuilder.BLOCK_TYPE_NODE, type.getName());
if (roomType != null) {
xml += XML_Converter.wrapLeaf(LocationBuilder.ROOM_TYPE_NODE, roomType.toString());
}
xml += XML_Converter.openXmlFormatted(LocationBuilder.COORDINATES_NODE);
for (Coordinates c : coordinates) {
xml += c.toString() + ";";
}
xml += XML_Converter.closeXmlFormatted(LocationBuilder.COORDINATES_NODE);
xml += XML_Converter.openXmlFormatted(LocationBuilder.OBJ_NODE);
for (Coordinates c : map.keySet()) {
Obj obj = map.get(c);
String name = obj.getName();
Integer chance = obj.getIntParam(G_PARAMS.CHANCE);
if (chance > 0) {
name += StringMaster.wrapInParenthesis(chance + "%");
}
xml += c + "=" + name + ",";
}
// ++ random objects
xml += XML_Converter.closeXmlFormatted(LocationBuilder.OBJ_NODE);
xml += XML_Converter.closeXmlFormatted(getShortName());
// objects?
return xml;
}
use of main.entity.obj.Obj in project Eidolons by IDemiurge.
the class BfAnalyzer method getClosestCell.
public Obj getClosestCell(Obj targetUnit, boolean canMove) {
Obj cell = checkAdjacentCell(targetUnit, canMove);
if (cell != null) {
return cell;
}
for (int i = 2; i < getMaxDistance(); i++) {
cell = checkCells(targetUnit, movementManager.getCellsInRadius(targetUnit, i), canMove);
if (cell != null) {
break;
}
}
if (cell == null) {
LogMaster.log(LogMaster.AI_DEBUG, "failed to find a cell for : " + getAi().getUnit() + " to attack " + targetUnit);
// throw new RuntimeException();
}
LogMaster.log(LogMaster.AI_DEBUG, cell + " is the closest cell to " + targetUnit);
return cell;
}
use of main.entity.obj.Obj in project Eidolons by IDemiurge.
the class GameState method removeObject.
public void removeObject(Integer id) {
Obj obj = objMap.get(id);
LogMaster.log(LogMaster.CORE_DEBUG_1, "Obj removed: " + obj);
objMap.remove(id);
removed(obj);
}
Aggregations