role.go 133 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466
  1. package model
  2. import (
  3. "crypto/md5"
  4. "encoding/hex"
  5. "encoding/json"
  6. "errors"
  7. "fmt"
  8. "math"
  9. "math/rand"
  10. "reflect"
  11. _ "rocommon/rpc"
  12. "rocommon/service"
  13. "rocommon/util"
  14. "roserver/baseserver/model"
  15. "roserver/serverproto"
  16. "sort"
  17. "strconv"
  18. "strings"
  19. "time"
  20. "unicode/utf8"
  21. )
  22. var TmpLeaseId int64 = 0
  23. type RoleOuter interface {
  24. model.StateMachine
  25. ReqAckConfirm(msgId, seqId uint32)
  26. SetOpenId(openId string)
  27. GetOpenId() string
  28. SetSelectZone(selectZone int32) //玩家当前选择的服务器,用户合服操作
  29. GetSelectZone() int32
  30. SetCliID(cId model.ClientID)
  31. SetCliIDSessionID(sessionID uint64)
  32. ReplayGate(msg interface{}, transmit bool) int
  33. GetUUid() uint64
  34. GetNickName() string
  35. GetImageId() int32
  36. KickNotSave(err int32)
  37. KickWithSave(err int32)
  38. LoginAck(err serverproto.ErrorCode)
  39. Load(role *serverproto.Role) error
  40. LoadOther(msg interface{}) error //load加载之后加载数据
  41. Update(ms uint64)
  42. DailyReset(notify bool)
  43. SetUpdateDailyReset(ms uint64, bReset bool)
  44. CliID() model.ClientID
  45. SetCreateData(msg *serverproto.CSCreateRoleReq)
  46. IsLogout(ms uint64) bool
  47. Logout()
  48. Save()
  49. SetReLogin(re bool)
  50. BanRole(isBan bool, banTime uint64, cheatType int32)
  51. BanRoleChat(isBan bool, banTime uint64, cheatType int32)
  52. SetPlatform(platform string)
  53. GetPlatform() string
  54. SetSubPlatform(subPlatform string)
  55. GetSubPlatform() string
  56. SetClientParam(clientInfo *serverproto.ClientParamInfo)
  57. GetClientParam() *NeteaseLogCommonInfo
  58. SetClientIP(ip string)
  59. GetClientIP() string
  60. GetHardFight() int
  61. SetHardFight(b int)
  62. SetYuanRankScore()
  63. SetSdkJson(a string)
  64. GetSdkJson() string
  65. }
  66. // 逻辑操作主接口(可以按照每个系统设定一个接口)
  67. type RoleLogicOuter interface {
  68. AddMoney(st AddItemST, add bool)
  69. AddBaseExp(st AddItemST) bool
  70. AddJobExp(st AddItemST) bool
  71. AddHeroExp(st AddItemST, add bool) bool
  72. AddAttrPoint(heroID int32, point interface{})
  73. AddRes(resType int32, st AddItemST, add bool)
  74. //AddItem(configId int32, count int32, addFrom int32)
  75. ResetAttrPoint(heroID int32)
  76. ActiveHead(headId int32)
  77. SetRoleHeadPic(headId int32)
  78. HeadInfoReq()
  79. SetRoleHeadFrameId(frameId int32)
  80. GetRoleHeadFrameInfo()
  81. UseHeadFrameItem(itemId uint64, itemNum uint32)
  82. ChangeRoleName(name string)
  83. SetRoleGuide(guideId int32)
  84. SetRoleStory(story *serverproto.KeyValueType)
  85. SetMapCartoon(id, status int32)
  86. OnAddQualityPoint(msg *serverproto.CSAddQualityPointReq)
  87. //hero
  88. AddHero(configId int32) bool
  89. HeroLevelUp(id int32) bool
  90. HeroAdvance(id int32) bool
  91. HeroBattle(id int32, isBattle bool)
  92. HeroStrength(id int32) bool
  93. HeroChangeJob(heroId int32, jobId int32) bool
  94. HeroRecruit(configId int32)
  95. FightPowerReq(heroId int32)
  96. HeroReplaceJob(heroId int32, replaceJob int32)
  97. //equip
  98. EquipForge(equipId, once, equipType, subEquipType int32)
  99. AddEquip(configId, num int32, notify bool, ignore bool)
  100. EquipUp(heroId, slotType, equipId int32)
  101. EquipDown(heroId int32, subIndex int32)
  102. EquipLevelUpAll(heroId int32)
  103. EquipSlotLevelUp(heroId, subSlotIndex int32)
  104. ComposeChip(configId int32)
  105. ChipDecompose(cardList []*serverproto.KeyValueType, cardType []int32)
  106. //skill equip
  107. SkillEquipSlotLevelUp(heroId, subIndex int32)
  108. SkillEquipStarLevelUp(heroId int32, skillEquipId uint32, cost []uint32)
  109. SkillEquipUp(heroId int32, skillEquipId uint32, slotIndex int32)
  110. SkillEquipDown(heroId int32, slotIndex int32)
  111. SkillEquipDecompose(skillEquipIds []uint32)
  112. SkillEquipRemade(skillEquipId uint32)
  113. GetSkillEquipPool()
  114. SkillEquipShift(msg *serverproto.CSSkillEquipShiftReq)
  115. //card
  116. CardMount(heroId, subSlotIndex, cardSlotIndex, cardCfgId int32)
  117. CardDown(heroId, subSlotIndex, cardSlotIndex int32)
  118. CardMountAll(msg *serverproto.CSCardEquipAllReq)
  119. CardDownAll(heroId int32)
  120. CardUpGradeAll(msg *serverproto.CSCardUpGradeAllReq)
  121. CardCollect()
  122. CardCollectReward(cardId, level int32)
  123. CardCompose(cardList []int32)
  124. CardDecompose(cardList []*serverproto.KeyValueType, cardType int32)
  125. CardUpGrade(msg *serverproto.CSCardUpGradeReq)
  126. CardLevelExchange(sourceCardId, targetCardId int32)
  127. //skill
  128. SkillReplace(heroId, idx, replaceSkillId int32)
  129. ActiveSkill(heroId int32, skillId int32)
  130. SwapSkill(heroId, firstSlotId, secondSlotId int32)
  131. SetSkillList(heroId int32, skillList []int32)
  132. SkillLevelUp(heroId int32, skillId int32)
  133. ResetSkillLevel(heroId int32, bsuper bool)
  134. ConverSkillExp(msg *serverproto.CSConverSkillExpReq)
  135. //fashion
  136. FashionUp(fashionCfgId []int32)
  137. FashionDown(fashionCfgId []int32)
  138. FashionCompose(paperCfgId int32)
  139. FashionPaperDecompose(paperCfgId int32)
  140. FashionResetAttr(fashionId int32, enter bool)
  141. FashionUpLvl(fashionId int32)
  142. //商店
  143. BuyItem(shopId, goodsId, goodsNum int32)
  144. ShopInfoReq(goodsType int32)
  145. ShopRefresh(goodsType int32)
  146. RedBagShopExchange()
  147. //task
  148. GetTaskReward(taskId uint32)
  149. GetTaskScoreReward(rewardType, rewardIdx int32)
  150. //item
  151. UseItem(itemId uint64, itemNum uint32, itemIdxList []int32, bForceItemId bool)
  152. DelItemByList(itemId []uint64, delFrom AddFromType)
  153. //chat
  154. CheckChatInvalid(targetId uint64, msgType int32, msg *serverproto.CSChatMessageReq) bool
  155. GetOfflineMsg(targetId uint64)
  156. //英灵殿
  157. GetArena()
  158. ArenaMatch(heroList []int32)
  159. ArenaResult(result int32)
  160. ArenaByCount(buyCount int32)
  161. ArenaRankList(rankType, startIdx int32)
  162. SetArenaRank(rankIdx int32, notify bool)
  163. //mail
  164. GetMailIst()
  165. MailRead(idList []int32)
  166. MailReward(idList []int32)
  167. MailDelRead()
  168. AddMail(configId int32, mailType serverproto.MailType, itemList map[int32]int32, paramList []int32,
  169. title, content string)
  170. AddMail1(configId int32, mailType int32, itemList []*serverproto.KeyValueType, paramList []int32,
  171. title, content string)
  172. //competition
  173. GetCompetition(competitionId int32) //competitionId为0表示获得当前正在进行的赛季
  174. CompetitionAddScore(itemList []*serverproto.KeyValueType) //上交道具获取积分
  175. VoteIdol(uid uint64, ticketCount int32)
  176. CheckInSeason() (serverproto.ErrorCode, int32)
  177. GetSelfVoteData(ackMsg *serverproto.SCCompetitionFansRewardRankAck)
  178. CheckFansReward(uid uint64, rewardLevel int32) serverproto.ErrorCode
  179. GetFansReward(idolUid uint64, rewardLevel int32, boxCount int32)
  180. CompulsoryGuidance(storyId, status int32) //强制引导
  181. //ClimbingTower 爬塔/无尽试炼
  182. ClimbingTowerInfoReq()
  183. GetFriendTowerInfo(begin, end int32)
  184. ClimbingTowerBegin(towerLevel int32)
  185. ClimbingTowerEnd(towerLevel, loadingTime int32, recordTimeStamp uint64)
  186. GetFriendBriefFromDB(final bool, begin int32, end int32, briefs []*serverproto.CommonPlayerBriefInfo)
  187. ClimbingTowerWjBegin(towerLevel int32)
  188. ClimbingTowerWjBuff(buff1, buff2, buff3 int32)
  189. ClimbingTowerWjEnd(towerLevel, loadingTime int32, recordTimeStamp uint64)
  190. //冲榜相关
  191. GetTowerFightCountReward(rushRound int32, rewardType int32)
  192. GetRushTowerInfo(ackMsg *serverproto.SCTowerActivityAck, curRushRound int32)
  193. GetRushTowerRankReward(ssAck *serverproto.SSGetRushRewardAck)
  194. GetArenaFightCountReward(rushRound int32, rewardType int32)
  195. GetRushArenaInfo(ackMsg *serverproto.SCArenaActivityAck, curRushRound int32)
  196. GetRushArenaRankReward(ssAck *serverproto.SSGetRushRewardAck)
  197. GetRushMapLevelReward(rushRound int32, rewardType int32)
  198. GetRushMapInfo(ackMsg *serverproto.SCMapActivityAck, curRushRound int32)
  199. GetRushMapRankReward(ssAck *serverproto.SSGetRushRewardAck)
  200. GetPetFightCountReward(rushRound int32, rewardType int32)
  201. GetRushPetInfo(ackMsg *serverproto.SCPetActivityAck, curRushRound int32)
  202. GetRushPetRankReward(ssAck *serverproto.SSGetRushRewardAck)
  203. GetFightCountReward(rushRound int32, rushType int32, rewardType int32)
  204. GetRushInfo(ackMsg *serverproto.SCRushActivityAck, curRushRound int32)
  205. GetRushRankReward(ssAck *serverproto.SSGetRushRewardAck)
  206. GetRushShopInfo(ackMsg *serverproto.SSGetRushShopInfoAck)
  207. //guild公会相关操作
  208. CheckBuildGuild(guildName string, guildBadge int32) serverproto.ErrorCode
  209. CheckApplyGuild(guildId uint64) bool
  210. CheckApplyInfo(msg *serverproto.CSApplyInfoHandleReq) serverproto.ErrorCode
  211. CheckGuildModifyInfo(msg *serverproto.CSSetGuildInfoReq) serverproto.ErrorCode
  212. CheckGuildRename(guildName string) serverproto.ErrorCode
  213. CheckGuildRenotice(notice string) serverproto.ErrorCode
  214. OnChangeGuileNameSuccess()
  215. CheckGuildBossChallenge(bossId uint32, damage uint32, fightTime uint32) serverproto.ErrorCode
  216. GetRoleGuildId() uint64
  217. GuildDemonBuyFightCount(buyCount int32)
  218. PackRoleViewInfo(info *serverproto.ViewRoleInfo)
  219. //获取战斗记录
  220. GetBattleRecord(recordType int32, paramList []uint32)
  221. //宠物
  222. PetLevelUp(petId uint32)
  223. PetAdvance(petId uint32, petList []uint32)
  224. PetManualReward(petCfgId, petId, advLevel int32)
  225. PetSkillLevelUp(petId uint32, costPetId uint32)
  226. PetDecompose(petIdList []uint32)
  227. PetBattle(battleList []*serverproto.KeyValueType)
  228. PetBondListGet()
  229. PetAssist(petIdList []uint32)
  230. PetBondAssistListGet(bondCfgId int32)
  231. PetBondActive(bondData []*serverproto.PetBondData)
  232. PetAdvAchievement(petCfgId int32)
  233. PetEquipLevelUp(petEquipId uint32)
  234. PetEquipUp(petId uint32, slotIndexList []*serverproto.KeyValueType)
  235. PetEquipDown(petId uint32, slotIndex int32)
  236. PetGetPetDetailInfo(petIdList []uint32)
  237. PetQiyueUnlock(heroId int32)
  238. PetQiyueSlotIn(heroId, slotIdx int32, petId uint32)
  239. PetQiyueSlotOut(heroId, slotIdx int32)
  240. PetQiyueBattlePetAttr()
  241. //精彩活动Activities
  242. ActivitiesReward(activityId, param, rewardNum int32)
  243. ActivitiesScoreReward(activityId, boxId int32)
  244. ActivitiesFirstChargeReward()
  245. ActivitiesExchange(msg *serverproto.CSActivitiesExchangeReq)
  246. ActivityWheelRefresh(activityId int32)
  247. ActivityWheelOpenReward(activityId int32)
  248. ActivityWheelReward(activityId int32, rewardAll bool)
  249. ActivityWheelClose(activityId int32)
  250. ActivitySummon(activityId, summonCount int32)
  251. ActivitySignIn(activityId int32)
  252. SetCollectionNotice(activityId int32, CollectId int32, notice bool)
  253. ActivitySmashEggs(activityId, drawType, drawCount int32)
  254. ActivitySmashEggsMsg(activityId, drawType int32)
  255. //invitation
  256. InvitationNumberGet()
  257. InvitationNumberUserInfoGet(number uint64)
  258. InvitationBeToMember(number, uid uint64)
  259. InvitationReward(taskIdList []uint32)
  260. InvitationClick(memberUidList []uint64)
  261. InvitationClickReplay(replayMasterUid uint64)
  262. InvitationDelMember(memberUidList []uint64)
  263. //vip等级获取
  264. GetRoleVipLevel() int32
  265. //pay
  266. CheckRushShopInfoGet(goodsType, goodsId, count int32) bool
  267. PayInfoGet(goodsType, goodsId, count int32, rushStage, rushRound int32, cpOrderId uint64, sdkOrderId string)
  268. OnPayCallback(payRewardInfo *serverproto.PayOrderSaveInfo, bSave bool, bAck bool)
  269. OnPayCallback2(cpOrderId uint64)
  270. CheckOrderInfo(payRewardInfo *serverproto.PayOrderSaveInfo) bool
  271. //卢恩商会
  272. GetRuneShopInfo(shopType int32, subShop int32)
  273. OnRuneExploreInfo()
  274. OnRuneMaxLvlAward()
  275. OnRuneReward(msg *serverproto.CSExploreRewardReq)
  276. //抽卡
  277. OnDrawReq(drawType int32, drawCount int32)
  278. GetResNotice(resType int32) serverproto.ErrorCode
  279. //百人道场
  280. GetDaoChang100SelfPosInfo(msg *serverproto.CSDaoChang100PlayerInfoReq)
  281. GetDaoChang100PosInfo(posIdxList []int32)
  282. GetDaoChang100Log(beginTime uint64)
  283. DaoChang100ChallengeReq(posIdx int32)
  284. DaoChang100TimeRewardReq()
  285. DaoChang100ChallengeResultReq(msg *serverproto.CSDaoChang100ChallengeResultReq)
  286. DaoChang100BuyChallengeCount()
  287. DaoChang100SetTips(tipDesc string)
  288. OnAntiCheatReq(cheatType int32)
  289. GiftReward(ackMsg *serverproto.SCGiftRewardAck)
  290. //问卷奖励获取
  291. QuestionReward()
  292. GetKeepSake()
  293. KeepSakeLevelUp(keepSakeId int32)
  294. // 称号操作
  295. OnHeadOperate(*serverproto.CSHeadOperateReq)
  296. OnHeadData(req *serverproto.CSHeadDataReq)
  297. // 许愿箱
  298. OnWishUse(*serverproto.CSWishBoxUseReq)
  299. OnWishSlotUnlock(*serverproto.CSWishUnlockSlotReq)
  300. OnWishSlotAction(req *serverproto.CSWishSlotReq)
  301. GetCombineServerInfo()
  302. }
  303. type BattleLogicOuter interface {
  304. //income
  305. Income()
  306. OnlineTimeReward() //累计在线时间奖励获取
  307. BossReward(challengeTime uint32, mapId, mapLevel uint32, recordTimeStamp uint64)
  308. BattleBossReq()
  309. //mapRank
  310. SetMapRank(selfRank, totalRanks uint32, topRankList []*serverproto.RankPlayerInfo, addSystemMsg bool)
  311. GetMapRank()
  312. GetQuickBattleReward()
  313. //Evil
  314. BattleEvilRefresh(bForce bool)
  315. BattleEvilChallenge(posIdx int32)
  316. //expedition
  317. ExpeditionChallengePre(expeditionType int32)
  318. ExpeditionChallenge(expeditionType, battleLevel int32, heroInfoList []*serverproto.BattleExpeditionActor,
  319. bossChangeHpList []*serverproto.BattleExpeditionActor, battleTime int32, bossIdx, flag int32)
  320. ExpeditionBuffSelect(selectBuf int32)
  321. ExpeditionReward(expeditionType, boxIdx int32)
  322. ExpeditionBattleHero(battleHeroList []int32)
  323. ExpeditionCallForHelp(assistHelpUid uint64)
  324. ExpeditionHelp(beHelpedUid uint64, msgType int32, helpMsgSendTime uint64)
  325. ExpeditionScoreRankList(startIdx int32)
  326. //actor attr(获取英雄属性,宠物属性)
  327. GetActorAttr(reqMsg *serverproto.CSActorAttrGetReq)
  328. }
  329. type CrossLogicOuter interface {
  330. //远航试炼
  331. YuanHangTrialViewList()
  332. //刷新远航试炼品质
  333. RefreshYuanHangTrialType(force bool)
  334. //发起远航试炼
  335. YuanHangTrial()
  336. YuanHangTrialReward()
  337. YuanHangTrialChallenge(challengeUid, challengeUidEndTime uint64)
  338. YuanHangTrialChallengeBuy()
  339. YuanHangTrialChallengeResult(msg *serverproto.CSCrossYuanHangTrialChallengeResultReq)
  340. YuanHangTrialInfoQuery(trialUid, trialEndTime uint64)
  341. YuanHangTrialLog(logTime uint64)
  342. //from router
  343. OnYuanHangTrialChallengeResult(msg *serverproto.SSCrossYuanHangTrialChallengeResultAck)
  344. YuanHangTrialRankList(startIdx int32)
  345. //巅峰之塔
  346. //获取挑战列表
  347. TopTowerFightListReq()
  348. //战斗结果通知
  349. TopTowerChallengeResultReq(bWin bool, fightIdx int32)
  350. //买路操作(直接胜利)
  351. TopTowerForceWinReq(fightIdx int32)
  352. }
  353. // //全局跨服地图相关
  354. type RoleCrossMapRouter interface {
  355. PlayerEnterMap(msg *serverproto.CSGCrossPlayerEnterMapReq)
  356. PlayerLeave(msg *serverproto.CSGCrossPlayerLeaveMapReq)
  357. PlayerMoveSync(msg *serverproto.CSGCrossPlayerMapSyncPosReq)
  358. PlayerSyncParam(msg *serverproto.CSGCrossPlayerMapSyncParamReq)
  359. //获取玩家地图展示信息
  360. GetPlayerMapShowInfo() *serverproto.PlayerShowInfo
  361. }
  362. // // bt服务器版本使用
  363. type RoleBTRouter interface {
  364. // 充值钱包商店购买(假钱购买)
  365. PayInfoGetForCreditRecharge(goodsId, count int32)
  366. // 特权卡商店每日礼包领取
  367. SpecialPrivilegeReward()
  368. // 充值钱包商店,Ro币礼包商店
  369. GetBTShopInfo(shopType int32, subShop int32)
  370. // Ro币礼包商店购买(消耗RO币)
  371. PayInfoGetForRoCoin(goodsId, count int32)
  372. // 获取爬塔馈赠奖励
  373. GetTowerLevelDayReward()
  374. // 波利商城
  375. BoliShopInfo()
  376. BoliLevelUp(num int32)
  377. BoliReward(RewardLevel, idx int32)
  378. BoliShopBuy(goodsId, num int32)
  379. //超值首充 & 百元大礼包
  380. FirstRechargeReward(rewardIdx int32)
  381. Recharge100Reward()
  382. }
  383. type RoleSaveObject interface {
  384. Load(msg interface{}) bool
  385. Save()
  386. IsDirty() bool
  387. SetDirty(b bool)
  388. }
  389. const (
  390. SLOT_NUM = 4 //4个上阵位置
  391. SLOT_TYPE_NUM = Equip_Type_Max - 1
  392. SKILL_EQUIP_SLOT_TYPE_NUM = Skill_Equip_Type_Max - 1
  393. )
  394. // 任务唯一id
  395. var timeWheelKeyUid uint64 = 1
  396. type SaveObject struct {
  397. isDirty bool
  398. role *Role
  399. }
  400. func (this *SaveObject) IsDirty() bool {
  401. return this.isDirty
  402. }
  403. func (this *SaveObject) SetDirty(b bool) {
  404. if this.isDirty == b {
  405. return
  406. }
  407. this.isDirty = b
  408. if this.isDirty {
  409. if this.role.twTask == nil {
  410. timeWheelKeyUid++
  411. this.role.twTask = &util.TWTask{
  412. Uid: this.role.GetUUid(),
  413. Key: timeWheelKeyUid, //任务唯一id
  414. CallbackType: util.TWTASK_TYPE_Save, //表示save操作
  415. Delay: 20,
  416. }
  417. }
  418. RoleMag.tw.AddTask(this.role.twTask)
  419. }
  420. }
  421. type Role struct {
  422. model.StateMachineCore
  423. soList []RoleSaveObject
  424. //在upate中标记是否需要重置,随后再每个玩家自身的update中进行reset操作,降低
  425. //同一时间的reset操作次数
  426. dailyResetTimer util.OnceTimer
  427. twTask *util.TWTask
  428. mysqlLogList []*serverproto.SSRoleLogData //mysql数据保存
  429. mysqlLogSaveTimer util.DurationTimer
  430. reqAckConfirmList map[uint32][]uint32
  431. cliID model.ClientID //在Gate上的信息
  432. dbNode string //选择处理信息的db节点
  433. socialNode string //选择处理信息的social节点
  434. //aoiNode string //aoi服务器节点(工会主城只会有一个)
  435. bossNode string //BattleBoss服务器节点
  436. rankNode string //Rank服务器节点
  437. guildNode string //Guild服务器接点
  438. platform string //平台
  439. subPlatform string //平台对应不同分发媒体
  440. clientParamInfo *NeteaseLogCommonInfo //客户端上报信息
  441. clientIp string //客户端IP
  442. tmpState bool //临时控制使用
  443. selectZone int32 ////玩家当前选择的服务器,用户合服操作
  444. uuid uint64 //Role的用户ID
  445. openId string //平台账号
  446. RegisterTime uint64 //注册时间
  447. UuidList []uint64 //用户拥有的所有角色ID
  448. UuidRoleList map[uint64]*serverproto.AccountRole //用户拥有的所有角色数据AccountRole
  449. SelectedUuid uint64 //用户选择的角色ID
  450. reLogin bool //是否是重新登陆
  451. isLoad bool //是否已经加载过
  452. activeCode string //激活码
  453. isHardFight int //是否是困难模式 //0普通.1困难,2噩梦
  454. Guid string //小七uid
  455. base *RoleBase //角色基础信息
  456. roleHero *RoleHero //伙伴信息
  457. roleBag *RoleBag //角色背包信息
  458. roleEquip *RoleEquip //装备信息
  459. roleChip *RoleChip //英雄碎片信息
  460. roleMap *RoleMap //地图信息
  461. roleSkill *RoleSkill //技能信息
  462. roleCard *RoleCard //卡片系统
  463. roleFashion *RoleFashion //时装
  464. roleBattle *RoleBattle //战斗相关信息
  465. roleTask *RoleTask //任务系统
  466. roleChat *RoleChat
  467. roleArena *RoleArena //竞技场
  468. roleRed *RoleRed //小红点
  469. roleMail *RoleMail //邮件
  470. roleShop *RoleShop //
  471. roleCompetition *RoleCompetition //赛季
  472. roleSocial *RoleSocial //social相关(friend)
  473. roleActivity *RoleActivity //活动信息
  474. roleTower *RoleTower //爬塔
  475. roleGuild *RoleGuild //公会
  476. rolePet *RolePet //宠物
  477. roleInvitation *RoleInvitation //邀请码功能
  478. roleDraw *RoleDraw //抽取系统
  479. roleRune *RoleRune //卢恩商店
  480. roleDaoChang100 *RoleDaoChang100 //百人道场
  481. roleStatistic *RoleStatistic //统计数据
  482. roleKeepSake *RoleKeepSake
  483. roleSkillEquip *RoleSkillEquip //神器系统
  484. roleCross *RoleCross //跨服数据
  485. roleRush *RoleRush //跨服数据
  486. roleBattleAttr *RoleBattleAttr //战斗属性计算,每个玩法的属性都放到该类中处理
  487. roleHead *RoleHead // 称号数据
  488. roleWish *RoleWishBox // 许愿箱
  489. roleBT *RoleBT // bt版本数据
  490. delete bool
  491. delete1 bool
  492. delete2 bool
  493. saveTimer util.DurationTimer //保存数据定时器
  494. offlineTimer util.OnceTimer //离线定时器
  495. lastProcessTime uint64 //无数据操作
  496. }
  497. var roleSaveTimeout time.Duration = 500 //保存数据的间隔时间
  498. var roleOfflineTimeout time.Duration = 30 * 60 * 1000 //
  499. var mysqlSaveTimeout time.Duration = 2000
  500. func NewRole(cId model.ClientID) RoleOuter {
  501. role := &Role{
  502. reqAckConfirmList: map[uint32][]uint32{},
  503. cliID: cId,
  504. uuid: 0,
  505. reLogin: false,
  506. }
  507. //初始化角色信息
  508. role.Init()
  509. return role
  510. }
  511. func (this *Role) Init() {
  512. this.UuidRoleList = map[uint64]*serverproto.AccountRole{}
  513. //初始化角色状态机
  514. this.InitState()
  515. this.RegisterState(int32(ROLE_STATE_PULLING_LIST), pullingRoleList)
  516. this.RegisterState(int32(ROLE_STATE_PULLED_LIST), pulledRoleList)
  517. this.RegisterState(int32(ROLE_STATE_CREATE), createRole)
  518. this.RegisterState(int32(ROLE_STATE_DB_ADD_ROLE_SUCCESS), createDbRoleSuccess)
  519. this.RegisterState(int32(ROLE_STATE_DB_ADD_ROLE_FAILURE), createDbRoleFailure)
  520. this.RegisterState(int32(ROLE_STATE_SELECT_ROLE), SelectingRole)
  521. this.RegisterState(int32(ROLE_STATE_SELECT_ROLE_SUCCESS), SelectRoleSuccess)
  522. this.RegisterState(int32(ROLE_STATE_ONLINE), RoleOnline)
  523. this.RegisterState(int32(ROLE_STATE_OFFLINE), RoleOffline)
  524. this.roleBattleAttr = newRoleBattleAttr(this)
  525. //this.base = roleBasePool.Get().(*RoleBase)
  526. this.base = newRoleBase()
  527. this.base.role = this
  528. this.roleHero = newRoleHero(this)
  529. this.roleBag = newRoleBag(this)
  530. this.roleEquip = newRoleEquip(this)
  531. this.roleChip = newRoleChip(this)
  532. this.roleMap = newRoleMap(this)
  533. this.roleSkill = newRoleSkill(this)
  534. this.roleCard = newRoleCard(this)
  535. this.roleFashion = newRoleFashion(this)
  536. this.roleBattle = newRoleBattle(this)
  537. this.roleTask = newRoleTask(this)
  538. //this.roleFightPower = newRoleFightPower(this)
  539. this.roleChat = newRoleChat(this)
  540. this.roleArena = newRoleArena(this)
  541. this.roleMail = newRoleMail(this)
  542. this.roleRed = newRoleRed(this)
  543. this.roleShop = newRoleShop(this)
  544. this.roleCompetition = newRoleCompetition(this)
  545. this.roleSocial = newRoleSocial(this)
  546. this.roleActivity = newRoleActivity(this)
  547. this.roleTower = newRoleTower(this)
  548. this.roleGuild = newRoleGuild(this)
  549. this.rolePet = newRolePet(this)
  550. this.roleInvitation = newRoleInvitation(this)
  551. this.roleDraw = newRoleDraw(this)
  552. this.roleRune = newRoleRune(this)
  553. this.roleDaoChang100 = newRoleDaoChang100(this)
  554. this.roleStatistic = newRoleStatistic(this)
  555. this.roleKeepSake = newRoleKeepSake(this)
  556. this.roleCross = newRoleCross(this)
  557. this.roleRush = newRoleRush(this)
  558. this.roleSkillEquip = newRoleSkillEquip(this)
  559. this.roleHead = newRoleHead(this)
  560. this.roleWish = newRoleWish(this)
  561. this.roleBT = newRoleBT(this)
  562. this.soList = append(this.soList,
  563. this.base,
  564. this.roleHero,
  565. this.roleBag,
  566. this.roleCard,
  567. this.roleEquip,
  568. this.roleChip,
  569. this.roleMap,
  570. this.roleMap,
  571. this.roleSkill,
  572. this.roleFashion,
  573. this.roleBattle,
  574. this.roleTask,
  575. this.roleChat,
  576. this.roleArena,
  577. this.roleMail,
  578. this.roleRed,
  579. this.roleShop,
  580. this.roleCompetition,
  581. this.roleSocial,
  582. this.roleActivity,
  583. this.roleTower,
  584. this.roleGuild,
  585. this.rolePet,
  586. this.roleInvitation,
  587. this.roleDraw,
  588. this.roleRune,
  589. this.roleDaoChang100,
  590. this.roleStatistic,
  591. this.roleKeepSake,
  592. this.roleRush,
  593. this.roleCross,
  594. this.roleSkillEquip,
  595. this.roleHead,
  596. this.roleWish,
  597. this.roleBT,
  598. )
  599. }
  600. //func (this *Role) SetIsChallenge(b bool) {
  601. // this.isChallenge = b
  602. //}
  603. //
  604. //func (this *Role) GetIsChallenge() bool {
  605. // return this.isChallenge
  606. //}
  607. func (this *Role) ReqAckConfirm(msgId, seqId uint32) {
  608. this.reqAckConfirmList[msgId] = append(this.reqAckConfirmList[msgId], seqId)
  609. }
  610. func (this *Role) SetOpenId(openId string) {
  611. this.openId = openId
  612. }
  613. func (this *Role) GetOpenId() string {
  614. return this.openId
  615. }
  616. func (this *Role) GetHardFight() int {
  617. return this.isHardFight
  618. }
  619. func (this *Role) GetSdkJson() string {
  620. return this.Guid
  621. }
  622. func (this *Role) SetSdkJson(a string) {
  623. this.Guid = a
  624. }
  625. func (this *Role) SetSelectZone(selectZone int32) {
  626. if selectZone <= 0 {
  627. this.selectZone = int32(service.GetServiceConfig().Node.Zone)
  628. } else {
  629. this.selectZone = selectZone
  630. }
  631. }
  632. func (this *Role) GetSelectZone() int32 {
  633. return this.selectZone
  634. }
  635. func (this *Role) SetPlatform(platform string) {
  636. this.platform = platform
  637. }
  638. func (this *Role) SetHardFight(b int) {
  639. this.isHardFight = b
  640. }
  641. func (this *Role) SetYuanRankScore() {
  642. this.roleCross.roleCrossInfo.Yuanhangtrial.TrialScore = 0
  643. this.roleCross.selfRank = 0
  644. this.roleCross.selfScore = 0
  645. this.roleCross.totalRank = 0
  646. }
  647. func (this *Role) GetPlatform() string {
  648. return this.platform
  649. }
  650. func (this *Role) SetSubPlatform(subPlatform string) {
  651. this.subPlatform = subPlatform
  652. }
  653. func (this *Role) GetSubPlatform() string {
  654. return this.subPlatform
  655. }
  656. func (this *Role) SetClientParam(clientInfo *serverproto.ClientParamInfo) {
  657. if clientInfo == nil {
  658. return
  659. }
  660. if this.clientParamInfo == nil {
  661. this.clientParamInfo = &NeteaseLogCommonInfo{}
  662. }
  663. this.clientParamInfo.DeviceModel = clientInfo.DeviceModel
  664. this.clientParamInfo.DeviceHeight = int(clientInfo.DeviceHeight)
  665. this.clientParamInfo.DeviceWidth = int(clientInfo.DeviceWidth)
  666. this.clientParamInfo.OsName = clientInfo.OsName
  667. this.clientParamInfo.OsVer = clientInfo.OsVer
  668. this.clientParamInfo.MacAddr = clientInfo.MacAddr
  669. this.clientParamInfo.Udid = clientInfo.Udid
  670. this.clientParamInfo.Isp = clientInfo.Isp
  671. this.clientParamInfo.Network = clientInfo.Network
  672. this.clientParamInfo.AppChannel = clientInfo.AppChannel
  673. this.clientParamInfo.AppVer = clientInfo.AppVer
  674. this.clientParamInfo.TransId = clientInfo.TransId
  675. this.clientParamInfo.UnisdkDeviceId = clientInfo.UnisdkDeviceid
  676. this.clientParamInfo.IsEmulator = int(clientInfo.IsEmulator)
  677. this.clientParamInfo.IsRoot = int(clientInfo.IsRoot)
  678. this.clientParamInfo.AccountId = clientInfo.AccountId
  679. this.clientParamInfo.OldAccountId = clientInfo.OldAccountid
  680. this.clientParamInfo.IMEI = clientInfo.IMEI
  681. this.clientParamInfo.CountryCode = clientInfo.CountryCode
  682. this.clientParamInfo.EnterSN = clientInfo.EnterSn
  683. this.clientParamInfo.OAid = clientInfo.Oaid
  684. this.clientParamInfo.EngineVer = clientInfo.EngineVer
  685. this.clientParamInfo.Server = service.GetServiceConfig().Node.Zone*100 + service.GetServiceConfig().Node.Id
  686. }
  687. func (this *Role) GetClientParam() *NeteaseLogCommonInfo {
  688. return this.clientParamInfo
  689. }
  690. func (this *Role) SetClientIP(ip string) {
  691. this.clientIp = ip
  692. if this.clientParamInfo == nil {
  693. this.clientParamInfo = &NeteaseLogCommonInfo{}
  694. }
  695. ipStr := this.GetClientIP()
  696. //先区分是否是IPV6
  697. strList := strings.Split(ipStr, ":")
  698. if len(strList) == 2 {
  699. this.clientParamInfo.IPv4 = strList[0]
  700. } else if len(strList) > 2 {
  701. position := strings.LastIndex(ipStr, ":")
  702. this.clientParamInfo.Ipv6 = ipStr[1 : position-1]
  703. }
  704. }
  705. func (this *Role) GetClientIP() string {
  706. return this.clientIp
  707. }
  708. func (this *Role) DBNode() string {
  709. return this.dbNode
  710. }
  711. func (this *Role) SocialNode() string {
  712. return this.socialNode
  713. }
  714. func (this *Role) AoiNode() string {
  715. //return this.aoiNode
  716. return ""
  717. }
  718. func (this *Role) BossNode() string {
  719. return this.bossNode
  720. }
  721. func (this *Role) RankNode() string {
  722. return this.rankNode
  723. }
  724. func (this *Role) GuildNode() string {
  725. return this.guildNode
  726. }
  727. func (this *Role) CliID() model.ClientID {
  728. return this.cliID
  729. }
  730. func (this *Role) SetCliID(cId model.ClientID) {
  731. this.cliID = cId
  732. }
  733. func (this *Role) SetCliIDSessionID(sessionID uint64) {
  734. this.cliID.SessID = sessionID
  735. }
  736. func (this *Role) setUUid(id uint64) {
  737. this.uuid = id
  738. }
  739. func (this *Role) GetUUid() uint64 {
  740. return this.uuid
  741. }
  742. func (this *Role) GetNickName() string {
  743. return this.GetRoleBase().GetRoleName()
  744. }
  745. func (this *Role) GetImageId() int32 {
  746. return this.GetRoleBase().RoleData().HeadId
  747. }
  748. func (this *Role) SetSelectUUid(id uint64) {
  749. this.SelectedUuid = id
  750. if data, ok := this.UuidRoleList[id]; ok {
  751. this.RegisterTime = data.RegisterTime
  752. }
  753. }
  754. func (this *Role) SetReLogin(re bool) {
  755. this.reLogin = re
  756. if re {
  757. this.isHardFight = 0
  758. }
  759. }
  760. func (this *Role) GetRoleBase() *RoleBase {
  761. return this.base
  762. }
  763. func (this *Role) GetRoleBag() *RoleBag {
  764. return this.roleBag
  765. }
  766. func (this *Role) GetRoleEquip() *RoleEquip {
  767. return this.roleEquip
  768. }
  769. func (this *Role) GetRoleHero() *RoleHero {
  770. return this.roleHero
  771. }
  772. func (this *Role) GetRoleChip() *RoleChip {
  773. return this.roleChip
  774. }
  775. func (this *Role) GetRoleMap() *RoleMap {
  776. return this.roleMap
  777. }
  778. func (this *Role) GetRoleSkill() *RoleSkill {
  779. return this.roleSkill
  780. }
  781. func (this *Role) GetRoleSkillEquip() *RoleSkillEquip {
  782. return this.roleSkillEquip
  783. }
  784. func (this *Role) GetRoleCard() *RoleCard {
  785. return this.roleCard
  786. }
  787. func (this *Role) GetRoleFashion() *RoleFashion {
  788. return this.roleFashion
  789. }
  790. func (this *Role) GetRoleBattle() *RoleBattle {
  791. return this.roleBattle
  792. }
  793. func (this *Role) GetRoleChat() *RoleChat {
  794. return this.roleChat
  795. }
  796. func (this *Role) GetRoleArena() *RoleArena {
  797. return this.roleArena
  798. }
  799. func (this *Role) GetRoleRed() *RoleRed {
  800. return this.roleRed
  801. }
  802. func (this *Role) GetRoleMail() *RoleMail {
  803. return this.roleMail
  804. }
  805. func (this *Role) GetRoleCompetition() *RoleCompetition {
  806. return this.roleCompetition
  807. }
  808. func (this *Role) GetRoleShop() *RoleShop {
  809. return this.roleShop
  810. }
  811. func (this *Role) GetRoleSocial() *RoleSocial {
  812. return this.roleSocial
  813. }
  814. func (this *Role) GetRoleTask() *RoleTask {
  815. return this.roleTask
  816. }
  817. // func (this *Role) GetRoleFightPower1() *RoleFightPower {
  818. // return this.roleFightPower
  819. // }
  820. func (this *Role) GetRoleActivity() *RoleActivity {
  821. return this.roleActivity
  822. }
  823. func (this *Role) GetRoleTower() *RoleTower {
  824. return this.roleTower
  825. }
  826. func (this *Role) GetRoleGuild() *RoleGuild {
  827. return this.roleGuild
  828. }
  829. func (this *Role) GetRolePet() *RolePet {
  830. return this.rolePet
  831. }
  832. func (this *Role) GetRoleInvitation() *RoleInvitation {
  833. return this.roleInvitation
  834. }
  835. func (this *Role) GetRoleDraw() *RoleDraw {
  836. return this.roleDraw
  837. }
  838. func (this *Role) GetRoleRune() *RoleRune {
  839. return this.roleRune
  840. }
  841. func (this *Role) GetRoleDaoChang100() *RoleDaoChang100 {
  842. return this.roleDaoChang100
  843. }
  844. func (this *Role) GetRoleStatistic() *RoleStatistic {
  845. return this.roleStatistic
  846. }
  847. func (this *Role) GetRoleKeepSake() *RoleKeepSake {
  848. return this.roleKeepSake
  849. }
  850. func (this *Role) GetRoleCross() *RoleCross {
  851. return this.roleCross
  852. }
  853. func (this *Role) GetRoleRush() *RoleRush {
  854. return this.roleRush
  855. }
  856. func (this *Role) GetRoleBT() *RoleBT {
  857. return this.roleBT
  858. }
  859. func (this *Role) SetCreateData(msg *serverproto.CSCreateRoleReq) {
  860. this.base.roleBase.Sex = msg.Sex
  861. this.base.roleBase.Country = msg.Country
  862. //JobId
  863. this.base.roleBase.RoleData.HeroData.ConfigId = msg.JobId
  864. this.base.roleBase.FashionData.Hair = msg.Hair
  865. this.base.roleBase.FashionData.HairAvatar = msg.HairAvatar
  866. this.base.roleBase.FashionData.Eye = msg.Eye
  867. if msg.Head != 0 {
  868. this.base.roleBase.FashionData.FashionUpList =
  869. append(this.base.roleBase.FashionData.FashionUpList, msg.Head)
  870. }
  871. this.activeCode = msg.ActiveCode
  872. }
  873. func (this *Role) IsLogout(ms uint64) bool {
  874. return this.offlineTimer.IsStart() && this.offlineTimer.IsExpired(ms)
  875. }
  876. func (this *Role) isBan() uint64 {
  877. if this.GetRoleBase().roleBase != nil && this.GetRoleBase().roleBase.BanTime > uint64(util.GetTimeSeconds()) {
  878. delTime := this.GetRoleBase().roleBase.BanTime - uint64(util.GetTimeSeconds())
  879. return delTime
  880. }
  881. return 0
  882. }
  883. func (this *Role) BanRole(isBan bool, banTime uint64, cheatType int32) {
  884. if this.GetRoleBase().roleBase == nil {
  885. util.InfoF("BanRole isBan=%v err=rolebase is nil", isBan)
  886. return
  887. }
  888. if banTime <= 0 {
  889. banTime = 24 * 60 * 60
  890. }
  891. if isBan {
  892. this.GetRoleBase().roleBase.BanTime = uint64(util.GetTimeSeconds()) + banTime
  893. this.GetRoleBase().roleBase.BanType = cheatType
  894. this.GetRoleBase().SetDirty(true)
  895. //作弊方式封号
  896. ssMsg := &serverproto.SSGameBanRoleNtf{
  897. BanUid: this.GetUUid(),
  898. BanEndTime: this.GetRoleBase().roleBase.BanTime,
  899. BanType: 1, //1封号,2禁言
  900. }
  901. this.SendDb(ssMsg)
  902. errCode := this.roleStatistic.GetCheatErrorCode(cheatType)
  903. this.KickWithSaveAndBan(errCode, banTime)
  904. } else {
  905. if this.GetRoleBase().roleBase.BanTime > 0 {
  906. this.GetRoleBase().roleBase.BanTime = 0
  907. this.GetRoleBase().roleBase.BanType = 0
  908. this.GetRoleBase().SetDirty(true)
  909. //清空作弊数据
  910. if this.GetRoleStatistic() != nil {
  911. this.GetRoleStatistic().ClearCheatData()
  912. }
  913. }
  914. }
  915. }
  916. // 禁言
  917. func (this *Role) BanRoleChat(isBan bool, banTime uint64, cheatType int32) {
  918. if this.GetRoleBase().roleBase == nil {
  919. util.InfoF("BanRole isBan=%v err=rolebase is nil", isBan)
  920. return
  921. }
  922. if banTime <= 0 {
  923. banTime = 24 * 60 * 60
  924. }
  925. if isBan {
  926. this.GetRoleBase().roleBase.ChatBanTime = uint64(util.GetTimeSeconds()) + banTime
  927. this.GetRoleBase().roleBase.ChatBanType = cheatType
  928. this.GetRoleBase().SetDirty(true)
  929. //禁言
  930. ssMsg := &serverproto.SSGameBanRoleNtf{
  931. BanUid: this.GetUUid(),
  932. BanEndTime: this.GetRoleBase().roleBase.BanTime,
  933. BanType: 2, //1封号,2禁言
  934. }
  935. this.SendDb(ssMsg)
  936. util.InfoF("uid=%v BanRoleChat endtime=%v", this.GetUUid(), this.GetRoleBase().roleBase.ChatBanTime)
  937. } else {
  938. if this.GetRoleBase().roleBase.ChatBanTime > 0 {
  939. this.GetRoleBase().roleBase.ChatBanTime = 0
  940. this.GetRoleBase().roleBase.ChatBanType = 0
  941. this.GetRoleBase().SetDirty(true)
  942. //清空作弊数据
  943. if this.GetRoleStatistic() != nil {
  944. this.GetRoleStatistic().ClearCheatData()
  945. }
  946. }
  947. }
  948. }
  949. // 来自gmweb的删除背包道具操作
  950. func (this *Role) WebGMDelItem(delItemList []*serverproto.KeyValueType) {
  951. util.InfoF("uid=%v WebGMDelItem delitemlist=%v", this.uuid, delItemList)
  952. for idx := 0; idx < len(delItemList); idx++ {
  953. this.GetRoleBag().DelItem(delItemList[idx].Key, delItemList[idx].Value, AddItemST{
  954. AddFrom: AddFrom_System,
  955. })
  956. }
  957. }
  958. func (this *Role) KickNotSave(err int32) {
  959. //通知gate踢人,并且不再反向通知logic服务器
  960. kickNtf := &serverproto.SSUserKickNtf{
  961. Error: err,
  962. ClientId: this.CliID().SessID,
  963. }
  964. this.ReplayGate(kickNtf, false)
  965. util.InfoF("uid=%v sessionID=%v KickNotSave game kick user err=%v", this.GetUUid(), this.CliID().SessID, err)
  966. this.SwitchState(ROLE_STATE_ZOMBIE, nil)
  967. }
  968. func (this *Role) KickWithSave(err int32) {
  969. //通知gate踢人,并且不再反向通知logic服务器
  970. kickNtf := &serverproto.SSUserKickNtf{
  971. Error: err,
  972. ClientId: this.CliID().SessID,
  973. }
  974. this.ReplayGate(kickNtf, false)
  975. util.InfoF("uid=%v sessionID=%v KickWithSave game kick user err=%v", this.GetUUid(), this.CliID().SessID, err)
  976. this.SwitchState(ROLE_STATE_OFFLINE, nil)
  977. }
  978. func (this *Role) KickWithSaveAndBan(err int32, banEndTime uint64) {
  979. //通知gate踢人,并且不再反向通知logic服务器
  980. kickNtf := &serverproto.SSUserKickNtf{
  981. Error: err,
  982. ClientId: this.CliID().SessID,
  983. BanEndTime: banEndTime,
  984. }
  985. this.ReplayGate(kickNtf, false)
  986. util.InfoF("uid=%v sessionID=%v KickWithSaveAndBan game kick user", this.GetUUid(), this.CliID().SessID)
  987. this.SwitchState(ROLE_STATE_OFFLINE, nil)
  988. }
  989. func (this *Role) Load(role *serverproto.Role) error {
  990. if this.reLogin && this.isLoad {
  991. //已经加载过
  992. return nil
  993. }
  994. //每个系统类型信息加载
  995. for _, data := range this.soList {
  996. if !data.Load(role) {
  997. return errors.New(fmt.Sprintf("uid=%v load savedObject module=%v failed",
  998. this.GetUUid(), reflect.TypeOf(data).Elem().Name()))
  999. }
  1000. }
  1001. this.isLoad = true
  1002. return nil
  1003. }
  1004. func (this *Role) LoadOther(msg interface{}) error {
  1005. //主角基本数据还未加载
  1006. if !this.isLoad {
  1007. return nil
  1008. }
  1009. switch m := msg.(type) {
  1010. //在登陆流程中
  1011. case *serverproto.SSLoadArenaNtf:
  1012. if this.roleArena != nil {
  1013. if !this.roleArena.LoadOther(m.RoleArena) {
  1014. return errors.New(fmt.Sprintf("uid=%v load SSLoadArenaNtf failed", this.GetUUid()))
  1015. }
  1016. }
  1017. case *serverproto.SSLoadMailNtf:
  1018. if this.roleMail != nil {
  1019. if !this.roleMail.LoadOther(m.Mail) {
  1020. return errors.New(fmt.Sprintf("uid=%v load SSLoadMailNtf failed", this.GetUUid()))
  1021. }
  1022. }
  1023. case *serverproto.SSLoadFriendDataNtf:
  1024. if this.roleSocial != nil {
  1025. if !this.roleSocial.LoadOther(m.Friend) {
  1026. return errors.New(fmt.Sprintf("uid=%v SSLoadFriendDataNtf failed", this.GetUUid()))
  1027. }
  1028. }
  1029. case *serverproto.SSLoadPetNtf:
  1030. if this.rolePet != nil {
  1031. if !this.rolePet.LoadOther(m) {
  1032. return errors.New(fmt.Sprintf("uid=%v SSLoadPetNtf failed", this.GetUUid()))
  1033. }
  1034. }
  1035. case *serverproto.SSLoadInvitationDataNtf:
  1036. if this.roleInvitation != nil {
  1037. if !this.roleInvitation.LoadOther(m.InvitationInfo) {
  1038. return errors.New(fmt.Sprintf("uid=%v SSLoadInvitationDataNtf failed", this.GetUUid()))
  1039. }
  1040. }
  1041. case *serverproto.SSLoadCrossDataNtf:
  1042. if this.roleCross != nil {
  1043. if !this.roleCross.LoadOther(m.LoadData) {
  1044. return errors.New(fmt.Sprintf("uid=%v SSLoadCrossDataNtf failed", this.GetUUid()))
  1045. }
  1046. }
  1047. default:
  1048. return errors.New(fmt.Sprintf("uid=%v load unkonw model !!!", this.GetUUid()))
  1049. //不在登陆流程中,后续通过协议主动获取
  1050. }
  1051. return nil
  1052. }
  1053. func (this *Role) Save() {
  1054. if !this.isLoad {
  1055. return
  1056. }
  1057. bSave := false
  1058. if this.GetState() == ROLE_STATE_ONLINE || this.GetState() == ROLE_STATE_OFFLINE {
  1059. for _, data := range this.soList {
  1060. //data.(*SaveObject).IsDirty()
  1061. if data.IsDirty() {
  1062. data.Save()
  1063. bSave = true
  1064. }
  1065. }
  1066. }
  1067. if bSave {
  1068. //最后save时间戳
  1069. this.lastProcessTime = util.GetTimeMilliseconds()
  1070. }
  1071. }
  1072. func (this *Role) Update(ms uint64) {
  1073. if this.GetState() == ROLE_STATE_ZOMBIE {
  1074. return
  1075. }
  1076. //放到time wheel中处理
  1077. //if this.saveTimer.IsStart() && this.saveTimer.IsExpired(ms) {
  1078. // this.Save()
  1079. //}
  1080. //活动数据更新定时器相关代码
  1081. if this.dailyResetTimer.IsStart() && this.dailyResetTimer.IsExpired(ms) {
  1082. //update过程中玩家已经通过上下线进行了重置操作
  1083. this.DailyReset(true)
  1084. ResetCount++
  1085. this.dailyResetTimer.Cancel()
  1086. }
  1087. this.roleArena.Update(ms)
  1088. this.roleMail.Update(ms)
  1089. if this.base == nil {
  1090. util.WarnF("uid=%v Role.Update skip: base==nil", this.GetUUid())
  1091. } else {
  1092. this.GetRoleBase().Update(ms)
  1093. }
  1094. this.roleTower.Update(ms)
  1095. this.roleRune.Update(ms)
  1096. this.roleHead.Update(ms)
  1097. this.roleWish.Update(ms)
  1098. if this.mysqlLogSaveTimer.IsStart() && this.mysqlLogSaveTimer.IsExpired(ms) {
  1099. this.saveMysqlLog()
  1100. }
  1101. ////1小时无任何保存操作,直接设置成离线状态
  1102. //if ms > this.lastProcessTime && this.lastProcessTime > 0 && ms-this.lastProcessTime > 60*60*1000 {
  1103. // if this.GetState() == ROLE_STATE_ONLINE {
  1104. // this.SwitchState(ROLE_STATE_OFFLINE, nil)
  1105. // util.DebugF("uid=%v online->offline", this.GetUUid())
  1106. // }
  1107. //}
  1108. }
  1109. func (this *Role) isDailyReset() bool {
  1110. if this.GetRoleBase().roleBase.DailyResetTimeStamp <= 0 {
  1111. this.GetRoleBase().roleBase.DailyResetTimeStamp = this.GetRoleBase().RoleData().LastLoginTime
  1112. }
  1113. return model.IsDailyResetHour5(this.GetRoleBase().roleBase.DailyResetTimeStamp)
  1114. //return model.IsDailyResetHour5(this.GetRoleBase().RoleData().LastLoginTime)
  1115. }
  1116. func (this *Role) DailyReset(notify bool) {
  1117. //加载完成后做重置操作
  1118. util.ErrorF("uid=%v daily reset nickname=%s", this.GetUUid(), this.GetNickName())
  1119. oldDailyResetTimeStamp := this.GetRoleBase().roleBase.DailyResetTimeStamp
  1120. this.roleArena.DailyReset(notify)
  1121. //this.roleTower.DailyReset(notify)
  1122. this.roleBattle.DailyReset(notify)
  1123. this.roleMap.DailyReset(notify)
  1124. this.roleTask.DailyReset(notify, oldDailyResetTimeStamp)
  1125. this.roleSkill.DailyReset(notify)
  1126. this.roleGuild.DailyReset(notify)
  1127. this.roleShop.DailyReset(notify)
  1128. this.roleActivity.DailyReset(notify)
  1129. this.roleInvitation.DailyReset(notify)
  1130. this.roleRune.DailyReset(notify)
  1131. this.roleDaoChang100.DailyReset(notify)
  1132. this.roleCross.DailyReset(notify, oldDailyResetTimeStamp)
  1133. this.roleHead.DailyReset(notify)
  1134. this.roleCompetition.DailyReset(notify)
  1135. this.roleBT.DailyReset(notify, oldDailyResetTimeStamp)
  1136. //最后重置,切记!
  1137. this.GetRoleBase().DailyReset(notify)
  1138. }
  1139. func (this *Role) SetUpdateDailyReset(ms uint64, bReset bool) {
  1140. //已经重置不需要再次重置
  1141. if !this.isDailyReset() {
  1142. return
  1143. }
  1144. randNum := rand.Int31n(3000)
  1145. this.dailyResetTimer.Reset(ms, time.Duration(randNum), false)
  1146. }
  1147. func (this *Role) FuncDisable() bool {
  1148. //RobotMode 1:机器人模式 2:无法注册 3:关闭付费功能
  1149. if service.GetServiceConfig().Node.RobotMode == 3 {
  1150. return true
  1151. }
  1152. return false
  1153. }
  1154. // 推送客户端启动时需要的信息,例如基本信息,背包信息等
  1155. func (this *Role) StartupProto() {
  1156. // todo 测试使用
  1157. time.Sleep(200 * time.Millisecond)
  1158. nowTime := util.GetTimeMilliseconds()
  1159. startUpTime := service.GetServiceStartupTime()
  1160. ntfMsg := &serverproto.SCStartupInfoNtf{
  1161. ServerTime: nowTime,
  1162. CreateTime: this.RegisterTime,
  1163. FuncDisable: this.FuncDisable(),
  1164. ServiceStartTime: startUpTime,
  1165. }
  1166. //角色基础信息
  1167. ntfMsg.RoleBase = &serverproto.RoleBase{}
  1168. this.GetRoleBase().CopyData(ntfMsg.RoleBase)
  1169. //小红点信息
  1170. ntfMsg.RoleRed = this.roleRed.redInfo
  1171. //伙伴
  1172. ntfMsg.RoleHero = &serverproto.RoleHero{}
  1173. this.roleHero.CopyData(ntfMsg.RoleHero)
  1174. //背包
  1175. ntfMsg.RoleBag = &serverproto.RoleBag{}
  1176. this.roleBag.CopyData(ntfMsg.RoleBag)
  1177. // 许愿箱
  1178. ntfMsg.RoleWishBox = &serverproto.RoleWish{}
  1179. this.roleWish.CopyData(ntfMsg.RoleWishBox)
  1180. // 特殊处理
  1181. ntfMsg.RoleBase.BtJiaDayRecharge = int32(float32(ntfMsg.RoleBase.BtJiaDayRecharge) * BTJiaChangeDollar)
  1182. ntfMsg.RoleBase.BtJiaTotalRecharge = uint64(float32(ntfMsg.RoleBase.BtJiaTotalRecharge) * BTJiaChangeDollar)
  1183. //分成多条协议进行发送
  1184. sendLen := this.ReplayGate(ntfMsg, true)
  1185. ntfMsg = &serverproto.SCStartupInfoNtf{
  1186. ServerTime: nowTime,
  1187. CreateTime: this.RegisterTime,
  1188. FuncDisable: this.FuncDisable(),
  1189. ServiceStartTime: startUpTime,
  1190. }
  1191. //碎片
  1192. ntfMsg.RoleChip = &serverproto.RoleChip{}
  1193. this.roleChip.CopyData(ntfMsg.RoleChip)
  1194. //时装
  1195. ntfMsg.RoleFashion = &serverproto.RoleFashion{}
  1196. //this.roleFashion.CopyDatatmp(ntfMsg.RoleFashion)
  1197. this.roleFashion.CopyData(ntfMsg.RoleFashion)
  1198. //战斗数据
  1199. ntfMsg.RoleBattle = &serverproto.RoleBattle{}
  1200. this.roleBattle.CopyData(ntfMsg.RoleBattle)
  1201. //私聊消息列表
  1202. ntfMsg.RoleChat = &serverproto.RoleChat{}
  1203. this.roleChat.CopyData(ntfMsg.RoleChat)
  1204. //rolemap
  1205. ntfMsg.RoleMap = this.roleMap.CopyData()
  1206. ntfMsg.RoleTower = &serverproto.RoleTower{}
  1207. this.roleTower.CopyData(ntfMsg.RoleTower)
  1208. //任务模块
  1209. ntfMsg.RoleTask = this.roleTask.CopyData()
  1210. ntfMsg.RoleDraw = &serverproto.RoleDraw{}
  1211. this.roleDraw.CopyData(ntfMsg.RoleDraw)
  1212. //赛季玩法数据
  1213. ntfMsg.RoleCompetition = &serverproto.RoleCompetition{}
  1214. this.roleCompetition.CopyData(ntfMsg.RoleCompetition)
  1215. //百人道场
  1216. ntfMsg.RoleDaochang100 = &serverproto.RoleDaoChang100{}
  1217. this.roleDaoChang100.CopyData(ntfMsg.RoleDaochang100)
  1218. //战斗力值
  1219. ntfMsg.RoleFightpower = &serverproto.FightPowerData{}
  1220. //this.roleFightPower.CopyData(ntfMsg.RoleFightpower)
  1221. this.roleBattleAttr.CopyData(ntfMsg.RoleFightpower)
  1222. // BT
  1223. ntfMsg.RoleBt = &serverproto.RoleBT{}
  1224. this.roleBT.CopyData(ntfMsg.RoleBt)
  1225. //RobotMode 1:机器人模式 2:无法注册 3:关闭付费功能
  1226. ntfMsg.FuncDisable = this.FuncDisable()
  1227. //分成多条协议进行发送
  1228. sendLen = this.ReplayGate(ntfMsg, true) + sendLen
  1229. ntfMsg = &serverproto.SCStartupInfoNtf{
  1230. ServerTime: nowTime,
  1231. CreateTime: this.RegisterTime,
  1232. FuncDisable: this.FuncDisable(),
  1233. ServiceStartTime: startUpTime,
  1234. }
  1235. //跨服个人数据
  1236. ntfMsg.RoleCross = &serverproto.RoleCross{}
  1237. this.roleCross.CopyData(ntfMsg.RoleCross)
  1238. ntfMsg.RoleSkillEquip = &serverproto.RoleSkillEquip{}
  1239. this.roleSkillEquip.CopyData(ntfMsg.RoleSkillEquip)
  1240. sendLen = this.ReplayGate(ntfMsg, true) + sendLen
  1241. this.tmpState = false
  1242. util.DebugF("uid=%v StartupProto ntfMsgLen=%v", this.GetUUid(), sendLen)
  1243. storyNtf := &serverproto.SCRoleStoryNtf{}
  1244. this.GetRoleBase().CopyStoryData(storyNtf)
  1245. this.ReplayGate(storyNtf, true)
  1246. //通知最近世界聊天信息
  1247. if this.roleChat != nil {
  1248. this.roleChat.WorldMsgNtf()
  1249. }
  1250. //走马灯公告
  1251. RoleMag.NoticeInfoNtf(this)
  1252. //装备
  1253. equipNtfMsg := &serverproto.SCStartupInfoEquipNtf{
  1254. RoleEquipInfo: &serverproto.RoleEquip{},
  1255. }
  1256. this.roleEquip.CopyData(equipNtfMsg.RoleEquipInfo)
  1257. sendLen = this.ReplayGate(equipNtfMsg, true)
  1258. util.DebugF("uid=%v StartupProto ntfMsgLen=%v equip", this.GetUUid(), sendLen)
  1259. //卡片
  1260. cardNtfMsg := &serverproto.SCStartupInfoCardNtf{
  1261. RoleCardInfo: &serverproto.RoleCard{},
  1262. }
  1263. this.roleCard.CopyData(cardNtfMsg.RoleCardInfo)
  1264. sendLen = this.ReplayGate(cardNtfMsg, true)
  1265. util.DebugF("uid=%v StartupProto ntfMsgLen=%v card", this.GetUUid(), sendLen)
  1266. //pet
  1267. this.rolePet.StartupNtf()
  1268. //精彩活动
  1269. this.roleActivity.StartupNtf()
  1270. //邀请码系统
  1271. this.roleInvitation.StartupNtf()
  1272. //初始化结束函数标志
  1273. endMsgNtf := &serverproto.SCStartupInfoEndNtf{}
  1274. this.ReplayGate(endMsgNtf, true)
  1275. this.GetRoleRune().GetFreeGoodsData()
  1276. this.CombineServerNtf()
  1277. }
  1278. // 上线处理
  1279. func (this *Role) onlineProcess(bRelogin bool) {
  1280. //清空缓存列表
  1281. this.reqAckConfirmList = map[uint32][]uint32{}
  1282. this.GetRoleBase().OnlineProcess()
  1283. if this.roleArena != nil {
  1284. this.roleArena.OnlineProcess()
  1285. }
  1286. if this.roleCross != nil {
  1287. this.roleCross.OnlineProcess()
  1288. }
  1289. if this.roleTower != nil {
  1290. this.roleTower.OnlineProcess()
  1291. }
  1292. if this.roleBattle != nil {
  1293. this.roleBattle.OnlineProcess()
  1294. }
  1295. if this.rolePet != nil {
  1296. this.rolePet.OnlineProcess()
  1297. }
  1298. if this.roleRush != nil {
  1299. this.roleRush.OnlineProcess()
  1300. }
  1301. if this.roleTask != nil {
  1302. this.roleTask.OnlineProcess()
  1303. }
  1304. if this.roleActivity != nil {
  1305. this.roleActivity.OnlineProcess()
  1306. }
  1307. if this.roleHead != nil {
  1308. this.roleHead.OnlineProcess()
  1309. }
  1310. // 上线获取赛季奖励处理
  1311. if this.roleCompetition != nil {
  1312. this.roleCompetition.OnlineGetCompetitionReward()
  1313. }
  1314. //上线日志记录
  1315. model.ElasticPutLogInfo(&model.ElasticLogST{
  1316. Uid: this.GetUUid(),
  1317. NickName: this.GetNickName(),
  1318. OpenId: this.GetOpenId(),
  1319. LogType: "RoleOnline",
  1320. LogDesc: "RoleOnline",
  1321. })
  1322. this.MysqlLogNtf(serverproto.MysqlLogType_LType_Online, nil, 0)
  1323. //更新简介信息中的离线时间(上线时也进行一次时间更新)
  1324. this.GetRoleBase().UpdatePlayerBriefInfo(false)
  1325. //获取离线信息玩家列表
  1326. ssOfflineMsg := &serverproto.SSChatOfflinePlayerReq{}
  1327. this.SendDb(ssOfflineMsg)
  1328. //后续功能往后加,,尽量不要影响上面的逻辑
  1329. this.GetRoleGuild().GuildBattleOnline()
  1330. }
  1331. func (this *Role) Logout() {
  1332. this.Save()
  1333. //清空角色信息数据
  1334. if this.base != nil {
  1335. //roleBasePool.Put(this.base)
  1336. this.base = nil
  1337. //删除连接信息
  1338. delConnInfo := &serverproto.SSSaveUserConnectInfo{
  1339. OpenId: this.GetOpenId(),
  1340. Platform: this.GetPlatform(),
  1341. }
  1342. this.SendDb(delConnInfo)
  1343. }
  1344. this.roleHero = nil
  1345. this.roleBag = nil
  1346. this.roleChip = nil
  1347. this.roleEquip = nil
  1348. this.roleMap = nil
  1349. this.roleSkill = nil
  1350. this.roleCard = nil
  1351. this.roleFashion = nil
  1352. this.roleBattle = nil
  1353. this.soList = this.soList[:0]
  1354. }
  1355. func (this *Role) BaseChangeNtf() {
  1356. this.base.BaseChangeNtf()
  1357. }
  1358. func (this *Role) MysqlLogNtf(logType serverproto.MysqlLogType, paramList []int32, subType int32) {
  1359. logData := &serverproto.SSRoleLogData{
  1360. Uid: this.GetUUid(),
  1361. Type: int32(logType),
  1362. SubType: subType,
  1363. ParamList: paramList, //oldval,newval,delval,param
  1364. }
  1365. if logType == serverproto.MysqlLogType_LType_Online {
  1366. if this.GetClientParam() != nil {
  1367. logData.StrList = append(logData.StrList, this.GetClientParam().DeviceModel)
  1368. }
  1369. logData.StrList = append(logData.StrList, this.GetClientIP())
  1370. }
  1371. this.mysqlLogList = append(this.mysqlLogList, logData)
  1372. //mysqlNtf := &serverproto.SSRoleLogNtf{}
  1373. //mysqlNtf.LogList = append(mysqlNtf.LogList, logData)
  1374. //
  1375. //this.SendDb(mysqlNtf)
  1376. }
  1377. func (this *Role) AddMysqlLog(logData *serverproto.SSRoleLogData) {
  1378. this.mysqlLogList = append(this.mysqlLogList, logData)
  1379. }
  1380. func (this *Role) saveMysqlLog() {
  1381. if len(this.mysqlLogList) > 0 {
  1382. mysqlNtf := &serverproto.SSRoleLogNtf{}
  1383. mysqlNtf.LogList = append(mysqlNtf.LogList, this.mysqlLogList...)
  1384. this.SendDb(mysqlNtf)
  1385. this.mysqlLogList = this.mysqlLogList[:0]
  1386. }
  1387. }
  1388. func (this *Role) AddRmb(st AddItemST, add bool) {
  1389. this.base.AddRMB(st, add)
  1390. }
  1391. func (this *Role) GetRmb() uint32 {
  1392. return this.base.GetRmb()
  1393. }
  1394. func (this *Role) AddMoney(st AddItemST, add bool) {
  1395. this.base.AddMoney(st, add)
  1396. }
  1397. func (this *Role) GetMoney() uint64 {
  1398. return this.base.GetMoney()
  1399. }
  1400. func (this *Role) AddHeroExp(st AddItemST, add bool) bool {
  1401. this.base.AddHeroExp(st, add)
  1402. return true
  1403. }
  1404. func (this *Role) AddCruise(st AddItemST, add bool) bool {
  1405. this.base.AddCruise(st, add)
  1406. return true
  1407. }
  1408. // 增加角色基础经验
  1409. func (this *Role) AddBaseExp(st AddItemST) bool {
  1410. //添加属性涉及到升级操作(自动升级)
  1411. this.base.AddBaseExp(st)
  1412. return true
  1413. }
  1414. // 增加职业经验
  1415. func (this *Role) AddJobExp(st AddItemST) bool {
  1416. this.base.AddJobExp(st)
  1417. return false
  1418. }
  1419. func (this *Role) GetRoleLevel() int32 {
  1420. return this.GetRoleBase().GetRoleLevel()
  1421. }
  1422. func (this *Role) GetJobLevel() int32 {
  1423. return this.GetRoleBase().GetRoleJobLevel()
  1424. }
  1425. // 创建角色开始的累计充值
  1426. func (this *Role) GetTotalRecharge() float32 {
  1427. return this.GetRoleBase().GetRoleTotalRecharge()
  1428. }
  1429. // 每日累计充值
  1430. func (this *Role) GetDayRecharge() float32 {
  1431. return this.GetRoleBase().roleBase.DayRecharge
  1432. }
  1433. // bt每日累计充值(真累计充值+假累计充值)
  1434. func (this *Role) GetBTDayRecharge() float32 {
  1435. return this.GetBTZhenDayRecharge() + this.GetBTJiaDayRecharge()
  1436. }
  1437. func (this *Role) GetBTZhenDayRecharge() float32 {
  1438. return this.GetRoleBase().roleBase.BtZhenDayRecharge
  1439. }
  1440. func (this *Role) GetBTJiaDayRecharge() float32 {
  1441. return float32(this.GetRoleBase().roleBase.BtJiaDayRecharge) * BTJiaChangeDollar
  1442. }
  1443. func (this *Role) GetBTJiaTotalRecharge() float32 {
  1444. return float32(this.GetRoleBase().roleBase.BtJiaTotalRecharge) * BTJiaChangeDollar
  1445. }
  1446. // 添加通用资源
  1447. func (this *Role) addCommonRes(resType int32, st AddItemST, add bool) {
  1448. this.base.AddCommonRes(resType, st, add)
  1449. }
  1450. func (this *Role) getCommonResNum(resType int32) int32 {
  1451. return this.base.GetCommonRes(resType)
  1452. }
  1453. func (this *Role) getChipResNum(resType int32) uint32 {
  1454. return this.roleChip.getChipResNum(resType)
  1455. }
  1456. func (this *Role) AddRes(resType int32, st AddItemST, add bool) {
  1457. switch serverproto.ResType(resType) {
  1458. case serverproto.ResType_Res_Coin:
  1459. this.AddMoney(st, add)
  1460. case serverproto.ResType_Res_Rmb:
  1461. this.AddRmb(st, add)
  1462. case serverproto.ResType_Res_RoleBaseExp:
  1463. this.AddBaseExp(st)
  1464. case serverproto.ResType_Res_RoleJobExp:
  1465. this.AddJobExp(st)
  1466. case serverproto.ResType_Res_HeroBaseExp:
  1467. this.AddHeroExp(st, add)
  1468. case serverproto.ResType_Res_Cruise:
  1469. this.AddCruise(st, add)
  1470. //添加通用资源
  1471. case serverproto.ResType_Res_Sprite:
  1472. fallthrough
  1473. case serverproto.ResType_Res_Reslove:
  1474. fallthrough
  1475. case serverproto.ResType_Res_EvilExp:
  1476. fallthrough
  1477. case serverproto.ResType_Res_Guild:
  1478. fallthrough
  1479. case serverproto.ResType_Res_DaoChang100:
  1480. fallthrough
  1481. case serverproto.ResType_Res_VipExp:
  1482. fallthrough
  1483. case serverproto.ResType_Res_Guild_Battle:
  1484. fallthrough
  1485. case serverproto.ResType_Res_PetCoin:
  1486. fallthrough
  1487. case serverproto.ResType_Res_PetExp:
  1488. fallthrough
  1489. case serverproto.ResType_Res_HightSkillExp:
  1490. fallthrough
  1491. case serverproto.ResType_Res_PetLevelUP_Exp:
  1492. fallthrough
  1493. case serverproto.ResType_Res_CreditRecharge:
  1494. fallthrough
  1495. case serverproto.ResType_Res_ROCoin:
  1496. fallthrough
  1497. case serverproto.ResType_Res_BoliShopExp:
  1498. this.addCommonRes(resType, st, add)
  1499. case serverproto.ResType_Res_RushMap:
  1500. this.GetRoleBattle().OnRushMapScoreChange(st.ItemCount, 0)
  1501. default:
  1502. }
  1503. this.GetRoleBase().SetDirty(true)
  1504. }
  1505. func (this *Role) GetResNum(resId int32) uint64 {
  1506. cfgData, ok := serverproto.ItemCfgLoader[resId]
  1507. if !ok {
  1508. util.InfoF("uid=%v item cfg data not found resid=%v", this.GetUUid(), resId)
  1509. return 0
  1510. }
  1511. switch serverproto.ResType(cfgData.ResType) {
  1512. case serverproto.ResType_Res_Coin:
  1513. return this.GetMoney()
  1514. case serverproto.ResType_Res_Rmb:
  1515. return uint64(this.GetRmb())
  1516. case serverproto.ResType_Res_RoleBaseExp:
  1517. return uint64(this.GetRoleBase().GetRoleBaseExp())
  1518. case serverproto.ResType_Res_HeroBaseExp:
  1519. return uint64(this.GetRoleBase().GetHeroBaseExp())
  1520. case serverproto.ResType_Res_RoleJobExp:
  1521. return uint64(this.GetRoleBase().GetRoleJobExp())
  1522. case serverproto.ResType_Res_Cruise:
  1523. return uint64(this.GetRoleBase().GetCruise())
  1524. case serverproto.ResType_Res_Sprite:
  1525. fallthrough
  1526. case serverproto.ResType_Res_Reslove:
  1527. fallthrough
  1528. case serverproto.ResType_Res_EvilExp:
  1529. fallthrough
  1530. case serverproto.ResType_Res_Guild:
  1531. fallthrough
  1532. case serverproto.ResType_Res_DaoChang100:
  1533. fallthrough
  1534. case serverproto.ResType_Res_VipExp:
  1535. fallthrough
  1536. case serverproto.ResType_Res_Guild_Battle:
  1537. fallthrough
  1538. case serverproto.ResType_Res_PetCoin:
  1539. fallthrough
  1540. case serverproto.ResType_Res_PetExp:
  1541. fallthrough
  1542. case serverproto.ResType_Res_HightSkillExp:
  1543. fallthrough
  1544. case serverproto.ResType_Res_PetLevelUP_Exp:
  1545. fallthrough
  1546. case serverproto.ResType_Res_CreditRecharge:
  1547. fallthrough
  1548. case serverproto.ResType_Res_ROCoin:
  1549. fallthrough
  1550. case serverproto.ResType_Res_BoliShopExp:
  1551. return uint64(this.getCommonResNum(resId))
  1552. //背包中
  1553. case serverproto.ResType_Res_SkillBook:
  1554. fallthrough
  1555. case serverproto.ResType_Res_Item:
  1556. fallthrough
  1557. case serverproto.ResType_Res_HeadFrame:
  1558. fallthrough
  1559. case serverproto.ResType_Res_QuickBattle:
  1560. fallthrough
  1561. case serverproto.ResType_Res_CashTicket:
  1562. fallthrough
  1563. case serverproto.ResType_Res_Gift:
  1564. return uint64(this.GetItemNum(resId))
  1565. case serverproto.ResType_Res_Chip:
  1566. return uint64(this.getChipResNum(resId))
  1567. case serverproto.ResType_Res_Equip:
  1568. fallthrough
  1569. case serverproto.ResType_Res_Fashion:
  1570. fallthrough
  1571. case serverproto.ResType_Res_Skill_Equip:
  1572. fallthrough
  1573. default:
  1574. return 0
  1575. }
  1576. }
  1577. func (this *Role) CheckResNum(resTypeList map[int32]int32) (bool, int32) {
  1578. for resType, resValue := range resTypeList {
  1579. if this.GetResNum(resType) < uint64(resValue) {
  1580. return false, resType
  1581. }
  1582. }
  1583. return true, 0
  1584. }
  1585. func (this *Role) CheckResLitNum(resTypeList map[int32]int32) bool {
  1586. for resType, resValue := range resTypeList {
  1587. if this.GetResNum(resType) < uint64(resValue) {
  1588. return false
  1589. }
  1590. }
  1591. return true
  1592. }
  1593. func (this *Role) CanAddItemList(resTypeList map[int32]int32) serverproto.ErrorCode {
  1594. if this.GetRoleBag() != nil {
  1595. return this.GetRoleBag().CanAddItemList(resTypeList)
  1596. }
  1597. return serverproto.ErrorCode_ERROR_FAIL
  1598. }
  1599. func (this *Role) AddItemList(resTypeList map[int32]int32, addFrom AddFromType, notify bool) {
  1600. if this.GetRoleBag() != nil {
  1601. this.GetRoleBag().AddItemList(resTypeList, AddItemST{AddFrom: addFrom, Notify: notify})
  1602. }
  1603. }
  1604. func (this *Role) AddItem(configId int32, count int32, addFrom AddFromType) {
  1605. if this.roleBag != nil {
  1606. this.roleBag.AddItem(configId, count, AddItemST{AddFrom: addFrom, Notify: true})
  1607. }
  1608. }
  1609. func (this *Role) DelItemList(resTypeList map[int32]int32, delFrom AddItemST) {
  1610. if this.GetRoleBag() != nil {
  1611. this.GetRoleBag().DelItemList(resTypeList, delFrom)
  1612. }
  1613. }
  1614. func (this *Role) DelItem(configId int32, count int32, delFrom AddItemST) {
  1615. if this.roleBag != nil {
  1616. this.roleBag.DelItem(configId, count, delFrom)
  1617. }
  1618. }
  1619. // 根据给定的道具动态ID(创建道具时生成的唯一ID)做删除操作
  1620. func (this *Role) DelItemByList(itemIdList []uint64, delFrom AddFromType) {
  1621. if this.roleBag == nil {
  1622. return
  1623. }
  1624. util.InfoF("uid=%v DelItem itemlist=%v ", this.GetUUid(), itemIdList)
  1625. ackMsg := &serverproto.SCDelItemAck{
  1626. Error: int32(serverproto.ErrorCode_ERROR_OK),
  1627. }
  1628. for idx := 0; idx < len(itemIdList); idx++ {
  1629. itemData := this.GetRoleBag().getItemById(itemIdList[idx])
  1630. if itemData != nil && itemData.Num > 0 {
  1631. this.GetRoleBag().DelItemById(itemIdList[idx], int32(itemData.Num), delFrom)
  1632. ackMsg.DelCfgIdList = append(ackMsg.DelCfgIdList, itemData.ConfigId)
  1633. }
  1634. }
  1635. this.ReplayGate(ackMsg, true)
  1636. }
  1637. func (this *Role) GetItemNum(configId int32) uint32 {
  1638. if this.roleBag != nil {
  1639. return this.roleBag.getItemNum(configId)
  1640. }
  1641. return 0
  1642. }
  1643. func (this *Role) UseItem(itemId uint64, itemNum uint32, itemIdxList []int32, bForceItemId bool) {
  1644. if this.roleBag != nil {
  1645. //默认使用一个
  1646. if itemNum == 0 {
  1647. itemNum = 1
  1648. }
  1649. err := this.roleBag.UseItem(itemId, itemNum, itemIdxList, bForceItemId)
  1650. if err != serverproto.ErrorCode_ERROR_OK {
  1651. ackMsg := &serverproto.SCUseItemAck{
  1652. Error: int32(err),
  1653. }
  1654. this.ReplayGate(ackMsg, true)
  1655. }
  1656. }
  1657. }
  1658. func (this *Role) OnlineTimeReward() {
  1659. err := this.GetRoleBase().OnlineTimeReward()
  1660. if err != serverproto.ErrorCode_ERROR_OK {
  1661. ackMsg := &serverproto.SCOnlineTimeRewardAck{
  1662. Error: int32(err),
  1663. }
  1664. this.ReplayGate(ackMsg, true)
  1665. }
  1666. }
  1667. // 获取当前累计充值所属档位
  1668. // 玩家累计充值金额档位1:[0-100] 2:(100,1000] 3:(1000,10000]
  1669. func (this *Role) GetTotalRechargeTap() int32 {
  1670. var tmpTap int32 = 0
  1671. tmpTotalRecharge := int32(this.GetTotalRecharge())
  1672. for idx := 0; idx < len(model.GlobalTotalRechargeList); idx++ {
  1673. if tmpTotalRecharge < model.GlobalTotalRechargeList[idx].Value {
  1674. return model.GlobalTotalRechargeList[idx].Key
  1675. }
  1676. tmpTap = model.GlobalTotalRechargeList[idx].Key
  1677. }
  1678. return tmpTap
  1679. }
  1680. func (this *Role) GetRoleBriefInfo(briefInfo *serverproto.CommonPlayerBriefInfo) {
  1681. briefInfo.Uid = this.GetUUid()
  1682. briefInfo.NickName = this.GetNickName()
  1683. briefInfo.Gender = this.GetRoleBase().GetRoleSex()
  1684. briefInfo.ImgId = this.GetImageId()
  1685. briefInfo.Level = this.GetRoleLevel()
  1686. briefInfo.ConfigId = this.GetRoleBase().RoleData().HeroData.ConfigId
  1687. briefInfo.FightPower = int32(this.roleBattleAttr.curTotalFightPower)
  1688. //briefInfo.FightPower = int32(this.GetRoleFightPower().TotalFightPower) //(this.GetRoleBase().RoleData().FightPower)
  1689. briefInfo.TowerLevel = this.GetRoleTower().nowTowerLevel
  1690. briefInfo.TowerTime = uint64(this.GetRoleTower().nowTowerPassTime)
  1691. briefInfo.HeadFrameId = this.GetRoleBase().RoleData().HeadFrameId
  1692. briefInfo.VipLevel = this.GetRoleVipLevel()
  1693. briefInfo.HeadId = this.GetHeadId()
  1694. briefInfo.TowerWjLevel = this.GetRoleTower().nowTowerWjLevel - 1
  1695. //1000层默认置为-1但是客户端显示需要1000
  1696. if this.GetRoleTower().nowTowerWjLevel == -1 {
  1697. briefInfo.TowerWjLevel = 1000
  1698. }
  1699. briefInfo.TowerWjTime = uint64(this.GetRoleTower().nowTowerWjPassTime)
  1700. if this.GetState() == ROLE_STATE_ONLINE {
  1701. briefInfo.OnlineState = true
  1702. } else {
  1703. briefInfo.OnlineTime = this.GetRoleBase().GetLastLoginTime()
  1704. }
  1705. }
  1706. func (this *Role) GetRoleFightInfo(fightInfo *serverproto.FightRoleInfo, isMainRole bool) {
  1707. fightInfo.IsRobot = false
  1708. fightInfo.BriefInfo = &serverproto.CommonPlayerBriefInfo{
  1709. Uid: this.GetUUid(),
  1710. NickName: this.GetNickName(),
  1711. Gender: this.GetRoleBase().GetRoleSex(),
  1712. ImgId: this.GetImageId(),
  1713. HeadFrameId: this.GetRoleBase().RoleData().HeadFrameId,
  1714. VipLevel: this.GetRoleVipLevel(),
  1715. SelectZone: this.GetSelectZone(),
  1716. ConfigId: this.GetRoleHero().GetMainHero().ConfigId,
  1717. Level: this.GetRoleLevel(),
  1718. }
  1719. fightInfo.JobLevel = this.GetJobLevel()
  1720. //后续需要处理
  1721. fightInfo.AttrList = this.GetRoleHero().GetMainHero().AttrList
  1722. fightInfo.FashionData = this.GetRoleBase().roleBase.FashionData
  1723. //技能竞技压制
  1724. fightInfo.RepressSkillPvpVal = this.GetRoleBase().roleBase.RepressSkillPvpVal
  1725. fightInfo.MaxFightPower = int32(this.GetRoleBase().RoleData().FightPower)
  1726. //世界boss,只上阵主角
  1727. mainHeroData := this.GetRoleBase().RoleData().HeroData
  1728. fightInfo.HeroDataList = append(fightInfo.HeroDataList, this.GetRoleBase().RoleData().HeroData)
  1729. if mainHeroData.BattlePetId > 0 && this.GetRolePet() != nil {
  1730. battlePetInfo := this.GetRolePet().getPet(mainHeroData.BattlePetId)
  1731. if battlePetInfo != nil {
  1732. fightInfo.BattlePetList = append(fightInfo.BattlePetList, battlePetInfo)
  1733. }
  1734. }
  1735. if !isMainRole {
  1736. //其他上阵伙伴
  1737. for _, data := range this.GetRoleHero().heroList {
  1738. if data.IsBattle {
  1739. fightInfo.HeroDataList = append(fightInfo.HeroDataList, data)
  1740. if data.BattlePetId > 0 && this.GetRolePet() != nil {
  1741. battlePetInfo := this.GetRolePet().getPet(data.BattlePetId)
  1742. if battlePetInfo != nil {
  1743. fightInfo.BattlePetList = append(fightInfo.BattlePetList, battlePetInfo)
  1744. }
  1745. }
  1746. }
  1747. }
  1748. }
  1749. }
  1750. type AddSystemMsg struct {
  1751. ParamId int32
  1752. ParamCount int32
  1753. AddFromType int32
  1754. UseItemCfgId int32
  1755. ParamList []int32
  1756. ParaStr string
  1757. }
  1758. func (this *Role) GenSystemMessage(sType SystemMessageType, st AddSystemMsg) *serverproto.SystemMessage {
  1759. ssMsgNtf := &serverproto.SSSystemMessageNtf{}
  1760. sysMsg := &serverproto.SystemMessage{
  1761. Type: int32(sType),
  1762. NickName: this.GetNickName(),
  1763. SendTime: util.GetTimeMilliseconds(),
  1764. }
  1765. if st.ParamId > 0 {
  1766. sysMsg.ParamId = append(sysMsg.ParamId, st.ParamId) //id
  1767. }
  1768. if st.ParamCount > 0 {
  1769. sysMsg.ParamId = append(sysMsg.ParamId, st.ParamCount) //count
  1770. }
  1771. if st.AddFromType > 0 {
  1772. sysMsg.ParamId = append(sysMsg.ParamId, st.AddFromType) //AddFromType
  1773. }
  1774. if st.UseItemCfgId > 0 {
  1775. sysMsg.ParamId = append(sysMsg.ParamId, st.UseItemCfgId) //UseItemCfgId
  1776. }
  1777. if len(st.ParamList) > 0 {
  1778. sysMsg.ParamId = append(sysMsg.ParamId, st.ParamList...)
  1779. }
  1780. if sType == SystemmessageType_GuildDemon {
  1781. sysMsg.NickName = st.ParaStr
  1782. }
  1783. ssMsgNtf.SysMsg = append(ssMsgNtf.SysMsg, sysMsg)
  1784. //util.InfoF("uid=%v GenSystemMessage type=%v param=%v", this.GetUUid(), sysMsg.Type, sysMsg.ParamId)
  1785. return sysMsg
  1786. }
  1787. func (this *Role) AddSystemMessage(sType SystemMessageType, st AddSystemMsg) {
  1788. ssMsgNtf := &serverproto.SSSystemMessageNtf{}
  1789. sysMsg := &serverproto.SystemMessage{
  1790. Type: int32(sType),
  1791. NickName: this.GetNickName(),
  1792. SendTime: util.GetTimeMilliseconds(),
  1793. }
  1794. if st.ParamId > 0 {
  1795. sysMsg.ParamId = append(sysMsg.ParamId, st.ParamId) //id
  1796. }
  1797. if st.ParamCount > 0 {
  1798. sysMsg.ParamId = append(sysMsg.ParamId, st.ParamCount) //count
  1799. }
  1800. if st.AddFromType > 0 {
  1801. sysMsg.ParamId = append(sysMsg.ParamId, st.AddFromType) //AddFromType
  1802. }
  1803. if st.UseItemCfgId > 0 {
  1804. sysMsg.ParamId = append(sysMsg.ParamId, st.UseItemCfgId) //UseItemCfgId
  1805. }
  1806. if len(st.ParamList) > 0 {
  1807. sysMsg.ParamId = append(sysMsg.ParamId, st.ParamList...)
  1808. }
  1809. if sType == SystemmessageType_GuildDemon {
  1810. sysMsg.NickName = st.ParaStr
  1811. }
  1812. ssMsgNtf.SysMsg = append(ssMsgNtf.SysMsg, sysMsg)
  1813. this.SendSocial(ssMsgNtf)
  1814. }
  1815. // 分配属性点
  1816. func (this *Role) AddAttrPoint(heroID int32, point interface{}) {
  1817. ret := this.GetRoleHero().AddAttrPoint(heroID, point)
  1818. if ret != serverproto.ErrorCode_ERROR_OK {
  1819. ackMsg := &serverproto.SCAddAttrPointAck{
  1820. Error: int32(ret),
  1821. HeroId: heroID,
  1822. }
  1823. this.ReplayGate(ackMsg, true)
  1824. }
  1825. }
  1826. // 分配属性点
  1827. func (this *Role) ReduceAttrPoint(count, itemid int32) {
  1828. this.GetRoleHero().ReduceAttrPoint(count, itemid)
  1829. }
  1830. // 重置属性点
  1831. func (this *Role) ResetAttrPoint(heroID int32) {
  1832. this.GetRoleHero().ResetAttrPoint(heroID, false)
  1833. }
  1834. // 增加素质点
  1835. func (this *Role) OnAddQualityPoint(msg *serverproto.CSAddQualityPointReq) {
  1836. if msg == nil {
  1837. return
  1838. }
  1839. ackMsg := &serverproto.SCAddQualityPointAck{}
  1840. ackMsg.HeroId = msg.HeroId
  1841. ackMsg.ItemId = msg.ItemId
  1842. ackMsg.Error = int32(this.GetRoleHero().UseQualityItem(msg.HeroId, msg.ItemId))
  1843. this.ReplayGate(ackMsg, true)
  1844. }
  1845. // 激活头像
  1846. func (this *Role) ActiveHead(headId int32) {
  1847. ackMsg := &serverproto.SCActiveHeadAck{
  1848. HeadId: headId,
  1849. }
  1850. bRet := this.base.ActiveHead(headId)
  1851. ackMsg.Error = int32(bRet)
  1852. this.ReplayGate(ackMsg, true)
  1853. }
  1854. // 设置头像
  1855. func (this *Role) SetRoleHeadPic(headId int32) {
  1856. ackMsg := &serverproto.SCSetHeadIdAck{
  1857. HeadId: headId,
  1858. }
  1859. bRet := this.GetRoleBase().SetRoleHeadPic(headId)
  1860. ackMsg.Error = int32(bRet)
  1861. this.ReplayGate(ackMsg, true)
  1862. //更新玩家简介信息
  1863. if bRet == serverproto.ErrorCode_ERROR_OK {
  1864. this.GetRoleBase().UpdatePlayerBriefInfo(false)
  1865. }
  1866. }
  1867. func (this *Role) SetRoleHeadFrameId(frameId int32) {
  1868. ackMsg := &serverproto.SCChangeHeadFrameAck{
  1869. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  1870. HeadFrameId: frameId,
  1871. }
  1872. bRet := this.GetRoleBase().SetHeadFrameId(frameId)
  1873. ackMsg.Error = int32(bRet)
  1874. this.ReplayGate(ackMsg, true)
  1875. }
  1876. func (this *Role) UseHeadFrameItem(itemId uint64, itemNum uint32) {
  1877. ackMsg := &serverproto.SCUseHeadFrameItemAck{
  1878. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  1879. }
  1880. bRet, res_list := this.GetRoleBag().UseHeadFrameItem(itemId, itemNum)
  1881. ackMsg.Error = int32(bRet)
  1882. ackMsg.ItemList = res_list
  1883. this.ReplayGate(ackMsg, true)
  1884. }
  1885. func (this *Role) GetRoleHeadFrameInfo() {
  1886. ackMsg := &serverproto.SCHeadFrameInfoAck{
  1887. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  1888. }
  1889. bRet := this.GetRoleBase().PackHeadFrameInfo(ackMsg)
  1890. ackMsg.Error = int32(bRet)
  1891. this.ReplayGate(ackMsg, true)
  1892. }
  1893. // 请求头像信息
  1894. func (this *Role) HeadInfoReq() {
  1895. this.base.HeadInfoReq()
  1896. }
  1897. func (this *Role) ChangeRoleName(name string) {
  1898. ackMsg := &serverproto.SCRenameAck{
  1899. Name: name,
  1900. }
  1901. bRet := this.base.ChangeRoleName(name)
  1902. ackMsg.Error = int32(bRet)
  1903. this.ReplayGate(ackMsg, true)
  1904. //更新玩家简介信息
  1905. if bRet == serverproto.ErrorCode_ERROR_OK {
  1906. this.GetRoleBase().UpdatePlayerBriefInfo(false)
  1907. }
  1908. }
  1909. func (this *Role) SetRoleGuide(guideId int32) {
  1910. this.GetRoleBase().SetGuideId(guideId)
  1911. }
  1912. func (this *Role) SetRoleStory(story *serverproto.KeyValueType) {
  1913. nRet := this.GetRoleBase().SetStoryId(story)
  1914. ackMsg := &serverproto.SCRoleStoryAck{
  1915. Error: int32(nRet),
  1916. StoryId: story,
  1917. }
  1918. this.ReplayGate(ackMsg, true)
  1919. }
  1920. func (this *Role) SetMapCartoon(id, status int32) {
  1921. bRet := this.GetRoleBase().SetNewMapCartoonId(id, status)
  1922. ackMsg := &serverproto.SCNewMapCartoonAck{
  1923. Error: int32(bRet),
  1924. MapCart: &serverproto.KeyValueType{
  1925. Key: id,
  1926. Value: status,
  1927. },
  1928. }
  1929. this.ReplayGate(ackMsg, true)
  1930. }
  1931. // /hero/partner
  1932. // 添加伙伴
  1933. func (this *Role) AddHero(configId int32) bool {
  1934. if this.roleHero != nil {
  1935. return this.roleHero.AddHero(configId)
  1936. }
  1937. return false
  1938. }
  1939. func (this *Role) HeroLevelUp(id int32) bool {
  1940. if this.roleHero != nil {
  1941. return this.roleHero.LevelUp(id)
  1942. }
  1943. return false
  1944. }
  1945. func (this *Role) HeroAdvance(id int32) bool {
  1946. if this.roleHero != nil {
  1947. ret := this.roleHero.Advance(id)
  1948. if ret == serverproto.ErrorCode_ERROR_OK {
  1949. ////进阶重新处理属性
  1950. //this.roleFightPower.onFighterAttrChange(id)
  1951. } else {
  1952. ackMsg := &serverproto.SCHeroAdvanceAck{
  1953. Error: int32(ret),
  1954. }
  1955. this.ReplayGate(ackMsg, true)
  1956. }
  1957. return ret == serverproto.ErrorCode_ERROR_OK
  1958. }
  1959. return false
  1960. }
  1961. func (this *Role) HeroStrength(id int32) bool {
  1962. if this.roleHero != nil {
  1963. ret := this.roleHero.HeroStrength(id)
  1964. return ret
  1965. }
  1966. return false
  1967. }
  1968. func (this *Role) HeroChangeJob(heroId int32, jobId int32) bool {
  1969. ackMsg := &serverproto.SCHeroChangeJobAck{
  1970. Error: int32(serverproto.ErrorCode_ERROR_OK),
  1971. HeroId: heroId,
  1972. }
  1973. if this.roleHero != nil {
  1974. ret := this.roleHero.HeroChangeJob(heroId, jobId)
  1975. if ret == serverproto.ErrorCode_ERROR_OK {
  1976. ////转职重新处理属性 后续重新开发
  1977. //this.roleFightPower.onFighterAttrChange(heroId)
  1978. }
  1979. ackMsg.Error = int32(ret)
  1980. this.ReplayGate(ackMsg, true)
  1981. return true
  1982. }
  1983. return false
  1984. }
  1985. func (this *Role) HeroRecruit(configId int32) {
  1986. ackMsg := &serverproto.SCHeroActiveAck{
  1987. HeroId: configId,
  1988. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  1989. }
  1990. if this.roleHero != nil {
  1991. nRet := this.roleHero.RecruitHero(configId)
  1992. ackMsg.Error = int32(nRet)
  1993. }
  1994. this.ReplayGate(ackMsg, true)
  1995. }
  1996. func (this *Role) FightPowerReq(heroId int32) {
  1997. ackMsg := &serverproto.SCHeroFighPowerAck{
  1998. Error: int32(serverproto.ErrorCode_ERROR_OK),
  1999. HeroId: heroId,
  2000. }
  2001. //this.roleFightPower.calcHeroFightPower(heroId)
  2002. this.ReplayGate(ackMsg, true)
  2003. }
  2004. func (this *Role) HeroBattle(heroId int32, isBattle bool) {
  2005. if this.roleHero != nil {
  2006. ret := this.roleHero.HeroBattle(heroId, isBattle)
  2007. ackMsg := &serverproto.SCHeroBattleAck{
  2008. Error: int32(ret),
  2009. }
  2010. this.ReplayGate(ackMsg, true)
  2011. }
  2012. }
  2013. func (this *Role) ComposeChip(configId int32) {
  2014. if this.roleChip != nil && this.roleHero != nil {
  2015. ret := this.roleChip.ComposeChip(configId)
  2016. if ret != serverproto.ErrorCode_ERROR_OK {
  2017. util.DebugF("uid=%v ComposeChip err=%v", this.GetUUid(), ret)
  2018. }
  2019. ackMsg := &serverproto.SCChipComposeAck{
  2020. Error: int32(ret),
  2021. }
  2022. this.ReplayGate(ackMsg, true)
  2023. }
  2024. }
  2025. func (this *Role) ChipDecompose(chipList []*serverproto.KeyValueType, heroChipType []int32) {
  2026. if this.roleChip != nil {
  2027. ret := this.roleChip.ChipDecompose(chipList, heroChipType)
  2028. if ret != serverproto.ErrorCode_ERROR_OK {
  2029. ackMsg := &serverproto.SCHeroChipDecomposeAck{
  2030. Error: int32(ret),
  2031. }
  2032. this.ReplayGate(ackMsg, true)
  2033. }
  2034. }
  2035. }
  2036. // /equip
  2037. func (this *Role) EquipForge(equipConfigId int32, once int32, equipType, subEquipType int32) {
  2038. if this.roleEquip != nil {
  2039. this.roleEquip.EquipForge(equipConfigId, once, equipType, subEquipType)
  2040. }
  2041. }
  2042. func (this *Role) AddEquip(configId int32, num int32, notify bool, ignore bool) {
  2043. if this.roleEquip != nil {
  2044. addEquip, _ := this.roleEquip.AddEquip(configId, num)
  2045. if addEquip != nil {
  2046. if notify {
  2047. ntfMsg := &serverproto.SCEquipChangeNtf{
  2048. Ignore: ignore,
  2049. }
  2050. ntfMsg.EquipList = append(ntfMsg.EquipList, addEquip.(*serverproto.EquipData))
  2051. this.ReplayGate(ntfMsg, true)
  2052. }
  2053. util.InfoF("uid=%v AddEquip id=%v now=%v num=%v", this.GetUUid(), configId,
  2054. addEquip.(*serverproto.EquipData).Num, num)
  2055. }
  2056. }
  2057. }
  2058. func (this *Role) AddSkillEquip(configId int32, num int32, notify bool, ignore bool) {
  2059. if this.roleSkillEquip != nil {
  2060. changeIdList := map[uint32]int32{}
  2061. var i int32 = 0
  2062. for ; i < num; i++ {
  2063. addSkillEquip, _ := this.roleSkillEquip.AddSkillEquip(configId, 0)
  2064. if addSkillEquip != nil {
  2065. detail, ok := addSkillEquip.(*serverproto.SkillEquipData)
  2066. if !ok {
  2067. continue
  2068. }
  2069. changeIdList[detail.Id] = detail.ConfigId
  2070. }
  2071. }
  2072. this.roleSkillEquip.ChangeNtf(changeIdList, ignore)
  2073. }
  2074. }
  2075. func (this *Role) EquipUp(heroId int32, slotIndex int32, equipId int32) {
  2076. if this.roleEquip != nil && this.roleHero != nil &&
  2077. heroId > 0 && slotIndex >= 0 && equipId >= 0 {
  2078. ret := this.base.EquipUp(heroId, slotIndex, equipId)
  2079. ackMsg := &serverproto.SCEquipUpAck{
  2080. Error: int32(ret),
  2081. }
  2082. this.ReplayGate(ackMsg, true)
  2083. } else {
  2084. ackMsg := &serverproto.SCEquipUpAck{
  2085. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2086. }
  2087. this.ReplayGate(ackMsg, true)
  2088. }
  2089. }
  2090. func (this *Role) EquipDown(heroId int32, subIndex int32) {
  2091. if this.roleEquip != nil && this.roleHero != nil {
  2092. this.base.EquipDown(heroId, subIndex)
  2093. }
  2094. }
  2095. func (this *Role) EquipLevelUpAll(heroId int32) {
  2096. if this.roleEquip != nil && this.roleHero != nil {
  2097. this.base.EquipLevelUpAll(heroId)
  2098. }
  2099. }
  2100. func (this *Role) EquipSlotLevelUp(heroId int32, subSlotIndex int32) {
  2101. if this.roleEquip != nil {
  2102. ret := this.base.EquipSlotLevelUp(heroId, subSlotIndex)
  2103. util.DebugF("uid=%v [EquipSlotLevelUp] err=%v", this.GetUUid(), ret)
  2104. ackMsg := &serverproto.SCEquipSlotLevelUpAck{
  2105. Error: int32(ret),
  2106. }
  2107. this.ReplayGate(ackMsg, true)
  2108. }
  2109. }
  2110. // 神器槽位升级
  2111. func (this *Role) SkillEquipSlotLevelUp(heroId, subIndex int32) {
  2112. if this.roleSkillEquip != nil && this.roleHero != nil {
  2113. slotData := this.base.getSkillEquipSlotData(heroId)
  2114. ret := this.roleSkillEquip.SkillEquipSlotLevelUp(slotData, heroId, subIndex)
  2115. util.DebugF("uid=%v [EquipSlotLevelUp] err=%v", this.GetUUid(), ret)
  2116. ackMsg := &serverproto.SCSkillEquipSlotLevelUpAck{
  2117. Error: int32(ret),
  2118. }
  2119. this.ReplayGate(ackMsg, true)
  2120. }
  2121. }
  2122. // 神器升星
  2123. func (this *Role) SkillEquipStarLevelUp(heroId int32, skillEquipId uint32, cost []uint32) {
  2124. if this.roleSkillEquip != nil && this.roleHero != nil {
  2125. slotData := this.base.getSkillEquipSlotData(heroId)
  2126. ret := this.roleSkillEquip.SkillEquipStarLevelUp(heroId, slotData, skillEquipId, cost)
  2127. util.DebugF("uid=%v [SkillEquipStarLevelUp] err=%v", this.GetUUid(), ret)
  2128. ackMsg := &serverproto.SCSkillEquipLevelUpAck{
  2129. Error: int32(ret),
  2130. }
  2131. this.ReplayGate(ackMsg, true)
  2132. }
  2133. }
  2134. // 神器转移
  2135. func (this *Role) SkillEquipShift(msg *serverproto.CSSkillEquipShiftReq) {
  2136. if msg == nil {
  2137. return
  2138. }
  2139. ret := this.roleSkillEquip.SkillEquipShift(msg.SrcId, msg.DstId)
  2140. util.DebugF("uid=%v [SkillEquipShift] err=%v", this.GetUUid(), ret)
  2141. ackMsg := &serverproto.SCSkillEquipShiftAck{
  2142. Error: int32(ret),
  2143. }
  2144. this.ReplayGate(ackMsg, true)
  2145. }
  2146. // 佩戴替换神器
  2147. func (this *Role) SkillEquipUp(heroId int32, skillEquipId uint32, slotIndex int32) {
  2148. if this.roleSkillEquip != nil && this.roleHero != nil {
  2149. slotData := this.base.getSkillEquipSlotData(heroId)
  2150. ret := this.roleSkillEquip.SkillEquipUp(heroId, slotData, skillEquipId, slotIndex)
  2151. util.DebugF("uid=%v [SkillEquipUp] err=%v", this.GetUUid(), ret)
  2152. ackMsg := &serverproto.SCSkillEquipUpAck{
  2153. Error: int32(ret),
  2154. }
  2155. this.ReplayGate(ackMsg, true)
  2156. }
  2157. }
  2158. // 卸下神器
  2159. func (this *Role) SkillEquipDown(heroId int32, slotIndex int32) {
  2160. if this.roleSkillEquip != nil && this.roleHero != nil {
  2161. slotData := this.base.getSkillEquipSlotData(heroId)
  2162. ret := this.roleSkillEquip.SkillEquipDown(heroId, slotData, slotIndex)
  2163. util.DebugF("uid=%v [SkillEquipDown] err=%v", this.GetUUid(), ret)
  2164. ackMsg := &serverproto.SCSkillEquipDownAck{
  2165. Error: int32(ret),
  2166. }
  2167. this.ReplayGate(ackMsg, true)
  2168. }
  2169. }
  2170. // 分解神器
  2171. func (this *Role) SkillEquipDecompose(skillEquipIds []uint32) {
  2172. if this.roleSkillEquip != nil && this.roleHero != nil {
  2173. reward, ret := this.roleSkillEquip.SkillEquipDecompose(skillEquipIds)
  2174. util.DebugF("uid=%v [SkillEquipDecompose] err=%v", this.GetUUid(), ret)
  2175. ackMsg := &serverproto.SCSkillEquipDecomposeAck{
  2176. Error: int32(ret),
  2177. }
  2178. if reward != nil && len(reward) > 0 {
  2179. for k, v := range reward {
  2180. ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
  2181. Key: k,
  2182. Value: v,
  2183. })
  2184. }
  2185. }
  2186. this.ReplayGate(ackMsg, true)
  2187. }
  2188. }
  2189. func (this *Role) SkillEquipRemade(skillEquipId uint32) {
  2190. if this.roleSkillEquip != nil && this.roleHero != nil {
  2191. ackMsg := &serverproto.SCSkillEquipRemadeAck{
  2192. OldId: skillEquipId,
  2193. }
  2194. ret, newId := this.roleSkillEquip.SkillEquipReforge(skillEquipId)
  2195. ackMsg.Error = int32(ret)
  2196. ackMsg.NewId = newId
  2197. this.ReplayGate(ackMsg, true)
  2198. }
  2199. }
  2200. func (this *Role) GetSkillEquipPool() {
  2201. if this.roleSkillEquip != nil {
  2202. ackMsg := &serverproto.SCSkillEquipPoolAck{}
  2203. ret := this.roleSkillEquip.GetSkillEquipPool(ackMsg)
  2204. ackMsg.Error = int32(ret)
  2205. this.ReplayGate(ackMsg, true)
  2206. }
  2207. }
  2208. // /card
  2209. func (this *Role) CardMount(heroId, subSlotIndex, cardSlotIndex, cardCfgId int32) {
  2210. if this.roleEquip != nil && this.roleCard != nil {
  2211. ret := this.base.SlotCardMount(heroId, subSlotIndex, cardSlotIndex, cardCfgId)
  2212. util.DebugF("uid=%v CardMount err=%v", this.GetUUid(), ret)
  2213. ackMsg := &serverproto.SCCardMountAck{
  2214. Error: int32(ret),
  2215. }
  2216. this.ReplayGate(ackMsg, true)
  2217. }
  2218. }
  2219. func (this *Role) CardDown(heroId, subSlotIndex, cardSlotIndex int32) {
  2220. if this.roleCard != nil {
  2221. ret := this.base.SlotCardDown(heroId, subSlotIndex, cardSlotIndex)
  2222. util.DebugF("uid=%v CardDown err=%v", this.GetUUid(), ret)
  2223. ackMsg := &serverproto.SCCardDownAck{
  2224. Error: int32(ret),
  2225. }
  2226. this.ReplayGate(ackMsg, true)
  2227. }
  2228. }
  2229. func (this *Role) CardMountAll(msg *serverproto.CSCardEquipAllReq) {
  2230. if msg == nil || len(msg.EqiupSlotData) <= 0 {
  2231. return
  2232. }
  2233. if this.roleEquip != nil && this.roleCard != nil {
  2234. ret := this.base.SlotCardMountAll(msg)
  2235. util.DebugF("uid=%v CardMountAll err=%v", this.GetUUid(), ret)
  2236. ackMsg := &serverproto.SCCardEquipAllAck{
  2237. Error: int32(ret),
  2238. }
  2239. this.ReplayGate(ackMsg, true)
  2240. }
  2241. }
  2242. func (this *Role) CardDownAll(heroId int32) {
  2243. if this.roleEquip != nil && this.roleCard != nil {
  2244. ret := this.base.SlotCardDownAll(heroId)
  2245. util.DebugF("uid=%v CardDownAll err=%v", this.GetUUid(), ret)
  2246. ackMsg := &serverproto.SCCardEquipDownAck{
  2247. Error: int32(ret),
  2248. HeroId: heroId,
  2249. }
  2250. this.ReplayGate(ackMsg, true)
  2251. }
  2252. }
  2253. func (this *Role) CardUpGradeAll(msg *serverproto.CSCardUpGradeAllReq) {
  2254. if this.roleCard != nil {
  2255. ret := this.base.SlotCardUpGradeAll(msg)
  2256. util.DebugF("uid=%v CardUpGradeAll err=%v", this.GetUUid(), ret)
  2257. ackMsg := &serverproto.SCCardUpGradeAllAck{
  2258. Error: int32(ret),
  2259. HeroId: msg.HeroId,
  2260. }
  2261. this.ReplayGate(ackMsg, true)
  2262. }
  2263. }
  2264. func (this *Role) CardLevelExchange(sourceCardId, targetCardId int32) {
  2265. ackMsg := &serverproto.SCCardLevelExchangeAck{
  2266. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2267. }
  2268. if this.roleCard != nil {
  2269. ret := this.roleCard.CardExchange(sourceCardId, targetCardId, ackMsg)
  2270. ackMsg.Error = int32(ret)
  2271. }
  2272. this.ReplayGate(ackMsg, true)
  2273. }
  2274. func (this *Role) CardCollect() {
  2275. if this.roleCard != nil {
  2276. ackMsg := &serverproto.SCCardCollectInfoAck{
  2277. Error: int32(serverproto.ErrorCode_ERROR_OK),
  2278. }
  2279. this.GetRoleCard().GetCardCollect(ackMsg)
  2280. this.ReplayGate(ackMsg, true)
  2281. }
  2282. }
  2283. func (this *Role) CardCollectReward(cardId, level int32) {
  2284. if this.roleCard != nil {
  2285. ackMsg := &serverproto.SCCardCollectRewardAck{
  2286. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2287. }
  2288. ret := this.GetRoleCard().GetCollectReward(cardId, level, ackMsg)
  2289. ackMsg.Error = int32(ret)
  2290. ackMsg.CardId = cardId
  2291. ackMsg.Level = level
  2292. this.ReplayGate(ackMsg, true)
  2293. }
  2294. }
  2295. func (this *Role) CardCompose(cardList []int32) {
  2296. if this.roleCard != nil {
  2297. ret, newCardId := this.roleCard.CardCompose(cardList)
  2298. util.DebugF("uid=%v CardCompose err=%v", this.GetUUid(), ret)
  2299. ackMsg := &serverproto.SCCardComposeAck{
  2300. Error: int32(ret),
  2301. NewCardId: newCardId,
  2302. }
  2303. this.ReplayGate(ackMsg, true)
  2304. }
  2305. }
  2306. func (this *Role) CardDecompose(cardList []*serverproto.KeyValueType, cardType int32) {
  2307. if this.roleCard != nil {
  2308. this.roleCard.CardDecompose(cardList, cardType)
  2309. }
  2310. }
  2311. func (this *Role) CardUpGrade(msg *serverproto.CSCardUpGradeReq) {
  2312. ackMsg := &serverproto.SCCardUpGradeAck{
  2313. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2314. }
  2315. if this.roleCard != nil && len(msg.ConfigIds) > 0 {
  2316. this.roleCard.BagCardUpGrade(msg, ackMsg)
  2317. }
  2318. this.ReplayGate(ackMsg, true)
  2319. }
  2320. // /skill
  2321. func (this *Role) SkillReplace(heroId, idx, replaceSkillId int32) {
  2322. if this.roleSkill != nil {
  2323. ret := this.roleSkill.SkillReplace(heroId, idx, replaceSkillId, true, true)
  2324. util.DebugF("uid=%v SkillReplace] err=%v", this.GetUUid(), ret)
  2325. this.ReplayGate(&serverproto.SCReplaceSkillAck{Error: int32(ret)}, true)
  2326. }
  2327. }
  2328. func (this *Role) ActiveSkill(heroId int32, skillId int32) {
  2329. if this.roleSkill != nil {
  2330. ret := this.roleSkill.ActiveSkill(heroId, skillId)
  2331. util.DebugF("uid=%v ActiveSkill err=%v heroid=%v skillid=%v", this.GetUUid(), ret, heroId, skillId)
  2332. this.ReplayGate(&serverproto.SCActiveSkillAck{Error: int32(ret)}, true)
  2333. }
  2334. }
  2335. func (this *Role) SwapSkill(heroId, firstSlotId, secondSlotId int32) {
  2336. if this.roleSkill != nil {
  2337. ret := this.roleSkill.SwapSkill(heroId, firstSlotId, secondSlotId)
  2338. util.DebugF("uid=%v SwapSkill err=%v s1=%v s2=%v", this.GetUUid(), ret, firstSlotId, secondSlotId)
  2339. this.ReplayGate(&serverproto.SCSwapSkillAck{Error: int32(ret)}, true)
  2340. }
  2341. }
  2342. func (this *Role) SetSkillList(heroId int32, skillList []int32) {
  2343. ackMsg := &serverproto.SCSetSkillListAck{
  2344. HeroId: heroId,
  2345. }
  2346. if this.roleSkill != nil {
  2347. ret := this.roleSkill.SetSkillList(heroId, skillList)
  2348. ackMsg.Error = int32(ret)
  2349. }
  2350. this.ReplayGate(ackMsg, true)
  2351. }
  2352. func (this *Role) SkillLevelUp(heroId int32, skillId int32) {
  2353. ackMsg := &serverproto.SCSkillLevelUpAck{
  2354. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2355. SkillId: skillId,
  2356. HeroId: heroId,
  2357. }
  2358. if this.roleHero == nil {
  2359. this.ReplayGate(ackMsg, true)
  2360. return
  2361. }
  2362. heroData := this.roleHero.GetHero(heroId)
  2363. if heroData == nil {
  2364. this.ReplayGate(ackMsg, true)
  2365. return
  2366. }
  2367. bRet := this.roleSkill.SkillLevelUp(heroData, skillId)
  2368. ackMsg.Error = int32(bRet)
  2369. this.ReplayGate(ackMsg, true)
  2370. }
  2371. // 兑换高级技能经验
  2372. func (this *Role) ConverSkillExp(msg *serverproto.CSConverSkillExpReq) {
  2373. ackMsg := &serverproto.SCConverSkillExpAck{}
  2374. ackMsg.Error = int32(this.roleSkill.ConverSkillExp(msg.Cnt))
  2375. this.ReplayGate(ackMsg, true)
  2376. }
  2377. func (this *Role) ResetSkillLevel(heroId int32, bsuper bool) {
  2378. if this.roleHero == nil {
  2379. return
  2380. }
  2381. heroData := this.roleHero.GetHero(heroId)
  2382. if heroData == nil {
  2383. return
  2384. }
  2385. ackMsg := &serverproto.SCResetSkillLevelAck{
  2386. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2387. HeroId: heroId,
  2388. }
  2389. bRet := this.roleSkill.ResetSkillLevel(heroId, bsuper)
  2390. ackMsg.Error = int32(bRet)
  2391. ackMsg.ResetCount = this.GetRoleBase().RoleData().SkillResetCount
  2392. this.ReplayGate(ackMsg, true)
  2393. }
  2394. // /card 相关
  2395. func (this *Role) FashionUp(fashionCfgIdList []int32) {
  2396. if this.roleFashion != nil {
  2397. ackMsg := &serverproto.SCFashionUpAck{}
  2398. for _, data := range fashionCfgIdList {
  2399. if ret := this.roleFashion.FashionUp(data); ret == serverproto.ErrorCode_ERROR_OK {
  2400. ackMsg.Error = int32(ret)
  2401. }
  2402. }
  2403. this.roleFashion.SetFashion()
  2404. this.ReplayGate(ackMsg, true)
  2405. }
  2406. }
  2407. func (this *Role) FashionDown(fashionCfgIdList []int32) {
  2408. if this.roleFashion != nil {
  2409. ackMsg := &serverproto.SCFashionDownAck{}
  2410. for _, data := range fashionCfgIdList {
  2411. if ret := this.roleFashion.FashionDown(data); ret == serverproto.ErrorCode_ERROR_OK {
  2412. ackMsg.Error = int32(ret)
  2413. }
  2414. }
  2415. this.roleFashion.SetFashion()
  2416. this.ReplayGate(ackMsg, true)
  2417. }
  2418. }
  2419. func (this *Role) FashionCompose(paperCfgId int32) {
  2420. if this.roleFashion != nil {
  2421. ret := this.roleFashion.FashionCompose(paperCfgId)
  2422. this.ReplayGate(&serverproto.SCFashionComposeAck{Error: int32(ret)}, true)
  2423. }
  2424. }
  2425. func (this *Role) FashionPaperDecompose(paperCfgId int32) {
  2426. if this.roleFashion != nil {
  2427. ret := this.roleFashion.FashionPaperDecompose(paperCfgId)
  2428. if ret != serverproto.ErrorCode_ERROR_OK {
  2429. this.ReplayGate(&serverproto.SCFashionPaperDecomposeAck{Error: int32(ret)}, true)
  2430. }
  2431. }
  2432. }
  2433. func (this *Role) FashionResetAttr(fashionId int32, enter bool) {
  2434. if this.roleFashion == nil {
  2435. return
  2436. }
  2437. ret, _ := this.roleFashion.FashionResetAttr(fashionId, enter)
  2438. this.roleFashion.FashionChangeNtf([]int32{fashionId})
  2439. this.ReplayGate(&serverproto.SCFashionResetAttrAck{Error: int32(ret)}, true)
  2440. }
  2441. func (this *Role) FashionUpLvl(fashionId int32) {
  2442. if this.roleFashion == nil {
  2443. return
  2444. }
  2445. ret := this.roleFashion.FashionUpLvl(fashionId)
  2446. this.roleFashion.FashionChangeNtf([]int32{fashionId})
  2447. this.ReplayGate(&serverproto.SCFashionUpLvlAck{Error: int32(ret)}, true)
  2448. }
  2449. func (this *Role) BuyItem(shopId, goodsId, goodsNum int32) {
  2450. ackMsg := &serverproto.SCShopBuyItemAck{
  2451. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2452. GoodsType: shopId,
  2453. GoodsId: goodsId,
  2454. }
  2455. if this.roleBag != nil && goodsNum > 0 {
  2456. bRet, buyTime, buyNum := this.roleShop.BuyItem(shopId, goodsId, goodsNum, ackMsg)
  2457. ackMsg.Error = int32(bRet)
  2458. ackMsg.CurNum = buyNum
  2459. ackMsg.CurBuyTime = buyTime
  2460. }
  2461. this.ReplayGate(ackMsg, true)
  2462. }
  2463. func (this *Role) ShopInfoReq(goodsType int32) {
  2464. ackMsg := &serverproto.SCShopInfoAck{
  2465. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2466. }
  2467. if this.roleBag != nil {
  2468. shopTypeData, ok := serverproto.ShopTypeCfgLoader[goodsType]
  2469. if ok {
  2470. if shopTypeData.ShopType == 2 {
  2471. bRet := this.roleShop.GetSpecialShopInfo(goodsType, ackMsg)
  2472. ackMsg.Error = int32(bRet)
  2473. } else {
  2474. bRet := this.roleShop.GetShopInfo(goodsType, ackMsg)
  2475. ackMsg.Error = int32(bRet)
  2476. }
  2477. }
  2478. }
  2479. util.DebugF("send ackMsg msg=%v", ackMsg)
  2480. this.ReplayGate(ackMsg, true)
  2481. }
  2482. func (this *Role) ShopRefresh(goodsType int32) {
  2483. ackMsg := &serverproto.SCShopRefreshAck{
  2484. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2485. }
  2486. if this.roleBag != nil {
  2487. bRet := this.roleShop.HandleSpecialShopRefresh(goodsType, ackMsg)
  2488. ackMsg.Error = int32(bRet)
  2489. }
  2490. this.ReplayGate(ackMsg, true)
  2491. }
  2492. func (this *Role) RedBagShopExchange() {
  2493. ackMsg := &serverproto.SCRedBagExchangeAck{
  2494. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2495. }
  2496. if this.roleBag != nil {
  2497. bRet := this.roleShop.ExchangeRedBagTicket(ackMsg)
  2498. ackMsg.Error = int32(bRet)
  2499. }
  2500. this.ReplayGate(ackMsg, true)
  2501. }
  2502. // /social相关
  2503. func (this *Role) playerSocialOnline() {
  2504. ntfMsg := &serverproto.SSPlayerOnlineNtf{
  2505. BriefInfo: &serverproto.PlayerBriefInfo{
  2506. Uid: this.GetUUid(),
  2507. NickName: this.GetRoleBase().roleBase.NickName,
  2508. },
  2509. }
  2510. ntfMsg.ServiceNode = service.GetLocalServiceID()
  2511. this.SendAllSocial(ntfMsg)
  2512. }
  2513. func (this *Role) playerSocialOffline() {
  2514. ntfMsg := &serverproto.SSPlayerOfflineNtf{
  2515. Uid: this.GetUUid(),
  2516. }
  2517. this.SendAllSocial(ntfMsg)
  2518. }
  2519. func (this *Role) playerGuildOnline(changeType int32) {
  2520. ntfMsg := &serverproto.SSPlayerStateChangeNtf{
  2521. Uid: this.GetUUid(),
  2522. GuildId: this.GetRoleGuildId(),
  2523. ChangeType: changeType,
  2524. DemonFightTime: this.GetRoleGuild().GetDemonFightTime(),
  2525. }
  2526. if changeType == 2 {
  2527. ntfMsg.DemonFightTime = 0
  2528. }
  2529. this.SendGuild(ntfMsg)
  2530. }
  2531. func (this *Role) PlayerBattleBossOffline() {
  2532. if this.roleMap.ChallengeBossId > 0 {
  2533. ntfMsg := &serverproto.SSPlayerOfflineNtf{
  2534. Uid: this.GetUUid(),
  2535. }
  2536. this.SendBattleBoss(ntfMsg)
  2537. this.roleMap.ChallengeBossId = 0
  2538. }
  2539. }
  2540. func (this *Role) playerMapOffline() {
  2541. if this.roleCross != nil {
  2542. this.roleCross.PlayerLeave(nil)
  2543. }
  2544. }
  2545. func (this *Role) playerBattleOffline() {
  2546. if this.roleBattle != nil {
  2547. this.roleBattle.FastBattleTimeOffline()
  2548. }
  2549. }
  2550. func (this *Role) SetMapRank(selfRank, totalRanks uint32, topRankList []*serverproto.RankPlayerInfo, addSystemMsg bool) {
  2551. if this.roleBattle != nil {
  2552. this.roleBattle.SetMapRank(selfRank, totalRanks, topRankList, addSystemMsg)
  2553. }
  2554. }
  2555. func (this *Role) GetMapRank() {
  2556. if this.roleBattle != nil {
  2557. this.roleBattle.GetMapRank()
  2558. }
  2559. }
  2560. func (this *Role) GetQuickBattleReward() {
  2561. if this.roleBattle != nil {
  2562. this.roleBattle.GetQuickBattleReward()
  2563. }
  2564. }
  2565. // chat
  2566. func (this *Role) CheckChatInvalid(targetId uint64, msgType int32, msg *serverproto.CSChatMessageReq) bool {
  2567. if this.roleChat != nil {
  2568. ret := this.roleChat.CheckChatInvalid(targetId, msgType, msg)
  2569. if ret != serverproto.ErrorCode_ERROR_OK {
  2570. ackMsg := &serverproto.SCChatMessageAck{
  2571. Error: int32(ret),
  2572. }
  2573. this.ReplayGate(ackMsg, true)
  2574. return false
  2575. }
  2576. //发送消息
  2577. this.roleChat.SendMsg(targetId, msgType, msg, false)
  2578. }
  2579. return true
  2580. }
  2581. func (this *Role) GetOfflineMsg(targetId uint64) {
  2582. if this.roleChat != nil {
  2583. ret := this.roleChat.GetOfflineMsg(targetId)
  2584. if ret != serverproto.ErrorCode_ERROR_OK {
  2585. ackMsg := &serverproto.SCChatOfflineMsgAck{
  2586. Error: int32(ret),
  2587. }
  2588. this.ReplayGate(ackMsg, true)
  2589. }
  2590. }
  2591. }
  2592. // mail
  2593. // 添加邮件
  2594. type AddMailST struct {
  2595. ConfigId int32
  2596. MailType serverproto.MailType
  2597. ItemList map[int32]int32
  2598. ParamList []int32
  2599. Title string
  2600. Content string
  2601. }
  2602. func (this *Role) AddMail(configId int32, mailType serverproto.MailType, itemList map[int32]int32, paramList []int32, title, content string) {
  2603. if this.roleMail != nil {
  2604. this.roleMail.AddMail(configId, mailType, itemList, paramList, title, content)
  2605. }
  2606. }
  2607. func (this *Role) AddMailByST(st *AddMailST) {
  2608. if this.roleMail != nil {
  2609. this.roleMail.AddMail(st.ConfigId, st.MailType, st.ItemList, st.ParamList, st.Title, st.Content)
  2610. }
  2611. }
  2612. func (this *Role) AddMail1(configId int32, mailType int32, itemList []*serverproto.KeyValueType, paramList []int32, title, content string) {
  2613. if this.roleMail != nil {
  2614. this.roleMail.AddMail1(configId, serverproto.MailType(mailType), itemList, paramList,
  2615. title, content)
  2616. }
  2617. }
  2618. func (this *Role) GetMailIst() {
  2619. if this.roleMail != nil {
  2620. this.roleMail.GetMailList()
  2621. }
  2622. }
  2623. func (this *Role) MailRead(idList []int32) {
  2624. if this.roleMail != nil {
  2625. ret := this.roleMail.MailRead(idList)
  2626. ackMsg := &serverproto.SCMailReadAck{
  2627. Error: int32(ret),
  2628. }
  2629. this.ReplayGate(ackMsg, true)
  2630. }
  2631. }
  2632. func (this *Role) MailDelRead() {
  2633. if this.roleMail != nil {
  2634. ret := this.roleMail.MailDelRead()
  2635. ackMsg := &serverproto.SCMailDelReadAck{
  2636. Error: int32(ret),
  2637. }
  2638. this.ReplayGate(ackMsg, true)
  2639. }
  2640. }
  2641. func (this *Role) MailReward(idList []int32) {
  2642. if this.roleMail != nil {
  2643. ret := this.roleMail.MailReward(idList)
  2644. if ret != serverproto.ErrorCode_ERROR_OK {
  2645. ackMsg := &serverproto.SCMailRewardAck{
  2646. Error: int32(ret),
  2647. }
  2648. this.ReplayGate(ackMsg, true)
  2649. }
  2650. }
  2651. }
  2652. // 打包数据
  2653. func (this *Role) PackRoleViewInfo(info *serverproto.ViewRoleInfo) {
  2654. info.Id = this.uuid
  2655. info.Brief = &serverproto.CommonPlayerBriefInfo{
  2656. Uid: this.GetUUid(),
  2657. NickName: this.GetNickName(),
  2658. Gender: this.GetRoleBase().GetRoleSex(),
  2659. ImgId: this.GetImageId(),
  2660. FightPower: int32(this.GetRoleBase().RoleData().FightPower),
  2661. HeadFrameId: this.GetRoleBase().RoleData().HeadFrameId,
  2662. ConfigId: this.GetRoleBase().RoleData().HeroData.ConfigId,
  2663. VipLevel: this.GetRoleVipLevel(),
  2664. HeadId: this.GetHeadId(),
  2665. }
  2666. //这里也是有问题的,后续需要处理
  2667. info.AttrList = this.GetRoleHero().GetMainHero().AttrList
  2668. info.FashionData = this.GetRoleBase().roleBase.FashionData
  2669. info.DanScore = this.GetRoleArena().arenaInfo.Score
  2670. //世界boss,只上阵主角
  2671. info.RoleHero = this.GetRoleBase().RoleData().HeroData
  2672. info.Hero = &serverproto.RoleHero{}
  2673. for _, data := range this.GetRoleHero().heroList {
  2674. info.Hero.HeroData = append(info.Hero.HeroData, data)
  2675. }
  2676. info.Fashion = &serverproto.RoleFashion{}
  2677. //for _, data := range this.roleFashion.fashionData {
  2678. //info.Fashion.FashionList = append(info.Fashion.FashionList, data.id)
  2679. this.roleFashion.CopyData(info.Fashion)
  2680. //}
  2681. for _, data := range this.roleFashion.fashionData {
  2682. info.Fashion.FashionList = append(info.Fashion.FashionList, data.id)
  2683. }
  2684. if this.GetRoleGuild().roleGuild.GuildId != 0 {
  2685. info.GuildName = this.GetRoleGuild().roleGuild.GuildName
  2686. }
  2687. if this.GetRolePet() != nil {
  2688. if info.RoleHero.BattlePetId != 0 {
  2689. pet := this.GetRolePet().getPet(info.RoleHero.BattlePetId)
  2690. if pet != nil {
  2691. info.PetList = append(info.PetList, pet)
  2692. }
  2693. }
  2694. for _, hero := range info.Hero.HeroData {
  2695. if hero.BattlePetId != 0 {
  2696. pet := this.GetRolePet().getPet(hero.BattlePetId)
  2697. if pet != nil {
  2698. info.PetList = append(info.PetList, pet)
  2699. }
  2700. }
  2701. }
  2702. }
  2703. }
  2704. func (this *Role) GetSignUpInfo() {
  2705. ackMsg := &serverproto.SCSignUpInfoAck{
  2706. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2707. }
  2708. if this.roleActivity != nil {
  2709. //检查是否大周期重置
  2710. this.roleActivity.CheckNewCircle()
  2711. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_OK)
  2712. ackMsg.SignInfo = this.roleActivity.signInfo
  2713. ackMsg.CurSignDay = this.roleActivity.GetCurSignDay()
  2714. ackMsg.NextSignTime = this.roleActivity.signInfo.CurSignInfo.LastSign
  2715. }
  2716. this.ReplayGate(ackMsg, true)
  2717. }
  2718. func (this *Role) OnSignUp() {
  2719. ackMsg := &serverproto.SCSignUpAck{
  2720. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2721. }
  2722. if this.roleActivity != nil {
  2723. bRet := this.roleActivity.SignUp(ackMsg)
  2724. ackMsg.Error = int32(bRet)
  2725. ackMsg.NextSignTime = int64(util.GetLatest5Hour())
  2726. ackMsg.SignInfo = this.roleActivity.signInfo
  2727. ackMsg.CurSignDay = this.roleActivity.GetCurSignDay()
  2728. }
  2729. this.ReplayGate(ackMsg, true)
  2730. }
  2731. // 强制引导
  2732. func (this *Role) CompulsoryGuidance(storyId, status int32) {
  2733. ackMsg := &serverproto.SCCompulsoryGuidanceAck{
  2734. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2735. }
  2736. if this.GetRoleBase() != nil {
  2737. //设置强制引导
  2738. nRet := this.GetRoleBase().SetCompulsoryId(storyId, status)
  2739. ackMsg.StoryId = storyId
  2740. ackMsg.Status = status
  2741. ackMsg.Error = int32(nRet)
  2742. }
  2743. this.ReplayGate(ackMsg, true)
  2744. }
  2745. // 爬塔功能信息
  2746. // 请求个人的爬塔信息
  2747. func (this *Role) ClimbingTowerInfoReq() {
  2748. if this.roleTower != nil {
  2749. this.roleTower.GetClimbingTowerInfo()
  2750. }
  2751. }
  2752. // 获取试炼馈赠
  2753. func (this *Role) GetTowerLevelDayReward() {
  2754. if this.roleTower != nil {
  2755. ret := this.roleTower.GetTowerLevelDayReward()
  2756. if ret != serverproto.ErrorCode_ERROR_OK {
  2757. ackMsg := &serverproto.SCClimbingTowerDayRewardAck{
  2758. Error: int32(ret),
  2759. }
  2760. this.ReplayGate(ackMsg, true)
  2761. }
  2762. }
  2763. }
  2764. // 查找好友数据
  2765. func (this *Role) GetFriendTowerInfo(begin, end int32) {
  2766. if this.roleTower != nil {
  2767. this.roleTower.GetFriendTowerRange(begin, end)
  2768. }
  2769. }
  2770. // 爬塔开始
  2771. func (this *Role) ClimbingTowerBegin(towerLevel int32) {
  2772. ackMsg := &serverproto.SCClimbingTowerBeginAck{
  2773. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2774. TowerLevel: towerLevel,
  2775. }
  2776. if this.roleTower != nil {
  2777. nRet, factorList := this.roleTower.OnTowerFightBegin(towerLevel)
  2778. ackMsg.Error = int32(nRet)
  2779. ackMsg.FactorList = factorList
  2780. }
  2781. this.ReplayGate(ackMsg, true)
  2782. }
  2783. // 爬塔开始
  2784. func (this *Role) ClimbingTowerWjBegin(towerLevel int32) {
  2785. ackMsg := &serverproto.SCClimbingTowerWjBeginAck{
  2786. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2787. TowerLevel: towerLevel,
  2788. }
  2789. if this.roleTower != nil {
  2790. nRet := this.roleTower.OnTowerWjFightBegin(towerLevel)
  2791. ackMsg.Error = int32(nRet)
  2792. }
  2793. this.ReplayGate(ackMsg, true)
  2794. }
  2795. func (this *Role) ClimbingTowerWjBuff(buff1, buff2, buff3 int32) {
  2796. ackMsg := &serverproto.SCClimbingTowerWjBuffAck{
  2797. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2798. }
  2799. if this.roleTower != nil {
  2800. var nRet serverproto.ErrorCode
  2801. ackMsg.Buff1, ackMsg.Buff2, ackMsg.Buff3, nRet = this.roleTower.OnTowerWjFightBuff(buff1, buff2, buff3)
  2802. ackMsg.Error = int32(nRet)
  2803. }
  2804. this.ReplayGate(ackMsg, true)
  2805. }
  2806. // 爬塔结束
  2807. func (this *Role) ClimbingTowerWjEnd(towerLevel, loadingTime int32, recordTimeStamp uint64) {
  2808. ackMsg := &serverproto.SCClimbingTowerWjEndAck{
  2809. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2810. }
  2811. if this.roleTower != nil {
  2812. nRet := this.roleTower.OnTowerWjFightEnd(towerLevel, loadingTime, recordTimeStamp, ackMsg)
  2813. ackMsg.Error = int32(nRet)
  2814. //打包newTowerLevel=2的所有好友的数据
  2815. //this.roleTower.PackFriendFightTower(towerLevel, ackMsg)
  2816. }
  2817. this.ReplayGate(ackMsg, true)
  2818. }
  2819. // 爬塔结束
  2820. func (this *Role) ClimbingTowerEnd(towerLevel, loadingTime int32, recordTimeStamp uint64) {
  2821. ackMsg := &serverproto.SCClimbingTowerEndAck{
  2822. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2823. }
  2824. if this.roleTower != nil {
  2825. nRet := this.roleTower.OnTowerFightEnd(towerLevel, loadingTime, recordTimeStamp, ackMsg)
  2826. ackMsg.Error = int32(nRet)
  2827. //打包newTowerLevel=2的所有好友的数据
  2828. this.roleTower.PackFriendFightTower(towerLevel, ackMsg)
  2829. }
  2830. this.ReplayGate(ackMsg, true)
  2831. }
  2832. func (this *Role) GetFriendBriefFromDB(final bool, begin int32, end int32, briefs []*serverproto.CommonPlayerBriefInfo) {
  2833. if this.roleTower != nil {
  2834. this.roleTower.SetFriendBriefInfo(briefs)
  2835. //同时返回数据到客户端
  2836. if final == true {
  2837. this.roleTower.SendClimbingTowerInfo(begin, end)
  2838. }
  2839. }
  2840. }
  2841. func (this *Role) GetTowerFightCountReward(rushRound int32, rewardType int32) {
  2842. ackMsg := &serverproto.SCRushActivityRewardAck{
  2843. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2844. RewardType: rewardType,
  2845. RushType: model.Rush_Type_Tower,
  2846. }
  2847. if this.GetRoleTower() != nil {
  2848. nRet := this.GetRoleTower().GetRushTowerBaseReward(ackMsg, rushRound)
  2849. ackMsg.Error = int32(nRet)
  2850. }
  2851. this.ReplayGate(ackMsg, true)
  2852. }
  2853. func (this *Role) GetRushTowerInfo(ackMsg *serverproto.SCTowerActivityAck, curRushRound int32) {
  2854. if this.GetRoleTower() != nil {
  2855. this.GetRoleTower().GetRushTowerInfo(ackMsg, curRushRound)
  2856. }
  2857. }
  2858. func (this *Role) GetRushTowerRankReward(ssAck *serverproto.SSGetRushRewardAck) {
  2859. ackMsg := &serverproto.SCRushActivityRewardAck{
  2860. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2861. RewardType: model.Rush_Reward_Type_Rank,
  2862. RushType: model.Rush_Type_Tower,
  2863. }
  2864. if this.GetRoleTower() != nil {
  2865. nRet := this.GetRoleTower().GetRushTowerRankReward(ssAck)
  2866. if nRet == serverproto.ErrorCode_ERROR_OK {
  2867. ackMsg.ItemList = ssAck.ItemList
  2868. }
  2869. ackMsg.Error = int32(nRet)
  2870. }
  2871. this.ReplayGate(ackMsg, true)
  2872. }
  2873. // 英灵殿冲榜
  2874. func (this *Role) GetArenaFightCountReward(rushRound int32, rewardType int32) {
  2875. ackMsg := &serverproto.SCRushActivityRewardAck{
  2876. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2877. RewardType: rewardType,
  2878. RushType: model.Rush_Type_Arena,
  2879. }
  2880. if this.GetRoleArena() != nil {
  2881. nRet := this.GetRoleArena().GetRushArenaBaseReward(ackMsg, rushRound)
  2882. ackMsg.Error = int32(nRet)
  2883. }
  2884. this.ReplayGate(ackMsg, true)
  2885. }
  2886. func (this *Role) GetRushArenaInfo(ackMsg *serverproto.SCArenaActivityAck, curRushRound int32) {
  2887. if this.GetRoleArena() != nil {
  2888. this.GetRoleArena().GetRushArenaInfo(ackMsg, curRushRound)
  2889. }
  2890. }
  2891. func (this *Role) GetRushArenaRankReward(ssAck *serverproto.SSGetRushRewardAck) {
  2892. ackMsg := &serverproto.SCRushActivityRewardAck{
  2893. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2894. RewardType: model.Rush_Reward_Type_Rank,
  2895. RushType: model.Rush_Type_Arena,
  2896. }
  2897. if this.GetRoleArena() != nil {
  2898. nRet := this.GetRoleArena().GetRushArenaRankReward(ssAck)
  2899. if nRet == serverproto.ErrorCode_ERROR_OK {
  2900. ackMsg.ItemList = ssAck.ItemList
  2901. }
  2902. ackMsg.Error = int32(nRet)
  2903. }
  2904. this.ReplayGate(ackMsg, true)
  2905. }
  2906. // 宠物冲榜
  2907. func (this *Role) GetPetFightCountReward(rushRound int32, rewardType int32) {
  2908. ackMsg := &serverproto.SCRushActivityRewardAck{
  2909. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2910. RewardType: rewardType,
  2911. RushType: model.Rush_Type_Pet,
  2912. }
  2913. if this.GetRolePet() != nil {
  2914. nRet := this.GetRolePet().GetBaseScoreReward(ackMsg, rushRound)
  2915. ackMsg.Error = int32(nRet)
  2916. }
  2917. this.ReplayGate(ackMsg, true)
  2918. }
  2919. func (this *Role) GetRushPetRankReward(ssAck *serverproto.SSGetRushRewardAck) {
  2920. ackMsg := &serverproto.SCRushActivityRewardAck{
  2921. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2922. RewardType: model.Rush_Reward_Type_Rank,
  2923. RushType: model.Rush_Type_Pet,
  2924. }
  2925. if this.GetRolePet() != nil {
  2926. nRet := this.GetRolePet().GetRushPetRankReward(ssAck)
  2927. if nRet == serverproto.ErrorCode_ERROR_OK {
  2928. ackMsg.ItemList = ssAck.ItemList
  2929. }
  2930. ackMsg.Error = int32(nRet)
  2931. }
  2932. this.ReplayGate(ackMsg, true)
  2933. }
  2934. func (this *Role) GetRushPetInfo(ackMsg *serverproto.SCPetActivityAck, curRushRound int32) {
  2935. if this.GetRolePet() != nil {
  2936. this.GetRolePet().GetRushPetInfo(ackMsg, curRushRound)
  2937. }
  2938. }
  2939. // 英灵殿冲榜
  2940. func (this *Role) GetFightCountReward(rushRound int32, rushType int32, rewardType int32) {
  2941. ackMsg := &serverproto.SCRushActivityRewardAck{
  2942. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2943. RewardType: rewardType,
  2944. RushType: rushType,
  2945. }
  2946. if this.GetRoleRush() != nil {
  2947. nRet := this.GetRoleRush().GetBaseReward(ackMsg, rushType, rushRound)
  2948. ackMsg.Error = int32(nRet)
  2949. }
  2950. this.ReplayGate(ackMsg, true)
  2951. }
  2952. func (this *Role) GetRushInfo(ackMsg *serverproto.SCRushActivityAck, curRushRound int32) {
  2953. if this.GetRoleRush() != nil {
  2954. this.GetRoleRush().GetRushInfo(ackMsg, curRushRound)
  2955. }
  2956. }
  2957. func (this *Role) GetRushRankReward(ssAck *serverproto.SSGetRushRewardAck) {
  2958. ackMsg := &serverproto.SCRushActivityRewardAck{
  2959. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2960. RewardType: model.Rush_Reward_Type_Rank,
  2961. RushType: ssAck.RushType,
  2962. }
  2963. if this.GetRoleRush() != nil {
  2964. nRet := this.GetRoleRush().GetRushRankReward(ssAck)
  2965. if nRet == serverproto.ErrorCode_ERROR_OK {
  2966. ackMsg.ItemList = ssAck.ItemList
  2967. }
  2968. ackMsg.Error = int32(nRet)
  2969. }
  2970. this.ReplayGate(ackMsg, true)
  2971. }
  2972. //1:bossReward 2:pvp
  2973. func (this *Role) GetBattleRecord(recordType int32, paramList []uint32) {
  2974. if len(paramList) <= 0 {
  2975. ackMsg := &serverproto.SCPlayerBattleRecordAck{
  2976. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  2977. }
  2978. this.ReplayGate(ackMsg, true)
  2979. return
  2980. }
  2981. msgReq := &serverproto.CSPlayerBattleRecordReq{
  2982. RecordType: recordType,
  2983. ParamList: paramList,
  2984. }
  2985. this.SendRank(msgReq)
  2986. }
  2987. func (this *Role) OnGetBattleRecordAck(ssMsg *serverproto.SCPlayerBattleRecordAck) {
  2988. ackMsg := &serverproto.SCPlayerBattleRecordAck{}
  2989. for idx := 0; idx < len(ssMsg.RecordList); idx++ {
  2990. levelCfgData, ok := serverproto.LevelCfgLoader[ssMsg.RecordList[idx].MapLevelId]
  2991. if !ok || levelCfgData.Version > ssMsg.RecordList[idx].BattleVersion {
  2992. continue
  2993. }
  2994. ackMsg.RecordList = append(ackMsg.RecordList, ssMsg.RecordList[idx])
  2995. }
  2996. this.ReplayGate(ackMsg, true)
  2997. }
  2998. // //////////////////////////// 公会功能 //////////////////////////////////////
  2999. // 创建工会
  3000. func (this *Role) CheckBuildGuild(guildName string, guildBadge int32) serverproto.ErrorCode {
  3001. //检查是否有公会,有就据掉,没有就转GuildServer
  3002. bRet := this.GetRoleGuild().CanBuildGuild(guildName)
  3003. if bRet != serverproto.ErrorCode_ERROR_OK { //有工会不能创建
  3004. ackMsg := &serverproto.SCBuildGuildAck{
  3005. Error: int32(bRet),
  3006. }
  3007. this.ReplayGate(ackMsg, true)
  3008. return bRet
  3009. }
  3010. return serverproto.ErrorCode_ERROR_OK
  3011. }
  3012. func (this *Role) CheckApplyGuild(guildId uint64) bool {
  3013. //检查是否有公会,有就据掉,没有就转GuildServer
  3014. //检查是否在被拒绝列表中
  3015. bRet := this.GetRoleGuild().CheckApply(guildId)
  3016. if bRet != serverproto.ErrorCode_ERROR_OK {
  3017. ackMsg := &serverproto.SCApplyGuildAck{
  3018. Error: int32(bRet),
  3019. }
  3020. this.ReplayGate(ackMsg, true)
  3021. return false
  3022. }
  3023. return true
  3024. }
  3025. // 申请处理
  3026. func (this *Role) CheckApplyInfo(msg *serverproto.CSApplyInfoHandleReq) serverproto.ErrorCode {
  3027. if this.GetRoleGuild().roleGuild.GuildId == 0 {
  3028. ackMsg := &serverproto.SCApplyInfoHandleAck{
  3029. Error: int32(serverproto.ErrorCode_ERROR_GUILD_NOT_IN_GUILD),
  3030. }
  3031. this.ReplayGate(ackMsg, true)
  3032. return serverproto.ErrorCode_ERROR_GUILD_NOT_IN_GUILD
  3033. }
  3034. return serverproto.ErrorCode_ERROR_OK
  3035. }
  3036. func (this *Role) CheckGuildModifyInfo(msg *serverproto.CSSetGuildInfoReq) serverproto.ErrorCode {
  3037. if this.GetRoleGuildId() == 0 {
  3038. return serverproto.ErrorCode_ERROR_GUILD_NOT_IN_GUILD
  3039. }
  3040. //公告长度
  3041. lenData, ok1 := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_Recruit_Max_Len)]
  3042. if !ok1 {
  3043. return serverproto.ErrorCode_ERROR_FAIL
  3044. }
  3045. noticeLen := utf8.RuneCountInString(msg.RecruitNotice)
  3046. if int32(noticeLen) > lenData.IVal {
  3047. return serverproto.ErrorCode_ERROR_GUILD_NOTICE_LEN
  3048. }
  3049. //检查敏感字
  3050. bSensitive := SensitiveUtil.IsMatch(msg.RecruitNotice)
  3051. if bSensitive == true {
  3052. return serverproto.ErrorCode_ERROR_GUILD_NAME_SENSITIVE
  3053. }
  3054. //校验徽章是否存在,
  3055. _, ok := serverproto.GuildBadgeCfgLoader[msg.GuildBadge]
  3056. if ok == false {
  3057. return serverproto.ErrorCode_ERROR_GUILD_CONFIG_NOT_FOUND
  3058. }
  3059. //校验入会等级是否合理
  3060. globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_Apply_Level)]
  3061. if !ok {
  3062. return serverproto.ErrorCode_ERROR_GUILD_CONFIG_NOT_FOUND
  3063. }
  3064. levelRes := strings.Split(globalData.SVal, ":")
  3065. if len(levelRes) >= 2 {
  3066. minLevel, _ := model.Str2Num(levelRes[0])
  3067. maxLevel, _ := model.Str2Num(levelRes[1])
  3068. if int32(minLevel) > msg.JoinLevel || msg.JoinLevel > int32(maxLevel) {
  3069. return serverproto.ErrorCode_ERROR_GUILD_OUT_APPLY_LEVEL
  3070. }
  3071. }
  3072. return serverproto.ErrorCode_ERROR_OK
  3073. }
  3074. func (this *Role) CheckGuildRename(guildName string) serverproto.ErrorCode {
  3075. if this.GetRoleGuildId() == 0 {
  3076. return serverproto.ErrorCode_ERROR_GUILD_NOT_IN_GUILD
  3077. }
  3078. nameLen := utf8.RuneCountInString(guildName)
  3079. if int32(nameLen) < model.GlobalGuildMinNameStringLen || int32(nameLen) > model.GlobalGuildMaxNameStringLen {
  3080. return serverproto.ErrorCode_ERROR_GUILD_NAME_LEN
  3081. }
  3082. //检查敏感字
  3083. bSensitive := SensitiveUtil.IsMatch(guildName)
  3084. if bSensitive == true {
  3085. return serverproto.ErrorCode_ERROR_GUILD_NAME_SENSITIVE
  3086. }
  3087. //校验消耗
  3088. globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_Rename_Cost)]
  3089. if !ok {
  3090. return serverproto.ErrorCode_ERROR_GUILD_CONFIG_NOT_FOUND
  3091. }
  3092. var costItemList = map[int32]int32{}
  3093. costRes := strings.Split(globalData.SVal, ":")
  3094. if len(costRes) >= 2 {
  3095. itemId, _ := model.Str2Num(costRes[0])
  3096. itemNum, _ := model.Str2Num(costRes[1])
  3097. costItemList[int32(itemId)] += int32(itemNum)
  3098. }
  3099. bRet := this.CheckResLitNum(costItemList)
  3100. if bRet == false {
  3101. return serverproto.ErrorCode_ERROR_RES_NOT_ENOUGH
  3102. }
  3103. return serverproto.ErrorCode_ERROR_OK
  3104. }
  3105. func (this *Role) CheckGuildRenotice(notice string) serverproto.ErrorCode {
  3106. globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_Notice_Max_Len)]
  3107. if !ok {
  3108. return serverproto.ErrorCode_ERROR_FAIL
  3109. }
  3110. if this.GetRoleGuildId() == 0 {
  3111. return serverproto.ErrorCode_ERROR_GUILD_NOT_IN_GUILD
  3112. }
  3113. //检查敏感字
  3114. bSensitive := SensitiveUtil.IsMatch(notice)
  3115. if bSensitive == true {
  3116. return serverproto.ErrorCode_ERROR_GUILD_NAME_SENSITIVE
  3117. }
  3118. noticeLen := utf8.RuneCountInString(notice)
  3119. if int32(noticeLen) > globalData.IVal {
  3120. return serverproto.ErrorCode_ERROR_GUILD_NOTICE_LEN
  3121. }
  3122. return serverproto.ErrorCode_ERROR_OK
  3123. }
  3124. func (this *Role) CheckGuildBossChallenge(bossId uint32, damage uint32, fightTime uint32) serverproto.ErrorCode {
  3125. //检查是否有公会,
  3126. guildId := this.GetRoleGuildId()
  3127. if guildId == 0 {
  3128. return serverproto.ErrorCode_ERROR_GUILD_NOT_IN_GUILD
  3129. }
  3130. bRet := this.GetRoleGuild().CheckBossFight(bossId, damage, fightTime)
  3131. return bRet
  3132. }
  3133. func (this *Role) OnChangeGuileNameSuccess() {
  3134. //扣除消耗
  3135. globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_Rename_Cost)]
  3136. if !ok {
  3137. return
  3138. }
  3139. var costItemList = map[int32]int32{}
  3140. costRes := strings.Split(globalData.SVal, ":")
  3141. if len(costRes) >= 2 {
  3142. itemId, _ := model.Str2Num(costRes[0])
  3143. itemNum, _ := model.Str2Num(costRes[1])
  3144. costItemList[int32(itemId)] += int32(itemNum)
  3145. }
  3146. bRet := this.CheckResLitNum(costItemList)
  3147. if bRet == false {
  3148. return
  3149. }
  3150. this.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_Guild})
  3151. }
  3152. func (this *Role) GetRoleGuildId() uint64 {
  3153. if this.GetRoleGuild() == nil {
  3154. return 0
  3155. }
  3156. return this.GetRoleGuild().roleGuild.GuildId
  3157. }
  3158. func (this *Role) GuildDemonBuyFightCount(buyCount int32) {
  3159. if this.GetRoleGuild() != nil {
  3160. ackMsg := &serverproto.SCGuildDemonBuyFightCountAck{}
  3161. err, leftUseCount, leftBuyCount := this.GetRoleGuild().BuyDemonFightCount(buyCount)
  3162. ackMsg.Error = int32(err)
  3163. ackMsg.LeftFightCount = leftUseCount
  3164. ackMsg.LeftBuyCount = leftBuyCount
  3165. this.ReplayGate(ackMsg, true)
  3166. }
  3167. }
  3168. func (this *Role) GetRoleVipLevel() int32 {
  3169. if this.GetRoleBase() != nil {
  3170. return this.GetRoleBase().roleBase.VipLevel
  3171. }
  3172. return 0
  3173. }
  3174. func (this *Role) GetHeadId() int32 {
  3175. if this.roleHead != nil {
  3176. return this.roleHead.GetHeadIdIng()
  3177. }
  3178. return 0
  3179. }
  3180. func (this *Role) GetHeadMag() *RoleHead {
  3181. return this.roleHead
  3182. }
  3183. func (this *Role) OnDrawReq(drawType int32, drawCount int32) {
  3184. ackMsg := &serverproto.SCDrawCardAck{
  3185. DrawType: drawType,
  3186. DrawCount: drawCount,
  3187. }
  3188. if this.roleDraw != nil {
  3189. bRet := this.GetRoleDraw().DrawReq(drawType, drawCount, ackMsg)
  3190. ackMsg.Error = int32(bRet)
  3191. }
  3192. this.ReplayGate(ackMsg, true)
  3193. }
  3194. func (this *Role) CheckRushShopInfoGet(goodsType, goodsId, count int32) bool {
  3195. reqMsg := &serverproto.SSGetRushShopBuyReq{}
  3196. switch (serverproto.PayGoodsType)(goodsType) {
  3197. case serverproto.PayGoodsType_EPayType_RushTower:
  3198. reqMsg.RushType = model.Rush_Type_Tower
  3199. case serverproto.PayGoodsType_EPayType_RushArena:
  3200. reqMsg.RushType = model.Rush_Type_Arena
  3201. case serverproto.PayGoodsType_EPayType_RushMap:
  3202. reqMsg.RushType = model.Rush_Type_Map
  3203. case serverproto.PayGoodsType_EPayType_RushPet:
  3204. reqMsg.RushType = model.Rush_Type_Pet
  3205. case serverproto.PayGoodsType_EPayType_RushSkill:
  3206. reqMsg.RushType = model.Rush_Type_Skill
  3207. default:
  3208. return false
  3209. }
  3210. reqMsg.Uid = this.GetUUid()
  3211. reqMsg.ShopType = goodsType
  3212. reqMsg.GoodsId = goodsId
  3213. reqMsg.GoodsNum = count
  3214. this.SendRank(reqMsg)
  3215. return true
  3216. }
  3217. func (this *Role) OnPayCallback2(cpOrderId uint64) {
  3218. msg33 := &serverproto.SSPayOrderDbReq{
  3219. Uid: this.GetUUid(),
  3220. CpOrderId: cpOrderId,
  3221. }
  3222. this.SendDb(msg33)
  3223. }
  3224. func (this *Role) CheckOrderInfo(payRewardInfo *serverproto.PayOrderSaveInfo) bool {
  3225. if payRewardInfo == nil {
  3226. return false
  3227. }
  3228. if this.roleBag.CanDelItem(40001, int32(payRewardInfo.Amount*100)) {
  3229. this.DelItem(40001, int32(payRewardInfo.Amount*100), AddItemST{
  3230. AddFrom: AddFrom_Activities,
  3231. })
  3232. util.ErrorF("uid:%v use cash buy :%v", this.GetUUid(), payRewardInfo.CpOrderId)
  3233. return true
  3234. }
  3235. return false
  3236. }
  3237. func (this *Role) PayInfoGet(goodsType, goodsId, count int32, rushStage, rushRound int32, cpOrderId uint64, sdkOrderId string) {
  3238. //合服期间,无法进行飞艇探索
  3239. if goodsType == int32(serverproto.PayGoodsType_EPayType_RuneExplore) {
  3240. bRet := this.CheckInCombinedService()
  3241. if bRet == true {
  3242. ackMsg := &serverproto.SCPayInfoGetAck{
  3243. Error: int32(serverproto.ErrorCode_ERROR_RUNE_EXPLORE_ON_COMBINE_SERVER),
  3244. GoodsType: goodsType,
  3245. GoodsId: goodsId,
  3246. Count: count,
  3247. }
  3248. this.ReplayGate(ackMsg, true)
  3249. return
  3250. }
  3251. }
  3252. ret, payOrderInfo := this.payInfoGet(goodsType, goodsId, count, rushStage, rushRound, cpOrderId)
  3253. ackMsg := &serverproto.SCPayInfoGetAck{
  3254. Error: int32(ret),
  3255. GoodsType: goodsType,
  3256. GoodsId: goodsId,
  3257. Count: count,
  3258. }
  3259. msg33 := &serverproto.SSGetServerPayMailReq{
  3260. Uid: this.GetUUid(),
  3261. //ZoneId: int32(service.GetServiceConfig().Node.Zone),
  3262. }
  3263. this.SendDb(msg33)
  3264. if ret == serverproto.ErrorCode_ERROR_OK {
  3265. // 如果是免费或者价格为0时直接购买成功
  3266. if payOrderInfo.Amount <= 0 {
  3267. ntfMsg := &serverproto.SCPayForGoodsNtf{}
  3268. ntfMsg.GoodsId = goodsId
  3269. ntfMsg.ItemList = payOrderInfo.RewardList
  3270. ntfMsg.GoodsType = goodsType
  3271. ntfMsg.GoodsNum = count
  3272. ntfMsg.CpOrderId = 0
  3273. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_PAY_GOOD_PRICE_FREE)
  3274. this.ReplayGate(ackMsg, true)
  3275. this.ReplayGate(ntfMsg, true)
  3276. util.InfoF("uid=%v free: shop:%v id:%v, count:%v", this.GetUUid(), payOrderInfo.GoodsType, payOrderInfo.GoodsId, payOrderInfo.Count)
  3277. return
  3278. }
  3279. calCeilAmount := math.Ceil(float64(payOrderInfo.Amount))
  3280. // 按照配置比例获取RO币
  3281. if model.GlobalRoCoinFactor > 0 {
  3282. tmpRoCoin := calCeilAmount * float64(model.GlobalRoCoinFactor)
  3283. //util.ErrorF("ro1111:%v ,%v ,%v", tmpRoCoin, calCeilAmount, model.GlobalRoCoinFactor)
  3284. payOrderInfo.RewardList = append(payOrderInfo.RewardList, &serverproto.KeyValueType{
  3285. Key: int32(serverproto.ResType_Res_ROCoin),
  3286. Value: int32(tmpRoCoin),
  3287. })
  3288. }
  3289. //给VIP经验
  3290. if model.GlobalRMBToVipExpRMB > 0 {
  3291. vipExp := float32(calCeilAmount) * model.GlobalRMBToVipExpVip / float32(model.GlobalRMBToVipExpRMB)
  3292. payOrderInfo.RewardList = append(payOrderInfo.RewardList, &serverproto.KeyValueType{
  3293. Key: int32(serverproto.ResType_Res_VipExp),
  3294. Value: int32(vipExp),
  3295. })
  3296. //this.role.AddRes(int32(serverproto.ResType_Res_VipExp), AddItemST{ItemCount: int32(vipExp)}, true)
  3297. }
  3298. if service.GetServiceConfig().Node.AuthMode == AUTHMODE_PC {
  3299. //内网PC模式下直接购买成功
  3300. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_PAY_PRODUCTION_MODE)
  3301. this.ReplayGate(ackMsg, true)
  3302. this.OnPayCallback(payOrderInfo, false, false)
  3303. util.InfoF("uid=%v pc mode: shop:%v id:%v, count:%v, price:%v", this.GetUUid(), payOrderInfo.GoodsType, payOrderInfo.GoodsId, payOrderInfo.Count, payOrderInfo.Amount)
  3304. return
  3305. } else if service.GetServiceConfig().Node.AuthMode == AUTHMODE_ACTIVE {
  3306. //激活码模式下提示充值功能未开放
  3307. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_PAY_NOT_OPEN)
  3308. this.ReplayGate(ackMsg, true)
  3309. util.InfoF("uid=%v pc mode: shop:%v id:%v, count:%v, price:%v", this.GetUUid(), payOrderInfo.GoodsType, payOrderInfo.GoodsId, payOrderInfo.Count, payOrderInfo.Amount)
  3310. return
  3311. }
  3312. ordeinfo := OrderRequest{
  3313. GameArea: "s1",
  3314. GameLevel: "50",
  3315. GameOrderId: "ORDER123456",
  3316. GameCurrency: "CNY",
  3317. GamePrice: "99.99",
  3318. GameRoleId: "role_001",
  3319. GameRoleName: "测试角色",
  3320. GameGuid: 12345,
  3321. NotifyId: "-1",
  3322. Subject: "至尊礼包",
  3323. GameAccessVersion: "2507",
  3324. }
  3325. extra := &Extras{
  3326. ServerId: int(payOrderInfo.SId / 2),
  3327. Platform: this.platform,
  3328. CpOrderId: strconv.FormatUint(payOrderInfo.CpOrderId, 10),
  3329. }
  3330. v, _ := json.Marshal(extra)
  3331. ordeinfo.ExtendsInfoData = string(v)
  3332. payOrderInfo.SdkOrderId = sdkOrderId
  3333. //保存订单信息到数据库
  3334. ackMsg.Amount = payOrderInfo.Amount
  3335. ackMsg.CpOrderId = payOrderInfo.CpOrderId
  3336. //ackMsg.GoodsName = payOrderInfo.GoodsName
  3337. info, err := GenerateGameSign(ordeinfo, "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCfYd3FqSaWqCpWLSktBSSgAelt0F6T+tO4C25YKR/6X/sPacDBbX662/0fW+H+YbXigHWFB/yangkhiZTpD/VmiOo5lISX6L0/m+13ti9b8jzTZcfVngfLsP+Ztbk81N1Jk0gWF4bndZxREJ3IxcEDHnIrwXgLGA2GJ89kdgudwIDAQAB")
  3338. if err != nil {
  3339. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_PAY_NOT_OPEN)
  3340. this.ReplayGate(ackMsg, true)
  3341. util.ErrorF("uid=%v GenerateGameSign err:%v", this.GetUUid(), err)
  3342. return
  3343. }
  3344. ackMsg.GoodsName = info
  3345. ssSaveReqMsg := &serverproto.SSPayInfoSaveReq{
  3346. PayOrderInfo: payOrderInfo,
  3347. SaveNotify: true,
  3348. }
  3349. this.SendDb(ssSaveReqMsg)
  3350. } else {
  3351. this.ReplayGate(ackMsg, true)
  3352. }
  3353. }
  3354. func GenerateGameSign(params interface{}, rsaPublicKey string) (string, error) {
  3355. // 1. 将结构体转换为 map
  3356. paramsMap, err := structToMap(params)
  3357. if err != nil {
  3358. return "", err
  3359. }
  3360. // 2. 过滤掉 game_sign 字段
  3361. delete(paramsMap, "game_sign")
  3362. // 3. 获取所有 key 并排序(字典序)
  3363. keys := make([]string, 0, len(paramsMap))
  3364. for k := range paramsMap {
  3365. keys = append(keys, k)
  3366. }
  3367. sort.Strings(keys)
  3368. // 4. 按顺序构建 QueryString
  3369. var queryParts []string
  3370. for _, k := range keys {
  3371. v := paramsMap[k]
  3372. // 跳过空值或零值(根据实际需求调整)
  3373. if v == "" || v == nil {
  3374. continue
  3375. }
  3376. // 将值转换为字符串
  3377. strValue := fmt.Sprintf("%v", v)
  3378. queryParts = append(queryParts, fmt.Sprintf("%s=%s", k, strValue))
  3379. }
  3380. queryString := strings.Join(queryParts, "&")
  3381. // 5. 在 QueryString 后面拼接 RSA 公钥
  3382. stringToSign := queryString + rsaPublicKey
  3383. // 6. 计算 MD5
  3384. hash := md5.Sum([]byte(stringToSign))
  3385. sign := hex.EncodeToString(hash[:])
  3386. return sign, nil
  3387. }
  3388. // structToMap 将结构体转换为 map[string]interface{}
  3389. // 使用 json tag 作为 key
  3390. func structToMap(obj interface{}) (map[string]interface{}, error) {
  3391. result := make(map[string]interface{})
  3392. v := reflect.ValueOf(obj)
  3393. t := reflect.TypeOf(obj)
  3394. // 如果是指针,获取其指向的值
  3395. if v.Kind() == reflect.Ptr {
  3396. v = v.Elem()
  3397. t = t.Elem()
  3398. }
  3399. // 确保是结构体类型
  3400. if v.Kind() != reflect.Struct {
  3401. return nil, fmt.Errorf("expected struct, got %v", v.Kind())
  3402. }
  3403. for i := 0; i < v.NumField(); i++ {
  3404. field := t.Field(i)
  3405. value := v.Field(i)
  3406. // 获取 json tag
  3407. jsonTag := field.Tag.Get("json")
  3408. if jsonTag == "" || jsonTag == "-" {
  3409. continue
  3410. }
  3411. // 处理 omitempty(去除后面的,omitempty)
  3412. jsonTag = strings.Split(jsonTag, ",")[0]
  3413. // 获取字段值
  3414. if value.Kind() == reflect.Ptr && value.IsNil() {
  3415. result[jsonTag] = nil
  3416. } else {
  3417. result[jsonTag] = value.Interface()
  3418. }
  3419. }
  3420. return result, nil
  3421. }
  3422. type OrderRequest struct {
  3423. // 訂單擴展數據,支持JSON或QueryString格式
  3424. ExtendsInfoData string `json:"extends_info_data"` // 最大128字符
  3425. // 角色所在的遊戲區,須與X7game平台上傳的開服表信息中的支付顯示區服欄位一致
  3426. GameArea string `json:"game_area"` // 最大20字符,必填
  3427. // 用戶遊戲中角色等級
  3428. GameLevel string `json:"game_level"` // 最大30字符,必填
  3429. // 遊戲訂單號
  3430. GameOrderId string `json:"game_orderid"` // 最大100字符,必填
  3431. // 貨幣單位,可用值:CNY,USD,HKD,VND,KRW (game_access_version=7.98時新增)
  3432. GameCurrency string `json:"game_currency"` // 最大10字符,必填
  3433. // 商品價格,保留小數點後兩位
  3434. GamePrice string `json:"game_price"` // 格式:10,2,必填
  3435. // 用戶遊戲中角色id信息
  3436. GameRoleId string `json:"game_role_id"` // 最大30字符,必填
  3437. // 用戶遊戲中角色名稱
  3438. GameRoleName string `json:"game_role_name"` // 最大30字符,必填
  3439. // 用戶遊戲小號的唯一標識
  3440. GameGuid int `json:"game_guid"` // 最大12位整數,必填
  3441. // 支付回調通知id,可設置為-1,但不允許為0
  3442. NotifyId string `json:"notify_id"` // 最大11字符,必填
  3443. // 道具簡介
  3444. Subject string `json:"subject"` // 最大100字符,必填
  3445. // 簽名,將其他所有字段按字典序生成QueryString後拼接小7RSA公鑰,再MD5
  3446. GameSign string `json:"game_sign"` // 最大32字符,必填
  3447. // 接入簽名方式版本,新遊戲接入選擇 '2507'
  3448. GameAccessVersion string `json:"game_access_version"` // 最大10字符,必填
  3449. }
  3450. type Extras struct {
  3451. ServerId int `json:"serverId"`
  3452. Platform string `json:"platform"`
  3453. SubPlatform string `json:"subPlatform"`
  3454. Bima string `json:"bima"`
  3455. CpOrderId string `json:"cpOrderId"`
  3456. }
  3457. func (this *Role) payInfoGet(goodsType, goodsId, count int32, rushStage, rushRound int32, cpOrderId uint64) (serverproto.ErrorCode, *serverproto.PayOrderSaveInfo) {
  3458. if count <= 0 {
  3459. return serverproto.ErrorCode_ERROR_PAY_ITEM_NO, nil
  3460. }
  3461. payRewardInfo := &serverproto.PayOrderSaveInfo{
  3462. OrderState: int32(serverproto.PayOrderState_EPayOrderState_Gen),
  3463. GoodsId: goodsId,
  3464. GoodsType: goodsType,
  3465. //早期uid生成规则修改过一次,老的uid无法通过uid来获取到zoneid
  3466. //CpOrderId: model.GenerateUidByZone(int(this.GetSelectZone())),
  3467. Uid: this.GetUUid(),
  3468. OrderProcessTime: util.GetTimeMilliseconds(),
  3469. SId: int32(service.GetServiceConfig().Node.Zone),
  3470. }
  3471. if cpOrderId > 0 {
  3472. payRewardInfo.CpOrderId = cpOrderId
  3473. } else {
  3474. payRewardInfo.CpOrderId = model.GenerateUidByZone(int(this.GetSelectZone()))
  3475. }
  3476. // 根据goodsType查找对应系统物品是否存在,并获得价格,物品
  3477. // for test
  3478. //payRewardInfo.Count = count
  3479. //payRewardInfo.Amount = 1
  3480. //payRewardInfo.GoodsName = "testgoods"
  3481. //payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{Key: 1, Value: 1000})
  3482. switch (serverproto.PayGoodsType)(goodsType) {
  3483. case serverproto.PayGoodsType_EPayType_Discount: //超值礼包购买
  3484. if !this.roleActivity.PayInfoGetDiscount(payRewardInfo) {
  3485. return serverproto.ErrorCode_ERROR_PAY_ITEM_NO, nil
  3486. }
  3487. case serverproto.PayGoodsType_EPayType_MonthCard:
  3488. bRet := this.roleRune.BuyMonthCardShopItem(payRewardInfo)
  3489. if bRet != serverproto.ErrorCode_ERROR_OK {
  3490. return bRet, nil
  3491. }
  3492. case serverproto.PayGoodsType_EPayType_NormalBag:
  3493. bRet := this.roleRune.BuyBagShopItem(payRewardInfo)
  3494. if bRet != serverproto.ErrorCode_ERROR_OK {
  3495. return bRet, nil
  3496. }
  3497. case serverproto.PayGoodsType_EPayType_LimitBag:
  3498. bRet := this.roleRune.BuyLimitShopItem(payRewardInfo)
  3499. if bRet != serverproto.ErrorCode_ERROR_OK {
  3500. return bRet, nil
  3501. }
  3502. case serverproto.PayGoodsType_EPayType_RushTower:
  3503. bRet := this.roleRune.BuyRushTowerShopItem(payRewardInfo, rushStage, rushRound)
  3504. if bRet != serverproto.ErrorCode_ERROR_OK {
  3505. return bRet, nil
  3506. }
  3507. case serverproto.PayGoodsType_EPayType_RushArena:
  3508. bRet := this.roleRune.BuyRushArenaShopItem(payRewardInfo, rushStage, rushRound)
  3509. if bRet != serverproto.ErrorCode_ERROR_OK {
  3510. return bRet, nil
  3511. }
  3512. case serverproto.PayGoodsType_EPayType_RushMap:
  3513. bRet := this.roleRune.BuyRushMapShopItem(payRewardInfo, rushStage, rushRound)
  3514. if bRet != serverproto.ErrorCode_ERROR_OK {
  3515. return bRet, nil
  3516. }
  3517. case serverproto.PayGoodsType_EPayType_GuildBattle:
  3518. bRet := this.roleRune.BuyGuildBattleShopItem(payRewardInfo)
  3519. if bRet != serverproto.ErrorCode_ERROR_OK {
  3520. return bRet, nil
  3521. }
  3522. case serverproto.PayGoodsType_EPayType_RuneExplore:
  3523. bRet := this.roleRune.BuyRuneExplore(payRewardInfo)
  3524. if bRet != serverproto.ErrorCode_ERROR_OK {
  3525. return bRet, nil
  3526. }
  3527. case serverproto.PayGoodsType_EPayType_RushPet:
  3528. bRet := this.roleRune.BuyRushPetShopItem(payRewardInfo, rushStage, rushRound)
  3529. if bRet != serverproto.ErrorCode_ERROR_OK {
  3530. return bRet, nil
  3531. }
  3532. case serverproto.PayGoodsType_EPayType_RushSkill:
  3533. bRet := this.roleRune.BuyRushSkillShopItem(payRewardInfo, rushStage, rushRound)
  3534. if bRet != serverproto.ErrorCode_ERROR_OK {
  3535. return bRet, nil
  3536. }
  3537. case serverproto.PayGoodsType_EPayType_RushIdol:
  3538. bRet := this.roleRune.BuyIdolSeasonShopItem(payRewardInfo)
  3539. if bRet != serverproto.ErrorCode_ERROR_OK {
  3540. return bRet, nil
  3541. }
  3542. case serverproto.PayGoodsType_EPayType_SpecialPrivilege:
  3543. // 特权卡商店
  3544. bRet := this.roleRune.BuySpecialPrivilegeShopItem(payRewardInfo)
  3545. if bRet != serverproto.ErrorCode_ERROR_OK {
  3546. return bRet, nil
  3547. }
  3548. case serverproto.PayGoodsType_EPayType_PassCheck:
  3549. // RO通行证
  3550. bRet := this.roleRune.BuyPassCheck(payRewardInfo)
  3551. if bRet != serverproto.ErrorCode_ERROR_OK {
  3552. return bRet, nil
  3553. }
  3554. case serverproto.PayGoodsType_EPayType_BTRecharge100:
  3555. // bt百元大礼包充值
  3556. bRet := this.roleBT.BuyRecharge100(payRewardInfo)
  3557. if bRet != serverproto.ErrorCode_ERROR_OK {
  3558. return bRet, nil
  3559. }
  3560. default:
  3561. return serverproto.ErrorCode_ERROR_FAIL, nil
  3562. }
  3563. payRewardInfo.GoodsName = service.GetServiceConfig().Node.PayCallBack
  3564. util.ErrorF("uid:%v pay info platform:%v order:%v", this.GetUUid(), this.platform, payRewardInfo)
  3565. //if this.platform == SDKPlatform_YouYi_IOS || this.platform == "PC" {
  3566. // payRewardInfo.GoodsName += ",1"
  3567. //}
  3568. return serverproto.ErrorCode_ERROR_OK, payRewardInfo
  3569. }
  3570. func (this *Role) OnPayCallback(payRewardInfo *serverproto.PayOrderSaveInfo, bSave bool, bAck bool) {
  3571. //获取充值奖励
  3572. var addItemList = map[int32]int32{}
  3573. for idx := 0; idx < len(payRewardInfo.RewardList); idx++ {
  3574. addItemList[payRewardInfo.RewardList[idx].Key] += payRewardInfo.RewardList[idx].Value
  3575. }
  3576. if this.GetRoleBag().CanAddItemList(addItemList) == serverproto.ErrorCode_ERROR_OK {
  3577. if payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_MonthCard) ||
  3578. payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_NormalBag) ||
  3579. payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_LimitBag) ||
  3580. payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_RushTower) ||
  3581. payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_RushMap) ||
  3582. payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_RushPet) ||
  3583. payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_RushSkill) ||
  3584. payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_RushArena) ||
  3585. payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_RushIdol) {
  3586. this.AddItemList(addItemList, AddFrom_Rune, true)
  3587. } else {
  3588. this.AddItemList(addItemList, AddFrom_Pay, true)
  3589. }
  3590. } else {
  3591. mailST := &AddMailST{
  3592. ConfigId: model.GlobalMailIdPayReward,
  3593. MailType: serverproto.MailType_MailType_Pay,
  3594. ItemList: addItemList,
  3595. }
  3596. this.AddMailByST(mailST)
  3597. util.InfoF("uid=%v OnPayCallback add bag error, use mail payRewardInfo=%v", this.GetUUid(), payRewardInfo)
  3598. }
  3599. if bAck {
  3600. ackMsg := &serverproto.SCPayInfoOrderOKListGetAck{}
  3601. for k, v := range addItemList {
  3602. ackMsg.RewardItemList = append(ackMsg.RewardItemList, &serverproto.KeyValueType{Key: k, Value: v})
  3603. }
  3604. this.ReplayGate(ackMsg, true)
  3605. }
  3606. //根据各个系统处理不同情况
  3607. switch (serverproto.PayGoodsType)(payRewardInfo.GoodsType) {
  3608. case serverproto.PayGoodsType_EPayType_Discount: //超值礼包购买
  3609. this.roleActivity.OnPayInfoGetDiscount(payRewardInfo)
  3610. case serverproto.PayGoodsType_EPayType_MonthCard: //
  3611. this.GetRoleRune().OnBuyMonthCardShopItem(payRewardInfo)
  3612. case serverproto.PayGoodsType_EPayType_NormalBag: //
  3613. fallthrough
  3614. case serverproto.PayGoodsType_EPayType_LimitBag: //
  3615. this.GetRoleRune().OnBuyItemSuccess(payRewardInfo)
  3616. case serverproto.PayGoodsType_EPayType_RushTower: //
  3617. fallthrough
  3618. case serverproto.PayGoodsType_EPayType_RushMap: //
  3619. fallthrough
  3620. case serverproto.PayGoodsType_EPayType_RushPet: //
  3621. fallthrough
  3622. case serverproto.PayGoodsType_EPayType_RushSkill: //
  3623. fallthrough
  3624. case serverproto.PayGoodsType_EPayType_RushArena: //
  3625. this.GetRoleRune().OnBuyRushShopSuccess(payRewardInfo)
  3626. case serverproto.PayGoodsType_EPayType_GuildBattle:
  3627. this.GetRoleRune().OnBuyGuildBattleSuccess(payRewardInfo)
  3628. case serverproto.PayGoodsType_EPayType_RuneExplore:
  3629. this.GetRoleRune().RuneUnlock()
  3630. case serverproto.PayGoodsType_EPayType_RushIdol:
  3631. this.GetRoleRune().OnBuyIdolSeasonSuccess(payRewardInfo)
  3632. case serverproto.PayGoodsType_EPayType_SpecialPrivilege:
  3633. // 特权卡商店
  3634. this.GetRoleRune().OnBuySpecialPrivilege(payRewardInfo)
  3635. case serverproto.PayGoodsType_EPayType_PassCheck:
  3636. // RO通行证
  3637. this.GetRoleRune().OnBuyPassCheck(payRewardInfo)
  3638. case serverproto.PayGoodsType_EPayType_BTRecharge100:
  3639. // bt百元大礼包充值
  3640. this.roleBT.OnBuyRecharge100(payRewardInfo)
  3641. default:
  3642. }
  3643. ntfMsg := &serverproto.SCPayForGoodsNtf{}
  3644. ntfMsg.GoodsId = payRewardInfo.GoodsId
  3645. ntfMsg.ItemList = payRewardInfo.RewardList
  3646. ntfMsg.GoodsType = payRewardInfo.GoodsType
  3647. ntfMsg.GoodsNum = payRewardInfo.Count
  3648. ntfMsg.CpOrderId = payRewardInfo.CpOrderId
  3649. this.ReplayGate(ntfMsg, true)
  3650. //充值金额 payRewardInfo.Amount
  3651. // 充值成功后的系统相关处理
  3652. this.GetRoleBase().AddPayRecharge(payRewardInfo)
  3653. ////////
  3654. if bSave {
  3655. payRewardInfo.OrderState = int32(serverproto.PayOrderState_EPayOrderState_PayOkReward)
  3656. ssSaveReqMsg := &serverproto.SSPayInfoSaveReq{
  3657. PayOrderInfo: payRewardInfo,
  3658. }
  3659. this.SendDb(ssSaveReqMsg)
  3660. }
  3661. }
  3662. func (this *Role) PayInfoGetForCreditRecharge(goodsId, count int32) {
  3663. err := this.roleRune.BuyCreditRechargeShopItem(goodsId, count)
  3664. if err != serverproto.ErrorCode_ERROR_OK {
  3665. ackMsg := &serverproto.SCCreditRechargeShopItemBuyAck{
  3666. Error: int32(err),
  3667. GoodsId: goodsId,
  3668. }
  3669. this.ReplayGate(ackMsg, true)
  3670. }
  3671. }
  3672. // 领取特权卡奖励
  3673. func (this *Role) SpecialPrivilegeReward() {
  3674. err := this.roleRune.SpecialPrivilegeReward()
  3675. if err != serverproto.ErrorCode_ERROR_OK {
  3676. ackMsg := &serverproto.SCRuneSpecialPrivilegeRewardAck{
  3677. Error: int32(err),
  3678. }
  3679. this.ReplayGate(ackMsg, true)
  3680. }
  3681. }
  3682. func (this *Role) PayInfoGetForRoCoin(goodsId, count int32) {
  3683. err := this.roleRune.PayInfoGetForRoCoin(goodsId, count)
  3684. if err != serverproto.ErrorCode_ERROR_OK {
  3685. ackMsg := &serverproto.SCBTRoCoinShopItemBuyAck{
  3686. GoodsType: Rune_Shop_Type_Bag,
  3687. SubType: Rune_BagShop_Type_ROCoin,
  3688. Error: int32(err),
  3689. }
  3690. this.ReplayGate(ackMsg, true)
  3691. }
  3692. }
  3693. // GM充值
  3694. func (this *Role) GMPay(amount float32) {
  3695. payRewardInfo := &serverproto.PayOrderSaveInfo{
  3696. Amount: amount,
  3697. OrderProcessTime: util.GetTimeMilliseconds(),
  3698. }
  3699. this.OnPayCallback(payRewardInfo, false, false)
  3700. }
  3701. func (this *Role) GMCalAttr() {
  3702. //var heroList []*serverproto.HeroData
  3703. //heroList = append(heroList, this.roleHero.GetMainHero())
  3704. this.roleBattleAttr.AttrChange(AttrChangeST{
  3705. ChangeType: Attr_Change_None,
  3706. ChangeHeroData: this.roleHero.GetMainHero(),
  3707. })
  3708. for _, val := range this.roleHero.heroList {
  3709. //heroList = append(heroList, val)
  3710. this.roleBattleAttr.AttrChange(AttrChangeST{
  3711. ChangeType: Attr_Change_None,
  3712. ChangeHeroData: val,
  3713. })
  3714. //this.roleBattleAttr.calcAttrHero(val, AttrChangeST{})
  3715. }
  3716. }
  3717. func (this *Role) GetRuneShopInfo(shopType int32, subShop int32) {
  3718. //冲榜卢恩商店流程
  3719. if shopType == Rune_Shop_Type_RushTower ||
  3720. shopType == Rune_Shop_Type_RushArena ||
  3721. shopType == Rune_Shop_Type_RushMap ||
  3722. shopType == Rune_Shop_Type_RushSkill ||
  3723. shopType == Rune_Shop_Type_RushPet {
  3724. reqMsg := &serverproto.SSGetRushShopInfoReq{}
  3725. reqMsg.Uid = this.GetUUid()
  3726. if shopType == Rune_Shop_Type_RushTower {
  3727. reqMsg.RushType = model.Rush_Type_Tower
  3728. } else if shopType == Rune_Shop_Type_RushArena {
  3729. reqMsg.RushType = model.Rush_Type_Arena
  3730. } else if shopType == Rune_Shop_Type_RushMap {
  3731. reqMsg.RushType = model.Rush_Type_Map
  3732. } else if shopType == Rune_Shop_Type_RushPet {
  3733. reqMsg.RushType = model.Rush_Type_Pet
  3734. } else if shopType == Rune_Shop_Type_RushSkill {
  3735. reqMsg.RushType = model.Rush_Type_Skill
  3736. }
  3737. reqMsg.ShopType = shopType
  3738. reqMsg.SubShopId = subShop
  3739. this.SendRank(reqMsg)
  3740. return
  3741. }
  3742. //其他商店
  3743. ackMsg := &serverproto.SCRuneShopInfoAck{
  3744. ShopType: shopType,
  3745. SubShop: subShop,
  3746. }
  3747. if this.GetRoleRune() != nil {
  3748. this.GetRoleRune().GetShopInfo(shopType, subShop, ackMsg)
  3749. }
  3750. util.InfoF("[role.go] GetRuneShopInfo:%+v", *ackMsg)
  3751. this.ReplayGate(ackMsg, true)
  3752. }
  3753. func (this *Role) GetBTShopInfo(shopType int32, subShop int32) {
  3754. util.InfoF("[GetBTShopInfo] shopType=%v subShop:%v", shopType, subShop)
  3755. // 100充值钱包商店
  3756. // RO币礼包商店
  3757. ackMsg := &serverproto.SCBTShopInfoAck{
  3758. ShopType: shopType,
  3759. SubShop: subShop,
  3760. }
  3761. switch shopType {
  3762. case Rune_Shop_Type_CreditRecharge: // 充值钱包商店
  3763. fallthrough
  3764. case Rune_Shop_Type_Bag: // RO币礼包商店
  3765. if this.GetRoleRune() != nil {
  3766. this.GetRoleRune().GetBTShopInfo(shopType, subShop, ackMsg)
  3767. }
  3768. this.ReplayGate(ackMsg, true)
  3769. }
  3770. }
  3771. func (this *Role) GetRushShopInfo(msg *serverproto.SSGetRushShopInfoAck) {
  3772. ackMsg := &serverproto.SCRuneShopInfoAck{
  3773. ShopType: msg.ShopType,
  3774. SubShop: msg.SubShopId,
  3775. }
  3776. if this.GetRoleRune() != nil {
  3777. this.GetRoleRune().GetRuneShopInfo(msg, ackMsg)
  3778. }
  3779. this.ReplayGate(ackMsg, true)
  3780. }
  3781. func (this *Role) OnRuneExploreInfo() {
  3782. ackMsg := &serverproto.SCExploreInfoAck{}
  3783. if this.GetRoleRune() != nil {
  3784. this.GetRoleRune().runeExplore.ConvertMsg(ackMsg)
  3785. }
  3786. this.ReplayGate(ackMsg, true)
  3787. }
  3788. func (this *Role) OnRuneMaxLvlAward() {
  3789. var ackMsg *serverproto.SCExploreExtraRewardAck = nil
  3790. if this.GetRoleRune() != nil {
  3791. ackMsg = this.GetRoleRune().MaxLvlAward()
  3792. }
  3793. this.ReplayGate(ackMsg, true)
  3794. }
  3795. func (this *Role) OnRuneReward(msg *serverproto.CSExploreRewardReq) {
  3796. if msg == nil {
  3797. return
  3798. }
  3799. var ret *serverproto.SCExploreRewardAck = nil
  3800. if rune := this.GetRoleRune(); rune != nil {
  3801. //领取类型:1表示普通奖励,2高级奖励
  3802. ret = rune.OnRuneReward(msg.Level, msg.RewardType)
  3803. //if msg.RewardType == 1 {
  3804. // ret = this.GetRoleRune().RuneReward(msg.Level)
  3805. //} else if msg.RewardType == 2 {
  3806. // ret = this.GetRoleRune().RuneCashReward(msg.Level)
  3807. //}
  3808. }
  3809. this.ReplayGate(ret, true)
  3810. }
  3811. func (this *Role) GetResNotice(resType int32) serverproto.ErrorCode {
  3812. switch serverproto.ResType(resType) {
  3813. case serverproto.ResType_Res_Coin:
  3814. return serverproto.ErrorCode_ERROR_MONEY_NOT_ENOUGH
  3815. case serverproto.ResType_Res_Rmb:
  3816. return serverproto.ErrorCode_ERROR_RMB_NOT_ENOUGH
  3817. case serverproto.ResType_Res_Cruise:
  3818. return serverproto.ErrorCode_ERROR_SHOP_RESOURCE_NOT_NEOUGH_CRUISE
  3819. case serverproto.ResType_Res_SkillBook:
  3820. return serverproto.ErrorCode_ERROR_SHOP_RESOURCE_NOT_NEOUGH_SKILLBOOK
  3821. case serverproto.ResType_Res_Sprite:
  3822. return serverproto.ErrorCode_ERROR_SHOP_RESOURCE_NOT_NEOUGH_SPRITE
  3823. case serverproto.ResType_Res_PetCoin:
  3824. return serverproto.ErrorCode_ERROR_SHOP_RESOURCE_NOT_NEOUGH_PETPIECE
  3825. case serverproto.ResType_Res_Guild:
  3826. return serverproto.ErrorCode_ERROR_SHOP_RESOURCE_NOT_NEOUGH_GUILD
  3827. case serverproto.ResType_Res_HightSkillExp:
  3828. return serverproto.ErrorCode_ERROR_SHOP_RESOURCE_NOT_NEOUGH_SKILLBOOK
  3829. }
  3830. return serverproto.ErrorCode_ERROR_SHOP_RESOURCE_NOT_NEOUGH
  3831. }
  3832. func (this *Role) OnAntiCheatReq(cheatType int32) {
  3833. if this.GetRoleStatistic() != nil {
  3834. this.GetRoleStatistic().RecordCheatData(cheatType)
  3835. ackMsg := &serverproto.SCAntiCheatAck{}
  3836. this.ReplayGate(ackMsg, true)
  3837. }
  3838. }
  3839. func (this *Role) GiftReward(ackMsg *serverproto.SCGiftRewardAck) {
  3840. if ackMsg == nil {
  3841. return
  3842. }
  3843. if ackMsg.Error == 0 {
  3844. if len(ackMsg.RewardList) <= 0 {
  3845. util.DebugF("uid=%v gift code item empty uid=%v", this.GetUUid())
  3846. } else {
  3847. totalItemList := make(map[int32]int32)
  3848. for _, data := range ackMsg.RewardList {
  3849. totalItemList[data.Key] += data.Value
  3850. }
  3851. this.AddItemList(totalItemList, AddFrom_GiftCode, true)
  3852. }
  3853. } else if ackMsg.Error == 1 {
  3854. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_GIFT_CODE_USED)
  3855. } else if ackMsg.Error == 2 {
  3856. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_GIFT_CODE_OUTDATE)
  3857. } else if ackMsg.Error == 3 {
  3858. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_GIFT_CODE_NOT_FOUND)
  3859. } else if ackMsg.Error == 4 {
  3860. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_GIFT_CODE_FORBID)
  3861. } else if ackMsg.Error == int32(serverproto.ErrorCode_ERROR_GIFT_CODE_USE_FAIL) {
  3862. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_GIFT_CODE_USE_FAIL)
  3863. } else if ackMsg.Error == 5 {
  3864. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_GIFT_CODE_REUSE)
  3865. } else {
  3866. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_FAIL)
  3867. }
  3868. }
  3869. func (this *Role) QuestionReward() {
  3870. //model.GlobalQuestionRewardList
  3871. ackMsg := &serverproto.SCQuestionRewardAck{
  3872. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  3873. }
  3874. if this.base.roleBase.QuestionReward <= 0 {
  3875. ret := this.CanAddItemList(model.GlobalQuestionRewardList)
  3876. ackMsg.Error = int32(ret)
  3877. if ret == serverproto.ErrorCode_ERROR_OK {
  3878. this.AddItemList(model.GlobalQuestionRewardList, AddFrom_QuestionReward, true)
  3879. this.base.roleBase.QuestionReward = 1
  3880. this.GetRoleBase().SetDirty(true)
  3881. }
  3882. } else {
  3883. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_QUESTION_REWARDED)
  3884. }
  3885. this.ReplayGate(ackMsg, true)
  3886. }
  3887. func (this *Role) GetKeepSake() {
  3888. ackMsg := &serverproto.SCOnlineGetKeepSakeAck{}
  3889. if this.GetRoleKeepSake() != nil {
  3890. ackMsg.RoleKeepSake = &serverproto.RoleKeepSake{}
  3891. this.GetRoleKeepSake().GetKeepSakeData(ackMsg.RoleKeepSake)
  3892. }
  3893. this.ReplayGate(ackMsg, true)
  3894. }
  3895. func (this *Role) KeepSakeLevelUp(keepSakeId int32) {
  3896. ackMsg := &serverproto.SCKeepSakeLevelUpAck{
  3897. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  3898. }
  3899. if this.GetRoleKeepSake() != nil {
  3900. nRet := this.GetRoleKeepSake().KeepSakeLevelUp(keepSakeId)
  3901. ackMsg.Error = int32(nRet)
  3902. }
  3903. this.ReplayGate(ackMsg, true)
  3904. }
  3905. func (this *Role) OnHeadOperate(msg *serverproto.CSHeadOperateReq) {
  3906. if msg == nil {
  3907. return
  3908. }
  3909. ackMsg := &serverproto.SCHeadOperateAck{
  3910. Error: int32(serverproto.ErrorCode_ERROR_FAIL),
  3911. HeadId: msg.HeadId,
  3912. OperateType: msg.OperateType,
  3913. }
  3914. head := this.roleHead.GetHeadByHeadId(msg.HeadId)
  3915. if head != nil {
  3916. if head.State == int32(Head_Not_Activate) {
  3917. ackMsg.Error = int32(this.roleHead.HeadActivate(msg.HeadId))
  3918. } else if head.State == int32(Head_Wear) {
  3919. ackMsg.Error = int32(this.roleHead.HeadUnload(msg.HeadId))
  3920. } else if head.State == int32(Head_Unload) {
  3921. ackMsg.Error = int32(this.roleHead.HeadWear(msg.HeadId))
  3922. }
  3923. }
  3924. this.ReplayGate(ackMsg, true)
  3925. }
  3926. func (this *Role) OnHeadData(req *serverproto.CSHeadDataReq) {
  3927. ackMsg := &serverproto.SCHeadDataAck{}
  3928. this.roleHead.SendAllHeadData()
  3929. this.ReplayGate(ackMsg, true)
  3930. }
  3931. func (this *Role) OnWishUse(msg *serverproto.CSWishBoxUseReq) {
  3932. ackMsg := &serverproto.SCWishBoxUseAck{}
  3933. error, index := this.roleWish.OnWishBoxUse(msg.ItemId, msg.SelectItem)
  3934. ackMsg.Error, ackMsg.Index = int32(error), index
  3935. this.ReplayGate(ackMsg, true)
  3936. }
  3937. func (this *Role) OnWishSlotUnlock(msg *serverproto.CSWishUnlockSlotReq) {
  3938. ackMsg := &serverproto.SCWishUnlockSlotAck{}
  3939. ackMsg.Error = int32(this.roleWish.OnUnlockWishSlot())
  3940. this.ReplayGate(ackMsg, true)
  3941. }
  3942. func (this *Role) OnWishSlotAction(req *serverproto.CSWishSlotReq) {
  3943. error, awardItem, luckyItem := this.roleWish.OnWishRewardGet(req.Index)
  3944. ackMsg := &serverproto.SCWishSlotReqAck{Error: int32(error), AwardItem: awardItem, LuckyItem: luckyItem}
  3945. this.ReplayGate(ackMsg, true)
  3946. }
  3947. // 检查是否在合服期间
  3948. func (this *Role) CheckInCombinedService() bool {
  3949. bRet, _ := model.CheckInCombined(this.GetSelectZone())
  3950. return bRet
  3951. }
  3952. func (this *Role) CombineServerNtf() {
  3953. ntfMsg := &serverproto.SCCombineServerOnlineNtf{}
  3954. ntfMsg.CombineTime = 0
  3955. data, ok := model.ConvertCombineServerData[1]
  3956. if ok {
  3957. zoneId := this.GetSelectZone()
  3958. for _, server := range data.ServerList {
  3959. if server.Key <= zoneId && zoneId <= server.Value {
  3960. ntfMsg.CombineTime = data.CombineTime
  3961. break
  3962. }
  3963. }
  3964. }
  3965. this.ReplayGate(ntfMsg, true)
  3966. }
  3967. func (this *Role) GetCombineServerInfo() {
  3968. ntfMsg := &serverproto.SCCombineServerInfoAck{}
  3969. bFind := false
  3970. data, ok := model.ConvertCombineServerData[1]
  3971. if ok {
  3972. zoneId := this.GetSelectZone()
  3973. for _, server := range data.ServerList {
  3974. if server.Key <= zoneId && zoneId <= server.Value {
  3975. ntfMsg.Error = int32(serverproto.ErrorCode_ERROR_OK)
  3976. ntfMsg.CombineTime = data.CombineTime
  3977. ntfMsg.Notice = data.Notice
  3978. bFind = true
  3979. break
  3980. }
  3981. }
  3982. }
  3983. if bFind == false {
  3984. ntfMsg.Error = int32(serverproto.ErrorCode_ERROR_COMBINE_SERVER_NOT_IN_STATE)
  3985. ntfMsg.CombineTime = 0
  3986. }
  3987. this.ReplayGate(ntfMsg, true)
  3988. }
  3989. func (this *Role) GMSetCombineServerFinish() {
  3990. model.ConvertCombineServerData = make(map[int32]*model.CombineServer)
  3991. util.InfoF("ConvertCombineServerData len:%v", len(model.ConvertCombineServerData))
  3992. }