⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umonster.pas

📁 千年源代码,只缺少控件,可以做二次开发用,好不容易得来的
💻 PAS
📖 第 1 页 / 共 3 页
字号:
unit uMonster;

interface

uses
  Windows, Classes, SysUtils, svClass,subutil, uAnsTick, AnsUnit,
  BasicObj, FieldMsg, MapUnit, DefType, Autil32, aiunit, uUser,
  uAIPath, uManager, uSkills, uMopSub;

type

   TMonster = class (TLifeObject)
   private
      pSelfData : PTMonsterData;

      AttackSkill : TAttackSkill;

      HaveItemClass : TMopHaveItemClass;
      HaveMagicClass : TMopHaveMagicClass;

      procedure  SetAttackSkillData;
   protected
      procedure  SetMonsterData;
      function   FieldProc (hfu: Longint; Msg: word; var SenderInfo: TBasicData; var aSubData: TSubData): Integer; override;

      function   Regen : Boolean;
      function   Start : Boolean;
   public
      MonsterName : String;

      constructor Create;
      destructor  Destroy; override;

      procedure   InitialEx (aMonsterName: String);
      procedure   Initial (aMonsterName: string; ax, ay, aw: integer);
      procedure   StartProcess; override;
      procedure   EndProcess; override;

      procedure   Update (CurTick: integer); override;

      procedure   CallMe(x, y : Integer);

      function    GetAttackSkill : TAttackSkill;
      procedure   SetAttackSkill (aAttackSkill : TAttackSkill);
   end;

   TMonsterList = class
   private
      Manager : TManager;

      CurProcessPos : integer;
      DataList : TList;

      function  GetCount: integer;
      procedure Clear;
   public
      constructor Create (aManager : TManager);
      destructor  Destroy; override;

      procedure   AddMonster (aMonsterName: string; ax, ay, aw: integer; aMemberStr : String);
      function    CallMonster (aMonsterName: string; ax, ay, aw: integer; aName : String) : TMonster;
      function    CopyMonster (aBasicData : TBasicData; aAttackSkill : TAttackSkill) : TMonster;
      procedure   ComeOn (aName : String; X, Y : Word);

      function    FindMonster (aMonsterName : String) : Integer;
      function    DeleteMonster (aMonsterName : String) : Boolean;

      procedure   ReLoadFromFile;

      procedure   Update (CurTick: integer);

      function    GetMonsterByName(aName : String) : TMonster;

      property    Count : integer read GetCount;
   end;

implementation

uses
   SvMain;

/////////////////////////////////////
//       Monster
////////////////////////////////////
constructor TMonster.Create;
var
   i : Integer;
begin
   inherited Create;

   pSelfData := nil;
   AttackSkill := nil;

   HaveItemClass := TMopHaveItemClass.Create (Self);
   HaveMagicClass := TMopHaveMagicClass.Create (SElf);
end;

destructor TMonster.Destroy;
begin
   HaveMagicClass.Free;
   HaveItemClass.Free;
   
   pSelfData := nil;
   if (AttackSkill <> nil) and (FboCopy = false) then begin
      AttackSkill.Free;
   end;
   inherited Destroy;
end;

function TMonster.Regen : Boolean;
var
   i, xx, yy : word;
begin
   Result := true;

   for i := 0 to 10 - 1 do begin
      xx := CreatedX - ActionWidth + Random(ActionWidth * 2);
      yy := CreatedY - ActionWidth + Random(ActionWidth * 2);
      if Maper.isMoveable (xx, yy) then begin
         EndProcess;

         BasicData.x := xx;
         BasicData.y := yy;
         BasicData.nx := xx;
         BasicData.ny := yy;
         BasicData.Feature.rHitMotion := AM_HIT1;

         CurLife := MaxLife;

         StartProcess;
         exit;
      end;
   end;
   Result := false;
end;

function TMonster.Start : Boolean;
var
   i, xx, yy : word;
begin
   Result := true;

   xx := BasicData.X;
   yy := BasicData.Y;
   for i := 0 to 10 - 1 do begin
      if Maper.isMoveable (xx, yy) then begin
         BasicData.x := xx;
         BasicData.y := yy;
         BasicData.nx := xx;
         BasicData.ny := yy;
         BasicData.Feature.rHitMotion := AM_HIT1;

         CurLife := MaxLife;

         StartProcess;
         exit;
      end;
      xx := CreatedX - ActionWidth + Random(ActionWidth * 2);
      yy := CreatedY - ActionWidth + Random(ActionWidth * 2);
   end;
   Result := false;
end;

procedure TMonster.SetAttackSkillData;
begin
   if pSelfData = nil then exit;
   if AttackSkill = nil then exit;

   AttackSkill.boViewHuman := pSelfData^.rboViewHuman;
   AttackSkill.boAutoAttack := pSelfData^.rboAutoAttack;
   AttackSkill.boAttack := pSelfData^.rboAttack;
   AttackSkill.EscapeLife := pSelfData^.rEscapeLife;
   AttackSkill.ViewWidth := pSelfData^.rViewWidth;
   AttackSkill.boChangeTarget := pSelfData^.rboChangeTarget;
   AttackSkill.boBoss := pSelfData^.rboBoss;
   AttackSkill.boVassal := pSelfData^.rboVassal;
   AttackSkill.VassalCount := pSelfData^.rVassalCount;

   AttackSkill.SetAttackMagic (pSelfData^.rAttackMagic);
end;

procedure TMonster.SetMonsterData;
var
   i : Integer;
begin
   if pSelfData = nil then exit;

   LifeData.damageBody      := LifeData.damageBody      + pSelfData^.rDamage;
   LifeData.damageHead      := LifeData.damageHead      + 0;
   LifeData.damageArm       := LifeData.damageArm       + 0;
   LifeData.damageLeg       := LifeData.damageLeg       + 0;
   LifeData.AttackSpeed     := LifeData.AttackSpeed     + pSelfData^.rAttackSpeed;
   LifeData.avoid           := LifeData.avoid           + pSelfData^.ravoid;
   LifeData.recovery        := LifeData.recovery        + pSelfData^.rrecovery;
   LifeData.armorBody       := LifeData.armorBody       + pSelfData^.rarmor;
   LifeData.armorHead       := LifeData.armorHead       + pSelfData^.rarmor;
   LifeData.armorArm        := LifeData.armorArm        + pSelfData^.rarmor;
   LifeData.armorLeg        := LifeData.armorLeg        + pSelfData^.rarmor;
   LifeData.HitArmor        := pSelfData^.rHitArmor;

   BasicData.Feature.raninumber := pSelfData^.rAnimate;
   BasicData.Feature.rImageNumber := pSelfData^.rShape;

   for i := 0 to MOP_DROPITEM_MAX - 1 do begin
      HaveItemClass.AddDropItem (pSelfData^.rHaveItem[i].rName, pSelfData^.rHaveItem[i].rCount); 
   end;

   MaxLife := pSelfData^.rLife;
   CurLife := MaxLife;

   SetAttackSkillData;

   WalkSpeed := pSelfData^.rWalkSpeed;
   SoundNormal := pSelfData^.rSoundNormal;
   SoundAttack := pSelfData^.rSoundAttack;
   SoundDie := pSelfData^.rSoundDie;
   SoundStructed := pSelfData^.rSoundStructed;
end;

procedure  TMonster.Initial (aMonsterName: string; ax, ay, aw: Integer);
var
   i : Integer;
   MonsterData : TMonsterData;
begin
   MonsterClass.GetMonsterData (aMonsterName, pSelfData);

   inherited Initial (aMonsterName, StrPas (@pSelfData^.rViewName));

   if AttackSkill = nil then begin
      AttackSkill := TAttackSkill.Create (Self);
   end;

   HaveItemClass.Clear;
   
   SetMonsterData;

   MonsterName := aMonsterName;

   Basicdata.id := GetNewMonsterId;
   BasicData.X := ax;
   BasicData.Y := ay;
   BasicData.ClassKind := CLASS_MONSTER;
   BasicData.Feature.rrace := RACE_MONSTER;

   CreatedX := ax;
   CreatedY := ay;

   ActionWidth := aw;

   HaveMagicClass.Init (pSelfData^.rHaveMagic);
end;

procedure  TMonster.InitialEx (aMonsterName: String);
var
   i : Integer;
   MonsterData : TMonsterData;
begin
   MonsterClass.GetMonsterData (aMonsterName, pSelfData);

   StrPCopy (@BasicData.Name, StrPas (@pSelfData^.rName));
   StrPCopy (@BasicData.ViewName, StrPas (@pSelfData^.rViewName));

   inherited InitialEx;

   if AttackSkill = nil then begin
      AttackSkill := TAttackSkill.Create (Self);
   end;

   HaveItemClass.DropItemClear;
   
   SetMonsterData;

   MonsterName := aMonsterName;

   HaveMagicClass.Init (pSelfData^.rHaveMagic);
end;

procedure TMonster.StartProcess;
var
   SubData : TSubData;
   MonsterData : TMonsterData;
begin
   inherited StartProcess;

   if AttackSkill = nil then begin
      AttackSkill := TAttackSkill.Create (Self);

      AttackSkill.TargetX := CreateX - 3 + Random (6);
      AttackSkill.TargetY := CreateY - 3 + Random (6);

      SetAttackSkillData;
   end;

   Phone.RegisterUser (BasicData.id, FieldProc, BasicData.X, BasicData.Y);
   Phone.SendMessage (0, FM_CREATE, BasicData, SubData);

   if FboCopy = true then begin
      ShowEffect (1, lek_none);
   end;

   // 篮脚贱
   if HaveMagicClass.isHaveHideMagic then begin
      if HaveMagicClass.RunHaveHideMagic (BasicData.LifePercent) then begin
         SetHideState (hs_0);
      end;
   end;
end;

procedure TMonster.EndProcess;
var
   SubData : TSubData;
begin
   if FboRegisted = FALSE then exit;
   
   SetAttackSkill (nil);
   FboCopy := false;

   Phone.SendMessage (0, FM_DESTROY, BasicData, SubData);
   Phone.UnRegisterUser (BasicData.id, BasicData.x, BasicData.y);

   inherited EndProcess;
end;

procedure TMonster.CallMe(x, y : Integer);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -