📄 envir.pas
字号:
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; //004B5B0C
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 continue;
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;
function TMapManager.GetMapOfServerIndex(sMapName: String): Integer; //004B7510
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; //004B6FFC
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; //004B6E24
begin
if m_QuestList.Count > 0 then Result:=True
else Result:=False;
end;
function TEnvirnoment.AddToMapMineEvent(nX,nY:Integer;nType:Integer;Event:TObject):TObject; //004B6600
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); //004B6980
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 then continue;
if (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; //004B5318
begin
// Pointer(MapCellArray) := nil;
Setlength(MapCellArray,0);
sMapName := '';
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;
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;
Dispose(OSObject);
end;
MapCellInfo.ObjList.Free;
MapCellInfo.ObjList:=nil;
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;
Setlength(MapCellArray,0);
inherited;
end;
function TEnvirnoment.LoadMapData(sMapFile: String):Boolean;//004B54E0
var
fHandle:Integer;
Header:Tnmpfileheader;// TMapHeader;
nMapSize:Integer;
n24,nW,nH:Integer;
MapBuffer:pNMPTMap;
Point:Integer;
Door:pTDoorInfo;
i:Integer;
MapCellinfo:pTMapCellinfo;
nmpcellflag1:pTnmpcellflag1;
step:integer;
error:boolean;
begin
Result:=False;
error:=false;
if FileExists(sMapFile) then begin
fHandle:=FileOpen (sMapFile, fmOpenRead or fmShareExclusive);
if fHandle > 0 then begin
FileRead (fHandle, Header, SizeOf(Tnmpfileheader));
if not (Header.flag in [1,3]) then begin
FileClose(fHandle);
exit;
end;
m_nWidth:=Header.X;
m_nHeight:=Header.Y;
Initialize(m_nWidth,m_nHeight); //这里已经初始化 MapCellArray
// nMapSize:=m_nWidth * SizeOf(TNMPMapUnitInfo) * m_nHeight ;
nMapSize:= filesize(sMapFile) - SizeOf(Tnmpfileheader);
MapBuffer:=AllocMem(nMapSize); // nMapSize
FileRead(fHandle,MapBuffer^,nMapSize);
step:=0; // MapCellInfo.chFlag =0 表示可以走
for nH:=0 to m_nHeight -1 do begin
for nW:=0 to m_nWidth -1 do begin
n24:=nW * m_nHeight;
MapCellinfo:=@MapCellArray[n24 + nH];
if Header.flag<>1 then begin
MapCellinfo.chFlag:=MapBuffer[step] and 1;
if (MapBuffer[step]<=31) then begin
if OFF[MapBuffer[step]]>1 THEN
inc(step,OFF[MapBuffer[step]])
else inc(step);
end else begin
error:=true;
break;
end;
end //flag=3
else begin //flag =1
nmpcellflag1:= @MapBuffer[step] ;
inc(step,12);
if nmpcellflag1.n3>1000 then MapCellinfo.chFlag:=0
else MapCellinfo.chFlag:=1;
end;
end; //for nw
end; //for nh
FreeMem(MapBuffer);
FileClose(fHandle);
if not error then Result:=True;
end;//004B57B1
end;//004B57B1
end;
procedure TEnvirnoment.Initialize(nWidth, nHeight: Integer);//004B53FC
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
MapCellInfo.ObjList.Free;
MapCellInfo.ObjList:=nil;
end;
end;
end;
Setlength(MapCellArray,0);
end;//004B54AF
m_nWidth:=nWidth;
m_nHeight:=nHeight;
SetLength(MapCellArray,m_nWidth * m_nHeight);
end;//004B54DB
end;
//nFlag,boFlag,Monster,Item,Quest,boGrouped
function TEnvirnoment.CreateQuest(nFlag, nValue: Integer; s24, s28, s2C: String;
boGrouped: Boolean): Boolean; //004B6C3C
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; //004B5DB0
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 then continue;
if 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
not BaseObject.m_boFixedHideMode and
not BaseObject.m_boObMode then begin
Inc(Result);
end;
end;
end;
end;
end;
end;
//004B2A6C
function TEnvirnoment.GetNextPosition(sx, sy, ndir,nFlag:Integer;var snx:Integer;var sny:Integer):Boolean;
begin
snx := sx;
sny := sy;
case nDir of
DR_UP: if sny > nFlag - 1 then Dec(sny,nFlag);
DR_DOWN: if sny < (m_nHeight - nFlag) then Inc(sny,nFlag);
DR_LEFT: if snx > nFlag - 1 then Dec(snx,nFlag);
DR_RIGHT: if snx < (m_nWidth - nFlag) then Inc(snx,nFlag);
DR_UPLEFT: begin
if (snx > nFlag - 1) and (sny > nFlag - 1) then begin
Dec(snx,nFlag);
Dec(sny,nFlag);
end;
end;
DR_UPRIGHT: begin //004B2B77
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -