admin 发表于 2026-5-3 12:59:58

修复无空爆问题

function TEnvirnoment.AddToMap(nX, nY: Integer; btType: Byte; pRemoveObject: TObject): Pointer;
var
MapCellInfo: pTMapCellinfo;       // 目标格子信息指针
OSObject: pTOSObject;             // 格子内对象指针
MapItem: PTMapItem;               // 物品对象指针
I: Integer;                     // 循环变量
nGoldCount: Integer;            // 金币叠加后的总数量
bo1E: Boolean;                  // 标记对象是否已完成处理(叠加/拦截)
boCode: Integer;                  // 异常定位标记,用于报错时定位问题位置
btRaceServer: Byte;               // 对象种族/类型标识(区分玩家、怪物等)
nItemCount: Integer;            // 当前格子内物品对象的数量
resourcestring
sExceptionMsg = ' TEnvirnoment::AddToMap';// 异常提示信息
begin
boCode := -1;
Result := nil;
try
    bo1E := False;
    // 获取目标格子信息,判断格子是否允许放置对象
    if GetMapCellInfo(nX, nY, MapCellInfo) and (MapCellInfo.chFlag = 0) then
    begin
      boCode := 1;
      // 若格子对象列表为空,创建新的列表
      if MapCellInfo.ObjList = nil then begin
      MapCellInfo.ObjList := TList.Create;
      end
      else begin
      boCode := 2;
      // 仅对物品类型对象进行处理(针对物品掉落场景)
      if btType = OS_ITEMOBJECT then begin
          // 金币叠加逻辑,相同金币可叠加,上限为2000
          if PTMapItem(pRemoveObject).Name = sSTRING_GOLDNAME then begin
            for I := 0 to MapCellInfo.ObjList.Count - 1 do begin
            OSObject := MapCellInfo.ObjList.Items;
            if (OSObject <> nil) and (OSObject.btType = OS_ITEMOBJECT) then begin
                MapItem := PTMapItem(pTOSObject(MapCellInfo.ObjList.Items).CellObj);
                if MapItem.Name = sSTRING_GOLDNAME then begin
                  nGoldCount := MapItem.Count + PTMapItem(pRemoveObject).Count;
                  if nGoldCount <= 2000 then begin // 控制金币叠加上限
                  MapItem.Count := nGoldCount;
                  MapItem.Looks := GetGoldShape(nGoldCount);
                  MapItem.AniCount := 0;
                  MapItem.Reserved := 0;
                  OSObject.dwAddTime := GetTickCount();
                  Result := MapItem;
                  bo1E := True; // 标记为已处理(叠加成功)
                  end;
                end;
            end;
            end;
          end;
          // 未叠加金币时,判断格子内物品数量是否超限
          if not bo1E then
          begin
            nItemCount := 0;
            // 遍历格子对象列表,统计物品类型对象数量
            for I := 0 to MapCellInfo.ObjList.Count - 1 do
            begin
            OSObject := MapCellInfo.ObjList.Items;
            if (OSObject <> nil) and (OSObject.btType = OS_ITEMOBJECT) then
                Inc(nItemCount);
            end;
            // 物品数量达到5个及以上时,拦截新物品加入
            if nItemCount >= 5 then
            begin
            Result := nil;
            bo1E := True; // 标记为已处理(拦截成功)
            end;
          end;
      end;
      end;
      boCode := 3;
      // 未被叠加或拦截时,正常创建对象并加入格子列表
      if not bo1E then begin
      New(OSObject);
      OSObject.btType := btType;
      OSObject.CellObj := pRemoveObject;
      OSObject.dwAddTime := GetTickCount();
      MapCellInfo.ObjList.Add(OSObject);
      Result := Pointer(pRemoveObject);
      // 处理移动对象(玩家、怪物),标记其地图状态并统计数量
      if (btType = OS_MOVINGOBJECT) and (not TBaseObject(pRemoveObject).m_boAddToMaped) then begin
          TBaseObject(pRemoveObject).m_boDelFormMaped := False;
          TBaseObject(pRemoveObject).m_boAddToMaped := True;
          btRaceServer := TBaseObject(pRemoveObject).m_btRaceServer;
          if btRaceServer = RC_PLAYOBJECT then
            Inc(m_nHumCount); // 玩家数量统计+1
          if btRaceServer >= RC_ANIMAL then
            Inc(m_nMonCount); // 怪物数量统计+1
      end;
      end;
    end;
except
    // 捕获异常并输出提示信息,包含异常定位标记
    MainOutMessage(sExceptionMsg + ' Code ' + IntToStr(boCode));
end;
end;修复效果:格子内物品数量统计准确,仅当物品数量≥5时拦截新物品加入,怪物、尸体等非物品对象不占用物品名额,物品掉落功能恢复正常,无空爆问题



页: [1]
查看完整版本: 修复无空爆问题