fix: 修复PVP赛季数据结构及相关逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -22,16 +22,16 @@ func (r *RPCfight) join(pvp info.RPCFightinfo) {
|
|||||||
ret := service.NewPVPService(pvp.PlayerID).Get(pvp.PlayerID)
|
ret := service.NewPVPService(pvp.PlayerID).Get(pvp.PlayerID)
|
||||||
score := 800
|
score := 800
|
||||||
if ret != nil {
|
if ret != nil {
|
||||||
score = int(ret.RankInfo.Score)
|
score = int(ret.RankInfo[len(ret.RankInfo)-1].Score)
|
||||||
}
|
}
|
||||||
r.zs.Add(pvp.PlayerID,
|
r.zs.Add(pvp.PlayerID,
|
||||||
ret)
|
ret)
|
||||||
if r.zs.Length() > 2 {
|
if r.zs.Length() > 2 {
|
||||||
u, s := r.zs.FindPrev(func(i *model.PVP) bool { return i.RankInfo.Score > score })
|
u, s := r.zs.FindPrev(func(i *model.PVP) bool { return i.RankInfo[len(ret.RankInfo)-1].Score > score })
|
||||||
|
|
||||||
diff := s - score
|
diff := s - score
|
||||||
// 等待越久,允许区间越大
|
// 等待越久,允许区间越大
|
||||||
wait := time.Now().Sub(u.RankInfo.LastMatchTime.Time).Seconds()
|
wait := time.Now().Sub(u.RankInfo[len(ret.RankInfo)-1].LastMatchTime.Time).Seconds()
|
||||||
maxAllow := 100 + int(wait)*10
|
maxAllow := 100 + int(wait)*10
|
||||||
if diff < maxAllow {
|
if diff < maxAllow {
|
||||||
//找到上一个,如果区间分数少于一定,
|
//找到上一个,如果区间分数少于一定,
|
||||||
|
|||||||
@@ -6,10 +6,26 @@ import (
|
|||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
"github.com/gogf/gf/v2/util/grand"
|
"github.com/gogf/gf/v2/util/grand"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IsToday 判断给定时间是否是今天
|
||||||
|
func IsToday(t1 *gtime.Time) bool {
|
||||||
|
if t1 == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
t := t1.Time
|
||||||
|
|
||||||
|
// 获取当前时间
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
// 比较年、月、日是否相同
|
||||||
|
return t.Year() == now.Year() &&
|
||||||
|
t.Month() == now.Month() &&
|
||||||
|
t.Day() == now.Day()
|
||||||
|
}
|
||||||
func FindWithIndex[T any](slice []T, predicate func(item T) bool) (int, *T, bool) {
|
func FindWithIndex[T any](slice []T, predicate func(item T) bool) (int, *T, bool) {
|
||||||
for i := range slice {
|
for i := range slice {
|
||||||
if predicate(slice[i]) {
|
if predicate(slice[i]) {
|
||||||
|
|||||||
@@ -15,10 +15,8 @@ const TableNamePlayerPVP = "player_pvp"
|
|||||||
type PVP struct {
|
type PVP struct {
|
||||||
*cool.Model
|
*cool.Model
|
||||||
PlayerID uint64 `gorm:"not null;index:idx_pvp_player_id;comment:'所属玩家ID'" json:"player_id"`
|
PlayerID uint64 `gorm:"not null;index:idx_pvp_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||||
|
//本赛季排名信息'通过下标来确认当前赛季
|
||||||
SeasonData []PVPRankInfo `gorm:"type:jsonb;not null;comment:'赛季核心数据'" json:"season_data"`
|
RankInfo []PVPRankInfo `gorm:"type:jsonb;not null;comment:'赛季核心数据'" json:"season_data"`
|
||||||
|
|
||||||
RankInfo PVPRankInfo `gorm:"type:jsonb;not null;comment:'本赛季排名信息'" json:"rank_info"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *PVP) Key() uint32 {
|
func (u *PVP) Key() uint32 {
|
||||||
@@ -27,10 +25,10 @@ func (u *PVP) Key() uint32 {
|
|||||||
|
|
||||||
// 如果分数不对的话,就按时间排序
|
// 如果分数不对的话,就按时间排序
|
||||||
func (u *PVP) Less(than *PVP) bool {
|
func (u *PVP) Less(than *PVP) bool {
|
||||||
if u.RankInfo.Score == than.RankInfo.Score {
|
if u.RankInfo[len(u.RankInfo)-1].Score == than.RankInfo[len(u.RankInfo)-1].Score {
|
||||||
return u.RankInfo.LastMatchTime.Unix() < than.RankInfo.LastMatchTime.Unix()
|
return u.RankInfo[len(u.RankInfo)-1].LastMatchTime.Unix() < than.RankInfo[len(u.RankInfo)-1].LastMatchTime.Unix()
|
||||||
}
|
}
|
||||||
return u.RankInfo.Score < than.RankInfo.Score
|
return u.RankInfo[len(u.RankInfo)-1].Score < than.RankInfo[len(u.RankInfo)-1].Score
|
||||||
}
|
}
|
||||||
func NewPVP() *PVP {
|
func NewPVP() *PVP {
|
||||||
return &PVP{
|
return &PVP{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/share"
|
"blazing/common/data/share"
|
||||||
|
"blazing/common/utils"
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"blazing/modules/config/service"
|
"blazing/modules/config/service"
|
||||||
"blazing/modules/player/model"
|
"blazing/modules/player/model"
|
||||||
@@ -93,7 +94,7 @@ func (s *InfoService) GetLogin() *model.PlayerInfo {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !IsToday(tt.LastResetTime) && cool.Config.ServerInfo.IsVip == 0 { //判断是否是今天
|
if !utils.IsToday(tt.LastResetTime) && cool.Config.ServerInfo.IsVip == 0 { //判断是否是今天
|
||||||
|
|
||||||
//每天login时候检查重置时间,然后把电池,任务,挖矿重置
|
//每天login时候检查重置时间,然后把电池,任务,挖矿重置
|
||||||
//挖矿需要单独存,因为防止多开挖矿
|
//挖矿需要单独存,因为防止多开挖矿
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"blazing/common/utils"
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
basemodel "blazing/modules/base/model"
|
basemodel "blazing/modules/base/model"
|
||||||
"blazing/modules/base/service"
|
"blazing/modules/base/service"
|
||||||
@@ -56,7 +57,11 @@ func (s *PetService) UPdatePrice(ctime uint32, Price uint32, is_sale uint32) err
|
|||||||
return fmt.Errorf("精灵数量已满")
|
return fmt.Errorf("精灵数量已满")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var p model.Pet
|
||||||
|
s.dbm(s.Model).Where("catch_time", ctime).Scan(&p)
|
||||||
|
if p.SalePrice != Price && utils.IsToday(p.UpdateTime) { //说明要修改价格
|
||||||
|
return fmt.Errorf("一天只允许改价一次")
|
||||||
|
}
|
||||||
res0, err := s.dbm(s.Model).
|
res0, err := s.dbm(s.Model).
|
||||||
Where("catch_time", ctime). // 限定 ctime,避免全表更新
|
Where("catch_time", ctime). // 限定 ctime,避免全表更新
|
||||||
Where("sale_price = ?", 0). // 只筛选 sale_price=0 的记录
|
Where("sale_price = ?", 0). // 只筛选 sale_price=0 的记录
|
||||||
@@ -145,6 +150,7 @@ RETURNING max_ts;
|
|||||||
player.Data = tt.Data
|
player.Data = tt.Data
|
||||||
player.CatchTime = tt.CatchTime
|
player.CatchTime = tt.CatchTime
|
||||||
player.Free = 0
|
player.Free = 0
|
||||||
|
player.SalePrice = tt.SalePrice
|
||||||
player.SaleCount = tt.SaleCount + 1
|
player.SaleCount = tt.SaleCount + 1
|
||||||
player.IsVip = cool.Config.ServerInfo.IsVip
|
player.IsVip = cool.Config.ServerInfo.IsVip
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"blazing/common/utils"
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
config "blazing/modules/config/service"
|
config "blazing/modules/config/service"
|
||||||
"blazing/modules/player/model"
|
"blazing/modules/player/model"
|
||||||
@@ -35,7 +36,7 @@ func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//因为这个是挖一次更新一次,而且是实时更新的,如果更新日期是今天,那么就可以确认不用再重置,否则就需要重置挖矿记录
|
//因为这个是挖一次更新一次,而且是实时更新的,如果更新日期是今天,那么就可以确认不用再重置,否则就需要重置挖矿记录
|
||||||
if !IsToday(talks.UpdateTime) {
|
if !utils.IsToday(talks.UpdateTime) {
|
||||||
|
|
||||||
talks.Count = 0
|
talks.Count = 0
|
||||||
m1.Save(talks)
|
m1.Save(talks)
|
||||||
|
|||||||
@@ -65,21 +65,6 @@ func (s *TaskService) Exec(id uint32, t func(*model.Task) bool) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsToday 判断给定时间是否是今天
|
|
||||||
func IsToday(t1 *gtime.Time) bool {
|
|
||||||
if t1 == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
t := t1.Time
|
|
||||||
|
|
||||||
// 获取当前时间
|
|
||||||
now := time.Now()
|
|
||||||
|
|
||||||
// 比较年、月、日是否相同
|
|
||||||
return t.Year() == now.Year() &&
|
|
||||||
t.Month() == now.Month() &&
|
|
||||||
t.Day() == now.Day()
|
|
||||||
}
|
|
||||||
func IsWEEK(t1 *gtime.Time) bool {
|
func IsWEEK(t1 *gtime.Time) bool {
|
||||||
if t1 == nil {
|
if t1 == nil {
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user