diff --git a/model/baginfo.go b/model/baginfo.go index cc16aff..ecbafae 100644 --- a/model/baginfo.go +++ b/model/baginfo.go @@ -87,16 +87,16 @@ func SaveToDelBackupBagItem(args *BagInfo) error { } type AddItemParam struct { - P *PlayerData - Change []*Item // 道具变化数量 - Cost []*Item // 获得道具时消耗的道具数量 - Add int64 // 加成数量 - GainWay int32 // 记录类型 - Operator, Remark string // 操作人,备注 - GameId, GameFreeId int64 // 游戏id,场次id - NoLog bool // 是否不记录日志 - LogId string // 撤销的id,道具兑换失败 - RoomConfigId int32 // 房间配置id + P *PlayerData // 玩家信息,玩家离线时不传 + Change []*Item // 道具变化数量 + Cost []*Item // 获得道具时消耗的道具数量 + Add int64 // 加成数量 + GainWay int32 // 记录类型 + Operator, Remark string // 操作人,备注 + GameId, GameFreeId int64 // 游戏id,场次id + NoLog bool // 是否不记录日志 + LogId string // 撤销的id,道具兑换失败 + RoomConfigId int32 // 房间配置id } type ChangeItemParam struct { diff --git a/worldsrv/action_player.go b/worldsrv/action_player.go index c64484d..c4506a2 100644 --- a/worldsrv/action_player.go +++ b/worldsrv/action_player.go @@ -1722,6 +1722,7 @@ func (this *CSPlayerVIPInfoHandler) Process(s *netlib.Session, packetid int, dat logger.Logger.Warn("CSPlayerVIPInfoHandler p == nil") return nil } + p.GetVIPLevel() p.SCVIPInfo() } return nil diff --git a/worldsrv/bagmgr.go b/worldsrv/bagmgr.go index 05f56a8..6ba0902 100644 --- a/worldsrv/bagmgr.go +++ b/worldsrv/bagmgr.go @@ -394,12 +394,12 @@ func (this *BagMgr) AddItems(param *model.AddItemParam) (*BagInfo, bag.OpResultC } case common.ItemTypeFishPower: //增加炮台 - p.ItemUnPlayerPowerListEx(v.ItemId) + //p.ItemUnPlayerPowerListEx(v.ItemId) case common.ItemTypeMoneyPond: //增加个人金币池 - if v.ItemId == common.ItemIDMoneyPond { - p.MoneyPond += v.ItemNum - } + //if v.ItemId == common.ItemIDMoneyPond { + // p.MoneyPond += v.ItemNum + //} case common.ItemTypeVipExp: //增加玩家VIP经验 if v.ItemId == common.ItemIDVipExp { diff --git a/worldsrv/player.go b/worldsrv/player.go index ace497e..1aba70e 100644 --- a/worldsrv/player.go +++ b/worldsrv/player.go @@ -310,13 +310,7 @@ func (this *Player) OnLogined() { this.SetOnline() //测试用 - if !this.IsRob { - old := this.VIP - this.VIP = this.GetVIPLevel() - if old != this.VIP { - this.dirty = true - } - } else { + if this.IsRob { this.VIP = rand.Int31n(6) + 1 //机器人随机vip和头像 this.RobRandVip() @@ -1720,55 +1714,46 @@ func (this *Player) AddDiamond(num, add int64, gainWay int32, oper, remark strin return } logger.Logger.Tracef("snid(%v) AddDiamond(%v)", this.SnId, num) - //async := false - //if num > 0 && this.scene != nil && !this.scene.IsTestScene() && this.scene.sceneMode != common.SceneMode_Thr { //游戏场中加币,需要同步到gamesrv上 - // if StartAsyncAddCoinTransact(this, num, gainWay, oper, remark, true, 0, true) { - // async = true - // } - //} - - if num != 0 /*&& !async*/ { - this.dirty = true - if num > 0 { - this.Diamond += num + this.dirty = true + if num > 0 { + this.Diamond += num + } else { + if -num > this.Diamond { + logger.Logger.Errorf("Player.AddCoin exception!!! num(%v) oper(%v)", num, oper) + num = -this.Diamond + this.Diamond = 0 } else { - if -num > this.Diamond { - logger.Logger.Errorf("Player.AddCoin exception!!! num(%v) oper(%v)", num, oper) - num = -this.Diamond - this.Diamond = 0 - } else { - this.Diamond += num - } - switch gainWay { - case common.GainWay_MatchSignup: // 排除的 - default: - TaskSubjectSingleton.Touch(common.TaskTypeCostDiamond, &TaskData{ - SnId: this.SnId, - Num: -num, - }) - } + this.Diamond += num } - - this.SendDiffData() - if !this.IsRob { - log := model.NewCoinLogEx(&model.CoinLogParam{ - Platform: this.Platform, - SnID: this.SnId, - Channel: this.Channel, - ChangeType: common.BillTypeDiamond, - ChangeNum: num, - RemainNum: this.Diamond, - Add: add, - LogType: gainWay, - GameID: 0, - GameFreeID: 0, - BaseCoin: 0, - Operator: oper, - Remark: remark, + switch gainWay { + case common.GainWay_MatchSignup: // 排除的 + default: + TaskSubjectSingleton.Touch(common.TaskTypeCostDiamond, &TaskData{ + SnId: this.SnId, + Num: -num, }) - if log != nil { - LogChannelSingleton.WriteLog(log) - } + } + } + + this.SendDiffData() + if !this.IsRob { + log := model.NewCoinLogEx(&model.CoinLogParam{ + Platform: this.Platform, + SnID: this.SnId, + Channel: this.Channel, + ChangeType: common.BillTypeDiamond, + ChangeNum: num, + RemainNum: this.Diamond, + Add: add, + LogType: gainWay, + GameID: 0, + GameFreeID: 0, + BaseCoin: 0, + Operator: oper, + Remark: remark, + }) + if log != nil { + LogChannelSingleton.WriteLog(log) } } } @@ -2265,23 +2250,14 @@ func (this *Player) BackDiffData() { this.diffData.SafeBoxCoin = this.SafeBoxCoin } -func (this *Player) UpdateVip() { - if this.IsRob { - return - } - this.VIP = this.GetVIPLevel() - //clubManager.UpdateVip(this) -} - func (this *Player) AddMoneyPayTotal(amount int64) { if amount > 0 { this.MoneyPayTotal += amount - this.SendDiffData() //更新vip + this.GetVIPLevel() } } func (this *Player) SendDiffData() { - this.UpdateVip() var dirty bool pack := &playerproto.SCPlayerDataUpdate{} pack.UpdateField = 0 @@ -2767,7 +2743,6 @@ func (this *Player) GetPromoterKey() (string, error) { //} func (this *Player) SendPlayerInfo() { - this.UpdateVip() scPlayerData := &playerproto.SCPlayerData{ OpRetCode: playerproto.OpResultCode_OPRC_Sucess, Data: &playerproto.PlayerData{ @@ -2878,6 +2853,8 @@ func (this *Player) SendPlayerInfo() { this.SendGameConfig(int32(this.scene.gameId), this.Platform, this.Channel) } //this.SendJackpotInfo() + // 更新vip + this.GetVIPLevel() // 后台道具配置 this.SCItems() // 引导配置 @@ -3606,8 +3583,6 @@ func (this *Player) SCVIPInfo() { pack.TolVipExp, pack.Money = this.GetCurrentVIPExp(vips) pack.Vip = this.VIP pack.OpRetCode = playerproto.OpResultCode_OPRC_Sucess - //WelfareMgrSington.MonitorWelfData(this) - //pack.VipId = append(pack.VipId, this.WelfData.VIPGift...) } this.SendToClient(int(playerproto.PlayerPacketID_PACKET_SC_VIPINFO), pack) logger.Logger.Tracef("send vipinfo to client:%v", pack) @@ -3732,6 +3707,8 @@ func (this *Player) VIPDraw(id, vip int32) { send() } +// GetCurrentVIPExp 更新vip等级 +// 返回当前经验和升级需要经验 func (this *Player) GetCurrentVIPExp(vipcfg ...*webapiproto.VIPcfgDataList) (exp int64, money int64) { var vips *webapiproto.VIPcfgDataList if len(vipcfg) == 0 { @@ -3767,6 +3744,7 @@ func (this *Player) GetCurrentVIPExp(vipcfg ...*webapiproto.VIPcfgDataList) (exp return // 默认 } +// GetVIPLevel 更新vip等级,返回vip等级 func (this *Player) GetVIPLevel() int32 { if this.IsRob { return 0 @@ -3786,6 +3764,7 @@ func (this *Player) GetVIPLevel() int32 { } var b bool if vip != this.VIP { + this.dirty = true b = true //玩家VIP升级 this.SCVIPInfo() @@ -4344,7 +4323,7 @@ func (this *Player) addLotteryCount(count int32) { } -// 增加手机积分 +// AddPhoneScore 增加手机积分 func (this *Player) AddPhoneScore(num, add int64, gainWay int32, oper, remark string) { if num == 0 { return @@ -4353,22 +4332,20 @@ func (this *Player) AddPhoneScore(num, add int64, gainWay int32, oper, remark st return } logger.Logger.Tracef("snid(%v) AddPhoneScore(%v)", this.SnId, num) - if num != 0 /*&& !async*/ { - this.dirty = true - if num > 0 { - this.PhoneScore += num - } else { - if -num > this.PhoneScore { - logger.Logger.Errorf("Player.AddPhoneScore exception!!! num(%v) oper(%v)", num, oper) - num = -this.PhoneScore - this.PhoneScore = 0 - } else { - this.PhoneScore += num - } - } - this.SendDiffData() + this.dirty = true + if num > 0 { + this.PhoneScore += num + } else { + if -num > this.PhoneScore { + logger.Logger.Errorf("Player.AddPhoneScore exception!!! num(%v) oper(%v)", num, oper) + num = -this.PhoneScore + this.PhoneScore = 0 + } else { + this.PhoneScore += num + } } + this.SendDiffData() } // 抽奖任务 @@ -4644,43 +4621,34 @@ func (this *Player) GetWeekCardPrivilege(typeId int32) bool { // 增加记牌器道具时限 func (this *Player) AddItemRecExpireTime(itemId int32, num, add int64, gainWay int32, oper, remark string) { - if num == 0 { + if num <= 0 { + return + } + logger.Logger.Tracef("snid(%v) AddItemRecExpireTime, itemId:(%v), num:(%v)", this.SnId, itemId, num) + + this.dirty = true + itemData := srvdata.GameItemMgr.Get(this.Platform, itemId) + if itemData == nil { return } - logger.Logger.Tracef("snid(%v) AddItemRecExpireTime, itemId:(%v), num:(%v)", this.SnId, itemId, num) - - if num != 0 /*&& !async*/ { - this.dirty = true - if num > 0 { - itemData := srvdata.GameItemMgr.Get(this.Platform, itemId) - if itemData == nil { - return - } - - if this.ItemRecExpireTime == 0 { - this.ItemRecExpireTime = time.Now().Unix() + int64(itemData.Time)*3600*num - } else { - if this.ItemRecExpireTime >= time.Now().Unix() { - this.ItemRecExpireTime += int64(itemData.Time) * 3600 * num - } else { - this.ItemRecExpireTime = time.Now().Unix() + int64(itemData.Time)*3600*num - } - } - - if this.scene != nil && this.scene.gameSess != nil { - msg := &serverproto.WGBuyRecTimeItem{ - SnId: this.SnId, - ExpireTime: this.ItemRecExpireTime, - Diamond: this.Diamond, - } - - proto.SetDefaults(msg) - this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_BUYRECTIMEITEM), msg) - } + if this.ItemRecExpireTime == 0 { + this.ItemRecExpireTime = time.Now().Unix() + int64(itemData.Time)*3600*num + } else { + if this.ItemRecExpireTime >= time.Now().Unix() { + this.ItemRecExpireTime += int64(itemData.Time) * 3600 * num + } else { + this.ItemRecExpireTime = time.Now().Unix() + int64(itemData.Time)*3600*num } + } - this.SendDiffData() + if this.scene != nil && this.scene.gameSess != nil { + msg := &serverproto.WGBuyRecTimeItem{ + SnId: this.SnId, + ExpireTime: this.ItemRecExpireTime, + Diamond: this.Diamond, + } + this.SendToGame(int(serverproto.SSPacketID_PACKET_WG_BUYRECTIMEITEM), msg) } } diff --git a/worldsrv/shopmgr.go b/worldsrv/shopmgr.go index e645d0d..594f085 100644 --- a/worldsrv/shopmgr.go +++ b/worldsrv/shopmgr.go @@ -921,18 +921,30 @@ func (this *ShopMgr) Exchange(p *Player, goodsId int32, username, mobile, commen }) } if info.DPrice > 0 { - item := model.ItemInfo{ - ItemId: common.ItemDollCard, - ItemNum: int64(info.JPrice * num), - } - _, _, isF := BagMgrSingleton.AddItem(p, int64(item.ItemId), -item.ItemNum, 0, common.GainWayItemChangeDoll, - "sys", fmt.Sprintf("兑换娃娃扣除%v", item.ItemId), 0, 0, false) - if !isF { // 扣掉金券 + n := int64(info.DPrice * num) + item := BagMgrSingleton.GetItem(p.SnId, common.ItemIDJCard) + if item != nil && item.ItemNum >= n { + BagMgrSingleton.AddItems(&model.AddItemParam{ + P: p.PlayerData, + Change: []*model.Item{ + { + ItemId: item.ItemId, + ItemNum: -n, + }, + }, + GainWay: common.GainWayItemChangeDoll, + Operator: "system", + Remark: fmt.Sprintf("兑换娃娃扣除%v", item.ItemId), + }) + } else { pack.RetCode = shop.OpResultCode_OPRC_DCoinNotEnough p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_EXCHANGE), pack) return false } - itemInfo = append(itemInfo, item) + itemInfo = append(itemInfo, &model.Item{ + ItemId: common.ItemDollCard, + ItemNum: n, + }) } task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { pack := &webapi_proto.ASCreateExchangeOrder{