商队修改

This commit is contained in:
meixiongfeng 2023-08-04 18:46:50 +08:00
parent 8a00c3798b
commit a8d8194605
11 changed files with 36 additions and 26 deletions

View File

@ -2,9 +2,8 @@ package caravan
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure" "go_dreamfactory/utils"
) )
//参数校验 //参数校验
@ -21,9 +20,9 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.CaravanGetListRe
if errdata = this.GetListCheck(session, req); errdata != nil { if errdata = this.GetListCheck(session, req); errdata != nil {
return // 参数校验失败直接返回 return // 参数校验失败直接返回
} }
list, err := this.module.modelCaravan.getCaravanList(session.GetUserId()) list, _ := this.module.modelCaravan.getCaravanList(session.GetUserId())
endtime := utils.WeekIntervalTime()
if configure.Now().Unix() >= list.Resettime || err == mgo.MongodbNil { // 初始化门票和虚拟币 if list.Resettime != endtime { // 初始化门票和虚拟币
if conf, err := this.module.configure.GetCaravanLv(list.Lv); err == nil { if conf, err := this.module.configure.GetCaravanLv(list.Lv); err == nil {
this.module.ModuleItems.CleanItemById(session, conf.Tickettop.T) // 清理之前的门票数据 this.module.ModuleItems.CleanItemById(session, conf.Tickettop.T) // 清理之前的门票数据
} else { } else {
@ -45,6 +44,8 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.CaravanGetListRe
list.Profit = 0 list.Profit = 0
update["reward"] = list.Reward // 初始化利润奖励 update["reward"] = list.Reward // 初始化利润奖励
update["profit"] = list.Profit // 初始化商品利润 update["profit"] = list.Profit // 初始化商品利润
list.Resettime = endtime
update["resettime"] = list.Resettime
this.module.modelCaravan.modifyCaravanDataByObjId(session.GetUserId(), update) this.module.modelCaravan.modifyCaravanDataByObjId(session.GetUserId(), update)
} }
} }

View File

@ -8,6 +8,7 @@ import (
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
"go_dreamfactory/utils"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
@ -47,11 +48,8 @@ func (this *modelCaravan) getCaravanList(uid string) (result *pb.DBCaravan, err
// 创建一条数据 // 创建一条数据
result.Id = primitive.NewObjectID().Hex() result.Id = primitive.NewObjectID().Hex()
// 活动持续时间 // 活动持续时间
sTime := int64(this.module.ModuleTools.GetGlobalConf().BusinessRewardday * 24 * 3600) // 单位s
openTime := this.module.service.GetOpentime().Unix() // 获取开服时间 result.Resettime = utils.WeekIntervalTime()
subTime := configure.Now().Unix() - openTime
result.Resettime = configure.Now().Unix() - (subTime % sTime) + sTime
//result.Resettime = +int64(this.module.ModuleTools.GetGlobalConf().BusinessRewardday * 24 * 3600)
result.Citystime = configure.Now().Unix() result.Citystime = configure.Now().Unix()
result.Rtime = configure.Now().Unix() result.Rtime = configure.Now().Unix()
@ -63,9 +61,10 @@ func (this *modelCaravan) getCaravanList(uid string) (result *pb.DBCaravan, err
this.module.InitCaravanCityData(uid, result) // 初始1级 this.module.InitCaravanCityData(uid, result) // 初始1级
this.module.InitCaravanItemData(uid, result) this.module.InitCaravanItemData(uid, result)
this.Add(uid, result) this.Add(uid, result)
err = nil
return return
} }
err = nil
return result, err return result, err
} }
func (this *modelCaravan) modifyCaravanDataByObjId(uid string, data map[string]interface{}) error { func (this *modelCaravan) modifyCaravanDataByObjId(uid string, data map[string]interface{}) error {

View File

@ -122,6 +122,7 @@ func (this *Caravan) InitCaravanCityData(uid string, data *pb.DBCaravan) {
city.NextexspecialPCT = v.Exspecialnum[int(comm.GetRandW(v.ExspecialnumWeight))] // 获取权重 city.NextexspecialPCT = v.Exspecialnum[int(comm.GetRandW(v.ExspecialnumWeight))] // 获取权重
data.City[v.Id] = city data.City[v.Id] = city
} }
//data.Citystime = utils.GetZeroTime(configure.Now().Unix())
data.Rtime = configure.Now().Unix() // 修改时间 data.Rtime = configure.Now().Unix() // 修改时间
} }
@ -167,7 +168,7 @@ func (this *Caravan) refreshCaravanCityInfo(uid string, caravan *pb.DBCaravan) {
changeTime = this.configure.GetCityRefreshTime() // 3分钟 changeTime = this.configure.GetCityRefreshTime() // 3分钟
// 刷新城市货物信息 // 刷新城市货物信息
if !utils.IsToday(caravan.Citystime) { if !utils.IsNextToday(caravan.Citystime) {
list := this.configure.GetAllCaravanCity() list := this.configure.GetAllCaravanCity()
for _, conf := range list { for _, conf := range list {
if v, ok := caravan.City[conf.Id]; ok { if v, ok := caravan.City[conf.Id]; ok {
@ -182,7 +183,7 @@ func (this *Caravan) refreshCaravanCityInfo(uid string, caravan *pb.DBCaravan) {
v.Special = append(v.Special, conf.Special...) v.Special = append(v.Special, conf.Special...)
} }
if utils.IsToday(caravan.Citystime - 24*3600) { if utils.IsToday(caravan.Citystime) {
v.Exspecial = make([]string, 0) v.Exspecial = make([]string, 0)
v.Exspecial = append(v.Exspecial, v.Nextexspecial...) v.Exspecial = append(v.Exspecial, v.Nextexspecial...)
v.ExspecialPCT = v.NextexspecialPCT v.ExspecialPCT = v.NextexspecialPCT
@ -215,17 +216,20 @@ func (this *Caravan) refreshCaravanCityInfo(uid string, caravan *pb.DBCaravan) {
} }
} }
caravan.Citystime = configure.Now().Unix() // 设置今天的时间 caravan.Citystime = utils.GetZeroTime(configure.Now().Unix()) // 设置第二天0点的时间
update["city"] = caravan.City update["city"] = caravan.City
update["citystime"] = caravan.Citystime update["citystime"] = caravan.Citystime
} }
if caravan.Itemtime == 0 {
caravan.Itemtime = configure.Now().Unix()
}
subTime := int32(curTime - caravan.Itemtime) subTime := int32(curTime - caravan.Itemtime)
if subTime >= changeTime { if subTime >= changeTime {
bChange = true bChange = true
icount := int32(subTime / changeTime) // 循环周期 icount := int32(subTime / changeTime) // 循环周期
caravan.Itemtime += int64(changeTime * icount) caravan.Itemtime += int64(changeTime * icount)
update["citystime"] = caravan.Itemtime update["itemtime"] = caravan.Itemtime
for k, v := range caravan.Goods { for k, v := range caravan.Goods {
if c, err := this.configure.GetCaravanGoods(k); err == nil { if c, err := this.configure.GetCaravanGoods(k); err == nil {
caravan.Oldprice[k] = v.Price caravan.Oldprice[k] = v.Price

View File

@ -62,7 +62,7 @@ func (this *modelRank) updateRank(guilds ...*pb.DBGuildGve) (err error) {
) )
menbers = make([]*redis.Z, len(guilds)) menbers = make([]*redis.Z, len(guilds))
for i, v := range guilds { for i, v := range guilds {
endtime := time.Unix(utils.WeekIntervalTime(0), 0) endtime := time.Unix(utils.WeekIntervalTime(), 0)
start := time.Unix(v.Lastkilltime, 0) start := time.Unix(v.Lastkilltime, 0)
seconds := endtime.Sub(start).Seconds() seconds := endtime.Sub(start).Seconds()
Integral := float64(v.Kills)*float64(10000000000) + seconds Integral := float64(v.Kills)*float64(10000000000) + seconds

View File

@ -115,7 +115,7 @@ type sumy struct {
func Test_Main(t *testing.T) { func Test_Main(t *testing.T) {
value, err := strconv.Atoi("944005411") value, err := strconv.Atoi("944005411")
fmt.Printf("%v,%v", value, err) fmt.Printf("%v,%v,%d", value, err, utils.WeekIntervalTime())
ids := utils.RandomNumbers(0, 10, 5) ids := utils.RandomNumbers(0, 10, 5)
for _, v := range ids { for _, v := range ids {
fmt.Printf("%d", v) fmt.Printf("%d", v)

View File

@ -40,7 +40,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.StonehengeGetLis
update["hero"] = stone.Hero update["hero"] = stone.Hero
stone.Addweight = make(map[int32]int32, 0) stone.Addweight = make(map[int32]int32, 0)
update["addweight"] = stone.Addweight update["addweight"] = stone.Addweight
stone.Etime = utils.WeekIntervalTime(0) stone.Etime = utils.WeekIntervalTime()
update["etime"] = stone.Etime update["etime"] = stone.Etime
this.module.modelStonehenge.ChangeStonehengeData(session.GetUserId(), update) this.module.modelStonehenge.ChangeStonehengeData(session.GetUserId(), update)
} }

View File

@ -59,7 +59,7 @@ func (this *MStonehenge) GetStonehengeData(uid string) *pb.DBStonehenge {
stone.Userbuff = make(map[int32]int32, 0) stone.Userbuff = make(map[int32]int32, 0)
stone.Reward = make(map[int32]bool, 0) stone.Reward = make(map[int32]bool, 0)
stone.Addweight = make(map[int32]int32, 0) stone.Addweight = make(map[int32]int32, 0)
stone.Etime = utils.WeekIntervalTime(0) stone.Etime = utils.WeekIntervalTime()
stone.Hero = make(map[string]*pb.BattleRole) stone.Hero = make(map[string]*pb.BattleRole)
this.Add(uid, stone) this.Add(uid, stone)
@ -78,13 +78,13 @@ func (this *MStonehenge) reLoadStoneBoos() (err error) {
s := &pb.DBStoneBoss{} s := &pb.DBStoneBoss{}
this.module.ModuleTools.GetGlobalData(StoneBossKey, s) this.module.ModuleTools.GetGlobalData(StoneBossKey, s)
if len(s.Bossstage) == 0 || utils.WeekIntervalTime(0) != s.Rtime { if len(s.Bossstage) == 0 || utils.WeekIntervalTime() != s.Rtime {
this.lock.Lock() this.lock.Lock()
this.bossStage = this.module.configure.CheckStage() this.bossStage = this.module.configure.CheckStage()
this.lock.Unlock() this.lock.Unlock()
this.module.ModuleTools.UpdateGlobalData(StoneBossKey, map[string]interface{}{ this.module.ModuleTools.UpdateGlobalData(StoneBossKey, map[string]interface{}{
"BossStage": this.bossStage, "BossStage": this.bossStage,
"rtime": utils.WeekIntervalTime(0), "rtime": utils.WeekIntervalTime(),
}) })
} else { } else {
this.lock.Lock() this.lock.Lock()

View File

@ -40,7 +40,7 @@ func (this *MWorldBuff) GetStonehengeData(uid string) *pb.DBStonehenge {
stone.Userbuff = make(map[int32]int32, 0) stone.Userbuff = make(map[int32]int32, 0)
stone.Reward = make(map[int32]bool, 0) stone.Reward = make(map[int32]bool, 0)
stone.Addweight = make(map[int32]int32, 0) stone.Addweight = make(map[int32]int32, 0)
stone.Etime = utils.WeekIntervalTime(0) stone.Etime = utils.WeekIntervalTime()
this.Add(uid, stone) this.Add(uid, stone)
return nil return nil
} }

View File

@ -83,7 +83,7 @@ func (this *CaravanRank) Start() (err error) {
} }
func (this *CaravanRank) TimerSeason() { func (this *CaravanRank) TimerSeason() {
endTime := utils.WeekIntervalTime(0) endTime := utils.WeekIntervalTime()
this.module.Debugf("TimerSeason end: %d,cur time:%d", endTime, configure.Now().Unix()) this.module.Debugf("TimerSeason end: %d,cur time:%d", endTime, configure.Now().Unix())
if err := this.service.RpcCall( if err := this.service.RpcCall(

View File

@ -15,6 +15,12 @@ func IsToday(d int64) bool {
now := configure.Now() now := configure.Now()
return tt.Year() == now.Year() && tt.Month() == now.Month() && tt.Day() == now.Day() return tt.Year() == now.Year() && tt.Month() == now.Month() && tt.Day() == now.Day()
} }
func IsNextToday(d int64) bool {
d += 24 * 3600
tt := time.Unix(d, 0)
now := configure.Now()
return tt.Year() == now.Year() && tt.Month() == now.Month() && tt.Day() == now.Day()
}
// 判断是否是出于同一周 // 判断是否是出于同一周
func IsSameWeek(d int64) bool { func IsSameWeek(d int64) bool {
@ -170,7 +176,7 @@ func DiffDays(t1, t2 int64) int {
return diffDays return diffDays
} }
func WeekIntervalTime(week int) (endTime int64) { func WeekIntervalTime() (endTime int64) {
now := time.Now() now := time.Now()
offset := int(time.Monday - now.Weekday()) offset := int(time.Monday - now.Weekday())
//周日做特殊判断 因为time.Monday = 0 //周日做特殊判断 因为time.Monday = 0
@ -181,7 +187,7 @@ func WeekIntervalTime(week int) (endTime int64) {
year, month, day := now.Date() year, month, day := now.Date()
thisWeek := time.Date(year, month, day, 0, 0, 0, 0, time.Local) thisWeek := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
//startTime = thisWeek.AddDate(0, 0, offset+7*week).Unix() //startTime = thisWeek.AddDate(0, 0, offset+7*week).Unix()
endTime = thisWeek.AddDate(0, 0, offset+6+7*week).Unix() endTime = thisWeek.AddDate(0, 0, offset+7).Unix()
return endTime return endTime
} }

View File

@ -119,7 +119,7 @@ func TestIsSameWeek(t *testing.T) {
} }
func TestWeekIntervalTime(t *testing.T) { func TestWeekIntervalTime(t *testing.T) {
ti := utils.WeekIntervalTime(0) ti := utils.WeekIntervalTime()
format := "2006-01-02 15:04:05" format := "2006-01-02 15:04:05"
formattedTime := time.Unix(ti, 0).Format(format) formattedTime := time.Unix(ti, 0).Format(format)
fmt.Println(formattedTime) fmt.Println(formattedTime)