760 lines
21 KiB
Go
760 lines
21 KiB
Go
package game
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"database/sql"
|
|
"encoding/gob"
|
|
"errors"
|
|
"server/GoUtil"
|
|
"server/MergeConst"
|
|
userCfg "server/conf/user"
|
|
"server/db"
|
|
"server/game/mod/limitedTimeEvent"
|
|
"server/game/mod/quest"
|
|
"server/msg"
|
|
"server/pkg/github.com/name5566/leaf/log"
|
|
"server/pkg/github.com/name5566/leaf/timer"
|
|
telog "server/thinkdata"
|
|
"time"
|
|
|
|
"github.com/robfig/cron/v3"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
type PlayerBaseData struct {
|
|
*PlayerData
|
|
Data msg.ResPlayerBaseInfo
|
|
KeyValueData map[int]string
|
|
MLeafTimer *timer.Timer
|
|
MTicker *time.Ticker
|
|
McronSave *cron.Cron
|
|
McronSaveID cron.EntryID
|
|
Mdispatr *timer.Dispatcher
|
|
DailyRenewTime int32
|
|
Update bool
|
|
isKeyValueDb bool
|
|
}
|
|
|
|
func (p *PlayerBaseData) GetData() interface{} {
|
|
return &p.Data
|
|
}
|
|
|
|
func (p *PlayerBaseData) BackUp() *PlayerBaseData {
|
|
return &PlayerBaseData{
|
|
Data: msg.ResPlayerBaseInfo{
|
|
Diamond: p.Data.Diamond,
|
|
DwUin: p.Data.DwUin,
|
|
Energy: p.Data.Energy,
|
|
Star: p.Data.Star,
|
|
RecoverTime: p.Data.RecoverTime,
|
|
Level: p.Data.Level,
|
|
Exp: p.Data.Exp,
|
|
StartOrderId: p.Data.StartOrderId,
|
|
MusicCode: p.Data.MusicCode,
|
|
Guild: p.Data.Guild,
|
|
PackUnlockCount: p.Data.PackUnlockCount,
|
|
LastPlayTime: p.Data.LastPlayTime,
|
|
EnergyBuyCount: p.Data.EnergyBuyCount,
|
|
LoginTime: p.Data.LoginTime,
|
|
UserName: p.Data.UserName,
|
|
LogoutTime: p.Data.LogoutTime,
|
|
Todayolinetime: p.Data.Todayolinetime,
|
|
Rolecreatetime: p.Data.Rolecreatetime,
|
|
LastChampGroupID: p.Data.LastChampGroupID,
|
|
ChampshipsGroupID: p.Data.ChampshipsGroupID,
|
|
NoAd: p.Data.NoAd,
|
|
FaceBookId: p.Data.FaceBookId,
|
|
},
|
|
MLeafTimer: p.MLeafTimer,
|
|
MTicker: p.MTicker,
|
|
McronSave: p.McronSave,
|
|
McronSaveID: p.McronSaveID,
|
|
Mdispatr: p.Mdispatr,
|
|
DailyRenewTime: p.DailyRenewTime,
|
|
isKeyValueDb: p.isKeyValueDb,
|
|
}
|
|
}
|
|
|
|
func (p *PlayerBaseData) Recover(old *PlayerBaseData) *PlayerBaseData {
|
|
old.Data = msg.ResPlayerBaseInfo{
|
|
Diamond: p.Data.Diamond,
|
|
DwUin: p.Data.DwUin,
|
|
Energy: p.Data.Energy,
|
|
Star: p.Data.Star,
|
|
RecoverTime: p.Data.RecoverTime,
|
|
Level: p.Data.Level,
|
|
Exp: p.Data.Exp,
|
|
StartOrderId: p.Data.StartOrderId,
|
|
MusicCode: p.Data.MusicCode,
|
|
Guild: p.Data.Guild,
|
|
PackUnlockCount: p.Data.PackUnlockCount,
|
|
LastPlayTime: p.Data.LastPlayTime,
|
|
EnergyBuyCount: p.Data.EnergyBuyCount,
|
|
LoginTime: p.Data.LoginTime,
|
|
UserName: p.Data.UserName,
|
|
LogoutTime: p.Data.LogoutTime,
|
|
Todayolinetime: p.Data.Todayolinetime,
|
|
Rolecreatetime: p.Data.Rolecreatetime,
|
|
LastChampGroupID: p.Data.LastChampGroupID,
|
|
ChampshipsGroupID: p.Data.ChampshipsGroupID,
|
|
NoAd: p.Data.NoAd,
|
|
FaceBookId: p.Data.FaceBookId,
|
|
}
|
|
return old
|
|
}
|
|
|
|
func (p *PlayerBaseData) LoadDataFromDB(UserName interface{}) bool {
|
|
sqlStr := "SELECT * FROM t_player_baseinfo WHERE user_name = ?"
|
|
sqlStruck := db.ResPlayerBaseInfo{}
|
|
if err := db.SqlDb.Get(&sqlStruck, sqlStr, UserName); err != nil {
|
|
log.Debug("get data failed, err:%v\n", err)
|
|
return false
|
|
}
|
|
sqlStr1 := "SELECT * FROM t_player_client_data WHERE dwUin = ?"
|
|
sqlStruck1 := db.SqlModStruct{}
|
|
db.SqlDb.Get(&sqlStruck1, sqlStr1, sqlStruck.DwUin)
|
|
|
|
p.Data.Diamond = sqlStruck.Diamond
|
|
p.Data.DwUin = sqlStruck.DwUin
|
|
p.Data.Energy = sqlStruck.Energy
|
|
p.Data.Star = sqlStruck.Star
|
|
p.Data.RecoverTime = sqlStruck.RecoverTime
|
|
p.Data.Level = sqlStruck.Level
|
|
p.Data.Exp = sqlStruck.Exp
|
|
p.Data.StartOrderId = sqlStruck.StartOrderId
|
|
p.Data.MusicCode = sqlStruck.MusicCode
|
|
p.Data.Guild = sqlStruck.Guild
|
|
p.Data.PackUnlockCount = sqlStruck.PackUnlockCount
|
|
p.Data.LastPlayTime = sqlStruck.LastPlayTime
|
|
p.Data.EnergyBuyCount = sqlStruck.EnergyBuyCount
|
|
p.Data.LoginTime = int32(time.Now().Unix())
|
|
p.Data.UserName = sqlStruck.UserName
|
|
p.Data.LogoutTime = sqlStruck.LogoutTime
|
|
p.Data.Todayolinetime = sqlStruck.Todayolinetime
|
|
p.Data.Rolecreatetime = sqlStruck.Rolecreatetime
|
|
p.Data.LastChampGroupID = sqlStruck.LastChampGroupID
|
|
p.Data.ChampshipsGroupID = sqlStruck.ChampshipsGroupID
|
|
p.DailyRenewTime = sqlStruck.DailyRenewTime
|
|
p.Data.NoAd = sqlStruck.NoAd
|
|
p.Data.FaceBookId = sqlStruck.FaceBookId
|
|
p.McronSave = cron.New()
|
|
p.Reconnect(false)
|
|
|
|
p.KeyValueData = make(map[int]string)
|
|
if len(sqlStruck1.ModData) > 0 {
|
|
var buf bytes.Buffer
|
|
buf.Write(sqlStruck1.ModData)
|
|
decode := gob.NewDecoder(&buf)
|
|
err := decode.Decode(&p.KeyValueData)
|
|
if err != nil {
|
|
log.Debug("decode failed, err:%v\n", err)
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerBaseData) AddSta() error {
|
|
curtime := time.Now().Unix()
|
|
delta := curtime - (int64)(p.Data.RecoverTime)
|
|
Recover := userCfg.GetRecover(int(p.Data.Level))
|
|
Addsta := int(delta) / Recover
|
|
if Addsta <= 0 {
|
|
return nil
|
|
}
|
|
if p.GetMaxEnergy() > p.Data.Energy {
|
|
p.Data.Energy = p.Data.Energy + int32(Addsta)
|
|
if p.Data.Energy > p.GetMaxEnergy() {
|
|
p.Data.Energy = p.GetMaxEnergy()
|
|
}
|
|
p.M_Player.CallEvent(time.Duration(Recover)*time.Second, func() {
|
|
p.M_Player.lock.Lock()
|
|
defer p.M_Player.lock.Unlock()
|
|
p.AddSta()
|
|
}, "AddEnergy")
|
|
}
|
|
p.Data.RecoverTime = int32(curtime)
|
|
p.M_Player.SendErrClienRes(p.BackAsset())
|
|
return nil
|
|
}
|
|
|
|
func (p *PlayerBaseData) Reconnect(b bool) {
|
|
p.AddSta()
|
|
if G_GameLogicPtr.DailyTaskTimestamp > (int64)(p.DailyRenewTime) {
|
|
p.DailyRenewTime = int32(G_GameLogicPtr.DailyTaskTimestamp)
|
|
p.Data.EnergyBuyCount = 0
|
|
}
|
|
GoUtil.RegisterEvent(MergeConst.Notify_Daily_Renew, p.Notify_Daily_Renew, p)
|
|
}
|
|
|
|
func (p *PlayerBaseData) SetChampshipID(ChampshipsGroupID int32, isNotify bool) {
|
|
p.Data.LastChampGroupID = p.Data.ChampshipsGroupID
|
|
p.Data.ChampshipsGroupID = ChampshipsGroupID
|
|
|
|
if isNotify {
|
|
notify := &msg.NotifyChampshipOpen{}
|
|
notify.CurChampshipsId = G_GameLogicPtr.M_SvrGlobal.CurChampshipsId
|
|
notify.LastChampshipsGroupID = p.Data.LastChampGroupID
|
|
notify.ChampshipsGroupID = p.Data.ChampshipsGroupID
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(notify)
|
|
G_getGameLogic().PackResInfo(agent, "NotifyChampshipOpen", data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (p *PlayerBaseData) Notify_Daily_Renew(param []interface{}) {
|
|
p.Data.EnergyBuyCount = 0
|
|
p.DailyRenewTime = int32(G_GameLogicPtr.DailyTaskTimestamp)
|
|
notify := &msg.NotifyRenewBuyEnergyCnt{}
|
|
notify.DwUin = p.M_Player.M_DwUin
|
|
notify.CurCnt = 0
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(notify)
|
|
G_getGameLogic().PackResInfo(agent, "NotifyRenewBuyEnergyCnt", data)
|
|
|
|
}
|
|
|
|
func (p *PlayerBaseData) SaveDataFromDB(Key interface{}) bool {
|
|
// G_getGameLogic().Mlogger.Debug("SaveDataFromDB:", p.Data.DwUin)
|
|
sqlStruck := db.ResPlayerBaseInfo{}
|
|
sqlStruck.Diamond = p.Data.Diamond
|
|
sqlStruck.DwUin = p.Data.DwUin
|
|
sqlStruck.Energy = p.Data.Energy
|
|
sqlStruck.Star = p.Data.Star
|
|
sqlStruck.RecoverTime = p.Data.RecoverTime
|
|
sqlStruck.Level = p.Data.Level
|
|
sqlStruck.Exp = p.Data.Exp
|
|
sqlStruck.StartOrderId = p.Data.StartOrderId
|
|
sqlStruck.MusicCode = p.Data.MusicCode
|
|
sqlStruck.Guild = p.Data.Guild
|
|
sqlStruck.PackUnlockCount = p.Data.PackUnlockCount
|
|
sqlStruck.LastPlayTime = p.Data.LastPlayTime
|
|
sqlStruck.EnergyBuyCount = p.Data.EnergyBuyCount
|
|
sqlStruck.LoginTime = p.Data.LoginTime
|
|
sqlStruck.UserName = p.Data.UserName
|
|
sqlStruck.LogoutTime = p.Data.LogoutTime
|
|
sqlStruck.Todayolinetime = p.Data.Todayolinetime
|
|
sqlStruck.Rolecreatetime = p.Data.Rolecreatetime
|
|
sqlStruck.DailyRenewTime = p.DailyRenewTime
|
|
sqlStruck.NoAd = p.Data.NoAd
|
|
sqlStruck.ChampshipsGroupID = p.Data.ChampshipsGroupID
|
|
sqlStruck.LastChampGroupID = p.Data.LastChampGroupID
|
|
sqlStruck.FaceBookId = p.Data.FaceBookId
|
|
db.FormatAllMemUpdateDb(&sqlStruck, "t_player_baseinfo", "dwUin")
|
|
|
|
// 存储KeyValue
|
|
var buf bytes.Buffer
|
|
encode := gob.NewEncoder(&buf)
|
|
encode.Encode(p.KeyValueData)
|
|
// log.Debug("player :%d KeyValueData Save:%v ", p.Data.DwUin, p.KeyValueData)
|
|
db.SavePlayerClientData(&db.SqlModStruct{
|
|
DwUin: p.Data.DwUin,
|
|
ModData: buf.Bytes(),
|
|
UpdataTime: int32(GoUtil.Now()),
|
|
})
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerBaseData) GetMaxEnergyMul() int {
|
|
MaxEnergyMul := userCfg.GetEnergyMulByLv(int(p.Data.Level))
|
|
if p.M_Player.PlayMod.getLimitedTimeEventMod().CheckExist(limitedTimeEvent.EVENT_TYPE_HIGH_ROLLER) {
|
|
MaxEnergyMul = 10
|
|
}
|
|
return MaxEnergyMul
|
|
}
|
|
|
|
func (p *PlayerBaseData) GetMaxEnergy() int32 {
|
|
MaxSta := MergeConst.G_Sta_Limit
|
|
|
|
if p.Data.Level < 7 {
|
|
MaxSta = MergeConst.G_Sta_Limit
|
|
} else if p.Data.Level < 12 {
|
|
MaxSta = 120
|
|
} else if p.Data.Level < 19 {
|
|
MaxSta = 130
|
|
} else if p.Data.Level < 27 {
|
|
MaxSta = 135
|
|
} else if p.Data.Level < 38 {
|
|
MaxSta = 140
|
|
} else if p.Data.Level < 44 {
|
|
MaxSta = 145
|
|
} else if p.Data.Level < 59 {
|
|
MaxSta = 150
|
|
} else {
|
|
MaxSta = 155
|
|
}
|
|
return MaxSta
|
|
}
|
|
|
|
// 定时增加体力
|
|
func (p *PlayerBaseData) NotifyAddSta(cnt int, timeStamp int64) {
|
|
p.M_Player.lock.Lock()
|
|
defer p.M_Player.lock.Unlock()
|
|
if p.GetMaxEnergy() <= p.Data.Energy {
|
|
return
|
|
}
|
|
G_getGameLogic().Mlogger.Debug("NotifyAddSta:", p.Data.DwUin)
|
|
p.Data.Energy = p.Data.Energy + int32(cnt)
|
|
p.Data.RecoverTime = int32(timeStamp)
|
|
|
|
notify := &msg.NotifyAddEnergy{}
|
|
notify.AddCnt = int32(cnt)
|
|
notify.DwUin = p.M_Player.M_DwUin
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(notify)
|
|
G_getGameLogic().PackResInfo(agent, "NotifyAddEnergy", data)
|
|
}
|
|
|
|
// 更新游戏道具
|
|
func (p *PlayerBaseData) UpdateBaseItemInfo(update *msg.UpdateBaseItemInfo) {
|
|
for k, v := range update.MUpdateItem {
|
|
switch k {
|
|
case 4:
|
|
p.Data.EnergyBuyCount = v
|
|
case 8:
|
|
p.Data.Guild = v
|
|
case 9:
|
|
p.Data.PackUnlockCount = v
|
|
case 10:
|
|
p.Data.EmitOrderCnt = v
|
|
case 11:
|
|
p.Data.LastPlayTime = v
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
func (p *PlayerBaseData) ReqRemoveAd(buf []byte) {
|
|
req := &msg.ReqRemoveAd{}
|
|
res := &msg.ResRemoveAd{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
p.Data.NoAd = 1
|
|
res.ResultCode = 0
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_getGameLogic().PackResInfo(agent, "ResRemoveAd", data)
|
|
}
|
|
|
|
func (p *PlayerBaseData) ResPlayerBaseInfo(player *Player) {
|
|
if player != p.M_Player {
|
|
return
|
|
}
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(&p.Data)
|
|
G_getGameLogic().PackResInfo(agent, "ResPlayerBaseInfo", data)
|
|
}
|
|
|
|
func (p *PlayerBaseData) BackKv() *msg.ResKv {
|
|
kv := make(map[int32]string)
|
|
for k, v := range p.KeyValueData {
|
|
kv[int32(k)] = v
|
|
}
|
|
return &msg.ResKv{
|
|
Kv: kv,
|
|
}
|
|
}
|
|
|
|
func (p *PlayerBaseData) ReqBindFacebookAccount(buf []byte) {
|
|
req := &msg.ReqBindFacebookAccount{}
|
|
res := &msg.ResBindFacebookAccount{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
sqlStr := "SELECT * FROM t_player_baseinfo WHERE FaceBookId = ?"
|
|
sqlStruck := db.ResPlayerBaseInfo{}
|
|
isHaveOther := false
|
|
|
|
if err := db.SqlDb.Get(&sqlStruck, sqlStr, req.BindAccountId); err != nil {
|
|
isHaveOther = false
|
|
} else {
|
|
isHaveOther = true
|
|
}
|
|
if isHaveOther {
|
|
if sqlStruck.DwUin == p.Data.DwUin {
|
|
res.ResultCode = MergeConst.Protocol_FaceBook_Binded
|
|
} else {
|
|
res.ResultCode = MergeConst.Protocol_FaceBook_Binded_other
|
|
}
|
|
} else {
|
|
res.ResultCode = 0
|
|
p.Data.FaceBookId = req.BindAccountId
|
|
res.BindAccountId = req.BindAccountId
|
|
p.M_Player.TeLog("platform_connect", map[string]interface{}{
|
|
"platform_type": "facebook",
|
|
"platform_id": req.BindAccountId,
|
|
"is_reward": false,
|
|
})
|
|
}
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_getGameLogic().PackResInfo(agent, "ResBindFacebookAccount", data)
|
|
}
|
|
|
|
func (p *PlayerBaseData) ReqUnBindFacebook(buf []byte) {
|
|
req := &msg.ReqUnBindFacebook{}
|
|
res := &msg.ResUnBindFacebook{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
res.ResultCode = 0
|
|
res.BindAccountId = req.BindAccountId
|
|
p.Data.FaceBookId = ""
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_getGameLogic().PackResInfo(agent, "ResUnBindFacebook", data)
|
|
p.M_Player.TeLog("platform_disconnect", map[string]interface{}{
|
|
"platform_type": "facebook",
|
|
"platform_id": req.BindAccountId,
|
|
})
|
|
}
|
|
func (p *PlayerBaseData) ReqOnlyBindFacebook(buf []byte) {
|
|
req := &msg.ReqOnlyBindFacebook{}
|
|
res := &msg.ResOnlyBindFacebook{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
sqlStr := "SELECT * FROM t_player_baseinfo WHERE FaceBookId = ?"
|
|
sqlStruck := db.ResPlayerBaseInfo{}
|
|
isHaveOther := false
|
|
err := db.SqlDb.Get(&sqlStruck, sqlStr, req.BindAccountId)
|
|
if err != nil {
|
|
isHaveOther = false
|
|
} else {
|
|
isHaveOther = true
|
|
}
|
|
if isHaveOther {
|
|
if sqlStruck.DwUin == p.Data.DwUin {
|
|
res.ResultCode = MergeConst.Protocol_FaceBook_Binded
|
|
} else {
|
|
sqlStruck.FaceBookId = ""
|
|
|
|
// 修改双方的faceBookId
|
|
ctx := context.Background()
|
|
txOptions := &sql.TxOptions{}
|
|
tx, _ := db.SqlDb.BeginTx(ctx, txOptions)
|
|
sqlStr := "update t_player_baseinfo set FaceBookId = ? where dwUin = ?"
|
|
_, err := tx.Exec(sqlStr, "", sqlStruck.DwUin)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
sqlStr = "update t_player_baseinfo set FaceBookId = ? where dwUin = ?"
|
|
_, err = tx.Exec(sqlStr, req.BindAccountId, p.Data.DwUin)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
tx.Commit()
|
|
|
|
res.ResultCode = 0
|
|
p.Data.FaceBookId = req.BindAccountId
|
|
res.BindAccountId = req.BindAccountId
|
|
p.M_Player.TeLog("platform_connect", map[string]interface{}{
|
|
"platform_type": "facebook",
|
|
"platform_id": req.BindAccountId,
|
|
"is_reward": false,
|
|
})
|
|
|
|
}
|
|
} else {
|
|
res.ResultCode = 0
|
|
p.Data.FaceBookId = req.BindAccountId
|
|
res.BindAccountId = req.BindAccountId
|
|
|
|
}
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_getGameLogic().PackResInfo(agent, "ResOnlyBindFacebook", data)
|
|
}
|
|
|
|
func (p *PlayerBaseData) ReqSynGameData(buf []byte) {
|
|
req := &msg.ReqSynGameData{}
|
|
res := &msg.ResSynGameData{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
sqlStr := "SELECT * FROM t_player_baseinfo WHERE FaceBookId = ?"
|
|
sqlStruck := db.ResPlayerBaseInfo{}
|
|
isHaveOther := false
|
|
|
|
if err := db.SqlDb.Get(&sqlStruck, sqlStr, req.NewFBId); err != nil {
|
|
isHaveOther = false
|
|
} else {
|
|
isHaveOther = true
|
|
}
|
|
if sqlStruck.DwUin == p.M_Player.M_DwUin {
|
|
return
|
|
}
|
|
OldPlayer := G_GameLogicPtr.GetPlayer(sqlStruck.DwUin)
|
|
if OldPlayer != nil {
|
|
agent := OldPlayer.GetAgentByPlayer()
|
|
// notify := &msg.ForceKickOut{}
|
|
notify := &msg.ResSynGameData{}
|
|
data, _ := proto.Marshal(notify)
|
|
if agent != nil {
|
|
G_getGameLogic().PackResInfo(agent, "ResSynGameData", data)
|
|
}
|
|
OldPlayer.ClearData()
|
|
G_GameLogicPtr.M_Players.Delete(sqlStruck.DwUin)
|
|
}
|
|
|
|
if isHaveOther {
|
|
if sqlStruck.DwUin == p.Data.DwUin {
|
|
res.ResultCode = MergeConst.Protocol_FaceBook_Binded
|
|
} else {
|
|
ReplaceName := sqlStruck.UserName
|
|
UserName := p.Data.UserName
|
|
res.ResultCode = 0
|
|
// 修改双方的账号
|
|
ctx := context.Background()
|
|
txOptions := &sql.TxOptions{}
|
|
tx, _ := db.SqlDb.BeginTx(ctx, txOptions)
|
|
sqlStr1 := "SELECT * FROM t_account WHERE user_name = ?"
|
|
sqlAccStruck1 := db.Db_Account{}
|
|
err2 := db.SqlDb.Get(&sqlAccStruck1, sqlStr1, UserName)
|
|
if err2 == nil {
|
|
sqlAccStruck1.UserName = ""
|
|
_, err := db.SqlDb.Exec("update t_account set user_name = ? where auto_id = ?", sqlAccStruck1.UserName, sqlAccStruck1.AutoId)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
}
|
|
p.Data.UserName = ""
|
|
_, err := db.SqlDb.Exec("update t_player_baseinfo set user_name = ? where dwUin = ?", "", p.Data.DwUin)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
|
|
sqlStruck.FaceBookId = req.NewFBId
|
|
sqlStruck.UserName = UserName
|
|
_, err = db.SqlDb.Exec("update t_player_baseinfo set user_name = ?, FaceBookId = ? where dwUin = ?", UserName, req.NewFBId, sqlStruck.DwUin)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
|
|
sqlStr := "SELECT * FROM t_account WHERE user_name = ?"
|
|
sqlAccStruck := db.Db_Account{}
|
|
err2 = db.SqlDb.Get(&sqlAccStruck, sqlStr, ReplaceName)
|
|
if err2 == nil {
|
|
sqlAccStruck.UserName = UserName
|
|
_, err := db.SqlDb.Exec("update t_account set user_name = ? where auto_id = ?", sqlAccStruck.UserName, sqlAccStruck.AutoId)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
}
|
|
tx.Commit()
|
|
}
|
|
} else {
|
|
res.ResultCode = 0
|
|
|
|
}
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_getGameLogic().PackResInfo(agent, "ResSynGameData", data)
|
|
}
|
|
|
|
func (p *PlayerBaseData) ClearData() bool {
|
|
p.Data.LogoutTime = int32(time.Now().Unix())
|
|
GoUtil.RemoveEvent(MergeConst.Notify_Daily_Renew, p.Notify_Daily_Renew, p)
|
|
p.McronSave.Remove(p.McronSaveID)
|
|
p.McronSave.Stop()
|
|
if p.MLeafTimer != nil {
|
|
p.MLeafTimer.Stop()
|
|
p.MLeafTimer = nil
|
|
}
|
|
if p.MTicker != nil {
|
|
p.MTicker.Stop()
|
|
p.MTicker = nil
|
|
}
|
|
p.SaveDataFromDB("")
|
|
return true
|
|
}
|
|
|
|
// 增加减少体力
|
|
func (p *PlayerBaseData) AddEnergy(cnt int) error {
|
|
NewEnergy := p.Data.Energy + int32(cnt)
|
|
if NewEnergy < 0 {
|
|
return errors.New("能量不足")
|
|
}
|
|
if cnt < 0 {
|
|
p.M_Player.QuestTrigger(&quest.Trigger{Label: quest.TRIGGER_LABEL_ENERGY, A: []interface{}{-cnt}})
|
|
}
|
|
if p.Data.Energy >= p.GetMaxEnergy() && NewEnergy < p.GetMaxEnergy() {
|
|
Recover := userCfg.GetRecover(int(p.Data.Level))
|
|
p.M_Player.CallEvent(time.Duration(Recover)*time.Second, func() {
|
|
p.M_Player.lock.Lock()
|
|
defer p.M_Player.lock.Unlock()
|
|
p.AddSta()
|
|
}, "AddEnergy")
|
|
p.Data.RecoverTime = int32(time.Now().Unix())
|
|
}
|
|
p.Data.Energy = NewEnergy
|
|
return nil
|
|
}
|
|
|
|
// 增加减少星星
|
|
func (p *PlayerBaseData) AddStar(cnt int) error {
|
|
NewStar := p.Data.Star + int32(cnt)
|
|
if NewStar < 0 {
|
|
return errors.New("星星不足")
|
|
}
|
|
|
|
p.Data.Star = NewStar
|
|
return nil
|
|
}
|
|
|
|
// 增加减少钻石
|
|
func (p *PlayerBaseData) AddDiamond(cnt int) error {
|
|
NewDiamond := p.Data.Diamond + int32(cnt)
|
|
if NewDiamond < 0 {
|
|
return errors.New("钻石不足")
|
|
}
|
|
p.Data.Diamond = NewDiamond
|
|
return nil
|
|
}
|
|
|
|
// 增加经验
|
|
func (p *PlayerBaseData) AddExp(exp int) (int, error) {
|
|
p.Data.Exp += int32(exp)
|
|
upLv := 0
|
|
upExp := userCfg.GetLevUpExp(int(p.Data.Level))
|
|
if p.Data.Exp >= int32(upExp) {
|
|
p.Data.Level++
|
|
p.Data.Exp -= int32(upExp)
|
|
|
|
// 日常任务解锁
|
|
DailyTaskMod := p.M_Player.PlayMod.getDailyTaskMod()
|
|
DecorateMod := p.M_Player.PlayMod.getDecorateMod()
|
|
if DailyTaskMod.LevUpTrigger(int(p.Data.Level), DecorateMod.GetAreaId()) {
|
|
p.M_Player.PushClientRes(DailyTaskMod.BackData())
|
|
}
|
|
upLv = int(p.Data.Level)
|
|
|
|
// 棋盘背包解锁
|
|
p.M_Player.PushClientRes(p.BackAsset())
|
|
ChessMod := p.M_Player.PlayMod.getChessMod()
|
|
if ChessMod.TriggerChessBagUnlock(int(p.Data.Level)) {
|
|
p.M_Player.PushClientRes(ChessMod.BackData())
|
|
}
|
|
|
|
ChargeMod := p.M_Player.PlayMod.getChargeMod()
|
|
ChargeMod.TriggerChargeUnlock(int(p.Data.Level), ChessMod.GetEmitList())
|
|
p.M_Player.PushClientRes(ChargeMod.BackData())
|
|
// 重载活动
|
|
p.M_Player.initAcitivity()
|
|
telog.Te.Track(p.Data.UserName, p.Data.UserName, "level_up", map[string]interface{}{
|
|
"after_level": p.Data.Level,
|
|
})
|
|
telog.Te.Track(p.Data.UserName, p.Data.UserName, "property_level_up", map[string]interface{}{
|
|
"property_level": p.Data.Level,
|
|
"property_level_reward": userCfg.GetUnlock(int(p.Data.Level)),
|
|
})
|
|
}
|
|
p.M_Player.PushClientRes(p.BackAsset())
|
|
return upLv, nil
|
|
|
|
}
|
|
|
|
func (p *PlayerBaseData) GetLevel() int {
|
|
return int(p.Data.Level)
|
|
}
|
|
|
|
func (p *PlayerBaseData) GetExp() int {
|
|
return int(p.Data.Exp)
|
|
}
|
|
|
|
func (p *PlayerBaseData) GetDiamond() int {
|
|
return int(p.Data.Diamond)
|
|
}
|
|
|
|
func (p *PlayerBaseData) GetEnergy() int {
|
|
return int(p.Data.Energy)
|
|
}
|
|
|
|
func (p *PlayerBaseData) GetStar() int {
|
|
return int(p.Data.Star)
|
|
}
|
|
|
|
func (p *PlayerBaseData) BackAsset() *msg.ResPlayerAsset {
|
|
return &msg.ResPlayerAsset{
|
|
DwUin: p.Data.DwUin,
|
|
Diamond: p.Data.Diamond,
|
|
Energy: p.Data.Energy,
|
|
Star: p.Data.Star,
|
|
RecoverTime: p.Data.RecoverTime,
|
|
Level: p.Data.Level,
|
|
Exp: p.Data.Exp,
|
|
}
|
|
}
|
|
|
|
func (p *PlayerBaseData) GetSevenLoginAdd() int {
|
|
return userCfg.GetSevenloginAdd(int(p.Data.Level))
|
|
}
|
|
|
|
func (p *PlayerBaseData) GetLastLoginTime() int {
|
|
return int(p.Data.LoginTime)
|
|
}
|
|
|
|
func (p *PlayerBaseData) GetName() string {
|
|
return p.Data.UserName
|
|
}
|
|
|
|
func (p *PlayerBaseData) GetLoginTime() int64 {
|
|
return int64(p.Data.LoginTime)
|
|
}
|
|
|
|
func (p *PlayerBaseData) GetDataByUid(Uid interface{}) bool {
|
|
sqlStr := "SELECT * FROM t_player_baseinfo WHERE dwUin = ?"
|
|
sqlStruck := db.ResPlayerBaseInfo{}
|
|
if err := db.SqlDb.Get(&sqlStruck, sqlStr, Uid); err != nil {
|
|
log.Debug("get data failed, err:%v\n", err)
|
|
return false
|
|
}
|
|
|
|
p.Data.Diamond = sqlStruck.Diamond
|
|
p.Data.DwUin = sqlStruck.DwUin
|
|
p.Data.Energy = sqlStruck.Energy
|
|
p.Data.Star = sqlStruck.Star
|
|
p.Data.RecoverTime = sqlStruck.RecoverTime
|
|
p.Data.Level = sqlStruck.Level
|
|
p.Data.Exp = sqlStruck.Exp
|
|
p.Data.StartOrderId = sqlStruck.StartOrderId
|
|
p.Data.MusicCode = sqlStruck.MusicCode
|
|
p.Data.Guild = sqlStruck.Guild
|
|
p.Data.PackUnlockCount = sqlStruck.PackUnlockCount
|
|
p.Data.LastPlayTime = sqlStruck.LastPlayTime
|
|
p.Data.EnergyBuyCount = sqlStruck.EnergyBuyCount
|
|
p.Data.LoginTime = int32(time.Now().Unix())
|
|
p.Data.UserName = sqlStruck.UserName
|
|
p.Data.LogoutTime = sqlStruck.LogoutTime
|
|
p.Data.Todayolinetime = sqlStruck.Todayolinetime
|
|
p.Data.Rolecreatetime = sqlStruck.Rolecreatetime
|
|
p.Data.LastChampGroupID = sqlStruck.LastChampGroupID
|
|
p.Data.ChampshipsGroupID = sqlStruck.ChampshipsGroupID
|
|
p.DailyRenewTime = sqlStruck.DailyRenewTime
|
|
p.Data.NoAd = sqlStruck.NoAd
|
|
p.Data.FaceBookId = sqlStruck.FaceBookId
|
|
p.McronSave = cron.New()
|
|
p.Reconnect(false)
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerBaseData) SetKv(Key int, Value string) error {
|
|
if p.KeyValueData == nil {
|
|
p.KeyValueData = make(map[int]string)
|
|
}
|
|
p.KeyValueData[Key] = Value
|
|
return nil
|
|
}
|