Search in sources :

Example 1 with MicroObj

use of main.entity.obj.MicroObj 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;
}
Also used : MicroObj(main.entity.obj.MicroObj) Coordinates(main.game.bf.Coordinates) ArrayList(java.util.ArrayList) Unit(eidolons.entity.obj.unit.Unit)

Example 2 with MicroObj

use of main.entity.obj.MicroObj in project Eidolons by IDemiurge.

the class SpellMaster method initSpellpool.

private List<DC_SpellObj> initSpellpool(MicroObj obj, PROPERTY PROP) {
    List<DC_SpellObj> spells = new ArrayList<>();
    String spellList = obj.getProperty(PROP);
    List<String> spellpool;
    spellpool = StringMaster.openContainer(spellList);
    for (String typeName : spellpool) {
        Ref ref = Ref.getCopy(obj.getRef());
        ObjType type = DataManager.getType(typeName, DC_TYPE.SPELLS);
        if (type == null) {
            continue;
        }
        Map<ObjType, MicroObj> cache = spellCache.get(obj);
        if (cache == null) {
            cache = new HashMap<>();
            spellCache.put(obj, cache);
        }
        MicroObj spell = cache.get(type);
        if (spell == null) {
            spell = getGame().createSpell(type, obj, ref);
            cache.put(type, spell);
        }
        SPELL_POOL spellPool = new EnumMaster<SPELL_POOL>().retrieveEnumConst(SPELL_POOL.class, PROP.getName());
        if (spellPool != null) {
            spell.setProperty(G_PROPS.SPELL_POOL, spellPool.toString());
        } else {
            LogMaster.log(1, PROP.getName() + " spell pool not found for " + typeName);
        }
        spells.add((DC_SpellObj) spell);
    }
    return spells;
}
Also used : MicroObj(main.entity.obj.MicroObj) Ref(main.entity.Ref) ObjType(main.entity.type.ObjType) ArrayList(java.util.ArrayList) DC_SpellObj(eidolons.entity.active.DC_SpellObj) SPELL_POOL(main.content.enums.entity.SpellEnums.SPELL_POOL)

Example 3 with MicroObj

use of main.entity.obj.MicroObj in project Eidolons by IDemiurge.

the class DC_ObjInitializer method processUnitDataStringToMap.

public static Map<Coordinates, MicroObj> processUnitDataStringToMap(Player owner, String objData, DC_Game game, boolean alt) {
    if (objData == null || objData.equals("")) {
        return null;
    }
    String[] items = objData.split(getObjSeparator(alt));
    Map<Coordinates, MicroObj> map = new HashMap<>();
    int i = 0;
    boolean first = true;
    boolean creeps = false;
    List<Coordinates> excludedCoordinates = new ArrayList<>();
    Boolean last = null;
    for (int indx = 0; indx < items.length; indx++) {
        String item = items[indx];
        boolean excludeCoordinate = false;
        if (mapBlockMode) {
            if (item.contains("%")) {
                Integer chance = StringMaster.getInteger(VariableManager.getVarPart(item).replace("%", " "));
                if (chance < 0) {
                    chance = -chance;
                    excludeCoordinate = true;
                }
                if (RandomWizard.chance(chance)) {
                    continue;
                }
            }
        }
        Coordinates c = null;
        if (item.contains("(") || item.contains("-")) {
            if (!item.contains("null=")) {
                c = getCoordinatesFromObjString(item, alt);
            }
        }
        String typeName = getNameFromObjString(item, alt);
        i++;
        if (i == items.length) {
            last = true;
        }
        int level = 0;
        if (typeName.contains(UnitGroupMaster.TYPE_LEVEL_SEPARATOR)) {
            level = StringMaster.getInteger(StringMaster.getLastPart(typeName, UnitGroupMaster.TYPE_LEVEL_SEPARATOR));
        }
        ObjType type = DataManager.getType(typeName, C_OBJ_TYPE.BF_OBJ);
        if (type == null) {
            type = DataManager.getType(typeName, C_OBJ_TYPE.ITEMS);
            if (type != null)
                createItem(type, c);
            continue;
        }
        if (type.getOBJ_TYPE_ENUM() == DC_TYPE.BF_OBJ)
            owner = DC_Player.NEUTRAL;
        else if (level == 0) {
            if (!owner.isMe())
                if (owner.isAi()) {
                    level = game.getDungeonMaster().getSpawner().getMinLevel(typeName);
                }
        }
        if (type == null) {
            type = DataManager.getType(typeName, DC_TYPE.ENCOUNTERS);
        }
        if (type == null) {
            main.system.auxiliary.log.LogMaster.log(1, "ERROR: Type not found - " + typeName);
            continue;
        }
        if (level != 0) {
            type = new UnitLevelManager().getLeveledType(type, level);
        }
        // UnitGroupMaster.getCurrentGroupHeight();
        int height = UnitGroupMaster.getGroupSizeY(owner);
        int width = UnitGroupMaster.getGroupSizeX(owner);
        if (UnitGroupMaster.getFlip() == FLIP.CW90) {
            int buffer = c.x;
            c.setX(c.y);
            c.setY(buffer);
        } else if (UnitGroupMaster.getFlip() == FLIP.CCW90) {
            int buffer = width - c.x;
            c.setX(height - c.y);
            c.setY(buffer);
        }
        if (UnitGroupMaster.isMirror()) {
            if (UnitGroupMaster.getFlip() == FLIP.CW90 || UnitGroupMaster.getFlip() == FLIP.CCW90) {
                c.setX(width - c.x);
            } else {
                c.setY(height - c.y);
            }
        // TODO c.setX(width - c.x);
        }
        if (offset != null) {
            c.setX(c.x + offset.x);
            c.setY(c.y + offset.y);
            if (!DC_Game.game.getRules().getStackingRule().canBeMovedOnto(type, c)) {
                // TODO tactics?
                // direction
                c = Positioner.adjustCoordinate(type, c, FacingMaster.getRandomFacing());
            // preference?
            }
        }
        if (mapBlockMode) {
            if (excludedCoordinates.contains(c)) {
                continue;
            }
            if (type.getOBJ_TYPE_ENUM() == DC_TYPE.ENCOUNTERS) {
                if (!game.isSimulation()) {
                    game.getBattleMaster().getSpawner().addDungeonEncounter(c_dungeon, block, c, type);
                }
                continue;
            }
            if (!CoreEngine.isLevelEditor() && C_OBJ_TYPE.UNITS_CHARS.equals(type.getOBJ_TYPE_ENUM())) {
                owner = game.getPlayer(false);
            } else {
                owner = DC_Player.NEUTRAL;
            }
            if (C_OBJ_TYPE.ITEMS.equals(type.getOBJ_TYPE_ENUM())) {
            // TODO 'treasure'?
            }
        }
        if (excludeCoordinate) {
            excludedCoordinates.add(c);
        }
        if (type == null) {
            continue;
        }
        if (data != null) {
        // data.addType(type, owner.isMe());
        }
        if (game.isDebugMode()) {
            if (owner.isMe()) {
                try {
                    TestMasterContent.addTestItems(type, last);
                } catch (Exception e) {
                    main.system.ExceptionMaster.printStackTrace(e);
                }
            }
        }
        last = false;
        // todo optimize create unit func it too slow
        BattleFieldObject unit = (BattleFieldObject) game.createUnit(type, c, owner);
        if (unit == null) {
            continue;
        }
        if (FAST_DC.isRunning()) {
            if (!owner.isMe()) {
                creeps = true;
            } else {
                try {
                    Unit hero = (Unit) unit;
                    if (first) {
                        PartyHelper.newParty(hero);
                    } else {
                        PartyHelper.addMember(hero);
                    }
                } catch (Exception e) {
                    main.system.ExceptionMaster.printStackTrace(e);
                }
            }
        }
        first = false;
        if (map.containsKey(c)) {
            ZCoordinates coordinates = new ZCoordinates(c.x, c.y, new Random().nextInt());
            map.put(coordinates, unit);
        } else {
            map.put(c, unit);
        }
        if (!CoreEngine.isLevelEditor()) {
            if (unit.getOBJ_TYPE_ENUM() == DC_TYPE.UNITS) {
                // if (!owner.isMe() || game.isDebugMode()) TODO why
                // not?
                // todo optimize train func it too slow
                UnitTrainingMaster.train((Unit) unit);
            }
        }
    }
    // PartyManager.addCreepParty(DataManager.convertToTypeList(list));
    return map;
}
Also used : MicroObj(main.entity.obj.MicroObj) ZCoordinates(main.game.bf.ZCoordinates) Coordinates(main.game.bf.Coordinates) Unit(eidolons.entity.obj.unit.Unit) ZCoordinates(main.game.bf.ZCoordinates) UnitLevelManager(eidolons.client.cc.logic.UnitLevelManager) ObjType(main.entity.type.ObjType) BattleFieldObject(eidolons.entity.obj.BattleFieldObject)

Aggregations

MicroObj (main.entity.obj.MicroObj)3 Unit (eidolons.entity.obj.unit.Unit)2 ArrayList (java.util.ArrayList)2 ObjType (main.entity.type.ObjType)2 Coordinates (main.game.bf.Coordinates)2 UnitLevelManager (eidolons.client.cc.logic.UnitLevelManager)1 DC_SpellObj (eidolons.entity.active.DC_SpellObj)1 BattleFieldObject (eidolons.entity.obj.BattleFieldObject)1 SPELL_POOL (main.content.enums.entity.SpellEnums.SPELL_POOL)1 Ref (main.entity.Ref)1 ZCoordinates (main.game.bf.ZCoordinates)1