role.go 126 KB

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