/
com/planet_ink/coffee_mud/Abilities/
com/planet_ink/coffee_mud/Abilities/Common/
com/planet_ink/coffee_mud/Abilities/Diseases/
com/planet_ink/coffee_mud/Abilities/Druid/
com/planet_ink/coffee_mud/Abilities/Fighter/
com/planet_ink/coffee_mud/Abilities/Prayers/
com/planet_ink/coffee_mud/Abilities/Properties/
com/planet_ink/coffee_mud/Abilities/Skills/
com/planet_ink/coffee_mud/Abilities/Songs/
com/planet_ink/coffee_mud/Abilities/Spells/
com/planet_ink/coffee_mud/Abilities/Thief/
com/planet_ink/coffee_mud/Abilities/Traps/
com/planet_ink/coffee_mud/Areas/interfaces/
com/planet_ink/coffee_mud/Behaviors/
com/planet_ink/coffee_mud/CharClasses/interfaces/
com/planet_ink/coffee_mud/Commands/
com/planet_ink/coffee_mud/Commands/interfaces/
com/planet_ink/coffee_mud/Exits/interfaces/
com/planet_ink/coffee_mud/Items/Armor/
com/planet_ink/coffee_mud/Items/Basic/
com/planet_ink/coffee_mud/Items/MiscMagic/
com/planet_ink/coffee_mud/Items/Software/
com/planet_ink/coffee_mud/Items/Weapons/
com/planet_ink/coffee_mud/Libraries/interfaces/
com/planet_ink/coffee_mud/Locales/
com/planet_ink/coffee_mud/Locales/interfaces/
com/planet_ink/coffee_mud/MOBS/
com/planet_ink/coffee_mud/MOBS/interfaces/
com/planet_ink/coffee_mud/Races/
com/planet_ink/coffee_mud/Races/interfaces/
com/planet_ink/coffee_mud/WebMacros/
com/planet_ink/coffee_mud/WebMacros/interfaces/
com/planet_ink/coffee_mud/application/
com/planet_ink/coffee_mud/core/smtp/
com/planet_ink/siplet/applet/
lib/
resources/examples/
resources/fakedb/
resources/quests/delivery/
resources/quests/diseased/
resources/quests/drowning/
resources/quests/gobwar/
resources/quests/holidays/
resources/quests/robbed/
resources/quests/smurfocide/
resources/quests/stolen/
resources/quests/templates/
resources/quests/treasurehunt/
resources/quests/vengeance/
web/
web/admin.templates/
web/admin/images/
web/pub.templates/
web/pub/images/mxp/
web/pub/sounds/
package com.planet_ink.coffee_mud.Abilities.Misc;
import com.planet_ink.coffee_mud.Abilities.StdAbility;
import com.planet_ink.coffee_mud.core.interfaces.*;
import com.planet_ink.coffee_mud.core.*;
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.Locales.interfaces.*;
import com.planet_ink.coffee_mud.MOBS.interfaces.*;
import com.planet_ink.coffee_mud.Races.interfaces.*;

import java.util.*;

/* 
   Copyright 2000-2006 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 Bleeding extends StdAbility
{
    public String ID() { return "Bleeding"; }
    public String name(){ return "Bleeding";}
    public String displayText(){ return "(Bleeding)";}
    protected int canAffectCode(){return CAN_ITEMS|Ability.CAN_MOBS;}
    protected int canTargetCode(){return 0;}
    protected int hpToKeep=-1;
    protected int lastDir=-1;
    protected Room lastRoom=null;
    
    public double healthPct(MOB mob){ return CMath.div(mob.curState().getHitPoints(),mob.maxState().getHitPoints());}
    
    public void affectEnvStats(Environmental affected, EnvStats affectedStats)
    {
        super.affectEnvStats(affected,affectedStats);
        //if(affected instanceof MOB)
        //    affectedStats.setSpeed(affectedStats.speed()*healthPct((MOB)affected));
    }

    public void unInvoke()
    {
        if((affected instanceof MOB)
        &&(canBeUninvoked())
        &&(!((MOB)affected).amDead())
        &&(CMLib.flags().isInTheGame(affected,true)))
            ((MOB)affected).location().show((MOB)affected,null,null,CMMsg.MSG_OK_VISUAL,"<S-NAME> stop(s) bleeding.");
        super.unInvoke();
    }
    
    public void affectCharState(MOB affected, CharState affectedState)
    {
        super.affectCharState(affected,affectedState);
        //affectedState.setMovement((int)Math.round(affectedState.getMovement()*CMath.div(affected.curState().getHitPoints(),affected.maxState().getHitPoints())));
        //affectedState.setMana((int)Math.round(affectedState.getMana()*CMath.div(affected.curState().getHitPoints(),affected.maxState().getHitPoints())));
    }

    public void  executeMsg(Environmental myHost, CMMsg msg)
    {
        super.executeMsg(myHost,msg);
        if((affected!=null)&&(msg.amITarget(affected))&&(affected instanceof MOB))
		{
	        if(msg.targetMinor()==CMMsg.TYP_HEALING)
	        {
	            hpToKeep=-1;
	            if(healthPct((MOB)affected)>0.50)
	            	unInvoke();
	        }
	        else
	        if((msg.targetMinor()==CMMsg.TYP_LOOK)
	        ||(msg.targetMinor()==CMMsg.TYP_EXAMINE))
	        	msg.source().tell((MOB)msg.target(),null,null,"^R<S-NAME> <S-IS-ARE> still bleeding...");
		}
        else
        if((msg.source()==affected)
        &&(msg.target() instanceof Room)
        &&(msg.tool() instanceof Exit)
        &&(msg.targetMinor()==CMMsg.TYP_LEAVE))
        {
        	Room R=(Room)msg.target();
        	int dir=-1;
        	for(int d=0;d<Directions.NUM_DIRECTIONS;d++)
        		if(msg.tool()==R.getReverseExit(d))
        			dir=d;
        	if((dir>=0)&&(R.fetchItem(null,"a trail of blood")==null))
        	{
        		Item I=CMClass.getItem("GenFatWallpaper");
        		I.setName("A trail of blood");
	        	if(lastDir>=0)
	        		I.setDisplayText("A faint trail of blood leads from "
        				+Directions.getDirectionName(lastDir)+" to "+Directions.getDirectionName(dir)+".");
	        	else
	        		I.setDisplayText("A faint trail of blood leads "+Directions.getDirectionName(dir)+".");
        		I.envStats().setDisposition(I.envStats().disposition()|EnvStats.IS_HIDDEN|EnvStats.IS_UNSAVABLE);
        		I.setSecretIdentity(msg.source().Name()+"`s blood.");
        		R.addItemRefuse(I,Item.REFUSE_MONSTER_EQ);
        	}
        	lastDir=Directions.getOpDirectionCode(dir);
        	lastRoom=R;
        }
    }
    public boolean tick(Tickable ticking, int tickID)
    {
        if(!super.tick(ticking,tickID))
        	return false;
        if((ticking instanceof MOB)&&(tickID==Tickable.TICKID_MOB))
        {
        	MOB mob=(MOB)ticking;
            if(hpToKeep<=0)
            {
                hpToKeep=mob.curState().getHitPoints();
                mob.recoverMaxState();
            }
            else
            {
	            if(mob.curState().getHitPoints()>hpToKeep)
	            	mob.curState().setHitPoints(hpToKeep);
	            int maxMana=(int)Math.round(CMath.mul(mob.maxState().getMana(),healthPct(mob)));
                if(mob.curState().getMana()>maxMana)
                	mob.curState().setMana(maxMana);
	            int maxMovement=(int)Math.round(CMath.mul(mob.maxState().getMovement(),healthPct(mob)));
                if(mob.curState().getMovement()>maxMovement)
                	mob.curState().setMovement(maxMovement);
            }
        }
        return true;
    }
    
    public boolean invoke(MOB mob, Vector commands, Environmental target, boolean auto, int asLevel)
    {
    	if(target==null) target=mob;
    	if(!(target instanceof MOB)) return false;
    	if(CMLib.flags().isGolem((MOB)target)) return false;
    	if(((MOB)target).envStats().level()<CMProps.getIntVar(CMProps.SYSTEMI_INJBLEEDMINLEVEL)) return false;
    	if(((MOB)target).fetchEffect(ID())!=null) return false;
    	if(((MOB)target).location()==null) return false;
    	if(((MOB)target).location().show((MOB)target,null,this,CMMsg.MSG_OK_VISUAL,"^R<S-NAME> start(s) BLEEDING!^?"))
	    	beneficialAffect(mob,target,asLevel,0);
    	return true;
    }
}