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

📄 sdk.pas

📁 飞尔传奇世界的引擎代码可直接编译M2Engine 请使用Delphi编译
💻 PAS
📖 第 1 页 / 共 4 页
字号:
  BigStorage: pTBigStorage;
  ItemCount: TItemCount;
begin
  m_StorageList.Lock();
  try
    if FileExists(sFileName) then begin
      FileHandle := FileOpen(sFileName, fmOpenRead or fmShareDenyNone);
      List := nil;
      if FileHandle > 0 then begin
        if FileRead(FileHandle, ItemCount, SizeOf(TItemCount)) = SizeOf(TItemCount) then begin
          for I := 0 to ItemCount - 1 do begin
            New(BigStorage);
            FillChar(BigStorage.UseItems, SizeOf(TUserItem), #0);
            if (FileRead(FileHandle, BigStorage^, SizeOf(TBigStorage)) = SizeOf(TBigStorage)) and (not BigStorage.boDelete) then begin
              Inc(m_ItemCount);
              List := GetUserBigStorageList(BigStorage.sCharName);
              if List = nil then begin
                List := TList.Create;
                List.Add(BigStorage);
                m_StorageList.AddObject(BigStorage.sCharName, List);
              end else begin
                List.Add(BigStorage);
              end;
            end else begin
              DisPoseAndNil(BigStorage);
            end;
          end;
          FileClose(FileHandle);
        end;
      end;
    end else begin
      FileHandle := FileCreate(sFileName);
      if FileHandle > 0 then begin
        m_ItemCount := 0;
        FileWrite(FileHandle, m_ItemCount, SizeOf(TItemCount));
        FileClose(FileHandle);
      end;
    end;
    FRecordCount := m_ItemCount;
    FHumManCount := m_StorageList.Count;
  finally
    m_StorageList.UnLock();
  end;
  //MainOutMessage('LoadSellGoodRecord: '+IntToStr(Self.Count));
end;

procedure TStorage.UnLoadBigStorageList();
var
  I, II: Integer;
  List: TList;
begin
  m_StorageList.Lock();
  try
    for I := 0 to m_StorageList.Count - 1 do begin
      List := TList(m_StorageList.Objects[I]);
      if List <> nil then begin
        for II := 0 to List.Count - 1 do begin
          Dispose(List.Items[II]);
        end;
        FreeAndNil(List);
      end;
    end;
    m_StorageList.Clear;
  finally
    m_StorageList.UnLock();
  end;
end;

function TStorage.GetUserBigStorageList(sChrName: string): TList;
var
  I: Integer;
begin
  Result := nil;
  m_StorageList.Lock();
  try
    for I := 0 to m_StorageList.Count - 1 do begin
      if CompareText(m_StorageList.Strings[I], sChrName) = 0 then begin
        Result := TList(m_StorageList.Objects[I]);
        Break;
      end;
    end;
  finally
    m_StorageList.UnLock();
  end;
end;

function TStorage.Add(var StorageList: TList; sChrName: string; UserItem: pTUserItem): Boolean;
var
  Storage: pTBigStorage;
begin
  Result := False;
  m_StorageList.Lock();
  try
    New(Storage);
    FillChar(Storage^.UseItems, SizeOf(TUserItem), #0);
    Storage^.boDelete := False;
    Storage^.sCharName := sChrName;
    Storage^.SaveDateTime := Now;
    Storage^.UseItems := UserItem^;
    if StorageList = nil then begin
      StorageList := TList.Create;
      m_StorageList.AddObject(sChrName, StorageList);
    end;
    StorageList.Add(Storage);
    Inc(m_ItemCount);
    Result := True;
  finally
    m_StorageList.UnLock();
  end;
end;

function TStorage.Delete(var StorageList: TList; sItemName: string; nMakeIndex: Integer): Boolean;
var
  I: Integer;
  Storage: pTBigStorage;
  UserItem: pTUserItem;
  sUserItemName: string;
begin
  Result := False;
  m_StorageList.Lock();
  try
    if StorageList <> nil then begin
      for I := StorageList.Count - 1 downto 0 do begin
        Storage := pTBigStorage(StorageList.Items[I]);
        if (Storage.UseItems.MakeIndex = nMakeIndex) and (not Storage.boDelete) then begin
          sUserItemName := '';
          if Storage.UseItems.btValue[13] = 1 then
            sUserItemName := ItemUnit.GetCustomItemName(Storage.UseItems.MakeIndex, Storage.UseItems.wIndex);
          if sUserItemName = '' then
            sUserItemName := UserEngine.GetStdItemName(Storage.UseItems.wIndex);
          if CompareText(sUserItemName, sItemName) = 0 then begin
            StorageList.Delete(I);
            Dispose(Storage);
            Dec(m_ItemCount);
            Result := True;
            Break;
          end;
        end;
      end;
      if StorageList.Count <= 0 then begin
        for I := m_StorageList.Count - 1 downto 0 do begin
          if m_StorageList.Objects[I] = StorageList then begin
            m_StorageList.Delete(I);
            FreeAndNil(StorageList);
            Break;
          end;
        end;
      end;
    end;
  finally
    m_StorageList.UnLock();
  end;
end;

function TStorage.GetItem(StorageList: TList; sItemName: string; nMakeIndex: Integer; var UserItem: TUserItem): Boolean;
var
  I: Integer;
  Storage: pTBigStorage;
  sUserItemName: string;
begin
  Result := False;
  m_StorageList.Lock();
  try
    if StorageList <> nil then begin
      for I := 0 to StorageList.Count - 1 do begin
        Storage := pTBigStorage(StorageList.Items[I]);
        if (Storage.UseItems.MakeIndex = nMakeIndex) and (not Storage.boDelete) then begin
          sUserItemName := '';
          if Storage.UseItems.btValue[13] = 1 then
            sUserItemName := ItemUnit.GetCustomItemName(Storage.UseItems.MakeIndex, Storage.UseItems.wIndex);
          if sUserItemName = '' then
            sUserItemName := UserEngine.GetStdItemName(Storage.UseItems.wIndex);
          if CompareText(sUserItemName, sItemName) = 0 then begin
            UserItem := Storage.UseItems;
            Result := True;
            Break;
          end;
        end;
      end;
    end;
  finally
    m_StorageList.UnLock();
  end;
end;

procedure TStorage.SaveToFile(const sFileName: string);
var
  I, II: Integer;
  FileHandle: Integer;
  Storage: pTBigStorage;
  List: TList;
begin
  m_StorageList.Lock();
  try
    //if FileExists(sFileName) then DeleteFile(sFileName);
    FileHandle := FileCreate(sFileName);
    if FileHandle > 0 then begin
      {FillChar(ItemCount, SizeOf(TItemCount), #0);
      for i := m_StorageList.Count - 1 downto 0 do begin
        List := TList(m_StorageList.Objects[i]);
        if List <> nil then begin
          if List.Count <= 0 then begin
            FreeAndNil(List);
            m_StorageList.Delete(i);
            Continue;
          end;
          Inc(ItemCount, List.Count);
        end else m_StorageList.Delete(i);
      end;}
      FileSeek(FileHandle, 0, 0);
      FileWrite(FileHandle, m_ItemCount, SizeOf(TItemCount));
      for I := 0 to m_StorageList.Count - 1 do begin
        List := TList(m_StorageList.Objects[I]);
        for II := 0 to List.Count - 1 do begin
          Storage := pTBigStorage(List.Items[II]);
          if not Storage.boDelete then begin
            FileWrite(FileHandle, Storage^, SizeOf(TBigStorage));
          end else begin

          end;
        end;
      end;
      FileClose(FileHandle);
    end;
  finally
    m_StorageList.UnLock();
  end;
end;

{ TGList }
constructor TGList.Create;
begin
  inherited;
  InitializeCriticalSection(CriticalSection);
end;

destructor TGList.Destroy;
begin
  DeleteCriticalSection(CriticalSection);
  inherited;
end;

procedure TGList.Lock;
begin
  EnterCriticalSection(CriticalSection);
end;

procedure TGList.UnLock;
begin
  LeaveCriticalSection(CriticalSection);
end;

{ TGStringList }

constructor TGStringList.Create;
begin
  inherited;
  InitializeCriticalSection(CriticalSection);
end;

destructor TGStringList.Destroy;
begin
  DeleteCriticalSection(CriticalSection);
  inherited;
end;

procedure TGStringList.Lock;
begin
  EnterCriticalSection(CriticalSection);
end;

procedure TGStringList.UnLock;
begin
  LeaveCriticalSection(CriticalSection);
end;

{TSellOffGoodList}


constructor TSellOffGoodList.Create;
begin
  inherited Create;
  FRecCount := 0;
  FUpDateSellOff := False;
  m_nChangeCount := 0;
  m_SellOffGoodList := TGList.Create;
end;

destructor TSellOffGoodList.Destroy;
begin
  UnLoadSellOffGoodList();
  inherited;
end;

procedure TSellOffGoodList.UnLoadSellOffGoodList();
var
  I, II: Integer;
begin
  m_SellOffGoodList.Lock();
  try
    SaveSellOffGoodList();
    FUpDateSellOff := True;
    for I := 0 to m_SellOffGoodList.Count - 1 do begin
      if m_SellOffGoodList.Count <= 0 then Break;
      if TList(m_SellOffGoodList.Items[I]).Count <= 0 then begin
        TList(m_SellOffGoodList.Items[I]).Free;
        Continue;
      end;
      for II := 0 to TList(m_SellOffGoodList.Items[I]).Count - 1 do begin
        Dispose(pTSellOffInfo(TList(m_SellOffGoodList.Items[I]).Items[II]));
      end;
      TList(m_SellOffGoodList.Items[I]).Free;
    end;
  finally
    m_SellOffGoodList.UnLock();
  end;
  m_SellOffGoodList.Free;
end;

procedure TSellOffGoodList.LoadSellOffGoodList();
var
  I: Integer;
  sFileName: string;
  FileHandle: Integer;
  List: TList;
  SellOffInfo: pTSellOffInfo;
  Header420: TSellOffHeader;
begin
  m_SellOffGoodList.Lock();
  try
    sFileName := g_Config.sEnvirDir + '\Market_SellOff\UserSellOff.sell';
    if FileExists(sFileName) then begin
      FileHandle := FileOpen(sFileName, fmOpenRead or fmShareDenyNone);
      List := nil;
      if FileHandle > 0 then begin
        if FileRead(FileHandle, Header420, SizeOf(TSellOffHeader)) = SizeOf(TSellOffHeader) then begin
          FRecCount := Header420.nItemCount;
          for I := 0 to Header420.nItemCount - 1 do begin
            New(SellOffInfo);
            FillChar(SellOffInfo.UseItems, SizeOf(TUserItem), #0);
            if (FileRead(FileHandle, SellOffInfo^, SizeOf(TSellOffInfo)) = SizeOf(TSellOffInfo)) and (SellOffInfo.UseItems.wIndex > 0) then begin
              if List = nil then begin
                List := TList.Create;
                List.Add(SellOffInfo);
              end else begin
                if pTSellOffInfo(List.Items[0]).UseItems.wIndex = SellOffInfo.UseItems.wIndex then begin
                  List.Add(SellOffInfo);
                end else begin
                  m_SellOffGoodList.Add(List);
                  List := TList.Create;
                  List.Add(SellOffInfo);
                end;
              end;
            end else begin
              Dispose(SellOffInfo);
            end;
          end;
          if List <> nil then
            m_SellOffGoodList.Add(List);
          FileClose(FileHandle);
        end;
      end;
    end else begin
      FileHandle := FileCreate(sFileName);
      if FileHandle > 0 then begin
        Header420.nItemCount := 0;

⌨️ 快捷键说明

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