use of main.system.auxiliary.RandomWizard in project Eidolons by IDemiurge.
the class HeroObjectModifyingEffect method applyThis.
/**
* Modstring format: valueName(value);valueName2(value2);... Use [mod],
* [set], [remove] to change the default ADD function of modstring
*/
public boolean applyThis() {
if (ref.getTargetObj().isDead() || ref.getSourceObj().isDead()) {
removeEffects();
return false;
}
if (game.isSimulation()) {
if (!checkApplyInSimulation()) {
return true;
}
}
// what if the group has changed? perhaps there should be a map...
if (prop) {
if (propMap == null) {
propMap = new RandomWizard<PROPERTY>().constructStringWeightMap(modString, PROPERTY.class);
} else {
LogMaster.log(1, "prop map " + propMap.toString());
}
} else if (// TODO support PROPERTY?
map == null) {
map = new RandomWizard<PARAMETER>().constructStringWeightMap(modString, PARAMETER.class);
} else {
LogMaster.log(0, "map " + map.toString());
}
List<? extends Obj> list = getObjectsToModify();
LogMaster.log(0, "list " + list.toString());
LogMaster.log(0, "effects " + effects.toString());
for (Obj obj : list) {
if (obj == null) {
continue;
}
if (obj.isDead()) {
// TODO clean up for owner is dead!
continue;
}
Effect effect = effects.get(obj);
if (effect != null) {
// if (isPermanent() && isApplied())
// continue;
effect.applyThis();
applied = true;
continue;
}
Ref REF = ref.getCopy();
REF.setTarget(obj.getId());
// map = new MapMaster<PARAMETER, String>().constructVarMap(
// modString, PARAMETER.class);
Effects modEffects = new Effects();
if (map != null) {
EffectFinder.initParamModEffects(modEffects, map, ref);
} else if (propMap != null) {
EffectFinder.initPropModEffects(modEffects, propMap, ref);
}
applied = true;
for (Effect e : modEffects.getEffects()) {
e.resetOriginalFormula();
e.appendFormulaByMod(getFormula().toString());
}
if (buff) {
AddBuffEffect buffEffect = new AddBuffEffect(buffName, modEffects);
// TODO LAYER?
buffEffect.setForcedLayer(getModEffectLayer());
modEffects.setForcedLayer(getModEffectLayer());
if (isPermanent()) {
buffEffect.setDuration(ContentManager.INFINITE_VALUE);
}
if (!game.isSimulation()) {
effects.put(obj, buffEffect);
}
buffEffect.apply(REF);
} else {
if (!game.isSimulation()) {
effects.put(obj, modEffects);
}
modEffects.apply(REF);
}
}
return true;
}
use of main.system.auxiliary.RandomWizard in project Eidolons by IDemiurge.
the class UnitShop method buy.
private static boolean buy(String repertoire, Unit unit, ITEM_SLOT slot, OBJ_TYPE OBJ_TYPE_ENUM) {
// Map<ObjType, Integer>
List<ObjType> itemPool = new ArrayList<>();
// ++ add weight! choose from repertoire!
WeightMap<ObjType> map = new WeightMap<>(new RandomWizard<ObjType>().constructWeightMap(repertoire, ObjType.class, OBJ_TYPE_ENUM));
Loop.startLoop(map.size());
while (!Loop.loopEnded() && !map.isEmpty()) {
ObjType baseType = getItem(map);
map.remove(baseType);
if (baseType == null) {
// *empty*
return false;
}
for (ObjType type : DataManager.getTypes(OBJ_TYPE_ENUM)) {
if (!checkItemType(type, baseType)) {
continue;
}
if (!checkCanEquip(baseType, unit, slot)) {
continue;
}
if (!specialCheck(unit, type)) {
continue;
}
// TODO for potions/jewelry?
if (// for potions/ammo?
!checkQualityRange(type, unit)) {
continue;
}
itemPool.add(type);
}
try {
itemPool = (List<ObjType>) SortMaster.sortByValue(itemPool, PARAMS.GOLD_COST, true);
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
DC_HeroItemObj item = null;
for (ObjType type : itemPool) {
// sort by cost? then go from top to bottom trying to buy...
if (!checkCost(type, unit)) {
continue;
}
item = buy(type, unit);
break;
}
if (item == null) {
continue;
}
equip(unit, item, slot);
return true;
}
return false;
// ++ sell TODO
}
use of main.system.auxiliary.RandomWizard in project Eidolons by IDemiurge.
the class LocationBuilder method getRandomCoordinate.
private Coordinates getRandomCoordinate(ROOM_TYPE roomType) {
// TODO totally random? a fair start...
boolean corner = false;
boolean center = false;
ROOM_TYPE[] adjacentRoomRequired = null;
switch(roomType) {
case DEATH_ROOM:
case GUARD_ROOM:
adjacentRoomRequired = new ROOM_TYPE[] { ROOM_TYPE.TREASURE_ROOM, ROOM_TYPE.THRONE_ROOM, ROOM_TYPE.EXIT_ROOM };
break;
case SECRET_ROOM:
case TREASURE_ROOM:
corner = true;
break;
}
Coordinates c = null;
if (adjacentRoomRequired != null) {
Loop.startLoop(500);
while (!Loop.loopEnded()) {
MapBlock block = new RandomWizard<MapBlock>().getRandomListItem(plan.getBlocks());
if (Arrays.asList(adjacentRoomRequired).contains(block.getRoomType())) {
List<Coordinates> list = CoordinatesMaster.getAdjacentToSquare(block.getCoordinates());
c = new RandomWizard<Coordinates>().getRandomListItem(list);
if (c.isInvalid()) {
continue;
}
if (helper.getUsedCoordinates().contains(c)) {
continue;
}
return c;
}
}
return null;
}
Loop.startLoop(100);
while (!Loop.loopEnded()) {
c = CoordinatesMaster.getRandomCoordinate(getDungeon().getCellsX(), getDungeon().getCellsY());
if (helper.getUsedCoordinates().contains(c)) {
continue;
}
// add the outer walls to usedCoordinates?
if (corner) {
if (Math.min(plan.getBorderX() - c.x, c.x) + Math.min(plan.getBorderY() - c.y, c.y) > 6) {
continue;
}
}
break;
}
return c;
}
use of main.system.auxiliary.RandomWizard in project Eidolons by IDemiurge.
the class LocationSpawner method getCreepGroupForBlock.
private Wave getCreepGroupForBlock(int preferredPower, Dungeon dungeon, MapBlock block, int min, int max) {
// alt? vielleicht fur einige spezielle orte...
String property = dungeon.getProperty(PROPS.ENCOUNTERS);
int mod = block.getSpawningPriority();
if (mod == 0) {
mod = 100;
}
Wave wave;
List<ObjType> list = DataManager.toTypeList(property, DC_TYPE.ENCOUNTERS);
Collections.shuffle(list);
ObjType type = null;
for (ObjType t : list) {
type = t;
if (EncounterMaster.getPower(type, false) < min * mod / 100) {
continue;
}
if (EncounterMaster.getPower(type, false) > max * mod / 100) {
continue;
}
break;
}
if (type == null) {
type = new RandomWizard<ObjType>().getObjectByWeight(property, ObjType.class);
}
wave = new Wave(type, game, new Ref(game), game.getPlayer(false));
wave.setPreferredPower(preferredPower * mod / 100);
wave.setBlock(block);
return wave;
}
use of main.system.auxiliary.RandomWizard in project Eidolons by IDemiurge.
the class ContainerMaster method getItem.
public ObjType getItem(CONTAINER_CONTENTS c, int maxCost) {
int random = RandomWizard.getRandomInt(100);
ITEM_RARITY rarity = ITEM_RARITY.COMMON;
for (ITEM_RARITY sub : ITEM_RARITY.values()) {
if (sub.getChance() >= random) {
rarity = sub;
break;
}
}
main.system.auxiliary.log.LogMaster.log(1, "getItem " + c + "; " + rarity + maxCost);
ObjType type = preselectBaseType(c, rarity);
main.system.auxiliary.log.LogMaster.log(1, "preselectBaseType " + type);
if (type == null)
return null;
// base types!
List<ObjType> pool = new ArrayList<>(getItemPool(c, rarity, type));
main.system.auxiliary.log.LogMaster.log(1, "pool= " + pool);
if (pool.isEmpty())
return null;
if (isRemoveBase(c, type))
pool.removeIf(item -> !item.isGenerated());
else {
pool.size();
}
if (pool.isEmpty())
return null;
pool.removeIf(item -> item.getIntParam(PARAMS.GOLD_COST) > maxCost);
if (pool.isEmpty())
return null;
if (pool.size() > 20) {
SortMaster.sortEntitiesByExpression(pool, (item) -> item.getIntParam(PARAMS.GOLD_COST));
pool.removeIf(item -> pool.indexOf(item) > pool.size() / 2);
}
main.system.auxiliary.log.LogMaster.log(1, "filtered pool= " + pool + " max cost: " + maxCost);
if (pool.isEmpty())
return null;
ObjType baseType = new RandomWizard<ObjType>().getRandomListItem(pool);
return baseType;
}
Aggregations