修改部分代码
This commit is contained in:
@@ -16,6 +16,16 @@ import (
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
)
|
||||
|
||||
func IsToday(t time.Time) bool {
|
||||
// 获取当前时间
|
||||
now := time.Now()
|
||||
|
||||
// 比较年、月、日是否相同
|
||||
return t.Year() == now.Year() &&
|
||||
t.Month() == now.Month() &&
|
||||
t.Day() == now.Day()
|
||||
}
|
||||
|
||||
// 处理命令: 1001
|
||||
func (h *Controller) Login(data *login.InInfo, c *socket.Conn) (result *login.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
|
||||
@@ -27,7 +37,17 @@ func (h *Controller) Login(data *login.InInfo, c *socket.Conn) (result *login.Ou
|
||||
t.Info.UserID = data.Head.UserID
|
||||
t.Onlinetime = uint32(time.Now().Unix()) //保存时间戳
|
||||
share.ShareManager.SetUserOnline(data.Head.UserID, h.Port) //设置用户登录服务器
|
||||
t.CompleteLogin() //通知客户端登录成功
|
||||
|
||||
if !IsToday(t.Info.LastResetTime) { //判断是否是今天
|
||||
t.Info.LastResetTime = time.Now()
|
||||
//每天login时候检查重置时间,然后把电池,任务,挖矿重置
|
||||
t.Info.TimeToday = 0 //重置电池
|
||||
for i := 400; i < 500; i++ {//每日任务区段
|
||||
t.Info.TaskList[i] = 0 //重置每日任务
|
||||
}
|
||||
}
|
||||
|
||||
t.CompleteLogin() //通知客户端登录成功
|
||||
|
||||
glog.Debug(context.Background(), "登录成功,初始地图 人数:", space.GetSpace(t.Info.MapID).Len())
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"blazing/common/data/socket"
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/logic/service/pet"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/blazing/service"
|
||||
)
|
||||
|
||||
@@ -25,6 +26,33 @@ func (h *Controller) PetRelease(
|
||||
c *socket.Player) (
|
||||
result *pet.PetReleaseOutboundInfo,
|
||||
err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
//放入背包=数据库置1+添加到背包+pet release发包 仓库=数据库置0+移除背包 设置首发等于取到首发精灵后重新排序
|
||||
//这里只修改,因为添加和移除背包在宠物获取时已经做了
|
||||
result = &pet.PetReleaseOutboundInfo{}
|
||||
result.PetInfo = make([]model.PetInfo, 0)
|
||||
t := service.NewUserService(c.Info.UserID).PetM(int(data.CatchTime), int(data.Flag))
|
||||
switch data.Flag {
|
||||
case 0:
|
||||
//todo 仓库
|
||||
removeIndex := -1
|
||||
for i, v := range c.Info.PetList {
|
||||
if v.CatchTime == uint32(data.CatchTime) {
|
||||
removeIndex = i
|
||||
break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环
|
||||
}
|
||||
|
||||
return nil, 0
|
||||
}
|
||||
if removeIndex != -1 {
|
||||
c.Info.PetList = append(c.Info.PetList[:removeIndex], c.Info.PetList[removeIndex+1:]...)
|
||||
}
|
||||
result.FirstPetTime = c.Info.PetList[0].CatchTime //设置首发
|
||||
|
||||
case 1:
|
||||
//todo 背包
|
||||
PetAdd(c, t)
|
||||
result.PetInfo = append(result.PetInfo, t)
|
||||
}
|
||||
|
||||
//service.NewUserService(c.Info.UserID).PetAdd( *r)
|
||||
return result, 0
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package controller
|
||||
import (
|
||||
"blazing/common/data/socket"
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/common/socket/handler"
|
||||
"blazing/logic/service/pet"
|
||||
"blazing/logic/service/task"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/blazing/service"
|
||||
@@ -15,9 +17,9 @@ import (
|
||||
*/
|
||||
func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *socket.Player) (result *task.AcceptTaskOutboundInfo, err errorcode.ErrorCode) {
|
||||
//isdaliy := false
|
||||
if data.Head.CMD != 2201 { //判断是每日任务
|
||||
//isdaliy = true
|
||||
}
|
||||
// if data.Head.CMD != 2201 { //判断是每日任务
|
||||
// //isdaliy = true
|
||||
// }
|
||||
|
||||
if c.Info.TaskList[data.TaskId] == 0 {
|
||||
c.Info.TaskList[data.TaskId] = 1
|
||||
@@ -32,10 +34,10 @@ func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *socket.Playe
|
||||
* 更新任务步骤
|
||||
*/
|
||||
func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *socket.Player) (result *task.AddTaskBufOutboundInfo, err errorcode.ErrorCode) {
|
||||
isdaliy := false
|
||||
if data.Head.CMD != 2204 { //判断是每日任务
|
||||
isdaliy = true
|
||||
}
|
||||
// isdaliy := false
|
||||
// if data.Head.CMD != 2204 { //判断是每日任务
|
||||
// isdaliy = true
|
||||
// }
|
||||
service.NewUserService(c.Info.UserID).TaskExec(func(ttt []model.TaskInfo) []model.TaskInfo {
|
||||
var ttt2 []model.TaskInfo
|
||||
for _, v := range ttt {
|
||||
@@ -47,7 +49,7 @@ func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *socket.Playe
|
||||
}
|
||||
|
||||
return ttt2
|
||||
}, isdaliy)
|
||||
})
|
||||
|
||||
return &task.AddTaskBufOutboundInfo{}, 0
|
||||
}
|
||||
@@ -93,7 +95,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *socket.
|
||||
r := model.GenPetInfo(1, 1, 1, 1, 1, 5)
|
||||
result.CaptureTime = r.CatchTime
|
||||
result.PetTypeId = r.ID
|
||||
service.NewUserService(c.Info.UserID).PetAdd(r.CatchTime, 1, *r)
|
||||
PetAdd(c, *r)
|
||||
}
|
||||
if data.TaskId == 87 { //新手注册任务
|
||||
|
||||
@@ -113,10 +115,10 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *socket.
|
||||
* 获取任务状态
|
||||
*/
|
||||
func (h Controller) Get_Task_Buf(data *task.GetTaskBufInboundInfo, c *socket.Player) (result *task.GetTaskBufOutboundInfo, err errorcode.ErrorCode) {
|
||||
isdaliy := false
|
||||
if data.Head.CMD == 2203 { //判断不是每日任务
|
||||
isdaliy = true
|
||||
}
|
||||
// isdaliy := false
|
||||
// if data.Head.CMD == 2203 { //判断不是每日任务
|
||||
// isdaliy = true
|
||||
// }
|
||||
|
||||
service.NewUserService(c.Info.UserID).TaskExec(func(ttt []model.TaskInfo) []model.TaskInfo {
|
||||
var ttt2 = make([]model.TaskInfo, 500)
|
||||
@@ -130,7 +132,7 @@ func (h Controller) Get_Task_Buf(data *task.GetTaskBufInboundInfo, c *socket.Pla
|
||||
}
|
||||
|
||||
return ttt2
|
||||
}, isdaliy)
|
||||
})
|
||||
|
||||
return result, 0
|
||||
}
|
||||
@@ -140,11 +142,22 @@ func (h Controller) Get_Task_Buf(data *task.GetTaskBufInboundInfo, c *socket.Pla
|
||||
*/
|
||||
func (h Controller) Delete_Task(data *task.DeleteTaskInboundInfo, c *socket.Player) (result *task.DeleteTaskOutboundInfo, err errorcode.ErrorCode) {
|
||||
|
||||
if data.Head.CMD == 2205 { //判断不是每日任务
|
||||
// if data.Head.CMD == 2205 { //判断不是每日任务
|
||||
|
||||
} else {
|
||||
// } else {
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
return &task.DeleteTaskOutboundInfo{}, 0
|
||||
}
|
||||
|
||||
// 添加精灵
|
||||
func PetAdd(c *socket.Player, y model.PetInfo) {
|
||||
c.Info.PetList = append(c.Info.PetList, y)
|
||||
|
||||
service.NewUserService(c.Info.UserID).PetAdd(y)
|
||||
t := handler.NewTomeeHeader(2304, c.Info.UserID)
|
||||
c.SendPack(t.Pack(&pet.PetReleaseOutboundInfo{PetInfo: []model.PetInfo{y}}))
|
||||
|
||||
//return lw.IsLogin
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ package node
|
||||
func (this *EffectNode) UseSkill() bool {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
func (this *EffectNode) OnSkillPP() bool {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
func (this *EffectNode) SkillUseEnd() bool {
|
||||
panic("not implemented") // TODO: Implement
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ type OutInfo struct {
|
||||
|
||||
// PetReleaseOutboundInfo 宠物释放出站消息
|
||||
type PetReleaseOutboundInfo struct {
|
||||
HomeEnergy uint64 `json:"home_energy" fieldDescription:"暂定0" autoCodec:"true" uint:"true"`
|
||||
FirstPetTime uint64 `json:"first_pet_time" fieldDescription:"精灵生成时间" autoCodec:"true" uint:"true"`
|
||||
HomeEnergy uint32 `json:"home_energy" fieldDescription:"暂定0" autoCodec:"true" uint:"true"`
|
||||
FirstPetTime uint32 `json:"first_pet_time" fieldDescription:"精灵生成时间" autoCodec:"true" uint:"true"`
|
||||
PetInfo []model.PetInfo `json:"pet_info" fieldDescription:"精灵信息" autoCodec:"true"`
|
||||
}
|
||||
|
||||
// 放入背包或者加入仓库
|
||||
type PetReleaseInboundInfo struct {
|
||||
Head handler.TomeeHeader `cmd:"2304" struc:"[0]pad"`
|
||||
CatchTime uint64 `json:"catch_time" fieldDescription:"精灵生成时间" autoCodec:"true" uint:"true"`
|
||||
Flag uint64 `json:"flag" fieldDescription:"0为放入仓库,1为放入背包" autoCodec:"true" uint:"true"`
|
||||
CatchTime uint32 `json:"catch_time" fieldDescription:"精灵生成时间" autoCodec:"true" uint:"true"`
|
||||
Flag uint32 `json:"flag" fieldDescription:"0为放入仓库,1为放入背包" autoCodec:"true" uint:"true"`
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ var (
|
||||
}
|
||||
|
||||
s := g.Server()
|
||||
|
||||
s.EnableAdmin()
|
||||
s.SetServerAgent(cool.Config.Name)
|
||||
s.BindHookHandler("/*", ghttp.HookBeforeServe, beforeServeHook)
|
||||
runtime.SetMutexProfileFraction(1) // (非必需)开启对锁调用的跟踪
|
||||
|
||||
@@ -5,7 +5,10 @@ server:
|
||||
openapiPath: "/api.json"
|
||||
swaggerPath: "/swagger"
|
||||
clientMaxBodySize: 104857600 # 100MB in bytes 100*1024*1024
|
||||
|
||||
# 平滑重启特性
|
||||
graceful: true # 是否开启平滑重启特性,开启时将会在本地增加10000的本地TCP端口用于进程间通信。默认false
|
||||
gracefulTimeout: 2 # 父进程在平滑重启后多少秒退出,默认2秒。若请求耗时大于该值,可能会导致请求中断
|
||||
gracefulShutdownTimeout: 5 # 关闭Server时如果存在正在执行的HTTP请求,Server等待多少秒才执行强行关闭
|
||||
logger:
|
||||
level: "all"
|
||||
stdout: true
|
||||
|
||||
@@ -15,7 +15,11 @@ type Pet struct {
|
||||
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"`
|
||||
Data string `gorm:"type:text;not null;comment:'精灵全部数据'" json:"data"`
|
||||
// Owner uint32 `struc:"skip"` //仅作为存储
|
||||
// FreedTime uint32 `struc:"skip"` //放生时间
|
||||
//是否可交易,这里应该定义在精灵ID里
|
||||
//是否上架
|
||||
Data string `gorm:"type:text;not null;comment:'精灵全部数据'" json:"data"`
|
||||
}
|
||||
|
||||
// * @param petTypeId 精灵类型ID
|
||||
@@ -125,8 +129,7 @@ func (c *PetInfo) CalculatePetPanelSize(base, iv, level, ev uint32, natureCorrec
|
||||
|
||||
// PetInfo 精灵信息结构(合并后的优化版本)
|
||||
type PetInfo struct {
|
||||
Owner uint32 `struc:"skip"` //仅作为存储
|
||||
freedTime uint32 `struc:"skip"` //放生时间
|
||||
|
||||
// 精灵编号(@UInt long → uint32)
|
||||
ID uint32 `fieldDesc:"精灵编号" `
|
||||
|
||||
|
||||
@@ -47,15 +47,26 @@ func (s *UserService) PetExec(ctime uint32, t func(uint32, model.PetInfo) model.
|
||||
m1.Save(player)
|
||||
|
||||
}
|
||||
func (s *UserService) PetAdd(ctime uint32, inbag int, y model.PetInfo) {
|
||||
func (s *UserService) PetAdd(y model.PetInfo) {
|
||||
|
||||
m1 := cool.DBM(s.pet.Model).Where("player_id", s.userid)
|
||||
var player model.Pet
|
||||
player.PlayerID = s.userid
|
||||
player.CatchTime = ctime
|
||||
player.InBag = inbag
|
||||
player.CatchTime = y.CatchTime
|
||||
player.InBag = 1
|
||||
tmp, _ := json.Marshal(y)
|
||||
player.Data = string(tmp)
|
||||
m1.Insert(player)
|
||||
|
||||
}
|
||||
func (s *UserService) PetM(ctime, type1 int) model.PetInfo {
|
||||
|
||||
m1 := cool.DBM(s.pet.Model).Where("player_id", s.userid).Where("catch_time", ctime)
|
||||
var player model.Pet
|
||||
player.InBag = type1
|
||||
m1.Update(player)
|
||||
var tt model.PetInfo
|
||||
json.Unmarshal([]byte(player.Data), &tt)
|
||||
return tt
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func (s *UserService) InitTask() {
|
||||
//panic(err)
|
||||
|
||||
}
|
||||
func (s *UserService) TaskExec(t func([]model.TaskInfo) []model.TaskInfo, isdaliy bool) (ret bool) {
|
||||
func (s *UserService) TaskExec(t func([]model.TaskInfo) []model.TaskInfo) (ret bool) {
|
||||
|
||||
//待实现检测是否为每日任务
|
||||
// if isdaliy {
|
||||
|
||||
Reference in New Issue
Block a user