📄 umonster.pas
字号:
end;
if CurTick < AttackSkill.ArrivalTick + 100 then exit;
BasicObject := TBasicObject (GetViewObjectByID (AttackSkill.GetSaveID));
if BasicObject <> nil then begin
if BasicObject.BasicData.Feature.rRace = RACE_ITEM then begin
Phone.SendMessage (BasicObject.BasicData.ID, FM_PICKUP, BasicData, SubData);
end;
end;
LifeObjectState := los_none;
if AttackSkill.GetTargetID <> 0 then LifeObjectState := los_attack;
end;
los_kill :
begin
if AttackSkill = nil then begin
LifeObjectState := los_none;
exit;
end;
if CurTick < AttackSkill.ArrivalTick + 100 then exit;
BasicObject := TBasicObject (GetViewObjectByID (AttackSkill.GetSaveID));
if BasicObject <> nil then begin
if BasicObject.BasicData.Feature.rRace = RACE_HUMAN then begin
if BasicObject.BasicData.Feature.rFeatureState = wfs_die then begin
key := GetNextDirection (BasicData.X, BasicData.Y, AttackSkill.TargetX, AttackSkill.TargetY);
if (key <> DR_DONTMOVE) and (key <> BasicData.dir) then begin
CommandTurn (key);
end;
Phone.SendMessage (BasicObject.BasicData.ID, FM_KILL, BasicData, SubData);
end;
end;
end;
LifeObjectState := los_none;
if AttackSkill.GetTargetID <> 0 then LifeObjectState := los_attack;
end;
los_move :
begin
if AttackSkill <> nil then begin
if AttackSkill.ProcessMove (CurTick) = false then exit;
end;
LifeObjectState := los_none;
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 (aManager: TManager);
begin
Manager := aManager;
CurProcessPos := 0;
// AnsList := TAnsList.Create (cnt, AllocFunction, FreeFunction);
// AnsList.MaxUnUsedCount := 10000;
DataList := TList.Create;
ReLoadFromFile;
end;
destructor TMonsterList.Destroy;
begin
Clear;
DAtaList.Free;
inherited destroy;
end;
procedure TMonsterList.Clear;
var
i : Integer;
Monster : TMonster;
begin
for i := 0 to DataList.Count - 1 do begin
Monster := DataList.Items [i];
Monster.EndProcess;
Monster.Free;
end;
DataList.Clear;
end;
procedure TMonsterList.ReLoadFromFile;
var
i, j : integer;
pd : PTCreateMonsterData;
FileName : String;
CreateMonsterList : TList;
begin
Clear;
FileName := format ('.\Setting\CreateMonster%d.SDB', [Manager.ServerID]);
if not FileExists (FileName) then exit;
CreateMonsterList := TList.Create;
LoadCreateMonster (FileName, CreateMonsterList);
for i := 0 to CreateMonsterList.Count - 1 do begin
pd := CreateMonsterList.Items [i];
if pd <> nil then begin
for j := 0 to pd^.Count - 1 do begin
AddMonster (pd^.mName, pd^.x, pd^.y, pd^.Width, pd^.Member);
end;
end;
end;
for i := 0 to CreateMonsterList.Count - 1 do begin
Dispose (CreateMonsterList[i]);
end;
CreateMonsterList.Clear;
CreateMonsterList.Free;
end;
function TMonsterList.GetCount: integer;
begin
Result := DataList.Count;
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 := TMonster.Create;
if Monster <> nil then begin
Monster.SetManagerClass (Manager);
Monster.Initial (aMonsterName, ax, ay, aw);
DataList.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 := TMonster.Create;
if Member <> nil then begin
Member.SetManagerClass (Manager);
Member.Initial (MemberName, ax, ay, aw);
DataList.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 := TMonster.Create;
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;
DataList.Add (Monster);
Result := Monster;
end;
end;
function TMonsterList.FindMonster (aMonsterName : String) : Integer;
var
i, iCount : Integer;
Monster : TMonster;
begin
Result := 0;
iCount := 0;
for i := 0 to DataList.Count - 1 do begin
Monster := DataList.Items [i];
if Monster.MonsterName = aMonsterName then begin
Inc (iCount);
end;
end;
Result := iCount;
end;
function TMonsterList.DeleteMonster (aMonsterName : String) : Boolean;
var
i, iCount : Integer;
Monster : TMonster;
begin
Result := false;
iCount := 0;
for i := 0 to DataList.Count - 1 do begin
Monster := DataList.Items [i];
if Monster.MonsterName = aMonsterName then begin
Monster.FboAllowDelete := true;
Inc (iCount);
end;
end;
if iCount > 0 then Result := true;
end;
function TMonsterList.CallMonster (aMonsterName: string; ax, ay, aw: integer; aName : String) : TMonster;
var
Monster : TMonster;
AttackSkill : TAttackSkill;
begin
Result := nil;
Monster := TMonster.Create;
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;
DataList.Add (Monster);
Result := Monster;
end;
end;
function TMonsterList.GetMonsterByName(aName : String) : TMonster;
var
i : Integer;
Monster : TMonster;
begin
Result := nil;
for i := 0 to DataList.Count - 1 do begin
Monster := DataList.Items [i];
if Monster.MonsterName = aName then begin
if Monster.BasicData.Feature.rfeaturestate = wfs_normal then begin
Result := Monster;
exit;
end;
end;
end;
end;
procedure TMonsterList.Update (CurTick: integer);
var
i : integer;
Monster : TMonster;
begin
if CurProcessPos >= DataList.Count then CurProcessPos := 0;
for i := 0 to ProcessListCount - 1 do begin
if DataList.Count = 0 then break;
if CurProcessPos >= DataList.Count then CurProcessPos := 0;
Monster := DataList [CurProcessPos];
if Monster.FboAllowDelete = true then begin
Monster.EndProcess;
Monster.Free;
DataList.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;
procedure TMonsterList.ComeOn (aName : String; X, Y : Word);
var
i : Integer;
Monster : TMonster;
begin
for i := 0 to DataList.Count - 1 do begin
Monster := DataList.Items [i];
if StrPas (@Monster.BasicData.Name) = aName then begin
if Monster.FboAllowDelete = true then continue;
if Monster.AttackSkill = nil then continue;
Monster.AttackSkill.SetSaveIDandPos (0, X, Y, los_none);
Monster.LifeObjectState := los_move;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -