role_rune.go 104 KB

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