重构
This commit is contained in:
@@ -15,8 +15,7 @@ github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrt
|
||||
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.3 h1:dRGGKKiT9FEnxhfHFerojy34uCKHgReKgpMbAOtqhsY=
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.3/go.mod h1:sGdaCPgN1AY0tho+WYAgYdUHJkXwuDf76M3ASgHXWRQ=
|
||||
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
|
||||
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
||||
|
||||
@@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.6.3
|
||||
github.com/gogf/gf/v2 v2.6.3
|
||||
github.com/gogf/gf/v2 v2.7.0
|
||||
gorm.io/driver/postgres v1.5.6
|
||||
gorm.io/gorm v1.25.7
|
||||
)
|
||||
|
||||
@@ -13,8 +13,7 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.6.3 h1:Q5wh3EHLksi0ej/KnBZBgr2MU6r3MISaEF341RjsBeI=
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.6.3/go.mod h1:4vzOwG+fZ76cGssHEhwao0Uto1nPpARPqgyZQ9ost/4=
|
||||
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
|
||||
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
||||
|
||||
@@ -2,7 +2,7 @@ module blazing/contrib/files/local
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/gogf/gf/v2 v2.6.3
|
||||
require github.com/gogf/gf/v2 v2.7.0
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
||||
|
||||
@@ -10,8 +10,7 @@ github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
|
||||
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
||||
|
||||
@@ -2,7 +2,7 @@ module blazing/contrib/files/pngcm
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/gogf/gf/v2 v2.6.3
|
||||
require github.com/gogf/gf/v2 v2.7.0
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
||||
|
||||
@@ -10,8 +10,7 @@ github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
|
||||
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
||||
|
||||
@@ -3,7 +3,7 @@ module blazing/cool
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.3
|
||||
github.com/gogf/gf/v2 v2.7.0
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0
|
||||
gorm.io/gorm v1.25.7
|
||||
)
|
||||
|
||||
@@ -16,8 +16,7 @@ github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
|
||||
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
|
||||
@@ -25,9 +25,7 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
|
||||
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||
github.com/gogf/gf/v2 v2.7.0/go.mod h1:Qu8nimKt9aupJQcdUL85tWF4Mfxocz97zUt8UC4abVI=
|
||||
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
|
||||
@@ -124,6 +124,36 @@ func (b *Topic[T]) PubAsync(event T) {
|
||||
b.rwMu.RUnlock()
|
||||
}
|
||||
|
||||
func (b *Topic[T]) PubAsyncCallBack(event T, fn func()) {
|
||||
// 1. 先获取当前所有订阅者的回调(缩短读锁持有时间)
|
||||
b.rwMu.RLock()
|
||||
// 复制回调到临时切片,避免持有锁期间阻塞写操作
|
||||
callbacks := make([]func(T), 0, len(b.subs))
|
||||
for _, sub := range b.subs {
|
||||
callbacks = append(callbacks, sub.callback)
|
||||
}
|
||||
b.rwMu.RUnlock() // 立即释放读锁
|
||||
|
||||
// 2. 等待所有回调执行完成
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(callbacks)) // 声明需要等待的任务数量
|
||||
|
||||
for _, cb := range callbacks {
|
||||
// 显式传递回调和事件,避免循环变量捕获问题
|
||||
go func(callback func(T), e T) {
|
||||
defer wg.Done() // 任务完成后通知WaitGroup
|
||||
callback(e) // 执行订阅者回调
|
||||
}(cb, event)
|
||||
}
|
||||
|
||||
wg.Wait() // 阻塞等待所有回调执行完毕
|
||||
|
||||
// 3. 所有回调完成后,执行传入的fn(如果非nil)
|
||||
if fn != nil {
|
||||
fn()
|
||||
}
|
||||
}
|
||||
|
||||
// Bus is being returned when you subscribe, so you can manually Cancel
|
||||
type Bus[T any] struct {
|
||||
listener *Listener[T]
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
// 处理命令: 1001
|
||||
func (h *Controller) CreatePlayer(data *user.CreatePlayerInboundInfo, c gnet.Conn) (result *user.CreatePlayerOutInfo, err errorcode.ErrorCode) {
|
||||
data.Nickname = strings.Trim(data.Nickname, "\x00")
|
||||
blservice.NewUserService(data.Head.UserID).Reg(cool.Filter.Replace(data.Nickname, '*'), data.Color)
|
||||
blservice.NewUserService(data.Head.UserID).Info.Reg(cool.Filter.Replace(data.Nickname, '*'), data.Color)
|
||||
return result, 0
|
||||
}
|
||||
|
||||
|
||||
@@ -96,9 +96,13 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *pla
|
||||
}
|
||||
|
||||
}
|
||||
c.PVPinfo = &info.PVPinfo{
|
||||
|
||||
Status: info.BattleStatus.FIGHT_WITH_BOSS,
|
||||
Mode: info.BattleMode.MULTI_MODE,
|
||||
}
|
||||
ai := player.NewAI_player(moinfo)
|
||||
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_BOSS, c, ai, func(foi *info.FightOverInfo) {
|
||||
fight.NewFight(c, ai, func(foi *info.FightOverInfo) {
|
||||
|
||||
})
|
||||
|
||||
@@ -126,8 +130,12 @@ func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundIn
|
||||
moinfo.Nick = xmlres.PetMAP[int(mo.ID)].DefName
|
||||
moinfo.PetList = append(moinfo.PetList, *mo)
|
||||
ai := player.NewAI_player(moinfo)
|
||||
c.PVPinfo = &info.PVPinfo{
|
||||
Mode: info.BattleMode.MULTI_MODE,
|
||||
Status: info.BattleStatus.FIGHT_WITH_NPC,
|
||||
}
|
||||
|
||||
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_NPC, c, ai, func(foi *info.FightOverInfo) {
|
||||
fight.NewFight(c, ai, func(foi *info.FightOverInfo) {
|
||||
|
||||
})
|
||||
|
||||
|
||||
@@ -35,7 +35,11 @@ func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.P
|
||||
|
||||
t := space.GetSpace(c.Info.MapID).Can_ARENA(c)
|
||||
if t != nil {
|
||||
fight.NewFight(info.BattleMode.SINGLE_MODE, info.BattleStatus.FIGHT_WITH_PLAYER, t, c, func(foi *info.FightOverInfo) {
|
||||
t.(*player.Player).PVPinfo = &info.PVPinfo{
|
||||
Mode: info.BattleMode.SINGLE_MODE,
|
||||
Status: info.BattleStatus.FIGHT_WITH_PLAYER,
|
||||
}
|
||||
fight.NewFight(t, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
|
||||
|
||||
@@ -20,9 +20,10 @@ func (h Controller) PET_MELEE(data *fight.StartPetWarInboundInfo, c *player.Play
|
||||
Status: info.BattleStatus.FIGHT_WITH_PLAYER}
|
||||
g := c.Pet_joinFight()
|
||||
if g != nil {
|
||||
fight.NewFight(info.BattleMode.PET_MELEE, info.BattleStatus.FIGHT_WITH_PLAYER, g, c, func(foi *info.FightOverInfo) {
|
||||
fight.NewFight(g, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
@@ -46,11 +47,12 @@ func (h Controller) PET_King(data *fight.PetKingJoinInboundInfo, c *player.Playe
|
||||
if g != nil {
|
||||
switch data.Type {
|
||||
case 5:
|
||||
fight.NewFight(info.BattleMode.SINGLE_MODE, info.BattleStatus.FIGHT_WITH_PLAYER, g, c, func(foi *info.FightOverInfo) {
|
||||
fight.NewFight(g, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
|
||||
case 6:
|
||||
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_PLAYER, g, c, func(foi *info.FightOverInfo) {
|
||||
fight.NewFight(g, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ import (
|
||||
func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
|
||||
if ok, p1 := c.AgreeBattle(data.UserID, data.Flag, data.Mode); ok {
|
||||
fight.NewFight(data.Mode, info.BattleStatus.FIGHT_WITH_PLAYER, p1, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
fight.NewFight(p1, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ func (h Controller) UserItemList(data *item.ItemListInboundInfo, c *player.Playe
|
||||
result = &item.ItemListOutboundInfo{}
|
||||
result.ItemList = make([]model.SingleItemInfo, 0)
|
||||
|
||||
item := c.Service.Item(data.Param1, data.Param2)
|
||||
item := c.Service.Item.Get(data.Param1, data.Param2)
|
||||
for _, v := range item {
|
||||
var vv model.SingleItemInfo
|
||||
vv.ItemId = v.ItemId
|
||||
@@ -87,7 +87,7 @@ func (h Controller) ChangePlayerCloth(data *item.ChangePlayerClothInboundInfo, c
|
||||
}
|
||||
func (h Controller) Talk(data *item.TalkCountInboundInfo, c *player.Player) (result *item.TalkCountOutboundInfo, err errorcode.ErrorCode) {
|
||||
result = &item.TalkCountOutboundInfo{}
|
||||
c.Service.Talk(func(t map[uint32]uint32) bool {
|
||||
c.Service.Talk.Exec(func(t map[uint32]uint32) bool {
|
||||
|
||||
tt, ok := t[data.ID]
|
||||
if ok {
|
||||
@@ -122,7 +122,7 @@ func (h Controller) TalkCate(data *item.TalkCateInboundInfo, c *player.Player) (
|
||||
|
||||
// 2. 生成 1-10 的随机数:rand.Intn(10) → 0-9,+1 后范围变为 1-10
|
||||
randomNum := rand.Intn(10) + 1
|
||||
c.Service.Talk(func(t map[uint32]uint32) bool {
|
||||
c.Service.Talk.Exec(func(t map[uint32]uint32) bool {
|
||||
if t == nil {
|
||||
t = make(map[uint32]uint32)
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.
|
||||
return
|
||||
}
|
||||
t.Service = blservice.NewUserService(data.Head.UserID)
|
||||
t.Info = t.Service.Person(data.Head.UserID)
|
||||
t.Info = t.Service.Info.Person(data.Head.UserID)
|
||||
if t.Info == nil {
|
||||
err = errorcode.ErrorCodes.ErrLoginServerError
|
||||
return
|
||||
@@ -96,8 +96,7 @@ func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.
|
||||
result = user.NewOutInfo() //设置登录消息
|
||||
|
||||
result.PlayerInfo = *t.Info
|
||||
go space.GetSpace(t.Info.MapID).EnterMap(t)
|
||||
|
||||
go space.GetSpace(t.Info.MapID).EnterMap(t)
|
||||
|
||||
return result, 0
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ func (h *Controller) GetPetInfo(
|
||||
if result == nil {
|
||||
|
||||
result = &pet.OutInfo{
|
||||
PetInfo: c.Service.PetInfo_One(data.CatchTime).Data,
|
||||
PetInfo: c.Service.Pet.PetInfo_One(data.CatchTime).Data,
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func (h *Controller) GetPetList(
|
||||
err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
result = &pet.GetPetListOutboundInfo{}
|
||||
|
||||
tt := c.Service.PetInfo(0) //获得未放生的精灵
|
||||
tt := c.Service.Pet.PetInfo(0) //获得未放生的精灵
|
||||
result.ShortInfoList = make([]pet.PetShortInfo, len(tt))
|
||||
for i, v := range tt {
|
||||
|
||||
@@ -72,7 +72,7 @@ func (h *Controller) PetRelease(
|
||||
|
||||
for _, v := range c.Info.PetList {
|
||||
if v.CatchTime == uint32(data.CatchTime) {
|
||||
c.Service.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
|
||||
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
|
||||
t.Data = v
|
||||
//t.InBag = 0
|
||||
|
||||
@@ -87,7 +87,7 @@ func (h *Controller) PetRelease(
|
||||
// break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环
|
||||
case 1:
|
||||
//todo 背包
|
||||
c.Service.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
|
||||
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
|
||||
|
||||
_, _, ok := utils.FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {
|
||||
return item.CatchTime == uint32(data.CatchTime)
|
||||
|
||||
@@ -22,7 +22,7 @@ func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *player.Playe
|
||||
if c.Info.TaskList[data.TaskId-1] == 0 {
|
||||
c.Info.TaskList[data.TaskId-1] = 1
|
||||
}
|
||||
c.Service.Task(uint32(data.TaskId), func(t *model.TaskEX) bool {
|
||||
c.Service.Task.Exec(uint32(data.TaskId), func(t *model.TaskEX) bool {
|
||||
t.Data = []uint32{}
|
||||
|
||||
return true
|
||||
@@ -42,7 +42,7 @@ func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *player.Playe
|
||||
// isdaliy = true
|
||||
// }
|
||||
|
||||
c.Service.Task(data.TaskId, func(te *model.TaskEX) bool {
|
||||
c.Service.Task.Exec(data.TaskId, func(te *model.TaskEX) bool {
|
||||
te.Data = data.TaskList
|
||||
return true
|
||||
})
|
||||
@@ -79,7 +79,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.
|
||||
r := c.GenPetInfo(int(tt.PetTypeId), 31, -1, 0, 0, 50)
|
||||
result.CaptureTime = r.CatchTime
|
||||
result.PetTypeId = r.ID
|
||||
c.Service.PetAdd(*r)
|
||||
c.Service.Pet.PetAdd(*r)
|
||||
}
|
||||
|
||||
var ttt []model.SingleItemInfo
|
||||
@@ -99,7 +99,7 @@ func (h Controller) Get_Task_Buf(data *task.GetTaskBufInboundInfo, c *player.Pla
|
||||
result = &task.GetTaskBufOutboundInfo{
|
||||
TaskId: data.TaskId,
|
||||
}
|
||||
c.Service.Task(data.TaskId, func(te *model.TaskEX) bool {
|
||||
c.Service.Task.Exec(data.TaskId, func(te *model.TaskEX) bool {
|
||||
|
||||
result.TaskList = te.Data
|
||||
return false
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
func (h Controller) UserSimInfo(data *user.SimUserInfoInboundInfo, c *player.Player) (result *user.SimUserInfoOutboundInfo, err errorcode.ErrorCode) {
|
||||
ret := &user.SimUserInfoOutboundInfo{}
|
||||
|
||||
copier.Copy(ret, c.Service.Person(data.UserId))
|
||||
copier.Copy(ret, c.Service.Info.Person(data.UserId))
|
||||
return ret, 0
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func (h Controller) UserSimInfo(data *user.SimUserInfoInboundInfo, c *player.Pla
|
||||
// 返回: 包含用户更多信息的输出结果和错误码。
|
||||
func (h Controller) UserMoreInfo(data *user.MoreUserInfoInboundInfo, c *player.Player) (result *user.MoreUserInfoOutboundInfo, err errorcode.ErrorCode) {
|
||||
ret := &user.MoreUserInfoOutboundInfo{}
|
||||
info := c.Service.Person(data.UserId)
|
||||
info := c.Service.Info.Person(data.UserId)
|
||||
copier.Copy(ret, info)
|
||||
|
||||
//todo 待实现
|
||||
|
||||
@@ -61,7 +61,7 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.3
|
||||
github.com/gogf/gf/v2 v2.7.0
|
||||
github.com/panjf2000/gnet/v2 v2.9.1
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@@ -42,8 +42,7 @@ github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs=
|
||||
github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc=
|
||||
github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.3 h1:tbN3rYVSi5MfCS5qAaZ1Xg3fSsyHeT++tJZqEiH1s4c=
|
||||
github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.3/go.mod h1:2+evGu1xAlamaYuDdSqa7QCiwPTm1RrGsUFSMc8PyLc=
|
||||
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
|
||||
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
||||
|
||||
@@ -78,7 +78,7 @@ func loadAccounts() {
|
||||
}
|
||||
t := service.NewBaseSysUserService().GetEamil(line)
|
||||
|
||||
blservice.NewUserService(uint32(t.ID)).Reg(t.Username, 0)
|
||||
blservice.NewUserService(uint32(t.ID)).Info.Reg(t.Username, 0)
|
||||
}
|
||||
//fmt.Printf("加载 %d 个账号\n", len(accounts))
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ type PlayerI interface {
|
||||
GetPlayerCaptureContext() *info.PlayerCaptureContext
|
||||
Roll(int, int) (bool, float64, float64)
|
||||
SendPack(b []byte) error
|
||||
Getfightinfo() info.PVPinfo
|
||||
SendReadyToFightInfo(info.FightStartOutboundInfo)
|
||||
SendNoteReadyToFightInfo(info.NoteReadyToFightInfo)
|
||||
Send_ARENA_GET_INFO(b info.S2C_ARENA_GET_INFO)
|
||||
|
||||
@@ -166,13 +166,13 @@ func (f *FightC) buildFightStartInfo() info.FightStartOutboundInfo {
|
||||
var startInfo info.FightStartOutboundInfo
|
||||
|
||||
// 复制双方初始宠物信息(取列表第一个宠物)
|
||||
if len(f.Info.OurPetList) > 0 {
|
||||
_ = copier.Copy(&startInfo.Info1, &f.Info.OurPetList[0])
|
||||
startInfo.Info1.UserID = f.Info.OurInfo.UserID
|
||||
if len(f.ReadyInfo.OurPetList) > 0 {
|
||||
_ = copier.Copy(&startInfo.Info1, &f.ReadyInfo.OurPetList[0])
|
||||
startInfo.Info1.UserID = f.ReadyInfo.OurInfo.UserID
|
||||
}
|
||||
if len(f.Info.OpponentPetList) > 0 {
|
||||
_ = copier.Copy(&startInfo.Info2, &f.Info.OpponentPetList[0])
|
||||
startInfo.Info2.UserID = f.Info.OpponentInfo.UserID
|
||||
if len(f.ReadyInfo.OpponentPetList) > 0 {
|
||||
_ = copier.Copy(&startInfo.Info2, &f.ReadyInfo.OpponentPetList[0])
|
||||
startInfo.Info2.UserID = f.ReadyInfo.OpponentInfo.UserID
|
||||
}
|
||||
|
||||
return startInfo
|
||||
@@ -189,10 +189,10 @@ func (f *FightC) checkBothPlayersReady(currentPlayer common.PlayerI) bool {
|
||||
// handleNPCFightSpecial 处理NPC战斗的特殊逻辑(如可捕捉标记)
|
||||
func (f *FightC) handleNPCFightSpecial(startInfo *info.FightStartOutboundInfo) {
|
||||
// 检查野怪是否可捕捉(根据宠物ID获取捕捉率)
|
||||
if len(f.Info.OpponentPetList) == 0 {
|
||||
if len(f.ReadyInfo.OpponentPetList) == 0 {
|
||||
return
|
||||
}
|
||||
npcPetID := int(f.Info.OpponentPetList[0].ID)
|
||||
npcPetID := int(f.ReadyInfo.OpponentPetList[0].ID)
|
||||
petCfg, ok := xmlres.PetMAP[npcPetID]
|
||||
if !ok {
|
||||
// log.Error(context.Background(), "NPC宠物配置不存在", "petID", npcPetID)
|
||||
|
||||
@@ -15,9 +15,6 @@ type Effect100 struct {
|
||||
}
|
||||
|
||||
func (e *Effect100) Skill_Hit() bool {
|
||||
if !e.Hit() {
|
||||
return true
|
||||
}
|
||||
|
||||
if e.Ctx().SkillEntity == nil {
|
||||
return true
|
||||
|
||||
@@ -30,7 +30,7 @@ func (e *Effect31) Damage_Mul(t *info.DamageZone) bool {
|
||||
|
||||
if t.Type == info.DamageType.Red {
|
||||
n := int(e.Input.FightC.GetRand().Int31n(int32(e.SideEffectArgs[1]-e.SideEffectArgs[0]+1))) + e.SideEffectArgs[0]
|
||||
e.Ctx().Our.DamageZone.Damage = e.Ctx().Our.DamageZone.Damage.Mul(decimal.NewFromInt(int64(n)))
|
||||
t.Damage = t.Damage.Mul(decimal.NewFromInt(int64(n)))
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -46,17 +46,16 @@ type Effect38_sub struct {
|
||||
}
|
||||
|
||||
func (e *Effect38_sub) Alive(t ...bool) bool {
|
||||
if !e.Hit() {
|
||||
return e.EffectNode.Alive()
|
||||
}
|
||||
e.EffectNode.Alive(t...)
|
||||
if len(t) > 0 {
|
||||
if !t[0] { //说明到了回合结束取消节点,那么就将变化过的属性变化回来
|
||||
//还原属性
|
||||
e.Ctx().Our.CurrentPet.Info.MaxHp = e.oldtype
|
||||
defer func() {
|
||||
if len(t) > 0 {
|
||||
if !t[0] { //说明到了回合结束取消节点,那么就将变化过的属性变化回来
|
||||
//还原属性
|
||||
e.Ctx().Our.CurrentPet.Info.MaxHp = e.oldtype
|
||||
}
|
||||
}
|
||||
}
|
||||
return e.EffectNode.Alive()
|
||||
}()
|
||||
|
||||
return e.EffectNode.Alive(t...)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -22,6 +22,13 @@ type Effect41 struct {
|
||||
node.EffectNode
|
||||
}
|
||||
|
||||
func (e *Effect41) SetArgs(t *input.Input, a ...int) {
|
||||
n := e.Input.FightC.GetRand().Int31n(int32(e.Args()[1]-e.Args()[0]+1)) + int32(e.Args()[0])
|
||||
e.EffectNode.SetArgs(t, a...)
|
||||
e.EffectNode.Duration(int(n))
|
||||
|
||||
}
|
||||
|
||||
// 伤害落实前触发,限制最大伤害
|
||||
func (e *Effect41) Damage_DIV_ex(t *info.DamageZone) bool {
|
||||
|
||||
|
||||
@@ -41,15 +41,14 @@ func (e *Effect45) SetArgs(t *input.Input, a ...int) {
|
||||
|
||||
}
|
||||
func (e *Effect45) Alive(t ...bool) bool {
|
||||
if !e.Hit() {
|
||||
return e.EffectNode.Alive()
|
||||
}
|
||||
e.EffectNode.Alive(t...)
|
||||
if len(t) > 0 {
|
||||
if !t[0] { //说明到了回合结束取消节点,那么就将变化过的属性变化回来
|
||||
//还原属性
|
||||
e.Ctx().Our.CurrentPet.Info.Prop[1] = e.oldtype
|
||||
defer func() {
|
||||
if len(t) > 0 {
|
||||
if !t[0] { //说明到了回合结束取消节点,那么就将变化过的属性变化回来
|
||||
//还原属性
|
||||
e.Ctx().Our.CurrentPet.Info.Prop[1] = e.oldtype
|
||||
}
|
||||
}
|
||||
}
|
||||
return e.EffectNode.Alive()
|
||||
}()
|
||||
|
||||
return e.EffectNode.Alive(t...)
|
||||
}
|
||||
|
||||
@@ -28,18 +28,13 @@ func (e *Effect49) Damage_SUB_ex(t *info.DamageZone) bool {
|
||||
//fmt.Println("Effect49_o", t.Damage)
|
||||
if t.Type == info.DamageType.Red {
|
||||
|
||||
t.Damage.Sub(decimal.NewFromInt(int64(e.Args()[0])))
|
||||
t.Damage = t.Damage.Sub(decimal.NewFromInt(int64(e.Args()[0])))
|
||||
|
||||
}
|
||||
|
||||
//fmt.Println("Effect49_n", t.Damage)
|
||||
return true
|
||||
}
|
||||
func (e *Effect49) SetArgs(t *input.Input, a ...int) {
|
||||
|
||||
e.EffectNode.SetArgs(t, a...)
|
||||
|
||||
}
|
||||
|
||||
// ---- 注册所有效果 ----
|
||||
func init() {
|
||||
|
||||
@@ -29,7 +29,7 @@ type Effect73 struct {
|
||||
func (e *Effect73) SetArgs(t *input.Input, a ...int) {
|
||||
|
||||
e.EffectNode.SetArgs(t, a...)
|
||||
e.EffectNode.Duration(e.EffectNode.SideEffectArgs[0])
|
||||
e.EffectNode.Duration(e.EffectNode.SideEffectArgs[0]-1)
|
||||
|
||||
}
|
||||
func (e *Effect73) Skill_Use_ex() bool {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package effect
|
||||
|
||||
import (
|
||||
element "blazing/common/data/Element"
|
||||
"blazing/logic/service/fight/action"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
@@ -10,115 +11,122 @@ import (
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
type BaseSataus struct {
|
||||
// 修正拼写错误:BaseSataus -> BaseStatus
|
||||
type BaseStatus struct {
|
||||
node.EffectNode
|
||||
Status info.EnumPetStatus
|
||||
Status info.EnumPetStatus // 状态类型枚举
|
||||
}
|
||||
|
||||
// /重写切换事件
|
||||
func (e *BaseSataus) Switch(in *input.Input, _ info.AttackValue, _ *info.BattlePetEntity) bool {
|
||||
|
||||
//状态如果是我方切换,那么就消除掉状态效果
|
||||
// 重写切换事件:我方单位切换时清除状态
|
||||
func (e *BaseStatus) Switch(in *input.Input, _ info.AttackValue, _ *info.BattlePetEntity) bool {
|
||||
// 我方单位下场时,状态失效
|
||||
if in == e.Ctx().Our {
|
||||
//下场,执行消回合效果
|
||||
// e.ctx.Our.CancelAll()
|
||||
///我放下场
|
||||
e.Alive(false)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
type StatusNotSkill struct {
|
||||
BaseSataus
|
||||
// 不能出手的基础状态(如麻痹、疲惫等)
|
||||
type StatusCannotAct struct {
|
||||
BaseStatus
|
||||
}
|
||||
|
||||
// 不能出手
|
||||
func (e *StatusNotSkill) Skill_Hit_Pre(a, b *action.SelectSkillAction) bool {
|
||||
|
||||
// 技能命中前拦截:阻止出手
|
||||
func (e *StatusCannotAct) Skill_Hit_Pre(attacker, defender *action.SelectSkillAction) bool {
|
||||
return false
|
||||
|
||||
}
|
||||
|
||||
type StatusSleep struct { //睡眠不能出手 ,这个挂载到对面来实现对方攻击后解除睡眠效果
|
||||
StatusNotSkill
|
||||
can bool
|
||||
// 睡眠状态:受击后解除
|
||||
type StatusSleep struct {
|
||||
StatusCannotAct
|
||||
hasTriedAct bool // 标记是否尝试过行动
|
||||
}
|
||||
|
||||
func (e *StatusSleep) Skill_Hit_Pre(a, b *action.SelectSkillAction) bool {
|
||||
|
||||
e.can = true
|
||||
return e.StatusNotSkill.Skill_Hit_Pre(a, b)
|
||||
|
||||
// 尝试出手时标记状态
|
||||
func (e *StatusSleep) Skill_Hit_Pre(attacker, defender *action.SelectSkillAction) bool {
|
||||
e.hasTriedAct = true
|
||||
return e.StatusCannotAct.Skill_Hit_Pre(attacker, defender)
|
||||
}
|
||||
|
||||
// 技能使用后处理:非状态类技能触发后解除睡眠
|
||||
func (e *StatusSleep) Skill_Use_ex() bool {
|
||||
if !e.can {
|
||||
if !e.hasTriedAct {
|
||||
return true
|
||||
}
|
||||
if e.Ctx().SkillEntity == nil {
|
||||
return true
|
||||
}
|
||||
if e.Ctx().Category() != info.Category.STATUS {
|
||||
// 技能实体存在且非状态类型技能,解除睡眠
|
||||
if e.Ctx().SkillEntity != nil && e.Ctx().Category() != info.Category.STATUS {
|
||||
e.Alive(false)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 扣血类
|
||||
type DrainHP struct {
|
||||
BaseSataus
|
||||
|
||||
damage decimal.Decimal
|
||||
// 持续伤害状态基类(中毒、冻伤、烧伤等)
|
||||
type ContinuousDamage struct {
|
||||
BaseStatus
|
||||
}
|
||||
|
||||
func (e *DrainHP) Skill_Hit_Pre(a, b *action.SelectSkillAction) bool {
|
||||
e.damage = decimal.NewFromUint64(uint64(e.Ctx().Our.CurrentPet.Info.MaxHp)).
|
||||
// 技能命中前触发伤害(1/8最大生命值真实伤害)
|
||||
func (e *ContinuousDamage) Skill_Hit_Pre_ex(attacker, defender *action.SelectSkillAction) bool {
|
||||
damage := e.calculateDamage()
|
||||
e.Ctx().Our.Damage(e.Input, &info.DamageZone{
|
||||
Type: info.DamageType.True,
|
||||
Damage: damage,
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
// 计算伤害:最大生命值的1/8
|
||||
func (e *ContinuousDamage) calculateDamage() decimal.Decimal {
|
||||
return decimal.NewFromUint64(uint64(e.Ctx().Our.CurrentPet.Info.MaxHp)).
|
||||
Div(decimal.NewFromInt(8))
|
||||
}
|
||||
|
||||
// 寄生种子状态:扣血同时给对方回血
|
||||
type ParasiticSeed struct {
|
||||
BaseStatus
|
||||
}
|
||||
|
||||
// 技能命中前触发寄生效果
|
||||
func (e *ParasiticSeed) Skill_Hit_Pre(attacker, defender *action.SelectSkillAction) bool {
|
||||
// 过滤特定类型单位(假设1是植物类型,使用枚举替代魔法数字)
|
||||
if gconv.Int(e.Ctx().Our.CurrentPet.Type) == int(element.ElementTypeGrass) {
|
||||
return true
|
||||
}
|
||||
|
||||
damage := decimal.NewFromUint64(uint64(e.Ctx().Our.CurrentPet.Info.MaxHp)).
|
||||
Div(decimal.NewFromInt(8))
|
||||
|
||||
// 对我方造成真实伤害
|
||||
e.Ctx().Our.Damage(e.Input, &info.DamageZone{
|
||||
|
||||
Type: info.DamageType.True,
|
||||
Damage: e.damage,
|
||||
Damage: damage,
|
||||
})
|
||||
|
||||
// 给对方回血(不受回血限制影响)
|
||||
e.Ctx().Opp.Heal(e.Ctx().Our, nil, damage)
|
||||
return true
|
||||
}
|
||||
|
||||
// 被寄生种子 扣血类
|
||||
type DrainedHP struct {
|
||||
DrainHP
|
||||
}
|
||||
|
||||
func (e *DrainedHP) Skill_Hit_Pre(a, b *action.SelectSkillAction) bool {
|
||||
|
||||
if gconv.Int(e.Ctx().Our.CurrentPet.Type) == 1 {
|
||||
return true
|
||||
}
|
||||
e.DrainHP.Skill_Hit_Pre(a, b) //先调用父类扣血
|
||||
//TODO 寄生种子 给对面回血,待实现回血buff
|
||||
|
||||
//这个回血不属于任何类型,所以不会被阻止回血
|
||||
e.Ctx().Opp.Heal(e.Ctx().Our, nil, e.damage)
|
||||
// input.CurrentPet.Info.Hp = -e.Input.CurrentPet.Info.MaxHp / 8
|
||||
|
||||
return true
|
||||
|
||||
}
|
||||
func init() {
|
||||
//麻痹,疲惫,害怕,石化,都是无法行动
|
||||
// 注册持续伤害类状态
|
||||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.DrainedHP), &ParasiticSeed{}) // 寄生种子
|
||||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.Poisoned), &ContinuousDamage{}) // 中毒
|
||||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.Frozen), &ContinuousDamage{}) // 冻伤
|
||||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.Burned), &ContinuousDamage{}) // 烧伤
|
||||
|
||||
tt := func(t info.EnumPetStatus, f *StatusNotSkill) {
|
||||
|
||||
f.Status = t
|
||||
input.InitEffect(input.EffectType.Status, int(t), f)
|
||||
// 批量注册不能行动的状态
|
||||
nonActingStatuses := []info.EnumPetStatus{
|
||||
info.PetStatus.Paralysis, // 麻痹
|
||||
info.PetStatus.Tired, // 疲惫
|
||||
info.PetStatus.Fear, // 害怕
|
||||
info.PetStatus.Petrified, // 石化
|
||||
}
|
||||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.DrainedHP), &DrainedHP{}) //寄生种子
|
||||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.Poisoned), &DrainHP{}) //中毒
|
||||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.Frozen), &DrainHP{}) //冻伤
|
||||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.Burned), &DrainHP{}) //烧伤
|
||||
tt(info.PetStatus.Paralysis, &StatusNotSkill{}) //麻痹
|
||||
tt(info.PetStatus.Tired, &StatusNotSkill{}) //疲惫
|
||||
tt(info.PetStatus.Fear, &StatusNotSkill{}) //害怕
|
||||
tt(info.PetStatus.Petrified, &StatusNotSkill{}) //石化
|
||||
input.InitEffect(input.EffectType.Status, 8, &StatusSleep{}) //睡眠
|
||||
for _, status := range nonActingStatuses {
|
||||
effect := &StatusCannotAct{}
|
||||
effect.Status = status
|
||||
input.InitEffect(input.EffectType.Status, int(status), effect)
|
||||
}
|
||||
|
||||
// 注册睡眠状态(使用枚举常量替代硬编码8)
|
||||
input.InitEffect(input.EffectType.Status, int(info.PetStatus.Sleep), &StatusSleep{})
|
||||
}
|
||||
|
||||
@@ -114,12 +114,6 @@ func (f *FightC) copyskill(t *action.SelectSkillAction) *info.SkillEntity {
|
||||
oldskill.(*info.SkillEntity).Rand = f.rand //拷贝后随机数丢失
|
||||
return oldskill.(*info.SkillEntity)
|
||||
}
|
||||
func (f *FightC) copypet(t *model.PetInfo) *model.PetInfo {
|
||||
|
||||
oldskill, _ := deepcopy.Anything(t) //备份技能
|
||||
// oldskill.(*info.BattlePetEntity).Rand = f.rand //拷贝后随机数丢失
|
||||
return oldskill.(*model.PetInfo)
|
||||
}
|
||||
|
||||
//回合有先手方和后手方,同时有攻击方和被攻击方
|
||||
|
||||
@@ -129,37 +123,14 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
|
||||
// 神罗、圣华登场时魂免,“登场时xx”等效果
|
||||
//阿枫的效果也在这里判断
|
||||
|
||||
// var oldpet [2]*model.PetInfo
|
||||
f.Broadcast(func(ff *input.Input) {
|
||||
ff.Exec(func(t input.Effect) bool { //回合开始前
|
||||
|
||||
// var oldhp [2]uint32
|
||||
// var oldskill [2][]model.SkillInfo
|
||||
|
||||
// oldpet[0], oldpet[1] = f.copypet(f.Our.CurrentPet.Info), f.copypet(f.Opp.CurrentPet.Info)
|
||||
|
||||
// fmt.Println("开始时对方最大体力值", f.Opp.CurrentPet.Info.MaxHp)
|
||||
// defer func() {
|
||||
// oldhp[0], oldhp[1] = f.Opp.CurrentPet.Info.Hp, f.Our.CurrentPet.Info.Hp
|
||||
// oldskill[0], oldskill[1] = f.Opp.CurrentPet.Info.SkillList, f.Our.CurrentPet.Info.SkillList
|
||||
// f.Our.CurrentPet.Info, f.Opp.CurrentPet.Info = oldpet[0], oldpet[1] //还原精灵信息
|
||||
// f.Opp.CurrentPet.Info.Hp, f.Our.CurrentPet.Info.Hp = oldhp[0], oldhp[1]
|
||||
// f.Opp.CurrentPet.Info.SkillList, f.Our.CurrentPet.Info.SkillList = oldskill[0], oldskill[1]
|
||||
|
||||
// fmt.Println("结束时对方最大体力值", f.Opp.CurrentPet.Info.MaxHp)
|
||||
|
||||
// }()
|
||||
f.Our.Exec(func(t input.Effect) bool { //回合开始前
|
||||
|
||||
//结算状态
|
||||
t.Turn_Start(fattack, sattack)
|
||||
return true
|
||||
//结算状态
|
||||
t.Turn_Start(fattack, sattack)
|
||||
return true
|
||||
})
|
||||
})
|
||||
f.Opp.Exec(func(t input.Effect) bool { //回合开始前
|
||||
|
||||
//结算状态
|
||||
t.Turn_Start(fattack, sattack)
|
||||
return true
|
||||
})
|
||||
// 伤害值
|
||||
|
||||
if fattack != nil { //如果首技能是空的,说明都空过了
|
||||
|
||||
@@ -173,35 +144,26 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
|
||||
f.Our.Parseskill(sattack)
|
||||
}
|
||||
}
|
||||
f.Broadcast(func(ff *input.Input) {
|
||||
ff.Exec(func(t input.Effect) bool { //回合开始前
|
||||
|
||||
f.Our.Exec(func(t input.Effect) bool { //回合开始前
|
||||
//结算状态
|
||||
t.Compare_Pre(fattack, sattack) //先结算技能的优先级
|
||||
return true
|
||||
})
|
||||
|
||||
//结算状态
|
||||
t.Compare_Pre(fattack, sattack) //先结算技能的优先级
|
||||
return true
|
||||
ff.ResetAttackValue()
|
||||
})
|
||||
f.Opp.Exec(func(t input.Effect) bool { //回合开始前
|
||||
|
||||
//结算状态
|
||||
t.Compare_Pre(fattack, sattack) //先结算技能的优先级
|
||||
return true
|
||||
})
|
||||
|
||||
f.First, f.Second = f.Our, f.Opp
|
||||
// 根据攻击方归属设置当前战斗的主/次攻击方属性
|
||||
if fattack != nil {
|
||||
if fattack.GetPlayerID() == f.ownerID {
|
||||
f.First, f.Second = f.Our, f.Opp // 攻击方为我方时,主攻击方是我方
|
||||
if fattack.GetPlayerID() != f.ownerID {
|
||||
|
||||
} else {
|
||||
f.First, f.Second = f.Opp, f.Our // 攻击方为对方时,主攻击方是对方
|
||||
|
||||
}
|
||||
} else {
|
||||
f.First, f.Second = f.Our, f.Opp
|
||||
}
|
||||
|
||||
f.First.ResetAttackValue()
|
||||
f.Second.ResetAttackValue()
|
||||
if fattack != nil && sattack != nil {
|
||||
switch {
|
||||
|
||||
@@ -235,7 +197,13 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
|
||||
}
|
||||
|
||||
currentskill = oldskill
|
||||
defender.Exec(func(t input.Effect) bool { //这个是能否使用技能
|
||||
//结算状态
|
||||
//然后这里还可以处理自爆类
|
||||
t.Ctx().SkillEntity = currentskill
|
||||
return t.Skill_Hit_Pre_ex(fattack, sattack) //返回本身结算,如果false,说明不能使用技能了
|
||||
|
||||
})
|
||||
canuseskill := attacker.Exec(func(t input.Effect) bool { //这个是能否使用技能
|
||||
//结算状态
|
||||
//然后这里还可以处理自爆类
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"blazing/logic/service/fight/action"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/blazing/model"
|
||||
"math/rand"
|
||||
"sync"
|
||||
@@ -16,12 +17,13 @@ import (
|
||||
)
|
||||
|
||||
type FightC struct {
|
||||
Info info.NoteReadyToFightInfo
|
||||
IsReady bool
|
||||
ownerID uint32 // 战斗发起者ID
|
||||
Our *input.Input //始终等于房主ID
|
||||
Opp *input.Input //对手ID
|
||||
Switch []*action.ActiveSwitchAction
|
||||
ReadyInfo info.NoteReadyToFightInfo
|
||||
Info info.PVPinfo
|
||||
IsReady bool
|
||||
ownerID uint32 // 战斗发起者ID
|
||||
Our *input.Input //始终等于房主ID
|
||||
Opp *input.Input //对手ID
|
||||
Switch []*action.ActiveSwitchAction
|
||||
|
||||
rand *rand.Rand
|
||||
StartTime time.Time
|
||||
@@ -180,7 +182,7 @@ func initfightready(in *input.Input) (info.FightUserInfo, []info.ReadyFightPetIn
|
||||
}
|
||||
|
||||
// 创建新战斗,邀请方和被邀请方,或者玩家和野怪方
|
||||
func NewFight(mode, status info.EnumBattleMode, p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) *FightC {
|
||||
func NewFight(p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) *FightC {
|
||||
f := &FightC{}
|
||||
f.ownerID = p1.GetInfo().UserID
|
||||
f.callback = fn
|
||||
@@ -189,17 +191,17 @@ func NewFight(mode, status info.EnumBattleMode, p1, p2 common.PlayerI, fn func(*
|
||||
f.StartTime = time.Now()
|
||||
seed := f.StartTime.UnixNano() ^ int64(p1.GetInfo().UserID) ^ int64(p2.GetInfo().UserID) // ^ int64(f.Round) // 用异或运算混合多维度信息
|
||||
f.rand = rand.New(rand.NewSource(seed))
|
||||
f.Info = info.NoteReadyToFightInfo{
|
||||
Status: status,
|
||||
Mode: mode,
|
||||
}
|
||||
f.Info = p1.Getfightinfo()
|
||||
p1.(*player.Player).PVPinfo = nil //清空战斗消息
|
||||
|
||||
f.ReadyInfo.Mode = f.Info.Mode
|
||||
|
||||
f.Our, f.Opp = f.initplayer(p1), f.initplayer(p2)
|
||||
|
||||
f.Info.OurInfo, f.Info.OurPetList = initfightready(f.Our)
|
||||
f.Info.OpponentInfo, f.Info.OpponentPetList = initfightready(f.Opp)
|
||||
f.ReadyInfo.OurInfo, f.ReadyInfo.OurPetList = initfightready(f.Our)
|
||||
f.ReadyInfo.OpponentInfo, f.ReadyInfo.OpponentPetList = initfightready(f.Opp)
|
||||
|
||||
switch f.Info.Status {
|
||||
switch f.Info.Mode {
|
||||
case info.BattleStatus.FIGHT_WITH_PLAYER:
|
||||
|
||||
default:
|
||||
@@ -211,7 +213,7 @@ func NewFight(mode, status info.EnumBattleMode, p1, p2 common.PlayerI, fn func(*
|
||||
|
||||
f.Broadcast(func(ff *input.Input) {
|
||||
|
||||
ff.Player.SendNoteReadyToFightInfo(f.Info)
|
||||
ff.Player.SendNoteReadyToFightInfo(f.ReadyInfo)
|
||||
|
||||
})
|
||||
// 60秒后判断战斗是否开始
|
||||
|
||||
@@ -11,7 +11,7 @@ type Effect interface {
|
||||
Compare_Pre(fattack, sattack *action.SelectSkillAction) bool //比较前对优先级的修改
|
||||
//技能命中前的返回值代表是否可以出手 ,对命中本身的修改应该是对上下文本身的修改
|
||||
//对技能修改 行动开始前,注入视为等参数在这里实现
|
||||
|
||||
Skill_Hit_Pre_ex(fattack, sattack *action.SelectSkillAction) bool //比较前对优先级的修改
|
||||
Skill_Hit_Pre(fattack, sattack *action.SelectSkillAction) bool //比较前对优先级的修改
|
||||
Skill_Hit() bool //这是是命中后的对技能的修改,比如变威力
|
||||
Skill_Hit_ex() bool // 技能命中前触发//预处理受击技能 被攻击方效果,比如受击时无效技能这样
|
||||
|
||||
@@ -220,7 +220,7 @@ func (f *FightC) handleItemAction(a *action.UseItemAction) {
|
||||
ok, res := f.Our.Capture(f.Opp.CurrentPet, a.ItemID, -1)
|
||||
if ok {
|
||||
fmt.Println(res)
|
||||
our.Service.PetAdd(f.Opp.CurrentPet.Info)
|
||||
our.Service.Pet.PetAdd(f.Opp.CurrentPet.Info)
|
||||
our.CatchPetInfo(info.CatchMonsterOutboundInfo{
|
||||
CatchTime: uint32(f.Opp.CurrentPet.Info.CatchTime),
|
||||
PetId: uint32(f.Opp.CurrentPet.ID),
|
||||
|
||||
@@ -7,7 +7,9 @@ import (
|
||||
func (e *EffectNode) Skill_Hit_Pre(fattack, sattack *action.SelectSkillAction) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (e *EffectNode) Skill_Hit_Pre_ex(fattack, sattack *action.SelectSkillAction) bool {
|
||||
return true
|
||||
}
|
||||
func (e *EffectNode) Compare_Pre(fattack, sattack *action.SelectSkillAction) bool { //比较前对优先级的修改 {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ type AI_player struct {
|
||||
CanCapture bool
|
||||
}
|
||||
|
||||
func (p *AI_player) Getfightinfo() info.PVPinfo {
|
||||
return info.PVPinfo{}
|
||||
}
|
||||
func (f *AI_player) SendPack(b []byte) error {
|
||||
return nil
|
||||
|
||||
|
||||
69
logic/service/player/done.go
Normal file
69
logic/service/player/done.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package player
|
||||
|
||||
import (
|
||||
"github.com/badu/bus"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
type Done struct {
|
||||
*Player //对玩家进行操作
|
||||
*bus.Topic[*model.MilestoneData]
|
||||
}
|
||||
|
||||
// 注册地图BOSS完成事件
|
||||
// MAPID 地图ID
|
||||
// BOSSID 地图BOSSID
|
||||
// 注册胜利次数
|
||||
//
|
||||
func (d *Done) SPT(mapid, bossid, count uint32, fn func()) {
|
||||
d.Topic.Sub(func(v *model.MilestoneData) {
|
||||
|
||||
if v.DoneType == model.MilestoneMode.BOSS && EqualBasicSlice(v.IDs, []uint32{mapid, bossid}) && v.Count == count {
|
||||
|
||||
_, ok := lo.Find(v.IDs, func(v1 uint32) bool { //寻找是否触发过
|
||||
|
||||
return v1 == count
|
||||
})
|
||||
if !ok { //说明没有触发过
|
||||
v.IDs = append(v.IDs, count) //把本次的记录添加
|
||||
fn()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// 分发事件 ,指定事件+1 并触发是否完成
|
||||
func (d *Done) Pub(Donetype model.EnumMilestone, id []uint32) {
|
||||
|
||||
t := d.Service.Done.Get(Donetype, id)
|
||||
s := model.MilestoneData{
|
||||
|
||||
DoneType: Donetype,
|
||||
IDs: id,
|
||||
Args: t.Args,
|
||||
Count: t.Count + 1,
|
||||
}
|
||||
d.Topic.Pub(&s) //异步发送,然后给事件+1
|
||||
// d.Topic.PubAsyncCallBack(s, func() { //如果没执行完,说明奖励没发完,直接掉线
|
||||
// d.Service.Done.Exec(s) //给计数器加1
|
||||
// }) //提交触发里程碑奖励
|
||||
d.Service.Done.Exec(s) //给计数器加1
|
||||
}
|
||||
|
||||
// 方法1:手动遍历(性能最优)
|
||||
func EqualBasicSlice[T int | string | bool | uint32](a, b []T) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i := range a {
|
||||
if a[i] != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func (p *Player) Pet_joinFight() *Player {
|
||||
|
||||
if *value.PVPinfo == *p.PVPinfo {
|
||||
p.PVPinfo = nil //先将自身的准备信息置空
|
||||
value.PVPinfo = nil
|
||||
//value.PVPinfo = nil
|
||||
lw = value
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ type Player struct {
|
||||
MainConn gnet.Conn
|
||||
baseplayer
|
||||
IsLogin bool //是否登录
|
||||
Done
|
||||
|
||||
StopChan timer.TimeNoder
|
||||
|
||||
@@ -83,6 +84,10 @@ func (p *Player) UseCoins(t uint32) bool {
|
||||
func (p *Player) GetAction() {
|
||||
|
||||
}
|
||||
func (p *Player) Getfightinfo() info.PVPinfo {
|
||||
return *p.PVPinfo
|
||||
}
|
||||
|
||||
func (p *Player) GetSpace() *space.Space {
|
||||
return space.GetSpace(p.Info.MapID)
|
||||
}
|
||||
@@ -256,7 +261,7 @@ func (p *Player) ItemAdd(t ...model.SingleItemInfo) (result []model.SingleItemIn
|
||||
itemx.Max = 1
|
||||
}
|
||||
|
||||
if p.Service.CheakItem(v.ItemId)+v.ItemCnt > uint32(itemx.Max) {
|
||||
if p.Service.Item.CheakItem(v.ItemId)+v.ItemCnt > uint32(itemx.Max) {
|
||||
cool.Loger.Error(context.TODO(), "物品超过拥有最大限制", v.ItemId)
|
||||
t1 := NewTomeeHeader(2601, p.Info.UserID)
|
||||
t1.Result = uint32(errorcode.ErrorCodes.ErrTooManyOfItem)
|
||||
@@ -264,7 +269,7 @@ func (p *Player) ItemAdd(t ...model.SingleItemInfo) (result []model.SingleItemIn
|
||||
p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样
|
||||
continue
|
||||
}
|
||||
p.Service.AddItem(v.ItemId, v.ItemCnt)
|
||||
p.Service.Item.AddItem(v.ItemId, v.ItemCnt)
|
||||
result = append(result, v)
|
||||
|
||||
}
|
||||
|
||||
@@ -44,9 +44,9 @@ func (p *Player) Save() {
|
||||
newtime := uint32(time.Now().Unix())
|
||||
p.Info.TimeToday = p.Info.TimeToday + newtime - uint32(p.Logintime) //保存电池时间
|
||||
|
||||
p.Info.OnlineTime = (newtime - uint32(p.Logintime)) / 60 //每次退出时候保存已经在线的分钟数
|
||||
p.Info.OnlineTime = p.Info.OnlineTime + (newtime-uint32(p.Logintime))/60 //每次退出时候保存已经在线的分钟数
|
||||
|
||||
p.Service.Save(p.Info)
|
||||
p.Service.Info.Save(p.Info)
|
||||
space.GetSpace(p.Info.MapID).LeaveMap(p)
|
||||
|
||||
p.StopChan.Stop() //停止刷怪
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package space
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
|
||||
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
||||
"golang.org/x/sync/singleflight"
|
||||
)
|
||||
@@ -30,9 +32,10 @@ var maphot = csmap.New[uint32, *int32](
|
||||
func GetMapHot() []MapHotInfo {
|
||||
ret := make([]MapHotInfo, 0)
|
||||
maphot.Range(func(key uint32, value *int32) (stop bool) {
|
||||
|
||||
ret = append(ret, MapHotInfo{
|
||||
MapID: key,
|
||||
Count: *value,
|
||||
Count: atomic.LoadInt32(value),
|
||||
})
|
||||
|
||||
return true
|
||||
|
||||
@@ -85,6 +85,7 @@ func (s *Space) UP_ARENA(c common.PlayerI, FLAG uint32) {
|
||||
|
||||
// NewSyncMap 创建一个新的玩家同步map
|
||||
func NewSpace() *Space {
|
||||
|
||||
return &Space{
|
||||
User: csmap.New[uint32, common.PlayerI](
|
||||
// set the number of map shards. the default value is 32.
|
||||
|
||||
@@ -2,8 +2,6 @@ package task
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/badu/bus"
|
||||
)
|
||||
|
||||
// RegisterTask 注册任务奖励
|
||||
@@ -263,7 +261,7 @@ func init() {
|
||||
}
|
||||
|
||||
// 任务触发里程碑
|
||||
var Tasktopic = bus.NewTopic[CompleteTaskInboundInfo]() //直接注册到用户
|
||||
|
||||
// func Test_event(b *testing.T) {
|
||||
|
||||
// topic := bus.NewTopic[*Task]() //直接注册到用户
|
||||
|
||||
@@ -8,11 +8,18 @@ type TaskResult struct {
|
||||
|
||||
var TaskResultMap = make(map[uint32]map[uint32]TaskResult)
|
||||
|
||||
// 添加默认分支0
|
||||
func Get_Task_Info(v CompleteTaskInboundInfo) *TaskResult {
|
||||
|
||||
t, ok := TaskResultMap[v.TaskId][v.OutState]
|
||||
if ok {
|
||||
|
||||
return &t
|
||||
} else {
|
||||
t, ok := TaskResultMap[v.TaskId][0]
|
||||
if ok {
|
||||
return &t
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ github.com/go-resty/resty/v2 v2.6.0/go.mod h1:PwvJS6hvaPkjtjNg9ph+VrSD92bi5Zq73w
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.3 h1:tbN3rYVSi5MfCS5qAaZ1Xg3fSsyHeT++tJZqEiH1s4c=
|
||||
github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.3/go.mod h1:2+evGu1xAlamaYuDdSqa7QCiwPTm1RrGsUFSMc8PyLc=
|
||||
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
|
||||
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
|
||||
@@ -62,7 +62,7 @@ func (c *BaseSysUserController) GetSession(ctx context.Context, req *SessionReq)
|
||||
|
||||
res.Session = retsid
|
||||
|
||||
if !blazing_service.NewUserService(uint32(t1.ID)).IsReg() {
|
||||
if !blazing_service.NewUserService(uint32(t1.ID)).Info.IsReg() {
|
||||
res.UserID = int(t1.ID)
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ module blazing/modules/base
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.3
|
||||
github.com/gogf/gf/v2 v2.7.0
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0
|
||||
)
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
|
||||
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
|
||||
@@ -28,7 +28,7 @@ func init() {
|
||||
&cool.Controller{
|
||||
Prefix: "/admin/monster/bag",
|
||||
Api: []string{"Delete", "Update", "Info", "List", "Page"},
|
||||
Service: service.NewPetService(),
|
||||
Service: service.NewPetService(0), //因为page已经过滤,所以这里需要改成0
|
||||
},
|
||||
}
|
||||
// 注册路由
|
||||
@@ -43,7 +43,7 @@ func (c *PetBagController) GetSession(ctx context.Context, req *PetGetReq) (res
|
||||
t := model.GenPetInfo(
|
||||
req.PetTypeId, req.IndividualValue, req.NatureId, req.AbilityTypeEnum, req.IsShiny, req.Level)
|
||||
|
||||
service.NewUserService(uint32(admin.UserId)).PetAdd(*t)
|
||||
service.NewUserService(uint32(admin.UserId)).Pet.PetAdd(*t)
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@ module blazing/modules/blazing
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/gogf/gf/v2 v2.6.3
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.0
|
||||
github.com/tnnmigga/enum v1.0.2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/dlclark/regexp2 v1.11.4 // indirect
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
||||
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
|
||||
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
|
||||
github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/creasty/defaults v1.8.0 h1:z27FJxCAa0JKt3utc0sCImAEb+spPucmKoOdLHvHYKk=
|
||||
github.com/creasty/defaults v1.8.0/go.mod h1:iGzKe6pbEHnpMPtfDXZEr0NVxWnPTjb1bbDy08fPzYM=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
|
||||
github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/dop251/goja v0.0.0-20251008123653-cf18d89f3cf6 h1:6dE1TmjqkY6tehR4A67gDNhvDtuZ54ocu7ab4K9o540=
|
||||
@@ -22,8 +22,8 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU=
|
||||
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
|
||||
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
|
||||
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||
github.com/gogf/gf/v2 v2.7.0 h1:CjxhbMiE7oqf6K8ZtGuKt3dQEwK4vL6LhiI+dI7tJGU=
|
||||
github.com/gogf/gf/v2 v2.7.0/go.mod h1:Qu8nimKt9aupJQcdUL85tWF4Mfxocz97zUt8UC4abVI=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U=
|
||||
github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg=
|
||||
@@ -54,7 +54,6 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
@@ -63,6 +62,8 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/tnnmigga/enum v1.0.2 h1:Yvchx0Esc01X5HiphW78sKzH/RXKttdFsfPO1ARiOa4=
|
||||
github.com/tnnmigga/enum v1.0.2/go.mod h1:QaBFBwGJi/2GAM34b2pz6UL2NRtl2TRZ8lXp4vGwqhA=
|
||||
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
|
||||
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
|
||||
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
|
||||
@@ -82,5 +83,6 @@ golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
65
modules/blazing/model/done.go
Normal file
65
modules/blazing/model/done.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
|
||||
"github.com/tnnmigga/enum"
|
||||
)
|
||||
|
||||
type EnumMilestone int
|
||||
|
||||
var MilestoneMode = enum.New[struct {
|
||||
BOSS EnumMilestone //boss类
|
||||
ITEM EnumMilestone //物品类
|
||||
}]()
|
||||
|
||||
// 里程碑数据结构,与DoneEvent对应,记录单条里程碑的详细信息
|
||||
type MilestoneData struct {
|
||||
DoneType EnumMilestone `json:"done_type"` // 里程碑类型(如:0-地图解锁,1-BOSS击杀,2-物品收集等)
|
||||
Args []uint32 `json:"args"` // 关联ID列表(如地图ID、BOSSID、物品ID等)
|
||||
Results []uint32 `json:"results"` // 完成情况参数(如:击杀次数、收集数量阈值等)
|
||||
Count uint32 `json:"count"` // 累计完成次数(如:某BOSS累计击杀3次)
|
||||
//IsCompleted bool `json:"is_completed"` // 是否完全达成(用于区分阶段性里程碑)
|
||||
}
|
||||
|
||||
const TableNameMilestone = "milestone"
|
||||
|
||||
// Milestone 数据库存储结构体,映射milestone表
|
||||
type Milestone struct {
|
||||
*cool.Model
|
||||
PlayerID uint64 `gorm:"not null;index:idx_milestone_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
DoneType uint32 `gorm:"not null;comment:'里程碑类型'" json:"done_type"`
|
||||
Args string `gorm:"type:jsonb;not null;comment:'里程碑ID'" json:"args"`
|
||||
// 注:不单独设置"里程碑ID",通过 PlayerID + DoneType + IDs 组合唯一标识一个里程碑(更灵活)
|
||||
Results string `gorm:"type:jsonb;not null;comment:'里程碑参数'" json:"results"`
|
||||
Count uint32 `gorm:"not null;comment:'里程碑完成次数'" json:"count"`
|
||||
}
|
||||
|
||||
// MilestoneEX 里程碑扩展结构体,用于业务层解析后的数据操作
|
||||
type MilestoneEX struct {
|
||||
Milestone
|
||||
IDs []uint32 `json:"args"` // 解析后的里程碑详细数据
|
||||
Args []uint32 `json:"results"` // 解析后的里程碑详细数据
|
||||
}
|
||||
|
||||
// TableName 返回表名
|
||||
func (*Milestone) TableName() string {
|
||||
return TableNameMilestone
|
||||
}
|
||||
|
||||
// GroupName 返回表组名
|
||||
func (*Milestone) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewMilestone 创建新里程碑实例
|
||||
func NewMilestone() *Milestone {
|
||||
return &Milestone{
|
||||
Model: cool.NewModel(),
|
||||
}
|
||||
}
|
||||
|
||||
// init 初始化表
|
||||
func init() {
|
||||
cool.CreateTable(&Milestone{})
|
||||
}
|
||||
43
modules/blazing/service/done.go
Normal file
43
modules/blazing/service/done.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
type DoneService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
func (s *DoneService) Get(data model.EnumMilestone, id []uint32) model.MilestoneEX {
|
||||
|
||||
m := s.GModel(s.Model).Where("done_type", data).Where("args", id)
|
||||
var tt model.MilestoneEX
|
||||
m.Scan(&tt)
|
||||
return tt
|
||||
|
||||
}
|
||||
func (s *DoneService) Exec(data model.MilestoneData) {
|
||||
|
||||
m := s.GModel(s.Model).Where("done_type", data.DoneType).Where("args", data.Args)
|
||||
var tt model.MilestoneEX
|
||||
m.Scan(&tt)
|
||||
tt.Args = data.Args
|
||||
_, err := m.Save(tt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
func NewDoneService(id uint32) *DoneService {
|
||||
return &DoneService{
|
||||
|
||||
BaseService: BaseService{userid: id,
|
||||
|
||||
Service: &cool.Service{Model: model.NewMilestone(), UniqueKey: map[string]string{
|
||||
"player_id": "角色名称不能重复",
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
)
|
||||
|
||||
// 是否注册,如果注册过,那么就会产生用户player信息
|
||||
func (s *UserService) IsReg() bool {
|
||||
func (s *InfoService) IsReg() bool {
|
||||
|
||||
m := s.Model(s.info.Model)
|
||||
m := s.GModel(s.Model)
|
||||
|
||||
record, err := m.One()
|
||||
if err != nil {
|
||||
@@ -25,7 +25,7 @@ func (s *UserService) IsReg() bool {
|
||||
}
|
||||
|
||||
// 实现注册,id+昵称+颜色
|
||||
func (s *UserService) Reg(nick string, color uint32) {
|
||||
func (s *InfoService) Reg(nick string, color uint32) {
|
||||
if s.IsReg() {
|
||||
return
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func (s *UserService) Reg(nick string, color uint32) {
|
||||
t.Data.Color = color
|
||||
t.Data.RegisterTime = uint32(time.Now().Unix()) //写入注册时间
|
||||
|
||||
_, err := cool.DBM(s.info.Model).Data(t).FieldsEx("id").Insert()
|
||||
_, err := cool.DBM(s.Model).Data(t).FieldsEx("id").Insert()
|
||||
if err != nil {
|
||||
glog.Error(context.Background(), err)
|
||||
return
|
||||
@@ -52,9 +52,9 @@ func (s *UserService) Reg(nick string, color uint32) {
|
||||
//go s.InitTask()
|
||||
}
|
||||
|
||||
func (s *UserService) Person(userid uint32) *model.PlayerInfo {
|
||||
func (s *InfoService) Person(userid uint32) *model.PlayerInfo {
|
||||
|
||||
m := cool.DBM(s.info.Model).Where("player_id", userid)
|
||||
m := cool.GDBM(s.Model).Where("player_id", userid)
|
||||
var tt model.PlayerEX
|
||||
err := m.Scan(&tt)
|
||||
if err != nil {
|
||||
@@ -64,9 +64,9 @@ func (s *UserService) Person(userid uint32) *model.PlayerInfo {
|
||||
return &ret
|
||||
|
||||
}
|
||||
func (s *UserService) Save(data *model.PlayerInfo) {
|
||||
func (s *InfoService) Save(data *model.PlayerInfo) {
|
||||
|
||||
m := s.Model(s.info.Model)
|
||||
m := s.GModel(s.Model)
|
||||
var tt model.PlayerEX
|
||||
m.Scan(&tt)
|
||||
tt.Data = *data
|
||||
@@ -76,3 +76,20 @@ func (s *UserService) Save(data *model.PlayerInfo) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type InfoService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
func NewInfoService(id uint32) *InfoService {
|
||||
return &InfoService{
|
||||
|
||||
BaseService: BaseService{userid: id,
|
||||
|
||||
Service: &cool.Service{Model: model.NewPlayer(), UniqueKey: map[string]string{
|
||||
"player_id": "角色名称不能重复",
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (s *UserService) Item(min, max uint32) []model.Item {
|
||||
func (s *ItemService) Get(min, max uint32) []model.Item {
|
||||
|
||||
//todo待测试
|
||||
var ttt []model.Item
|
||||
s.Model(s.item.Model).Where(g.Map{
|
||||
s.GModel(s.Model).Where(g.Map{
|
||||
"item_id <=": max,
|
||||
"item_id >=": min,
|
||||
}).Scan(&ttt)
|
||||
@@ -18,11 +19,11 @@ func (s *UserService) Item(min, max uint32) []model.Item {
|
||||
return ttt
|
||||
|
||||
}
|
||||
func (s *UserService) AddItem(id, count uint32) {
|
||||
if t, _ := s.Model(s.item.Model).Where("item_id", id).Count(); t != 0 {
|
||||
s.Model(s.item.Model).Where("item_id", id).Increment("item_cnt", count)
|
||||
func (s *ItemService) AddItem(id, count uint32) {
|
||||
if t, _ := s.GModel(s.Model).Where("item_id", id).Count(); t != 0 {
|
||||
s.GModel(s.Model).Where("item_id", id).Increment("item_cnt", count)
|
||||
} else {
|
||||
s.Model(s.item.Model).Data(g.Map{
|
||||
s.GModel(s.Model).Data(g.Map{
|
||||
"player_id": s.userid,
|
||||
"item_id": id,
|
||||
"item_cnt": count,
|
||||
@@ -30,15 +31,31 @@ func (s *UserService) AddItem(id, count uint32) {
|
||||
}
|
||||
|
||||
}
|
||||
func (s *UserService) SubItem(id, count uint32) {
|
||||
func (s *ItemService) SubItem(id, count uint32) {
|
||||
|
||||
s.Model(s.item.Model).Where("item_id", id).Decrement("item_cnt", count)
|
||||
s.GModel(s.Model).Where("item_id", id).Decrement("item_cnt", count)
|
||||
|
||||
}
|
||||
func (s *UserService) CheakItem(id uint32) uint32 {
|
||||
func (s *ItemService) CheakItem(id uint32) uint32 {
|
||||
var ttt model.Item
|
||||
s.Model(s.item.Model).Where("item_id", id).Scan(&ttt)
|
||||
s.GModel(s.Model).Where("item_id", id).Scan(&ttt)
|
||||
return ttt.ItemCnt
|
||||
}
|
||||
|
||||
// /添加进来的物品一定是保证存在的
|
||||
type ItemService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
func NewItemService(id uint32) *ItemService {
|
||||
return &ItemService{
|
||||
|
||||
BaseService: BaseService{userid: id,
|
||||
|
||||
Service: &cool.Service{Model: model.NewPlayerBag(), UniqueKey: map[string]string{
|
||||
"player_id": "角色名称不能重复",
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -26,52 +25,69 @@ func NewLoginServiceService() *LoginService {
|
||||
}
|
||||
|
||||
// 生成session
|
||||
// GetSessionId 生成并返回会话ID、UUID字符串及可能的错误
|
||||
// 会话ID由accountID(4字节) + UUID(16字节) + 随机数(4字节)组成,最终编码为十六进制字符串
|
||||
func (s *LoginService) GetSessionId(accountID uint) (string, string, error) {
|
||||
|
||||
t1, _ := uuid.NewV7()
|
||||
tt := strings.Replace(t1.String(), "-", "", -1)
|
||||
|
||||
rand.NewSource(time.Now().UnixNano())
|
||||
|
||||
// 生成4个随机字节
|
||||
bytes := make([]byte, 4)
|
||||
for i := range bytes {
|
||||
bytes[i] = byte(rand.Intn(256)) // 生成0-255之间的随机数
|
||||
// 生成UUID v7,带错误处理(UUID生成失败时返回错误)
|
||||
uuidV7, err := uuid.NewV7()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
buf2 := make([]byte, 4) // 创建4字节的缓冲区
|
||||
binary.BigEndian.PutUint32(buf2, uint32(accountID))
|
||||
// 移除UUID中的连字符,便于后续处理
|
||||
uuidStr := strings.ReplaceAll(uuidV7.String(), "-", "")
|
||||
|
||||
//fmt.Printf("小端序: %v (十六进制: %x)\n", buf2, buf2) // 输出: [252 255 255 255] (0xFCFFFFFF)
|
||||
ttid, _ := hex.DecodeString(tt)
|
||||
//fmt.Println(bytes, "随机字节")
|
||||
ret := append(buf2, ttid...)
|
||||
ret = append(ret, bytes...)
|
||||
// 解码UUID字符串为字节数组(32位十六进制字符串对应16字节)
|
||||
uuidBytes, err := hex.DecodeString(uuidStr)
|
||||
if err != nil {
|
||||
// 理论上UUID生成的字符串不会出现解码错误,此处为防御性处理
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
return hex.EncodeToString(ret), tt, nil
|
||||
// /t1.
|
||||
// 以上过程只需全局一次,且应在生成ID之前完成。
|
||||
// 生成4字节安全随机数(使用crypto/rand提高随机性,适合会话ID场景)
|
||||
randomBytes := make([]byte, 4)
|
||||
if _, err := rand.Read(randomBytes); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
// 将accountID转换为4字节大端序字节数组
|
||||
accountBytes := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(accountBytes, uint32(accountID))
|
||||
|
||||
// 预分配缓冲区(总长度:4+16+4=24字节),减少内存分配
|
||||
sessionBytes := make([]byte, 0, 24)
|
||||
sessionBytes = append(sessionBytes, accountBytes...)
|
||||
sessionBytes = append(sessionBytes, uuidBytes...)
|
||||
sessionBytes = append(sessionBytes, randomBytes...)
|
||||
|
||||
// 编码为十六进制字符串作为最终会话ID
|
||||
sessionID := hex.EncodeToString(sessionBytes)
|
||||
|
||||
return sessionID, uuidStr, nil
|
||||
}
|
||||
func (s *LoginService) SetServerID(OnlineID uint16, Port uint16) error {
|
||||
|
||||
m := cool.DBM(s.Model).Where("online_id", OnlineID)
|
||||
|
||||
record, err := m.One()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if record == nil {
|
||||
//说明是新的服务器
|
||||
// record, err := m.One()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if record == nil {
|
||||
// //说明是新的服务器
|
||||
|
||||
_, err := m.InsertAndGetId(&model.ServerList{OnlineID: OnlineID, Port: Port})
|
||||
// _, err := m.InsertAndGetId(&model.ServerList{OnlineID: OnlineID, Port: Port})
|
||||
|
||||
return err
|
||||
}
|
||||
// return err
|
||||
// }
|
||||
var tttt model.ServerList
|
||||
record.Struct(&tttt)
|
||||
//t.Quit(int32(tttt.Port))
|
||||
m.Data(&model.ServerList{OnlineID: OnlineID, Port: Port}).Where("online_id", OnlineID).Update()
|
||||
m.Scan(&tttt)
|
||||
tttt.Port = Port
|
||||
tttt.OnlineID = OnlineID
|
||||
|
||||
//t.Quit(int32(tttt.Port))
|
||||
//m.Data(&model.ServerList{OnlineID: OnlineID, Port: Port}).Where("online_id", OnlineID).Update()
|
||||
m.Save(tttt)
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
)
|
||||
|
||||
// 获取精灵信息 0是仓库,1是放生
|
||||
func (s *UserService) PetInfo(flag int) []model.PetEX {
|
||||
func (s *PetService) PetInfo(flag int) []model.PetEX {
|
||||
var tt []model.PetEX
|
||||
err := cool.DBM(s.pet.Model).Where("player_id", s.userid).Where("free", flag).Scan(&tt)
|
||||
err := cool.DBM(s.Model).Where("player_id", s.userid).Where("free", flag).Scan(&tt)
|
||||
if err != nil {
|
||||
return []model.PetEX{}
|
||||
}
|
||||
@@ -26,9 +26,9 @@ func (s *UserService) PetInfo(flag int) []model.PetEX {
|
||||
|
||||
}
|
||||
|
||||
func (s *UserService) PetInfo_One_exec(cachetime uint32, t func(*model.PetEX)) {
|
||||
func (s *PetService) PetInfo_One_exec(cachetime uint32, t func(*model.PetEX)) {
|
||||
|
||||
m := cool.DBM(s.pet.Model).Where("player_id", s.userid).Where("catch_time", cachetime)
|
||||
m := cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime)
|
||||
var tt model.PetEX
|
||||
m.Scan(&tt)
|
||||
if tt.CatchTime == 0 {
|
||||
@@ -38,19 +38,19 @@ func (s *UserService) PetInfo_One_exec(cachetime uint32, t func(*model.PetEX)) {
|
||||
t(&tt)
|
||||
m.Update(tt)
|
||||
}
|
||||
func (s *UserService) PetInfo_One(cachetime uint32) model.PetEX {
|
||||
func (s *PetService) PetInfo_One(cachetime uint32) model.PetEX {
|
||||
|
||||
m := cool.DBM(s.pet.Model).Where("player_id", s.userid).Where("catch_time", cachetime)
|
||||
m := cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime)
|
||||
var tt model.PetEX
|
||||
|
||||
m.Scan(&tt)
|
||||
tt.Data.CatchTime = tt.CatchTime
|
||||
return tt
|
||||
}
|
||||
func (s *UserService) PetAdd(y model.PetInfo) {
|
||||
func (s *PetService) PetAdd(y model.PetInfo) {
|
||||
|
||||
for {
|
||||
m1 := cool.DBM(s.pet.Model).Where("player_id", s.userid)
|
||||
m1 := cool.DBM(s.Model).Where("player_id", s.userid)
|
||||
var player model.PetEX
|
||||
player.PlayerID = s.userid
|
||||
player.Data = y
|
||||
@@ -67,9 +67,10 @@ func (s *UserService) PetAdd(y model.PetInfo) {
|
||||
|
||||
}
|
||||
func (s *PetService) ModifyBefore(ctx context.Context, method string, param map[string]interface{}) (err error) {
|
||||
admin := cool.GetAdmin(ctx)
|
||||
userId := admin.UserId
|
||||
s.userid = uint32(userId)
|
||||
if method == "Update" {
|
||||
admin := cool.GetAdmin(ctx)
|
||||
userId := admin.UserId
|
||||
|
||||
if gconv.Uint(param["free"]) != 0 {
|
||||
err = fmt.Errorf("修改失败")
|
||||
@@ -84,23 +85,26 @@ func (s *PetService) ModifyBefore(ctx context.Context, method string, param map[
|
||||
}
|
||||
|
||||
type PetService struct {
|
||||
*cool.Service
|
||||
BaseService
|
||||
}
|
||||
|
||||
func NewPetService() *PetService {
|
||||
func NewPetService(userid uint32) *PetService {
|
||||
return &PetService{
|
||||
&cool.Service{
|
||||
Model: model.NewPet(),
|
||||
PageQueryOp: &cool.QueryOp{
|
||||
Where: func(ctx context.Context) [][]interface{} {
|
||||
var (
|
||||
admin = cool.GetAdmin(ctx)
|
||||
userId = admin.UserId
|
||||
)
|
||||
return [][]interface{}{
|
||||
{"player_id", userId, true},
|
||||
{"free", 0, true},
|
||||
}
|
||||
BaseService: BaseService{
|
||||
userid: userid,
|
||||
Service: &cool.Service{
|
||||
Model: model.NewPet(),
|
||||
PageQueryOp: &cool.QueryOp{
|
||||
Where: func(ctx context.Context) [][]interface{} {
|
||||
var (
|
||||
admin = cool.GetAdmin(ctx)
|
||||
userId = admin.UserId
|
||||
)
|
||||
return [][]interface{}{
|
||||
{"player_id", userId, true},
|
||||
{"free", 0, true},
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
type TalkService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
func NewTalkService(id uint32) *TalkService {
|
||||
return &TalkService{
|
||||
|
||||
BaseService: BaseService{userid: id,
|
||||
|
||||
Service: &cool.Service{Model: model.NewTalk()},
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TalkCheck 获取玩家当前的Talk数据
|
||||
// todo 待实现xml解析判断是否溢出
|
||||
func (s *UserService) Talk(t func(map[uint32]uint32) bool) {
|
||||
func (s *TalkService) Exec(t func(map[uint32]uint32) bool) {
|
||||
|
||||
m1 := s.Model(s.talk.Model)
|
||||
m1 := s.GModel(s.Model)
|
||||
|
||||
var talks model.TalkEX
|
||||
m1.Scan(&talks)
|
||||
@@ -19,9 +35,9 @@ func (s *UserService) Talk(t func(map[uint32]uint32) bool) {
|
||||
}
|
||||
|
||||
}
|
||||
func (s *UserService) Talk_Reset() {
|
||||
func (s *TalkService) Talk_Reset() {
|
||||
|
||||
m1 := s.Model(s.talk.Model)
|
||||
m1 := s.GModel(s.Model)
|
||||
|
||||
var talks model.TalkEX
|
||||
m1.Scan(&talks)
|
||||
|
||||
@@ -11,7 +11,6 @@ func Exec[T cool.UserModel, F any](userid uint32, s *cool.Service, processFunc f
|
||||
//todo待测试
|
||||
var player T
|
||||
|
||||
|
||||
m1 := cool.DBM(s.Model).Where("player_id", userid)
|
||||
m1.Scan(&player)
|
||||
// 方法2:使用反射获取
|
||||
@@ -37,23 +36,19 @@ func Exec[T cool.UserModel, F any](userid uint32, s *cool.Service, processFunc f
|
||||
}
|
||||
|
||||
// 获取任务信息
|
||||
func (s *UserService) Task(id uint32, t func(*model.TaskEX) bool) {
|
||||
func (s *TaskService) Exec(id uint32, t func(*model.TaskEX) bool) {
|
||||
var gg model.TaskEX
|
||||
m1 := cool.DBM(s.task.Model).
|
||||
m1 := cool.GDBM(s.Model).
|
||||
Where("player_id", s.userid).
|
||||
Where("task_id", id)
|
||||
err := m1.Scan(&gg)
|
||||
m1.Scan(&gg)
|
||||
tre := t(&gg)
|
||||
if !tre { //不需要更新
|
||||
return
|
||||
}
|
||||
gg.PlayerID = uint64(s.userid)
|
||||
gg.TaskID = id
|
||||
if err != nil {
|
||||
m1.Insert(gg)
|
||||
} else {
|
||||
m1.Update(gg)
|
||||
}
|
||||
m1.Save(gg)
|
||||
|
||||
}
|
||||
|
||||
@@ -67,3 +62,18 @@ func IsToday(t time.Time) bool {
|
||||
t.Month() == now.Month() &&
|
||||
t.Day() == now.Day()
|
||||
}
|
||||
|
||||
type TaskService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
func NewTaskService(id uint32) *TaskService {
|
||||
return &TaskService{
|
||||
|
||||
BaseService: BaseService{userid: id,
|
||||
|
||||
Service: &cool.Service{Model: model.NewTask()},
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,45 +2,37 @@ package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
)
|
||||
|
||||
type UserService struct {
|
||||
type BaseService struct {
|
||||
userid uint32
|
||||
//感觉可以给每个server重新继承?
|
||||
talk *cool.Service //挖矿
|
||||
task *cool.Service //任务
|
||||
info *cool.Service //信息
|
||||
pet *PetService //精灵
|
||||
item *cool.Service //物品
|
||||
*cool.Service
|
||||
}
|
||||
type UserService struct {
|
||||
Talk *TalkService //挖矿
|
||||
Task *TaskService //任务
|
||||
Info *InfoService //信息
|
||||
Pet *PetService //精灵
|
||||
Item *ItemService //物品
|
||||
Done *DoneService //完成
|
||||
}
|
||||
|
||||
func NewUserService(id uint32) *UserService {
|
||||
return &UserService{
|
||||
userid: id,
|
||||
task: &cool.Service{
|
||||
Model: model.NewTask(),
|
||||
},
|
||||
info: &cool.Service{
|
||||
Model: model.NewPlayer(),
|
||||
UniqueKey: map[string]string{
|
||||
"player_id": "角色名称不能重复",
|
||||
},
|
||||
},
|
||||
pet: NewPetService(),
|
||||
item: &cool.Service{Model: model.NewPlayerBag(),
|
||||
UniqueKey: map[string]string{
|
||||
"player_id": "角色名称不能重复",
|
||||
}},
|
||||
talk: &cool.Service{Model: model.NewTalk(), UniqueKey: map[string]string{
|
||||
"player_id": "角色名称不能重复",
|
||||
}},
|
||||
|
||||
Task: NewTaskService(id),
|
||||
Info: NewInfoService(id),
|
||||
Pet: NewPetService(id),
|
||||
Item: NewItemService(id),
|
||||
Talk: NewTalkService(id),
|
||||
Done: NewDoneService(id),
|
||||
}
|
||||
|
||||
}
|
||||
func (s *UserService) Model(m cool.IModel) *gdb.Model {
|
||||
|
||||
func (s *BaseService) GModel(m cool.IModel) *gdb.Model {
|
||||
|
||||
return cool.DBM(m).Where("player_id", s.userid)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ module blazing/modules/dict
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/gogf/gf/v2 v2.6.3
|
||||
require github.com/gogf/gf/v2 v2.7.0
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
||||
|
||||
@@ -10,8 +10,7 @@ github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
|
||||
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
||||
|
||||
@@ -2,7 +2,7 @@ module blazing/modules/space
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/gogf/gf/v2 v2.6.3
|
||||
require github.com/gogf/gf/v2 v2.7.0
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
||||
|
||||
@@ -7,8 +7,7 @@ github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
|
||||
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
||||
|
||||
@@ -3,7 +3,7 @@ module blazing/modules/task
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.3
|
||||
github.com/gogf/gf/v2 v2.7.0
|
||||
github.com/robfig/cron v1.2.0
|
||||
)
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@ github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
|
||||
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
|
||||
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
||||
|
||||
Reference in New Issue
Block a user