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

📄 unpc.pas

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

interface

uses
  Windows, Messages, Classes, SysUtils, svClass,subutil, uAnsTick, AnsUnit,
  BasicObj, FieldMsg, MapUnit, DefType, Autil32, uMonster, uUser, UserSDB,
  uManager, uSkills, AnsStringCls;

type

   TNpc = class (TLifeObject)
    private
     pSelfData : PTNpcData;
     // boFighterNpc: Boolean;
     DblClick_UserId : integer;

     BuySellSkill : TBuySellSkill;
     SpeechSkill : TSpeechSkill;
     DeallerSkill : TDeallerSkill;
     AttackSkill : TAttackSkill;

     function  Regen : Boolean;
     function  Start : Boolean;
    protected
     procedure  SetNpcAttrib;
     function   FieldProc (hfu: Longint; Msg: word; var SenderInfo: TBasicData; var aSubData: TSubData): Integer; override;
     procedure  Initial (aNpcName: string; ax, ay, aw: integer; aBookName : String);
     procedure  StartProcess; override;
     procedure  EndProcess; override;
    public
     NpcName : string;
     CreateIndex : integer;
     constructor Create;
     destructor Destroy; override;
     procedure  Update (CurTick: integer); override;

     procedure CallMe(x, y : Integer);
     function GetAttackSkill : TAttackSkill;
     procedure SetAttackSkill (aAttackSkill : TAttackSkill);
   end;

   TNpcList = class
   private
     Manager : TManager;
     CurProcessPos : integer;

     // AnsList : TAnsList;
     DataList : TList;

     {
     function  AllocFunction: pointer;
     procedure FreeFunction (item: pointer);
     }
     function  GetCount: integer;

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

     procedure   ReLoadFromFile;

     function    CallNpc (aNpcName: string; ax, ay, aw: integer; aName : String) : TNpc;
     procedure   AddNpc (aNpcName: string; ax, ay, aw: integer; aBookName : String);
     procedure   Update (CurTick: integer);
     property    Count : integer read GetCount;

     function    GetNpcByName (aName : String) : TBasicObject;
   end;

// var
   // FighterNpc : TNpc = nil;

implementation

uses
   svMain;

/////////////////////////////////////
//       Npc
////////////////////////////////////
constructor TNpc.Create;
begin
   inherited Create;

   pSelfData := nil;
   DblClick_UserId := 0;
   // boFighterNpc := FALSE;

   BuySellSkill := nil;
   SpeechSkill := nil;
   DeallerSkill := nil;
   AttackSkill := nil;
end;

destructor TNpc.Destroy;
begin
   pSelfData := nil;
   if BuySellSkill <> nil then BuySellSkill.Free;
   if SpeechSkill <> nil then SpeechSkill.Free;
   if DeallerSkill <> nil then DeallerSkill.Free;
   if (AttackSkill <> nil) and (FboCopy = false) then AttackSkill.Free;

   inherited destroy;
end;

function  TNpc.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.dir := DR_4;
         BasicData.Feature.rhitmotion := AM_HIT1;

         CurLife := MaxLife;

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

function TNpc.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 TNpc.SetNpcAttrib;
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;

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

procedure  TNpc.Initial (aNpcName: string; ax, ay, aw: integer; aBookName : String);
begin
   NpcClass.GetNpcData (aNpcName, pSelfData);

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

   {
   if aNpcName = '厚公厘' then boFighterNpc := TRUE
   else boFighterNpc := FALSE;
   }

   DblClick_UserId := 0;

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

   SetNpcAttrib;

   NpcName := aNpcName;

   if pSelfData^.rboSeller = true then begin
      if BuySellSkill = nil then
         BuySellSkill := TBuySellSkill.Create (Self);

      BuySellSkill.LoadFromFile ('.\NpcSetting\' + StrPas (@pSelfData^.rNpcText));
   end;

   BasicData.id := GetNewMonsterId;
   BasicData.X := ax;
   BasicData.Y := ay;
   BasicData.ClassKind := CLASS_NPC;
   BasicData.Feature.rrace := RACE_NPC;

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

   CreatedX := ax;
   CreatedY := ay;
   ActionWidth := aw;

   MaxLife := pSelfData^.rLife;

   if aBookName <> '' then begin
      if SpeechSkill = nil then begin
         SpeechSkill := TSpeechSkill.Create (Self);
      end;
      SpeechSkill.LoadFromFile ('.\NpcSetting\' + aBookName);
      if DeallerSkill = nil then begin
         DeallerSkill := TDeallerSkill.Create (Self);
      end;
      DeallerSkill.LoadFromFile ('.\NpcSetting\' + aBookName);
   end;
end;

procedure TNpc.StartProcess;
var
   SubData : TSubData;
begin
   inherited StartProcess;

   CurLife := MaxLife;

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

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

   {
   if boFighterNpc then begin
      FighterNpc := Self;
      DontAttacked := TRUE;
   end;
   }

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

procedure TNpc.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);
   {
   if boFighterNpc then begin
      FighterNpc := nil;
      DontAttacked := FALSE;
   end;
   }
   
   inherited EndProcess;
end;

procedure TNpc.CallMe(x, y : Integer);
begin
   EndProcess;
   BasicData.x := x;
   BasicData.y := y;
   StartProcess;
end;

function  TNpc.FieldProc (hfu: Longint; Msg: word; var SenderInfo: TBasicData; var aSubData: TSubData): Integer;
var
   i : integer;
   tx, ty : Word;
   RetStr, Str : string;
   bo : TBasicObject;
   User : TUser;
   Mon : TMonster;
   SubData: TSubData;
   ItemData : TItemData;
   tmpAttackSkill : TAttackSkill;
begin
   Result := PROC_FALSE;

   if isRangeMessage ( hfu, Msg, SenderInfo) = FALSE then exit;
   Result := inherited FieldProc (hfu, Msg, Senderinfo, aSubData);
   if Result = PROC_TRUE then exit;
   if FboAllowDelete = true then exit;

   {
   if boFighterNpc then begin
      UserList.FieldProc2 (hfu, Msg, SenderInfo, aSubData);
      exit;
   end;
   }

   if LifeObjectState = los_die then exit;
   case Msg of
      FM_CLICK :
         begin
            if BuySellSkill <> nil then begin
               if BuySellSkill.CanLogItem = true then begin
                  User := UserList.GetUserPointer (StrPas (@SenderInfo.Name));
                  if User <> nil then begin
                     RetStr := User.ShowItemLogWindow;
                     if RetStr <> '' then begin
                        CommandSay (RetStr);
                     end;
                  end;
               end;
            end;
         end;
      FM_SHOW :
         begin
            if SenderInfo.id = BasicData.id then exit;

⌨️ 快捷键说明

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