@Override public void setMiscText(String txt) { super.setMiscText(""); if (txt.startsWith("-")) { txt = txt.substring(1).toLowerCase().trim(); for (final Object[] A : affects) if (((CMObject) A[0]).ID().toLowerCase().equals(txt)) { unAffectAffected(A); return; } for (final Object[] A : affects) if ((A[0] instanceof Ability) && (((Environmental) A[0]).name().toLowerCase().startsWith(txt))) { unAffectAffected(A); return; } for (final Object[] A : affects) if ((A[0] instanceof Behavior) && (((Behavior) A[0]).name().toLowerCase().startsWith(txt))) { unAffectAffected(A); return; } } else if (txt.trim().length() > 0) { if (txt.startsWith("+")) txt = txt.substring(1); else for (final Object[] A : affects) unAffectAffected(A); int x = txt.indexOf(' '); if (x < 0) return; final String abilityStr = txt.substring(0, x).trim(); String numTicksStr = txt.substring(x + 1).trim(); String parms = ""; x = numTicksStr.indexOf(' '); if (x > 0) { parms = numTicksStr.substring(x + 1).trim(); numTicksStr = numTicksStr.substring(0, x); } CMObject A = CMClass.getAbility(abilityStr); if (A == null) A = CMClass.getBehavior(abilityStr); if (A == null) A = CMClass.findAbility(abilityStr); if (A == null) A = CMClass.findBehavior(abilityStr); if (A != null) { affects.addElement(new Object[] {A, new int[] {CMath.s_int(numTicksStr)}}); if (A instanceof Ability) ((Ability) A).setMiscText(parms); if ((A instanceof Behavior) && (affected instanceof PhysicalAgent)) ((Behavior) A).setParms(parms); finishInit(A); } } }
@Override public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) { if (commands.size() < 3) { mob.tell( L("Specify a target, a property, number of ticks, and (optionally) some misc text!")); return false; } final Vector V = new XVector(commands.firstElement()); final Physical target = getAnyTarget(mob, V, givenTarget, Wearable.FILTER_ANY); if (target == null) return false; commands.removeElementAt(0); final String abilityStr = (String) commands.firstElement(); CMObject A = CMClass.getAbility(abilityStr); if (A == null) A = CMClass.getBehavior(abilityStr); if (A == null) A = CMClass.findAbility(abilityStr); if (A == null) A = CMClass.findBehavior(abilityStr); if (A == null) { mob.tell(L("No such ability or behavior as @x1!", abilityStr)); return false; } final String numTicks = ((String) commands.elementAt(1)).trim(); if ((!CMath.isInteger(numTicks)) || (CMath.s_int(numTicks) <= 0)) { mob.tell(L("'@x1' is not a number of ticks!", numTicks)); return false; } final String parms = CMParms.combine(commands, 2); if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; TemporaryAffects T = (TemporaryAffects) target.fetchEffect(ID()); if (T == null) { T = (TemporaryAffects) this.newInstance(); T.affects = new SVector<Object[]>(); T.startTickDown(mob, target, 10); T = (TemporaryAffects) target.fetchEffect(ID()); } if (T != null) { T.setMiscText("+" + A.ID() + " " + numTicks.trim() + " " + parms.trim()); T.makeLongLasting(); } return true; }