role.go 128 KB

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