Merge branch 'main' of github.com:72wo/blazing
This commit is contained in:
@@ -420,8 +420,8 @@ func (s *Service) ModifyAfter(ctx context.Context, method string, param g.MapStr
|
||||
func (s *Service) GetModel() IModel {
|
||||
return s.Model
|
||||
}
|
||||
// GetModel 获取model
|
||||
|
||||
// GetModel 获取model
|
||||
|
||||
// NewService 新建一个service
|
||||
func NewService(model IModel) *Service {
|
||||
|
||||
@@ -45,6 +45,15 @@ type PetInfo struct {
|
||||
LearnableMoves LearnableMoves `xml:"LearnableMoves"` // 可学习的技能
|
||||
}
|
||||
|
||||
|
||||
func (basic *PetInfo) GetBasic() uint32 {
|
||||
return basic.Atk +
|
||||
basic.Def +
|
||||
basic.SpAtk +
|
||||
basic.SpDef +
|
||||
basic.Spd +
|
||||
uint32(basic.HP)
|
||||
}
|
||||
// Monsters 表示所有怪物的集合
|
||||
type Monsters struct {
|
||||
XMLName xml.Name `xml:"Monsters"`
|
||||
|
||||
@@ -155,14 +155,17 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) {
|
||||
conn.Context().(*player.ClientData).IsCrossDomain = true
|
||||
data, err := s.codec.Decode(conn)
|
||||
if err != nil {
|
||||
if err != codec.ErrIncompletePacket {
|
||||
action = gnet.Close
|
||||
return
|
||||
} else {
|
||||
|
||||
if err == codec.ErrIncompletePacket&&conn.InboundBuffered()>0 {
|
||||
t, _ := conn.Peek(conn.InboundBuffered())
|
||||
cool.Loger.Debug(context.Background(), "断包", err.Error(), conn.InboundBuffered(), t)
|
||||
if err := conn.Wake(nil); err != nil { // wake up the connection manually to avoid missing the leftover data
|
||||
logging.Errorf("failed to wake up the connection, %v", err)
|
||||
return gnet.Close
|
||||
}
|
||||
} else {
|
||||
action = gnet.Close
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
1
logic/controller/chat.go
Normal file
1
logic/controller/chat.go
Normal file
@@ -0,0 +1 @@
|
||||
package controller
|
||||
11
logic/service/chat/chat.go
Normal file
11
logic/service/chat/chat.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package chat
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
|
||||
type ChatInboundInfo struct {
|
||||
|
||||
|
||||
Head player.TomeeHeader `cmd:"2102" struc:"[0]pad"`
|
||||
Reserve uint32 `json:"reserve" fieldDescription:"填充 默认值为0" uint:"true"` // @UInt long reserve,无符号长整数
|
||||
Message string `json:"message" fieldDescription:"消息内容, 结束符为utf-8的数字0"` // 消息内容,包含utf-8空字符('\x00')作为结束符
|
||||
}
|
||||
@@ -37,52 +37,35 @@ func calculateExperience(level uint32, baseValue uint32) uint32 {
|
||||
func (p *Player) AddPetExp(petinfo *model.PetInfo, addExp uint32, bro bool) {
|
||||
|
||||
originalLevel := petinfo.Level
|
||||
for {
|
||||
|
||||
petinfo.Exp += addExp
|
||||
p.Info.ExpPool -= addExp //减去已使用的经验
|
||||
for petinfo.Exp >= petinfo.NextLvExp {
|
||||
|
||||
petinfo.Level++
|
||||
if originalLevel < 100 && petinfo.Level == 100 { //升到100了
|
||||
p.Info.ExpPool += (petinfo.Exp) //减去已使用的经验
|
||||
petinfo.Exp = 0
|
||||
break //停止升级
|
||||
}
|
||||
basic := xmlres.PetMAP[int(petinfo.ID)]
|
||||
ba := basic.Atk +
|
||||
basic.Def +
|
||||
basic.SpAtk +
|
||||
basic.SpDef +
|
||||
basic.Spd +
|
||||
uint32(basic.HP)
|
||||
needExp := calculateExperience(petinfo.Level, ba)
|
||||
needExp -= petinfo.Exp
|
||||
if addExp >= needExp {
|
||||
addExp -= needExp
|
||||
p.Info.ExpPool -= needExp //减去已使用的经验
|
||||
petinfo.Level++
|
||||
// 检查是否可以进化
|
||||
if basic.EvolvesTo != 0 && // 有明确的进化
|
||||
int(petinfo.Level) >= basic.EvolvingLv && // 有明确的进化等级
|
||||
basic.IsLarge == 0 { // 非最终形态
|
||||
|
||||
if originalLevel < 100 && petinfo.Level == 100 { //升到100了
|
||||
petinfo.Cure()
|
||||
petinfo.NextLvExp = calculateExperience(petinfo.Level, ba)
|
||||
break //停止升级
|
||||
}
|
||||
petinfo.ID = uint32(basic.EvolvesTo)
|
||||
|
||||
// 检查是否可以进化
|
||||
if basic.EvolvesTo != 0 && // 有明确的进化
|
||||
int(petinfo.Level) >= basic.EvolvingLv && // 有明确的进化等级
|
||||
basic.IsLarge == 0 { // 非最终形态
|
||||
|
||||
petinfo.ID = uint32(basic.EvolvesTo)
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
p.Info.ExpPool -= addExp //减去已使用的经验
|
||||
petinfo.Exp = addExp //零头添到这里
|
||||
petinfo.NextLvExp = calculateExperience(petinfo.Level, ba)
|
||||
break
|
||||
}
|
||||
|
||||
petinfo.Exp -= petinfo.NextLvExp
|
||||
petinfo.LvExp = petinfo.NextLvExp
|
||||
petinfo.NextLvExp = calculateExperience(petinfo.Level, basic.GetBasic())
|
||||
}
|
||||
|
||||
//petinfo.Exp = addExp
|
||||
|
||||
petinfo.LvExp = petinfo.NextLvExp - petinfo.Exp
|
||||
// 处理进化逻辑
|
||||
|
||||
// 重新计算面板
|
||||
if originalLevel != petinfo.Level {
|
||||
petinfo.Cure()
|
||||
petinfo.CalculatePetPane()
|
||||
}
|
||||
if bro {
|
||||
|
||||
@@ -11,8 +11,8 @@ const TableNamePet = "pet"
|
||||
type Pet struct {
|
||||
*cool.Model
|
||||
PlayerID uint32 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
InBag int `gorm:"not null;comment:'是否在背包中'" json:"in_bag"` //"0为放入仓库,1为放入背包
|
||||
CatchTime uint32 `gorm:"not null;comment:'捕捉时间'" json:"catch_time"`
|
||||
InBag int `gorm:"not null;comment:'是否在背包中'" json:"in_bag"` //"0为放入仓库,1为放入背包
|
||||
CatchTime uint32 `gorm:"not null;unique;comment:'捕捉时间'" json:"catch_time"` //唯一键
|
||||
// Owner uint32 `struc:"skip"` //仅作为存储
|
||||
// FreedTime uint32 `struc:"skip"` //放生时间
|
||||
//是否可交易,这里应该定义在精灵ID里
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
// 是否注册,如果注册过,那么就会产生用户player信息
|
||||
func (s *UserService) IsReg() bool {
|
||||
|
||||
m := cool.DBM(s.info.Model).Where("player_id", s.userid)
|
||||
m := s.Model(s.info.Model)
|
||||
|
||||
record, err := m.One()
|
||||
if err != nil {
|
||||
@@ -52,7 +52,7 @@ func (s *UserService) Reg(nick string, color uint32) {
|
||||
|
||||
func (s *UserService) Person(userid uint32) *model.PlayerInfo {
|
||||
|
||||
m := cool.DBM(s.info.Model).Where("player_id", userid)
|
||||
m := s.Model(s.info.Model)
|
||||
var tt model.PlayerEX
|
||||
err := m.Scan(&tt)
|
||||
if err != nil {
|
||||
@@ -64,7 +64,7 @@ func (s *UserService) Person(userid uint32) *model.PlayerInfo {
|
||||
}
|
||||
func (s *UserService) Save(data *model.PlayerInfo) {
|
||||
|
||||
m := cool.DBM(s.info.Model).Where("player_id", data.UserID)
|
||||
m := s.Model(s.info.Model)
|
||||
var tt model.PlayerEX
|
||||
m.Scan(&tt)
|
||||
tt.Data = data
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
@@ -9,7 +8,7 @@ func (s *UserService) Item(t func(map[uint32]model.SingleItemInfo) bool) {
|
||||
|
||||
//todo待测试
|
||||
var player model.ItemEX
|
||||
m1 := cool.DBM(s.item.Model).Where("player_id", s.userid)
|
||||
m1 := s.Model(s.item.Model)
|
||||
|
||||
err := m1.Scan(&player)
|
||||
if err != nil {
|
||||
|
||||
@@ -34,19 +34,30 @@ func (s *UserService) PetInfo_One(cachetime uint32) model.PetEX {
|
||||
}
|
||||
func (s *UserService) PetAdd(y model.PetInfo) {
|
||||
|
||||
m1 := cool.DBM(s.pet.Model).Where("player_id", s.userid)
|
||||
var player model.PetEX
|
||||
player.PlayerID = s.userid
|
||||
player.Data = y
|
||||
player.CatchTime = y.CatchTime
|
||||
player.InBag = 0
|
||||
for {
|
||||
m1 := cool.DBM(s.pet.Model).Where("player_id", s.userid)
|
||||
var player model.PetEX
|
||||
player.PlayerID = s.userid
|
||||
player.Data = y
|
||||
player.CatchTime = y.CatchTime
|
||||
player.InBag = 0
|
||||
|
||||
m1.Insert(player)
|
||||
_, err := m1.Insert(player)
|
||||
if err != nil {
|
||||
y.CatchTime += 1 //自增保持时间排序
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func NewPetService() *MonsterService {
|
||||
return &MonsterService{
|
||||
type PetService struct {
|
||||
*cool.Service
|
||||
}
|
||||
|
||||
func NewPetService() *PetService {
|
||||
return &PetService{
|
||||
&cool.Service{
|
||||
Model: model.NewPet(),
|
||||
PageQueryOp: &cool.QueryOp{
|
||||
|
||||
@@ -11,6 +11,7 @@ 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:使用反射获取
|
||||
|
||||
@@ -10,11 +10,11 @@ import (
|
||||
type UserService struct {
|
||||
userid uint32
|
||||
//感觉可以给每个server重新继承?
|
||||
talk *cool.Service //挖矿
|
||||
task *cool.Service //任务
|
||||
info *cool.Service //信息
|
||||
pet *cool.Service //精灵
|
||||
item *cool.Service //物品
|
||||
talk *cool.Service //挖矿
|
||||
task *cool.Service //任务
|
||||
info *cool.Service //信息
|
||||
pet *PetService //精灵
|
||||
item *cool.Service //物品
|
||||
}
|
||||
|
||||
func NewUserService(id uint32) *UserService {
|
||||
@@ -29,7 +29,7 @@ func NewUserService(id uint32) *UserService {
|
||||
"player_id": "角色名称不能重复",
|
||||
},
|
||||
},
|
||||
pet: &cool.Service{Model: model.NewPet()},
|
||||
pet: NewPetService(),
|
||||
item: &cool.Service{Model: model.NewPlayerBag(),
|
||||
UniqueKey: map[string]string{
|
||||
"player_id": "角色名称不能重复",
|
||||
|
||||
Reference in New Issue
Block a user