use of eidolons.entity.item.DC_QuickItemObj in project Eidolons by IDemiurge.
the class ArmorMaster method getBlockPercentage.
// % to block for shield; max % of attack's damage blocked for armor
private int getBlockPercentage(boolean shield, boolean spell, boolean canCritOrBlock, boolean average, DC_Obj armorObj, boolean offhand, Unit attacker, Unit attacked, DC_ActiveObj action) {
if (!average)
average = action.getGame().getCombatMaster().isDiceAverage();
if (canCritOrBlock)
canCritOrBlock = !action.getGame().getCombatMaster().isChancesOff();
int covered = armorObj.getIntParam(PARAMS.COVER_PERCENTAGE);
int uncovered = 100 - covered;
DC_WeaponObj weapon = attacker.getActiveWeapon(offhand);
Integer area = action.getIntParam(PARAMS.IMPACT_AREA);
if (action.isRanged() && !action.isThrow()) {
if (weapon.isRanged()) {
try {
DC_QuickItemObj ammo = (DC_QuickItemObj) weapon.getRef().getObj(KEYS.AMMO);
if (ammo == null) // ammo = attacker.getAmmo(weapon); TODO
{
ammo = attacker.getQuickItems().get(0);
}
weapon = ammo.getWrappedWeapon();
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
area = 15;
}
}
}
if (!spell) {
if (area == 0) {
area = weapon.getIntParam(PARAMS.IMPACT_AREA);
}
}
int maximum = covered;
int minimum = area - uncovered;
if (minimum < 0) {
minimum = 0;
}
if (!canCritOrBlock) {
if (simulation || average) {
return MathMaster.getAverage(minimum, maximum);
}
return RandomWizard.getRandomIntBetween(minimum, maximum);
}
// sneak?
int attack = DefenseVsAttackRule.getAttackValue(offhand, attacker, attacked, action);
int defense = DefenseVsAttackRule.getDefenseValue(attacker, attacked, action);
// sneakCondition.preCheck(attacker);
boolean sneak = false;
// boolean watched_attacker=false;// watchCondition.preCheck(attacker)
// boolean watched_target=false;// watchCondition.preCheck(attacked)
int def_coef = 100;
int atk_coef = 100;
if (sneak) {
def_coef = 25;
}
if (shield) {
defense = 10 + 2 * attacked.getIntParam(PARAMS.SHIELD_MASTERY);
} else {
def_coef += attacked.getIntParam(PARAMS.ARMORER_MASTERY);
defense += attacked.getIntParam(PARAMS.ARMORER_MASTERY);
}
// TODO action must already have those params from attacker!
if (!spell) {
atk_coef = atk_coef * action.getIntParam(PARAMS.ARMOR_MOD) / 100;
atk_coef += action.getIntParam(PARAMS.ARMOR_PENETRATION);
}
// else accuracy/resist penetr
int blockPercBonus = (def_coef * defense - atk_coef * attack) / 100;
if (shield) {
return Math.max(0, MathMaster.addFactor((maximum + minimum) / 2, blockPercBonus));
}
// TODO OR MAKE REFLEX ROLL TO DOUBLE BLOCK CHANCE?
if (simulation || average) {
return (minimum + maximum) / 2;
}
boolean crit_or_block = RandomWizard.chance(Math.abs(blockPercBonus));
if (crit_or_block) {
if (blockPercBonus > 0) {
return maximum;
}
return minimum;
}
int percentageBlocked = RandomWizard.getRandomIntBetween(minimum, maximum);
return percentageBlocked;
}
use of eidolons.entity.item.DC_QuickItemObj in project Eidolons by IDemiurge.
the class ActionSequenceConstructor method getRangedReloadAction.
// now replaced with Atomic logic?
private List<AiQuickItemAction> getRangedReloadAction(Action action) {
Obj weapon = action.getActive().getRef().getObj(KEYS.RANGED);
WEAPON_GROUP weapon_group = null;
List<AiQuickItemAction> list = new ArrayList<>();
if (weapon instanceof DC_WeaponObj) {
DC_WeaponObj dc_WeaponObj = (DC_WeaponObj) weapon;
if (dc_WeaponObj.getWeaponGroup() == ItemEnums.WEAPON_GROUP.BOWS) {
weapon_group = ItemEnums.WEAPON_GROUP.ARROWS;
}
if (dc_WeaponObj.getWeaponGroup() == ItemEnums.WEAPON_GROUP.CROSSBOWS) {
weapon_group = ItemEnums.WEAPON_GROUP.BOLTS;
}
for (DC_QuickItemObj ammo : action.getSource().getQuickItems()) {
if (!ammo.isAmmo()) {
continue;
}
ammo.construct();
if (ammo.getWrappedWeapon().getWeaponGroup() == weapon_group) {
AiQuickItemAction qia = new AiQuickItemAction(ammo);
if (qia.canBeActivated()) {
list.add(qia);
}
}
}
}
return list;
}
use of eidolons.entity.item.DC_QuickItemObj in project Eidolons by IDemiurge.
the class AtomicAi method getReloadAction.
private Action getReloadAction(UnitAI ai) {
DC_QuickItemObj ammo = null;
Integer maxCost = 0;
for (DC_QuickItemObj a : ai.getUnit().getQuickItems()) {
if (a.isAmmo()) {
Integer cost = a.getWrappedWeapon().getIntParam(PARAMS.GOLD_COST);
if (cost > maxCost) {
ammo = a;
}
}
}
if (ammo != null) {
return AiActionFactory.newAction(ammo.getActive(), new Ref(ai.getUnit()));
}
return null;
}
use of eidolons.entity.item.DC_QuickItemObj in project Eidolons by IDemiurge.
the class DC_HeroManager method removeQuickSlotItem.
@Override
public void removeQuickSlotItem(Unit hero, Entity type) {
DC_QuickItemObj item = null;
if (type instanceof DC_QuickItemObj) {
item = (DC_QuickItemObj) type;
}
for (DC_QuickItemObj itemObj : hero.getQuickItems()) {
if (itemObj.getType() == type) {
item = itemObj;
break;
}
}
hero.removeQuickItem(item);
hero.addItemToInventory(item);
// if (hero.getQuickItems().isEmpty())
// hero.setQuickItems(null); //in DC_HeroObj for now
update(hero);
}
use of eidolons.entity.item.DC_QuickItemObj in project Eidolons by IDemiurge.
the class DC_HeroManager method setHeroItem.
@Override
public int setHeroItem(Unit hero, ITEM_SLOT slot, Entity type) {
int result = 0;
if (slot == ItemEnums.ITEM_SLOT.ARMOR) {
if (!hero.checkBool(GenericEnums.STD_BOOLS.ARMOR_CHANGE)) {
return 0;
}
result++;
}
DC_HeroItemObj slotItem = null;
DC_QuickItemObj quick = null;
if (type instanceof DC_QuickItemObj) {
quick = ((DC_QuickItemObj) type);
slotItem = quick.getWrappedWeapon();
}
if (type instanceof DC_HeroItemObj) {
slotItem = (DC_HeroItemObj) type;
} else {
for (DC_HeroItemObj item : hero.getInventory()) {
if (item.getType() == type) {
slotItem = item;
break;
}
}
// item
}
hero.setItem(slotItem, slot);
if (quick != null) {
hero.removeQuickItem(quick);
} else {
hero.removeFromInventory(slotItem);
}
result++;
if (result > 0) {
update(hero);
}
return result;
}
Aggregations