role_rune.go 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543
  1. package model
  2. import (
  3. "rocommon/service"
  4. "rocommon/util"
  5. "roserver/baseserver/model"
  6. "roserver/serverproto"
  7. "strconv"
  8. "time"
  9. "unsafe"
  10. )
  11. const (
  12. Rune_Shop_Type_MonthCard = 1 //月卡商店
  13. Rune_Shop_Type_Bag = 2 //礼包商店
  14. Rune_Shop_Type_TimeLimit = 3 //限时商店
  15. Rune_Shop_Type_RushTower = 4 //爬塔冲榜商店
  16. Rune_Shop_Type_RushArena = 5 //英灵殿冲榜商店
  17. Rune_Shop_Type_RushMap = 6 //推图冲榜商店
  18. Rune_Shop_Type_GuildBattle = 8 //公会战商店
  19. Rune_Shop_Type_RushPet = 9 //宠物冲榜商店
  20. Rune_Shop_Type_RushSkill = 10 //技能冲榜商店
  21. Rune_Shop_Type_Idol = 11 //偶像季商店
  22. Rune_Shop_Type_CreditRecharge = 100 // 充值钱包商店
  23. )
  24. const (
  25. Rune_BagShop_Type_Day = 1
  26. Rune_BagShop_Type_Week = 2
  27. Rune_BagShop_Type_Month = 3
  28. Rune_BagShop_Type_Gold = 4
  29. Rune_BagShop_Type_CreditRecharge = 5 // 充值钱包类型
  30. Rune_BagShop_Type_ROCoin = 6 // RO币礼包类型
  31. )
  32. type RoleRune struct {
  33. SaveObject
  34. runeGiftShop map[int32]*serverproto.RuneShop
  35. runeLimitShop *serverproto.RuneShop
  36. runeMonthCardShop *serverproto.RuneShop
  37. runeRushTowerShop *serverproto.RuneShop
  38. runeRushArenaShop *serverproto.RuneShop
  39. runeRushMapShop *serverproto.RuneShop
  40. runeGuildBattleShop *serverproto.RuneShop
  41. runeRushPetShop *serverproto.RuneShop
  42. runeRushSkillShop *serverproto.RuneShop
  43. runeIdolSeasonShop *serverproto.RuneShop
  44. runeCreditRecharge map[int32]*serverproto.RuneShop // 充值钱包商店
  45. runeBase *serverproto.RuneBaseData
  46. runeExplore *StRuneExplore
  47. saveShopLists map[int32]bool //卢恩商店变化
  48. tickTime uint64
  49. }
  50. type StRuneExplore struct {
  51. serverproto.RuneExplore
  52. }
  53. func (this *StRuneExplore) init(data *serverproto.RuneExplore) {
  54. if data == nil {
  55. return
  56. }
  57. if !RuneShopMag.IsOpen() || data.AlreadyRune != RuneShopMag.GetCurRound() {
  58. this.resetData()
  59. } else {
  60. this.RuneExplore = *data
  61. }
  62. }
  63. func (this *StRuneExplore) resetData() {
  64. util.InfoF("resetdata rune Explore, %v, %v, %v", RuneShopMag.IsOpen(), RuneShopMag.GetCurRound(), this.AlreadyRune)
  65. this.CurLvl = 1
  66. this.TotalExp = 0
  67. this.MissionExp = 0
  68. this.BUnlock = false
  69. this.FullMaxAward = false
  70. this.State = this.State[0:0]
  71. this.AlreadyRune = 0
  72. }
  73. func (this StRuneExplore) GetTotalExp() int32 {
  74. return this.TotalExp
  75. }
  76. func (this StRuneExplore) GetMissionExp() int32 {
  77. return this.MissionExp
  78. }
  79. func (this StRuneExplore) ConvertMsg(msg *serverproto.SCExploreInfoAck) {
  80. if msg == nil {
  81. return
  82. }
  83. msg.Level = this.CurLvl
  84. msg.TotalExp = this.GetTotalExp()
  85. msg.EndTime = RuneShopMag.GetEndTime()
  86. msg.MissionExp = this.MissionExp
  87. msg.CurRoune = RuneShopMag.GetCurRound()
  88. msg.BUnlock = this.BUnlock
  89. msg.DrawRewar = this.State
  90. msg.FullAward = this.FullMaxAward
  91. msg.StartTime = RuneShopMag.GetStartTime()
  92. msg.NextStartTime = RuneShopMag.GetNextStartTime()
  93. }
  94. //func (this *StRuneExplore) reset() {
  95. // this.CurLvl = 1
  96. // this.TotalExp = 0
  97. // this.MissionExp = 0
  98. // this.BUnlock = false
  99. // this.FullMaxAward = false
  100. // this.State = this.State[0:0]
  101. //}
  102. func (this *StRuneExplore) AddGoldExp(value int32) {
  103. db := RuneShopMag.GetCurDb()
  104. if db == nil {
  105. return
  106. }
  107. this.TotalExp += value * db.GoldScale()
  108. this.RuneUpLvl()
  109. }
  110. func (this *StRuneExplore) AddMissionExp(value int32) {
  111. db := RuneShopMag.GetCurDb()
  112. if db == nil {
  113. return
  114. }
  115. scale := db.MissionScale()
  116. if this.BUnlock {
  117. scale = db.MissionUp()
  118. }
  119. this.MissionExp += value * scale
  120. this.TotalExp += value * scale
  121. this.RuneUpLvl()
  122. }
  123. func (this *StRuneExplore) RuneUpLvl() {
  124. if !RuneShopMag.IsOpen() {
  125. return
  126. }
  127. db := RuneShopMag.GetCurDb()
  128. if db == nil {
  129. return
  130. }
  131. max, ok := model.DbRuneShopExploreMax[db.GetRound()]
  132. if !ok {
  133. return
  134. }
  135. if this.CurLvl >= max.MaxLvl {
  136. return
  137. }
  138. var totalExp int32 = 0
  139. var levle int32 = 1
  140. for {
  141. rewardDb, ok1 := model.DbRuneShopExploreReward[db.GetRound()<<16|levle+1]
  142. if !ok1 {
  143. break
  144. }
  145. totalExp += rewardDb.Exp()
  146. if totalExp > this.GetTotalExp() {
  147. break
  148. }
  149. levle++
  150. }
  151. this.CurLvl = levle
  152. this.AlreadyRune = db.GetRound()
  153. }
  154. func (this *RoleRune) OnRuneReward(lvl int32, awardtype int32) *serverproto.SCExploreRewardAck {
  155. ackMsg := &serverproto.SCExploreRewardAck{}
  156. ackMsg.Level = lvl
  157. ackMsg.Type = awardtype
  158. if !RuneShopMag.IsOpen() {
  159. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_RUNE_NO_OPEN)
  160. return ackMsg
  161. }
  162. if this.runeExplore.CurLvl < lvl {
  163. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_RUNE_LEVLEL_NOT)
  164. return ackMsg
  165. }
  166. db := RuneShopMag.GetCurDb()
  167. if db == nil {
  168. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_RUNE_DATA_ERROR)
  169. return ackMsg
  170. }
  171. rewardDb, ok := model.DbRuneShopExploreReward[db.GetRound()<<16|lvl]
  172. if !ok {
  173. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_RUNE_DATA_ERROR)
  174. return ackMsg
  175. }
  176. index, offset := this.runeExplore.GetStateOffset(lvl)
  177. var awardItems map[int32]int32 = nil
  178. var stateValue *int32 = nil
  179. if awardtype == 1 {
  180. stateValue = &this.runeExplore.State[index].Key
  181. awardItems = rewardDb.GetAward()
  182. } else {
  183. stateValue = &this.runeExplore.State[index].Value
  184. awardItems = rewardDb.GetCashAward()
  185. if !this.runeExplore.BUnlock {
  186. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_RUNE_NO_ULOCK)
  187. return ackMsg
  188. }
  189. }
  190. if awardItems == nil || stateValue == nil {
  191. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_RUNE_DATA_ERROR)
  192. return ackMsg
  193. }
  194. if this.runeExplore.GetAwardState(*stateValue, offset) {
  195. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_RUNE_AWARD_GET)
  196. return ackMsg
  197. }
  198. if err := this.role.CanAddItemList(awardItems); err != serverproto.ErrorCode_ERROR_OK {
  199. ackMsg.Error = int32(err)
  200. return ackMsg
  201. }
  202. this.role.AddItemList(awardItems, AddFrom_Rune, true)
  203. this.runeExplore.SetAwardState(stateValue, offset)
  204. for k, v := range awardItems {
  205. ackMsg.AwardItem = append(ackMsg.AwardItem, &serverproto.KeyValueType{Key: k, Value: v})
  206. }
  207. this.runeExplore.AlreadyRune = db.GetRound()
  208. this.SetDirty(true)
  209. ackMsg.Error = int32(serverproto.ErrorCode_ERROR_OK)
  210. ackMsg.DrawRewar = this.runeExplore.GetState()
  211. return ackMsg
  212. }
  213. // 获得等级对应 状态下标以及偏移
  214. func (this *StRuneExplore) GetStateOffset(lvl int32) (int32, uint) {
  215. if len(this.State) <= 0 {
  216. this.State = append(this.State, &serverproto.KeyValueType{})
  217. }
  218. size := unsafe.Sizeof(this.State[0].Key) * 8
  219. index := lvl / int32(size)
  220. cnt := index
  221. if int(lvl%int32(size)) > 0 {
  222. cnt += 1
  223. }
  224. if len(this.State) < int(cnt) {
  225. for i := 0; i < int(cnt)-len(this.State); i++ {
  226. this.State = append(this.State, &serverproto.KeyValueType{})
  227. }
  228. }
  229. return index, uint(lvl - index*int32(size) - 1)
  230. }
  231. func (this StRuneExplore) GetAwardState(value int32, offset uint) bool {
  232. return uint(value)&(uint(1)<<uint(offset)) != 0
  233. }
  234. func (this *StRuneExplore) SetAwardState(value *int32, offset uint) {
  235. if value == nil {
  236. return
  237. }
  238. *value |= (1 << uint(offset))
  239. }
  240. func (this *StRuneExplore) GetAllAward(roune int32) map[int32]int32 {
  241. retMap := make(map[int32]int32)
  242. for lvl := int32(1); lvl <= this.CurLvl; lvl++ {
  243. index, offset := this.GetStateOffset(lvl)
  244. rewardDb, ok := model.DbRuneShopExploreReward[roune<<16|lvl]
  245. if !ok {
  246. continue
  247. }
  248. if int(index) >= len(this.State) {
  249. continue
  250. }
  251. var stateKey = &this.State[index].Key
  252. if !this.GetAwardState(*stateKey, offset) {
  253. for k, v := range rewardDb.GetAward() {
  254. retMap[k] += v
  255. }
  256. }
  257. var stateValue = &this.State[index].Value
  258. if this.BUnlock && !this.GetAwardState(*stateValue, offset) {
  259. for k, v := range rewardDb.GetCashAward() {
  260. retMap[k] += v
  261. }
  262. }
  263. }
  264. dbMax, ok := model.DbRuneShopExploreMax[roune]
  265. dbExplore := model.GetRuneExploreDataByRound(roune)
  266. if ok && dbExplore != nil && this.CurLvl >= dbMax.MaxLvl {
  267. diffExp := this.GetTotalExp() - dbMax.MaxExp
  268. multiple := diffExp / dbExplore.ExpCost()
  269. if multiple > 0 {
  270. for k, v := range dbExplore.MaxAward() {
  271. retMap[k] += v * multiple
  272. }
  273. }
  274. }
  275. return retMap
  276. }
  277. // 解锁高级奖励
  278. func (this *RoleRune) RuneUnlock() {
  279. //if payRewardInfo.GoodsType != int32(serverproto.PayGoodsType_EPayType_RuneExplore) {
  280. // return
  281. //}
  282. if this.runeExplore.BUnlock {
  283. return
  284. }
  285. db := RuneShopMag.GetCurDb()
  286. if db == nil {
  287. return
  288. }
  289. this.AddMissionExp(this.runeExplore.GetMissionExp() * (db.MissionUp() - db.MissionScale()) / 100)
  290. this.runeExplore.BUnlock = true
  291. msg := &serverproto.SCExploreInfoAck{}
  292. this.runeExplore.ConvertMsg(msg)
  293. this.role.ReplayGate(msg, true)
  294. this.SetDirty(true)
  295. }
  296. // 满级奖励
  297. func (this *RoleRune) MaxLvlAward() *serverproto.SCExploreExtraRewardAck {
  298. runeE := this.runeExplore
  299. ret := &serverproto.SCExploreExtraRewardAck{}
  300. if !RuneShopMag.IsOpen() {
  301. ret.Error = int32(serverproto.ErrorCode_ERROR_OK)
  302. return ret
  303. }
  304. db := RuneShopMag.GetCurDb()
  305. if db == nil {
  306. ret.Error = int32(serverproto.ErrorCode_ERROR_RUNE_DATA_ERROR)
  307. return ret
  308. }
  309. dbMax, ok := model.DbRuneShopExploreMax[db.GetRound()]
  310. if !ok {
  311. ret.Error = int32(serverproto.ErrorCode_ERROR_RUNE_DATA_ERROR)
  312. return ret
  313. }
  314. if runeE.CurLvl < dbMax.MaxLvl {
  315. ret.Error = int32(serverproto.ErrorCode_ERROR_RUNE_LEVLEL_NOT)
  316. return ret
  317. }
  318. dbExplore := model.GetRuneExploreDataByRound(db.GetRound())
  319. if dbExplore == nil {
  320. ret.Error = int32(serverproto.ErrorCode_ERROR_RUNE_DATA_ERROR)
  321. return ret
  322. }
  323. if runeE.GetTotalExp() < dbMax.MaxExp+dbExplore.ExpCost() {
  324. ret.Error = int32(serverproto.ErrorCode_ERROR_FAIL)
  325. return ret
  326. }
  327. if err := this.role.CanAddItemList(dbExplore.MaxAward()); err != serverproto.ErrorCode_ERROR_OK {
  328. ret.Error = int32(err)
  329. return ret
  330. }
  331. runeE.FullMaxAward = true
  332. diffExp := runeE.GetTotalExp() - dbMax.MaxExp
  333. multiple := diffExp / dbExplore.ExpCost()
  334. var items = make(map[int32]int32)
  335. for k, v := range dbExplore.MaxAward() {
  336. items[k] = v * multiple
  337. }
  338. this.role.AddItemList(items, AddFrom_Rune, true)
  339. runeE.TotalExp -= dbExplore.ExpCost() * multiple
  340. for k, v := range items {
  341. ret.AwardItem = append(ret.AwardItem, &serverproto.KeyValueType{Key: k, Value: v})
  342. }
  343. this.SetDirty(true)
  344. ret.TotalExp = runeE.GetTotalExp()
  345. ret.MissionExp = runeE.GetMissionExp()
  346. ret.Error = int32(serverproto.ErrorCode_ERROR_OK)
  347. return ret
  348. }
  349. func (this *RoleRune) AddGoldExp(value int32) {
  350. if !RuneShopMag.IsOpen() {
  351. return
  352. }
  353. this.runeExplore.AddGoldExp(value)
  354. this.SetDirty(true)
  355. this.SendExpChange()
  356. }
  357. func (this *RoleRune) AddMissionExp(value int32) {
  358. if !RuneShopMag.IsOpen() {
  359. return
  360. }
  361. this.runeExplore.AddMissionExp(value)
  362. this.SetDirty(true)
  363. this.SendExpChange()
  364. }
  365. func (this RoleRune) SendExpChange() {
  366. msg := &serverproto.SCExploreExpChangeNtf{}
  367. msg.TotalExp = this.runeExplore.GetTotalExp()
  368. msg.MissionExp = this.runeExplore.GetMissionExp()
  369. msg.Level = this.runeExplore.GetCurLvl()
  370. this.role.ReplayGate(msg, true)
  371. }
  372. func newRoleRune(r *Role) *RoleRune {
  373. roleRune := &RoleRune{
  374. SaveObject: SaveObject{
  375. role: r,
  376. },
  377. }
  378. roleRune.runeGiftShop = make(map[int32]*serverproto.RuneShop)
  379. roleRune.runeLimitShop = &serverproto.RuneShop{}
  380. roleRune.runeMonthCardShop = &serverproto.RuneShop{}
  381. roleRune.runeRushTowerShop = &serverproto.RuneShop{}
  382. roleRune.runeRushArenaShop = &serverproto.RuneShop{}
  383. roleRune.runeRushMapShop = &serverproto.RuneShop{}
  384. roleRune.runeGuildBattleShop = &serverproto.RuneShop{}
  385. roleRune.runeRushPetShop = &serverproto.RuneShop{}
  386. roleRune.runeRushSkillShop = &serverproto.RuneShop{}
  387. roleRune.runeIdolSeasonShop = &serverproto.RuneShop{}
  388. roleRune.saveShopLists = make(map[int32]bool)
  389. roleRune.runeBase = &serverproto.RuneBaseData{}
  390. roleRune.runeExplore = &StRuneExplore{}
  391. roleRune.runeExplore.resetData()
  392. return roleRune
  393. }
  394. func (this *RoleRune) Load(msg interface{}) bool {
  395. proRole := msg.(*serverproto.Role)
  396. if proRole == nil {
  397. return false
  398. }
  399. if proRole.RoleRune != nil {
  400. this.runeBase = proRole.RoleRune.RuneBase
  401. if this.runeBase == nil {
  402. this.runeBase = &serverproto.RuneBaseData{
  403. PrivilegeData: &serverproto.RuneSpecialPrivilegeData{},
  404. }
  405. }
  406. // 充值钱包没有达到上限时处理
  407. // 特权卡商店初始化
  408. this.loadCreditRecharge()
  409. util.InfoF("proRole.RoleRune.ShopList :%v", proRole.RoleRune.ShopList)
  410. for _, data := range proRole.RoleRune.ShopList {
  411. if data.ShopId == Rune_Shop_Type_MonthCard {
  412. this.runeMonthCardShop = data
  413. } else if data.ShopId == Rune_Shop_Type_Bag {
  414. this.runeGiftShop[data.SubShopId] = data
  415. } else if data.ShopId == Rune_Shop_Type_TimeLimit {
  416. this.runeLimitShop = data
  417. } else if data.ShopId == Rune_Shop_Type_RushTower {
  418. this.runeRushTowerShop = data
  419. } else if data.ShopId == Rune_Shop_Type_RushArena {
  420. this.runeRushArenaShop = data
  421. } else if data.ShopId == Rune_Shop_Type_RushMap {
  422. this.runeRushMapShop = data
  423. } else if data.SubShopId == Rune_Shop_Type_GuildBattle {
  424. this.runeGuildBattleShop = data
  425. } else if data.ShopId == Rune_Shop_Type_RushPet {
  426. this.runeRushPetShop = data
  427. } else if data.ShopId == Rune_Shop_Type_RushSkill {
  428. this.runeRushSkillShop = data
  429. } else if data.ShopId == Rune_Shop_Type_Idol {
  430. this.runeIdolSeasonShop = data
  431. util.InfoF("this.runeIdolSeasonShop: %v", this.runeIdolSeasonShop)
  432. } else if data.ShopId == Rune_Shop_Type_CreditRecharge {
  433. this.runeCreditRecharge[data.SubShopId] = data
  434. }
  435. }
  436. if len(proRole.RoleRune.ShopList) <= 0 {
  437. this.InitGiftShop()
  438. this.InitLimitShop()
  439. this.InitMonthCardShop()
  440. this.InitRushTowerShop()
  441. this.InitRushArenaShop()
  442. this.InitRushMapShop()
  443. this.InitGuildBattleShop()
  444. this.InitRushPetShop()
  445. this.InitRushSkillShop()
  446. this.InitIdolSeasonShop()
  447. this.initCreditRechargeShop()
  448. this.initSpecialShop()
  449. } else {
  450. this.CheckNewGoodsAdd()
  451. }
  452. if !RuneShopMag.IsValid() {
  453. util.ErrorF("RuneShopMag init not finish")
  454. return false
  455. }
  456. //if proRole.RoleRune.RuneExplore != nil {
  457. this.runeExplore.init(proRole.RoleRune.RuneExplore)
  458. //}
  459. }
  460. this.tickTime = util.GetCurrentTime()
  461. util.InfoF("[Rune] InitGiftShop:%v", this.runeGiftShop)
  462. return true
  463. }
  464. func (this *RoleRune) loadCreditRecharge() {
  465. this.runeCreditRecharge = map[int32]*serverproto.RuneShop{}
  466. // 充值钱包没有达到上限时处理
  467. if !this.runeBase.CreditRechargeLimit {
  468. if this.runeBase.MaxCreditRecharge <= 0 {
  469. this.runeBase.MaxCreditRecharge = model.GlobalCreditRechargeInitMax
  470. this.SetDirty(true)
  471. }
  472. }
  473. // 特权卡商店初始化
  474. if this.runeBase.PrivilegeData == nil {
  475. this.runeBase.PrivilegeData = &serverproto.RuneSpecialPrivilegeData{}
  476. }
  477. }
  478. func (this *RoleRune) Save() {
  479. this.SetDirty(false)
  480. util.DebugF("uid=%v RoleRune save... %v", this.role.GetUUid(), this.runeExplore)
  481. saveMsg := &serverproto.SSRuneDataSaveReq{
  482. RoleRune: &serverproto.RoleRune{},
  483. }
  484. for key, value := range this.saveShopLists {
  485. if value == true {
  486. if key == Rune_Shop_Type_MonthCard {
  487. saveMsg.RoleRune.ShopList = append(saveMsg.RoleRune.ShopList, this.runeMonthCardShop)
  488. } else if key == Rune_Shop_Type_Bag {
  489. for _, shop := range this.runeGiftShop {
  490. saveMsg.RoleRune.ShopList = append(saveMsg.RoleRune.ShopList, shop)
  491. }
  492. } else if key == Rune_Shop_Type_TimeLimit {
  493. saveMsg.RoleRune.ShopList = append(saveMsg.RoleRune.ShopList, this.runeLimitShop)
  494. } else if key == Rune_Shop_Type_RushTower {
  495. saveMsg.RoleRune.ShopList = append(saveMsg.RoleRune.ShopList, this.runeRushTowerShop)
  496. } else if key == Rune_Shop_Type_RushArena {
  497. saveMsg.RoleRune.ShopList = append(saveMsg.RoleRune.ShopList, this.runeRushArenaShop)
  498. } else if key == Rune_Shop_Type_RushMap {
  499. saveMsg.RoleRune.ShopList = append(saveMsg.RoleRune.ShopList, this.runeRushMapShop)
  500. } else if key == Rune_Shop_Type_RushPet {
  501. saveMsg.RoleRune.ShopList = append(saveMsg.RoleRune.ShopList, this.runeRushPetShop)
  502. } else if key == Rune_Shop_Type_RushSkill {
  503. saveMsg.RoleRune.ShopList = append(saveMsg.RoleRune.ShopList, this.runeRushSkillShop)
  504. } else if key == Rune_Shop_Type_Idol {
  505. saveMsg.RoleRune.ShopList = append(saveMsg.RoleRune.ShopList, this.runeIdolSeasonShop)
  506. } else if key == Rune_Shop_Type_CreditRecharge {
  507. for _, shop := range this.runeCreditRecharge {
  508. saveMsg.RoleRune.ShopList = append(saveMsg.RoleRune.ShopList, shop)
  509. }
  510. }
  511. }
  512. delete(this.saveShopLists, key)
  513. }
  514. saveMsg.RoleRune.RuneExplore = &this.runeExplore.RuneExplore
  515. saveMsg.RoleRune.RuneBase = this.runeBase
  516. //if len(saveMsg.RoleRune.ShopList) > 0 {
  517. this.role.SendDb(saveMsg)
  518. //}
  519. }
  520. func (this *RoleRune) RuneExploreEndAward() {
  521. roleRune := this.runeExplore
  522. if roleRune.AlreadyRune <= 0 {
  523. return
  524. }
  525. if RuneShopMag.GetCurRound() == roleRune.AlreadyRune {
  526. return
  527. }
  528. mapAward := roleRune.GetAllAward(roleRune.AlreadyRune)
  529. if len(mapAward) > 0 {
  530. this.role.AddMail(model.GlobalMailRuneExplore, serverproto.MailType_MailType_Rune_Explore, mapAward, []int32{}, "", "")
  531. }
  532. util.InfoF("uid=%v RuneExploreEndAward over Award Reset", this.role.GetUUid())
  533. //roleRune.AlreadyRune = 0
  534. roleRune.resetData()
  535. this.SetDirty(true)
  536. }
  537. func (this *RoleRune) CopyData(rune *serverproto.RoleRune) {
  538. rune.ShopList = append(rune.ShopList, this.runeLimitShop)
  539. for _, data := range this.runeGiftShop {
  540. rune.ShopList = append(rune.ShopList, data)
  541. }
  542. }
  543. func (this *RoleRune) addShopChange(shopId int32) {
  544. this.saveShopLists[shopId] = true
  545. this.SetDirty(true)
  546. }
  547. // 上线是否有可领取的礼包
  548. func (this *RoleRune) HasFreeBag() bool {
  549. for _, data := range model.ConvertFreeBag {
  550. _, ok := this.runeGiftShop[data.BagType]
  551. if !ok {
  552. return false
  553. }
  554. for _, goods := range this.runeGiftShop[data.BagType].GoodsInfo {
  555. if goods.BuyNum < data.LimitCount {
  556. return true
  557. }
  558. }
  559. }
  560. return false
  561. }
  562. func (this *RoleRune) GetNextRefresh(bagType int32) uint64 {
  563. if bagType == Rune_BagShop_Type_Day ||
  564. bagType == Rune_BagShop_Type_CreditRecharge ||
  565. bagType == Rune_BagShop_Type_ROCoin {
  566. return util.GetLatest5Hour()
  567. } else if bagType == Rune_BagShop_Type_Week {
  568. return util.GetLatestWeek5Hour(0)
  569. } else if bagType == Rune_BagShop_Type_Month {
  570. return util.GetLatestMonth5Hour()
  571. }
  572. return 0
  573. }
  574. func (this *RoleRune) InitGiftShop() {
  575. //初始化礼包商店
  576. this.runeGiftShop = make(map[int32]*serverproto.RuneShop)
  577. for _, data := range model.ConvertGiftBag {
  578. _, ok := this.runeGiftShop[data.BagType]
  579. if !ok {
  580. shopData := &serverproto.RuneShop{
  581. ShopId: Rune_Shop_Type_Bag,
  582. SubShopId: data.BagType,
  583. NextRefresh: int64(this.GetNextRefresh(data.BagType)),
  584. }
  585. this.runeGiftShop[data.BagType] = shopData
  586. }
  587. goods := &serverproto.RuneGoods{
  588. GoodsId: data.GoodsId,
  589. BuyNum: 0,
  590. HistoryBuy: 0,
  591. }
  592. this.runeGiftShop[data.BagType].GoodsInfo = append(this.runeGiftShop[data.BagType].GoodsInfo, goods)
  593. }
  594. this.addShopChange(Rune_Shop_Type_Bag)
  595. }
  596. // 初次加载或者大版本重置。
  597. func (this *RoleRune) InitLimitShop() {
  598. //初始化限时商店
  599. this.runeLimitShop = &serverproto.RuneShop{
  600. ShopId: Rune_Shop_Type_TimeLimit,
  601. SubShopId: 0,
  602. NextRefresh: 0,
  603. }
  604. for _, data := range model.ConvertLimitGag {
  605. goods := &serverproto.RuneGoods{
  606. GoodsId: data.GoodsId,
  607. BuyNum: 0,
  608. HistoryBuy: 0,
  609. }
  610. this.runeLimitShop.GoodsInfo = append(this.runeLimitShop.GoodsInfo, goods)
  611. }
  612. this.addShopChange(Rune_Shop_Type_TimeLimit)
  613. }
  614. const restTime = 1000
  615. func (this *RoleRune) Update(ms uint64) {
  616. if this.tickTime == 0 {
  617. return
  618. }
  619. if this.tickTime+restTime > ms {
  620. return
  621. }
  622. this.tickTime += ms
  623. bChange := false
  624. if this.runeBase.MonthCardModify == false {
  625. this.CheckMonthCardLeftTime()
  626. bChange = true
  627. } else {
  628. for _, data := range this.runeMonthCardShop.GoodsInfo {
  629. if data.NextRewardTime >= data.EndTime && data.EndTime < int64(ms) && data.EndTime > 0 {
  630. data.EndTime = 0
  631. bChange = true
  632. }
  633. }
  634. }
  635. if bChange {
  636. this.addShopChange(Rune_Shop_Type_MonthCard)
  637. }
  638. }
  639. func (this *RoleRune) CheckMonthCardLeftTime() {
  640. nowTime := util.GetCurrentTime()
  641. for _, data := range this.runeMonthCardShop.GoodsInfo {
  642. if data.EndTime == 0 {
  643. continue
  644. }
  645. realEndTime := this.ModifyCardEndTime(data.EndTime)
  646. if realEndTime != 0 {
  647. data.EndTime = realEndTime
  648. }
  649. if data.NextRewardTime >= data.EndTime && data.EndTime < int64(nowTime) {
  650. data.EndTime = 0
  651. }
  652. }
  653. this.runeBase.MonthCardModify = true
  654. }
  655. // 初次加载或者大版本重置。
  656. func (this *RoleRune) InitMonthCardShop() {
  657. //初始化限时商店
  658. this.runeMonthCardShop = &serverproto.RuneShop{
  659. ShopId: Rune_Shop_Type_MonthCard,
  660. SubShopId: 0,
  661. NextRefresh: 0,
  662. }
  663. for _, data := range model.ConvertMonthCard {
  664. goods := &serverproto.RuneGoods{
  665. GoodsId: data.GoodsId,
  666. BuyNum: 0,
  667. HistoryBuy: 0,
  668. }
  669. this.runeMonthCardShop.GoodsInfo = append(this.runeMonthCardShop.GoodsInfo, goods)
  670. }
  671. this.addShopChange(Rune_Shop_Type_MonthCard)
  672. }
  673. // 初次加载或者大版本重置。
  674. func (this *RoleRune) InitRushTowerShop() {
  675. //初始化限时商店
  676. this.runeRushTowerShop = &serverproto.RuneShop{
  677. ShopId: Rune_Shop_Type_RushTower,
  678. SubShopId: 0,
  679. NextRefresh: 0,
  680. }
  681. for _, data := range model.ConvertTowerShop {
  682. goods := &serverproto.RuneGoods{
  683. GoodsId: data.GoodsId,
  684. BuyNum: 0,
  685. HistoryBuy: 0,
  686. }
  687. this.runeRushTowerShop.GoodsInfo = append(this.runeRushTowerShop.GoodsInfo, goods)
  688. }
  689. this.addShopChange(Rune_Shop_Type_RushTower)
  690. }
  691. // 初次加载或者大版本重置。
  692. func (this *RoleRune) InitRushArenaShop() {
  693. //初始化限时商店
  694. this.runeRushArenaShop = &serverproto.RuneShop{
  695. ShopId: Rune_Shop_Type_RushArena,
  696. SubShopId: 0,
  697. NextRefresh: 0,
  698. }
  699. for _, data := range model.ConvertArenaShop {
  700. goods := &serverproto.RuneGoods{
  701. GoodsId: data.GoodsId,
  702. BuyNum: 0,
  703. HistoryBuy: 0,
  704. }
  705. this.runeRushArenaShop.GoodsInfo = append(this.runeRushArenaShop.GoodsInfo, goods)
  706. }
  707. this.addShopChange(Rune_Shop_Type_RushArena)
  708. }
  709. // 初次加载或者大版本重置。
  710. func (this *RoleRune) InitRushMapShop() {
  711. //初始化限时商店
  712. this.runeRushMapShop = &serverproto.RuneShop{
  713. ShopId: Rune_Shop_Type_RushMap,
  714. SubShopId: 0,
  715. NextRefresh: 0,
  716. }
  717. for _, data := range model.ConvertMapShop {
  718. goods := &serverproto.RuneGoods{
  719. GoodsId: data.GoodsId,
  720. BuyNum: 0,
  721. HistoryBuy: 0,
  722. }
  723. this.runeRushMapShop.GoodsInfo = append(this.runeRushMapShop.GoodsInfo, goods)
  724. }
  725. this.addShopChange(Rune_Shop_Type_RushMap)
  726. }
  727. // 初次加载或者大版本重置。
  728. func (this *RoleRune) InitRushPetShop() {
  729. //初始化限时商店
  730. this.runeRushPetShop = &serverproto.RuneShop{
  731. ShopId: Rune_Shop_Type_RushPet,
  732. SubShopId: 0,
  733. NextRefresh: 0,
  734. }
  735. for _, data := range model.ConvertPetShop {
  736. goods := &serverproto.RuneGoods{
  737. GoodsId: data.GoodsId,
  738. BuyNum: 0,
  739. HistoryBuy: 0,
  740. }
  741. this.runeRushPetShop.GoodsInfo = append(this.runeRushPetShop.GoodsInfo, goods)
  742. }
  743. this.addShopChange(Rune_Shop_Type_RushPet)
  744. }
  745. // 初次加载或者大版本重置。
  746. func (this *RoleRune) InitRushSkillShop() {
  747. //初始化限时商店
  748. this.runeRushSkillShop = &serverproto.RuneShop{
  749. ShopId: Rune_Shop_Type_RushSkill,
  750. SubShopId: 0,
  751. NextRefresh: 0,
  752. }
  753. for _, data := range model.ConvertSkillShop {
  754. goods := &serverproto.RuneGoods{
  755. GoodsId: data.GoodsId,
  756. BuyNum: 0,
  757. HistoryBuy: 0,
  758. }
  759. this.runeRushSkillShop.GoodsInfo = append(this.runeRushSkillShop.GoodsInfo, goods)
  760. }
  761. this.addShopChange(Rune_Shop_Type_RushSkill)
  762. }
  763. // 初次加载或者大版本重置。
  764. func (this *RoleRune) InitIdolSeasonShop() {
  765. //初始化限时商店
  766. this.runeIdolSeasonShop = &serverproto.RuneShop{
  767. ShopId: Rune_Shop_Type_Idol,
  768. SubShopId: 0,
  769. NextRefresh: 0,
  770. }
  771. for _, data := range model.ConvertIdolShop {
  772. goods := &serverproto.RuneGoods{
  773. GoodsId: data.GoodsId,
  774. BuyNum: 0,
  775. HistoryBuy: 0,
  776. }
  777. this.runeIdolSeasonShop.GoodsInfo = append(this.runeIdolSeasonShop.GoodsInfo, goods)
  778. }
  779. this.addShopChange(Rune_Shop_Type_Idol)
  780. }
  781. // 初次加载或者大版本重置。
  782. func (this *RoleRune) InitGuildBattleShop() {
  783. //初始化限时商店
  784. this.runeGuildBattleShop = &serverproto.RuneShop{
  785. ShopId: Rune_Shop_Type_GuildBattle,
  786. SubShopId: 0,
  787. NextRefresh: 0,
  788. }
  789. for _, data := range model.ConvertMapShop {
  790. goods := &serverproto.RuneGoods{
  791. GoodsId: data.GoodsId,
  792. BuyNum: 0,
  793. HistoryBuy: 0,
  794. }
  795. this.runeGuildBattleShop.GoodsInfo = append(this.runeGuildBattleShop.GoodsInfo, goods)
  796. }
  797. this.addShopChange(Rune_Shop_Type_GuildBattle)
  798. }
  799. func (this *RoleRune) initCreditRechargeShop() {
  800. // 充值钱包商店
  801. // 初始化礼包商店
  802. //this.runeCreditRecharge = make(map[int32]*serverproto.RuneShop)
  803. for _, data := range model.ConvertPurseShop {
  804. _, ok := this.runeCreditRecharge[data.BagType] // Rune_BagShop_Type_CreditRecharge
  805. if !ok {
  806. shopData := &serverproto.RuneShop{
  807. ShopId: Rune_Shop_Type_CreditRecharge,
  808. SubShopId: data.BagType,
  809. NextRefresh: int64(this.GetNextRefresh(data.BagType)), // 日,周,月需要获取下次更新时间的goods
  810. }
  811. this.runeCreditRecharge[data.BagType] = shopData
  812. }
  813. goods := &serverproto.RuneGoods{
  814. GoodsId: data.GoodsId,
  815. BuyNum: 0,
  816. HistoryBuy: 0,
  817. }
  818. this.runeCreditRecharge[data.BagType].GoodsInfo = append(this.runeCreditRecharge[data.BagType].GoodsInfo, goods)
  819. }
  820. this.addShopChange(Rune_Shop_Type_CreditRecharge)
  821. }
  822. func (this *RoleRune) initSpecialShop() {
  823. // 特权卡商店
  824. }
  825. func (this *RoleRune) DailyReset(notify bool) {
  826. this.ResetGiftShop()
  827. this.ResetLimitShop()
  828. this.ResetMonthCardShop()
  829. this.ResetRushTowerShop()
  830. this.ResetRushArenaShop()
  831. this.ResetRushMapShop()
  832. this.ResetGuildBattleShop()
  833. this.ResetRushSkillShop()
  834. // 充值钱包商店
  835. this.ResetCreditRechargeShop(notify)
  836. this.CheckNewGoodsAdd()
  837. if notify == true {
  838. this.GetFreeGoodsData()
  839. }
  840. //给奖励
  841. this.SendMonthCardMail()
  842. }
  843. func (this *RoleRune) ModifyCardEndTime(endTime int64) int64 {
  844. //获得结束天数的凌晨5点。
  845. loc := util.GetLoc()
  846. tmpTime := util.GetTimeByUint64(uint64(endTime))
  847. dayT1Str := tmpTime.Format(util.DATE_FORMAT1)
  848. dayT1, _ := time.ParseInLocation(util.DATE_FORMAT1, dayT1Str, loc)
  849. dayT1 = dayT1.Add(time.Hour * 5)
  850. dayT1Sec := dayT1.UnixNano() / 1e6
  851. if dayT1Sec != endTime {
  852. dayT1 = dayT1.AddDate(0, 0, int(1))
  853. dayT1Sec = dayT1.UnixNano() / 1e6
  854. return dayT1Sec
  855. }
  856. return 0
  857. }
  858. func (this *RoleRune) SendMonthCardMail() {
  859. if len(this.runeMonthCardShop.GoodsInfo) <= 0 {
  860. return
  861. }
  862. bChanged := false
  863. if this.runeBase.MonthCardModify == false {
  864. this.CheckMonthCardLeftTime()
  865. bChanged = true
  866. }
  867. nowTime := util.GetCurrentTime()
  868. for _, data := range this.runeMonthCardShop.GoodsInfo {
  869. shopItemCfg, ok := model.ConvertMonthCard[data.GoodsId]
  870. if !ok {
  871. continue
  872. }
  873. if data.EndTime == 0 || data.NextRewardTime == 0 || data.NextRewardTime > int64(nowTime) || len(shopItemCfg.MailReward) <= 0 {
  874. continue
  875. }
  876. reward := make(map[int32]int32)
  877. for _, item := range shopItemCfg.MailReward {
  878. reward[item.Key] = item.Value
  879. }
  880. if len(reward) <= 0 {
  881. continue
  882. }
  883. //循环 前次下线间隔天数的邮件奖励
  884. for data.NextRewardTime < data.EndTime {
  885. if data.NextRewardTime > int64(util.GetCurrentTime()) {
  886. break
  887. }
  888. leftDay := uint64(data.EndTime-data.NextRewardTime) / (24 * 3600 * 1000) //剩余天数
  889. this.role.GetRoleMail().AddMail(shopItemCfg.MailCfgId, serverproto.MailType_MailType_MonthCard,
  890. reward, []int32{int32(leftDay - 1)}, "", "")
  891. loc := util.GetLoc()
  892. tmpTime := util.GetTimeByUint64(uint64(data.NextRewardTime))
  893. dayT1Str := tmpTime.Format(util.DATE_FORMAT1)
  894. dayT1, _ := time.ParseInLocation(util.DATE_FORMAT1, dayT1Str, loc)
  895. //设定下次领奖时间
  896. dayT1 = dayT1.AddDate(0, 0, int(1))
  897. dayT1 = dayT1.Add(time.Hour * 5)
  898. data.NextRewardTime = dayT1.UnixNano() / 1e6 //下一次领奖时间
  899. bChanged = true
  900. if data.NextRewardTime >= data.EndTime {
  901. // data.EndTime = 0
  902. break
  903. }
  904. }
  905. if data.EndTime < int64(nowTime) {
  906. data.EndTime = 0
  907. }
  908. }
  909. if bChanged == true {
  910. this.addShopChange(Rune_BagShop_Type_Month)
  911. }
  912. }
  913. func (this *RoleRune) GetFreeGoodsData() {
  914. ntfMsg := &serverproto.SCRuneFreeRedChangeInfoNtf{}
  915. for _, goods := range model.ConvertFreeBag {
  916. _, ok := this.runeGiftShop[goods.BagType]
  917. if !ok {
  918. continue
  919. }
  920. for _, item := range this.runeGiftShop[goods.BagType].GoodsInfo {
  921. if item.GoodsId == goods.GoodsId {
  922. if goods.LimitCount >= 9999 {
  923. break
  924. }
  925. if item.BuyNum < goods.LimitCount {
  926. ntfMsg.RuneRed = append(ntfMsg.RuneRed, &serverproto.KeyValueType{
  927. Key: Rune_Shop_Type_Bag,
  928. Value: goods.BagType,
  929. })
  930. }
  931. break
  932. }
  933. }
  934. }
  935. curTime := int64(util.GetCurrentTime())
  936. for i := 0; i < len(this.runeLimitShop.GoodsInfo); i++ {
  937. shopItem, ok := model.ConvertLimitGag[this.runeLimitShop.GoodsInfo[i].GoodsId]
  938. if !ok {
  939. continue
  940. }
  941. //判定时间 if 绝对时间判定,else 开服时间判定
  942. if shopItem.LimitType == LimitType_Abs_Time {
  943. if curTime < shopItem.BeginTime ||
  944. shopItem.BeginTime == 0 || shopItem.EndTime == 0 ||
  945. shopItem.EndTime < curTime {
  946. continue
  947. }
  948. } else if shopItem.LimitType == LimitType_StartServer {
  949. bRet := this.CheckInShowTime(shopItem.StartDay, shopItem.EndDay, uint64(curTime))
  950. if bRet == Shop_Time_Not_Ready_To_Show || bRet == Shop_Time_Out_Of_Date {
  951. continue
  952. }
  953. } else {
  954. bRet, _ := this.role.roleCompetition.CheckInCompetitionSeason(shopItem.SeasonId)
  955. if bRet == Shop_Time_Not_Ready_To_Show || bRet == Shop_Time_Out_Of_Date {
  956. continue
  957. }
  958. }
  959. //如果该商品已经售罄,不推送红点道具
  960. if shopItem.LimitCount < 9999 {
  961. var buyNum int32 = shopItem.LimitCount - this.runeLimitShop.GoodsInfo[i].BuyNum
  962. if buyNum <= 0 {
  963. continue
  964. }
  965. }
  966. ntfMsg.LimitRed = append(ntfMsg.LimitRed, shopItem.GoodsId)
  967. }
  968. if len(ntfMsg.RuneRed) > 0 || len(ntfMsg.LimitRed) > 0 {
  969. this.role.ReplayGate(ntfMsg, true)
  970. }
  971. this.runeBaseDataChangeNtf()
  972. }
  973. func (this *RoleRune) CheckRushShopData() {
  974. for _, value := range model.ConvertPetShop {
  975. bFind := false
  976. for _, goods := range this.runeRushPetShop.GoodsInfo {
  977. if goods.GoodsId == value.GoodsId {
  978. bFind = true
  979. break
  980. }
  981. }
  982. if bFind == true {
  983. continue
  984. }
  985. runGoods := &serverproto.RuneGoods{
  986. GoodsId: value.GoodsId,
  987. BuyNum: 0,
  988. HistoryBuy: 0,
  989. }
  990. this.runeRushPetShop.GoodsInfo = append(this.runeRushPetShop.GoodsInfo, runGoods)
  991. this.addShopChange(Rune_Shop_Type_RushPet)
  992. }
  993. }
  994. func (this *RoleRune) CheckNewGoodsAdd() {
  995. this.CheckRushShopData()
  996. //上线判定是否有新道具更新
  997. for _, value := range model.ConvertGiftBag {
  998. _, ok := this.runeGiftShop[value.BagType]
  999. if !ok {
  1000. shopData := &serverproto.RuneShop{
  1001. ShopId: Rune_Shop_Type_Bag,
  1002. SubShopId: value.BagType,
  1003. }
  1004. shopData.NextRefresh = int64(this.GetNextRefresh(value.BagType))
  1005. this.runeGiftShop[value.BagType] = shopData
  1006. runGoods := &serverproto.RuneGoods{
  1007. GoodsId: value.GoodsId,
  1008. BuyNum: 0,
  1009. HistoryBuy: 0,
  1010. }
  1011. this.runeGiftShop[value.BagType].GoodsInfo = append(this.runeGiftShop[value.BagType].GoodsInfo, runGoods)
  1012. this.addShopChange(Rune_Shop_Type_Bag)
  1013. }
  1014. bFind := false
  1015. for _, goods := range this.runeGiftShop[value.BagType].GoodsInfo {
  1016. if goods.GoodsId == value.GoodsId {
  1017. bFind = true
  1018. break
  1019. }
  1020. }
  1021. if bFind == true {
  1022. continue
  1023. }
  1024. runGoods := &serverproto.RuneGoods{
  1025. GoodsId: value.GoodsId,
  1026. BuyNum: 0,
  1027. HistoryBuy: 0,
  1028. }
  1029. this.runeGiftShop[value.BagType].GoodsInfo = append(this.runeGiftShop[value.BagType].GoodsInfo, runGoods)
  1030. this.addShopChange(Rune_Shop_Type_Bag)
  1031. }
  1032. //限时商店
  1033. for _, value := range model.ConvertLimitGag {
  1034. bFind := false
  1035. for _, goods := range this.runeLimitShop.GoodsInfo {
  1036. if goods.GoodsId == value.GoodsId {
  1037. bFind = true
  1038. break
  1039. }
  1040. }
  1041. if bFind == true {
  1042. continue
  1043. }
  1044. runGoods := &serverproto.RuneGoods{
  1045. GoodsId: value.GoodsId,
  1046. BuyNum: 0,
  1047. HistoryBuy: 0,
  1048. }
  1049. this.runeLimitShop.GoodsInfo = append(this.runeLimitShop.GoodsInfo, runGoods)
  1050. this.addShopChange(Rune_Shop_Type_TimeLimit)
  1051. }
  1052. for _, value := range model.ConvertMonthCard {
  1053. bFind := false
  1054. for _, goods := range this.runeMonthCardShop.GoodsInfo {
  1055. if goods.GoodsId == value.GoodsId {
  1056. bFind = true
  1057. break
  1058. }
  1059. }
  1060. if bFind == true {
  1061. continue
  1062. }
  1063. runGoods := &serverproto.RuneGoods{
  1064. GoodsId: value.GoodsId,
  1065. BuyNum: 0,
  1066. HistoryBuy: 0,
  1067. }
  1068. this.runeMonthCardShop.GoodsInfo = append(this.runeMonthCardShop.GoodsInfo, runGoods)
  1069. this.addShopChange(Rune_Shop_Type_MonthCard)
  1070. }
  1071. //检查三个冲榜表格是否有新物品加载
  1072. //todo wangzhaocan 检查卢恩商店物品是否有新加
  1073. for _, value := range model.ConvertGuildBattle {
  1074. bFind := false
  1075. for _, goods := range this.runeGuildBattleShop.GoodsInfo {
  1076. if goods.GoodsId == value.GoodsId {
  1077. bFind = true
  1078. break
  1079. }
  1080. }
  1081. if bFind == true {
  1082. continue
  1083. }
  1084. runGoods := &serverproto.RuneGoods{
  1085. GoodsId: value.GoodsId,
  1086. BuyNum: 0,
  1087. HistoryBuy: 0,
  1088. }
  1089. this.runeGuildBattleShop.GoodsInfo = append(this.runeGuildBattleShop.GoodsInfo, runGoods)
  1090. this.addShopChange(Rune_Shop_Type_GuildBattle)
  1091. }
  1092. for _, value := range model.ConvertSkillShop {
  1093. bFind := false
  1094. for _, goods := range this.runeRushSkillShop.GoodsInfo {
  1095. if goods.GoodsId == value.GoodsId {
  1096. bFind = true
  1097. break
  1098. }
  1099. }
  1100. if bFind == true {
  1101. continue
  1102. }
  1103. runGoods := &serverproto.RuneGoods{
  1104. GoodsId: value.GoodsId,
  1105. BuyNum: 0,
  1106. HistoryBuy: 0,
  1107. }
  1108. this.runeRushSkillShop.GoodsInfo = append(this.runeRushSkillShop.GoodsInfo, runGoods)
  1109. this.addShopChange(Rune_Shop_Type_RushSkill)
  1110. }
  1111. if this.runeIdolSeasonShop.ShopId == 0 {
  1112. this.runeIdolSeasonShop.ShopId = Rune_Shop_Type_Idol
  1113. this.addShopChange(Rune_Shop_Type_Idol)
  1114. }
  1115. for _, value := range model.ConvertIdolShop {
  1116. bFind := false
  1117. for _, goods := range this.runeIdolSeasonShop.GoodsInfo {
  1118. if goods.GoodsId == value.GoodsId {
  1119. bFind = true
  1120. break
  1121. }
  1122. }
  1123. if bFind == true {
  1124. continue
  1125. }
  1126. runGoods := &serverproto.RuneGoods{
  1127. GoodsId: value.GoodsId,
  1128. BuyNum: 0,
  1129. HistoryBuy: 0,
  1130. }
  1131. this.runeIdolSeasonShop.GoodsInfo = append(this.runeIdolSeasonShop.GoodsInfo, runGoods)
  1132. this.addShopChange(Rune_Shop_Type_Idol)
  1133. }
  1134. //充值钱包商店
  1135. this.CheckNewGoodsCreditRecharge()
  1136. // 该函数需要放在最后处理
  1137. this.ResetGiftGoldShop()
  1138. }
  1139. func (this *RoleRune) CheckNewGoodsCreditRecharge() {
  1140. for _, value := range model.ConvertPurseShop {
  1141. _, ok := this.runeCreditRecharge[value.BagType]
  1142. if !ok {
  1143. shopData := &serverproto.RuneShop{
  1144. ShopId: Rune_Shop_Type_CreditRecharge,
  1145. SubShopId: value.BagType,
  1146. }
  1147. shopData.NextRefresh = int64(this.GetNextRefresh(value.BagType))
  1148. this.runeCreditRecharge[value.BagType] = shopData
  1149. runGoods := &serverproto.RuneGoods{
  1150. GoodsId: value.GoodsId,
  1151. BuyNum: 0,
  1152. HistoryBuy: 0,
  1153. }
  1154. this.runeCreditRecharge[value.BagType].GoodsInfo = append(this.runeCreditRecharge[value.BagType].GoodsInfo, runGoods)
  1155. this.addShopChange(Rune_Shop_Type_CreditRecharge)
  1156. }
  1157. bFind := false
  1158. for _, goods := range this.runeCreditRecharge[value.BagType].GoodsInfo {
  1159. if goods.GoodsId == value.GoodsId {
  1160. bFind = true
  1161. break
  1162. }
  1163. }
  1164. if bFind == true {
  1165. continue
  1166. }
  1167. runGoods := &serverproto.RuneGoods{
  1168. GoodsId: value.GoodsId,
  1169. BuyNum: 0,
  1170. HistoryBuy: 0,
  1171. }
  1172. this.runeCreditRecharge[value.BagType].GoodsInfo = append(this.runeCreditRecharge[value.BagType].GoodsInfo, runGoods)
  1173. this.addShopChange(Rune_Shop_Type_CreditRecharge)
  1174. }
  1175. }
  1176. func (this *RoleRune) ResetGiftGoldShop() {
  1177. if this.runeBase == nil {
  1178. this.runeBase = &serverproto.RuneBaseData{
  1179. ResetVersion: 0,
  1180. }
  1181. }
  1182. bNeedReset := false
  1183. if this.runeBase.ResetVersion < model.GlobalRuneGiftGoldShopResetVersion {
  1184. this.runeBase.ResetVersion = model.GlobalRuneGiftGoldShopResetVersion
  1185. bNeedReset = true
  1186. this.addShopChange(Rune_Shop_Type_Bag)
  1187. } else {
  1188. return
  1189. }
  1190. for _, data := range this.runeGiftShop {
  1191. if bNeedReset && data.SubShopId == Rune_BagShop_Type_Gold {
  1192. for _, good := range data.GoodsInfo {
  1193. good.HistoryBuy = 0
  1194. }
  1195. break
  1196. }
  1197. }
  1198. // 充值钱包也需要
  1199. for _, data := range this.runeCreditRecharge {
  1200. if bNeedReset && data.SubShopId == Rune_BagShop_Type_CreditRecharge {
  1201. for _, good := range data.GoodsInfo {
  1202. good.HistoryBuy = 0
  1203. }
  1204. break
  1205. }
  1206. }
  1207. if bNeedReset == true {
  1208. this.addShopChange(Rune_Shop_Type_Bag)
  1209. // 充值钱包也需要
  1210. this.addShopChange(Rune_BagShop_Type_CreditRecharge)
  1211. }
  1212. }
  1213. func (this *RoleRune) ResetGiftShop() {
  1214. for _, data := range this.runeGiftShop {
  1215. needRefresh := false
  1216. if data.NextRefresh < int64(util.GetCurrentTime()) {
  1217. needRefresh = true
  1218. }
  1219. if needRefresh == false {
  1220. continue
  1221. }
  1222. for i := 0; i < len(data.GoodsInfo); {
  1223. _, ok := serverproto.RuneShopGiftsCfgLoader[data.GoodsInfo[i].GoodsId]
  1224. if !ok {
  1225. //配置表没找到,删除这个商品信息
  1226. data.GoodsInfo = append(data.GoodsInfo[:i], data.GoodsInfo[i+1:]...)
  1227. continue
  1228. }
  1229. //重置次数次数
  1230. data.GoodsInfo[i].BuyNum = 0
  1231. i++
  1232. }
  1233. data.NextRefresh = int64(this.GetNextRefresh(data.SubShopId))
  1234. }
  1235. this.addShopChange(Rune_Shop_Type_Bag)
  1236. }
  1237. func (this *RoleRune) ResetLimitShop() {
  1238. if len(this.runeLimitShop.GoodsInfo) >= 0 {
  1239. for i := 0; i < len(this.runeLimitShop.GoodsInfo); {
  1240. _, ok := model.ConvertLimitGag[this.runeLimitShop.GoodsInfo[i].GoodsId] //serverproto.RuneShopGiftsCfgLoader[this.runeLimitShop.GoodsInfo[i].GoodsId]
  1241. if !ok {
  1242. //配置表没找到,删除这个商品信息
  1243. this.runeLimitShop.GoodsInfo = append(this.runeLimitShop.GoodsInfo[:i], this.runeLimitShop.GoodsInfo[i+1:]...)
  1244. continue
  1245. }
  1246. i++
  1247. }
  1248. }
  1249. this.addShopChange(Rune_Shop_Type_TimeLimit)
  1250. }
  1251. func (this *RoleRune) ResetMonthCardShop() {
  1252. if len(this.runeMonthCardShop.GoodsInfo) >= 0 {
  1253. for i := 0; i < len(this.runeMonthCardShop.GoodsInfo); {
  1254. _, ok := model.ConvertMonthCard[this.runeMonthCardShop.GoodsInfo[i].GoodsId]
  1255. if !ok {
  1256. //配置表没找到,删除这个商品信息
  1257. this.runeMonthCardShop.GoodsInfo = append(this.runeMonthCardShop.GoodsInfo[:i], this.runeMonthCardShop.GoodsInfo[i+1:]...)
  1258. continue
  1259. }
  1260. i++
  1261. }
  1262. }
  1263. this.addShopChange(Rune_Shop_Type_MonthCard)
  1264. }
  1265. func (this *RoleRune) ResetRushTowerShop() {
  1266. if len(this.runeRushTowerShop.GoodsInfo) >= 0 {
  1267. for i := 0; i < len(this.runeRushTowerShop.GoodsInfo); {
  1268. _, ok := model.ConvertTowerShop[this.runeRushTowerShop.GoodsInfo[i].GoodsId]
  1269. if !ok {
  1270. //配置表没找到,删除这个商品信息
  1271. this.runeRushTowerShop.GoodsInfo = append(this.runeRushTowerShop.GoodsInfo[:i], this.runeRushTowerShop.GoodsInfo[i+1:]...)
  1272. continue
  1273. }
  1274. i++
  1275. }
  1276. }
  1277. this.addShopChange(Rune_Shop_Type_RushTower)
  1278. }
  1279. func (this *RoleRune) ResetRushArenaShop() {
  1280. if len(this.runeRushArenaShop.GoodsInfo) >= 0 {
  1281. for i := 0; i < len(this.runeRushArenaShop.GoodsInfo); {
  1282. _, ok := model.ConvertArenaShop[this.runeRushArenaShop.GoodsInfo[i].GoodsId]
  1283. if !ok {
  1284. //配置表没找到,删除这个商品信息
  1285. this.runeRushArenaShop.GoodsInfo = append(this.runeRushArenaShop.GoodsInfo[:i], this.runeRushArenaShop.GoodsInfo[i+1:]...)
  1286. continue
  1287. }
  1288. i++
  1289. }
  1290. }
  1291. this.addShopChange(Rune_Shop_Type_RushArena)
  1292. }
  1293. func (this *RoleRune) ResetRushMapShop() {
  1294. if len(this.runeRushMapShop.GoodsInfo) >= 0 {
  1295. for i := 0; i < len(this.runeRushMapShop.GoodsInfo); {
  1296. _, ok := model.ConvertMapShop[this.runeRushMapShop.GoodsInfo[i].GoodsId]
  1297. if !ok {
  1298. //配置表没找到,删除这个商品信息
  1299. this.runeRushMapShop.GoodsInfo = append(this.runeRushMapShop.GoodsInfo[:i], this.runeRushMapShop.GoodsInfo[i+1:]...)
  1300. continue
  1301. }
  1302. i++
  1303. }
  1304. }
  1305. this.addShopChange(Rune_Shop_Type_RushMap)
  1306. }
  1307. func (this *RoleRune) ResetRushSkillShop() {
  1308. if len(this.runeRushSkillShop.GoodsInfo) >= 0 {
  1309. for i := 0; i < len(this.runeRushSkillShop.GoodsInfo); {
  1310. _, ok := model.ConvertSkillShop[this.runeRushSkillShop.GoodsInfo[i].GoodsId]
  1311. if !ok {
  1312. //配置表没找到,删除这个商品信息
  1313. this.runeRushSkillShop.GoodsInfo = append(this.runeRushSkillShop.GoodsInfo[:i], this.runeRushSkillShop.GoodsInfo[i+1:]...)
  1314. continue
  1315. }
  1316. i++
  1317. }
  1318. }
  1319. this.addShopChange(Rune_Shop_Type_RushSkill)
  1320. }
  1321. func (this *RoleRune) ResetRushPetShop() {
  1322. if len(this.runeRushPetShop.GoodsInfo) >= 0 {
  1323. for i := 0; i < len(this.runeRushPetShop.GoodsInfo); {
  1324. _, ok := model.ConvertPetShop[this.runeRushPetShop.GoodsInfo[i].GoodsId]
  1325. if !ok {
  1326. //配置表没找到,删除这个商品信息
  1327. this.runeRushPetShop.GoodsInfo = append(this.runeRushPetShop.GoodsInfo[:i], this.runeRushPetShop.GoodsInfo[i+1:]...)
  1328. continue
  1329. }
  1330. i++
  1331. }
  1332. }
  1333. this.addShopChange(Rune_Shop_Type_RushPet)
  1334. }
  1335. func (this *RoleRune) ResetGuildBattleShop() {
  1336. if len(this.runeGuildBattleShop.GoodsInfo) >= 0 {
  1337. for i := 0; i < len(this.runeGuildBattleShop.GoodsInfo); {
  1338. _, ok := model.ConvertGuildBattle[this.runeGuildBattleShop.GoodsInfo[i].GoodsId]
  1339. if !ok {
  1340. //配置表没找到,删除这个商品信息
  1341. this.runeGuildBattleShop.GoodsInfo = append(this.runeGuildBattleShop.GoodsInfo[:i], this.runeGuildBattleShop.GoodsInfo[i+1:]...)
  1342. continue
  1343. }
  1344. i++
  1345. }
  1346. }
  1347. this.addShopChange(Rune_Shop_Type_GuildBattle)
  1348. }
  1349. func (this *RoleRune) ResetCreditRechargeShop(notify bool) {
  1350. for _, data := range this.runeCreditRecharge {
  1351. needRefresh := false
  1352. if data.NextRefresh < int64(util.GetCurrentTime()) {
  1353. needRefresh = true
  1354. }
  1355. if needRefresh == false {
  1356. continue
  1357. }
  1358. for i := 0; i < len(data.GoodsInfo); {
  1359. _, ok := serverproto.PurseShopCfgLoader[data.GoodsInfo[i].GoodsId]
  1360. if !ok {
  1361. //配置表没找到,删除这个商品信息
  1362. data.GoodsInfo = append(data.GoodsInfo[:i], data.GoodsInfo[i+1:]...)
  1363. this.addShopChange(Rune_Shop_Type_CreditRecharge)
  1364. continue
  1365. }
  1366. //重置次数次数
  1367. data.GoodsInfo[i].BuyNum = 0
  1368. i++
  1369. }
  1370. data.NextRefresh = int64(this.GetNextRefresh(data.SubShopId))
  1371. this.addShopChange(Rune_Shop_Type_CreditRecharge)
  1372. }
  1373. // 充值钱包对应的资源数据重置
  1374. this.role.GetRoleBase().ResetCommonRes(int32(serverproto.ResType_Res_CreditRecharge), notify)
  1375. // 充值钱包使用额度重置
  1376. this.runeBase.UsedCreditRecharge = 0
  1377. // 特权卡商店每日领取奖励重置
  1378. if this.runeBase.PrivilegeData.ProcessTime > 0 { //说明已经购买
  1379. nowTime := util.GetTimeMilliseconds()
  1380. diffDay := util.GetDurationDay2(this.runeBase.PrivilegeData.ProcessTime, nowTime) - 1
  1381. if this.runeBase.PrivilegeData.RewardTime > 0 { //之前没有领取
  1382. diffDay -= 1
  1383. }
  1384. cfgData := this.getSpecialPrivilegeCfgData(this.runeBase.PrivilegeData.SpecialId)
  1385. if cfgData != nil {
  1386. // 奖励邮件发送
  1387. for idx := 0; idx < int(diffDay); idx++ {
  1388. this.role.GetRoleMail().AddMail(model.GlobalMailSpecialPrivilegeCard, serverproto.MailType_MailType_SpecialPrivilege,
  1389. cfgData.VipReward, nil, "", "")
  1390. }
  1391. }
  1392. this.runeBase.PrivilegeData.RewardTime = 0
  1393. this.runeBase.PrivilegeData.ProcessTime = util.GetTimeMilliseconds()
  1394. }
  1395. if notify {
  1396. this.runeBaseDataChangeNtf()
  1397. }
  1398. this.SetDirty(true)
  1399. }
  1400. func (this *RoleRune) runeBaseDataChangeNtf() {
  1401. ntfMsg := &serverproto.SCRuneBaseDataNtf{
  1402. RuneBaseData: this.runeBase,
  1403. }
  1404. this.role.ReplayGate(ntfMsg, true)
  1405. }
  1406. func (this *RoleRune) GetRuneShopInfo(msg *serverproto.SSGetRushShopInfoAck, ackMsg *serverproto.SCRuneShopInfoAck) {
  1407. if ackMsg == nil {
  1408. return
  1409. }
  1410. if msg.RushRound == 0 {
  1411. return
  1412. }
  1413. if msg.ShopType == Rune_Shop_Type_RushTower {
  1414. this.PackRushTowerData(ackMsg, msg.RushRound)
  1415. } else if msg.ShopType == Rune_Shop_Type_RushArena {
  1416. this.PackRushArenaData(ackMsg, msg.RushRound)
  1417. } else if msg.ShopType == Rune_Shop_Type_RushMap {
  1418. this.PackRushMapData(ackMsg, msg.RushRound)
  1419. } else if msg.ShopType == Rune_Shop_Type_RushPet {
  1420. this.PackRushPetData(ackMsg, msg.RushRound)
  1421. } else if msg.ShopType == Rune_Shop_Type_RushSkill {
  1422. this.PackRushSkillData(ackMsg, msg.RushRound)
  1423. }
  1424. }
  1425. func (this *RoleRune) GetShopInfo(shopType, subType int32, ackMsg *serverproto.SCRuneShopInfoAck) {
  1426. if ackMsg == nil {
  1427. return
  1428. }
  1429. if shopType == Rune_Shop_Type_Bag {
  1430. this.PackBagData(subType, ackMsg)
  1431. } else if shopType == Rune_Shop_Type_TimeLimit {
  1432. this.PackLimitData(ackMsg)
  1433. util.InfoF("Rune_Shop_Type_TimeLimit items : ackMsg : %v", ackMsg)
  1434. } else if shopType == Rune_Shop_Type_MonthCard {
  1435. this.PackMonthCardData(ackMsg)
  1436. } else if shopType == Rune_Shop_Type_GuildBattle {
  1437. this.PackGuildBattleData(ackMsg)
  1438. } else if shopType == Rune_Shop_Type_Idol {
  1439. this.PackIdolSeasonShopData(ackMsg)
  1440. }
  1441. }
  1442. func (this *RoleRune) GetBTShopInfo(shopType, subType int32, ackMsg *serverproto.SCBTShopInfoAck) {
  1443. util.InfoF("[GetBTShopInfo] shopType=%v subShop:%v", shopType, subType)
  1444. if shopType == Rune_Shop_Type_CreditRecharge {
  1445. this.PackCreditRechargeShopData(ackMsg)
  1446. } else if shopType == Rune_Shop_Type_Bag {
  1447. this.PackROCoinShopData(subType, ackMsg)
  1448. }
  1449. }
  1450. // 打包礼包商店
  1451. func (this *RoleRune) PackBagData(subType int32, ackMsg *serverproto.SCRuneShopInfoAck) {
  1452. if ackMsg == nil {
  1453. return
  1454. }
  1455. shopData, ok := this.runeGiftShop[subType]
  1456. if !ok {
  1457. return
  1458. }
  1459. for i := 0; i < len(shopData.GoodsInfo); {
  1460. shopItem, ok := model.ConvertGiftBag[shopData.GoodsInfo[i].GoodsId]
  1461. if !ok {
  1462. shopData.GoodsInfo = append(shopData.GoodsInfo[:i], shopData.GoodsInfo[i+1:]...)
  1463. this.addShopChange(Rune_Shop_Type_Bag)
  1464. continue
  1465. }
  1466. goods := &serverproto.RuneShopItem{}
  1467. goods.GoodsId = shopData.GoodsInfo[i].GoodsId
  1468. goods.EndTime = 0
  1469. if shopItem.LimitCount >= 9999 {
  1470. goods.BuyNums = 0
  1471. } else {
  1472. var buyNum int32 = shopItem.LimitCount - shopData.GoodsInfo[i].BuyNum
  1473. if buyNum < 0 {
  1474. buyNum = 0
  1475. }
  1476. goods.BuyNums = buyNum
  1477. }
  1478. goods.Price = shopItem.Price
  1479. goods.FirstBuy = true
  1480. if shopData.GoodsInfo[i].HistoryBuy > 0 {
  1481. goods.FirstBuy = false
  1482. }
  1483. goods.BuyLimit = true
  1484. if shopItem.LimitCount >= 9999 {
  1485. goods.BuyLimit = false
  1486. }
  1487. i++
  1488. if shopItem.RmbTotalPay > 0 && this.role.GetTotalRecharge() < float32(shopItem.RmbTotalPay) {
  1489. continue
  1490. }
  1491. ackMsg.GoodsList = append(ackMsg.GoodsList, goods)
  1492. }
  1493. ackMsg.EndTime = shopData.NextRefresh
  1494. }
  1495. func (this *RoleRune) PackMonthCardData(ackMsg *serverproto.SCRuneShopInfoAck) {
  1496. if ackMsg == nil || this.runeMonthCardShop == nil || len(this.runeMonthCardShop.GoodsInfo) <= 0 {
  1497. return
  1498. }
  1499. for i := 0; i < len(this.runeMonthCardShop.GoodsInfo); {
  1500. shopItem, ok := model.ConvertMonthCard[this.runeMonthCardShop.GoodsInfo[i].GoodsId]
  1501. if !ok {
  1502. this.runeMonthCardShop.GoodsInfo = append(this.runeMonthCardShop.GoodsInfo[:i], this.runeMonthCardShop.GoodsInfo[i+1:]...)
  1503. this.addShopChange(Rune_Shop_Type_MonthCard)
  1504. continue
  1505. }
  1506. goods := &serverproto.RuneShopItem{}
  1507. goods.GoodsId = this.runeMonthCardShop.GoodsInfo[i].GoodsId
  1508. goods.EndTime = 0
  1509. goods.BuyNums = 9999 //表示不限制购买
  1510. goods.Price = shopItem.Price
  1511. goods.FirstBuy = true
  1512. if this.runeMonthCardShop.GoodsInfo[i].HistoryBuy > 0 {
  1513. goods.FirstBuy = false
  1514. }
  1515. goods.EndTime = this.runeMonthCardShop.GoodsInfo[i].EndTime
  1516. goods.BuyLimit = false
  1517. ackMsg.GoodsList = append(ackMsg.GoodsList, goods)
  1518. i++
  1519. }
  1520. }
  1521. func (this *RoleRune) PackRushTowerData(ackMsg *serverproto.SCRuneShopInfoAck, rushRound int32) {
  1522. if ackMsg == nil || this.runeRushTowerShop == nil || len(this.runeRushTowerShop.GoodsInfo) <= 0 {
  1523. return
  1524. }
  1525. for i := 0; i < len(this.runeRushTowerShop.GoodsInfo); {
  1526. shopItem, ok := model.ConvertTowerShop[this.runeRushTowerShop.GoodsInfo[i].GoodsId]
  1527. if !ok {
  1528. this.runeRushTowerShop.GoodsInfo = append(this.runeRushTowerShop.GoodsInfo[:i], this.runeRushTowerShop.GoodsInfo[i+1:]...)
  1529. this.addShopChange(Rune_Shop_Type_RushTower)
  1530. continue
  1531. }
  1532. if shopItem.Activity != rushRound {
  1533. i++
  1534. continue
  1535. }
  1536. goods := &serverproto.RuneShopItem{}
  1537. goods.GoodsId = this.runeRushTowerShop.GoodsInfo[i].GoodsId
  1538. goods.EndTime = 0
  1539. if shopItem.LimitCount >= 9999 {
  1540. goods.BuyNums = 0
  1541. } else {
  1542. var buyNum int32 = shopItem.LimitCount - this.runeRushTowerShop.GoodsInfo[i].BuyNum
  1543. if buyNum < 0 {
  1544. buyNum = 0
  1545. }
  1546. goods.BuyNums = buyNum
  1547. }
  1548. goods.BuyLimit = true
  1549. if shopItem.LimitCount >= 9999 {
  1550. goods.BuyLimit = false
  1551. }
  1552. goods.Price = shopItem.Price
  1553. goods.FirstBuy = true
  1554. if this.runeRushTowerShop.GoodsInfo[i].HistoryBuy > 0 {
  1555. goods.FirstBuy = false
  1556. }
  1557. goods.EndTime = this.runeRushTowerShop.GoodsInfo[i].EndTime
  1558. ackMsg.GoodsList = append(ackMsg.GoodsList, goods)
  1559. i++
  1560. }
  1561. }
  1562. func (this *RoleRune) PackRushArenaData(ackMsg *serverproto.SCRuneShopInfoAck, rushRound int32) {
  1563. if ackMsg == nil || this.runeRushArenaShop == nil || len(this.runeRushArenaShop.GoodsInfo) <= 0 {
  1564. return
  1565. }
  1566. if rushRound == 0 {
  1567. return
  1568. }
  1569. for i := 0; i < len(this.runeRushArenaShop.GoodsInfo); {
  1570. shopItem, ok := model.ConvertArenaShop[this.runeRushArenaShop.GoodsInfo[i].GoodsId]
  1571. if !ok {
  1572. this.runeRushArenaShop.GoodsInfo = append(this.runeRushArenaShop.GoodsInfo[:i], this.runeRushArenaShop.GoodsInfo[i+1:]...)
  1573. this.addShopChange(Rune_Shop_Type_RushArena)
  1574. continue
  1575. }
  1576. if shopItem.Activity != rushRound {
  1577. i++
  1578. continue
  1579. }
  1580. goods := &serverproto.RuneShopItem{}
  1581. goods.GoodsId = this.runeRushArenaShop.GoodsInfo[i].GoodsId
  1582. goods.EndTime = 0
  1583. goods.BuyNums = 9999 //表示不限制购买
  1584. if shopItem.LimitCount >= 9999 {
  1585. goods.BuyNums = 0
  1586. } else {
  1587. var buyNum int32 = shopItem.LimitCount - this.runeRushArenaShop.GoodsInfo[i].BuyNum
  1588. if buyNum < 0 {
  1589. buyNum = 0
  1590. }
  1591. goods.BuyNums = buyNum
  1592. }
  1593. goods.BuyLimit = true
  1594. if shopItem.LimitCount >= 9999 {
  1595. goods.BuyLimit = false
  1596. }
  1597. goods.Price = shopItem.Price
  1598. goods.FirstBuy = true
  1599. if this.runeRushArenaShop.GoodsInfo[i].HistoryBuy > 0 {
  1600. goods.FirstBuy = false
  1601. }
  1602. goods.EndTime = this.runeRushArenaShop.GoodsInfo[i].EndTime
  1603. ackMsg.GoodsList = append(ackMsg.GoodsList, goods)
  1604. i++
  1605. }
  1606. }
  1607. func (this *RoleRune) PackRushMapData(ackMsg *serverproto.SCRuneShopInfoAck, rushRound int32) {
  1608. if ackMsg == nil || this.runeRushMapShop == nil || len(this.runeRushMapShop.GoodsInfo) <= 0 {
  1609. return
  1610. }
  1611. if rushRound == 0 {
  1612. return
  1613. }
  1614. for i := 0; i < len(this.runeRushMapShop.GoodsInfo); {
  1615. shopItem, ok := model.ConvertMapShop[this.runeRushMapShop.GoodsInfo[i].GoodsId]
  1616. if !ok {
  1617. this.runeRushMapShop.GoodsInfo = append(this.runeRushMapShop.GoodsInfo[:i], this.runeRushMapShop.GoodsInfo[i+1:]...)
  1618. this.addShopChange(Rune_Shop_Type_RushMap)
  1619. continue
  1620. }
  1621. if shopItem.Activity != rushRound {
  1622. i++
  1623. continue
  1624. }
  1625. goods := &serverproto.RuneShopItem{}
  1626. goods.GoodsId = this.runeRushMapShop.GoodsInfo[i].GoodsId
  1627. goods.EndTime = 0
  1628. goods.BuyNums = 9999 //表示不限制购买
  1629. if shopItem.LimitCount >= 9999 {
  1630. goods.BuyNums = 0
  1631. } else {
  1632. var buyNum int32 = shopItem.LimitCount - this.runeRushMapShop.GoodsInfo[i].BuyNum
  1633. if buyNum < 0 {
  1634. buyNum = 0
  1635. }
  1636. goods.BuyNums = buyNum
  1637. }
  1638. goods.BuyLimit = true
  1639. if shopItem.LimitCount >= 9999 {
  1640. goods.BuyLimit = false
  1641. }
  1642. goods.Price = shopItem.Price
  1643. goods.FirstBuy = true
  1644. if this.runeRushMapShop.GoodsInfo[i].HistoryBuy > 0 {
  1645. goods.FirstBuy = false
  1646. }
  1647. goods.EndTime = this.runeRushMapShop.GoodsInfo[i].EndTime
  1648. ackMsg.GoodsList = append(ackMsg.GoodsList, goods)
  1649. i++
  1650. }
  1651. }
  1652. func (this *RoleRune) PackRushPetData(ackMsg *serverproto.SCRuneShopInfoAck, rushRound int32) {
  1653. if ackMsg == nil || this.runeRushPetShop == nil || len(this.runeRushPetShop.GoodsInfo) <= 0 {
  1654. return
  1655. }
  1656. if rushRound == 0 {
  1657. return
  1658. }
  1659. for i := 0; i < len(this.runeRushPetShop.GoodsInfo); {
  1660. shopItem, ok := model.ConvertPetShop[this.runeRushPetShop.GoodsInfo[i].GoodsId]
  1661. if !ok {
  1662. this.runeRushPetShop.GoodsInfo = append(this.runeRushPetShop.GoodsInfo[:i], this.runeRushPetShop.GoodsInfo[i+1:]...)
  1663. this.addShopChange(Rune_Shop_Type_RushPet)
  1664. continue
  1665. }
  1666. if shopItem.Activity != rushRound {
  1667. i++
  1668. continue
  1669. }
  1670. goods := &serverproto.RuneShopItem{}
  1671. goods.GoodsId = this.runeRushPetShop.GoodsInfo[i].GoodsId
  1672. goods.EndTime = 0
  1673. goods.BuyNums = 9999 //表示不限制购买
  1674. if shopItem.LimitCount >= 9999 {
  1675. goods.BuyNums = 0
  1676. } else {
  1677. var buyNum int32 = shopItem.LimitCount - this.runeRushPetShop.GoodsInfo[i].BuyNum
  1678. if buyNum < 0 {
  1679. buyNum = 0
  1680. }
  1681. goods.BuyNums = buyNum
  1682. }
  1683. goods.BuyLimit = true
  1684. if shopItem.LimitCount >= 9999 {
  1685. goods.BuyLimit = false
  1686. }
  1687. goods.Price = shopItem.Price
  1688. goods.FirstBuy = true
  1689. if this.runeRushPetShop.GoodsInfo[i].HistoryBuy > 0 {
  1690. goods.FirstBuy = false
  1691. }
  1692. goods.EndTime = this.runeRushPetShop.GoodsInfo[i].EndTime
  1693. ackMsg.GoodsList = append(ackMsg.GoodsList, goods)
  1694. i++
  1695. }
  1696. }
  1697. func (this *RoleRune) PackRushSkillData(ackMsg *serverproto.SCRuneShopInfoAck, rushRound int32) {
  1698. if ackMsg == nil || this.runeRushSkillShop == nil || len(this.runeRushSkillShop.GoodsInfo) <= 0 {
  1699. return
  1700. }
  1701. if rushRound == 0 {
  1702. return
  1703. }
  1704. for i := 0; i < len(this.runeRushSkillShop.GoodsInfo); {
  1705. shopItem, ok := model.ConvertSkillShop[this.runeRushSkillShop.GoodsInfo[i].GoodsId]
  1706. if !ok {
  1707. this.runeRushSkillShop.GoodsInfo = append(this.runeRushSkillShop.GoodsInfo[:i], this.runeRushSkillShop.GoodsInfo[i+1:]...)
  1708. this.addShopChange(Rune_Shop_Type_RushSkill)
  1709. continue
  1710. }
  1711. if shopItem.Activity != rushRound {
  1712. i++
  1713. continue
  1714. }
  1715. goods := &serverproto.RuneShopItem{}
  1716. goods.GoodsId = this.runeRushSkillShop.GoodsInfo[i].GoodsId
  1717. goods.EndTime = 0
  1718. goods.BuyNums = 9999 //表示不限制购买
  1719. if shopItem.LimitCount >= 9999 {
  1720. goods.BuyNums = 0
  1721. } else {
  1722. var buyNum int32 = shopItem.LimitCount - this.runeRushSkillShop.GoodsInfo[i].BuyNum
  1723. if buyNum < 0 {
  1724. buyNum = 0
  1725. }
  1726. goods.BuyNums = buyNum
  1727. }
  1728. goods.BuyLimit = true
  1729. if shopItem.LimitCount >= 9999 {
  1730. goods.BuyLimit = false
  1731. }
  1732. goods.Price = shopItem.Price
  1733. goods.FirstBuy = true
  1734. if this.runeRushSkillShop.GoodsInfo[i].HistoryBuy > 0 {
  1735. goods.FirstBuy = false
  1736. }
  1737. goods.EndTime = this.runeRushSkillShop.GoodsInfo[i].EndTime
  1738. ackMsg.GoodsList = append(ackMsg.GoodsList, goods)
  1739. i++
  1740. }
  1741. }
  1742. func (this *RoleRune) PackGuildBattleData(ackMsg *serverproto.SCRuneShopInfoAck) {
  1743. if ackMsg == nil || this.runeGuildBattleShop == nil || len(this.runeGuildBattleShop.GoodsInfo) <= 0 {
  1744. return
  1745. }
  1746. //todo wangzhaocan 公会战时间判定
  1747. for i := 0; i < len(this.runeGuildBattleShop.GoodsInfo); {
  1748. shopItem, ok := model.ConvertGuildBattle[this.runeGuildBattleShop.GoodsInfo[i].GoodsId]
  1749. if !ok {
  1750. this.runeGuildBattleShop.GoodsInfo = append(this.runeGuildBattleShop.GoodsInfo[:i], this.runeGuildBattleShop.GoodsInfo[i+1:]...)
  1751. this.addShopChange(Rune_Shop_Type_GuildBattle)
  1752. continue
  1753. }
  1754. goods := &serverproto.RuneShopItem{}
  1755. goods.GoodsId = this.runeGuildBattleShop.GoodsInfo[i].GoodsId
  1756. goods.EndTime = 0
  1757. goods.BuyNums = 9999 //表示不限制购买
  1758. if shopItem.LimitCount >= 9999 {
  1759. goods.BuyNums = 0
  1760. } else {
  1761. var buyNum int32 = shopItem.LimitCount - this.runeGuildBattleShop.GoodsInfo[i].BuyNum
  1762. if buyNum < 0 {
  1763. buyNum = 0
  1764. }
  1765. goods.BuyNums = buyNum
  1766. }
  1767. goods.BuyLimit = true
  1768. if shopItem.LimitCount >= 9999 {
  1769. goods.BuyLimit = false
  1770. }
  1771. goods.Price = shopItem.Price
  1772. goods.FirstBuy = true
  1773. if this.runeGuildBattleShop.GoodsInfo[i].HistoryBuy > 0 {
  1774. goods.FirstBuy = false
  1775. }
  1776. goods.EndTime = this.runeGuildBattleShop.GoodsInfo[i].EndTime
  1777. ackMsg.GoodsList = append(ackMsg.GoodsList, goods)
  1778. i++
  1779. }
  1780. }
  1781. func (this *RoleRune) PackIdolSeasonShopData(ackMsg *serverproto.SCRuneShopInfoAck) {
  1782. if ackMsg == nil || this.runeIdolSeasonShop == nil || len(this.runeIdolSeasonShop.GoodsInfo) <= 0 {
  1783. return
  1784. }
  1785. //todo wangzhaocan 公会战时间判定
  1786. for i := 0; i < len(this.runeIdolSeasonShop.GoodsInfo); {
  1787. shopItem, ok := model.ConvertIdolShop[this.runeIdolSeasonShop.GoodsInfo[i].GoodsId]
  1788. if !ok {
  1789. this.runeIdolSeasonShop.GoodsInfo = append(this.runeIdolSeasonShop.GoodsInfo[:i], this.runeIdolSeasonShop.GoodsInfo[i+1:]...)
  1790. this.addShopChange(Rune_Shop_Type_Idol)
  1791. continue
  1792. }
  1793. goods := &serverproto.RuneShopItem{}
  1794. goods.GoodsId = this.runeIdolSeasonShop.GoodsInfo[i].GoodsId
  1795. goods.EndTime = 0
  1796. goods.BuyNums = 9999 //表示不限制购买
  1797. if shopItem.LimitCount >= 9999 {
  1798. goods.BuyNums = 0
  1799. } else {
  1800. var buyNum int32 = shopItem.LimitCount - this.runeIdolSeasonShop.GoodsInfo[i].BuyNum
  1801. if buyNum < 0 {
  1802. buyNum = 0
  1803. }
  1804. goods.BuyNums = buyNum
  1805. }
  1806. goods.BuyLimit = true
  1807. if shopItem.LimitCount >= 9999 {
  1808. goods.BuyLimit = false
  1809. }
  1810. goods.Price = shopItem.Price
  1811. goods.FirstBuy = true
  1812. if this.runeIdolSeasonShop.GoodsInfo[i].HistoryBuy > 0 {
  1813. goods.FirstBuy = false
  1814. }
  1815. goods.EndTime = this.runeIdolSeasonShop.GoodsInfo[i].EndTime
  1816. ackMsg.GoodsList = append(ackMsg.GoodsList, goods)
  1817. i++
  1818. }
  1819. }
  1820. func (this *RoleRune) PackCreditRechargeShopData(ackMsg *serverproto.SCBTShopInfoAck) {
  1821. shopData, ok := this.runeCreditRecharge[Rune_BagShop_Type_CreditRecharge]
  1822. if !ok {
  1823. return
  1824. }
  1825. for i := 0; i < len(shopData.GoodsInfo); {
  1826. shopItem, ok := model.ConvertPurseShop[shopData.GoodsInfo[i].GoodsId]
  1827. if !ok {
  1828. shopData.GoodsInfo = append(shopData.GoodsInfo[:i], shopData.GoodsInfo[i+1:]...)
  1829. this.addShopChange(Rune_Shop_Type_CreditRecharge)
  1830. continue
  1831. }
  1832. goods := &serverproto.RuneShopItem{
  1833. GoodsId: shopData.GoodsInfo[i].GoodsId,
  1834. Price: shopItem.Price,
  1835. FirstBuy: true,
  1836. BuyLimit: true,
  1837. }
  1838. if shopItem.LimitCount >= 9999 {
  1839. goods.BuyNums = 0
  1840. } else {
  1841. buyNum := shopItem.LimitCount - shopData.GoodsInfo[i].BuyNum
  1842. if buyNum < 0 {
  1843. buyNum = 0
  1844. }
  1845. goods.BuyNums = buyNum
  1846. }
  1847. if shopData.GoodsInfo[i].HistoryBuy > 0 {
  1848. goods.FirstBuy = false
  1849. }
  1850. if shopItem.LimitCount >= 9999 {
  1851. goods.BuyLimit = false
  1852. }
  1853. i++
  1854. if shopItem.RmbTotalPay > 0 && this.role.GetTotalRecharge() < float32(shopItem.RmbTotalPay) {
  1855. continue
  1856. }
  1857. ackMsg.GoodsList = append(ackMsg.GoodsList, goods)
  1858. }
  1859. ackMsg.EndTime = shopData.NextRefresh
  1860. }
  1861. func (this *RoleRune) PackROCoinShopData(subType int32, ackMsg *serverproto.SCBTShopInfoAck) {
  1862. util.InfoF("[PackROCoinShopData] subShop:%v", subType)
  1863. shopData, ok := this.runeGiftShop[subType]
  1864. util.InfoF("[PackROCoinShopData] shopData:%v ok:%v", shopData, ok)
  1865. if !ok {
  1866. return
  1867. }
  1868. for i := 0; i < len(shopData.GoodsInfo); {
  1869. shopItem, ok := model.ConvertGiftBag[shopData.GoodsInfo[i].GoodsId]
  1870. if !ok {
  1871. shopData.GoodsInfo = append(shopData.GoodsInfo[:i], shopData.GoodsInfo[i+1:]...)
  1872. this.addShopChange(Rune_Shop_Type_Bag)
  1873. continue
  1874. }
  1875. goods := &serverproto.RuneShopItem{
  1876. GoodsId: shopData.GoodsInfo[i].GoodsId,
  1877. Price: shopItem.Price,
  1878. FirstBuy: true,
  1879. BuyLimit: true,
  1880. }
  1881. if shopItem.LimitCount >= 9999 {
  1882. goods.BuyNums = 0
  1883. } else {
  1884. buyNum := shopItem.LimitCount - shopData.GoodsInfo[i].BuyNum
  1885. if buyNum < 0 {
  1886. buyNum = 0
  1887. }
  1888. goods.BuyNums = buyNum
  1889. }
  1890. if shopData.GoodsInfo[i].HistoryBuy > 0 {
  1891. goods.FirstBuy = false
  1892. }
  1893. if shopItem.LimitCount >= 9999 {
  1894. goods.BuyLimit = false
  1895. }
  1896. i++
  1897. if shopItem.RmbTotalPay > 0 && this.role.GetTotalRecharge() < float32(shopItem.RmbTotalPay) {
  1898. continue
  1899. }
  1900. ackMsg.GoodsList = append(ackMsg.GoodsList, goods)
  1901. }
  1902. ackMsg.EndTime = shopData.NextRefresh
  1903. }
  1904. func (this *RoleRune) CheckInSellingTime(startDay int32, endDay int32) bool {
  1905. if startDay > endDay {
  1906. return false
  1907. }
  1908. startUpTime := service.GetServiceStartupTime()
  1909. if startUpTime <= 0 {
  1910. return false
  1911. }
  1912. beginTime := startUpTime + (uint64(startDay)-1)*24*3600*1000
  1913. endTime := startUpTime + (uint64(endDay)-1)*24*3600*1000
  1914. if beginTime <= util.GetCurrentTime() && util.GetCurrentTime() <= endTime {
  1915. return true
  1916. }
  1917. return false
  1918. }
  1919. const (
  1920. Shop_Time_Out_Of_Date = 0
  1921. Shop_Time_Not_Ready_To_Show = 1
  1922. Shop_Time_Show = 2
  1923. Shop_Time_Not_In_Season = 3
  1924. )
  1925. func (this *RoleRune) CheckInShowTime(startDay int32, endDay int32, nowTime uint64) int32 {
  1926. if startDay > endDay {
  1927. return Shop_Time_Out_Of_Date
  1928. }
  1929. startUpTime := service.GetServiceStartupTime()
  1930. if startUpTime <= 0 {
  1931. return Shop_Time_Out_Of_Date
  1932. }
  1933. beginTime := startUpTime + (uint64(startDay)-1)*24*3600*1000
  1934. endTime := startUpTime + (uint64(endDay)-1)*24*3600*1000
  1935. if nowTime >= endTime {
  1936. return Shop_Time_Out_Of_Date
  1937. }
  1938. if nowTime < beginTime {
  1939. return Shop_Time_Not_Ready_To_Show
  1940. }
  1941. return Shop_Time_Show
  1942. }
  1943. const (
  1944. LimitType_Abs_Time = 0 //绝对时间
  1945. LimitType_StartServer = 1 //开服时间
  1946. LimitType_Competition = 2 //赛季
  1947. LimitType_Activity = 3 //活动
  1948. )
  1949. // 打包限时商店
  1950. func (this *RoleRune) PackLimitData(ackMsg *serverproto.SCRuneShopInfoAck) {
  1951. if ackMsg == nil || this.runeLimitShop == nil || len(this.runeLimitShop.GoodsInfo) < 0 {
  1952. return
  1953. }
  1954. curTime := util.GetCurrentTime()
  1955. startUpTime := service.GetServiceStartupTime()
  1956. activityEndTime := int64(0)
  1957. for i := 0; i < len(this.runeLimitShop.GoodsInfo); {
  1958. shopItem, ok := model.ConvertLimitGag[this.runeLimitShop.GoodsInfo[i].GoodsId]
  1959. if !ok {
  1960. this.runeLimitShop.GoodsInfo = append(this.runeLimitShop.GoodsInfo[:i], this.runeLimitShop.GoodsInfo[i+1:]...)
  1961. this.addShopChange(Rune_Shop_Type_TimeLimit)
  1962. continue
  1963. }
  1964. //判定时间 if 绝对时间判定,else 开服时间判定
  1965. if shopItem.LimitType == LimitType_Abs_Time {
  1966. if int64(curTime) < shopItem.BeginTime {
  1967. i++
  1968. continue
  1969. }
  1970. if shopItem.BeginTime == 0 || shopItem.EndTime == 0 || shopItem.EndTime < int64(curTime) {
  1971. this.runeLimitShop.GoodsInfo = append(this.runeLimitShop.GoodsInfo[:i], this.runeLimitShop.GoodsInfo[i+1:]...)
  1972. this.addShopChange(Rune_Shop_Type_TimeLimit)
  1973. continue
  1974. }
  1975. } else if shopItem.LimitType == LimitType_StartServer {
  1976. bRet := this.CheckInShowTime(shopItem.StartDay, shopItem.EndDay, curTime)
  1977. if bRet == Shop_Time_Not_Ready_To_Show {
  1978. i++
  1979. continue
  1980. }
  1981. if bRet == Shop_Time_Out_Of_Date {
  1982. this.runeLimitShop.GoodsInfo = append(this.runeLimitShop.GoodsInfo[:i], this.runeLimitShop.GoodsInfo[i+1:]...)
  1983. this.addShopChange(Rune_Shop_Type_TimeLimit)
  1984. continue
  1985. }
  1986. } else if shopItem.LimitType == LimitType_Activity {
  1987. bRet := this.role.GetRoleActivity().ActivityHDRuneGoodsAdd(shopItem.ActivityId)
  1988. if bRet == 0 {
  1989. i++
  1990. continue
  1991. }
  1992. activityEndTime = int64(bRet)
  1993. //todo wangzhaocan 卢恩活动道具,后续补充删除过期商品
  1994. } else {
  1995. bRet, _ := this.role.roleCompetition.CheckInCompetitionSeason(shopItem.SeasonId)
  1996. if bRet == Shop_Time_Not_Ready_To_Show {
  1997. i++
  1998. continue
  1999. }
  2000. if bRet == Shop_Time_Out_Of_Date {
  2001. this.runeLimitShop.GoodsInfo = append(this.runeLimitShop.GoodsInfo[:i], this.runeLimitShop.GoodsInfo[i+1:]...)
  2002. this.addShopChange(Rune_Shop_Type_TimeLimit)
  2003. continue
  2004. }
  2005. }
  2006. goods := &serverproto.RuneShopItem{}
  2007. goods.GoodsId = this.runeLimitShop.GoodsInfo[i].GoodsId
  2008. if shopItem.EndTime != 0 {
  2009. goods.EndTime = shopItem.EndTime
  2010. } else {
  2011. if shopItem.LimitType == LimitType_StartServer {
  2012. goods.EndTime = int64(startUpTime) + int64(shopItem.EndDay-1)*24*3600*1000
  2013. } else if shopItem.LimitType == LimitType_Activity {
  2014. goods.EndTime = activityEndTime
  2015. } else if shopItem.LimitType == LimitType_Competition {
  2016. goods.EndTime = int64(this.role.roleCompetition.curCompInfo.CurEndTime)
  2017. }
  2018. }
  2019. if shopItem.LimitCount >= 9999 {
  2020. goods.BuyNums = 0
  2021. } else {
  2022. var buyNum = shopItem.LimitCount - this.runeLimitShop.GoodsInfo[i].BuyNum
  2023. if buyNum < 0 {
  2024. buyNum = 0
  2025. }
  2026. goods.BuyNums = buyNum
  2027. }
  2028. goods.Price = shopItem.Price
  2029. goods.FirstBuy = true
  2030. if this.runeLimitShop.GoodsInfo[i].HistoryBuy > 0 {
  2031. goods.FirstBuy = false
  2032. }
  2033. goods.BuyLimit = true
  2034. if shopItem.LimitCount >= 9999 {
  2035. goods.BuyLimit = false
  2036. }
  2037. ackMsg.GoodsList = append(ackMsg.GoodsList, goods)
  2038. i++
  2039. }
  2040. }
  2041. // 购买礼包商店道具
  2042. func (this *RoleRune) BuyBagShopItem(payRewardInfo *serverproto.PayOrderSaveInfo) serverproto.ErrorCode {
  2043. if payRewardInfo == nil {
  2044. return serverproto.ErrorCode_ERROR_FAIL
  2045. }
  2046. shopItem, ok := model.ConvertGiftBag[payRewardInfo.GoodsId]
  2047. if !ok {
  2048. return serverproto.ErrorCode_ERROR_FAIL
  2049. }
  2050. _, ok1 := this.runeGiftShop[shopItem.BagType]
  2051. if !ok1 {
  2052. return serverproto.ErrorCode_ERROR_FAIL
  2053. }
  2054. bFind := false
  2055. bFirst := true
  2056. for _, goods := range this.runeGiftShop[shopItem.BagType].GoodsInfo {
  2057. if goods.GoodsId == payRewardInfo.GoodsId {
  2058. if shopItem.LimitCount != 0 && goods.BuyNum >= shopItem.LimitCount {
  2059. return serverproto.ErrorCode_ERROR_FAIL
  2060. }
  2061. if goods.HistoryBuy > 0 {
  2062. bFirst = false
  2063. }
  2064. bFind = true
  2065. break
  2066. }
  2067. }
  2068. //商店找不到此商品,返回
  2069. if bFind == false {
  2070. return serverproto.ErrorCode_ERROR_FAIL
  2071. }
  2072. util.InfoF("BuyBagShopItem payRewardInfo=%v shopItem:%v", *payRewardInfo, shopItem)
  2073. payRewardInfo.Count = 1
  2074. payRewardInfo.GoodsId = payRewardInfo.GoodsId
  2075. payRewardInfo.Amount = shopItem.Price * float32(payRewardInfo.Count)
  2076. payRewardInfo.GoodsName = shopItem.Name
  2077. //打包正常购买
  2078. reward := make(map[int32]int32)
  2079. for _, items := range shopItem.BuyReward {
  2080. payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{
  2081. Key: items.Key,
  2082. Value: items.Value,
  2083. })
  2084. reward[items.Key] += items.Value
  2085. }
  2086. //打包额外道具 //首冲或者非首冲
  2087. if bFirst == true {
  2088. for _, items := range shopItem.FirstReward {
  2089. payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{
  2090. Key: items.Key,
  2091. Value: items.Value,
  2092. })
  2093. reward[items.Key] += items.Value
  2094. }
  2095. } else {
  2096. for _, items := range shopItem.ExtraReward {
  2097. payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{
  2098. Key: items.Key,
  2099. Value: items.Value,
  2100. })
  2101. reward[items.Key] += items.Value
  2102. }
  2103. }
  2104. util.InfoF("uid=%v bag shop: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2105. if payRewardInfo.Amount == 0 {
  2106. this.role.AddItemList(reward, AddFrom_Rune, true)
  2107. this.addShopChange(Rune_Shop_Type_Bag)
  2108. this.OnBuyItemSuccess(payRewardInfo)
  2109. }
  2110. return serverproto.ErrorCode_ERROR_OK
  2111. }
  2112. // 购买限时商店道具
  2113. func (this *RoleRune) BuyLimitShopItem(payRewardInfo *serverproto.PayOrderSaveInfo) serverproto.ErrorCode {
  2114. if payRewardInfo == nil {
  2115. return serverproto.ErrorCode_ERROR_FAIL
  2116. }
  2117. shopItem, ok := model.ConvertLimitGag[payRewardInfo.GoodsId]
  2118. if !ok {
  2119. return serverproto.ErrorCode_ERROR_FAIL
  2120. }
  2121. if shopItem.BeginTime != 0 && shopItem.EndTime != 0 {
  2122. if int64(util.GetCurrentTime()) < shopItem.BeginTime || shopItem.EndTime < int64(util.GetCurrentTime()) {
  2123. return serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
  2124. }
  2125. } else {
  2126. if shopItem.LimitType == LimitType_StartServer {
  2127. bRet := this.CheckInSellingTime(shopItem.StartDay, shopItem.EndDay)
  2128. if bRet == false {
  2129. return serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
  2130. }
  2131. } else if shopItem.LimitType == LimitType_Activity {
  2132. bRet := this.role.GetRoleActivity().ActivityHDRuneGoodsAdd(shopItem.ActivityId)
  2133. if bRet == 0 {
  2134. return serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
  2135. }
  2136. } else if shopItem.LimitType == LimitType_Competition {
  2137. bRet, _ := this.role.roleCompetition.CheckInCompetitionSeason(shopItem.SeasonId)
  2138. if bRet != Shop_Time_Show {
  2139. return serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
  2140. }
  2141. }
  2142. }
  2143. bFind := false
  2144. for _, goods := range this.runeLimitShop.GoodsInfo {
  2145. if goods.GoodsId == payRewardInfo.GoodsId {
  2146. if goods.BuyNum >= shopItem.LimitCount {
  2147. return serverproto.ErrorCode_ERROR_FAIL
  2148. }
  2149. bFind = true
  2150. break
  2151. }
  2152. }
  2153. //商店找不到此商品,返回
  2154. if bFind == false {
  2155. return serverproto.ErrorCode_ERROR_FAIL
  2156. }
  2157. payRewardInfo.Count = 1
  2158. payRewardInfo.GoodsId = payRewardInfo.GoodsId
  2159. payRewardInfo.Amount = shopItem.Price * float32(payRewardInfo.Count)
  2160. payRewardInfo.GoodsName = shopItem.Name
  2161. //打包正常购买
  2162. reward := make(map[int32]int32)
  2163. for _, items := range shopItem.BuyReward {
  2164. payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{
  2165. Key: items.Key,
  2166. Value: items.Value,
  2167. })
  2168. }
  2169. util.InfoF("uid=%v limit shop: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2170. if payRewardInfo.Amount == 0 {
  2171. this.role.AddItemList(reward, AddFrom_Rune, true)
  2172. this.addShopChange(Rune_Shop_Type_TimeLimit)
  2173. this.OnBuyItemSuccess(payRewardInfo)
  2174. }
  2175. return serverproto.ErrorCode_ERROR_OK
  2176. }
  2177. func (this *RoleRune) BuyMonthCardShopItem(payRewardInfo *serverproto.PayOrderSaveInfo) serverproto.ErrorCode {
  2178. if payRewardInfo == nil {
  2179. return serverproto.ErrorCode_ERROR_FAIL
  2180. }
  2181. shopItem, ok := model.ConvertMonthCard[payRewardInfo.GoodsId]
  2182. if !ok {
  2183. return serverproto.ErrorCode_ERROR_FAIL
  2184. }
  2185. payRewardInfo.Count = 1
  2186. payRewardInfo.GoodsId = payRewardInfo.GoodsId
  2187. payRewardInfo.Amount = shopItem.Price
  2188. payRewardInfo.GoodsName = shopItem.Name
  2189. //打包正常购买
  2190. for _, items := range shopItem.BuyReward {
  2191. payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{
  2192. Key: items.Key,
  2193. Value: items.Value,
  2194. })
  2195. }
  2196. util.InfoF("uid=%v monthcard: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2197. return serverproto.ErrorCode_ERROR_OK
  2198. }
  2199. func (this *RoleRune) BuyRushTowerShopItem(payRewardInfo *serverproto.PayOrderSaveInfo, rushStage, rushRound int32) serverproto.ErrorCode {
  2200. if this.role.GetRoleTower() == nil || payRewardInfo == nil {
  2201. return serverproto.ErrorCode_ERROR_FAIL
  2202. }
  2203. if rushStage != 1 {
  2204. return serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
  2205. }
  2206. shopItem, ok := model.ConvertTowerShop[payRewardInfo.GoodsId]
  2207. if !ok {
  2208. return serverproto.ErrorCode_ERROR_FAIL
  2209. }
  2210. for _, goods := range this.runeRushTowerShop.GoodsInfo {
  2211. if goods.GoodsId == payRewardInfo.GoodsId {
  2212. if goods.BuyNum >= shopItem.LimitCount {
  2213. return serverproto.ErrorCode_ERROR_FAIL
  2214. }
  2215. break
  2216. }
  2217. }
  2218. if rushRound != 0 && rushRound != shopItem.Activity {
  2219. return serverproto.ErrorCode_ERROR_FAIL
  2220. }
  2221. payRewardInfo.Count = 1
  2222. payRewardInfo.GoodsId = payRewardInfo.GoodsId
  2223. payRewardInfo.Amount = shopItem.Price
  2224. payRewardInfo.GoodsName = shopItem.Name
  2225. //打包正常购买
  2226. for _, items := range shopItem.BuyReward {
  2227. payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{
  2228. Key: items.Key,
  2229. Value: items.Value,
  2230. })
  2231. }
  2232. util.InfoF("uid=%v rushtower: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2233. return serverproto.ErrorCode_ERROR_OK
  2234. }
  2235. func (this *RoleRune) BuyRushArenaShopItem(payRewardInfo *serverproto.PayOrderSaveInfo, rushStage, rushRound int32) serverproto.ErrorCode {
  2236. if this.role.GetRoleArena() == nil {
  2237. return serverproto.ErrorCode_ERROR_FAIL
  2238. }
  2239. if rushStage != 1 {
  2240. return serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
  2241. }
  2242. if payRewardInfo == nil {
  2243. return serverproto.ErrorCode_ERROR_FAIL
  2244. }
  2245. shopItem, ok := model.ConvertArenaShop[payRewardInfo.GoodsId]
  2246. if !ok {
  2247. return serverproto.ErrorCode_ERROR_FAIL
  2248. }
  2249. for _, goods := range this.runeRushArenaShop.GoodsInfo {
  2250. if goods.GoodsId == payRewardInfo.GoodsId {
  2251. if goods.BuyNum >= shopItem.LimitCount {
  2252. return serverproto.ErrorCode_ERROR_FAIL
  2253. }
  2254. break
  2255. }
  2256. }
  2257. if rushRound != 0 && rushRound != shopItem.Activity {
  2258. return serverproto.ErrorCode_ERROR_FAIL
  2259. }
  2260. payRewardInfo.Count = 1
  2261. payRewardInfo.GoodsId = payRewardInfo.GoodsId
  2262. payRewardInfo.Amount = shopItem.Price
  2263. payRewardInfo.GoodsName = shopItem.Name
  2264. //打包正常购买
  2265. for _, items := range shopItem.BuyReward {
  2266. payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{
  2267. Key: items.Key,
  2268. Value: items.Value,
  2269. })
  2270. }
  2271. util.InfoF("uid=%v rusharena: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2272. return serverproto.ErrorCode_ERROR_OK
  2273. }
  2274. func (this *RoleRune) BuyRushMapShopItem(payRewardInfo *serverproto.PayOrderSaveInfo, rushStage, rushRound int32) serverproto.ErrorCode {
  2275. if this.role.GetRoleBattle() == nil {
  2276. return serverproto.ErrorCode_ERROR_FAIL
  2277. }
  2278. if rushStage != 1 {
  2279. return serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
  2280. }
  2281. if payRewardInfo == nil {
  2282. return serverproto.ErrorCode_ERROR_FAIL
  2283. }
  2284. shopItem, ok := model.ConvertMapShop[payRewardInfo.GoodsId]
  2285. if !ok {
  2286. return serverproto.ErrorCode_ERROR_FAIL
  2287. }
  2288. for _, goods := range this.runeRushMapShop.GoodsInfo {
  2289. if goods.GoodsId == payRewardInfo.GoodsId {
  2290. if goods.BuyNum >= shopItem.LimitCount {
  2291. return serverproto.ErrorCode_ERROR_FAIL
  2292. }
  2293. break
  2294. }
  2295. }
  2296. if rushRound != 0 && rushRound != shopItem.Activity {
  2297. return serverproto.ErrorCode_ERROR_FAIL
  2298. }
  2299. payRewardInfo.Count = 1
  2300. payRewardInfo.GoodsId = payRewardInfo.GoodsId
  2301. payRewardInfo.Amount = shopItem.Price
  2302. payRewardInfo.GoodsName = shopItem.Name
  2303. //打包正常购买
  2304. for _, items := range shopItem.BuyReward {
  2305. payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{
  2306. Key: items.Key,
  2307. Value: items.Value,
  2308. })
  2309. }
  2310. util.InfoF("uid=%v rushmap: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2311. return serverproto.ErrorCode_ERROR_OK
  2312. }
  2313. func (this *RoleRune) BuyRushPetShopItem(payRewardInfo *serverproto.PayOrderSaveInfo, rushStage, rushRound int32) serverproto.ErrorCode {
  2314. if this.role.GetRolePet() == nil {
  2315. return serverproto.ErrorCode_ERROR_FAIL
  2316. }
  2317. if rushStage != 1 {
  2318. return serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
  2319. }
  2320. if payRewardInfo == nil {
  2321. return serverproto.ErrorCode_ERROR_FAIL
  2322. }
  2323. shopItem, ok := model.ConvertPetShop[payRewardInfo.GoodsId]
  2324. if !ok {
  2325. return serverproto.ErrorCode_ERROR_FAIL
  2326. }
  2327. for _, goods := range this.runeRushPetShop.GoodsInfo {
  2328. if goods.GoodsId == payRewardInfo.GoodsId {
  2329. if goods.BuyNum >= shopItem.LimitCount {
  2330. return serverproto.ErrorCode_ERROR_FAIL
  2331. }
  2332. break
  2333. }
  2334. }
  2335. if rushRound != 0 && rushRound != shopItem.Activity {
  2336. return serverproto.ErrorCode_ERROR_FAIL
  2337. }
  2338. payRewardInfo.Count = 1
  2339. payRewardInfo.GoodsId = payRewardInfo.GoodsId
  2340. payRewardInfo.Amount = shopItem.Price
  2341. payRewardInfo.GoodsName = shopItem.Name
  2342. //打包正常购买
  2343. for _, items := range shopItem.BuyReward {
  2344. payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{
  2345. Key: items.Key,
  2346. Value: items.Value,
  2347. })
  2348. }
  2349. util.InfoF("uid=%v rushmap: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2350. return serverproto.ErrorCode_ERROR_OK
  2351. }
  2352. func (this *RoleRune) BuyRushSkillShopItem(payRewardInfo *serverproto.PayOrderSaveInfo, rushStage, rushRound int32) serverproto.ErrorCode {
  2353. if this.role.GetRoleRush() == nil {
  2354. return serverproto.ErrorCode_ERROR_FAIL
  2355. }
  2356. if rushStage != 1 {
  2357. return serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
  2358. }
  2359. if payRewardInfo == nil {
  2360. return serverproto.ErrorCode_ERROR_FAIL
  2361. }
  2362. shopItem, ok := model.ConvertSkillShop[payRewardInfo.GoodsId]
  2363. if !ok {
  2364. return serverproto.ErrorCode_ERROR_FAIL
  2365. }
  2366. for _, goods := range this.runeRushSkillShop.GoodsInfo {
  2367. if goods.GoodsId == payRewardInfo.GoodsId {
  2368. if goods.BuyNum >= shopItem.LimitCount {
  2369. return serverproto.ErrorCode_ERROR_FAIL
  2370. }
  2371. break
  2372. }
  2373. }
  2374. if rushRound != 0 && rushRound != shopItem.Activity {
  2375. return serverproto.ErrorCode_ERROR_FAIL
  2376. }
  2377. payRewardInfo.Count = 1
  2378. payRewardInfo.GoodsId = payRewardInfo.GoodsId
  2379. payRewardInfo.Amount = shopItem.Price
  2380. payRewardInfo.GoodsName = shopItem.Name
  2381. //打包正常购买
  2382. for _, items := range shopItem.BuyReward {
  2383. payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{
  2384. Key: items.Key,
  2385. Value: items.Value,
  2386. })
  2387. }
  2388. util.InfoF("uid=%v rushmap: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2389. return serverproto.ErrorCode_ERROR_OK
  2390. }
  2391. func (this *RoleRune) BuyIdolSeasonShopItem(payRewardInfo *serverproto.PayOrderSaveInfo) serverproto.ErrorCode {
  2392. if payRewardInfo == nil {
  2393. return serverproto.ErrorCode_ERROR_FAIL
  2394. }
  2395. shopItem, ok := model.ConvertIdolShop[payRewardInfo.GoodsId]
  2396. if !ok {
  2397. return serverproto.ErrorCode_ERROR_FAIL
  2398. }
  2399. for _, goods := range this.runeIdolSeasonShop.GoodsInfo {
  2400. if goods.GoodsId == payRewardInfo.GoodsId {
  2401. if goods.BuyNum >= shopItem.LimitCount {
  2402. return serverproto.ErrorCode_ERROR_FAIL
  2403. }
  2404. break
  2405. }
  2406. }
  2407. payRewardInfo.Count = 1
  2408. payRewardInfo.GoodsId = payRewardInfo.GoodsId
  2409. payRewardInfo.Amount = shopItem.Price
  2410. payRewardInfo.GoodsName = shopItem.Name
  2411. //打包正常购买
  2412. for _, items := range shopItem.BuyReward {
  2413. payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{
  2414. Key: items.Key,
  2415. Value: items.Value,
  2416. })
  2417. }
  2418. util.InfoF("uid=%v idol season: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2419. return serverproto.ErrorCode_ERROR_OK
  2420. }
  2421. func (this *RoleRune) BuyRuneExplore(payRewardInfo *serverproto.PayOrderSaveInfo) serverproto.ErrorCode {
  2422. if payRewardInfo == nil {
  2423. return serverproto.ErrorCode_ERROR_FAIL
  2424. }
  2425. if this.runeExplore.BUnlock {
  2426. return serverproto.ErrorCode_ERROR_FAIL
  2427. }
  2428. if !RuneShopMag.IsOpen() {
  2429. return serverproto.ErrorCode_ERROR_FAIL
  2430. }
  2431. db := model.GetRuneExploreDataByRound(RuneShopMag.GetCurRound())
  2432. if db == nil {
  2433. return serverproto.ErrorCode_ERROR_FAIL
  2434. }
  2435. payRewardInfo.Amount = db.GetRMB()
  2436. payRewardInfo.Count = 1
  2437. payRewardInfo.GoodsName = strconv.Itoa(int(RuneShopMag.GetCurRound()))
  2438. util.InfoF("uid=%v guildbattle: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2439. return serverproto.ErrorCode_ERROR_OK
  2440. }
  2441. // 公会战购买
  2442. func (this *RoleRune) BuyGuildBattleShopItem(payRewardInfo *serverproto.PayOrderSaveInfo) serverproto.ErrorCode {
  2443. if this.role.GetRoleBattle() == nil {
  2444. return serverproto.ErrorCode_ERROR_FAIL
  2445. }
  2446. //todo wangzhaocan 判定是否在购买时间内
  2447. /*
  2448. if this.role.GetRoleBattle().IsInRushMapStage() == false {
  2449. return serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
  2450. }
  2451. */
  2452. if payRewardInfo == nil {
  2453. return serverproto.ErrorCode_ERROR_FAIL
  2454. }
  2455. shopItem, ok := model.ConvertGuildBattle[payRewardInfo.GoodsId]
  2456. if !ok {
  2457. return serverproto.ErrorCode_ERROR_FAIL
  2458. }
  2459. for _, goods := range this.runeGuildBattleShop.GoodsInfo {
  2460. if goods.GoodsId == payRewardInfo.GoodsId {
  2461. if goods.BuyNum >= shopItem.LimitCount {
  2462. return serverproto.ErrorCode_ERROR_FAIL
  2463. }
  2464. break
  2465. }
  2466. }
  2467. payRewardInfo.Count = 1
  2468. payRewardInfo.GoodsId = payRewardInfo.GoodsId
  2469. payRewardInfo.Amount = shopItem.Price
  2470. payRewardInfo.GoodsName = shopItem.Name
  2471. //打包正常购买
  2472. for _, items := range shopItem.BuyReward {
  2473. payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{
  2474. Key: items.Key,
  2475. Value: items.Value,
  2476. })
  2477. }
  2478. util.InfoF("uid=%v guildbattle: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2479. return serverproto.ErrorCode_ERROR_OK
  2480. }
  2481. // 充值钱包商店购买(假购买消耗对应道具)
  2482. func (this *RoleRune) BuyCreditRechargeShopItem(goodsId, count int32) serverproto.ErrorCode {
  2483. if count <= 0 || goodsId <= 0 {
  2484. return serverproto.ErrorCode_ERROR_PAY_ITEM_NO
  2485. }
  2486. shipItemCfg, ok := model.ConvertPurseShop[goodsId]
  2487. if !ok {
  2488. return serverproto.ErrorCode_ERROR_PAY_ITEM_NO
  2489. }
  2490. if _, ok := this.runeCreditRecharge[shipItemCfg.BagType]; !ok {
  2491. util.WarnF("uid=%v CreditRechargeShop item not init", this.role.GetUUid())
  2492. return serverproto.ErrorCode_ERROR_FAIL
  2493. }
  2494. bFind := false
  2495. bFirst := true
  2496. for _, goods := range this.runeCreditRecharge[shipItemCfg.BagType].GoodsInfo {
  2497. if goods.GoodsId == goodsId {
  2498. if shipItemCfg.LimitCount != 0 && goods.BuyNum >= shipItemCfg.LimitCount {
  2499. return serverproto.ErrorCode_ERROR_FAIL
  2500. }
  2501. if goods.HistoryBuy > 0 {
  2502. bFirst = false
  2503. }
  2504. bFind = true
  2505. break
  2506. }
  2507. }
  2508. // 商店找不到此商品,返回
  2509. if !bFind {
  2510. util.WarnF("uid=%v CreditRechargeShop itemList not find", this.role.GetUUid())
  2511. return serverproto.ErrorCode_ERROR_PAY_ITEM_NO
  2512. }
  2513. // 判断资源道具是否足够
  2514. delItemList := map[int32]int32{}
  2515. delItemList[int32(serverproto.ResType_Res_CreditRecharge)] += int32(shipItemCfg.Price) //消耗特定资源
  2516. if !this.role.GetRoleBag().CanDelItemList(delItemList) {
  2517. return serverproto.ErrorCode_ERROR_PAY_CREDITRECHARGE_NOT_ENOUGH
  2518. }
  2519. // 判断是否有足够的(充值钱包额度)
  2520. if !this.runeBase.CreditRechargeLimit {
  2521. price := int32(shipItemCfg.Price)
  2522. curVal := price + this.runeBase.UsedCreditRecharge
  2523. if this.runeBase.MaxCreditRecharge < curVal {
  2524. return serverproto.ErrorCode_ERROR_PAY_CREDITRECHARGE_LIMIT_NOT_ENOUGH
  2525. } else {
  2526. this.runeBase.UsedCreditRecharge += price
  2527. this.runeBaseDataChangeNtf()
  2528. this.SetDirty(true)
  2529. }
  2530. }
  2531. this.role.GetRoleBag().DelItemList(delItemList, AddItemST{AddFrom: AddFrom_CreditRecharge})
  2532. // 奖励物品处理
  2533. ackMsg := &serverproto.SCCreditRechargeShopItemBuyAck{
  2534. GoodsId: goodsId,
  2535. ShopItem: &serverproto.RuneShopItem{},
  2536. }
  2537. rewardList := map[int32]int32{}
  2538. for _, items := range shipItemCfg.BuyReward {
  2539. ackMsg.RewardItemList = append(ackMsg.RewardItemList, &serverproto.KeyValueType{
  2540. Key: items.Key,
  2541. Value: items.Value,
  2542. })
  2543. rewardList[items.Key] += items.Value
  2544. }
  2545. // 首冲或者非首冲获得
  2546. if bFirst == true {
  2547. for _, items := range shipItemCfg.FirstReward {
  2548. ackMsg.RewardItemList = append(ackMsg.RewardItemList, &serverproto.KeyValueType{
  2549. Key: items.Key,
  2550. Value: items.Value,
  2551. })
  2552. rewardList[items.Key] += items.Value
  2553. }
  2554. } else {
  2555. for _, items := range shipItemCfg.ExtraReward {
  2556. ackMsg.RewardItemList = append(ackMsg.RewardItemList, &serverproto.KeyValueType{
  2557. Key: items.Key,
  2558. Value: items.Value,
  2559. })
  2560. rewardList[items.Key] += items.Value
  2561. }
  2562. }
  2563. util.InfoF("uid=%v CreditRechargeShop id=%v count=%v", this.role.GetUUid(), goodsId, count)
  2564. this.role.AddItemList(rewardList, AddFrom_Rune, true)
  2565. // 获取物品后的后续逻辑处理
  2566. for _, goods := range this.runeCreditRecharge[shipItemCfg.BagType].GoodsInfo {
  2567. if goods.GoodsId == goodsId {
  2568. goods.BuyNum += 1
  2569. goods.HistoryBuy += 1
  2570. ackMsg.ShopItem.GoodsId = goods.GoodsId
  2571. ackMsg.ShopItem.Price = shipItemCfg.Price
  2572. ackMsg.ShopItem.FirstBuy = false
  2573. if shipItemCfg.LimitCount >= 9999 {
  2574. ackMsg.ShopItem.BuyNums = 0
  2575. ackMsg.ShopItem.BuyLimit = false
  2576. } else {
  2577. buyNum := shipItemCfg.LimitCount - goods.BuyNum
  2578. if buyNum < 0 {
  2579. buyNum = 0
  2580. }
  2581. ackMsg.ShopItem.BuyNums = buyNum
  2582. ackMsg.ShopItem.BuyLimit = true
  2583. }
  2584. ackMsg.ShopItem.EndTime = 0
  2585. this.addShopChange(Rune_Shop_Type_CreditRecharge)
  2586. break
  2587. }
  2588. }
  2589. this.role.ReplayGate(ackMsg, true)
  2590. return serverproto.ErrorCode_ERROR_OK
  2591. }
  2592. // 特权卡商店道具购买
  2593. func (this *RoleRune) BuySpecialPrivilegeShopItem(payRewardInfo *serverproto.PayOrderSaveInfo) serverproto.ErrorCode {
  2594. if this.runeBase.PrivilegeData == nil {
  2595. return serverproto.ErrorCode_ERROR_FAIL
  2596. }
  2597. goodsId := this.runeBase.PrivilegeData.SpecialId
  2598. if goodsId <= 0 && len(model.ConvertSpecialPrivilegeRight) > 0 {
  2599. goodsId = model.ConvertSpecialPrivilegeRight[0].Id
  2600. } else {
  2601. nextCfgData := this.getNextSpecialPrivilegeCfgData(goodsId)
  2602. if nextCfgData != nil {
  2603. goodsId = nextCfgData.Id
  2604. }
  2605. }
  2606. if goodsId <= 0 {
  2607. util.InfoF("uid=%v BuySpecialPrivilegeShopItem data not find!!!", this.role.GetUUid())
  2608. return serverproto.ErrorCode_ERROR_PAY_ITEM_NO
  2609. }
  2610. if goodsId == this.runeBase.PrivilegeData.SpecialId {
  2611. //无后续特权卡可购买
  2612. return serverproto.ErrorCode_ERROR_PAY_ITEM_NO
  2613. }
  2614. shopItemCfg := this.getSpecialPrivilegeCfgData(goodsId)
  2615. if shopItemCfg == nil {
  2616. return serverproto.ErrorCode_ERROR_PAY_ITEM_NO
  2617. }
  2618. // 初级开荒特权是否购买/是否具备购买高级开荒特权条件
  2619. // 任务条件不存在或者已经完成的状态下可以进行购买
  2620. ret := this.role.GetRoleBase().checkUnLockState(0, shopItemCfg.ConditionList)
  2621. if ret != serverproto.ErrorCode_ERROR_OK {
  2622. return serverproto.ErrorCode_ERROR_PAY_SPECIALPRIVILEGE_UNLOCK
  2623. }
  2624. payRewardInfo.Count = 1
  2625. payRewardInfo.GoodsId = goodsId
  2626. payRewardInfo.Amount = shopItemCfg.Price
  2627. payRewardInfo.GoodsName = shopItemCfg.GoodsName
  2628. // 购买获得道具
  2629. //for k, v := range shopItemCfg.VipReward {
  2630. // payRewardInfo.RewardList = append(payRewardInfo.RewardList, &serverproto.KeyValueType{
  2631. // Key: k,
  2632. // Value: v,
  2633. // })
  2634. //}
  2635. util.InfoF("uid=%v BuySpecialPrivilegeShopItem id=%v price=%v", this.role.GetUUid(), payRewardInfo.GoodsId, payRewardInfo.Amount)
  2636. return serverproto.ErrorCode_ERROR_OK
  2637. }
  2638. // RO通行证购买
  2639. func (this *RoleRune) BuyPassCheck(payRewardInfo *serverproto.PayOrderSaveInfo) serverproto.ErrorCode {
  2640. if model.ConvertPassCheckData == nil {
  2641. return serverproto.ErrorCode_ERROR_FAIL
  2642. }
  2643. if this.runeBase.IsPassCheck {
  2644. return serverproto.ErrorCode_ERROR_PAY_PASSCHECK_BUY
  2645. }
  2646. payRewardInfo.Count = 1
  2647. payRewardInfo.GoodsId = model.ConvertPassCheckData.Id
  2648. payRewardInfo.Amount = model.ConvertPassCheckData.Price
  2649. payRewardInfo.GoodsName = model.ConvertPassCheckData.GoodsName
  2650. //特权在购买成功后生效
  2651. util.InfoF("uid=%v BuyPassCheck id=%v price=%v", this.role.GetUUid(), payRewardInfo.GoodsId, payRewardInfo.Amount)
  2652. return serverproto.ErrorCode_ERROR_OK
  2653. }
  2654. // RO币礼包商店购买
  2655. func (this *RoleRune) PayInfoGetForRoCoin(goodsId, count int32) serverproto.ErrorCode {
  2656. if count <= 0 || goodsId <= 0 {
  2657. return serverproto.ErrorCode_ERROR_PAY_ITEM_NO
  2658. }
  2659. shipItemCfg, ok := model.ConvertGiftBag[goodsId]
  2660. if !ok || shipItemCfg.BagType != Rune_BagShop_Type_ROCoin {
  2661. return serverproto.ErrorCode_ERROR_PAY_ITEM_NO
  2662. }
  2663. bFind := false
  2664. bFirst := true
  2665. shopDataInfo, ok := this.runeGiftShop[shipItemCfg.BagType]
  2666. if ok {
  2667. for _, goods := range shopDataInfo.GoodsInfo {
  2668. if goods.GoodsId == goodsId {
  2669. if shipItemCfg.LimitCount != 0 && goods.BuyNum >= shipItemCfg.LimitCount {
  2670. return serverproto.ErrorCode_ERROR_FAIL
  2671. }
  2672. if goods.HistoryBuy > 0 {
  2673. bFirst = false
  2674. }
  2675. bFind = true
  2676. break
  2677. }
  2678. }
  2679. } else {
  2680. util.WarnF("uid=%v PayInfoGetForRoCoin item not init goodsId=%v ", this.role.GetUUid(), goodsId)
  2681. return serverproto.ErrorCode_ERROR_FAIL
  2682. }
  2683. //商店找不到此商品,返回
  2684. if bFind == false {
  2685. util.WarnF("uid=%v PayInfoGetForRoCoin item not find goodsId=%v", this.role.GetUUid(), goodsId)
  2686. return serverproto.ErrorCode_ERROR_FAIL
  2687. }
  2688. consumeVal := int32(shipItemCfg.Price)
  2689. if !this.role.GetRoleBag().CanDelItem(int32(serverproto.ResType_Res_ROCoin), consumeVal) {
  2690. return this.role.GetResNotice(int32(serverproto.ResType_Res_ROCoin))
  2691. }
  2692. this.role.DelItem(int32(serverproto.ResType_Res_ROCoin), consumeVal, AddItemST{
  2693. AddFrom: AddFrom_Rune,
  2694. Notify: true,
  2695. })
  2696. ackMsg := &serverproto.SCBTRoCoinShopItemBuyAck{
  2697. GoodsType: Rune_Shop_Type_Bag,
  2698. SubType: Rune_BagShop_Type_ROCoin,
  2699. GoodsId: goodsId,
  2700. ShopItem: &serverproto.RuneShopItem{},
  2701. }
  2702. reward := make(map[int32]int32)
  2703. for _, items := range shipItemCfg.BuyReward {
  2704. ackMsg.RewardItemList = append(ackMsg.RewardItemList, &serverproto.KeyValueType{
  2705. Key: items.Key,
  2706. Value: items.Value,
  2707. })
  2708. reward[items.Key] += items.Value
  2709. }
  2710. //打包额外道具 //首冲或者非首冲
  2711. if bFirst == true {
  2712. for _, items := range shipItemCfg.FirstReward {
  2713. ackMsg.RewardItemList = append(ackMsg.RewardItemList, &serverproto.KeyValueType{
  2714. Key: items.Key,
  2715. Value: items.Value,
  2716. })
  2717. reward[items.Key] += items.Value
  2718. }
  2719. } else {
  2720. for _, items := range shipItemCfg.ExtraReward {
  2721. ackMsg.RewardItemList = append(ackMsg.RewardItemList, &serverproto.KeyValueType{
  2722. Key: items.Key,
  2723. Value: items.Value,
  2724. })
  2725. reward[items.Key] += items.Value
  2726. }
  2727. }
  2728. util.InfoF("uid=%v PayInfoGetForRoCoin additemlist=%v", this.role.GetUUid(), ackMsg.RewardItemList)
  2729. this.role.AddItemList(reward, AddFrom_Rune, true)
  2730. // 获取物品后的后续逻辑处理
  2731. for _, goods := range shopDataInfo.GoodsInfo {
  2732. if goods.GoodsId == goodsId {
  2733. goods.BuyNum += 1
  2734. goods.HistoryBuy += 1
  2735. ackMsg.ShopItem.GoodsId = goods.GoodsId
  2736. ackMsg.ShopItem.Price = shipItemCfg.Price
  2737. ackMsg.ShopItem.FirstBuy = false
  2738. if shipItemCfg.LimitCount >= 9999 {
  2739. ackMsg.ShopItem.BuyNums = 0
  2740. ackMsg.ShopItem.BuyLimit = false
  2741. } else {
  2742. buyNum := shipItemCfg.LimitCount - goods.BuyNum
  2743. if buyNum < 0 {
  2744. buyNum = 0
  2745. }
  2746. ackMsg.ShopItem.BuyNums = buyNum
  2747. ackMsg.ShopItem.BuyLimit = true
  2748. }
  2749. ackMsg.ShopItem.EndTime = 0
  2750. this.addShopChange(Rune_Shop_Type_Bag)
  2751. break
  2752. }
  2753. }
  2754. this.role.ReplayGate(ackMsg, true)
  2755. return serverproto.ErrorCode_ERROR_OK
  2756. }
  2757. func (this *RoleRune) getSpecialPrivilegeCfgData(privilegeCfgId int32) *model.PrivilegeData {
  2758. for idx := 0; idx < len(model.ConvertSpecialPrivilegeRight); idx++ {
  2759. if model.ConvertSpecialPrivilegeRight[idx].Id == privilegeCfgId {
  2760. return model.ConvertSpecialPrivilegeRight[idx]
  2761. }
  2762. }
  2763. return nil
  2764. }
  2765. func (this *RoleRune) getNextSpecialPrivilegeCfgData(privilegeCfgId int32) *model.PrivilegeData {
  2766. // ConvertSpecialPrivilegeRight已经排序
  2767. for idx := 0; idx < len(model.ConvertSpecialPrivilegeRight); idx++ {
  2768. if model.ConvertSpecialPrivilegeRight[idx].Id > privilegeCfgId {
  2769. return model.ConvertSpecialPrivilegeRight[idx]
  2770. }
  2771. }
  2772. return nil
  2773. }
  2774. func (this *RoleRune) AddMonthCardItem(goodId, cnt int32) {
  2775. ntfMsg := &serverproto.SCRuneShopBuyItemNtf{
  2776. ShopType: Rune_Shop_Type_MonthCard,
  2777. ShopItem: &serverproto.RuneShopItem{},
  2778. SubShop: 0,
  2779. }
  2780. shopItemCfg, shopItemOk := model.ConvertMonthCard[goodId]
  2781. for _, data := range this.runeMonthCardShop.GoodsInfo {
  2782. if data.GoodsId == goodId {
  2783. //首次充值
  2784. if data.EndTime == 0 {
  2785. data.EndTime = (int64(util.GetLatest5Hour()) + int64(shopItemCfg.Duration)*24*3600*1000)
  2786. data.NextRewardTime = int64(util.GetLatest5Hour())
  2787. //非续时,给邮件奖励
  2788. reward := make(map[int32]int32)
  2789. for _, item := range shopItemCfg.MailReward {
  2790. reward[item.Key] = item.Value
  2791. }
  2792. if len(reward) > 0 {
  2793. this.role.GetRoleMail().AddMail(shopItemCfg.MailCfgId, serverproto.MailType_MailType_MonthCard,
  2794. reward, []int32{29}, "", "")
  2795. }
  2796. } else {
  2797. data.EndTime += int64(shopItemCfg.Duration) * 24 * 3600 * 1000 //30天d
  2798. }
  2799. data.BuyNum += cnt
  2800. data.HistoryBuy += cnt
  2801. if shopItemOk {
  2802. ntfMsg.ShopItem.GoodsId = data.GoodsId
  2803. ntfMsg.ShopItem.Price = shopItemCfg.Price
  2804. ntfMsg.ShopItem.FirstBuy = false
  2805. ntfMsg.ShopItem.BuyNums = data.BuyNum
  2806. ntfMsg.ShopItem.BuyLimit = false
  2807. ntfMsg.ShopItem.EndTime = data.EndTime
  2808. }
  2809. }
  2810. }
  2811. //购买成功,给VIP经验
  2812. //util.InfoF("uid=%v buy succ: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2813. this.role.ReplayGate(ntfMsg, true)
  2814. this.addShopChange(Rune_Shop_Type_MonthCard)
  2815. }
  2816. func (this *RoleRune) SpecialPrivilegeReward() serverproto.ErrorCode {
  2817. if this.runeBase.PrivilegeData == nil {
  2818. return serverproto.ErrorCode_ERROR_FAIL
  2819. }
  2820. cfgData := this.getSpecialPrivilegeCfgData(this.runeBase.PrivilegeData.SpecialId)
  2821. if cfgData == nil {
  2822. return serverproto.ErrorCode_ERROR_FAIL
  2823. }
  2824. if this.runeBase.PrivilegeData.RewardTime > 0 {
  2825. return serverproto.ErrorCode_ERROR_PAY_SPECIALPRIVILEGE_HAS_REWARD
  2826. }
  2827. nowTime := util.GetTimeMilliseconds()
  2828. this.runeBase.PrivilegeData.RewardTime = nowTime
  2829. this.runeBase.PrivilegeData.ProcessTime = nowTime
  2830. this.SetDirty(true)
  2831. this.runeBaseDataChangeNtf()
  2832. this.role.AddItemList(cfgData.VipReward, AddFrom_SpecialPrivilege, true)
  2833. ackMsg := &serverproto.SCRuneSpecialPrivilegeRewardAck{}
  2834. for k, v := range cfgData.VipReward {
  2835. ackMsg.RewardItemList = append(ackMsg.RewardItemList, &serverproto.KeyValueType{
  2836. Key: k,
  2837. Value: v,
  2838. })
  2839. }
  2840. this.role.ReplayGate(ackMsg, true)
  2841. return serverproto.ErrorCode_ERROR_OK
  2842. }
  2843. func (this *RoleRune) OnBuyMonthCardShopItem(payRewardInfo *serverproto.PayOrderSaveInfo) {
  2844. if payRewardInfo == nil {
  2845. return
  2846. }
  2847. this.AddMonthCardItem(payRewardInfo.GoodsId, payRewardInfo.Count)
  2848. //购买成功,给VIP经验
  2849. util.InfoF("uid=%v buy succ: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2850. taskT := serverproto.TaskType_Eve_Month_Card
  2851. if payRewardInfo.GoodsId == 2 {
  2852. taskT = serverproto.TaskType_Eve_Month_Card_High
  2853. }
  2854. this.role.roleTask.AddTypeCnt(taskT, 1)
  2855. TaskMagCheck(this.role, taskT, payRewardInfo.GoodsId)
  2856. //ntfMsg := &serverproto.SCRuneShopBuyItemNtf{
  2857. // ShopType: Rune_Shop_Type_MonthCard,
  2858. // ShopItem: &serverproto.RuneShopItem{},
  2859. // SubShop: 0,
  2860. //}
  2861. //
  2862. //shopItemCfg, shopItemOk := model.ConvertMonthCard[payRewardInfo.GoodsId]
  2863. //for _, data := range this.runeMonthCardShop.GoodsInfo {
  2864. // if data.GoodsId == payRewardInfo.GoodsId {
  2865. // //首次充值
  2866. // if data.EndTime == 0 {
  2867. // data.EndTime = (int64(util.GetCurrentTime()) + 29*24*3600*1000)
  2868. // data.NextRewardTime = int64(util.GetLatest5Hour())
  2869. //
  2870. // //非续时,给邮件奖励
  2871. // reward := make(map[int32]int32)
  2872. // for _, item := range shopItemCfg.MailReward {
  2873. // reward[item.Key] = item.Value
  2874. // }
  2875. //
  2876. // if len(reward) > 0 {
  2877. // this.role.GetRoleMail().AddMail(shopItemCfg.MailCfgId, serverproto.MailType_MailType_MonthCard,
  2878. // reward, []int32{29}, "", "")
  2879. // }
  2880. // } else {
  2881. // data.EndTime += 30 * 24 * 3600 * 1000 //30天d
  2882. // }
  2883. // data.BuyNum += payRewardInfo.Count
  2884. // data.HistoryBuy += payRewardInfo.Count
  2885. //
  2886. // if shopItemOk {
  2887. // ntfMsg.ShopItem.GoodsId = data.GoodsId
  2888. // ntfMsg.ShopItem.Price = shopItemCfg.Price
  2889. // ntfMsg.ShopItem.FirstBuy = false
  2890. // ntfMsg.ShopItem.BuyNums = data.BuyNum
  2891. // ntfMsg.ShopItem.BuyLimit = false
  2892. // ntfMsg.ShopItem.EndTime = data.EndTime
  2893. // }
  2894. // }
  2895. //}
  2896. //
  2897. ////购买成功,给VIP经验
  2898. //util.InfoF("uid=%v buy succ: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2899. //
  2900. //this.role.ReplayGate(ntfMsg, true)
  2901. //this.addShopChange(Rune_Shop_Type_MonthCard)
  2902. }
  2903. // 给VIP经验
  2904. func (this *RoleRune) OnBuyItemSuccess(payRewardInfo *serverproto.PayOrderSaveInfo) {
  2905. ntfMsg := &serverproto.SCRuneShopBuyItemNtf{
  2906. ShopItem: &serverproto.RuneShopItem{},
  2907. }
  2908. if payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_NormalBag) {
  2909. goodCfg, ok := model.ConvertGiftBag[payRewardInfo.GoodsId]
  2910. if !ok {
  2911. return
  2912. }
  2913. _, ok1 := this.runeGiftShop[goodCfg.BagType]
  2914. if !ok1 {
  2915. return
  2916. }
  2917. ntfMsg.ShopType = Rune_Shop_Type_Bag
  2918. ntfMsg.SubShop = goodCfg.BagType
  2919. for _, goods := range this.runeGiftShop[goodCfg.BagType].GoodsInfo {
  2920. if goods.GoodsId == payRewardInfo.GoodsId {
  2921. goods.BuyNum += payRewardInfo.Count
  2922. goods.HistoryBuy += payRewardInfo.Count
  2923. //打包购买后商品信息
  2924. ntfMsg.ShopItem.GoodsId = goods.GoodsId
  2925. ntfMsg.ShopItem.Price = goodCfg.Price
  2926. ntfMsg.ShopItem.FirstBuy = false
  2927. if goodCfg.LimitCount >= 9999 {
  2928. ntfMsg.ShopItem.BuyNums = 0
  2929. ntfMsg.ShopItem.BuyLimit = false
  2930. } else {
  2931. var buyNum int32 = goodCfg.LimitCount - goods.BuyNum
  2932. if buyNum < 0 {
  2933. buyNum = 0
  2934. }
  2935. ntfMsg.ShopItem.BuyNums = buyNum
  2936. ntfMsg.ShopItem.BuyLimit = true
  2937. }
  2938. ntfMsg.ShopItem.EndTime = 0
  2939. this.addShopChange(Rune_Shop_Type_Bag)
  2940. break
  2941. }
  2942. }
  2943. } else if payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_LimitBag) {
  2944. ntfMsg.ShopType = Rune_Shop_Type_TimeLimit
  2945. for _, goods := range this.runeLimitShop.GoodsInfo {
  2946. if goods.GoodsId == payRewardInfo.GoodsId {
  2947. goods.BuyNum += payRewardInfo.Count
  2948. goods.HistoryBuy += payRewardInfo.Count
  2949. //打包购买后商品信息
  2950. goodCfg, ok := model.ConvertLimitGag[payRewardInfo.GoodsId]
  2951. if ok {
  2952. ntfMsg.ShopItem.GoodsId = goods.GoodsId
  2953. ntfMsg.ShopItem.Price = goodCfg.Price
  2954. ntfMsg.ShopItem.FirstBuy = false
  2955. if goodCfg.LimitCount >= 9999 {
  2956. ntfMsg.ShopItem.BuyNums = 0
  2957. ntfMsg.ShopItem.BuyLimit = false
  2958. } else {
  2959. var buyNum int32 = goodCfg.LimitCount - goods.BuyNum
  2960. if buyNum < 0 {
  2961. buyNum = 0
  2962. }
  2963. ntfMsg.ShopItem.BuyNums = buyNum
  2964. ntfMsg.ShopItem.BuyLimit = true
  2965. }
  2966. ntfMsg.ShopItem.EndTime = 0
  2967. if goodCfg.EndTime != 0 {
  2968. ntfMsg.ShopItem.EndTime = goodCfg.EndTime
  2969. } else {
  2970. if goodCfg.LimitType == LimitType_StartServer {
  2971. startUpTime := service.GetServiceStartupTime()
  2972. if startUpTime > 0 {
  2973. ntfMsg.ShopItem.EndTime = int64(startUpTime) + int64(goodCfg.EndDay-1)*24*3600*1000
  2974. }
  2975. } else if goodCfg.LimitType == LimitType_Activity {
  2976. endTime := this.role.GetRoleActivity().ActivityHDRuneGoodsAdd(goodCfg.ActivityId)
  2977. ntfMsg.ShopItem.EndTime = int64(endTime)
  2978. } else if goodCfg.LimitType == LimitType_Competition {
  2979. ntfMsg.ShopItem.EndTime = int64(this.role.roleCompetition.curCompInfo.CurEndTime)
  2980. }
  2981. }
  2982. }
  2983. this.addShopChange(Rune_Shop_Type_TimeLimit)
  2984. break
  2985. }
  2986. }
  2987. }
  2988. util.InfoF("uid=%v buy succ: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  2989. this.role.ReplayGate(ntfMsg, true)
  2990. }
  2991. // 爬塔、英灵殿、推图商店购买
  2992. func (this *RoleRune) OnBuyRushShopSuccess(payRewardInfo *serverproto.PayOrderSaveInfo) {
  2993. ntfMsg := &serverproto.SCRuneShopBuyItemNtf{
  2994. ShopItem: &serverproto.RuneShopItem{},
  2995. }
  2996. var rushShop *serverproto.RuneShop = nil
  2997. var goodCfg *model.RushShop = nil
  2998. var ok bool = false
  2999. var changedShop int32
  3000. if payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_RushTower) {
  3001. rushShop = this.runeRushTowerShop
  3002. goodCfg, ok = model.ConvertTowerShop[payRewardInfo.GoodsId]
  3003. changedShop = Rune_Shop_Type_RushTower
  3004. } else if payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_RushArena) {
  3005. goodCfg, ok = model.ConvertArenaShop[payRewardInfo.GoodsId]
  3006. rushShop = this.runeRushArenaShop
  3007. changedShop = Rune_Shop_Type_RushArena
  3008. } else if payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_RushMap) {
  3009. goodCfg, ok = model.ConvertMapShop[payRewardInfo.GoodsId]
  3010. rushShop = this.runeRushMapShop
  3011. changedShop = Rune_Shop_Type_RushMap
  3012. } else if payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_RushPet) {
  3013. goodCfg, ok = model.ConvertPetShop[payRewardInfo.GoodsId]
  3014. rushShop = this.runeRushPetShop
  3015. changedShop = Rune_Shop_Type_RushPet
  3016. } else if payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_RushSkill) {
  3017. goodCfg, ok = model.ConvertSkillShop[payRewardInfo.GoodsId]
  3018. rushShop = this.runeRushSkillShop
  3019. changedShop = Rune_Shop_Type_RushSkill
  3020. }
  3021. ntfMsg.ShopType = changedShop
  3022. if rushShop == nil || !ok || goodCfg == nil {
  3023. //严重报错
  3024. return
  3025. }
  3026. for _, goods := range rushShop.GoodsInfo {
  3027. if goods.GoodsId == payRewardInfo.GoodsId {
  3028. goods.BuyNum += payRewardInfo.Count
  3029. goods.HistoryBuy += payRewardInfo.Count
  3030. //打包购买后商品信息
  3031. ntfMsg.ShopItem.GoodsId = goods.GoodsId
  3032. ntfMsg.ShopItem.Price = goodCfg.Price
  3033. ntfMsg.ShopItem.FirstBuy = false
  3034. if goodCfg.LimitCount >= 9999 {
  3035. ntfMsg.ShopItem.BuyNums = 0
  3036. ntfMsg.ShopItem.BuyLimit = false
  3037. } else {
  3038. var buyNum int32 = goodCfg.LimitCount - goods.BuyNum
  3039. if buyNum < 0 {
  3040. buyNum = 0
  3041. }
  3042. ntfMsg.ShopItem.BuyNums = buyNum
  3043. ntfMsg.ShopItem.BuyLimit = true
  3044. }
  3045. ntfMsg.ShopItem.EndTime = 0
  3046. break
  3047. }
  3048. }
  3049. if payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_RushMap) {
  3050. if goodCfg.Score != 0 {
  3051. this.role.GetRoleBattle().OnRushMapScoreChange(0, goodCfg.Score)
  3052. }
  3053. }
  3054. this.addShopChange(changedShop)
  3055. util.InfoF("uid=%v rush shop buy succ: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  3056. this.role.ReplayGate(ntfMsg, true)
  3057. }
  3058. // 爬塔、英灵殿、推图商店购买
  3059. func (this *RoleRune) OnBuyGuildBattleSuccess(payRewardInfo *serverproto.PayOrderSaveInfo) {
  3060. ntfMsg := &serverproto.SCRuneShopBuyItemNtf{
  3061. ShopItem: &serverproto.RuneShopItem{},
  3062. }
  3063. var rushShop *serverproto.RuneShop = nil
  3064. var goodCfg *model.RushShop = nil
  3065. var ok bool = false
  3066. var changedShop int32
  3067. if payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_GuildBattle) {
  3068. ntfMsg.ShopType = Rune_Shop_Type_GuildBattle
  3069. rushShop = this.runeGuildBattleShop
  3070. goodCfg, ok = model.ConvertGuildBattle[payRewardInfo.GoodsId]
  3071. changedShop = Rune_Shop_Type_GuildBattle
  3072. }
  3073. if rushShop == nil || !ok || goodCfg == nil {
  3074. util.ErrorF("uid=%v buy guildbattle shop failed : shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  3075. //严重报错
  3076. return
  3077. }
  3078. for _, goods := range rushShop.GoodsInfo {
  3079. if goods.GoodsId == payRewardInfo.GoodsId {
  3080. goods.BuyNum += payRewardInfo.Count
  3081. goods.HistoryBuy += payRewardInfo.Count
  3082. //打包购买后商品信息
  3083. ntfMsg.ShopItem.GoodsId = goods.GoodsId
  3084. ntfMsg.ShopItem.Price = goodCfg.Price
  3085. ntfMsg.ShopItem.FirstBuy = false
  3086. if goodCfg.LimitCount >= 9999 {
  3087. ntfMsg.ShopItem.BuyNums = 0
  3088. ntfMsg.ShopItem.BuyLimit = false
  3089. } else {
  3090. var buyNum int32 = goodCfg.LimitCount - goods.BuyNum
  3091. if buyNum < 0 {
  3092. buyNum = 0
  3093. }
  3094. ntfMsg.ShopItem.BuyNums = buyNum
  3095. ntfMsg.ShopItem.BuyLimit = true
  3096. }
  3097. ntfMsg.ShopItem.EndTime = 0
  3098. break
  3099. }
  3100. }
  3101. this.addShopChange(changedShop)
  3102. util.InfoF("uid=%v guildbattle shop buy succ: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  3103. this.role.ReplayGate(ntfMsg, true)
  3104. }
  3105. func (this *RoleRune) OnBuyIdolSeasonSuccess(payRewardInfo *serverproto.PayOrderSaveInfo) {
  3106. ntfMsg := &serverproto.SCRuneShopBuyItemNtf{
  3107. ShopItem: &serverproto.RuneShopItem{},
  3108. }
  3109. var rushShop *serverproto.RuneShop = nil
  3110. var goodCfg *model.RushShop = nil
  3111. var ok bool = false
  3112. var changedShop int32
  3113. if payRewardInfo.GoodsType == int32(serverproto.PayGoodsType_EPayType_RushIdol) {
  3114. rushShop = this.runeIdolSeasonShop
  3115. goodCfg, ok = model.ConvertIdolShop[payRewardInfo.GoodsId]
  3116. changedShop = Rune_Shop_Type_Idol
  3117. }
  3118. ntfMsg.ShopType = changedShop
  3119. if rushShop == nil || !ok || goodCfg == nil {
  3120. util.ErrorF("uid=%v buy idol season shop failed : shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  3121. //严重报错
  3122. return
  3123. }
  3124. for _, goods := range rushShop.GoodsInfo {
  3125. if goods.GoodsId == payRewardInfo.GoodsId {
  3126. goods.BuyNum += payRewardInfo.Count
  3127. goods.HistoryBuy += payRewardInfo.Count
  3128. //打包购买后商品信息
  3129. ntfMsg.ShopItem.GoodsId = goods.GoodsId
  3130. ntfMsg.ShopItem.Price = goodCfg.Price
  3131. ntfMsg.ShopItem.FirstBuy = false
  3132. if goodCfg.LimitCount >= 9999 {
  3133. ntfMsg.ShopItem.BuyNums = 0
  3134. ntfMsg.ShopItem.BuyLimit = false
  3135. } else {
  3136. var buyNum int32 = goodCfg.LimitCount - goods.BuyNum
  3137. if buyNum < 0 {
  3138. buyNum = 0
  3139. }
  3140. ntfMsg.ShopItem.BuyNums = buyNum
  3141. ntfMsg.ShopItem.BuyLimit = true
  3142. }
  3143. ntfMsg.ShopItem.EndTime = 0
  3144. break
  3145. }
  3146. }
  3147. if goodCfg.Score > 0 {
  3148. this.role.GetRoleCompetition().AddSeasonBoxScore(goodCfg.Score, true)
  3149. }
  3150. if goodCfg.Ticket > 0 {
  3151. this.role.GetRoleCompetition().VoteIdol(this.role.GetUUid(), goodCfg.Ticket, false)
  3152. }
  3153. this.addShopChange(changedShop)
  3154. util.InfoF("uid=%v idol season shop buy succ: shop:%v id:%v, count:%v,price:%v", this.role.GetUUid(), payRewardInfo.GoodsType, payRewardInfo.GoodsId, payRewardInfo.Count, payRewardInfo.Amount)
  3155. this.role.ReplayGate(ntfMsg, true)
  3156. }
  3157. func (this *RoleRune) OnBuySpecialPrivilege(payRewardInfo *serverproto.PayOrderSaveInfo) {
  3158. // 判断初级特权没领取的情况下,直接升级到高级特权
  3159. oldSpecialId := this.runeBase.PrivilegeData.SpecialId
  3160. if oldSpecialId != payRewardInfo.GoodsId && this.runeBase.PrivilegeData.RewardTime <= 0 {
  3161. cfgData := this.getSpecialPrivilegeCfgData(oldSpecialId)
  3162. if cfgData != nil {
  3163. // 奖励邮件发送
  3164. this.role.GetRoleMail().AddMail(model.GlobalMailSpecialPrivilegeCard, serverproto.MailType_MailType_SpecialPrivilege,
  3165. cfgData.VipReward, nil, "", "")
  3166. }
  3167. }
  3168. // 特权购买
  3169. this.runeBase.PrivilegeData.SpecialId = payRewardInfo.GoodsId
  3170. this.runeBase.PrivilegeData.RewardTime = 0
  3171. this.runeBase.PrivilegeData.ProcessTime = util.GetTimeMilliseconds()
  3172. this.SetDirty(true)
  3173. cfgData := this.getSpecialPrivilegeCfgData(payRewardInfo.GoodsId)
  3174. if cfgData == nil {
  3175. util.ErrorF("uid=%v OnBuySpecialPrivilege cfgData not found=%v", this.role.GetUUid(), payRewardInfo.GoodsId)
  3176. return
  3177. }
  3178. // 特权处理
  3179. // 充值钱包额度,战斗内加速
  3180. for k, v := range cfgData.VipRight {
  3181. switch k {
  3182. case model.Vip_System_FastBattleTime:
  3183. // 解锁战斗加速功能
  3184. // 客户端判定购买过特权卡就拥有加速功能
  3185. case model.Vip_System_CreditRecharge:
  3186. // 充值钱包额度(添加的数值)
  3187. if v < 0 {
  3188. // 无额度上限
  3189. this.runeBase.CreditRechargeLimit = true
  3190. } else {
  3191. this.runeBase.MaxCreditRecharge += v
  3192. }
  3193. }
  3194. }
  3195. this.runeBaseDataChangeNtf()
  3196. util.InfoF("uid=%v OnBuySpecialPrivilege GoodsId=%v success", this.role.GetUUid(), payRewardInfo.GoodsId)
  3197. }
  3198. func (this *RoleRune) GMAddCreditRecharge(val int32, limit bool) {
  3199. if limit {
  3200. this.runeBase.CreditRechargeLimit = true
  3201. } else {
  3202. this.runeBase.MaxCreditRecharge += val
  3203. }
  3204. this.SetDirty(true)
  3205. this.runeBaseDataChangeNtf()
  3206. }
  3207. func (this *RoleRune) OnBuyPassCheck(payRewardInfo *serverproto.PayOrderSaveInfo) {
  3208. if model.ConvertPassCheckData == nil {
  3209. return
  3210. }
  3211. this.runeBase.IsPassCheck = true
  3212. this.SetDirty(true)
  3213. // 特权处理
  3214. // 3.添加属性
  3215. this.role.roleBattleAttr.AttrChange(AttrChangeST{
  3216. ChangeType: Attr_Change_VipPrivilege,
  3217. ChangeHeroData: this.role.GetRoleHero().GetMainHero(),
  3218. })
  3219. this.runeBaseDataChangeNtf()
  3220. util.ErrorF("uid=%v OnBuyPassCheck GoodsId=%v", this.role.GetUUid(), payRewardInfo.GoodsId)
  3221. }