role_battle.go 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023
  1. package model
  2. import (
  3. "math"
  4. "math/rand"
  5. "rocommon/util"
  6. "roserver/baseserver/model"
  7. "roserver/baseserver/set"
  8. "roserver/serverproto"
  9. "strings"
  10. )
  11. func (this *Role) Income() {
  12. if this.roleBattle != nil {
  13. ret := this.roleBattle.Income()
  14. if ret != serverproto.ErrorCode_ERROR_OK {
  15. ackMsg := &serverproto.SCPlayerIncomeAck{
  16. Error: int32(ret),
  17. }
  18. this.ReplayGate(ackMsg, true)
  19. }
  20. }
  21. }
  22. // battle相关
  23. func (this *Role) BattleBossReq() {
  24. if this.roleBattle != nil {
  25. ret, deltaTime, factorList := this.roleBattle.BossRewardPre()
  26. ackMsg := &serverproto.SCBattleBossFightAck{
  27. Error: int32(ret),
  28. LeftCdTime: deltaTime,
  29. FactorList: factorList,
  30. }
  31. this.ReplayGate(ackMsg, true)
  32. if ret == serverproto.ErrorCode_ERROR_OK {
  33. //挑战时判断CD
  34. TaskMagCheck(this, serverproto.TaskType_Battle_Boss_Count, 1)
  35. }
  36. }
  37. }
  38. func (this *Role) BossReward(challengeTime uint32, mapId, mapLevel uint32, recordTimeStamp uint64) {
  39. if this.roleBattle != nil {
  40. ret := this.roleBattle.BossReward(challengeTime, mapId, mapLevel, recordTimeStamp)
  41. if ret != serverproto.ErrorCode_ERROR_OK {
  42. ackMsg := &serverproto.SCPlayerBossRewardAck{
  43. Error: int32(ret),
  44. }
  45. this.ReplayGate(ackMsg, true)
  46. }
  47. }
  48. }
  49. // evil
  50. func (this *Role) BattleEvilRefresh(bForce bool) {
  51. if this.roleBattle != nil {
  52. ret, changeIdxList := this.roleBattle.BattleEvilRefresh(bForce)
  53. ackMsg := &serverproto.SCEvilRefreshAck{
  54. Error: int32(ret),
  55. }
  56. if changeIdxList != nil {
  57. ackMsg.PosIdxList = append(changeIdxList)
  58. }
  59. this.ReplayGate(ackMsg, true)
  60. }
  61. }
  62. func (this *Role) BattleEvilChallenge(posIdx int32) {
  63. if this.roleBattle != nil {
  64. ret, addCount := this.roleBattle.BattleEvilChallenge(posIdx)
  65. ackMsg := &serverproto.SCEvilChallengeAck{
  66. Error: int32(ret),
  67. PosIdx: posIdx,
  68. AddCount: addCount,
  69. }
  70. this.ReplayGate(ackMsg, true)
  71. }
  72. }
  73. // expedition
  74. func (this *Role) ExpeditionChallengePre(expeditionType int32) {
  75. ackMsg := &serverproto.SCExpeditionChallengePreAck{
  76. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  77. }
  78. if this.roleBattle != nil {
  79. ret := this.roleBattle.ExpeditionPre(expeditionType)
  80. ackMsg.Error = int32(ret)
  81. }
  82. this.ReplayGate(ackMsg, true)
  83. }
  84. // 挑战区域地图关卡boss(结束上报)
  85. func (this *Role) ExpeditionChallenge(expeditionType, battleLevel int32, heroInfoList []*serverproto.BattleExpeditionActor,
  86. bossChangeHpList []*serverproto.BattleExpeditionActor, battleTime int32, bossIdx, flag int32) {
  87. ackMsg := &serverproto.SCExpeditionChallengeAck{
  88. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  89. }
  90. if this.roleBattle != nil {
  91. ret, bufList, isFinish := this.roleBattle.ExpeditionChallenge(expeditionType, battleLevel,
  92. heroInfoList, bossChangeHpList, battleTime, bossIdx, flag)
  93. ackMsg.Error = int32(ret)
  94. ackMsg.BuffList = bufList
  95. if isFinish {
  96. //1战斗开始,2刷新,3战斗结束 4(胜利的方式战斗结束服务之赋值)
  97. ackMsg.Flag = 4 //胜利的方式赋值成4
  98. } else {
  99. ackMsg.Flag = flag
  100. }
  101. }
  102. this.ReplayGate(ackMsg, true)
  103. }
  104. func (this *Role) ExpeditionBuffSelect(selectBuf int32) {
  105. ackMsg := &serverproto.SCExpeditionSelectBuffAck{
  106. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  107. }
  108. if this.roleBattle != nil {
  109. ret := this.roleBattle.ExpeditionBuffSelect(selectBuf)
  110. ackMsg.Error = int32(ret)
  111. }
  112. this.ReplayGate(ackMsg, true)
  113. }
  114. func (this *Role) ExpeditionReward(expeditionType, boxIdx int32) {
  115. ackMsg := &serverproto.SCExpeditionRewardAck{
  116. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  117. }
  118. if this.roleBattle != nil {
  119. ret := this.roleBattle.ExpeditionReward(expeditionType, boxIdx, ackMsg)
  120. ackMsg.Error = int32(ret)
  121. }
  122. this.ReplayGate(ackMsg, true)
  123. }
  124. func (this *Role) ExpeditionBattleHero(battleHeroList []int32) {
  125. ackMsg := &serverproto.SCExpeditionBattleHeroAck{
  126. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  127. }
  128. if this.roleBattle != nil {
  129. ret := this.roleBattle.ExpeditionBattleHero(battleHeroList)
  130. ackMsg.Error = int32(ret)
  131. }
  132. this.ReplayGate(ackMsg, true)
  133. }
  134. func (this *Role) ExpeditionCallForHelp(assistHelpUid uint64) {
  135. ackMsg := &serverproto.SCExpeditionCallForHelpAck{
  136. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  137. }
  138. if this.roleBattle != nil {
  139. ret := this.roleBattle.ExpeditionCallForHelp(assistHelpUid)
  140. ackMsg.Error = int32(ret)
  141. }
  142. this.ReplayGate(ackMsg, true)
  143. }
  144. func (this *Role) ExpeditionHelp(beHelpedUid uint64, msgType int32, helpMsgSendTime uint64) {
  145. ackMsg := &serverproto.SCExpeditionHelpAck{
  146. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  147. }
  148. if this.roleBattle != nil {
  149. ret := this.roleBattle.ExpeditionHelp(beHelpedUid, msgType, helpMsgSendTime)
  150. if ret != serverproto.ErrorCode_ERROR_OK {
  151. ackMsg.Error = int32(ret)
  152. this.ReplayGate(ackMsg, true)
  153. }
  154. }
  155. }
  156. func (this *Role) ExpeditionScoreRankList(startIdx int32) {
  157. if this.roleBattle != nil {
  158. if startIdx <= 0 || startIdx > math.MaxInt32 {
  159. ackMsg := &serverproto.SCExpeditionScoreRankListAck{
  160. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  161. }
  162. this.ReplayGate(ackMsg, true)
  163. return
  164. }
  165. ssMsg := &serverproto.SSExpeditionScoreRankListReq{
  166. StartIdx: startIdx,
  167. }
  168. this.SendRank(ssMsg)
  169. }
  170. }
  171. func (this *Role) ExpeditionPassReward(expeditionType int32) {
  172. if this.roleBattle == nil || expeditionType <= 0 {
  173. ackMsg := &serverproto.SCExpeditionPassRewardAck{
  174. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  175. }
  176. this.ReplayGate(ackMsg, true)
  177. return
  178. }
  179. ret := this.roleBattle.ExpeditionPassReward(expeditionType)
  180. if ret != serverproto.ErrorCode_ERROR_OK {
  181. ackMsg := &serverproto.SCExpeditionPassRewardAck{
  182. Error: int32(ret),
  183. }
  184. this.ReplayGate(ackMsg, true)
  185. }
  186. }
  187. func (this *Role) GetRushMapLevelReward(rushRound int32, rewardType int32) {
  188. ackMsg := &serverproto.SCRushActivityRewardAck{
  189. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  190. RewardType: rewardType,
  191. RushType: model.Rush_Type_Map,
  192. }
  193. if this.GetRoleBattle() != nil {
  194. nRet := this.GetRoleBattle().GetRushMapBaseReward(ackMsg, rushRound)
  195. ackMsg.Error = int32(nRet)
  196. }
  197. this.ReplayGate(ackMsg, true)
  198. }
  199. func (this *Role) GetRushMapInfo(ackMsg *serverproto.SCMapActivityAck, curRushRound int32) {
  200. if this.GetRoleBattle() != nil {
  201. this.GetRoleBattle().GetRushMapInfo(ackMsg, curRushRound)
  202. }
  203. }
  204. func (this *Role) GetRushMapRankReward(ssAck *serverproto.SSGetRushRewardAck) {
  205. ackMsg := &serverproto.SCRushActivityRewardAck{
  206. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  207. RewardType: model.Rush_Reward_Type_Rank,
  208. RushType: model.Rush_Type_Map,
  209. }
  210. if this.GetRoleBattle() != nil {
  211. nRet := this.GetRoleBattle().GetRushMapRankReward(ssAck)
  212. if nRet == serverproto.ErrorCode_ERROR_OK {
  213. ackMsg.ItemList = ssAck.ItemList
  214. }
  215. ackMsg.Error = int32(nRet)
  216. }
  217. this.ReplayGate(ackMsg, true)
  218. }
  219. const (
  220. MAX_BATTLEBOSS_NUM = 4
  221. //1 绿,2蓝,3紫,4金
  222. EvilBossType_Green = 1
  223. EvilBossType_Blue = 2
  224. EvilBossType_Purple = 3
  225. EvilBossType_Glod = 4
  226. )
  227. // 战斗相关处理
  228. type RoleBattle struct {
  229. SaveObject
  230. incomeTime uint64
  231. maxIncomeTime uint64
  232. mapLevel uint32
  233. mapId uint32
  234. mapLevelHard uint32 //困难模式
  235. mapIdHard uint32 //困难模式
  236. mapRewardCount uint32 //累计的挑战boss成功次数
  237. mapRewardId uint32
  238. mapRewardLevel uint32
  239. //mapRewardIdHard uint32 //困难模式
  240. //mapRewardLevelHard uint32 //困难模式
  241. mapLevelTime uint64
  242. selfRank uint32
  243. totalRanks uint32
  244. topRankList []*serverproto.RankPlayerInfo
  245. getRankTimeStamp int64
  246. mapLevelChallengeNumList []*serverproto.KeyValueType
  247. quickBattle *serverproto.QuickBattleData
  248. mapRewardShowNum uint32 //income中显示当前有多少关卡的奖励没领取
  249. /*
  250. rushMapId uint32 //冲榜地图ID
  251. rewardRound int32 //冲榜保底奖励(记录领奖轮次)
  252. fightRound int32 //冲榜轮次
  253. mapScore uint32 //冲榜积分
  254. bagScore uint32 //礼包积分
  255. rankReward int32 //推图冲榜奖励轮次
  256. */
  257. rushMap *serverproto.RushMap
  258. //evil
  259. evilData *serverproto.BattleEvilData //evil
  260. lastChallengeTime int64
  261. battleBossGapTime int64 //BOSS战斗间隔时间10秒
  262. isChallengeBegin bool
  263. //expedition
  264. expeditionData *serverproto.BattleExpedition
  265. expeditionBuffList set.Interface
  266. // bt服务器战斗加速时间
  267. lastRecordBattleAcceTime uint64 // 时间戳
  268. battleAcceDuration uint64 // 持续时间ms
  269. }
  270. func newRoleBattle(r *Role) *RoleBattle {
  271. roleBattle := &RoleBattle{
  272. SaveObject: SaveObject{
  273. role: r,
  274. },
  275. battleBossGapTime: 10,
  276. }
  277. return roleBattle
  278. }
  279. func (this *RoleBattle) Load(msg interface{}) bool {
  280. proRole := msg.(*serverproto.Role)
  281. if proRole != nil && proRole.RoleBattle != nil {
  282. this.incomeTime = proRole.RoleBattle.LastIncomeTime
  283. if this.incomeTime <= 0 {
  284. //创建新号后,默认赠送1次挂机宝箱计数 送4分钟
  285. globalIncomeTime := uint64(model.GlobalIncomeTime) * 1000
  286. this.incomeTime = this.role.RegisterTime - globalIncomeTime
  287. globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Battle_Limit_Time)]
  288. if ok {
  289. this.maxIncomeTime = uint64(globalData.IVal * 1000)
  290. }
  291. this.SetDirty(true)
  292. }
  293. this.mapLevelChallengeNumList = proRole.RoleBattle.MapChallengeNumList
  294. this.mapLevel = proRole.RoleBattle.MapLevel
  295. this.mapId = proRole.RoleBattle.MapId
  296. this.mapLevelHard = proRole.RoleBattle.MapLevelHard
  297. this.mapIdHard = proRole.RoleBattle.MapIdHard
  298. //累计的挑战boss成功次数
  299. this.mapRewardCount = proRole.RoleBattle.RewardMapCount
  300. this.mapRewardId = proRole.RoleBattle.RewardMapId
  301. this.mapRewardLevel = proRole.RoleBattle.RewardMapLevel
  302. //this.mapRewardIdHard = proRole.RoleBattle.RewardMapIdHard
  303. //this.mapRewardLevelHard = proRole.RoleBattle.RewardMapLevelHard
  304. this.mapLevelTime = proRole.RoleBattle.MapLevelTime
  305. this.lastRecordBattleAcceTime = proRole.RoleBattle.LastRecordBattleAcceTime
  306. this.battleAcceDuration = proRole.RoleBattle.BattleAcceDuration
  307. if this.mapLevel == 0 || this.mapId == 0 {
  308. this.mapLevel = 1
  309. this.mapId = 1
  310. this.SetDirty(true)
  311. }
  312. //if this.mapRewardId == 0 || this.mapRewardLevel == 0 {
  313. // this.mapRewardId = 1
  314. // this.mapRewardLevel = 1
  315. // this.SetDirty(true)
  316. //}
  317. if this.mapLevelHard == 0 || this.mapIdHard == 0 {
  318. this.mapLevelHard = 1
  319. this.mapIdHard = 1
  320. this.SetDirty(true)
  321. }
  322. //if this.mapRewardIdHard == 0 || this.mapRewardLevelHard == 0 {
  323. // this.mapRewardIdHard = 1
  324. // this.mapRewardLevelHard = 1
  325. // this.SetDirty(true)
  326. //}
  327. this.getMapRewardShowCount()
  328. this.quickBattle = &serverproto.QuickBattleData{}
  329. if proRole.RoleBattle.QuickBattle != nil {
  330. *this.quickBattle = *(proRole.RoleBattle.QuickBattle)
  331. }
  332. //evil
  333. this.loadEvil(proRole.RoleBattle)
  334. //expedition
  335. this.loadExpedition(proRole.RoleBattle)
  336. if proRole.RoleBattle.RushMap == nil {
  337. this.rushMap = &serverproto.RushMap{}
  338. this.SetDirty(true)
  339. } else {
  340. this.rushMap = proRole.RoleBattle.RushMap
  341. }
  342. // this.OnlineCheckReward(proRole.RoleBattle)
  343. }
  344. this.RefreshQuickBattle(false)
  345. return true
  346. }
  347. func (this *RoleBattle) loadEvil(tmpRoleBattle *serverproto.RoleBattle) {
  348. vipData := this.role.GetRoleBase().GetVipData(model.Vip_System_Evil)
  349. if tmpRoleBattle.EvilInfo != nil {
  350. this.evilData = tmpRoleBattle.EvilInfo
  351. if this.evilData.EvilLevel <= 0 {
  352. this.evilData.EvilLevel = 1
  353. if vipData > 0 {
  354. this.evilData.FreeCount = vipData
  355. this.evilData.TotalCount = vipData
  356. }
  357. this.evilRefresh(true, false, false)
  358. this.SetDirty(true)
  359. } else {
  360. //等级超过上限强制回退
  361. _, ok := model.ConvertEvilBossList[this.evilData.EvilLevel]
  362. if !ok {
  363. this.evilData.EvilLevel--
  364. this.SetDirty(true)
  365. }
  366. }
  367. } else {
  368. this.evilData = &serverproto.BattleEvilData{
  369. EvilLevel: 1,
  370. }
  371. if vipData > 0 {
  372. this.evilData.FreeCount = vipData
  373. this.evilData.TotalCount = vipData
  374. }
  375. this.evilRefresh(true, false, false)
  376. this.SetDirty(true)
  377. }
  378. }
  379. func (this *RoleBattle) loadExpedition(tmpRoleBattle *serverproto.RoleBattle) {
  380. this.expeditionData = tmpRoleBattle.ExpeditionInfo
  381. if this.expeditionData == nil {
  382. this.expeditionData = &serverproto.BattleExpedition{
  383. ChallengeNum: model.GlobalExpeditionChallengeNum,
  384. ExpeditionType: 1,
  385. }
  386. this.SetDirty(true)
  387. }
  388. if this.expeditionData.ExpeditionScoreResetTime <= 0 {
  389. this.expeditionData.CurExpeditionScore = 0
  390. this.expeditionData.CurExpeditionScoreMax = 0
  391. this.expeditionData.ExpeditionScoreResetTime = util.GetTimeMilliseconds()
  392. this.SetDirty(true)
  393. }
  394. if this.expeditionData.ExpeditionType <= 0 {
  395. this.expeditionData.ExpeditionType = 1
  396. this.SetDirty(true)
  397. }
  398. this.expeditionBuffList = set.New(set.NonThreadSafe)
  399. for idx := 0; idx < len(this.expeditionData.BattleBuffList); idx++ {
  400. this.expeditionBuffList.Add(this.expeditionData.BattleBuffList[idx])
  401. }
  402. if this.expeditionData.AssistNum == nil {
  403. this.expeditionData.AssistNum = &serverproto.KeyValueType{
  404. Key: model.GlobalExpeditionGuildHelpNum,
  405. Value: 0,
  406. }
  407. this.SetDirty(true)
  408. } else {
  409. if this.expeditionData.AssistNum.Key <= 0 {
  410. this.expeditionData.AssistNum.Key = model.GlobalExpeditionGuildHelpNum
  411. }
  412. this.SetDirty(true)
  413. }
  414. if this.expeditionData.BeAssistNum == nil {
  415. this.expeditionData.BeAssistNum = &serverproto.KeyValueType{
  416. Key: model.GlobalExpeditionGuildBeHelpedNum,
  417. Value: 0,
  418. }
  419. this.SetDirty(true)
  420. } else {
  421. if this.expeditionData.BeAssistNum.Key <= 0 {
  422. this.expeditionData.BeAssistNum.Key = model.GlobalExpeditionGuildBeHelpedNum
  423. this.SetDirty(true)
  424. }
  425. }
  426. }
  427. func (this *RoleBattle) Save() {
  428. this.SetDirty(false)
  429. //util.DebugF("uid=%v RoleBattle save...", this.role.GetUUid())
  430. //save to db
  431. saveMsg := &serverproto.SSBattleDataSaveReq{
  432. Battle: &serverproto.RoleBattle{
  433. LastIncomeTime: this.incomeTime,
  434. MapLevel: this.mapLevel,
  435. MapId: this.mapId,
  436. QuickBattle: this.quickBattle,
  437. RewardMapId: this.mapRewardId,
  438. RewardMapLevel: this.mapRewardLevel,
  439. RewardMapCount: this.mapRewardCount,
  440. EvilInfo: this.evilData,
  441. ExpeditionInfo: this.expeditionData,
  442. MapLevelTime: this.mapLevelTime,
  443. RushMap: this.rushMap,
  444. LastRecordBattleAcceTime: this.lastRecordBattleAcceTime,
  445. BattleAcceDuration: this.battleAcceDuration,
  446. MapIdHard: this.mapIdHard,
  447. MapLevelHard: this.mapLevelHard,
  448. //todo...
  449. //MapChallengeNumList: this.mapLevelChallengeNumList, 数据太大后续做优化处理
  450. },
  451. }
  452. this.role.SendDb(saveMsg)
  453. }
  454. func (this *RoleBattle) CopyData(data *serverproto.RoleBattle) {
  455. data.LastIncomeTime = this.incomeTime
  456. data.MapId = this.mapId
  457. data.MapLevel = this.mapLevel
  458. data.RewardMapCount = this.getMapRewardShowCount()
  459. this.quickBattle.MaxTimes = model.GlobalQuickBattleTimes
  460. vipData := this.role.GetRoleBase().GetVipData(model.Vip_System_QuickBattle)
  461. this.quickBattle.MaxTimes += vipData
  462. data.QuickBattle = this.quickBattle
  463. data.EvilInfo = this.evilData
  464. data.ExpeditionInfo = this.expeditionData
  465. data.BattleAcceDuration = this.battleAcceDuration
  466. data.LastRecordBattleAcceTime = this.lastRecordBattleAcceTime
  467. }
  468. func (this *RoleBattle) DailyReset(notify bool) {
  469. this.RefreshQuickBattle(notify)
  470. vipData := this.role.GetRoleBase().GetVipData(model.Vip_System_Evil)
  471. this.evilData.FreeCount = vipData
  472. this.evilData.TotalCount = vipData
  473. if vipData <= 0 {
  474. this.evilData.FreeLimit = true
  475. }
  476. if notify {
  477. this.evilDataChangeNtf()
  478. }
  479. this.dailyResetExpedition(notify)
  480. this.SetDirty(true)
  481. }
  482. func (this *RoleBattle) RefreshQuickBattle(bNtf bool) {
  483. if this.quickBattle == nil {
  484. return
  485. }
  486. isReset := model.IsDailyResetHour5(this.quickBattle.DrawTime * 1000)
  487. if true == isReset { //不是同一天,重置
  488. this.quickBattle.DrawTime = uint64(util.GetTimeSeconds())
  489. this.quickBattle.DayTimes = 0
  490. this.SetDirty(true)
  491. if bNtf {
  492. this.changeBattleDataNtf()
  493. }
  494. }
  495. }
  496. func (this *RoleBattle) getMapRewardShowCount() uint32 {
  497. if this.mapRewardShowNum <= 0 {
  498. this.mapRewardShowNum = this.getDeltaMapCount(this.mapRewardId, this.mapRewardLevel, this.mapId, this.mapLevel)
  499. }
  500. return this.mapRewardShowNum
  501. }
  502. func (this *RoleBattle) getDeltaMapCount(mapIdOld, mapLevelOld, mapIdNew, mapLevelNew uint32) uint32 {
  503. var rewardCount uint32 = 0
  504. if mapIdOld == mapIdNew {
  505. if mapLevelNew > mapLevelOld {
  506. rewardCount += mapLevelNew - mapLevelOld
  507. }
  508. } else if mapIdNew > mapIdOld && mapLevelNew > 0 {
  509. tmpMapId := mapIdOld
  510. tmpMapLevel := mapLevelOld
  511. for {
  512. levelId := this.getLevelId(tmpMapId, tmpMapLevel)
  513. _, ok := serverproto.LevelCfgLoader[levelId]
  514. if !ok {
  515. tmpMapId++
  516. tmpMapLevel = 1
  517. if tmpMapId > mapIdNew {
  518. break
  519. }
  520. continue
  521. }
  522. rewardCount++
  523. tmpMapLevel++
  524. if tmpMapId == mapIdNew && tmpMapLevel >= mapLevelNew {
  525. break
  526. }
  527. }
  528. }
  529. return rewardCount
  530. }
  531. // 获取关卡累计奖励
  532. func (this *RoleBattle) GetMapShowReward(addItemList map[int32]int32) {
  533. showNum := this.getMapRewardShowCount()
  534. if showNum > 0 {
  535. for idx := 0; idx < len(this.role.GetRoleBase().GetBossReward()); idx++ {
  536. item := this.role.GetRoleBase().GetBossReward()[idx]
  537. addItemList[item.Key] += item.Value
  538. }
  539. this.role.GetRoleBase().ClearBossReward()
  540. this.mapRewardShowNum = 0
  541. this.mapRewardId = this.mapId
  542. this.mapRewardLevel = this.mapLevel
  543. this.SetDirty(true)
  544. this.changeBattleDataNtf()
  545. }
  546. }
  547. func (this *RoleBattle) SendBattleData() {
  548. this.changeBattleDataNtf()
  549. }
  550. func (this *RoleBattle) addMapRewardCount(rewardCount uint32) {
  551. if rewardCount > 0 {
  552. this.mapRewardCount += rewardCount
  553. this.mapRewardShowNum += rewardCount
  554. this.SetDirty(true)
  555. }
  556. }
  557. func (this *RoleBattle) changeBattleDataNtf() {
  558. if this.quickBattle != nil && this.quickBattle.MaxTimes == 0 {
  559. maxTime := model.GlobalQuickBattleTimes
  560. vipData := this.role.GetRoleBase().GetVipData(model.Vip_System_QuickBattle)
  561. maxTime += vipData
  562. this.quickBattle.MaxTimes = int32(maxTime)
  563. this.SetDirty(true)
  564. }
  565. ntfMsg := &serverproto.SCPlayerBattleDataChangeNtf{
  566. LastIncomeTime: this.incomeTime,
  567. MapId: this.mapId,
  568. MapLevel: this.mapLevel,
  569. MaxIncomeTime: uint64(this.maxIncomeTime),
  570. QuickBattle: this.quickBattle,
  571. RewardMapCount: this.getMapRewardShowCount(),
  572. }
  573. if this.role.GetHardFight() {
  574. ntfMsg.MapId = this.mapIdHard
  575. ntfMsg.MapLevel = this.mapLevelHard
  576. }
  577. this.role.ReplayGate(ntfMsg, true)
  578. }
  579. func (this *RoleBattle) changeQuickBattleNtf(errorCode int32, itemList []*serverproto.KeyValueType) {
  580. ntfMsg := &serverproto.SCQuickBattleIncomeAck{
  581. Error: errorCode,
  582. ItemList: itemList,
  583. }
  584. this.role.ReplayGate(ntfMsg, true)
  585. }
  586. func (this *RoleBattle) SetMapRank(selfRank, totalRanks uint32, topRankList []*serverproto.RankPlayerInfo, addSystemMsg bool) {
  587. this.selfRank = selfRank
  588. this.totalRanks = totalRanks
  589. this.topRankList = topRankList
  590. //刚打完战斗时,会回调并设置,这边需要重新设置时间
  591. this.getRankTimeStamp = util.GetTimeSeconds()
  592. //util.InfoF("uid=%v SetMapRank selfRank=%v totalRanks=%v topRankList=%v", this.role.GetUUid(),
  593. // this.selfRank, this.totalRanks, this.topRankList)
  594. //第一个通过该关卡的玩家
  595. if this.selfRank == 1 && addSystemMsg {
  596. if this.mapId > 1 && this.mapLevel%5 == 0 {
  597. this.role.AddSystemMessage(SystemMessageType_PassMap,
  598. AddSystemMsg{ParamId: this.getLevelId(this.mapId, this.mapLevel)})
  599. }
  600. }
  601. }
  602. // 通关指定关卡次数,目前都是一次,后续有特殊关卡会记录通关次数
  603. func (this *RoleBattle) GetPassBattleIdNum(passBattleId int32) int32 {
  604. if this.getLevelId(this.mapId, this.mapLevel) > passBattleId {
  605. return 1
  606. }
  607. return 0
  608. }
  609. func (this *RoleBattle) SetIncomeTime(incomeTime uint64) {
  610. this.incomeTime = incomeTime
  611. this.SetDirty(true)
  612. this.changeBattleDataNtf()
  613. }
  614. func (this *RoleBattle) GetLevelId() int32 {
  615. return this.getLevelId(this.mapId, this.mapLevel)
  616. }
  617. func (this *RoleBattle) getLevelId(mapId uint32, mapLevel uint32) int32 {
  618. return int32(mapId*10000 + mapLevel)
  619. }
  620. func (this *RoleBattle) addMapRank(rewardCount uint32, oldMapId, oldMapLevel uint32, passTime uint32, recordTimeStamp uint64) {
  621. NewMapLevelId := this.getLevelId(this.mapId, this.mapLevel)
  622. oldMapLevelId := this.getLevelId(oldMapId, oldMapLevel)
  623. dbMsg := &serverproto.SSMapLevelChangeReq{
  624. NewMapLevelId: uint32(NewMapLevelId),
  625. PassTime: uint64(util.GetTimeMilliseconds()),
  626. }
  627. dbMsg.RecordInfo = &serverproto.BattleRecordInfo{
  628. Uid: this.role.GetUUid(),
  629. BattleRecordId: model.GenerateUid(),
  630. NickName: this.role.GetNickName(),
  631. ImgId: this.role.GetImageId(),
  632. Gender: this.role.GetRoleBase().GetRoleSex(),
  633. Level: this.role.GetRoleLevel(),
  634. ConfigId: this.role.GetRoleBase().RoleData().HeroData.ConfigId,
  635. FightPower: int32(this.role.roleBattleAttr.curTotalFightPower),
  636. //FightPower: int32(this.role.GetRoleFightPower().TotalFightPower),
  637. RecordTime: recordTimeStamp,
  638. BattleTime: passTime,
  639. MapLevelId: oldMapLevelId,
  640. HeadFrameId: this.role.GetRoleBase().RoleData().HeadFrameId,
  641. }
  642. oldLevelCfgData, ok := serverproto.LevelCfgLoader[oldMapLevelId]
  643. if ok {
  644. dbMsg.RecordInfo.BattleVersion = oldLevelCfgData.Version
  645. }
  646. this.role.SendRank(dbMsg)
  647. this.addMapRewardCount(rewardCount)
  648. //技能槽解锁
  649. if this.role.GetRoleSkill() != nil {
  650. this.role.GetRoleSkill().CheckSlotLockState()
  651. }
  652. //判断解锁卡槽
  653. if this.role.GetRoleCard() != nil {
  654. this.role.GetRoleCard().CheckUnLockState()
  655. }
  656. //首充是否开启 /超值礼包开启
  657. if this.role.GetRoleActivity() != nil {
  658. this.role.GetRoleActivity().FirstChargeUnlockState()
  659. //超值礼包开启
  660. this.role.GetRoleActivity().SuperChargeUnlockCheck(
  661. serverproto.UnlockChargeType_UChargeType_BattleLevel, &SuperChargeUnlockST{oldValue: oldMapLevelId})
  662. }
  663. //百人道场功能解锁
  664. if this.role.GetRoleDaoChang100() != nil {
  665. this.role.GetRoleDaoChang100().Unlock()
  666. }
  667. //BT根据关卡的功能解锁
  668. if this.role.GetRoleBT() != nil {
  669. this.role.GetRoleBT().UnlockBTSystem()
  670. }
  671. //任务处理
  672. TaskMagCheck(this.role, serverproto.TaskType_Level_Battle_Count, 0)
  673. TaskMagCheck(this.role, serverproto.TaskType_Battle_Boss_Reward_Count, 1)
  674. this.role.GetRoleBase().UpdatePlayerBriefInfo(false)
  675. this.role.GetRoleBase().SetFightPower(0)
  676. }
  677. // 收益
  678. func (this *RoleBattle) Income() serverproto.ErrorCode {
  679. levelId := this.getLevelId(this.mapId, this.mapLevel)
  680. nowTime := util.GetTimeMilliseconds()
  681. if nowTime <= this.incomeTime {
  682. util.WarnF("uid=%v now time less income time !!!", this.role.GetUUid())
  683. return serverproto.ErrorCode_ERROR_BATTLE_INCOME_INVALID
  684. }
  685. globalIncomeTime := uint64(model.GlobalIncomeTime) * 1000
  686. if this.maxIncomeTime <= 0 {
  687. this.maxIncomeTime = uint64(model.GlobalIncomeLimitTime) * 1000
  688. }
  689. //VIP额外时间
  690. extraTime := this.role.GetRoleBase().GetVipData(model.Vip_System_HungExtraTime)
  691. if extraTime > 0 {
  692. this.maxIncomeTime += uint64(extraTime) * 1000
  693. }
  694. globalIncomeLimitTime := this.maxIncomeTime
  695. deltaTime := nowTime - this.incomeTime
  696. if deltaTime < globalIncomeTime && !this.role.GetRoleBase().HasBossReward() {
  697. util.WarnF("uid=%v delta time less Global income time !!!", this.role.GetUUid())
  698. return serverproto.ErrorCode_ERROR_BATTLE_INCOME_INVALID
  699. }
  700. //超过上限时间用上限时间
  701. var incomeNum int32
  702. if deltaTime > globalIncomeLimitTime {
  703. deltaTime = globalIncomeLimitTime
  704. incomeNum = int32(deltaTime / globalIncomeTime)
  705. //设置下次收益领取时间
  706. this.SetIncomeTime(nowTime)
  707. } else {
  708. incomeNum = int32(deltaTime / globalIncomeTime)
  709. //设置下次收益领取时间
  710. this.SetIncomeTime(this.incomeTime + uint64(incomeNum)*globalIncomeTime)
  711. }
  712. //获取活动道具产出次数
  713. //util.DebugF("deltaTime:%v incomeNum:%v incomeTime:%v globalIncomeTime:%v globalIncomeLimitTime:%v",
  714. // deltaTime, incomeNum, this.incomeTime, globalIncomeTime, globalIncomeLimitTime)
  715. var addItemList = map[int32]int32{}
  716. this.levelOnlineReward(levelId, addItemList, incomeNum)
  717. //获取关卡累计奖励
  718. this.GetMapShowReward(addItemList)
  719. this.role.AddItemList(addItemList, AddFrom_Battle, true)
  720. //客户端显示
  721. ackMsg := &serverproto.SCPlayerIncomeAck{
  722. Error: int32(serverproto.ErrorCode_ERROR_OK),
  723. }
  724. for key, value := range addItemList {
  725. ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
  726. Key: key,
  727. Value: value,
  728. })
  729. }
  730. this.role.ReplayGate(ackMsg, true)
  731. TaskMagCheck(this.role, serverproto.TaskType_Get_Online_Box_Count, 1)
  732. util.DebugF("uid=%v Income dropList=%v", this.role.GetUUid(), addItemList)
  733. return serverproto.ErrorCode_ERROR_OK
  734. }
  735. func (this *RoleBattle) levelOnlineReward(levelId int32, addItemList map[int32]int32, rewardNum int32) {
  736. if rewardNum <= 0 {
  737. return
  738. }
  739. levelCfgData, ok := serverproto.LevelCfgLoader[levelId]
  740. if !ok {
  741. return
  742. }
  743. //baseExp
  744. vipBase := this.role.GetRoleBase().GetVipData(int32(model.Vip_System_HungExp))
  745. exBase := int64(vipBase) * int64(levelCfgData.BaseExpOl) * int64(rewardNum) / 10000
  746. addItemList[int32(serverproto.ResType_Res_RoleBaseExp)] = levelCfgData.BaseExpOl*rewardNum + int32(exBase)
  747. //coin
  748. vipSilver := this.role.GetRoleBase().GetVipData(int32(model.Vip_System_HungSilver))
  749. exSilver := int64(vipSilver) * int64(levelCfgData.ZenyOl) * int64(rewardNum) / 10000
  750. addItemList[int32(serverproto.ResType_Res_Coin)] = levelCfgData.ZenyOl*rewardNum + int32(exSilver)
  751. //伙伴经验
  752. vipPartner := this.role.GetRoleBase().GetVipData(int32(model.Vip_System_HungPartnerExp))
  753. exPartner := int64(vipPartner) * int64(levelCfgData.ParterOl) * int64(rewardNum) / 10000
  754. addItemList[int32(serverproto.ResType_Res_HeroBaseExp)] = levelCfgData.ParterOl*rewardNum + int32(exPartner)
  755. //Cruise
  756. vipSkill := this.role.GetRoleBase().GetVipData(int32(model.Vip_System_HungSkillExp))
  757. exSKill := int64(vipSkill) * int64(levelCfgData.CruiseOl) * int64(rewardNum) / 10000
  758. addItemList[int32(serverproto.ResType_Res_Cruise)] = levelCfgData.CruiseOl*rewardNum + int32(exSKill)
  759. //EvilExp
  760. addItemList[int32(serverproto.ResType_Res_EvilExp)] = levelCfgData.EvilOl * rewardNum
  761. //rmb
  762. addItemList[int32(serverproto.ResType_Res_Rmb)] = levelCfgData.GoldOl * rewardNum
  763. //Drop处理
  764. rand.Seed(int64(util.GetTimeMilliseconds()))
  765. for i := 0; i < int(rewardNum); i++ {
  766. dropId := this.genDropId(model.LevelDropCommonDataList, levelId)
  767. for idx := 0; idx < len(dropId); idx++ {
  768. this.DropProcess(addItemList, dropId[idx])
  769. }
  770. }
  771. //活动奖励掉落赛季
  772. for idx := 0; idx < int(rewardNum); idx++ {
  773. hpDropIdList := this.genHDDropId(model.LevelDropHDDataList, levelId)
  774. for key, val := range hpDropIdList {
  775. addItemList[key] += val
  776. }
  777. }
  778. // 特权魔魂值加成
  779. devilsUp := this.role.GetRoleBase().GetVipData(model.Vip_System_DevilsUp)
  780. if devilsUp > 0 {
  781. addItemList[int32(serverproto.ResType_Res_EvilExp)] += devilsUp * rewardNum
  782. }
  783. }
  784. func (this *RoleBattle) GMIncome(incomeTime int32) {
  785. levelId := this.getLevelId(this.mapId, this.mapLevel)
  786. incomeNum := incomeTime * 60 / model.GlobalIncomeTime
  787. var addItemList = map[int32]int32{}
  788. if incomeNum > 0 {
  789. //包含异常情况发送过大数据
  790. if incomeNum > 50 {
  791. incomeNum = 50
  792. }
  793. this.levelOnlineReward(levelId, addItemList, incomeNum)
  794. this.role.AddItemList(addItemList, AddFrom_Battle, true)
  795. }
  796. //回复客户端用户显示
  797. ackMsg := &serverproto.SCPlayerIncomeAck{
  798. Error: int32(serverproto.ErrorCode_ERROR_OK),
  799. }
  800. for key, value := range addItemList {
  801. ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
  802. Key: key,
  803. Value: value,
  804. })
  805. }
  806. this.role.ReplayGate(ackMsg, true)
  807. util.DebugF("uid=%v GMIncome incomenum=%v dropList=%v", this.role.GetUUid(), incomeNum, ackMsg)
  808. }
  809. func (this *RoleBattle) GMSetMapLevel(mapId, mapLevel uint32, b bool) {
  810. //关卡数据不存在
  811. levelId := this.getLevelId(mapId, mapLevel)
  812. _, ok := serverproto.LevelCfgLoader[levelId]
  813. if !ok {
  814. return
  815. }
  816. if b {
  817. this.mapIdHard = mapId
  818. this.mapLevelHard = mapLevel
  819. this.SetDirty(true)
  820. } else {
  821. rewardCount := this.getDeltaMapCount(this.mapId, this.mapLevel, mapId, mapLevel)
  822. oldMapId := this.mapId
  823. oldMapLevel := this.mapLevel
  824. this.mapId = mapId
  825. this.mapLevel = mapLevel
  826. this.SetDirty(true)
  827. //修改地图通关排名(需要通关该关卡)
  828. this.addMapRank(rewardCount, oldMapId, oldMapLevel, 0, 0)
  829. }
  830. this.changeBattleDataNtf()
  831. }
  832. // 开启所有解锁的关卡区域地图
  833. func (this *RoleBattle) GmExpeditionOpenAll() {
  834. if this.expeditionData != nil {
  835. for _, val := range model.ConvertExpeditionDataList {
  836. if val.ExpeditionType > this.expeditionData.ExpeditionType {
  837. this.expeditionData.ExpeditionType = val.ExpeditionType
  838. this.SetDirty(true)
  839. }
  840. }
  841. this.expeditionChangeNtf(false)
  842. }
  843. }
  844. func (this *RoleBattle) GmExpeditionOpen(level int32) {
  845. if this.expeditionData != nil {
  846. for _, val := range model.ConvertExpeditionDataList {
  847. if val.ExpeditionType == level {
  848. this.expeditionData.ExpeditionType = val.ExpeditionType
  849. this.SetDirty(true)
  850. }
  851. }
  852. this.expeditionChangeNtf(false)
  853. }
  854. }
  855. func (this *RoleBattle) GmExpeditionFightCount(count int32) {
  856. if this.expeditionData != nil {
  857. this.expeditionData.ChallengeNum = count
  858. this.SetDirty(true)
  859. this.expeditionChangeNtf(false)
  860. }
  861. }
  862. func (this *RoleBattle) GmExpeditionRankScore(score int32) {
  863. this.expeditionData.CurExpeditionScore += uint32(score)
  864. this.expeditionData.CurExpeditionScoreMax = this.expeditionData.CurExpeditionScore
  865. //update rank
  866. ssMsg := &serverproto.SSExpeditionUpdateScoreRankNtf{
  867. CurScore: this.expeditionData.CurExpeditionScoreMax,
  868. }
  869. this.role.SendRank(ssMsg)
  870. //ntf player
  871. this.expeditionChangeNtf(false)
  872. }
  873. // 点击挑战时的预处理
  874. func (this *RoleBattle) BossRewardPre() (serverproto.ErrorCode, int32, []*serverproto.KeyValueType) {
  875. this.role.roleBattleAttr.BattleAttrInit()
  876. nowTime := util.GetTimeMilliseconds()
  877. //校验是否连续战斗
  878. if this.lastChallengeTime != 0 && this.battleBossGapTime != 0 {
  879. deltaTime := int64(nowTime/1000) - this.lastChallengeTime
  880. if deltaTime < this.battleBossGapTime && deltaTime > 0 {
  881. util.InfoF("uid=%v BossRewardPre cd time!!! cdTime=%v delTime=%v", this.role.GetUUid(), this.battleBossGapTime, deltaTime)
  882. return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_CD_TIME, int32(deltaTime), nil
  883. }
  884. }
  885. this.lastChallengeTime = int64(nowTime / 1000)
  886. this.isChallengeBegin = true
  887. //获取衰减系数
  888. var decayList []*serverproto.KeyValueType
  889. var code serverproto.ErrorCode
  890. code = this.mapFightCheck()
  891. if code == serverproto.ErrorCode_ERROR_OK {
  892. var kvList = map[int32]int32{}
  893. this.getDecayList(kvList, nowTime)
  894. for k, v := range kvList {
  895. decayList = append(decayList, &serverproto.KeyValueType{Key: k, Value: v})
  896. }
  897. } else {
  898. return code, 0, decayList
  899. }
  900. //todo...
  901. //统计挑战次数z
  902. //数据量太大暂时屏蔽
  903. //mapLevel := this.GetLevelId()
  904. //bFind := false
  905. //for idx := 0; idx < len(this.mapLevelChallengeNumList); idx++ {
  906. // if this.mapLevelChallengeNumList[idx].Key == mapLevel {
  907. // this.mapLevelChallengeNumList[idx].Value++
  908. // bFind = true
  909. // this.SetDirty(true)
  910. // break
  911. // }
  912. //}
  913. //if !bFind {
  914. // this.mapLevelChallengeNumList = append(this.mapLevelChallengeNumList, &serverproto.KeyValueType{Key: mapLevel, Value: 1})
  915. // this.SetDirty(true)
  916. //}
  917. return serverproto.ErrorCode_ERROR_OK, 0, decayList
  918. }
  919. func (this *RoleBattle) getDecayList(kvList map[int32]int32, nowTime uint64) {
  920. mapLevelId := this.GetLevelId()
  921. convertData, ok := model.ConvertLevelPowerDecayFactorList[mapLevelId]
  922. if ok {
  923. convertData.GetDecayList(kvList, uint64(this.role.roleBattleAttr.curTotalFightPower))
  924. //convertData.GetDecayList(kvList, this.role.GetRoleFightPower().TotalFightPower)
  925. }
  926. convertData, ok = model.ConvertLevelTimeDecayFactorList[mapLevelId]
  927. if ok {
  928. deltaTime := (nowTime - this.mapLevelTime) / 1000
  929. deltaTime = deltaTime / 60
  930. convertData.GetDecayList(kvList, deltaTime)
  931. }
  932. if model.ConvertLevelSpAdd != nil {
  933. kvList[model.ConvertLevelSpAdd.Key] += model.ConvertLevelSpAdd.Value
  934. }
  935. util.InfoF("uid=%v RoleBattleDecay kv=%v", this.role.GetUUid(), kvList)
  936. }
  937. // 挑战BOSS奖励
  938. func (this *RoleBattle) BossReward(challengeTime uint32, mapId, mapLevel uint32, recordTimeStamp uint64) serverproto.ErrorCode {
  939. //合法性检测
  940. //机器人处理
  941. //if service.GetServiceConfig().Node.RobotMode != 1 {
  942. // ret := this.bossRewardCheck(challengeTime, mapId, mapLevel)
  943. // if ret != serverproto.ErrorCode_ERROR_OK {
  944. // return ret
  945. // }
  946. //}
  947. //ret := this.bossRewardCheck(challengeTime, mapId, mapLevel)
  948. //if ret != serverproto.ErrorCode_ERROR_OK {
  949. // return ret
  950. //}
  951. isHard := this.role.isHardFight
  952. levelId := this.getLevelId(this.mapId, this.mapLevel)
  953. if isHard {
  954. levelId = this.getLevelId(this.mapIdHard, this.mapLevelHard)
  955. }
  956. levelCfgData, ok := serverproto.LevelCfgLoader[levelId]
  957. if !ok {
  958. return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_DATA_NOT_FOUND
  959. }
  960. //checkRet := this.checkMapLevelChallenge(levelCfgData)
  961. //if checkRet != serverproto.ErrorCode_ERROR_OK {
  962. // return checkRet
  963. //}
  964. nowTime := util.GetTimeMilliseconds()
  965. oldMapId := this.mapId
  966. oldMapLevel := this.mapLevel
  967. var addItemList = map[int32]int32{}
  968. if isHard {
  969. hardLevelCfgData, ok2 := serverproto.HardLevelCfgLoader[levelId]
  970. if !ok2 {
  971. return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_DATA_NOT_FOUND
  972. }
  973. //baseExp
  974. addItemList[int32(serverproto.ResType_Res_RoleBaseExp)] = hardLevelCfgData.BaseExp
  975. //伙伴经验
  976. addItemList[int32(serverproto.ResType_Res_HeroBaseExp)] = hardLevelCfgData.Parter
  977. //jobExp
  978. addItemList[int32(serverproto.ResType_Res_RoleJobExp)] = hardLevelCfgData.JobExp
  979. //rmb
  980. addItemList[int32(serverproto.ResType_Res_Rmb)] = hardLevelCfgData.Gold
  981. //通关免费充值额度
  982. addItemList[int32(serverproto.ResType_Res_CreditRecharge)] = hardLevelCfgData.FreeInvest
  983. //cash//做活动时间判定,活动时间内才给
  984. if !this.role.FuncDisable() {
  985. if ok := CheckHDItemAdd(int32(serverproto.ResType_Res_CashTicket), this.role); ok && (hardLevelCfgData.Cash != 0) {
  986. addItemList[int32(serverproto.ResType_Res_CashTicket)] = hardLevelCfgData.Cash
  987. }
  988. }
  989. //coin
  990. addItemList[int32(serverproto.ResType_Res_Coin)] = hardLevelCfgData.Zeny
  991. dropId := this.genDropId(model.LevelDropBossDataList, levelId) //放到income中领取
  992. for idx := 0; idx < len(dropId); idx++ {
  993. this.DropProcess(addItemList, dropId[idx])
  994. }
  995. } else {
  996. //baseExp
  997. addItemList[int32(serverproto.ResType_Res_RoleBaseExp)] = levelCfgData.BaseExp
  998. //伙伴经验
  999. addItemList[int32(serverproto.ResType_Res_HeroBaseExp)] = levelCfgData.Parter
  1000. //jobExp
  1001. addItemList[int32(serverproto.ResType_Res_RoleJobExp)] = levelCfgData.JobExp
  1002. //rmb
  1003. addItemList[int32(serverproto.ResType_Res_Rmb)] = levelCfgData.Gold
  1004. //通关免费充值额度
  1005. addItemList[int32(serverproto.ResType_Res_CreditRecharge)] = levelCfgData.FreeInvest
  1006. //cash//做活动时间判定,活动时间内才给
  1007. if !this.role.FuncDisable() {
  1008. if ok := CheckHDItemAdd(int32(serverproto.ResType_Res_CashTicket), this.role); ok && (levelCfgData.Cash != 0) {
  1009. addItemList[int32(serverproto.ResType_Res_CashTicket)] = levelCfgData.Cash
  1010. }
  1011. }
  1012. //coin
  1013. addItemList[int32(serverproto.ResType_Res_Coin)] = levelCfgData.Zeny
  1014. dropId := this.genDropId(model.LevelDropBossDataList, levelId) //放到income中领取
  1015. for idx := 0; idx < len(dropId); idx++ {
  1016. this.DropProcess(addItemList, dropId[idx])
  1017. }
  1018. }
  1019. this.role.AddItemList(addItemList, AddFrom_Battle, true)
  1020. //Drop处理//放到预处理中通过income的方式来获取奖励
  1021. /*
  1022. var bossRewardList = map[int32]int32{}
  1023. dropId := this.genDropId(model.LevelDropBossDataList, levelId) //放到income中领取
  1024. this.dropProcess(bossRewardList, dropId)
  1025. this.role.GetRoleBase().AddBossReward(bossRewardList)
  1026. */
  1027. //地图处理
  1028. _, ok1 := serverproto.LevelCfgLoader[levelId+1]
  1029. if !ok1 {
  1030. nextLevelId := this.getLevelId(this.mapId+1, 1)
  1031. if isHard {
  1032. nextLevelId = this.getLevelId(this.mapIdHard+1, 1)
  1033. }
  1034. _, ok2 := serverproto.LevelCfgLoader[nextLevelId]
  1035. if !ok2 {
  1036. util.WarnF("uid=%v BossReward next level cfg data not found!!!", this.role.GetUUid())
  1037. } else {
  1038. util.InfoF("uid=%v BossReward to next mapId=%v level=%v", this.role.GetUUid(), this.mapId+1, 1)
  1039. if isHard {
  1040. this.mapIdHard++
  1041. this.mapLevelHard = 1
  1042. } else {
  1043. this.mapId++
  1044. this.mapLevel = 1
  1045. //修改地图通关排名(需要通关该关卡)
  1046. this.addMapRank(1, oldMapId, oldMapLevel, challengeTime, recordTimeStamp)
  1047. }
  1048. this.mapLevelTime = nowTime
  1049. this.SetDirty(true)
  1050. this.changeBattleDataNtf()
  1051. }
  1052. } else {
  1053. if isHard {
  1054. this.mapLevelHard++
  1055. } else {
  1056. this.mapLevel++
  1057. //修改地图通关排名(需要通关该关卡)
  1058. this.addMapRank(1, oldMapId, oldMapLevel, challengeTime, recordTimeStamp)
  1059. }
  1060. this.mapLevelTime = nowTime
  1061. this.SetDirty(true)
  1062. util.InfoF("uid=%v BossReward to next mapId=%v level=%v", this.role.GetUUid(), this.mapId, this.mapLevel)
  1063. this.changeBattleDataNtf()
  1064. }
  1065. //回复客户端用户显示
  1066. ackMsg := &serverproto.SCPlayerBossRewardAck{
  1067. Error: int32(serverproto.ErrorCode_ERROR_OK),
  1068. }
  1069. for key, value := range addItemList {
  1070. if key == 40 { //代金券不发送客户端
  1071. continue
  1072. }
  1073. ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
  1074. Key: key,
  1075. Value: value,
  1076. })
  1077. }
  1078. this.role.ReplayGate(ackMsg, true)
  1079. //this.lastChallengeTime = util.GetTimeSeconds()
  1080. this.battleBossGapTime = int64(levelCfgData.FightCD)
  1081. if levelCfgData.GuildActive != 0 {
  1082. this.role.roleGuild.AddGuildActivity(levelCfgData.GuildActive)
  1083. }
  1084. this.OnRushMapScoreChange(levelCfgData.MapScore, 0)
  1085. util.DebugF("uid=%v dropList=%v", this.role.GetUUid(), addItemList)
  1086. return serverproto.ErrorCode_ERROR_OK
  1087. }
  1088. func (this *RoleBattle) bossRewardCheck(challengeTime uint32, mapId, mapLevel uint32) serverproto.ErrorCode {
  1089. if !this.isChallengeBegin {
  1090. return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_CD_TIME
  1091. }
  1092. this.isChallengeBegin = false
  1093. //发送的关卡ID不合法(重发协议)
  1094. if mapId != this.mapId || this.mapLevel != mapLevel {
  1095. util.InfoF("uid=%v bossRewardCheck mapId=%v level=%v invalid", this.role.GetUUid(), mapId, mapLevel)
  1096. return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_INVALID
  1097. }
  1098. deltaTime := (util.GetTimeMilliseconds() - this.mapLevelTime) / 1000
  1099. //时间判断 CloseDown
  1100. levelId := this.getLevelId(this.mapId, this.mapLevel)
  1101. levelCfgData, ok := serverproto.LevelCfgLoader[levelId]
  1102. if !ok {
  1103. return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_DATA_NOT_FOUND
  1104. }
  1105. tmpStrList := strings.Split(levelCfgData.CloseDown, ";")
  1106. if len(tmpStrList) >= 2 {
  1107. tmpChallengeTime, _ := model.Str2Num(tmpStrList[0])
  1108. tmpRecharge, _ := model.Str2Num(tmpStrList[1])
  1109. //1 在对应关卡或者爬塔层的停留时间≥60分钟时,不会触发判定外挂机制
  1110. //2 玩家战力≥2.5*最低通关战力时,不会触发判定机制
  1111. fightCheck := uint64(levelCfgData.FightCheck) * 25 / 10
  1112. if tmpChallengeTime > 0 && deltaTime < 60*60 && this.role.roleBattleAttr.curTotalFightPower < uint32(fightCheck) {
  1113. if int(this.role.GetTotalRecharge()) < tmpRecharge && challengeTime < uint32(tmpChallengeTime) {
  1114. this.role.GetRoleStatistic().RecordCheatData(CheatType_NormalLevel)
  1115. return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_CD_TIME
  1116. }
  1117. }
  1118. }
  1119. //战斗力校验
  1120. return this.mapFightCheck()
  1121. }
  1122. func (this *RoleBattle) mapFightCheck() serverproto.ErrorCode {
  1123. //战斗力校验
  1124. levelId := this.getLevelId(this.mapId, this.mapLevel)
  1125. if this.role.GetHardFight() {
  1126. levelId = this.getLevelId(this.mapIdHard, this.mapLevelHard)
  1127. }
  1128. levelCfgData, ok := serverproto.LevelCfgLoader[levelId]
  1129. if !ok {
  1130. return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_DATA_NOT_FOUND
  1131. }
  1132. curTotalFightPower := this.role.roleBattleAttr.curTotalFightPower
  1133. if curTotalFightPower > 0 && curTotalFightPower < uint32(levelCfgData.FightCheck) {
  1134. //if this.role.GetRoleFightPower() != nil && this.role.GetRoleFightPower().TotalFightPower < uint64(levelCfgData.FightCheck) {
  1135. util.ErrorF("uid=%v bossRewardCheck failed levelId=%v FightCheck=%v > CurFight=%v", this.role.GetUUid(), levelId, levelCfgData.FightCheck, curTotalFightPower)
  1136. return serverproto.ErrorCode_ERROR_FIGHT_CHECK
  1137. }
  1138. return serverproto.ErrorCode_ERROR_OK
  1139. }
  1140. func (this *RoleBattle) checkMapLevelChallenge(levelCfgData *serverproto.LevelCfg) serverproto.ErrorCode {
  1141. if this.role.GetRoleLevel() < levelCfgData.FightLv {
  1142. return serverproto.ErrorCode_ERROR_ROLE_LEVEL_NOT_ENOUGH
  1143. }
  1144. //job经验限制处理
  1145. jobCfg, ok := serverproto.JobCfgLoader[this.role.GetRoleBase().RoleData().HeroData.ConfigId]
  1146. if !ok || this.role.GetJobLevel() >= jobCfg.MaxJobLv {
  1147. return serverproto.ErrorCode_ERROR_HERO_MAX_JOB_STAGE
  1148. }
  1149. return serverproto.ErrorCode_ERROR_OK
  1150. }
  1151. func (this *RoleBattle) genDropId(convertData map[int32]*model.ConvertDropData, levelId int32) []int32 {
  1152. var retDropIdList []int32
  1153. dropData, ok := convertData[levelId]
  1154. if !ok {
  1155. util.ErrorF("uid=%v genDropId level drop data not found levelId=%v", this.role.GetUUid(), levelId)
  1156. return retDropIdList
  1157. }
  1158. for _, data := range dropData.DropList {
  1159. //万分比随机
  1160. dropRate := rand.Int31n(10000)
  1161. if data.Weight >= dropRate {
  1162. retDropIdList = append(retDropIdList, data.Key)
  1163. }
  1164. }
  1165. return retDropIdList
  1166. }
  1167. func (this *RoleBattle) genHDDropId(convertData map[int32]*model.ConvertDropData, levelId int32) map[int32]int32 {
  1168. retDropIdList := map[int32]int32{}
  1169. dropData, ok := convertData[levelId]
  1170. if !ok {
  1171. util.ErrorF("uid=%v genDropId level drop data not found levelId=%v", this.role.GetUUid(), levelId)
  1172. return retDropIdList
  1173. }
  1174. for _, data := range dropData.DropList {
  1175. //万分比随机
  1176. dropRate := rand.Int31n(10000)
  1177. if data.Weight >= dropRate {
  1178. if !CheckHDItemAdd(data.Key, this.role) {
  1179. continue
  1180. }
  1181. retDropIdList[data.Key] += data.GetValue()
  1182. }
  1183. }
  1184. return retDropIdList
  1185. }
  1186. func (this *RoleBattle) DropProcess(dropList map[int32]int32, dropId int32) {
  1187. model.DropCfgProcess(dropList, dropId)
  1188. }
  1189. func (this *RoleBattle) GetMapRank() {
  1190. nowTime := util.GetTimeSeconds()
  1191. if this.getRankTimeStamp > 0 && (nowTime-this.getRankTimeStamp) < 5 {
  1192. ackMsg := &serverproto.SCGetMapRankAck{
  1193. Error: int32(serverproto.ErrorCode_ERROR_OK),
  1194. SelfRank: this.selfRank,
  1195. TotalRank: this.totalRanks,
  1196. TopPlayerList: append(this.topRankList),
  1197. }
  1198. this.role.ReplayGate(ackMsg, true)
  1199. return
  1200. }
  1201. this.getRankTimeStamp = nowTime
  1202. //重新获取排名
  1203. dbMsg := &serverproto.SSMapLevelChangeReq{}
  1204. this.role.SendRank(dbMsg)
  1205. }
  1206. func (this *RoleBattle) GetQuickBattleReward() {
  1207. //查看是否开启此功能
  1208. var itemList []*serverproto.KeyValueType
  1209. unlockData, globalOk := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Quick_Battle_Unlock)]
  1210. incomeData, incomeOk := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Battle_Income_Time)]
  1211. if !globalOk || !incomeOk || incomeData.IVal <= 0 {
  1212. this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_FAIL), itemList)
  1213. return
  1214. }
  1215. levelId := this.getLevelId(this.mapId, this.mapLevel)
  1216. if levelId <= unlockData.IVal {
  1217. util.InfoF("uid=%v QuickBattle unlock quick battle unlock=%v levelId=%v", this.role.GetUUid(), unlockData.IVal, levelId)
  1218. this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_QUICK_BATTLE_UNLOCKED), itemList) //未解锁
  1219. return
  1220. }
  1221. //检查领取上限
  1222. vipQuickBattle := this.role.GetRoleBase().GetVipData(model.Vip_System_QuickBattle)
  1223. if vipQuickBattle <= 0 {
  1224. vipQuickBattle = 0
  1225. }
  1226. MaxTime := int(model.GlobalQuickBattleTimes + vipQuickBattle)
  1227. if int32(MaxTime) <= this.quickBattle.DayTimes {
  1228. util.InfoF("uid=%v QuickBattle max draw times, DayTimes=%v maxTime=%v", this.role.GetUUid(), this.quickBattle.DayTimes, MaxTime)
  1229. this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_QUICK_BATTLE_MAX_DRAWTIMES), itemList) //最大次数
  1230. return
  1231. }
  1232. //检查领取花费
  1233. incomeCfg, ok := serverproto.QuickBattleCostCfgLoader[this.quickBattle.DayTimes+1]
  1234. if !ok {
  1235. util.InfoF("uid=%v QuickBattleCostCfgLoader not found DayTimes=%v", this.role.GetUUid(), this.quickBattle.DayTimes)
  1236. this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_FAIL), itemList)
  1237. return
  1238. }
  1239. //给奖励
  1240. levelCfgData, levelCfgOk := serverproto.LevelCfgLoader[levelId]
  1241. if !levelCfgOk {
  1242. util.InfoF("uid=%v QuickBattle reward not found levelId=%v", this.role.GetUUid(), levelId)
  1243. this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_FAIL), itemList)
  1244. return
  1245. }
  1246. //给道具CopyData
  1247. var incomeNum = Quick_Battle_Time / incomeData.IVal
  1248. var addItemList = map[int32]int32{}
  1249. //时光助力主角经验提升万分比(特权加成)
  1250. baseExpOl := levelCfgData.BaseExpOl * incomeNum
  1251. baseExpOlFactor := float32(this.role.GetRoleBase().GetVipData(model.Vip_System_QuickBattleBaseExp)) / 10000.0
  1252. baseExpOl = int32(float32(baseExpOl) * (1 + baseExpOlFactor))
  1253. addItemList[int32(serverproto.ResType_Res_RoleBaseExp)] = baseExpOl
  1254. //coin
  1255. addItemList[int32(serverproto.ResType_Res_Coin)] = levelCfgData.ZenyOl * incomeNum
  1256. //伙伴经验
  1257. addItemList[int32(serverproto.ResType_Res_HeroBaseExp)] = levelCfgData.ParterOl * incomeNum
  1258. //Cruise
  1259. addItemList[int32(serverproto.ResType_Res_Cruise)] = levelCfgData.CruiseOl * incomeNum
  1260. //魔魂值
  1261. addItemList[int32(serverproto.ResType_Res_EvilExp)] = levelCfgData.EvilOl * incomeNum
  1262. //Drop处理
  1263. rand.Seed(int64(util.GetTimeMilliseconds()))
  1264. for i := 0; i < int(incomeNum); i++ {
  1265. dropId := this.genDropId(model.LevelDropCommonDataList, levelId)
  1266. for idx := 0; idx < len(dropId); idx++ {
  1267. this.DropProcess(addItemList, dropId[idx])
  1268. }
  1269. }
  1270. //活动奖励掉落赛季
  1271. for idx := 0; idx < int(incomeNum); idx++ {
  1272. hpDropIdList := this.genHDDropId(model.LevelDropHDDataList, levelId)
  1273. for key, val := range hpDropIdList {
  1274. addItemList[key] += val
  1275. }
  1276. }
  1277. for key, value := range addItemList {
  1278. itemList = append(itemList, &serverproto.KeyValueType{
  1279. Key: key,
  1280. Value: value,
  1281. })
  1282. }
  1283. if ret := this.role.CanAddItemList(addItemList); ret != serverproto.ErrorCode_ERROR_OK {
  1284. this.changeQuickBattleNtf(int32(ret), nil)
  1285. return
  1286. }
  1287. if incomeCfg.Cost != 0 {
  1288. var costItemList = map[int32]int32{}
  1289. costItemList[incomeCfg.CostType] = incomeCfg.Cost
  1290. if this.role.CheckResLitNum(costItemList) {
  1291. this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_Quick_Battle})
  1292. } else {
  1293. util.DebugF("uid=%v QuickBattle item not enough DayTimes=%v", this.role.GetUUid(), this.quickBattle.DayTimes)
  1294. this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_QUICK_BATTLE_ITEM_NOT_ENOUGH), itemList) //所需资源不足
  1295. return
  1296. }
  1297. }
  1298. //领取次数自加
  1299. this.quickBattle.DayTimes += 1
  1300. this.quickBattle.DrawTime = uint64(util.GetTimeSeconds())
  1301. this.quickBattle.MaxTimes = int32(MaxTime)
  1302. this.SetDirty(true)
  1303. this.changeBattleDataNtf()
  1304. this.role.AddItemList(addItemList, AddFrom_Quick_Battle, true)
  1305. this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_OK), itemList)
  1306. this.role.roleTask.AddTypeCnt(serverproto.TaskType_Eve_Use_Quick_Battle, 1)
  1307. TaskMagCheck(this.role, serverproto.TaskType_Role_Quick_Battle_Count, 1)
  1308. TaskMagCheck(this.role, serverproto.TaskType_Eve_Use_Quick_Battle, 1)
  1309. }
  1310. // evil
  1311. func (this *RoleBattle) evilDataChangeNtf() {
  1312. ntfMsg := &serverproto.SCEvilChangeNtf{
  1313. EvilInfo: this.evilData,
  1314. }
  1315. this.role.ReplayGate(ntfMsg, true)
  1316. }
  1317. func (this *RoleBattle) CheckEvilBattleCount() {
  1318. vipData := this.role.GetRoleBase().GetVipData(model.Vip_System_Evil)
  1319. if vipData == 0 && this.evilData.TotalCount == 0 {
  1320. return
  1321. }
  1322. bChanged := false
  1323. if vipData == 0 && this.evilData.TotalCount != 0 {
  1324. this.evilData.FreeCount = 0
  1325. this.evilData.TotalCount = 0
  1326. this.evilData.FreeLimit = true
  1327. bChanged = true
  1328. }
  1329. if vipData != 0 && vipData > this.evilData.TotalCount {
  1330. this.evilData.FreeCount += vipData - this.evilData.TotalCount
  1331. this.evilData.TotalCount = vipData
  1332. bChanged = true
  1333. }
  1334. if bChanged == true {
  1335. this.SetDirty(true)
  1336. this.evilDataChangeNtf()
  1337. }
  1338. }
  1339. func (this *RoleBattle) refreshEvilLevel() {
  1340. if data, ok := model.ConvertEvilBossList[this.evilData.EvilLevel]; ok {
  1341. if data.LevelTimes > 0 {
  1342. this.evilData.ChallengeCount++
  1343. if data.LevelTimes <= this.evilData.ChallengeCount {
  1344. if _, ok1 := model.ConvertEvilBossList[this.evilData.EvilLevel+1]; !ok1 {
  1345. this.evilData.ChallengeCount = 0
  1346. this.SetDirty(true)
  1347. return
  1348. }
  1349. this.evilData.EvilLevel++
  1350. this.evilData.ChallengeCount = 0
  1351. this.SetDirty(true)
  1352. //恶魔等级升级获得物品
  1353. this.role.AddItemList(data.LevelReward, AddFrom_Evil, true)
  1354. ntfMsg := &serverproto.SCEvilChangeNtf{
  1355. EvilInfo: this.evilData,
  1356. }
  1357. for key, val := range data.LevelReward {
  1358. ntfMsg.AddItemList = append(ntfMsg.AddItemList, &serverproto.KeyValueType{
  1359. Key: key,
  1360. Value: val,
  1361. })
  1362. }
  1363. this.role.ReplayGate(ntfMsg, true)
  1364. TaskMagCheck(this.role, serverproto.TaskType_Eve_Evil_Fight_Lvl, this.evilData.EvilLevel)
  1365. return
  1366. }
  1367. this.SetDirty(true)
  1368. }
  1369. }
  1370. }
  1371. func (this *RoleBattle) getEvilBossInfo(posIdx int32) *serverproto.BattleEvilBossData {
  1372. for idx := 0; idx < len(this.evilData.BossList); idx++ {
  1373. data := this.evilData.BossList[idx]
  1374. if data.PosIdx == posIdx {
  1375. return data
  1376. }
  1377. }
  1378. return nil
  1379. }
  1380. func (this *RoleBattle) randEvilBoss(force bool, bossQualityType int) *serverproto.KeyValueTypeList {
  1381. var evilLevel int32 = 0
  1382. if !force {
  1383. evilLevel = this.evilData.EvilLevel
  1384. }
  1385. convertData, ok := model.ConvertEvilBossList[evilLevel]
  1386. if !ok || len(convertData.MonsterList) <= 0 {
  1387. return nil
  1388. }
  1389. var totalWeight int32 = 0
  1390. var randList []*serverproto.KeyValueType
  1391. for idx := 0; idx < len(convertData.MonsterList); idx++ {
  1392. if bossQualityType > 0 {
  1393. if bossQualityType <= int(convertData.MonsterList[idx].ValueList[2]) {
  1394. totalWeight += convertData.MonsterList[idx].ValueList[3]
  1395. randList = append(randList, &serverproto.KeyValueType{Key: totalWeight, Value: int32(idx)})
  1396. }
  1397. } else {
  1398. totalWeight += convertData.MonsterList[idx].ValueList[3]
  1399. randList = append(randList, &serverproto.KeyValueType{Key: totalWeight, Value: int32(idx)})
  1400. }
  1401. }
  1402. randWeight := rand.Int31n(totalWeight)
  1403. idx := 0
  1404. for ; idx < len(randList); idx++ {
  1405. if randList[idx].Key > randWeight {
  1406. break
  1407. }
  1408. }
  1409. return convertData.MonsterList[int(randList[idx].Value)]
  1410. }
  1411. func (this *RoleBattle) BattleEvilRefresh(bForce bool) (serverproto.ErrorCode, []int32) {
  1412. if len(this.evilData.BossList) <= 0 {
  1413. return this.evilRefresh(true, false, false)
  1414. }
  1415. if bForce {
  1416. vipData := this.role.GetRoleBase().GetVipData(model.Vip_System_Evil)
  1417. if vipData > 0 && this.evilData.FreeCount > 0 {
  1418. this.evilData.FreeCount--
  1419. return this.evilRefresh(true, true, false)
  1420. } else if vipData <= 0 {
  1421. //升级到对应vip等级无限制免费刷新
  1422. return this.evilRefresh(true, true, false)
  1423. } else {
  1424. if !this.role.CheckResLitNum(model.GlobalEvilRefreshConsume) {
  1425. return serverproto.ErrorCode_ERROR_RMB_NOT_ENOUGH, nil
  1426. }
  1427. this.role.DelItemList(model.GlobalEvilRefreshConsume, AddItemST{AddFrom: AddFrom_Evil})
  1428. return this.evilRefresh(true, true, true)
  1429. }
  1430. } else {
  1431. return this.evilRefresh(false, true, false)
  1432. }
  1433. }
  1434. func (this *RoleBattle) evilRefresh(bForce bool, notify bool, bConsume bool) (serverproto.ErrorCode, []int32) {
  1435. nowTime := util.GetTimeMilliseconds()
  1436. //恶魔协会增加刷新保底机制
  1437. //1 绿,2蓝,3紫,4金
  1438. specialBossType := EvilBossType_Blue
  1439. if bConsume {
  1440. specialBossType = EvilBossType_Purple
  1441. }
  1442. if vipData, ok := model.ConvertVipRight[this.role.GetRoleVipLevel()]; ok {
  1443. if right, ok := vipData.VipRight[model.Vip_System_Evil]; ok {
  1444. if right <= 0 {
  1445. specialBossType = EvilBossType_Glod
  1446. }
  1447. }
  1448. }
  1449. if this.role.roleBT != nil {
  1450. var boliLevel int32 = 0
  1451. if this.role.roleBT.boliData != nil {
  1452. boliLevel = this.role.roleBT.boliData.Level
  1453. }
  1454. cfgData, ok := model.ConvertBoliVipData[boliLevel]
  1455. if ok {
  1456. if right, ok := cfgData.VipRight[model.Vip_System_Evil]; ok {
  1457. if right == 0 {
  1458. specialBossType = EvilBossType_Glod
  1459. }
  1460. }
  1461. }
  1462. }
  1463. if this.role.GetRoleRune() != nil && this.role.GetRoleRune().runeBase.IsPassCheck {
  1464. if right, ok := model.ConvertPassCheckData.VipRight[model.Vip_System_Evil]; ok {
  1465. if right == 0 {
  1466. specialBossType = EvilBossType_Glod
  1467. }
  1468. }
  1469. }
  1470. var changeIdx []int32
  1471. rand.Seed(int64(nowTime))
  1472. specialBossTypeIdx := rand.Intn(MAX_BATTLEBOSS_NUM) + 1
  1473. //第一次需要刷新出特殊的Boss
  1474. for idx := 1; idx <= MAX_BATTLEBOSS_NUM; idx++ {
  1475. evilBoss := this.getEvilBossInfo(int32(idx))
  1476. if evilBoss == nil {
  1477. evilBoss = &serverproto.BattleEvilBossData{
  1478. PosIdx: int32(idx),
  1479. ExpireTime: 0,
  1480. }
  1481. var tmpBossInfo *serverproto.KeyValueTypeList = nil
  1482. if idx == 1 {
  1483. //第一次需要刷新出特殊的Boss
  1484. tmpBossInfo = this.randEvilBoss(true, 0)
  1485. if specialBossTypeIdx == idx {
  1486. specialBossTypeIdx++
  1487. }
  1488. } else {
  1489. if idx == specialBossTypeIdx {
  1490. tmpBossInfo = this.randEvilBoss(false, specialBossType)
  1491. } else {
  1492. tmpBossInfo = this.randEvilBoss(false, 0)
  1493. }
  1494. }
  1495. if tmpBossInfo != nil {
  1496. evilBoss.BossId = tmpBossInfo.Key
  1497. evilBoss.RewardEvilExp = tmpBossInfo.ValueList[0]
  1498. evilBoss.RefreshTime = tmpBossInfo.ValueList[1]
  1499. evilBoss.Quality = tmpBossInfo.ValueList[2]
  1500. this.evilData.BossList = append(this.evilData.BossList, evilBoss)
  1501. changeIdx = append(changeIdx, int32(idx))
  1502. } else {
  1503. util.ErrorF("uid=%v evi refresh error!!!", this.role.GetUUid())
  1504. }
  1505. } else {
  1506. if bForce {
  1507. var tmpBossInfo *serverproto.KeyValueTypeList = nil
  1508. if idx == specialBossTypeIdx {
  1509. tmpBossInfo = this.randEvilBoss(false, specialBossType)
  1510. } else {
  1511. tmpBossInfo = this.randEvilBoss(false, 0)
  1512. }
  1513. if tmpBossInfo != nil {
  1514. evilBoss.BossId = tmpBossInfo.Key
  1515. evilBoss.ExpireTime = 0
  1516. evilBoss.RefreshTime = tmpBossInfo.ValueList[1]
  1517. evilBoss.RewardEvilExp = tmpBossInfo.ValueList[0]
  1518. evilBoss.Quality = tmpBossInfo.ValueList[2]
  1519. changeIdx = append(changeIdx, int32(idx))
  1520. } else {
  1521. util.ErrorF("uid=%v evi refresh error!!!", this.role.GetUUid())
  1522. }
  1523. } else if evilBoss.ExpireTime < nowTime && evilBoss.ExpireTime > 0 {
  1524. var tmpBossInfo *serverproto.KeyValueTypeList = nil
  1525. if idx == specialBossTypeIdx {
  1526. tmpBossInfo = this.randEvilBoss(false, specialBossType)
  1527. } else {
  1528. tmpBossInfo = this.randEvilBoss(false, 0)
  1529. }
  1530. if tmpBossInfo != nil {
  1531. evilBoss.BossId = tmpBossInfo.Key
  1532. evilBoss.ExpireTime = 0
  1533. evilBoss.RefreshTime = tmpBossInfo.ValueList[1]
  1534. evilBoss.RewardEvilExp = tmpBossInfo.ValueList[0]
  1535. evilBoss.Quality = tmpBossInfo.ValueList[2]
  1536. changeIdx = append(changeIdx, int32(idx))
  1537. } else {
  1538. util.ErrorF("uid=%v evi refresh error!!!", this.role.GetUUid())
  1539. }
  1540. }
  1541. }
  1542. }
  1543. if len(changeIdx) > 0 {
  1544. this.SetDirty(true)
  1545. if notify {
  1546. this.evilDataChangeNtf()
  1547. }
  1548. }
  1549. //util.DebugF("uid=%v nowTime=%v freeCount=%v", this.role.GetUUid(), nowTime, this.evilData.FreeCount)
  1550. return serverproto.ErrorCode_ERROR_OK, changeIdx
  1551. }
  1552. func (this *RoleBattle) BattleEvilChallenge(posIdx int32) (serverproto.ErrorCode, int32) {
  1553. bossInfo := this.getEvilBossInfo(posIdx)
  1554. if bossInfo == nil {
  1555. return serverproto.ErrorCode_ERROR_BATTLE_EVIL_BOSS_NOT_FIND, 0
  1556. }
  1557. nowTime := util.GetTimeMilliseconds()
  1558. if bossInfo.ExpireTime == 0 && bossInfo.BossId != 0 {
  1559. var costItemList = map[int32]int32{}
  1560. costItemList[int32(serverproto.ResType_Res_EvilExp)] = model.GlobalEviChallengeCost
  1561. if !this.role.CheckResLitNum(costItemList) {
  1562. return serverproto.ErrorCode_ERROR_BATTLE_EVIL_REFRESH_COST_NOT_ENOUGH, 0
  1563. }
  1564. this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_Evil})
  1565. var addItemList = map[int32]int32{}
  1566. addItemList[int32(serverproto.ResType_Res_Cruise)] = bossInfo.RewardEvilExp
  1567. this.role.AddItemList(addItemList, AddFrom_Evil, true)
  1568. bossInfo.ExpireTime = nowTime + uint64(bossInfo.RefreshTime)*1000
  1569. bFind := false
  1570. for idx := 0; idx < len(this.evilData.QualityChallengeCount); idx++ {
  1571. tmpData := this.evilData.QualityChallengeCount[idx]
  1572. if tmpData.Key == bossInfo.Quality {
  1573. this.evilData.QualityChallengeCount[idx].Value++
  1574. bFind = true
  1575. break
  1576. }
  1577. }
  1578. if !bFind {
  1579. this.evilData.QualityChallengeCount = append(this.evilData.QualityChallengeCount,
  1580. &serverproto.KeyValueType{Key: bossInfo.Quality, Value: 1})
  1581. }
  1582. this.refreshEvilLevel()
  1583. this.SetDirty(true)
  1584. this.evilDataChangeNtf()
  1585. //Task
  1586. TaskMagCheck(this.role, serverproto.TaskType_Evil_Fight_Count, 1)
  1587. TaskMagCheck(this.role, serverproto.TaskType_Evil_Battle_Count_Accu, bossInfo.Quality)
  1588. TaskMagCheck(this.role, serverproto.TaskType_Eve_Accu_count, bossInfo.Quality)
  1589. return serverproto.ErrorCode_ERROR_OK, bossInfo.RewardEvilExp
  1590. }
  1591. return serverproto.ErrorCode_ERROR_BATTLE_EVIL_BOSS_DIED, 0
  1592. }
  1593. func (this *RoleBattle) GetQualityBossChallengeCount(quality int32) int32 {
  1594. var ret int32 = 0
  1595. for idx := 0; idx < len(this.evilData.QualityChallengeCount); idx++ {
  1596. tmpData := this.evilData.QualityChallengeCount[idx]
  1597. if tmpData.Key >= quality {
  1598. ret += tmpData.Value
  1599. }
  1600. }
  1601. return ret
  1602. }
  1603. func (this *RoleBattle) GetEvilLvl() int32 {
  1604. return this.evilData.EvilLevel
  1605. }
  1606. // expedition
  1607. func (this *RoleBattle) expeditionChangeNtf(dayReset bool) {
  1608. ntfMsg := &serverproto.SCExpeditionChangeNtf{
  1609. ExpeditionInfo: this.expeditionData,
  1610. DayReset: dayReset,
  1611. }
  1612. this.role.ReplayGate(ntfMsg, true)
  1613. }
  1614. func (this *RoleBattle) dailyResetExpedition(notify bool) {
  1615. //奖励通过邮件发送
  1616. var addItemList = map[int32]int32{}
  1617. for idx := 0; idx < len(this.expeditionData.FinishExpeditionList); idx++ {
  1618. tmpExpeditionType := this.expeditionData.FinishExpeditionList[idx]
  1619. convertCfgData, ok := model.ConvertExpeditionDataList[tmpExpeditionType]
  1620. if !ok {
  1621. continue
  1622. }
  1623. this.expeditionRewardAll(convertCfgData, addItemList)
  1624. }
  1625. convertCfgData, ok := model.ConvertExpeditionDataList[this.expeditionData.CurExpeditionType]
  1626. if ok {
  1627. this.expeditionRewardAll(convertCfgData, addItemList)
  1628. }
  1629. if len(this.expeditionData.FinishExpeditionList) > 0 {
  1630. this.expeditionData.FinishExpeditionList = this.expeditionData.FinishExpeditionList[:0]
  1631. this.SetDirty(true)
  1632. }
  1633. if len(this.expeditionData.RewardStateList) > 0 {
  1634. this.expeditionData.RewardStateList = this.expeditionData.RewardStateList[:0]
  1635. this.SetDirty(true)
  1636. }
  1637. if len(addItemList) > 0 {
  1638. this.role.GetRoleMail().AddMail(model.GlobalMailIdExpeditionReward, serverproto.MailType_MailType_Expedition,
  1639. addItemList, nil, "", "")
  1640. }
  1641. //重置数据
  1642. bReset := false
  1643. if this.expeditionData.ChallengeNum != model.GlobalExpeditionChallengeNum {
  1644. this.expeditionData.ChallengeNum = model.GlobalExpeditionChallengeNum
  1645. this.SetDirty(true)
  1646. bReset = true
  1647. }
  1648. if this.expeditionData.CurExpeditionType > 0 || this.expeditionData.CurBattleLevel > 0 ||
  1649. this.expeditionData.CurExpeditionScore > 0 {
  1650. this.expeditionData.CurExpeditionType = 0
  1651. this.expeditionData.CurBattleLevel = 0
  1652. this.expeditionData.CurExpeditionScore = 0
  1653. this.SetDirty(true)
  1654. bReset = true
  1655. }
  1656. if len(this.expeditionData.BossList) > 0 || len(this.expeditionData.BattleBuffList) > 0 ||
  1657. len(this.expeditionData.BattleHeroHpList) > 0 || len(this.expeditionData.BattleSelectBuffList) > 0 {
  1658. this.expeditionData.BossList = this.expeditionData.BossList[:0]
  1659. this.expeditionData.BattleBuffList = this.expeditionData.BattleBuffList[:0]
  1660. this.expeditionData.BattleSelectBuffList = this.expeditionData.BattleSelectBuffList[:0]
  1661. this.expeditionData.BattleHeroHpList = this.expeditionData.BattleHeroHpList[:0]
  1662. this.SetDirty(true)
  1663. bReset = true
  1664. }
  1665. if this.expeditionData.AssistNum.Value > 0 || this.expeditionData.BeAssistNum.Value > 0 ||
  1666. this.expeditionData.BattleIdx > 0 || this.expeditionData.AssistState {
  1667. this.expeditionData.AssistNum.Value = 0
  1668. this.expeditionData.BeAssistNum.Value = 0
  1669. this.expeditionData.AssistState = false
  1670. this.expeditionData.AssistTimeStamp = 0
  1671. this.expeditionData.BattleIdx = 0
  1672. this.SetDirty(true)
  1673. bReset = true
  1674. }
  1675. if this.expeditionData.ExpeditionTypeReward > 0 {
  1676. this.expeditionData.ExpeditionTypeReward = 0
  1677. this.SetDirty(true)
  1678. bReset = true
  1679. }
  1680. if notify && (bReset || len(addItemList) > 0) {
  1681. this.expeditionChangeNtf(true)
  1682. }
  1683. }
  1684. func (this *RoleBattle) ExpeditionPre(expeditionType int32) serverproto.ErrorCode {
  1685. convertData, ok := model.ConvertExpeditionDataList[expeditionType]
  1686. if !ok {
  1687. return serverproto.ErrorCode_ERROR_EXPEDITION_CHALLENGE
  1688. }
  1689. //是否已经解锁
  1690. if this.expeditionData.ExpeditionType < expeditionType {
  1691. return serverproto.ErrorCode_ERROR_EXPEDITION_TYPE_UNLOCK
  1692. }
  1693. if this.expeditionData.CurExpeditionType != 0 {
  1694. if this.expeditionData.CurExpeditionType != expeditionType {
  1695. return serverproto.ErrorCode_ERROR_EXPEDITION_CHALLENGE
  1696. }
  1697. } else {
  1698. //当前是否已经挑战完该区域id地图
  1699. bFind := false
  1700. for idx := 0; idx < len(this.expeditionData.FinishExpeditionList); idx++ {
  1701. if this.expeditionData.FinishExpeditionList[idx] == expeditionType {
  1702. bFind = true
  1703. }
  1704. }
  1705. if bFind {
  1706. return serverproto.ErrorCode_ERROR_EXPEDITION_CHALLENGE_HAS
  1707. }
  1708. }
  1709. //扣除次数,并生成第一关boss数据列表
  1710. if this.expeditionData.CurExpeditionType == 0 {
  1711. if this.expeditionData.ChallengeNum <= 0 {
  1712. return serverproto.ErrorCode_ERROR_EXPEDITION_CHALLENGE_NO_NUM
  1713. }
  1714. this.expeditionData.ChallengeNum--
  1715. this.expeditionData.CurExpeditionType = expeditionType
  1716. this.expeditionData.CurExpeditionScore = 0
  1717. this.expeditionData.CurBattleLevel = 1
  1718. this.expeditionData.BattleSelectBuffList = this.expeditionData.BattleSelectBuffList[:0]
  1719. this.expeditionData.BattleBuffList = this.expeditionData.BattleBuffList[:0]
  1720. this.SetDirty(true)
  1721. this.expeditionBuffList.Clear()
  1722. this.randExpeditionBoss(convertData)
  1723. this.expeditionChangeNtf(false)
  1724. TaskMagCheck(this.role, serverproto.TaskType_Expedition_Challenge_Count, 1)
  1725. }
  1726. return serverproto.ErrorCode_ERROR_OK
  1727. }
  1728. func (this *RoleBattle) ExpeditionChallenge(expeditionType, battleLevel int32, heroInfoList []*serverproto.BattleExpeditionActor,
  1729. bossChangeHpList []*serverproto.BattleExpeditionActor, battleTime int32, bossIdx int32, flag int32) (serverproto.ErrorCode, []int32, bool) {
  1730. if expeditionType != this.expeditionData.CurExpeditionType || battleLevel != this.expeditionData.CurBattleLevel {
  1731. util.InfoF("uid=%v ExpeditionChallenge cheat data for client type=%v level=%v", this.role.GetUUid(), expeditionType, battleLevel)
  1732. return serverproto.ErrorCode_ERROR_EXPEDITION_CHALLENGE, nil, false
  1733. }
  1734. //cfgData check
  1735. convertCfgData, ok := model.ConvertExpeditionDataList[expeditionType]
  1736. if !ok {
  1737. util.DebugF("uid=%v ExpeditionChallenge expeditionType=%v invalid", this.role.GetUUid(), expeditionType)
  1738. return serverproto.ErrorCode_ERROR_FAIL, nil, false
  1739. }
  1740. levelCfgData, ok := convertCfgData.LevelInfo[battleLevel]
  1741. if !ok {
  1742. util.DebugF("uid=%v ExpeditionChallenge battleLevel=%v invalid", this.role.GetUUid(), battleLevel)
  1743. return serverproto.ErrorCode_ERROR_FAIL, nil, false
  1744. }
  1745. if levelCfgData.MaxFightingTime < battleTime && battleTime > 0 {
  1746. util.DebugF("uid=%v ExpeditionChallenge battleTime=%v invalid", this.role.GetUUid(), battleTime)
  1747. return serverproto.ErrorCode_ERROR_CHALLENGE_TIME_LIMIT, nil, false
  1748. }
  1749. if bossIdx <= 0 || bossIdx > int32(len(this.expeditionData.BossList)) {
  1750. util.DebugF("uid=%v ExpeditionChallenge bossIdx=%v invalid", this.role.GetUUid(), battleLevel)
  1751. return serverproto.ErrorCode_ERROR_FAIL, nil, false
  1752. }
  1753. //flag 1开始 2战斗过程 3战斗结束 4胜利方式返回给客户端
  1754. //判断之前战斗胜利的buff是否已经选择
  1755. if flag == 1 {
  1756. if len(this.expeditionData.BattleSelectBuffList) > 0 {
  1757. return serverproto.ErrorCode_ERROR_OK, this.expeditionData.BattleSelectBuffList, false
  1758. }
  1759. }
  1760. //挑战英雄是否合法
  1761. ret := this.isCurBattleHeroDied(heroInfoList, flag)
  1762. if ret != serverproto.ErrorCode_ERROR_OK {
  1763. return ret, nil, false
  1764. }
  1765. //boss血量检查
  1766. //客户端
  1767. var accuBossHpChange int32 = 0
  1768. var accuBossSpChange int32 = 0
  1769. for idx := 0; idx < len(bossChangeHpList); idx++ {
  1770. accuBossHpChange += bossChangeHpList[idx].Hp
  1771. accuBossSpChange += bossChangeHpList[idx].Sp
  1772. }
  1773. //判断是否挑战同一个boss
  1774. curBattleBossIdx := this.findBattleBossIdx()
  1775. if curBattleBossIdx != 0 && curBattleBossIdx != bossIdx {
  1776. bossIdx = curBattleBossIdx
  1777. util.DebugF("uid=%v ExpeditionChallenge curBossIdx=%v bossIdx=%v", this.role.GetUUid(), curBattleBossIdx, bossIdx)
  1778. //return serverproto.ErrorCode_ERROR_EXPEDITION_NOT_SAME_BOSS, nil, false
  1779. }
  1780. if bossIdx <= 0 {
  1781. return serverproto.ErrorCode_ERROR_EXPEDITION_CHALLENGE, nil, false
  1782. }
  1783. //战斗开始时判断boss是否已经死亡
  1784. if flag == 1 {
  1785. this.expeditionData.BattleIdx = bossIdx
  1786. this.SetDirty(true)
  1787. if this.expeditionData.BossList[bossIdx-1].Hp <= 0 {
  1788. //数据不正确,重置boss数据
  1789. this.randExpeditionBoss(convertCfgData)
  1790. this.expeditionChangeNtf(false)
  1791. util.DebugF("uid=%v ExpeditionChallenge boss data invalid", this.role.GetUUid())
  1792. return serverproto.ErrorCode_ERROR_EXPEDITION_NOT_SAME_BOSS, nil, false
  1793. }
  1794. }
  1795. for idx := 0; idx < len(heroInfoList); idx++ {
  1796. bFind := false
  1797. for k := 0; k < len(this.expeditionData.BattleHeroHpList); k++ {
  1798. if this.expeditionData.BattleHeroHpList[k].Id == heroInfoList[idx].Id {
  1799. bFind = true
  1800. if this.expeditionData.BattleHeroHpList[k].Hp <= 0 {
  1801. break
  1802. }
  1803. this.expeditionData.BattleHeroHpList[k].Hp = heroInfoList[idx].Hp
  1804. if this.expeditionData.BattleHeroHpList[k].Hp > 100 {
  1805. this.expeditionData.BattleHeroHpList[k].Hp = 100
  1806. }
  1807. if this.expeditionData.BattleHeroHpList[k].Hp < 0 {
  1808. this.expeditionData.BattleHeroHpList[k].Hp = 0
  1809. }
  1810. this.expeditionData.BattleHeroHpList[k].Sp = heroInfoList[idx].Sp
  1811. if this.expeditionData.BattleHeroHpList[k].Sp > 100 {
  1812. this.expeditionData.BattleHeroHpList[k].Sp = 100
  1813. }
  1814. if this.expeditionData.BattleHeroHpList[k].Sp < 0 {
  1815. this.expeditionData.BattleHeroHpList[k].Sp = 0
  1816. }
  1817. break
  1818. }
  1819. }
  1820. if !bFind {
  1821. //万分比
  1822. if heroInfoList[idx].Hp > 100 {
  1823. heroInfoList[idx].Hp = 100
  1824. }
  1825. if heroInfoList[idx].Sp > 100 {
  1826. heroInfoList[idx].Sp = 100
  1827. }
  1828. this.expeditionData.BattleHeroHpList = append(this.expeditionData.BattleHeroHpList, heroInfoList[idx])
  1829. }
  1830. }
  1831. bFinish := false
  1832. tmpBossInfo := this.expeditionData.BossList[bossIdx-1]
  1833. tmpBossInfo.Hp += accuBossHpChange
  1834. tmpBossInfo.Sp += accuBossSpChange
  1835. if tmpBossInfo.Sp < 0 {
  1836. tmpBossInfo.Sp = 0
  1837. }
  1838. //隔天重置,战斗还在进行中,结束时数据已经被清空
  1839. oldBattleLevel := this.expeditionData.CurBattleLevel
  1840. if tmpBossInfo.Hp <= 0 && flag == 3 && this.expeditionData.BattleIdx > 0 && this.expeditionData.CurExpeditionType > 0 {
  1841. if this.expeditionData.CurBattleLevel >= convertCfgData.LevelNum {
  1842. this.expeditionData.FinishExpeditionList = append(this.expeditionData.FinishExpeditionList, this.expeditionData.CurExpeditionType)
  1843. if this.expeditionData.ExpeditionType <= this.expeditionData.CurExpeditionType {
  1844. _, ok1 := model.ConvertExpeditionDataList[this.expeditionData.ExpeditionType+1]
  1845. if ok1 {
  1846. this.expeditionData.ChallengeNum += convertCfgData.LevelUnlockAddNum
  1847. this.expeditionData.ExpeditionType++
  1848. }
  1849. }
  1850. this.expeditionData.TotalExpeditionNum++
  1851. //获取勇士积分
  1852. this.GenWarriorScore(levelCfgData)
  1853. this.FinishExpeditionTypeReset()
  1854. //Task
  1855. TaskMagCheck(this.role, serverproto.TaskType_Expedition_Battle_Count, 1)
  1856. TaskMagCheck(this.role, serverproto.TaskType_Eve_Expedition_Battle_Type, 1)
  1857. } else {
  1858. //获取buff列表
  1859. this.randBattleBuffList(levelCfgData)
  1860. //获取勇士积分
  1861. this.GenWarriorScore(levelCfgData)
  1862. //boss死亡刷新下一关boss列表
  1863. this.expeditionData.CurBattleLevel++
  1864. this.expeditionData.BattleIdx = 0
  1865. this.randExpeditionBoss(convertCfgData)
  1866. }
  1867. bFinish = true
  1868. util.InfoF("uid=%v ExpeditionChallenge finish=%v buff=%v oldBattleLevel=%v bossid=%v nextlevelbosslist=%v", this.role.GetUUid(), bFinish,
  1869. this.expeditionData.BattleSelectBuffList, oldBattleLevel, tmpBossInfo.Id, this.expeditionData.BossList)
  1870. }
  1871. this.SetDirty(true)
  1872. this.expeditionChangeNtf(false)
  1873. return serverproto.ErrorCode_ERROR_OK, this.expeditionData.BattleSelectBuffList, bFinish
  1874. }
  1875. func (this *RoleBattle) GetExpeditionTotalFinishNum() int32 {
  1876. return this.expeditionData.TotalExpeditionNum
  1877. }
  1878. func (this *RoleBattle) GetExpeditionCur() int32 {
  1879. if this.expeditionData.ExpeditionType > 0 {
  1880. return this.expeditionData.ExpeditionType - 1
  1881. }
  1882. return this.expeditionData.ExpeditionType
  1883. }
  1884. func (this *RoleBattle) FinishExpeditionTypeReset() {
  1885. convertCfgData, ok := model.ConvertExpeditionDataList[this.expeditionData.CurExpeditionType]
  1886. if ok {
  1887. var addItemList = map[int32]int32{}
  1888. this.expeditionRewardAll(convertCfgData, addItemList)
  1889. if len(addItemList) > 0 {
  1890. this.role.GetRoleMail().AddMail(model.GlobalMailIdExpeditionReward, serverproto.MailType_MailType_Expedition,
  1891. addItemList, nil, "", "")
  1892. }
  1893. }
  1894. this.expeditionData.CurExpeditionType = 0
  1895. this.expeditionData.CurBattleLevel = 1
  1896. this.expeditionData.BattleIdx = 0
  1897. this.expeditionData.AssistState = false
  1898. this.expeditionData.AssistTimeStamp = 0
  1899. this.expeditionData.BossList = this.expeditionData.BossList[:0]
  1900. this.expeditionData.BattleBuffList = this.expeditionData.BattleBuffList[:0]
  1901. this.expeditionData.BattleSelectBuffList = this.expeditionData.BattleSelectBuffList[:0]
  1902. this.expeditionData.BattleHeroHpList = this.expeditionData.BattleHeroHpList[:0]
  1903. this.expeditionBuffList.Clear()
  1904. this.SetDirty(true)
  1905. }
  1906. func (this *RoleBattle) addExpeditionRankScore(addScore uint32) bool {
  1907. this.expeditionData.CurExpeditionScore += addScore
  1908. if this.expeditionData.CurExpeditionScoreMax < this.expeditionData.CurExpeditionScore {
  1909. this.expeditionData.CurExpeditionScoreMax = this.expeditionData.CurExpeditionScore
  1910. ssMsg := &serverproto.SSExpeditionUpdateScoreRankNtf{
  1911. CurScore: this.expeditionData.CurExpeditionScoreMax,
  1912. }
  1913. this.role.SendRank(ssMsg)
  1914. return true
  1915. }
  1916. return false
  1917. }
  1918. func (this *RoleBattle) ExpeditionBuffSelect(selectBuf int32) serverproto.ErrorCode {
  1919. bFind := false
  1920. for idx := 0; idx < len(this.expeditionData.BattleSelectBuffList); idx++ {
  1921. if this.expeditionData.BattleSelectBuffList[idx] == selectBuf {
  1922. bFind = true
  1923. break
  1924. }
  1925. }
  1926. if !bFind {
  1927. return serverproto.ErrorCode_ERROR_EXPEDITION_BUFF_NOT_EXIST
  1928. }
  1929. this.expeditionData.BattleIdx = 0
  1930. this.expeditionData.BattleBuffList = append(this.expeditionData.BattleBuffList, selectBuf)
  1931. this.expeditionBuffList.Add(selectBuf)
  1932. this.expeditionData.BattleSelectBuffList = this.expeditionData.BattleSelectBuffList[:0]
  1933. this.SetDirty(true)
  1934. //选择buff添加勇士积分
  1935. if cfgData, ok := serverproto.ExpeditionBuffCfgLoader[selectBuf]; ok {
  1936. tmpScore := float32(cfgData.WarriorScore)
  1937. convertData, ok1 := model.ConvertExpeditionDataList[this.expeditionData.CurExpeditionType]
  1938. if ok1 {
  1939. tmpScore *= convertData.LevelCoefficient
  1940. }
  1941. this.addExpeditionRankScore(uint32(tmpScore))
  1942. }
  1943. this.expeditionChangeNtf(false)
  1944. return serverproto.ErrorCode_ERROR_OK
  1945. }
  1946. func (this *RoleBattle) ExpeditionReward(expeditionType, boxIdx int32, ackMsg *serverproto.SCExpeditionRewardAck) serverproto.ErrorCode {
  1947. if expeditionType <= 0 || boxIdx < 0 {
  1948. return serverproto.ErrorCode_ERROR_FAIL
  1949. }
  1950. convertCfgData, ok := model.ConvertExpeditionDataList[expeditionType]
  1951. if !ok {
  1952. return serverproto.ErrorCode_ERROR_FAIL
  1953. }
  1954. var addItemList = map[int32]int32{}
  1955. //一键领取
  1956. if boxIdx <= 0 {
  1957. retReward := this.expeditionRewardAll(convertCfgData, addItemList)
  1958. if retReward != serverproto.ErrorCode_ERROR_OK {
  1959. return retReward
  1960. }
  1961. } else {
  1962. retReward := this.expeditionRewardBox(convertCfgData, boxIdx, addItemList)
  1963. if retReward != serverproto.ErrorCode_ERROR_OK {
  1964. return retReward
  1965. }
  1966. }
  1967. this.expeditionChangeNtf(false)
  1968. this.role.AddItemList(addItemList, AddFrom_Expedition, true)
  1969. for key, val := range addItemList {
  1970. ackMsg.RewardItemList = append(ackMsg.RewardItemList, &serverproto.KeyValueType{Key: key, Value: val})
  1971. }
  1972. return serverproto.ErrorCode_ERROR_OK
  1973. }
  1974. func (this *RoleBattle) ExpeditionBattleHero(battleHeroList []int32) serverproto.ErrorCode {
  1975. if len(battleHeroList) > SLOT_NUM {
  1976. return serverproto.ErrorCode_ERROR_FAIL
  1977. }
  1978. heroIdList := set.New(set.NonThreadSafe)
  1979. for idx := 0; idx < len(battleHeroList); idx++ {
  1980. if battleHeroList[idx] == 0 {
  1981. continue
  1982. }
  1983. if heroIdList.Has(battleHeroList[idx]) {
  1984. return serverproto.ErrorCode_ERROR_FAIL
  1985. }
  1986. heroData := this.role.GetRoleHero().GetHero(battleHeroList[idx])
  1987. if heroData == nil {
  1988. return serverproto.ErrorCode_ERROR_HERO_NO_FOUND
  1989. }
  1990. heroIdList.Add(battleHeroList[idx])
  1991. }
  1992. this.expeditionData.BattleHeroList = battleHeroList
  1993. this.SetDirty(true)
  1994. this.expeditionChangeNtf(false)
  1995. return serverproto.ErrorCode_ERROR_OK
  1996. }
  1997. func (this *RoleBattle) ExpeditionCallForHelp(assistHelpUid uint64) serverproto.ErrorCode {
  1998. if this.role.GetUUid() == assistHelpUid {
  1999. return serverproto.ErrorCode_ERROR_FAIL
  2000. }
  2001. //已经被救助的次数达到上限,无法发起求助请求
  2002. if this.expeditionData.BeAssistNum != nil &&
  2003. this.expeditionData.BeAssistNum.Key <= this.expeditionData.BeAssistNum.Value {
  2004. return serverproto.ErrorCode_ERROR_EXPEDITION_CALLFORHELP_LIMIT
  2005. }
  2006. //是否有英雄死亡,可以发起求助操作
  2007. bFind := false
  2008. for idx := 0; idx < len(this.expeditionData.BattleHeroHpList); idx++ {
  2009. if this.expeditionData.BattleHeroHpList[idx].Hp <= 0 {
  2010. bFind = true
  2011. }
  2012. }
  2013. if !bFind {
  2014. return serverproto.ErrorCode_ERROR_EXPEDITION_CALLFROHELP_NO_HERO
  2015. }
  2016. nowTime := util.GetTimeMilliseconds()
  2017. // 发起公会求助
  2018. if assistHelpUid <= 0 {
  2019. //cd time
  2020. if nowTime < this.expeditionData.AssistGuildEndTime {
  2021. return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_GUILD_CD
  2022. }
  2023. if this.role.GetRoleGuildId() <= 0 {
  2024. return serverproto.ErrorCode_ERROR_EXPEDITION_CALLFROHELP_NO_GUILD
  2025. }
  2026. this.expeditionData.AssistGuildEndTime = nowTime + model.GlobalExpeditionGuildCallForHelpCDTime
  2027. this.expeditionData.AssistState = true
  2028. if this.expeditionData.AssistTimeStamp <= 0 {
  2029. this.expeditionData.AssistTimeStamp = nowTime
  2030. }
  2031. this.SetDirty(true)
  2032. this.expeditionChangeNtf(false)
  2033. chatMsg := &serverproto.CSChatMessageReq{
  2034. TargetId: assistHelpUid,
  2035. Type: int32(serverproto.ChatMessageType_CMT_GUILD),
  2036. Message: &serverproto.ChatMessageInfo{
  2037. SendTime: nowTime,
  2038. SubType: int32(serverproto.ChatMessageSubType_CMT_SUB_TYPE_Expedition),
  2039. },
  2040. }
  2041. this.role.GetRoleChat().SendMsg(assistHelpUid,
  2042. int32(serverproto.ChatMessageType_CMT_GUILD), chatMsg, true)
  2043. } else {
  2044. bFind := false
  2045. //发起好友求助
  2046. friendList := this.role.GetRoleSocial().GetFriendList()
  2047. for idx := 0; idx < len(friendList); idx++ {
  2048. if friendList[idx] == assistHelpUid {
  2049. bFind = true
  2050. this.expeditionData.AssistState = true
  2051. if this.expeditionData.AssistTimeStamp <= 0 {
  2052. this.expeditionData.AssistTimeStamp = nowTime
  2053. }
  2054. this.SetDirty(true)
  2055. this.expeditionChangeNtf(false)
  2056. chatMsg := &serverproto.CSChatMessageReq{
  2057. TargetId: assistHelpUid,
  2058. Type: int32(serverproto.ChatMessageType_CMT_PERSONAL),
  2059. Message: &serverproto.ChatMessageInfo{
  2060. SendTime: nowTime,
  2061. SubType: int32(serverproto.ChatMessageSubType_CMT_SUB_TYPE_Expedition),
  2062. },
  2063. }
  2064. this.role.GetRoleChat().SendMsg(assistHelpUid,
  2065. int32(serverproto.ChatMessageType_CMT_PERSONAL), chatMsg, true)
  2066. break
  2067. }
  2068. }
  2069. if !bFind {
  2070. return serverproto.ErrorCode_ERROR_FAIL
  2071. }
  2072. }
  2073. //Task
  2074. TaskMagCheck(this.role, serverproto.TaskType_Expedition_CallHelp_Count, 1)
  2075. //玩家发起救助时删除过期日志
  2076. this.checkBeHelpUidListExpire()
  2077. return serverproto.ErrorCode_ERROR_OK
  2078. }
  2079. func (this *RoleBattle) ExpeditionHelp(beHelpedUid uint64, msgType int32, helpMsgSendTime uint64) serverproto.ErrorCode {
  2080. if this.role.GetUUid() == beHelpedUid || beHelpedUid <= 0 {
  2081. return serverproto.ErrorCode_ERROR_FAIL
  2082. }
  2083. if this.expeditionData.AssistNum != nil &&
  2084. this.expeditionData.AssistNum.Key <= this.expeditionData.AssistNum.Value {
  2085. return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_LIMIT
  2086. }
  2087. if msgType == int32(serverproto.ChatMessageType_CMT_PERSONAL) {
  2088. //判断是否是好友,
  2089. bFind := false
  2090. friendList := this.role.GetRoleSocial().GetFriendList()
  2091. for idx := 0; idx < len(friendList); idx++ {
  2092. if friendList[idx] == beHelpedUid {
  2093. bFind = true
  2094. break
  2095. }
  2096. }
  2097. if !bFind {
  2098. return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_NOT_FRIEND
  2099. }
  2100. } else if msgType == int32(serverproto.ChatMessageType_CMT_GUILD) {
  2101. //判断是否是同一公会
  2102. if this.role.GetRoleGuildId() <= 0 {
  2103. return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_NOT_GUILD
  2104. }
  2105. }
  2106. //发起救助操作
  2107. ssMsg := &serverproto.SSExpeditionHelpReq{
  2108. BeHelpedUid: beHelpedUid,
  2109. FromUid: &serverproto.CommonPlayerBriefInfo{},
  2110. HelpMsgSendTime: helpMsgSendTime,
  2111. }
  2112. this.role.GetRoleBriefInfo(ssMsg.FromUid)
  2113. this.role.SendSocial(ssMsg)
  2114. return serverproto.ErrorCode_ERROR_OK
  2115. }
  2116. // from social
  2117. // 被救助玩家离线,返回发起救助玩家并进行db操作
  2118. func (this *RoleBattle) OnExpeditionHelp(beHelpedUid uint64, retCode int32) {
  2119. switch retCode {
  2120. case int32(serverproto.ErrorCode_ERROR_EXPEDITION_NOT_FIND_SERVICE_ID):
  2121. //被救助的玩家最近未上线,db操作
  2122. ssDBMsg := &serverproto.SSExpeditionDBHelpReq{
  2123. BeHelpedUid: beHelpedUid,
  2124. FromUid: this.role.GetUUid(),
  2125. }
  2126. this.role.SendDb(ssDBMsg)
  2127. case int32(serverproto.ErrorCode_ERROR_OK):
  2128. //成功救助
  2129. if this.expeditionData.AssistNum == nil {
  2130. this.expeditionData.AssistNum = &serverproto.KeyValueType{Key: model.GlobalExpeditionGuildHelpNum}
  2131. }
  2132. this.expeditionData.AssistNum.Value += 1
  2133. this.SetDirty(true)
  2134. this.role.AddItemList(model.GlobalExpeditionHelpRewardList, AddFrom_Expedition, true)
  2135. this.expeditionChangeNtf(false)
  2136. ackMsg := &serverproto.SCExpeditionHelpAck{
  2137. Error: retCode,
  2138. }
  2139. for key, val := range model.GlobalExpeditionHelpRewardList {
  2140. ackMsg.RewardItemList = append(ackMsg.RewardItemList, &serverproto.KeyValueType{Key: key, Value: val})
  2141. }
  2142. this.role.ReplayGate(ackMsg, true)
  2143. default:
  2144. ackMsg := &serverproto.SCExpeditionHelpAck{
  2145. Error: retCode,
  2146. }
  2147. this.role.ReplayGate(ackMsg, true)
  2148. }
  2149. }
  2150. // 判断是否可以成功被救助(玩家最近在线直接内存操作,不涉及DB操作)
  2151. func (this *RoleBattle) OnExpeditionBeHelp(fromUid, beHelpedUid uint64, helpMsgSendTime uint64) serverproto.ErrorCode {
  2152. if this.expeditionData.BeAssistNum != nil {
  2153. //该玩家被救助的次数达到上限,无法救助
  2154. if this.expeditionData.BeAssistNum.Key <= this.expeditionData.BeAssistNum.Value {
  2155. return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_CALLFORHELP_LIMIT
  2156. }
  2157. }
  2158. //之前过期的救助消息
  2159. if this.expeditionData.AssistTimeStamp > helpMsgSendTime || this.expeditionData.AssistTimeStamp == 0 {
  2160. return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_MSG_EXPIRED
  2161. }
  2162. //已经救助过该玩家,无法再次救助
  2163. bFind := false
  2164. idx := 0
  2165. for idx = 0; idx < len(this.expeditionData.BeAssistUidList); idx++ {
  2166. tmpUidData := this.expeditionData.BeAssistUidList[idx]
  2167. //判断是否是同一天救助
  2168. bNotSameDay := model.IsDailyResetHour5(uint64(tmpUidData.Value) * 1000)
  2169. if tmpUidData.Key == fromUid {
  2170. if !bNotSameDay {
  2171. return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_CALLFORHELP_HAS
  2172. }
  2173. bFind = true
  2174. break
  2175. }
  2176. }
  2177. //判断是否需要救助(英雄是否有死亡)
  2178. canBeHelp := false
  2179. for idx := 0; idx < len(this.expeditionData.BattleHeroHpList); idx++ {
  2180. if this.expeditionData.BattleHeroHpList[idx].Hp <= 0 {
  2181. canBeHelp = true
  2182. break
  2183. }
  2184. }
  2185. if !canBeHelp {
  2186. return serverproto.ErrorCode_ERROR_EXPEDITION_BE_HELPED
  2187. }
  2188. if this.expeditionData.BeAssistNum == nil {
  2189. this.expeditionData.BeAssistNum = &serverproto.KeyValueType{
  2190. Key: model.GlobalExpeditionGuildBeHelpedNum,
  2191. }
  2192. }
  2193. this.expeditionData.BeAssistNum.Value += 1
  2194. this.expeditionData.AssistState = false
  2195. this.expeditionData.AssistTimeStamp = 0
  2196. //回复所有英雄hp,sp
  2197. this.expeditionData.BattleHeroHpList = this.expeditionData.BattleHeroHpList[:0]
  2198. //加入救助列表
  2199. if bFind {
  2200. this.expeditionData.BeAssistUidList[idx].Value = int32(util.GetTimeSeconds())
  2201. } else {
  2202. this.expeditionData.BeAssistUidList = append(this.expeditionData.BeAssistUidList,
  2203. &serverproto.KeyValueType64{Key: fromUid, Value: int32(util.GetTimeSeconds())})
  2204. }
  2205. this.SetDirty(true)
  2206. this.expeditionChangeNtf(false)
  2207. return serverproto.ErrorCode_ERROR_OK
  2208. }
  2209. func (this *RoleBattle) ExpeditionPassReward(expeditionType int32) serverproto.ErrorCode {
  2210. if this.expeditionData == nil {
  2211. return serverproto.ErrorCode_ERROR_FAIL
  2212. }
  2213. //没有通关/最后一关没有奖励
  2214. if this.expeditionData.ExpeditionType <= expeditionType {
  2215. return serverproto.ErrorCode_ERROR_FAIL
  2216. }
  2217. if this.expeditionData.ExpeditionTypeReward&(1<<uint64(expeditionType)) > 0 {
  2218. return serverproto.ErrorCode_ERROR_EXPEDITION_PASS_REWARD_HAS
  2219. }
  2220. cfgData, ok := model.ConvertExpeditionDataList[expeditionType]
  2221. if !ok {
  2222. return serverproto.ErrorCode_ERROR_FAIL
  2223. }
  2224. rewardItemList := map[int32]int32{}
  2225. for idx := 0; idx < len(cfgData.PassRewardList); idx++ {
  2226. rewardItemList[cfgData.PassRewardList[idx].Key] += cfgData.PassRewardList[idx].Value
  2227. }
  2228. ret := this.role.GetRoleBag().CanAddItemList(rewardItemList)
  2229. if ret != serverproto.ErrorCode_ERROR_OK {
  2230. return ret
  2231. }
  2232. this.role.AddItemList(rewardItemList, AddFrom_Expedition, true)
  2233. this.expeditionData.ExpeditionTypeReward |= 1 << uint64(expeditionType)
  2234. this.SetDirty(true)
  2235. this.expeditionChangeNtf(false)
  2236. ackMsg := &serverproto.SCExpeditionPassRewardAck{
  2237. RewardItemList: cfgData.PassRewardList,
  2238. }
  2239. this.role.ReplayGate(ackMsg, true)
  2240. return serverproto.ErrorCode_ERROR_OK
  2241. }
  2242. // 救助日志过期惰性删除
  2243. func (this *RoleBattle) checkBeHelpUidListExpire() {
  2244. idx := 0
  2245. for idx < len(this.expeditionData.BeAssistUidList) {
  2246. tmpUidData := this.expeditionData.BeAssistUidList[idx]
  2247. //判断是否是同一天救助
  2248. recordTime := util.GetTimeByUint32(uint32(tmpUidData.Value)).AddDate(0, 0, 3)
  2249. if util.GetCurrentTimeNow().After(recordTime) {
  2250. this.expeditionData.BeAssistUidList = append(this.expeditionData.BeAssistUidList[:idx],
  2251. this.expeditionData.BeAssistUidList[idx+1:]...)
  2252. this.SetDirty(true)
  2253. } else {
  2254. idx++
  2255. }
  2256. }
  2257. }
  2258. func (this *RoleBattle) randExpeditionBoss(convertData *model.ConvertExpedition) {
  2259. levelCfgData, ok := convertData.LevelInfo[this.expeditionData.CurBattleLevel]
  2260. if !ok {
  2261. return
  2262. }
  2263. this.expeditionData.BossList = this.expeditionData.BossList[:0]
  2264. var tmpBossIdxList []int
  2265. for k := 0; k < 3; k++ {
  2266. bossInfo, bossRandIdx := levelCfgData.RandBoss(tmpBossIdxList)
  2267. if bossInfo != nil {
  2268. tmpBossIdxList = append(tmpBossIdxList, bossRandIdx)
  2269. this.expeditionData.BossList = append(this.expeditionData.BossList,
  2270. &serverproto.BattleExpeditionActor{
  2271. Id: bossInfo.BossId,
  2272. Level: bossInfo.BossLevel,
  2273. Hp: bossInfo.BossHP,
  2274. Sp: bossInfo.BossSP,
  2275. })
  2276. }
  2277. util.DebugF("randExpeditionBoss id=%v", bossInfo)
  2278. }
  2279. this.SetDirty(true)
  2280. }
  2281. func (this *RoleBattle) randBattleBuffList(levelInfo *model.ConvertExpeditionDetailInfo) {
  2282. //隔天重置,战斗还在进行中,结束时数据已经被清空
  2283. if this.expeditionData.BattleIdx <= 0 {
  2284. return
  2285. }
  2286. this.expeditionData.BattleSelectBuffList = this.expeditionData.BattleSelectBuffList[:0]
  2287. rand.Seed(int64(util.GetTimeMilliseconds()))
  2288. for idx := 0; idx < 3; idx++ {
  2289. bossId := this.expeditionData.BossList[this.expeditionData.BattleIdx-1].Id
  2290. tmpBossId := uint64(bossId)*100000 + uint64(this.expeditionData.CurExpeditionType*1000+this.expeditionData.CurBattleLevel)
  2291. buffId := levelInfo.RandBuff(this.expeditionBuffList, this.expeditionData.BattleSelectBuffList, tmpBossId)
  2292. if buffId > 0 {
  2293. this.expeditionData.BattleSelectBuffList = append(this.expeditionData.BattleSelectBuffList, buffId)
  2294. } else {
  2295. break
  2296. }
  2297. }
  2298. }
  2299. func (this *RoleBattle) GenWarriorScore(levelInfo *model.ConvertExpeditionDetailInfo) {
  2300. //获取勇士积分
  2301. //关卡积分
  2302. tmpAddScore := uint32(levelInfo.WarriorScore)
  2303. //this.expeditionData.CurExpeditionScore += uint32(levelInfo.WarriorScore)
  2304. //boss积分
  2305. if this.expeditionData.BattleIdx > 0 {
  2306. bossIdx := this.expeditionData.BattleIdx
  2307. bossId := this.expeditionData.BossList[bossIdx-1].Id
  2308. tmpBossId := uint64(bossId)*100000 + uint64(this.expeditionData.CurExpeditionType*1000+this.expeditionData.CurBattleLevel)
  2309. if bossCfgData, ok := model.ConvertExpeditionDropBuffList[tmpBossId]; ok {
  2310. tmpAddScore += uint32(bossCfgData.WarriorScore)
  2311. //this.expeditionData.CurExpeditionScore += uint32(bossCfgData.WarriorScore)
  2312. }
  2313. }
  2314. //更新勇士积分
  2315. if this.addExpeditionRankScore(tmpAddScore) {
  2316. //ntf player
  2317. this.expeditionChangeNtf(false)
  2318. }
  2319. this.SetDirty(true)
  2320. }
  2321. // 获取当前正在调整的boss id
  2322. func (this *RoleBattle) findBattleBossIdx() int32 {
  2323. return this.expeditionData.BattleIdx
  2324. }
  2325. // 判断挑战使用的英雄是否有已经死亡的
  2326. func (this *RoleBattle) isCurBattleHeroDied(heroInfoList []*serverproto.BattleExpeditionActor, flag int32) serverproto.ErrorCode {
  2327. if flag == 1 {
  2328. if len(heroInfoList) <= 0 {
  2329. return serverproto.ErrorCode_ERROR_EXPEDITION_HERO_NOT_IN_CHALLENGE
  2330. }
  2331. }
  2332. for idx := 0; idx < len(heroInfoList); idx++ {
  2333. bFind := false
  2334. for k := 0; k < len(this.expeditionData.BattleHeroList); k++ {
  2335. if this.expeditionData.BattleHeroList[k] == heroInfoList[idx].Id {
  2336. bFind = true
  2337. break
  2338. }
  2339. }
  2340. if !bFind {
  2341. return serverproto.ErrorCode_ERROR_EXPEDITION_HERO_NOT_IN_CHALLENGE
  2342. }
  2343. //挑战使用的英雄是否已经死亡
  2344. //开始阶段判断
  2345. if flag == 1 {
  2346. bFind = false
  2347. for k := 0; k < len(this.expeditionData.BattleHeroHpList); k++ {
  2348. if this.expeditionData.BattleHeroHpList[k].Hp <= 0 &&
  2349. this.expeditionData.BattleHeroHpList[k].Id == heroInfoList[idx].Id {
  2350. bFind = true
  2351. break
  2352. }
  2353. }
  2354. if bFind {
  2355. return serverproto.ErrorCode_ERROR_EXPEDITION_HERO_DIED
  2356. }
  2357. }
  2358. }
  2359. return serverproto.ErrorCode_ERROR_OK
  2360. }
  2361. func (this *RoleBattle) expeditionRewardAll(cfgData *model.ConvertExpedition, addItemList map[int32]int32) serverproto.ErrorCode {
  2362. var levelNum int32 = 0
  2363. bFind := false
  2364. for idx := 0; idx < len(this.expeditionData.FinishExpeditionList); idx++ {
  2365. tmpReward := this.expeditionData.FinishExpeditionList[idx]
  2366. if tmpReward == cfgData.ExpeditionType {
  2367. bFind = true
  2368. break
  2369. }
  2370. }
  2371. if bFind {
  2372. levelNum = cfgData.LevelNum + 1
  2373. } else {
  2374. if this.expeditionData.CurExpeditionType != cfgData.ExpeditionType {
  2375. return serverproto.ErrorCode_ERROR_FAIL
  2376. }
  2377. levelNum = this.expeditionData.CurBattleLevel
  2378. }
  2379. bFind = false
  2380. for idx := 0; idx < len(this.expeditionData.RewardStateList); idx++ {
  2381. tmpReward := this.expeditionData.RewardStateList[idx]
  2382. if tmpReward.ExpeditionType == cfgData.ExpeditionType {
  2383. //无奖励可领取
  2384. if len(tmpReward.RewardState) >= int(levelNum-1) {
  2385. return serverproto.ErrorCode_ERROR_EXPEDITION_REWARD_NO
  2386. }
  2387. bFind = true
  2388. for levelIdx := 1; levelIdx < int(levelNum); levelIdx++ {
  2389. bReward := false
  2390. for j := 0; j < len(tmpReward.RewardState); j++ {
  2391. if tmpReward.RewardState[j] == int32(levelIdx) {
  2392. bReward = true
  2393. break
  2394. }
  2395. }
  2396. if !bReward {
  2397. cfgData.GetLevelReward(int32(levelIdx), addItemList)
  2398. tmpReward.RewardState = append(tmpReward.RewardState, int32(levelIdx))
  2399. }
  2400. }
  2401. break
  2402. }
  2403. }
  2404. //该区域还未领取过奖励
  2405. if !bFind {
  2406. tmpReward := &serverproto.BattleExpeditionReward{
  2407. ExpeditionType: cfgData.ExpeditionType,
  2408. }
  2409. for levelIdx := 1; levelIdx < int(levelNum); levelIdx++ {
  2410. cfgData.GetLevelReward(int32(levelIdx), addItemList)
  2411. tmpReward.RewardState = append(tmpReward.RewardState, int32(levelIdx))
  2412. }
  2413. this.expeditionData.RewardStateList = append(this.expeditionData.RewardStateList, tmpReward)
  2414. }
  2415. if len(addItemList) > 0 {
  2416. this.SetDirty(true)
  2417. return serverproto.ErrorCode_ERROR_OK
  2418. }
  2419. return serverproto.ErrorCode_ERROR_EXPEDITION_REWARD_NO
  2420. }
  2421. func (this *RoleBattle) expeditionRewardBox(cfgData *model.ConvertExpedition, rewardBoxIdx int32, addItemList map[int32]int32) serverproto.ErrorCode {
  2422. var levelNum int32 = 0
  2423. bFind := false
  2424. for idx := 0; idx < len(this.expeditionData.FinishExpeditionList); idx++ {
  2425. tmpReward := this.expeditionData.FinishExpeditionList[idx]
  2426. if tmpReward == cfgData.ExpeditionType {
  2427. bFind = true
  2428. break
  2429. }
  2430. }
  2431. if bFind {
  2432. levelNum = cfgData.LevelNum + 1
  2433. } else {
  2434. if this.expeditionData.CurExpeditionType != cfgData.ExpeditionType {
  2435. return serverproto.ErrorCode_ERROR_FAIL
  2436. }
  2437. levelNum = this.expeditionData.CurBattleLevel
  2438. }
  2439. //还没完成的关卡无法获取奖励
  2440. if rewardBoxIdx >= levelNum {
  2441. return serverproto.ErrorCode_ERROR_EXPEDITION_REWARD_NO
  2442. }
  2443. bFind = false
  2444. for idx := 0; idx < len(this.expeditionData.RewardStateList); idx++ {
  2445. tmpReward := this.expeditionData.RewardStateList[idx]
  2446. if tmpReward.ExpeditionType != cfgData.ExpeditionType {
  2447. continue
  2448. }
  2449. bFind = true
  2450. for i := 0; i < len(tmpReward.RewardState); i++ {
  2451. if tmpReward.RewardState[i] == rewardBoxIdx {
  2452. return serverproto.ErrorCode_ERROR_EXPEDITION_REWARD_HAS
  2453. }
  2454. }
  2455. tmpReward.RewardState = append(tmpReward.RewardState, rewardBoxIdx)
  2456. }
  2457. if !bFind {
  2458. tmpReward := &serverproto.BattleExpeditionReward{
  2459. ExpeditionType: cfgData.ExpeditionType,
  2460. }
  2461. tmpReward.RewardState = append(tmpReward.RewardState, rewardBoxIdx)
  2462. this.expeditionData.RewardStateList = append(this.expeditionData.RewardStateList, tmpReward)
  2463. }
  2464. cfgData.GetLevelReward(rewardBoxIdx, addItemList)
  2465. this.SetDirty(true)
  2466. return serverproto.ErrorCode_ERROR_OK
  2467. }
  2468. // ============================================== 冲榜相关 ===========================================
  2469. func (this *RoleBattle) OnlineGetRushMapBaseReward(rewardRound int32) {
  2470. if this.rushMap == nil || rewardRound <= 0 {
  2471. return
  2472. }
  2473. if this.rushMap.RewardRound >= rewardRound {
  2474. this.rushMap.RushMapId = 0
  2475. this.rushMap.BagScore = 0
  2476. this.rushMap.MapScore = 0
  2477. this.SetDirty(true)
  2478. return
  2479. }
  2480. var addItemList = map[int32]int32{}
  2481. rewardLevel := model.GetRushActivityBaseReward(this.rushMap.FightRound, model.Rush_Type_Map, int32(this.rushMap.RushMapId), addItemList)
  2482. if len(addItemList) > 0 {
  2483. this.role.AddMail(model.GlobalMailRushMapBaseReward, serverproto.MailType_MailType_RushMap,
  2484. addItemList, []int32{int32(this.rushMap.RushMapId), rewardLevel}, "", "")
  2485. }
  2486. this.rushMap.RewardRound = rewardRound
  2487. this.rushMap.BagScore = 0
  2488. this.rushMap.MapScore = 0
  2489. this.SetDirty(true)
  2490. }
  2491. func (this *RoleBattle) OnlineProcess() {
  2492. this.OnlineCheckReward()
  2493. // 战斗加速时间 上线处理
  2494. this.FastBattleTimeOnline()
  2495. }
  2496. func (this *RoleBattle) OnlineCheckReward() {
  2497. if this.rushMap == nil {
  2498. this.rushMap = &serverproto.RushMap{}
  2499. this.SetDirty(true)
  2500. return
  2501. }
  2502. if this.rushMap != nil {
  2503. if this.rushMap.FightRound != 0 && this.rushMap.FightRound > this.rushMap.RewardRound {
  2504. reqMsg := &serverproto.SSGetRushBaseRewardReq{}
  2505. reqMsg.Uid = this.role.GetUUid()
  2506. reqMsg.RushType = model.Rush_Type_Map
  2507. reqMsg.RushRound = this.rushMap.FightRound
  2508. this.role.SendRank(reqMsg)
  2509. }
  2510. //发送奖励查询请求
  2511. /*
  2512. reqMsg := &serverproto.SSGetRushRankReq{
  2513. Uid: this.role.GetUUid(),
  2514. RushType: model.Rush_Type_Map,
  2515. RushRound: this.rushMap.RankReward,
  2516. }
  2517. this.role.SendRank(reqMsg)
  2518. */
  2519. }
  2520. }
  2521. func (this *RoleBattle) GetRushMapBaseReward(ackMsg *serverproto.SCRushActivityRewardAck, rushRound int32) serverproto.ErrorCode {
  2522. if ackMsg == nil {
  2523. return serverproto.ErrorCode_ERROR_FAIL
  2524. }
  2525. if this.rushMap.RewardRound >= rushRound {
  2526. return serverproto.ErrorCode_ERROR_RUSH_ACTIVITY_REWARD_FINISH
  2527. }
  2528. //检查this.fightRound 对应的保底奖励
  2529. addItemList := map[int32]int32{}
  2530. model.GetRushActivityBaseReward(this.rushMap.FightRound, model.Rush_Type_Map, int32(this.rushMap.RushMapId), addItemList)
  2531. this.rushMap.RewardRound = rushRound
  2532. this.role.AddItemList(addItemList, AddFrom_RushMap, true)
  2533. for key, value := range addItemList {
  2534. ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
  2535. Key: key,
  2536. Value: value,
  2537. })
  2538. }
  2539. this.SetDirty(true)
  2540. return serverproto.ErrorCode_ERROR_OK
  2541. }
  2542. func (this *RoleBattle) GetRushMapRankReward(ssAck *serverproto.SSGetRushRewardAck) serverproto.ErrorCode {
  2543. if ssAck == nil {
  2544. return serverproto.ErrorCode_ERROR_FAIL
  2545. }
  2546. if this.rushMap.RankReward >= ssAck.RushRound {
  2547. return serverproto.ErrorCode_ERROR_RUSH_ACTIVITY_REWARD_FINISH
  2548. }
  2549. var addItemList = map[int32]int32{}
  2550. for _, data := range ssAck.ItemList {
  2551. addItemList[data.Key] += data.Value
  2552. }
  2553. this.role.AddItemList(addItemList, AddFrom_RushMap, true)
  2554. this.rushMap.RankReward = ssAck.RushRound
  2555. this.SetDirty(true)
  2556. return serverproto.ErrorCode_ERROR_OK
  2557. }
  2558. func (this *RoleBattle) GetRushMapInfo(ackMsg *serverproto.SCMapActivityAck, curRound int32) {
  2559. if ackMsg == nil {
  2560. return
  2561. }
  2562. ackMsg.MapScore = int32(this.rushMap.MapScore)
  2563. ackMsg.BagScore = int32(this.rushMap.BagScore)
  2564. ackMsg.RankReward = false
  2565. ackMsg.RushLevel = this.rushMap.RushMapId
  2566. if this.rushMap.RankReward == curRound {
  2567. ackMsg.RankReward = true
  2568. }
  2569. ackMsg.ChallengReward = false
  2570. if this.rushMap.RewardRound != 0 && this.rushMap.RewardRound >= this.rushMap.FightRound {
  2571. ackMsg.ChallengReward = true
  2572. }
  2573. }
  2574. func (this *RoleBattle) CheckRankReward(finishRound int32) serverproto.ErrorCode {
  2575. if this.rushMap.RankReward >= finishRound {
  2576. return serverproto.ErrorCode_ERROR_FAIL
  2577. }
  2578. return serverproto.ErrorCode_ERROR_OK
  2579. }
  2580. func (this *RoleBattle) SetRankReward(finishRound int32) {
  2581. this.rushMap.RankReward = finishRound
  2582. this.SetDirty(true)
  2583. }
  2584. func (this *RoleBattle) GetFightCountMailReward(rushRound int32) {
  2585. if rushRound <= 0 {
  2586. return
  2587. }
  2588. if this.rushMap.RewardRound < this.rushMap.FightRound {
  2589. //发送上一轮冲榜战斗次数的奖励邮件
  2590. addItemList := map[int32]int32{}
  2591. rewardLevel := model.GetRushActivityBaseReward(this.rushMap.FightRound, model.Rush_Type_Map, int32(this.rushMap.RushMapId), addItemList)
  2592. if len(addItemList) > 0 {
  2593. this.role.AddMail(model.GlobalMailRushMapBaseReward, serverproto.MailType_MailType_RushMap,
  2594. addItemList, []int32{int32(this.rushMap.RushMapId), rewardLevel}, "", "")
  2595. }
  2596. this.rushMap.RewardRound = this.rushMap.FightRound
  2597. this.rushMap.BagScore = 0
  2598. this.rushMap.MapScore = 0
  2599. this.SetDirty(true)
  2600. }
  2601. }
  2602. // 去排行榜服务器校验是否活动内
  2603. func (this *RoleBattle) OnRushMapScoreChange(score2 int32, score3 int32) {
  2604. reqMsg := &serverproto.SSRushDataChangeReq{}
  2605. reqMsg.Uid = this.role.GetUUid()
  2606. reqMsg.RushType = model.Rush_Type_Map
  2607. reqMsg.Score2 = score2
  2608. reqMsg.Score3 = score3
  2609. this.role.SendRank(reqMsg)
  2610. }
  2611. // score2 战斗分数 score3 礼包分数
  2612. func (this *RoleBattle) AddRushMapScore(rushRound int32, score2 int32, score3 int32) {
  2613. if rushRound == 0 {
  2614. return
  2615. }
  2616. if this.rushMap == nil {
  2617. util.ErrorF("add score failed ,not init rushmap , uid: %v score: %v", this.role.GetUUid(), score2, score3)
  2618. return
  2619. }
  2620. globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Rush_Map_Activity_Unlock)]
  2621. if !ok {
  2622. util.ErrorF("add score failed ,config not found , uid: %v score: %v", this.role.GetUUid(), score2, score3)
  2623. return
  2624. }
  2625. if (score2 != Rush_Map_Fight_Score && this.GetLevelId() <= globalData.IVal) ||
  2626. (score3 == Rush_Map_Bag_Score && this.GetLevelId() < globalData.IVal) {
  2627. util.ErrorF("add score failed ,map level lower , uid: %v score: %v", this.role.GetUUid(), score2, score3)
  2628. return
  2629. }
  2630. if this.rushMap.FightRound != rushRound {
  2631. this.rushMap.FightRound = rushRound
  2632. this.rushMap.BagScore = 0
  2633. this.rushMap.MapScore = 0
  2634. }
  2635. this.rushMap.RushMapId = uint32(this.GetLevelId())
  2636. if score2 != 0 {
  2637. this.rushMap.MapScore += uint32(score2)
  2638. util.InfoF("rush map add score uid: %v score: %v", this.role.GetUUid(), score2)
  2639. }
  2640. if score3 != 0 {
  2641. this.rushMap.BagScore += uint32(score3)
  2642. util.InfoF("buy item add score uid: %v score: %v", this.role.GetUUid(), score3)
  2643. }
  2644. this.sendRushMapScoreToRank()
  2645. this.SetDirty(true)
  2646. }
  2647. // 同步积分到rank服务器
  2648. func (this *RoleBattle) sendRushMapScoreToRank() {
  2649. ntfMsg := &serverproto.SSRushMapScoreNtf{
  2650. Uid: this.role.GetUUid(),
  2651. }
  2652. ntfMsg.Score = this.rushMap.MapScore + this.rushMap.BagScore
  2653. this.role.SendRank(ntfMsg)
  2654. }
  2655. func (this *RoleBattle) OnExpeditionRankList(ssAckMsg *serverproto.SSExpeditionScoreRankListAck) {
  2656. ackMsg := &serverproto.SCExpeditionScoreRankListAck{
  2657. StartIdx: ssAckMsg.StartIdx,
  2658. RankList: ssAckMsg.RankList,
  2659. }
  2660. if ssAckMsg.SelfRankInfo == nil {
  2661. ackMsg.SelfRankInfo = &serverproto.ExpeditionRankInfo{
  2662. Score: this.expeditionData.CurExpeditionScoreMax,
  2663. }
  2664. } else {
  2665. ackMsg.SelfRankInfo = ssAckMsg.SelfRankInfo
  2666. ackMsg.SelfRankInfo.Score = this.expeditionData.CurExpeditionScoreMax
  2667. }
  2668. this.role.ReplayGate(ackMsg, true)
  2669. }
  2670. // bt服务器
  2671. // 特殊处理使用道具添加战斗倍数时间
  2672. // addTime(in s)
  2673. func (this *RoleBattle) FastBattleTimeAdd(durationTime int32) {
  2674. curTime := util.GetTimeMilliseconds()
  2675. addTime := uint64(durationTime) * 1000
  2676. if this.lastRecordBattleAcceTime <= 0 {
  2677. this.lastRecordBattleAcceTime = curTime
  2678. this.battleAcceDuration = addTime
  2679. } else {
  2680. //之前的持续时间用完了,需要重新设置,否则就是累加
  2681. if this.lastRecordBattleAcceTime+this.battleAcceDuration <= curTime {
  2682. this.lastRecordBattleAcceTime = curTime
  2683. this.battleAcceDuration = addTime
  2684. } else {
  2685. this.battleAcceDuration += addTime
  2686. }
  2687. }
  2688. this.SetDirty(true)
  2689. ntfMsg := &serverproto.SCPlayerBattleAcctTimeNtf{
  2690. LastRecordBattleAcceTime: this.lastRecordBattleAcceTime,
  2691. BattleAcceDuration: this.battleAcceDuration,
  2692. }
  2693. this.role.ReplayGate(ntfMsg, true)
  2694. }
  2695. // 战斗加速时间 离线处理
  2696. func (this *RoleBattle) FastBattleTimeOffline() {
  2697. if this.battleAcceDuration > 0 {
  2698. curTime := util.GetTimeMilliseconds()
  2699. if this.lastRecordBattleAcceTime+this.battleAcceDuration <= curTime {
  2700. this.battleAcceDuration = 0
  2701. } else {
  2702. this.battleAcceDuration -= curTime - this.lastRecordBattleAcceTime
  2703. }
  2704. this.lastRecordBattleAcceTime = curTime
  2705. util.InfoF("uid=%v FastBattleTimeOffline duration=%v", this.role.GetUUid(), this.battleAcceDuration)
  2706. this.SetDirty(true)
  2707. }
  2708. }
  2709. // 战斗加速时间 上线处理
  2710. func (this *RoleBattle) FastBattleTimeOnline() {
  2711. if this.battleAcceDuration > 0 {
  2712. curTime := util.GetTimeMilliseconds()
  2713. this.lastRecordBattleAcceTime = curTime
  2714. this.SetDirty(true)
  2715. }
  2716. }