ThrowDamageNumProxy.lua 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. local DebugProxy = requireProxy("DebugProxy")
  2. local ThrowDamageNumProxy = class("ThrowDamageNumProxy", DebugProxy)
  3. ThrowDamageNumProxy.NAME = global.ProxyTable.ThrowDamageNumProxy
  4. ThrowDamageNumProxy.PARAM_TYPE = {
  5. TIME_PARAM = 1,
  6. ANCHOR_PARAM = 2,
  7. MOVEBY_ACTION = 3,
  8. SCALETO_ACTION = 4,
  9. FADETO_ACTION = 5,
  10. DELAY_ACTION = 6,
  11. MAX = 6,
  12. }
  13. local duration = 0.2
  14. --[[
  15. 自己的参数字段名:own_param
  16. 其他人的参数字段名:other_param
  17. 参数说明:
  18. TIME_PARAM = 1
  19. 时间变量(1#多少秒)
  20. ANCHOR_PARAM = 2,
  21. 锚点(2#x#Y)
  22. 左下角为(0,0),右上角为(1,1)
  23. MOVEBY_ACTION = 3,
  24. 移动(3#X#Y)
  25. SCALETO_ACTION = 4,
  26. 缩放(4#value)
  27. value范围为:0-1
  28. FADETO_ACTION = 5,
  29. 透明度(5#value)
  30. value范围为:0-1
  31. DELAY_ACTION = 6,
  32. 等待时间(6#多少秒)
  33. ]]--
  34. function ThrowDamageNumProxy:ctor()
  35. ThrowDamageNumProxy.super.ctor(self)
  36. self._config = {}
  37. end
  38. function ThrowDamageNumProxy:onRegister()
  39. ThrowDamageNumProxy.super.onRegister(self)
  40. end
  41. function ThrowDamageNumProxy:LoadConfig()
  42. self._config = requireGameConfig("cfg_damage_number")
  43. end
  44. function ThrowDamageNumProxy:GetConfig( type )
  45. if not type then
  46. return nil
  47. end
  48. return self._config[type]
  49. end
  50. function ThrowDamageNumProxy:IsThrowNum( type )
  51. local config = self:GetConfig( type )
  52. if not config then
  53. return false
  54. end
  55. return config.type == 1
  56. end
  57. function ThrowDamageNumProxy:GetThrowShowType( type )
  58. local config = self:GetConfig( type )
  59. if not config then
  60. return false
  61. end
  62. return config.type
  63. end
  64. function ThrowDamageNumProxy:GetAnimID( type )
  65. local config = self:GetConfig( type )
  66. if not config then
  67. return nil
  68. end
  69. if config.animID and config.animID ~= 0 then
  70. return config.animID
  71. end
  72. return nil
  73. end
  74. function ThrowDamageNumProxy:IsShake( type )
  75. local config = self:GetConfig( type )
  76. if not config then
  77. return false
  78. end
  79. return config.shake == 1
  80. end
  81. -- 低血预警
  82. function ThrowDamageNumProxy:IsBeDamaged( type )
  83. local config = self:GetConfig( type )
  84. if not config then
  85. return false
  86. end
  87. return config.damage_type == 1
  88. end
  89. function ThrowDamageNumProxy:GetOwnActionData( type )
  90. local config = self:GetConfig( type )
  91. if not config then
  92. return nil
  93. end
  94. if not config.ownData then
  95. config.ownData = self:parseAllStepParam( config.own_param )
  96. end
  97. return config.ownData
  98. end
  99. function ThrowDamageNumProxy:GetOtherActionData( type )
  100. local config = self:GetConfig( type )
  101. if not config then
  102. return nil
  103. end
  104. if not config.otherData then
  105. config.otherData = self:parseAllStepParam( config.other_param )
  106. end
  107. return config.otherData
  108. end
  109. function ThrowDamageNumProxy:GetOffsetData( type )
  110. local config = self:GetConfig( type )
  111. if not config then
  112. return nil
  113. end
  114. if not config.offsetData then
  115. config.offsetData = self:parseOffsetParam( config.offset_param )
  116. end
  117. return config.offsetData
  118. end
  119. local function checkSplitParam( param )
  120. if not param or string.len( param ) <= 0 then
  121. return false
  122. end
  123. return true
  124. end
  125. function ThrowDamageNumProxy:parseAllStepParam( all_steps_param )
  126. if not checkSplitParam( all_steps_param ) then
  127. return {}
  128. end
  129. -- 1#X#Y|2#0.5|3#0.5|1#X#Y&1#X#Y
  130. local steps_actions = {}
  131. local steps_param = string.split( all_steps_param, "&" )
  132. for _, step_param in ipairs( steps_param ) do -- steps
  133. if checkSplitParam( step_param ) then
  134. local actions = {}
  135. local actions_param = string.split( step_param, "|" )
  136. for _, action_param in ipairs( actions_param ) do -- actions
  137. if checkSplitParam( action_param ) then
  138. local param = string.split( action_param, "#" )
  139. if #param > 0 then
  140. local action_data = self:parseActionParam( param )
  141. if action_data then
  142. table.insert( actions, action_data )
  143. end
  144. end
  145. end
  146. end
  147. if #actions > 0 then
  148. table.insert( steps_actions, actions )
  149. end
  150. end
  151. end
  152. return steps_actions
  153. end
  154. function ThrowDamageNumProxy:parseActionParam( param )
  155. if (not param) or (#param <= 0) then
  156. return nil
  157. end
  158. local paramType = tonumber(param[1])
  159. if not paramType or paramType < 1 or paramType > self.PARAM_TYPE.MAX then
  160. return nil
  161. end
  162. local ret = { type = paramType }
  163. if paramType == self.PARAM_TYPE.ANCHOR_PARAM or paramType == self.PARAM_TYPE.MOVEBY_ACTION then
  164. ret.x = tonumber( param[2] or 0 )
  165. ret.y = tonumber( param[3] or 0 )
  166. ret.duration = duration
  167. elseif paramType == self.PARAM_TYPE.TIME_PARAM then
  168. duration = tonumber( param[2] ) or 0.2
  169. else
  170. ret.value = tonumber( param[2] ) or 1
  171. ret.duration = duration
  172. end
  173. return ret
  174. end
  175. function ThrowDamageNumProxy:parseOffsetParam( param )
  176. if not checkSplitParam( param ) then
  177. return {}
  178. end
  179. local ret = {}
  180. -- push origin pos
  181. table.insert( ret, cc.p( 0, 0 ) )
  182. local all_offsets_param = string.split( param, "|" )
  183. for _, offset_param in ipairs( all_offsets_param ) do
  184. local offset = string.split( offset_param, "#" )
  185. table.insert( ret, cc.p( tonumber( offset[1] ) or 0, tonumber( offset[2] ) or 0 ) )
  186. end
  187. return ret
  188. end
  189. function ThrowDamageNumProxy.OnUnloaded()
  190. local facade = global.Facade
  191. facade:removeProxy(ThrowDamageNumProxy.NAME)
  192. end
  193. function ThrowDamageNumProxy.Onloaded()
  194. local proxy = ThrowDamageNumProxy.new()
  195. global.Facade:registerProxy(proxy)
  196. end
  197. return ThrowDamageNumProxy