代码优化
This commit is contained in:
parent
c1a15c59c3
commit
a822e21524
|
@ -19,6 +19,8 @@ func (hw HandlerWrapper) Process(s *netlib.Session, packetid int, data interface
|
|||
return hw(s, packetid, data, sid)
|
||||
}
|
||||
|
||||
// RegisterHandler 消息注册
|
||||
// Deprecated: use [common.Register] instead
|
||||
func RegisterHandler(packetId int, h Handler) {
|
||||
if _, ok := handlers[packetId]; ok {
|
||||
panic(fmt.Sprintf("repeate register handler: %v Handler type=%v", packetId, reflect.TypeOf(h)))
|
||||
|
@ -36,7 +38,11 @@ func GetHandler(packetId int) Handler {
|
|||
}
|
||||
|
||||
func Register(mainId int, msgType interface{}, h func(s *netlib.Session, packetId int, data interface{}, sid int64) error) {
|
||||
RegisterHandler(mainId, HandlerWrapper(h))
|
||||
if _, ok := handlers[mainId]; ok {
|
||||
panic(fmt.Sprintf("repeate register handler: %v Handler type=%v", mainId, reflect.TypeOf(h)))
|
||||
}
|
||||
handlers[mainId] = HandlerWrapper(h)
|
||||
|
||||
f := func() interface{} {
|
||||
tp := reflect.TypeOf(msgType)
|
||||
if tp.Kind() == reflect.Ptr {
|
||||
|
|
|
@ -1424,3 +1424,50 @@ func (this *Player) GetWeekCardPrivilege(typeId int32) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// UpdatePigBankCoin 更新玩家存钱罐
|
||||
func (this *Player) UpdatePigBankCoin(gainTexCoin int64) {
|
||||
if this.IsRobot() {
|
||||
return
|
||||
}
|
||||
|
||||
if this.PlayerData.WelfData == nil || this.PlayerData.WelfData.PigBank == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fGetPropValue := func(propName string) int64 {
|
||||
pool := srvdata.PBDB_Pigbank_PropMgr.Datas.GetArr()
|
||||
for _, PropItem := range pool {
|
||||
if PropItem.PorpName == propName {
|
||||
return int64(PropItem.PropValue)
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
BankCoinMax := fGetPropValue("BankMaxCoin")
|
||||
|
||||
pack := &player.SCPigBankCoin{}
|
||||
|
||||
if gainTexCoin < 0 {
|
||||
LoseCoinRate := fGetPropValue("LoseCoinRate")
|
||||
pack.AddBankCoin = int64(math.Abs(math.Ceil(float64(gainTexCoin) * float64(LoseCoinRate) / 100.0)))
|
||||
}
|
||||
|
||||
if gainTexCoin > 0 {
|
||||
WinCoinRate := fGetPropValue("WinCoinRate")
|
||||
pack.AddBankCoin = int64(math.Ceil(float64(gainTexCoin) * float64(WinCoinRate) / 100.0))
|
||||
}
|
||||
|
||||
this.WelfData.PigBank.BankCoin += pack.AddBankCoin
|
||||
if this.WelfData.PigBank.BankCoin > BankCoinMax {
|
||||
this.WelfData.PigBank.BankCoin = BankCoinMax
|
||||
}
|
||||
|
||||
pack.BankCoinMax = BankCoinMax
|
||||
pack.BankCoin = this.WelfData.PigBank.BankCoin
|
||||
|
||||
logger.Logger.Trace("(this *TienLenPlayerData) UpdatePigbankCoin player SnId:", this.SnId, ";pack: ", pack, ";gainTexCoin: ", gainTexCoin)
|
||||
|
||||
this.SendToClient(int(player.PlayerPacketID_PACKET_SCPigBankCoin), pack)
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package tienlen
|
||||
|
||||
import (
|
||||
"math"
|
||||
"math/rand"
|
||||
"mongo.games.com/game/protocol/player"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -11,8 +9,6 @@ import (
|
|||
"mongo.games.com/game/gamesrv/base"
|
||||
"mongo.games.com/game/proto"
|
||||
"mongo.games.com/game/protocol/tienlen"
|
||||
"mongo.games.com/game/srvdata"
|
||||
"mongo.games.com/goserver/core/logger"
|
||||
)
|
||||
|
||||
// 玩家身上的额外数据
|
||||
|
@ -221,50 +217,3 @@ func (this *TienLenPlayerData) CanUseRecordItem() bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// 更新玩家存钱罐
|
||||
func (this *TienLenPlayerData) UpdatePigbankCoin(gainTexCoin int64) {
|
||||
if this.IsRobot() {
|
||||
return
|
||||
}
|
||||
|
||||
if this.PlayerData.WelfData == nil || this.PlayerData.WelfData.PigBank == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fGetPropValue := func(propName string) int64 {
|
||||
pool := srvdata.PBDB_Pigbank_PropMgr.Datas.GetArr()
|
||||
for _, PropItem := range pool {
|
||||
if PropItem.PorpName == propName {
|
||||
return int64(PropItem.PropValue)
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
BankCoinMax := fGetPropValue("BankMaxCoin")
|
||||
|
||||
pack := &player.SCPigBankCoin{}
|
||||
|
||||
if gainTexCoin < 0 {
|
||||
LoseCoinRate := fGetPropValue("LoseCoinRate")
|
||||
pack.AddBankCoin = int64(math.Abs(math.Ceil(float64(gainTexCoin) * float64(LoseCoinRate) / 100.0)))
|
||||
}
|
||||
|
||||
if gainTexCoin > 0 {
|
||||
WinCoinRate := fGetPropValue("WinCoinRate")
|
||||
pack.AddBankCoin = int64(math.Ceil(float64(gainTexCoin) * float64(WinCoinRate) / 100.0))
|
||||
}
|
||||
|
||||
this.WelfData.PigBank.BankCoin += pack.AddBankCoin
|
||||
if this.WelfData.PigBank.BankCoin > BankCoinMax {
|
||||
this.WelfData.PigBank.BankCoin = BankCoinMax
|
||||
}
|
||||
|
||||
pack.BankCoinMax = BankCoinMax
|
||||
pack.BankCoin = this.WelfData.PigBank.BankCoin
|
||||
|
||||
logger.Logger.Trace("-------(this *TienLenPlayerData) UpdatePigbankCoin player SnId:", this.SnId, ";pack: ", pack, ";gainTexCoin: ", gainTexCoin)
|
||||
|
||||
this.SendToClient(int(player.PlayerPacketID_PACKET_SCPigBankCoin), pack)
|
||||
}
|
||||
|
|
|
@ -2581,9 +2581,9 @@ func (this *SceneBilledStateTienLen) OnEnter(s *base.Scene) {
|
|||
}
|
||||
|
||||
// 刷新存钱罐
|
||||
playerEx, _ := s.GetPlayer(o_player.UserId).GetExtraData().(*TienLenPlayerData)
|
||||
playerEx := s.GetPlayer(o_player.UserId)
|
||||
if playerEx != nil && (!(s.IsFreePublic() || s.IsMatchScene())) {
|
||||
playerEx.UpdatePigbankCoin(o_player.GainCoin)
|
||||
playerEx.UpdatePigBankCoin(o_player.GainCoin)
|
||||
}
|
||||
|
||||
validFlow := totalin + totalout
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"mongo.games.com/game/protocol/shop"
|
||||
"mongo.games.com/game/protocol/webapi"
|
||||
)
|
||||
|
@ -60,6 +62,27 @@ type ShopInfo struct {
|
|||
AmountFinal int64 // 实际获得数量
|
||||
}
|
||||
|
||||
func (this *ShopInfo) GetName() string {
|
||||
return this.Name + "|" + strconv.Itoa(int(this.Id))
|
||||
}
|
||||
|
||||
func (this *ShopInfo) GetItems() []ItemInfo {
|
||||
var ret []ItemInfo
|
||||
if this.ItemId > 0 {
|
||||
ret = append(ret, ItemInfo{
|
||||
ItemId: this.ItemId,
|
||||
ItemNum: this.Amount,
|
||||
})
|
||||
}
|
||||
for _, v := range this.AddItemInfo {
|
||||
ret = append(ret, ItemInfo{
|
||||
ItemId: v.ItemId,
|
||||
ItemNum: v.ItemNum,
|
||||
})
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
type AllConfig struct {
|
||||
// 平台配置
|
||||
Platform *webapi.Platform
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"mongo.games.com/goserver/core/basic"
|
||||
|
@ -139,24 +138,22 @@ func (this *CSVCPayShopHandler) Process(s *netlib.Session, packetid int, data in
|
|||
logger.Logger.Warn("CSVCPayShopHandler p == nil")
|
||||
return nil
|
||||
}
|
||||
|
||||
platform := p.GetPlatform()
|
||||
if platform == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
shopInfo := ShopMgrSington.GetShopInfo(msg.ShopId, p)
|
||||
if shopInfo == nil {
|
||||
return nil
|
||||
}
|
||||
var lastLookTime int64
|
||||
|
||||
// 看广告不走这里
|
||||
if shopInfo.Ad > 0 {
|
||||
lastLookTime = p.ShopLastLookTime[msg.ShopId]
|
||||
adLookedNum := p.ShopTotal[msg.ShopId].AdLookedNum
|
||||
coolingTime := int64(shopInfo.CoolingTime[adLookedNum])
|
||||
if coolingTime != 0 && time.Now().Unix()-lastLookTime < coolingTime {
|
||||
logger.Logger.Error("时间差:", time.Now().Unix()-lastLookTime, int64(shopInfo.CoolingTime[adLookedNum]))
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var pack = &shop.SCVCPayShop{}
|
||||
SendClient := func(ret shop.OpResultCode) {
|
||||
pack.RetCode = ret
|
||||
|
@ -167,9 +164,8 @@ func (this *CSVCPayShopHandler) Process(s *netlib.Session, packetid int, data in
|
|||
}
|
||||
pack.ShopInfo.VipShopId = msg.VipShopId
|
||||
}
|
||||
logger.Logger.Trace("SCVCPayShop:", pack)
|
||||
proto.SetDefaults(pack)
|
||||
p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_VCPAYSHOP), pack)
|
||||
logger.Logger.Trace("SCVCPayShop:", pack)
|
||||
}
|
||||
|
||||
if p.VIP < shopInfo.VipLevel {
|
||||
|
@ -178,34 +174,35 @@ func (this *CSVCPayShopHandler) Process(s *netlib.Session, packetid int, data in
|
|||
return nil
|
||||
}
|
||||
|
||||
if shopInfo.Page == ShopPageVip {
|
||||
// 购买检查
|
||||
switch shopInfo.Page {
|
||||
case ShopPageVip:
|
||||
if p.VipShopData[msg.VipShopId] == nil || p.VipShopData[msg.VipShopId].IsBuy {
|
||||
SendClient(shop.OpResultCode_OPRC_ExchangeLimit)
|
||||
logger.Logger.Tracef("玩家VIP商城购买 当前物品无法购买! snid = %v,p.VipShopData[shopInfo.Id] = %v", p.SnId, p.GetVipShopData(shopInfo.Id, msg.VipShopId))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if shopInfo.Page == ShopPageGift {
|
||||
|
||||
case ShopPageGift:
|
||||
if !p.CheckWeekCard(shopInfo.Id) {
|
||||
SendClient(shop.OpResultCode_OPRC_Error)
|
||||
return nil
|
||||
}
|
||||
default:
|
||||
}
|
||||
//不需要观看广告的
|
||||
var money int32 = rand.Int31n(shopInfo.CostArea[1]-shopInfo.CostArea[0]+1) + shopInfo.CostArea[0]
|
||||
if shopInfo.Page == ShopPageVip {
|
||||
money = p.VipShopData[msg.VipShopId].CostArea
|
||||
}
|
||||
|
||||
// 消耗检查
|
||||
costNum := ShopMgrSington.GetCostNum(p, shopInfo, msg.GetVipShopId())
|
||||
switch shopInfo.ConstType {
|
||||
case ShopConsumeCoin:
|
||||
//金币
|
||||
if int64(money) > p.Coin {
|
||||
if costNum > p.Coin {
|
||||
SendClient(shop.OpResultCode_OPRC_Error)
|
||||
return nil
|
||||
}
|
||||
case ShopConsumeDiamond:
|
||||
//钻石
|
||||
if int64(money) > p.Diamond {
|
||||
if costNum > p.Diamond {
|
||||
SendClient(shop.OpResultCode_OPRC_Error)
|
||||
return nil
|
||||
}
|
||||
|
@ -213,7 +210,7 @@ func (this *CSVCPayShopHandler) Process(s *netlib.Session, packetid int, data in
|
|||
SendClient(shop.OpResultCode_OPRC_Error)
|
||||
return nil
|
||||
case ShopConsumePhoneScore:
|
||||
if int64(money) > p.PhoneScore {
|
||||
if costNum > p.PhoneScore {
|
||||
SendClient(shop.OpResultCode_OPRC_Error)
|
||||
return nil
|
||||
}
|
||||
|
@ -221,10 +218,8 @@ func (this *CSVCPayShopHandler) Process(s *netlib.Session, packetid int, data in
|
|||
SendClient(shop.OpResultCode_OPRC_Error)
|
||||
return nil
|
||||
}
|
||||
op := ShopMgrSington.ReceiveVCPayShop(shopInfo, p, msg.VipShopId, msg.GetPosition())
|
||||
if shopInfo.Page == ShopPageGift {
|
||||
p.UpdateWeekCardData(shopInfo.Id)
|
||||
}
|
||||
|
||||
op := ShopMgrSington.GainShop(shopInfo, p, msg.VipShopId, msg.GetPosition())
|
||||
SendClient(op)
|
||||
}
|
||||
return nil
|
||||
|
@ -639,7 +634,7 @@ func init() {
|
|||
// 看广告领取商品,校验冷却时间和领取次数(免费)
|
||||
common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_ADLOOKED), &CSAdLookedHandler{})
|
||||
netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_ADLOOKED), &CSAdLookedPacketFactory{})
|
||||
// 看广告领取商品,校验冷却时间(非免费)
|
||||
// 购买商品不看广告
|
||||
common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_VCPAYSHOP), &CSVCPayShopHandler{})
|
||||
netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_VCPAYSHOP), &CSVCPayShopPacketFactory{})
|
||||
// 获取订单记录(非现金:金币,道具;现金的走透传后台获取)
|
||||
|
|
|
@ -248,7 +248,7 @@ func (this *PetMgr) GetShopAward(shopInfo *model.ShopInfo, p *Player) (award, ro
|
|||
}
|
||||
|
||||
//VIP商城没有人物加成
|
||||
if shopInfo.Page == ShopPageVip || shopInfo.Page == ShopPagePhoneScore || shopInfo.Page == ShopPagePhoneScore_google {
|
||||
if shopInfo.Page == ShopPageVip || shopInfo.Page == ShopPagePhoneScore || shopInfo.Page == ShopPagePhoneScoreGoogle {
|
||||
award = 0
|
||||
}
|
||||
return award, roleId
|
||||
|
|
|
@ -2227,8 +2227,6 @@ func (this *Player) OnDayTimer(login, continuous bool, t int) {
|
|||
this.VipMatchTimes = 0
|
||||
//VIP商城数据更新
|
||||
this.UpdateVipShopData()
|
||||
//周卡数据更新
|
||||
this.WeekCardAward = make(map[int32]bool)
|
||||
// 重置每日任务
|
||||
if this.WelfData != nil {
|
||||
if this.WelfData.Task != nil {
|
||||
|
@ -2239,6 +2237,8 @@ func (this *Player) OnDayTimer(login, continuous bool, t int) {
|
|||
this.WelfData.Task[common.TaskIDInviteFirstLogin] = &model.TaskData{}
|
||||
}
|
||||
}
|
||||
//周卡数据更新
|
||||
this.WeekCardAward = make(map[int32]bool)
|
||||
//周卡领取奖励
|
||||
now := time.Now().Unix()
|
||||
for id, endTime := range this.WeekCardTime {
|
||||
|
|
|
@ -2,11 +2,9 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"slices"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"mongo.games.com/goserver/core/basic"
|
||||
|
@ -35,23 +33,23 @@ const (
|
|||
|
||||
// 消费类型
|
||||
const (
|
||||
ShopConsumeCoin = iota + 1 // 金币
|
||||
ShopConsumeDiamond // 钻石
|
||||
ShopConsumeMoney // 现金
|
||||
ExchangeConsumeCash //兑换消耗现金
|
||||
ShopConsumePhoneScore = 11 //手机积分
|
||||
ShopConsumeCoin = 1 // 金币
|
||||
ShopConsumeDiamond = 2 // 钻石
|
||||
ShopConsumeMoney = 3 // 现金
|
||||
ExchangeConsumeCash = 4 // 兑换消耗现金
|
||||
ShopConsumePhoneScore = 11 // 手机积分
|
||||
)
|
||||
|
||||
// page类型
|
||||
const (
|
||||
ShopPageCoin = iota + 1 //金币页面
|
||||
ShopPageDiamond //钻石页面
|
||||
ShopPageItem //道具页面
|
||||
ShopPageVip //VIP页面
|
||||
ShopPagePrivilege //VIP特权礼包
|
||||
ShopPagePhoneScore = 61 //手机积分商城
|
||||
ShopPagePhoneScore_google = 62
|
||||
ShopPageGift = 7 //礼包页面
|
||||
ShopPageCoin = 1 //金币页面
|
||||
ShopPageDiamond = 2 //钻石页面
|
||||
ShopPageItem = 3 //道具页面
|
||||
ShopPageVip = 4 //VIP页面
|
||||
ShopPagePrivilege = 5 //VIP特权礼包
|
||||
ShopPagePhoneScore = 61 //手机积分商城
|
||||
ShopPagePhoneScoreGoogle = 62
|
||||
ShopPageGift = 7 //礼包页面
|
||||
)
|
||||
|
||||
// 商品类型
|
||||
|
@ -497,113 +495,64 @@ func (this *ShopMgr) LookAdReceive(shopId int32, p *Player, position int32) shop
|
|||
shopTotal := p.ShopTotal[shopId]
|
||||
if shopTotal.AdReceiveNum < shopInfo.RepeatTimes {
|
||||
shopTotal.AdReceiveNum++
|
||||
return this.ReceiveVCPayShop(shopInfo, p, 0, position)
|
||||
return this.GainShop(shopInfo, p, 0, position)
|
||||
}
|
||||
}
|
||||
return shop.OpResultCode_OPRC_Error
|
||||
}
|
||||
|
||||
// ReceiveVCPayShop 领取VC看广告商品
|
||||
func (this *ShopMgr) ReceiveVCPayShop(shopInfo *model.ShopInfo, p *Player, vipShopId, position int32) shop.OpResultCode {
|
||||
if shopInfo == nil {
|
||||
logger.Logger.Errorf("this shop == nil")
|
||||
return shop.OpResultCode_OPRC_Error
|
||||
// GetCostNum 消耗数量
|
||||
func (this *ShopMgr) GetCostNum(p *Player, shop *model.ShopInfo, vipShopId int32) int64 {
|
||||
if shop == nil {
|
||||
return 0
|
||||
}
|
||||
//产生订单
|
||||
this.PayAway(shopInfo, p, vipShopId, position)
|
||||
return shop.OpResultCode_OPRC_Sucess
|
||||
costNum := rand.Int63n(int64(shop.CostArea[1]-shop.CostArea[0]+1)) + int64(shop.CostArea[0])
|
||||
if shop.Page == ShopPageVip {
|
||||
shopData := p.GetVipShopData(shop.Id, vipShopId)
|
||||
if shopData != nil {
|
||||
costNum = int64(shopData.CostArea)
|
||||
}
|
||||
}
|
||||
return costNum
|
||||
}
|
||||
|
||||
// PayAway 商城 领取商品
|
||||
func (this *ShopMgr) PayAway(shopInfo *model.ShopInfo, p *Player, vipShopId, position int32) {
|
||||
shopName := shopInfo.Name + "|" + strconv.Itoa(int(shopInfo.Id))
|
||||
costNum := rand.Int31n(shopInfo.CostArea[1]-shopInfo.CostArea[0]+1) + shopInfo.CostArea[0]
|
||||
if shopInfo.Page == ShopPageVip {
|
||||
shopData := p.GetVipShopData(shopInfo.Id, vipShopId)
|
||||
if shopData != nil {
|
||||
costNum = shopData.CostArea
|
||||
}
|
||||
}
|
||||
if shopInfo.Ad <= 0 { //消耗
|
||||
logger.Logger.Tracef("AddOrder Consume[%v],shopName[%v]", shopInfo.ConstType, shopName, costNum)
|
||||
switch shopInfo.ConstType {
|
||||
case ShopConsumeCoin:
|
||||
p.AddCoin(int64(-costNum), 0, common.GainWay_Shop_Buy, "sys", shopName)
|
||||
case ShopConsumeDiamond:
|
||||
p.AddDiamond(int64(-costNum), 0, common.GainWay_Shop_Buy, "sys", shopName)
|
||||
case ShopConsumePhoneScore:
|
||||
p.AddPhoneScore(int64(-costNum), 0, common.GainWay_Shop_Buy, "sys", shopName)
|
||||
case ShopConsumeMoney:
|
||||
//task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||
// return webapi.API_CreateOrder(common.GetAppId(),"", p.SnId, shopInfo.Id, p.Platform, p.PackageID, p.DeviceOS,
|
||||
// p.DeviceId, shopInfo.Name, shopInfo.Amount, shopInfo.ConsumptionAmount)
|
||||
//}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||||
// if data != nil {
|
||||
// //失败
|
||||
// }
|
||||
//}), "API_CreateOrder").Start()
|
||||
//p.AddMoneyPayTotal(int64(shopInfo.ConsumptionAmount))
|
||||
return
|
||||
}
|
||||
} else {
|
||||
TaskSubjectSingleton.Touch(common.TaskTypeAdv, &TaskData{
|
||||
SnId: p.SnId,
|
||||
Num: 1,
|
||||
Position: position,
|
||||
})
|
||||
}
|
||||
amount := [3]int32{} // 获得
|
||||
if shopInfo.Page == ShopPageVip {
|
||||
if p.VipShopData[vipShopId] == nil {
|
||||
return
|
||||
}
|
||||
p.VipShopData[vipShopId].IsBuy = true
|
||||
logger.Logger.Trace("玩家购买VIP商城物品成功,商品Id = ", shopInfo.Id)
|
||||
}
|
||||
// shopAddItem 商城购买增加道具
|
||||
func (this *ShopMgr) shopAddItem(p *Player, shopInfo *model.ShopInfo, vipShopId int32) {
|
||||
name := shopInfo.GetName()
|
||||
|
||||
addTotal := this.GetAmountFinal(p, shopInfo.Id, vipShopId)
|
||||
logger.Logger.Trace("addTotal ", addTotal, shopInfo.Amount)
|
||||
switch shopInfo.Type {
|
||||
case ShopTypeCoin:
|
||||
amount[shopInfo.Type-1] = int32(addTotal)
|
||||
p.AddCoin(addTotal, 0, common.GainWay_Shop_Buy, "system", shopName)
|
||||
if shopInfo.Ad > 0 { //观看广告
|
||||
if !p.IsRob {
|
||||
LogChannelSingleton.WriteMQData(model.GenerateSystemFreeGive(p.SnId, p.Name, p.Platform, p.Channel, model.SystemFreeGive_GiveType_ShopAd, model.SystemFreeGive_CoinType_Coin, addTotal))
|
||||
}
|
||||
}
|
||||
// 记录钻石兑换金币的金币数量,个人水池调控使用
|
||||
if shopInfo.ConstType == ShopConsumeDiamond && shopInfo.Ad <= 0 && costNum > 0 {
|
||||
p.AddDiamondToCoin(addTotal)
|
||||
}
|
||||
if shopInfo.Ad <= 0 && costNum != 0 {
|
||||
TaskSubjectSingleton.Touch(common.TaskTypeBuyCoin, &TaskData{SnId: p.SnId, Num: 1, Position: position})
|
||||
}
|
||||
|
||||
case ShopTypeDiamond:
|
||||
//增加钻石
|
||||
amount[shopInfo.Type-1] = int32(addTotal)
|
||||
p.AddDiamond(addTotal, 0, common.GainWay_Shop_Buy, "system", shopName)
|
||||
if shopInfo.Ad > 0 { //观看广告
|
||||
if !p.IsRob {
|
||||
LogChannelSingleton.WriteMQData(model.GenerateSystemFreeGive(p.SnId, p.Name, p.Platform, p.Channel, model.SystemFreeGive_GiveType_ShopAd, model.SystemFreeGive_CoinType_Diamond, addTotal))
|
||||
}
|
||||
}
|
||||
case ShopTypeItem:
|
||||
//增加道具
|
||||
item := &Item{ItemId: shopInfo.ItemId, ItemNum: addTotal, ObtainTime: time.Now().Unix()}
|
||||
BagMgrSingleton.AddJybBagInfo(p, []*Item{item}, 0, common.GainWay_Shop_Buy, "system", shopName)
|
||||
for _, info := range shopInfo.GetItems() {
|
||||
item := &Item{ItemId: info.ItemId, ItemNum: info.ItemNum, ObtainTime: time.Now().Unix()}
|
||||
BagMgrSingleton.AddJybBagInfo(p, []*Item{item}, 0, common.GainWay_Shop_Buy, "system", name)
|
||||
data := srvdata.PBDB_GameItemMgr.GetData(item.ItemId)
|
||||
if data != nil {
|
||||
BagMgrSingleton.RecordItemLog(p.Platform, p.SnId, ItemObtain, shopInfo.ItemId, data.Name, addTotal, "商城购买")
|
||||
BagMgrSingleton.RecordItemLog(p.Platform, p.SnId, ItemObtain, info.ItemId, data.Name, info.ItemNum, "商城购买")
|
||||
}
|
||||
PetMgrSington.CheckShowRed(p)
|
||||
}
|
||||
this.ShopAddItem(shopInfo, p)
|
||||
|
||||
this.CreateVCOrder(shopInfo, p.SnId, costNum, p.Platform, amount)
|
||||
// 获得道具,检查是否显示红点
|
||||
PetMgrSington.CheckShowRed(p)
|
||||
}
|
||||
|
||||
//抽奖兑换统计
|
||||
// createOrder 保存购买记录
|
||||
func (this *ShopMgr) createOrder(p *Player, shopInfo *model.ShopInfo, costNum int64, amount [3]int32) {
|
||||
if shopInfo.Type < ShopTypeCoin && shopInfo.Type > ShopTypeItem {
|
||||
logger.Logger.Errorf("createOrder err: type = %v", shopInfo.Type)
|
||||
return
|
||||
}
|
||||
|
||||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||
dbShop := model.NewDbShop(p.Platform, shopInfo.Page, amount[:], "sys", 0, shopInfo.ConstType, int32(costNum),
|
||||
common.GainWay_ShopBuy, shopInfo.GetItems(), shopInfo.Id, shopInfo.Name, p.SnId, 1, "shop_goods", []int32{})
|
||||
return model.InsertDbShopLog(dbShop)
|
||||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||||
if data != nil {
|
||||
logger.Logger.Errorf("createOrder err: %v", data)
|
||||
}
|
||||
}), "createOrder").Start()
|
||||
}
|
||||
|
||||
// createPhoneScore 保存手机积分抽奖兑换统计
|
||||
func (this *ShopMgr) createPhoneScore(p *Player, shopInfo *model.ShopInfo, costNum, gainNum int64) {
|
||||
if shopInfo.ConstType == ShopConsumePhoneScore {
|
||||
items := make([]*Item, 0)
|
||||
itemId := int32(0)
|
||||
|
@ -616,8 +565,8 @@ func (this *ShopMgr) PayAway(shopInfo *model.ShopInfo, p *Player, vipShopId, pos
|
|||
itemId = shopInfo.ItemId
|
||||
}
|
||||
items = append(items, &Item{
|
||||
ItemId: itemId, // 物品id
|
||||
ItemNum: addTotal, // 数量
|
||||
ItemId: itemId, // 物品id
|
||||
ItemNum: gainNum, // 数量
|
||||
})
|
||||
jsonData, err := json.Marshal(items)
|
||||
if err == nil {
|
||||
|
@ -678,48 +627,96 @@ func (this *ShopMgr) GetAmountFinal(p *Player, shopId, vipShopId int32) int64 {
|
|||
addTotal *= 2
|
||||
}
|
||||
}
|
||||
default:
|
||||
}
|
||||
return addTotal
|
||||
}
|
||||
|
||||
// 商城购买 额外增加道具
|
||||
func (this *ShopMgr) ShopAddItem(shopInfo *model.ShopInfo, p *Player) {
|
||||
for _, info := range shopInfo.AddItemInfo {
|
||||
item := &Item{ItemId: info.ItemId, ItemNum: info.ItemNum, ObtainTime: time.Now().Unix()}
|
||||
BagMgrSingleton.AddJybBagInfo(p, []*Item{item}, 0, common.GainWay_Shop_Buy, "system", shopInfo.Name)
|
||||
data := srvdata.PBDB_GameItemMgr.GetData(item.ItemId)
|
||||
if data != nil {
|
||||
BagMgrSingleton.RecordItemLog(p.Platform, p.SnId, ItemObtain, info.ItemId, data.Name, info.ItemNum, "商城购买")
|
||||
}
|
||||
PetMgrSington.CheckShowRed(p)
|
||||
// GainShop 获得商品,非现金
|
||||
func (this *ShopMgr) GainShop(shopInfo *model.ShopInfo, p *Player, vipShopId, position int32) shop.OpResultCode {
|
||||
if shopInfo == nil || p == nil {
|
||||
logger.Logger.Error("GainShop err")
|
||||
return shop.OpResultCode_OPRC_Error
|
||||
}
|
||||
}
|
||||
|
||||
// CreateVCOrder 产生VC订单,记录看广告获取商品的订单
|
||||
func (this *ShopMgr) CreateVCOrder(shopInfo *model.ShopInfo, snid, costNum int32, platform string, amount [3]int32) {
|
||||
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||
//获得类型
|
||||
if shopInfo.Type < ShopTypeCoin && shopInfo.Type > ShopTypeItem {
|
||||
return errors.New("error type")
|
||||
shopName := shopInfo.GetName()
|
||||
costNum := this.GetCostNum(p, shopInfo, vipShopId)
|
||||
if shopInfo.Ad <= 0 { //消耗
|
||||
logger.Logger.Tracef("GainShop ConstType[%v],shopName[%v],costNum[%v]", shopInfo.ConstType, shopName, costNum)
|
||||
switch shopInfo.ConstType {
|
||||
case ShopConsumeCoin:
|
||||
p.AddCoin(-costNum, 0, common.GainWay_Shop_Buy, "sys", shopName)
|
||||
case ShopConsumeDiamond:
|
||||
p.AddDiamond(-costNum, 0, common.GainWay_Shop_Buy, "sys", shopName)
|
||||
case ShopConsumePhoneScore:
|
||||
p.AddPhoneScore(-costNum, 0, common.GainWay_Shop_Buy, "sys", shopName)
|
||||
default:
|
||||
logger.Logger.Errorf("GainShop ConstType[%v] err", shopInfo.ConstType)
|
||||
return shop.OpResultCode_OPRC_Error
|
||||
}
|
||||
//道具
|
||||
var item []model.ItemInfo
|
||||
if shopInfo.Type == ShopTypeItem {
|
||||
item = append(item, model.ItemInfo{ItemId: shopInfo.ItemId, ItemNum: shopInfo.Amount})
|
||||
if shopInfo.AddItemInfo != nil {
|
||||
for _, info := range shopInfo.AddItemInfo {
|
||||
item = append(item, model.ItemInfo{ItemId: info.ItemId, ItemNum: int64(info.ItemNum)})
|
||||
}
|
||||
} else {
|
||||
logger.Logger.Tracef("GainShop free ConstType[%v],shopName[%v],costNum[%v]", shopInfo.ConstType, shopName, costNum)
|
||||
TaskSubjectSingleton.Touch(common.TaskTypeAdv, &TaskData{
|
||||
SnId: p.SnId,
|
||||
Num: 1,
|
||||
Position: position,
|
||||
})
|
||||
}
|
||||
|
||||
amount := [3]int32{} // 获得含义:金币,钻石,经验
|
||||
if shopInfo.Page == ShopPageVip {
|
||||
if p.VipShopData[vipShopId] == nil {
|
||||
logger.Logger.Errorf("GainShop 没有找到vip商品 shopId:%v vipShopId:%v snid:%v", shopInfo.Id, vipShopId, p.SnId)
|
||||
return shop.OpResultCode_OPRC_Error
|
||||
}
|
||||
p.VipShopData[vipShopId].IsBuy = true
|
||||
logger.Logger.Trace("GainShop 玩家购买VIP商城物品成功,商品Id = ", shopInfo.Id)
|
||||
}
|
||||
|
||||
addTotal := this.GetAmountFinal(p, shopInfo.Id, vipShopId)
|
||||
logger.Logger.Tracef("商品Id:%v 最终获得:%v", shopInfo.Id, addTotal)
|
||||
|
||||
switch shopInfo.Type {
|
||||
case ShopTypeCoin:
|
||||
amount[0] = int32(addTotal)
|
||||
p.AddCoin(addTotal, 0, common.GainWay_Shop_Buy, "system", shopName)
|
||||
if shopInfo.Ad > 0 { //观看广告
|
||||
if !p.IsRob {
|
||||
LogChannelSingleton.WriteMQData(model.GenerateSystemFreeGive(p.SnId, p.Name, p.Platform, p.Channel, model.SystemFreeGive_GiveType_ShopAd, model.SystemFreeGive_CoinType_Coin, addTotal))
|
||||
}
|
||||
}
|
||||
dbShop := model.NewDbShop(platform, shopInfo.Page, amount[:], "sys", 0, shopInfo.ConstType, costNum,
|
||||
common.GainWay_ShopBuy, item, shopInfo.Id, shopInfo.Name, snid, 1, "shop_goods", []int32{})
|
||||
return model.InsertDbShopLog(dbShop)
|
||||
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
||||
if data != nil {
|
||||
logger.Logger.Errorf("err:", data.(error))
|
||||
// 记录钻石兑换金币的金币数量,个人水池调控使用
|
||||
if shopInfo.ConstType == ShopConsumeDiamond && shopInfo.Ad <= 0 && costNum > 0 {
|
||||
p.AddDiamondToCoin(addTotal)
|
||||
}
|
||||
}), "CreateVCOrder").Start()
|
||||
if shopInfo.Ad <= 0 && costNum != 0 {
|
||||
TaskSubjectSingleton.Touch(common.TaskTypeBuyCoin, &TaskData{SnId: p.SnId, Num: 1, Position: position})
|
||||
}
|
||||
|
||||
case ShopTypeDiamond:
|
||||
//增加钻石
|
||||
amount[1] = int32(addTotal)
|
||||
p.AddDiamond(addTotal, 0, common.GainWay_Shop_Buy, "system", shopName)
|
||||
if shopInfo.Ad > 0 { //观看广告
|
||||
if !p.IsRob {
|
||||
LogChannelSingleton.WriteMQData(model.GenerateSystemFreeGive(p.SnId, p.Name, p.Platform, p.Channel, model.SystemFreeGive_GiveType_ShopAd, model.SystemFreeGive_CoinType_Diamond, addTotal))
|
||||
}
|
||||
}
|
||||
default:
|
||||
}
|
||||
// 获得道具
|
||||
this.shopAddItem(p, shopInfo, vipShopId)
|
||||
// 获得周卡
|
||||
if shopInfo.Page == ShopPageGift {
|
||||
p.UpdateWeekCardData(shopInfo.Id)
|
||||
}
|
||||
|
||||
// 保存购买记录
|
||||
this.createOrder(p, shopInfo, costNum, amount)
|
||||
// 保存手机积分抽奖兑换统计
|
||||
this.createPhoneScore(p, shopInfo, costNum, addTotal)
|
||||
|
||||
return shop.OpResultCode_OPRC_Sucess
|
||||
}
|
||||
|
||||
func (this *ShopMgr) GetExchangeData(platform string, id int32) *ExchangeShopInfo {
|
||||
|
|
Loading…
Reference in New Issue