unit ObjMon2;

interface
uses
  Windows, Classes, Grobal2, ObjBase, ObjActor, ObjMon;
type
  TStickMonster = class(TAnimalObject)
    bo550: Boolean;
    n554: Integer;
    n558: Integer;
  private

  public
    constructor Create(); override;
    destructor Destroy; override;
    function AttackTarget(): Boolean; virtual;
    procedure sub_FFEA; virtual;
    procedure sub_FFE9; virtual;
    procedure VisbleActors; virtual; //FFE8
    function Operate(ProcessMsg: pTProcessMessage): Boolean; override; //FFFC
    procedure Run; override;
  end;
  TBeeQueen = class(TAnimalObject)
    BBList: TList;
  private
    procedure MakeChildBee;
  public
    constructor Create(); override;
    destructor Destroy; override;
    function Operate(ProcessMsg: pTProcessMessage): Boolean; override; //FFFC
    procedure Run; override;
  end;
  TCustomMonster3 = class(TATMonster)
    dw558: LongWord;
    bo55C: Boolean;
    bo55D: Boolean;
    n560: Integer;
    dw564: LongWord;
    dw568: LongWord;
    dw56C: LongWord;
    dw570: LongWord;
  private

  public
    constructor Create(); override;
    destructor Destroy; override;
    procedure Run; override;
    procedure Attack(TargeTActorObject: TActorObject; nDir: Integer); override;
    procedure Initialize(); override;
  end;
  TCrystalSpider = class (TElectronicScolpionMon)
  private
   m_boUseMagic:Boolean;
  public
    function AttackTarget():Boolean; override;//FFEB
    constructor Create();override;
    destructor Destroy; override;
  end;
  TDDevil  = class(TMonster)
  m_dwSpellTick  :LongWord;
  private
    m_boUseMagic:Boolean;

    procedure LightingAttack(nDir:Integer);

  public
    constructor Create();override;
    destructor Destroy; override;
    procedure Run;override;
  end;
  TCentipedeKingMonster = class(TStickMonster)
    m_dwAttickTick: LongWord; //0x560
  private
    function sub_4A5B0C: Boolean;
  public
    constructor Create(); override;
    destructor Destroy; override;
    function AttackTarget(): Boolean; override;
    procedure sub_FFE9; override;
    procedure Run; override;
  end;
  TOmaLord = class(TMonster)
    m_nDangerLevel: Integer;
    m_SlaveObjectList: TList; //0x55C
  private
    procedure CallSlave;
  public
    constructor Create(); override;
    destructor Destroy; override;
    procedure Attack(TargeTActorObject: TActorObject; nDir: Integer); override; //0FFED
    procedure Run; override;
  end;
  TMinoGuard2 = class(TMonster)
  private
   procedure MagicAttack(nDir:Integer);
    procedure MagicAttack2(nDir:Integer);
  public
    constructor Create();override;
    destructor Destroy; override;
    procedure Run; override;
  end;
  TCustomMonster4 = class(TMonster)
  m_dwDragTick  :LongWord;
   private
   procedure Drag();
   public
    constructor Create();override;
    destructor Destroy; override;
    procedure Run; override;
function AttackTarget():boolean;override;
  end;
  TCustomMonster2 = class(TMonster)
  m_dwDragTick  :LongWord;
   private
   procedure Drag();
   public
    constructor Create();override;
    destructor Destroy; override;
    procedure Run; override;
function AttackTarget():boolean;override;
  end;
  TCustomMonster = class(TMonster)
   private
    procedure RepulseCircle();
   public
    constructor Create();override;
    destructor Destroy; override;
    procedure Run; override;
    function AttackTarget():Boolean;virtual;
  end;
  TBigHeartMonster = class(TAnimalObject)
  private

  public
    constructor Create(); override;
    destructor Destroy; override;

    function AttackTarget(): Boolean; virtual;
    procedure Run; override;
  end;

    THellGuard = class(TAnimalObject)
  private
    procedure RepulseCircle();
  public
    constructor Create();override;
    destructor Destroy; override;

    function AttackTarget():Boolean;virtual;
    procedure Run;override;
  end;

  TSpiderHouseMonster = class(TAnimalObject)
    BBList: TList;
  private
    procedure GenBB;
  public
    constructor Create(); override;
    destructor Destroy; override;
    function Operate(ProcessMsg: pTProcessMessage): Boolean; override; //FFFC
    procedure Run; override;
  end;
  TExplosionSpider = class(TMonster)
    dw558: LongWord;
  private
    procedure sub_4A65C4;

  public
    constructor Create(); override;
    destructor Destroy; override;
    procedure Run; override;
    function AttackTarget(): Boolean; override; //FFEB
  end;
  TWhiteFox = class(TMonster)
    m_dwSpellTick : LongWord;
  private
    procedure MagicAttack(nDir:Integer);
  public
    constructor Create();override;
    destructor Destroy; override;
    function AttackTarget():Boolean;virtual;
    procedure Run;override;
  end;
  TWhiteFox2 = class(TMonster)
    ldistx:Integer;
    ldisty:Integer;
    m_dwSpellTick : LongWord;
  private
    procedure MagicAttack(Target:TBaseObject);
    function MagicAttack2():Boolean;
  public
    constructor Create();override;
    destructor Destroy; override;
    function AttackTarget():Boolean;virtual;
    procedure Run;override;
  end;
  TGuardUnit = class(TAnimalObject)
    dw54C: LongWord; //0x54C
    m_nX550: Integer; //0x550
    m_nY554: Integer; //0x554
    m_nDirection: Integer; //0x558
  public
    function IsProperTarget(ActorObject: TActorObject): Boolean; override; //FFF4
    procedure Struck(hiter: TActorObject); override; //FFEC
  end;
  TArcherGuard = class(TGuardUnit)
  private
    procedure sub_4A6B30(TargeTActorObject: TActorObject);

  public
    constructor Create(); override;
    destructor Destroy; override;
    procedure Run; override;
  end;
  TArcherPolice = class(TArcherGuard)
  private
  public
    constructor Create(); override;
    destructor Destroy; override;
  end;
  TCastleDoor = class(TGuardUnit)
    dw55C: LongWord; //0x55C
    dw560: LongWord; //0x560
    m_boOpened: Boolean; //0x564
    bo565n: Boolean; //0x565
    bo566n: Boolean; //0x566
    bo567n: Boolean; //0x567
  private
    procedure SetMapXYFlag(nFlag: Integer);
  public
    constructor Create(); override;
    destructor Destroy; override;
    procedure Die; override;
    procedure Run; override;
    procedure Initialize(); override;
    procedure Close;
    procedure Open;
    procedure RefStatus;
  end;
  TWallStructure = class(TGuardUnit)
    n55C: Integer;
    dw560: LongWord;
    boSetMapFlaged: Boolean;
  private
  public
    constructor Create(); override;
    destructor Destroy; override;
    procedure Initialize; override;
    procedure Die; override;
    procedure Run; override;
    procedure RefStatus;
  end;
  TSoccerBall = class(TAnimalObject)
    n548: Integer;
    n550: Integer;
  private

  public
    constructor Create(); override;
    destructor Destroy; override;
    procedure Struck(hiter: TActorObject); virtual; //FFEC
    procedure Run; override;
  end;

  TEvilMir = class(TAnimalObject)
    m_dwSpellTick :LongWord;
    boSlaves :Boolean;
  private
      procedure FlameCircle(nDir: Integer);
      procedure MassThunder();
  public
    constructor Create();override;
    destructor Destroy; override;
    function  Operate(ProcessMsg:pTProcessMessage):Boolean; override;
    procedure Run;override;
    procedure Die; override;
  end;

  TDragonStatue = class(TAnimalObject)
  private
    procedure FireBang();
  public
    constructor Create();override;
    destructor Destroy; override;
	  procedure Run; override;
  end;

 TRedThunderZuma = class(TScultureMonster)
    m_dwSpellTick : LongWord;
   private
    procedure MagicAttack();
   public
    constructor Create();override;
    destructor Destroy; override;
    procedure Run;override;
  end;

   TKhazard = class(TMonster)
    m_dwDragTick  :LongWord;
  private
    procedure Drag();
  public
  function AttackTarget():boolean;override;
    constructor Create();override;
    destructor Destroy; override;
    procedure Run; override;
  end;

  TFoxOrbSpirit = class(TAnimalObject)
    m_dwSpellTick  :LongWord;
    boSlaves:Boolean;
  private
      procedure FlameCircle(nDir: Integer);
      procedure FlameCircle2();
  public
    constructor Create();override;
    destructor Destroy; override;
    procedure Run;override;
  end;

  TFrostTiger = class(TMonster)
    m_dwSpellTick:LongWord;
    m_dwLastWalkTick:LongWord;
  private
    procedure FrostAttack();
  public
    constructor Create();override;
    destructor Destroy; override;
    procedure Run; override;
  end;

  TRedPoisonMob = class(TMonster)
  private
  public
    function AttackTarget():boolean;override;
    constructor Create();override;
    destructor Destroy; override;
    procedure Run; override;
  end;

implementation

uses M2Share, HUtil32, Castle, Guild;


{ TStickMonster }

constructor TStickMonster.Create; //004A51C0
begin
  inherited;
  bo550 := False;
  m_nViewRange := 7;
  m_nRunTime := 250;
  m_dwSearchTime := Random(1500) + 2500;
  m_dwSearchTick := GetTickCount();
  m_btRaceServer := 85;
  n554 := 4;
  n558 := 4;
  m_boFixedHideMode := True;
  m_boStickMode := True;
  m_boAnimal := True;
end;

destructor TStickMonster.Destroy; //004A5290
begin

  inherited;
end;

function TStickMonster.AttackTarget: Boolean;
var
  btDir: Byte;
begin
  Result := False;
  if m_TargetCret = nil then Exit;
  if GetAttackDir(m_TargetCret, btDir) then begin
    if Integer(GetTickCount - m_dwHitTick) > m_nNextHitTime then begin
      m_dwHitTick := GetTickCount();
      m_dwTargetFocusTick := GetTickCount();
      Attack(m_TargetCret, btDir);
    end;
    Result := True;
    Exit;
  end;
  if m_TargetCret.m_PEnvir = m_PEnvir then begin
    SetTargetXY(m_TargetCret.m_nCurrX, m_TargetCret.m_nCurrY); {0FFF0h}
  end else begin
    DelTargetCreat(); {0FFF1h}
  end;
end;

procedure TStickMonster.sub_FFE9();
begin
  m_boFixedHideMode := False;
  SendRefMsg(RM_DIGUP, m_btDirection, m_nCurrX, m_nCurrY, 0, '');
end;

procedure TStickMonster.VisbleActors(); //004A53E4
var
  I: Integer;
resourcestring
  sExceptionMsg = '[Exception] TStickMonster::VisbleActors Dispose';
begin
  SendRefMsg(RM_DIGDOWN, m_btDirection, m_nCurrX, m_nCurrY, 0, '');
  for I := 0 to m_VisibleActors.Count - 1 do begin
    try
      Dispose(pTVisibleBaseObject(m_VisibleActors.Items[I]));
    except
      MainOutMessage(sExceptionMsg);
    end;
  end;
  m_VisibleActors.Clear;
  m_boFixedHideMode := True;
end;

procedure TStickMonster.sub_FFEA();
var
  I: Integer;
  ActorObject: TActorObject;
begin
  for I := 0 to m_VisibleActors.Count - 1 do begin
    ActorObject := TActorObject(pTVisibleBaseObject(m_VisibleActors.Items[I]).BaseObject);
    if ActorObject.m_boDeath then Continue;
    if IsProperTarget(ActorObject) then begin
      if not ActorObject.m_boHideMode or m_boCoolEye then begin
        if (abs(m_nCurrX - ActorObject.m_nCurrX) < n554) and (abs(m_nCurrY - ActorObject.m_nCurrY) < n554) then begin
          sub_FFE9();
          Break;
        end;
      end;
    end;
  end; // for
end;

function TStickMonster.Operate(ProcessMsg: pTProcessMessage): Boolean;
begin
  Result := inherited Operate(ProcessMsg);
end;

procedure TStickMonster.Run; //004A5614
var
  bo05: Boolean;
begin
  if not m_boGhost and
    not m_boDeath and
    (m_wStatusTimeArr[POISON_STONE {5 0x6A}] = 0) then begin
    if Integer(GetTickCount - m_dwWalkTick) > m_nWalkSpeed then begin
      m_dwWalkTick := GetTickCount();
      if m_boFixedHideMode then begin
        sub_FFEA();
      end else begin
        if Integer(GetTickCount - m_dwHitTick) > m_nNextHitTime then begin
          SearchTarget();
        end;
        bo05 := False;
        if m_TargetCret <> nil then begin
          if (abs(m_TargetCret.m_nCurrX - m_nCurrX) > n558) or
            (abs(m_TargetCret.m_nCurrY - m_nCurrY) > n558) then begin
            bo05 := True;
          end;
        end else bo05 := True;
        if bo05 then begin
          VisbleActors();
        end else begin
          if AttackTarget then begin
            inherited;
            Exit;
          end;
        end;
      end;
    end;
  end;
  inherited;
end;



{ TSoccerBall }

constructor TSoccerBall.Create; //004A764C
begin
  inherited;
  m_boAnimal := False;
  m_boSuperMan := True;
  n550 := 0;
  m_nTargetX := -1;
end;

destructor TSoccerBall.Destroy;
begin

  inherited;
end;



procedure TSoccerBall.Run;
var
  n08, n0C: Integer;
  bo0D: Boolean;
begin
  if n550 > 0 then begin
    if m_PEnvir.GetNextPosition(m_nCurrX, m_nCurrY, m_btDirection, 1, n08, n0C) then begin
      if m_PEnvir.CanWalk(n08, n0C, bo0D) then begin
        case m_btDirection of //
          0: m_btDirection := 4;
          1: m_btDirection := 7;
          2: m_btDirection := 6;
          3: m_btDirection := 5;
          4: m_btDirection := 0;
          5: m_btDirection := 3;
          6: m_btDirection := 2;
          7: m_btDirection := 1;
        end; // case
        m_PEnvir.GetNextPosition(m_nCurrX, m_nCurrY, m_btDirection, n550, m_nTargetX, m_nTargetY)
      end;
    end;
  end else begin //004A78A1
    m_nTargetX := -1;
  end;
  if m_nTargetX <> -1 then begin
    GotoTargetXY();
    if (m_nTargetX = m_nCurrX) and (m_nTargetY = m_nCurrY) then
      n550 := 0;
  end;

  inherited;

end;

procedure TSoccerBall.Struck(hiter: TActorObject);
begin
  if hiter = nil then Exit;
  m_btDirection := hiter.m_btDirection;
  n550 := Random(4) + (n550 + 4);
  n550 := _MIN(20, n550);
  m_PEnvir.GetNextPosition(m_nCurrX, m_nCurrY, m_btDirection, n550, m_nTargetX, m_nTargetY);
end;

{ TBeeQueen }

constructor TBeeQueen.Create; //004A5750
begin
  inherited;
  m_nViewRange := 9;
  m_nRunTime := 250;
  m_dwSearchTime := Random(1500) + 2500;
  m_dwSearchTick := GetTickCount();
  m_boStickMode := True;
  BBList := TList.Create;
end;

destructor TBeeQueen.Destroy; //004A57F0
begin
  BBList.Free;
  inherited;
end;

procedure TBeeQueen.MakeChildBee;
begin
  if BBList.Count >= 15 then Exit;
  SendRefMsg(RM_HIT, m_btDirection, m_nCurrX, m_nCurrY, 0, '');
  SendDelayMsg(Self, RM_ZEN_BEE, 0, 0, 0, 0, '', 500);
end;

function TBeeQueen.Operate(ProcessMsg: pTProcessMessage): Boolean;
var
  BB: TActorObject;
begin
  if ProcessMsg.wIdent = RM_ZEN_BEE then begin
    BB := UserEngine.RegenMonsterByName(nil, m_PEnvir.sMapName, m_nCurrX, m_nCurrY, g_Config.sBee);
    if BB <> nil then begin
      BB.SetTargetCreat(m_TargetCret);
      BBList.Add(BB);
    end;
  end;
  Result := inherited Operate(ProcessMsg);
end;

procedure TBeeQueen.Run;
var
  I: Integer;
  BB: TActorObject;
begin
  if not m_boGhost and
    not m_boDeath and
    (m_wStatusTimeArr[POISON_STONE {5 0x6A}] = 0) then begin
    if Integer(GetTickCount - m_dwWalkTick) >= m_nWalkSpeed then begin
      m_dwWalkTick := GetTickCount();
      if Integer(GetTickCount - m_dwHitTick) >= m_nNextHitTime then begin
        m_dwHitTick := GetTickCount();
        SearchTarget();
        if m_TargetCret <> nil then MakeChildBee();
      end;
      for I := BBList.Count - 1 downto 0 do begin
        BB := TActorObject(BBList.Items[I]);
        if (BB <> nil) and (BB.m_boDeath) or (BB.m_boGhost) then BBList.Delete(I);
      end;
    end;
  end;
  inherited;
end;

{ TCentipedeKingMonster }



constructor TCentipedeKingMonster.Create; //004A5A8C
begin
  inherited;
  m_nViewRange := 6;
  n554 := 4;
  n558 := 6;
  m_boAnimal := False;
  m_dwAttickTick := GetTickCount();
end;

destructor TCentipedeKingMonster.Destroy;
begin

  inherited;
end;

function TCentipedeKingMonster.sub_4A5B0C: Boolean;
var
  I: Integer;
  ActorObject: TActorObject;
begin
  Result := False;
  for I := 0 to m_VisibleActors.Count - 1 do begin
    ActorObject := TActorObject(pTVisibleBaseObject(m_VisibleActors.Items[I]).BaseObject);
    if ActorObject.m_boDeath then Continue;
    if IsProperTarget(ActorObject) then begin
      if (abs(m_nCurrX - ActorObject.m_nCurrX) <= m_nViewRange) and (abs(m_nCurrY - ActorObject.m_nCurrY) <= m_nViewRange) then begin
        Result := True;
        Break;
      end;
    end;
  end;
end;

function TCentipedeKingMonster.AttackTarget: Boolean;
var
  WAbil: pTAbility;
  nPower, I: Integer;
  ActorObject: TActorObject;
begin
  Result := False;
  if not sub_4A5B0C then begin
    Exit;
  end;
  if Integer(GetTickCount - m_dwHitTick) > m_nNextHitTime then begin
    m_dwHitTick := GetTickCount();
    SendAttackMsg(RM_HIT, m_btDirection, m_nCurrX, m_nCurrY);
    WAbil := @m_WAbil;
    nPower := (Random(Integer(HiWord(WAbil.DC) - LoWord(WAbil.DC)) + 1) + LoWord(WAbil.DC));
    for I := 0 to m_VisibleActors.Count - 1 do begin
      ActorObject := TActorObject(pTVisibleBaseObject(m_VisibleActors.Items[I]).BaseObject);
      if ActorObject.m_boDeath then Continue;
      if IsProperTarget(ActorObject) then begin
        if (abs(m_nCurrX - ActorObject.m_nCurrX) < m_nViewRange) and (abs(m_nCurrY - ActorObject.m_nCurrY) < m_nViewRange) then begin
          m_dwTargetFocusTick := GetTickCount();
          SendDelayMsg(Self, RM_DELAYMAGIC, nPower, MakeLong(ActorObject.m_nCurrX, ActorObject.m_nCurrY), MakeLong(2, 0), Integer(ActorObject), '', 600);
          if Random(4) = 0 then begin
            if Random(3) <> 0 then begin
              ActorObject.MakePosion(POISON_DECHEALTH, 60, 3);
            end else begin
              ActorObject.MakePosion(POISON_STONE, 5, 0);
            end;
            m_TargetCret := ActorObject;
          end;
        end;
      end;
    end; // for
  end;
  Result := True;
end;

procedure TCentipedeKingMonster.sub_FFE9;
begin
  inherited;
  m_WAbil.HP := m_WAbil.MaxHP;
end;

procedure TCentipedeKingMonster.Run;
var
  I: Integer;
  ActorObject: TActorObject;
begin
  if not m_boGhost and
    not m_boDeath and
    (m_wStatusTimeArr[POISON_STONE {5 0x6A}] = 0) then begin
    if Integer(GetTickCount - m_dwWalkTick) > m_nWalkSpeed then begin
      m_dwWalkTick := GetTickCount();
      if m_boFixedHideMode then begin
        if (GetTickCount - m_dwAttickTick) > 10000 then begin
          for I := 0 to m_VisibleActors.Count - 1 do begin
            ActorObject := TActorObject(pTVisibleBaseObject(m_VisibleActors.Items[I]).BaseObject);
            if ActorObject.m_boDeath then Continue;
            if IsProperTarget(ActorObject) then begin
              if not ActorObject.m_boHideMode or m_boCoolEye then begin
                if (abs(m_nCurrX - ActorObject.m_nCurrX) < n554) and (abs(m_nCurrY - ActorObject.m_nCurrY) < n554) then begin
                  sub_FFE9();
                  m_dwAttickTick := GetTickCount();
                  Break;
                end;
              end;
            end;
          end;
        end; //004A5F86
      end else begin
        if (GetTickCount - m_dwAttickTick) > 3000 then begin
          if AttackTarget() then begin
            inherited;
            Exit;
          end;
          if (GetTickCount - m_dwAttickTick) > 10000 then begin
            VisbleActors();
            m_dwAttickTick := GetTickCount();
          end;
        end;
      end;
    end;
  end;
  inherited;
end;


{ TBigHeartMonster }


constructor TBigHeartMonster.Create;
begin
  inherited;
  m_nViewRange := 16;
  m_boAnimal := False;
end;

destructor TBigHeartMonster.Destroy;
begin

  inherited;
end;

function TBigHeartMonster.AttackTarget(): Boolean;
var
  I: Integer;
  ActorObject: TActorObject;
  nPower: Integer;
  WAbil: pTAbility;
begin
  Result := False;
  if Integer(GetTickCount - m_dwHitTick) > m_nNextHitTime then begin
    m_dwHitTick := GetTickCount();
    SendRefMsg(RM_HIT, m_btDirection, m_nCurrX, m_nCurrY, 0, '');
    WAbil := @m_WAbil;
    nPower := (Random(Integer(HiWord(WAbil.DC) - LoWord(WAbil.DC)) + 1) + LoWord(WAbil.DC));
    for I := 0 to m_VisibleActors.Count - 1 do begin
      ActorObject := TActorObject(pTVisibleBaseObject(m_VisibleActors.Items[I]).BaseObject);
      if ActorObject.m_boDeath then Continue;
      if IsProperTarget(ActorObject) then begin
        if (abs(m_nCurrX - ActorObject.m_nCurrX) <= m_nViewRange) and (abs(m_nCurrY - ActorObject.m_nCurrY) <= m_nViewRange) then begin
          SendDelayMsg(Self, RM_DELAYMAGIC, nPower, MakeLong(ActorObject.m_nCurrX, ActorObject.m_nCurrY), MakeLong(2, 0), Integer(ActorObject), '', 200);
          SendRefMsg(RM_10205, 0, ActorObject.m_nCurrX, ActorObject.m_nCurrY, 1 {type}, '');
        end;
      end;
    end; // for
    Result := True;
  end;
  //  inherited;
end;

procedure TBigHeartMonster.Run; //004A617C
begin
  if not m_boGhost and
    not m_boDeath and
    (m_wStatusTimeArr[POISON_STONE {5 0x6A}] = 0) then begin
    if m_VisibleActors.Count > 0 then
      AttackTarget();
  end;
  inherited;
end;

{ TSpiderHouseMonster }

constructor TSpiderHouseMonster.Create; //004A61D0
begin
  inherited;
  m_nViewRange := 9;
  m_nRunTime := 250;
  m_dwSearchTime := Random(1500) + 2500;
  m_dwSearchTick := 0;
  m_boStickMode := True;
  BBList := TList.Create;
end;

destructor TSpiderHouseMonster.Destroy;
begin
  BBList.Free;
  inherited;
end;

procedure TSpiderHouseMonster.GenBB;
begin
  if BBList.Count < 15 then begin
    SendRefMsg(RM_HIT, m_btDirection, m_nCurrX, m_nCurrY, 0, '');
    SendDelayMsg(Self, RM_ZEN_BEE, 0, 0, 0, 0, '', 500);
  end;
end;

function TSpiderHouseMonster.Operate(ProcessMsg: pTProcessMessage): Boolean;
var
  BB: TActorObject;
  n08, n0C: Integer;
begin
  if ProcessMsg.wIdent = RM_ZEN_BEE then begin
    n08 := m_nCurrX;
    n0C := m_nCurrY + 1;
    if m_PEnvir.CanWalk(n08, n0C, True) and m_PEnvir.CanWalkOfEvent(Self, n08, n0C) then begin
      BB := UserEngine.RegenMonsterByName(nil, m_PEnvir.sMapName, n08, n0C, g_Config.sSpider);
      if BB <> nil then begin
        BB.SetTargetCreat(m_TargetCret);
        BBList.Add(BB);
      end;
    end;
  end;
  Result := inherited Operate(ProcessMsg);
end;

procedure TSpiderHouseMonster.Run;
var
  I: Integer;
  BB: TActorObject;
begin
  if not m_boGhost and
    not m_boDeath and
    (m_wStatusTimeArr[POISON_STONE {5 0x6A}] = 0) then begin
    if Integer(GetTickCount - m_dwWalkTick) >= m_nWalkSpeed then begin
      m_dwWalkTick := GetTickCount();
      if Integer(GetTickCount - m_dwHitTick) >= m_nNextHitTime then begin
        m_dwHitTick := GetTickCount();
        SearchTarget();
        if m_TargetCret <> nil then GenBB();
      end;
      for I := BBList.Count - 1 downto 0 do begin
        if BBList.Count <= 0 then Break;
        BB := TActorObject(BBList.Items[I]);
        if BB <> nil then begin
          if BB.m_boDeath or (BB.m_boGhost) then BBList.Delete(I);
        end;
      end; // for
    end;
  end;
  inherited;
end;

{ TExplosionSpider }

constructor TExplosionSpider.Create;
//004A6538
begin
  inherited;
  m_nViewRange := 5;
  m_nRunTime := 250;
  m_dwSearchTime := Random(1500) + 2500;
  m_dwSearchTick := 0;
  dw558 := GetTickCount();
end;

destructor TExplosionSpider.Destroy;
begin

  inherited;
end;

procedure TExplosionSpider.sub_4A65C4;
var
  WAbil: pTAbility;
  I, nPower, n10: Integer;
  ActorObject: TActorObject;
begin
  m_WAbil.HP := 0;
  WAbil := @m_WAbil;
  nPower := (Random(Integer(HiWord(WAbil.DC) - LoWord(WAbil.DC)) + 1) + LoWord(WAbil.DC));
  for I := 0 to m_VisibleActors.Count - 1 do begin
    ActorObject := TActorObject(pTVisibleBaseObject(m_VisibleActors.Items[I]).BaseObject);
    if ActorObject.m_boDeath then Continue;
    if IsProperTarget(ActorObject) then begin
      if (abs(m_nCurrX - ActorObject.m_nCurrX) <= 1) and (abs(m_nCurrY - ActorObject.m_nCurrY) <= 1) then begin
        n10 := 0;

        nPower := nPower + GetAddPowerPoint(5, nPower);

        Inc(n10, ActorObject.GetHitStruckDamage(Self, nPower div 2));
        Inc(n10, ActorObject.GetMagStruckDamage(Self, nPower div 2));
        ActorObject.StartNewShield();
        if n10 > 0 then begin
          ActorObject.StruckDamage(n10);
          ActorObject.SendDelayMsg(TActorObject(RM_STRUCK), RM_10101, n10, ActorObject.m_WAbil.HP, ActorObject.m_WAbil.MaxHP, Integer(Self), '', 700);

          n10 := ActorObject.GetAddPowerPoint(4, n10); //·΄ΙδΙΛΊ¦
          if n10 > 0 then begin
            //n10 := n10 + ActorObject.GetAddPowerPoint(5, n10);
            StruckDamage(n10);
            SendDelayMsg(TActorObject(RM_STRUCK), RM_10101, n10, m_WAbil.HP, m_WAbil.MaxHP, Integer(ActorObject), '', 700);
          end;

        end;
      end;
    end;
  end; // for
end;

function TExplosionSpider.AttackTarget: Boolean;
var
  btDir: Byte;
begin
  Result := False;
  if m_TargetCret = nil then Exit;
  if GetAttackDir(m_TargetCret, btDir) then begin
    if Integer(GetTickCount - m_dwHitTick) > m_nNextHitTime then begin
      m_dwHitTick := GetTickCount();
      m_dwTargetFocusTick := GetTickCount();
      sub_4A65C4();
    end;
    Result := True;
  end else begin
    if m_TargetCret.m_PEnvir = m_PEnvir then begin
      SetTargetXY(m_TargetCret.m_nCurrX, m_TargetCret.m_nCurrY);
    end else begin
      DelTargetCreat();
    end;
  end;
end;

procedure TExplosionSpider.Run;
begin
  if not m_boDeath and not m_boGhost then
    if (GetTickCount - dw558) > 60 * 1000 then begin
      dw558 := GetTickCount();
      sub_4A65C4();
    end;

  inherited;
end;

{ TGuardUnit }

procedure TGuardUnit.Struck(hiter: TActorObject);
begin
  inherited;
  if m_Castle <> nil then begin
    bo2B0 := True;
    m_dw2B4Tick := GetTickCount();
  end;
end;

function TGuardUnit.IsProperTarget(ActorObject: TActorObject): Boolean;
begin
  Result := False;
  if m_Castle <> nil then begin
    if m_LastHiter = ActorObject then Result := True;
    if (ActorObject <> nil) and (ActorObject.bo2B0) then begin
      if (GetTickCount - ActorObject.m_dw2B4Tick) < 2 * 60 * 1000 then begin
        Result := True;
      end else ActorObject.bo2B0 := False;
      if ActorObject.m_Castle <> nil then begin
        ActorObject.bo2B0 := False;
        Result := False;
      end;
    end;
    if TUserCastle(m_Castle).m_boUnderWar then Result := True;
    if TUserCastle(m_Castle).m_MasterGuild <> nil then begin
      if ActorObject.Master = nil then begin
        if (TUserCastle(m_Castle).m_MasterGuild = ActorObject.m_MyGuild) or
          (TUserCastle(m_Castle).m_MasterGuild.IsAllyGuild(TGUild(ActorObject.m_MyGuild))) then begin
          if m_LastHiter <> ActorObject then Result := False;
        end;
      end else begin
        if (TUserCastle(m_Castle).m_MasterGuild = ActorObject.Master.m_MyGuild) or
          (TUserCastle(m_Castle).m_MasterGuild.IsAllyGuild(TGUild(ActorObject.Master.m_MyGuild))) then begin
          if (m_LastHiter <> ActorObject.Master) and (m_LastHiter <> ActorObject) then Result := False;
        end;
      end;
    end;
    if (ActorObject <> nil) and
      ActorObject.m_boAdminMode or
      ActorObject.m_boStoneMode or
      ((ActorObject.m_btRaceServer >= 10) and
      (ActorObject.m_btRaceServer < 50)) or
      (ActorObject = Self) or (ActorObject.m_Castle = Self.m_Castle) then begin
      Result := False;
    end;
    Exit;
  end;
  if m_LastHiter = ActorObject then Result := True;
  if (ActorObject.m_TargetCret <> nil) and (ActorObject.m_TargetCret.m_btRaceServer = 112) then
    Result := True;
  if (ActorObject <> nil) and (ActorObject.PKLevel >= 2) then Result := True;
  if (ActorObject <> nil) and ActorObject.m_boAdminMode or
    ActorObject.m_boStoneMode or
    (ActorObject = Self) then Result := False;
end;

{ TArcherGuard }

constructor TArcherGuard.Create;
begin
  inherited;
  m_nViewRange := 12;
  m_boWantRefMsg := True;
  m_Castle := nil;
  m_nDirection := -1;
  m_btRaceServer := 112;
end;

destructor TArcherGuard.Destroy;
begin

  inherited;
end;

procedure TArcherGuard.sub_4A6B30(TargeTActorObject: TActorObject); //004A6B30
var
  nPower: Integer;
  WAbil: pTAbility;
begin
  if TargeTActorObject <> nil then begin
    m_btDirection := GetNextDirection(m_nCurrX, m_nCurrY, TargeTActorObject.m_nCurrX, TargeTActorObject.m_nCurrY);
    WAbil := @m_WAbil;
    nPower := (Random(Integer(HiWord(WAbil.DC) - LoWord(WAbil.DC)) + 1) + LoWord(WAbil.DC));

    nPower := nPower + GetAddPowerPoint(5, nPower);

    if nPower > 0 then
      nPower := TargeTActorObject.GetHitStruckDamage(Self, nPower);
    TargeTActorObject.StartNewShield();
    if nPower > 0 then begin
      TargeTActorObject.SetLastHiter(Self);
      TargeTActorObject.m_ExpHitter := nil;
      TargeTActorObject.StruckDamage(nPower);

      TargeTActorObject.SendDelayMsg(TActorObject(RM_STRUCK), RM_10101, nPower, TargeTActorObject.m_WAbil.HP, TargeTActorObject.m_WAbil.MaxHP, Integer(Self), '',
        _MAX(abs(m_nCurrX - TargeTActorObject.m_nCurrX), abs(m_nCurrY - TargeTActorObject.m_nCurrY)) * 50 + 600);


      nPower := TargeTActorObject.GetAddPowerPoint(4, nPower); //·΄ΙδΙΛΊ¦
      if nPower > 0 then begin
        //nPower := nPower + TargeTActorObject.GetAddPowerPoint(5, nPower);
        StruckDamage(nPower);
        SendDelayMsg(TActorObject(RM_STRUCK), RM_10101, nPower, m_WAbil.HP, m_WAbil.MaxHP, Integer(TargeTActorObject), '', _MAX(abs(m_nCurrX - TargeTActorObject.m_nCurrX), abs(m_nCurrY - TargeTActorObject.m_nCurrY)) * 50 + 600);
      end;

    end;
    SendRefMsg(RM_FLYAXE, m_btDirection, m_nCurrX, m_nCurrY, Integer(TargeTActorObject), '');
  end;
end;

procedure TArcherGuard.Run;
var
  I: Integer;
  nAbs: Integer;
  nRage: Integer;
  ActorObject: TActorObject;
  TargeTActorObject: TActorObject;
begin
  nRage := 9999;
  TargeTActorObject := nil;
  if not m_boDeath and
    not m_boGhost and
    (m_wStatusTimeArr[POISON_STONE {5 0x6A}] = 0) then begin
    if Integer(GetTickCount - m_dwWalkTick) >= m_nWalkSpeed then begin
      m_dwWalkTick := GetTickCount();
      for I := 0 to m_VisibleActors.Count - 1 do begin
        ActorObject := TActorObject(pTVisibleBaseObject(m_VisibleActors.Items[I]).BaseObject);
        if ActorObject.m_boDeath then Continue;
        if IsProperTarget(ActorObject) then begin
          nAbs := abs(m_nCurrX - ActorObject.m_nCurrX) + abs(m_nCurrY - ActorObject.m_nCurrY);
          if nAbs < nRage then begin
            nRage := nAbs;
            TargeTActorObject := ActorObject;
          end;
        end;
      end;
      if TargeTActorObject <> nil then begin
        SetTargetCreat(TargeTActorObject);
      end else begin
        DelTargetCreat();
      end;
    end;
    if m_TargetCret <> nil then begin
      if Integer(GetTickCount - m_dwHitTick) >= m_nNextHitTime then begin
        m_dwHitTick := GetTickCount();
        sub_4A6B30(m_TargetCret);
      end;
    end else begin
      if (m_nDirection >= 0) and (m_btDirection <> m_nDirection) then begin
        TurnTo(m_nDirection);
      end;
    end;
  end;
  inherited;
end;

{ TArcherPolice }

constructor TArcherPolice.Create;
begin
  inherited;
  m_btRaceServer := 20;
end;

destructor TArcherPolice.Destroy;
begin

  inherited;
end;


{ TCastleDoor }

constructor TCastleDoor.Create;
begin
  inherited;
  m_boAnimal := False;
  m_boStickMode := True;
  m_boOpened := False;
  m_btAntiPoison := 200;
end;

destructor TCastleDoor.Destroy;
begin

  inherited;
end;

procedure TCastleDoor.SetMapXYFlag(nFlag: Integer);
var
  bo06: Boolean;
begin
  m_PEnvir.SetMapXYFlag(m_nCurrX, m_nCurrY - 2, True);
  m_PEnvir.SetMapXYFlag(m_nCurrX + 1, m_nCurrY - 1, True);
  m_PEnvir.SetMapXYFlag(m_nCurrX + 1, m_nCurrY - 2, True);
  if nFlag = 1 then bo06 := False
  else bo06 := True;
  m_PEnvir.SetMapXYFlag(m_nCurrX, m_nCurrY, bo06);
  m_PEnvir.SetMapXYFlag(m_nCurrX, m_nCurrY - 1, bo06);
  m_PEnvir.SetMapXYFlag(m_nCurrX, m_nCurrY - 2, bo06);
  m_PEnvir.SetMapXYFlag(m_nCurrX + 1, m_nCurrY - 1, bo06);
  m_PEnvir.SetMapXYFlag(m_nCurrX + 1, m_nCurrY - 2, bo06);
  m_PEnvir.SetMapXYFlag(m_nCurrX - 1, m_nCurrY, bo06);
  m_PEnvir.SetMapXYFlag(m_nCurrX - 2, m_nCurrY, bo06);
  m_PEnvir.SetMapXYFlag(m_nCurrX - 1, m_nCurrY - 1, bo06);
  m_PEnvir.SetMapXYFlag(m_nCurrX - 1, m_nCurrY + 1, bo06);
  if nFlag = 0 then begin
    m_PEnvir.SetMapXYFlag(m_nCurrX, m_nCurrY - 2, False);
    m_PEnvir.SetMapXYFlag(m_nCurrX + 1, m_nCurrY - 1, False);
    m_PEnvir.SetMapXYFlag(m_nCurrX + 1, m_nCurrY - 2, False);
  end;
end;

procedure TCastleDoor.Open;
begin
  if m_boDeath then Exit;
  m_btDirection := 7;
  SendRefMsg(RM_DIGUP, m_btDirection, m_nCurrX, m_nCurrY, 0, '');
  m_boOpened := True;
  m_boStoneMode := True;
  SetMapXYFlag(0);
  bo2B9 := False;
end;

procedure TCastleDoor.Close;
begin
  if m_boDeath then Exit;
  m_btDirection := 3 - Round(m_WAbil.HP / m_WAbil.MaxHP * 3.0);
  if (m_btDirection - 3) >= 0 then m_btDirection := 0;
  SendRefMsg(RM_DIGDOWN, m_btDirection, m_nCurrX, m_nCurrY, 0, '');
  m_boOpened := False;
  m_boStoneMode := False;
  SetMapXYFlag(1);
  bo2B9 := True;
end;

procedure TCastleDoor.Die;
begin
  inherited;
  dw560 := GetTickCount();
  SetMapXYFlag(2);
end;

procedure TCastleDoor.Run;
var
  n08: Integer;
begin
  if m_boDeath and (m_Castle <> nil) then
    m_dwDeathTick := GetTickCount()
  else m_nHealthTick := 0;
  if not m_boOpened then begin
    n08 := 3 - Round(m_WAbil.HP / m_WAbil.MaxHP * 3.0);
    if (m_btDirection <> n08) and (n08 < 3) then begin
      m_btDirection := n08;
      SendRefMsg(RM_TURN, m_btDirection, m_nCurrX, m_nCurrY, 0, '');
    end;
  end;
  inherited;
end;

procedure TCastleDoor.RefStatus;
var
  n08: Integer;
begin
  n08 := 3 - Round(m_WAbil.HP / m_WAbil.MaxHP * 3.0);
  if (n08 - 3) >= 0 then n08 := 0;
  m_btDirection := n08;
  SendRefMsg(RM_ALIVE, m_btDirection, m_nCurrX, m_nCurrY, 0, '');
end;

procedure TCastleDoor.Initialize;
begin
  //  m_btDirection:=0;
  inherited;
  {
  if m_WAbil.HP > 0 then begin
    if m_boOpened then begin
      SetMapXYFlag(0);
      exit;
    end;
    SetMapXYFlag(1);
    exit;
  end;
  SetMapXYFlag(2);
  }
end;

{ TWallStructure }

constructor TWallStructure.Create;
begin
  inherited;
  m_boAnimal := False;
  m_boStickMode := True;
  boSetMapFlaged := False;
  m_btAntiPoison := 200;
end;

destructor TWallStructure.Destroy;
begin

  inherited;
end;

procedure TWallStructure.Initialize;
begin
  m_btDirection := 0;
  inherited;
end;

procedure TWallStructure.RefStatus;
var
  n08: Integer;
begin
  if m_WAbil.HP > 0 then begin
    n08 := 3 - Round(m_WAbil.HP / m_WAbil.MaxHP * 3.0);
  end else begin
    n08 := 4;
  end;
  if n08 >= 5 then n08 := 0;
  m_btDirection := n08;
  SendRefMsg(RM_ALIVE, m_btDirection, m_nCurrX, m_nCurrY, 0, '');
end;

procedure TWallStructure.Die;
begin
  inherited;
  dw560 := GetTickCount();
end;

procedure TWallStructure.Run;
var
  n08: Integer;
begin
  if m_boDeath then begin
    m_dwDeathTick := GetTickCount();
    if boSetMapFlaged then begin
      m_PEnvir.SetMapXYFlag(m_nCurrX, m_nCurrY, True);
      boSetMapFlaged := False;
    end;
  end else begin
    m_nHealthTick := 0;
    if not boSetMapFlaged then begin
      m_PEnvir.SetMapXYFlag(m_nCurrX, m_nCurrY, False);
      boSetMapFlaged := True;
    end;
  end;
  if m_WAbil.HP > 0 then begin
    n08 := 3 - Round(m_WAbil.HP / m_WAbil.MaxHP * 3.0);
  end else begin
    n08 := 4;
  end;
  if (m_btDirection <> n08) and (n08 < 5) then begin
    m_btDirection := n08;
    SendRefMsg(RM_DIGUP, m_btDirection, m_nCurrX, m_nCurrY, 0, '');
  end;
  inherited;
end;

constructor TEvilMir.Create;
begin
  inherited;
  m_dwSpellTick:=GetTickCount();
  m_boAnimal:=False;
  boSlaves:=False;
  dwEMDied:=0;
  m_nViewRange:=20;
end;

destructor TEvilMir.Destroy;
begin
  inherited;
end;

procedure TEvilMir.Run;
var
nDir:Byte;
nCurrX , nCurrY : Integer;
begin
 if (m_boDeath)and (boSlaves = True) then begin
    boSlaves:= False;
    nEMDrops:=0;
    nEMHitCount:=0;
    dwEMDied:=GetTickCount();
    Inc(nEMKills)
 end;
   if not m_boFixedHideMode and
not m_boStoneMode and
CanMove(nCurrX, nCurrY, False) then begin


      if (m_TargetCret <> nil) and (Integer(GetTickCount - m_dwHitTick) > 3500) and (Abs(m_nCurrX - m_TargetCret.m_nCurrX) <= 10) and  (Abs(m_nCurrY - m_TargetCret.m_nCurrY) <= 10) then begin
       m_dwHitTick:=GetCurrentTime;
       nDir:= GetNextDirection(m_nCurrX, m_nCurrY,m_TargetCret.m_nCurrX, m_TargetCret.m_nCurrY);
       FlameCircle(nDir);
      end;
     if (m_TargetCret <> nil) and (Integer(GetTickCount - m_dwSpellTick) > 30000) and (Abs(m_nCurrX - m_TargetCret.m_nCurrX) <= 10) and (Abs(m_nCurrY - m_TargetCret.m_nCurrY) <= 10) then begin
       MassThunder;
     end;

     if ((GetTickCount - m_dwSearchEnemyTick) > 8000) or
        (((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil))then begin
       m_dwSearchEnemyTick:=GetTickCount();
       SearchTarget();
     end;
     inherited;
    end;
end;



procedure TEvilMir.FlameCircle(nDir: Integer);
var
I: Integer;
magpwr: Integer;
Wabil: pTAbility;
BaseObject: TActorObject;
Target: TBaseObject;
begin
Target := m_TargetCret;
if nDir <= 4 then
  SendRefMsg(RM_81,nDir,m_nCurrX,m_nCurrY,Integer(Target),'');
  if nDir = 5 then
  SendRefMsg(RM_82,nDir,m_nCurrX,m_nCurrY,Integer(Target),'');
  if nDir = 6 then
  SendRefMsg(RM_83,nDir,m_nCurrX,m_nCurrY,Integer(Target),'');
  for i := 0 to Target.m_VisibleActors.count-1  do begin
    BaseObject:= TActorObject (pTVisibleBaseObject(Target.m_VisibleActors[i]).BaseObject);
   if (abs(Target.m_nCurrX-BaseObject.m_nCurrX) <= 2) and (abs(Target.m_nCurrY-BaseObject.m_nCurrY) <= 2) then begin

    if BaseObject <> nil then begin
      if IsProperTarget (BaseObject) then begin
        if Random(50) >= BaseObject.m_nAntiMagic then begin
          WAbil:=@m_WAbil;
          magpwr:=Random(nEMKills * 5) + (Random(SmallInt(HiWord(WAbil.MC) - LoWord(WAbil.MC)) + 1) + LoWord(WAbil.MC));
          BaseObject.SendDelayMsg (self, RM_MAGSTRUCK, 0, magpwr, 1, 0, '', 600);
        end;
      end;
    end;
   end;
  end;
end;

procedure TEvilMir.MassThunder();
var
  xTargetList:TList;
  BaseObject:TActorObject;
  WAbil:pTAbility;
  magpwr:Integer;
  i:Integer;
begin
  m_dwSpellTick:=GetTickCount();
  SendAttackMsg(RM_hit,0,m_nCurrX,m_nCurrY);//make client show random tbolting;
  xTargetList := TList.Create;
  GetMapActorObjects(m_PEnvir,m_nCurrX,m_nCurrY,14,xTargetList);

	if (xTargetList.Count>0) then begin
    for i:=xTargetList.Count-1 downto 0 do begin
      BaseObject := TActorObject(xTargetList.Items[i]);

      if (BaseObject<>nil) then begin
      if IsProperTarget(BaseObject) then begin
         WAbil:=@m_WAbil;
          magpwr:=Random(nEMKills * 12) + (Random(SmallInt(HiWord(WAbil.SC) - LoWord(WAbil.SC)) + 1) + LoWord(WAbil.SC));
          BaseObject.SendDelayMsg (self, RM_MAGSTRUCK, 0, magpwr, 1, 0, '', 600);
      end;
        xTargetList.Delete(i);
		  end;
    end;
	end;
  xTargetList.Free;
end;


function TEvilMir.Operate(ProcessMsg:pTProcessMessage):boolean;
begin
  if (ProcessMsg.wIdent = RM_POISON) then begin
    massthunder();
  end;
  Result:=inherited Operate(ProcessMsg);
end;

procedure TEvilMir.Die;
begin
  inherited;
  m_dwDeathTick := GetTickCount + 5*60*1000;
end;

{DragonStatue}
constructor TDragonStatue.Create;
begin
m_nViewRange:=15;
  inherited;
  m_boAnimal:=False;
end;

destructor TDragonStatue.Destroy;
begin

  inherited;
end;

procedure TDragonStatue.Run;//004A617C
begin
  if (not m_boDeath) and (not m_boGhost) then begin
  //doing firebang thing
    if (m_TargetCret <> nil) and (GetCurrentTime - m_dwHitTick > GetHitSpeed) and (abs(m_nCurrX - m_TargetCret.m_nCurrX) <= 12) and (abs(m_nCurrY - m_TargetCret.m_nCurrY) <= 12) then begin
      m_dwHitTick:=GetCurrentTime;
      FireBang();
     end;
     //search for targets nearbye(rather then using official search this thing has wider range :p)
    if ((GetTickCount - m_dwSearchEnemyTick) > 8000) or
       (((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil)) then begin
      m_dwSearchEnemyTick:=GetTickCount();
      SearchTarget();
   end;

  end;
  inherited;
end;

procedure TDragonStatue.FireBang();
var
 // nSX,nSY,nTX,nTY,nPwr:Integer;
  I:Integer;
  magpwr:Integer;
  //TargetNum:Integer;
  WAbil:pTAbility;
  BaseObject:TActorObject;
  Target:TActorObject;
begin
//target selected
 Target := m_TargetCret;

 {do spell effect}
 SendRefMsg(RM_LIGHTING,1,m_nCurrX,m_nCurrY,Integer(Target),'');

 for i:=0 to Target.m_VisibleActors.Count-1 do begin
  BaseObject:= TActorObject (pTVisibleBaseObject(Target.m_VisibleActors[i]).BaseObject);
   if (abs(Target.m_nCurrX-BaseObject.m_nCurrX) <= 1) and (abs(Target.m_nCurrY-BaseObject.m_nCurrY) <= 1) then begin

    if BaseObject <> nil then begin
      if IsProperTarget (BaseObject) then begin
        if Random(50) >= BaseObject.m_nAntiMagic then begin
          WAbil:=@m_WAbil;
          magpwr:=(Random(SmallInt(HiWord(WAbil.MC) - LoWord(WAbil.MC)) + 1) + LoWord(WAbil.MC));
          BaseObject.SendDelayMsg (self, RM_MAGSTRUCK, 0, magpwr, 1, 0, '', 600);
        end;
      end;
    end;
   end;
  end;
end;

{FoxOrbSpiri}
constructor TFoxOrbSpirit.Create;
begin
  inherited;

end;

destructor TFoxOrbSpirit.Destroy;
begin
  inherited;
end;

procedure TFoxOrbSpirit.Run;
var
  nDir:Byte;
  nCurrX , nCurrY : Integer;
begin

  if not m_boFixedHideMode and
   not m_boStoneMode and
    CanMove( nCurrX, nCurrY, False) then begin


     if (m_TargetCret <> nil) and (Integer(GetTickCount - m_dwHitTick) > 7000) and (abs(m_nCurrX - m_TargetCret.m_nCurrX) <= 10) and (abs(m_nCurrY - m_TargetCret.m_nCurrY) <= 10) then begin
      m_dwHitTick:=GetCurrentTime;
      nDir:= GetNextDirection (m_nCurrX, m_nCurrY, m_TargetCret.m_nCurrX, m_TargetCret.m_nCurrY);
      if Random(3) = 0 then
      FlameCircle2
      else
      FlameCircle(0);
     end;

    if ((GetTickCount - m_dwSearchEnemyTick) > 8000) or
       (((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil)) then begin
      m_dwSearchEnemyTick:=GetTickCount();
      SearchTarget();
   end;
  end;
  inherited;
end;

procedure TFoxOrbSpirit.FlameCircle(nDir:Integer);
var
 // nSX,nSY,nTX,nTY,nPwr:Integer;
  I:Integer;
  magpwr:Integer;
 // TargetNum:Integer;
  WAbil:pTAbility;
  BaseObject:TActorObject;
  Target:TActorObject;
begin
 Target := m_TargetCret;
   SendRefMsg(RM_LIGHTING,nDir,m_nCurrX,m_nCurrY,Integer(Target),'');

 for i:=0 to Target.m_VisibleActors.Count-1 do begin
  BaseObject:=TActorObject(pTVisibleBaseObject(Target.m_VisibleActors.Items[I]).BaseObject);
   if (abs(Target.m_nCurrX-BaseObject.m_nCurrX) <= 2) and (abs(Target.m_nCurrY-BaseObject.m_nCurrY) <= 2) then begin
    if BaseObject <> nil then begin
      if IsProperTarget (BaseObject) then begin
        if Random(50) >= BaseObject.m_nAntiMagic then begin
          WAbil:=@m_WAbil;
          magpwr:=Random(nEMKills * 5) + (Random(SmallInt(HiWord(WAbil.MC) - LoWord(WAbil.MC)) + 1) + LoWord(WAbil.MC));
          BaseObject.SendDelayMsg (self, RM_MAGSTRUCK, 0, magpwr, 1, 0, '', 600);
          SendRefMsg(RM_10205,0,BaseObject.m_nCurrX,BaseObject.m_nCurrY,26{type},'');
        end;
      end;
    end;
   end;
  end;
end;

procedure TFoxOrbSpirit.FlameCircle2();
var
  xTargetList:TList;
  BaseObject:TActorObject;
  WAbil:pTAbility;
  magpwr:Integer;
  i:Integer;
begin
  xTargetList := TList.Create;
  GetMapActorObjects(m_PEnvir,m_nCurrX,m_nCurrY,14,xTargetList);
  SendRefMsg(RM_FLYAXE,0,m_nCurrX,m_nCurrY,Integer(m_TargetCret),'');
	if (xTargetList.Count>0) then begin
    for i:=xTargetList.Count-1 downto 0 do begin
      BaseObject := TActorObject(xTargetList.Items[i]);

      if (BaseObject<>nil) then begin
      if IsProperTarget(BaseObject) then begin
         WAbil:=@m_WAbil;
          magpwr:=Random(nEMKills * 12) + (Random(SmallInt(HiWord(WAbil.SC) - LoWord(WAbil.SC)) + 1) + LoWord(WAbil.SC));
          BaseObject.SendDelayMsg (self, RM_MAGSTRUCK, 0, magpwr, 1, 0, '', 600);
      end;
        xTargetList.Delete(i);
		  end;
    end;
	end;
  xTargetList.Free;
end;

{Red Thunder Zuma}
constructor TRedThunderZuma.Create;//004AAE20
begin

  m_dwSearchTime:=Random(1500) + 1500;
  m_boStoneMode:=True;
  m_nCharStatusEx:=STATE_STONE_MODE;
  m_nViewRange:=12;
  m_dwSpellTick:=GetTickCount();
  inherited;
end;

destructor TRedThunderZuma.Destroy;
begin
  inherited;
end;


procedure TRedThunderZuma.Run;//004AAF98
begin
  if (not bo554) and not m_boGhost and not m_boDeath and (m_wStatusTimeArr[POISON_STONE {5 0x6A}] = 0) then begin
    if m_TargetCret <> nil then begin
      if (Integer(GetTickCount - m_dwSpellTick) > 2500) then begin
        m_dwSpellTick:=GetTickCount();
        MagicAttack();
      end;
    end;
  end;
  inherited;
end;

procedure TRedThunderZuma.MagicAttack();
var
  WAbil:pTAbility;
  nPwr:Integer;
begin
  SendRefMsg(RM_LIGHTING,1,m_nCurrX,m_nCurrY,Integer(m_TargetCret),'');

  if IsProperTarget(m_TargetCret) then begin
    WAbil:=@m_WAbil;
    nPwr:=(Random(SmallInt(HiWord(WAbil.MC) - LoWord(WAbil.MC)) + 1) + LoWord(WAbil.MC));
    if nPwr > 0 then
    m_TargetCret.SendDelayMsg (self, RM_MAGSTRUCK, 0, npwr, 1, 0, '', 600);
  end;
end;

{Red PoisonMob}
constructor TRedPoisonMob.Create;
begin
  inherited;
end;

procedure TRedPoisonMob.Run;
var
  nAttackDir:Integer;
  nX,nY,distx,disty,nDir:Integer;
  boAllowed:Boolean;
begin
  boAllowed := False;
  if (not bo554) and not m_boGhost and not m_boDeath and (m_wStatusTimeArr[POISON_STONE {5 0x6A}] = 0) then begin

    if ((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil) then begin
      m_dwSearchEnemyTick:=GetTickCount();
      SearchTarget();
    end;
    if m_TargetCret <> nil then begin
    //walking
     if (GetCurrentTime - m_dwWalkTick > GetWalkSpeed) then begin //check if we should walk closer or not and do it :p
        distx:=abs(m_nCurrX - m_TargetCret.m_nCurrX);
        disty := abs(m_nCurrY - m_TargetCret.m_nCurrY);
        nDir:=GetNextDirection(m_nCurrX,m_nCurrY,m_TargetCret.m_nCurrX,m_TargetCret.m_nCurrY);
        if (((distx > 1) or (disty > 1)) and ((distx < 12) and (disty < 12))) or (MagCanHitTarget(m_nCurrX,m_nCurrY,m_targetCret) = false) then begin //restrict the maximum pursuit distance to 12 coords away
          m_dwWalkTick:=GetCurrentTime;
          m_nTargetX := m_TargetCret.m_nCurrX;
          m_nTargetY := m_TargetCret.m_nCurrY;
          GotoTargetXY
//          WalkTo(nDir,False);
        end;
      end;

    if m_TargetCret <> nil then begin
      nX:=abs(m_nCurrX - m_TargetCret.m_nCurrX);
      nY:=abs(m_nCurrY - m_TargetCret.m_nCurrY);
        //if ((nX <= 1) and (nY <= 1)) and (Integer(GetTickCount - Self.m_dwHitTick)
      end;
    end;
  end;
  inherited Run;
end;

destructor TRedPoisonMob.Destroy;
begin
  inherited;
end;

function TRedPoisonMob.AttackTarget(): Boolean;
var
  btDir:Byte;
begin
  Result:=False;
  if m_TargetCret <> nil then begin
    if GetAttackDir(m_TargetCret,btDir) then begin
      if GetCurrentTime - m_dwHitTick > GetHitSpeed then begin
        m_dwHitTick:=GetCurrentTime;
        m_dwTargetFocusTick:=GetTickCount();
        Attack(m_TargetCret,btDir);
        if Random(2) = 0 then
        m_TargetCret.MakePosion(POISON_DAMAGEARMOR,Random(60) + 1,1);
      end;
      Result:=True;
    end;
  end;
end;

{ khazard }
constructor TKhazard.Create; //004A9690
begin
  inherited;
  m_dwThinkTick:=GetTickCount();
  m_dwSearchTime:=Random(1500) + 1500;
end;

destructor TKhazard.Destroy;
begin

  inherited;
end;

procedure TKhazard.Run;//004A9720
var
  time1 : integer;
begin
  if not m_boFixedHideMode and
     not m_boStoneMode and
     not m_boGhost and not m_boDeath and (m_wStatusTimeArr[POISON_STONE {5 0x6A}] = 0) then begin
    time1:=random(2);
    if m_TargetCret <> nil then begin

    //attack code
      if IsProperTarget(m_TargetCret) then begin
        m_nTargetX:=m_TargetCret.m_nCurrX;
        m_nTargetY:=m_TargetCret.m_nCurrY;
        if (abs(m_nTargetX-m_nCurrX) = 2) or (abs(m_nTargety-m_nCurry)=2) then begin
          if (GetTickCount - m_dwThinkTick) > 1000 then begin //do drag back on random
            m_dwThinkTick:=GetTickCount();
            if time1 < 2 then
              drag();
          end else
            AttackTarget();
        end;
      end;
    end;
    if ((GetTickCount - m_dwSearchEnemyTick) > 8000) or
       (((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil)) then begin
      m_dwSearchEnemyTick:=GetTickCount();
      SearchTarget();
    end;
  end;
  inherited;
end;

procedure TKhazard.Drag();
var
  nx,ny: Integer;
  nAttackDir: Integer;
begin
  nAttackDir:=GetNextDirection(m_TargetCret.m_nCurrX,m_TargetCret.m_nCurrY,m_nCurrX,m_nCurrY); //technicaly this is the dir the target would be facing if he was hitting us
  GetFrontPosition(nx,ny);
  SendRefMsg(RM_LIGHTING,1,m_nCurrX,m_nCurrY,Integer(m_TargetCret),'');

  m_TargetCret.CharPushed(nAttackDir,1);
  if (Random(1) = 0) and (Random(m_TargetCret.m_btAntiPoison + 7) <= 6) then begin
    m_TargetCret.MakePosion(POISON_DECHEALTH,35,2);
    exit;
  end;
end;

function TKhazard.AttackTarget():Boolean; //004A8F34
var
  btDir:Byte;
begin
  Result:=False;
  if m_TargetCret <> nil then begin
    if GetAttackDir(m_TargetCret,btDir) then begin
      if GetCurrentTime - m_dwHitTick > GetHitSpeed then begin
        m_dwHitTick:=GetCurrentTime;
        m_dwTargetFocusTick:=GetTickCount();
        Attack(m_TargetCret,btDir);  //FFED
        if (Random(1) = 0) and (Random(m_TargetCret.m_btAntiPoison + 7) <= 6) then begin
            m_TargetCret.MakePosion(POISON_DECHEALTH,35,2);
            exit;
        end;
      end;
      Result:=True;
    end;
  end;
end;

{ TFrostTigerMonster }

constructor TFrostTiger.Create; //004A9690
begin
  inherited;
  m_dwSearchTime:=Random(1500) + 1500;
  m_dwSpellTick:=GetTickCount();
  m_dwLastWalkTick:=GetTickCount();
  m_boApproach:=FALSE;
end;

destructor TFrostTiger.Destroy;
begin
  inherited;
end;

procedure TFrostTiger.Run;//004A9720
begin
  if (not bo554) and not m_boDeath and (m_wStatusTimeArr[POISON_STONE {5 0x6A}] = 0) then begin

    if m_TargetCret = nil then begin  //if theres no target stay transparent

      if not m_boHideMode then begin
        if (gettickcount - m_dwLastWalkTick > 2000) then begin
          m_dwLastWalkTick := GetTickCount();
          MagicManager.MagMakePrivateTransparent(Self,180);
          SendRefMsg(RM_DIGDOWN, m_btDirection, m_nCurrX, m_nCurrY, 0, '');
        end;
      end else
        m_dwLastWalkTick := GetTickCount();
    end else begin
    //there is a target so take of transparency
      if not m_TargetCret.m_boDeath then begin
        if m_boHideMode then begin
          m_wStatusTimeArr[STATE_TRANSPARENT{0x70}]:=1;
          SendRefMsg(RM_DIGUP, m_btDirection, m_nCurrX, m_nCurrY, 0, '');
        end;
      end else
        m_TargetCret := nil;

      if (Integer(GetTickCount - m_dwLastWalkTick) > m_nWalkSpeed) then begin //check if we should walk closer or not and do it :p
        m_dwLastWalkTick:=GetTickCount();
        m_nTargetX:=m_TargetCret.m_nCurrX;
        m_nTargetY:=m_TargetCret.m_nCurry;
        GotoTargetXY();
      end;
    end;

    if ((GetTickCount - m_dwSpellTick) > 3000) and (m_TargetCret <> nil) then begin
      if (abs(m_TargetCret.m_nCurrX-m_nCurrX) >= 2) or (abs(m_TargetCret.m_nCurrY-m_nCurry) >= 2) then begin
        m_dwSpellTick:=GetTickCount();
        FrostAttack();
      end;
    end;

    if ((GetTickCount - m_dwSearchEnemyTick) > 8000) or
       (((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil)) then begin
      m_dwSearchEnemyTick:=GetTickCount();
      //SearchTarget();
    end;
  end;
  inherited;
end;

procedure TFrostTiger.FrostAttack();
var
Target:TActorObject;
magpwr:Integer;
WAbil:pTAbility;
begin
  if m_TargetCret = nil then exit;
  Target:=m_TargetCret;
  SendRefMsg(RM_LIGHTING,1,m_nCurrX,m_nCurrY,Integer(Target),'');

 if IsProperTarget (Target) then begin
  if Random(50) >= Target.m_nAntiMagic then begin
      WAbil:=@m_WAbil;
      magpwr:=(Random(SmallInt(HiWord(WAbil.MC) - LoWord(WAbil.MC)) + 1) + LoWord(WAbil.MC));
      Target.SendDelayMsg (self, RM_MAGSTRUCK, 0, magpwr, 0, 0, '', 600);
      if (Random(15) <= 3) and (Random(Target.m_btAntiPoison) = 0) then begin
        Target.MakePosion(POISON_FREEZE,(2 * 3),0);
      end;
         end;
          end;
    end;
{ THellGuard }

constructor THellGuard.Create;
begin
  inherited;
  m_nViewRange:=16;
  m_boAnimal:=False;
end;

destructor THellGuard.Destroy;
begin

  inherited;
end;

function THellGuard.AttackTarget():Boolean;
var
  I: Integer;
  ActorObject: TActorObject;
  nPower:Integer;
  WAbil:pTAbility;
begin
  Result:=False;
  if GetCurrentTime - m_dwHitTick > GetHitSpeed then begin
    m_dwHitTick:=GetCurrentTime;
    SendRefMsg(RM_HIT,m_btDirection,m_nCurrX,m_nCurrY,0,'');
    WAbil:=@m_WAbil;
    nPower:=(Random(SmallInt(HiWord(WAbil.DC) - LoWord(WAbil.DC)) +1) + LoWord(WAbil.DC));
    for I := 0 to m_VisibleActors.Count - 1 do begin
      ActorObject := TActorObject(pTVisibleBaseObject(m_VisibleActors.Items[I]).BaseObject);
      if ActorObject.m_boDeath then Continue;
      if IsProperTarget(ActorObject) then begin
        if (abs(m_nCurrX - ActorObject.m_nCurrX) <= m_nViewRange) and (abs(m_nCurrY - ActorObject.m_nCurrY) <= m_nViewRange) then begin
          SendDelayMsg(Self,RM_DELAYMAGIC,nPower,MakeLong(ActorObject.m_nCurrX,ActorObject.m_nCurrY),1,Integer(ActorObject),'',200);
          SendRefMsg(RM_10205,0,ActorObject.m_nCurrX,ActorObject.m_nCurrY,17{type},'');
        end;
      end;
    end;
    Result:=True;
  end;
end;



procedure THellGuard.Run;
var
 nCurrX , nCurrY : Integer;
begin
  if CanMove(nCurrX, nCurrY, False) then begin
    if m_VisibleActors.Count > 0 then
      AttackTarget();
  end;
   if (Random(10) = 0) then begin
      RepulseCircle();
   end;
  inherited;
end;

procedure THellGuard.RepulseCircle();
var
  I:Integer;
  ActorObject:TActorObject;
  nDir:Byte;
  push:integer;
begin
if m_TargetCret = nil then exit;
 nDir:= GetNextDirection (m_nCurrX, m_nCurrY, m_TargetCret.m_nCurrX, m_TargetCret.m_nCurrY);
 m_btDirection:=nDir;
 SendRefMsg(RM_LIGHTING,nDir,m_nCurrX,m_nCurrY,Integer(self),'');

 for i:=0 to m_VisibleActors.Count-1 do begin
  ActorObject:= TActorObject (pTVisibleBaseObject(m_VisibleActors[i]).BaseObject);
   if (abs(m_nCurrX-ActorObject.m_nCurrX) <= 2) and (abs(m_nCurrY-ActorObject.m_nCurrY) <= 2)
    and ((abs(m_nCurrY - m_TargetCret.m_nCurrY) + abs(m_nCurrX - m_TargetCret.m_nCurrX)) <= 3) then begin

    if (ActorObject <> nil) and not ActorObject.m_boDeath then begin
      if IsProperTarget (ActorObject) then begin
        if Random(50) >= ActorObject.m_nAntiMagic then begin
          push := 1 + Random(3);
          nDir:= GetNextDirection (m_nCurrX, m_nCurrY, ActorObject.m_nCurrX, ActorObject.m_nCurrY);
          ActorObject.CharPushed (nDir, push);
          SendRefMsg(RM_10205,0,ActorObject.m_nCurrX,ActorObject.m_nCurrY,18{type},'');

        end;
      end;
    end;
   end;
  end;
end;

{================================}
 { TDDevilMon }

constructor TDDevil.Create;
begin
  inherited;
  m_dwSearchTime:=Random(1500) + 1500;
  m_boUseMagic:=False;
  m_dwSpellTick:=GetTickCount();
end;

destructor TDDevil.Destroy;
begin

  inherited;
end;


procedure TDDevil.LightingAttack(nDir: Integer);
var
  WAbil:pTAbility;
  nSX,nSY,nTX,nTY,nPwr:Integer;

begin
  m_btDirection:=nDir;
  if m_PEnvir.GetNextPosition(m_nCurrX,m_nCurrY,nDir,1,nSX,nSY) then begin
    m_PEnvir.GetNextPosition(m_nCurrX,m_nCurrY,nDir,2,nTX,nTY);

    WAbil:=@m_WAbil;
    nPwr:=(Random(SmallInt(HiWord(WAbil.DC) - LoWord(WAbil.DC)) + 1) + LoWord(WAbil.DC));

  MagPassThroughMagic(nSX, nSY, nTX, nTY, nDir, nPwr, True, AT_LIGHT);
  end;
  SendRefMsg(RM_LIGHTING,1,m_nCurrX,m_nCurrY,Integer(m_TargetCret),'');
end;

procedure TDDevil.Run;
var
  nAttackDir:Integer;
  nX,nY:Integer;
  nCurrX , nCurrY : Integer;
begin
     if CanMove(nCurrX, nCurrY, False) and (not bo554) then begin

    if ((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil) then begin
      m_dwSearchEnemyTick:=GetTickCount();
      SearchTarget();
    end;
    if m_TargetCret <> nil then begin
      nX:=abs(m_nCurrX - m_TargetCret.m_nCurrX);
      nY:=abs(m_nCurrY - m_TargetCret.m_nCurrY);
      if (nX <= 2) and (nY <= 2) then begin

        if (Integer(GetTickCount - m_dwSpellTick) > (m_nNextHitTime * 4)) then begin
          m_dwSpellTick:=GetTickCount();
          nAttackDir:=GetNextDirection(m_nCurrX,m_nCurrY,m_TargetCret.m_nCurrX,m_TargetCret.m_nCurrY);
          LightingAttack(nAttackDir);
        end;
      end;
    end;
  end;
  inherited Run;
end;
 {================================}
constructor TWhiteFox2.Create;
begin
  ldistx:=0;
  ldisty:=0;
  m_dwSearchTime:=Random(1500) + 1500;
  m_dwSpellTick:=GetTickCount();
  m_boAnimal:=False;
  inherited;
end;

destructor TWhiteFox2.Destroy;
begin
  inherited;
end;

function TWhiteFox2.MagicAttack2():Boolean;
var
  magpwr:Integer;
  WAbil:pTAbility;
  nDir:integer;
begin
if m_TargetCret = nil then exit;
 nDir:= GetNextDirection (m_nCurrX, m_nCurrY, m_TargetCret.m_nCurrX, m_TargetCret.m_nCurrY);
  m_btDirection:=nDir;
 SendRefMsg(RM_LIGHTING,nDir,m_nCurrX,m_nCurrY,Integer(m_TargetCret),'');

   if (abs(m_nCurrX-m_TargetCret.m_nCurrX) <= 8) and (abs(m_nCurrY-m_TargetCret.m_nCurrY) <= 8) then begin
      if IsProperTarget (m_TargetCret) then begin
        if Random(50) >= m_TargetCret.m_nAntiMagic then begin
          WAbil:=@m_WAbil;
          magpwr:=(m_TargetCret.m_WAbil.MaxHP * LoWord(WAbil.MC)) div 100;
          m_TargetCret.SendDelayMsg (self, RM_MAGSTRUCK, 0, magpwr, 1, 0, '', 600);
          if Random(3) <> 0 then
            m_TargetCret.MakePosion(POISON_STONE,5,0);
      end;
    end;
   end;
  end;

function TWhiteFox2.AttackTarget():Boolean;
var
  btDir:Byte;
begin
  Result:=False;
  if m_TargetCret <> nil then begin
    if GetAttackDir(m_TargetCret,btDir) then begin
      if GetCurrentTime - m_dwHitTick > GetHitSpeed  then begin
        m_dwHitTick:=GetCurrentTime;
        m_dwTargetFocusTick:=GetTickCount();
        Attack(m_TargetCret,btDir);
        BreakHolySeizeMode();
      end;
      Result:=True;
    end else begin
      if m_TargetCret.m_PEnvir = m_PEnvir then begin
        SetTargetXY(m_TargetCret.m_nCurrX,m_TargetCret.m_nCurrY);
      end else begin
        DelTargetCreat();
      end;
    end;
  end;
end;

procedure TWhiteFox2.MagicAttack(Target:TBaseObject);
var
  WAbil:pTAbility;
  nDamage:Integer;
begin
  if m_PEnvir.CanFly(m_nCurrX,m_nCurrY,Target.m_nCurrX,Target.m_nCurrY) then begin
    m_btDirection:=GetNextDirection(m_nCurrX,m_nCurrY,Target.m_nCurrX,Target.m_nCurrY);
    WAbil:=@m_WAbil;
    nDamage:=(Random(SmallInt(HiWord(WAbil.DC) - LoWord(WAbil.DC)) +1) + LoWord(WAbil.DC));

    if nDamage > 0 then begin
    StruckDamage(nDamage);
    SendDelayMsg(TActorObject(RM_STRUCK), RM_10101, nDamage, m_WAbil.HP, m_WAbil.MaxHP, Integer(m_TargetCret), '', 200);
  end;
  end;
end;


procedure TWhiteFox2.Run;
var
nDir:integer;
 nCurrX , nCurrY : Integer;
begin
  if not m_boFixedHideMode and
     not m_boStoneMode and
      CanMove(nCurrX, nCurrY, false) then begin

  if (m_TargetCret <> nil) then begin
 if (abs(m_nCurrX - m_TargetCret.m_nCurrX) <= 3) and (abs(m_nCurrX - m_TargetCret.m_nCurrX) <= 3) then begin
     if (GetCurrentTime - m_dwWalkTick > GetWalkSpeed) then begin
      m_dwWalkTick:=GetCurrentTime;

       nDir:= GetNextDirection (m_nCurrX, m_nCurrY, m_TargetCret.m_nCurrX, m_TargetCret.m_nCurrY);
       m_btDirection:=nDir;
      if GetCurrentTime - m_dwHitTick > GetHitSpeed  then begin
        m_dwHitTick:=GetCurrentTime;
        m_dwTargetFocusTick:=GetTickCount();
        Attack(m_TargetCret,nDir);
        BreakHolySeizeMode();
      end;
     end;
    end else begin
    if (Integer(GetTickCount - m_dwSpellTick) > 6000) then begin
        m_dwSpellTick:=GetTickCount();
        nDir:= GetNextDirection (m_nCurrX, m_nCurrY, m_TargetCret.m_nCurrX, m_TargetCret.m_nCurrY);
        m_btDirection:=nDir;
        if (Random(3) = 0) then begin
        MagicAttack(m_TargetCret);
        end else begin
        MagicAttack2();
        end; 
     end;
    end;
   end;

    if ((GetTickCount - m_dwSearchEnemyTick) > 8000) or
       (((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil)) then begin
      m_dwSearchEnemyTick:=GetTickCount();
      SearchTarget();
     end;
  inherited;
   end;
   end;
      {================================}
 constructor TCrystalSpider.Create;
begin
  inherited;
  m_dwSearchTime:=Random(1500) + 1500;
  m_boUseMagic:=False;
end;

destructor TCrystalSpider.Destroy;
begin
  inherited;
end;

function TCrystalSpider.AttackTarget():Boolean;
var
  btDir:Byte;
begin
  Result:=False;
  if m_TargetCret <> nil then begin
    if GetAttackDir(m_TargetCret,btDir) then begin
      if GetCurrentTime - m_dwHitTick > GetHitSpeed then begin
        m_dwHitTick:=GetCurrentTime;
        m_dwTargetFocusTick:=GetTickCount();
        Attack(m_TargetCret,btDir);
        if (Random(m_TargetCret.m_btAntiPoison + 20) = 0) then
          m_TargetCret.MakePosion(POISON_DECHEALTH,30,1);
        BreakHolySeizeMode();
      end;
      Result:=True;
    end else begin
      if m_TargetCret.m_PEnvir = m_PEnvir then begin
        SetTargetXY(m_TargetCret.m_nCurrX,m_TargetCret.m_nCurrY);
      end else begin
        DelTargetCreat();
      end;
    end;
  end;
end;
  {================================}
constructor TCustomMonster.Create;
begin
  inherited;
  m_dwSearchTime:=Random(1500) + 1500;
end;

destructor TCustomMonster.Destroy;
begin

  inherited;
end;

procedure TCustomMonster.Run;
var
   nCurrX , nCurrY : Integer;
begin
  if CanMove(nCurrX, nCurrY, False) then begin
    if m_VisibleActors.Count > 0 then
      AttackTarget();
  end;
   if (Random(10) = 0) then begin
      RepulseCircle();
   end;
//  inherited;
//end;
  if m_TargetCret <> nil then begin
    if  (abs(m_nCurrX-m_nTargetX) > 5) or
             (abs(m_nCurrY-m_nTargetY) > 5) then begin
           // if 5 spaces away teleport to the enemy!
            SendRefMsg(RM_SPACEMOVE_FIRE,0,0,0,0,'');
          SpaceMove(m_TargetCret.M_sMapName, m_TargetCret.m_nCurrX, m_TargetCret.m_nCurrY, 0);
          end;
  end;

    if ((GetTickCount - m_dwSearchEnemyTick) > 8000) or
       (((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil)) then begin
      m_dwSearchEnemyTick:=GetTickCount();
      SearchTarget();
    end;
//  end;
  inherited;
end;

function TCustomMonster.AttackTarget():Boolean;
var
  I: Integer;
  ActorObject: TActorObject;
  nPower:Integer;
  WAbil:pTAbility;
begin
  Result:=False;
  if GetCurrentTime - m_dwHitTick > GetHitSpeed then begin
    m_dwHitTick:=GetCurrentTime;
    SendRefMsg(RM_HIT,m_btDirection,m_nCurrX,m_nCurrY,0,'');
    WAbil:=@m_WAbil;
    nPower:=(Random(SmallInt(HiWord(WAbil.DC) - LoWord(WAbil.DC)) +1) + LoWord(WAbil.DC));
    for I := 0 to m_VisibleActors.Count - 1 do begin
      ActorObject := TActorObject(pTVisibleBaseObject(m_VisibleActors.Items[I]).BaseObject);
      if ActorObject.m_boDeath then Continue;
      if IsProperTarget(ActorObject) then begin
        if (abs(m_nCurrX - ActorObject.m_nCurrX) <= m_nViewRange) and (abs(m_nCurrY - ActorObject.m_nCurrY) <= m_nViewRange) then begin
          SendDelayMsg(Self,RM_DELAYMAGIC,nPower,MakeLong(ActorObject.m_nCurrX,ActorObject.m_nCurrY),1,Integer(ActorObject),'',200);
          SendRefMsg(RM_10205,0,ActorObject.m_nCurrX,ActorObject.m_nCurrY,17{type},'');
        end;
      end;
    end;
    Result:=True;
  end;
end;
 procedure TCustomMonster.RepulseCircle();
var
  I:Integer;
  ActorObject:TActorObject;
  nDir:Byte;
  push:integer;
begin
if m_TargetCret = nil then exit;
 nDir:= GetNextDirection (m_nCurrX, m_nCurrY, m_TargetCret.m_nCurrX, m_TargetCret.m_nCurrY);
 m_btDirection:=nDir;
 SendRefMsg(RM_LIGHTING,nDir,m_nCurrX,m_nCurrY,Integer(self),'');

 for i:=0 to m_VisibleActors.Count-1 do begin
  ActorObject:= TActorObject (pTVisibleBaseObject(m_VisibleActors[i]).BaseObject);
   if (abs(m_nCurrX-ActorObject.m_nCurrX) <= 2) and (abs(m_nCurrY-ActorObject.m_nCurrY) <= 2)
    and ((abs(m_nCurrY - m_TargetCret.m_nCurrY) + abs(m_nCurrX - m_TargetCret.m_nCurrX)) <= 3) then begin

    if (ActorObject <> nil) and not ActorObject.m_boDeath then begin
      if IsProperTarget (ActorObject) then begin
        if Random(50) >= ActorObject.m_nAntiMagic then begin
          push := 1 + Random(3);
          nDir:= GetNextDirection (m_nCurrX, m_nCurrY, ActorObject.m_nCurrX, ActorObject.m_nCurrY);
          ActorObject.CharPushed (nDir, push);
          SendRefMsg(RM_10205,0,ActorObject.m_nCurrX,ActorObject.m_nCurrY,18{type},'');

        end;
      end;
    end;
   end;
  end;
end;

    {================================}
constructor TCustomMonster2.Create;
begin
  inherited;
  m_dwSearchTime:=Random(1500) + 1500;
end;

destructor TCustomMonster2.Destroy;
begin

  inherited;
end;

procedure TCustomMonster2.Run;
var
  time1 : integer;
begin
  if not m_boFixedHideMode and
     not m_boStoneMode and
     not m_boGhost and not m_boDeath and (m_wStatusTimeArr[POISON_DAMAGEARMOR] = 0) then begin
    time1:=random(20);
    if m_TargetCret <> nil then begin

      if IsProperTarget(m_TargetCret) then begin
        m_nTargetX:=m_TargetCret.m_nCurrX;
        m_nTargetY:=m_TargetCret.m_nCurrY;
        if (abs(m_nTargetX-m_nCurrX) = 3) or (abs(m_nTargety-m_nCurry)= 3) then begin
          if (GetTickCount - m_dwThinkTick) > 50 then begin
            m_dwThinkTick:=GetTickCount();
            if time1 < 200 then
              drag();
          end else
            AttackTarget();
        end;
      end;
    end;
    if ((GetTickCount - m_dwSearchEnemyTick) > 8000) or
       (((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil)) then begin
      m_dwSearchEnemyTick:=GetTickCount();
      SearchTarget();
    end;
  end;
  inherited;
end;

function TCustomMonster2.AttackTarget():Boolean;
var
  btDir:Byte;
begin
  Result:=False;
  if m_TargetCret <> nil then begin
    if GetAttackDir(m_TargetCret,btDir) then begin
      if GetCurrentTime - m_dwHitTick > GetHitSpeed then begin
        m_dwHitTick:=GetCurrentTime;
        m_dwTargetFocusTick:=GetTickCount();
        Attack(m_TargetCret,btDir);
      Result:=True;
    end;
  end;
end;
end;

 procedure TCustomMonster2.Drag();
var
  nx,ny: Integer;
  nAttackDir: Integer;
begin
  nAttackDir:=GetNextDirection(m_TargetCret.m_nCurrX,m_TargetCret.m_nCurrY,m_nCurrX,m_nCurrY);
  GetFrontPosition(nx,ny);
  SendRefMsg(RM_LIGHTING,1,m_nCurrX,m_nCurrY,Integer(m_TargetCret),'');

  m_TargetCret.CharPushed(nAttackDir,1);
  if (Random(1) = 0) and (Random(m_TargetCret.m_btAntiPoison + 7) <= 6) then begin
    m_TargetCret.MakePosion(POISON_DECHEALTH,35,2);
    m_TargetCret.MakePosion(POISON_68,Random(60) + 1,1);
    m_TargetCret.MakePosion(POISON_DAMAGEARMOR,Random(60) + 1,1);
    exit;
  end;
end;
       {================================}
constructor TCustomMonster3.Create;
begin
  inherited;
  m_dwSearchTime := Random(1500) + 500;
  dw558 := GetTickCount();
  bo2BF := True;
  n560 := 0;
  bo55C := False;
  bo55D := False;
end;

destructor TCustomMonster3.Destroy;
begin

  inherited;
end;

procedure TCustomMonster3.Attack(TargeTActorObject: TActorObject; nDir: Integer);
var
  WAbil: pTAbility;
  nPower: Integer;
begin
  WAbil := @m_WAbil;
  nPower := GetAttackPower(LoWord(WAbil.DC), Integer(HiWord(WAbil.DC) - LoWord(WAbil.DC)));
  HitMagAttackTarget(TargeTActorObject, nPower div 2, nPower div 2, True);
end;

procedure TCustomMonster3.Initialize;
begin
  dw56C := m_nNextHitTime;
  dw570 := m_nWalkSpeed;
  inherited;
end;

procedure TCustomMonster3.Run;
var
  I: Integer;
  n8, nC, n10, n14, n1C: Integer;
  ActorObject1C, ActorObject: TActorObject;
begin
  n10 := 9999;
  ActorObject := nil;
  ActorObject1C := nil;
  if not m_boDeath and
    not bo554 and
    not m_boGhost and
    (m_wStatusTimeArr[POISON_STONE {5 0x6A}] = 0) then begin
    if Integer(GetTickCount - m_dwWalkTick) >= m_nWalkSpeed then begin
      for I := 0 to m_VisibleActors.Count - 1 do begin
        ActorObject := TActorObject(pTVisibleBaseObject(m_VisibleActors.Items[I]).BaseObject);
        if ActorObject.m_boDeath then Continue;
        if IsProperTarget(ActorObject) then begin
          if not ActorObject.m_boHideMode or m_boCoolEye then begin
            nC := abs(m_nCurrX - ActorObject.m_nCurrX) + abs(m_nCurrY - ActorObject.m_nCurrY);
            if nC < n10 then begin
              n10 := nC;
              ActorObject1C := ActorObject;
            end;
          end;
        end;
      end; // for
      if ActorObject1C <> nil then begin
        m_boRunAwayMode := True;
        m_TargetCret := ActorObject1C;
      n560 := 7 - m_WAbil.HP div (m_WAbil.MaxHP div 7);
    if (n560 >= 4) and (n560 <> n8) then begin
      bo55C := True;
      dw564 := GetTickCount();
      end else begin
        m_boRunAwayMode := False;
        m_TargetCret := nil;
      end;
    end; //
    if m_boRunAwayMode and
      (m_TargetCret <> nil) and
      (Integer(GetTickCount - m_dwWalkTick) >= m_nWalkSpeed) then begin
      if (abs(m_nCurrX - ActorObject.m_nCurrX) <= 16) and (abs(m_nCurrX - ActorObject.m_nCurrX) <= 16) then begin
        n14 := GetNextDirection(m_nCurrX, m_nCurrY, m_TargetCret.m_nCurrX, m_TargetCret.m_nCurrY);
        m_PEnvir.GetNextPosition(m_TargetCret.m_nCurrX, m_TargetCret.m_nCurrY, n14, 7, m_nTargetX, m_nTargetY);
  end;
      if bo55C then begin
      if (GetTickCount - dw564) < 8000 then begin
        m_nNextHitTime := 10000;
      end else begin
        bo55C := False;
        bo55D := True;
        dw568 := GetTickCount();
      end;
    end;
    if bo55D then begin
      if (GetTickCount - dw568) < 8000 then begin
        m_nNextHitTime := 500;
        m_nWalkSpeed := 400;
      end else begin
        bo55D := False;
        m_nNextHitTime := dw56C;
        m_nWalkSpeed := dw570;
      end;
    end;
  end;
  inherited;
end;
 end;
 end;
      {================================}

 constructor TWhiteFox.Create;
begin
  inherited;
  m_dwSearchTime:=Random(1500) + 1500;
  m_dwHitTick:=GetCurrentTime;
end;

destructor TWhiteFox.Destroy;
begin
  inherited;
end;

function TWhiteFox.AttackTarget():Boolean;
var
  nPower:Integer;
  WAbil:pTAbility;
begin
  Result:=False;
  if GetCurrentTime - m_dwHitTick > GetHitSpeed then begin
    m_dwHitTick:=GetCurrentTime;
    SendRefMsg(RM_LIGHTING,m_btDirection,m_nCurrX,m_nCurrY,Integer(m_TargetCret),'');
    WAbil:=@m_WAbil;
    nPower:=(Random(SmallInt(HiWord(WAbil.DC) - LoWord(WAbil.DC)) +1) + LoWord(WAbil.DC));
      if IsProperTarget(m_TargetCret) then begin
        if (abs(m_nCurrX - m_TargetCret.m_nCurrX) <= m_nViewRange) and (abs(m_nCurrY - m_TargetCret.m_nCurrY) <= m_nViewRange) then begin
          SendDelayMsg(Self,RM_DELAYMAGIC,nPower,MakeLong(m_TargetCret.m_nCurrX,m_TargetCret.m_nCurrY),2,Integer(m_TargetCret),'',200);
          if (Random(3) = 0) then
          m_TargetCret.MakePosion(POISON_SLOWDOWN,4,0); 
      end;
    end;
    Result:=True;
  end;
end;

procedure TWhiteFox.MagicAttack(nDir:Integer);
var
  nPower:Integer;
  WAbil:pTAbility;
begin
  if GetCurrentTime - m_dwHitTick > GetHitSpeed then begin
    m_dwHitTick:=GetCurrentTime;
    SendRefMsg(RM_FLYAXE,nDir,m_nCurrX,m_nCurrY,Integer(m_TargetCret),'');
    WAbil:=@m_WAbil;
    nPower:=(Random(SmallInt(HiWord(WAbil.DC) - LoWord(WAbil.DC)) +1) + LoWord(WAbil.DC));
      if IsProperTarget(m_TargetCret) then begin
        if (abs(m_nCurrX - m_TargetCret.m_nCurrX) <= m_nViewRange) and (abs(m_nCurrY - m_TargetCret.m_nCurrY) <= m_nViewRange) then begin
          SendDelayMsg(Self,RM_DELAYMAGIC,nPower,MakeLong(m_TargetCret.m_nCurrX,m_TargetCret.m_nCurrY),1,Integer(m_TargetCret),'',200);
      end;
    end;
  end;
end;

procedure TWhiteFox.Run;
var
nDir:integer;
nCurrX , nCurrY : Integer;
begin
    if CanMove(nCurrX, nCurrY, True) then begin

    if m_TargetCret <> nil then begin
      if (Integer(GetTickCount - m_dwSpellTick) > 6000) then begin
        m_dwSpellTick:=GetTickCount();
        nDir:= GetNextDirection (m_nCurrX, m_nCurrY, m_TargetCret.m_nCurrX, m_TargetCret.m_nCurrY);
        m_btDirection:=nDir;
        if (Random(3) = 0) then begin
        AttackTarget();
        end else begin
        MagicAttack(nDir);
        end;
      end;
    end;

    if ((GetTickCount - m_dwSearchEnemyTick) > 8000) or
       (((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil)) then begin
      m_dwSearchEnemyTick:=GetTickCount();
      SearchTarget();
    end;
  end;
  inherited;
end;
    {================================}

constructor TCustomMonster4.Create;
begin
  inherited;
  m_dwSearchTime:=Random(1500) + 1500;
end;

destructor TCustomMonster4.Destroy;
begin

  inherited;
end;

procedure TCustomMonster4.Run;
var
  time1 : integer;
begin
  if not m_boFixedHideMode and
     not m_boStoneMode and
     not m_boGhost and not m_boDeath and (m_wStatusTimeArr[POISON_DECHEALTH] = 0) then begin
    time1:=random(20);
    if m_TargetCret <> nil then begin

      if IsProperTarget(m_TargetCret) then begin
        m_nTargetX:=m_TargetCret.m_nCurrX;
        m_nTargetY:=m_TargetCret.m_nCurrY;
        if (abs(m_nTargetX-m_nCurrX) = 3) or (abs(m_nTargety-m_nCurry)= 3) then begin
          if (GetTickCount - m_dwThinkTick) > 50 then begin
            m_dwThinkTick:=GetTickCount();
            if time1 < 200 then
              drag();
          end else
            AttackTarget();
        end;
      end;
    end;
    if ((GetTickCount - m_dwSearchEnemyTick) > 8000) or
       (((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil)) then begin
      m_dwSearchEnemyTick:=GetTickCount();
      SearchTarget();
    end;
  end;
  inherited;
end;

function TCustomMonster4.AttackTarget():Boolean;
var
  btDir:Byte;
begin
  Result:=False;
  if m_TargetCret <> nil then begin
    if GetAttackDir(m_TargetCret,btDir) then begin
      if GetCurrentTime - m_dwHitTick > GetHitSpeed then begin
        m_dwHitTick:=GetCurrentTime;
        m_dwTargetFocusTick:=GetTickCount();
        Attack(m_TargetCret,btDir);
      Result:=True;
    end;
  end;
end;
end;

 procedure TCustomMonster4.Drag();
var
  nx,ny: Integer;
  nAttackDir: Integer;
begin
  nAttackDir:=GetNextDirection(m_TargetCret.m_nCurrX,m_TargetCret.m_nCurrY,m_nCurrX,m_nCurrY);
  GetFrontPosition(nx,ny);
  SendRefMsg(RM_LIGHTING,1,m_nCurrX,m_nCurrY,Integer(m_TargetCret),'');

 // m_TargetCret.CharPushed(nAttackDir,1);
  if (Random(1) = 0) and (Random(m_TargetCret.m_btAntiPoison + 7) <= 6) then begin
    m_TargetCret.MakePosion(POISON_SLOWDOWN,5,0);
    exit;
  end;
end;
       {================================}
  {TMinoGuard2}

constructor TMinoGuard2.Create; //004A9690
begin
  inherited;
  m_dwSearchTime:=Random(1500) + 1500;
  m_dwHitTick:=GetCurrentTime;
end;

destructor TMinoGuard2.Destroy;
begin
  inherited;
end;

procedure TMinoGuard2.MagicAttack(nDir:Integer);
var
Target:TActorObject;
magpwr:Integer;
WAbil:pTAbility;
begin
if m_TargetCret <> nil then Target:=m_TargetCret;

SendRefMsg(RM_LIGHTING,nDir,m_nCurrX,m_nCurrY,Integer(Target),'');

 {Hit first Target}
 if IsProperTarget (Target) then begin
  if Random(50) >= Target.m_nAntiMagic then begin
       WAbil:=@m_WAbil;
       magpwr:=(Random(SmallInt(HiWord(WAbil.MC) - LoWord(WAbil.MC)) + 1) + LoWord(WAbil.MC));
       Target.SendDelayMsg (self, RM_MAGSTRUCK, 0, magpwr, 0, 0, '', 600);
      // Target.SendDelayMsg(Target,RM_10205,0,Target.m_nCurrX,Target.m_nCurrY,102{type},'',1000);
  end;
 end;
end;

procedure TMinoGuard2.MagicAttack2(nDir:Integer);
var
Target:TActorObject;
magpwr:Integer;
WAbil:pTAbility;
begin
if m_TargetCret <> nil then Target:=m_TargetCret;

SendRefMsg(RM_FLYAXE,nDir,m_nCurrX,m_nCurrY,Integer(Target),'');

 {Hit first Target}
 if IsProperTarget (Target) then begin
  if Random(50) >= Target.m_nAntiMagic then begin
       WAbil:=@m_WAbil;
       magpwr:=(Random(SmallInt(HiWord(WAbil.MC) - LoWord(WAbil.MC)) + 1) + LoWord(WAbil.MC));
       Target.SendDelayMsg (self, RM_MAGSTRUCK, 0, magpwr, 0, 0, '', 600);
      // Target.SendDelayMsg(Target,RM_10205,0,Target.m_nCurrX,Target.m_nCurrY,102{type},'',1000);
  end;
 end;
end;

procedure TMinoGuard2.Run;//004A9720
var
nAttackDir:integer;
begin
  if not bo554 and CanMove then begin

     if (m_TargetCret <> nil) and
       ((abs(m_nCurrX - m_TargetCret.m_nCurrX) >= 4) or
       (abs(m_nCurrY - m_TargetCret.m_nCurrY) >= 4)) and
       (Integer(GetTickCount - m_dwHitTick) > 2200) then begin
      if MagCanHitTarget(m_nCurrX,m_nCurrY,m_targetCret) then begin //make sure the 'line' in wich magic will go isnt blocked
        m_dwHitTick:=GetCurrentTime;
        nAttackDir:=GetNextDirection(m_nCurrX,m_nCurrY,m_TargetCret.m_nCurrX,m_TargetCret.m_nCurrY);
        if (Random(3) = 0) then
        MagicAttack(nAttackDir)
        else
        MagicAttack2(nAttackDir);
      end;
     end;

    if ((GetTickCount - m_dwSearchEnemyTick) > 8000) or
       (((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil)) then begin
      m_dwSearchEnemyTick:=GetTickCount();
      SearchTarget();
    end;
  end;
  inherited;
end;


        {================================}
  {TOmaLord}

constructor TOmaLord.Create; //004AB120
begin
  inherited;
  m_dwSearchTime := Random(1500) + 1500;
  m_nViewRange := 8;
  m_btDirection := 5;
  m_nDangerLevel := 5;
  m_SlaveObjectList := TList.Create;
end;

destructor TOmaLord.Destroy;
begin
  m_SlaveObjectList.Free;
  inherited;
end;


procedure TOmaLord.CallSlave;
var
  I: Integer;
  nC: Integer;
  n10, n14: Integer;
  //sMonName:array[0..3] of String;
  ActorObject: TActorObject;
begin
  nC := Random(6) + 6;
  GetFrontPosition(n10, n14);
  {
  sMonName[0]:=sZuma1;
  sMonName[1]:=sZuma2;
  sMonName[2]:=sZuma3;
  sMonName[3]:=sZuma4;
  }
  for I := 1 to nC do begin
    if m_SlaveObjectList.Count >= 30 then Break;
    ActorObject := UserEngine.RegenMonsterByName(nil, m_sMapName, n10, n14, g_Config.sOma);
  //  ActorObject := UserEngine.RegenMonsterByName(nil, m_PEnvir.sMapName, m_nCurrX, m_nCurrY, g_Config.sOma);
   // ActorObject := UserEngine.RegenMonsterByName(nil, m_sMapName, n10, n14, g_Config.sZuma[Random(4)]);
    if ActorObject <> nil then begin
      //ActorObject.m_Master:=Self;
      //ActorObject.m_dwMasterRoyaltyTick:=GetTickCount + 24 * 60 * 60 * 1000;
      m_SlaveObjectList.Add(ActorObject);
    end;
  end; // for
end;

procedure TOmaLord.Attack(TargeTActorObject: TActorObject; nDir: Integer); //004AB3E8
var
  WAbil: pTAbility;
  nPower: Integer;
begin
  if TargeTActorObject <> nil then begin
    WAbil := @m_WAbil;
    nPower := GetAttackPower(LoWord(WAbil.DC), Integer(HiWord(WAbil.DC) - LoWord(WAbil.DC)));
    HitMagAttackTarget(TargeTActorObject, 0, nPower, True);
  end;
end;

procedure TOmaLord.Run;
var
  I: Integer;
  n10: Integer;
  ActorObject: TActorObject;
begin
  if (not m_boGhost) and
    (not m_boDeath) and
    (m_wStatusTimeArr[POISON_STONE {5 0x6A}] = 0) and
    (Integer(GetTickCount - m_dwWalkTick) >= m_nWalkSpeed) then begin
    n10 := 0;
    if m_boStoneMode then begin
      //MeltStone();//²βΚΤΣΓ
      for I := 0 to m_VisibleActors.Count - 1 do begin
        ActorObject := TActorObject(pTVisibleBaseObject(m_VisibleActors.Items[I]).BaseObject);
        if ActorObject.m_boDeath then Continue;
        if IsProperTarget(ActorObject) then begin
          if not ActorObject.m_boHideMode or m_boCoolEye then begin
            if (abs(m_nCurrX - ActorObject.m_nCurrX) <= 2) and (abs(m_nCurrY - ActorObject.m_nCurrY) <= 2) then begin
           //   MeltStone();
              Break;
            end;
          end;
        end;
      end; // for
    end else begin
      if ((GetTickCount - m_dwSearchEnemyTick) > 8000) or
        (((GetTickCount - m_dwSearchEnemyTick) > 1000) and (m_TargetCret = nil)) then begin
        m_dwSearchEnemyTick := GetTickCount();
        SearchTarget();
        //CallSlave(); //²βΚΤΣΓ
        if (m_nDangerLevel > m_WAbil.HP / m_WAbil.MaxHP * 5) and (m_nDangerLevel > 0) then begin
          Dec(m_nDangerLevel);
          CallSlave();
        end;
        if m_WAbil.HP = m_WAbil.MaxHP then
          m_nDangerLevel := 5;
      end;
    end;
    for I := m_SlaveObjectList.Count - 1 downto 0 do begin
      if m_SlaveObjectList.Count <= 0 then Break;
      ActorObject := TActorObject(m_SlaveObjectList.Items[I]);
      if ActorObject <> nil then begin
        if ActorObject.m_boDeath or ActorObject.m_boGhost then
          m_SlaveObjectList.Delete(I);
      end;
    end; // for
  end;
  inherited;
end;
{--------------------------------}

end.

