@Override public boolean okMessage(final Environmental myHost, final CMMsg msg) { if (!(myHost instanceof MOB)) return super.okMessage(myHost, msg); final MOB myChar = (MOB) myHost; if (msg.tool() instanceof Ability) { if (msg.amISource(myChar) && (!myChar.isMonster()) && (msg.sourceMinor() != CMMsg.TYP_PREINVOKE)) { final WeakReference<Ability> curRef = invokable; if ((curRef != null) && (msg.tool() == curRef.get())) { curRef.clear(); final Ability A = ((Ability) msg.tool()); final int[] usageCost = A.usageCost(myChar, false); if (CMath.bset(A.usageType(), Ability.USAGE_MANA)) myChar.curState().adjMana(usageCost[Ability.USAGEINDEX_MANA] / 4, myChar.maxState()); if (CMath.bset(A.usageType(), Ability.USAGE_MOVEMENT)) myChar .curState() .adjMovement(usageCost[Ability.USAGEINDEX_MOVEMENT] / 4, myChar.maxState()); if (CMath.bset(A.usageType(), Ability.USAGE_HITPOINTS)) myChar .curState() .adjHitPoints(usageCost[Ability.USAGEINDEX_HITPOINTS] / 4, myChar.maxState()); } } else if (msg.amITarget(myChar)) { if (((((Ability) msg.tool()).classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_SPELL) && ((((Ability) msg.tool()).classificationCode() & Ability.ALL_DOMAINS) == Ability.DOMAIN_DIVINATION) && (CMLib.dice().roll(1, 100, 0) < (myChar.charStats().getClassLevel(this) * 4))) { myChar .location() .show( msg.source(), myChar, CMMsg.MSG_OK_ACTION, L( "<T-NAME> fool(s) <S-NAMESELF>, causing <S-HIM-HER> to fizzle @x1.", msg.tool().name())); return false; } } } return super.okMessage(myHost, msg); }
public void affectCharState(MOB mob, CharState state) { super.affectCharState(mob, state); if (mob.baseCharStats().getCurrentClass().ID().equals(ID())) { Ability A = null; for (int a = 0; a < mob.numLearnedAbilities(); a++) { A = mob.fetchAbility(a); if ((A != null) && ((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_SPELL) && (!CMLib.ableMapper().getDefaultGain(ID(), false, A.ID()))) { int[] cost = A.usageCost(mob, true); int manaCost = cost[Ability.USAGEINDEX_MANA]; if (manaCost > 0) { if (state.getMana() < manaCost) { mob.delAbility(A); a--; } else state.setMana(state.getMana() - manaCost); } } } if (mob.curState().getMana() > state.getMana()) mob.curState().setMana(state.getMana()); } }