<NME> Skill_Subdue.java
<BEF> package com.planet_ink.coffee_mud.Abilities.Skills;
import com.planet_ink.coffee_mud.core.interfaces.*;
import com.planet_ink.coffee_mud.core.*;
import com.planet_ink.coffee_mud.core.collections.*;
import com.planet_ink.coffee_mud.Abilities.interfaces.*;
import com.planet_ink.coffee_mud.Areas.interfaces.*;
import com.planet_ink.coffee_mud.Behaviors.interfaces.*;
import com.planet_ink.coffee_mud.CharClasses.interfaces.*;
import com.planet_ink.coffee_mud.Commands.interfaces.*;
import com.planet_ink.coffee_mud.Common.interfaces.*;
import com.planet_ink.coffee_mud.Exits.interfaces.*;
import com.planet_ink.coffee_mud.Items.interfaces.*;
import com.planet_ink.coffee_mud.Libraries.interfaces.*;
import com.planet_ink.coffee_mud.Locales.interfaces.*;
import com.planet_ink.coffee_mud.MOBS.interfaces.*;
import com.planet_ink.coffee_mud.Races.interfaces.*;

import java.util.*;

/*
   Copyright 2011-2022 Bo Zimmerman

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

	   http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
public class Skill_Subdue extends StdSkill
{
	@Override
	public String ID()
	{
		return "Skill_Subdue";
	}

	private final static String localizedName = CMLib.lang().L("Subdue");

	@Override
	public String name()
	{
		return localizedName;
	}

	@Override
	public String displayText()
	{
		final MOB whom=this.whom;
		if(whom == null)
			return L("(Subdueing)");
		else
		if(affected instanceof MOB)
			return L("(Subdueing "+whom.name((MOB)affected)+")");
		else
			return L("(Subdueing "+whom.name()+")");
	}

	@Override
	protected int canAffectCode()
	{
		return CAN_MOBS;
	}

	@Override
	protected int canTargetCode()
	{
		return CAN_MOBS;
	}

	@Override
	public int abstractQuality()
	{
		return Ability.QUALITY_MALICIOUS;
	}

	private static final String[] triggerStrings =I(new String[] {"SUBDUE"});
	@Override
	public String[] triggerStrings()
	{
		return triggerStrings;
	}

	@Override
	public int classificationCode()
	{
		return Ability.ACODE_SKILL|Ability.DOMAIN_EVASIVE;
	}

	@Override
	public int usageType()
	{
		return USAGE_MOVEMENT;
	}

	protected MOB whom=null;
	protected int whomDamage=0;
	protected int asLevel=0;

	@Override
	public void affectPhyStats(final Physical affected, final PhyStats affectableStats)
	{
		super.affectPhyStats(affected,affectableStats);
		affectableStats.setArmor(affectableStats.attackAdjustment() - 10 + super.getXLEVELLevel(invoker()));
	}

	@Override
	public boolean okMessage(final Environmental myHost, final CMMsg msg)
	{
		if(affected instanceof MOB)
		{
			final MOB M=(MOB)affected;
			final MOB whom = (this.whom==null)?M.getVictim():this.whom;
			if(canBeUninvoked()&&
			(M.amDead()||(!CMLib.flags().isInTheGame(M, false))||(!M.amActive())||M.amDestroyed()||(M.getVictim()!=whom)))
			{
				unInvoke();
				return true;
			}
			if((msg.targetMinor()==CMMsg.TYP_DAMAGE)
			&&(affected !=null)
			&&(msg.source()==affected)
			&&(msg.target()==whom))
			{
				whomDamage+=msg.value();
				msg.setValue(1);
			}
		}
		return true;
	}

	@Override
	public void executeMsg(final Environmental myHost, final CMMsg msg)
	{
		if(affected instanceof MOB)
		{
			final MOB whom = (this.whom==null)?((MOB)affected).getVictim():this.whom;
			if((msg.source()==affected)
			&&(msg.target()==whom)
			&&(msg.targetMinor()==CMMsg.TYP_EXAMINE)
			&&(CMLib.flags().canBeSeenBy(whom, msg.source())))
			{
				final double actualHitPct = CMath.div(whom.curState().getHitPoints()-whomDamage,whom.baseState().getHitPoints());
				msg.source().tell(msg.source(),whom,null,L("<T-NAME> is @x1 health away from being overcome.",CMath.toPct(actualHitPct)));
			}

			if((msg.targetMinor()==CMMsg.TYP_DAMAGE)
			&&(affected !=null)
			&&(msg.source()==affected)
			&&(msg.target()==whom)
			&&(whom.curState().getHitPoints() - whomDamage)<=0)
			{
					sap.invoke(whom,new XVector<String>("SAFELY",Integer.toString(adjustedLevel(msg.source(),asLevel))),whom,true,0);
				whom.makePeace(true);
				msg.source().makePeace(true);
				unInvoke();
			}
		}
			}
		}
	}

	@Override
	public void unInvoke()
	{
		final Physical P=affected;
		if((canBeUninvoked())
		&&(P instanceof MOB)
		&&(whom!=null))
			((MOB)P).tell(L("You are no longer trying to subdue @x1",whom.name()));
		super.unInvoke();
	}

	@Override
	public int castingQuality(final MOB mob, final Physical target)
	{
		return Ability.QUALITY_INDIFFERENT;
	}

	@Override
	public boolean invoke(final MOB mob, final List<String> commands, final Physical givenTarget, final boolean auto, final int asLevel)
	{
		final Ability A=mob.fetchEffect(ID());
		if(A!=null)
			A.unInvoke();
		final MOB target=this.getTarget(mob,commands,givenTarget);
		if(target==null)
			return false;

		if(!super.invoke(mob,commands,givenTarget,auto,asLevel))
			return false;

		final boolean success=proficiencyCheck(mob,0,auto);

		if(success)
		{
			final CMMsg msg=CMClass.getMsg(mob,target,this,CMMsg.MSK_MALICIOUS_MOVE|CMMsg.TYP_JUSTICE|(auto?CMMsg.MASK_ALWAYS:0),auto?"":L("^F^<FIGHT^><S-NAME> attempt(s) to subdue <T-NAMESELF>!^</FIGHT^>^?"));
			CMLib.color().fixSourceFightColor(msg);
			if(mob.location().okMessage(mob,msg))
			{
				mob.location().send(mob,msg);
				beneficialAffect(mob,mob,asLevel,0);
				final Skill_Subdue SK=(Skill_Subdue)mob.fetchEffect(ID());
				if(SK!=null)
				{
					SK.whom=target;
					SK.asLevel=asLevel;
				}
			}
		}
		else
			return maliciousFizzle(mob,target,L("<S-NAME> attempt(s) to subdue <T-NAMESELF>, but fails."));
		return success;
	}
}

<MSG> Tracking the recently subdued.

git-svn-id: 0cdf8356e41b2d8ccbb41bb76c82068fe80b2514@20909 0d6f1817-ed0e-0410-87c9-987e46238f29

<DFF> @@ -101,6 +101,7 @@ public class Skill_Subdue extends StdSkill
 	protected MOB whom=null;
 	protected int whomDamage=0;
 	protected int asLevel=0;
+	protected final Set<MOB> lastKills = new LimitedTreeSet<MOB>(TimeManager.MILI_DAY,250,false);
 
 	@Override
 	public void affectPhyStats(final Physical affected, final PhyStats affectableStats)
@@ -158,6 +159,12 @@ public class Skill_Subdue extends StdSkill
 					sap.invoke(whom,new XVector<String>("SAFELY",Integer.toString(adjustedLevel(msg.source(),asLevel))),whom,true,0);
 				whom.makePeace(true);
 				msg.source().makePeace(true);
+				final Skill_Subdue skillA = (Skill_Subdue)msg.source().fetchAbility(ID());
+				if((skillA!=null)
+				&&(!skillA.lastKills.contains(whom)))
+				{
+					skillA.lastKills.add(whom);
+				}
 				unInvoke();
 			}
 		}

{'commit': 'diff --git a/com/planet_ink/coffee_mud/Abilities/Skills/Skill_Subdue.java b/com/planet_ink/coffee_mud/Abilities/Skills/Skill_Subdue.java\nindex 6e1aaa7739..3986ab9c02 100644\n--- a/com/planet_ink/coffee_mud/Abilities/Skills/Skill_Subdue.java\n+++ b/com/planet_ink/coffee_mud/Abilities/Skills/Skill_Subdue.java\n@@ -101,6 +101,7 @@ public class Skill_Subdue extends StdSkill\n \tprotected MOB whom=null;\r\n \tprotected int whomDamage=0;\r\n \tprotected int asLevel=0;\r\n+\tprotected final Set<MOB> lastKills = new LimitedTreeSet<MOB>(TimeManager.MILI_DAY,250,false);\r\n \r\n \t@Override\r\n \tpublic void affectPhyStats(final Physical affected, final PhyStats affectableStats)\r\n@@ -158,6 +159,12 @@ public class Skill_Subdue extends StdSkill\n \t\t\t\t\tsap.invoke(whom,new XVector<String>("SAFELY",Integer.toString(adjustedLevel(msg.source(),asLevel))),whom,true,0);\r\n \t\t\t\twhom.makePeace(true);\r\n \t\t\t\tmsg.source().makePeace(true);\r\n+\t\t\t\tfinal Skill_Subdue skillA = (Skill_Subdue)msg.source().fetchAbility(ID());\r\n+\t\t\t\tif((skillA!=null)\r\n+\t\t\t\t&&(!skillA.lastKills.contains(whom)))\r\n+\t\t\t\t{\r\n+\t\t\t\t\tskillA.lastKills.add(whom);\r\n+\t\t\t\t}\r\n \t\t\t\tunInvoke();\r\n \t\t\t}\r\n \t\t}\r\n', 'commit_subject': 'Tracking the recently subdued.', 'repo_name': 'bozimmerman/CoffeeMud', 'committer': {'name': 'bozimmerman', 'email': 'dc45fe023482b3b890b5e574e53c1d051f45b1ef@zimmers.net', 'time_sec': '1623885000', 'tz_offset': '0', 'date': {'seconds': '1623885000'}}, 'commit_tree': '98bbc68dc7a34a927447376822f6add10f2ad2e1', 'commit_message': 'Tracking the recently subdued.\n\ngit-svn-id: 0cdf8356e41b2d8ccbb41bb76c82068fe80b2514@20909 0d6f1817-ed0e-0410-87c9-987e46238f29\n', 'language_name': 'HTML', 'license': 'apache-2.0', 'hunks': '@@ -101,6 +101,7 @@ public class Skill_Subdue extends StdSkill\n \tprotected MOB whom=null;\r\n \tprotected int whomDamage=0;\r\n \tprotected int asLevel=0;\r\n+\tprotected final Set<MOB> lastKills = new LimitedTreeSet<MOB>(TimeManager.MILI_DAY,250,false);\r\n \r\n \t@Override\r\n \tpublic void affectPhyStats(final Physical affected, final PhyStats affectableStats)\r\n@@ -158,6 +159,12 @@ public class Skill_Subdue extends StdSkill\n \t\t\t\t\tsap.invoke(whom,new XVector<String>("SAFELY",Integer.toString(adjustedLevel(msg.source(),asLevel))),whom,true,0);\r\n \t\t\t\twhom.makePeace(true);\r\n \t\t\t\tmsg.source().makePeace(true);\r\n+\t\t\t\tfinal Skill_Subdue skillA = (Skill_Subdue)msg.source().fetchAbility(ID());\r\n+\t\t\t\tif((skillA!=null)\r\n+\t\t\t\t&&(!skillA.lastKills.contains(whom)))\r\n+\t\t\t\t{\r\n+\t\t\t\t\tskillA.lastKills.add(whom);\r\n+\t\t\t\t}\r\n \t\t\t\tunInvoke();\r\n \t\t\t}\r\n \t\t}\r\n', 'addition_count': 7, 'deletion_count': 0, 'src_file': 'a/com/planet_ink/coffee_mud/Abilities/Skills/Skill_Subdue.java', 'tgt_file': 'b/com/planet_ink/coffee_mud/Abilities/Skills/Skill_Subdue.java', 'file_extension': '.java', 'before_file': 'package com.planet_ink.coffee_mud.Abilities.Skills;\nimport com.planet_ink.coffee_mud.core.interfaces.*;\nimport com.planet_ink.coffee_mud.core.*;\nimport com.planet_ink.coffee_mud.core.collections.*;\nimport com.planet_ink.coffee_mud.Abilities.interfaces.*;\nimport com.planet_ink.coffee_mud.Areas.interfaces.*;\nimport com.planet_ink.coffee_mud.Behaviors.interfaces.*;\nimport com.planet_ink.coffee_mud.CharClasses.interfaces.*;\nimport com.planet_ink.coffee_mud.Commands.interfaces.*;\nimport com.planet_ink.coffee_mud.Common.interfaces.*;\nimport com.planet_ink.coffee_mud.Exits.interfaces.*;\nimport com.planet_ink.coffee_mud.Items.interfaces.*;\nimport com.planet_ink.coffee_mud.Libraries.interfaces.*;\nimport com.planet_ink.coffee_mud.Locales.interfaces.*;\nimport com.planet_ink.coffee_mud.MOBS.interfaces.*;\nimport com.planet_ink.coffee_mud.Races.interfaces.*;\n\nimport java.util.*;\n\n/*\n   Copyright 2011-2022 Bo Zimmerman\n\n   Licensed under the Apache License, Version 2.0 (the "License");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n\t   http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an "AS IS" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n*/\npublic class Skill_Subdue extends StdSkill\n{\n\t@Override\n\tpublic String ID()\n\t{\n\t\treturn "Skill_Subdue";\n\t}\n\n\tprivate final static String localizedName = CMLib.lang().L("Subdue");\n\n\t@Override\n\tpublic String name()\n\t{\n\t\treturn localizedName;\n\t}\n\n\t@Override\n\tpublic String displayText()\n\t{\n\t\tfinal MOB whom=this.whom;\n\t\tif(whom == null)\n\t\t\treturn L("(Subdueing)");\n\t\telse\n\t\tif(affected instanceof MOB)\n\t\t\treturn L("(Subdueing "+whom.name((MOB)affected)+")");\n\t\telse\n\t\t\treturn L("(Subdueing "+whom.name()+")");\n\t}\n\n\t@Override\n\tprotected int canAffectCode()\n\t{\n\t\treturn CAN_MOBS;\n\t}\n\n\t@Override\n\tprotected int canTargetCode()\n\t{\n\t\treturn CAN_MOBS;\n\t}\n\n\t@Override\n\tpublic int abstractQuality()\n\t{\n\t\treturn Ability.QUALITY_MALICIOUS;\n\t}\n\n\tprivate static final String[] triggerStrings =I(new String[] {"SUBDUE"});\n\t@Override\n\tpublic String[] triggerStrings()\n\t{\n\t\treturn triggerStrings;\n\t}\n\n\t@Override\n\tpublic int classificationCode()\n\t{\n\t\treturn Ability.ACODE_SKILL|Ability.DOMAIN_EVASIVE;\n\t}\n\n\t@Override\n\tpublic int usageType()\n\t{\n\t\treturn USAGE_MOVEMENT;\n\t}\n\n\tprotected MOB whom=null;\r\n\tprotected int whomDamage=0;\r\n\tprotected int asLevel=0;\r\n\r\n\t@Override\r\n\tpublic void affectPhyStats(final Physical affected, final PhyStats affectableStats)\r\n\t{\n\t\tsuper.affectPhyStats(affected,affectableStats);\n\t\taffectableStats.setArmor(affectableStats.attackAdjustment() - 10 + super.getXLEVELLevel(invoker()));\n\t}\n\n\t@Override\n\tpublic boolean okMessage(final Environmental myHost, final CMMsg msg)\n\t{\n\t\tif(affected instanceof MOB)\n\t\t{\n\t\t\tfinal MOB M=(MOB)affected;\n\t\t\tfinal MOB whom = (this.whom==null)?M.getVictim():this.whom;\n\t\t\tif(canBeUninvoked()&&\n\t\t\t(M.amDead()||(!CMLib.flags().isInTheGame(M, false))||(!M.amActive())||M.amDestroyed()||(M.getVictim()!=whom)))\n\t\t\t{\n\t\t\t\tunInvoke();\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif((msg.targetMinor()==CMMsg.TYP_DAMAGE)\n\t\t\t&&(affected !=null)\n\t\t\t&&(msg.source()==affected)\n\t\t\t&&(msg.target()==whom))\n\t\t\t{\n\t\t\t\twhomDamage+=msg.value();\n\t\t\t\tmsg.setValue(1);\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t@Override\n\tpublic void executeMsg(final Environmental myHost, final CMMsg msg)\n\t{\n\t\tif(affected instanceof MOB)\n\t\t{\n\t\t\tfinal MOB whom = (this.whom==null)?((MOB)affected).getVictim():this.whom;\n\t\t\tif((msg.source()==affected)\n\t\t\t&&(msg.target()==whom)\n\t\t\t&&(msg.targetMinor()==CMMsg.TYP_EXAMINE)\n\t\t\t&&(CMLib.flags().canBeSeenBy(whom, msg.source())))\n\t\t\t{\n\t\t\t\tfinal double actualHitPct = CMath.div(whom.curState().getHitPoints()-whomDamage,whom.baseState().getHitPoints());\n\t\t\t\tmsg.source().tell(msg.source(),whom,null,L("<T-NAME> is @x1 health away from being overcome.",CMath.toPct(actualHitPct)));\n\t\t\t}\n\n\t\t\tif((msg.targetMinor()==CMMsg.TYP_DAMAGE)\n\t\t\t&&(affected !=null)\n\t\t\t&&(msg.source()==affected)\n\t\t\t&&(msg.target()==whom)\n\t\t\t&&(whom.curState().getHitPoints() - whomDamage)<=0)\n\t\t\t{\n\t\t\t\t\tsap.invoke(whom,new XVector<String>("SAFELY",Integer.toString(adjustedLevel(msg.source(),asLevel))),whom,true,0);\r\n\t\t\t\twhom.makePeace(true);\r\n\t\t\t\tmsg.source().makePeace(true);\r\n\t\t\t\tunInvoke();\r\n\t\t\t}\r\n\t\t}\r\n\t\t\t}\n\t\t}\n\t}\n\n\t@Override\n\tpublic void unInvoke()\n\t{\n\t\tfinal Physical P=affected;\n\t\tif((canBeUninvoked())\n\t\t&&(P instanceof MOB)\n\t\t&&(whom!=null))\n\t\t\t((MOB)P).tell(L("You are no longer trying to subdue @x1",whom.name()));\n\t\tsuper.unInvoke();\n\t}\n\n\t@Override\n\tpublic int castingQuality(final MOB mob, final Physical target)\n\t{\n\t\treturn Ability.QUALITY_INDIFFERENT;\n\t}\n\n\t@Override\n\tpublic boolean invoke(final MOB mob, final List<String> commands, final Physical givenTarget, final boolean auto, final int asLevel)\n\t{\n\t\tfinal Ability A=mob.fetchEffect(ID());\n\t\tif(A!=null)\n\t\t\tA.unInvoke();\n\t\tfinal MOB target=this.getTarget(mob,commands,givenTarget);\n\t\tif(target==null)\n\t\t\treturn false;\n\n\t\tif(!super.invoke(mob,commands,givenTarget,auto,asLevel))\n\t\t\treturn false;\n\n\t\tfinal boolean success=proficiencyCheck(mob,0,auto);\n\n\t\tif(success)\n\t\t{\n\t\t\tfinal CMMsg msg=CMClass.getMsg(mob,target,this,CMMsg.MSK_MALICIOUS_MOVE|CMMsg.TYP_JUSTICE|(auto?CMMsg.MASK_ALWAYS:0),auto?"":L("^F^<FIGHT^><S-NAME> attempt(s) to subdue <T-NAMESELF>!^</FIGHT^>^?"));\n\t\t\tCMLib.color().fixSourceFightColor(msg);\n\t\t\tif(mob.location().okMessage(mob,msg))\n\t\t\t{\n\t\t\t\tmob.location().send(mob,msg);\n\t\t\t\tbeneficialAffect(mob,mob,asLevel,0);\n\t\t\t\tfinal Skill_Subdue SK=(Skill_Subdue)mob.fetchEffect(ID());\n\t\t\t\tif(SK!=null)\n\t\t\t\t{\n\t\t\t\t\tSK.whom=target;\n\t\t\t\t\tSK.asLevel=asLevel;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t\treturn maliciousFizzle(mob,target,L("<S-NAME> attempt(s) to subdue <T-NAMESELF>, but fails."));\n\t\treturn success;\n\t}\n}\n', 'message': 'Tracking the recently subdued.\n\ngit-svn-id: 0cdf8356e41b2d8ccbb41bb76c82068fe80b2514@20909 0d6f1817-ed0e-0410-87c9-987e46238f29\n', 'author_name': 'bozimmerman', 'lang': 'java'}