ItemExchangeCfgArray.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using ET;
  2. using System.Collections.Generic;
  3. using cfg.GfgCfg;
  4. namespace GFGGame
  5. {
  6. public class ItemExchangeCfgArray : SingletonBaseET<ItemExchangeCfgArray>
  7. {
  8. //根据已兑换次数和本次兑换次数计算所需消耗id和消耗数量
  9. public void GetMoneyIdAndNum(int itemId, int exchangedTimes, int exchangeTimesThis, out int costId,
  10. out int costNum, out int buyNum)
  11. {
  12. ItemExchangeCfg itemExchangeCfg = CommonDataManager.Tables.TblItemExchangeCfg.GetOrDefault(itemId);
  13. costId = itemExchangeCfg.CostId;
  14. costNum = 0;
  15. buyNum = 0;
  16. for (var i = exchangedTimes + 1; i <= exchangedTimes + exchangeTimesThis; i++)
  17. {
  18. GetCostAndBuyNum(itemExchangeCfg, i, out int _costNum, out int _buyNum);
  19. costNum += _costNum;
  20. buyNum += _buyNum;
  21. }
  22. }
  23. //根据第几次购买获取消耗货币个数
  24. public void GetCostAndBuyNum(ItemExchangeCfg itemExchangeCfg, int theExchangeTimes, out int costNum,
  25. out int buyNum)
  26. {
  27. costNum = 0;
  28. buyNum = 0;
  29. //每次从最高位检测
  30. if (itemExchangeCfg.Times.Count > 0)
  31. {
  32. for (var i = itemExchangeCfg.Times.Count - 1; i >= 0; i--)
  33. {
  34. var time = itemExchangeCfg.Times[i];
  35. if (theExchangeTimes >= time)
  36. {
  37. costNum = itemExchangeCfg.CostNum[i];
  38. buyNum = itemExchangeCfg.Num;
  39. break;
  40. }
  41. }
  42. }
  43. else
  44. {
  45. costNum = itemExchangeCfg.CostNum[0];
  46. buyNum = itemExchangeCfg.Num;
  47. }
  48. }
  49. }
  50. }