活动初始化增加定时器
This commit is contained in:
parent
5a05536321
commit
6837a17813
@ -57,7 +57,6 @@ func GetActivityList() []*gamedata.ActivityData {
|
||||
log.Debug("GetActivityList err:%v", err)
|
||||
return nil
|
||||
}
|
||||
Now := GoUtil.Now()
|
||||
List := make([]*gamedata.ActivityData, 0, len(data))
|
||||
|
||||
for k, v := range data {
|
||||
@ -65,18 +64,12 @@ func GetActivityList() []*gamedata.ActivityData {
|
||||
EndTimeStr := gamedata.GetStringValue(v, "EndTime")
|
||||
StartTime := GoUtil.ParseTime(StartTimeStr)
|
||||
EndTime := GoUtil.ParseTime(EndTimeStr)
|
||||
if Now >= StartTime && Now <= EndTime {
|
||||
Id, err := strconv.Atoi(k)
|
||||
if err != nil {
|
||||
log.Debug("GetActivityList parse id err:%v, key:%s", err, k)
|
||||
continue
|
||||
}
|
||||
Type := gamedata.GetIntValue(v, "Type")
|
||||
Name := gamedata.GetStringValue(v, "Name")
|
||||
Title := gamedata.GetStringValue(v, "Title")
|
||||
Level := gamedata.GetIntValue(v, "Level")
|
||||
ActivityData := &gamedata.ActivityData{
|
||||
Id: Id,
|
||||
Id: GoUtil.Int(k),
|
||||
Type: Type,
|
||||
AType: gamedata.GetIntValue(v, "AType"),
|
||||
Name: Name,
|
||||
@ -87,7 +80,6 @@ func GetActivityList() []*gamedata.ActivityData {
|
||||
}
|
||||
List = append(List, ActivityData)
|
||||
}
|
||||
}
|
||||
return List
|
||||
}
|
||||
func GetActivityListOrigin() []*gamedata.ActivityData {
|
||||
|
||||
@ -31,7 +31,19 @@ func (p *Player) ActivityLogin() {
|
||||
if OldId == 0 {
|
||||
return
|
||||
}
|
||||
ItemId := guesscolorCfg.GetActivityItemId(OldId)
|
||||
var ItemId int
|
||||
switch actType {
|
||||
case activity.ACT_TYPE_MINING:
|
||||
ItemId = miningCfg.GetActivityItemId(OldId)
|
||||
case activity.ACT_TYPE_GUESS_COLOR:
|
||||
ItemId = guesscolorCfg.GetActivityItemId(OldId)
|
||||
case activity.ACT_TYPE_RACE:
|
||||
ItemId = raceCfg.GetCoin(OldId)
|
||||
case activity.ACT_TYPE_PASS:
|
||||
ItemId = passCfg.GetActivityItemId(OldId)
|
||||
default:
|
||||
return
|
||||
}
|
||||
ItemNum := ItemMod.GetItem(ItemId)
|
||||
if ItemNum != 0 {
|
||||
ItemMod.AddItem(ItemId, -ItemNum)
|
||||
|
||||
@ -90,7 +90,7 @@ func (p *Player) ActivityFire(ChargeId int) {
|
||||
}
|
||||
}
|
||||
p.PlayMod.save()
|
||||
p.initActivity()
|
||||
p.InitActivity()
|
||||
p.BackDataActivity()
|
||||
}
|
||||
|
||||
|
||||
@ -104,7 +104,7 @@ func ReqGmCommand_(player *Player, Command string) error {
|
||||
player.PlayMod.getBaseMod().Level = num
|
||||
player.PlayMod.getBaseMod().Exp = 0
|
||||
player.PushClientRes(player.PlayerBaseMod.BackAsset())
|
||||
player.initActivity()
|
||||
player.InitActivity()
|
||||
player.PlayMod.getGuideTaskMod().Unlock(num)
|
||||
player.PlayMod.getOrderMod().TriggerOrder(num, order.TRIGGER_TYPE_LV, nil, 1)
|
||||
player.PushClientRes(player.PlayMod.getOrderMod().BackData())
|
||||
@ -127,7 +127,7 @@ func ReqGmCommand_(player *Player, Command string) error {
|
||||
ActivityMod.Var = nil
|
||||
ActivityMod.InitData()
|
||||
player.PlayMod.save()
|
||||
player.initActivity()
|
||||
player.InitActivity()
|
||||
player.BackDataActivity()
|
||||
case "weekUpdate":
|
||||
VarMod := player.PlayMod.getVarMod()
|
||||
|
||||
@ -561,7 +561,7 @@ func (p *PlayerBaseData) AddExp(player *Player, exp int, pexp int) (int, error)
|
||||
player.TriggerOrder(BaseMod.Level, order.TRIGGER_TYPE_LV, ChessMod.GetOrderEmit(), player.PlayMod.getBaseMod().GetEnergyMul())
|
||||
player.PushClientRes(OrderMod.BackData())
|
||||
// 重载活动
|
||||
player.initActivity()
|
||||
player.InitActivity()
|
||||
player.BackDataActivity()
|
||||
player.QuestTrigger(&quest.Trigger{Label: quest.TRIGGER_LABEL_UPLV})
|
||||
player.TeLog("level_up", map[string]interface{}{
|
||||
|
||||
@ -248,7 +248,7 @@ func (p *Player) InitPlayer(UserName string) error {
|
||||
log.Debug("AddFunc failed:", err)
|
||||
}
|
||||
p.McronSave.Start()
|
||||
p.initActivity()
|
||||
p.InitActivity()
|
||||
p.ZeroUpdate(nil)
|
||||
p.NoonUpdate(nil)
|
||||
p.Login()
|
||||
@ -307,7 +307,7 @@ func (p *Player) InitPlayerByUid(Uid int) error {
|
||||
log.Debug("AddFunc failed:", err)
|
||||
}
|
||||
p.McronSave.Start()
|
||||
p.initActivity()
|
||||
p.InitActivity()
|
||||
p.ZeroUpdate(nil)
|
||||
p.NoonUpdate(nil)
|
||||
p.Login()
|
||||
@ -384,7 +384,7 @@ func (p *Player) ZeroUpdate(a []interface{}) {
|
||||
}
|
||||
p.PlayroomBackData()
|
||||
p.PlayMod.getChampshipMod().ZeroUpdate()
|
||||
p.initActivity()
|
||||
p.InitActivity()
|
||||
p.ActivityZeroUpdate()
|
||||
|
||||
// 每日任务
|
||||
@ -1171,11 +1171,15 @@ func (p *Player) TeLog(Type string, Param map[string]interface{}) {
|
||||
}
|
||||
|
||||
// 初始化活动
|
||||
func (p *Player) initActivity() {
|
||||
func (p *Player) InitActivity() {
|
||||
p.activity = make(map[int]*ActivityInfo)
|
||||
ActivityList := activityCfg.GetActivityList()
|
||||
Level := p.GetPlayerBaseMod().GetLevel()
|
||||
ActivityMod := p.PlayMod.getActivityMod()
|
||||
now := GoUtil.Now()
|
||||
var startduration int64
|
||||
var minduration int64
|
||||
var endduration int64
|
||||
for _, v := range ActivityList {
|
||||
if v.Level > Level {
|
||||
continue
|
||||
@ -1184,6 +1188,17 @@ func (p *Player) initActivity() {
|
||||
if Status == 0 {
|
||||
continue
|
||||
}
|
||||
startduration = v.StartTime - now
|
||||
endduration = v.EndTime - now + 1
|
||||
if startduration > 0 && (minduration == 0 || minduration > startduration) {
|
||||
minduration = startduration
|
||||
}
|
||||
if endduration > 0 && (minduration == 0 || minduration > endduration) {
|
||||
minduration = endduration
|
||||
}
|
||||
if v.StartTime > now || v.EndTime < now {
|
||||
continue
|
||||
}
|
||||
p.activity[v.Id] = &ActivityInfo{
|
||||
StartT: v.StartTime,
|
||||
EndT: v.EndTime,
|
||||
@ -1193,10 +1208,23 @@ func (p *Player) initActivity() {
|
||||
Title: v.Title,
|
||||
}
|
||||
}
|
||||
if minduration > 0 {
|
||||
p.CallEvent(time.Duration(minduration)*time.Second, p.TickActivity, "init_activity")
|
||||
}
|
||||
p.TeLog("activity_ids", map[string]interface{}{
|
||||
"info": p.activity,
|
||||
})
|
||||
p.ActivityLogin()
|
||||
|
||||
}
|
||||
|
||||
func (p *Player) TickActivity() {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
p.InitActivity()
|
||||
p.ActivityZeroUpdate()
|
||||
p.BackDataActivity()
|
||||
p.SendClientRes()
|
||||
}
|
||||
|
||||
func (p *Player) BackDataActivity() {
|
||||
|
||||
@ -4647,7 +4647,7 @@ func ReqActivityReward(player *Player, buf []byte) error {
|
||||
"Items": Items,
|
||||
})
|
||||
player.PlayMod.save()
|
||||
player.initActivity()
|
||||
player.InitActivity()
|
||||
player.BackDataActivity()
|
||||
player.PushClientRes(&msg.ResActivityReward{
|
||||
Code: msg.RES_CODE_SUCCESS,
|
||||
|
||||
13
src/server/test/activity_test.go
Normal file
13
src/server/test/activity_test.go
Normal file
@ -0,0 +1,13 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"server/game"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestActivityOpenEnd(t *testing.T) {
|
||||
p := new(game.Player)
|
||||
p.InitPlayer("3625212")
|
||||
p.InitActivity()
|
||||
p.ActivityLogin()
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user