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

📄 sdk.pas

📁 FIR引擎最新源码+注册
💻 PAS
📖 第 1 页 / 共 4 页
字号:
end;

procedure TSellOffGoldList.UnLoadSellOffGoldList();
var
  I: Integer;
begin
  m_SellOffGoldList.Lock();
  try
    SaveSellOffGoldList();
    FUpDateSellOff := True;
    for I := 0 to m_SellOffGoldList.Count - 1 do begin
      if m_SellOffGoldList.Count <= 0 then Break;
      Dispose(pTSellOffInfo(m_SellOffGoldList.Items[I]));
    end;
  finally
    m_SellOffGoldList.UnLock();
  end;
  m_SellOffGoldList.Free;
end;

procedure TSellOffGoldList.LoadSellOffGoldList();
var
  I: Integer;
  sFileName: string;
  FileHandle: Integer;
  SellOffInfo: pTSellOffInfo;
  Header420: TSellOffHeader;
begin
  m_SellOffGoldList.Lock();
  try
    sFileName := g_Config.sEnvirDir + '\Market_SellOff\UserSellOff.gold';
    if FileExists(sFileName) then begin
      FileHandle := FileOpen(sFileName, fmOpenRead or fmShareDenyNone);
      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
              m_SellOffGoldList.Add(SellOffInfo);
            end else begin
              Dispose(SellOffInfo);
            end;
          end;
          FileClose(FileHandle);
        end;
      end;
    end else begin
      FileHandle := FileCreate(sFileName);
      if FileHandle > 0 then begin
        Header420.nItemCount := 0;
        FileWrite(FileHandle, Header420, SizeOf(TSellOffHeader));
        FileClose(FileHandle);
      end;
    end;
  finally
    m_SellOffGoldList.UnLock();
  end;
end;

procedure TSellOffGoldList.GetUserSellOffGoldListByChrName(sChrName: string; var SellOffList: TList);
var
  I: Integer;
  SellOffInfo: pTSellOffInfo;
begin
  m_SellOffGoldList.Lock();
  try
    for I := 0 to m_SellOffGoldList.Count - 1 do begin
      if m_SellOffGoldList.Count <= 0 then Break;
      SellOffInfo := pTSellOffInfo(m_SellOffGoldList.Items[I]);
      if (SellOffInfo <> nil) and (CompareText(SellOffInfo.sCharName, sChrName) = 0) and (SellOffInfo.nSellGold > 0) then
        SellOffList.Add(SellOffInfo);
    end;
  finally
    m_SellOffGoldList.UnLock();
  end;
end;

function TSellOffGoldList.AddItemToSellOffGoldList(SellOffInfo: pTSellOffInfo): Boolean;
begin
  m_SellOffGoldList.Lock();
  try
    Result := False;
    m_SellOffGoldList.Add(SellOffInfo);
    Inc(m_nChangeCount);
    Result := True;
  finally
    m_SellOffGoldList.UnLock();
  end;
end;

function TSellOffGoldList.DelSellOffGoldItem(nMakeIndex: Integer): Boolean;
var
  I: Integer;
begin
  m_SellOffGoldList.Lock();
  try
    Result := False;
    for I := m_SellOffGoldList.Count - 1 downto 0 do begin
      if m_SellOffGoldList.Count <= 0 then Break;
      if pTSellOffInfo(m_SellOffGoldList.Items[I]).UseItems.MakeIndex = nMakeIndex then begin
        Dispose(pTSellOffInfo(m_SellOffGoldList.Items[I]));
        m_SellOffGoldList.Delete(I);
        Inc(m_nChangeCount);
        Result := True;
        Break;
      end;
    end;
  finally
    m_SellOffGoldList.UnLock();
  end;
end;

function TSellOffGoldList.SaveSellOffGoldList(): Boolean;
var
  I: Integer;
  sFileName: string;
  FileHandle: Integer;
  SellOffInfo: pTSellOffInfo;
  Header420: TSellOffHeader; //Inc(m_nChangeCount);
  nChangeCount: Integer;
begin
  m_SellOffGoldList.Lock();
  try
    Result := False;
    if (g_boExitServer) and (m_nChangeCount <= 0) then m_nChangeCount := 1;
    if (not FUpDateSellOff) and (m_nChangeCount > 0) then begin
      nChangeCount := m_nChangeCount;
      FUpDateSellOff := True;
      sFileName := g_Config.sEnvirDir + '\Market_SellOff\UserSellOff.gold';
      if FileExists(sFileName) then begin
        FileHandle := FileOpen(sFileName, fmOpenWrite or fmShareDenyNone);
      end else begin
        FileHandle := FileCreate(sFileName);
      end;
      if FileHandle > 0 then begin
        FillChar(Header420, SizeOf(TSellOffHeader), #0);
        Header420.nItemCount := m_SellOffGoldList.Count;
        FileWrite(FileHandle, Header420, SizeOf(TSellOffHeader));
        for I := 0 to m_SellOffGoldList.Count - 1 do begin
          SellOffInfo := m_SellOffGoldList.Items[I];
          if SellOffInfo <> nil then
            FileWrite(FileHandle, SellOffInfo^, SizeOf(TSellOffInfo));
        end;
        FileClose(FileHandle);
      end;
      FUpDateSellOff := False;
      m_nChangeCount := 0;
      Result := True;
    end;
  finally
    m_SellOffGoldList.UnLock();
  end;
end;

{===================================排序StringList=============================}

procedure TSortStringList.ObjectSort(Order: Boolean);
var
  nIndex, j: Integer;
  TempList: TStringList;
  MinList: TStringList;
  MaxList: TStringList;
  nMax, nMIN, nMaxIndex, nMinIndex: Integer;
begin
  TempList := TStringList.Create;
  MinList := TStringList.Create;
  MaxList := TStringList.Create;
  TempList.AddStrings(Self);
  Clear;
  while True do begin
    if TempList.Count <= 0 then Break;
    nMax := Low(Integer);
    nMIN := High(Integer);
    nMaxIndex := -1;
    nMinIndex := -1;
    nIndex := 0;
    while True do begin
      if TempList.Count <= nIndex then Break;
      j := Integer(TempList.Objects[nIndex]);
      if j > nMax then begin
        nMax := j;
        nMaxIndex := nIndex;
      end;
      if j < nMIN then begin
        nMIN := j;
        nMinIndex := nIndex;
      end;
      Inc(nIndex);
    end;
    if Order then begin
      if nMinIndex = nMaxIndex then begin
        if nMinIndex >= 0 then begin
          MinList.AddObject(TempList.Strings[nMinIndex], TempList.Objects[nMinIndex]);
          TempList.Delete(nMinIndex);
        end;
      end else begin
        if nMinIndex < nMaxIndex then begin
          if nMaxIndex >= 0 then begin
            MaxList.InsertObject(0, TempList.Strings[nMaxIndex], TempList.Objects[nMaxIndex]);
            TempList.Delete(nMaxIndex);
          end;
          if nMinIndex >= 0 then begin
            MinList.AddObject(TempList.Strings[nMinIndex], TempList.Objects[nMinIndex]);
            TempList.Delete(nMinIndex);
          end;
        end else begin
          if nMinIndex >= 0 then begin
            MinList.AddObject(TempList.Strings[nMinIndex], TempList.Objects[nMinIndex]);
            TempList.Delete(nMinIndex);
          end;
          if nMaxIndex >= 0 then begin
            MaxList.InsertObject(0, TempList.Strings[nMaxIndex], TempList.Objects[nMaxIndex]);
            TempList.Delete(nMaxIndex);
          end;
        end;
      end;
    end else begin
      if nMinIndex = nMaxIndex then begin
        if nMinIndex >= 0 then begin
          MaxList.AddObject(TempList.Strings[nMinIndex], TempList.Objects[nMinIndex]);
          TempList.Delete(nMinIndex);
        end;
      end else begin
        if nMinIndex < nMaxIndex then begin
          if nMaxIndex >= 0 then begin
            MaxList.AddObject(TempList.Strings[nMaxIndex], TempList.Objects[nMaxIndex]);
            TempList.Delete(nMaxIndex);
          end;
          if nMinIndex >= 0 then begin
            MinList.InsertObject(0, TempList.Strings[nMinIndex], TempList.Objects[nMinIndex]);
            TempList.Delete(nMinIndex);
          end;
        end else begin
          if nMinIndex >= 0 then begin
            MinList.InsertObject(0, TempList.Strings[nMinIndex], TempList.Objects[nMinIndex]);
            TempList.Delete(nMinIndex);
          end;
          if nMaxIndex >= 0 then begin
            MaxList.AddObject(TempList.Strings[nMaxIndex], TempList.Objects[nMaxIndex]);
            TempList.Delete(nMaxIndex);
          end;
        end;
      end;
    end;
  end;
  if Order then begin
    AddStrings(MinList);
    AddStrings(MaxList);
  end else begin
    AddStrings(MaxList);
    AddStrings(MinList);
  end;
  TempList.Free;
  MinList.Free;
  MaxList.Free;
end;

procedure TSortStringList.StringSort(Order: Boolean);
var
  nIndex, j: Integer;
  TempList: TStringList;
  MinList: TStringList;
  MaxList: TStringList;
  nMax, nMIN, nMaxIndex, nMinIndex: Integer;
begin
  TempList := TStringList.Create;
  MinList := TStringList.Create;
  MaxList := TStringList.Create;
  TempList.AddStrings(Self);
  Clear;
  while True do begin
    if TempList.Count <= 0 then Break;
    nMax := Low(Integer);
    nMIN := High(Integer);
    nMaxIndex := -1;
    nMinIndex := -1;
    nIndex := 0;
    while True do begin
      if TempList.Count <= nIndex then Break;
      j := StrToInt(TempList.Strings[nIndex]);
      if j > nMax then begin
        nMax := j;
        nMaxIndex := nIndex;
      end;
      if j < nMIN then begin
        nMIN := j;
        nMinIndex := nIndex;
      end;
      Inc(nIndex);
    end;
    if Order then begin
      if nMinIndex = nMaxIndex then begin
        if nMinIndex >= 0 then begin
          MinList.AddObject(TempList.Strings[nMinIndex], TempList.Objects[nMinIndex]);
          TempList.Delete(nMinIndex);
        end;
      end else begin
        if nMinIndex < nMaxIndex then begin
          if nMaxIndex >= 0 then begin
            MaxList.InsertObject(0, TempList.Strings[nMaxIndex], TempList.Objects[nMaxIndex]);
            TempList.Delete(nMaxIndex);
          end;
          if nMinIndex >= 0 then begin
            MinList.AddObject(TempList.Strings[nMinIndex], TempList.Objects[nMinIndex]);
            TempList.Delete(nMinIndex);
          end;
        end else begin
          if nMinIndex >= 0 then begin
            MinList.AddObject(TempList.Strings[nMinIndex], TempList.Objects[nMinIndex]);
            TempList.Delete(nMinIndex);
          end;
          if nMaxIndex >= 0 then begin
            MaxList.InsertObject(0, TempList.Strings[nMaxIndex], TempList.Objects[nMaxIndex]);
            TempList.Delete(nMaxIndex);
          end;
        end;
      end;
    end else begin
      if nMinIndex = nMaxIndex then begin
        if nMinIndex >= 0 then begin
          MaxList.AddObject(TempList.Strings[nMinIndex], TempList.Objects[nMinIndex]);
          TempList.Delete(nMinIndex);
        end;
      end else begin
        if nMinIndex < nMaxIndex then begin
          if nMaxIndex >= 0 then begin
            MaxList.AddObject(TempList.Strings[nMaxIndex], TempList.Objects[nMaxIndex]);
            TempList.Delete(nMaxIndex);
          end;
          if nMinIndex >= 0 then begin
            MinList.InsertObject(0, TempList.Strings[nMinIndex], TempList.Objects[nMinIndex]);
            TempList.Delete(nMinIndex);
          end;
        end else begin
          if nMinIndex >= 0 then begin
            MinList.InsertObject(0, TempList.Strings[nMinIndex], TempList.Objects[nMinIndex]);
            TempList.Delete(nMinIndex);
          end;
          if nMaxIndex >= 0 then begin
            MaxList.AddObject(TempList.Strings[nMaxIndex], TempList.Objects[nMaxIndex]);
            TempList.Delete(nMaxIndex);
          end;
        end;
      end;
    end;
  end;
  if Order then begin
    AddStrings(MinList);
    AddStrings(MaxList);
  end else begin
    AddStrings(MaxList);
    AddStrings(MinList);
  end;
  TempList.Free;
  MinList.Free;
  MaxList.Free;
end;

end.

⌨️ 快捷键说明

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