| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939 |
- package model
- import (
- "math"
- "math/rand"
- "rocommon/util"
- "roserver/baseserver/model"
- "roserver/baseserver/set"
- "roserver/serverproto"
- "strings"
- )
- func (this *Role) Income() {
- if this.roleBattle != nil {
- ret := this.roleBattle.Income()
- if ret != serverproto.ErrorCode_ERROR_OK {
- ackMsg := &serverproto.SCPlayerIncomeAck{
- Error: int32(ret),
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- }
- //battle相关
- func (this *Role) BattleBossReq() {
- if this.roleBattle != nil {
- ret, deltaTime, factorList := this.roleBattle.BossRewardPre()
- ackMsg := &serverproto.SCBattleBossFightAck{
- Error: int32(ret),
- LeftCdTime: deltaTime,
- FactorList: factorList,
- }
- this.ReplayGate(ackMsg, true)
- if ret == serverproto.ErrorCode_ERROR_OK {
- //挑战时判断CD
- TaskMagCheck(this, serverproto.TaskType_Battle_Boss_Count, 1)
- }
- }
- }
- func (this *Role) BossReward(challengeTime uint32, mapId, mapLevel uint32, recordTimeStamp uint64) {
- if this.roleBattle != nil {
- ret := this.roleBattle.BossReward(challengeTime, mapId, mapLevel, recordTimeStamp)
- if ret != serverproto.ErrorCode_ERROR_OK {
- ackMsg := &serverproto.SCPlayerBossRewardAck{
- Error: int32(ret),
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- }
- //evil
- func (this *Role) BattleEvilRefresh(bForce bool) {
- if this.roleBattle != nil {
- ret, changeIdxList := this.roleBattle.BattleEvilRefresh(bForce)
- ackMsg := &serverproto.SCEvilRefreshAck{
- Error: int32(ret),
- }
- if changeIdxList != nil {
- ackMsg.PosIdxList = append(changeIdxList)
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- func (this *Role) BattleEvilChallenge(posIdx int32) {
- if this.roleBattle != nil {
- ret, addCount := this.roleBattle.BattleEvilChallenge(posIdx)
- ackMsg := &serverproto.SCEvilChallengeAck{
- Error: int32(ret),
- PosIdx: posIdx,
- AddCount: addCount,
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- //expedition
- func (this *Role) ExpeditionChallengePre(expeditionType int32) {
- ackMsg := &serverproto.SCExpeditionChallengePreAck{
- Error: int32(serverproto.ErrorCode_ERROR_FAIL),
- }
- if this.roleBattle != nil {
- ret := this.roleBattle.ExpeditionPre(expeditionType)
- ackMsg.Error = int32(ret)
- }
- this.ReplayGate(ackMsg, true)
- }
- //挑战区域地图关卡boss(结束上报)
- func (this *Role) ExpeditionChallenge(expeditionType, battleLevel int32, heroInfoList []*serverproto.BattleExpeditionActor,
- bossChangeHpList []*serverproto.BattleExpeditionActor, battleTime int32, bossIdx, flag int32) {
- ackMsg := &serverproto.SCExpeditionChallengeAck{
- Error: int32(serverproto.ErrorCode_ERROR_FAIL),
- }
- if this.roleBattle != nil {
- ret, bufList, isFinish := this.roleBattle.ExpeditionChallenge(expeditionType, battleLevel,
- heroInfoList, bossChangeHpList, battleTime, bossIdx, flag)
- ackMsg.Error = int32(ret)
- ackMsg.BuffList = bufList
- if isFinish {
- //1战斗开始,2刷新,3战斗结束 4(胜利的方式战斗结束服务之赋值)
- ackMsg.Flag = 4 //胜利的方式赋值成4
- } else {
- ackMsg.Flag = flag
- }
- }
- this.ReplayGate(ackMsg, true)
- }
- func (this *Role) ExpeditionBuffSelect(selectBuf int32) {
- ackMsg := &serverproto.SCExpeditionSelectBuffAck{
- Error: int32(serverproto.ErrorCode_ERROR_FAIL),
- }
- if this.roleBattle != nil {
- ret := this.roleBattle.ExpeditionBuffSelect(selectBuf)
- ackMsg.Error = int32(ret)
- }
- this.ReplayGate(ackMsg, true)
- }
- func (this *Role) ExpeditionReward(expeditionType, boxIdx int32) {
- ackMsg := &serverproto.SCExpeditionRewardAck{
- Error: int32(serverproto.ErrorCode_ERROR_FAIL),
- }
- if this.roleBattle != nil {
- ret := this.roleBattle.ExpeditionReward(expeditionType, boxIdx, ackMsg)
- ackMsg.Error = int32(ret)
- }
- this.ReplayGate(ackMsg, true)
- }
- func (this *Role) ExpeditionBattleHero(battleHeroList []int32) {
- ackMsg := &serverproto.SCExpeditionBattleHeroAck{
- Error: int32(serverproto.ErrorCode_ERROR_FAIL),
- }
- if this.roleBattle != nil {
- ret := this.roleBattle.ExpeditionBattleHero(battleHeroList)
- ackMsg.Error = int32(ret)
- }
- this.ReplayGate(ackMsg, true)
- }
- func (this *Role) ExpeditionCallForHelp(assistHelpUid uint64) {
- ackMsg := &serverproto.SCExpeditionCallForHelpAck{
- Error: int32(serverproto.ErrorCode_ERROR_FAIL),
- }
- if this.roleBattle != nil {
- ret := this.roleBattle.ExpeditionCallForHelp(assistHelpUid)
- ackMsg.Error = int32(ret)
- }
- this.ReplayGate(ackMsg, true)
- }
- func (this *Role) ExpeditionHelp(beHelpedUid uint64, msgType int32, helpMsgSendTime uint64) {
- ackMsg := &serverproto.SCExpeditionHelpAck{
- Error: int32(serverproto.ErrorCode_ERROR_FAIL),
- }
- if this.roleBattle != nil {
- ret := this.roleBattle.ExpeditionHelp(beHelpedUid, msgType, helpMsgSendTime)
- if ret != serverproto.ErrorCode_ERROR_OK {
- ackMsg.Error = int32(ret)
- this.ReplayGate(ackMsg, true)
- }
- }
- }
- func (this *Role) ExpeditionScoreRankList(startIdx int32) {
- if this.roleBattle != nil {
- if startIdx <= 0 || startIdx > math.MaxInt32 {
- ackMsg := &serverproto.SCExpeditionScoreRankListAck{
- Error: int32(serverproto.ErrorCode_ERROR_FAIL),
- }
- this.ReplayGate(ackMsg, true)
- return
- }
- ssMsg := &serverproto.SSExpeditionScoreRankListReq{
- StartIdx: startIdx,
- }
- this.SendRank(ssMsg)
- }
- }
- func (this *Role) ExpeditionPassReward(expeditionType int32) {
- if this.roleBattle == nil || expeditionType <= 0 {
- ackMsg := &serverproto.SCExpeditionPassRewardAck{
- Error: int32(serverproto.ErrorCode_ERROR_FAIL),
- }
- this.ReplayGate(ackMsg, true)
- return
- }
- ret := this.roleBattle.ExpeditionPassReward(expeditionType)
- if ret != serverproto.ErrorCode_ERROR_OK {
- ackMsg := &serverproto.SCExpeditionPassRewardAck{
- Error: int32(ret),
- }
- this.ReplayGate(ackMsg, true)
- }
- }
- func (this *Role) GetRushMapLevelReward(rushRound int32, rewardType int32) {
- ackMsg := &serverproto.SCRushActivityRewardAck{
- Error: int32(serverproto.ErrorCode_ERROR_FAIL),
- RewardType: rewardType,
- RushType: model.Rush_Type_Map,
- }
- if this.GetRoleBattle() != nil {
- nRet := this.GetRoleBattle().GetRushMapBaseReward(ackMsg, rushRound)
- ackMsg.Error = int32(nRet)
- }
- this.ReplayGate(ackMsg, true)
- }
- func (this *Role) GetRushMapInfo(ackMsg *serverproto.SCMapActivityAck, curRushRound int32) {
- if this.GetRoleBattle() != nil {
- this.GetRoleBattle().GetRushMapInfo(ackMsg, curRushRound)
- }
- }
- func (this *Role) GetRushMapRankReward(ssAck *serverproto.SSGetRushRewardAck) {
- ackMsg := &serverproto.SCRushActivityRewardAck{
- Error: int32(serverproto.ErrorCode_ERROR_FAIL),
- RewardType: model.Rush_Reward_Type_Rank,
- RushType: model.Rush_Type_Map,
- }
- if this.GetRoleBattle() != nil {
- nRet := this.GetRoleBattle().GetRushMapRankReward(ssAck)
- if nRet == serverproto.ErrorCode_ERROR_OK {
- ackMsg.ItemList = ssAck.ItemList
- }
- ackMsg.Error = int32(nRet)
- }
- this.ReplayGate(ackMsg, true)
- }
- const (
- MAX_BATTLEBOSS_NUM = 4
- //1 绿,2蓝,3紫,4金
- EvilBossType_Green = 1
- EvilBossType_Blue = 2
- EvilBossType_Purple = 3
- EvilBossType_Glod = 4
- )
- //战斗相关处理
- type RoleBattle struct {
- SaveObject
- incomeTime uint64
- maxIncomeTime uint64
- mapLevel uint32
- mapId uint32
- mapRewardCount uint32 //累计的挑战boss成功次数
- mapRewardId uint32
- mapRewardLevel uint32
- mapLevelTime uint64
- selfRank uint32
- totalRanks uint32
- topRankList []*serverproto.RankPlayerInfo
- getRankTimeStamp int64
- mapLevelChallengeNumList []*serverproto.KeyValueType
- quickBattle *serverproto.QuickBattleData
- mapRewardShowNum uint32 //income中显示当前有多少关卡的奖励没领取
- /*
- rushMapId uint32 //冲榜地图ID
- rewardRound int32 //冲榜保底奖励(记录领奖轮次)
- fightRound int32 //冲榜轮次
- mapScore uint32 //冲榜积分
- bagScore uint32 //礼包积分
- rankReward int32 //推图冲榜奖励轮次
- */
- rushMap *serverproto.RushMap
- //evil
- evilData *serverproto.BattleEvilData //evil
- lastChallengeTime int64
- battleBossGapTime int64 //BOSS战斗间隔时间10秒
- isChallengeBegin bool
- //expedition
- expeditionData *serverproto.BattleExpedition
- expeditionBuffList set.Interface
- // bt服务器战斗加速时间
- lastRecordBattleAcceTime uint64 // 时间戳
- battleAcceDuration uint64 // 持续时间ms
- }
- func newRoleBattle(r *Role) *RoleBattle {
- roleBattle := &RoleBattle{
- SaveObject: SaveObject{
- role: r,
- },
- battleBossGapTime: 10,
- }
- return roleBattle
- }
- func (this *RoleBattle) Load(msg interface{}) bool {
- proRole := msg.(*serverproto.Role)
- if proRole != nil && proRole.RoleBattle != nil {
- this.incomeTime = proRole.RoleBattle.LastIncomeTime
- if this.incomeTime <= 0 {
- //创建新号后,默认赠送1次挂机宝箱计数 送4分钟
- globalIncomeTime := uint64(model.GlobalIncomeTime) * 1000
- this.incomeTime = this.role.RegisterTime - globalIncomeTime
- globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Battle_Limit_Time)]
- if ok {
- this.maxIncomeTime = uint64(globalData.IVal * 1000)
- }
- this.SetDirty(true)
- }
- this.mapLevelChallengeNumList = proRole.RoleBattle.MapChallengeNumList
- this.mapLevel = proRole.RoleBattle.MapLevel
- this.mapId = proRole.RoleBattle.MapId
- //累计的挑战boss成功次数
- this.mapRewardCount = proRole.RoleBattle.RewardMapCount
- this.mapRewardId = proRole.RoleBattle.RewardMapId
- this.mapRewardLevel = proRole.RoleBattle.RewardMapLevel
- this.mapLevelTime = proRole.RoleBattle.MapLevelTime
- this.lastRecordBattleAcceTime = proRole.RoleBattle.LastRecordBattleAcceTime
- this.battleAcceDuration = proRole.RoleBattle.BattleAcceDuration
- if this.mapLevel == 0 || this.mapId == 0 {
- this.mapLevel = 1
- this.mapId = 1
- this.SetDirty(true)
- }
- if this.mapRewardId == 0 || this.mapRewardLevel == 0 {
- this.mapRewardId = 1
- this.mapRewardLevel = 1
- this.SetDirty(true)
- }
- this.getMapRewardShowCount()
- this.quickBattle = &serverproto.QuickBattleData{}
- if proRole.RoleBattle.QuickBattle != nil {
- *this.quickBattle = *(proRole.RoleBattle.QuickBattle)
- }
- //evil
- this.loadEvil(proRole.RoleBattle)
- //expedition
- this.loadExpedition(proRole.RoleBattle)
- if proRole.RoleBattle.RushMap == nil {
- this.rushMap = &serverproto.RushMap{}
- this.SetDirty(true)
- } else {
- this.rushMap = proRole.RoleBattle.RushMap
- }
- // this.OnlineCheckReward(proRole.RoleBattle)
- }
- this.RefreshQuickBattle(false)
- return true
- }
- func (this *RoleBattle) loadEvil(tmpRoleBattle *serverproto.RoleBattle) {
- vipData := this.role.GetRoleBase().GetVipData(model.Vip_System_Evil)
- if tmpRoleBattle.EvilInfo != nil {
- this.evilData = tmpRoleBattle.EvilInfo
- if this.evilData.EvilLevel <= 0 {
- this.evilData.EvilLevel = 1
- if vipData > 0 {
- this.evilData.FreeCount = vipData
- this.evilData.TotalCount = vipData
- }
- this.evilRefresh(true, false, false)
- this.SetDirty(true)
- } else {
- //等级超过上限强制回退
- _, ok := model.ConvertEvilBossList[this.evilData.EvilLevel]
- if !ok {
- this.evilData.EvilLevel--
- this.SetDirty(true)
- }
- }
- } else {
- this.evilData = &serverproto.BattleEvilData{
- EvilLevel: 1,
- }
- if vipData > 0 {
- this.evilData.FreeCount = vipData
- this.evilData.TotalCount = vipData
- }
- this.evilRefresh(true, false, false)
- this.SetDirty(true)
- }
- }
- func (this *RoleBattle) loadExpedition(tmpRoleBattle *serverproto.RoleBattle) {
- this.expeditionData = tmpRoleBattle.ExpeditionInfo
- if this.expeditionData == nil {
- this.expeditionData = &serverproto.BattleExpedition{
- ChallengeNum: model.GlobalExpeditionChallengeNum,
- ExpeditionType: 1,
- }
- this.SetDirty(true)
- }
- if this.expeditionData.ExpeditionScoreResetTime <= 0 {
- this.expeditionData.CurExpeditionScore = 0
- this.expeditionData.CurExpeditionScoreMax = 0
- this.expeditionData.ExpeditionScoreResetTime = util.GetTimeMilliseconds()
- this.SetDirty(true)
- }
- if this.expeditionData.ExpeditionType <= 0 {
- this.expeditionData.ExpeditionType = 1
- this.SetDirty(true)
- }
- this.expeditionBuffList = set.New(set.NonThreadSafe)
- for idx := 0; idx < len(this.expeditionData.BattleBuffList); idx++ {
- this.expeditionBuffList.Add(this.expeditionData.BattleBuffList[idx])
- }
- if this.expeditionData.AssistNum == nil {
- this.expeditionData.AssistNum = &serverproto.KeyValueType{
- Key: model.GlobalExpeditionGuildHelpNum,
- Value: 0,
- }
- this.SetDirty(true)
- } else {
- if this.expeditionData.AssistNum.Key <= 0 {
- this.expeditionData.AssistNum.Key = model.GlobalExpeditionGuildHelpNum
- }
- this.SetDirty(true)
- }
- if this.expeditionData.BeAssistNum == nil {
- this.expeditionData.BeAssistNum = &serverproto.KeyValueType{
- Key: model.GlobalExpeditionGuildBeHelpedNum,
- Value: 0,
- }
- this.SetDirty(true)
- } else {
- if this.expeditionData.BeAssistNum.Key <= 0 {
- this.expeditionData.BeAssistNum.Key = model.GlobalExpeditionGuildBeHelpedNum
- this.SetDirty(true)
- }
- }
- }
- func (this *RoleBattle) Save() {
- this.SetDirty(false)
- //util.DebugF("uid=%v RoleBattle save...", this.role.GetUUid())
- //save to db
- saveMsg := &serverproto.SSBattleDataSaveReq{
- Battle: &serverproto.RoleBattle{
- LastIncomeTime: this.incomeTime,
- MapLevel: this.mapLevel,
- MapId: this.mapId,
- QuickBattle: this.quickBattle,
- RewardMapId: this.mapRewardId,
- RewardMapLevel: this.mapRewardLevel,
- RewardMapCount: this.mapRewardCount,
- EvilInfo: this.evilData,
- ExpeditionInfo: this.expeditionData,
- MapLevelTime: this.mapLevelTime,
- RushMap: this.rushMap,
- LastRecordBattleAcceTime: this.lastRecordBattleAcceTime,
- BattleAcceDuration: this.battleAcceDuration,
- //todo...
- //MapChallengeNumList: this.mapLevelChallengeNumList, 数据太大后续做优化处理
- },
- }
- this.role.SendDb(saveMsg)
- }
- func (this *RoleBattle) CopyData(data *serverproto.RoleBattle) {
- data.LastIncomeTime = this.incomeTime
- data.MapId = this.mapId
- data.MapLevel = this.mapLevel
- data.RewardMapCount = this.getMapRewardShowCount()
- this.quickBattle.MaxTimes = model.GlobalQuickBattleTimes
- vipData := this.role.GetRoleBase().GetVipData(model.Vip_System_QuickBattle)
- this.quickBattle.MaxTimes += vipData
- data.QuickBattle = this.quickBattle
- data.EvilInfo = this.evilData
- data.ExpeditionInfo = this.expeditionData
- data.BattleAcceDuration = this.battleAcceDuration
- data.LastRecordBattleAcceTime = this.lastRecordBattleAcceTime
- }
- func (this *RoleBattle) DailyReset(notify bool) {
- this.RefreshQuickBattle(notify)
- vipData := this.role.GetRoleBase().GetVipData(model.Vip_System_Evil)
- this.evilData.FreeCount = vipData
- this.evilData.TotalCount = vipData
- if vipData <= 0 {
- this.evilData.FreeLimit = true
- }
- if notify {
- this.evilDataChangeNtf()
- }
- this.dailyResetExpedition(notify)
- this.SetDirty(true)
- }
- func (this *RoleBattle) RefreshQuickBattle(bNtf bool) {
- if this.quickBattle == nil {
- return
- }
- isReset := model.IsDailyResetHour5(this.quickBattle.DrawTime * 1000)
- if true == isReset { //不是同一天,重置
- this.quickBattle.DrawTime = uint64(util.GetTimeSeconds())
- this.quickBattle.DayTimes = 0
- this.SetDirty(true)
- if bNtf {
- this.changeBattleDataNtf()
- }
- }
- }
- func (this *RoleBattle) getMapRewardShowCount() uint32 {
- if this.mapRewardShowNum <= 0 {
- this.mapRewardShowNum = this.getDeltaMapCount(this.mapRewardId, this.mapRewardLevel, this.mapId, this.mapLevel)
- }
- return this.mapRewardShowNum
- }
- func (this *RoleBattle) getDeltaMapCount(mapIdOld, mapLevelOld, mapIdNew, mapLevelNew uint32) uint32 {
- var rewardCount uint32 = 0
- if mapIdOld == mapIdNew {
- if mapLevelNew > mapLevelOld {
- rewardCount += mapLevelNew - mapLevelOld
- }
- } else if mapIdNew > mapIdOld && mapLevelNew > 0 {
- tmpMapId := mapIdOld
- tmpMapLevel := mapLevelOld
- for {
- levelId := this.getLevelId(tmpMapId, tmpMapLevel)
- _, ok := serverproto.LevelCfgLoader[levelId]
- if !ok {
- tmpMapId++
- tmpMapLevel = 1
- if tmpMapId > mapIdNew {
- break
- }
- continue
- }
- rewardCount++
- tmpMapLevel++
- if tmpMapId == mapIdNew && tmpMapLevel >= mapLevelNew {
- break
- }
- }
- }
- return rewardCount
- }
- //获取关卡累计奖励
- func (this *RoleBattle) GetMapShowReward(addItemList map[int32]int32) {
- showNum := this.getMapRewardShowCount()
- if showNum > 0 {
- for idx := 0; idx < len(this.role.GetRoleBase().GetBossReward()); idx++ {
- item := this.role.GetRoleBase().GetBossReward()[idx]
- addItemList[item.Key] += item.Value
- }
- this.role.GetRoleBase().ClearBossReward()
- this.mapRewardShowNum = 0
- this.mapRewardId = this.mapId
- this.mapRewardLevel = this.mapLevel
- this.SetDirty(true)
- this.changeBattleDataNtf()
- }
- }
- func (this *RoleBattle) addMapRewardCount(rewardCount uint32) {
- if rewardCount > 0 {
- this.mapRewardCount += rewardCount
- this.mapRewardShowNum += rewardCount
- this.SetDirty(true)
- }
- }
- func (this *RoleBattle) changeBattleDataNtf() {
- if this.quickBattle != nil && this.quickBattle.MaxTimes == 0 {
- maxTime := model.GlobalQuickBattleTimes
- vipData := this.role.GetRoleBase().GetVipData(model.Vip_System_QuickBattle)
- maxTime += vipData
- this.quickBattle.MaxTimes = int32(maxTime)
- this.SetDirty(true)
- }
- ntfMsg := &serverproto.SCPlayerBattleDataChangeNtf{
- LastIncomeTime: this.incomeTime,
- MapId: this.mapId,
- MapLevel: this.mapLevel,
- MaxIncomeTime: uint64(this.maxIncomeTime),
- QuickBattle: this.quickBattle,
- RewardMapCount: this.getMapRewardShowCount(),
- }
- this.role.ReplayGate(ntfMsg, true)
- }
- func (this *RoleBattle) changeQuickBattleNtf(errorCode int32, itemList []*serverproto.KeyValueType) {
- ntfMsg := &serverproto.SCQuickBattleIncomeAck{
- Error: errorCode,
- ItemList: itemList,
- }
- this.role.ReplayGate(ntfMsg, true)
- }
- func (this *RoleBattle) SetMapRank(selfRank, totalRanks uint32, topRankList []*serverproto.RankPlayerInfo, addSystemMsg bool) {
- this.selfRank = selfRank
- this.totalRanks = totalRanks
- this.topRankList = topRankList
- //刚打完战斗时,会回调并设置,这边需要重新设置时间
- this.getRankTimeStamp = util.GetTimeSeconds()
- //util.InfoF("uid=%v SetMapRank selfRank=%v totalRanks=%v topRankList=%v", this.role.GetUUid(),
- // this.selfRank, this.totalRanks, this.topRankList)
- //第一个通过该关卡的玩家
- if this.selfRank == 1 && addSystemMsg {
- if this.mapId > 1 && this.mapLevel%5 == 0 {
- this.role.AddSystemMessage(SystemMessageType_PassMap,
- AddSystemMsg{ParamId: this.getLevelId(this.mapId, this.mapLevel)})
- }
- }
- }
- //通关指定关卡次数,目前都是一次,后续有特殊关卡会记录通关次数
- func (this *RoleBattle) GetPassBattleIdNum(passBattleId int32) int32 {
- if this.getLevelId(this.mapId, this.mapLevel) > passBattleId {
- return 1
- }
- return 0
- }
- func (this *RoleBattle) SetIncomeTime(incomeTime uint64) {
- this.incomeTime = incomeTime
- this.SetDirty(true)
- this.changeBattleDataNtf()
- }
- func (this *RoleBattle) GetLevelId() int32 {
- return this.getLevelId(this.mapId, this.mapLevel)
- }
- func (this *RoleBattle) getLevelId(mapId uint32, mapLevel uint32) int32 {
- return int32(mapId*10000 + mapLevel)
- }
- func (this *RoleBattle) addMapRank(rewardCount uint32, oldMapId, oldMapLevel uint32, passTime uint32, recordTimeStamp uint64) {
- NewMapLevelId := this.getLevelId(this.mapId, this.mapLevel)
- oldMapLevelId := this.getLevelId(oldMapId, oldMapLevel)
- dbMsg := &serverproto.SSMapLevelChangeReq{
- NewMapLevelId: uint32(NewMapLevelId),
- PassTime: uint64(util.GetTimeMilliseconds()),
- }
- dbMsg.RecordInfo = &serverproto.BattleRecordInfo{
- Uid: this.role.GetUUid(),
- BattleRecordId: model.GenerateUid(),
- NickName: this.role.GetNickName(),
- ImgId: this.role.GetImageId(),
- Gender: this.role.GetRoleBase().GetRoleSex(),
- Level: this.role.GetRoleLevel(),
- ConfigId: this.role.GetRoleBase().RoleData().HeroData.ConfigId,
- FightPower: int32(this.role.roleBattleAttr.curTotalFightPower),
- //FightPower: int32(this.role.GetRoleFightPower().TotalFightPower),
- RecordTime: recordTimeStamp,
- BattleTime: passTime,
- MapLevelId: oldMapLevelId,
- HeadFrameId: this.role.GetRoleBase().RoleData().HeadFrameId,
- }
- oldLevelCfgData, ok := serverproto.LevelCfgLoader[oldMapLevelId]
- if ok {
- dbMsg.RecordInfo.BattleVersion = oldLevelCfgData.Version
- }
- this.role.SendRank(dbMsg)
- this.addMapRewardCount(rewardCount)
- //技能槽解锁
- if this.role.GetRoleSkill() != nil {
- this.role.GetRoleSkill().CheckSlotLockState()
- }
- //判断解锁卡槽
- if this.role.GetRoleCard() != nil {
- this.role.GetRoleCard().CheckUnLockState()
- }
- //首充是否开启 /超值礼包开启
- if this.role.GetRoleActivity() != nil {
- this.role.GetRoleActivity().FirstChargeUnlockState()
- //超值礼包开启
- this.role.GetRoleActivity().SuperChargeUnlockCheck(
- serverproto.UnlockChargeType_UChargeType_BattleLevel, &SuperChargeUnlockST{oldValue: oldMapLevelId})
- }
- //百人道场功能解锁
- if this.role.GetRoleDaoChang100() != nil {
- this.role.GetRoleDaoChang100().Unlock()
- }
- //BT根据关卡的功能解锁
- if this.role.GetRoleBT() != nil {
- this.role.GetRoleBT().UnlockBTSystem()
- }
- //任务处理
- TaskMagCheck(this.role, serverproto.TaskType_Level_Battle_Count, 0)
- TaskMagCheck(this.role, serverproto.TaskType_Battle_Boss_Reward_Count, 1)
- this.role.GetRoleBase().UpdatePlayerBriefInfo(false)
- this.role.GetRoleBase().SetFightPower(0)
- }
- //收益
- func (this *RoleBattle) Income() serverproto.ErrorCode {
- levelId := this.getLevelId(this.mapId, this.mapLevel)
- nowTime := util.GetTimeMilliseconds()
- if nowTime <= this.incomeTime {
- util.WarnF("uid=%v now time less income time !!!", this.role.GetUUid())
- return serverproto.ErrorCode_ERROR_BATTLE_INCOME_INVALID
- }
- globalIncomeTime := uint64(model.GlobalIncomeTime) * 1000
- if this.maxIncomeTime <= 0 {
- this.maxIncomeTime = uint64(model.GlobalIncomeLimitTime) * 1000
- }
- //VIP额外时间
- extraTime := this.role.GetRoleBase().GetVipData(model.Vip_System_HungExtraTime)
- if extraTime > 0 {
- this.maxIncomeTime += uint64(extraTime) * 1000
- }
- globalIncomeLimitTime := this.maxIncomeTime
- deltaTime := nowTime - this.incomeTime
- if deltaTime < globalIncomeTime && !this.role.GetRoleBase().HasBossReward() {
- util.WarnF("uid=%v delta time less Global income time !!!", this.role.GetUUid())
- return serverproto.ErrorCode_ERROR_BATTLE_INCOME_INVALID
- }
- //超过上限时间用上限时间
- var incomeNum int32
- if deltaTime > globalIncomeLimitTime {
- deltaTime = globalIncomeLimitTime
- incomeNum = int32(deltaTime / globalIncomeTime)
- //设置下次收益领取时间
- this.SetIncomeTime(nowTime)
- } else {
- incomeNum = int32(deltaTime / globalIncomeTime)
- //设置下次收益领取时间
- this.SetIncomeTime(this.incomeTime + uint64(incomeNum)*globalIncomeTime)
- }
- //获取活动道具产出次数
- //util.DebugF("deltaTime:%v incomeNum:%v incomeTime:%v globalIncomeTime:%v globalIncomeLimitTime:%v",
- // deltaTime, incomeNum, this.incomeTime, globalIncomeTime, globalIncomeLimitTime)
- var addItemList = map[int32]int32{}
- this.levelOnlineReward(levelId, addItemList, incomeNum)
- //获取关卡累计奖励
- this.GetMapShowReward(addItemList)
- this.role.AddItemList(addItemList, AddFrom_Battle, true)
- //客户端显示
- ackMsg := &serverproto.SCPlayerIncomeAck{
- Error: int32(serverproto.ErrorCode_ERROR_OK),
- }
- for key, value := range addItemList {
- ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
- Key: key,
- Value: value,
- })
- }
- this.role.ReplayGate(ackMsg, true)
- TaskMagCheck(this.role, serverproto.TaskType_Get_Online_Box_Count, 1)
- util.DebugF("uid=%v Income dropList=%v", this.role.GetUUid(), addItemList)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) levelOnlineReward(levelId int32, addItemList map[int32]int32, rewardNum int32) {
- if rewardNum <= 0 {
- return
- }
- levelCfgData, ok := serverproto.LevelCfgLoader[levelId]
- if !ok {
- return
- }
- //baseExp
- vipBase := this.role.GetRoleBase().GetVipData(int32(model.Vip_System_HungExp))
- exBase := int64(vipBase) * int64(levelCfgData.BaseExpOl) * int64(rewardNum) / 10000
- addItemList[int32(serverproto.ResType_Res_RoleBaseExp)] = levelCfgData.BaseExpOl*rewardNum + int32(exBase)
- //coin
- vipSilver := this.role.GetRoleBase().GetVipData(int32(model.Vip_System_HungSilver))
- exSilver := int64(vipSilver) * int64(levelCfgData.ZenyOl) * int64(rewardNum) / 10000
- addItemList[int32(serverproto.ResType_Res_Coin)] = levelCfgData.ZenyOl*rewardNum + int32(exSilver)
- //伙伴经验
- vipPartner := this.role.GetRoleBase().GetVipData(int32(model.Vip_System_HungPartnerExp))
- exPartner := int64(vipPartner) * int64(levelCfgData.ParterOl) * int64(rewardNum) / 10000
- addItemList[int32(serverproto.ResType_Res_HeroBaseExp)] = levelCfgData.ParterOl*rewardNum + int32(exPartner)
- //Cruise
- vipSkill := this.role.GetRoleBase().GetVipData(int32(model.Vip_System_HungSkillExp))
- exSKill := int64(vipSkill) * int64(levelCfgData.CruiseOl) * int64(rewardNum) / 10000
- addItemList[int32(serverproto.ResType_Res_Cruise)] = levelCfgData.CruiseOl*rewardNum + int32(exSKill)
- //EvilExp
- addItemList[int32(serverproto.ResType_Res_EvilExp)] = levelCfgData.EvilOl * rewardNum
- //rmb
- addItemList[int32(serverproto.ResType_Res_Rmb)] = levelCfgData.GoldOl * rewardNum
- //Drop处理
- rand.Seed(int64(util.GetTimeMilliseconds()))
- for i := 0; i < int(rewardNum); i++ {
- dropId := this.genDropId(model.LevelDropCommonDataList, levelId)
- for idx := 0; idx < len(dropId); idx++ {
- this.DropProcess(addItemList, dropId[idx])
- }
- }
- //活动奖励掉落赛季
- for idx := 0; idx < int(rewardNum); idx++ {
- hpDropIdList := this.genHDDropId(model.LevelDropHDDataList, levelId)
- for key, val := range hpDropIdList {
- addItemList[key] += val
- }
- }
- // 特权魔魂值加成
- devilsUp := this.role.GetRoleBase().GetVipData(model.Vip_System_DevilsUp)
- if devilsUp > 0 {
- addItemList[int32(serverproto.ResType_Res_EvilExp)] += devilsUp * rewardNum
- }
- }
- func (this *RoleBattle) GMIncome(incomeTime int32) {
- levelId := this.getLevelId(this.mapId, this.mapLevel)
- incomeNum := incomeTime * 60 / model.GlobalIncomeTime
- var addItemList = map[int32]int32{}
- if incomeNum > 0 {
- //包含异常情况发送过大数据
- if incomeNum > 50 {
- incomeNum = 50
- }
- this.levelOnlineReward(levelId, addItemList, incomeNum)
- this.role.AddItemList(addItemList, AddFrom_Battle, true)
- }
- //回复客户端用户显示
- ackMsg := &serverproto.SCPlayerIncomeAck{
- Error: int32(serverproto.ErrorCode_ERROR_OK),
- }
- for key, value := range addItemList {
- ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
- Key: key,
- Value: value,
- })
- }
- this.role.ReplayGate(ackMsg, true)
- util.DebugF("uid=%v GMIncome incomenum=%v dropList=%v", this.role.GetUUid(), incomeNum, ackMsg)
- }
- func (this *RoleBattle) GMSetMapLevel(mapId, mapLevel uint32) {
- //关卡数据不存在
- levelId := this.getLevelId(mapId, mapLevel)
- _, ok := serverproto.LevelCfgLoader[levelId]
- if !ok {
- return
- }
- rewardCount := this.getDeltaMapCount(this.mapId, this.mapLevel, mapId, mapLevel)
- oldMapId := this.mapId
- oldMapLevel := this.mapLevel
- this.mapId = mapId
- this.mapLevel = mapLevel
- this.SetDirty(true)
- //修改地图通关排名(需要通关该关卡)
- this.addMapRank(rewardCount, oldMapId, oldMapLevel, 0, 0)
- this.changeBattleDataNtf()
- }
- //开启所有解锁的关卡区域地图
- func (this *RoleBattle) GmExpeditionOpenAll() {
- if this.expeditionData != nil {
- for _, val := range model.ConvertExpeditionDataList {
- if val.ExpeditionType > this.expeditionData.ExpeditionType {
- this.expeditionData.ExpeditionType = val.ExpeditionType
- this.SetDirty(true)
- }
- }
- this.expeditionChangeNtf(false)
- }
- }
- func (this *RoleBattle) GmExpeditionOpen(level int32) {
- if this.expeditionData != nil {
- for _, val := range model.ConvertExpeditionDataList {
- if val.ExpeditionType == level {
- this.expeditionData.ExpeditionType = val.ExpeditionType
- this.SetDirty(true)
- }
- }
- this.expeditionChangeNtf(false)
- }
- }
- func (this *RoleBattle) GmExpeditionFightCount(count int32) {
- if this.expeditionData != nil {
- this.expeditionData.ChallengeNum = count
- this.SetDirty(true)
- this.expeditionChangeNtf(false)
- }
- }
- func (this *RoleBattle) GmExpeditionRankScore(score int32) {
- this.expeditionData.CurExpeditionScore += uint32(score)
- this.expeditionData.CurExpeditionScoreMax = this.expeditionData.CurExpeditionScore
- //update rank
- ssMsg := &serverproto.SSExpeditionUpdateScoreRankNtf{
- CurScore: this.expeditionData.CurExpeditionScoreMax,
- }
- this.role.SendRank(ssMsg)
- //ntf player
- this.expeditionChangeNtf(false)
- }
- //点击挑战时的预处理
- func (this *RoleBattle) BossRewardPre() (serverproto.ErrorCode, int32, []*serverproto.KeyValueType) {
- this.role.roleBattleAttr.BattleAttrInit()
- nowTime := util.GetTimeMilliseconds()
- //校验是否连续战斗
- if this.lastChallengeTime != 0 && this.battleBossGapTime != 0 {
- deltaTime := int64(nowTime/1000) - this.lastChallengeTime
- if deltaTime < this.battleBossGapTime && deltaTime > 0 {
- util.InfoF("uid=%v BossRewardPre cd time!!! cdTime=%v delTime=%v", this.role.GetUUid(), this.battleBossGapTime, deltaTime)
- return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_CD_TIME, int32(deltaTime), nil
- }
- }
- this.lastChallengeTime = int64(nowTime / 1000)
- this.isChallengeBegin = true
- //获取衰减系数
- var decayList []*serverproto.KeyValueType
- if this.mapFightCheck() == serverproto.ErrorCode_ERROR_OK {
- var kvList = map[int32]int32{}
- this.getDecayList(kvList, nowTime)
- for k, v := range kvList {
- decayList = append(decayList, &serverproto.KeyValueType{Key: k, Value: v})
- }
- }
- //todo...
- //统计挑战次数
- //数据量太大暂时屏蔽
- //mapLevel := this.GetLevelId()
- //bFind := false
- //for idx := 0; idx < len(this.mapLevelChallengeNumList); idx++ {
- // if this.mapLevelChallengeNumList[idx].Key == mapLevel {
- // this.mapLevelChallengeNumList[idx].Value++
- // bFind = true
- // this.SetDirty(true)
- // break
- // }
- //}
- //if !bFind {
- // this.mapLevelChallengeNumList = append(this.mapLevelChallengeNumList, &serverproto.KeyValueType{Key: mapLevel, Value: 1})
- // this.SetDirty(true)
- //}
- return serverproto.ErrorCode_ERROR_OK, 0, decayList
- }
- func (this *RoleBattle) getDecayList(kvList map[int32]int32, nowTime uint64) {
- mapLevelId := this.GetLevelId()
- convertData, ok := model.ConvertLevelPowerDecayFactorList[mapLevelId]
- if ok {
- convertData.GetDecayList(kvList, uint64(this.role.roleBattleAttr.curTotalFightPower))
- //convertData.GetDecayList(kvList, this.role.GetRoleFightPower().TotalFightPower)
- }
- convertData, ok = model.ConvertLevelTimeDecayFactorList[mapLevelId]
- if ok {
- deltaTime := (nowTime - this.mapLevelTime) / 1000
- deltaTime = deltaTime / 60
- convertData.GetDecayList(kvList, deltaTime)
- }
- if model.ConvertLevelSpAdd != nil {
- kvList[model.ConvertLevelSpAdd.Key] += model.ConvertLevelSpAdd.Value
- }
- util.InfoF("uid=%v RoleBattleDecay kv=%v", this.role.GetUUid(), kvList)
- }
- //挑战BOSS奖励
- func (this *RoleBattle) BossReward(challengeTime uint32, mapId, mapLevel uint32, recordTimeStamp uint64) serverproto.ErrorCode {
- //合法性检测
- //机器人处理
- //if service.GetServiceConfig().Node.RobotMode != 1 {
- // ret := this.bossRewardCheck(challengeTime, mapId, mapLevel)
- // if ret != serverproto.ErrorCode_ERROR_OK {
- // return ret
- // }
- //}
- ret := this.bossRewardCheck(challengeTime, mapId, mapLevel)
- if ret != serverproto.ErrorCode_ERROR_OK {
- return ret
- }
- levelId := this.getLevelId(this.mapId, this.mapLevel)
- levelCfgData, ok := serverproto.LevelCfgLoader[levelId]
- if !ok {
- return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_DATA_NOT_FOUND
- }
- checkRet := this.checkMapLevelChallenge(levelCfgData)
- if checkRet != serverproto.ErrorCode_ERROR_OK {
- return checkRet
- }
- nowTime := util.GetTimeMilliseconds()
- oldMapId := this.mapId
- oldMapLevel := this.mapLevel
- var addItemList = map[int32]int32{}
- //baseExp
- addItemList[int32(serverproto.ResType_Res_RoleBaseExp)] = levelCfgData.BaseExp
- //伙伴经验
- addItemList[int32(serverproto.ResType_Res_HeroBaseExp)] = levelCfgData.Parter
- //jobExp
- addItemList[int32(serverproto.ResType_Res_RoleJobExp)] = levelCfgData.JobExp
- //rmb
- addItemList[int32(serverproto.ResType_Res_Rmb)] = levelCfgData.Gold
- //通关免费充值额度
- addItemList[int32(serverproto.ResType_Res_CreditRecharge)] = levelCfgData.FreeInvest
- //cash//做活动时间判定,活动时间内才给
- if !this.role.FuncDisable() {
- if ok := CheckHDItemAdd(int32(serverproto.ResType_Res_CashTicket), this.role); ok && (levelCfgData.Cash != 0) {
- addItemList[int32(serverproto.ResType_Res_CashTicket)] = levelCfgData.Cash
- }
- }
- //coin
- addItemList[int32(serverproto.ResType_Res_Coin)] = levelCfgData.Zeny
- dropId := this.genDropId(model.LevelDropBossDataList, levelId) //放到income中领取
- for idx := 0; idx < len(dropId); idx++ {
- this.DropProcess(addItemList, dropId[idx])
- }
- this.role.AddItemList(addItemList, AddFrom_Battle, true)
- //Drop处理//放到预处理中通过income的方式来获取奖励
- /*
- var bossRewardList = map[int32]int32{}
- dropId := this.genDropId(model.LevelDropBossDataList, levelId) //放到income中领取
- this.dropProcess(bossRewardList, dropId)
- this.role.GetRoleBase().AddBossReward(bossRewardList)
- */
- //地图处理
- _, ok1 := serverproto.LevelCfgLoader[levelId+1]
- if !ok1 {
- nextLevelId := this.getLevelId(this.mapId+1, 1)
- _, ok2 := serverproto.LevelCfgLoader[nextLevelId]
- if !ok2 {
- util.WarnF("uid=%v BossReward next level cfg data not found!!!", this.role.GetUUid())
- } else {
- util.InfoF("uid=%v BossReward to next mapId=%v level=%v", this.role.GetUUid(), this.mapId+1, 1)
- this.mapId++
- this.mapLevel = 1
- this.mapLevelTime = nowTime
- this.SetDirty(true)
- //修改地图通关排名(需要通关该关卡)
- this.addMapRank(1, oldMapId, oldMapLevel, challengeTime, recordTimeStamp)
- this.changeBattleDataNtf()
- }
- } else {
- this.mapLevel++
- this.mapLevelTime = nowTime
- this.SetDirty(true)
- //修改地图通关排名(需要通关该关卡)
- this.addMapRank(1, oldMapId, oldMapLevel, challengeTime, recordTimeStamp)
- util.InfoF("uid=%v BossReward to next mapId=%v level=%v", this.role.GetUUid(), this.mapId, this.mapLevel)
- this.changeBattleDataNtf()
- }
- //回复客户端用户显示
- ackMsg := &serverproto.SCPlayerBossRewardAck{
- Error: int32(serverproto.ErrorCode_ERROR_OK),
- }
- for key, value := range addItemList {
- if key == 40 { //代金券不发送客户端
- continue
- }
- ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
- Key: key,
- Value: value,
- })
- }
- this.role.ReplayGate(ackMsg, true)
- //this.lastChallengeTime = util.GetTimeSeconds()
- this.battleBossGapTime = int64(levelCfgData.FightCD)
- if levelCfgData.GuildActive != 0 {
- this.role.roleGuild.AddGuildActivity(levelCfgData.GuildActive)
- }
- this.OnRushMapScoreChange(levelCfgData.MapScore, 0)
- util.DebugF("uid=%v dropList=%v", this.role.GetUUid(), addItemList)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) bossRewardCheck(challengeTime uint32, mapId, mapLevel uint32) serverproto.ErrorCode {
- if !this.isChallengeBegin {
- return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_CD_TIME
- }
- this.isChallengeBegin = false
- //发送的关卡ID不合法(重发协议)
- if mapId != this.mapId || this.mapLevel != mapLevel {
- util.InfoF("uid=%v bossRewardCheck mapId=%v level=%v invalid", this.role.GetUUid(), mapId, mapLevel)
- return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_INVALID
- }
- deltaTime := (util.GetTimeMilliseconds() - this.mapLevelTime) / 1000
- //时间判断 CloseDown
- levelId := this.getLevelId(this.mapId, this.mapLevel)
- levelCfgData, ok := serverproto.LevelCfgLoader[levelId]
- if !ok {
- return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_DATA_NOT_FOUND
- }
- tmpStrList := strings.Split(levelCfgData.CloseDown, ";")
- if len(tmpStrList) >= 2 {
- tmpChallengeTime, _ := model.Str2Num(tmpStrList[0])
- tmpRecharge, _ := model.Str2Num(tmpStrList[1])
- //1 在对应关卡或者爬塔层的停留时间≥60分钟时,不会触发判定外挂机制
- //2 玩家战力≥2.5*最低通关战力时,不会触发判定机制
- fightCheck := uint64(levelCfgData.FightCheck) * 25 / 10
- if tmpChallengeTime > 0 && deltaTime < 60*60 && this.role.roleBattleAttr.curTotalFightPower < uint32(fightCheck) {
- if int(this.role.GetTotalRecharge()) < tmpRecharge && challengeTime < uint32(tmpChallengeTime) {
- this.role.GetRoleStatistic().RecordCheatData(CheatType_NormalLevel)
- return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_CD_TIME
- }
- }
- }
- //战斗力校验
- return this.mapFightCheck()
- }
- func (this *RoleBattle) mapFightCheck() serverproto.ErrorCode {
- //战斗力校验
- levelId := this.getLevelId(this.mapId, this.mapLevel)
- levelCfgData, ok := serverproto.LevelCfgLoader[levelId]
- if !ok {
- return serverproto.ErrorCode_ERROR_BATTLE_LEVEL_DATA_NOT_FOUND
- }
- curTotalFightPower := this.role.roleBattleAttr.curTotalFightPower
- if curTotalFightPower > 0 && curTotalFightPower < uint32(levelCfgData.FightCheck) {
- //if this.role.GetRoleFightPower() != nil && this.role.GetRoleFightPower().TotalFightPower < uint64(levelCfgData.FightCheck) {
- util.ErrorF("uid=%v bossRewardCheck failed levelId=%v FightCheck=%v > CurFight=%v", this.role.GetUUid(), levelId, levelCfgData.FightCheck, curTotalFightPower)
- return serverproto.ErrorCode_ERROR_FIGHT_CHECK
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) checkMapLevelChallenge(levelCfgData *serverproto.LevelCfg) serverproto.ErrorCode {
- if this.role.GetRoleLevel() < levelCfgData.FightLv {
- return serverproto.ErrorCode_ERROR_ROLE_LEVEL_NOT_ENOUGH
- }
- //job经验限制处理
- jobCfg, ok := serverproto.JobCfgLoader[this.role.GetRoleBase().RoleData().HeroData.ConfigId]
- if !ok || this.role.GetJobLevel() >= jobCfg.MaxJobLv {
- return serverproto.ErrorCode_ERROR_HERO_MAX_JOB_STAGE
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) genDropId(convertData map[int32]*model.ConvertDropData, levelId int32) []int32 {
- var retDropIdList []int32
- dropData, ok := convertData[levelId]
- if !ok {
- util.ErrorF("uid=%v genDropId level drop data not found levelId=%v", this.role.GetUUid(), levelId)
- return retDropIdList
- }
- for _, data := range dropData.DropList {
- //万分比随机
- dropRate := rand.Int31n(10000)
- if data.Weight >= dropRate {
- retDropIdList = append(retDropIdList, data.Key)
- }
- }
- return retDropIdList
- }
- func (this *RoleBattle) genHDDropId(convertData map[int32]*model.ConvertDropData, levelId int32) map[int32]int32 {
- retDropIdList := map[int32]int32{}
- dropData, ok := convertData[levelId]
- if !ok {
- util.ErrorF("uid=%v genDropId level drop data not found levelId=%v", this.role.GetUUid(), levelId)
- return retDropIdList
- }
- for _, data := range dropData.DropList {
- //万分比随机
- dropRate := rand.Int31n(10000)
- if data.Weight >= dropRate {
- if !CheckHDItemAdd(data.Key, this.role) {
- continue
- }
- retDropIdList[data.Key] += data.GetValue()
- }
- }
- return retDropIdList
- }
- func (this *RoleBattle) DropProcess(dropList map[int32]int32, dropId int32) {
- model.DropCfgProcess(dropList, dropId)
- }
- func (this *RoleBattle) GetMapRank() {
- nowTime := util.GetTimeSeconds()
- if this.getRankTimeStamp > 0 && (nowTime-this.getRankTimeStamp) < 5 {
- ackMsg := &serverproto.SCGetMapRankAck{
- Error: int32(serverproto.ErrorCode_ERROR_OK),
- SelfRank: this.selfRank,
- TotalRank: this.totalRanks,
- TopPlayerList: append(this.topRankList),
- }
- this.role.ReplayGate(ackMsg, true)
- return
- }
- this.getRankTimeStamp = nowTime
- //重新获取排名
- dbMsg := &serverproto.SSMapLevelChangeReq{}
- this.role.SendRank(dbMsg)
- }
- func (this *RoleBattle) GetQuickBattleReward() {
- //查看是否开启此功能
- var itemList []*serverproto.KeyValueType
- unlockData, globalOk := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Quick_Battle_Unlock)]
- incomeData, incomeOk := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Battle_Income_Time)]
- if !globalOk || !incomeOk || incomeData.IVal <= 0 {
- this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_FAIL), itemList)
- return
- }
- levelId := this.getLevelId(this.mapId, this.mapLevel)
- if levelId <= unlockData.IVal {
- util.InfoF("uid=%v QuickBattle unlock quick battle unlock=%v levelId=%v", this.role.GetUUid(), unlockData.IVal, levelId)
- this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_QUICK_BATTLE_UNLOCKED), itemList) //未解锁
- return
- }
- //检查领取上限
- vipQuickBattle := this.role.GetRoleBase().GetVipData(model.Vip_System_QuickBattle)
- if vipQuickBattle <= 0 {
- vipQuickBattle = 0
- }
- MaxTime := int(model.GlobalQuickBattleTimes + vipQuickBattle)
- if int32(MaxTime) <= this.quickBattle.DayTimes {
- util.InfoF("uid=%v QuickBattle max draw times, DayTimes=%v maxTime=%v", this.role.GetUUid(), this.quickBattle.DayTimes, MaxTime)
- this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_QUICK_BATTLE_MAX_DRAWTIMES), itemList) //最大次数
- return
- }
- //检查领取花费
- incomeCfg, ok := serverproto.QuickBattleCostCfgLoader[this.quickBattle.DayTimes+1]
- if !ok {
- util.InfoF("uid=%v QuickBattleCostCfgLoader not found DayTimes=%v", this.role.GetUUid(), this.quickBattle.DayTimes)
- this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_FAIL), itemList)
- return
- }
- //给奖励
- levelCfgData, levelCfgOk := serverproto.LevelCfgLoader[levelId]
- if !levelCfgOk {
- util.InfoF("uid=%v QuickBattle reward not found levelId=%v", this.role.GetUUid(), levelId)
- this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_FAIL), itemList)
- return
- }
- //给道具CopyData
- var incomeNum = Quick_Battle_Time / incomeData.IVal
- var addItemList = map[int32]int32{}
- //时光助力主角经验提升万分比(特权加成)
- baseExpOl := levelCfgData.BaseExpOl * incomeNum
- baseExpOlFactor := float32(this.role.GetRoleBase().GetVipData(model.Vip_System_QuickBattleBaseExp)) / 10000.0
- baseExpOl = int32(float32(baseExpOl) * (1 + baseExpOlFactor))
- addItemList[int32(serverproto.ResType_Res_RoleBaseExp)] = baseExpOl
- //coin
- addItemList[int32(serverproto.ResType_Res_Coin)] = levelCfgData.ZenyOl * incomeNum
- //伙伴经验
- addItemList[int32(serverproto.ResType_Res_HeroBaseExp)] = levelCfgData.ParterOl * incomeNum
- //Cruise
- addItemList[int32(serverproto.ResType_Res_Cruise)] = levelCfgData.CruiseOl * incomeNum
- //魔魂值
- addItemList[int32(serverproto.ResType_Res_EvilExp)] = levelCfgData.EvilOl * incomeNum
- //Drop处理
- rand.Seed(int64(util.GetTimeMilliseconds()))
- for i := 0; i < int(incomeNum); i++ {
- dropId := this.genDropId(model.LevelDropCommonDataList, levelId)
- for idx := 0; idx < len(dropId); idx++ {
- this.DropProcess(addItemList, dropId[idx])
- }
- }
- //活动奖励掉落赛季
- for idx := 0; idx < int(incomeNum); idx++ {
- hpDropIdList := this.genHDDropId(model.LevelDropHDDataList, levelId)
- for key, val := range hpDropIdList {
- addItemList[key] += val
- }
- }
- for key, value := range addItemList {
- itemList = append(itemList, &serverproto.KeyValueType{
- Key: key,
- Value: value,
- })
- }
- if ret := this.role.CanAddItemList(addItemList); ret != serverproto.ErrorCode_ERROR_OK {
- this.changeQuickBattleNtf(int32(ret), nil)
- return
- }
- if incomeCfg.Cost != 0 {
- var costItemList = map[int32]int32{}
- costItemList[incomeCfg.CostType] = incomeCfg.Cost
- if this.role.CheckResLitNum(costItemList) {
- this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_Quick_Battle})
- } else {
- util.DebugF("uid=%v QuickBattle item not enough DayTimes=%v", this.role.GetUUid(), this.quickBattle.DayTimes)
- this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_QUICK_BATTLE_ITEM_NOT_ENOUGH), itemList) //所需资源不足
- return
- }
- }
- //领取次数自加
- this.quickBattle.DayTimes += 1
- this.quickBattle.DrawTime = uint64(util.GetTimeSeconds())
- this.quickBattle.MaxTimes = int32(MaxTime)
- this.SetDirty(true)
- this.changeBattleDataNtf()
- this.role.AddItemList(addItemList, AddFrom_Quick_Battle, true)
- this.changeQuickBattleNtf(int32(serverproto.ErrorCode_ERROR_OK), itemList)
- this.role.roleTask.AddTypeCnt(serverproto.TaskType_Eve_Use_Quick_Battle, 1)
- TaskMagCheck(this.role, serverproto.TaskType_Role_Quick_Battle_Count, 1)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Use_Quick_Battle, 1)
- }
- //evil
- func (this *RoleBattle) evilDataChangeNtf() {
- ntfMsg := &serverproto.SCEvilChangeNtf{
- EvilInfo: this.evilData,
- }
- this.role.ReplayGate(ntfMsg, true)
- }
- func (this *RoleBattle) CheckEvilBattleCount() {
- vipData := this.role.GetRoleBase().GetVipData(model.Vip_System_Evil)
- if vipData == 0 && this.evilData.TotalCount == 0 {
- return
- }
- bChanged := false
- if vipData == 0 && this.evilData.TotalCount != 0 {
- this.evilData.FreeCount = 0
- this.evilData.TotalCount = 0
- this.evilData.FreeLimit = true
- bChanged = true
- }
- if vipData != 0 && vipData > this.evilData.TotalCount {
- this.evilData.FreeCount += vipData - this.evilData.TotalCount
- this.evilData.TotalCount = vipData
- bChanged = true
- }
- if bChanged == true {
- this.SetDirty(true)
- this.evilDataChangeNtf()
- }
- }
- func (this *RoleBattle) refreshEvilLevel() {
- if data, ok := model.ConvertEvilBossList[this.evilData.EvilLevel]; ok {
- if data.LevelTimes > 0 {
- this.evilData.ChallengeCount++
- if data.LevelTimes <= this.evilData.ChallengeCount {
- if _, ok1 := model.ConvertEvilBossList[this.evilData.EvilLevel+1]; !ok1 {
- this.evilData.ChallengeCount = 0
- this.SetDirty(true)
- return
- }
- this.evilData.EvilLevel++
- this.evilData.ChallengeCount = 0
- this.SetDirty(true)
- //恶魔等级升级获得物品
- this.role.AddItemList(data.LevelReward, AddFrom_Evil, true)
- ntfMsg := &serverproto.SCEvilChangeNtf{
- EvilInfo: this.evilData,
- }
- for key, val := range data.LevelReward {
- ntfMsg.AddItemList = append(ntfMsg.AddItemList, &serverproto.KeyValueType{
- Key: key,
- Value: val,
- })
- }
- this.role.ReplayGate(ntfMsg, true)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Evil_Fight_Lvl, this.evilData.EvilLevel)
- return
- }
- this.SetDirty(true)
- }
- }
- }
- func (this *RoleBattle) getEvilBossInfo(posIdx int32) *serverproto.BattleEvilBossData {
- for idx := 0; idx < len(this.evilData.BossList); idx++ {
- data := this.evilData.BossList[idx]
- if data.PosIdx == posIdx {
- return data
- }
- }
- return nil
- }
- func (this *RoleBattle) randEvilBoss(force bool, bossQualityType int) *serverproto.KeyValueTypeList {
- var evilLevel int32 = 0
- if !force {
- evilLevel = this.evilData.EvilLevel
- }
- convertData, ok := model.ConvertEvilBossList[evilLevel]
- if !ok || len(convertData.MonsterList) <= 0 {
- return nil
- }
- var totalWeight int32 = 0
- var randList []*serverproto.KeyValueType
- for idx := 0; idx < len(convertData.MonsterList); idx++ {
- if bossQualityType > 0 {
- if bossQualityType <= int(convertData.MonsterList[idx].ValueList[2]) {
- totalWeight += convertData.MonsterList[idx].ValueList[3]
- randList = append(randList, &serverproto.KeyValueType{Key: totalWeight, Value: int32(idx)})
- }
- } else {
- totalWeight += convertData.MonsterList[idx].ValueList[3]
- randList = append(randList, &serverproto.KeyValueType{Key: totalWeight, Value: int32(idx)})
- }
- }
- randWeight := rand.Int31n(totalWeight)
- idx := 0
- for ; idx < len(randList); idx++ {
- if randList[idx].Key > randWeight {
- break
- }
- }
- return convertData.MonsterList[int(randList[idx].Value)]
- }
- func (this *RoleBattle) BattleEvilRefresh(bForce bool) (serverproto.ErrorCode, []int32) {
- if len(this.evilData.BossList) <= 0 {
- return this.evilRefresh(true, false, false)
- }
- if bForce {
- vipData := this.role.GetRoleBase().GetVipData(model.Vip_System_Evil)
- if vipData > 0 && this.evilData.FreeCount > 0 {
- this.evilData.FreeCount--
- return this.evilRefresh(true, true, false)
- } else if vipData <= 0 {
- //升级到对应vip等级无限制免费刷新
- return this.evilRefresh(true, true, false)
- } else {
- if !this.role.CheckResLitNum(model.GlobalEvilRefreshConsume) {
- return serverproto.ErrorCode_ERROR_RMB_NOT_ENOUGH, nil
- }
- this.role.DelItemList(model.GlobalEvilRefreshConsume, AddItemST{AddFrom: AddFrom_Evil})
- return this.evilRefresh(true, true, true)
- }
- } else {
- return this.evilRefresh(false, true, false)
- }
- }
- func (this *RoleBattle) evilRefresh(bForce bool, notify bool, bConsume bool) (serverproto.ErrorCode, []int32) {
- nowTime := util.GetTimeMilliseconds()
- //恶魔协会增加刷新保底机制
- //1 绿,2蓝,3紫,4金
- specialBossType := EvilBossType_Blue
- if bConsume {
- specialBossType = EvilBossType_Purple
- }
- if vipData, ok := model.ConvertVipRight[this.role.GetRoleVipLevel()]; ok {
- if right, ok := vipData.VipRight[model.Vip_System_Evil]; ok {
- if right <= 0 {
- specialBossType = EvilBossType_Glod
- }
- }
- }
- if this.role.roleBT != nil {
- var boliLevel int32 = 0
- if this.role.roleBT.boliData != nil {
- boliLevel = this.role.roleBT.boliData.Level
- }
- cfgData, ok := model.ConvertBoliVipData[boliLevel]
- if ok {
- if right, ok := cfgData.VipRight[model.Vip_System_Evil]; ok {
- if right == 0 {
- specialBossType = EvilBossType_Glod
- }
- }
- }
- }
- if this.role.GetRoleRune() != nil && this.role.GetRoleRune().runeBase.IsPassCheck {
- if right, ok := model.ConvertPassCheckData.VipRight[model.Vip_System_Evil]; ok {
- if right == 0 {
- specialBossType = EvilBossType_Glod
- }
- }
- }
- var changeIdx []int32
- rand.Seed(int64(nowTime))
- specialBossTypeIdx := rand.Intn(MAX_BATTLEBOSS_NUM) + 1
- //第一次需要刷新出特殊的Boss
- for idx := 1; idx <= MAX_BATTLEBOSS_NUM; idx++ {
- evilBoss := this.getEvilBossInfo(int32(idx))
- if evilBoss == nil {
- evilBoss = &serverproto.BattleEvilBossData{
- PosIdx: int32(idx),
- ExpireTime: 0,
- }
- var tmpBossInfo *serverproto.KeyValueTypeList = nil
- if idx == 1 {
- //第一次需要刷新出特殊的Boss
- tmpBossInfo = this.randEvilBoss(true, 0)
- if specialBossTypeIdx == idx {
- specialBossTypeIdx++
- }
- } else {
- if idx == specialBossTypeIdx {
- tmpBossInfo = this.randEvilBoss(false, specialBossType)
- } else {
- tmpBossInfo = this.randEvilBoss(false, 0)
- }
- }
- if tmpBossInfo != nil {
- evilBoss.BossId = tmpBossInfo.Key
- evilBoss.RewardEvilExp = tmpBossInfo.ValueList[0]
- evilBoss.RefreshTime = tmpBossInfo.ValueList[1]
- evilBoss.Quality = tmpBossInfo.ValueList[2]
- this.evilData.BossList = append(this.evilData.BossList, evilBoss)
- changeIdx = append(changeIdx, int32(idx))
- } else {
- util.ErrorF("uid=%v evi refresh error!!!", this.role.GetUUid())
- }
- } else {
- if bForce {
- var tmpBossInfo *serverproto.KeyValueTypeList = nil
- if idx == specialBossTypeIdx {
- tmpBossInfo = this.randEvilBoss(false, specialBossType)
- } else {
- tmpBossInfo = this.randEvilBoss(false, 0)
- }
- if tmpBossInfo != nil {
- evilBoss.BossId = tmpBossInfo.Key
- evilBoss.ExpireTime = 0
- evilBoss.RefreshTime = tmpBossInfo.ValueList[1]
- evilBoss.RewardEvilExp = tmpBossInfo.ValueList[0]
- evilBoss.Quality = tmpBossInfo.ValueList[2]
- changeIdx = append(changeIdx, int32(idx))
- } else {
- util.ErrorF("uid=%v evi refresh error!!!", this.role.GetUUid())
- }
- } else if evilBoss.ExpireTime < nowTime && evilBoss.ExpireTime > 0 {
- var tmpBossInfo *serverproto.KeyValueTypeList = nil
- if idx == specialBossTypeIdx {
- tmpBossInfo = this.randEvilBoss(false, specialBossType)
- } else {
- tmpBossInfo = this.randEvilBoss(false, 0)
- }
- if tmpBossInfo != nil {
- evilBoss.BossId = tmpBossInfo.Key
- evilBoss.ExpireTime = 0
- evilBoss.RefreshTime = tmpBossInfo.ValueList[1]
- evilBoss.RewardEvilExp = tmpBossInfo.ValueList[0]
- evilBoss.Quality = tmpBossInfo.ValueList[2]
- changeIdx = append(changeIdx, int32(idx))
- } else {
- util.ErrorF("uid=%v evi refresh error!!!", this.role.GetUUid())
- }
- }
- }
- }
- if len(changeIdx) > 0 {
- this.SetDirty(true)
- if notify {
- this.evilDataChangeNtf()
- }
- }
- //util.DebugF("uid=%v nowTime=%v freeCount=%v", this.role.GetUUid(), nowTime, this.evilData.FreeCount)
- return serverproto.ErrorCode_ERROR_OK, changeIdx
- }
- func (this *RoleBattle) BattleEvilChallenge(posIdx int32) (serverproto.ErrorCode, int32) {
- bossInfo := this.getEvilBossInfo(posIdx)
- if bossInfo == nil {
- return serverproto.ErrorCode_ERROR_BATTLE_EVIL_BOSS_NOT_FIND, 0
- }
- nowTime := util.GetTimeMilliseconds()
- if bossInfo.ExpireTime == 0 && bossInfo.BossId != 0 {
- var costItemList = map[int32]int32{}
- costItemList[int32(serverproto.ResType_Res_EvilExp)] = model.GlobalEviChallengeCost
- if !this.role.CheckResLitNum(costItemList) {
- return serverproto.ErrorCode_ERROR_BATTLE_EVIL_REFRESH_COST_NOT_ENOUGH, 0
- }
- this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_Evil})
- var addItemList = map[int32]int32{}
- addItemList[int32(serverproto.ResType_Res_Cruise)] = bossInfo.RewardEvilExp
- this.role.AddItemList(addItemList, AddFrom_Evil, true)
- bossInfo.ExpireTime = nowTime + uint64(bossInfo.RefreshTime)*1000
- bFind := false
- for idx := 0; idx < len(this.evilData.QualityChallengeCount); idx++ {
- tmpData := this.evilData.QualityChallengeCount[idx]
- if tmpData.Key == bossInfo.Quality {
- this.evilData.QualityChallengeCount[idx].Value++
- bFind = true
- break
- }
- }
- if !bFind {
- this.evilData.QualityChallengeCount = append(this.evilData.QualityChallengeCount,
- &serverproto.KeyValueType{Key: bossInfo.Quality, Value: 1})
- }
- this.refreshEvilLevel()
- this.SetDirty(true)
- this.evilDataChangeNtf()
- //Task
- TaskMagCheck(this.role, serverproto.TaskType_Evil_Fight_Count, 1)
- TaskMagCheck(this.role, serverproto.TaskType_Evil_Battle_Count_Accu, bossInfo.Quality)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Accu_count, bossInfo.Quality)
- return serverproto.ErrorCode_ERROR_OK, bossInfo.RewardEvilExp
- }
- return serverproto.ErrorCode_ERROR_BATTLE_EVIL_BOSS_DIED, 0
- }
- func (this *RoleBattle) GetQualityBossChallengeCount(quality int32) int32 {
- var ret int32 = 0
- for idx := 0; idx < len(this.evilData.QualityChallengeCount); idx++ {
- tmpData := this.evilData.QualityChallengeCount[idx]
- if tmpData.Key >= quality {
- ret += tmpData.Value
- }
- }
- return ret
- }
- func (this *RoleBattle) GetEvilLvl() int32 {
- return this.evilData.EvilLevel
- }
- //expedition
- func (this *RoleBattle) expeditionChangeNtf(dayReset bool) {
- ntfMsg := &serverproto.SCExpeditionChangeNtf{
- ExpeditionInfo: this.expeditionData,
- DayReset: dayReset,
- }
- this.role.ReplayGate(ntfMsg, true)
- }
- func (this *RoleBattle) dailyResetExpedition(notify bool) {
- //奖励通过邮件发送
- var addItemList = map[int32]int32{}
- for idx := 0; idx < len(this.expeditionData.FinishExpeditionList); idx++ {
- tmpExpeditionType := this.expeditionData.FinishExpeditionList[idx]
- convertCfgData, ok := model.ConvertExpeditionDataList[tmpExpeditionType]
- if !ok {
- continue
- }
- this.expeditionRewardAll(convertCfgData, addItemList)
- }
- convertCfgData, ok := model.ConvertExpeditionDataList[this.expeditionData.CurExpeditionType]
- if ok {
- this.expeditionRewardAll(convertCfgData, addItemList)
- }
- if len(this.expeditionData.FinishExpeditionList) > 0 {
- this.expeditionData.FinishExpeditionList = this.expeditionData.FinishExpeditionList[:0]
- this.SetDirty(true)
- }
- if len(this.expeditionData.RewardStateList) > 0 {
- this.expeditionData.RewardStateList = this.expeditionData.RewardStateList[:0]
- this.SetDirty(true)
- }
- if len(addItemList) > 0 {
- this.role.GetRoleMail().AddMail(model.GlobalMailIdExpeditionReward, serverproto.MailType_MailType_Expedition,
- addItemList, nil, "", "")
- }
- //重置数据
- bReset := false
- if this.expeditionData.ChallengeNum != model.GlobalExpeditionChallengeNum {
- this.expeditionData.ChallengeNum = model.GlobalExpeditionChallengeNum
- this.SetDirty(true)
- bReset = true
- }
- if this.expeditionData.CurExpeditionType > 0 || this.expeditionData.CurBattleLevel > 0 ||
- this.expeditionData.CurExpeditionScore > 0 {
- this.expeditionData.CurExpeditionType = 0
- this.expeditionData.CurBattleLevel = 0
- this.expeditionData.CurExpeditionScore = 0
- this.SetDirty(true)
- bReset = true
- }
- if len(this.expeditionData.BossList) > 0 || len(this.expeditionData.BattleBuffList) > 0 ||
- len(this.expeditionData.BattleHeroHpList) > 0 || len(this.expeditionData.BattleSelectBuffList) > 0 {
- this.expeditionData.BossList = this.expeditionData.BossList[:0]
- this.expeditionData.BattleBuffList = this.expeditionData.BattleBuffList[:0]
- this.expeditionData.BattleSelectBuffList = this.expeditionData.BattleSelectBuffList[:0]
- this.expeditionData.BattleHeroHpList = this.expeditionData.BattleHeroHpList[:0]
- this.SetDirty(true)
- bReset = true
- }
- if this.expeditionData.AssistNum.Value > 0 || this.expeditionData.BeAssistNum.Value > 0 ||
- this.expeditionData.BattleIdx > 0 || this.expeditionData.AssistState {
- this.expeditionData.AssistNum.Value = 0
- this.expeditionData.BeAssistNum.Value = 0
- this.expeditionData.AssistState = false
- this.expeditionData.AssistTimeStamp = 0
- this.expeditionData.BattleIdx = 0
- this.SetDirty(true)
- bReset = true
- }
- if this.expeditionData.ExpeditionTypeReward > 0 {
- this.expeditionData.ExpeditionTypeReward = 0
- this.SetDirty(true)
- bReset = true
- }
- if notify && (bReset || len(addItemList) > 0) {
- this.expeditionChangeNtf(true)
- }
- }
- func (this *RoleBattle) ExpeditionPre(expeditionType int32) serverproto.ErrorCode {
- convertData, ok := model.ConvertExpeditionDataList[expeditionType]
- if !ok {
- return serverproto.ErrorCode_ERROR_EXPEDITION_CHALLENGE
- }
- //是否已经解锁
- if this.expeditionData.ExpeditionType < expeditionType {
- return serverproto.ErrorCode_ERROR_EXPEDITION_TYPE_UNLOCK
- }
- if this.expeditionData.CurExpeditionType != 0 {
- if this.expeditionData.CurExpeditionType != expeditionType {
- return serverproto.ErrorCode_ERROR_EXPEDITION_CHALLENGE
- }
- } else {
- //当前是否已经挑战完该区域id地图
- bFind := false
- for idx := 0; idx < len(this.expeditionData.FinishExpeditionList); idx++ {
- if this.expeditionData.FinishExpeditionList[idx] == expeditionType {
- bFind = true
- }
- }
- if bFind {
- return serverproto.ErrorCode_ERROR_EXPEDITION_CHALLENGE_HAS
- }
- }
- //扣除次数,并生成第一关boss数据列表
- if this.expeditionData.CurExpeditionType == 0 {
- if this.expeditionData.ChallengeNum <= 0 {
- return serverproto.ErrorCode_ERROR_EXPEDITION_CHALLENGE_NO_NUM
- }
- this.expeditionData.ChallengeNum--
- this.expeditionData.CurExpeditionType = expeditionType
- this.expeditionData.CurExpeditionScore = 0
- this.expeditionData.CurBattleLevel = 1
- this.expeditionData.BattleSelectBuffList = this.expeditionData.BattleSelectBuffList[:0]
- this.expeditionData.BattleBuffList = this.expeditionData.BattleBuffList[:0]
- this.SetDirty(true)
- this.expeditionBuffList.Clear()
- this.randExpeditionBoss(convertData)
- this.expeditionChangeNtf(false)
- TaskMagCheck(this.role, serverproto.TaskType_Expedition_Challenge_Count, 1)
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) ExpeditionChallenge(expeditionType, battleLevel int32, heroInfoList []*serverproto.BattleExpeditionActor,
- bossChangeHpList []*serverproto.BattleExpeditionActor, battleTime int32, bossIdx int32, flag int32) (serverproto.ErrorCode, []int32, bool) {
- if expeditionType != this.expeditionData.CurExpeditionType || battleLevel != this.expeditionData.CurBattleLevel {
- util.InfoF("uid=%v ExpeditionChallenge cheat data for client type=%v level=%v", this.role.GetUUid(), expeditionType, battleLevel)
- return serverproto.ErrorCode_ERROR_EXPEDITION_CHALLENGE, nil, false
- }
- //cfgData check
- convertCfgData, ok := model.ConvertExpeditionDataList[expeditionType]
- if !ok {
- util.DebugF("uid=%v ExpeditionChallenge expeditionType=%v invalid", this.role.GetUUid(), expeditionType)
- return serverproto.ErrorCode_ERROR_FAIL, nil, false
- }
- levelCfgData, ok := convertCfgData.LevelInfo[battleLevel]
- if !ok {
- util.DebugF("uid=%v ExpeditionChallenge battleLevel=%v invalid", this.role.GetUUid(), battleLevel)
- return serverproto.ErrorCode_ERROR_FAIL, nil, false
- }
- if levelCfgData.MaxFightingTime < battleTime && battleTime > 0 {
- util.DebugF("uid=%v ExpeditionChallenge battleTime=%v invalid", this.role.GetUUid(), battleTime)
- return serverproto.ErrorCode_ERROR_CHALLENGE_TIME_LIMIT, nil, false
- }
- if bossIdx <= 0 || bossIdx > int32(len(this.expeditionData.BossList)) {
- util.DebugF("uid=%v ExpeditionChallenge bossIdx=%v invalid", this.role.GetUUid(), battleLevel)
- return serverproto.ErrorCode_ERROR_FAIL, nil, false
- }
- //flag 1开始 2战斗过程 3战斗结束 4胜利方式返回给客户端
- //判断之前战斗胜利的buff是否已经选择
- if flag == 1 {
- if len(this.expeditionData.BattleSelectBuffList) > 0 {
- return serverproto.ErrorCode_ERROR_OK, this.expeditionData.BattleSelectBuffList, false
- }
- }
- //挑战英雄是否合法
- ret := this.isCurBattleHeroDied(heroInfoList, flag)
- if ret != serverproto.ErrorCode_ERROR_OK {
- return ret, nil, false
- }
- //boss血量检查
- //客户端
- var accuBossHpChange int32 = 0
- var accuBossSpChange int32 = 0
- for idx := 0; idx < len(bossChangeHpList); idx++ {
- accuBossHpChange += bossChangeHpList[idx].Hp
- accuBossSpChange += bossChangeHpList[idx].Sp
- }
- //判断是否挑战同一个boss
- curBattleBossIdx := this.findBattleBossIdx()
- if curBattleBossIdx != 0 && curBattleBossIdx != bossIdx {
- bossIdx = curBattleBossIdx
- util.DebugF("uid=%v ExpeditionChallenge curBossIdx=%v bossIdx=%v", this.role.GetUUid(), curBattleBossIdx, bossIdx)
- //return serverproto.ErrorCode_ERROR_EXPEDITION_NOT_SAME_BOSS, nil, false
- }
- if bossIdx <= 0 {
- return serverproto.ErrorCode_ERROR_EXPEDITION_CHALLENGE, nil, false
- }
- //战斗开始时判断boss是否已经死亡
- if flag == 1 {
- this.expeditionData.BattleIdx = bossIdx
- this.SetDirty(true)
- if this.expeditionData.BossList[bossIdx-1].Hp <= 0 {
- //数据不正确,重置boss数据
- this.randExpeditionBoss(convertCfgData)
- this.expeditionChangeNtf(false)
- util.DebugF("uid=%v ExpeditionChallenge boss data invalid", this.role.GetUUid())
- return serverproto.ErrorCode_ERROR_EXPEDITION_NOT_SAME_BOSS, nil, false
- }
- }
- for idx := 0; idx < len(heroInfoList); idx++ {
- bFind := false
- for k := 0; k < len(this.expeditionData.BattleHeroHpList); k++ {
- if this.expeditionData.BattleHeroHpList[k].Id == heroInfoList[idx].Id {
- bFind = true
- if this.expeditionData.BattleHeroHpList[k].Hp <= 0 {
- break
- }
- this.expeditionData.BattleHeroHpList[k].Hp = heroInfoList[idx].Hp
- if this.expeditionData.BattleHeroHpList[k].Hp > 100 {
- this.expeditionData.BattleHeroHpList[k].Hp = 100
- }
- if this.expeditionData.BattleHeroHpList[k].Hp < 0 {
- this.expeditionData.BattleHeroHpList[k].Hp = 0
- }
- this.expeditionData.BattleHeroHpList[k].Sp = heroInfoList[idx].Sp
- if this.expeditionData.BattleHeroHpList[k].Sp > 100 {
- this.expeditionData.BattleHeroHpList[k].Sp = 100
- }
- if this.expeditionData.BattleHeroHpList[k].Sp < 0 {
- this.expeditionData.BattleHeroHpList[k].Sp = 0
- }
- break
- }
- }
- if !bFind {
- //万分比
- if heroInfoList[idx].Hp > 100 {
- heroInfoList[idx].Hp = 100
- }
- if heroInfoList[idx].Sp > 100 {
- heroInfoList[idx].Sp = 100
- }
- this.expeditionData.BattleHeroHpList = append(this.expeditionData.BattleHeroHpList, heroInfoList[idx])
- }
- }
- bFinish := false
- tmpBossInfo := this.expeditionData.BossList[bossIdx-1]
- tmpBossInfo.Hp += accuBossHpChange
- tmpBossInfo.Sp += accuBossSpChange
- if tmpBossInfo.Sp < 0 {
- tmpBossInfo.Sp = 0
- }
- //隔天重置,战斗还在进行中,结束时数据已经被清空
- oldBattleLevel := this.expeditionData.CurBattleLevel
- if tmpBossInfo.Hp <= 0 && flag == 3 && this.expeditionData.BattleIdx > 0 && this.expeditionData.CurExpeditionType > 0 {
- if this.expeditionData.CurBattleLevel >= convertCfgData.LevelNum {
- this.expeditionData.FinishExpeditionList = append(this.expeditionData.FinishExpeditionList, this.expeditionData.CurExpeditionType)
- if this.expeditionData.ExpeditionType <= this.expeditionData.CurExpeditionType {
- _, ok1 := model.ConvertExpeditionDataList[this.expeditionData.ExpeditionType+1]
- if ok1 {
- this.expeditionData.ChallengeNum += convertCfgData.LevelUnlockAddNum
- this.expeditionData.ExpeditionType++
- }
- }
- this.expeditionData.TotalExpeditionNum++
- //获取勇士积分
- this.GenWarriorScore(levelCfgData)
- this.FinishExpeditionTypeReset()
- //Task
- TaskMagCheck(this.role, serverproto.TaskType_Expedition_Battle_Count, 1)
- TaskMagCheck(this.role, serverproto.TaskType_Eve_Expedition_Battle_Type, 1)
- } else {
- //获取buff列表
- this.randBattleBuffList(levelCfgData)
- //获取勇士积分
- this.GenWarriorScore(levelCfgData)
- //boss死亡刷新下一关boss列表
- this.expeditionData.CurBattleLevel++
- this.expeditionData.BattleIdx = 0
- this.randExpeditionBoss(convertCfgData)
- }
- bFinish = true
- util.InfoF("uid=%v ExpeditionChallenge finish=%v buff=%v oldBattleLevel=%v bossid=%v nextlevelbosslist=%v", this.role.GetUUid(), bFinish,
- this.expeditionData.BattleSelectBuffList, oldBattleLevel, tmpBossInfo.Id, this.expeditionData.BossList)
- }
- this.SetDirty(true)
- this.expeditionChangeNtf(false)
- return serverproto.ErrorCode_ERROR_OK, this.expeditionData.BattleSelectBuffList, bFinish
- }
- func (this *RoleBattle) GetExpeditionTotalFinishNum() int32 {
- return this.expeditionData.TotalExpeditionNum
- }
- func (this *RoleBattle) GetExpeditionCur() int32 {
- if this.expeditionData.ExpeditionType > 0 {
- return this.expeditionData.ExpeditionType - 1
- }
- return this.expeditionData.ExpeditionType
- }
- func (this *RoleBattle) FinishExpeditionTypeReset() {
- convertCfgData, ok := model.ConvertExpeditionDataList[this.expeditionData.CurExpeditionType]
- if ok {
- var addItemList = map[int32]int32{}
- this.expeditionRewardAll(convertCfgData, addItemList)
- if len(addItemList) > 0 {
- this.role.GetRoleMail().AddMail(model.GlobalMailIdExpeditionReward, serverproto.MailType_MailType_Expedition,
- addItemList, nil, "", "")
- }
- }
- this.expeditionData.CurExpeditionType = 0
- this.expeditionData.CurBattleLevel = 1
- this.expeditionData.BattleIdx = 0
- this.expeditionData.AssistState = false
- this.expeditionData.AssistTimeStamp = 0
- this.expeditionData.BossList = this.expeditionData.BossList[:0]
- this.expeditionData.BattleBuffList = this.expeditionData.BattleBuffList[:0]
- this.expeditionData.BattleSelectBuffList = this.expeditionData.BattleSelectBuffList[:0]
- this.expeditionData.BattleHeroHpList = this.expeditionData.BattleHeroHpList[:0]
- this.expeditionBuffList.Clear()
- this.SetDirty(true)
- }
- func (this *RoleBattle) addExpeditionRankScore(addScore uint32) bool {
- this.expeditionData.CurExpeditionScore += addScore
- if this.expeditionData.CurExpeditionScoreMax < this.expeditionData.CurExpeditionScore {
- this.expeditionData.CurExpeditionScoreMax = this.expeditionData.CurExpeditionScore
- ssMsg := &serverproto.SSExpeditionUpdateScoreRankNtf{
- CurScore: this.expeditionData.CurExpeditionScoreMax,
- }
- this.role.SendRank(ssMsg)
- return true
- }
- return false
- }
- func (this *RoleBattle) ExpeditionBuffSelect(selectBuf int32) serverproto.ErrorCode {
- bFind := false
- for idx := 0; idx < len(this.expeditionData.BattleSelectBuffList); idx++ {
- if this.expeditionData.BattleSelectBuffList[idx] == selectBuf {
- bFind = true
- break
- }
- }
- if !bFind {
- return serverproto.ErrorCode_ERROR_EXPEDITION_BUFF_NOT_EXIST
- }
- this.expeditionData.BattleIdx = 0
- this.expeditionData.BattleBuffList = append(this.expeditionData.BattleBuffList, selectBuf)
- this.expeditionBuffList.Add(selectBuf)
- this.expeditionData.BattleSelectBuffList = this.expeditionData.BattleSelectBuffList[:0]
- this.SetDirty(true)
- //选择buff添加勇士积分
- if cfgData, ok := serverproto.ExpeditionBuffCfgLoader[selectBuf]; ok {
- tmpScore := float32(cfgData.WarriorScore)
- convertData, ok1 := model.ConvertExpeditionDataList[this.expeditionData.CurExpeditionType]
- if ok1 {
- tmpScore *= convertData.LevelCoefficient
- }
- this.addExpeditionRankScore(uint32(tmpScore))
- }
- this.expeditionChangeNtf(false)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) ExpeditionReward(expeditionType, boxIdx int32, ackMsg *serverproto.SCExpeditionRewardAck) serverproto.ErrorCode {
- if expeditionType <= 0 || boxIdx < 0 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- convertCfgData, ok := model.ConvertExpeditionDataList[expeditionType]
- if !ok {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- var addItemList = map[int32]int32{}
- //一键领取
- if boxIdx <= 0 {
- retReward := this.expeditionRewardAll(convertCfgData, addItemList)
- if retReward != serverproto.ErrorCode_ERROR_OK {
- return retReward
- }
- } else {
- retReward := this.expeditionRewardBox(convertCfgData, boxIdx, addItemList)
- if retReward != serverproto.ErrorCode_ERROR_OK {
- return retReward
- }
- }
- this.expeditionChangeNtf(false)
- this.role.AddItemList(addItemList, AddFrom_Expedition, true)
- for key, val := range addItemList {
- ackMsg.RewardItemList = append(ackMsg.RewardItemList, &serverproto.KeyValueType{Key: key, Value: val})
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) ExpeditionBattleHero(battleHeroList []int32) serverproto.ErrorCode {
- if len(battleHeroList) > SLOT_NUM {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- heroIdList := set.New(set.NonThreadSafe)
- for idx := 0; idx < len(battleHeroList); idx++ {
- if battleHeroList[idx] == 0 {
- continue
- }
- if heroIdList.Has(battleHeroList[idx]) {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- heroData := this.role.GetRoleHero().GetHero(battleHeroList[idx])
- if heroData == nil {
- return serverproto.ErrorCode_ERROR_HERO_NO_FOUND
- }
- heroIdList.Add(battleHeroList[idx])
- }
- this.expeditionData.BattleHeroList = battleHeroList
- this.SetDirty(true)
- this.expeditionChangeNtf(false)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) ExpeditionCallForHelp(assistHelpUid uint64) serverproto.ErrorCode {
- if this.role.GetUUid() == assistHelpUid {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- //已经被救助的次数达到上限,无法发起求助请求
- if this.expeditionData.BeAssistNum != nil &&
- this.expeditionData.BeAssistNum.Key <= this.expeditionData.BeAssistNum.Value {
- return serverproto.ErrorCode_ERROR_EXPEDITION_CALLFORHELP_LIMIT
- }
- //是否有英雄死亡,可以发起求助操作
- bFind := false
- for idx := 0; idx < len(this.expeditionData.BattleHeroHpList); idx++ {
- if this.expeditionData.BattleHeroHpList[idx].Hp <= 0 {
- bFind = true
- }
- }
- if !bFind {
- return serverproto.ErrorCode_ERROR_EXPEDITION_CALLFROHELP_NO_HERO
- }
- nowTime := util.GetTimeMilliseconds()
- // 发起公会求助
- if assistHelpUid <= 0 {
- //cd time
- if nowTime < this.expeditionData.AssistGuildEndTime {
- return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_GUILD_CD
- }
- if this.role.GetRoleGuildId() <= 0 {
- return serverproto.ErrorCode_ERROR_EXPEDITION_CALLFROHELP_NO_GUILD
- }
- this.expeditionData.AssistGuildEndTime = nowTime + model.GlobalExpeditionGuildCallForHelpCDTime
- this.expeditionData.AssistState = true
- if this.expeditionData.AssistTimeStamp <= 0 {
- this.expeditionData.AssistTimeStamp = nowTime
- }
- this.SetDirty(true)
- this.expeditionChangeNtf(false)
- chatMsg := &serverproto.CSChatMessageReq{
- TargetId: assistHelpUid,
- Type: int32(serverproto.ChatMessageType_CMT_GUILD),
- Message: &serverproto.ChatMessageInfo{
- SendTime: nowTime,
- SubType: int32(serverproto.ChatMessageSubType_CMT_SUB_TYPE_Expedition),
- },
- }
- this.role.GetRoleChat().SendMsg(assistHelpUid,
- int32(serverproto.ChatMessageType_CMT_GUILD), chatMsg, true)
- } else {
- bFind := false
- //发起好友求助
- friendList := this.role.GetRoleSocial().GetFriendList()
- for idx := 0; idx < len(friendList); idx++ {
- if friendList[idx] == assistHelpUid {
- bFind = true
- this.expeditionData.AssistState = true
- if this.expeditionData.AssistTimeStamp <= 0 {
- this.expeditionData.AssistTimeStamp = nowTime
- }
- this.SetDirty(true)
- this.expeditionChangeNtf(false)
- chatMsg := &serverproto.CSChatMessageReq{
- TargetId: assistHelpUid,
- Type: int32(serverproto.ChatMessageType_CMT_PERSONAL),
- Message: &serverproto.ChatMessageInfo{
- SendTime: nowTime,
- SubType: int32(serverproto.ChatMessageSubType_CMT_SUB_TYPE_Expedition),
- },
- }
- this.role.GetRoleChat().SendMsg(assistHelpUid,
- int32(serverproto.ChatMessageType_CMT_PERSONAL), chatMsg, true)
- break
- }
- }
- if !bFind {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- }
- //Task
- TaskMagCheck(this.role, serverproto.TaskType_Expedition_CallHelp_Count, 1)
- //玩家发起救助时删除过期日志
- this.checkBeHelpUidListExpire()
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) ExpeditionHelp(beHelpedUid uint64, msgType int32, helpMsgSendTime uint64) serverproto.ErrorCode {
- if this.role.GetUUid() == beHelpedUid || beHelpedUid <= 0 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if this.expeditionData.AssistNum != nil &&
- this.expeditionData.AssistNum.Key <= this.expeditionData.AssistNum.Value {
- return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_LIMIT
- }
- if msgType == int32(serverproto.ChatMessageType_CMT_PERSONAL) {
- //判断是否是好友,
- bFind := false
- friendList := this.role.GetRoleSocial().GetFriendList()
- for idx := 0; idx < len(friendList); idx++ {
- if friendList[idx] == beHelpedUid {
- bFind = true
- break
- }
- }
- if !bFind {
- return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_NOT_FRIEND
- }
- } else if msgType == int32(serverproto.ChatMessageType_CMT_GUILD) {
- //判断是否是同一公会
- if this.role.GetRoleGuildId() <= 0 {
- return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_NOT_GUILD
- }
- }
- //发起救助操作
- ssMsg := &serverproto.SSExpeditionHelpReq{
- BeHelpedUid: beHelpedUid,
- FromUid: &serverproto.CommonPlayerBriefInfo{},
- HelpMsgSendTime: helpMsgSendTime,
- }
- this.role.GetRoleBriefInfo(ssMsg.FromUid)
- this.role.SendSocial(ssMsg)
- return serverproto.ErrorCode_ERROR_OK
- }
- //from social
- //被救助玩家离线,返回发起救助玩家并进行db操作
- func (this *RoleBattle) OnExpeditionHelp(beHelpedUid uint64, retCode int32) {
- switch retCode {
- case int32(serverproto.ErrorCode_ERROR_EXPEDITION_NOT_FIND_SERVICE_ID):
- //被救助的玩家最近未上线,db操作
- ssDBMsg := &serverproto.SSExpeditionDBHelpReq{
- BeHelpedUid: beHelpedUid,
- FromUid: this.role.GetUUid(),
- }
- this.role.SendDb(ssDBMsg)
- case int32(serverproto.ErrorCode_ERROR_OK):
- //成功救助
- if this.expeditionData.AssistNum == nil {
- this.expeditionData.AssistNum = &serverproto.KeyValueType{Key: model.GlobalExpeditionGuildHelpNum}
- }
- this.expeditionData.AssistNum.Value += 1
- this.SetDirty(true)
- this.role.AddItemList(model.GlobalExpeditionHelpRewardList, AddFrom_Expedition, true)
- this.expeditionChangeNtf(false)
- ackMsg := &serverproto.SCExpeditionHelpAck{
- Error: retCode,
- }
- for key, val := range model.GlobalExpeditionHelpRewardList {
- ackMsg.RewardItemList = append(ackMsg.RewardItemList, &serverproto.KeyValueType{Key: key, Value: val})
- }
- this.role.ReplayGate(ackMsg, true)
- default:
- ackMsg := &serverproto.SCExpeditionHelpAck{
- Error: retCode,
- }
- this.role.ReplayGate(ackMsg, true)
- }
- }
- //判断是否可以成功被救助(玩家最近在线直接内存操作,不涉及DB操作)
- func (this *RoleBattle) OnExpeditionBeHelp(fromUid, beHelpedUid uint64, helpMsgSendTime uint64) serverproto.ErrorCode {
- if this.expeditionData.BeAssistNum != nil {
- //该玩家被救助的次数达到上限,无法救助
- if this.expeditionData.BeAssistNum.Key <= this.expeditionData.BeAssistNum.Value {
- return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_CALLFORHELP_LIMIT
- }
- }
- //之前过期的救助消息
- if this.expeditionData.AssistTimeStamp > helpMsgSendTime || this.expeditionData.AssistTimeStamp == 0 {
- return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_MSG_EXPIRED
- }
- //已经救助过该玩家,无法再次救助
- bFind := false
- idx := 0
- for idx = 0; idx < len(this.expeditionData.BeAssistUidList); idx++ {
- tmpUidData := this.expeditionData.BeAssistUidList[idx]
- //判断是否是同一天救助
- bNotSameDay := model.IsDailyResetHour5(uint64(tmpUidData.Value) * 1000)
- if tmpUidData.Key == fromUid {
- if !bNotSameDay {
- return serverproto.ErrorCode_ERROR_EXPEDITION_HELP_CALLFORHELP_HAS
- }
- bFind = true
- break
- }
- }
- //判断是否需要救助(英雄是否有死亡)
- canBeHelp := false
- for idx := 0; idx < len(this.expeditionData.BattleHeroHpList); idx++ {
- if this.expeditionData.BattleHeroHpList[idx].Hp <= 0 {
- canBeHelp = true
- break
- }
- }
- if !canBeHelp {
- return serverproto.ErrorCode_ERROR_EXPEDITION_BE_HELPED
- }
- if this.expeditionData.BeAssistNum == nil {
- this.expeditionData.BeAssistNum = &serverproto.KeyValueType{
- Key: model.GlobalExpeditionGuildBeHelpedNum,
- }
- }
- this.expeditionData.BeAssistNum.Value += 1
- this.expeditionData.AssistState = false
- this.expeditionData.AssistTimeStamp = 0
- //回复所有英雄hp,sp
- this.expeditionData.BattleHeroHpList = this.expeditionData.BattleHeroHpList[:0]
- //加入救助列表
- if bFind {
- this.expeditionData.BeAssistUidList[idx].Value = int32(util.GetTimeSeconds())
- } else {
- this.expeditionData.BeAssistUidList = append(this.expeditionData.BeAssistUidList,
- &serverproto.KeyValueType64{Key: fromUid, Value: int32(util.GetTimeSeconds())})
- }
- this.SetDirty(true)
- this.expeditionChangeNtf(false)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) ExpeditionPassReward(expeditionType int32) serverproto.ErrorCode {
- if this.expeditionData == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- //没有通关/最后一关没有奖励
- if this.expeditionData.ExpeditionType <= expeditionType {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if this.expeditionData.ExpeditionTypeReward&(1<<uint64(expeditionType)) > 0 {
- return serverproto.ErrorCode_ERROR_EXPEDITION_PASS_REWARD_HAS
- }
- cfgData, ok := model.ConvertExpeditionDataList[expeditionType]
- if !ok {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- rewardItemList := map[int32]int32{}
- for idx := 0; idx < len(cfgData.PassRewardList); idx++ {
- rewardItemList[cfgData.PassRewardList[idx].Key] += cfgData.PassRewardList[idx].Value
- }
- ret := this.role.GetRoleBag().CanAddItemList(rewardItemList)
- if ret != serverproto.ErrorCode_ERROR_OK {
- return ret
- }
- this.role.AddItemList(rewardItemList, AddFrom_Expedition, true)
- this.expeditionData.ExpeditionTypeReward |= 1 << uint64(expeditionType)
- this.SetDirty(true)
- this.expeditionChangeNtf(false)
- ackMsg := &serverproto.SCExpeditionPassRewardAck{
- RewardItemList: cfgData.PassRewardList,
- }
- this.role.ReplayGate(ackMsg, true)
- return serverproto.ErrorCode_ERROR_OK
- }
- //救助日志过期惰性删除
- func (this *RoleBattle) checkBeHelpUidListExpire() {
- idx := 0
- for idx < len(this.expeditionData.BeAssistUidList) {
- tmpUidData := this.expeditionData.BeAssistUidList[idx]
- //判断是否是同一天救助
- recordTime := util.GetTimeByUint32(uint32(tmpUidData.Value)).AddDate(0, 0, 3)
- if util.GetCurrentTimeNow().After(recordTime) {
- this.expeditionData.BeAssistUidList = append(this.expeditionData.BeAssistUidList[:idx],
- this.expeditionData.BeAssistUidList[idx+1:]...)
- this.SetDirty(true)
- } else {
- idx++
- }
- }
- }
- func (this *RoleBattle) randExpeditionBoss(convertData *model.ConvertExpedition) {
- levelCfgData, ok := convertData.LevelInfo[this.expeditionData.CurBattleLevel]
- if !ok {
- return
- }
- this.expeditionData.BossList = this.expeditionData.BossList[:0]
- var tmpBossIdxList []int
- for k := 0; k < 3; k++ {
- bossInfo, bossRandIdx := levelCfgData.RandBoss(tmpBossIdxList)
- if bossInfo != nil {
- tmpBossIdxList = append(tmpBossIdxList, bossRandIdx)
- this.expeditionData.BossList = append(this.expeditionData.BossList,
- &serverproto.BattleExpeditionActor{
- Id: bossInfo.BossId,
- Level: bossInfo.BossLevel,
- Hp: bossInfo.BossHP,
- Sp: bossInfo.BossSP,
- })
- }
- util.DebugF("randExpeditionBoss id=%v", bossInfo)
- }
- this.SetDirty(true)
- }
- func (this *RoleBattle) randBattleBuffList(levelInfo *model.ConvertExpeditionDetailInfo) {
- //隔天重置,战斗还在进行中,结束时数据已经被清空
- if this.expeditionData.BattleIdx <= 0 {
- return
- }
- this.expeditionData.BattleSelectBuffList = this.expeditionData.BattleSelectBuffList[:0]
- rand.Seed(int64(util.GetTimeMilliseconds()))
- for idx := 0; idx < 3; idx++ {
- bossId := this.expeditionData.BossList[this.expeditionData.BattleIdx-1].Id
- tmpBossId := uint64(bossId)*100000 + uint64(this.expeditionData.CurExpeditionType*1000+this.expeditionData.CurBattleLevel)
- buffId := levelInfo.RandBuff(this.expeditionBuffList, this.expeditionData.BattleSelectBuffList, tmpBossId)
- if buffId > 0 {
- this.expeditionData.BattleSelectBuffList = append(this.expeditionData.BattleSelectBuffList, buffId)
- } else {
- break
- }
- }
- }
- func (this *RoleBattle) GenWarriorScore(levelInfo *model.ConvertExpeditionDetailInfo) {
- //获取勇士积分
- //关卡积分
- tmpAddScore := uint32(levelInfo.WarriorScore)
- //this.expeditionData.CurExpeditionScore += uint32(levelInfo.WarriorScore)
- //boss积分
- if this.expeditionData.BattleIdx > 0 {
- bossIdx := this.expeditionData.BattleIdx
- bossId := this.expeditionData.BossList[bossIdx-1].Id
- tmpBossId := uint64(bossId)*100000 + uint64(this.expeditionData.CurExpeditionType*1000+this.expeditionData.CurBattleLevel)
- if bossCfgData, ok := model.ConvertExpeditionDropBuffList[tmpBossId]; ok {
- tmpAddScore += uint32(bossCfgData.WarriorScore)
- //this.expeditionData.CurExpeditionScore += uint32(bossCfgData.WarriorScore)
- }
- }
- //更新勇士积分
- if this.addExpeditionRankScore(tmpAddScore) {
- //ntf player
- this.expeditionChangeNtf(false)
- }
- this.SetDirty(true)
- }
- //获取当前正在调整的boss id
- func (this *RoleBattle) findBattleBossIdx() int32 {
- return this.expeditionData.BattleIdx
- }
- //判断挑战使用的英雄是否有已经死亡的
- func (this *RoleBattle) isCurBattleHeroDied(heroInfoList []*serverproto.BattleExpeditionActor, flag int32) serverproto.ErrorCode {
- if flag == 1 {
- if len(heroInfoList) <= 0 {
- return serverproto.ErrorCode_ERROR_EXPEDITION_HERO_NOT_IN_CHALLENGE
- }
- }
- for idx := 0; idx < len(heroInfoList); idx++ {
- bFind := false
- for k := 0; k < len(this.expeditionData.BattleHeroList); k++ {
- if this.expeditionData.BattleHeroList[k] == heroInfoList[idx].Id {
- bFind = true
- break
- }
- }
- if !bFind {
- return serverproto.ErrorCode_ERROR_EXPEDITION_HERO_NOT_IN_CHALLENGE
- }
- //挑战使用的英雄是否已经死亡
- //开始阶段判断
- if flag == 1 {
- bFind = false
- for k := 0; k < len(this.expeditionData.BattleHeroHpList); k++ {
- if this.expeditionData.BattleHeroHpList[k].Hp <= 0 &&
- this.expeditionData.BattleHeroHpList[k].Id == heroInfoList[idx].Id {
- bFind = true
- break
- }
- }
- if bFind {
- return serverproto.ErrorCode_ERROR_EXPEDITION_HERO_DIED
- }
- }
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) expeditionRewardAll(cfgData *model.ConvertExpedition, addItemList map[int32]int32) serverproto.ErrorCode {
- var levelNum int32 = 0
- bFind := false
- for idx := 0; idx < len(this.expeditionData.FinishExpeditionList); idx++ {
- tmpReward := this.expeditionData.FinishExpeditionList[idx]
- if tmpReward == cfgData.ExpeditionType {
- bFind = true
- break
- }
- }
- if bFind {
- levelNum = cfgData.LevelNum + 1
- } else {
- if this.expeditionData.CurExpeditionType != cfgData.ExpeditionType {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- levelNum = this.expeditionData.CurBattleLevel
- }
- bFind = false
- for idx := 0; idx < len(this.expeditionData.RewardStateList); idx++ {
- tmpReward := this.expeditionData.RewardStateList[idx]
- if tmpReward.ExpeditionType == cfgData.ExpeditionType {
- //无奖励可领取
- if len(tmpReward.RewardState) >= int(levelNum-1) {
- return serverproto.ErrorCode_ERROR_EXPEDITION_REWARD_NO
- }
- bFind = true
- for levelIdx := 1; levelIdx < int(levelNum); levelIdx++ {
- bReward := false
- for j := 0; j < len(tmpReward.RewardState); j++ {
- if tmpReward.RewardState[j] == int32(levelIdx) {
- bReward = true
- break
- }
- }
- if !bReward {
- cfgData.GetLevelReward(int32(levelIdx), addItemList)
- tmpReward.RewardState = append(tmpReward.RewardState, int32(levelIdx))
- }
- }
- break
- }
- }
- //该区域还未领取过奖励
- if !bFind {
- tmpReward := &serverproto.BattleExpeditionReward{
- ExpeditionType: cfgData.ExpeditionType,
- }
- for levelIdx := 1; levelIdx < int(levelNum); levelIdx++ {
- cfgData.GetLevelReward(int32(levelIdx), addItemList)
- tmpReward.RewardState = append(tmpReward.RewardState, int32(levelIdx))
- }
- this.expeditionData.RewardStateList = append(this.expeditionData.RewardStateList, tmpReward)
- }
- if len(addItemList) > 0 {
- this.SetDirty(true)
- return serverproto.ErrorCode_ERROR_OK
- }
- return serverproto.ErrorCode_ERROR_EXPEDITION_REWARD_NO
- }
- func (this *RoleBattle) expeditionRewardBox(cfgData *model.ConvertExpedition, rewardBoxIdx int32, addItemList map[int32]int32) serverproto.ErrorCode {
- var levelNum int32 = 0
- bFind := false
- for idx := 0; idx < len(this.expeditionData.FinishExpeditionList); idx++ {
- tmpReward := this.expeditionData.FinishExpeditionList[idx]
- if tmpReward == cfgData.ExpeditionType {
- bFind = true
- break
- }
- }
- if bFind {
- levelNum = cfgData.LevelNum + 1
- } else {
- if this.expeditionData.CurExpeditionType != cfgData.ExpeditionType {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- levelNum = this.expeditionData.CurBattleLevel
- }
- //还没完成的关卡无法获取奖励
- if rewardBoxIdx >= levelNum {
- return serverproto.ErrorCode_ERROR_EXPEDITION_REWARD_NO
- }
- bFind = false
- for idx := 0; idx < len(this.expeditionData.RewardStateList); idx++ {
- tmpReward := this.expeditionData.RewardStateList[idx]
- if tmpReward.ExpeditionType != cfgData.ExpeditionType {
- continue
- }
- bFind = true
- for i := 0; i < len(tmpReward.RewardState); i++ {
- if tmpReward.RewardState[i] == rewardBoxIdx {
- return serverproto.ErrorCode_ERROR_EXPEDITION_REWARD_HAS
- }
- }
- tmpReward.RewardState = append(tmpReward.RewardState, rewardBoxIdx)
- }
- if !bFind {
- tmpReward := &serverproto.BattleExpeditionReward{
- ExpeditionType: cfgData.ExpeditionType,
- }
- tmpReward.RewardState = append(tmpReward.RewardState, rewardBoxIdx)
- this.expeditionData.RewardStateList = append(this.expeditionData.RewardStateList, tmpReward)
- }
- cfgData.GetLevelReward(rewardBoxIdx, addItemList)
- this.SetDirty(true)
- return serverproto.ErrorCode_ERROR_OK
- }
- //============================================== 冲榜相关 ===========================================
- func (this *RoleBattle) OnlineGetRushMapBaseReward(rewardRound int32) {
- if this.rushMap == nil || rewardRound <= 0 {
- return
- }
- if this.rushMap.RewardRound >= rewardRound {
- this.rushMap.RushMapId = 0
- this.rushMap.BagScore = 0
- this.rushMap.MapScore = 0
- this.SetDirty(true)
- return
- }
- var addItemList = map[int32]int32{}
- rewardLevel := model.GetRushActivityBaseReward(this.rushMap.FightRound, model.Rush_Type_Map, int32(this.rushMap.RushMapId), addItemList)
- if len(addItemList) > 0 {
- this.role.AddMail(model.GlobalMailRushMapBaseReward, serverproto.MailType_MailType_RushMap,
- addItemList, []int32{int32(this.rushMap.RushMapId), rewardLevel}, "", "")
- }
- this.rushMap.RewardRound = rewardRound
- this.rushMap.BagScore = 0
- this.rushMap.MapScore = 0
- this.SetDirty(true)
- }
- func (this *RoleBattle) OnlineProcess() {
- this.OnlineCheckReward()
- // 战斗加速时间 上线处理
- this.FastBattleTimeOnline()
- }
- func (this *RoleBattle) OnlineCheckReward() {
- if this.rushMap == nil {
- this.rushMap = &serverproto.RushMap{}
- this.SetDirty(true)
- return
- }
- if this.rushMap != nil {
- if this.rushMap.FightRound != 0 && this.rushMap.FightRound > this.rushMap.RewardRound {
- reqMsg := &serverproto.SSGetRushBaseRewardReq{}
- reqMsg.Uid = this.role.GetUUid()
- reqMsg.RushType = model.Rush_Type_Map
- reqMsg.RushRound = this.rushMap.FightRound
- this.role.SendRank(reqMsg)
- }
- //发送奖励查询请求
- /*
- reqMsg := &serverproto.SSGetRushRankReq{
- Uid: this.role.GetUUid(),
- RushType: model.Rush_Type_Map,
- RushRound: this.rushMap.RankReward,
- }
- this.role.SendRank(reqMsg)
- */
- }
- }
- func (this *RoleBattle) GetRushMapBaseReward(ackMsg *serverproto.SCRushActivityRewardAck, rushRound int32) serverproto.ErrorCode {
- if ackMsg == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if this.rushMap.RewardRound >= rushRound {
- return serverproto.ErrorCode_ERROR_RUSH_ACTIVITY_REWARD_FINISH
- }
- //检查this.fightRound 对应的保底奖励
- addItemList := map[int32]int32{}
- model.GetRushActivityBaseReward(this.rushMap.FightRound, model.Rush_Type_Map, int32(this.rushMap.RushMapId), addItemList)
- this.rushMap.RewardRound = rushRound
- this.role.AddItemList(addItemList, AddFrom_RushMap, true)
- for key, value := range addItemList {
- ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
- Key: key,
- Value: value,
- })
- }
- this.SetDirty(true)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) GetRushMapRankReward(ssAck *serverproto.SSGetRushRewardAck) serverproto.ErrorCode {
- if ssAck == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if this.rushMap.RankReward >= ssAck.RushRound {
- return serverproto.ErrorCode_ERROR_RUSH_ACTIVITY_REWARD_FINISH
- }
- var addItemList = map[int32]int32{}
- for _, data := range ssAck.ItemList {
- addItemList[data.Key] += data.Value
- }
- this.role.AddItemList(addItemList, AddFrom_RushMap, true)
- this.rushMap.RankReward = ssAck.RushRound
- this.SetDirty(true)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) GetRushMapInfo(ackMsg *serverproto.SCMapActivityAck, curRound int32) {
- if ackMsg == nil {
- return
- }
- ackMsg.MapScore = int32(this.rushMap.MapScore)
- ackMsg.BagScore = int32(this.rushMap.BagScore)
- ackMsg.RankReward = false
- ackMsg.RushLevel = this.rushMap.RushMapId
- if this.rushMap.RankReward == curRound {
- ackMsg.RankReward = true
- }
- ackMsg.ChallengReward = false
- if this.rushMap.RewardRound != 0 && this.rushMap.RewardRound >= this.rushMap.FightRound {
- ackMsg.ChallengReward = true
- }
- }
- func (this *RoleBattle) CheckRankReward(finishRound int32) serverproto.ErrorCode {
- if this.rushMap.RankReward >= finishRound {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleBattle) SetRankReward(finishRound int32) {
- this.rushMap.RankReward = finishRound
- this.SetDirty(true)
- }
- func (this *RoleBattle) GetFightCountMailReward(rushRound int32) {
- if rushRound <= 0 {
- return
- }
- if this.rushMap.RewardRound < this.rushMap.FightRound {
- //发送上一轮冲榜战斗次数的奖励邮件
- addItemList := map[int32]int32{}
- rewardLevel := model.GetRushActivityBaseReward(this.rushMap.FightRound, model.Rush_Type_Map, int32(this.rushMap.RushMapId), addItemList)
- if len(addItemList) > 0 {
- this.role.AddMail(model.GlobalMailRushMapBaseReward, serverproto.MailType_MailType_RushMap,
- addItemList, []int32{int32(this.rushMap.RushMapId), rewardLevel}, "", "")
- }
- this.rushMap.RewardRound = this.rushMap.FightRound
- this.rushMap.BagScore = 0
- this.rushMap.MapScore = 0
- this.SetDirty(true)
- }
- }
- //去排行榜服务器校验是否活动内
- func (this *RoleBattle) OnRushMapScoreChange(score2 int32, score3 int32) {
- reqMsg := &serverproto.SSRushDataChangeReq{}
- reqMsg.Uid = this.role.GetUUid()
- reqMsg.RushType = model.Rush_Type_Map
- reqMsg.Score2 = score2
- reqMsg.Score3 = score3
- this.role.SendRank(reqMsg)
- }
- //score2 战斗分数 score3 礼包分数
- func (this *RoleBattle) AddRushMapScore(rushRound int32, score2 int32, score3 int32) {
- if rushRound == 0 {
- return
- }
- if this.rushMap == nil {
- util.ErrorF("add score failed ,not init rushmap , uid: %v score: %v", this.role.GetUUid(), score2, score3)
- return
- }
- globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Rush_Map_Activity_Unlock)]
- if !ok {
- util.ErrorF("add score failed ,config not found , uid: %v score: %v", this.role.GetUUid(), score2, score3)
- return
- }
- if (score2 != Rush_Map_Fight_Score && this.GetLevelId() <= globalData.IVal) ||
- (score3 == Rush_Map_Bag_Score && this.GetLevelId() < globalData.IVal) {
- util.ErrorF("add score failed ,map level lower , uid: %v score: %v", this.role.GetUUid(), score2, score3)
- return
- }
- if this.rushMap.FightRound != rushRound {
- this.rushMap.FightRound = rushRound
- this.rushMap.BagScore = 0
- this.rushMap.MapScore = 0
- }
- this.rushMap.RushMapId = uint32(this.GetLevelId())
- if score2 != 0 {
- this.rushMap.MapScore += uint32(score2)
- util.InfoF("rush map add score uid: %v score: %v", this.role.GetUUid(), score2)
- }
- if score3 != 0 {
- this.rushMap.BagScore += uint32(score3)
- util.InfoF("buy item add score uid: %v score: %v", this.role.GetUUid(), score3)
- }
- this.sendRushMapScoreToRank()
- this.SetDirty(true)
- }
- //同步积分到rank服务器
- func (this *RoleBattle) sendRushMapScoreToRank() {
- ntfMsg := &serverproto.SSRushMapScoreNtf{
- Uid: this.role.GetUUid(),
- }
- ntfMsg.Score = this.rushMap.MapScore + this.rushMap.BagScore
- this.role.SendRank(ntfMsg)
- }
- func (this *RoleBattle) OnExpeditionRankList(ssAckMsg *serverproto.SSExpeditionScoreRankListAck) {
- ackMsg := &serverproto.SCExpeditionScoreRankListAck{
- StartIdx: ssAckMsg.StartIdx,
- RankList: ssAckMsg.RankList,
- }
- if ssAckMsg.SelfRankInfo == nil {
- ackMsg.SelfRankInfo = &serverproto.ExpeditionRankInfo{
- Score: this.expeditionData.CurExpeditionScoreMax,
- }
- } else {
- ackMsg.SelfRankInfo = ssAckMsg.SelfRankInfo
- ackMsg.SelfRankInfo.Score = this.expeditionData.CurExpeditionScoreMax
- }
- this.role.ReplayGate(ackMsg, true)
- }
- // bt服务器
- // 特殊处理使用道具添加战斗倍数时间
- // addTime(in s)
- func (this *RoleBattle) FastBattleTimeAdd(durationTime int32) {
- curTime := util.GetTimeMilliseconds()
- addTime := uint64(durationTime) * 1000
- if this.lastRecordBattleAcceTime <= 0 {
- this.lastRecordBattleAcceTime = curTime
- this.battleAcceDuration = addTime
- } else {
- //之前的持续时间用完了,需要重新设置,否则就是累加
- if this.lastRecordBattleAcceTime+this.battleAcceDuration <= curTime {
- this.lastRecordBattleAcceTime = curTime
- this.battleAcceDuration = addTime
- } else {
- this.battleAcceDuration += addTime
- }
- }
- this.SetDirty(true)
- ntfMsg := &serverproto.SCPlayerBattleAcctTimeNtf{
- LastRecordBattleAcceTime: this.lastRecordBattleAcceTime,
- BattleAcceDuration: this.battleAcceDuration,
- }
- this.role.ReplayGate(ntfMsg, true)
- }
- // 战斗加速时间 离线处理
- func (this *RoleBattle) FastBattleTimeOffline() {
- if this.battleAcceDuration > 0 {
- curTime := util.GetTimeMilliseconds()
- if this.lastRecordBattleAcceTime+this.battleAcceDuration <= curTime {
- this.battleAcceDuration = 0
- } else {
- this.battleAcceDuration -= curTime - this.lastRecordBattleAcceTime
- }
- this.lastRecordBattleAcceTime = curTime
- util.InfoF("uid=%v FastBattleTimeOffline duration=%v", this.role.GetUUid(), this.battleAcceDuration)
- this.SetDirty(true)
- }
- }
- // 战斗加速时间 上线处理
- func (this *RoleBattle) FastBattleTimeOnline() {
- if this.battleAcceDuration > 0 {
- curTime := util.GetTimeMilliseconds()
- this.lastRecordBattleAcceTime = curTime
- this.SetDirty(true)
- }
- }
|