Merge branch 'develop' into sdk
This commit is contained in:
commit
30b758ad52
2
.gitignore
vendored
2
.gitignore
vendored
@ -13,3 +13,5 @@ src/server/unit_test.go
|
||||
src/server/teLog/*
|
||||
src/server/teLog/log.2024-11-28
|
||||
src/server/logs/ga_log/*.log
|
||||
src/server/goroutine.prof
|
||||
src/server/heap_after.pb.gz
|
||||
|
||||
@ -126,6 +126,7 @@ func SendServerMsg(m *msg.Msg, serverId int) error {
|
||||
}
|
||||
|
||||
func CallServerMsg(m *msg.Msg, serverId int) (*msg.Msg, error) {
|
||||
m.UniKey = GoUtil.UniKey(fmt.Sprintf("%v,Cluster Msg", m))
|
||||
if v, ok := serverAgent.Load(serverId); ok {
|
||||
data, err := GoUtil.GobMarshal(m)
|
||||
if err != nil {
|
||||
@ -134,7 +135,6 @@ func CallServerMsg(m *msg.Msg, serverId int) (*msg.Msg, error) {
|
||||
}
|
||||
v.(network.Agent).WriteMsg(data)
|
||||
}
|
||||
m.UniKey = GoUtil.UniKey("clusterGlobal")
|
||||
newChan := make(chan *msg.Msg, 1)
|
||||
registerChanel(m.UniKey, newChan)
|
||||
timeout := time.After(15 * time.Second)
|
||||
|
||||
@ -314,6 +314,14 @@ func GetChargeInfo(ChargeId int) (float64, string) {
|
||||
return gamedata.GetFloatValue(data, "Money"), gamedata.GetStringValue(data, "Unit")
|
||||
}
|
||||
|
||||
func GetProduceName(ChargeId int) string {
|
||||
data, err := gamedata.GetDataByIntKey(CFG_CHARGE, ChargeId)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return gamedata.GetStringValue(data, "Remark")
|
||||
}
|
||||
|
||||
func GetWishCount(ItemId int) int {
|
||||
data, err := gamedata.GetDataByIntKey(CFG_CHARGE_WISH, ItemId)
|
||||
if err != nil {
|
||||
|
||||
@ -47,6 +47,7 @@ var Server struct {
|
||||
|
||||
ListenAddr string
|
||||
CenterAddr string
|
||||
CenterNode int
|
||||
|
||||
RemoteAddr string
|
||||
GameConfPath string
|
||||
|
||||
@ -6,23 +6,27 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
CFG_LANGUAGE = "LanguageData"
|
||||
CFG_LANGUAGE = "LanguageData"
|
||||
CFG_ALLLANGUAGE = "AllLanguage"
|
||||
)
|
||||
|
||||
func init() {
|
||||
gamedata.InitCfg(CFG_LANGUAGE)
|
||||
gamedata.InitCfg(CFG_ALLLANGUAGE)
|
||||
}
|
||||
|
||||
func GetLanguage(lang msg.LANG_TYPE, key string) string {
|
||||
data, err := gamedata.GetDataByKey(CFG_LANGUAGE, key)
|
||||
data, err := gamedata.GetDataByKey(CFG_ALLLANGUAGE, key)
|
||||
if err != nil {
|
||||
return key
|
||||
}
|
||||
switch lang {
|
||||
case msg.LANG_TYPE_LANG_EN:
|
||||
return gamedata.GetStringValue(data, "English")
|
||||
return gamedata.GetStringValue(data, "en_US")
|
||||
case msg.LANG_TYPE_LANG_PTBR:
|
||||
return gamedata.GetStringValue(data, "pt_BR")
|
||||
case msg.LANG_TYPE_LANG_CN:
|
||||
return gamedata.GetStringValue(data, "zh_CN")
|
||||
default:
|
||||
return key
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ const (
|
||||
CFG_LIMITED_TIME_EVENT_MONEY = "LimitedTimeEventMoney"
|
||||
CFG_LIMITED_TIME_EVENT_LUCKY = "LimitedTimeEventLucky"
|
||||
CFG_LIMITED_TIME_EVENT_CAT_TRICK = "LimitedTimeEventCatTrick"
|
||||
CFG_LIMTTED_TIME_EVENT_DECORATE_OFF = "LimitedTimeEventDecorateOff"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -41,6 +42,7 @@ func init() {
|
||||
gamedata.InitCfg(CFG_LIMITED_TIME_EVENT_MONEY)
|
||||
gamedata.InitCfg(CFG_LIMITED_TIME_EVENT_LUCKY)
|
||||
gamedata.InitCfg(CFG_LIMITED_TIME_EVENT_CAT_TRICK)
|
||||
gamedata.InitCfg(CFG_LIMTTED_TIME_EVENT_DECORATE_OFF)
|
||||
}
|
||||
|
||||
// 获取限时事件触发列表
|
||||
@ -417,3 +419,21 @@ func GetCatTrickDiamond(Type int) (int, int) {
|
||||
}
|
||||
return gamedata.GetIntValue(data, "Diamond"), gamedata.GetIntValue(data, "Energy")
|
||||
}
|
||||
|
||||
func GetDecorateOffDiscount(AreaId, StepId int) int {
|
||||
data, err := gamedata.GetData(CFG_LIMTTED_TIME_EVENT_DECORATE_OFF)
|
||||
if err != nil {
|
||||
log.Debug("GetDecorateOffDiscount err:%v", err)
|
||||
return 100
|
||||
}
|
||||
for _, v := range data {
|
||||
StartAreaId := gamedata.GetIntValue(v, "StartArea")
|
||||
EndAreaId := gamedata.GetIntValue(v, "EndArea")
|
||||
StartStepId := gamedata.GetIntValue(v, "StartStep")
|
||||
EndStepId := gamedata.GetIntValue(v, "EndStep")
|
||||
if AreaId >= StartAreaId && AreaId <= EndAreaId && StepId >= StartStepId && StepId <= EndStepId {
|
||||
return gamedata.GetIntValue(v, "Off")
|
||||
}
|
||||
}
|
||||
return 100
|
||||
}
|
||||
|
||||
@ -24,6 +24,10 @@
|
||||
"ServerStatus" : 1,
|
||||
"ServerCenter" : 1,
|
||||
"GameConfPath": "D:/Github/pet_home_server/src/server/gamedata/config/",
|
||||
|
||||
"ListenAddr":":9001",
|
||||
"CenterAddr": "pethome.bywaystudios.com:9000",
|
||||
"RemoteAddr":"host.docker.internal:9001",
|
||||
|
||||
"RedisAddr":"127.0.0.1",
|
||||
"RedisPort" :"6379",
|
||||
@ -35,7 +39,6 @@
|
||||
"RedisConnType":"Direct",
|
||||
|
||||
"GoogleVerify":false,
|
||||
"RemoteAddr":"host.docker.internal:9001",
|
||||
"Partition":3,
|
||||
"KafkaHost":"kafka-server",
|
||||
"CountryCode":"004",
|
||||
|
||||
@ -3,6 +3,7 @@ package game
|
||||
import (
|
||||
"server/GoUtil"
|
||||
activityCfg "server/conf/activity"
|
||||
catnipCfg "server/conf/catnip"
|
||||
guesscolorCfg "server/conf/guessColor"
|
||||
itemCfg "server/conf/item"
|
||||
mailCfg "server/conf/mail"
|
||||
@ -55,6 +56,13 @@ func ActivityLogin(p *Player) {
|
||||
SendActivityMail(p, ItemId, ItemNum, ActivityId, nil)
|
||||
}
|
||||
}
|
||||
// 猫草大作战
|
||||
ActivityId = GetActivityId(p, activity.ACT_TYPE_CATNIP)
|
||||
CatnipMod := p.PlayMod.getCatnipMod()
|
||||
OldId = CatnipMod.Login(ActivityId)
|
||||
if OldId != 0 {
|
||||
// 清空猫草大作战数据无需发邮件
|
||||
}
|
||||
|
||||
// 通行证
|
||||
ActivityId = GetActivityId(p, activity.ACT_TYPE_PASS)
|
||||
@ -99,6 +107,16 @@ func ActivityZeroUpdate(p *Player) {
|
||||
RaceMod := p.PlayMod.getRaceMod()
|
||||
RaceMod.ZeroUpdate(ActivityInfo.Id)
|
||||
}
|
||||
ActivityInfo = GetActivityInfo(p, activity.ACT_TYPE_PASS)
|
||||
if ActivityInfo != nil {
|
||||
PassMod := p.PlayMod.getPassMod()
|
||||
PassMod.ZeroUpdate(ActivityInfo.Id)
|
||||
}
|
||||
ActivityInfo = GetActivityInfo(p, activity.ACT_TYPE_CATNIP)
|
||||
if ActivityInfo != nil {
|
||||
CatnipMod := p.PlayMod.getCatnipMod()
|
||||
CatnipMod.ZeroUpdate(ActivityInfo.Id)
|
||||
}
|
||||
}
|
||||
|
||||
func GetActivityInfo(p *Player, actType int) *ActivityInfo {
|
||||
@ -287,6 +305,10 @@ func GetActivityItem(p *Player, ActType []int) []*item.Item {
|
||||
}
|
||||
|
||||
func (p *Player) CatnipBackData() {
|
||||
ActivityInfo := GetActivityInfo(p, activity.ACT_TYPE_PASS)
|
||||
if ActivityInfo == nil {
|
||||
return
|
||||
}
|
||||
CatnipMod := p.PlayMod.getCatnipMod()
|
||||
Status := GetActivityStatus(p, activity.ACT_TYPE_CATNIP)
|
||||
if CatnipMod == nil {
|
||||
@ -298,6 +320,8 @@ func (p *Player) CatnipBackData() {
|
||||
Id: int32(v.Id),
|
||||
Progress: int32(v.Progress),
|
||||
Status: int32(v.Status),
|
||||
Reward: GoUtil.SliceIntToInt32(v.Reward),
|
||||
Emoji: int32(v.EmojiId),
|
||||
}
|
||||
if v.Partner != 0 {
|
||||
PlayerData := G_getGameLogic().GetResSimplePlayerByUid(v.Partner)
|
||||
@ -305,12 +329,32 @@ func (p *Player) CatnipBackData() {
|
||||
GameInfo.Partner = PlayerData
|
||||
}
|
||||
}
|
||||
InviteList := make([]*msg.CatnipInvite, 0)
|
||||
for _, iv := range v.InviteList {
|
||||
InviteList = append(InviteList, &msg.CatnipInvite{
|
||||
Uid: int64(iv.InviteId),
|
||||
Time: int64(iv.Time),
|
||||
})
|
||||
}
|
||||
GameInfo.InviteList = InviteList
|
||||
BeInvitedList := make([]*msg.CatnipInvite, 0)
|
||||
for _, iv := range v.BeInvitedList {
|
||||
BeInvitedList = append(BeInvitedList, &msg.CatnipInvite{
|
||||
Uid: int64(iv.InviteId),
|
||||
Time: int64(iv.Time),
|
||||
})
|
||||
}
|
||||
GameInfo.BeInviteList = BeInvitedList
|
||||
GameList = append(GameList, GameInfo)
|
||||
}
|
||||
Template := catnipCfg.GetTemplateId(CatnipMod.Id)
|
||||
res := &msg.ResCatnip{
|
||||
Id: int32(CatnipMod.Id),
|
||||
EndTime: int32(ActivityInfo.EndT),
|
||||
Status: int32(Status),
|
||||
Template: int32(Template),
|
||||
GameList: GameList,
|
||||
Multiply: int32(CatnipMod.Mul),
|
||||
}
|
||||
p.PushClientRes(res)
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ func ADPetWorkFire(p *Player, ChargeId int) {
|
||||
}
|
||||
}
|
||||
p.PlayMod.save()
|
||||
p.PushClientRes(ChargeMod.BackData())
|
||||
p.ChargeBackData()
|
||||
}
|
||||
|
||||
func ActivityFire(p *Player, ChargeId int) {
|
||||
@ -154,7 +154,7 @@ func ChargeFire(p *Player, ChargeId int) {
|
||||
log.Debug("ChargeFire err : %s", err)
|
||||
}
|
||||
p.PlayMod.save()
|
||||
p.PushClientRes(ChargeMod.BackData())
|
||||
p.ChargeBackData()
|
||||
}
|
||||
|
||||
func ChargeItem(p *Player, ChargeId int) []*item.Item {
|
||||
|
||||
@ -37,4 +37,20 @@ func init() {
|
||||
RegisterClusterHandler(msg.HANDLE_TYPE_REQ_CARD, FriendMgrSend)
|
||||
RegisterClusterHandler(msg.HANDLE_TYPE_AGREE_CARD, FriendMgrSend)
|
||||
RegisterClusterHandler(msg.CLUSTER_FRIEND_SYNC, ClusterFriendSync)
|
||||
RegisterClusterHandler(msg.HANDLE_TYPE_CHAMPSHIP_INRANK, champshipInrankHandler)
|
||||
RegisterClusterHandler(msg.HANDLE_TYPE_CHAMPSHIP_RANK_INFO, champshipRankInfoHandler)
|
||||
}
|
||||
|
||||
func champshipInrankHandler(m *msg.Msg) error {
|
||||
G_GameLogicPtr.ChampshipMgrSend(m)
|
||||
return nil
|
||||
}
|
||||
|
||||
func champshipRankInfoHandler(m *msg.Msg) error {
|
||||
data := G_GameLogicPtr.ChampshipMgrCall(m)
|
||||
m.To = m.From
|
||||
m.From = 0
|
||||
m.Extra = data
|
||||
FriendMgrSend(m)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -91,6 +91,8 @@ func (f *FriendMgr) Init() {
|
||||
f.RegisterHandler(msg.HANDLE_TYPE_VAR_USER_SET, f.SetVarUserData)
|
||||
|
||||
f.RegisterHandler(msg.HANDLE_TYPE_VAR_EXPIRE_SET, f.SetExpireVarData)
|
||||
|
||||
f.RegisterHandler(msg.HANDLE_TYPE_CHAMPSHIP_LOGIN, f.SendMsgToCenter)
|
||||
}
|
||||
|
||||
func (f *FriendMgr) getData() *FirendData {
|
||||
@ -253,6 +255,15 @@ func ClusterFriendSync(m *msg.Msg) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 异步发送消息给中心服
|
||||
func (f *FriendMgr) SendMsgToCenter(m *msg.Msg) (interface{}, error) {
|
||||
return nil, mergeCluster.SendServerMsg(m, conf.Server.CenterNode)
|
||||
}
|
||||
|
||||
func (f *FriendMgr) CallMsgToCenter(m *msg.Msg) (interface{}, error) {
|
||||
return mergeCluster.CallServerMsg(m, conf.Server.CenterNode)
|
||||
}
|
||||
|
||||
func FriendMgrCall(m *msg.Msg) interface{} {
|
||||
ToServer := GoUtil.GetServerIdByUid(m.To)
|
||||
if ToServer != conf.Server.ServerID {
|
||||
|
||||
@ -287,7 +287,7 @@ func (ad *GameLogic) SetUserData(Uid int, Op int, Data interface{}) {
|
||||
}
|
||||
|
||||
func (ad *GameLogic) SetDataSync(Uid int, Op int, Data interface{}) error {
|
||||
_, err := ad.FriendMgr.Call(&MsgMod.Msg{
|
||||
_, err := ad.VarMgr.Call(&MsgMod.Msg{
|
||||
From: Uid,
|
||||
To: Uid,
|
||||
Type: MsgMod.HANDLE_TYPE_VAR_EXPIRE_SET,
|
||||
@ -297,6 +297,21 @@ func (ad *GameLogic) SetDataSync(Uid int, Op int, Data interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (ad *GameLogic) SetCatnipPartner(Uid int, GameId int, PartnerUid int) error {
|
||||
_, err := ad.VarMgr.Call(&MsgMod.Msg{
|
||||
From: Uid,
|
||||
To: Uid,
|
||||
Type: MsgMod.HANDLE_TYPE_SET_CATNIP_PARTNER,
|
||||
SendT: GoUtil.Now(),
|
||||
Extra: map[string]interface{}{
|
||||
"uid": Uid,
|
||||
"game_id": GameId,
|
||||
"partner_uid": PartnerUid,
|
||||
},
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (ad *GameLogic) GetUserData(Uid int) *VarUserData {
|
||||
result, err := ad.FriendMgr.Call(&MsgMod.Msg{
|
||||
From: Uid,
|
||||
@ -891,6 +906,7 @@ func (ad *GameLogic) RegisterNetWorkFunc() {
|
||||
RegisterMsgProcessFunc("ReqCatnipPlay", ReqCatnipPlay) // 猫草大作战游戏转盘
|
||||
RegisterMsgProcessFunc("ReqCatnipReward", ReqCatnipReward) // 猫草大作战领取奖励
|
||||
RegisterMsgProcessFunc("ReqCatnipGrandReward", ReqCatnipGrandReward) // 猫草大作战领取大奖
|
||||
RegisterMsgProcessFunc("ReqCatnipEmoji", ReqCatnipEmoji)
|
||||
// 活动通行证
|
||||
RegisterMsgProcessFunc("ReqActPass", ReqActPass) // 请求活动通行证数据
|
||||
RegisterMsgProcessFunc("ReqActPassReward", ReqActPassReward) // 领取活动通行证奖励
|
||||
|
||||
@ -540,7 +540,7 @@ func ReqGmCommand_(player *Player, Command string) error {
|
||||
case "resetWeekly":
|
||||
ChargeMod := player.PlayMod.getChargeMod()
|
||||
ChargeMod.WeeklyDiscount = make(map[int]int)
|
||||
player.PushClientRes(ChargeMod.BackData())
|
||||
player.ChargeBackData()
|
||||
PlayroomMod := player.PlayMod.getPlayroomMod()
|
||||
PlayroomMod.WeeklyDiscount = make(map[int]int)
|
||||
PlayroomBackData(player)
|
||||
|
||||
@ -76,6 +76,15 @@ func LimitedTimeEventTrigger(p *Player, AddEventId int) {
|
||||
p.PushClientRes(p.PlayMod.getOrderMod().BackData())
|
||||
case limitedTimeEvent.EVENT_TYPE_CARD_FESTIVAL:
|
||||
p.PlayMod.getCardMod().CreateCardFestival()
|
||||
case limitedTimeEvent.EVENT_TYPE_CAT_DAY_SALE: // 猫咪大甩卖
|
||||
ChargeMod := p.PlayMod.getChargeMod()
|
||||
PlayroomMod := p.PlayMod.getPlayroomMod()
|
||||
if !ChargeMod.IsWeeklyDiscountDay() {
|
||||
ChargeMod.ResetWeeklyDiscount()
|
||||
PlayroomMod.ResetWeeklyDiscount()
|
||||
}
|
||||
|
||||
p.ChargeBackData()
|
||||
}
|
||||
}
|
||||
p.PushClientRes(p.PlayMod.getLimitedTimeEventMod().BackData())
|
||||
|
||||
@ -2,10 +2,11 @@ package game
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"runtime"
|
||||
kafkaMiddleware "server/middleware/kafka"
|
||||
"server/pkg/github.com/name5566/leaf/log"
|
||||
"sync"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -15,13 +16,18 @@ const (
|
||||
)
|
||||
const (
|
||||
PLAYROOM_LOST = "playroom_lost"
|
||||
LOG_LENGTH = 10000
|
||||
// 增大缓冲:针对 ~1000 条/s,保留足够秒数的缓冲(可按需调整)
|
||||
LOG_LENGTH = 100000
|
||||
WORKER_COUNT = 16
|
||||
)
|
||||
|
||||
type LogMgr struct {
|
||||
L []*Log
|
||||
McronSave *cron.Cron
|
||||
Lock sync.Mutex
|
||||
// 将切片改为带缓冲通道
|
||||
L chan *Log
|
||||
Lock sync.Mutex
|
||||
wg sync.WaitGroup
|
||||
stopOnce sync.Once
|
||||
closing bool
|
||||
}
|
||||
|
||||
type Log struct {
|
||||
@ -34,46 +40,101 @@ type Log struct {
|
||||
}
|
||||
|
||||
func (L *LogMgr) InitManager() {
|
||||
L.McronSave = cron.New()
|
||||
L.L = make([]*Log, 0, LOG_LENGTH)
|
||||
L.McronSave.AddFunc("@every 10s", func() {
|
||||
L.Lock.Lock()
|
||||
defer L.Lock.Unlock()
|
||||
if kafkaMiddleware.KafkaMod == nil {
|
||||
if len(L.L) > LOG_LENGTH {
|
||||
L.L = L.L[:0]
|
||||
} else if len(L.L) > LOG_LENGTH {
|
||||
L.L = L.L[len(L.L)-LOG_LENGTH:]
|
||||
// 初始化通道与启动 worker 循环写入 kafka
|
||||
L.L = make(chan *Log, LOG_LENGTH)
|
||||
|
||||
// 启动 worker(允许基于 CPU 动态扩展)
|
||||
workerCount := WORKER_COUNT
|
||||
if cpuWorkers := runtime.NumCPU() * 2; cpuWorkers > workerCount {
|
||||
workerCount = cpuWorkers
|
||||
}
|
||||
for i := 0; i < workerCount; i++ {
|
||||
L.wg.Add(1)
|
||||
go func() {
|
||||
defer L.wg.Done()
|
||||
for v := range L.L {
|
||||
// 如果 kafka 未就绪,尝试重入队列并等待一小段时间(缩短等待)
|
||||
if kafkaMiddleware.KafkaMod == nil {
|
||||
// 尝试非阻塞重入,否则丢弃最旧再试一次
|
||||
select {
|
||||
case L.L <- v:
|
||||
default:
|
||||
select {
|
||||
case <-L.L:
|
||||
default:
|
||||
}
|
||||
select {
|
||||
case L.L <- v:
|
||||
default:
|
||||
}
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
continue
|
||||
}
|
||||
|
||||
value, _ := json.Marshal(v)
|
||||
if err := kafkaMiddleware.SendMsg([]byte(v.EventName), value); err != nil {
|
||||
log.Debug("kafka log send err:%s", err.Error())
|
||||
// 发送失败,尝试将消息放回通道(非阻塞策略)
|
||||
select {
|
||||
case L.L <- v:
|
||||
default:
|
||||
// 通道满,丢弃最旧一条后再尝试一次入队
|
||||
select {
|
||||
case <-L.L:
|
||||
default:
|
||||
}
|
||||
select {
|
||||
case L.L <- v:
|
||||
default:
|
||||
// 放不下则丢弃
|
||||
}
|
||||
}
|
||||
// 缩短退避,避免快速循环阻塞
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
Quene := L.L
|
||||
NewQuene := make([]*Log, 0, LOG_LENGTH)
|
||||
for _, v := range Quene {
|
||||
value, _ := json.Marshal(v)
|
||||
err := kafkaMiddleware.SendMsg([]byte(v.EventName), value)
|
||||
if err != nil {
|
||||
NewQuene = append(NewQuene, v)
|
||||
}
|
||||
}
|
||||
L.L = NewQuene
|
||||
})
|
||||
L.McronSave.Start()
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func (L *LogMgr) AddLog(logs *Log) {
|
||||
// 如果已经开始关闭,直接丢弃
|
||||
L.Lock.Lock()
|
||||
defer L.Lock.Unlock()
|
||||
L.L = append(L.L, logs)
|
||||
if L.closing {
|
||||
L.Lock.Unlock()
|
||||
return
|
||||
}
|
||||
// 非阻塞入队:若通道满则先丢弃最旧一条再入队,避免阻塞调用者
|
||||
select {
|
||||
case L.L <- logs:
|
||||
L.Lock.Unlock()
|
||||
return
|
||||
default:
|
||||
// 丢弃最旧一条以腾出空间(若有)
|
||||
select {
|
||||
case <-L.L:
|
||||
default:
|
||||
}
|
||||
// 再尝试入队一次
|
||||
select {
|
||||
case L.L <- logs:
|
||||
default:
|
||||
// 放不下就直接丢弃
|
||||
}
|
||||
L.Lock.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func (L *LogMgr) Close() {
|
||||
L.McronSave.Stop()
|
||||
L.Lock.Lock()
|
||||
defer L.Lock.Unlock()
|
||||
for _, v := range L.L {
|
||||
value, _ := json.Marshal(v)
|
||||
kafkaMiddleware.SendMsg([]byte(v.EventName), value)
|
||||
}
|
||||
L.L = L.L[:0]
|
||||
L.stopOnce.Do(func() {
|
||||
L.Lock.Lock()
|
||||
// 标记为正在关闭,阻止后续入队
|
||||
L.closing = true
|
||||
// 关闭通道,通知所有 worker 退出(workers 会消费完所有已入队的消息)
|
||||
close(L.L)
|
||||
L.Lock.Unlock()
|
||||
// 等待所有 worker 处理完
|
||||
L.wg.Wait()
|
||||
})
|
||||
}
|
||||
|
||||
@ -327,7 +327,7 @@ func (p *Player) ZeroUpdate(a []interface{}) {
|
||||
ChessMod := p.PlayMod.getChessMod()
|
||||
ChargeMod := p.PlayMod.getChargeMod()
|
||||
ChargeMod.ZeroUpdate(ChessMod.GetEmitList())
|
||||
p.PushClientRes(p.PlayMod.getChargeMod().BackData())
|
||||
p.ChargeBackData()
|
||||
|
||||
// 无尽礼包
|
||||
p.PlayMod.getEndlessMod().ZeroUpdate(p.PlayMod.getChargeMod().GetMaxCharge(), p.PlayMod.getBaseMod().GetLevel())
|
||||
@ -344,6 +344,9 @@ func (p *Player) ZeroUpdate(a []interface{}) {
|
||||
// playroom
|
||||
PlayroomMod := p.PlayMod.getPlayroomMod()
|
||||
PlayroomMod.ZeroUpdate()
|
||||
if ChargeMod.IsWeeklyDiscountDay() {
|
||||
PlayroomMod.ResetWeeklyDiscount()
|
||||
}
|
||||
PlayroomBackData(p)
|
||||
p.PlayMod.getChampshipMod().ZeroUpdate()
|
||||
p.initAcitivity()
|
||||
@ -375,7 +378,7 @@ func (p *Player) NoonUpdate(a []interface{}) {
|
||||
ChessMod := p.PlayMod.getChessMod()
|
||||
// 礼包充值
|
||||
p.PlayMod.getChargeMod().NoonUpdate(ChessMod.GetEmitList())
|
||||
p.PushClientRes(p.PlayMod.getChargeMod().BackData())
|
||||
p.ChargeBackData()
|
||||
p.PlayMod.save()
|
||||
}
|
||||
|
||||
@ -414,17 +417,30 @@ func (p *Player) Login() {
|
||||
ChargeMod.WeeklyEndTime = WeeklyEndTime
|
||||
}
|
||||
if WeeklyStartTime > now {
|
||||
go func() {
|
||||
time.Sleep(time.Duration(WeeklyStartTime-now) * time.Second)
|
||||
p.CallEvent(time.Duration(WeeklyStartTime-now)*time.Second, func() {
|
||||
ChargeMod.WeeklyEndTime = WeeklyEndTime
|
||||
p.PushClientRes(ChargeMod.BackData())
|
||||
ChargeMod.ResetWeeklyDiscount()
|
||||
PlayroomMod := p.PlayMod.getPlayroomMod()
|
||||
PlayroomMod.ResetWeeklyDiscount()
|
||||
p.ChargeBackData()
|
||||
PlayroomBackData(p)
|
||||
}()
|
||||
}, "WeeklyDiscountStart")
|
||||
}
|
||||
if WeeklyEndTime > now {
|
||||
p.CallEvent(time.Duration(WeeklyEndTime-now)*time.Second, func() {
|
||||
ChargeMod.WeeklyEndTime = 0
|
||||
p.ChargeBackData()
|
||||
PlayroomBackData(p)
|
||||
LimitEventMod := p.PlayMod.getLimitedTimeEventMod()
|
||||
LimitEventMod.EndCatDaySale()
|
||||
p.PushClientRes(LimitEventMod.BackData())
|
||||
}, "WeeklyDiscountEnd")
|
||||
}
|
||||
if Duration > 604800 {
|
||||
FriendMod := p.PlayMod.getFriendMod()
|
||||
FriendMod.AddActLog(friend.ACT_LOG_TYPE_LOST_USER_RETURN, "")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (p *Player) Outline() {
|
||||
@ -879,7 +895,6 @@ func (p *Player) LoginBackData() {
|
||||
p.PushClientRes(p.PlayMod.mod_list.DailyTask.BackData())
|
||||
p.PushClientRes(p.PlayMod.mod_list.SevenLogin.BackData())
|
||||
p.PushClientRes(p.PlayMod.mod_list.LimitedTimeEvent.ProgressBackData())
|
||||
p.PushClientRes(p.PlayMod.mod_list.Charge.BackData())
|
||||
p.PushClientRes(p.PlayMod.mod_list.Charge.PetWorkBackData())
|
||||
p.PushClientRes(p.PlayMod.mod_list.Endless.BackData())
|
||||
p.PushClientRes(p.PlayMod.mod_list.PiggyBank.BackData())
|
||||
@ -890,6 +905,7 @@ func (p *Player) LoginBackData() {
|
||||
p.PushClientRes(p.PlayMod.mod_list.Friend.BubbleBackData())
|
||||
p.PushClientRes(p.PlayMod.mod_list.Guide.BackData())
|
||||
p.BackDataActivity()
|
||||
p.ChargeBackData()
|
||||
BackChampship(p)
|
||||
BackUserInfo(p)
|
||||
}
|
||||
|
||||
@ -2,8 +2,10 @@ package game
|
||||
|
||||
import (
|
||||
"server/GoUtil"
|
||||
chargeCfg "server/conf/charge"
|
||||
playroomCfg "server/conf/playroom"
|
||||
"server/game/mod/item"
|
||||
"server/game/mod/limitedTimeEvent"
|
||||
proto "server/msg"
|
||||
)
|
||||
|
||||
@ -125,7 +127,9 @@ func PlayroomBackData(p *Player) {
|
||||
}
|
||||
weeklyDiscount := make(map[int32]*proto.WeeklyDiscountInfo)
|
||||
ChargeMod := p.PlayMod.getChargeMod()
|
||||
if ChargeMod.IsWeeklyDiscountDay() {
|
||||
LimitedEventMod := p.PlayMod.getLimitedTimeEventMod()
|
||||
// 优惠日开启或者猫咪闪促开启
|
||||
if ChargeMod.IsWeeklyDiscountDay() || LimitedEventMod.CheckExist(limitedTimeEvent.EVENT_TYPE_CAT_DAY_SALE) {
|
||||
w1 := playroomCfg.GetShopWeeklyLimit()
|
||||
for k, v := range w1 {
|
||||
limitNum := PlayroomMod.WeeklyDiscount[k]
|
||||
@ -196,7 +200,6 @@ func PlayroomVisit(p *Player, Uid int) {
|
||||
r.Chip = int32(data.Chip)
|
||||
r.Kiss = int32(data.Kiss)
|
||||
r.DressSet = GoUtil.MapIntToInt32(PlayerData.DressSet)
|
||||
|
||||
p.PushClientRes(r)
|
||||
}
|
||||
|
||||
@ -229,3 +232,65 @@ func BackUserInfo(p *Player) {
|
||||
AddCode: BaseMod.AddCode,
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Player) ChargeBackData() {
|
||||
c := p.PlayMod.getChargeMod()
|
||||
LimitedEvnetMod := p.PlayMod.getLimitedTimeEventMod()
|
||||
SpecialShop := make(map[int32]*proto.ResSpecialShop)
|
||||
ChessShop := make(map[int32]*proto.ResChessShop)
|
||||
for k, v := range c.SpecialShop {
|
||||
SpecialShop[int32(k)] = &proto.ResSpecialShop{
|
||||
Grade: int32(v.Grade),
|
||||
Count: int32(v.Count),
|
||||
}
|
||||
}
|
||||
|
||||
for k, v := range c.ChessShop {
|
||||
ChessShop[int32(k)] = &proto.ResChessShop{
|
||||
Diamond: int32(v.Diamond),
|
||||
Count: int32(v.Count),
|
||||
ChessId: int32(v.Id),
|
||||
}
|
||||
}
|
||||
resWish := &proto.WishList{}
|
||||
if c.WishList != nil {
|
||||
resWish = &proto.WishList{
|
||||
Id: int32(c.WishList.ItemId),
|
||||
Count: int32(c.WishList.Count),
|
||||
Uid: c.WishList.SendList,
|
||||
}
|
||||
}
|
||||
WeeklyDiscount := make(map[int32]*proto.WeeklyDiscountInfo)
|
||||
WeeklyDiscountInfo := chargeCfg.GetWeeklyInfoAll()
|
||||
// 优惠日开启或者猫咪闪促开启
|
||||
if c.IsWeeklyDiscountDay() || LimitedEvnetMod.CheckExist(limitedTimeEvent.EVENT_TYPE_CAT_DAY_SALE) {
|
||||
for k, v := range WeeklyDiscountInfo {
|
||||
LimitNum := c.WeeklyDiscount[k]
|
||||
WeeklyDiscount[int32(k)] = &proto.WeeklyDiscountInfo{
|
||||
Discount: int32(v.Discount),
|
||||
Count: int32(v.WeeklyLimit - LimitNum),
|
||||
Id: int32(k),
|
||||
}
|
||||
}
|
||||
}
|
||||
CatDaySaleEndTime := LimitedEvnetMod.GetCatDaySaleEndTime()
|
||||
p.PushClientRes(&proto.ResCharge{
|
||||
Charge: float32(c.Charge),
|
||||
Total: int32(c.Total),
|
||||
First: GoUtil.MapIntToSlice(c.EnergyShop),
|
||||
SpecialShop: SpecialShop,
|
||||
FreeShop: int32(c.FreeShop),
|
||||
ChessShop: ChessShop,
|
||||
Gift: GoUtil.MapIntToInt32(c.Gift),
|
||||
Ad: c.Ad,
|
||||
SpecialCharge: float32(c.SpecialCharge),
|
||||
SpecialChargeWeek: int32(GoUtil.FullWeeksSince(c.LastSpecialCharge)),
|
||||
TodayCharge: float32(c.TodayCharge),
|
||||
MonthCharge: float32(c.MonthCharge),
|
||||
Wish: resWish,
|
||||
AdEndTime: c.AdEndTime,
|
||||
WeeklyDiscount: WeeklyDiscount,
|
||||
PetWorkRemainTime: c.PetWorkTime,
|
||||
WeeklyEndTime: max(c.WeeklyEndTime, CatDaySaleEndTime),
|
||||
})
|
||||
}
|
||||
|
||||
@ -213,7 +213,10 @@ func (p *PlayerBaseData) ResPlayerBaseInfo(player *Player) {
|
||||
func (p *PlayerBaseData) ReqBindFacebookAccount(player *Player, buf []byte) {
|
||||
req := &msg.ReqBindFacebookAccount{}
|
||||
res := &msg.ResBindFacebookAccount{}
|
||||
proto.Unmarshal(buf, req)
|
||||
err := proto.Unmarshal(buf, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sqlStr := "SELECT * FROM t_player_baseinfo WHERE FaceBookId = ?"
|
||||
sqlStruck := db.ResPlayerBaseInfo{}
|
||||
@ -251,7 +254,10 @@ func (p *PlayerBaseData) ReqBindFacebookAccount(player *Player, buf []byte) {
|
||||
func (p *PlayerBaseData) ReqUnBindFacebook(player *Player, buf []byte) {
|
||||
req := &msg.ReqUnBindFacebook{}
|
||||
res := &msg.ResUnBindFacebook{}
|
||||
proto.Unmarshal(buf, req)
|
||||
err := proto.Unmarshal(buf, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
res.ResultCode = 0
|
||||
res.BindAccountId = req.BindAccountId
|
||||
@ -270,12 +276,15 @@ func (p *PlayerBaseData) ReqUnBindFacebook(player *Player, buf []byte) {
|
||||
func (p *PlayerBaseData) ReqOnlyBindFacebook(player *Player, buf []byte) {
|
||||
req := &msg.ReqOnlyBindFacebook{}
|
||||
res := &msg.ResOnlyBindFacebook{}
|
||||
proto.Unmarshal(buf, req)
|
||||
err := proto.Unmarshal(buf, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sqlStr := "SELECT * FROM t_player_baseinfo WHERE FaceBookId = ?"
|
||||
sqlStruck := db.ResPlayerBaseInfo{}
|
||||
isHaveOther := false
|
||||
err := db.SqlDb.Get(&sqlStruck, sqlStr, req.BindAccountId)
|
||||
err = db.SqlDb.Get(&sqlStruck, sqlStr, req.BindAccountId)
|
||||
if err != nil {
|
||||
isHaveOther = false
|
||||
} else {
|
||||
@ -334,7 +343,10 @@ func (p *PlayerBaseData) ReqOnlyBindFacebook(player *Player, buf []byte) {
|
||||
func (p *PlayerBaseData) ReqSynGameData(player *Player, buf []byte) {
|
||||
req := &msg.ReqSynGameData{}
|
||||
res := &msg.ResSynGameData{}
|
||||
proto.Unmarshal(buf, req)
|
||||
err := proto.Unmarshal(buf, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sqlStr := "SELECT * FROM t_player_baseinfo WHERE FaceBookId = ?"
|
||||
sqlStruck := db.ResPlayerBaseInfo{}
|
||||
@ -524,7 +536,7 @@ func (p *PlayerBaseData) AddExp(player *Player, exp int, pexp int) (int, error)
|
||||
}
|
||||
ChargeMod := player.PlayMod.getChargeMod()
|
||||
ChargeMod.TriggerChargeUnlock(int(BaseMod.Level), ChessMod.GetEmitList())
|
||||
player.PushClientRes(ChargeMod.BackData())
|
||||
player.ChargeBackData()
|
||||
OrderMod := player.PlayMod.getOrderMod()
|
||||
player.TriggerOrder(BaseMod.Level, order.TRIGGER_TYPE_LV, ChessMod.GetOrderEmit(), player.PlayMod.getBaseMod().GetEnergyMul())
|
||||
player.PushClientRes(OrderMod.BackData())
|
||||
|
||||
@ -23,6 +23,7 @@ import (
|
||||
"server/game/mod/card"
|
||||
"server/game/mod/friend"
|
||||
"server/game/mod/item"
|
||||
"server/game/mod/limitedTimeEvent"
|
||||
"server/game/mod/mail"
|
||||
"server/game/mod/msg"
|
||||
"server/game/mod/order"
|
||||
@ -320,7 +321,7 @@ func handle(p *Player, m *msg.Msg) error {
|
||||
ChargeMod := p.PlayMod.getChargeMod()
|
||||
ChargeMod.AddWishCount()
|
||||
p.AddLog(m.From, friend.LOG_TYPE_WISH, "", m.SendT)
|
||||
p.PushClientRes(ChargeMod.BackData())
|
||||
p.ChargeBackData()
|
||||
case msg.HANDLE_TYPE_PLAYROOM_KISS: // playroom亲吻
|
||||
p.NotifyPlayroomKiss()
|
||||
case msg.HANDLE_TYPE_CATNIP_INVITE: // 邀请好友参与猫咪游戏
|
||||
@ -331,6 +332,8 @@ func handle(p *Player, m *msg.Msg) error {
|
||||
return nil
|
||||
}
|
||||
CatnipMod.BeInvited(CatnipMsg.GameId, int(m.From), m.SendT)
|
||||
FriendMod := p.PlayMod.getFriendMod()
|
||||
FriendMod.AddReplyInfo(m.From, friend.REPLY_TYPE_CATNIP, fmt.Sprintf("%d", CatnipMsg.GameId), m.End)
|
||||
case msg.HANDLE_TYPE_CATNIP_AGREE: // 同意好友参与猫咪游戏
|
||||
CatnipMod := p.PlayMod.getCatnipMod()
|
||||
CatnipMsgInfo := m.Extra.(CatnipMsg)
|
||||
@ -378,7 +381,7 @@ func handle(p *Player, m *msg.Msg) error {
|
||||
case msg.HANDLE_TYPE_FRIEND_GREETING_REPLY:
|
||||
FriendMod := p.PlayMod.getFriendMod()
|
||||
if v, ok := m.Extra.(friend.ReplyInfo); ok {
|
||||
FriendMod.AddReplyInfo(v.Uid, v.Type, v.Param)
|
||||
FriendMod.AddReplyInfo(v.Uid, v.Type, v.Param, GoUtil.Now()+24*3600)
|
||||
FriendLogBackData(p)
|
||||
}
|
||||
case msg.HANDLE_TYPE_FRIEND_SPONSOER:
|
||||
@ -965,7 +968,7 @@ func EmitRetireTrigger2(p *Player) {
|
||||
ChessMod.FinishRetire(k)
|
||||
ChargeMod := p.PlayMod.getChargeMod()
|
||||
ChargeMod.InitChessShop(ChessMod.GetEmitList())
|
||||
p.PushClientRes(ChargeMod.BackData())
|
||||
p.ChargeBackData()
|
||||
continue
|
||||
}
|
||||
OrderMod.CreateCleanOrder(ChessList)
|
||||
@ -1576,3 +1579,9 @@ func (player *Player) GetPlayroomClean() map[int]int {
|
||||
}
|
||||
return Item
|
||||
}
|
||||
|
||||
func (player *Player) IsWeeklyDiscount() bool {
|
||||
ChargeMod := player.PlayMod.getChargeMod()
|
||||
LimitEventMod := player.PlayMod.getLimitedTimeEventMod()
|
||||
return ChargeMod.IsWeeklyDiscountDay() || LimitEventMod.CheckExist(limitedTimeEvent.EVENT_TYPE_CAT_DAY_SALE)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -8,6 +8,7 @@ import (
|
||||
"server/MergeConst"
|
||||
"server/conf"
|
||||
champshipCfg "server/conf/champship"
|
||||
chargeCfg "server/conf/charge"
|
||||
languageCfg "server/conf/language"
|
||||
mailCfg "server/conf/mail"
|
||||
mergeDataCfg "server/conf/mergeData"
|
||||
@ -113,12 +114,10 @@ func TriggerShippingOrderOrigin(player *Player, req *msg.ReqShippingOrder) {
|
||||
log.Debug("charge shipping order already shipped OrderSn:%s", OrderSn)
|
||||
return
|
||||
}
|
||||
// if !conf.Server.GoogleVerify {
|
||||
// Order.PayStatus = MergeConst.ORDER_STATUS_PAY
|
||||
// return
|
||||
// }
|
||||
|
||||
if conf.Server.GameName == "Merge_Pet_online" {
|
||||
GoUtil.SendFeishuOrder(int(player.M_DwUin), OrderData.PayChannelOrderId, OrderData.Price, req.ProduceId, OrderData.PayTime, GoUtil.Now())
|
||||
ProduceName := chargeCfg.GetProduceName(OrderData.ProductId)
|
||||
GoUtil.SendFeishuOrder(int(player.M_DwUin), OrderData.PayChannelOrderId, OrderData.Price, ProduceName, OrderData.PayTime, GoUtil.Now())
|
||||
}
|
||||
log.Debug("[order verify success] Uid:%d;OrderSn:%s;PayOrder:%s;Token:%s", player.M_DwUin, OrderData.OrderId, OrderData.PayChannelOrderId, req.Token)
|
||||
player.lock.Lock()
|
||||
|
||||
@ -332,7 +332,7 @@ func UnitDecoratePartCost(p *Player) error {
|
||||
DecorateMod.PartClassPool = []int{}
|
||||
DecorateMod.PartPool = make(map[int]int)
|
||||
DecorateMod.InitData()
|
||||
Items, _, _ := DecorateMod.GetDecorateCostItem(1, 33)
|
||||
Items, _, _ := DecorateMod.GetDecorateCostItem(1, 33, false)
|
||||
err := p.HandleLoseItem(Items, "")
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
|
||||
@ -2,6 +2,7 @@ package game
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"server/GoUtil"
|
||||
"server/game/mod/card"
|
||||
"server/game/mod/msg"
|
||||
@ -51,6 +52,7 @@ func (f *VarMgr) Init() {
|
||||
f.ZeroUpdate(&msg.Msg{})
|
||||
}
|
||||
f.RegisterHandler(msg.SERVER_ZERO_UPDATE, f.ZeroUpdate)
|
||||
f.RegisterHandler(msg.HANDLE_TYPE_SET_CATNIP_PARTNER, f.SetCatnipPartner)
|
||||
|
||||
f.mDispatr.AfterFunc(time.Duration(GoUtil.NextZeroTimestampDuration())*time.Second, func() {
|
||||
f.Send(&msg.Msg{
|
||||
@ -79,6 +81,30 @@ func (f *VarMgr) ZeroUpdate(m *msg.Msg) (interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f *VarMgr) SetCatnipPartner(m *msg.Msg) (interface{}, error) {
|
||||
if Param, ok := m.Extra.(map[string]interface{}); ok {
|
||||
MyUid := GoUtil.Int(Param["uid"])
|
||||
CatnipGameId := GoUtil.Int(Param["game_id"])
|
||||
CatnipPartnerId := GoUtil.Int(Param["partner_uid"])
|
||||
myKey := fmt.Sprintf("catnip_partner_%d_%d", MyUid, CatnipGameId)
|
||||
key := fmt.Sprintf("catnip_partner_%d_%d", CatnipPartnerId, CatnipGameId)
|
||||
PartnerInfo := f.GetExpireVar(key)
|
||||
if PartnerInfo.D != nil {
|
||||
return nil, fmt.Errorf("catnip partner already set for uid %d in game %d", CatnipPartnerId, CatnipGameId)
|
||||
}
|
||||
f.SetExpireVar(key, &VarExpireData{
|
||||
D: MyUid,
|
||||
T: m.End,
|
||||
})
|
||||
f.SetExpireVar(myKey, &VarExpireData{
|
||||
D: CatnipPartnerId,
|
||||
T: m.End,
|
||||
})
|
||||
return nil, nil
|
||||
}
|
||||
return nil, fmt.Errorf("invalid parameters for setting catnip partner")
|
||||
}
|
||||
|
||||
func (f *VarMgr) SetVar(key string, value interface{}) {
|
||||
f.getData().Var[key] = value
|
||||
}
|
||||
|
||||
@ -8,9 +8,9 @@ import (
|
||||
)
|
||||
|
||||
type CatnipMod struct {
|
||||
Id int
|
||||
Game map[int]*CatnipGame
|
||||
|
||||
Id int
|
||||
Game map[int]*CatnipGame
|
||||
Mul int // 倍数
|
||||
IsGetGrandReward bool // 是否领取过大丰收奖励
|
||||
}
|
||||
|
||||
@ -25,10 +25,10 @@ type CatnipGame struct {
|
||||
Progress int // 进度
|
||||
PartnerAdd int // 伙伴贡献
|
||||
Reward []int // 已领取阶段奖励
|
||||
Mul int // 倍数
|
||||
Status int // 0: Not Started, 1: In Progress, 2: Completed
|
||||
InviteList map[int]*InviteInfo // 邀请列表,key: 邀请者ID, value: 被邀请者ID
|
||||
BeInvitedList map[int]*InviteInfo // 被邀请列表,key: 被邀请者ID, value: 邀请者ID
|
||||
EmojiId int // 表情ID
|
||||
}
|
||||
|
||||
const (
|
||||
@ -39,6 +39,7 @@ const (
|
||||
|
||||
func (c *CatnipMod) InitData() {
|
||||
// Initialize Catnip data here
|
||||
// c.Game = nil
|
||||
if c.Game == nil {
|
||||
c.Game = make(map[int]*CatnipGame)
|
||||
}
|
||||
@ -56,13 +57,16 @@ func (c *CatnipMod) Login(Id int) int {
|
||||
c.Id = Id
|
||||
c.IsGetGrandReward = false // Reset grand reward status on login
|
||||
c.Game = make(map[int]*CatnipGame)
|
||||
c.Mul = 1 // Default multiplier
|
||||
GameNum := catnipCfg.GetGameNum(c.Id) // Assuming 1 is the default game ID
|
||||
for i := 1; i <= GameNum; i++ {
|
||||
c.Game[i] = &CatnipGame{
|
||||
Id: i,
|
||||
Partner: 0, // No partner initially
|
||||
Progress: 0, // Initial progress
|
||||
Status: GAME_STATUS_IDLE, // Not started
|
||||
Id: i,
|
||||
Partner: 0, // No partner initially
|
||||
Progress: 0, // Initial progress
|
||||
Status: GAME_STATUS_IDLE, // Not started
|
||||
InviteList: make(map[int]*InviteInfo), // Initialize invite list
|
||||
BeInvitedList: make(map[int]*InviteInfo), // Initialize be invited list
|
||||
}
|
||||
}
|
||||
return c.Id
|
||||
@ -144,12 +148,8 @@ func (c *CatnipMod) DelInvited(Id, Uid int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *CatnipMod) Multiply(Id, Mul int) error {
|
||||
GameInfo, ok := c.Game[Id]
|
||||
if !ok {
|
||||
return fmt.Errorf("game with ID %d does not exist", Id)
|
||||
}
|
||||
GameInfo.Mul = Mul
|
||||
func (c *CatnipMod) Multiply(Mul int) error {
|
||||
c.Mul = Mul
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -170,11 +170,12 @@ func (c *CatnipMod) Play(Id int) (int, int, int, []*item.Item, []*item.Item, err
|
||||
if !ok {
|
||||
return 0, 0, 0, nil, nil, fmt.Errorf("game with ID %d does not exist", Id)
|
||||
}
|
||||
Id, Items, Growth := catnipCfg.GetJackpotItem(GameInfo.Mul)
|
||||
Id, Items, Growth := catnipCfg.GetJackpotItem(c.Mul)
|
||||
if Growth > 0 {
|
||||
c.Growth(Id, Growth)
|
||||
}
|
||||
ItemCost := catnipCfg.GetItemCost(c.Id, GameInfo.Mul)
|
||||
ItemCost := catnipCfg.GetItemCost(c.Id, c.Mul)
|
||||
GameInfo.Progress += Growth
|
||||
return Id, Growth, GameInfo.Partner, Items, ItemCost, nil
|
||||
}
|
||||
|
||||
@ -219,3 +220,12 @@ func (c *CatnipMod) Growth(Id, Growth int) {
|
||||
GameInfo.Status = GAME_STATUS_COMPLETED
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CatnipMod) SetEmoji(Id, EmojiId int) {
|
||||
GameInfo, ok := c.Game[Id]
|
||||
if !ok {
|
||||
return // Game does not exist
|
||||
}
|
||||
// Here we can set the emoji for the game. This is a placeholder implementation.
|
||||
GameInfo.EmojiId = EmojiId
|
||||
}
|
||||
|
||||
@ -136,8 +136,8 @@ func (c *ChargeMod) ZeroUpdate(Emit []int) {
|
||||
c.SpecialShop[i] = &SepcialShop{Grade: SpecialGrade, Count: SpecialShopCount}
|
||||
}
|
||||
c.WishList.SendList = make([]int64, 0)
|
||||
c.WeeklyDiscount = make(map[int]int)
|
||||
if c.IsWeeklyDiscountDay() && c.WeeklyEndTime < Now {
|
||||
c.WeeklyDiscount = make(map[int]int)
|
||||
c.WeeklyEndTime = GoUtil.ZeroTimestamp() + 7*24*3600
|
||||
}
|
||||
c.InitChessShop(Emit)
|
||||
@ -285,63 +285,63 @@ func (c *ChargeMod) FireFreeShop() ([]*item.Item, error) {
|
||||
}
|
||||
|
||||
// 返回数据
|
||||
func (c *ChargeMod) BackData() *msg.ResCharge {
|
||||
SpecialShop := make(map[int32]*msg.ResSpecialShop)
|
||||
ChessShop := make(map[int32]*msg.ResChessShop)
|
||||
for k, v := range c.SpecialShop {
|
||||
SpecialShop[int32(k)] = &msg.ResSpecialShop{
|
||||
Grade: int32(v.Grade),
|
||||
Count: int32(v.Count),
|
||||
}
|
||||
}
|
||||
// func (c *ChargeMod) BackData() *msg.ResCharge {
|
||||
// SpecialShop := make(map[int32]*msg.ResSpecialShop)
|
||||
// ChessShop := make(map[int32]*msg.ResChessShop)
|
||||
// for k, v := range c.SpecialShop {
|
||||
// SpecialShop[int32(k)] = &msg.ResSpecialShop{
|
||||
// Grade: int32(v.Grade),
|
||||
// Count: int32(v.Count),
|
||||
// }
|
||||
// }
|
||||
|
||||
for k, v := range c.ChessShop {
|
||||
ChessShop[int32(k)] = &msg.ResChessShop{
|
||||
Diamond: int32(v.Diamond),
|
||||
Count: int32(v.Count),
|
||||
ChessId: int32(v.Id),
|
||||
}
|
||||
}
|
||||
resWish := &msg.WishList{}
|
||||
if c.WishList != nil {
|
||||
resWish = &msg.WishList{
|
||||
Id: int32(c.WishList.ItemId),
|
||||
Count: int32(c.WishList.Count),
|
||||
Uid: c.WishList.SendList,
|
||||
}
|
||||
}
|
||||
WeeklyDiscount := make(map[int32]*msg.WeeklyDiscountInfo)
|
||||
WeeklyDiscountInfo := chargeCfg.GetWeeklyInfoAll()
|
||||
if c.IsWeeklyDiscountDay() {
|
||||
for k, v := range WeeklyDiscountInfo {
|
||||
LimitNum := c.WeeklyDiscount[k]
|
||||
WeeklyDiscount[int32(k)] = &msg.WeeklyDiscountInfo{
|
||||
Discount: int32(v.Discount),
|
||||
Count: int32(v.WeeklyLimit - LimitNum),
|
||||
Id: int32(k),
|
||||
}
|
||||
}
|
||||
}
|
||||
return &msg.ResCharge{
|
||||
Charge: float32(c.Charge),
|
||||
Total: int32(c.Total),
|
||||
First: GoUtil.MapIntToSlice(c.EnergyShop),
|
||||
SpecialShop: SpecialShop,
|
||||
FreeShop: int32(c.FreeShop),
|
||||
ChessShop: ChessShop,
|
||||
Gift: GoUtil.MapIntToInt32(c.Gift),
|
||||
Ad: c.Ad,
|
||||
SpecialCharge: float32(c.SpecialCharge),
|
||||
SpecialChargeWeek: int32(GoUtil.FullWeeksSince(c.LastSpecialCharge)),
|
||||
TodayCharge: float32(c.TodayCharge),
|
||||
MonthCharge: float32(c.MonthCharge),
|
||||
Wish: resWish,
|
||||
AdEndTime: c.AdEndTime,
|
||||
WeeklyDiscount: WeeklyDiscount,
|
||||
PetWorkRemainTime: c.PetWorkTime,
|
||||
WeeklyEndTime: c.WeeklyEndTime,
|
||||
}
|
||||
}
|
||||
// for k, v := range c.ChessShop {
|
||||
// ChessShop[int32(k)] = &msg.ResChessShop{
|
||||
// Diamond: int32(v.Diamond),
|
||||
// Count: int32(v.Count),
|
||||
// ChessId: int32(v.Id),
|
||||
// }
|
||||
// }
|
||||
// resWish := &msg.WishList{}
|
||||
// if c.WishList != nil {
|
||||
// resWish = &msg.WishList{
|
||||
// Id: int32(c.WishList.ItemId),
|
||||
// Count: int32(c.WishList.Count),
|
||||
// Uid: c.WishList.SendList,
|
||||
// }
|
||||
// }
|
||||
// WeeklyDiscount := make(map[int32]*msg.WeeklyDiscountInfo)
|
||||
// WeeklyDiscountInfo := chargeCfg.GetWeeklyInfoAll()
|
||||
// if c.IsWeeklyDiscountDay() {
|
||||
// for k, v := range WeeklyDiscountInfo {
|
||||
// LimitNum := c.WeeklyDiscount[k]
|
||||
// WeeklyDiscount[int32(k)] = &msg.WeeklyDiscountInfo{
|
||||
// Discount: int32(v.Discount),
|
||||
// Count: int32(v.WeeklyLimit - LimitNum),
|
||||
// Id: int32(k),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return &msg.ResCharge{
|
||||
// Charge: float32(c.Charge),
|
||||
// Total: int32(c.Total),
|
||||
// First: GoUtil.MapIntToSlice(c.EnergyShop),
|
||||
// SpecialShop: SpecialShop,
|
||||
// FreeShop: int32(c.FreeShop),
|
||||
// ChessShop: ChessShop,
|
||||
// Gift: GoUtil.MapIntToInt32(c.Gift),
|
||||
// Ad: c.Ad,
|
||||
// SpecialCharge: float32(c.SpecialCharge),
|
||||
// SpecialChargeWeek: int32(GoUtil.FullWeeksSince(c.LastSpecialCharge)),
|
||||
// TodayCharge: float32(c.TodayCharge),
|
||||
// MonthCharge: float32(c.MonthCharge),
|
||||
// Wish: resWish,
|
||||
// AdEndTime: c.AdEndTime,
|
||||
// WeeklyDiscount: WeeklyDiscount,
|
||||
// PetWorkRemainTime: c.PetWorkTime,
|
||||
// WeeklyEndTime: c.WeeklyEndTime,
|
||||
// }
|
||||
// }
|
||||
|
||||
func (c *ChargeMod) InitChessShop(Emit []int) {
|
||||
if len(Emit) == 0 {
|
||||
@ -401,9 +401,9 @@ func (c *ChargeMod) InitChessShop(Emit []int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ChargeMod) BuyEnergy() ([]*item.Item, []*item.Item, int) {
|
||||
func (c *ChargeMod) BuyEnergy(IsWeeklyDiscount bool) ([]*item.Item, []*item.Item, int) {
|
||||
diamond := 40
|
||||
if c.IsWeeklyDiscountDay() {
|
||||
if IsWeeklyDiscount {
|
||||
LimitNum := c.WeeklyDiscount[0]
|
||||
Discount, WeeklyLimit := chargeCfg.GetWeeklyInfo(0)
|
||||
if LimitNum < WeeklyLimit {
|
||||
@ -419,7 +419,7 @@ func (c *ChargeMod) BuyEnergy() ([]*item.Item, []*item.Item, int) {
|
||||
}, diamond
|
||||
}
|
||||
|
||||
func (c *ChargeMod) BuyChess(Chess int) ([]*item.Item, []*item.Item, int, error) {
|
||||
func (c *ChargeMod) BuyChess(Chess int, IsWeeklyDiscount bool) ([]*item.Item, []*item.Item, int, error) {
|
||||
v, ok := c.ChessShop[Chess]
|
||||
if !ok {
|
||||
return nil, nil, 0, fmt.Errorf("BuyChess chess id not exist id:%d", Chess)
|
||||
@ -430,7 +430,7 @@ func (c *ChargeMod) BuyChess(Chess int) ([]*item.Item, []*item.Item, int, error)
|
||||
}
|
||||
v.Count--
|
||||
diamond := v.Diamond
|
||||
if c.IsWeeklyDiscountDay() {
|
||||
if IsWeeklyDiscount {
|
||||
LimitNum := c.WeeklyDiscount[Chess]
|
||||
Discount, WeeklyLimit := chargeCfg.GetWeeklyInfo(Chess)
|
||||
if LimitNum < WeeklyLimit {
|
||||
@ -521,6 +521,13 @@ func (c *ChargeMod) IsWeeklyDiscountDay() bool {
|
||||
return Weekday == Day || c.WeeklyEndTime > GoUtil.Now()
|
||||
}
|
||||
|
||||
func (c *ChargeMod) ResetWeeklyDiscount() {
|
||||
if c.IsWeeklyDiscountDay() {
|
||||
return
|
||||
}
|
||||
c.WeeklyDiscount = make(map[int]int)
|
||||
}
|
||||
|
||||
func (c *ChargeMod) PetWorkBackData() *msg.LogoutPetWork {
|
||||
res := &msg.LogoutPetWork{
|
||||
WorkTime: c.LastWorkTime,
|
||||
@ -529,3 +536,11 @@ func (c *ChargeMod) PetWorkBackData() *msg.LogoutPetWork {
|
||||
c.LastWorkTime = 0
|
||||
return res
|
||||
}
|
||||
|
||||
func (c *ChargeMod) GetWeeklyEndTime() int64 {
|
||||
return c.WeeklyEndTime
|
||||
}
|
||||
|
||||
func (c *ChargeMod) SetWeeklyEndTime(EndTime int64) {
|
||||
c.WeeklyEndTime = EndTime
|
||||
}
|
||||
|
||||
@ -2,8 +2,10 @@ package decorate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"server/GoUtil"
|
||||
decorateCfg "server/conf/decorate"
|
||||
limitedTimeEventCfg "server/conf/limitedTimeEvent"
|
||||
"server/game/mod/item"
|
||||
"server/msg"
|
||||
"sort"
|
||||
@ -75,10 +77,14 @@ func (d *Decorate) GetDecorateAddEnergy(cnt int) []*item.Item {
|
||||
}
|
||||
|
||||
// 获取装饰消耗
|
||||
func (d *Decorate) GetDecorateCostItem(AreaId, DecorateId int) ([]*item.Item, int, []*item.Item) {
|
||||
func (d *Decorate) GetDecorateCostItem(AreaId, DecorateId int, DecorateOffIsExist bool) ([]*item.Item, int, []*item.Item) {
|
||||
Item := decorateCfg.GetStarCost(AreaId, DecorateId)
|
||||
PetExp := decorateCfg.GetDecoratePExp(AreaId, DecorateId)
|
||||
Id := decorateCfg.GetIdBySenceAndLv(AreaId, DecorateId)
|
||||
if DecorateOffIsExist {
|
||||
OffRate := limitedTimeEventCfg.GetDecorateOffDiscount(AreaId, DecorateId)
|
||||
Item = int(math.Ceil(float64(Item) * float64(OffRate)))
|
||||
}
|
||||
Items := []*item.Item{item.NewItem(item.ITEM_STAR_ID, Item)}
|
||||
PartItem := d.PartCost[Id]
|
||||
PartItemList := make([]*item.Item, 0)
|
||||
@ -93,7 +99,7 @@ func (d *Decorate) GetDecorateCostItem(AreaId, DecorateId int) ([]*item.Item, in
|
||||
return Items, PetExp, PartItemList
|
||||
}
|
||||
|
||||
func (d *Decorate) DecorateAll(Star int) ([]*item.Item, []*item.Item, int, []int, []interface{}, int) {
|
||||
func (d *Decorate) DecorateAll(Star int, DecorateOffIsExist bool) ([]*item.Item, []*item.Item, int, []int, []interface{}, int) {
|
||||
DecorateAll := decorateCfg.GetAllSortIdByAreaId(d.AreaId)
|
||||
SubAlice := GoUtil.SubSlices(DecorateAll, GoUtil.MapIntToIntSlice(d.FinishList))
|
||||
sort.Ints(SubAlice)
|
||||
@ -111,6 +117,10 @@ func (d *Decorate) DecorateAll(Star int) ([]*item.Item, []*item.Item, int, []int
|
||||
break
|
||||
}
|
||||
NeedStar := decorateCfg.GetStarCost(d.AreaId, v)
|
||||
if DecorateOffIsExist {
|
||||
OffRate := limitedTimeEventCfg.GetDecorateOffDiscount(d.AreaId, v)
|
||||
NeedStar = int(math.Ceil(float64(NeedStar) * float64(OffRate)))
|
||||
}
|
||||
if Star < NeedStar {
|
||||
break
|
||||
}
|
||||
|
||||
@ -69,6 +69,7 @@ type ApplyInfo struct {
|
||||
const (
|
||||
REPLY_TYPE_GREETING = 1 // 问候
|
||||
REPLY_TYPE_GREETING_Get = 2 // 收到问候
|
||||
REPLY_TYPE_CATNIP = 3 // 猫薄荷
|
||||
)
|
||||
|
||||
// 24小时内与玩家进行过以下互动的用户,若被选中参加本次宠物宝藏,在其头像旁添加礼物盒
|
||||
@ -499,9 +500,9 @@ func (f *FriendMod) GetActLogLast() *ActLogInfo {
|
||||
return f.ActivityLog[len(f.ActivityLog)-1]
|
||||
}
|
||||
|
||||
func (f *FriendMod) AddReplyInfo(Uid int, Type int, Param string) {
|
||||
func (f *FriendMod) AddReplyInfo(Uid int, Type int, Param string, EndTime int64) {
|
||||
f.AutoId++
|
||||
EndTime := GoUtil.Now() + 24*3600
|
||||
|
||||
f.ReplyList = append(f.ReplyList, &ReplyInfo{
|
||||
Id: f.AutoId,
|
||||
Uid: Uid,
|
||||
|
||||
@ -13,6 +13,12 @@ func (f *KvMod) InitData() {
|
||||
}
|
||||
|
||||
func (f *KvMod) SetVar(key int, value string) {
|
||||
if len(value) > 500 {
|
||||
return
|
||||
}
|
||||
if len(f.Data) > 150 {
|
||||
return
|
||||
}
|
||||
f.Data[key] = value
|
||||
}
|
||||
|
||||
|
||||
@ -28,6 +28,7 @@ const (
|
||||
EVENT_TYPE_PAYBACK_DAY = 15 // 回收日
|
||||
EVENT_TYPE_LITTLE_APPRENTICE = 16 // 小学徒
|
||||
EVENT_TYPE_CAT_DAY_SALE = 17 // 猫咪大甩卖
|
||||
EVENT_TYPE_DECORATE_OFF = 18 // 装饰打折
|
||||
)
|
||||
|
||||
const (
|
||||
@ -557,3 +558,14 @@ func getLimitEventMsg(t int, e *LTEInfo) *msg.LimitEvent {
|
||||
Param: Param,
|
||||
}
|
||||
}
|
||||
|
||||
func (l LimitedTimeEventMod) EndCatDaySale() {
|
||||
delete(l.EventList, EVENT_TYPE_CAT_DAY_SALE)
|
||||
}
|
||||
|
||||
func (l LimitedTimeEventMod) GetCatDaySaleEndTime() int64 {
|
||||
if l.EventList[EVENT_TYPE_CAT_DAY_SALE] == nil {
|
||||
return 0
|
||||
}
|
||||
return l.EventList[EVENT_TYPE_CAT_DAY_SALE].StartT + l.EventList[EVENT_TYPE_CAT_DAY_SALE].Remian
|
||||
}
|
||||
|
||||
@ -107,6 +107,10 @@ const (
|
||||
|
||||
HANDLE_TYPE_FRIEND_GREETING_REPLY // 好友问候回复
|
||||
HANDLE_TYPE_FRIEND_SPONSOER // 好友赞助体力
|
||||
|
||||
HANDLE_TYPE_CHAMPSHIP_LOGIN // 锦标赛登录
|
||||
HANDLE_TYPE_CHAMPSHIP_RANK_INFO // 锦标赛排名信息
|
||||
HANDLE_TYPE_SET_CATNIP_PARTNER
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@ -307,7 +307,6 @@ func (p *PlayroomMod) ZeroUpdate() {
|
||||
p.DailyTaskReward = make([]int, 0)
|
||||
p.TodayVisitedUsers = make([]int, 0)
|
||||
p.ADItem = make(map[int]*ItemInfo)
|
||||
p.WeeklyDiscount = make(map[int]int)
|
||||
p.InitDailyTask()
|
||||
}
|
||||
|
||||
@ -1116,3 +1115,7 @@ func (p *PlayroomMod) AdWatch(Id int) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PlayroomMod) ResetWeeklyDiscount() {
|
||||
p.WeeklyDiscount = make(map[int]int)
|
||||
}
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"runtime/debug"
|
||||
"server/conf"
|
||||
"server/game"
|
||||
"server/gate"
|
||||
"server/pkg/github.com/name5566/leaf"
|
||||
|
||||
lconf "server/pkg/github.com/name5566/leaf/conf"
|
||||
)
|
||||
|
||||
@ -19,6 +21,14 @@ func main() {
|
||||
lconf.ListenAddr = conf.Server.ListenAddr
|
||||
lconf.CenterAddr = conf.Server.CenterAddr
|
||||
lconf.PendingWriteNum = conf.PendingWriteNum
|
||||
// 当内存>2G时开始GC
|
||||
debug.SetGCPercent(50)
|
||||
debug.SetMemoryLimit(2 << 30)
|
||||
// 启动 pprof(仅绑定本地)
|
||||
go func() {
|
||||
// 如果需要绑定所有接口改为 ":6060"
|
||||
_ = http.ListenAndServe("127.0.0.1:6060", nil)
|
||||
}()
|
||||
|
||||
leaf.Run(
|
||||
game.Module,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user