WarFlag.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. --涉及到的相关属性在属性表配置
  2. WarFlag = {}
  3. local this = WarFlag;
  4. local filename = "WarFlag";
  5. function WarFlag.canUseWarFlagItem(actor, itemInfo)
  6. if itemInfo == nil then
  7. return true
  8. end
  9. local cfgItem = ConfigDataManager.getTable("cfg_item", "id",itemInfo.cfgid)[1]
  10. if cfgItem.useparam == nil then
  11. return true
  12. end
  13. local useParams = string.split(cfgItem.useparam, "#")
  14. if #useParams < 2 or useParams[2] ~= "20" then
  15. return true
  16. end
  17. local equipInfos = getallequipinfo(actor)
  18. local oldFlag = nil
  19. for key, equipInfo in pairs(equipInfos) do
  20. if equipInfo.equipindex ~= nil and equipInfo.equipindex ~= 0 and equipInfo.cfgid == 23100001 then
  21. oldFlag = equipInfo
  22. break
  23. end
  24. end
  25. if oldFlag == nil then
  26. messagebox(actor,"没有装备战旗,无法使用该道具")
  27. return false
  28. end
  29. return true
  30. end
  31. --设置当前sd 并同步客户端
  32. function WarFlag.useWarFlagItem(actor, cfgId, count)
  33. local cfgItem = ConfigDataManager.getTable("cfg_item", "id",cfgId)[1]
  34. if cfgItem.useparam == nil then
  35. return
  36. end
  37. local useParams = string.split(cfgItem.useparam, "#")
  38. if #useParams < 2 or useParams[2] ~= "20" then
  39. return
  40. end
  41. local newWarFlagId = tonumber(useParams[1])
  42. local equipInfos = getallequipinfo(actor)
  43. local oldFlag = nil
  44. for key, equipInfo in pairs(equipInfos) do
  45. if equipInfo.equipindex ~= nil and equipInfo.equipindex ~= 0 and equipInfo.cfgid == 23100001 then
  46. oldFlag = equipInfo
  47. break
  48. end
  49. end
  50. if oldFlag == nil then
  51. messagebox(actor,"没有装备战旗,无法使用该道具")
  52. additemtobag(actor, cfgId, count, 0, 9999, '战旗使用失败重新添加')
  53. return
  54. end
  55. local newItemId = additemtobag(actor, newWarFlagId, 1, 0, 9999, '战旗合成')
  56. local bagList = getallbagiteminfo(actor)
  57. local newEquip=nil
  58. for _, itemInfo in pairs(bagList) do
  59. if itemInfo.id == newItemId then
  60. newEquip = itemInfo
  61. break
  62. end
  63. end
  64. takeofftheequip(actor, oldFlag.equipindex)
  65. putontheequip(actor, newEquip.bagindex, oldFlag.equipindex)
  66. local bagIndex = gainbagidxbyitemid(actor, oldFlag.id)
  67. destroyitemafter(actor, bagIndex, "战旗合成")
  68. end
  69. function WarFlag.printTable(t, indent)
  70. indent = indent or 0
  71. local spaces = string.rep(" ", indent)
  72. for k, v in pairs(t) do
  73. if type(v) == "table" then
  74. print(spaces .. tostring(k) .. ":")
  75. printTable(v, indent + 4)
  76. else
  77. print(spaces .. tostring(k) .. " = " .. tostring(v))
  78. end
  79. end
  80. end
  81. -- function getitem(actor,cfgId)
  82. -- local config = ConfigDataManager.getById("cfg_fruit", cfgId)
  83. -- if config == nil or next(config) == nil then
  84. -- -- lg('果实表中没有找到主键', cfgId)
  85. -- return 0, 0
  86. -- end
  87. -- -- lg(cfgId, count)
  88. -- local hasCount = getbagitemcountbyid(actor, cfgId)
  89. -- -- lg('拥有道具' .. cfgId .. '数量' .. hasCount)
  90. -- -- 这里加上count是因为判断的逻辑在消耗了果实之后,要判断消耗之前的
  91. -- if tonumber(hasCount)== 0 then
  92. -- -- lg('道具数量不足')
  93. -- return 0, 0
  94. -- end
  95. -- local canUse = self:canUseFruit(actor, cfgId)
  96. -- if not canUse then
  97. -- return 0, 0
  98. -- end
  99. -- end
  100. -- 检查装备栏中是否存在指定cfgid的装备
  101. -- @param actor 玩家对象
  102. -- @param cfgArray 装备配置ID
  103. -- @return boolean 是否存在
  104. function WarFlag.hasEquipInSlot(equipInfos, cfgArray)
  105. if table.isNullOrEmpty(equipInfos) then
  106. return false
  107. end
  108. for _, equipInfo in pairs(equipInfos) do
  109. -- info("WarFlag: 身上的装备,cfgId:", equipInfo.cfgid)
  110. for _, cfgId in ipairs(cfgArray) do
  111. if equipInfo.cfgid == cfgId then
  112. return true
  113. end
  114. end
  115. end
  116. return false
  117. end