use of eidolons.entity.obj.unit.Unit in project Eidolons by IDemiurge.
the class LE_ObjMaster method addObj.
public Unit addObj(ObjType type, boolean stack, Coordinates... coordinates) {
Unit obj = null;
for (Coordinates c : coordinates) {
List<Unit> list = LevelEditor.getSimulation().getObjectsOnCoordinate(c);
if (!StackingRule.checkCanPlace(c, type, list)) {
// replace cases? if 1 coordinate, prompt...
if (LevelEditor.getCurrentLevel().isInitialized()) {
SoundMaster.playStandardSound(STD_SOUNDS.DIS__BLOCKED);
// DialogMaster.inform(type +
// " cannot be placed onto wall - " + c);
}
continue;
}
obj = getObject(type, c);
List<Unit> objects = LevelEditor.getSimulation().getUnitMap().get(c);
if (objects == null) {
objects = new ArrayList<>();
LevelEditor.getSimulation().getUnitMap().put(c, objects);
}
objects.add(obj);
LevelEditor.getCurrentLevel().addObj(obj, c, stack);
if (obj.isOverlaying()) {
LE_ObjMaster.setDirection(obj, c);
}
try {
if (LE_MapViewComp.isMinimapMode()) {
LevelEditor.getMainPanel().getMiniGrid().refreshComp(null, c);
} else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
LevelEditor.getGrid().refresh();
}
});
}
// LevelEditor.getGrid().repaintComp(c);
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
}
// preCheck wall ?
return obj;
}
use of eidolons.entity.obj.unit.Unit in project Eidolons by IDemiurge.
the class LE_ObjMaster method getObject.
public static Unit getObject(ObjType type, Coordinates c) {
Unit obj = null;
if (type.checkProperty(G_PROPS.BF_OBJECT_GROUP, BfObjEnums.BF_OBJECT_GROUP.ENTRANCE.toString())) {
// obj = new Entrance(c.x, c.y, type, LevelEditor.getCurrentLevel().getDungeon(), null);
} else {
obj = getObjCache().get(type);
if (obj == null) {
obj = new Unit(type, c.x, c.y, DC_Player.NEUTRAL, LevelEditor.getSimulation(), new Ref());
}
}
getObjCache().put(type, obj);
return obj;
}
use of eidolons.entity.obj.unit.Unit in project Eidolons by IDemiurge.
the class LE_ObjMaster method replace.
public static void replace(ObjType type, ObjType type2, List<Coordinates> coordinates) {
cache();
for (Coordinates coordinate : coordinates) {
List<Unit> objects = LevelEditor.getSimulation().getUnitMap().get(coordinate);
// .getObjects();
if (objects != null) {
for (Unit obj : new ArrayList<>(objects)) {
if (obj.getType().equals(type)) {
objects.remove(obj);
objects.add(getObject(type2, coordinate));
}
}
}
}
LevelEditor.getMainPanel().getMapViewComp().getGrid().refresh();
}
use of eidolons.entity.obj.unit.Unit in project Eidolons by IDemiurge.
the class LocationSpawner method spawn.
@Override
public List<Unit> spawn(UnitData data, DC_Player player, SPAWN_MODE mode) {
if (data.getValue(PARTY_VALUE.MEMBERS) != null) {
String units = data.getValue(PARTY_VALUE.MEMBERS).replace(DataUnitFactory.getContainerSeparator(UnitData.FORMAT), "");
if (FileManager.isFile(units))
return spawnUnitGroup(player.isMe(), units);
}
if (player.isMe() && PresetMaster.getPreset() == null && getGame().getMetaMaster() != null) {
Party party = getGame().getMetaMaster().getPartyManager().getParty();
if (party == null) {
return new LinkedList<>();
}
List<String> list = ListMaster.toNameList(party.getMembers());
getPositioner().setMaxSpacePercentageTaken(50);
List<Coordinates> coords = getPositioner().getPlayerPartyCoordinates(list);
Iterator<Coordinates> iterator = coords.iterator();
for (Unit member : party.getMembers()) {
if (!iterator.hasNext()) {
main.system.auxiliary.log.LogMaster.log(1, "Spawn failed: Coordinates: " + coords + "; Units" + list);
break;
}
member.setCoordinates(iterator.next());
member.setConstructed(false);
getGame().getState().addObject(member);
member.setOriginalOwner(player);
member.setOwner(player);
member.setFacing(getFacingAdjuster().getPartyMemberFacing(member));
applyStartBonuses(member);
// what else should be done to *spawn*?
}
} else {
super.spawn(data, player, mode);
}
return null;
}
use of eidolons.entity.obj.unit.Unit in project Eidolons by IDemiurge.
the class Spawner method spawnUnitGroup.
protected List<Unit> spawnUnitGroup(boolean me, String filePath) {
String data = UnitGroupMaster.readGroupFile(filePath);
boolean mirror = me;
if (UnitGroupMaster.isFactionMode()) {
if (UnitGroupMaster.factionLeaderRequired) {
data += UnitGroupMaster.getHeroData(me);
}
mirror = !mirror;
}
UnitGroupMaster.setMirror(mirror);
int width = UnitGroupMaster.maxX;
int height = UnitGroupMaster.maxY;
Coordinates offset_coordinate;
Coordinates spawnCoordinates;
int offsetX = -width / 2;
int offsetY = -height / 2;
if (!UnitGroupMaster.isFactionMode()) {
UnitGroupMaster.setCurrentGroupHeight(MathMaster.getMaxY(data));
UnitGroupMaster.setCurrentGroupWidth(MathMaster.getMaxX(data));
width = 1 + UnitGroupMaster.getCurrentGroupWidth();
height = 2 * UnitGroupMaster.getCurrentGroupHeight();
offsetX = -width / 2;
offsetY = -height / 2;
} else {
if (UnitGroupMaster.isMirror()) {
offsetY -= 1;
}
}
spawnCoordinates = (me) ? getPositioner().getPlayerSpawnCoordinates() : getPositioner().getEnemySpawningCoordinates();
offset_coordinate = spawnCoordinates.getOffsetByX(offsetX).getOffsetByY(offsetY);
List<MicroObj> units = DC_ObjInitializer.createUnits(game.getPlayer(me), data, offset_coordinate);
LogMaster.logToFile("spawnCoordinates=" + spawnCoordinates + " ;offset_coordinate=" + offset_coordinate + ";height=" + height + "; width=" + width);
LogMaster.log(1, "spawnCoordinates=" + spawnCoordinates + " ;offset_coordinate=" + offset_coordinate + ";height=" + height + "; width=" + width);
List<Unit> list = new ArrayList<>();
units.stream().forEach(unit -> list.add((Unit) unit));
return list;
}
Aggregations