role.go 134 KB

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