Merge branch 'main' of https://github.com/72wo/blazing
This commit is contained in:
@@ -22,4 +22,5 @@ type PlayerI interface {
|
||||
SetFightC(FightI)
|
||||
SendLeaveMapInfo(b maps.LeaveMapOutboundInfo)
|
||||
SendEnterMapInfo(b maps.OutInfo)
|
||||
SendWalkMapInfo(b maps.WalkOutInfo)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,28 @@ import (
|
||||
"github.com/creasty/defaults"
|
||||
)
|
||||
|
||||
type ListMapPlayerOutboundInfo struct {
|
||||
PlayersLen uint32 `struc:"sizeof=Player" json:"player_len"`
|
||||
|
||||
// 穿戴装备的信息
|
||||
Player []OutInfo ` json:"player"`
|
||||
}
|
||||
|
||||
// PeopleWalkOutboundInfo PeopleWalkOutboundInfo类,实现OutboundMessage接口
|
||||
type WalkOutInfo struct {
|
||||
// Flag: 0为走,1为飞行模式
|
||||
Flag uint32 `fieldDesc:"0为走,1为飞行模式" codec:"uint"`
|
||||
|
||||
// UserID: 走动的人的米米号
|
||||
UserID uint32 `fieldDesc:"走动的人的米米号" codec:"uint"`
|
||||
|
||||
// Point: 直接给坐标x,y
|
||||
Point model.Pos `fieldDesc:"直接给坐标x,y"`
|
||||
|
||||
PathLen uint32 `struc:"sizeof=Path" `
|
||||
Path string
|
||||
}
|
||||
|
||||
// 这里存储星球的map
|
||||
//var planetmap utils.SyncMap[] //= space.NewSyncMap()
|
||||
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
package maps
|
||||
|
||||
import (
|
||||
"blazing/logic/service/maps/info"
|
||||
"blazing/logic/service/player"
|
||||
)
|
||||
|
||||
type ListMapPlayerInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2003" struc:"[0]pad"` //切换地图
|
||||
}
|
||||
|
||||
type ListMapPlayerOutboundInfo struct {
|
||||
PlayersLen uint32 `struc:"sizeof=Player" json:"player_len"`
|
||||
|
||||
// 穿戴装备的信息
|
||||
Player []info.OutInfo ` json:"player"`
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package maps
|
||||
|
||||
import (
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/space"
|
||||
|
||||
"blazing/modules/blazing/model"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
type WalkInInfo struct {
|
||||
@@ -21,35 +17,3 @@ type WalkInInfo struct {
|
||||
PathLen uint32 `struc:"sizeof=Path" `
|
||||
Path string
|
||||
}
|
||||
|
||||
var limiter = rate.NewLimiter(rate.Limit(10), 5)
|
||||
|
||||
func (t *WalkInInfo) Broadcast(mapid uint32, o WalkOutInfo) {
|
||||
// cool.Limiter.Take()
|
||||
//r := cool.Limiter.Get("Broadcast"+gconv.String(mapid), rate.Limit(10), 5)
|
||||
if !limiter.Allow() {
|
||||
return
|
||||
}
|
||||
space.GetSpace(mapid).User.Range(func(playerID uint32, player common.PlayerI) bool {
|
||||
t.Head.Result = 0
|
||||
tt := t.Head.Pack(&o)
|
||||
player.SendPack(tt)
|
||||
return false
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// PeopleWalkOutboundInfo PeopleWalkOutboundInfo类,实现OutboundMessage接口
|
||||
type WalkOutInfo struct {
|
||||
// Flag: 0为走,1为飞行模式
|
||||
Flag uint32 `fieldDesc:"0为走,1为飞行模式" codec:"uint"`
|
||||
|
||||
// UserID: 走动的人的米米号
|
||||
UserID uint32 `fieldDesc:"走动的人的米米号" codec:"uint"`
|
||||
|
||||
// Point: 直接给坐标x,y
|
||||
Point model.Pos `fieldDesc:"直接给坐标x,y"`
|
||||
|
||||
PathLen uint32 `struc:"sizeof=Path" `
|
||||
Path string
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ type AI_player struct {
|
||||
func (f *AI_player) SendPack(b []byte) error {
|
||||
return nil
|
||||
|
||||
}
|
||||
func (p *AI_player) SendWalkMapInfo(b maps.WalkOutInfo) {
|
||||
|
||||
}
|
||||
func (p *AI_player) SendLeaveMapInfo(b maps.LeaveMapOutboundInfo) {
|
||||
|
||||
|
||||
@@ -23,6 +23,13 @@ func (p *Player) SendEnterMapInfo(b maps.OutInfo) {
|
||||
p.SendPack(t1.Pack(&b)) //准备包由各自发,因为协议不一样
|
||||
|
||||
}
|
||||
func (p *Player) SendWalkMapInfo(b maps.WalkOutInfo) {
|
||||
t1 := NewTomeeHeader(2101, p.Info.UserID)
|
||||
|
||||
p.SendPack(t1.Pack(&b)) //准备包由各自发,因为协议不一样
|
||||
|
||||
}
|
||||
|
||||
func (p *Player) SendChangePet(b info.ChangePetInfo) {
|
||||
t1 := NewTomeeHeader(2407, p.Info.UserID)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"blazing/common/utils"
|
||||
"blazing/cool"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/space"
|
||||
"math/rand"
|
||||
"strings"
|
||||
|
||||
@@ -81,6 +82,9 @@ func (p *Player) UseCoins(t uint32) bool {
|
||||
}
|
||||
func (p *Player) GetAction() {
|
||||
|
||||
}
|
||||
func (p *Player) GetSpace() *space.Space {
|
||||
return space.GetSpace(p.Info.MapID)
|
||||
}
|
||||
func (p *Player) CanFight() bool {
|
||||
if p.FightC != nil {
|
||||
|
||||
@@ -1,45 +1,68 @@
|
||||
package space
|
||||
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
|
||||
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
||||
"golang.org/x/sync/singleflight"
|
||||
)
|
||||
|
||||
var requestGroup singleflight.Group // SingleFlight 实例
|
||||
// MapHotInfo 表示地图热度信息
|
||||
type MapHotInfo struct {
|
||||
MapID uint32 `json:"mapId"` // 地图ID
|
||||
Count uint32 `json:"count"` // 地图里的人数
|
||||
MapID uint32 `json:"mapId"` // 地图ID
|
||||
Count int32 `struc:"uint32" json:"count"` // 地图里的人数
|
||||
}
|
||||
|
||||
var maphot = csmap.New[uint32, *int32](
|
||||
// set the number of map shards. the default value is 32.
|
||||
csmap.WithShardCount[uint32, *int32](32),
|
||||
|
||||
// // if don't set custom hasher, use the built-in maphash.
|
||||
// csmap.WithCustomHasher[string, int](func(key string) uint64 {
|
||||
// hash := fnv.New64a()
|
||||
// hash.Write([]byte(key))
|
||||
// return hash.Sum64()
|
||||
// }),
|
||||
|
||||
// set the total capacity, every shard map has total capacity/shard count capacity. the default value is 0.
|
||||
// csmap.WithSize[string, int](1000),
|
||||
)
|
||||
|
||||
func GetMapHot() []MapHotInfo {
|
||||
ret := make([]MapHotInfo, 0)
|
||||
maphot.Range(func(key uint32, value *int32) (stop bool) {
|
||||
ret = append(ret, MapHotInfo{
|
||||
MapID: key,
|
||||
Count: *value,
|
||||
})
|
||||
|
||||
result1, _, _ := requestGroup.Do("map_hot", func() (interface{}, error) {
|
||||
|
||||
tt := make(map[uint32]uint32)
|
||||
|
||||
for _, v := range xmlres.MapConfig.Maps {
|
||||
|
||||
t1, ok := tt[uint32(v.Super)]
|
||||
if ok {
|
||||
tt[uint32(v.Super)] = uint32(int(t1) + GetSpace(uint32(v.ID)).User.Count())
|
||||
|
||||
} else {
|
||||
tt[uint32(v.Super)] = uint32(GetSpace(uint32(v.ID)).User.Count())
|
||||
}
|
||||
|
||||
}
|
||||
var result = make([]MapHotInfo, 0)
|
||||
for k, v := range tt {
|
||||
|
||||
result = append(result, MapHotInfo{
|
||||
MapID: uint32(k),
|
||||
Count: uint32(v),
|
||||
})
|
||||
|
||||
}
|
||||
return result, nil
|
||||
return true
|
||||
})
|
||||
return result1.([]MapHotInfo)
|
||||
return ret
|
||||
// result1, _, _ := requestGroup.Do("map_hot", func() (interface{}, error) {
|
||||
|
||||
// tt := make(map[uint32]uint32)
|
||||
|
||||
// for _, v := range xmlres.MapConfig.Maps {
|
||||
|
||||
// t1, ok := tt[uint32(v.Super)]
|
||||
// if ok {
|
||||
// tt[uint32(v.Super)] = uint32(int(t1) + GetSpace(uint32(v.ID)).User.Count())
|
||||
|
||||
// } else {
|
||||
// tt[uint32(v.Super)] = uint32(GetSpace(uint32(v.ID)).User.Count())
|
||||
// }
|
||||
|
||||
// }
|
||||
// var result = make([]MapHotInfo, 0)
|
||||
// for k, v := range tt {
|
||||
|
||||
// result = append(result, MapHotInfo{
|
||||
// MapID: uint32(k),
|
||||
// Count: uint32(v),
|
||||
// })
|
||||
|
||||
// }
|
||||
// return result, nil
|
||||
// })
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,11 @@ package space
|
||||
import (
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/maps/info"
|
||||
maps "blazing/logic/service/maps/info"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
func (s *Space) LeaveMap(c common.PlayerI) {
|
||||
@@ -14,9 +17,6 @@ func (s *Space) LeaveMap(c common.PlayerI) {
|
||||
if c.GetInfo() == nil {
|
||||
return
|
||||
}
|
||||
if c.GetInfo().MapID == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
s.UP_ARENA(c, 0) //退出擂台
|
||||
s.User.Range(func(k uint32, v common.PlayerI) (stop bool) {
|
||||
@@ -29,6 +29,12 @@ func (s *Space) LeaveMap(c common.PlayerI) {
|
||||
})
|
||||
|
||||
s.User.Delete(c.GetInfo().UserID)
|
||||
s.UserInfo.Delete(c.GetInfo().UserID)
|
||||
if s.SuperValue != nil {
|
||||
|
||||
atomic.AddInt32(s.SuperValue, -1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *Space) EnterMap(c common.PlayerI) {
|
||||
@@ -36,10 +42,52 @@ func (s *Space) EnterMap(c common.PlayerI) {
|
||||
out := info.NewOutInfo()
|
||||
copier.CopyWithOption(out, c.GetInfo(), copier.Option{DeepCopy: true})
|
||||
s.User.Range(func(k uint32, v common.PlayerI) (stop bool) {
|
||||
|
||||
v.SendEnterMapInfo(*out)
|
||||
|
||||
if k != c.GetInfo().UserID {
|
||||
v.SendEnterMapInfo(*out)
|
||||
}
|
||||
return false
|
||||
})
|
||||
s.User.Store(c.GetInfo().UserID, c)
|
||||
s.UserInfo.Store(c.GetInfo().UserID, *out)
|
||||
if s.SuperValue != nil {
|
||||
atomic.AddInt32(s.SuperValue, 1)
|
||||
}
|
||||
|
||||
}
|
||||
func (s *Space) GetInfo() []maps.OutInfo {
|
||||
ret := make([]maps.OutInfo, 0)
|
||||
s.UserInfo.Range(func(k uint32, v maps.OutInfo) (stop bool) {
|
||||
ret = append(ret, v)
|
||||
return len(ret) > 30
|
||||
})
|
||||
|
||||
return ret
|
||||
|
||||
}
|
||||
|
||||
var limiter = rate.NewLimiter(rate.Limit(10), 5)
|
||||
|
||||
func (s *Space) Walk(b maps.WalkOutInfo) {
|
||||
// cool.Limiter.Take()
|
||||
//r := cool.Limiter.Get("Broadcast"+gconv.String(mapid), rate.Limit(10), 5)
|
||||
if !limiter.Allow() {
|
||||
return
|
||||
}
|
||||
|
||||
s.User.Range(func(playerID uint32, player common.PlayerI) bool {
|
||||
player.SendWalkMapInfo(b)
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func LastFourElements[T any](s []T) []T {
|
||||
n := len(s)
|
||||
if n <= 30 {
|
||||
// 切片长度小于等于4时,返回整个切片
|
||||
return s
|
||||
}
|
||||
// 切片长度大于4时,返回最后4个元素(从n-4索引到末尾)
|
||||
return s[n-30:]
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight/info"
|
||||
maps "blazing/logic/service/maps/info"
|
||||
|
||||
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
||||
)
|
||||
@@ -13,7 +14,10 @@ import (
|
||||
// Space 针对Player的并发安全map,键为uint32类型
|
||||
type Space struct {
|
||||
User *csmap.CsMap[uint32, common.PlayerI] // 存储玩家数据的map,键为玩家ID
|
||||
CanRefresh bool //是否能够刷怪
|
||||
UserInfo *csmap.CsMap[uint32, maps.OutInfo]
|
||||
CanRefresh bool //是否能够刷怪
|
||||
Super uint32
|
||||
SuperValue *int32
|
||||
//ID uint32 // 地图ID
|
||||
Name string //地图名称
|
||||
ARENA info.S2C_ARENA_GET_INFO
|
||||
@@ -93,6 +97,20 @@ func NewSpace() *Space {
|
||||
// return hash.Sum64()
|
||||
// }),
|
||||
|
||||
// set the total capacity, every shard map has total capacity/shard count capacity. the default value is 0.
|
||||
// csmap.WithSize[string, int](1000),
|
||||
),
|
||||
UserInfo: csmap.New[uint32, maps.OutInfo](
|
||||
// set the number of map shards. the default value is 32.
|
||||
csmap.WithShardCount[uint32, maps.OutInfo](32),
|
||||
|
||||
// // if don't set custom hasher, use the built-in maphash.
|
||||
// csmap.WithCustomHasher[string, int](func(key string) uint64 {
|
||||
// hash := fnv.New64a()
|
||||
// hash.Write([]byte(key))
|
||||
// return hash.Sum64()
|
||||
// }),
|
||||
|
||||
// set the total capacity, every shard map has total capacity/shard count capacity. the default value is 0.
|
||||
// csmap.WithSize[string, int](1000),
|
||||
),
|
||||
@@ -113,6 +131,16 @@ func GetSpace(id uint32) *Space {
|
||||
for _, v := range xmlres.MapConfig.Maps {
|
||||
if v.ID == int(id) { //找到这个地图
|
||||
t := NewSpace()
|
||||
t.Super = uint32(v.Super)
|
||||
ok := maphot.Has(t.Super)
|
||||
if !ok {
|
||||
var tt int32 = 0
|
||||
maphot.Store(uint32(v.Super), &tt)
|
||||
t.SuperValue = &tt //创建一个
|
||||
|
||||
} else {
|
||||
t.SuperValue, _ = maphot.Load(uint32(v.Super))
|
||||
}
|
||||
|
||||
t.Name = v.Name
|
||||
|
||||
|
||||
@@ -18,6 +18,6 @@ type CompleteTaskOutboundInfo struct {
|
||||
// ItemInfo
|
||||
// 用于表示发放物品的信息
|
||||
type ItemInfo struct {
|
||||
ItemId uint32 `json:"itemId" description:"发放物品ID"` // 发放物品ID,
|
||||
ItemCount uint32 `json:"itemCount" description:"发放物品的数量"` // 发放物品的数量,
|
||||
ItemId uint32 `json:"itemId" description:"发放物品ID"` // 发放物品ID,
|
||||
ItemCnt uint32 `json:"itemCount" description:"发放物品的数量"` // 发放物品的数量,
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func init() {
|
||||
{300011, 3}, // 初级体力药剂x3
|
||||
}, 0)
|
||||
|
||||
RegisterTask(88, 0, []ItemInfo{ // 新手任务4(默认分支)
|
||||
RegisterTask(88, 1, []ItemInfo{ // 新手任务4(默认分支)
|
||||
{1, 50000}, // 赛尔豆x50000
|
||||
{3, 50000}, // 累积经验x50000
|
||||
{5, 20}, // 金豆x20
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package task
|
||||
|
||||
|
||||
type TaskResult struct {
|
||||
PetTypeId uint32 `json:"petTypeId" description:"发放的精灵ID"` // 发放的精灵ID,
|
||||
|
||||
@@ -19,9 +18,9 @@ func Get_Task_Info(v CompleteTaskInboundInfo) *TaskResult {
|
||||
}
|
||||
func init() {
|
||||
// 定义通用奖励:经验奖励(ItemId:3,数量20000)
|
||||
expReward := []ItemInfo{{ItemId: 3, ItemCount: 20000}}
|
||||
expReward := []ItemInfo{{ItemId: 3, ItemCnt: 20000}}
|
||||
// 定义扭蛋牌奖励(ItemId:400501,数量5)
|
||||
eggReward := []ItemInfo{{ItemId: 400501, ItemCount: 5}}
|
||||
eggReward := []ItemInfo{{ItemId: 400501, ItemCnt: 5}}
|
||||
|
||||
// 批量初始化任务ID 401-407(奖励均为经验)
|
||||
for taskID := 401; taskID <= 407; taskID++ {
|
||||
|
||||
Reference in New Issue
Block a user