role.go 124 KB

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