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

IF
  OR(2)
    Heard([NEUTRAL],79)
    Heard([EVILCUTOFF],79)
  Allegiance(Myself,NEUTRAL)
THEN
  RESPONSE #100
    Enemy()
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("TOLGER2")  // ~Tolgerias~
  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("SUREHP1")  // <Invalid Strref -1>
    ReallyForceSpell(Myself,CLERIC_HEAL)
    SetGlobal("BPSPHERE","GLOBAL",15)
    SetGlobal("BP_IMoved","LOCALS",1)
    SetGlobal("BP_MageMoved","GLOBAL",1) //could fix immortality issues
    EndCutSceneMode()
END

IF
  CheckStat(Myself,1,127)
  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)
END

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

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

IF
  Global("BPSPHERE","GLOBAL",2)
  ActionListEmpty()
THEN
  RESPONSE #100
    DisplayStringHead(Myself,73139)  // ~Contingency - Fired~
    DisplayString(Myself,26328)  // ~Chain Contingency~
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
    ReallyForceSpell(Myself,WIZARD_SPELL_SHIELD)
    SetGlobalTimer("BPTTIME","GLOBAL",ONE_ROUND)
    SmallWait(5)
    DisplayString(Myself,40252)  // ~Contingency - Protection from Magical Weapons~
    DisplayString(Myself,3302)  // ~Chain Contingency - Spell Turning~
    SetGlobal("BPSPHERE","GLOBAL",3)
END

IF
  Global("BPSPHERE","GLOBAL",4)
  ActionListEmpty()
THEN
  RESPONSE #100
    SetGlobal("BPSPHERE","GLOBAL",5)
    SetGlobalTimer("BPTTIME","GLOBAL",ONE_ROUND)
    ReallyForceSpellPointRES("SPWI402",[675.1175])
END

IF
  Global("BPSPHERE","GLOBAL",5)
  GlobalTimerExpired("BPTTIME","GLOBAL")
  ActionListEmpty()
THEN
  RESPONSE #100
    ForceSpellPoint([850.1300],WIZARD_SUMMON_EFREET)
    SetGlobal("BPSPHERE","GLOBAL",6)
    Spell(Myself,WIZARD_MISLEAD)
END

IF
  Global("BPSPHERE","GLOBAL",8)
  GlobalTimerExpired("BPTTIME","GLOBAL")
  ActionListEmpty()
  OR(2)
    See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
THEN
  RESPONSE #100
	ApplySpell(Myself,WIZARD_PROTECTION_FROM_EVIL)
	ApplySpell("TOLGER2",WIZARD_PROTECTION_FROM_EVIL)
    Spell(LastSeenBy(Myself),WIZARD_SUMMON_NISHRUU)
    SetGlobal("BPSPHERE","GLOBAL",9)
    SetGlobalTimer("BPTTIME","GLOBAL",ONE_ROUND)
    SpellPoint([1100.1400],WIZARD_SUMMON_FIEND)
END

IF
  Global("BPSPHERE","GLOBAL",8)
  ActionListEmpty()
THEN
  RESPONSE #100
	ApplySpell(Myself,WIZARD_PROTECTION_FROM_EVIL)
	ApplySpell("TOLGER2",WIZARD_PROTECTION_FROM_EVIL)
    SetGlobal("BPSPHERE","GLOBAL",9)
    SetGlobalTimer("BPTTIME","GLOBAL",ONE_ROUND)
    SpellPoint([1100.1400],WIZARD_SUMMON_FIEND)
END

IF
  Global("BPSPHERE","GLOBAL",10)
  ActionListEmpty()
THEN
  RESPONSE #100
    DisplayStringHead(Myself,39968)  // ~Spell Trigger - Fired~
    SmallWait(5)
    DisplayString(Myself,26243)  // ~Spell Trigger~
    ReallyForceSpell(Myself,WIZARD_IMPROVED_MANTLE)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_THE_ELEMENTS)
    ReallyForceSpell(Myself,WIZARD_SPELL_SHIELD)
    SetGlobal("BPSPHERE","GLOBAL",11)
END

IF
  Global("BPSPHERE","GLOBAL",12)
  GlobalTimerExpired("BPTTIME","GLOBAL")
  ActionListEmpty()
THEN
  RESPONSE #100
    ReallyForceSpellPointRES("SPWI402",[675.1175])
    SetGlobal("BPSPHERE","GLOBAL",13)
    SpellPoint([920.1305],WIZARD_SUMMON_DJINNI)
    SpellPoint([960.1350],WIZARD_WYVERN_CALL)
    Spell(Myself,WIZARD_MELF_METEOR)
END

