feat: 重构地图热度信息并添加地图提示功能
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
将地图热度信息从简单的计数器改为包含提示信息的结构体 添加矿物、BOSS、宠物和掉落等提示信息的收集功能 优化地图进入和离开时的计数逻辑
This commit is contained in:
@@ -5,15 +5,40 @@ type MapHotInfo struct {
|
|||||||
MapID uint32 `json:"mapId"` // 地图ID
|
MapID uint32 `json:"mapId"` // 地图ID
|
||||||
Count int32 `struc:"uint32" json:"count"` // 地图里的人数
|
Count int32 `struc:"uint32" json:"count"` // 地图里的人数
|
||||||
}
|
}
|
||||||
|
type MapTip struct {
|
||||||
|
Count int `struc:"uint32" json:"count"` // 地图里的人数
|
||||||
|
TipInfoS map[uint32]*TipInfo `json:"tipInfoS"`
|
||||||
|
}
|
||||||
|
|
||||||
var maphot = make(map[uint32]*int32, 0)
|
type TipInfo struct {
|
||||||
|
Talk []uint32 `json:"talk"` //矿物
|
||||||
|
Boss []uint32 `json:"boss"` //boss
|
||||||
|
Pet []uint32 `json:"pet"` //宠物
|
||||||
|
Diao []uint32 `json:"diao"` //掉落
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MapTip) GetCount(t int) int {
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case t < 0:
|
||||||
|
if m.Count > 0 {
|
||||||
|
m.Count -= t
|
||||||
|
}
|
||||||
|
case t > 0:
|
||||||
|
m.Count += t
|
||||||
|
}
|
||||||
|
|
||||||
|
return m.Count
|
||||||
|
}
|
||||||
|
|
||||||
|
var maphot = make(map[uint32]*MapTip, 0)
|
||||||
|
|
||||||
func GetMapHot() []MapHotInfo {
|
func GetMapHot() []MapHotInfo {
|
||||||
ret := make([]MapHotInfo, 0)
|
ret := make([]MapHotInfo, 0)
|
||||||
for k, v := range maphot {
|
for k, v := range maphot {
|
||||||
ret = append(ret, MapHotInfo{
|
ret = append(ret, MapHotInfo{
|
||||||
MapID: k,
|
MapID: k,
|
||||||
Count: *v,
|
Count: int32(v.GetCount(0)),
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,9 @@ func (s *Space) LeaveMap(c common.PlayerI) {
|
|||||||
s.Broadcast(c, 2002, info)
|
s.Broadcast(c, 2002, info)
|
||||||
|
|
||||||
current, ok := maphot[s.Super]
|
current, ok := maphot[s.Super]
|
||||||
if ok && *current > 0 {
|
if ok {
|
||||||
atomic.AddInt32(maphot[s.Super], -1)
|
current.GetCount(-1)
|
||||||
|
|
||||||
}
|
}
|
||||||
if atomic.CompareAndSwapUint32(&s.Owner.UserID, c.GetInfo().UserID, 0) {
|
if atomic.CompareAndSwapUint32(&s.Owner.UserID, c.GetInfo().UserID, 0) {
|
||||||
|
|
||||||
@@ -57,9 +58,10 @@ func (s *Space) EnterMap(c common.PlayerI) {
|
|||||||
s.Broadcast(c, 2001, out)
|
s.Broadcast(c, 2001, out)
|
||||||
s.User.Store(c.GetInfo().UserID, c)
|
s.User.Store(c.GetInfo().UserID, c)
|
||||||
s.UserInfo.Store(c.GetInfo().UserID, *out)
|
s.UserInfo.Store(c.GetInfo().UserID, *out)
|
||||||
_, ok := maphot[s.Super]
|
curmaps, ok := maphot[s.Super]
|
||||||
if ok {
|
if ok {
|
||||||
atomic.AddInt32(maphot[s.Super], 1)
|
curmaps.GetCount(1)
|
||||||
|
//atomic.AddInt32(maphot[s.Super], 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,10 +80,19 @@ func GetSpace(id uint32) *Space {
|
|||||||
|
|
||||||
_, ok := maphot[ret.Super]
|
_, ok := maphot[ret.Super]
|
||||||
if !ok {
|
if !ok {
|
||||||
var t1 int32
|
|
||||||
maphot[ret.Super] = &t1
|
|
||||||
}
|
|
||||||
|
|
||||||
|
maphot[ret.Super] = &MapTip{}
|
||||||
|
maphot[ret.Super].TipInfoS = make(map[uint32]*TipInfo, 0)
|
||||||
|
}
|
||||||
|
_, ok = maphot[ret.Super].TipInfoS[ret.ID]
|
||||||
|
if !ok {
|
||||||
|
tips := &TipInfo{}
|
||||||
|
tips.Diao = service.NewMapService().GetData(ret.ID).DropItemIds
|
||||||
|
tips.Pet = service.NewMapPitService().GetDataALL(ret.ID)
|
||||||
|
tips.Talk = service.NewTalkConfigService().GetTip(ret.ID)
|
||||||
|
tips.Boss = service.NewMapNodeService().GetTip(ret.ID)
|
||||||
|
maphot[ret.Super].TipInfoS[ret.ID] = tips
|
||||||
|
}
|
||||||
ret.Name = v.Name
|
ret.Name = v.Name
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,15 +31,20 @@ type TimeMapReq struct {
|
|||||||
func (this *MapController) TimeMap(ctx context.Context, req *TimeMapReq) (res *cool.BaseRes, err error) {
|
func (this *MapController) TimeMap(ctx context.Context, req *TimeMapReq) (res *cool.BaseRes, err error) {
|
||||||
res = &cool.BaseRes{}
|
res = &cool.BaseRes{}
|
||||||
res.Data = service.NewMapService().GetTimeMap()
|
res.Data = service.NewMapService().GetTimeMap()
|
||||||
|
// re := service.NewMapService().GetTimeMap()
|
||||||
|
// for _, v := range re {
|
||||||
|
// v.
|
||||||
|
|
||||||
|
// }
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type MapTipReq struct {
|
// type MapTipReq struct {
|
||||||
g.Meta `path:"/maptip" method:"GET"`
|
// g.Meta `path:"/maptip" method:"GET"`
|
||||||
}
|
// }
|
||||||
|
|
||||||
func (this *MapController) MapTip(ctx context.Context, req *MapTipReq) (res *cool.BaseRes, err error) {
|
// func (this *MapController) MapTip(ctx context.Context, req *MapTipReq) (res *cool.BaseRes, err error) {
|
||||||
res = &cool.BaseRes{}
|
// res = &cool.BaseRes{}
|
||||||
res.Data = service.NewMapService().GetTimeMap()
|
// res.Data = service.NewMapService().GetTimeMap()
|
||||||
return res, nil
|
// return res, nil
|
||||||
}
|
// }
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ type MapPit struct {
|
|||||||
// 复用通用基础配置(ID/创建时间/更新时间等)
|
// 复用通用基础配置(ID/创建时间/更新时间等)
|
||||||
MapID int32 `gorm:"not null;index;comment:'所属地图ID'" json:"map_id" description:"地图ID"`
|
MapID int32 `gorm:"not null;index;comment:'所属地图ID'" json:"map_id" description:"地图ID"`
|
||||||
|
|
||||||
RefreshID []int `gorm:"type:int[];comment:'精灵ID列表'" json:"refresh_id"`
|
RefreshID []uint32 `gorm:"type:int[];comment:'精灵ID列表'" json:"refresh_id"`
|
||||||
Pos []int `gorm:"type:int[];comment:'坑位位置'" json:"pos"`
|
Pos []int `gorm:"type:int[];comment:'坑位位置'" json:"pos"`
|
||||||
//最小等级
|
//最小等级
|
||||||
MinLevel int `gorm:"type:int;not null;default:1;comment:'最小等级'" json:"min_level"`
|
MinLevel int `gorm:"type:int;not null;default:1;comment:'最小等级'" json:"min_level"`
|
||||||
|
|||||||
@@ -39,12 +39,13 @@ func (s *MapService) GetTimeMap() (ret []model.MapConfig) {
|
|||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
func (s *MapService) GetTimeTip() (ret []model.MapConfig) {
|
|
||||||
//cacheKey := strings.Join([]string{fmt.Sprintf("%d", p1), fmt.Sprintf("%d", p2)}, ":")
|
|
||||||
m := dbm_notenable(s.Model)
|
|
||||||
|
|
||||||
m.Where(`is_time_space`, 1).Scan(&ret)
|
// func (s *MapService) GetTimeTip() (ret []model.MapConfig) {
|
||||||
|
// //cacheKey := strings.Join([]string{fmt.Sprintf("%d", p1), fmt.Sprintf("%d", p2)}, ":")
|
||||||
|
// m := dbm_notenable(s.Model)
|
||||||
|
|
||||||
return
|
// m.Where(`is_time_space`, 1).Scan(&ret)
|
||||||
|
|
||||||
}
|
// return
|
||||||
|
|
||||||
|
// }
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package service
|
|||||||
import (
|
import (
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"blazing/modules/config/model"
|
"blazing/modules/config/model"
|
||||||
|
|
||||||
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MapNodeService struct {
|
type MapNodeService struct {
|
||||||
@@ -44,3 +46,16 @@ func (s *MapNodeService) GetDataNode(mapid, node uint32) *model.MapNode {
|
|||||||
return pet
|
return pet
|
||||||
|
|
||||||
}
|
}
|
||||||
|
func (s *MapNodeService) GetTip(mapid uint32) []uint32 {
|
||||||
|
|
||||||
|
var pet []model.MapNode //一个特性应该是唯一的,但是我们要获取默认随机特性
|
||||||
|
dbm_enable(s.Model).Where("map_id", mapid).Scan(&pet)
|
||||||
|
var ret []uint32
|
||||||
|
for _, v := range pet {
|
||||||
|
ret = append(ret, v.TriggerID)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return lo.Union(ret)
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package service
|
|||||||
import (
|
import (
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"blazing/modules/config/model"
|
"blazing/modules/config/model"
|
||||||
|
|
||||||
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MapPitService struct {
|
type MapPitService struct {
|
||||||
@@ -28,3 +30,16 @@ func (s *MapPitService) GetData(mapid, pos uint32) []model.MapPit {
|
|||||||
return pet
|
return pet
|
||||||
|
|
||||||
}
|
}
|
||||||
|
func (s *MapPitService) GetDataALL(mapid uint32) []uint32 {
|
||||||
|
|
||||||
|
var pet []model.MapPit //一个特性应该是唯一的,但是我们要获取默认随机特性
|
||||||
|
dbm_enable(s.Model).Where("map_id", mapid).Scan(&pet)
|
||||||
|
var ret []uint32
|
||||||
|
for _, v := range pet {
|
||||||
|
|
||||||
|
ret = append(ret, v.RefreshID...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return lo.Union(ret)
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package service
|
|||||||
import (
|
import (
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"blazing/modules/config/model"
|
"blazing/modules/config/model"
|
||||||
|
|
||||||
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TalkConfigService struct {
|
type TalkConfigService struct {
|
||||||
@@ -25,3 +27,16 @@ func (s *TalkConfigService) GetCache(flag int) model.MineralCollectionConfig {
|
|||||||
return config
|
return config
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *TalkConfigService) GetTip(mapid uint32) []uint32 {
|
||||||
|
var item []model.TaskConfig
|
||||||
|
dbm_enable(s.Model).Where("map_id", mapid).Scan(&item)
|
||||||
|
var res []uint32
|
||||||
|
for _, v := range item {
|
||||||
|
res = append(res, v.ItemRewardIds...)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return lo.Union(res)
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -57,3 +57,4 @@ func (s *TaskService) IsAcceptable(taskid uint32) (out *model.TaskConfig) {
|
|||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<Eggs>
|
|
||||||
<Egg Id="1" MaleMon="450" FemaleMon="447" OutputMons="445 448 512" Probs="35 35 30" />
|
|
||||||
<Egg Id="2" MaleMon="253" FemaleMon="256" OutputMons="252 254 519" Probs="35 35 30" />
|
|
||||||
<Egg Id="3" MaleMon="516" FemaleMon="470" OutputMons="515 469 517" Probs="35 35 30" />
|
|
||||||
<Egg Id="4" MaleMon="525" FemaleMon="295" OutputMons="523 293 533" Probs="35 35 30" />
|
|
||||||
<Egg Id="5" MaleMon="337" FemaleMon="549" OutputMons="335 547 550" Probs="35 35 30" />
|
|
||||||
<Egg Id="6" MaleMon="597" FemaleMon="599" OutputMons="596 598 600" Probs="50 45 5" />
|
|
||||||
<Egg Id="7" MaleMon="67" FemaleMon="606" OutputMons="65 604 607" Probs="30 30 40" />
|
|
||||||
<Egg Id="8" MaleMon="962" FemaleMon="965" OutputMons="960 963 977" Probs="5 5 90" />
|
|
||||||
</Eggs>
|
|
||||||
Reference in New Issue
Block a user