actorUtils.lua 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. local optionsUtils = requireProxy("optionsUtils")
  2. local actorUtils = {
  3. mReLvColor = nil, -- 转身变色颜色
  4. mReLvChange = nil, -- 转身变色颜色时间间隔
  5. mReLvColorCount = 0, -- 转身变色颜色的颜色数量
  6. }
  7. function SetActorProperty(actor, jsonData)
  8. -- jsonData.UserID
  9. if jsonData.race and actor.SetRace then
  10. actor:SetRace(jsonData.race)
  11. end
  12. if jsonData.RaceServer and actor.SetRaceServer then
  13. actor:SetRaceServer(jsonData.RaceServer)
  14. end
  15. if jsonData.raceImg and actor.SetRaceImg then
  16. actor:SetRaceImg(jsonData.raceImg)
  17. end
  18. if jsonData.sex and actor.SetSexID then
  19. actor:SetSexID(jsonData.sex)
  20. end
  21. if jsonData.Job and actor.SetJobID then
  22. actor:SetJobID(jsonData.Job)
  23. end
  24. if jsonData.type and actor.SetSubType then
  25. actor:SetSubType(jsonData.type)
  26. end
  27. if jsonData.nActorId and actor.SetTypeIndex then
  28. actor:SetTypeIndex(jsonData.nActorId)
  29. end
  30. if jsonData.WalkBaseSpeed and actor.SetWalkStepTime then
  31. -- max network delay.for smooth walk
  32. actor:SetWalkStepTime(jsonData.WalkBaseSpeed * 0.001)
  33. end
  34. if jsonData.WalkCurrSpeed and jsonData.WalkCurrSpeed > 0 and actor.SetWalkSpeed then
  35. if actor:IsPlayer() and actor:IsMainPlayer() then
  36. actor:SetWalkSpeed(actor:GetWalkStepTime() / (jsonData.WalkCurrSpeed * 0.001 + global.MMO.NETWORK_DELAY))
  37. else
  38. actor:SetWalkSpeed(actor:GetWalkStepTime() / (jsonData.WalkCurrSpeed * 0.001 + global.ConstantConfig.NetPlayerDelayTime * 0.001))
  39. end
  40. end
  41. if jsonData.RunBaseSpeed and actor.SetRunStepTime then
  42. -- max network delay.for smooth walk
  43. actor:SetRunStepTime(jsonData.RunBaseSpeed * 0.001)
  44. end
  45. if jsonData.RunCurrSpeed and jsonData.RunCurrSpeed > 0 and actor.SetRunSpeed then
  46. if actor:IsPlayer() and actor:IsMainPlayer() then
  47. actor:SetRunSpeed(actor:GetRunStepTime() / (jsonData.RunCurrSpeed * 0.001 + global.MMO.NETWORK_DELAY))
  48. else
  49. actor:SetRunSpeed(actor:GetRunStepTime() / (jsonData.RunCurrSpeed * 0.001 + global.ConstantConfig.NetPlayerDelayTime * 0.001))
  50. end
  51. end
  52. if jsonData.AttackBaseSpeed and actor.SetAttackStepTime then
  53. -- actor:SetAttackStepTime(jsonData.AttackBaseSpeed * 0.001)
  54. end
  55. if jsonData.AttackCurrSpeed and jsonData.AttackCurrSpeed > 0 and actor.SetAttackSpeed then
  56. actor:SetAttackSpeed(actor:GetAttackStepTime() / (jsonData.AttackCurrSpeed * 0.001))
  57. end
  58. if jsonData.MagicBaseSpeed and actor.SetMagicStepTime then
  59. -- actor:SetMagicStepTime(jsonData.MagicBaseSpeed * 0.001)
  60. end
  61. if jsonData.MagicCurrSpeed and jsonData.MagicCurrSpeed > 0 and actor.SetMagicSpeed then
  62. actor:SetMagicSpeed(actor:GetMagicStepTime() / (jsonData.MagicCurrSpeed * 0.001))
  63. end
  64. if jsonData.MasterId and actor.SetMasterID then
  65. actor:SetMasterID(jsonData.MasterId)
  66. end
  67. if jsonData.nLevel and actor.SetLevel then
  68. actor:SetLevel(jsonData.nLevel)
  69. end
  70. if jsonData.Hp and jsonData.MaxHp and actor.SetHPHUD then
  71. actor:SetHPHUD(jsonData.Hp, jsonData.MaxHp)
  72. end
  73. if jsonData.Mp and jsonData.MaxMp and actor.SetShieldHUD then
  74. actor:SetShieldHUD(jsonData.Mp, jsonData.MaxMp)
  75. end
  76. -- 内功
  77. if jsonData.InternalForce and jsonData.MaxInternalForce and actor.SetNGHUD then
  78. actor:SetNGHUD(jsonData.InternalForce, jsonData.MaxInternalForce)
  79. end
  80. if jsonData.Group and actor.SetTeamState then
  81. actor:SetTeamState(jsonData.Group)
  82. end
  83. if actor.SetStoneMode and jsonData.StoneMode then
  84. actor:SetStoneMode(jsonData.StoneMode == 1)
  85. end
  86. if actor.SetOwnerID and jsonData.OwnerID then
  87. actor:SetOwnerID(jsonData.OwnerID)
  88. end
  89. if actor.SetOwnerName and jsonData.OwnerName then
  90. actor:SetOwnerName(jsonData.OwnerName)
  91. end
  92. if actor.SetPKLv and jsonData.pklv then
  93. actor:SetPKLv(jsonData.pklv)
  94. end
  95. if actor.SetNearShow and jsonData.RangeCanFindMe then
  96. actor:SetNearShow(jsonData.RangeCanFindMe)
  97. end
  98. local mapX, mapY = jsonData.X, jsonData.Y
  99. if mapX and mapY and actor.SetInSafeZone then
  100. local MapProxy = global.Facade:retrieveProxy( global.ProxyTable.Map )
  101. actor:SetInSafeZone( MapProxy:GetInSafeArea(mapX, mapY) )
  102. end
  103. if actor.SetIsOffLine and jsonData.OffLine ~= nil then
  104. actor:SetIsOffLine(jsonData.OffLine)
  105. end
  106. if actor.SetIsThrough and jsonData.Through ~= nil then
  107. actor:SetIsThrough(jsonData.Through)
  108. end
  109. if actor.SetActionType and jsonData.ActionType then
  110. actor:SetActionType(jsonData.ActionType)
  111. end
  112. if actor.SetHuShen and jsonData.MagicShield then
  113. --设置护身状态
  114. actor:SetHuShen(jsonData.MagicShield)
  115. end
  116. if actor.SetShenMiRen and jsonData.ShenMiRen then
  117. -- 神秘人
  118. actor:SetShenMiRen(jsonData.ShenMiRen)
  119. end
  120. if actor.SetFaction then
  121. local faction = jsonData.nCamp or jsonData.campid or 0
  122. local lastFaction = actor:GetFaction()
  123. actor:SetFaction(faction)
  124. CheckActorCampValue(actor, faction, lastFaction)
  125. end
  126. if jsonData.nServerId and actor.SetServerID then -- 区服id
  127. actor:SetServerID(jsonData.nServerId)
  128. end
  129. if actor.SetNationID then --国家id
  130. actor:SetNationID( jsonData.nationid )
  131. end
  132. if actor.SetNationEnemyPK then --国家模式是否可被攻击
  133. actor:SetNationEnemyPK( jsonData.nPlayerPk )
  134. end
  135. if jsonData.bigtip and jsonData.bigtip > 0 and actor.SetBigTipIcon then -- 怪物大血条头像id
  136. actor:SetBigTipIcon( jsonData.bigtip )
  137. end
  138. if jsonData.me and actor.SetMoveEff then
  139. actor:SetMoveEff( jsonData.me )
  140. end
  141. if jsonData.noShowName and actor.SetNoShowName then
  142. actor:SetNoShowName(jsonData.noShowName)
  143. end
  144. if jsonData.noShowHPBar and actor.SetNoShowHPBar then
  145. actor:SetNoShowHPBar(jsonData.noShowHPBar)
  146. end
  147. if jsonData.Color and actor.SetNameColor then
  148. actor:SetNameColor( jsonData.Color )
  149. end
  150. if jsonData.WarZone and actor.SetWarZone then
  151. actor:SetWarZone( jsonData.WarZone )
  152. end
  153. if jsonData.STID and actor.SetSiTuID then
  154. actor:SetSiTuID( jsonData.STID )
  155. end
  156. if jsonData.DearID and actor.SetDearID then
  157. actor:SetDearID( jsonData.DearID )
  158. end
  159. if jsonData.caved ~= nil and actor.SetSleepInCave then
  160. local hide = jsonData.caved == true
  161. actor:SetSleepInCave( hide )
  162. actor:SetKeyValue(global.MMO.Is_Cave, hide)
  163. end
  164. if jsonData.IsBoss then
  165. actor:SetSubType(global.MMO.ACTOR_SUBTYPE_BOSS)
  166. end
  167. if jsonData.gmData and actor.SetGMData then
  168. actor:SetGMData(jsonData.gmData)
  169. end
  170. if jsonData.ReLv and actor.SetReLevel then
  171. actor:SetReLevel(jsonData.ReLv)
  172. end
  173. end
  174. if not global.ActorAttr then
  175. global.ActorAttr = {}
  176. end
  177. function SetActorAttrByID( actorID, key, value )
  178. if not actorID or not key then
  179. return nil
  180. end
  181. if not global.ActorAttr[actorID] then
  182. global.ActorAttr[actorID] = {}
  183. end
  184. global.ActorAttr[actorID][key] = value
  185. end
  186. function GetActorAttrByID( actorID, key )
  187. if not actorID or not key then
  188. return nil
  189. end
  190. if not global.ActorAttr[actorID] then
  191. return nil
  192. end
  193. return global.ActorAttr[actorID][key]
  194. end
  195. function SetActorAttr( actor, key, value )
  196. if not actor or not key then
  197. return nil
  198. end
  199. local actorID = actor:GetID()
  200. SetActorAttrByID( actorID, key, value )
  201. end
  202. function GetActorAttr( actor, key )
  203. if not actor or not key then
  204. return nil
  205. end
  206. local actorID = actor:GetID()
  207. return GetActorAttrByID( actorID, key )
  208. end
  209. function ClenupActorAttrByID( actorID )
  210. if not actorID then
  211. return nil
  212. end
  213. if global.ActorAttr[actorID] then
  214. global.ActorAttr[actorID] = nil
  215. end
  216. end
  217. function ClenupActorAttr( actor )
  218. if not actor then
  219. return nil
  220. end
  221. local actorID = actor:GetID()
  222. ClenupActorAttrByID( actorID )
  223. end
  224. function CalcActorDirByPos( currPos, destPos, defaultDir )
  225. local dx = destPos.x - currPos.x
  226. local dy = destPos.y - currPos.y
  227. local ret = defaultDir
  228. if dx == 0 and dy < 0 then -- top
  229. ret = 0
  230. elseif dx > 0 and dy < 0 then -- right top
  231. ret = 1
  232. elseif dx > 0 and dy == 0 then -- right
  233. ret = 2
  234. elseif dx > 0 and dy > 0 then -- right bottom
  235. ret = 3
  236. elseif dx == 0 and dy > 0 then -- bottom
  237. ret = 4
  238. elseif dx < 0 and dy > 0 then -- left bottom
  239. ret = 5
  240. elseif dx < 0 and dy == 0 then -- left
  241. ret = 6
  242. elseif dx < 0 and dy < 0 then -- left top
  243. ret = 7
  244. end
  245. return ret
  246. end
  247. function SetActorName(actor, hudParam)
  248. if not actor or not hudParam then
  249. return nil
  250. end
  251. if actor:IsPlayer() then
  252. local MapProxy = global.Facade:retrieveProxy( global.ProxyTable.Map )
  253. local isUnitveName = true
  254. local MasterID = actor:GetMasterID() or ""
  255. if actor:IsHumanoid() and MasterID == "" then
  256. isUnitveName = false
  257. end
  258. if isUnitveName and MapProxy:IsUnitiveName() then
  259. hudParam.Name = MapProxy:GetUnitiveName( true )
  260. end
  261. if isUnitveName and actor:IsShenMiRen() then
  262. hudParam.Name = GET_STRING(800720)
  263. end
  264. elseif actor:IsMonster() then
  265. if hudParam.Master then
  266. hudParam.Name = hudParam.Name .. " (" .. hudParam.Master .. ")"
  267. end
  268. end
  269. actor:SetONameStr(hudParam.Name)
  270. -- 拆分
  271. local spName = hudParam.Name or ""
  272. local nameStr = string.split(spName, "\\")
  273. local showName = nameStr[1]
  274. if actor:IsNPC() then
  275. local bubbleName = string.match(showName or "", "^$(.+)$$")
  276. if bubbleName then
  277. showName = ""
  278. actor:SetBubbleName(bubbleName)
  279. end
  280. end
  281. actor:SetName( showName or "" )
  282. -- set actor guild name
  283. local GuildID = hudParam.GuildID
  284. if hudParam.GuildName then
  285. local GuildName = hudParam.GuildName
  286. if GuildID and string.len(GuildID) > 0 then
  287. else
  288. GuildID = hudParam.guildid or ""
  289. end
  290. if GuildName and string.len( GuildName ) > 0 then
  291. actor:SetGuildName( GuildName )
  292. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  293. if mainPlayer and mainPlayer:GetGuildName() == GuildName then
  294. local needRefresh = actor:SetCampValue("InGuild", true)
  295. if needRefresh then
  296. optionsUtils:CheckOwnSidePlayerVisible(actor)
  297. end
  298. end
  299. else
  300. actor:SetGuildName( "" )
  301. local needRefresh = actor:SetCampValue("InGuild", false)
  302. if needRefresh then
  303. optionsUtils:CheckOwnSidePlayerVisible(actor)
  304. end
  305. end
  306. elseif actor:IsPlayer() then
  307. actor:SetGuildName("")
  308. local needRefresh = actor:SetCampValue("InGuild", false)
  309. if needRefresh then
  310. optionsUtils:CheckOwnSidePlayerVisible(actor)
  311. end
  312. end
  313. if actor:IsPlayer() then
  314. actor:SetGuildID(GuildID)
  315. end
  316. -- record main player name/guild
  317. local actorID = actor:GetID()
  318. local mainPlayerID = global.gamePlayerController:GetMainPlayerID()
  319. if (mainPlayerID == actorID ) then
  320. local PlayerProperty = global.Facade:retrieveProxy( global.ProxyTable.PlayerProperty )
  321. PlayerProperty:SetName( actor:GetName() )
  322. local lastGuildName = PlayerProperty:GetGuildName()
  323. PlayerProperty:SetGuildName( actor:GetGuildName() )
  324. PlayerProperty:SetMainPlayerNameColor(hudParam.Color or global.MMO.HUD_COLOR_DEFAULT)
  325. ssr.ssrBridge:OnPlayerNameInited(actor:GetName())
  326. if lastGuildName ~= actor:GetGuildName() then
  327. global.Facade:sendNotification(global.NoticeTable.MainActorChange_OwnSidePlayer, 1)
  328. end
  329. end
  330. end
  331. function CheckActorCampValue(actor, faction, lastFaction)
  332. if not actor then
  333. return
  334. end
  335. local isSet = false
  336. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  337. if mainPlayer and mainPlayer:GetID() ~= actor:GetID() then
  338. if faction and faction > 0 and faction == mainPlayer:GetFaction() then
  339. if actor.SetCampValue then
  340. local needRefresh = actor:SetCampValue("InCamp", true)
  341. if needRefresh then
  342. optionsUtils:CheckOwnSidePlayerVisible(actor)
  343. end
  344. isSet = true
  345. end
  346. end
  347. end
  348. if not isSet and actor.SetCampValue then
  349. local needRefresh = actor:SetCampValue("InCamp", false)
  350. if needRefresh then
  351. optionsUtils:CheckOwnSidePlayerVisible(actor)
  352. end
  353. end
  354. if actor:IsPlayer() and actor:IsMainPlayer() and lastFaction ~= faction then
  355. global.Facade:sendNotification(global.NoticeTable.MainActorChange_OwnSidePlayer, 3)
  356. end
  357. end
  358. ------------------------------------- player render order -------------------------------
  359. local renderOrderIdle =
  360. {
  361. { 2, 3, 5, 0, 4, 1 }, -- weapon, cloth, wings, shield, hair, left-weapon
  362. { 4, 2, 5, 0, 3, 1 },
  363. { 5, 3, 2, 0, 4, 1 },
  364. { 5, 3, 2, 0, 4, 1 },
  365. { 2, 3, 0, 4, 5, 1 },
  366. { 1, 2, 0, 5, 3, 4 },
  367. { 0, 1, 3, 5, 2, 4 },
  368. { 0, 1, 3, 5, 2, 4 },
  369. }
  370. local renderOrderRun =
  371. {
  372. { 2, 3, 5, 0, 4, 1 }, -- weapon, cloth, wings, shield, hair
  373. { 4, 2, 5, 0, 3, 1 },
  374. { 4, 2, 5, 0, 3, 1 },
  375. { 5, 3, 2, 0, 4, 1 },
  376. { 5, 1, 0, 4, 2, 3 },
  377. { 1, 2, 0, 5, 3, 4 },
  378. { 0, 1, 3, 5, 2, 4 },
  379. { 0, 1, 3, 5, 2, 4 },
  380. }
  381. local renderOrderAttack =
  382. {
  383. { 2, 3, 5, 0, 4, 1 }, -- weapon, cloth, wings, shield, hair
  384. { 4, 2, 5, 0, 3, 1 },
  385. { 4, 2, 5, 0, 3, 1 },
  386. { 5, 3, 2, 0, 4, 1 },
  387. { 5, 1, 0, 4, 2, 3 },
  388. { 1, 2, 0, 5, 3, 4 },
  389. { 0, 1, 3, 5, 2, 4 },
  390. { 0, 1, 3, 5, 2, 4 },
  391. }
  392. local renderOrderDie =
  393. {
  394. { 3, 1, 0, 4, 2, 5 }, -- weapon, cloth, wings, shield, hair
  395. { 5, 3, 2, 0, 4, 1 },
  396. { 5, 3, 2, 0, 4, 1 },
  397. { 5, 3, 2, 0, 4, 1 },
  398. { 5, 1, 0, 3, 2, 4 },
  399. { 1, 2, 0, 4, 3, 5 },
  400. { 0, 1, 3, 4, 2, 5 },
  401. { 0, 1, 3, 4, 2, 5 },
  402. }
  403. local renderOrderStuck =
  404. {
  405. { 2, 0, 3, 4, 1, 5 }, -- weapon, cloth, wings, shield, hair, left-weapon
  406. { 4, 2, 5, 0, 3, 1 },
  407. { 2, 3, 5, 0, 4, 1 },
  408. { 2, 3, 5, 0, 4, 1 },
  409. { 5, 1, 0, 4, 2, 3 },
  410. { 1, 2, 0, 5, 3, 4 },
  411. { 0, 1, 3, 5, 2, 4 },
  412. { 0, 1, 3, 5, 2, 4 },
  413. }
  414. local PlayerRenderOrder = {
  415. [global.MMO.ANIM_IDLE] = renderOrderIdle,
  416. [global.MMO.ANIM_WALK] = renderOrderIdle,
  417. [global.MMO.ANIM_ATTACK] = renderOrderAttack,
  418. [global.MMO.ANIM_SKILL] = renderOrderAttack,
  419. [global.MMO.ANIM_DIE] = renderOrderDie,
  420. [global.MMO.ANIM_RUN] = renderOrderRun,
  421. [global.MMO.ANIM_STUCK] = renderOrderStuck,
  422. [global.MMO.ANIM_SITDOWN] = renderOrderAttack,
  423. [global.MMO.ANIM_BORN] = renderOrderIdle,
  424. [global.MMO.ANIM_MINING] = renderOrderAttack,
  425. }
  426. actorUtils.PlayerRenderOrder = PlayerRenderOrder
  427. if SL:GetMetaValue("GAME_DATA", "WeaponLooksOrderUp") and next(SL:GetMetaValue("GAME_DATA", "WeaponLooksOrderUp")) then
  428. local PlayerRenderOrder = actorUtils.PlayerRenderOrder
  429. for _, param in ipairs(SL:GetMetaValue("GAME_DATA", "WeaponLooksOrderUp")) do
  430. if PlayerRenderOrder[param.act] and PlayerRenderOrder[param.act][param.dir + 1] then
  431. PlayerRenderOrder[param.act][param.dir + 1] = ReOrderPlayerRender(PlayerRenderOrder[param.act][param.dir + 1])
  432. end
  433. end
  434. end
  435. local renderWeaponOrder=
  436. {
  437. [32*100+global.MMO.ANIM_IDLE] = { -- 武器动画id*100 + 状态
  438. [5] = { 1, 2, 0, 5, 4, 3 }, -- weapon, cloth, wings, shield, hair
  439. },
  440. [32*100+global.MMO.ANIM_WALK] = {
  441. [5] = { 1, 2, 0, 5, 4, 3 }, -- weapon, cloth, wings, shield, hair
  442. },
  443. [32*100+global.MMO.ANIM_RUN] = {
  444. [5] = { 1, 2, 0, 5, 4, 3 }, -- weapon, cloth, wings, shield, hair
  445. },
  446. [32*100+global.MMO.ANIM_DIE] = {
  447. [5] = { 1, 2, 0, 5, 4, 3 }, -- weapon, cloth, wings, shield, hair
  448. }
  449. }
  450. actorUtils.PlayerWeaponRenderOrder = renderWeaponOrder
  451. ------------------------------------- player render order -------------------------------
  452. function IsSmoothMove(actor)
  453. return not global.isWinPlayMode or 1 == CHECK_SETTING(global.MMO.SETTING_IDX_WINDOW_SMOOTH_VIEW)
  454. end
  455. function CheckRunStep()
  456. local PlayerProperty = global.Facade:retrieveProxy( global.ProxyTable.PlayerProperty )
  457. local isRide = PlayerProperty:CheckIsRide()
  458. if not isRide and CHECK_SERVER_OPTION(global.MMO.SERVER_RUN_ONE) then
  459. return 1
  460. end
  461. return isRide and 3 or 2
  462. end
  463. function CheckRunAble()
  464. if global.ConstantConfig.gameOption_WalkOnly == 1 then
  465. return false
  466. end
  467. local PlayerProperty = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  468. -- 721号消息禁跑/只能走
  469. if PlayerProperty:IsNotRun() then
  470. return false
  471. end
  472. -- 血量低于10不可以跑
  473. if PlayerProperty:GetRoleCurrHP() < 10 then
  474. return false
  475. end
  476. local buffProxy = global.Facade:retrieveProxy(global.ProxyTable.Buff)
  477. return buffProxy:CheckRunEnable() == true
  478. end
  479. local moveActions = {
  480. [global.MMO.ACTION_WALK] = true, -- 走
  481. [global.MMO.ACTION_RUN] = true, -- 跑
  482. [global.MMO.ACTION_RIDE_RUN] = true, -- 坐骑跑
  483. [global.MMO.ACTION_DASH] = true, -- 野蛮
  484. [global.MMO.ACTION_ZXC] = true, -- 追心刺
  485. [global.MMO.ACTION_ONPUSH] = true, -- 被野蛮/被推开
  486. [global.MMO.ACTION_TELEPORT] = true, -- 瞬移
  487. [global.MMO.ACTION_SBYS] = true, -- 十步一杀
  488. [global.MMO.ACTION_ASSASSIN_SNEAK] = true, -- 潜行
  489. }
  490. function IsMoveAction(act)
  491. if not act then
  492. return false
  493. end
  494. return moveActions[act] == true
  495. end
  496. local launchActions = {
  497. [global.MMO.ACTION_SKILL] = true, --施法
  498. [global.MMO.ACTION_ATTACK] = true, --攻击
  499. }
  500. function IsLaunchAction(act)
  501. if not act then
  502. return false
  503. end
  504. return launchActions[act]
  505. end
  506. local skillActions = {
  507. [global.MMO.ACTION_YTPD] = true, -- 倚天辟地
  508. [global.MMO.ACTION_ZXC] = true, -- 追心刺
  509. [global.MMO.ACTION_SJS] = true, -- 三绝杀
  510. [global.MMO.ACTION_DYZ] = true, -- 断岳斩
  511. [global.MMO.ACTION_HSQJ] = true, -- 横扫千军
  512. [global.MMO.ACTION_FWJ] = true, -- 凤舞祭
  513. [global.MMO.ACTION_JLB] = true, -- 惊雷爆
  514. [global.MMO.ACTION_BTXD] = true, -- 冰天雪地
  515. [global.MMO.ACTION_SLP] = true, -- 双龙破
  516. [global.MMO.ACTION_HXJ] = true, -- 虎啸诀
  517. [global.MMO.ACTION_BGZ] = true, -- 八卦掌
  518. [global.MMO.ACTION_SYZ] = true, -- 三焰咒
  519. [global.MMO.ACTION_WJGZ] = true, -- 万剑归宗
  520. [global.MMO.ACTION_ASSASSIN_RUN] = true, -- 刺客跑步
  521. [global.MMO.ACTION_ASSASSIN_SNEAK] = true, -- 刺客潜行
  522. [global.MMO.ACTION_ASSASSIN_SMITE] = true, -- 刺客重击
  523. [global.MMO.ACTION_ASSASSIN_SKILL] = true, -- 刺客施法
  524. [global.MMO.ACTION_ASSASSIN_SY] = true, -- 刺客霜月
  525. [global.MMO.ACTION_ASSASSIN_UNKNOWN] = true, -- 刺客未知动作
  526. [global.MMO.ACTION_ASSASSIN_XFT] = true, -- 旋风腿
  527. [global.MMO.ACTION_JY] = true, -- 箭雨1
  528. [global.MMO.ACTION_JY2] = true, -- 箭雨2
  529. [global.MMO.ACTION_TSZ] = true, -- 推山掌
  530. [global.MMO.ACTION_XLFH] = true, -- 降龙伏虎
  531. }
  532. function CheckInSkillAction(action)
  533. if not action then
  534. return false
  535. end
  536. return skillActions[action] == true
  537. end
  538. local dashActions = {
  539. [global.MMO.ACTION_DASH] = true, -- 野蛮
  540. [global.MMO.ACTION_ONPUSH] = true, -- 被野蛮
  541. [global.MMO.ACTION_TELEPORT] = true, -- 瞬移
  542. [global.MMO.ACTION_SBYS] = true, -- 十步一杀
  543. [global.MMO.ACTION_DASH_FAIL] = true, -- 野蛮失败
  544. [global.MMO.ACTION_DASH_WAITING] = true, -- 追心刺
  545. }
  546. function actorUtils.CheckActionDashAble(act)
  547. if not act then
  548. return false
  549. end
  550. return dashActions[act] == nil
  551. end
  552. function actorUtils.actorZhuiXinCi(actor, mapX, mapY, dir, zxcTime)
  553. actor:SetAction(global.MMO.ACTION_IDLE, true)
  554. -- 加速中
  555. if actor:GetIsFullSpeedup() then
  556. zxcTime = zxcTime / global.MMO.DEFAULT_MUCH_FAST_TIME
  557. elseif actor:GetIsSpeedup() then
  558. zxcTime = zxcTime / global.MMO.DEFAULT_FAST_TIME_RATE
  559. end
  560. -- pos & dir
  561. local lastPos = actor:getPosition()
  562. actor:SetDirection(dir)
  563. actor:setPosition(lastPos.x, lastPos.y)
  564. global.actorManager:SetActorMapXY( actor, mapX, mapY )
  565. -- action & anim
  566. actor:SetCurrActTime(zxcTime)
  567. actor:SetAction(global.MMO.ACTION_ZXC, true)
  568. end
  569. function actorUtils.actorDash(actor, mapX, mapY, sMapX, sMapY, dir, dashTime)
  570. -- for move interrupt, force position
  571. actor:SetAction(global.MMO.ACTION_IDLE, true)
  572. -- 加速中
  573. if actor:GetIsFullSpeedup() then
  574. dashTime = dashTime / global.MMO.DEFAULT_MUCH_FAST_TIME
  575. elseif actor:GetIsSpeedup() then
  576. dashTime = dashTime / global.MMO.DEFAULT_FAST_TIME_RATE
  577. end
  578. -- 强刷位置
  579. if sMapX > 0 and sMapY > 0 then
  580. local pos = global.sceneManager:MapPos2WorldPos(sMapX, sMapY, true)
  581. actor:setPosition(pos.x, pos.y)
  582. end
  583. -- pos & dir
  584. local lastPos = actor:getPosition()
  585. actor:SetDirection(dir)
  586. actor:setPosition(lastPos.x, lastPos.y)
  587. global.actorManager:SetActorMapXY( actor, mapX, mapY )
  588. -- action & anim
  589. actor:SetCurrActTime(dashTime)
  590. actor:SetDashWaiting(false)
  591. actor:SetAction(global.MMO.ACTION_DASH, true)
  592. end
  593. function actorUtils.actorOnDash(actor, mapX, mapY, sMapX, sMapY, dir, dashTime, idleTime)
  594. -- for move interrupt, force position
  595. actor:SetAction(global.MMO.ACTION_IDLE, true)
  596. -- 加速中
  597. if actor:GetIsFullSpeedup() then
  598. dashTime = dashTime / global.MMO.DEFAULT_MUCH_FAST_TIME
  599. elseif actor:GetIsSpeedup() then
  600. dashTime = dashTime / global.MMO.DEFAULT_FAST_TIME_RATE
  601. end
  602. if actor:GetIsFullSpeedup() then
  603. idleTime = idleTime / global.MMO.DEFAULT_MUCH_FAST_TIME
  604. elseif actor:GetIsSpeedup() then
  605. idleTime = idleTime / global.MMO.DEFAULT_FAST_TIME_RATE
  606. end
  607. -- action & anim
  608. -- 位置坐标不对
  609. if mapX == actor:GetMapX() and mapY == actor:GetMapY() then
  610. local currentActT = dashTime + idleTime
  611. actor:SetAction(global.MMO.ACTION_IDLE_LOCK, true)
  612. actor.mCurrentActT = currentActT
  613. else
  614. -- 强刷位置
  615. if sMapX > 0 and sMapY > 0 then
  616. local pos = global.sceneManager:MapPos2WorldPos(sMapX, sMapY, true)
  617. actor:setPosition(pos.x, pos.y)
  618. end
  619. -- pos & dir
  620. local lastPos = actor:getPosition()
  621. actor:SetDirection(dir)
  622. actor:setPosition(lastPos.x, lastPos.y, lastPos.z)
  623. global.actorManager:SetActorMapXY( actor, mapX, mapY )
  624. -- action & anim
  625. actor:SetCurrActTime(dashTime)
  626. if actor:IsPlayer() then
  627. actor:SetOnPushIdleTime(idleTime)
  628. end
  629. actor:SetAction(global.MMO.ACTION_ONPUSH, true)
  630. end
  631. --
  632. local buffData =
  633. {
  634. actorID = actor:GetID(),
  635. buffID = global.MMO.BUFF_ID_ONDASH_IDLE,
  636. param = dashTime + idleTime,
  637. autoRemove = true,
  638. }
  639. global.Facade:sendNotification(global.NoticeTable.AddBuffEntity, buffData)
  640. end
  641. function actorUtils.actorSBYS(actor, mapX, mapY, dir)
  642. global.actorManager:SetActorMapXY( actor, mapX, mapY )
  643. actor:SetDirection(dir)
  644. actor:SetDashWaiting(false)
  645. actor:SetAction(global.MMO.ACTION_SBYS, true)
  646. end
  647. function actorUtils.actorQLS(actor, mapX, mapY, dir)
  648. global.actorManager:SetActorMapXY( actor, mapX, mapY )
  649. local worldPos = global.sceneManager:MapPos2WorldPos( mapX, mapY, true )
  650. actor:setPosition( worldPos.x, worldPos.y )
  651. actor:SetDirection(dir)
  652. actor:SetAction(global.MMO.ACTION_TELEPORT, true)
  653. actor:SetCurrActTime(0.01)
  654. end
  655. function actorUtils.calcMapDistance(sX, sY, dX, dY)
  656. return math.max(math.abs(sX - dX), math.abs(sY - dY))
  657. end
  658. function actorUtils.actorReLvData( data )
  659. data = data or {}
  660. actorUtils.mReLvColor = data.RelvColor
  661. actorUtils.mReLvChange = data.RelvChange / 1000
  662. if actorUtils.mReLvColor then
  663. actorUtils.mReLvColorCount = #actorUtils.mReLvColor
  664. actorUtils.mReLvColor[0] = actorUtils.mReLvColor[actorUtils.mReLvColorCount]
  665. actorUtils.mReLvColor[actorUtils.mReLvColorCount] = nil
  666. end
  667. end
  668. function actorUtils.actorIsReLvChange()
  669. return actorUtils.mReLvColor and actorUtils.mReLvChange
  670. end
  671. function actorUtils.actorReLvChange(actor, randomNum, timeCount)
  672. if timeCount >= 0 and timeCount < actorUtils.mReLvChange then
  673. return false
  674. end
  675. if not randomNum then
  676. return true
  677. end
  678. local hudParam = GetActorAttr( actor, global.MMO.ACTOR_ATTR_HUDPARAM )
  679. if hudParam and next(hudParam) then
  680. local index = (GetServerTime() + randomNum) % actorUtils.mReLvColorCount
  681. local newColor = actorUtils.mReLvColor[ index ] or actor:GetNameColor()
  682. local gmColor = GUIFunction.CheckGMActorNameColor and GUIFunction:CheckGMActorNameColor( actor:GetID(), newColor, true )
  683. hudParam.Color = gmColor or newColor
  684. global.Facade:sendNotification( global.NoticeTable.DelayRefreshHUDLabel, { actor = actor, actorID = actor:GetID(), hudParam = hudParam } )
  685. end
  686. return timeCount >= 0 -- <0时,hudParam可能还没值
  687. end
  688. return actorUtils