金币道具优化

This commit is contained in:
sk 2024-09-19 11:37:25 +08:00
parent 47f98ad5f8
commit ba27fa4b3a
5 changed files with 116 additions and 135 deletions

View File

@ -87,16 +87,16 @@ func SaveToDelBackupBagItem(args *BagInfo) error {
} }
type AddItemParam struct { type AddItemParam struct {
P *PlayerData P *PlayerData // 玩家信息,玩家离线时不传
Change []*Item // 道具变化数量 Change []*Item // 道具变化数量
Cost []*Item // 获得道具时消耗的道具数量 Cost []*Item // 获得道具时消耗的道具数量
Add int64 // 加成数量 Add int64 // 加成数量
GainWay int32 // 记录类型 GainWay int32 // 记录类型
Operator, Remark string // 操作人,备注 Operator, Remark string // 操作人,备注
GameId, GameFreeId int64 // 游戏id,场次id GameId, GameFreeId int64 // 游戏id,场次id
NoLog bool // 是否不记录日志 NoLog bool // 是否不记录日志
LogId string // 撤销的id,道具兑换失败 LogId string // 撤销的id,道具兑换失败
RoomConfigId int32 // 房间配置id RoomConfigId int32 // 房间配置id
} }
type ChangeItemParam struct { type ChangeItemParam struct {

View File

@ -1722,6 +1722,7 @@ func (this *CSPlayerVIPInfoHandler) Process(s *netlib.Session, packetid int, dat
logger.Logger.Warn("CSPlayerVIPInfoHandler p == nil") logger.Logger.Warn("CSPlayerVIPInfoHandler p == nil")
return nil return nil
} }
p.GetVIPLevel()
p.SCVIPInfo() p.SCVIPInfo()
} }
return nil return nil

View File

@ -394,12 +394,12 @@ func (this *BagMgr) AddItems(param *model.AddItemParam) (*BagInfo, bag.OpResultC
} }
case common.ItemTypeFishPower: case common.ItemTypeFishPower:
//增加炮台 //增加炮台
p.ItemUnPlayerPowerListEx(v.ItemId) //p.ItemUnPlayerPowerListEx(v.ItemId)
case common.ItemTypeMoneyPond: case common.ItemTypeMoneyPond:
//增加个人金币池 //增加个人金币池
if v.ItemId == common.ItemIDMoneyPond { //if v.ItemId == common.ItemIDMoneyPond {
p.MoneyPond += v.ItemNum // p.MoneyPond += v.ItemNum
} //}
case common.ItemTypeVipExp: case common.ItemTypeVipExp:
//增加玩家VIP经验 //增加玩家VIP经验
if v.ItemId == common.ItemIDVipExp { if v.ItemId == common.ItemIDVipExp {

View File

@ -310,13 +310,7 @@ func (this *Player) OnLogined() {
this.SetOnline() this.SetOnline()
//测试用 //测试用
if !this.IsRob { if this.IsRob {
old := this.VIP
this.VIP = this.GetVIPLevel()
if old != this.VIP {
this.dirty = true
}
} else {
this.VIP = rand.Int31n(6) + 1 this.VIP = rand.Int31n(6) + 1
//机器人随机vip和头像 //机器人随机vip和头像
this.RobRandVip() this.RobRandVip()
@ -1720,55 +1714,46 @@ func (this *Player) AddDiamond(num, add int64, gainWay int32, oper, remark strin
return return
} }
logger.Logger.Tracef("snid(%v) AddDiamond(%v)", this.SnId, num) logger.Logger.Tracef("snid(%v) AddDiamond(%v)", this.SnId, num)
//async := false this.dirty = true
//if num > 0 && this.scene != nil && !this.scene.IsTestScene() && this.scene.sceneMode != common.SceneMode_Thr { //游戏场中加币,需要同步到gamesrv上 if num > 0 {
// if StartAsyncAddCoinTransact(this, num, gainWay, oper, remark, true, 0, true) { this.Diamond += num
// async = true } else {
// } if -num > this.Diamond {
//} logger.Logger.Errorf("Player.AddCoin exception!!! num(%v) oper(%v)", num, oper)
num = -this.Diamond
if num != 0 /*&& !async*/ { this.Diamond = 0
this.dirty = true
if num > 0 {
this.Diamond += num
} else { } else {
if -num > this.Diamond { this.Diamond += num
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,
})
}
} }
switch gainWay {
this.SendDiffData() case common.GainWay_MatchSignup: // 排除的
if !this.IsRob { default:
log := model.NewCoinLogEx(&model.CoinLogParam{ TaskSubjectSingleton.Touch(common.TaskTypeCostDiamond, &TaskData{
Platform: this.Platform, SnId: this.SnId,
SnID: this.SnId, Num: -num,
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) }
}
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 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) { func (this *Player) AddMoneyPayTotal(amount int64) {
if amount > 0 { if amount > 0 {
this.MoneyPayTotal += amount this.MoneyPayTotal += amount
this.SendDiffData() //更新vip this.GetVIPLevel()
} }
} }
func (this *Player) SendDiffData() { func (this *Player) SendDiffData() {
this.UpdateVip()
var dirty bool var dirty bool
pack := &playerproto.SCPlayerDataUpdate{} pack := &playerproto.SCPlayerDataUpdate{}
pack.UpdateField = 0 pack.UpdateField = 0
@ -2767,7 +2743,6 @@ func (this *Player) GetPromoterKey() (string, error) {
//} //}
func (this *Player) SendPlayerInfo() { func (this *Player) SendPlayerInfo() {
this.UpdateVip()
scPlayerData := &playerproto.SCPlayerData{ scPlayerData := &playerproto.SCPlayerData{
OpRetCode: playerproto.OpResultCode_OPRC_Sucess, OpRetCode: playerproto.OpResultCode_OPRC_Sucess,
Data: &playerproto.PlayerData{ Data: &playerproto.PlayerData{
@ -2878,6 +2853,8 @@ func (this *Player) SendPlayerInfo() {
this.SendGameConfig(int32(this.scene.gameId), this.Platform, this.Channel) this.SendGameConfig(int32(this.scene.gameId), this.Platform, this.Channel)
} }
//this.SendJackpotInfo() //this.SendJackpotInfo()
// 更新vip
this.GetVIPLevel()
// 后台道具配置 // 后台道具配置
this.SCItems() this.SCItems()
// 引导配置 // 引导配置
@ -3606,8 +3583,6 @@ func (this *Player) SCVIPInfo() {
pack.TolVipExp, pack.Money = this.GetCurrentVIPExp(vips) pack.TolVipExp, pack.Money = this.GetCurrentVIPExp(vips)
pack.Vip = this.VIP pack.Vip = this.VIP
pack.OpRetCode = playerproto.OpResultCode_OPRC_Sucess 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) this.SendToClient(int(playerproto.PlayerPacketID_PACKET_SC_VIPINFO), pack)
logger.Logger.Tracef("send vipinfo to client:%v", pack) logger.Logger.Tracef("send vipinfo to client:%v", pack)
@ -3732,6 +3707,8 @@ func (this *Player) VIPDraw(id, vip int32) {
send() send()
} }
// GetCurrentVIPExp 更新vip等级
// 返回当前经验和升级需要经验
func (this *Player) GetCurrentVIPExp(vipcfg ...*webapiproto.VIPcfgDataList) (exp int64, money int64) { func (this *Player) GetCurrentVIPExp(vipcfg ...*webapiproto.VIPcfgDataList) (exp int64, money int64) {
var vips *webapiproto.VIPcfgDataList var vips *webapiproto.VIPcfgDataList
if len(vipcfg) == 0 { if len(vipcfg) == 0 {
@ -3767,6 +3744,7 @@ func (this *Player) GetCurrentVIPExp(vipcfg ...*webapiproto.VIPcfgDataList) (exp
return // 默认 return // 默认
} }
// GetVIPLevel 更新vip等级返回vip等级
func (this *Player) GetVIPLevel() int32 { func (this *Player) GetVIPLevel() int32 {
if this.IsRob { if this.IsRob {
return 0 return 0
@ -3786,6 +3764,7 @@ func (this *Player) GetVIPLevel() int32 {
} }
var b bool var b bool
if vip != this.VIP { if vip != this.VIP {
this.dirty = true
b = true b = true
//玩家VIP升级 //玩家VIP升级
this.SCVIPInfo() 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) { func (this *Player) AddPhoneScore(num, add int64, gainWay int32, oper, remark string) {
if num == 0 { if num == 0 {
return return
@ -4353,22 +4332,20 @@ func (this *Player) AddPhoneScore(num, add int64, gainWay int32, oper, remark st
return return
} }
logger.Logger.Tracef("snid(%v) AddPhoneScore(%v)", this.SnId, num) 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) { 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 return
} }
logger.Logger.Tracef("snid(%v) AddItemRecExpireTime, itemId:(%v), num:(%v)", this.SnId, itemId, num) if this.ItemRecExpireTime == 0 {
this.ItemRecExpireTime = time.Now().Unix() + int64(itemData.Time)*3600*num
if num != 0 /*&& !async*/ { } else {
this.dirty = true if this.ItemRecExpireTime >= time.Now().Unix() {
if num > 0 { this.ItemRecExpireTime += int64(itemData.Time) * 3600 * num
itemData := srvdata.GameItemMgr.Get(this.Platform, itemId) } else {
if itemData == nil { this.ItemRecExpireTime = time.Now().Unix() + int64(itemData.Time)*3600*num
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)
}
} }
}
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)
} }
} }

View File

@ -921,18 +921,30 @@ func (this *ShopMgr) Exchange(p *Player, goodsId int32, username, mobile, commen
}) })
} }
if info.DPrice > 0 { if info.DPrice > 0 {
item := model.ItemInfo{ n := int64(info.DPrice * num)
ItemId: common.ItemDollCard, item := BagMgrSingleton.GetItem(p.SnId, common.ItemIDJCard)
ItemNum: int64(info.JPrice * num), if item != nil && item.ItemNum >= n {
} BagMgrSingleton.AddItems(&model.AddItemParam{
_, _, isF := BagMgrSingleton.AddItem(p, int64(item.ItemId), -item.ItemNum, 0, common.GainWayItemChangeDoll, P: p.PlayerData,
"sys", fmt.Sprintf("兑换娃娃扣除%v", item.ItemId), 0, 0, false) Change: []*model.Item{
if !isF { // 扣掉金券 {
ItemId: item.ItemId,
ItemNum: -n,
},
},
GainWay: common.GainWayItemChangeDoll,
Operator: "system",
Remark: fmt.Sprintf("兑换娃娃扣除%v", item.ItemId),
})
} else {
pack.RetCode = shop.OpResultCode_OPRC_DCoinNotEnough pack.RetCode = shop.OpResultCode_OPRC_DCoinNotEnough
p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_EXCHANGE), pack) p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_EXCHANGE), pack)
return false 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{} { task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
pack := &webapi_proto.ASCreateExchangeOrder{ pack := &webapi_proto.ASCreateExchangeOrder{