IF
  Die()
THEN
  RESPONSE #100
    Shout(66)
END

IF
  Global("BPCHARM","LOCALS",1)
  !StateCheck(Myself,STATE_CHARMED)
THEN
  RESPONSE #100
    SetGlobal("BPCHARM","LOCALS",0)
    ClearActions(Myself)
    Continue()
END

IF
  OR(2)
    HPLT(Myself,5)
    Dead("TOLMAG02")  // ~Mage~
  Global("BP_IMoved","LOCALS",0)
THEN
  RESPONSE #100
    ClearAllActions()
    StartCutSceneMode()
    ReallyForceSpellPointRES("SPWI402",[1800.600])
    DestroyItem("SUREHP1")  // <Invalid Strref -1>
    ReallyForceSpell(Myself,CLERIC_HEAL)
    SetGlobal("BPSPHERE","GLOBAL",15)
    SetGlobal("BP_MageMoved","GLOBAL",1)
    SetGlobal("BP_IMoved","LOCALS",1)
    EndCutSceneMode()
END

IF
  Global("BP_MageMoved","GLOBAL",1)
  Global("BP_IMoved","LOCALS",0)
THEN
  RESPONSE #100
    ClearAllActions()
    StartCutSceneMode()
    ReallyForceSpellPointRES("SPWI402",[1800.600])
    DestroyItem("MINHP1")  // <Invalid Strref -1>
    ReallyForceSpell(Myself,CLERIC_HEAL)
    SetGlobal("BP_IMoved","LOCALS",1)
    SetGlobal("BP_MageMoved","GLOBAL",1)
    EndCutSceneMode()
END

IF
  CheckStat(Myself,1,WIZARD_MISLEAD)
  See([EVILCUTOFF.0.0.LONG_BOW.0.ILLUSIONARY])
THEN
  RESPONSE #100
    ActionOverride(LastSeenBy(Myself),ChangeAIScript("BPTMG2IM",OVERRIDE))
    ChangeSpecifics(LastSeenBy(Myself),NEEDS_BREACH)
    ChangeGender(LastSeenBy(Myself),EXTRA2)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_IMPROVED_HASTE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_STONE_SKIN)
  CheckStatLT(Myself,1,STONESKINS)
  GlobalGT("BPSPHERE","GLOBAL",1)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_STONE_SKIN)
END

IF
  HPPercentLT(Myself,60)
  !GlobalTimerNotExpired("POT","LOCALS")
  HasItem("POTN52",Myself)  // ~Potion of Extra Healing~
THEN
  RESPONSE #100
    SetGlobalTimer("POT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    UseItem("POTN52",Myself)  // ~Potion of Extra Healing~
END

IF
  GlobalGT("BPSPHERE","GLOBAL",13)
THEN
  RESPONSE #100
END

IF
  Global("BPSPHERE","GLOBAL",1)
  ActionListEmpty()
THEN
  RESPONSE #100
    SetGlobal("BPSPHERE","GLOBAL",2)
    DisplayStringHead(Myself,73139)  // ~Contingency - Fired~
    DisplayString(Myself,26328)  // ~Chain Contingency~
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
    ReallyForceSpell(Myself,WIZARD_SPELL_TRAP)
    SmallWait(5)
    DisplayString(Myself,40252)  // ~Contingency - Protection from Magical Weapons~
    DisplayString(Myself,61343)  // ~Contingency - Protection from Normal Missiles~
END

IF
  Global("BPSPHERE","GLOBAL",3)
  GlobalTimerExpired("BPTTIME","GLOBAL")
  ActionListEmpty()
THEN
  RESPONSE #100
    SetGlobal("BPSPHERE","GLOBAL",4)
    ReallyForceSpellPointRES("SPWI402",[1000.1165])
END

IF
  Global("BPSPHERE","GLOBAL",6)
  ActionListEmpty()
THEN
  RESPONSE #100
    SetGlobal("BPSPHERE","GLOBAL",7)
    SetGlobalTimer("BPTTIME","GLOBAL",8)
    SpellPoint([850.1290],COM_RAGING_BULL)
END

IF
  Global("BPSPHERE","GLOBAL",7)
  GlobalTimerExpired("BPTTIME","GLOBAL")
  ActionListEmpty()
  OR(2)
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  OR(4)
    CheckStatGT(LastSeenBy(Myself),0,164)
    CheckStatGT(LastSeenBy(Myself),0,129)
    CheckStatGT(LastSeenBy(Myself),0,116)
    CheckStatGT(LastSeenBy(Myself),0,SHIELDGLOBE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPTTIME","GLOBAL",4)
    SetGlobal("BPSPHERE","GLOBAL",8)
    Spell(LastSeenBy(Myself),WIZARD_RUBY_RAY_OF_REVERSAL)
END

IF
  Global("BPSPHERE","GLOBAL",7)
  GlobalTimerExpired("BPTTIME","GLOBAL")
  ActionListEmpty()
  OR(2)
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  OR(4)
    CheckStatGT(LastSeenBy(Myself),0,128)
    CheckStatGT(LastSeenBy(Myself),0,126)
    CheckStatGT(LastSeenBy(Myself),60,RESISTELECTRICITY)
    CheckStatGT(LastSeenBy(Myself),0,130)
THEN
  RESPONSE #100
    SetGlobal("BPSPHERE","GLOBAL",8)
    SetGlobalTimer("BPTTIME","GLOBAL",4)
    Spell(LastSeenBy(Myself),WIZARD_BREACH)
END

IF
  Global("BPSPHERE","GLOBAL",7)
  GlobalTimerExpired("BPTTIME","GLOBAL")
  ActionListEmpty()
THEN
  RESPONSE #100
    SetGlobalTimer("BPTTIME","GLOBAL",4)
    SetGlobal("BPSPHERE","GLOBAL",8)
END

IF
	Global("BPSPHERE","GLOBAL",9)
	GlobalTimerExpired("BPTTIME","GLOBAL")
	ActionListEmpty()
    OR(6)
	    See(NearestEnemyOfType([PC]))
	    See(SecondNearestEnemyOfType([PC]))
	    See(ThirdNearestEnemyOfType([PC]))
	    See(FourthNearestEnemyOfType([PC]))
        See(NearestEnemyOfType([PC.0.0.LONG_BOW]))
        See(NearestEnemyOfType([PC.0.0.SORCERER]))
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_TIME_STOP)
		Spell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
		Spell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_STUN)
		Spell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_FEAR)
		Spell(LastSeenBy(Myself),WIZARD_CHAOS)
		SetGlobalTimer("BPTTIME","GLOBAL",4)
		SetGlobal("BPSPHERE","GLOBAL",10)
END

IF
	Global("BPSPHERE","GLOBAL",9)
	!GlobalTimerNotExpired("BPTTIME","GLOBAL")
	ActionListEmpty()
THEN
	RESPONSE #100
		Spell(Myself,WIZARD_TIME_STOP)
		SpellPoint([850.1300],WIZARD_ABI_DALZIMS_HORRID_WILTING)
		SpellPoint([850.1300],WIZARD_NPC_SYMBOL_STUN)
		SpellPoint([850.1300],WIZARD_NPC_SYMBOL_FEAR)
		SpellPoint([850.1300],WIZARD_CHAOS)
		SetGlobalTimer("BPTTIME","GLOBAL",4)
		SetGlobal("BPSPHERE","GLOBAL",10)
END

IF
  Global("BPSPHERE","GLOBAL",11)
  ActionListEmpty()
THEN
  RESPONSE #100
    DisplayStringHead(Myself,39968)  // ~Spell Trigger - Fired~
    DisplayString(Myself,26243)  // ~Spell Trigger~
    ReallyForceSpell(Myself,WIZARD_ABSOLUTE_IMMUNITY)
    ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
    ReallyForceSpell(Myself,WIZARD_SPELL_IMMUNITY_INVOCATION)
    ReallyForceSpell(Myself,WIZARD_SPELL_SHIELD)
    SetGlobalTimer("BPTTIME","GLOBAL",ONE_ROUND)
    SetGlobal("BPSPHERE","GLOBAL",12)
END

IF
  Global("BPSPHERE","GLOBAL",13)
  ActionListEmpty()
THEN
  RESPONSE #100
    ReallyForceSpellPointRES("SPWI402",[1285.1135])
    Spell(Myself,WIZARD_MELF_METEOR)
    Spell(Myself,WIZARD_MISLEAD)
    SetGlobal("BPSPHERE","GLOBAL",14)
END

