envir.pas
来自「FIR引擎最新源码+注册」· PAS 代码 · 共 1,618 行 · 第 1/4 页
PAS
1,618 行
if (OSObject.btType = btType) and (OSObject.CellObj = pRemoveObject) then begin
MapCellInfo.ObjList.Delete(n18);
DisPoseAndNil(OSObject);
Result := 1;
//减地图人物怪物计数
if (btType = OS_MOVINGOBJECT) and (not TBaseObject(pRemoveObject).m_boDelFormMaped) then begin
TBaseObject(pRemoveObject).m_boDelFormMaped := True;
TBaseObject(pRemoveObject).m_boAddToMaped := False;
btRaceServer := TBaseObject(pRemoveObject).m_btRaceServer;
if btRaceServer = RC_PLAYOBJECT then Dec(m_nHumCount);
if btRaceServer >= RC_ANIMAL then Dec(m_nMonCount);
end;
if MapCellInfo.ObjList.Count <= 0 then begin
FreeAndNil(MapCellInfo.ObjList);
Break;
end;
Continue;
end
end else begin
MapCellInfo.ObjList.Delete(n18);
if MapCellInfo.ObjList.Count > 0 then Continue;
if MapCellInfo.ObjList.Count <= 0 then begin
FreeAndNil(MapCellInfo.ObjList);
Break;
end;
end;
Inc(n18);
end;
end else begin
Result := -2;
end;
except
OSObject := nil;
MainOutMessage(Format(sExceptionMsg1, [btType]));
end;
end else Result := -3;
end else Result := 0;
except
MainOutMessage(Format(sExceptionMsg2, [btType]));
end;
end;
function TEnvirnoment.GetItem(nX, nY: Integer): PTMapItem;
var
I: Integer;
MapCellInfo: pTMapCellinfo;
OSObject: pTOSObject;
BaseObject: TBaseObject;
begin
Result := nil;
bo2C := False;
if GetMapCellInfo(nX, nY, MapCellInfo) and (MapCellInfo.chFlag = 0) then begin
bo2C := True;
if MapCellInfo.ObjList <> nil then begin
for I := 0 to MapCellInfo.ObjList.Count - 1 do begin
OSObject := MapCellInfo.ObjList.Items[I];
if OSObject <> nil then begin
if OSObject.btType = OS_ITEMOBJECT then begin
Result := PTMapItem(OSObject.CellObj);
Exit;
end;
if OSObject.btType = OS_GATEOBJECT then
bo2C := False;
if OSObject.btType = OS_MOVINGOBJECT then begin
BaseObject := TBaseObject(OSObject.CellObj);
if not BaseObject.m_boDeath then
bo2C := False;
end;
end;
end;
end;
end;
end;
function TMapManager.GetMapOfServerIndex(sMapName: string): Integer;
var
I: Integer;
Envir: TEnvirnoment;
begin
Result := 0;
Lock;
try
for I := 0 to Count - 1 do begin
Envir := Items[I];
if (CompareText(Envir.sMapName, sMapName) = 0) then begin
Result := Envir.nServerIndex;
Break;
end;
end;
finally
UnLock;
end;
end;
procedure TMapManager.LoadMapDoor;
var
I: Integer;
begin
for I := 0 to Count - 1 do begin
TEnvirnoment(Items[I]).AddDoorToMap;
end;
end;
procedure TMapManager.ProcessMapDoor;
begin
end;
procedure TMapManager.ReSetMinMap;
var
I, II: Integer;
Envirnoment: TEnvirnoment;
begin
for I := 0 to Count - 1 do begin
Envirnoment := TEnvirnoment(Items[I]);
for II := 0 to MiniMapList.Count - 1 do begin
if CompareText(MiniMapList.Strings[II], Envirnoment.sMapName) = 0 then begin
Envirnoment.nMinMap := Integer(MiniMapList.Objects[II]);
Break;
end;
end;
end;
end;
function TEnvirnoment.IsCheapStuff: Boolean;
begin
if m_QuestList.Count > 0 then Result := True
else Result := False;
end;
function TEnvirnoment.AddToMapMineEvent(nX, nY: Integer; nType: Integer; Event: TObject): TObject;
var
MapCellInfo: pTMapCellinfo;
OSObject: pTOSObject;
bo19, bo1A: Boolean;
resourcestring
sExceptionMsg = '[Exception] TEnvirnoment::AddToMapMineEvent ';
begin
Result := nil;
try
bo19 := GetMapCellInfo(nX, nY, MapCellInfo);
bo1A := False;
if bo19 and (MapCellInfo.chFlag <> 0) then begin
if MapCellInfo.ObjList = nil then MapCellInfo.ObjList := TList.Create;
if not bo1A then begin
New(OSObject);
OSObject.btType := nType;
OSObject.CellObj := Event;
OSObject.dwAddTime := GetTickCount();
MapCellInfo.ObjList.Add(OSObject);
Result := Event;
end;
end;
except
MainOutMessage(sExceptionMsg);
end;
end;
procedure TEnvirnoment.VerifyMapTime(nX, nY: Integer; BaseObject: TObject);
var
I: Integer;
MapCellInfo: pTMapCellinfo;
OSObject: pTOSObject;
boVerify: Boolean;
resourcestring
sExceptionMsg = '[Exception] TEnvirnoment::VerifyMapTime';
begin
try
boVerify := False;
if GetMapCellInfo(nX, nY, MapCellInfo) and (MapCellInfo <> nil) and (MapCellInfo.ObjList <> nil) then begin
for I := 0 to MapCellInfo.ObjList.Count - 1 do begin
OSObject := MapCellInfo.ObjList.Items[I];
if (OSObject <> nil) and (OSObject.btType = OS_MOVINGOBJECT) and (OSObject.CellObj = BaseObject) then begin
OSObject.dwAddTime := GetTickCount();
boVerify := True;
Break;
end;
end;
end;
if not boVerify then
AddToMap(nX, nY, OS_MOVINGOBJECT, BaseObject);
except
MainOutMessage(sExceptionMsg);
end;
end;
constructor TEnvirnoment.Create;
begin
Pointer(MapCellArray) := nil;
sMapName := '';
sSubMapName := '';
sMainMapName := '';
m_boMainMap := False;
nServerIndex := 0;
nMinMap := 0;
m_nWidth := 0;
m_nHeight := 0;
m_boDARK := False;
m_boDAY := False;
m_nMonCount := 0;
m_nHumCount := 0; ;
m_DoorList := TList.Create;
m_QuestList := TList.Create;
m_UnAllowStdItemsList := TGStringList.Create;
m_UnAllowMagicList := TGStringList.Create;
end;
destructor TEnvirnoment.Destroy;
var
I: Integer;
MapCellInfo: pTMapCellinfo;
OSObject: pTOSObject;
nX, nY: Integer;
DoorInfo: pTDoorInfo;
begin
for nX := 0 to m_nWidth - 1 do begin
for nY := 0 to m_nHeight - 1 do begin
if GetMapCellInfo(nX, nY, MapCellInfo) and (MapCellInfo.ObjList <> nil) then begin
for I := 0 to MapCellInfo.ObjList.Count - 1 do begin
OSObject := MapCellInfo.ObjList.Items[I];
case OSObject.btType of
OS_ITEMOBJECT: Dispose(PTMapItem(OSObject.CellObj));
OS_GATEOBJECT: Dispose(pTGateObj(OSObject.CellObj));
OS_EVENTOBJECT: TEvent(OSObject.CellObj).Free;
end;
DisPoseAndNil(OSObject);
end;
FreeAndNil(MapCellInfo.ObjList);
end;
end;
end;
for I := 0 to m_DoorList.Count - 1 do begin
DoorInfo := m_DoorList.Items[I];
Dec(DoorInfo.Status.nRefCount);
if DoorInfo.Status.nRefCount <= 0 then
Dispose(DoorInfo.Status);
Dispose(DoorInfo);
end;
m_DoorList.Free;
for I := 0 to m_QuestList.Count - 1 do begin
Dispose(pTMapQuestInfo(m_QuestList.Items[I]));
end;
m_QuestList.Free;
FreeMem(Pointer(MapCellArray));
Pointer(MapCellArray) := nil;
m_UnAllowStdItemsList.Free; //2006-12-28 增加
m_UnAllowMagicList.Free; //2006-12-28 增加
inherited;
end;
function TEnvirnoment.LoadMapData(sMapFile: string): Boolean;
var
fHandle: Integer;
Header: TMapHeader;
nMapSize: Integer;
n24, nW, nH: Integer;
MapBuffer: pTMap;
Point: Integer;
Door: pTDoorInfo;
I: Integer;
MapCellInfo: pTMapCellinfo;
begin
Result := False;
if FileExists(sMapFile) then begin
fHandle := FileOpen(sMapFile, fmOpenRead or fmShareExclusive);
if fHandle > 0 then begin
FileRead(fHandle, Header, SizeOf(TMapHeader));
m_nWidth := Header.wWidth;
m_nHeight := Header.wHeight;
Initialize(m_nWidth, m_nHeight);
nMapSize := m_nWidth * SizeOf(TMapUnitInfo) * m_nHeight;
MapBuffer := AllocMem(nMapSize);
FileRead(fHandle, MapBuffer^, nMapSize);
for nW := 0 to m_nWidth - 1 do begin
n24 := nW * m_nHeight;
for nH := 0 to m_nHeight - 1 do begin
if (MapBuffer[n24 + nH].wBkImg) and $8000 <> 0 then begin
MapCellInfo := @MapCellArray[n24 + nH];
MapCellInfo.chFlag := 1;
end;
if MapBuffer[n24 + nH].wFrImg and $8000 <> 0 then begin
MapCellInfo := @MapCellArray[n24 + nH];
MapCellInfo.chFlag := 2;
end;
if MapBuffer[n24 + nH].btDoorIndex and $80 <> 0 then begin
Point := (MapBuffer[n24 + nH].btDoorIndex and $7F);
if Point > 0 then begin
New(Door);
Door.nX := nW;
Door.nY := nH;
Door.n08 := Point;
Door.Status := nil;
for I := 0 to m_DoorList.Count - 1 do begin
if abs(pTDoorInfo(m_DoorList.Items[I]).nX - Door.nX) <= 10 then begin
if abs(pTDoorInfo(m_DoorList.Items[I]).nY - Door.nY) <= 10 then begin
if pTDoorInfo(m_DoorList.Items[I]).n08 = Point then begin
Door.Status := pTDoorInfo(m_DoorList.Items[I]).Status;
Inc(Door.Status.nRefCount);
Break;
end;
end;
end;
end;
if Door.Status = nil then begin
New(Door.Status);
Door.Status.boOpened := False;
Door.Status.bo01 := False;
Door.Status.n04 := 0;
Door.Status.dwOpenTick := 0;
Door.Status.nRefCount := 1;
end;
m_DoorList.Add(Door);
end;
end;
end;
end;
//Dispose(MapBuffer);
FreeMem(MapBuffer);
FileClose(fHandle);
Result := True;
end;
end;
end;
procedure TEnvirnoment.Initialize(nWidth, nHeight: Integer);
var
nW, nH: Integer;
MapCellInfo: pTMapCellinfo;
begin
if (nWidth > 1) and (nHeight > 1) then begin
if MapCellArray <> nil then begin
for nW := 0 to m_nWidth - 1 do begin
for nH := 0 to m_nHeight - 1 do begin
MapCellInfo := @MapCellArray[nW * m_nHeight + nH];
if MapCellInfo.ObjList <> nil then begin
FreeAndNil(MapCellInfo.ObjList);
end;
end;
end;
FreeMem(Pointer(MapCellArray));
Pointer(MapCellArray) := nil;
end;
m_nWidth := nWidth;
m_nHeight := nHeight;
Pointer(MapCellArray) := AllocMem((m_nWidth * m_nHeight) * SizeOf(TMapCellinfo));
end;
end;
//nFlag,boFlag,Monster,Item,Quest,boGrouped
function TEnvirnoment.CreateQuest(nFlag, nValue: Integer; s24, s28, s2C: string;
boGrouped: Boolean): Boolean;
var
MapQuest: pTMapQuestInfo;
MapMerchant: TMerchant;
begin
Result := False;
if nFlag < 0 then Exit;
New(MapQuest);
MapQuest.nFlag := nFlag;
if nValue > 1 then nValue := 1;
MapQuest.nValue := nValue;
if s24 = '*' then s24 := '';
MapQuest.s08 := s24;
if s28 = '*' then s28 := '';
MapQuest.s0C := s28;
if s2C = '*' then s2C := '';
MapQuest.bo10 := boGrouped;
MapMerchant := TMerchant.Create;
MapMerchant.m_sMapName := '0';
MapMerchant.m_nCurrX := 0;
MapMerchant.m_nCurrY := 0;
MapMerchant.m_sCharName := s2C;
MapMerchant.m_nFlag := 0;
MapMerchant.m_wAppr := 0;
MapMerchant.m_sFilePath := 'MapQuest_def\';
MapMerchant.m_boIsHide := True;
MapMerchant.m_boIsQuest := False;
UserEngine.QuestNPCList.Add(MapMerchant);
MapQuest.NPC := MapMerchant;
m_QuestList.Add(MapQuest);
Result := True;
end;
function TEnvirnoment.GetXYObjCount(nX, nY: Integer): Integer;
var
I: Integer;
MapCellInfo: pTMapCellinfo;
OSObject: pTOSObject;
BaseObject: TBaseObject;
begin
Result := 0;
if GetMapCellInfo(nX, nY, MapCellInfo) and (MapCellInfo.ObjList <> nil) then begin
for I := 0 to MapCellInfo.ObjList.Count - 1 do begin
OSObject := MapCellInfo.ObjList.Items[I];
if (OSObject <> nil) and (OSObject.btType = OS_MOVINGOBJECT) then begin
BaseObject := TBaseObject(OSObject.CellObj);
if BaseObject <> nil then begin
if not BaseObject.m_boGhost and
BaseObject.bo2B9 and
not BaseObject.m_boDeath and
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?