2328 lines
63 KiB
Go
2328 lines
63 KiB
Go
package game
|
|
|
|
import (
|
|
// "fmt"
|
|
|
|
"fmt"
|
|
"math/rand"
|
|
"sort"
|
|
|
|
// "math"
|
|
"server/GoUtil"
|
|
"server/MergeConst"
|
|
mergeDataCfg "server/conf/mergeData"
|
|
"server/db"
|
|
"server/gamedata"
|
|
"server/msg"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"server/pkg/github.com/name5566/leaf/timer"
|
|
|
|
cmap "github.com/orcaman/concurrent-map/v2"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
type PlayerDataModule interface {
|
|
LoadDataFromDB(key interface{}) bool
|
|
SaveDataFromDB(key interface{}) bool
|
|
SetPlayer(p *Player)
|
|
GetPlayer() *Player
|
|
GetData() interface{}
|
|
ClearData() bool
|
|
Reconnect(bool)
|
|
AutoSaveInterval()
|
|
}
|
|
|
|
type PlayerData struct {
|
|
Name string
|
|
IsHaveDataDb bool
|
|
M_Player *Player
|
|
}
|
|
|
|
func (d *PlayerData) SetPlayer(p *Player) {
|
|
d.M_Player = p
|
|
}
|
|
|
|
func (d *PlayerData) GetPlayer() *Player {
|
|
return d.M_Player
|
|
}
|
|
|
|
func (d *PlayerData) Reconnect(b bool) {
|
|
|
|
}
|
|
func (d *PlayerData) AutoSaveInterval() {
|
|
|
|
}
|
|
|
|
func (d *PlayerData) LoadDataFromDB(UserName interface{}) bool {
|
|
|
|
return true
|
|
}
|
|
|
|
func (d *PlayerData) SaveDataFromDB(Key interface{}) bool {
|
|
|
|
return true
|
|
}
|
|
func (d *PlayerData) ClearData() bool {
|
|
|
|
return true
|
|
}
|
|
func (d *PlayerData) GetData() interface{} {
|
|
res := struct{}{}
|
|
return res
|
|
}
|
|
|
|
func NewPlayerData(name string, player *Player) *PlayerData {
|
|
return &PlayerData{
|
|
Name: name,
|
|
M_Player: player,
|
|
}
|
|
}
|
|
|
|
type PlayerEmitDetailData struct {
|
|
*PlayerData
|
|
Data msg.ResEmitMergeMap
|
|
CountData msg.ResEmitCountMap
|
|
TimeData msg.ResEmitCDStartData
|
|
// MLeafTimerList map[int32]*timer.Timer
|
|
MLeafTimerList cmap.ConcurrentMap[string, *timer.Timer]
|
|
Mdispatr *timer.Dispatcher
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) LoadDataFromDB(dwUin interface{}) bool {
|
|
sqlStr := "SELECT * FROM t_Emit_detail_data WHERE dwUin = ?"
|
|
sqlStruck := db.SqlEmitStruct{}
|
|
p.Mdispatr = timer.NewDispatcher(1)
|
|
p.Data.MEmitMergeData = make(map[int32]int32)
|
|
p.CountData.MEmitCountData = make(map[int32]int32)
|
|
p.TimeData.MEmitCDData = make(map[int32]int32)
|
|
// p.MLeafTimerList = make(map[int32]*timer.Timer)
|
|
p.MLeafTimerList = cmap.New[*timer.Timer]()
|
|
if err := db.SqlDb.Get(&sqlStruck, sqlStr, dwUin.(int32)); err != nil {
|
|
fmt.Printf("t_Emit_detail_data get data failed, err:%v\n", err)
|
|
p.IsHaveDataDb = false
|
|
} else {
|
|
p.IsHaveDataDb = true
|
|
}
|
|
if sqlStruck.MEmitMergeData != "" {
|
|
units := strings.Split(sqlStruck.MEmitMergeData, "_")
|
|
for i := 0; i < len(units); i++ {
|
|
unit := units[i]
|
|
ss := strings.Split(unit, ",")
|
|
key, _ := strconv.ParseInt(ss[0], 10, 32)
|
|
value, _ := strconv.ParseInt(ss[1], 10, 32)
|
|
p.Data.MEmitMergeData[int32(key)] = int32(value)
|
|
}
|
|
}
|
|
if sqlStruck.MEmitCountData != "" {
|
|
units1 := strings.Split(sqlStruck.MEmitCountData, "_")
|
|
for i := 0; i < len(units1); i++ {
|
|
unit := units1[i]
|
|
ss := strings.Split(unit, ",")
|
|
key, _ := strconv.ParseInt(ss[0], 10, 32)
|
|
value, _ := strconv.ParseInt(ss[1], 10, 32)
|
|
p.CountData.MEmitCountData[int32(key)] = int32(value)
|
|
}
|
|
}
|
|
if sqlStruck.MEmitTimeData != "" {
|
|
units2 := strings.Split(sqlStruck.MEmitTimeData, "_")
|
|
for i := 0; i < len(units2); i++ {
|
|
unit := units2[i]
|
|
ss := strings.Split(unit, ",")
|
|
key, _ := strconv.ParseInt(ss[0], 10, 32)
|
|
value, _ := strconv.ParseInt(ss[1], 10, 32)
|
|
p.TimeData.MEmitCDData[int32(key)] = int32(value)
|
|
}
|
|
}
|
|
tempMap := make(map[int32]int32)
|
|
isDelete := false
|
|
for k, v := range p.TimeData.MEmitCDData {
|
|
MergeId := p.GetMergeIDByChestid(k)
|
|
if int(MergeId) != 0 {
|
|
tempMap[k] = v
|
|
} else {
|
|
isDelete = true
|
|
}
|
|
}
|
|
p.TimeData.MEmitCDData = tempMap
|
|
if isDelete {
|
|
p.SaveDataFromDB("")
|
|
}
|
|
|
|
p.Reconnect(false)
|
|
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) Reconnect(b bool) {
|
|
for k, v := range p.TimeData.MEmitCDData {
|
|
MergeId := p.GetMergeIDByChestid(k)
|
|
item, _ := mergeDataCfg.GetOne(int(MergeId))
|
|
cnt := p.M_Player.GetIFGameData("PlayerEmitUnlockData").(*PlayerEmitUnlockData).GetUnlockCntByID(k)
|
|
cool := float32(item.CoolTime)*(1.0+0.2*float32(cnt)) + float32(v)
|
|
deltaTime := int32(cool) - int32(time.Now().Unix())
|
|
if deltaTime > 0 {
|
|
EmitID := k
|
|
go func() {
|
|
|
|
LeafTimer := p.Mdispatr.AfterFunc(time.Duration(deltaTime)*time.Second, func() {
|
|
p.NotifyEmitCDTimeEndData(EmitID)
|
|
// delete(p.MLeafTimerList, EmitID)
|
|
p.MLeafTimerList.Remove(strconv.Itoa(int(EmitID)))
|
|
})
|
|
// p.MLeafTimerList[EmitID] = LeafTimer
|
|
p.MLeafTimerList.Set(strconv.Itoa(int(EmitID)), LeafTimer)
|
|
(<-p.Mdispatr.ChanTimer).Cb()
|
|
}()
|
|
} else {
|
|
delete(p.TimeData.MEmitCDData, k)
|
|
}
|
|
|
|
}
|
|
p.NotifyInitEmitCDTimeData()
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) NotifyInitEmitCDTimeData() {
|
|
notify := &msg.NotifyInitEmitCDTimeData{}
|
|
notify.MEmitCDData = make(map[int32]int32)
|
|
notify.MEmitCDData = p.TimeData.MEmitCDData
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(notify)
|
|
G_GameLogicPtr.PackResInfo(agent, "NotifyInitEmitCDTimeData", data)
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) NotifyEmitCDTimeEndData(EmitID int32) {
|
|
notify := &msg.NotifyEmitCDTimeEndData{}
|
|
notify.MEmitCDData = make(map[int32]int32)
|
|
notify.MEmitCDData[EmitID] = 0
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(notify)
|
|
G_GameLogicPtr.PackResInfo(agent, "NotifyEmitCDTimeEndData", data)
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) ClearEmitCD(id int32) {
|
|
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) ClearAllEmitCD() {
|
|
|
|
for k := range p.TimeData.MEmitCDData {
|
|
p.TimeData.MEmitCDData[k] = 0
|
|
p.ClearEmitCD(k)
|
|
}
|
|
keys := p.MLeafTimerList.Keys()
|
|
for _, k := range keys {
|
|
v, _ := p.MLeafTimerList.Get(k)
|
|
v.Disabled()
|
|
p.Mdispatr.ChanTimer <- v
|
|
v.Stop()
|
|
}
|
|
p.MLeafTimerList.Clear()
|
|
for k := range p.TimeData.MEmitCDData {
|
|
delete(p.TimeData.MEmitCDData, k)
|
|
}
|
|
|
|
p.NotifyInitEmitCDTimeData()
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) ReqEmitSubCD(buf []byte) {
|
|
update := &msg.ReqEmitSubCD{}
|
|
proto.Unmarshal(buf, update)
|
|
|
|
_, ok := p.TimeData.MEmitCDData[update.EmitID]
|
|
if ok {
|
|
if update.Type == 3 {
|
|
p.TimeData.MEmitCDData[update.EmitID] = p.TimeData.MEmitCDData[update.EmitID] - 60*30
|
|
}
|
|
///diamond
|
|
if update.Type == 2 {
|
|
p.TimeData.MEmitCDData[update.EmitID] = 0
|
|
}
|
|
///diamond
|
|
if update.Type == 4 {
|
|
p.TimeData.MEmitCDData[update.EmitID] = 0
|
|
}
|
|
if update.Type == 1 {
|
|
p.TimeData.MEmitCDData[update.EmitID] = 0
|
|
}
|
|
}
|
|
////ad
|
|
keys := p.MLeafTimerList.Keys()
|
|
for _, k := range keys {
|
|
v, _ := p.MLeafTimerList.Get(k)
|
|
v.Disabled()
|
|
p.Mdispatr.ChanTimer <- v
|
|
v.Stop()
|
|
}
|
|
p.MLeafTimerList.Clear()
|
|
|
|
for k, v := range p.TimeData.MEmitCDData {
|
|
MergeId := p.GetMergeIDByChestid(k)
|
|
item, _ := mergeDataCfg.GetOne(int(MergeId))
|
|
cnt := p.M_Player.GetIFGameData("PlayerEmitUnlockData").(*PlayerEmitUnlockData).GetUnlockCntByID(k)
|
|
cool := float32(item.CoolTime)*(1.0+0.2*float32(cnt)) + float32(v)
|
|
deltaTime := int32(cool) - int32(time.Now().Unix())
|
|
if deltaTime > 0 {
|
|
EmitID := k
|
|
go func() {
|
|
LeafTimer := p.Mdispatr.AfterFunc(time.Duration(deltaTime)*time.Second, func() {
|
|
p.NotifyEmitCDTimeEndData(EmitID)
|
|
p.MLeafTimerList.Remove(strconv.Itoa(int(EmitID)))
|
|
})
|
|
p.MLeafTimerList.Set(strconv.Itoa(int(EmitID)), LeafTimer)
|
|
(<-p.Mdispatr.ChanTimer).Cb()
|
|
}()
|
|
} else {
|
|
delete(p.TimeData.MEmitCDData, k)
|
|
}
|
|
}
|
|
p.NotifyInitEmitCDTimeData()
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) ClearData() bool {
|
|
p.SaveDataFromDB("")
|
|
keys := p.MLeafTimerList.Keys()
|
|
for _, k := range keys {
|
|
v, _ := p.MLeafTimerList.Get(k)
|
|
v.Disabled()
|
|
p.Mdispatr.ChanTimer <- v
|
|
v.Stop()
|
|
}
|
|
p.MLeafTimerList.Clear()
|
|
// for _, v := range p.MLeafTimerList {
|
|
// v.Disabled()
|
|
// p.Mdispatr.ChanTimer <- v
|
|
// v.Stop()
|
|
// }
|
|
// for k := range p.MLeafTimerList {
|
|
// delete(p.MLeafTimerList, k)
|
|
// }
|
|
|
|
return true
|
|
}
|
|
func (p *PlayerEmitDetailData) SaveDataFromDB(Key interface{}) bool {
|
|
|
|
sqlStruck := db.SqlEmitStruct{}
|
|
sqlStruck.DwUin = p.M_Player.M_DwUin
|
|
strarr := []string{}
|
|
strarr1 := []string{}
|
|
strarr2 := []string{}
|
|
for k, v := range p.Data.MEmitMergeData {
|
|
str := fmt.Sprintf("%d,%d", k, v)
|
|
strarr = append(strarr, str)
|
|
}
|
|
for k, v := range p.CountData.MEmitCountData {
|
|
str := fmt.Sprintf("%d,%d", k, v)
|
|
strarr1 = append(strarr1, str)
|
|
}
|
|
for k, v := range p.TimeData.MEmitCDData {
|
|
str := fmt.Sprintf("%d,%d", k, v)
|
|
strarr2 = append(strarr2, str)
|
|
}
|
|
str_concat := strings.Join(strarr, "_")
|
|
str_concat1 := strings.Join(strarr1, "_")
|
|
str_concat2 := strings.Join(strarr2, "_")
|
|
|
|
sqlStruck.MEmitMergeData = str_concat
|
|
sqlStruck.MEmitCountData = str_concat1
|
|
sqlStruck.MEmitTimeData = str_concat2
|
|
|
|
if p.IsHaveDataDb {
|
|
db.FormatAllMemUpdateDb(&sqlStruck, "t_Emit_detail_data", "dwUin")
|
|
} else {
|
|
db.FormatAllMemInsertDb(&sqlStruck, "t_Emit_detail_data")
|
|
}
|
|
p.IsHaveDataDb = true
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) GetMergeIDByChestid(emitId int32) int32 {
|
|
_, ok := p.Data.MEmitMergeData[emitId]
|
|
if ok {
|
|
return p.Data.MEmitMergeData[emitId]
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) SetMergeIDByChestid(emitId int32, MergeId int32) {
|
|
|
|
p.Data.MEmitMergeData[emitId] = MergeId
|
|
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) ResEmitMergeMap(buf []byte) {
|
|
update := &msg.ReqEmitMergeMap{}
|
|
proto.Unmarshal(buf, update)
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(&p.Data)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResEmitMergeMap", data)
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) ResEmitCountMap(buf []byte) {
|
|
update := &msg.ReqEmitCountMap{}
|
|
proto.Unmarshal(buf, update)
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(&p.CountData)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResEmitCountMap", data)
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) ResEmitCDStartData(buf []byte) {
|
|
update := &msg.ReqEmitCDStartData{}
|
|
proto.Unmarshal(buf, update)
|
|
|
|
MergeId := p.GetMergeIDByChestid(update.EmitID)
|
|
item, _ := mergeDataCfg.GetOne(int(MergeId))
|
|
CurTime := time.Now().Unix()
|
|
|
|
cnt := p.M_Player.GetIFGameData("PlayerEmitUnlockData").(*PlayerEmitUnlockData).GetUnlockCntByID(update.EmitID)
|
|
deltaTime := float32(item.CoolTime) * (1.0 + 0.2*float32(cnt))
|
|
if deltaTime > 0 {
|
|
EmitID := update.EmitID
|
|
go func() {
|
|
|
|
LeafTimer := p.Mdispatr.AfterFunc(time.Duration(int32(deltaTime))*time.Second, func() {
|
|
p.NotifyEmitCDTimeEndData(EmitID)
|
|
// delete(p.MLeafTimerList, EmitID)
|
|
p.MLeafTimerList.Remove(strconv.Itoa(int(EmitID)))
|
|
})
|
|
// p.MLeafTimerList[EmitID] = LeafTimer
|
|
p.MLeafTimerList.Set(strconv.Itoa(int(EmitID)), LeafTimer)
|
|
(<-p.Mdispatr.ChanTimer).Cb()
|
|
}()
|
|
p.TimeData.MEmitCDData[EmitID] = int32(CurTime)
|
|
}
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(&p.TimeData)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResEmitCDStartData", data)
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) UpdateEmitCountMap(buf []byte) {
|
|
update := &msg.UpdateEmitCountMap{}
|
|
proto.Unmarshal(buf, update)
|
|
|
|
p.CountData.MEmitCountData = update.MEmitCountData
|
|
p.SaveDataFromDB("")
|
|
}
|
|
|
|
func (p *PlayerEmitDetailData) UpdateEmitMergeMap(buf []byte) {
|
|
update := &msg.UpdateEmitMergeMap{}
|
|
proto.Unmarshal(buf, update)
|
|
|
|
p.Data.MEmitMergeData = update.MEmitMergeData
|
|
p.SaveDataFromDB("")
|
|
}
|
|
|
|
//////////////////////////////////
|
|
|
|
////////////////////////
|
|
|
|
type PlayerLevelUpPackData struct {
|
|
*PlayerData
|
|
Data msg.ResLevelUpPackInfo
|
|
}
|
|
|
|
func (p *PlayerLevelUpPackData) LoadDataFromDB(dwUin interface{}) bool {
|
|
|
|
sqlStr := "SELECT * FROM t_player_lv_Pack WHERE dwUin = ?"
|
|
sqlStruck := db.SqlLevelUpPackStruct{}
|
|
sqlStruck.CurBuyedLv = 0
|
|
if err := db.SqlDb.Get(&sqlStruck, sqlStr, dwUin.(int32)); err != nil {
|
|
fmt.Printf("get data failed, err:%v\n", err)
|
|
p.IsHaveDataDb = false
|
|
} else {
|
|
p.IsHaveDataDb = true
|
|
}
|
|
p.Data.DwUin = p.M_Player.M_DwUin
|
|
p.Data.CurBuyLv = sqlStruck.CurBuyedLv
|
|
return true
|
|
}
|
|
func (p *PlayerLevelUpPackData) Reconnect(b bool) {
|
|
|
|
}
|
|
|
|
func (p *PlayerLevelUpPackData) ClearData() bool {
|
|
p.SaveDataFromDB("")
|
|
|
|
return true
|
|
}
|
|
func (p *PlayerLevelUpPackData) SaveDataFromDB(Key interface{}) bool {
|
|
|
|
sqlStruck := db.SqlLevelUpPackStruct{}
|
|
sqlStruck.DwUin = p.M_Player.M_DwUin
|
|
sqlStruck.CurBuyedLv = p.Data.CurBuyLv
|
|
|
|
if p.IsHaveDataDb {
|
|
db.FormatAllMemUpdateDb(&sqlStruck, "t_player_lv_Pack", "dwUin")
|
|
} else {
|
|
db.FormatAllMemInsertDb(&sqlStruck, "t_player_lv_Pack")
|
|
}
|
|
p.IsHaveDataDb = true
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerLevelUpPackData) ResLevelUpPackInfo(player *Player) {
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(&p.Data)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResLevelUpPackInfo", data)
|
|
}
|
|
|
|
func (p *PlayerLevelUpPackData) ReqBuyLevelUpPack(buf []byte) {
|
|
req := &msg.ReqBuyLevelUpPack{}
|
|
res := &msg.ResBuyLevelUpPack{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
list := gamedata.GetConfigByName("LevelUpBuyPack").Indexes(1)
|
|
recode, ok := list[int(req.CurBuyLv)]
|
|
if ok {
|
|
if req.CurBuyLv <= p.Data.CurBuyLv {
|
|
res.ResultCode = MergeConst.Protocol_LvUpPack_Buyed
|
|
} else {
|
|
recode = recode.(*gamedata.LevelUpPackRecord)
|
|
res.ResultCode = 0
|
|
res.CurBuyLv = req.CurBuyLv
|
|
p.Data.CurBuyLv = req.CurBuyLv
|
|
p.SaveDataFromDB("")
|
|
}
|
|
} else {
|
|
res.ResultCode = MergeConst.Protocol_LvUpPack_No_Exsit
|
|
}
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResBuyLevelUpPack", data)
|
|
}
|
|
|
|
////////////////////////
|
|
|
|
type PlayerGrowthFundData struct {
|
|
*PlayerData
|
|
Data msg.ResGrowthFundInfo
|
|
}
|
|
|
|
func (p *PlayerGrowthFundData) LoadDataFromDB(dwUin interface{}) bool {
|
|
|
|
sqlStr := "SELECT * FROM t_player_growth_fund WHERE dwUin = ?"
|
|
sqlStruck := db.SqlGrowthFundStruct{}
|
|
sqlStruck.CurBuyLv = ""
|
|
sqlStruck.IsBuy = 0
|
|
if err := db.SqlDb.Get(&sqlStruck, sqlStr, dwUin.(int32)); err != nil {
|
|
fmt.Printf("get data failed, err:%v\n", err)
|
|
p.IsHaveDataDb = false
|
|
} else {
|
|
p.IsHaveDataDb = true
|
|
}
|
|
p.Data.DwUin = p.M_Player.M_DwUin
|
|
p.Data.CurBuyLv = sqlStruck.CurBuyLv
|
|
p.Data.IsBuy = sqlStruck.IsBuy
|
|
return true
|
|
}
|
|
func (p *PlayerGrowthFundData) Reconnect(b bool) {
|
|
|
|
}
|
|
|
|
func (p *PlayerGrowthFundData) ClearData() bool {
|
|
p.SaveDataFromDB("")
|
|
|
|
return true
|
|
}
|
|
func (p *PlayerGrowthFundData) SaveDataFromDB(Key interface{}) bool {
|
|
|
|
sqlStruck := db.SqlGrowthFundStruct{}
|
|
sqlStruck.DwUin = p.M_Player.M_DwUin
|
|
sqlStruck.CurBuyLv = p.Data.CurBuyLv
|
|
sqlStruck.IsBuy = p.Data.IsBuy
|
|
if p.IsHaveDataDb {
|
|
db.FormatAllMemUpdateDb(&sqlStruck, "t_player_growth_fund", "dwUin")
|
|
} else {
|
|
db.FormatAllMemInsertDb(&sqlStruck, "t_player_growth_fund")
|
|
}
|
|
p.IsHaveDataDb = true
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerGrowthFundData) ResGrowthFundInfo(player *Player) {
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(&p.Data)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResGrowthFundInfo", data)
|
|
}
|
|
|
|
func (p *PlayerGrowthFundData) ReqBuyGrowthFund(buf []byte) {
|
|
req := &msg.ReqBuyGrowthFund{}
|
|
res := &msg.ResBuyGrowthFund{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
p.Data.IsBuy = 1
|
|
res.ResultCode = 0
|
|
p.SaveDataFromDB("")
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResBuyGrowthFund", data)
|
|
}
|
|
|
|
func (p *PlayerGrowthFundData) ReqGetGrowthFundWard(buf []byte) {
|
|
req := &msg.ReqGetGrowthFundWard{}
|
|
res := &msg.ResGetGrowthFundWard{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
res.ResultCode = 0
|
|
res.CurBuyLv = req.CurBuyLv
|
|
isGet := false
|
|
if p.Data.CurBuyLv != "" {
|
|
units := strings.Split(p.Data.CurBuyLv, ",")
|
|
for i := 0; i < len(units); i++ {
|
|
con, _ := strconv.Atoi(units[i])
|
|
if con == int(req.CurBuyLv) {
|
|
isGet = true
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
if !isGet {
|
|
res.ResultCode = 0
|
|
if p.Data.CurBuyLv == "" {
|
|
p.Data.CurBuyLv = strconv.Itoa(int(req.CurBuyLv))
|
|
} else {
|
|
p.Data.CurBuyLv = p.Data.CurBuyLv + "," + strconv.Itoa(int(req.CurBuyLv))
|
|
}
|
|
|
|
} else {
|
|
res.ResultCode = MergeConst.Protocol_GrowthFund_Geted
|
|
}
|
|
p.SaveDataFromDB("")
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResGetGrowthFundWard", data)
|
|
}
|
|
|
|
////////////////////////
|
|
|
|
type PlayerSupermeGiftData struct {
|
|
*PlayerData
|
|
Data msg.ResSupremeGiftInfo
|
|
Mdispatr *timer.Dispatcher
|
|
MLeafTimer *timer.Timer
|
|
MLeafTimer1 *timer.Timer
|
|
}
|
|
|
|
func (p *PlayerSupermeGiftData) LoadDataFromDB(dwUin interface{}) bool {
|
|
|
|
sqlStr := "SELECT * FROM t_player_supremeGift_data WHERE dwUin = ?"
|
|
sqlStruck := db.SqlSupermeGiftStruct{}
|
|
|
|
sqlStruck.IsBuy = 0
|
|
if err := db.SqlDb.Get(&sqlStruck, sqlStr, dwUin.(int32)); err != nil {
|
|
fmt.Printf("get data failed, err:%v\n", err)
|
|
p.IsHaveDataDb = false
|
|
} else {
|
|
p.IsHaveDataDb = true
|
|
}
|
|
p.Data.DwUin = p.M_Player.M_DwUin
|
|
|
|
p.Data.IsBuy = sqlStruck.IsBuy
|
|
p.Data.NoAdStartTime = sqlStruck.NoAdStartTime
|
|
p.Data.NoAdEndTime = sqlStruck.NoAdEndTime
|
|
p.Data.StorgeEndTime = sqlStruck.StorgeEndTime
|
|
p.Data.StorgeStartTime = sqlStruck.StorgeStartTime
|
|
p.Mdispatr = timer.NewDispatcher(2)
|
|
p.Reconnect(false)
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerSupermeGiftData) CreateTimer() {
|
|
|
|
curSvrTime := int32(time.Now().Unix())
|
|
if p.Data.NoAdEndTime > curSvrTime {
|
|
go func() {
|
|
// 注释内容也可以使用
|
|
t1 := (p.Data.NoAdEndTime) - curSvrTime
|
|
|
|
p.MLeafTimer = p.Mdispatr.AfterFunc(time.Duration(t1)*time.Second, func() {
|
|
|
|
p.NotifySupremeGiftTimeOver(1)
|
|
p.MLeafTimer = nil
|
|
|
|
})
|
|
|
|
(<-p.Mdispatr.ChanTimer).Cb()
|
|
|
|
}()
|
|
}
|
|
if p.Data.StorgeEndTime > curSvrTime {
|
|
go func() {
|
|
// 注释内容也可以使用
|
|
t1 := (p.Data.StorgeEndTime) - curSvrTime
|
|
|
|
p.MLeafTimer1 = p.Mdispatr.AfterFunc(time.Duration(t1)*time.Second, func() {
|
|
p.NotifySupremeGiftTimeOver(2)
|
|
p.MLeafTimer1 = nil
|
|
})
|
|
(<-p.Mdispatr.ChanTimer).Cb()
|
|
}()
|
|
}
|
|
|
|
}
|
|
|
|
func (p *PlayerSupermeGiftData) Reconnect(b bool) {
|
|
|
|
p.CreateTimer()
|
|
|
|
}
|
|
|
|
func (p *PlayerSupermeGiftData) ClearData() bool {
|
|
p.SaveDataFromDB("")
|
|
if p.MLeafTimer != nil {
|
|
p.MLeafTimer.Stop()
|
|
p.MLeafTimer = nil
|
|
}
|
|
if p.MLeafTimer1 != nil {
|
|
p.MLeafTimer1.Stop()
|
|
p.MLeafTimer1 = nil
|
|
}
|
|
return true
|
|
}
|
|
func (p *PlayerSupermeGiftData) SaveDataFromDB(Key interface{}) bool {
|
|
|
|
sqlStruck := db.SqlSupermeGiftStruct{}
|
|
sqlStruck.DwUin = p.M_Player.M_DwUin
|
|
sqlStruck.NoAdStartTime = p.Data.NoAdStartTime
|
|
sqlStruck.NoAdEndTime = p.Data.NoAdEndTime
|
|
sqlStruck.StorgeStartTime = p.Data.StorgeStartTime
|
|
sqlStruck.StorgeEndTime = p.Data.StorgeEndTime
|
|
sqlStruck.IsBuy = p.Data.IsBuy
|
|
|
|
// if p.IsHaveDataDb {
|
|
// db.FormatAllMemUpdateDb(&sqlStruck, "t_player_supremeGift_data", "dwUin")
|
|
// } else {
|
|
// db.FormatAllMemInsertDb(&sqlStruck, "t_player_supremeGift_data")
|
|
// }
|
|
p.IsHaveDataDb = true
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerSupermeGiftData) ResSupremeGiftInfo(player *Player) {
|
|
|
|
p.Data.CurSvrTime = int32(time.Now().Unix())
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(&p.Data)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResSupremeGiftInfo", data)
|
|
}
|
|
|
|
func (p *PlayerSupermeGiftData) ReqBuySupremeGift(buf []byte) {
|
|
req := &msg.ReqBuySupremeGift{}
|
|
res := &msg.ResBuySupremeGift{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
res.ResultCode = 0
|
|
res.NoAdStartTime = int32(time.Now().Unix())
|
|
res.NoAdEndTime = res.NoAdStartTime + 3600*24
|
|
|
|
res.StorgeStartTime = res.NoAdStartTime
|
|
res.StorgeEndTime = res.StorgeStartTime + 3600*24
|
|
res.CurSvrTime = res.NoAdStartTime
|
|
|
|
p.Data.IsBuy = 1
|
|
p.Data.NoAdStartTime = res.NoAdStartTime
|
|
p.Data.NoAdEndTime = res.NoAdStartTime + 3600*24
|
|
|
|
p.Data.StorgeStartTime = res.NoAdStartTime
|
|
p.Data.StorgeEndTime = res.StorgeStartTime + 3600*24
|
|
p.Data.CurSvrTime = res.NoAdStartTime
|
|
|
|
p.SaveDataFromDB("")
|
|
p.CreateTimer()
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResBuySupremeGift", data)
|
|
}
|
|
|
|
func (p *PlayerSupermeGiftData) NotifySupremeGiftTimeOver(type1 int32) {
|
|
notify := &msg.NotifySupremeGiftTimeOver{}
|
|
notify.Type = type1
|
|
notify.CurSvrTime = int32(time.Now().Unix())
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(notify)
|
|
G_GameLogicPtr.PackResInfo(agent, "NotifySupremeGiftTimeOver", data)
|
|
}
|
|
|
|
/////////////////////////////////////////////
|
|
|
|
type PlayerIllustrateData struct {
|
|
*PlayerData
|
|
Data msg.ResIllustratedInfo
|
|
sqlStrucks []db.SqlIllustrateStruct
|
|
}
|
|
|
|
func (p *PlayerIllustrateData) LoadDataFromDB(dwUin interface{}) bool {
|
|
|
|
sqlStr := "SELECT * FROM t_player_illustrated_data WHERE dwUin = ?"
|
|
p.sqlStrucks = []db.SqlIllustrateStruct{}
|
|
|
|
if err := db.SqlDb.Select(&p.sqlStrucks, sqlStr, dwUin.(int32)); err != nil {
|
|
fmt.Printf("get data failed, err:%v\n", err)
|
|
p.IsHaveDataDb = false
|
|
} else {
|
|
p.IsHaveDataDb = true
|
|
}
|
|
p.Data.DwUin = p.M_Player.M_DwUin
|
|
p.Data.Datas = []*msg.CategoryIllustratedData{}
|
|
|
|
for i := 0; i < len(p.sqlStrucks); i++ {
|
|
data := msg.CategoryIllustratedData{}
|
|
data.Category = p.sqlStrucks[i].Category
|
|
data.Items = []*msg.SingleIllustratedItem{}
|
|
data.IllustratedID = p.sqlStrucks[i].IllustratedID
|
|
str := p.sqlStrucks[i].ItemInfoStr
|
|
if str != "" {
|
|
MergeInfo := strings.Split(str, ";")
|
|
for m := 0; m < len(MergeInfo); m++ {
|
|
item := MergeInfo[m]
|
|
units := strings.Split(item, ",")
|
|
single := msg.SingleIllustratedItem{}
|
|
MergeId, _ := strconv.Atoi(units[0])
|
|
Status, _ := strconv.Atoi(units[1])
|
|
single.MergeId = int32(MergeId)
|
|
single.Status = int32(Status)
|
|
data.Items = append(data.Items, &single)
|
|
}
|
|
}
|
|
p.Data.Datas = append(p.Data.Datas, &data)
|
|
}
|
|
p.Reconnect(false)
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerIllustrateData) Reconnect(b bool) {
|
|
|
|
}
|
|
|
|
func (p *PlayerIllustrateData) ClearData() bool {
|
|
p.SaveDataFromDB("")
|
|
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerIllustrateData) SaveDataFromDBSingle(Category string, isUpdate bool) {
|
|
|
|
// dbs db.SqlIllustrateStruct
|
|
|
|
data := p.FindIllustratedDataByCategory(Category)
|
|
sqlStruck := db.SqlIllustrateStruct{}
|
|
sqlStruck.Category = Category
|
|
sqlStruck.DwUin = p.M_Player.M_DwUin
|
|
sqlStruck.IllustrateType = 1
|
|
sqlStruck.IllustratedID = data.IllustratedID
|
|
sqlStruck.ItemInfoStr = ""
|
|
|
|
finalStr := []string{}
|
|
for i := 0; i < len(data.Items); i++ {
|
|
temp := strconv.Itoa(int(data.Items[i].MergeId)) + "," + strconv.Itoa(int(data.Items[i].Status))
|
|
finalStr = append(finalStr, temp)
|
|
}
|
|
|
|
sqlStruck.ItemInfoStr = strings.Join(finalStr, ";")
|
|
if isUpdate {
|
|
db.FormatAllMemUpdateDb(&sqlStruck, "t_player_illustrated_data", "IllustratedID")
|
|
} else {
|
|
insertID, _ := db.FormatAllMemInsertDb(&sqlStruck, "t_player_illustrated_data")
|
|
data.IllustratedID = int32(insertID)
|
|
}
|
|
}
|
|
|
|
func (p *PlayerIllustrateData) SaveDataFromDB(Key interface{}) bool {
|
|
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerIllustrateData) ResIllustratedInfo(player *Player) {
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(&p.Data)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResIllustratedInfo", data)
|
|
}
|
|
|
|
func (p *PlayerIllustrateData) FindIllustratedDataByCategory(Category string) *msg.CategoryIllustratedData {
|
|
for i := 0; i < len(p.Data.Datas); i++ {
|
|
if p.Data.Datas[i].Category == Category {
|
|
return p.Data.Datas[i]
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *PlayerIllustrateData) FindMergeInfoById(mergeId int32, data *msg.CategoryIllustratedData) *msg.SingleIllustratedItem {
|
|
for i := 0; i < len(data.Items); i++ {
|
|
if mergeId == data.Items[i].MergeId {
|
|
return data.Items[i]
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *PlayerIllustrateData) ReqGetIllustrateItemReward(buf []byte) {
|
|
req := &msg.ReqGetIllustrateItemReward{}
|
|
res := &msg.ResGetIllustrateItemReward{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
res.ResultCode = 0
|
|
res.Category = req.Category
|
|
data := p.FindIllustratedDataByCategory(req.Category)
|
|
if data == nil {
|
|
res.ResultCode = MergeConst.Protocol_Illustrate_InActive
|
|
} else {
|
|
Item := p.FindMergeInfoById(req.MergeId, data)
|
|
if Item != nil {
|
|
if Item.Status == 1 {
|
|
res.ResultCode = MergeConst.Protocol_Illustrate_InActive
|
|
}
|
|
if Item.Status == 3 {
|
|
res.ResultCode = MergeConst.Protocol_Illustrate_Geted
|
|
}
|
|
if Item.Status == 2 {
|
|
res.ResultCode = 0
|
|
res.Status = 3
|
|
res.MergeId = req.MergeId
|
|
Item.Status = 3
|
|
p.SaveDataFromDBSingle(req.Category, true)
|
|
}
|
|
} else {
|
|
res.ResultCode = MergeConst.Protocol_Illustrate_InActive
|
|
}
|
|
|
|
}
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data1, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResGetIllustrateItemReward", data1)
|
|
}
|
|
|
|
func (p *PlayerIllustrateData) UpdateIllustrateItem(buf []byte) {
|
|
update := &msg.UpdateIllustrateItem{}
|
|
proto.Unmarshal(buf, update)
|
|
data := p.FindIllustratedDataByCategory(update.Category)
|
|
if data != nil {
|
|
Item := p.FindMergeInfoById(update.MergeId, data)
|
|
if Item != nil {
|
|
Item.Status = update.Status
|
|
} else {
|
|
item := &msg.SingleIllustratedItem{}
|
|
item.MergeId = update.MergeId
|
|
item.Status = update.Status
|
|
data.Items = append(data.Items, item)
|
|
}
|
|
p.SaveDataFromDBSingle(update.Category, true)
|
|
} else {
|
|
newdata := &msg.CategoryIllustratedData{}
|
|
newdata.Category = update.Category
|
|
newdata.IllustratedID = 0
|
|
newdata.Items = []*msg.SingleIllustratedItem{}
|
|
item := &msg.SingleIllustratedItem{}
|
|
item.MergeId = update.MergeId
|
|
item.Status = update.Status
|
|
newdata.Items = append(newdata.Items, item)
|
|
p.Data.Datas = append(p.Data.Datas, newdata)
|
|
p.SaveDataFromDBSingle(update.Category, false)
|
|
}
|
|
|
|
}
|
|
|
|
//////////////////////////////
|
|
|
|
type PlayerDailyTaskData struct {
|
|
*PlayerData
|
|
Data msg.ResDailyTaskData
|
|
sqlStruck db.SqlDailyTaskStruct
|
|
Mdispatr *timer.Dispatcher
|
|
MLeafTimer *timer.Timer
|
|
MTicker *time.Ticker
|
|
// MLeafTimer1 *timer.Timer
|
|
}
|
|
|
|
func (p *PlayerDailyTaskData) LoadDataFromDB(dwUin interface{}) bool {
|
|
|
|
sqlStr := "SELECT * FROM t_player_daily_task_data WHERE dwUin = ?"
|
|
|
|
p.Data.TodayTaskList = []string{}
|
|
p.sqlStruck = db.SqlDailyTaskStruct{}
|
|
p.sqlStruck.DwUin = dwUin.(int32)
|
|
if err := db.SqlDb.Get(&p.sqlStruck, sqlStr, dwUin.(int32)); err != nil {
|
|
fmt.Printf("get data failed, err:%v\n", err)
|
|
p.IsHaveDataDb = false
|
|
} else {
|
|
p.IsHaveDataDb = true
|
|
}
|
|
|
|
p.Data.DwUin = p.sqlStruck.DwUin
|
|
p.Data.NowSortId = p.sqlStruck.NowSortId
|
|
p.Data.NowTaskProgress = p.sqlStruck.NowTaskProgress
|
|
p.Data.WeekActive = p.sqlStruck.WeekyActive
|
|
p.Data.CurSvrTime = int32(time.Now().Unix())
|
|
if p.sqlStruck.TodayTaskList != "" {
|
|
strarr := strings.Split(p.sqlStruck.TodayTaskList, ";")
|
|
|
|
for i := 0; i < len(strarr); i++ {
|
|
p.Data.TodayTaskList = append(p.Data.TodayTaskList, strarr[i])
|
|
}
|
|
}
|
|
|
|
p.Mdispatr = timer.NewDispatcher(1)
|
|
p.Reconnect(false)
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerDailyTaskData) Notify_Daily_Renew(param []interface{}) {
|
|
p.NotifyRenewDailyTask()
|
|
}
|
|
|
|
func (p *PlayerDailyTaskData) CreateTimer() {
|
|
|
|
timeStamp := time.Now().Unix()
|
|
t := time.Unix(timeStamp, 0).Local()
|
|
// zero := timeStamp - (int64)(t.Hour()*3600+t.Minute()*60+t.Second())
|
|
var week = t.Weekday()
|
|
if t.Weekday() == 0 {
|
|
week = 7
|
|
}
|
|
go func() {
|
|
// 注释内容也可以使用
|
|
p.MLeafTimer = p.Mdispatr.AfterFunc(time.Duration(3600*24*7-(int32)(week-1)*3600*24-(int32)(t.Hour()*3600+t.Minute()*60+t.Second()))*time.Second, func() {
|
|
p.NotifyRenewWeekyActive()
|
|
p.MLeafTimer = nil
|
|
|
|
p.MTicker = time.NewTicker(time.Second * time.Duration(3600*24*7))
|
|
for {
|
|
select {
|
|
case <-p.MTicker.C:
|
|
p.NotifyRenewWeekyActive()
|
|
}
|
|
}
|
|
})
|
|
(<-p.Mdispatr.ChanTimer).Cb()
|
|
|
|
}()
|
|
|
|
if timeStamp >= int64(p.sqlStruck.StartDailySvrTime)+3600*24 {
|
|
p.NotifyRenewDailyTask()
|
|
}
|
|
if timeStamp >= int64(p.sqlStruck.StartWeekySvrTime)+3600*24*7 {
|
|
p.NotifyRenewWeekyActive()
|
|
}
|
|
|
|
GoUtil.RegisterEvent(MergeConst.Notify_Daily_Renew, p.Notify_Daily_Renew, p)
|
|
|
|
}
|
|
|
|
func (p *PlayerDailyTaskData) Reconnect(b bool) {
|
|
|
|
p.CreateTimer()
|
|
|
|
}
|
|
|
|
func (p *PlayerDailyTaskData) ClearData() bool {
|
|
p.SaveDataFromDB("")
|
|
if p.MLeafTimer != nil {
|
|
p.MLeafTimer.Stop()
|
|
p.MLeafTimer = nil
|
|
}
|
|
if p.MTicker != nil {
|
|
p.MTicker.Stop()
|
|
p.MTicker = nil
|
|
}
|
|
GoUtil.RemoveEvent(MergeConst.Notify_Daily_Renew, p.Notify_Daily_Renew, p)
|
|
return true
|
|
}
|
|
func (p *PlayerDailyTaskData) SaveDataFromDB(Key interface{}) bool {
|
|
if p.IsHaveDataDb {
|
|
db.FormatAllMemUpdateDb(&p.sqlStruck, "t_player_daily_task_data", "dwUin")
|
|
} else {
|
|
db.FormatAllMemInsertDb(&p.sqlStruck, "t_player_daily_task_data")
|
|
}
|
|
p.IsHaveDataDb = true
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerDailyTaskData) ResDailyTaskData(player *Player) {
|
|
|
|
p.Data.CurSvrTime = int32(time.Now().Unix())
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
|
|
data, _ := proto.Marshal(&p.Data)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResDailyTaskData", data)
|
|
}
|
|
|
|
func (p *PlayerDailyTaskData) UpdateDailyTaskData(buf []byte) {
|
|
req := &msg.UpdateDailyTaskData{}
|
|
|
|
proto.Unmarshal(buf, req)
|
|
|
|
p.Data.NowSortId = req.NowSortId
|
|
p.Data.NowTaskProgress = req.NowTaskProgress
|
|
p.Data.WeekActive = req.WeekActive
|
|
p.Data.TodayTaskList = req.TodayTaskList
|
|
|
|
p.sqlStruck.TodayTaskList = strings.Join(req.TodayTaskList, ";")
|
|
p.sqlStruck.NowSortId = req.NowSortId
|
|
p.sqlStruck.NowTaskProgress = req.NowTaskProgress
|
|
p.sqlStruck.WeekyActive = req.WeekActive
|
|
p.SaveDataFromDB("")
|
|
|
|
}
|
|
|
|
func (p *PlayerDailyTaskData) NotifyRenewDailyTask() {
|
|
notify := &msg.NotifyRenewDailyTask{}
|
|
notify.DwUin = p.sqlStruck.DwUin
|
|
notify.CurSvrTime = int32(time.Now().Unix())
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(notify)
|
|
G_GameLogicPtr.PackResInfo(agent, "NotifyRenewDailyTask", data)
|
|
}
|
|
|
|
func (p *PlayerDailyTaskData) NotifyRenewWeekyActive() {
|
|
notify := &msg.NotifyRenewWeekyActive{}
|
|
notify.DwUin = p.sqlStruck.DwUin
|
|
notify.CurSvrTime = int32(time.Now().Unix())
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(notify)
|
|
G_GameLogicPtr.PackResInfo(agent, "NotifyRenewWeekyActive", data)
|
|
}
|
|
|
|
func (p *PlayerDailyTaskData) RenewDailyTaskData(buf []byte) {
|
|
req := &msg.RenewDailyTaskData{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
timeStamp := time.Now().Unix()
|
|
t := time.Unix(timeStamp, 0).Local()
|
|
zero := timeStamp - (int64)(t.Hour()*3600+t.Minute()*60+t.Second())
|
|
|
|
p.Data.NowSortId = req.NowSortId
|
|
p.Data.NowTaskProgress = req.NowTaskProgress
|
|
// p.Data.WeekActive = req.WeekActive
|
|
p.Data.TodayTaskList = req.TodayTaskList
|
|
|
|
p.sqlStruck.StartDailySvrTime = int32(zero)
|
|
p.sqlStruck.TodayTaskList = strings.Join(req.TodayTaskList, ";")
|
|
p.sqlStruck.NowSortId = req.NowSortId
|
|
p.sqlStruck.NowTaskProgress = req.NowTaskProgress
|
|
// p.sqlStruck.WeekyActive = req.WeekActive
|
|
|
|
p.SaveDataFromDB("")
|
|
}
|
|
|
|
func (p *PlayerDailyTaskData) RenewWeekyActiveData(buf []byte) {
|
|
req := &msg.RenewWeekyActiveData{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
p.Data.WeekActive = req.WeekActive
|
|
|
|
timeStamp := time.Now().Unix()
|
|
t := time.Unix(timeStamp, 0).Local()
|
|
|
|
var week = t.Weekday()
|
|
if t.Weekday() == 0 {
|
|
week = 7
|
|
}
|
|
|
|
p.sqlStruck.StartWeekySvrTime = int32(timeStamp - (int64)(week-1)*3600*24 - (int64)(t.Hour()*3600+t.Minute()*60+t.Second()))
|
|
|
|
p.sqlStruck.WeekyActive = req.WeekActive
|
|
p.SaveDataFromDB("")
|
|
}
|
|
|
|
/////////////////////////
|
|
|
|
type PlayerMilestoneData struct {
|
|
*PlayerData
|
|
Data msg.ResMileStoneData
|
|
sqlStruck db.SqlMileStoneStruct
|
|
|
|
// MLeafTimer1 *timer.Timer
|
|
}
|
|
|
|
func (p *PlayerMilestoneData) LoadDataFromDB(dwUin interface{}) bool {
|
|
|
|
sqlStr := "SELECT * FROM t_milestone_data WHERE dwUin = ?"
|
|
|
|
p.Data.MileStoneTaskList = []string{}
|
|
p.sqlStruck = db.SqlMileStoneStruct{}
|
|
p.sqlStruck.DwUin = dwUin.(int32)
|
|
if err := db.SqlDb.Get(&p.sqlStruck, sqlStr, dwUin.(int32)); err != nil {
|
|
fmt.Printf("get data failed, err:%v\n", err)
|
|
p.IsHaveDataDb = false
|
|
} else {
|
|
p.IsHaveDataDb = true
|
|
}
|
|
|
|
p.Data.DwUin = p.sqlStruck.DwUin
|
|
p.Data.Score = p.sqlStruck.MileStoneScore
|
|
p.Data.StartSvrTime = p.sqlStruck.StartMileStoneTime
|
|
p.Data.CurSvrTime = int32(time.Now().Unix())
|
|
p.Data.OpenSvrTime = G_GameLogicPtr.M_SvrGlobal.OpenSvrTime
|
|
if p.sqlStruck.MileStoneTaskList != "" {
|
|
strarr := strings.Split(p.sqlStruck.MileStoneTaskList, ";")
|
|
|
|
for i := 0; i < len(strarr); i++ {
|
|
p.Data.MileStoneTaskList = append(p.Data.MileStoneTaskList, strarr[i])
|
|
}
|
|
}
|
|
|
|
p.Reconnect(false)
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerMilestoneData) Notify_MileStone_Renew(param []interface{}) {
|
|
|
|
p.NotifyRenewMileStone(param[0].(int32))
|
|
}
|
|
|
|
func (p *PlayerMilestoneData) Reconnect(b bool) {
|
|
if p.Data.StartSvrTime < G_GameLogicPtr.M_SvrGlobal.StartMileStoneSvrTime {
|
|
var a1 = []interface{}{G_GameLogicPtr.M_SvrGlobal.StartMileStoneSvrTime}
|
|
p.Notify_MileStone_Renew(a1)
|
|
}
|
|
GoUtil.RegisterEvent(MergeConst.Notify_MileStone_Renew, p.Notify_MileStone_Renew, p)
|
|
|
|
}
|
|
|
|
func (p *PlayerMilestoneData) ClearData() bool {
|
|
p.SaveDataFromDB("")
|
|
|
|
GoUtil.RemoveEvent(MergeConst.Notify_MileStone_Renew, p.Notify_MileStone_Renew, p)
|
|
return true
|
|
}
|
|
func (p *PlayerMilestoneData) SaveDataFromDB(Key interface{}) bool {
|
|
if p.IsHaveDataDb {
|
|
db.FormatAllMemUpdateDb(&p.sqlStruck, "t_milestone_data", "dwUin")
|
|
} else {
|
|
db.FormatAllMemInsertDb(&p.sqlStruck, "t_milestone_data")
|
|
}
|
|
p.IsHaveDataDb = true
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerMilestoneData) ResMileStoneData(player *Player) {
|
|
|
|
p.Data.CurSvrTime = int32(time.Now().Unix())
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
|
|
data, _ := proto.Marshal(&p.Data)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResMileStoneData", data)
|
|
}
|
|
|
|
func (p *PlayerMilestoneData) UpdateMileStoneData(buf []byte) {
|
|
req := &msg.UpdateMileStoneData{}
|
|
|
|
proto.Unmarshal(buf, req)
|
|
|
|
p.Data.MileStoneTaskList = req.MileStoneTaskList
|
|
p.Data.Score = req.Score
|
|
|
|
p.sqlStruck.MileStoneTaskList = strings.Join(req.MileStoneTaskList, ";")
|
|
p.sqlStruck.MileStoneScore = req.Score
|
|
|
|
p.SaveDataFromDB("")
|
|
|
|
}
|
|
|
|
func (p *PlayerMilestoneData) NotifyRenewMileStone(renewTime int32) {
|
|
notify := &msg.NotifyRenewMileStone{}
|
|
notify.DwUin = p.sqlStruck.DwUin
|
|
notify.CurSvrTime = int32(time.Now().Unix())
|
|
notify.StartSvrTime = renewTime
|
|
|
|
p.Data.StartSvrTime = renewTime
|
|
p.Data.Score = 0
|
|
|
|
p.sqlStruck.StartMileStoneTime = renewTime
|
|
p.sqlStruck.MileStoneScore = 0
|
|
|
|
p.SaveDataFromDB("")
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(notify)
|
|
G_GameLogicPtr.PackResInfo(agent, "NotifyRenewMileStone", data)
|
|
}
|
|
|
|
func (p *PlayerMilestoneData) RenewMileStoneData(buf []byte) {
|
|
req := &msg.RenewMileStoneData{}
|
|
proto.Unmarshal(buf, req)
|
|
p.Data.Score = req.Score
|
|
p.Data.MileStoneTaskList = req.MileStoneTaskList
|
|
|
|
p.sqlStruck.MileStoneTaskList = strings.Join(req.MileStoneTaskList, ";")
|
|
|
|
p.SaveDataFromDB("")
|
|
}
|
|
|
|
/////
|
|
|
|
/////////////////////////
|
|
|
|
type PlayerPetData struct {
|
|
*PlayerData
|
|
Data msg.ResPlayerPetData
|
|
sqlStruck db.SqlPlayerPetData
|
|
|
|
// MLeafTimer1 *timer.Timer
|
|
}
|
|
|
|
func (p *PlayerPetData) LoadDataFromDB(dwUin interface{}) bool {
|
|
|
|
sqlStr := "SELECT * FROM t_player_Pet_Data WHERE dwUin = ?"
|
|
|
|
p.sqlStruck = db.SqlPlayerPetData{}
|
|
p.sqlStruck.DwUin = dwUin.(int32)
|
|
if err := db.SqlDb.Get(&p.sqlStruck, sqlStr, dwUin.(int32)); err != nil {
|
|
fmt.Printf("get data failed, err:%v\n", err)
|
|
p.IsHaveDataDb = false
|
|
p.sqlStruck.ImageFrame = 1
|
|
p.sqlStruck.ImageIcon = 1
|
|
} else {
|
|
p.IsHaveDataDb = true
|
|
}
|
|
|
|
p.Data.DwUin = p.sqlStruck.DwUin
|
|
p.Data.ImageFrame = p.sqlStruck.ImageFrame
|
|
p.Data.ImageIcon = p.sqlStruck.ImageIcon
|
|
p.Data.PetNickName = p.sqlStruck.PetNickName
|
|
p.Data.UnlockFrame = p.sqlStruck.UnlockFrame
|
|
p.Data.UnlockIcon = p.sqlStruck.UnlockIcon
|
|
|
|
p.Reconnect(false)
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerPetData) Reconnect(b bool) {
|
|
|
|
}
|
|
|
|
func (p *PlayerPetData) ClearData() bool {
|
|
p.SaveDataFromDB("")
|
|
|
|
return true
|
|
}
|
|
func (p *PlayerPetData) SaveDataFromDB(Key interface{}) bool {
|
|
if p.IsHaveDataDb {
|
|
db.FormatAllMemUpdateDb(&p.sqlStruck, "t_player_Pet_Data", "dwUin")
|
|
} else {
|
|
db.FormatAllMemInsertDb(&p.sqlStruck, "t_player_Pet_Data")
|
|
}
|
|
p.IsHaveDataDb = true
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerPetData) ReqPlayerPetData(player *Player) {
|
|
|
|
p.SaveDataFromDB("")
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(&p.Data)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResPlayerPetData", data)
|
|
}
|
|
|
|
func (p *PlayerPetData) ReqUpdatePetProfile(buf []byte) {
|
|
req := &msg.ReqUpdatePetProfile{}
|
|
res := &msg.ResUpdatePetProfile{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
res.Type = req.Type
|
|
res.Param = req.Param
|
|
res.ResultCode = 0
|
|
res.DwUin = p.M_Player.M_DwUin
|
|
if req.Type == 1 {
|
|
p.Data.PetNickName = req.Param
|
|
p.sqlStruck.PetNickName = req.Param
|
|
}
|
|
if req.Type == 2 {
|
|
value, _ := strconv.Atoi(req.Param)
|
|
p.Data.ImageFrame = int32(value)
|
|
p.sqlStruck.ImageFrame = int32(value)
|
|
}
|
|
if req.Type == 3 {
|
|
value, _ := strconv.Atoi(req.Param)
|
|
p.Data.ImageIcon = int32(value)
|
|
p.sqlStruck.ImageIcon = int32(value)
|
|
}
|
|
|
|
p.SaveDataFromDB("")
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResUpdatePetProfile", data)
|
|
}
|
|
|
|
/////////////////////////
|
|
|
|
//////////////
|
|
|
|
type PlayerPetHomeData struct {
|
|
*PlayerData
|
|
Data msg.ResPetHomeData
|
|
sqlStruck db.SqlPetHomeData
|
|
Mdispatr *timer.Dispatcher
|
|
|
|
MLeafTimer *timer.Timer
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) LoadDataFromDB(dwUin interface{}) bool {
|
|
|
|
sqlStr := "SELECT * FROM t_player_PetHome_Data WHERE dwUin = ?"
|
|
|
|
p.sqlStruck = db.SqlPetHomeData{}
|
|
p.sqlStruck.DwUin = dwUin.(int32)
|
|
if err := db.SqlDb.Get(&p.sqlStruck, sqlStr, dwUin.(int32)); err != nil {
|
|
fmt.Printf("get data failed, err:%v\n", err)
|
|
p.IsHaveDataDb = false
|
|
} else {
|
|
p.IsHaveDataDb = true
|
|
}
|
|
|
|
if !p.IsHaveDataDb {
|
|
p.sqlStruck.DwUin = dwUin.(int32)
|
|
p.sqlStruck.NestId = 1
|
|
p.sqlStruck.OrnamentsId = 1
|
|
} else {
|
|
|
|
}
|
|
timeStamp := time.Now().Unix()
|
|
t := time.Unix(timeStamp, 0).Local()
|
|
t1 := time.Unix(int64(p.sqlStruck.OtherWorkTime), 0).Local()
|
|
if p.sqlStruck.SelfWorkTime+3600*24 < int32(timeStamp) {
|
|
p.sqlStruck.SelfWorkTime = 0
|
|
|
|
}
|
|
|
|
if timeStamp-int64(t.Hour()*3600)-int64(t.Minute()*60)-int64(t.Second()) != int64(p.sqlStruck.OtherWorkTime)-int64(t1.Hour()*3600)-int64(t1.Minute()*60)-int64(t1.Second()) {
|
|
p.sqlStruck.OtherWorkTime = 0
|
|
}
|
|
isHome := p.GetSelfPetAutoGoHome()
|
|
if isHome {
|
|
p.sqlStruck.AtHome = 0
|
|
}
|
|
p.Data.UnlockDecorateList = []int32{}
|
|
p.Data.SelectDecorateMap = make(map[int32]int32)
|
|
p.SingnalData()
|
|
|
|
if p.sqlStruck.SelfWorkTime > 0 {
|
|
go func() {
|
|
// 注释内容也可以使用
|
|
curtime := p.sqlStruck.SelfWorkTime + 3600*24
|
|
t1 := (int64)(curtime) - (int64)(timeStamp)
|
|
p.Mdispatr = timer.NewDispatcher(1)
|
|
p.MLeafTimer = p.Mdispatr.AfterFunc(time.Duration(t1)*time.Second, func() {
|
|
p.sqlStruck.SelfWorkTime = 0
|
|
|
|
p.NotifyPetWorkEnd(1)
|
|
p.MLeafTimer = nil
|
|
p.SingnalData()
|
|
p.SaveDataFromDB("")
|
|
})
|
|
|
|
(<-p.Mdispatr.ChanTimer).Cb()
|
|
}()
|
|
}
|
|
p.Reconnect(false)
|
|
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) Notify_Daily_Renew(param []interface{}) {
|
|
|
|
p.sqlStruck.AtHome = 0
|
|
notify := &msg.NotifyPetGoHome{}
|
|
notify.AtHome = 0
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(notify)
|
|
G_GameLogicPtr.PackResInfo(agent, "NotifyPetGoHome", data)
|
|
|
|
if p.sqlStruck.OtherWorkTime != 0 {
|
|
p.sqlStruck.OtherWorkTime = 0
|
|
p.SingnalData()
|
|
p.NotifyPetWorkEnd(2)
|
|
p.SaveDataFromDB("")
|
|
}
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) NotifyPetOtherBorrow() {
|
|
if p.sqlStruck.SelfWorkTime == 0 {
|
|
p.sqlStruck.AtHome = 1
|
|
|
|
notify := &msg.NotifyPetLeave{}
|
|
notify.AtHome = 1
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(notify)
|
|
G_GameLogicPtr.PackResInfo(agent, "NotifyPetLeave", data)
|
|
p.SingnalData()
|
|
p.SaveDataFromDB("")
|
|
}
|
|
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) NotifyPetWorkEnd(mtype int32) {
|
|
notify := &msg.NotifyPetWorkEnd{}
|
|
notify.MType = mtype
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(notify)
|
|
G_GameLogicPtr.PackResInfo(agent, "NotifyPetWorkEnd", data)
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) Reconnect(b bool) {
|
|
|
|
GoUtil.RegisterEvent(MergeConst.Notify_Daily_Renew, p.Notify_Daily_Renew, p)
|
|
if b {
|
|
sqlStr := "SELECT * FROM t_player_PetHome_Data WHERE dwUin = ?"
|
|
db.SqlDb.Get(&p.sqlStruck, sqlStr, p.M_Player.M_DwUin)
|
|
|
|
timeStamp := time.Now().Unix()
|
|
t := time.Unix(timeStamp, 0).Local()
|
|
t1 := time.Unix(int64(p.sqlStruck.OtherWorkTime), 0).Local()
|
|
if p.sqlStruck.SelfWorkTime > 0 && p.sqlStruck.SelfWorkTime+3600*24 <= int32(timeStamp) {
|
|
p.sqlStruck.SelfWorkTime = 0
|
|
p.NotifyPetWorkEnd(1)
|
|
}
|
|
|
|
if p.sqlStruck.OtherWorkTime > 0 && timeStamp-int64(t.Hour()*3600)-int64(t.Minute()*60)-int64(t.Second()) != int64(p.sqlStruck.OtherWorkTime)-int64(t1.Hour()*3600)-int64(t1.Minute()*60)-int64(t1.Second()) {
|
|
p.sqlStruck.OtherWorkTime = 0
|
|
p.NotifyPetWorkEnd(2)
|
|
}
|
|
isHome := p.GetSelfPetAutoGoHome()
|
|
if isHome {
|
|
p.sqlStruck.AtHome = 0
|
|
}
|
|
p.SingnalData()
|
|
if p.sqlStruck.SelfWorkTime > 0 {
|
|
go func() {
|
|
// 注释内容也可以使用
|
|
curtime := p.sqlStruck.SelfWorkTime + 3600*24
|
|
t1 := (int64)(curtime) - (int64)(timeStamp)
|
|
p.Mdispatr = timer.NewDispatcher(1)
|
|
p.MLeafTimer = p.Mdispatr.AfterFunc(time.Duration(t1)*time.Second, func() {
|
|
p.sqlStruck.SelfWorkTime = 0
|
|
|
|
p.NotifyPetWorkEnd(1)
|
|
p.MLeafTimer = nil
|
|
p.SingnalData()
|
|
p.SaveDataFromDB("")
|
|
})
|
|
|
|
(<-p.Mdispatr.ChanTimer).Cb()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
p.SaveDataFromDB("")
|
|
}
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) SingnalData() {
|
|
|
|
p.Data.DwUin = p.sqlStruck.DwUin
|
|
p.Data.InterActEndTime = p.sqlStruck.InterActEndTime
|
|
p.Data.NestId = p.sqlStruck.NestId
|
|
p.Data.OrnamentsId = p.sqlStruck.OrnamentsId
|
|
p.Data.CurInterActUin = p.sqlStruck.CurInterActUin
|
|
p.Data.MiniGameResult = p.sqlStruck.MiniGameResult
|
|
p.Data.SelfWorkTime = p.sqlStruck.SelfWorkTime
|
|
p.Data.OtherWorkTime = p.sqlStruck.OtherWorkTime
|
|
p.Data.UnlockPetNest = p.sqlStruck.UnlockPetNest
|
|
p.Data.UnlockPetOrnaments = p.sqlStruck.UnlockPetOrnaments
|
|
p.Data.UnlockPetEmotion = p.sqlStruck.UnlockPetEmotion
|
|
p.Data.AtHome = p.sqlStruck.AtHome
|
|
p.Data.Mood = p.sqlStruck.Mood
|
|
|
|
if p.sqlStruck.UnlockDecorateList != "" {
|
|
units := strings.Split(p.sqlStruck.UnlockDecorateList, ";")
|
|
p.Data.UnlockDecorateList = []int32{}
|
|
for i := 0; i < len(units); i++ {
|
|
id, _ := strconv.Atoi(units[i])
|
|
p.Data.UnlockDecorateList = append(p.Data.UnlockDecorateList, int32(id))
|
|
}
|
|
}
|
|
|
|
if p.sqlStruck.SelectDecorateMap != "" {
|
|
units := strings.Split(p.sqlStruck.SelectDecorateMap, ";")
|
|
p.Data.SelectDecorateMap = make(map[int32]int32)
|
|
for i := 0; i < len(units); i++ {
|
|
item := strings.Split(units[i], ",")
|
|
type1, _ := strconv.Atoi(item[0])
|
|
id, _ := strconv.Atoi(item[1])
|
|
p.Data.SelectDecorateMap[int32(type1)] = int32(id)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) ClearData() bool {
|
|
p.SaveDataFromDB("")
|
|
if p.MLeafTimer != nil {
|
|
p.MLeafTimer.Stop()
|
|
p.MLeafTimer = nil
|
|
}
|
|
GoUtil.RemoveEvent(MergeConst.Notify_Daily_Renew, p.Notify_Daily_Renew, p)
|
|
return true
|
|
}
|
|
func (p *PlayerPetHomeData) SaveDataFromDB(Key interface{}) bool {
|
|
// if p.IsHaveDataDb {
|
|
// db.FormatAllMemUpdateDb(&p.sqlStruck, "t_player_PetHome_Data", "dwUin")
|
|
// } else {
|
|
// db.FormatAllMemInsertDb(&p.sqlStruck, "t_player_PetHome_Data")
|
|
// }
|
|
p.IsHaveDataDb = true
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) ReqPetHomeData(player *Player) {
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(&p.Data)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResPetHomeData", data)
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) ReqUnlockDecorate(buf []byte) {
|
|
req := &msg.ReqUnlockDecorate{}
|
|
res := &msg.ResUnlockDecorate{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
isHave := false
|
|
for i := 0; i < len(p.Data.UnlockDecorateList); i++ {
|
|
if p.Data.UnlockDecorateList[i] == req.DecorateId {
|
|
isHave = true
|
|
break
|
|
}
|
|
}
|
|
if !isHave {
|
|
if p.sqlStruck.UnlockDecorateList == "" {
|
|
p.sqlStruck.UnlockDecorateList = strconv.Itoa(int(req.DecorateId))
|
|
} else {
|
|
temp := []string{p.sqlStruck.UnlockDecorateList, strconv.Itoa(int(req.DecorateId))}
|
|
p.sqlStruck.UnlockDecorateList = strings.Join(temp, ",")
|
|
}
|
|
|
|
}
|
|
|
|
p.SingnalData()
|
|
p.SaveDataFromDB("")
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResUnlockDecorate", data)
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) ReqSaveSelectDecorate(buf []byte) {
|
|
req := &msg.ReqSaveSelectDecorate{}
|
|
res := &msg.ResSaveSelectDecorate{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
for k, v := range req.SelectDecorateMap {
|
|
p.Data.SelectDecorateMap[k] = v
|
|
}
|
|
temp := []string{}
|
|
for k, v := range p.Data.SelectDecorateMap {
|
|
temp = append(temp, strconv.Itoa(int(k))+","+strconv.Itoa(int(v)))
|
|
}
|
|
p.sqlStruck.SelectDecorateMap = strings.Join(temp, ";")
|
|
res.SelectDecorateMap = p.Data.SelectDecorateMap
|
|
// p.SingnalData()
|
|
p.SaveDataFromDB("")
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResSaveSelectDecorate", data)
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) ReqOpenOtherPetHome(buf []byte) {
|
|
req := &msg.ReqOpenOtherPetHome{}
|
|
res := &msg.ResOpenOtherPetHome{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
Profile := G_GameLogicPtr.MPlayerProfileManager.RandomGetAnPlayer(p.Data.DwUin)
|
|
|
|
if Profile != nil {
|
|
res.TargetUin = Profile.DwUin
|
|
|
|
}
|
|
sqlStr := "SELECT * FROM t_player_PetHome_Data WHERE dwUin = ?"
|
|
|
|
sqlStruck := db.SqlPetHomeData{}
|
|
sqlStruck.DwUin = res.TargetUin
|
|
sqlStruck.NestId = 1
|
|
sqlStruck.OrnamentsId = 1
|
|
db.SqlDb.Get(&sqlStruck, sqlStr, res.TargetUin)
|
|
|
|
res.NestId = sqlStruck.NestId
|
|
res.OrnamentsId = sqlStruck.OrnamentsId
|
|
res.BriefProfile = &msg.ResPlayerBriefProfileData{}
|
|
|
|
if Profile != nil {
|
|
res.BriefProfile.DwUin = res.TargetUin
|
|
res.BriefProfile.ImageFrame = Profile.ImageFrame
|
|
res.BriefProfile.ImageIcon = Profile.ImageIcon
|
|
res.BriefProfile.NickName = Profile.NickName
|
|
res.BriefProfile.PicURL = Profile.PicURL
|
|
|
|
DecorateCnt, ActiveTime, _ := G_GameLogicPtr.MPlayerProfileManager.GetPlayerDecorate(res.TargetUin)
|
|
res.BriefProfile.DecorateCnt = int32(DecorateCnt)
|
|
res.BriefProfile.ActiveTime = int32(ActiveTime)
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResOpenOtherPetHome", data)
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) ReqShiftVisitPet(buf []byte) {
|
|
req := &msg.ReqShiftVisitPet{}
|
|
res := &msg.ResShiftVisitPet{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
res.TargetUin = req.TargetUin
|
|
|
|
sqlStr := "SELECT * FROM t_player_PetHome_Data WHERE dwUin = ?"
|
|
|
|
sqlStruck := db.SqlPetHomeData{}
|
|
sqlStruck.DwUin = res.TargetUin
|
|
sqlStruck.NestId = 1
|
|
sqlStruck.OrnamentsId = 1
|
|
db.SqlDb.Get(&sqlStruck, sqlStr, res.TargetUin)
|
|
|
|
res.NestId = sqlStruck.NestId
|
|
res.OrnamentsId = sqlStruck.OrnamentsId
|
|
res.BriefProfile = &msg.ResPlayerBriefProfileData{}
|
|
|
|
Profile := G_GameLogicPtr.MPlayerProfileManager.GetPlayerProfile(req.TargetUin)
|
|
if Profile != nil {
|
|
res.BriefProfile.DwUin = res.TargetUin
|
|
res.BriefProfile.ImageFrame = Profile.ImageFrame
|
|
res.BriefProfile.ImageIcon = Profile.ImageIcon
|
|
res.BriefProfile.NickName = Profile.NickName
|
|
res.BriefProfile.PicURL = Profile.PicURL
|
|
|
|
DecorateCnt, ActiveTime, _ := G_GameLogicPtr.MPlayerProfileManager.GetPlayerDecorate(res.TargetUin)
|
|
res.BriefProfile.DecorateCnt = int32(DecorateCnt)
|
|
res.BriefProfile.ActiveTime = int32(ActiveTime)
|
|
|
|
} else {
|
|
sql := &db.SqlPlayerProfileStruct{}
|
|
sql.DwUin = req.TargetUin
|
|
sql.ImageFrame = 1
|
|
sql.ImageIcon = 1
|
|
sql.NickName = "Player" + strconv.Itoa(int(req.TargetUin))
|
|
sql.PicURL = ""
|
|
G_GameLogicPtr.MPlayerProfileManager.UpdateNewProfile(sql)
|
|
|
|
res.BriefProfile.DwUin = res.TargetUin
|
|
res.BriefProfile.ImageFrame = sql.ImageFrame
|
|
res.BriefProfile.ImageIcon = sql.ImageIcon
|
|
res.BriefProfile.NickName = sql.NickName
|
|
res.BriefProfile.PicURL = sql.PicURL
|
|
DecorateCnt, ActiveTime, _ := G_GameLogicPtr.MPlayerProfileManager.GetPlayerDecorate(res.TargetUin)
|
|
res.BriefProfile.DecorateCnt = int32(DecorateCnt)
|
|
res.BriefProfile.ActiveTime = int32(ActiveTime)
|
|
|
|
}
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResShiftVisitPet", data)
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) ReqOpenSelfPet(buf []byte) {
|
|
req := &msg.ReqOpenSelfPet{}
|
|
res := &msg.ResOpenSelfPet{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
res.SelfWorkTime = int32(time.Now().Unix())
|
|
p.sqlStruck.SelfWorkTime = res.SelfWorkTime
|
|
|
|
go func() {
|
|
// 注释内容也可以使用
|
|
curtime := p.sqlStruck.SelfWorkTime + 3600*24
|
|
t1 := (int64)(curtime) - (int64)(res.SelfWorkTime)
|
|
p.Mdispatr = timer.NewDispatcher(1)
|
|
p.MLeafTimer = p.Mdispatr.AfterFunc(time.Duration(t1)*time.Second, func() {
|
|
p.sqlStruck.SelfWorkTime = 0
|
|
|
|
p.NotifyPetWorkEnd(1)
|
|
p.MLeafTimer = nil
|
|
p.SingnalData()
|
|
p.SaveDataFromDB("")
|
|
})
|
|
|
|
(<-p.Mdispatr.ChanTimer).Cb()
|
|
|
|
}()
|
|
p.SingnalData()
|
|
p.SaveDataFromDB("")
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResOpenSelfPet", data)
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) ReqCompleteMiniGame(buf []byte) {
|
|
req := &msg.ReqCompleteMiniGame{}
|
|
res := &msg.ResCompleteMiniGame{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
res.DwUin = req.DwUin
|
|
res.TargetUin = req.TargetUin
|
|
|
|
sqlStr := "SELECT * FROM t_player_PetHome_Data WHERE dwUin = ?"
|
|
|
|
sqlStruck := db.SqlPetHomeData{}
|
|
sqlStruck.DwUin = res.TargetUin
|
|
sqlStruck.NestId = 1
|
|
sqlStruck.OrnamentsId = 1
|
|
db.SqlDb.Get(&sqlStruck, sqlStr, res.TargetUin)
|
|
|
|
res.NestId = sqlStruck.NestId
|
|
res.OrnamentsId = sqlStruck.OrnamentsId
|
|
res.InterActEndTime = int32(time.Now().Unix())
|
|
res.Result = req.Result
|
|
|
|
p.sqlStruck.OtherWorkTime = res.InterActEndTime
|
|
p.sqlStruck.InterActEndTime = res.InterActEndTime
|
|
p.sqlStruck.MiniGameResult = req.Result
|
|
|
|
st := db.SqlPetHomeInterAct{}
|
|
st.DwUin = p.M_Player.M_DwUin
|
|
st.InterActEndTime = res.InterActEndTime
|
|
st.TargetUin = res.TargetUin
|
|
|
|
sqlStr1 := "SELECT * FROM t_player_PetHome_InterAct_Data WHERE dwUin = ? And TargetUin = ?"
|
|
ishave := false
|
|
if err := db.SqlDb.Get(&st, sqlStr1, p.Data.DwUin, res.TargetUin); err != nil {
|
|
fmt.Printf("get data failed, err:%v\n", err)
|
|
|
|
} else {
|
|
ishave = true
|
|
}
|
|
|
|
if req.Result == 3 {
|
|
if ishave {
|
|
db.FormatAllMemUpdateDb(&st, "t_player_PetHome_InterAct_Data", "auto_id")
|
|
} else {
|
|
db.FormatAllMemInsertDb(&st, "t_player_PetHome_InterAct_Data")
|
|
}
|
|
player, ok := G_GameLogicPtr.M_Players[req.TargetUin]
|
|
if ok {
|
|
if player.GetGameData("PlayerPetHomeData") != nil {
|
|
player.GetIFGameData("PlayerPetHomeData").(*PlayerPetHomeData).NotifyPetOtherBorrow()
|
|
} else {
|
|
// sqlStr := "SELECT * FROM t_player_PetHome_Data WHERE dwUin = ?"
|
|
sqlStruck := db.SqlPetHomeData{}
|
|
sqlStruck.DwUin = req.TargetUin
|
|
sqlStruck.NestId = 1
|
|
sqlStruck.OrnamentsId = 1
|
|
|
|
// if err := db.SqlDb.Get(&sqlStruck, sqlStr, req.TargetUin); err != nil {
|
|
// sqlStruck.AtHome = 1
|
|
// db.FormatAllMemInsertDb(&sqlStruck, "t_player_PetHome_Data")
|
|
// } else {
|
|
// if sqlStruck.SelfWorkTime+3600*24 <= int32(time.Now().Unix()) {
|
|
// sqlStruck.AtHome = 1
|
|
// }
|
|
// db.FormatAllMemUpdateDb(&sqlStruck, "t_player_PetHome_Data", "dwUin")
|
|
// }
|
|
}
|
|
} else {
|
|
// sqlStr := "SELECT * FROM t_player_PetHome_Data WHERE dwUin = ?"
|
|
sqlStruck := db.SqlPetHomeData{}
|
|
sqlStruck.DwUin = req.TargetUin
|
|
sqlStruck.NestId = 1
|
|
sqlStruck.OrnamentsId = 1
|
|
// if err := db.SqlDb.Get(&sqlStruck, sqlStr, req.TargetUin); err != nil {
|
|
// sqlStruck.AtHome = 1
|
|
// db.FormatAllMemInsertDb(&sqlStruck, "t_player_PetHome_Data")
|
|
// } else {
|
|
// if sqlStruck.SelfWorkTime+3600*24 <= int32(time.Now().Unix()) {
|
|
// sqlStruck.AtHome = 1
|
|
// }
|
|
// db.FormatAllMemUpdateDb(&sqlStruck, "t_player_PetHome_Data", "dwUin")
|
|
// }
|
|
|
|
}
|
|
|
|
} else {
|
|
if ishave {
|
|
sqlStr2 := "DELETE FROM " + "t_player_PetHome_InterAct_Data" + " WHERE auto_id = ?"
|
|
db.SqlDb.Exec(sqlStr2, st.AutoId)
|
|
}
|
|
res.InterActEndTime = 0
|
|
}
|
|
if req.IsThief > 0 {
|
|
sqlStr := "SELECT * FROM t_player_card_data WHERE dwUin = ?"
|
|
MsqlStruck := db.SqlCardCollectStruct{}
|
|
|
|
err := db.SqlDb.Get(&MsqlStruck, sqlStr, req.TargetUin)
|
|
if err != nil {
|
|
|
|
} else {
|
|
if MsqlStruck.CardInfo != "" {
|
|
units := strings.Split(MsqlStruck.CardInfo, ";")
|
|
rate := make(map[int][]int)
|
|
rate[1] = []int{50, 40, 10}
|
|
rate[2] = []int{25, 40, 20, 15}
|
|
if len(units) > 0 {
|
|
CardDetailCfg := gamedata.GetConfigByName("CardDetailCfg")
|
|
cardmap := make(map[int][]*gamedata.CardDetailRecord)
|
|
|
|
for i := 0; i < len(units); i++ {
|
|
strr := strings.Split(units[i], ",")
|
|
cnt, _ := strconv.Atoi(strr[1])
|
|
id, _ := strconv.Atoi(strr[0])
|
|
if cnt > 0 {
|
|
cfg := CardDetailCfg.Index(id).(*gamedata.CardDetailRecord)
|
|
value, ok := cardmap[cfg.Color]
|
|
if ok {
|
|
if cfg.IsGold == 0 {
|
|
cardmap[cfg.Color] = append(cardmap[cfg.Color], cfg)
|
|
}
|
|
|
|
} else {
|
|
if cfg.IsGold == 0 {
|
|
value = []*gamedata.CardDetailRecord{}
|
|
value = append(value, cfg)
|
|
cardmap[cfg.Color] = value
|
|
}
|
|
}
|
|
}
|
|
}
|
|
weight := 0
|
|
enum := rand.Intn(100) + 1
|
|
index := 0
|
|
for j := 0; j < len(rate[int(req.IsThief)]); j++ {
|
|
weight = rate[int(req.IsThief)][j] + weight
|
|
if weight >= enum {
|
|
index = j
|
|
break
|
|
}
|
|
}
|
|
value, ok := cardmap[index+1]
|
|
if ok {
|
|
temp := rand.Intn(len(value))
|
|
res.CardId = int32(value[temp].Id)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
dataName := G_GameLogicPtr.MLimiteEventManager.GetLimitDataNameById(10)
|
|
p.M_Player.GetIFGameData(dataName).(*PlayerPetRobberData).RemoveTagByPlayerId(req.TargetUin)
|
|
}
|
|
p.SingnalData()
|
|
p.SaveDataFromDB("")
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResCompleteMiniGame", data)
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) GetSelfPetAutoGoHome() bool {
|
|
MPetHomeInterActSTs := []*msg.PetHomeInterActST{}
|
|
|
|
sqlStr1 := "SELECT * FROM t_player_PetHome_InterAct_Data WHERE TargetUin = ?"
|
|
st := []db.SqlPetHomeInterAct{}
|
|
if err := db.SqlDb.Select(&st, sqlStr1, p.Data.DwUin); err != nil {
|
|
fmt.Printf("get data failed, err:%v\n", err)
|
|
|
|
} else {
|
|
|
|
}
|
|
for i := 0; i < len(st); i++ {
|
|
item := &msg.PetHomeInterActST{}
|
|
item.DwUin = st[i].DwUin
|
|
item.TargetUin = st[i].TargetUin
|
|
item.InterActEndTime = st[i].InterActEndTime
|
|
MPetHomeInterActSTs = append(MPetHomeInterActSTs, item)
|
|
}
|
|
sort.Slice(MPetHomeInterActSTs, func(i, j int) bool {
|
|
return MPetHomeInterActSTs[i].InterActEndTime > MPetHomeInterActSTs[j].InterActEndTime
|
|
})
|
|
if len(MPetHomeInterActSTs) > 0 {
|
|
timeStamp := int64(MPetHomeInterActSTs[0].InterActEndTime)
|
|
t := time.Unix(timeStamp, 0).Local()
|
|
zero := timeStamp - (int64)(t.Hour()*3600+t.Minute()*60+t.Second())
|
|
|
|
curtime := time.Now().Unix()
|
|
t1 := time.Unix(curtime, 0).Local()
|
|
zero1 := curtime - (int64)(t1.Hour()*3600+t1.Minute()*60+t1.Second())
|
|
|
|
if zero1 == zero {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) GetHomeInterActST() []*msg.PetHomeInterActST {
|
|
MPetHomeInterActSTs := []*msg.PetHomeInterActST{}
|
|
|
|
sqlStr1 := "SELECT * FROM t_player_PetHome_InterAct_Data WHERE TargetUin = ?"
|
|
st := []db.SqlPetHomeInterAct{}
|
|
db.SqlDb.Select(&st, sqlStr1, p.Data.DwUin)
|
|
|
|
for i := 0; i < len(st); i++ {
|
|
item := &msg.PetHomeInterActST{}
|
|
item.DwUin = st[i].DwUin
|
|
item.TargetUin = st[i].TargetUin
|
|
item.InterActEndTime = st[i].InterActEndTime
|
|
|
|
dbst := G_GameLogicPtr.MPlayerProfileManager.NewGetPlayerProfile(item.DwUin)
|
|
|
|
item.BriefProfile = &msg.ResPlayerBriefProfileData{}
|
|
item.BriefProfile.DwUin = item.DwUin
|
|
item.BriefProfile.ImageFrame = dbst.ImageFrame
|
|
item.BriefProfile.ImageIcon = dbst.ImageIcon
|
|
item.BriefProfile.NickName = dbst.NickName
|
|
item.BriefProfile.PicURL = dbst.PicURL
|
|
|
|
DecorateCnt, ActiveTime, _ := G_GameLogicPtr.MPlayerProfileManager.GetPlayerDecorate(item.DwUin)
|
|
item.BriefProfile.DecorateCnt = int32(DecorateCnt)
|
|
item.BriefProfile.ActiveTime = int32(ActiveTime)
|
|
MPetHomeInterActSTs = append(MPetHomeInterActSTs, item)
|
|
}
|
|
return MPetHomeInterActSTs
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) ReqPetHomeInterActST(buf []byte) {
|
|
req := &msg.ReqPetHomeInterActST{}
|
|
res := &msg.ResPetHomeInterActST{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
res.MPetHomeInterActSTs = []*msg.PetHomeInterActST{}
|
|
|
|
sqlStr1 := "SELECT * FROM t_player_PetHome_InterAct_Data WHERE TargetUin = ?"
|
|
st := []db.SqlPetHomeInterAct{}
|
|
if err := db.SqlDb.Select(&st, sqlStr1, p.Data.DwUin); err != nil {
|
|
fmt.Printf("get data failed, err:%v\n", err)
|
|
|
|
} else {
|
|
|
|
}
|
|
for i := 0; i < len(st); i++ {
|
|
item := &msg.PetHomeInterActST{}
|
|
item.DwUin = st[i].DwUin
|
|
item.TargetUin = st[i].TargetUin
|
|
item.InterActEndTime = st[i].InterActEndTime
|
|
|
|
dbst := G_GameLogicPtr.MPlayerProfileManager.NewGetPlayerProfile(item.DwUin)
|
|
|
|
item.BriefProfile = &msg.ResPlayerBriefProfileData{}
|
|
item.BriefProfile.DwUin = item.DwUin
|
|
item.BriefProfile.ImageFrame = dbst.ImageFrame
|
|
item.BriefProfile.ImageIcon = dbst.ImageIcon
|
|
item.BriefProfile.NickName = dbst.NickName
|
|
item.BriefProfile.PicURL = dbst.PicURL
|
|
|
|
DecorateCnt, ActiveTime, _ := G_GameLogicPtr.MPlayerProfileManager.GetPlayerDecorate(item.DwUin)
|
|
item.BriefProfile.DecorateCnt = int32(DecorateCnt)
|
|
item.BriefProfile.ActiveTime = int32(ActiveTime)
|
|
res.MPetHomeInterActSTs = append(res.MPetHomeInterActSTs, item)
|
|
}
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResPetHomeInterActST", data)
|
|
}
|
|
|
|
func (p *PlayerPetHomeData) ReqCallBackPet(buf []byte) {
|
|
req := &msg.ReqCallBackPet{}
|
|
res := &msg.ResCallBackPet{}
|
|
proto.Unmarshal(buf, req)
|
|
p.sqlStruck.AtHome = 0
|
|
p.SingnalData()
|
|
p.SaveDataFromDB("")
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResCallBackPet", data)
|
|
}
|
|
|
|
///////////////
|
|
|
|
type Player7DayCallBackData struct {
|
|
*PlayerData
|
|
Data msg.Notify7DayCallbackData
|
|
sqlStruck db.SqlNotify7DayCallbackData
|
|
|
|
// MLeafTimer1 *timer.Timer
|
|
}
|
|
|
|
func (p *Player7DayCallBackData) LoadDataFromDB(dwUin interface{}) bool {
|
|
|
|
sqlStr := "SELECT * FROM t_player_callback_7Day WHERE dwUin = ?"
|
|
|
|
p.sqlStruck = db.SqlNotify7DayCallbackData{}
|
|
p.sqlStruck.DwUin = dwUin.(int32)
|
|
if err := db.SqlDb.Get(&p.sqlStruck, sqlStr, dwUin.(int32)); err != nil {
|
|
fmt.Printf("get data failed, err:%v\n", err)
|
|
p.IsHaveDataDb = false
|
|
} else {
|
|
p.IsHaveDataDb = true
|
|
}
|
|
|
|
p.Data.DwUin = p.sqlStruck.DwUin
|
|
p.Data.StartSvrTime = p.sqlStruck.StartSvrTime
|
|
p.Data.GetIndex = p.sqlStruck.GetIndex
|
|
p.Data.LastGetTime = p.sqlStruck.LastGetTime
|
|
|
|
return true
|
|
}
|
|
func (p *Player7DayCallBackData) OpenNewCallBack() {
|
|
timeStamp := time.Now().Unix()
|
|
t := time.Unix(timeStamp, 0).Local()
|
|
|
|
p.sqlStruck.StartSvrTime = int32(timeStamp) - int32(t.Hour())*3600 - int32(t.Minute())*60 - int32(t.Second())
|
|
p.sqlStruck.GetIndex = 0
|
|
p.sqlStruck.LastGetTime = 0
|
|
|
|
p.Data.DwUin = p.sqlStruck.DwUin
|
|
p.Data.StartSvrTime = p.sqlStruck.StartSvrTime
|
|
p.Data.GetIndex = p.sqlStruck.GetIndex
|
|
p.Data.LastGetTime = p.sqlStruck.LastGetTime
|
|
p.SaveDataFromDB("")
|
|
|
|
p.Notify7DayCallbackData(int32(time.Now().Unix()))
|
|
p.Reconnect(false)
|
|
}
|
|
|
|
func (p *Player7DayCallBackData) ProcessIsOutline() {
|
|
timeStamp := time.Now().Unix()
|
|
|
|
if p.sqlStruck.StartSvrTime+7*3600 <= int32(timeStamp) {
|
|
|
|
} else {
|
|
|
|
p.Notify7DayCallbackData(int32(timeStamp))
|
|
}
|
|
}
|
|
|
|
func (p *Player7DayCallBackData) Notify_Daily_Renew(param []interface{}) {
|
|
|
|
timeStamp := G_GameLogicPtr.DailyTaskTimestamp
|
|
|
|
if p.sqlStruck.StartSvrTime+7*3600*24 <= int32(timeStamp) {
|
|
p.Notify7DayCallbackEnd()
|
|
} else {
|
|
p.Data.DwUin = p.sqlStruck.DwUin
|
|
p.Data.StartSvrTime = p.sqlStruck.StartSvrTime
|
|
p.Data.GetIndex = p.sqlStruck.GetIndex
|
|
p.Data.LastGetTime = p.sqlStruck.LastGetTime
|
|
p.Notify7DayCallbackData(int32(timeStamp))
|
|
}
|
|
}
|
|
|
|
func (p *Player7DayCallBackData) Reconnect(b bool) {
|
|
|
|
GoUtil.RegisterEvent(MergeConst.Notify_Daily_Renew, p.Notify_Daily_Renew, p)
|
|
|
|
}
|
|
|
|
func (p *Player7DayCallBackData) ClearData() bool {
|
|
p.SaveDataFromDB("")
|
|
|
|
GoUtil.RemoveEvent(MergeConst.Notify_Daily_Renew, p.Notify_Daily_Renew, p)
|
|
return true
|
|
}
|
|
func (p *Player7DayCallBackData) SaveDataFromDB(Key interface{}) bool {
|
|
if p.IsHaveDataDb {
|
|
db.FormatAllMemUpdateDb(&p.sqlStruck, "t_player_callback_7Day", "dwUin")
|
|
} else {
|
|
db.FormatAllMemInsertDb(&p.sqlStruck, "t_player_callback_7Day")
|
|
}
|
|
p.IsHaveDataDb = true
|
|
return true
|
|
}
|
|
|
|
func (p *Player7DayCallBackData) Req7DayCallbackSignal(buf []byte) {
|
|
req := &msg.Req7DayCallbackSignal{}
|
|
res := &msg.Res7DayCallbackSignal{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
timeStamp := time.Now().Unix()
|
|
t := time.Unix(timeStamp, 0).Local()
|
|
zero := timeStamp - int64(t.Hour())*3600 - int64(t.Minute())*60 - int64(t.Second())
|
|
|
|
if int64(p.sqlStruck.LastGetTime) == zero {
|
|
res.ResultCode = MergeConst.Protocol_Active_7Day_Rewarded
|
|
} else {
|
|
res.CurSvrTime = int32(timeStamp)
|
|
res.GetIndex = req.GetIndex
|
|
res.LastGetTime = int32(zero)
|
|
p.sqlStruck.GetIndex = res.GetIndex
|
|
p.sqlStruck.LastGetTime = res.LastGetTime
|
|
p.Data.GetIndex = res.GetIndex
|
|
p.Data.LastGetTime = res.LastGetTime
|
|
res.ResultCode = 0
|
|
}
|
|
p.SaveDataFromDB("")
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "Res7DayCallbackSignal", data)
|
|
}
|
|
|
|
func (p *Player7DayCallBackData) Notify7DayCallbackData(renewTime int32) {
|
|
p.Data.CurSvrTime = renewTime
|
|
p.SaveDataFromDB("")
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(&p.Data)
|
|
G_GameLogicPtr.PackResInfo(agent, "Notify7DayCallbackData", data)
|
|
}
|
|
|
|
func (p *Player7DayCallBackData) Notify7DayCallbackEnd() {
|
|
|
|
notify := msg.Notify7DayCallbackEnd{}
|
|
notify.DwUin = p.M_Player.M_DwUin
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(¬ify)
|
|
G_GameLogicPtr.PackResInfo(agent, "Notify7DayCallbackEnd", data)
|
|
}
|
|
|
|
// ////////////
|
|
type PlayerNewInfinitePackData struct {
|
|
*PlayerData
|
|
MsqlStruck db.SqlLimitInfinitePackStruct
|
|
}
|
|
|
|
func (p *PlayerNewInfinitePackData) LoadDataFromDB(dwUin interface{}) bool {
|
|
|
|
sqlStr := "SELECT * FROM t_player_new_LimitInfinitePack WHERE dwUin = ?"
|
|
p.MsqlStruck = db.SqlLimitInfinitePackStruct{}
|
|
|
|
if err := db.SqlDb.Get(&p.MsqlStruck, sqlStr, dwUin.(int32)); err != nil {
|
|
fmt.Printf("get data failed, err:%v\n", err)
|
|
p.IsHaveDataDb = false
|
|
} else {
|
|
p.IsHaveDataDb = true
|
|
}
|
|
p.MsqlStruck.DwUin = dwUin.(int32)
|
|
timeStamp := time.Now().Unix()
|
|
t := time.Unix(timeStamp, 0).Local()
|
|
zero := timeStamp - int64(t.Hour())*3600 - int64(t.Minute())*60 - int64(t.Second())
|
|
|
|
if p.MsqlStruck.StartSvrTime < int32(zero) {
|
|
p.MsqlStruck.StartSvrTime = int32(zero)
|
|
p.MsqlStruck.EndSvrTime = int32(zero) + 3600*24
|
|
p.MsqlStruck.CurGear = 0
|
|
|
|
}
|
|
|
|
p.Reconnect(false)
|
|
return true
|
|
}
|
|
|
|
func (p *PlayerNewInfinitePackData) Notify_Daily_Renew(args []interface{}) {
|
|
timeStamp := G_GameLogicPtr.DailyTaskTimestamp
|
|
t := time.Unix(timeStamp, 0).Local()
|
|
zero := timeStamp - int64(t.Hour())*3600 - int64(t.Minute())*60 - int64(t.Second())
|
|
|
|
p.MsqlStruck.StartSvrTime = int32(zero)
|
|
p.MsqlStruck.EndSvrTime = int32(zero) + 3600*24
|
|
p.MsqlStruck.CurGear = 0
|
|
p.SaveDataFromDB("")
|
|
p.NotifyRefreshInfinitePack()
|
|
|
|
}
|
|
|
|
func (p *PlayerNewInfinitePackData) NotifyRefreshInfinitePack() {
|
|
|
|
res := &msg.NotifyRefreshInfinitePack{}
|
|
res.ActiveID = p.MsqlStruck.ActiveID
|
|
res.CurSvrTime = int32(time.Now().Unix())
|
|
res.StartSvrTime = p.MsqlStruck.StartSvrTime
|
|
res.EndSvrTime = p.MsqlStruck.EndSvrTime
|
|
res.CurGear = p.MsqlStruck.CurGear
|
|
res.DwUin = p.M_Player.M_DwUin
|
|
res.ResultCode = 0
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "NotifyRefreshInfinitePack", data)
|
|
}
|
|
|
|
func (p *PlayerNewInfinitePackData) Reconnect(b bool) {
|
|
GoUtil.RemoveEvent(MergeConst.Notify_Daily_Renew, p.Notify_Daily_Renew, p)
|
|
GoUtil.RegisterEvent(MergeConst.Notify_Daily_Renew, p.Notify_Daily_Renew, p)
|
|
if b {
|
|
timeStamp := time.Now().Unix()
|
|
t := time.Unix(timeStamp, 0).Local()
|
|
zero := timeStamp - int64(t.Hour())*3600 - int64(t.Minute())*60 - int64(t.Second())
|
|
|
|
if p.MsqlStruck.StartSvrTime < int32(zero) {
|
|
p.MsqlStruck.StartSvrTime = int32(zero)
|
|
p.MsqlStruck.EndSvrTime = int32(zero) + 3600*24
|
|
p.MsqlStruck.CurGear = 0
|
|
p.SaveDataFromDB("")
|
|
p.NotifyRefreshInfinitePack()
|
|
}
|
|
}
|
|
}
|
|
|
|
func (p *PlayerNewInfinitePackData) ResInfinitePackDetail(buf []byte) {
|
|
req := &msg.ReqInfinitePackDetail{}
|
|
proto.Unmarshal(buf, req)
|
|
st := p.MsqlStruck
|
|
res := &msg.ResInfinitePackDetail{}
|
|
|
|
res.ActiveID = st.ActiveID
|
|
res.CurSvrTime = int32(time.Now().Unix())
|
|
res.StartSvrTime = st.StartSvrTime
|
|
res.EndSvrTime = st.EndSvrTime
|
|
res.CurGear = st.CurGear
|
|
res.DwUin = p.M_Player.M_DwUin
|
|
res.ResultCode = 0
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResInfinitePackDetail", data)
|
|
}
|
|
|
|
func (p *PlayerNewInfinitePackData) ResBuyInfinitePack(buf []byte) {
|
|
req := &msg.ReqBuyInfinitePack{}
|
|
proto.Unmarshal(buf, req)
|
|
|
|
res := &msg.ResBuyInfinitePack{}
|
|
|
|
res.ActiveID = p.MsqlStruck.ActiveID
|
|
res.DwUin = p.M_Player.M_DwUin
|
|
res.ResultCode = 0
|
|
res.CurGear = req.CurGear + 1
|
|
p.MsqlStruck.CurGear = req.CurGear + 1
|
|
|
|
agent := p.GetPlayer().GetAgentByPlayer()
|
|
data, _ := proto.Marshal(res)
|
|
G_GameLogicPtr.PackResInfo(agent, "ResBuyInfinitePack", data)
|
|
}
|
|
|
|
func (p *PlayerNewInfinitePackData) SaveDataFromDB(Key interface{}) bool {
|
|
if p.IsHaveDataDb {
|
|
db.FormatAllMemUpdateDb(&p.MsqlStruck, "t_player_new_LimitInfinitePack", "dwUin")
|
|
} else {
|
|
db.FormatAllMemInsertDb(&p.MsqlStruck, "t_player_new_LimitInfinitePack")
|
|
}
|
|
|
|
p.IsHaveDataDb = true
|
|
return true
|
|
}
|
|
func (p *PlayerNewInfinitePackData) ClearData() bool {
|
|
p.SaveDataFromDB("")
|
|
GoUtil.RemoveEvent(MergeConst.Notify_Daily_Renew, p.Notify_Daily_Renew, p)
|
|
|
|
return true
|
|
}
|