unit AxeMon; //ﵥԪΪʲôҪӸaxe?
//actor.pasֻnpcactor,,humactor,,ûжmonactor

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grobal2, DxDraws, CliUtil, ClFunc, magiceff, Actor, ClEvent;


const
   DEATHEFFECTBASE = 340; //mon3.wilп·ĹӰЧ
   DEATHFIREEFFECTBASE = 2860; //mon3еĹӰЧ
   AXEMONATTACKFRAME = 6; //mon3·520-525,,530-535,,540-545,,
   KUDEGIGASBASE = 1445; //mon3ж綾֭Ч,,ڴmonitem,kudegigas,,?
   COWMONFIREBASE = 1800; //mon4л湥Ч,,,,monitem,,cowmon 껹һ?
   //cowmon?
   COWMONLIGHTBASE = 1900; //mon4ħЧlight??⹥??
   ZOMBILIGHTINGBASE = 350; //mon5е罩ʬļ⹥Ч
   ZOMBIDIEBASE = 340; //mon5е罩ʬĹӰЧ
   ZOMBILIGHTINGEXPBASE = 520; //ǿ
   SCULPTUREFIREBASE = 1680; //mon7ŻĹЧ
   MOTHPOISONGASBASE = 3590; //mon4ƶ綾֭Ч,,ƶڴ˵ֽ
   DUNGPOISONGASBASE = 3590; //mon3кħЫЧ
   WARRIORELFFIREBASE = 820; //warrior elf fire mon18޴ħЧ
//mir2Թ߼ķԴplayscn.pasеfunction  TPlayScene.NewActor()еõһЩο
type
   TSkeletonOma = class (TActor) //·Ͱ
   private
   protected
      EffectSurface: TDirectDrawSurface;
      ax, ay: integer;
   public
      constructor Create; override;
      //destructor Destroy; override;
      procedure CalcActorFrame; override;
      function  GetDefaultFrame (wmode: Boolean): integer; override;
      procedure LoadSurface; override;
      procedure Run; override;
      procedure DrawChr (dsurface: TDirectDrawSurface; dx, dy: integer; blend: Boolean); override;
   end;

   TDualAxeOma = class (TSkeletonOma)  //  //˫֣·??
   private
   public
      procedure Run; override;
   end;

   TCatMon = class (TSkeletonOma) //
   private
   public
      procedure DrawChr (dsurface: TDirectDrawSurface; dx, dy: integer; blend: Boolean); override;
   end;

   TArcherMon = class (TCatMon) //ֹ
   public
      procedure Run; override;
   end;

   TScorpionMon = class (TCatMon) //Ыӹ
   public
   end;

   THuSuABi = class (TSkeletonOma) //
   public
      procedure LoadSurface; override;
   end;

   TZombiDigOut = class (TSkeletonOma) //ʯĹʬ  ,,tskeletonoma,,ʯĹʬ(ʬZombiһ)Ҳڰ޿·?
   public
      procedure RunFrameAction (frame: integer); override;
   end;

   TZombiZilkin = class (TSkeletonOma) 
   public
   end;

   TWhiteSkeleton = class (TSkeletonOma) //ɫ·??
   public
   end;


   TGasKuDeGi = class (TActor) //
   protected
      AttackEffectSurface: TDirectDrawSurface;
      DieEffectSurface: TDirectDrawSurface;
      BoUseDieEffect: Boolean;
      firedir, fire16dir, ax, ay, bx, by: integer;
   public
      constructor Create; override;
      procedure CalcActorFrame; override;
      function  GetDefaultFrame (wmode: Boolean): integer; override;
      procedure LoadSurface; override;
      procedure Run; override;
      procedure DrawChr (dsurface: TDirectDrawSurface; dx, dy: integer; blend: Boolean); override;
      procedure DrawEff (dsurface: TDirectDrawSurface; dx, dy: integer); override;
   end;

   TFireCowFaceMon = class (TGasKuDeGi)
   public
      function   Light: integer; override;
   end;

   TCowFaceKing = class (TGasKuDeGi)
   public
      function   Light: integer; override;
   end;

   TZombiLighting = class (TGasKuDeGi)
   protected
   public
   end;

   TSculptureMon = class (TSkeletonOma) //?
   private
      AttackEffectSurface: TDirectDrawSurface;
      ax, ay, firedir: integer;
   public
      procedure CalcActorFrame; override;
      procedure LoadSurface; override;
      function  GetDefaultFrame (wmode: Boolean): integer; override;
      procedure DrawEff (dsurface: TDirectDrawSurface; dx, dy: integer); override;
      procedure Run; override;
   end;

   TSculptureKingMon = class (TSculptureMon) //֮?ʲô?
   public
   end;

   TSmallElfMonster = class (TSkeletonOma) //elf,,С飬, , ˣ
   public
   end;

   TWarriorElfMonster = class (TSkeletonOma) //warrior,,ʿ ,,,ʿ=(,뿿CQʵ+Դ½˼)
   private
      oldframe: integer;
   public
      procedure  RunFrameAction (frame: integer); override;  //Ӹ Ưϰ ؾ
   end;



implementation

uses
   ClMain;


{============================== TSkeletonOma =============================}

//      ذ (ذ, ūذ, ذ)

{--------------------------}


constructor TSkeletonOma.Create;
begin
   inherited Create;
   EffectSurface := nil;
   BoUseEffect := FALSE;
end;

procedure TSkeletonOma.CalcActorFrame;
var
   pm: PTMonsterAction;
   haircount: integer; //ͷ??
begin
   currentframe := -1;
   ReverseFrame := FALSE; //Ƿת֡
   BoUseEffect := FALSE;

   BodyOffset := GetOffset (Appearance);
   pm := RaceByPM (Race);
   if pm = nil then exit;

   case CurrentAction of
      SM_TURN: 
         begin
            startframe := pm.ActStand.start + Dir * (pm.ActStand.frame + pm.ActStand.skip);
            endframe := startframe + pm.ActStand.frame - 1;
            frametime := pm.ActStand.ftime;
            starttime := GetTickCount;
            defframecount := pm.ActStand.frame;
            Shift (Dir, 0, 0, 1);
         end;
      SM_WALK, SM_BACKSTEP:
         begin
            startframe := pm.ActWalk.start + Dir * (pm.ActWalk.frame + pm.ActWalk.skip);
            endframe := startframe + pm.ActWalk.frame - 1;
            frametime := pm.ActWalk.ftime;
            starttime := GetTickCount;
            maxtick := pm.ActWalk.UseTick;
            curtick := 0;
            //WarMode := FALSE;
            movestep := 1;
            if CurrentAction = SM_WALK then
               Shift (Dir, movestep, 0, endframe-startframe+1)
            else  //sm_backstep
               Shift (GetBack(Dir), movestep, 0, endframe-startframe+1);
         end;
      SM_DIGUP: //ȱ , SM_DIGUP,  .
         begin
            if (Race = 23) then begin //or (Race = 54) or (Race = 55) then begin
               //
               startframe := pm.ActDeath.start;
            end else begin
               startframe := pm.ActDeath.start + Dir * (pm.ActDeath.frame + pm.ActDeath.skip);
            end;
            endframe := startframe + pm.ActDeath.frame - 1;
            frametime := pm.ActDeath.ftime;
            starttime := GetTickCount;
            //WarMode := FALSE;
            Shift (Dir, 0, 0, 1);
         end;
      SM_DIGDOWN:
         begin
            if Race = 55 then begin
               //ż1   
               startframe := pm.ActCritical.start + Dir * (pm.ActCritical.frame + pm.ActCritical.skip);
               endframe := startframe + pm.ActCritical.frame - 1;
               frametime := pm.ActCritical.ftime;
               starttime := GetTickCount;
               ReverseFrame := TRUE;
               //WarMode := FALSE;
               Shift (Dir, 0, 0, 1);
            end;
         end;
      SM_HIT,
      SM_FLYAXE,
      SM_LIGHTING: //繥,ţħʦ
         begin
            startframe := pm.ActAttack.start + Dir * (pm.ActAttack.frame + pm.ActAttack.skip);
            endframe := startframe + pm.ActAttack.frame - 1;
            frametime := pm.ActAttack.ftime;
            starttime := GetTickCount;
            //WarMode := TRUE;
            WarModeTime := GetTickCount;
            if (Race = 16) or (Race = 54) then
               BoUseEffect := TRUE;
            Shift (Dir, 0, 0, 1);
         end;
      SM_STRUCK:
         begin
            startframe := pm.ActStruck.start + Dir * (pm.ActStruck.frame + pm.ActStruck.skip);
            endframe := startframe + pm.ActStruck.frame - 1;
            frametime := struckframetime; //pm.ActStruck.ftime;
            starttime := GetTickCount;
         end;
      SM_DEATH:
         begin
            startframe := pm.ActDie.start + Dir * (pm.ActDie.frame + pm.ActDie.skip);
            endframe := startframe + pm.ActDie.frame - 1;
            startframe := endframe; //
            frametime := pm.ActDie.ftime;
            starttime := GetTickCount;
         end;
      SM_NOWDEATH:
         begin
            startframe := pm.ActDie.start + Dir * (pm.ActDie.frame + pm.ActDie.skip);
            endframe := startframe + pm.ActDie.frame - 1;
            frametime := pm.ActDie.ftime;
            starttime := GetTickCount;
            if Race <> 22 then
               BoUseEffect := TRUE;
         end;
      SM_SKELETON:
         begin
            startframe := pm.ActDeath.start;
            endframe := startframe + pm.ActDeath.frame - 1;
            frametime := pm.ActDeath.ftime;
            starttime := GetTickCount;
         end;
      SM_ALIVE:
         begin
            startframe := pm.ActDeath.start + Dir * (pm.ActDeath.frame + pm.ActDeath.skip);
            endframe := startframe + pm.ActDeath.frame - 1;
            frametime := pm.ActDeath.ftime;
            starttime := GetTickCount;
         end;
   end;
end;

function  TSkeletonOma.GetDefaultFrame (wmode: Boolean): integer;
var
   cf, dr: integer;
   pm: PTMonsterAction;
begin
   pm := RaceByPM (Race);
   if pm = nil then exit;

   if Death then begin
      // 
      if Appearance in [30..34, 151] then //  ü     
         DownDrawLevel := 1;

      if Skeleton then
         Result := pm.ActDeath.start
      else Result := pm.ActDie.start + Dir * (pm.ActDie.frame + pm.ActDie.skip) + (pm.ActDie.frame - 1);
   end else begin
      defframecount := pm.ActStand.frame;
      if currentdefframe < 0 then cf := 0
      else if currentdefframe >= pm.ActStand.frame then cf := 0
      else cf := currentdefframe;
      Result := pm.ActStand.start + Dir * (pm.ActStand.frame + pm.ActStand.skip) + cf;
   end;
end;

procedure  TSkeletonOma.LoadSurface;
begin
   inherited LoadSurface;
   case Race of
      //
      14, 15, 17, 22, 53: 
         begin
            if BoUseEffect then
               EffectSurface := FrmMain.WMon3Img.GetCachedImage (DEATHEFFECTBASE + currentframe-startframe, ax, ay);
         end;
      23:
         begin
            if CurrentAction = SM_DIGUP then begin
               BodySurface := nil;
               EffectSurface := FrmMain.WMon4Img.GetCachedImage (BodyOffset + currentframe, ax, ay);
               BoUseEffect := TRUE;
            end else
               BoUseEffect := FALSE;
         end;
   end;
end;

procedure  TSkeletonOma.Run;
var
   prv: integer;
   frametimetime: longword;
begin
   if (CurrentAction = SM_WALK) or (CurrentAction = SM_BACKSTEP) or (CurrentAction = SM_RUN) then exit;

   msgmuch := FALSE;
   if MsgList.Count >= 2 then msgmuch := TRUE;

   // ȿ
   RunActSound (currentframe - startframe);
   RunFrameAction (currentframe - startframe);

   prv := currentframe;
   if CurrentAction <> 0 then begin
      if (currentframe < startframe) or (currentframe > endframe) then
         currentframe := startframe;

      if msgmuch then frametimetime := Round(frametime * 2 / 3)
      else frametimetime := frametime;

      if GetTickCount - starttime > frametimetime then begin
         if currentframe < endframe then begin
            Inc (currentframe);
            starttime := GetTickCount;
         end else begin
            // .
            CurrentAction := 0; // Ϸ
            BoUseEffect := FALSE;
         end;
      end;
      currentdefframe := 0;
      defframetime := GetTickCount;
   end else begin
      if GetTickCount - smoothmovetime > 200 then begin
         if GetTickCount - defframetime > 500 then begin
            defframetime := GetTickCount;
            Inc (currentdefframe);
            if currentdefframe >= defframecount then
               currentdefframe := 0;
         end;
         DefaultMotion;
      end;
   end;

   if prv <> currentframe then begin
      loadsurfacetime := GetTickCount;
      LoadSurface;
   end;

end;


procedure TSkeletonOma.DrawChr (dsurface: TDirectDrawSurface; dx, dy: integer; blend: Boolean);
var
   idx: integer;
   d: TDirectDrawSurface;
   ceff: TColorEffect;
begin
   if not (Dir in [0..7]) then exit;
   if GetTickCount - loadsurfacetime > 60 * 1000 then begin
      loadsurfacetime := GetTickCount;
      LoadSurface; //bodysurface loadsurface ٽ θ ʾ ޸𸮰 Ǵ  
   end;

   ceff := GetDrawEffectValue;

   if BodySurface <> nil then begin
      DrawEffSurface (dsurface, BodySurface, dx + px + ShiftX, dy + py + ShiftY, blend, ceff);
   end;

   if BoUseEffect then
      if EffectSurface <> nil then begin
         DrawBlend (dsurface,
                    dx + ax + ShiftX,
                    dy + ay + ShiftY,
                    EffectSurface, 1);
      end;
end;




{============================== TSkeletonOma =============================}

//      ذ (ذ, ūذ, ذ)

{--------------------------}


procedure  TDualAxeOma.Run;
var
   prv: integer;
   frametimetime: longword;
   meff: TFlyingAxe;
begin
   if (CurrentAction = SM_WALK) or (CurrentAction = SM_BACKSTEP) or (CurrentAction = SM_RUN) then exit;

   msgmuch := FALSE;
   if MsgList.Count >= 2 then msgmuch := TRUE;

   // ȿ
   RunActSound (currentframe - startframe);
   //Ӹ ؾ 
   RunFrameAction (currentframe - startframe);

   prv := currentframe;
   if CurrentAction <> 0 then begin
      if (currentframe < startframe) or (currentframe > endframe) then
         currentframe := startframe;

      if msgmuch then frametimetime := Round(frametime * 2 / 3)
      else frametimetime := frametime;

      if GetTickCount - starttime > frametimetime then begin
         if currentframe < endframe then begin
            Inc (currentframe);
            starttime := GetTickCount;
         end else begin
            // .
            CurrentAction := 0; // Ϸ
            BoUseEffect := FALSE;
         end;
         if (CurrentAction = SM_FLYAXE) and (currentframe-startframe = AXEMONATTACKFRAME-4) then begin //  
            // ߻
            meff := TFlyingAxe (PlayScene.NewFlyObject (self,
                             XX,
                             YY,
                             TargetX,
                             TargetY,
                             TargetRecog,
                             mtFlyAxe));
            if meff <> nil then begin
               meff.ImgLib := FrmMain.WMon3Img;
               case Race of
                  15: meff.FlyImageBase := FLYOMAAXEBASE;
                  22: meff.FlyImageBase := THORNBASE;
               end;
            end;      
         end;
      end;
      currentdefframe := 0;
      defframetime := GetTickCount;
   end else begin
      if GetTickCount - smoothmovetime > 200 then begin
         if GetTickCount - defframetime > 500 then begin
            defframetime := GetTickCount;
            Inc (currentdefframe);
            if currentdefframe >= defframecount then
               currentdefframe := 0;
         end;
         DefaultMotion;
      end;
   end;

   if prv <> currentframe then begin
      loadsurfacetime := GetTickCount;
      LoadSurface;
   end;

end;


{============================== TGasKuDeGi =============================}

//         TCatMon : ,   ذ̶ ,  ִϰ .
//ẫģôز½


procedure  TWarriorElfMonster.RunFrameAction (frame: integer); //Ӹ Ưϰ ؾ
var
   meff: TMapEffect;
   event: TClEvent;
begin
   if CurrentAction = SM_HIT then begin
      if (frame = 5) and (oldframe <> frame) then begin
         meff := TMapEffect.Create (WARRIORELFFIREBASE + 10 * Dir + 1, 5, XX, YY);
         meff.ImgLib := FrmMain.WMon18Img;
         meff.NextFrameTime := 100;
         PlayScene.EffectList.Add (meff);
      end;
      oldframe := frame;
   end;
end;

{============================== TGasKuDeGi =============================}

//         TCatMon : ,   ذ̶ ,  ִϰ .

{--------------------------}


procedure TCatMon.DrawChr (dsurface: TDirectDrawSurface; dx, dy: integer; blend: Boolean);
var
   idx: integer;
   d: TDirectDrawSurface;
   ceff: TColorEffect;
begin
   if not (Dir in [0..7]) then exit;
   if GetTickCount - loadsurfacetime > 60 * 1000 then begin
      loadsurfacetime := GetTickCount;
      LoadSurface; //bodysurface loadsurface ٽ θ ʾ ޸𸮰 Ǵ  
   end;

   ceff := GetDrawEffectValue;

   if BodySurface <> nil then
      DrawEffSurface (dsurface, BodySurface, dx + px + ShiftX, dy + py + ShiftY, blend, ceff);

end;


{============================= TArcherMon =============================}


procedure TArcherMon.Run;
var
   prv: integer;
   frametimetime: longword;
   meff: TFlyingAxe;
begin
   if (CurrentAction = SM_WALK) or (CurrentAction = SM_BACKSTEP) or (CurrentAction = SM_RUN) then exit;

   msgmuch := FALSE;
   if MsgList.Count >= 2 then msgmuch := TRUE;

   // ȿ
   RunActSound (currentframe - startframe);
   //Ӹ ؾ 
   RunFrameAction (currentframe - startframe);

   prv := currentframe;
   if CurrentAction <> 0 then begin
      if (currentframe < startframe) or (currentframe > endframe) then
         currentframe := startframe;

      if msgmuch then frametimetime := Round(frametime * 2 / 3)
      else frametimetime := frametime;

      if GetTickCount - starttime > frametimetime then begin
         if currentframe < endframe then begin
            Inc (currentframe);
            starttime := GetTickCount;
         end else begin
            // .
            CurrentAction := 0; // Ϸ
            BoUseEffect := FALSE;
         end;
         if (CurrentAction = SM_FLYAXE) and (currentframe-startframe = 4) then begin
            //ȭ 
//(** 6ġ

            meff := TFlyingArrow (PlayScene.NewFlyObject (self,
                             XX,
                             YY,
                             TargetX,
                             TargetY,
                             TargetRecog,
                             mtFlyArrow));
            if meff <> nil then begin
               meff.ImgLib := FrmMain.WEffectImg; //WMon5Img;
               meff.NextFrameTime := 30;
               meff.FlyImageBase := ARCHERBASE2;
            end;
//**)
(** 
            meff := TFlyingArrow (PlayScene.NewFlyObject (self,
                             XX,
                             YY,
                             TargetX,
                             TargetY,
                             TargetRecog,
                             mtFlyAxe));
            if meff <> nil then begin
               meff.ImgLib := FrmMain.WMon5Img;
               meff.NextFrameTime := 30;
               meff.FlyImageBase := ARCHERBASE;
            end;
//**)
         end;
      end;
      currentdefframe := 0;
      defframetime := GetTickCount;
   end else begin
      if GetTickCount - smoothmovetime > 200 then begin
         if GetTickCount - defframetime > 500 then begin
            defframetime := GetTickCount;
            Inc (currentdefframe);
            if currentdefframe >= defframecount then
               currentdefframe := 0;
         end;
         DefaultMotion;
      end;
   end;

   if prv <> currentframe then begin
      loadsurfacetime := GetTickCount;
      LoadSurface;
   end;

end;


{============================= TZombiDigOut =============================}


procedure TZombiDigOut.RunFrameAction (frame: integer);
var
   clevent: TClEvent;
begin
   if CurrentAction = SM_DIGUP then begin
      if frame = 6 then begin
         clevent := TClEvent.Create (CurrentEvent, XX, YY, ET_DIGOUTZOMBI);
         clevent.Dir := Dir;
         EventMan.AddEvent (clevent);
         //pdo.DSurface := FrmMain.WMon6Img.GetCachedImage (ZOMBIDIGUPDUSTBASE+Dir, pdo.px, pdo.py);
//zombi,,ʬ࣬ʬ罩ʬнʬ
//һ±Ĵͻ˵¼ʢ棬¹11ȵ,11ǹrace?
      end;
   end;
end;


{============================== THuSuABi =============================}

//      ƺ

{--------------------------}


procedure  THuSuABi.LoadSurface;
begin
   inherited LoadSurface;
   if BoUseEffect then
      EffectSurface := FrmMain.WMon3Img.GetCachedImage (DEATHFIREEFFECTBASE + currentframe-startframe, ax, ay);
end;


{============================== TGasKuDeGi =============================}

//       ( )

{--------------------------}


constructor TGasKuDeGi.Create;
begin
   inherited Create;
   AttackEffectSurface := nil;
   DieEffectSurface := nil;
   BoUseEffect := FALSE;
   BoUseDieEffect := FALSE;
end;

procedure TGasKuDeGi.CalcActorFrame;
var
   pm: PTMonsterAction;
   actor: TActor;
   haircount, scx, scy, stx, sty: integer;
   meff: TCharEffect;
begin
   currentframe := -1;

   BodyOffset := GetOffset (Appearance);
   pm := RaceByPM (Race);
   if pm = nil then exit;

   case CurrentAction of
      SM_TURN:
         begin
            startframe := pm.ActStand.start + Dir * (pm.ActStand.frame + pm.ActStand.skip);
            endframe := startframe + pm.ActStand.frame - 1;
            frametime := pm.ActStand.ftime;
            starttime := GetTickCount;
            defframecount := pm.ActStand.frame;
            Shift (Dir, 0, 0, 1);
         end;
      SM_WALK:
         begin
            startframe := pm.ActWalk.start + Dir * (pm.ActWalk.frame + pm.ActWalk.skip);
            endframe := startframe + pm.ActWalk.frame - 1;
            frametime := pm.ActWalk.ftime;
            starttime := GetTickCount;
            maxtick := pm.ActWalk.UseTick;
            curtick := 0;
            //WarMode := FALSE;
            movestep := 1;
            if CurrentAction = SM_WALK then
               Shift (Dir, movestep, 0, endframe-startframe+1)
            else  //sm_backstep
               Shift (GetBack(Dir), movestep, 0, endframe-startframe+1);
         end;
      SM_HIT,
      SM_LIGHTING:
         begin
            startframe := pm.ActAttack.start + Dir * (pm.ActAttack.frame + pm.ActAttack.skip);
            endframe := startframe + pm.ActAttack.frame - 1;
            frametime := pm.ActAttack.ftime;
            starttime := GetTickCount;
            //WarMode := TRUE;
            WarModeTime := GetTickCount;
            Shift (Dir, 0, 0, 1);
            BoUseEffect := TRUE;
            firedir := Dir;
            effectframe := startframe;
            effectstart := startframe;
            if Race = 20 then effectend := endframe + 1
            else effectend := endframe;
            effectstarttime := GetTickCount;
            effectframetime := frametime;

            //16  
            actor := PlayScene.FindActor (TargetRecog);
            if actor <> nil then begin
               PlayScene.ScreenXYfromMCXY (XX, YY, scx, scy);
               PlayScene.ScreenXYfromMCXY (actor.XX, actor.YY, stx, sty);
               fire16dir := GetFlyDirection16 (scx, scy, stx, sty);
               //meff := TCharEffect.Create (ZOMBILIGHTINGEXPBASE, 12, actor);  //´  ȿ
               //meff.ImgLib := FrmMain.WMon5Img;
               //meff.NextFrameTime := 50;
               //PlayScene.EffectList.Add (meff);
            end else
               fire16dir := firedir * 2;
         end;
      SM_STRUCK:
         begin
            startframe := pm.ActStruck.start + Dir * (pm.ActStruck.frame + pm.ActStruck.skip);
            endframe := startframe + pm.ActStruck.frame - 1;
            frametime := struckframetime; //pm.ActStruck.ftime;
            starttime := GetTickCount;
         end;
      SM_DEATH:
         begin
            startframe := pm.ActDie.start + Dir * (pm.ActDie.frame + pm.ActDie.skip);
            endframe := startframe + pm.ActDie.frame - 1;
            startframe := endframe; //
            frametime := pm.ActDie.ftime;
            starttime := GetTickCount;
         end;
      SM_NOWDEATH:
         begin
            startframe := pm.ActDie.start + Dir * (pm.ActDie.frame + pm.ActDie.skip);
            endframe := startframe + pm.ActDie.frame - 1;
            frametime := pm.ActDie.ftime;
            starttime := GetTickCount;

            if Race = 40 then  // 
               BoUseDieEffect := TRUE;
         end;
      SM_SKELETON:
         begin
            startframe := pm.ActDeath.start;
            endframe := startframe + pm.ActDeath.frame - 1;
            frametime := pm.ActDeath.ftime;
            starttime := GetTickCount;
         end;
   end;
end;

function  TGasKuDeGi.GetDefaultFrame (wmode: Boolean): integer;
var
   cf, dr: integer;
   pm: PTMonsterAction;
begin
   pm := RaceByPM (Race);
   if pm = nil then exit;

   if Death then begin
      if Skeleton then
         Result := pm.ActDeath.start
      else Result := pm.ActDie.start + Dir * (pm.ActDie.frame + pm.ActDie.skip) + (pm.ActDie.frame - 1);
   end else begin
      defframecount := pm.ActStand.frame;
      if currentdefframe < 0 then cf := 0
      else if currentdefframe >= pm.ActStand.frame then cf := 0
      else cf := currentdefframe;
      Result := pm.ActStand.start + Dir * (pm.ActStand.frame + pm.ActStand.skip) + cf;
   end;
end;

procedure  TGasKuDeGi.LoadSurface;
begin
   inherited LoadSurface;
   case Race of
      //
      16:
         begin
            if BoUseEffect then
               AttackEffectSurface := FrmMain.WMon3Img.GetCachedImage (
                        KUDEGIGASBASE-1 + (firedir * 10) + effectframe-effectstart, // ó  ʰ .
                        ax, ay);
         end;
      20:
         begin
            if BoUseEffect then
               AttackEffectSurface := FrmMain.WMon4Img.GetCachedImage (
                        COWMONFIREBASE + (firedir * 10) + effectframe-effectstart, //
                        ax, ay);
         end;
      21:
         begin
            if BoUseEffect then
               AttackEffectSurface := FrmMain.WMon4Img.GetCachedImage (
                        COWMONLIGHTBASE + (firedir * 10) + effectframe-effectstart, //
                        ax, ay);
         end;
      40:
         begin
            if BoUseEffect then begin
               AttackEffectSurface := FrmMain.WMon5Img.GetCachedImage (
                        ZOMBILIGHTINGBASE + (fire16dir * 10) + effectframe-effectstart, //
                        ax, ay);
            end;
            if BoUseDieEffect then begin
               DieEffectSurface := FrmMain.WMon5Img.GetCachedImage (
                        ZOMBIDIEBASE + currentframe-startframe, //
                        bx, by);
            end;
         end;
      52:
         begin
            if BoUseEffect then
               AttackEffectSurface := FrmMain.WMon4Img.GetCachedImage (
                        MOTHPOISONGASBASE + (firedir * 10) + effectframe-effectstart, //
                        ax, ay);
         end;
      53:
         begin
            if BoUseEffect then
               AttackEffectSurface := FrmMain.WMon3Img.GetCachedImage (
                        DUNGPOISONGASBASE + (firedir * 10) + effectframe-effectstart, //
                        ax, ay);
         end;
   end;
end;

procedure  TGasKuDeGi.Run;
var
   prv: integer;
   effectframetimetime, frametimetime: longword;
begin
   if (CurrentAction = SM_WALK) or (CurrentAction = SM_BACKSTEP) or (CurrentAction = SM_RUN) then exit;

   msgmuch := FALSE;
   if MsgList.Count >= 2 then msgmuch := TRUE;

   // ȿ
   RunActSound (currentframe - startframe);
   RunFrameAction (currentframe - startframe);

   if BoUseEffect then begin
      if msgmuch then effectframetimetime := Round(effectframetime * 2 / 3)
      else effectframetimetime := effectframetime;
      if GetTickCount - effectstarttime > effectframetimetime then begin
         effectstarttime := GetTickCount;
         if effectframe < effectend then begin
            Inc (effectframe);
         end else begin
            BoUseEffect := FALSE;
         end;
      end;
   end;

   prv := currentframe;
   if CurrentAction <> 0 then begin
      if (currentframe < startframe) or (currentframe > endframe) then
         currentframe := startframe;

      if msgmuch then frametimetime := Round(frametime * 2 / 3)
      else frametimetime := frametime;

      if GetTickCount - starttime > frametimetime then begin
         if currentframe < endframe then begin
            Inc (currentframe);
            starttime := GetTickCount;
         end else begin
            // .
            CurrentAction := 0; // Ϸ
            BoUseDieEffect := FALSE;
         end;

      end;
      currentdefframe := 0;
      defframetime := GetTickCount;
   end else begin
      if GetTickCount - smoothmovetime > 200 then begin
         if GetTickCount - defframetime > 500 then begin
            defframetime := GetTickCount;
            Inc (currentdefframe);
            if currentdefframe >= defframecount then
               currentdefframe := 0;
         end;
         DefaultMotion;
      end;
   end;

   if prv <> currentframe then begin
      loadsurfacetime := GetTickCount;
      LoadSurface;
   end;

end;


procedure TGasKuDeGi.DrawChr (dsurface: TDirectDrawSurface; dx, dy: integer; blend: Boolean);
var
   idx: integer;
   d: TDirectDrawSurface;
   ceff: TColorEffect;
begin
   if not (Dir in [0..7]) then exit;
   if GetTickCount - loadsurfacetime > 60 * 1000 then begin
      loadsurfacetime := GetTickCount;
      LoadSurface; //bodysurface loadsurface ٽ θ ʾ ޸𸮰 Ǵ  
   end;

   ceff := GetDrawEffectValue;

   if BodySurface <> nil then
      DrawEffSurface (dsurface, BodySurface, dx + px + ShiftX, dy + py + ShiftY, blend, ceff);

end;

procedure TGasKuDeGi.DrawEff (dsurface: TDirectDrawSurface; dx, dy: integer);
var
   idx: integer;
   d: TDirectDrawSurface;
   ceff: TColorEffect;
begin
   if BoUseEffect then
      if AttackEffectSurface <> nil then begin
         DrawBlend (dsurface,
                    dx + ax + ShiftX,
                    dy + ay + ShiftY,
                    AttackEffectSurface, 1);
      end;
   if BoUseDieEffect then
      if DieEffectSurface <> nil then begin
         DrawBlend (dsurface,
                    dx + bx + ShiftX,
                    dy + by + ShiftY,
                    DieEffectSurface, 1);
      end;
end;



{-----------------------------------------------------------}

function  TFireCowFaceMon.Light: integer; //ţ??
var
   l: integer;
begin
   l := ChrLight;
   if l < 2 then begin
      if BoUseEffect then
         l := 2;
   end;
   Result := l;
end;

function  TCowFaceKing.Light: integer; //ţħ??,,
var
   l: integer;
begin
   l := ChrLight;
   if l < 2 then begin
      if BoUseEffect then
         l := 2;
   end;
   Result := l;
end;


{-----------------------------------------------------------}

//procedure TZombiLighting.Run;


{-----------------------------------------------------------}


procedure TSculptureMon.CalcActorFrame;
var
   pm: PTMonsterAction;
   haircount: integer;
begin
   currentframe := -1;

   BodyOffset := GetOffset (Appearance);
   pm := RaceByPM (Race);
   if pm = nil then exit;
   BoUseEffect := FALSE;

   case CurrentAction of
      SM_TURN:
         begin
            if (State and STATE_STONE_MODE) <> 0 then begin
               if (Race = 48) or (Race = 49) then
                  startframe := pm.ActDeath.start // + Dir * (pm.ActDeath.frame + pm.ActDeath.skip)
               else
                  startframe := pm.ActDeath.start + Dir * (pm.ActDeath.frame + pm.ActDeath.skip);
               endframe := startframe;
               frametime := pm.ActDeath.ftime;
               starttime := GetTickCount;
               defframecount := pm.ActDeath.frame;
            end else begin
               startframe := pm.ActStand.start + Dir * (pm.ActStand.frame + pm.ActStand.skip);
               endframe := startframe + pm.ActStand.frame - 1;
               frametime := pm.ActStand.ftime;
               starttime := GetTickCount;
               defframecount := pm.ActStand.frame;
            end;
            Shift (Dir, 0, 0, 1);
         end;
      SM_WALK, SM_BACKSTEP:
         begin
            startframe := pm.ActWalk.start + Dir * (pm.ActWalk.frame + pm.ActWalk.skip);
            endframe := startframe + pm.ActWalk.frame - 1;
            frametime := pm.ActWalk.ftime;
            starttime := GetTickCount;
            maxtick := pm.ActWalk.UseTick;
            curtick := 0;
            //WarMode := FALSE;
            movestep := 1;
            if CurrentAction = SM_WALK then
               Shift (Dir, movestep, 0, endframe-startframe+1)
            else  //sm_backstep
               Shift (GetBack(Dir), movestep, 0, endframe-startframe+1);
         end;
      SM_DIGUP: //ȱ , SM_DIGUP,  .
         begin
            if (Race = 48) or (Race = 49) then begin
               startframe := pm.ActDeath.start;
            end else begin
               startframe := pm.ActDeath.start + Dir * (pm.ActDeath.frame + pm.ActDeath.skip);
            end;
            endframe := startframe + pm.ActDeath.frame - 1;
            frametime := pm.ActDeath.ftime;
            starttime := GetTickCount;
            //WarMode := FALSE;
            Shift (Dir, 0, 0, 1);
         end;
      SM_HIT:
         begin
            startframe := pm.ActAttack.start + Dir * (pm.ActAttack.frame + pm.ActAttack.skip);
            endframe := startframe + pm.ActAttack.frame - 1;
            frametime := pm.ActAttack.ftime;
            starttime := GetTickCount;
            if Race = 49 then begin
               BoUseEffect := TRUE;
               firedir := Dir;
               effectframe := 0; //startframe;
               effectstart := 0; //startframe;
               effectend := effectstart + 8;
               effectstarttime := GetTickCount;
               effectframetime := frametime;
            end;
            Shift (Dir, 0, 0, 1);
         end;
      SM_STRUCK:
         begin
            startframe := pm.ActStruck.start + Dir * (pm.ActStruck.frame + pm.ActStruck.skip);
            endframe := startframe + pm.ActStruck.frame - 1;
            frametime := struckframetime; //pm.ActStruck.ftime;
            starttime := GetTickCount;
         end;
      SM_DEATH:
         begin
            startframe := pm.ActDie.start + Dir * (pm.ActDie.frame + pm.ActDie.skip);
            endframe := startframe + pm.ActDie.frame - 1;
            startframe := endframe; //
            frametime := pm.ActDie.ftime;
            starttime := GetTickCount;
         end;
      SM_NOWDEATH:
         begin
            startframe := pm.ActDie.start + Dir * (pm.ActDie.frame + pm.ActDie.skip);
            endframe := startframe + pm.ActDie.frame - 1;
            frametime := pm.ActDie.ftime;
            starttime := GetTickCount;
         end;
   end;
end;

procedure  TSculptureMon.LoadSurface;
begin
   inherited LoadSurface;
   case Race of
      48, 49:
         begin
            if BoUseEffect then
               AttackEffectSurface := FrmMain.WMon7Img.GetCachedImage (
                        SCULPTUREFIREBASE + (firedir * 10) + effectframe-effectstart, //
                        ax, ay);
         end;
   end;
end;

function  TSculptureMon.GetDefaultFrame (wmode: Boolean): integer;
var
   cf, dr: integer;
   pm: PTMonsterAction;
begin
   pm := RaceByPM (Race);
   if pm = nil then exit;

   if Death then begin
      Result := pm.ActDie.start + Dir * (pm.ActDie.frame + pm.ActDie.skip) + (pm.ActDie.frame - 1);
   end else begin
      if (State and STATE_STONE_MODE) <> 0 then begin
         case Race of
            47: Result := pm.ActDeath.start + Dir * (pm.ActDeath.frame + pm.ActDeath.skip);
            48, 49: Result := pm.ActDeath.start;
         end;
      end else begin
         defframecount := pm.ActStand.frame;
         if currentdefframe < 0 then cf := 0
         else if currentdefframe >= pm.ActStand.frame then cf := 0
         else cf := currentdefframe;
         Result := pm.ActStand.start + Dir * (pm.ActStand.frame + pm.ActStand.skip) + cf;
      end;
   end;
end;

procedure TSculptureMon.DrawEff (dsurface: TDirectDrawSurface; dx, dy: integer);
var
   idx: integer;
   d: TDirectDrawSurface;
   ceff: TColorEffect;
begin
   if BoUseEffect then
      if AttackEffectSurface <> nil then begin
         DrawBlend (dsurface,
                    dx + ax + ShiftX,
                    dy + ay + ShiftY,
                    AttackEffectSurface, 1);
      end;
end;

procedure TSculptureMon.Run;
var
   effectframetimetime, frametimetime: longword;
begin
   if (CurrentAction = SM_WALK) or (CurrentAction = SM_BACKSTEP) or (CurrentAction = SM_RUN) then exit;
   if BoUseEffect then begin
      effectframetimetime := effectframetime;
      if GetTickCount - effectstarttime > effectframetimetime then begin
         effectstarttime := GetTickCount;
         if effectframe < effectend then begin
            Inc (effectframe);
         end else begin
            BoUseEffect := FALSE;
         end;
      end;
   end;
   inherited Run;
end;


end.
