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

📄 umonster.pas

📁 千年源代码,只缺少控件,可以做二次开发用,好不容易得来的
💻 PAS
📖 第 1 页 / 共 2 页
字号:
            if SenderInfo.id = BasicData.id then begin
               if CurLife <= 0 then begin
                  BasicData.nx := BasicData.x;
                  BasicData.ny := BasicData.y;

                  AttackSkill.SetTargetId (0, true);

                  for i := 0 to 5 - 1 do begin
                     if HaveItem[i].rName <> '' then begin
                        if ItemClass.GetCheckItemData (MonsterName, HaveItem[i], ItemData) = false then continue;
                        ItemData.rOwnerName[0] := 0;
                        SubData.ItemData := ItemData;
                        SubData.ServerId := Manager.ServerId;
                        Phone.SendMessage (MANAGERPHONE, FM_ADDITEM, BasicData, SubData);
                     end;
                  end;
                  exit;
               end;
               if AttackSkill.boChangeTarget then begin
                  Bo := GetViewObjectByID (AttackSkill.GetTargetID);
                  if Bo <> nil then begin
                     len := GetLargeLength (BasicData.x, BasicData.y, Bo.Posx, Bo.Posy);
                     if len > 1 then begin
                        AttackSkill.SetTargetId (aSubData.attacker, true);
                     end;
                  end;
               end;
               if isUserId (aSubData.attacker) then AttackSkill.HateHumanId := aSubData.attacker;
            end;
         end;
      FM_DEADHIT :
         begin
            if SenderInfo.id = BasicData.id then exit;
            if BasicData.Feature.rfeaturestate = wfs_die then begin Result := PROC_TRUE; exit; end;
            CurLife := 0;
            
            AttackSkill.SetTargetId (0, true);

            BasicData.nx := BasicData.x;
            BasicData.ny := BasicData.y;

            for i := 0 to 5 - 1 do begin
               if HaveItem[i].rName <> '' then begin
                  if ItemClass.GetCheckItemData (MonsterName, HaveItem[i], ItemData) = false then continue;
                  ItemData.rOwnerName[0] := 0;
                  SubData.ItemData := ItemData;
                  SubData.ServerId := Manager.ServerId;
                  Phone.SendMessage (MANAGERPHONE, FM_ADDITEM, BasicData, SubData);
               end;
            end;

            CommandChangeCharState (wfs_die);
         end;
      FM_HIT :
         begin
         //
         end;
      FM_SAY :
         begin
         end;
   end;
end;

procedure TMonster.Update (CurTick: integer);
var
   i : Integer;
   boFlag : Boolean;
   BO : TLifeObject;
begin
//   inherited UpDate (CurTick);
   if (BasicData.Feature.rfeaturestate = wfs_die) and (LifeObjectState <> los_die) then begin
      LifeObjectState := los_die;
   end;
   
   case LifeObjectState of
      los_init :
         begin
            Start;
            exit;
         end;
      los_die :
         begin
            if CurTick > DiedTick + 1600 then begin
               if Manager.RegenInterval = 0 then begin
                  Regen;
                  exit;
               end;
            end;
            if CurTick > DiedTick + 800 then begin
               if Manager.RegenInterval > 0 then begin
                  FboAllowDelete := true;
                  exit;
               end;
            end;
         end;
      los_none:
         begin
            if AttackSkill <> nil then AttackSkill.ProcessNone (CurTick);
         end;
      los_escape:
         begin
            if AttackSkill <> nil then AttackSkill.ProcessEscape (CurTick);
         end;
      los_attack:
         begin
            if AttackSkill <> nil then begin
               boFlag := AttackSkill.ProcessAttack (CurTick, Self);
               if (boFlag = false) and (boSkillUsed = true) and (FboCopy = false) then begin
                  boSkillUsed := false;
                  if CopiedList <> nil then begin
                     for i := 0 to CopiedList.Count - 1 do begin
                        BO := TLifeObject (CopiedList[i]);
                        BO.boAllowDelete := true;
                     end;
                  end;
               end;
            end;
         end;
      los_moveattack :
         begin
            if AttackSkill <> nil then AttackSkill.ProcessMoveAttack (CurTick);
         end;
      los_deadattack :
         begin
            if AttackSkill <> nil then AttackSkill.ProcessDeadAttack (CurTick);
         end;
   end;
end;

function TMonster.GetAttackSkill : TAttackSkill;
begin
   if AttackSkill = nil then
      AttackSkill := TAttackSkill.Create (Self);
      
   Result := AttackSkill;
end;

procedure TMonster.SetAttackSkill (aAttackSkill : TAttackSkill);
begin
   if AttackSkill <> nil then begin
      if FboCopy = false then begin
         AttackSkill.Free;
      end;
   end;

   AttackSkill := aAttackSkill;
end;

////////////////////////////////////////////////////
//
//             ===  MonsterList  ===
//
////////////////////////////////////////////////////

constructor TMonsterList.Create (cnt: integer; aManager: TManager);
begin
   Manager := aManager;

   CurProcessPos := 0;
   AnsList := TAnsList.Create (cnt, AllocFunction, FreeFunction);

   ReLoadFromFile;
end;

destructor TMonsterList.Destroy;
begin
   Clear;
   AnsList.Free;
   inherited destroy;
end;

procedure TMonsterList.Clear;
var
   i : Integer;
begin
   for i := AnsList.Count - 1 downto 0 do begin
      TMonster (AnsList[i]).EndProcess;
      AnsList.Delete (i);
   end;
end;

procedure   TMonsterList.ReLoadFromFile;
var
   i, j, iCount : integer;
   FileName, iName, MonsterName : String;
   CreateMonsterData : TCreateMonsterData;
   MonsterData : TMonsterData;
   DB : TUserStringDB;
begin
   Clear;

   FileName := '.\Setting\CreateMonster' + IntToStr (Manager.ServerID) + '.SDB';

   if not FileExists (FileName) then exit;

   DB := TUserStringDb.Create;
   DB.LoadFromFile (FileName);

   for i := 0 to DB.Count - 1 do begin
      iName := DB.GetIndexName (i);
      if iName = '' then continue;

      MonsterName := DB.GetFieldValueString (iName, 'MonsterName');
      if MonsterName = '' then continue;
      MonsterClass.GetMonsterData (MonsterName, @MonsterData);
      if MonsterData.rName[0] = 0 then continue;
      iCount := DB.GetFieldValueInteger (iName, 'Count');
      if iCount <= 0 then continue;

      CreateMonsterData.Name := MonsterName;
      CreateMonsterData.x := DB.GetFieldValueInteger (iName, 'X');
      CreateMonsterData.y := DB.GetFieldValueInteger (iName, 'Y');
      CreateMonsterData.Width := DB.GetFieldValueInteger (iName, 'Width');
      CreateMonsterData.Member := DB.GetFieldValueString (iName, 'Member');

      for j := 0 to iCount - 1 do begin
         AddMonster (CreateMonsterData.Name, CreateMonsterData.x, CreateMonsterData.y, CreateMonsterData.Width, CreateMonsterData.Member);
      end;
   end;
   DB.Free;
end;

function  TMonsterList.GetCount: integer;
begin
   Result := AnsList.Count;
end;

function TMonsterList.AllocFunction: pointer;
begin
   Result := TMonster.Create;
end;

procedure TMonsterList.FreeFunction (item: pointer);
begin
   TMonster (item).Free;
end;

procedure TMonsterList.AddMonster (aMonsterName: string; ax, ay, aw: integer; aMemberStr : String);
var
   Monster, Member : TMonster;
   str, MemberName, MemberCount : String;
   i, Count : Integer;
   AttackSkill, tmpAttackSkill : TAttackSkill;
begin
   Monster := AnsList.GetUnUsedPointer;
   if Monster <> nil then begin
      Monster.SetManagerClass (Manager);
      Monster.Initial (aMonsterName, ax, ay, aw);
      AnsList.Add (Monster);
      if aMemberStr <> '' then begin
         AttackSkill := Monster.GetAttackSkill;
         AttackSkill.SetGroupSkill;
         str := aMemberStr;
         while str <> '' do begin
            str := GetValidStr3 (str, MemberName, ':');
            if MemberName = '' then break;
            str := GetValidStr3 (str, MemberCount, ':');
            if MemberCount = '' then break;
            Count := _StrToInt (MemberCount);

            for i := 0 to Count - 1 do begin
               Member := AnsList.GetUnUsedPointer;
               if Member <> nil then begin
                  Member.SetManagerClass (Manager);
                  Member.Initial (MemberName, ax, ay, aw);
                  AnsList.Add (Member);
                  AttackSkill.AddGroup (Member);
                  tmpAttackSkill := Member.GetAttackSkill;
                  if tmpAttackSkill <> nil then
                     tmpAttackSkill.SetBoss (Monster);
               end;
            end;
         end;
      end;
   end;
end;

function TMonsterList.CopyMonster (aBasicData : TBasicData; aAttackSkill : TAttackSkill) : TMonster;
var
   Monster : TMonster;
begin
   Result := nil;
   Monster := AnsList.GetUnUsedPointer;
   if Monster <> nil then begin
      Monster.SetManagerClass (Manager);
      Monster.SetAttackSkill (aAttackSkill);
      Monster.FboCopy := true;
      Monster.Initial (StrPas (@aBasicData.Name), aBasicData.x, aBasicData.y, 4);
      if Monster.Start = false then begin
         Monster.Free;
         exit;
      end;
      AnsList.Add (Monster);

      Result := Monster;
   end;
end;

function TMonsterList.CallMonster (aMonsterName: string; ax, ay, aw: integer; aName : String) : TMonster;
var
   Monster : TMonster;
   AttackSkill : TAttackSkill;
begin
   Result := nil;
   
   Monster := AnsList.GetUnUsedPointer;
   if Monster <> nil then begin
      Monster.SetManagerClass (Manager);
      Monster.Initial (aMonsterName, ax, ay, aw);
      if Monster.Start = false then begin
         Monster.Free;
         exit;
      end;
      AttackSkill := Monster.GetAttackSkill;
      if AttackSkill <> nil then begin
         AttackSkill.SetDeadAttackName (aName);
      end;
      AnsList.Add (Monster);

      Result := Monster;
   end;
end;


function TMonsterList.GetMonsterByName(aName : String) : TMonster;
var
   i : Integer;
begin
   Result := nil;
   for i := 0 to AnsList.Count - 1 do begin
      if TMonster(AnsList.Items[i]).MonsterName = aName then begin
         if TMonster(AnsList.Items[i]).BasicData.Feature.rfeaturestate = wfs_normal then begin
            Result := TMonster(AnsList.Items[i]);
            exit;
         end;
      end;
   end;
end;

procedure TMonsterList.Update (CurTick: integer);
var
   i : integer;
   Monster : TMonster;
begin
   if CurProcessPos >= AnsList.Count then CurProcessPos := 0;

   for i := 0 to ProcessListCount - 1 do begin
      if AnsList.Count = 0 then break;
      if CurProcessPos >= AnsList.Count then CurProcessPos := 0;
      Monster := TMonster (AnsList[CurProcessPos]);
      if Monster.FboAllowDelete = true then begin
         Monster.EndProcess;
         AnsList.Delete (CurProcessPos);
      end else begin
         try
            Monster.UpDate (CurTick);
            Inc (CurProcessPos);
         except
            Monster.FBoAllowDelete := true;
            frmMain.WriteLogInfo (format ('TMonsterList.Update (%s) failed', [Monster.MonsterName]));
         end;
      end;
   end;
end;

end.

⌨️ 快捷键说明

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