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

📄 sdk.pas

📁 飞尔传奇世界的引擎代码可直接编译M2Engine 请使用Delphi编译
💻 PAS
📖 第 1 页 / 共 4 页
字号:
        FileWrite(FileHandle, Header420, SizeOf(TSellOffHeader));
        FileClose(FileHandle);
      end;
    end;
  finally
    m_SellOffGoodList.UnLock();
  end;
  //MainOutMessage('LoadSellGoodRecord: '+IntToStr(Self.Count));
end;

procedure TSellOffGoodList.GetSellOffGoodList(var SellOffList: TList);
var
  I: Integer;
  List: TList;
  SellOffInfo: pTSellOffInfo;
begin
  m_SellOffGoodList.Lock();
  try
    if SellOffList <> nil then begin
      SellOffList.Clear;
      for I := 0 to m_SellOffGoodList.Count - 1 do begin
        if m_SellOffGoodList.Count <= 0 then Break;
        List := TList(m_SellOffGoodList.Items[I]);
        if List.Count <= 0 then Continue;
        SellOffInfo := pTSellOffInfo(List.Items[0]);
        SellOffList.Add(SellOffInfo);
      end;
    end;
  finally
    m_SellOffGoodList.UnLock();
  end;
end;

procedure TSellOffGoodList.GetUserSellOffGoodListByChrName(sChrName: string; var SellOffList: TList);
var
  I, II: Integer;
  List: TList;
  SellOffInfo: pTSellOffInfo;
begin
  m_SellOffGoodList.Lock();
  try
    for I := 0 to m_SellOffGoodList.Count - 1 do begin
      if m_SellOffGoodList.Count <= 0 then Break;
      List := TList(m_SellOffGoodList.Items[I]);
      if List = nil then Continue;
      if List.Count <= 0 then Continue;
      for II := 0 to List.Count - 1 do begin
        SellOffInfo := pTSellOffInfo(List.Items[II]);
        if CompareText(SellOffInfo.sCharName, sChrName) = 0 then
          SellOffList.Add(SellOffInfo);
      end;
    end;
  finally
    m_SellOffGoodList.UnLock();
  end;
end;

procedure TSellOffGoodList.GetUserSellOffGoodListByItemName(sItemName: string; var SellOffList: TList);
var
  I: Integer;
  List: TList;
  SellOffInfo: pTSellOffInfo;
  sUserItemName: string;
  StdItem: pTStdItem;
begin
  m_SellOffGoodList.Lock();
  try
    SellOffList := nil;
    for I := 0 to m_SellOffGoodList.Count - 1 do begin
      if m_SellOffGoodList.Count <= 0 then Break;
      List := TList(m_SellOffGoodList.Items[I]);
      if List = nil then Continue;
      if List.Count <= 0 then Continue;
      SellOffInfo := pTSellOffInfo(List.Items[0]);
      sUserItemName := '';
      if SellOffInfo.UseItems.btValue[13] = 1 then
        sUserItemName := ItemUnit.GetCustomItemName(SellOffInfo.UseItems.MakeIndex, SellOffInfo.UseItems.wIndex);
      if sUserItemName = '' then
        sUserItemName := UserEngine.GetStdItemName(SellOffInfo.UseItems.wIndex);
      StdItem := UserEngine.GetStdItem(SellOffInfo.UseItems.wIndex);
      if (StdItem <> nil) and (CompareText(sUserItemName, sItemName) = 0) then begin
        SellOffList := List;
        Break;
      end;
    end;
  finally
    m_SellOffGoodList.UnLock();
  end;
end;

procedure TSellOffGoodList.GetUserSellOffGoodListByMakeIndex(nMakeIndex: Integer; var SellOffInfo: pTSellOffInfo);
var
  I, II: Integer;
  List: TList;
begin
  m_SellOffGoodList.Lock();
  try
    SellOffInfo := nil;
    for I := 0 to m_SellOffGoodList.Count - 1 do begin
      if m_SellOffGoodList.Count <= 0 then Break;
      List := TList(m_SellOffGoodList.Items[I]);
      if List.Count <= 0 then Continue;
      for II := List.Count - 1 downto 0 do begin
        if pTSellOffInfo(List.Items[II]).UseItems.MakeIndex = nMakeIndex then begin
          SellOffInfo := pTSellOffInfo(List.Items[II]);
          Break;
        end;
      end;
    end;
  finally
    m_SellOffGoodList.UnLock();
  end;
end;

procedure TSellOffGoodList.GetUserSellOffItem(sItemName: string; nMakeIndex: Integer; var SellOffInfo: pTSellOffInfo; var StdItem: pTStdItem);
var
  I, II, n01: Integer;
  List: TList;
  sUserItemName: string;
begin
  m_SellOffGoodList.Lock();
  try
    SellOffInfo := nil;
    StdItem := nil;
    n01 := 0;
    for I := 0 to m_SellOffGoodList.Count - 1 do begin
      if m_SellOffGoodList.Count <= 0 then Break;
      List := TList(m_SellOffGoodList.Items[I]);
      if List.Count <= 0 then Continue;
      SellOffInfo := pTSellOffInfo(List.Items[0]);
      sUserItemName := '';
      if SellOffInfo.UseItems.btValue[13] = 1 then
        sUserItemName := ItemUnit.GetCustomItemName(SellOffInfo.UseItems.MakeIndex, SellOffInfo.UseItems.wIndex);
      if sUserItemName = '' then
        sUserItemName := UserEngine.GetStdItemName(SellOffInfo.UseItems.wIndex);
      StdItem := UserEngine.GetStdItem(SellOffInfo.UseItems.wIndex);
      if (StdItem <> nil) and (CompareText(sUserItemName, sItemName) = 0) then begin
        for II := 0 to List.Count - 1 do begin
          SellOffInfo := pTSellOffInfo(List.Items[II]);
          if (StdItem.StdMode <= 4) or
            (StdItem.StdMode = 42) or
            (StdItem.StdMode = 31) or
            (SellOffInfo.UseItems.MakeIndex = nMakeIndex) then begin
            Inc(n01);
            Break;
          end;
        end;
        Break;
      end;
    end;
    if n01 = 0 then begin
      SellOffInfo := nil;
      StdItem := nil;
    end;
  finally
    m_SellOffGoodList.UnLock();
  end;
end;

function TSellOffGoodList.GetUserSellOffCount(sCharName: string): Integer;
var
  ItemList: TList;
  I, II: Integer;
begin
  m_SellOffGoodList.Lock();
  try
    Result := -1;
    for I := 0 to m_SellOffGoodList.Count - 1 do begin
      if m_SellOffGoodList.Count <= 0 then Break;
      ItemList := TList(m_SellOffGoodList.Items[I]);
      if ItemList.Count <= 0 then Continue;
      for II := ItemList.Count - 1 downto 0 do begin
        if ItemList.Count <= 0 then Continue;
        if CompareText(pTSellOffInfo(ItemList.Items[II]).sCharName, sCharName) = 0 then
          Inc(Result);
      end;
    end;
  finally
    m_SellOffGoodList.UnLock();
  end;
end;

function TSellOffGoodList.GetUserLimitSellOffCount(sCharName: string): Boolean;
var
  ItemList: TList;
  I, II: Integer;
  n01: Integer;
begin
  m_SellOffGoodList.Lock();
  try
    n01 := 0;
    Result := False;
    for I := 0 to m_SellOffGoodList.Count - 1 do begin
      if m_SellOffGoodList.Count <= 0 then Break;
      ItemList := TList(m_SellOffGoodList.Items[I]);
      if ItemList.Count <= 0 then Continue;
      for II := ItemList.Count - 1 downto 0 do begin
        if ItemList.Count <= 0 then Continue;
        if CompareText(pTSellOffInfo(ItemList.Items[II]).sCharName, sCharName) = 0 then begin
          Inc(n01);
          if n01 >= g_Config.nUserSellOffCount then begin
            Result := True;
            Break;
          end;
        end;
      end;
    end;
  finally
    m_SellOffGoodList.UnLock();
  end;
end;

procedure TSellOffGoodList.GetUserSellOffListByIndex(nIndex: Integer; var SellOffList: TList); //0049F118
var
  I: Integer;
  List: TList;
begin
  m_SellOffGoodList.Lock();
  try
    SellOffList := nil;
    for I := 0 to m_SellOffGoodList.Count - 1 do begin
      if nIndex <= 0 then Break;
      List := TList(m_SellOffGoodList.Items[I]);
      if List.Count > 0 then begin
        if pTSellOffInfo(List.Items[0]).UseItems.wIndex = nIndex then begin
          SellOffList := List;
          Break;
        end;
      end;
    end;
  finally
    m_SellOffGoodList.UnLock();
  end;
end;

function TSellOffGoodList.AddItemToSellOffGoodsList(SellOffInfo: pTSellOffInfo): Boolean;
var
  ItemList: TList;
begin
  m_SellOffGoodList.Lock();
  try
    Result := False;
    GetUserSellOffListByIndex(SellOffInfo.UseItems.wIndex, ItemList);
    if ItemList = nil then begin
      ItemList := TList.Create;
      m_SellOffGoodList.Add(ItemList);
    end;
    ItemList.Insert(0, SellOffInfo);
    Inc(m_nChangeCount);
    Result := True;
  finally
    m_SellOffGoodList.UnLock();
  end;
end;

function TSellOffGoodList.DelSellOffItem(nMakeIndex: Integer): Boolean;
var
  I, II: Integer;
  List: TList;
begin
  Result := False;
  m_SellOffGoodList.Lock();
  try
    for I := m_SellOffGoodList.Count - 1 downto 0 do begin
      if m_SellOffGoodList.Count <= 0 then Break;
      List := TList(m_SellOffGoodList.Items[I]);
      if List.Count <= 0 then begin
        List.Free;
        m_SellOffGoodList.Delete(I);
        Continue;
      end;
      for II := List.Count - 1 downto 0 do begin
        if pTSellOffInfo(List.Items[II]).UseItems.MakeIndex = nMakeIndex then begin
          Dispose(pTSellOffInfo(List.Items[II]));
          List.Delete(II);
          if List.Count <= 0 then begin
            List.Free;
            m_SellOffGoodList.Delete(I);
          end;
          Inc(m_nChangeCount);
          Result := True;
          Break;
        end;
      end;
    end;
  finally
    m_SellOffGoodList.UnLock();
  end;
end;

function TSellOffGoodList.SaveSellOffGoodList(): Boolean;
var
  I, II: Integer;
  sFileName: string;
  FileHandle: Integer;
  SellOffInfo: pTSellOffInfo;
  List: TList;
  Header420: TSellOffHeader;
  nChangeCount: Integer;
begin
  m_SellOffGoodList.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.sell';
      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);
        for I := m_SellOffGoodList.Count - 1 downto 0 do begin
          List := TList(m_SellOffGoodList.Items[I]);
          if List <> nil then begin
            if List.Count <= 0 then begin
              List.Free;
              m_SellOffGoodList.Delete(I);
            end;
          end;
        end;
        for I := 0 to m_SellOffGoodList.Count - 1 do begin
          List := TList(m_SellOffGoodList.Items[I]);
          if List <> nil then begin
            Inc(Header420.nItemCount, List.Count);
          end;
        end;
        FileWrite(FileHandle, Header420, SizeOf(TSellOffHeader));
        for I := 0 to m_SellOffGoodList.Count - 1 do begin
          List := TList(m_SellOffGoodList.Items[I]);
          for II := 0 to List.Count - 1 do begin
            if (List = nil) or (List.Count <= 0) then Continue;
            SellOffInfo := pTSellOffInfo(List.Items[II]);
            if SellOffInfo <> nil then
              FileWrite(FileHandle, SellOffInfo^, SizeOf(TSellOffInfo));
          end;
        end;
        FileClose(FileHandle);
      end;
      FUpDateSellOff := False;
      m_nChangeCount := 0;
      Result := True;
    end;
  finally
    m_SellOffGoodList.UnLock();
  end;
end;

{TSellOffGoldList}

constructor TSellOffGoldList.Create;
begin
  inherited Create;
  FRecCount := 0;
  FUpDateSellOff := False;
  m_nChangeCount := 0;
  m_SellOffGoldList := TGList.Create;
end;

destructor TSellOffGoldList.Destroy;
begin
  UnLoadSellOffGoldList();
  inherited;

⌨️ 快捷键说明

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