role_battle.go 94 KB

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