KunDunInfo.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. ---@class KunDunInfo
  2. KunDunInfo = class()
  3. local this = KunDunInfo
  4. function this:ctor()
  5. end
  6. function this:Reset()
  7. self.data = nil
  8. self.KunDunInfo={}
  9. self.kunDunFaction = {}
  10. end
  11. function this:Init()
  12. self.KunDunInfo={}
  13. self.kunDunFaction = {}
  14. self:RegistMessages()
  15. end
  16. function this:RegistMessages()
  17. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_KUN_DUN_AUCTION_PANEL_INFO,self.RES_KUN_DUN_AUCTION_PANEL_INFO,self) -- 响应昆顿竞拍面板信息
  18. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_PLAYER_ENTER_VIEW_INFO, self.RES_PLAYER_ENTER_VIEW_INFO, self) -- 响应玩家进入视野
  19. SL:RegisterLUAEvent(LUA_EVENT_CREATE_PLAYER_SUCCESS, self.LUA_EVENT_CREATE_PLAYER_SUCCESS , self)
  20. SL:RegisterTrigger(LUA_TRIGGER_CHECK_PKMODE_RELATION, self.LUA_TRIGGER_CHECK_PKMODE_RELATION , self)
  21. SL:RegisterTrigger(LUA_TRIGGER_CHECK_PKMODE_IS_ATTACK, self.LUA_TRIGGER_CHECK_PKMODE_IS_ATTACK , self)
  22. end
  23. -- 响应昆顿竞拍面板信息
  24. function this:RES_KUN_DUN_AUCTION_PANEL_INFO(_,_data)
  25. if _data and _data.isOpen and _data.goods then
  26. local all_list = {}
  27. for k, v in pairs(_data.goods) do
  28. table.insert(all_list,v)
  29. end
  30. table.sort(all_list,function(a,b)
  31. return tonumber(a.id) < tonumber(b.id)
  32. end)
  33. self.data = {goods=all_list,isOpen=_data.isOpen}
  34. else
  35. self.data = nil
  36. end
  37. end
  38. -- 响应玩家进入视野
  39. function this:RES_PLAYER_ENTER_VIEW_INFO(_,message)
  40. --SL:LogTable(message,true)
  41. if message.kunDunFaction then
  42. self.kunDunFaction[message.rid] = message.kunDunFaction
  43. local rank = self:GetFactionRank(message.kunDunFaction)
  44. -- SL:LogError(message.rid)
  45. -- SL:LogError(message.kunDunFaction)
  46. -- SL:LogError(rank)
  47. SL:SetRoleActivityCamp(tonumber(message.rid),message.kunDunFaction,rank)
  48. end
  49. end
  50. function this:KunDunTrade_IsOpen()
  51. if self.data and self.data.isOpen then
  52. local server_time = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)
  53. if self.data.goods then
  54. for k, v in ipairs(self.data.goods) do
  55. if v.endTime > server_time then
  56. return true
  57. end
  58. end
  59. end
  60. end
  61. return false
  62. end
  63. --- 筛选跨服拍卖物品
  64. function this:KunDunTrade_GetInfo(select_type,sub_type,sortType,careerType)
  65. local jinengshu = 3
  66. local select_list = {}
  67. if self.data and self.data.isOpen then
  68. local server_time = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)
  69. if self.data.goods then
  70. for k, v in ipairs(self.data.goods) do
  71. if v.endTime > server_time then
  72. local is_add = false
  73. if not select_type then
  74. is_add = true
  75. elseif select_type == jinengshu then
  76. local item = SL:GetConfig("cfg_stall",v.cfgid)
  77. if item.type == jinengshu then
  78. is_add = true
  79. end
  80. else
  81. local item = SL:GetConfig("cfg_stall",v.cfgid)
  82. if item.type == select_type and item.subType == sub_type then
  83. is_add = true
  84. end
  85. end
  86. if is_add then
  87. table.insert(select_list,v)
  88. end
  89. end
  90. end
  91. end
  92. end
  93. return select_list
  94. end
  95. function this:SetRankList(message)
  96. self.team_rankList = {}
  97. if message.factionRank then
  98. for i = 1, 3, 1 do
  99. local id = tostring(i)
  100. if message.factionRank[id] then
  101. self.team_rankList[message.factionRank[id]] = i
  102. else
  103. break
  104. end
  105. end
  106. end
  107. end
  108. function this:GetFactionRank(faction)
  109. if not self.team_rankList or not self.team_rankList[faction] then
  110. return 0
  111. end
  112. return self.team_rankList[faction]
  113. end
  114. function this:LUA_EVENT_CREATE_PLAYER_SUCCESS(_,rid)
  115. if not self.kunDunFaction[tostring(rid)] then
  116. return
  117. end
  118. local faction = self.kunDunFaction[tostring(rid)]
  119. local rank = self:GetFactionRank(faction)
  120. SL:SetRoleActivityCamp(rid,faction,rank)
  121. end
  122. --判断当前模式玩家之间的关系
  123. function this:LUA_TRIGGER_CHECK_PKMODE_RELATION(pk_mode,player1,player2)
  124. local pkMode = SL:GetMetaValue(EMetaVarGetKey.PKMODE)
  125. if pkMode == EPKMode.Camp then
  126. SL:LogError("玩家之间的关系")
  127. SL:LogError(pk_mode)
  128. -- SL:LogError(bb.id)
  129. -- SL:LogError(cc.id)
  130. local faction_1 = self.kunDunFaction[tostring(player1.id)]
  131. local faction_2 = self.kunDunFaction[tostring(player2.id)]
  132. SL:LogError(faction_1)
  133. SL:LogError(faction_2)
  134. if faction_1 == faction_2 then
  135. SL:LogError("Friend")
  136. return ERelationshipType.Friend
  137. else
  138. SL:LogError("Enemy")
  139. return ERelationshipType.Enemy
  140. end
  141. end
  142. end
  143. --判断当前模式玩家是否能被攻击
  144. function this:LUA_TRIGGER_CHECK_PKMODE_IS_ATTACK(message)
  145. --SL:LogTable(message,true)
  146. local pkMode = SL:GetMetaValue(EMetaVarGetKey.PKMODE)
  147. if pkMode == EPKMode.Camp then
  148. local my_rid = SL:GetMetaValue(EMetaVarGetKey.USER_ID)
  149. local faction_1 = self.kunDunFaction[my_rid]
  150. local faction_2 = self.kunDunFaction[tostring(message.id)]
  151. SL:LogError("是否能被攻击"..faction_1 .. " " .. faction_2)
  152. if faction_1 == faction_2 then
  153. SL:LogError("不攻击")
  154. return false
  155. else
  156. SL:LogError("攻击")
  157. return true
  158. end
  159. end
  160. end