MoneyProxy.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. local RemoteProxy = requireProxy( "remote/RemoteProxy" )
  2. local MoneyProxy = class( "MoneyProxy", RemoteProxy )
  3. MoneyProxy.NAME = global.ProxyTable.MoneyProxy
  4. local MoneyType = {
  5. Gold = 1,
  6. YuanBao = 2,
  7. BindYuanBao = 4,
  8. Exp = 6
  9. }
  10. function MoneyProxy:ctor()
  11. MoneyProxy.super.ctor( self )
  12. self.isInit = true
  13. self.moneyConfig = {}
  14. self.moneyData = {}
  15. self.GoldType = 1 -- 金币类型ID 唯一值
  16. self.noShowList = {}
  17. self.noSoundList = {}
  18. end
  19. function MoneyProxy:onRegister()
  20. MoneyProxy.super.onRegister(self)
  21. end
  22. function MoneyProxy:InitMoneyConfig( data )
  23. for k,v in pairs(data) do
  24. self.moneyConfig[v.Id] = v
  25. self.moneyData[v.Id] = v
  26. end
  27. end
  28. function MoneyProxy:GetMoneyConfigById( id )
  29. return self.moneyConfig[id]
  30. end
  31. function MoneyProxy:GetMoneyNameById( id )
  32. local data = self:GetMoneyConfigById( id )
  33. local name = data and data.Name
  34. return name
  35. end
  36. function MoneyProxy:GetMoneyIdByName( name )
  37. local id = nil
  38. for k,v in pairs(self.moneyConfig) do
  39. if v.Name == name then
  40. id = v.Id
  41. break
  42. end
  43. end
  44. return id
  45. end
  46. function MoneyProxy:GetMoneyDataById( id )
  47. return self.moneyData[id]
  48. end
  49. function MoneyProxy:GetMoneyCountById( id , famlilar)
  50. local data = self:GetMoneyDataById( id )
  51. if not data then
  52. print("*************************")
  53. print(" money Type is nil ")
  54. print("*************************")
  55. return 0
  56. end
  57. local count = data.Count or 0
  58. if famlilar then
  59. local ItemConfigProxy = global.Facade:retrieveProxy( global.ProxyTable.ItemConfigProxy )
  60. local moneys = ItemConfigProxy:GetSameReservedByMoneyIndex(id)
  61. for i, v in ipairs(moneys) do
  62. local otherMoney = self:GetMoneyDataById( v )
  63. count = count + (otherMoney.Count or 0)
  64. end
  65. end
  66. return count
  67. end
  68. function MoneyProxy:GetGoldType()
  69. return self.GoldType
  70. end
  71. function MoneyProxy:GetMoneyType()
  72. return MoneyType
  73. end
  74. function MoneyProxy:UpdateMoneyData( data, init)
  75. for k,v in pairs(data) do
  76. if self.moneyData[v.ID] then
  77. v.Value = v.Value or 0
  78. local baseValue = self.moneyData[v.ID].Count or 0
  79. local diff = v.Value - baseValue
  80. if diff ~= 0 or self.isInit then
  81. self.moneyData[v.ID].Count = v.Value
  82. local changeData = {
  83. id = v.ID,
  84. count = v.Value
  85. }
  86. if v.ID ~= MoneyType.Exp then -- 经验就不广播了
  87. global.Facade:sendNotification( global.NoticeTable.PlayerMoneyChange, changeData )
  88. ssr.ssrBridge:OnPlayerMoneyChange(changeData)
  89. SLBridge:onLUAEvent(LUA_EVENT_MONEYCHANGE, changeData)
  90. end
  91. -- init 外部加载数据
  92. if not init and not self.isInit and not self.noShowList[v.ID] then
  93. local nData = {}
  94. nData.name = self:GetMoneyDataById(v.ID).Name
  95. nData.num = math.abs(diff)
  96. local notice = global.NoticeTable.ShowCostItem
  97. if diff > 0 then
  98. notice = global.NoticeTable.ShowGetBagItem
  99. end
  100. global.Facade:sendNotification( notice, nData )
  101. end
  102. if not init and not self.isInit and not self.noSoundList[v.ID] then
  103. global.Facade:sendNotification( global.NoticeTable.Audio_Play, {type=global.MMO.SND_TYPE_MONEY} )
  104. end
  105. end
  106. end
  107. end
  108. end
  109. function MoneyProxy:InitNoShowItemList()
  110. local noShowString = SL:GetMetaValue("GAME_DATA","currency_shield") and string.split(SL:GetMetaValue("GAME_DATA","currency_shield"), "#")
  111. if noShowString and noShowString[1] and noShowString[1] ~= "" then
  112. local shield_list = string.split(noShowString[1],"|")
  113. for k,v in pairs(shield_list) do
  114. if tonumber(v) then
  115. self.noShowList[tonumber(v)] = 1
  116. end
  117. end
  118. end
  119. -- no sound
  120. if noShowString and noShowString[2] and noShowString[2] ~= "" then
  121. local no_sound_list = string.split(noShowString[2],"|")
  122. for k,v in pairs(no_sound_list) do
  123. if tonumber(v) then
  124. self.noSoundList[tonumber(v)] = 1
  125. end
  126. end
  127. end
  128. end
  129. function MoneyProxy:handle_MSG_SC_INIT_MONEY_INFO(msg)
  130. local data = ParseRawMsgToJson(msg)
  131. if not data then
  132. return
  133. end
  134. self:InitMoneyConfig(data)
  135. -- 不能在注册的时候加载配置 因为注册时还没有拉到最新配置
  136. self:InitNoShowItemList()
  137. end
  138. function MoneyProxy:handle_MSG_SC_UPDATA_MONEY_NUMBER( msg )
  139. local data = ParseRawMsgToJson(msg)
  140. if not data then
  141. return
  142. end
  143. self:UpdateMoneyData(data)
  144. if self.isInit then
  145. self.isInit = false
  146. end
  147. end
  148. function MoneyProxy:ResetInitStatus()
  149. self.isInit = true
  150. end
  151. function MoneyProxy:RegisterMsgHandler()
  152. MoneyProxy.super.RegisterMsgHandler(self)
  153. local msgType = global.MsgType
  154. -- 根据页签返回页签数据
  155. LuaRegisterMsgHandler( msgType.MSG_SC_INIT_MONEY_INFO, handler( self, self.handle_MSG_SC_INIT_MONEY_INFO) )
  156. -- 刷新角色货币
  157. LuaRegisterMsgHandler( msgType.MSG_SC_UPDATA_MONEY_NUMBER, handler( self, self.handle_MSG_SC_UPDATA_MONEY_NUMBER) )
  158. end
  159. return MoneyProxy