| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818 |
- package model
- import (
- "math"
- "rocommon/util"
- "roserver/baseserver/model"
- "roserver/serverproto"
- "time"
- )
- const (
- ShopType_Normal = 1 //普通商店
- ShopType_Arane = 2 //英灵殿
- ShopType_Dark = 3 //黑市
- ShopType_Guild = 4 //公会
- ShopType_Pet = 5 //宠物
- ShopType_Dao = 6 //道场
- ShopType_Spring = 9 //新春
- ShopType_NewBee = 10 //新手
- ShopType_CashShop = 50 //cash shop
- )
- type RoleShop struct {
- SaveObject
- shopBuyInfo map[int32]*serverproto.BuyInfo
- specialShop map[int32]*serverproto.SpecialShop
- costRes []*serverproto.ShopCost
- totalBuyNum int32 //商店总购买次数
- }
- func newRoleShop(r *Role) *RoleShop {
- roleShop := &RoleShop{
- SaveObject: SaveObject{
- role: r,
- },
- }
- roleShop.shopBuyInfo = make(map[int32]*serverproto.BuyInfo)
- roleShop.specialShop = make(map[int32]*serverproto.SpecialShop)
- return roleShop
- }
- func (this *RoleShop) Load(msg interface{}) bool {
- proRole := msg.(*serverproto.Role)
- if proRole != nil && proRole.RoleShop != nil {
- for _, buyInfo := range proRole.RoleShop.Info {
- for _, itemInfo := range buyInfo.ItemInfo {
- this.shopBuyInfo[itemInfo.GoodsId] = itemInfo
- }
- //黑市类型商店
- shopType, ok := serverproto.ShopTypeCfgLoader[buyInfo.GoodsType]
- if ok && shopType.ShopType == 2 {
- this.specialShop[buyInfo.GoodsType] = buyInfo.RefData
- }
- }
- for _, costRes := range proRole.RoleShop.CostRes {
- this.costRes = append(this.costRes, costRes)
- }
- this.totalBuyNum = proRole.RoleShop.TotalBuyNum
- }
- return true
- }
- func (this *RoleShop) DailyReset(notify bool) {
- for _, shop := range this.specialShop {
- shop.RefreshCount = 0
- }
- this.SetDirty(true)
- }
- func (this *RoleShop) Save() {
- this.SetDirty(false)
- util.DebugF("uid=%v RoleShop save...", this.role.GetUUid())
- saveMsg := &serverproto.SSShopDataSaveReq{
- Shop: &serverproto.RoleShop{
- TotalBuyNum: this.totalBuyNum,
- },
- }
- //处理购买信息相关数据
- for _, buyData := range this.shopBuyInfo {
- goodsType := this.GetGoodsType(buyData.GoodsId)
- if goodsType == 0 {
- continue
- }
- var bFind = false
- for _, buyInfo := range saveMsg.Shop.Info {
- if buyInfo.GoodsType == goodsType {
- buyInfo.ItemInfo = append(buyInfo.ItemInfo, buyData)
- bFind = true
- break
- }
- }
- if bFind == false {
- buyInfo := &serverproto.ShopBuyInfo{
- GoodsType: goodsType,
- }
- buyInfo.ItemInfo = append(buyInfo.ItemInfo, buyData)
- saveMsg.Shop.Info = append(saveMsg.Shop.Info, buyInfo)
- }
- }
- //打包黑市商店售卖数据
- for goodsType, shopData := range this.specialShop {
- bFind := false
- for idx, msgShop := range saveMsg.Shop.Info {
- if goodsType == msgShop.GoodsType {
- saveMsg.Shop.Info[idx].RefData = shopData
- bFind = true
- }
- }
- if bFind == false {
- buyInfo := &serverproto.ShopBuyInfo{
- GoodsType: goodsType,
- }
- buyInfo.RefData = shopData
- saveMsg.Shop.Info = append(saveMsg.Shop.Info, buyInfo)
- }
- }
- for _, data := range this.costRes {
- saveMsg.Shop.CostRes = append(saveMsg.Shop.CostRes, data)
- }
- this.role.SendDb(saveMsg)
- }
- func (this *RoleShop) GetGoodsType(shopItem int32) int32 {
- cfg, ok := serverproto.ShopCfgLoader[shopItem]
- if !ok {
- return 0
- }
- return cfg.GoodsType
- }
- func (this *RoleShop) GetShopType(shopId int32) int32 {
- cfg, ok := serverproto.ShopTypeCfgLoader[shopId]
- if !ok {
- return 0
- }
- return cfg.ShopType
- }
- func (this *RoleShop) GetShopTotalBuyNum() int32 {
- return this.totalBuyNum
- }
- //循环限购-单独处理//计算当前轮次购买数量
- func (this *RoleShop) GetCurRoundBuyNum(buyItem *serverproto.BuyInfo, shopItem *serverproto.ShopItem) (int32, serverproto.ErrorCode) {
- if shopItem == nil {
- return 0, serverproto.ErrorCode_ERROR_SHOP_CONFIG_ITEM_NO_FOUND
- }
- curTime := util.GetTimeSeconds()
- //这个判定现在不要了。只针对限购类型3,时间段限购 //超过最大时间就不让买了
- /*
- if shopItem.EndTime > 0 && curTime > shopItem.EndTime {
- return 0, serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
- }
- */
- if buyItem.BuyNum == 0 { //压根没买过
- return shopItem.Count, serverproto.ErrorCode_ERROR_OK
- }
- if shopItem.LimitType == LIMIT_TYPE_WEEK || shopItem.LimitType == LIMIT_TYPE_DAY {
- if curTime < buyItem.RefTime {
- if shopItem.Count < buyItem.BuyNum {
- return 0, serverproto.ErrorCode_ERROR_SHOP_MAX_BUY_NUM
- }
- return shopItem.Count - buyItem.BuyNum, serverproto.ErrorCode_ERROR_OK
- } else {
- buyItem.BuyNum = 0
- buyItem.BuyTime = 0
- this.SetDirty(true)
- if buyItem.RefTime != 0 {
- util.DebugF("uid=%v %s RoleShop refresh...", this.role.GetUUid(), this.role.GetNickName())
- }
- return shopItem.Count, serverproto.ErrorCode_ERROR_OK
- }
- }
- return 0, 0
- }
- func (this *RoleShop) GetShopItemConfig(shopId int32, goodsId int32) (serverproto.ErrorCode, *serverproto.ShopItem) {
- shopType, ok := serverproto.ShopTypeCfgLoader[shopId]
- if ok && shopType.ShopType == 2 {
- specialShop, ok2 := model.ConvertRoleShopData[shopId]
- if !ok2 {
- return serverproto.ErrorCode_ERROR_SHOP_CONFIG_NO_FOUND, nil
- }
- for _, data := range specialShop.ItemList {
- if data.ShopItem.GoodsId == goodsId {
- return serverproto.ErrorCode_ERROR_OK, data.ShopItem
- }
- }
- return serverproto.ErrorCode_ERROR_SHOP_CONFIG_ITEM_NO_FOUND, nil
- }
- //
- if shopId == ShopType_CashShop {
- shopItem, ok := model.ConvertRedBagShopItemData[goodsId]
- if !ok || shopItem == nil {
- return serverproto.ErrorCode_ERROR_SHOP_CONFIG_ITEM_NO_FOUND, nil
- }
- return serverproto.ErrorCode_ERROR_OK, shopItem.ShopItem
- }
- shopItem, ok := model.ConvertShopItemData[goodsId]
- if !ok || shopItem == nil {
- return serverproto.ErrorCode_ERROR_SHOP_CONFIG_ITEM_NO_FOUND, nil
- }
- return serverproto.ErrorCode_ERROR_OK, shopItem
- }
- //返回购买数量可错误码,-1表示不限购
- func (this *RoleShop) CheckBuyLimit(shopId, goodsId, goodsNum int32) (int32, serverproto.ErrorCode) {
- if goodsNum <= 0 || goodsNum >= 1000 {
- return -1, serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
- }
- bRet, shopInfo := this.GetShopItemConfig(shopId, goodsId)
- if bRet != serverproto.ErrorCode_ERROR_OK || shopInfo == nil {
- return 0, serverproto.ErrorCode_ERROR_SHOP_CONFIG_ITEM_NO_FOUND
- }
- if shopInfo.LimitType == LIMIT_TYPE_NONE && shopInfo.HdItemId == 0 {
- return -1, serverproto.ErrorCode_ERROR_OK
- }
- //黑市类型商店需要检查,当前商店是否有此道具
- shopType := this.GetShopType(shopId)
- if shopType == 2 {
- shop := this.specialShop[shopId]
- if shop == nil {
- return -1, serverproto.ErrorCode_ERROR_SHOP_CONFIG_NO_FOUND
- }
- //判定下时间,过期了说明没刷新
- if shop.RefreshTime < int64(util.GetTimeSeconds()) {
- return -1, serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
- }
- //判定商店是否有此件商品
- bFind := false
- for _, data := range shop.GoodsList {
- if data == goodsId {
- bFind = true
- break
- }
- }
- if !bFind {
- return -1, serverproto.ErrorCode_ERROR_SHOP_NOT_FOUND_ITEM
- }
- }
- //先判定时间//当前不在限购时间内
- if shopInfo.LimitType == LIMIT_TYPE_RANGE {
- curTime := util.GetTimeSeconds()
- if curTime > shopInfo.EndTime || curTime < shopInfo.StartTime {
- return 0, serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
- }
- }
- if shopInfo.HdItemId != 0 {
- if !this.checkHDShopItem(shopInfo) {
- return 0, serverproto.ErrorCode_ERROR_SHOP_NOT_IN_RANGE_TIME
- }
- if shopInfo.LimitType == 0 {
- return -1, serverproto.ErrorCode_ERROR_OK
- }
- }
- //没有购买记录,则直接给上限
- buyInfo, ok := this.shopBuyInfo[goodsId]
- if !ok {
- return shopInfo.Count, serverproto.ErrorCode_ERROR_OK
- }
- if shopInfo.LimitType == LIMIT_TYPE_FOREVER || shopInfo.LimitType == LIMIT_TYPE_SPECIAL {
- //当前购买数量和限购数量差额
- if shopInfo.Count <= buyInfo.BuyNum {
- return 0, serverproto.ErrorCode_ERROR_SHOP_MAX_BUY_NUM
- }
- return shopInfo.Count - buyInfo.BuyNum, serverproto.ErrorCode_ERROR_OK
- }
- //固定天刷新
- if shopInfo.LimitType == LIMIT_TYPE_DAY || shopInfo.LimitType == LIMIT_TYPE_WEEK {
- //查看限购期间已购买数量和限购数量差额
- count, err := this.GetCurRoundBuyNum(buyInfo, shopInfo)
- return count, err
- }
- if shopInfo.LimitType == LIMIT_TYPE_RANGE {
- //在限购时间内,返回可购买数量
- if shopInfo.Count <= buyInfo.BuyNum {
- return 0, serverproto.ErrorCode_ERROR_SHOP_MAX_BUY_NUM
- }
- return shopInfo.Count - buyInfo.BuyNum, serverproto.ErrorCode_ERROR_OK
- }
- return 0, serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleShop) BuyItem(goodsType, goodsId, goodsNum int32, ackMsg *serverproto.SCShopBuyItemAck) (serverproto.ErrorCode, uint64, int32) {
- if ackMsg == nil {
- return serverproto.ErrorCode_ERROR_FAIL, 0, 0
- }
- //校验配置
- shopCfg, ok := serverproto.ShopCfgLoader[goodsId]
- if !ok {
- return serverproto.ErrorCode_ERROR_SHOP_CONFIG_ITEM_NO_FOUND, 0, 0
- }
- bRet, shopInfo := this.GetShopItemConfig(goodsType, goodsId)
- if bRet != serverproto.ErrorCode_ERROR_OK || shopInfo == nil {
- return bRet, 0, 0
- }
- //校验是否限购/限时
- nRet, err := this.CheckBuyLimit(goodsType, goodsId, goodsNum)
- if err != serverproto.ErrorCode_ERROR_OK {
- return err, 0, 0
- }
- if nRet != -1 && nRet < goodsNum {
- return serverproto.ErrorCode_ERROR_SHOP_MAX_BUY_NUM, 0, 0
- }
- //前置条件判定通过,资源扣除成功,给道具
- var addItemList = map[int32]int32{}
- if shopCfg.GoodsType != ShopType_CashShop {
- addItemList[int32(shopCfg.GoodsItem)] = int32(goodsNum)
- } else {
- shopData, ok := model.ConvertRedBagShopItemData[shopCfg.GoodsId]
- if !ok {
- return serverproto.ErrorCode_ERROR_SHOP_CONFIG_NO_FOUND, 0, 0
- }
- for key, value := range shopData.ItemList {
- addItemList[key] = value
- }
- }
- if ret := this.role.CanAddItemList(addItemList); ret != serverproto.ErrorCode_ERROR_OK {
- return ret, 0, 0
- }
- //下面下面这段枚举代码,是客户端限时要,非常蛋疼的代码
- addFrom := AddFrom_Shop_Buy
- if shopCfg.GoodsType == ShopType_Arane {
- addFrom = AddFrom_Shop_Arane
- } else if shopCfg.GoodsType == ShopType_Dark {
- addFrom = AddFrom_Shop_Dark
- } else if shopCfg.GoodsType == ShopType_Guild {
- addFrom = AddFrom_Shop_Guild
- } else if shopCfg.GoodsType == ShopType_Pet {
- addFrom = AddFrom_Shop_Pet
- } else if shopCfg.GoodsType == ShopType_CashShop {
- addFrom = AddFrom_RedBagShop
- }
- //校验钱是否够
- price := shopCfg.PayForNum
- if shopCfg.DiscountPayForNum != 0 {
- price = shopCfg.DiscountPayForNum
- }
- needRes := uint64(price) * uint64(goodsNum)
- if needRes >= math.MaxInt32 {
- util.DebugF("uid=%v %s RoleShop Bug, goodsNum:%v ...", this.role.GetUUid(), this.role.GetNickName(), uint64(goodsNum))
- return serverproto.ErrorCode_ERROR_SHOP_MAX_BUY_NUM, 0, 0
- }
- var costItemList = map[int32]int32{}
- costItemList[shopCfg.PayForType] = int32(needRes)
- if this.role.CheckResLitNum(costItemList) {
- this.role.DelItemList(costItemList, AddItemST{AddFrom: addFrom, ReasonParam: goodsId, ReasonParam2: goodsNum})
- } else {
- bRet := this.role.GetResNotice(shopCfg.PayForType)
- return bRet, 0, 0
- }
- //前置条件判定通过,资源扣除成功,给道具
- if len(addItemList) > 0 {
- // this.role.AddItemList(shopCfg.GoodsItem, goodsNum, addFrom)
- this.role.AddItemList(addItemList, addFrom, true)
- }
- //添加购买数量
- var buyNum int32 = goodsNum
- notTime := uint64(util.GetTimeSeconds())
- if nRet != -1 { //非无限购买的商品
- buyData, ok := this.shopBuyInfo[goodsId]
- if !ok {
- data := &serverproto.BuyInfo{
- GoodsId: goodsId,
- BuyNum: goodsNum,
- BuyTime: notTime,
- }
- this.shopBuyInfo[goodsId] = data
- buyData = this.shopBuyInfo[goodsId]
- } else {
- buyData.BuyNum += goodsNum
- buyData.BuyTime = notTime
- buyNum = buyData.BuyNum
- }
- //记录下次刷新时间
- if shopInfo.LimitType == LIMIT_TYPE_DAY {
- buyData.RefTime = int64(util.GetLatest5Hour()) / 1000
- } else if shopInfo.LimitType == LIMIT_TYPE_WEEK {
- buyData.RefTime = int64(util.GetLatestWeek5Hour(0)) / 1000
- } else {
- buyData.RefTime = 0
- }
- }
- this.totalBuyNum++
- TaskMagCheck(this.role, serverproto.TaskType_Shop_Buy_Count, 0)
- this.OnBuyEnd(goodsType, shopCfg.PayForType, int32(needRes))
- if shopCfg.PayForType == int32(serverproto.ResType_Res_Rmb) {
- nLog := &NeteaseLogGoldBuyItem{}
- nLog.ItemId = int(goodsId)
- nLog.ItemName = shopCfg.GoodsName
- nLog.BuyTime = uint64(util.GetTimeSeconds())
- nLog.Price = int(shopCfg.PayForNum)
- nLog.Gold = int(needRes)
- nLog.CostMoney = 0
- nLog.ExpireTime = 0
- nLog.ItemCount = int(goodsNum)
- nLog.LogRoleGoldBuyItem(this.role)
- }
- this.SetDirty(true)
- //打包数据
- if len(addItemList) > 0 {
- for key, count := range addItemList {
- if key != 0 && count != 0 {
- ackMsg.ItemList = append(ackMsg.ItemList, &serverproto.KeyValueType{
- Key: key,
- Value: count,
- })
- }
- }
- }
- return serverproto.ErrorCode_ERROR_OK, notTime, buyNum
- }
- func (this *RoleShop) HandleSpecialShopRefresh(goodsType int32, ackMsg *serverproto.SCShopRefreshAck) serverproto.ErrorCode {
- shopInfo, ok := this.specialShop[goodsType]
- if !ok {
- return serverproto.ErrorCode_ERROR_SHOP_CONFIG_ITEM_NO_FOUND
- }
- shopData, ok2 := model.ConvertRoleShopData[goodsType]
- if !ok2 {
- return serverproto.ErrorCode_ERROR_SHOP_CONFIG_ITEM_NO_FOUND
- }
- if len(shopData.RefreshCost) <= 0 {
- return serverproto.ErrorCode_ERROR_SHOP_RESOURCE_NOT_NEOUGH
- }
- //判定刷新次数是否够
- if shopData.RefreshCount <= shopInfo.RefreshCount {
- return serverproto.ErrorCode_ERROR_SHOP_REFRESH_COUNT_MAX
- }
- //配置文件错误
- if len(shopData.RefreshCost) <= 0 {
- return serverproto.ErrorCode_ERROR_SHOP_CONFIG_ITEM_NO_FOUND
- }
- costIndex := shopInfo.RefreshCount
- if shopInfo.RefreshCount >= int32(len(shopData.RefreshCost)) {
- costIndex = int32(len(shopData.RefreshCost)) - 1
- }
- if this.role.CheckResLitNum(shopData.RefreshCost[costIndex].ItemList) == false {
- return serverproto.ErrorCode_ERROR_SHOP_REMOVE_COST_FAIL
- }
- bRet := this.RefreshSpecialShop(goodsType, shopInfo)
- //刷新异常,策划配置表错误。
- if bRet == false {
- util.ErrorF("uid=%v %s refresh failed shopType:=%v", this.role.GetUUid(), this.role.GetNickName(), goodsType)
- return serverproto.ErrorCode_ERROR_SHOP_CONFIG_ITEM_NO_FOUND
- }
- this.role.DelItemList(shopData.RefreshCost[costIndex].ItemList, AddItemST{AddFrom: AddFrom_Shop_Buy})
- ackMsg.ShopData = &serverproto.ShopData{
- GoodsType: goodsType,
- }
- shopInfo.RefreshCount += 1
- //打包道具数据
- for _, goodsId := range shopInfo.GoodsList {
- for _, data := range shopData.ItemList {
- if goodsId == data.ShopItem.GoodsId {
- ackMsg.ShopData.ItemInfo = append(ackMsg.ShopData.ItemInfo, data.ShopItem)
- }
- }
- }
- ackMsg.ShopData.GoodsType = goodsType
- ackMsg.ShopData.RefreshTime = shopInfo.RefreshTime
- ackMsg.ShopData.RefreshCount = shopInfo.RefreshCount
- this.SetDirty(true)
- util.DebugF("uid=%v %s GetSpecialShopInfo possitive refresh shopType:=%v", this.role.GetUUid(), this.role.GetNickName(), goodsType)
- return serverproto.ErrorCode_ERROR_OK
- }
- //下一次刷新时间:精确到秒
- func (this *RoleShop) GetNextRefreshTime(goodsType int32) int64 {
- loc := util.GetLoc()
- nowTime := util.GetCurrentTimeNow()
- curHour := nowTime.Hour()
- dayTimeStr := nowTime.Format(util.DATE_FORMAT1)
- tempDayTime, _ := time.ParseInLocation(util.DATE_FORMAT1, dayTimeStr, loc)
- refreshHour := model.GetNextShopRefreshHour(goodsType, int32(curHour))
- if refreshHour > int32(curHour) {
- tempDayTime = tempDayTime.Add(time.Hour * time.Duration(refreshHour))
- } else {
- tempDayTime = tempDayTime.Add(time.Hour * (time.Duration(refreshHour) + 24))
- }
- return (tempDayTime.UnixNano() / 1e9)
- }
- //刷新接口,删除老的购买列表和购买记录,刷新最新的额购买列表
- func (this *RoleShop) RefreshSpecialShop(goodsType int32, refData *serverproto.SpecialShop) bool {
- for _, goodsId := range refData.GoodsList {
- //删除购买记录
- _, ok2 := this.shopBuyInfo[goodsId]
- if !ok2 {
- continue
- }
- delete(this.shopBuyInfo, goodsId)
- }
- //获取最新的道具
- shopWeight := this.role.GetRoleBase().GetVipData(model.Vip_System_ShopWeight)
- goodsList := model.GetShopItemByShopType(goodsType, shopWeight)
- if goodsList != nil {
- refData.GoodsList = []int32{}
- for _, goodId := range goodsList {
- refData.GoodsList = append(refData.GoodsList, goodId)
- }
- return true
- }
- return false
- }
- func (this *RoleShop) GetSpecialShopInfo(goodsType int32, ackMsg *serverproto.SCShopInfoAck) serverproto.ErrorCode {
- if ackMsg == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- ackMsg.ShopData = &serverproto.ShopData{
- GoodsType: goodsType,
- }
- //没有触发过特殊商店。或者需要刷新
- shop, ok := this.specialShop[goodsType]
- if ok {
- //打包刷新数据
- needRefresh := model.CheckShopNeedRefresh(shop.RefreshTime)
- if needRefresh == true {
- this.RefreshSpecialShop(goodsType, shop)
- shop.RefreshTime = this.GetNextRefreshTime(goodsType)
- this.SetDirty(true)
- util.ErrorF("uid=%v %s refresh failed shopType:=%v", this.role.GetUUid(), this.role.GetNickName(), goodsType)
- }
- } else {
- //初始化特殊类型商店
- this.specialShop[goodsType] = &serverproto.SpecialShop{
- RefreshTime: this.GetNextRefreshTime(goodsType),
- RefreshCount: 0,
- }
- shopWeight := this.role.GetRoleBase().GetVipData(model.Vip_System_ShopWeight)
- goodsList := model.GetShopItemByShopType(goodsType, shopWeight)
- if goodsList != nil {
- for _, goodId := range goodsList {
- this.specialShop[goodsType].GoodsList = append(this.specialShop[goodsType].GoodsList, goodId)
- }
- this.SetDirty(true)
- util.InfoF("uid=%v %s init success shopType:=%v", this.role.GetUUid(), this.role.GetNickName(), goodsType)
- } else {
- util.ErrorF("uid=%v %s refresh failed shopType:=%v", this.role.GetUUid(), this.role.GetNickName(), goodsType)
- }
- }
- if this.specialShop[goodsType].RefreshTime == 0 {
- return serverproto.ErrorCode_ERROR_SHOP_REFRESH_TIME
- }
- //打包商品数据
- ackMsg.ShopData.GoodsType = goodsType
- shopList, ok := model.ConvertRoleShopData[goodsType]
- if !ok || shopList == nil {
- return serverproto.ErrorCode_ERROR_SHOP_CONFIG_ITEM_NO_FOUND
- }
- for _, goodsId := range this.specialShop[goodsType].GoodsList {
- for _, data := range shopList.ItemList {
- if goodsId == data.ShopItem.GoodsId {
- ackMsg.ShopData.ItemInfo = append(ackMsg.ShopData.ItemInfo, data.ShopItem)
- buyInfo, ok2 := this.shopBuyInfo[goodsId]
- if !ok2 { //没有买过
- continue
- }
- ackMsg.ShopData.BuyInfo = append(ackMsg.ShopData.BuyInfo, buyInfo)
- }
- }
- }
- ackMsg.ShopData.RefreshTime = this.specialShop[goodsType].RefreshTime
- ackMsg.ShopData.RefreshCount = this.specialShop[goodsType].RefreshCount
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleShop) GetShopConfig(goodsId, goodsType int32) *serverproto.ShopItem {
- if goodsType == 50 {
- shopInfo, ok := model.ConvertRedBagShopItemData[goodsId]
- if ok {
- return shopInfo.ShopItem
- }
- } else {
- shopInfo, ok := model.ConvertShopItemData[goodsId]
- if ok {
- return shopInfo
- }
- }
- return nil
- }
- func (this *RoleShop) GetShopInfo(goodsType int32, ackMsg *serverproto.SCShopInfoAck) serverproto.ErrorCode {
- if ackMsg == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- ackMsg.ShopData = &serverproto.ShopData{
- GoodsType: goodsType,
- }
- ackMsg.ShopData.DayEnd = int64(util.GetLatest5Hour()) / 1000
- ackMsg.ShopData.WeekEnd = int64(util.GetLatestWeek5Hour(0)) / 1000
- for _, buyData := range this.shopBuyInfo {
- gType := this.GetGoodsType(buyData.GoodsId)
- if gType == 0 {
- continue
- }
- //处理循环区间刷新的道具
- shopInfo := this.GetShopConfig(buyData.GoodsId, goodsType)
- if shopInfo == nil {
- continue
- }
- condition, ok := model.ConvertShopItemCondition[buyData.GoodsId]
- if ok {
- bRet := this.role.GetRoleBase().checkUnLockState(0, condition.Conditions)
- if bRet != serverproto.ErrorCode_ERROR_OK {
- continue
- }
- }
- /*
- shopInfo, ok := model.ConvertShopItemData[buyData.GoodsId]
- if !ok || shopInfo == nil {
- continue
- }
- */
- if goodsType != 0 && gType != goodsType {
- continue
- }
- //活动期间掉落道具判断
- if !this.checkHDShopItem(shopInfo) {
- continue
- }
- if shopInfo.LimitType == LIMIT_TYPE_DAY || shopInfo.LimitType == LIMIT_TYPE_WEEK {
- this.GetCurRoundBuyNum(buyData, shopInfo)
- }
- ackMsg.ShopData.BuyInfo = append(ackMsg.ShopData.BuyInfo, buyData)
- }
- //购买后更新购买信息(限购等)
- if goodsType == ShopType_CashShop {
- for _, shopData := range model.ConvertRedBagShopItemData {
- gType := this.GetGoodsType(shopData.ShopItem.GoodsId)
- if gType == 0 {
- continue
- }
- if goodsType != 0 && goodsType != gType {
- continue
- }
- condition, ok := model.ConvertShopItemCondition[shopData.ShopItem.GoodsId]
- if ok {
- bRet := this.role.GetRoleBase().checkUnLockState(0, condition.Conditions)
- if bRet != serverproto.ErrorCode_ERROR_OK {
- continue
- }
- }
- ackMsg.ShopData.ItemInfo = append(ackMsg.ShopData.ItemInfo, shopData.ShopItem)
- }
- } else {
- for _, shopData := range model.ConvertShopItemData {
- gType := this.GetGoodsType(shopData.GoodsId)
- if gType == 0 {
- continue
- }
- if goodsType != 0 && goodsType != gType {
- continue
- }
- //活动期间掉落道具判断
- if !this.checkHDShopItem(shopData) {
- continue
- }
- condition, ok := model.ConvertShopItemCondition[shopData.GoodsId]
- if ok {
- bRet := this.role.GetRoleBase().checkUnLockState(0, condition.Conditions)
- if bRet != serverproto.ErrorCode_ERROR_OK {
- continue
- }
- }
- ackMsg.ShopData.ItemInfo = append(ackMsg.ShopData.ItemInfo, shopData)
- }
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *RoleShop) CheckAndAddCostRes(shopType int32, resType int32, resCount uint32) uint32 {
- var retCount uint32 = 0
- bFind := false
- for _, data := range this.costRes {
- if data.ShopType == shopType && data.ResType == resType {
- data.ResCount += resCount
- bFind = true
- retCount = data.ResCount
- break
- }
- }
- if bFind == false {
- this.costRes = append(this.costRes, &serverproto.ShopCost{
- ShopType: shopType,
- ResType: resType,
- ResCount: resCount,
- })
- retCount = resCount
- }
- this.SetDirty(true)
- return retCount
- }
- func (this *RoleShop) OnBuyEnd(shopType int32, useResType int32, useResNum int32) {
- st := &SuperChargeUnlockST{}
- unlockType := serverproto.UnlockChargeType_UChargeType_None
- switch shopType {
- case ShopType_Normal:
- unlockType = serverproto.UnlockChargeType_UChargeType_ShopNormalRMBCost
- if useResType != int32(serverproto.ResType_Res_Rmb) {
- return
- }
- case ShopType_Arane:
- unlockType = serverproto.UnlockChargeType_UChargeType_ArenaShopCost
- if useResType != int32(serverproto.ResType_Res_Sprite) {
- return
- }
- case ShopType_Dark:
- unlockType = serverproto.UnlockChargeType_UChargeType_SpecialShopRMB
- if useResType != int32(serverproto.ResType_Res_Rmb) {
- return
- }
- case ShopType_Guild:
- unlockType = serverproto.UnlockChargeType_UChargeType_GuildShopCost
- if useResType != int32(serverproto.ResType_Res_Guild) {
- return
- }
- case ShopType_Pet:
- unlockType = serverproto.UnlockChargeType_UChargeType_PetShopCost
- if useResType != int32(serverproto.ResType_Res_PetCoin) {
- return
- }
- default:
- return
- }
- totalRes := this.CheckAndAddCostRes(shopType, useResType, uint32(useResNum))
- st.oldValue = int32(totalRes)
- this.role.GetRoleActivity().SuperChargeUnlockCheck(unlockType, st)
- }
- //活动期间掉落道具判断
- func (this *RoleShop) checkHDShopItem(shopItem *serverproto.ShopItem) bool {
- if shopItem.HdItemId <= 0 {
- return true
- }
- if CheckHDItemAdd(shopItem.HdItemId, this.role) {
- return true
- }
- return false
- }
- func (this *RoleShop) ExchangeRedBagTicket(ackMsg *serverproto.SCRedBagExchangeAck) serverproto.ErrorCode {
- if ackMsg == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- var costItemList = map[int32]int32{}
- costItemList[model.GlobalCashShopCostId] = model.GlobalCashShopCostCount
- if this.role.CheckResLitNum(costItemList) {
- this.role.DelItemList(costItemList, AddItemST{AddFrom: AddFrom_RedBagExchange})
- } else {
- return serverproto.ErrorCode_ERROR_SHOP_RESOURCE_NOT_NEOUGH
- }
- //给道具
- var addItemList = map[int32]int32{}
- for _, items := range model.GlobalCashShopReward {
- addItemList[items.Key] = items.Value
- }
- if ret := this.role.CanAddItemList(addItemList); ret != serverproto.ErrorCode_ERROR_OK {
- return serverproto.ErrorCode_ERROR_SHOP_CONFIG_ITEM_NO_FOUND
- }
- if len(addItemList) > 0 {
- this.role.AddItemList(addItemList, AddFrom_RedBagExchange, true)
- }
- //回包数据
- for _, items := range model.GlobalCashShopReward {
- ackMsg.Reward = append(ackMsg.Reward, items)
- }
- return serverproto.ErrorCode_ERROR_OK
- }
|