BEGIN ~rukmage1~

IF ~Global("RukrakiaMageCome","GLOBAL",20)~
  THEN BEGIN rukdead0
  SAY @0
  IF ~~ THEN REPLY @1 DO ~SetGlobal("RukrakiaMageCome","GLOBAL",21)~ GOTO rukdead1
  IF ~~ THEN REPLY @2 DO ~SetGlobal("RukrakiaMageCome","GLOBAL",21)~ GOTO rukdead2
  IF ~~ THEN REPLY @3 DO ~SetGlobal("RukrakiaMageCome","GLOBAL",21)~ GOTO rukdead3
  IF ~~ THEN REPLY @4 DO ~SetGlobal("RukrakiaMageCome","GLOBAL",21)~ GOTO rukdead1
END

IF ~~
  THEN BEGIN rukdead1
  SAY @5 = @6 = @7 = @8 = @9 = @10
  IF ~!IsValidForPartyDialog("minsc")
      !IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      !IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("rukmage1",Enemy())
                                                  ActionOverride("rukmage1",SetName(@11))
                                                  ActionOverride("rukmage1",ChangeAIScript("RUMAGECR",OVERRIDE))~ EXIT
  IF ~IsValidForPartyDialog("minsc")~ THEN DO ~ActionOverride("MINSC",LeaveParty())
                                               ActionOverride("MINSC",EscapeArea())~ EXTERN MINSCJ milteminsc
  IF ~!IsValidForPartyDialog("minsc")
      IsValidForPartyDialog("jaheira")~ THEN DO ~ActionOverride("JAHEIRA",LeaveParty())
                                                 ActionOverride("JAHEIRA",EscapeArea())~ EXTERN JAHEIRAJ miltejaheira
  IF ~!IsValidForPartyDialog("minsc")
      !IsValidForPartyDialog("jaheira")
      IsValidForPartyDialog("mazzy")~ THEN DO ~ActionOverride("MAZZY",LeaveParty())
                                               ActionOverride("MAZZY",EscapeArea())~ EXTERN MAZZYJ miltemazzy
  IF ~!IsValidForPartyDialog("minsc")
      !IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      IsValidForPartyDialog("anomen")~ THEN DO ~ActionOverride("ANOMEN",LeaveParty())
                                                ActionOverride("ANOMEN",Enemy())~ EXTERN ANOMENJ milteanomen
  IF ~!IsValidForPartyDialog("minsc")
      !IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      IsValidForPartyDialog("keldorn")~ THEN DO ~ActionOverride("KELDORN",LeaveParty())
                                                 ActionOverride("KELDORN",Enemy())~ EXTERN KELDORJ miltekeldorn
  IF ~!IsValidForPartyDialog("minsc")
      !IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      IsValidForPartyDialog("aerie")~ THEN DO ~ActionOverride("AERIE",LeaveParty())
                                               ActionOverride("AERIE",EscapeArea())~ EXTERN AERIEJ milteaerie
  IF ~!IsValidForPartyDialog("minsc")
      !IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      IsValidForPartyDialog("nalia")~ THEN DO ~ActionOverride("NALIA",LeaveParty())
                                               ActionOverride("NALIA",EscapeArea())~ EXTERN NALIAJ miltenalia
  IF ~!IsValidForPartyDialog("minsc")
      !IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      IsValidForPartyDialog("cernd")~ THEN DO ~ActionOverride("CERND",LeaveParty())
                                               ActionOverride("CERND",EscapeArea())~ EXTERN CERNDJ miltecernd
  IF ~!IsValidForPartyDialog("minsc")
      !IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("VALYGAR",LeaveParty())
                                                 ActionOverride("VALYGAR",EscapeArea())~ EXTERN VALYGARJ miltevalygar
END

IF ~~
  THEN BEGIN rukdead2
  SAY @5 = @6 = @7 = @8 = @12 = @13 = @14
  IF ~~ THEN DO ~StartCutSceneMode()
                 ForceSpellRES("ruksnw2",Myself)
                 Wait(3)
                 SetGlobal("RukrakiaMageCome","GLOBAL",20)
                 EndCutSceneMode()
                 DestroySelf()~ EXIT
END

IF ~~
  THEN BEGIN rukdead3
  SAY @5 = @6 = @7 = @8 = @15 = @16 = @13 = @14
  IF ~~ THEN DO ~StartCutSceneMode()
                 ForceSpellRES("ruksnw2",Myself)
                 Wait(3)
                 SetGlobal("RukrakiaMageCome","GLOBAL",20)
                 EndCutSceneMode()
                 DestroySelf()~ EXIT
END

APPEND MINSCJ
IF ~~
  THEN BEGIN milteminsc
  SAY @17
  IF ~!IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      !IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("rukmage1",Enemy())
                                                  ActionOverride("rukmage1",SetName(@11))
                                                  ActionOverride("rukmage1",ChangeAIScript("RUMAGECR",OVERRIDE))~ EXIT
  IF ~IsValidForPartyDialog("jaheira")~ THEN DO ~ActionOverride("JAHEIRA",LeaveParty())
                                                 ActionOverride("JAHEIRA",EscapeArea())~ EXTERN JAHEIRAJ miltejaheira
  IF ~!IsValidForPartyDialog("jaheira")
      IsValidForPartyDialog("mazzy")~ THEN DO ~ActionOverride("MAZZY",LeaveParty())
                                               ActionOverride("MAZZY",EscapeArea())~ EXTERN MAZZYJ miltemazzy
  IF ~!IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      IsValidForPartyDialog("anomen")~ THEN DO ~ActionOverride("ANOMEN",LeaveParty())
                                                ActionOverride("ANOMEN",Enemy())~ EXTERN ANOMENJ milteanomen
  IF ~!IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      IsValidForPartyDialog("keldorn")~ THEN DO ~ActionOverride("KELDORN",LeaveParty())
                                                 ActionOverride("KELDORN",Enemy())~ EXTERN KELDORJ miltekeldorn
  IF ~!IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      IsValidForPartyDialog("aerie")~ THEN DO ~ActionOverride("AERIE",LeaveParty())
                                               ActionOverride("AERIE",EscapeArea())~ EXTERN AERIEJ milteaerie
  IF ~!IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      IsValidForPartyDialog("nalia")~ THEN DO ~ActionOverride("NALIA",LeaveParty())
                                               ActionOverride("NALIA",EscapeArea())~ EXTERN NALIAJ miltenalia
  IF ~!IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      IsValidForPartyDialog("cernd")~ THEN DO ~ActionOverride("CERND",LeaveParty())
                                               ActionOverride("CERND",EscapeArea())~ EXTERN CERNDJ miltecernd
  IF ~!IsValidForPartyDialog("jaheira")
      !IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("VALYGAR",LeaveParty())
                                                 ActionOverride("VALYGAR",EscapeArea())~ EXTERN VALYGARJ miltevalygar
END
END

APPEND JAHEIRAJ
IF ~~
  THEN BEGIN miltejaheira
  SAY @18
  IF ~!IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      !IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("rukmage1",Enemy())
                                                  ActionOverride("rukmage1",SetName(@11))
                                                  ActionOverride("rukmage1",ChangeAIScript("RUMAGECR",OVERRIDE))~ EXIT
  IF ~IsValidForPartyDialog("mazzy")~ THEN DO ~ActionOverride("MAZZY",LeaveParty())
                                               ActionOverride("MAZZY",EscapeArea())~ EXTERN MAZZYJ miltemazzy
  IF ~!IsValidForPartyDialog("mazzy")
      IsValidForPartyDialog("anomen")~ THEN DO ~ActionOverride("ANOMEN",LeaveParty())
                                                ActionOverride("ANOMEN",Enemy())~ EXTERN ANOMENJ milteanomen
  IF ~!IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      IsValidForPartyDialog("keldorn")~ THEN DO ~ActionOverride("KELDORN",LeaveParty())
                                                 ActionOverride("KELDORN",Enemy())~ EXTERN KELDORJ miltekeldorn
  IF ~!IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      IsValidForPartyDialog("aerie")~ THEN DO ~ActionOverride("AERIE",LeaveParty())
                                               ActionOverride("AERIE",EscapeArea())~ EXTERN AERIEJ milteaerie
  IF ~!IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      IsValidForPartyDialog("nalia")~ THEN DO ~ActionOverride("NALIA",LeaveParty())
                                               ActionOverride("NALIA",EscapeArea())~ EXTERN NALIAJ miltenalia
  IF ~!IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      IsValidForPartyDialog("cernd")~ THEN DO ~ActionOverride("CERND",LeaveParty())
                                               ActionOverride("CERND",EscapeArea())~ EXTERN CERNDJ miltecernd
  IF ~!IsValidForPartyDialog("mazzy")
      !IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("VALYGAR",LeaveParty())
                                                 ActionOverride("VALYGAR",EscapeArea())~ EXTERN VALYGARJ miltevalygar
END
END

APPEND MAZZYJ
IF ~~
  THEN BEGIN miltemazzy
  SAY @19
  IF ~!IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      !IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("rukmage1",Enemy())
                                                  ActionOverride("rukmage1",SetName(@11))
                                                  ActionOverride("rukmage1",ChangeAIScript("RUMAGECR",OVERRIDE))~ EXIT
  IF ~IsValidForPartyDialog("anomen")~ THEN DO ~ActionOverride("ANOMEN",LeaveParty())
                                                ActionOverride("ANOMEN",Enemy())~ EXTERN ANOMENJ milteanomen
  IF ~!IsValidForPartyDialog("anomen")
      IsValidForPartyDialog("keldorn")~ THEN DO ~ActionOverride("KELDORN",LeaveParty())
                                                 ActionOverride("KELDORN",Enemy())~ EXTERN KELDORJ miltekeldorn
  IF ~!IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      IsValidForPartyDialog("aerie")~ THEN DO ~ActionOverride("AERIE",LeaveParty())
                                               ActionOverride("AERIE",EscapeArea())~ EXTERN AERIEJ milteaerie
  IF ~!IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      IsValidForPartyDialog("nalia")~ THEN DO ~ActionOverride("NALIA",LeaveParty())
                                               ActionOverride("NALIA",EscapeArea())~ EXTERN NALIAJ miltenalia
  IF ~!IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      IsValidForPartyDialog("cernd")~ THEN DO ~ActionOverride("CERND",LeaveParty())
                                               ActionOverride("CERND",EscapeArea())~ EXTERN CERNDJ miltecernd
  IF ~!IsValidForPartyDialog("anomen")
      !IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("VALYGAR",LeaveParty())
                                                 ActionOverride("VALYGAR",EscapeArea())~ EXTERN VALYGARJ miltevalygar
END
END

APPEND ANOMENJ
IF ~~
  THEN BEGIN milteanomen
  SAY @20
  IF ~!IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      !IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("rukmage1",Enemy())
                                                  ActionOverride("rukmage1",SetName(@11))
                                                  ActionOverride("rukmage1",ChangeAIScript("RUMAGECR",OVERRIDE))~ EXIT
  IF ~IsValidForPartyDialog("keldorn")~ THEN DO ~ActionOverride("KELDORN",LeaveParty())
                                                 ActionOverride("KELDORN",Enemy())~ EXTERN KELDORJ miltekeldorn
  IF ~!IsValidForPartyDialog("keldorn")
      IsValidForPartyDialog("aerie")~ THEN DO ~ActionOverride("AERIE",LeaveParty())
                                               ActionOverride("AERIE",EscapeArea())~ EXTERN AERIEJ milteaerie
  IF ~!IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      IsValidForPartyDialog("nalia")~ THEN DO ~ActionOverride("NALIA",LeaveParty())
                                               ActionOverride("NALIA",EscapeArea())~ EXTERN NALIAJ miltenalia
  IF ~!IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      IsValidForPartyDialog("cernd")~ THEN DO ~ActionOverride("CERND",LeaveParty())
                                               ActionOverride("CERND",EscapeArea())~ EXTERN CERNDJ miltecernd
  IF ~!IsValidForPartyDialog("keldorn")
      !IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("VALYGAR",LeaveParty())
                                                 ActionOverride("VALYGAR",EscapeArea())~ EXTERN VALYGARJ miltevalygar
END
END

APPEND KELDORJ
IF ~~
  THEN BEGIN miltekeldorn
  SAY @21
  IF ~!IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      !IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("rukmage1",Enemy())
                                                  ActionOverride("rukmage1",SetName(@11))
                                                  ActionOverride("rukmage1",ChangeAIScript("RUMAGECR",OVERRIDE))~ EXIT
  IF ~IsValidForPartyDialog("aerie")~ THEN DO ~ActionOverride("AERIE",LeaveParty())
                                               ActionOverride("AERIE",EscapeArea())~ EXTERN AERIEJ milteaerie
  IF ~!IsValidForPartyDialog("aerie")
      IsValidForPartyDialog("nalia")~ THEN DO ~ActionOverride("NALIA",LeaveParty())
                                               ActionOverride("NALIA",EscapeArea())~ EXTERN NALIAJ miltenalia
  IF ~!IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      IsValidForPartyDialog("cernd")~ THEN DO ~ActionOverride("CERND",LeaveParty())
                                               ActionOverride("CERND",EscapeArea())~ EXTERN CERNDJ miltecernd
  IF ~!IsValidForPartyDialog("aerie")
      !IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("VALYGAR",LeaveParty())
                                                 ActionOverride("VALYGAR",EscapeArea())~ EXTERN VALYGARJ miltevalygar
END
END

APPEND AERIEJ
IF ~~
  THEN BEGIN milteaerie
  SAY @22
  IF ~!IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      !IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("rukmage1",Enemy())
                                                  ActionOverride("rukmage1",SetName(@11))
                                                  ActionOverride("rukmage1",ChangeAIScript("RUMAGECR",OVERRIDE))~ EXIT
  IF ~IsValidForPartyDialog("nalia")~ THEN DO ~ActionOverride("NALIA",LeaveParty())
                                               ActionOverride("NALIA",EscapeArea())~ EXTERN NALIAJ miltenalia
  IF ~!IsValidForPartyDialog("nalia")
      IsValidForPartyDialog("cernd")~ THEN DO ~ActionOverride("CERND",LeaveParty())
                                               ActionOverride("CERND",EscapeArea())~ EXTERN CERNDJ miltecernd
  IF ~!IsValidForPartyDialog("nalia")
      !IsValidForPartyDialog("cernd")
      IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("VALYGAR",LeaveParty())
                                                 ActionOverride("VALYGAR",EscapeArea())~ EXTERN VALYGARJ miltevalygar
END
END

APPEND NALIAJ
IF ~~
  THEN BEGIN miltenalia
  SAY @23
  IF ~!IsValidForPartyDialog("cernd")
      !IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("rukmage1",Enemy())
                                                  ActionOverride("rukmage1",SetName(@11))
                                                  ActionOverride("rukmage1",ChangeAIScript("RUMAGECR",OVERRIDE))~ EXIT
  IF ~IsValidForPartyDialog("cernd")~ THEN DO ~ActionOverride("CERND",LeaveParty())
                                               ActionOverride("CERND",EscapeArea())~ EXTERN CERNDJ miltecernd
  IF ~!IsValidForPartyDialog("cernd")
      IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("VALYGAR",LeaveParty())
                                                 ActionOverride("VALYGAR",EscapeArea())~ EXTERN VALYGARJ miltevalygar
END
END

APPEND CERNDJ
IF ~~
  THEN BEGIN miltecernd
  SAY @24
  IF ~!IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("rukmage1",Enemy())
                                                  ActionOverride("rukmage1",SetName(@11))
                                                  ActionOverride("rukmage1",ChangeAIScript("RUMAGECR",OVERRIDE))~ EXIT
  IF ~IsValidForPartyDialog("valygar")~ THEN DO ~ActionOverride("VALYGAR",LeaveParty())
                                                 ActionOverride("VALYGAR",EscapeArea())~ EXTERN VALYGARJ miltevalygar
END
END

APPEND VALYGARJ
IF ~~
  THEN BEGIN miltevalygar
  SAY @25
  IF ~~ THEN DO ~ActionOverride("rukmage1",Enemy())
                 ActionOverride("rukmage1",SetName(@11))
                 ActionOverride("rukmage1",ChangeAIScript("RUMAGECR",OVERRIDE))~ EXIT
END
END