feat(fight): 添加战斗前状态检查与经验获取限制判断
- 在挑战BOSS和野外怪物战斗前,增加 CanFight 状态检查,防止非法战斗 - 修复战斗胜利后经验与物品发放逻辑,增加 CanGetExp 判断避免重复获取 - 优化战斗中精灵切换逻辑与相关伤害效果处理,确保死亡标记正确设置 - 修正战斗轮次中被动切换行为及技能执行顺序问题 - 移除无用的管理员会话控制器和宠物融合模型代码 - 调整战斗输入结构体中的 Switch 类型为 Map 以提高查找效率 - 修复战斗中精灵存活判定条件,
This commit is contained in:
24
modules/blazing/controller/admin/pet_fusion_controller.go
Normal file
24
modules/blazing/controller/admin/pet_fusion_controller.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/service"
|
||||
)
|
||||
|
||||
// PetFusionController 宠物融合配方主表Admin控制器(对应/admin/pet/fusion路由)
|
||||
type PetFusionController struct {
|
||||
*cool.Controller
|
||||
}
|
||||
|
||||
func init() {
|
||||
// 初始化控制器,配置路由前缀、支持的API、绑定Service
|
||||
var petFusionController = &PetFusionController{
|
||||
&cool.Controller{
|
||||
Prefix: "/admin/pet/fusion", // 路由前缀(按模块分类:宠物-融合配方)
|
||||
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"}, // 支持的基础CRUD接口
|
||||
Service: service.NewPetFusionService(), // 绑定主表Service
|
||||
},
|
||||
}
|
||||
// 注册控制器到框架
|
||||
cool.RegisterController(petFusionController)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/service"
|
||||
)
|
||||
|
||||
// PetFusionMaterialController 宠物融合材料子表Admin控制器(对应/admin/pet/fusion/material路由)
|
||||
type PetFusionMaterialController struct {
|
||||
*cool.Controller
|
||||
}
|
||||
|
||||
func init() {
|
||||
// 初始化控制器,配置路由前缀、支持的API、绑定Service
|
||||
var petFusionMaterialController = &PetFusionMaterialController{
|
||||
&cool.Controller{
|
||||
Prefix: "/admin/pet/fusionmaterial", // 路由前缀(主表路由+子表名,层级清晰)
|
||||
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"}, // 支持的基础CRUD接口
|
||||
Service: service.NewPetFusionMaterialService(), // 绑定子表Service
|
||||
},
|
||||
}
|
||||
// 注册控制器到框架
|
||||
cool.RegisterController(petFusionMaterialController)
|
||||
}
|
||||
@@ -1,85 +1,85 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"blazing/common/data/share"
|
||||
"blazing/cool"
|
||||
baseservice "blazing/modules/base/service"
|
||||
"blazing/modules/blazing/service"
|
||||
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type SessionReq struct {
|
||||
g.Meta `path:"/getSessionByAuth" method:"GET"`
|
||||
Email string `json:"email" v:"required|email"`
|
||||
Password string `json:"password" v:"required"`
|
||||
}
|
||||
type SessionRes struct {
|
||||
Msg string `json:"msg"`
|
||||
Code int `json:"code"`
|
||||
Session string `json:"session"`
|
||||
}
|
||||
|
||||
type BlazingController struct {
|
||||
*cool.Controller
|
||||
}
|
||||
|
||||
var biazing_service = service.NewLoginServiceService()
|
||||
|
||||
func init() {
|
||||
var blazing_controller = &BlazingController{
|
||||
&cool.Controller{
|
||||
Prefix: "/seer/game",
|
||||
Api: []string{},
|
||||
Service: biazing_service,
|
||||
},
|
||||
}
|
||||
// 注册路由
|
||||
cool.RegisterController(blazing_controller)
|
||||
}
|
||||
func (c *BlazingController) GetSession(ctx context.Context, req *SessionReq) (res *SessionRes, err error) {
|
||||
|
||||
res = &SessionRes{
|
||||
Msg: "success",
|
||||
Code: 200,
|
||||
Session: ""}
|
||||
if err := g.Validator().Data(req).Run(ctx); err != nil {
|
||||
fmt.Println(err)
|
||||
res.Code = 400
|
||||
res.Msg = err.Error()
|
||||
|
||||
}
|
||||
res1, err := baseservice.NewBaseSysUserService().GetSession(req.Email, req.Password)
|
||||
|
||||
if err != nil || res1 == nil {
|
||||
res.Code = 400
|
||||
res.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
accountID := res1.ID
|
||||
retsid, sid, err := biazing_service.GetSessionId(accountID)
|
||||
if err != nil {
|
||||
res.Code = 400
|
||||
res.Msg = err.Error()
|
||||
|
||||
}
|
||||
|
||||
res.Session = retsid
|
||||
|
||||
if err := share.ShareManager.SaveSession(sid, uint32(accountID)); err != nil {
|
||||
res.Code = 400
|
||||
res.Msg = err.Error()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type MockReq struct {
|
||||
g.Meta `path:"/mock" method:"GET"`
|
||||
Email string `json:"email" v:"required|email"`
|
||||
Password string `json:"password" v:"required"`
|
||||
}
|
||||
package app
|
||||
|
||||
import (
|
||||
"blazing/common/data/share"
|
||||
"blazing/cool"
|
||||
baseservice "blazing/modules/base/service"
|
||||
"blazing/modules/blazing/service"
|
||||
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type SessionReq struct {
|
||||
g.Meta `path:"/getSessionByAuth" method:"GET"`
|
||||
Email string `json:"email" v:"required|email"`
|
||||
Password string `json:"password" v:"required"`
|
||||
}
|
||||
type SessionRes struct {
|
||||
Msg string `json:"msg"`
|
||||
Code int `json:"code"`
|
||||
Session string `json:"session"`
|
||||
}
|
||||
|
||||
type BlazingController struct {
|
||||
*cool.Controller
|
||||
}
|
||||
|
||||
var biazing_service = service.NewLoginServiceService()
|
||||
|
||||
func init() {
|
||||
var blazing_controller = &BlazingController{
|
||||
&cool.Controller{
|
||||
Prefix: "/seer/game",
|
||||
Api: []string{},
|
||||
Service: biazing_service,
|
||||
},
|
||||
}
|
||||
// 注册路由
|
||||
cool.RegisterController(blazing_controller)
|
||||
}
|
||||
func (c *BlazingController) GetSession(ctx context.Context, req *SessionReq) (res *SessionRes, err error) {
|
||||
|
||||
res = &SessionRes{
|
||||
Msg: "success",
|
||||
Code: 200,
|
||||
Session: ""}
|
||||
if err := g.Validator().Data(req).Run(ctx); err != nil {
|
||||
fmt.Println(err)
|
||||
res.Code = 400
|
||||
res.Msg = err.Error()
|
||||
|
||||
}
|
||||
res1, err := baseservice.NewBaseSysUserService().GetSession(req.Email, req.Password)
|
||||
|
||||
if err != nil || res1 == nil {
|
||||
res.Code = 400
|
||||
res.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
accountID := res1.ID
|
||||
retsid, sid, err := biazing_service.GetSessionId(accountID)
|
||||
if err != nil {
|
||||
res.Code = 400
|
||||
res.Msg = err.Error()
|
||||
|
||||
}
|
||||
|
||||
res.Session = retsid
|
||||
|
||||
if err := share.ShareManager.SaveSession(sid, uint32(accountID)); err != nil {
|
||||
res.Code = 400
|
||||
res.Msg = err.Error()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type MockReq struct {
|
||||
g.Meta `path:"/mock" method:"GET"`
|
||||
Email string `json:"email" v:"required|email"`
|
||||
Password string `json:"password" v:"required"`
|
||||
}
|
||||
@@ -2,4 +2,5 @@ package controller
|
||||
|
||||
import (
|
||||
_ "blazing/modules/blazing/controller/admin"
|
||||
_ "blazing/modules/blazing/controller/app"
|
||||
)
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
const (
|
||||
TableNamePetFusion = "pet_fusion" // 宠物融合配方表(主宠-副宠-材料-概率-融合结果)
|
||||
)
|
||||
|
||||
// PetFusion 宠物融合配方模型(对应尼尔+闪皮+材料1-4=卡鲁/闪尼等融合规则)
|
||||
type PetFusion struct {
|
||||
*cool.Model // 嵌入通用Model(包含ID/创建时间/更新时间等通用字段)
|
||||
|
||||
MainPetID int32 `gorm:"not null;comment:'主宠物ID(如:尼尔)'" json:"main_pet_id"`
|
||||
SubPetID int32 `gorm:"not null;comment:'副宠物ID(如:闪皮)'" json:"sub_pet_id"`
|
||||
// Material1 int32 `gorm:"not null;default:0;comment:'融合材料1ID(无则填0)'" json:"material1"`
|
||||
// Material2 int32 `gorm:"not null;default:0;comment:'融合材料2ID(无则填0)'" json:"material2"`
|
||||
// Material3 int32 `gorm:"not null;default:0;comment:'融合材料3ID(无则填0)'" json:"material3"`
|
||||
// Material4 int32 `gorm:"not null;default:0;comment:'融合材料4ID(无则填0)'" json:"material4"`
|
||||
Probability float32 `gorm:"not null;comment:'融合成功率(百分比,如80代表80%)'" json:"probability"`
|
||||
ResultPetID int32 `gorm:"not null;comment:'融合结果宠物ID(如:卡鲁、闪尼)'" json:"result_pet_id"`
|
||||
Remark string `gorm:"type:varchar(255);default:'';comment:'融合配方备注(如:尼尔+闪皮=闪尼)'" json:"remark"`
|
||||
IsEnable int32 `gorm:"not null;default:1;comment:'是否启用(1:启用,0:禁用)'" json:"is_enable"`
|
||||
// 新增:是否默认配方(核心逻辑:所有匹配配方都不满足时,随机选择默认配方)
|
||||
IsDefault int32 `gorm:"not null;default:0;comment:'是否默认配方(1:默认配方,0:非默认;所有配方不匹配时随机选默认配方)'" json:"is_default"`
|
||||
}
|
||||
|
||||
// PetFusionEX 宠物融合配方扩展模型(如需前端展示多维度数据时使用,如ID转名称等)
|
||||
type PetFusionEX struct {
|
||||
PetFusion
|
||||
MainPetName string `json:"main_pet_name"` // 主宠名称(前端展示用)
|
||||
SubPetName string `json:"sub_pet_name"` // 副宠名称(前端展示用)
|
||||
ResultPetName string `json:"result_pet_name"` // 结果宠名称(前端展示用)
|
||||
}
|
||||
|
||||
// TableName 指定PetFusion对应的数据库表名
|
||||
func (*PetFusion) TableName() string {
|
||||
return TableNamePetFusion
|
||||
}
|
||||
|
||||
// GroupName 指定表所属的分组(保持和MonsterRefresh一致)
|
||||
func (*PetFusion) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewPetFusion 创建一个新的PetFusion实例(初始化通用Model)
|
||||
func NewPetFusion() *PetFusion {
|
||||
return &PetFusion{
|
||||
Model: cool.NewModel(),
|
||||
}
|
||||
}
|
||||
|
||||
// init 初始化表结构(程序启动时自动创建/同步表)
|
||||
func init() {
|
||||
cool.CreateTable(&PetFusion{})
|
||||
}
|
||||
47
modules/blazing/model/pet_fusion.go
Normal file
47
modules/blazing/model/pet_fusion.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
const (
|
||||
TableNamePetFusion = "pet_fusion" // 宠物融合配方表(主表)
|
||||
)
|
||||
|
||||
// PetFusion 宠物融合配方主模型(核心配方规则)
|
||||
type PetFusion struct {
|
||||
*cool.Model // 嵌入通用Model(ID/创建时间/更新时间等)
|
||||
|
||||
MainPetID int32 `gorm:"not null;comment:'主宠物ID(如:尼尔)'" json:"main_pet_id"`
|
||||
SubPetID int32 `gorm:"not null;comment:'副宠物ID(如:闪皮)'" json:"sub_pet_id"`
|
||||
Probability float32 `gorm:"not null;comment:'融合成功率(百分比,如80代表80%)'" json:"probability"`
|
||||
ResultPetID int32 `gorm:"not null;comment:'融合结果宠物ID(如:卡鲁、闪尼)'" json:"result_pet_id"`
|
||||
Remark string `gorm:"type:varchar(255);default:'';comment:'融合配方备注(如:尼尔+闪皮=闪尼)'" json:"remark"`
|
||||
IsEnable int32 `gorm:"not null;default:1;comment:'是否启用(1:启用,0:禁用)'" json:"is_enable"`
|
||||
IsDefault int32 `gorm:"not null;default:0;comment:'是否默认配方(1:默认配方,0:非默认;所有配方不匹配时随机选默认配方)'" json:"is_default"`
|
||||
|
||||
// 关联:一个配方对应多个材料(gorm 一对多关联,查询时可预加载)
|
||||
//Materials []*PetFusionMaterial `gorm:"foreignKey:PetFusionID;references:ID" json:"materials,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 指定主表名
|
||||
func (*PetFusion) TableName() string {
|
||||
return TableNamePetFusion
|
||||
}
|
||||
|
||||
// GroupName 表分组(与原逻辑一致)
|
||||
func (*PetFusion) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewPetFusion 创建主表实例
|
||||
func NewPetFusion() *PetFusion {
|
||||
return &PetFusion{
|
||||
Model: cool.NewModel(),
|
||||
}
|
||||
}
|
||||
|
||||
// init 初始化主表结构
|
||||
func init() {
|
||||
cool.CreateTable(&PetFusion{})
|
||||
}
|
||||
48
modules/blazing/model/pet_fusion_material.go
Normal file
48
modules/blazing/model/pet_fusion_material.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package model
|
||||
|
||||
import "blazing/cool"
|
||||
|
||||
const (
|
||||
TableNamePetFusionMaterial = "pet_fusion_material" // 宠物融合材料表(子表)
|
||||
)
|
||||
|
||||
// PetFusionMaterial 融合材料模型(与配方主表一对一关联)
|
||||
type PetFusionMaterial struct {
|
||||
*cool.Model // 嵌入通用Model(ID/创建时间/更新时间等)
|
||||
|
||||
// 4个材料ID(对应XML ItemGroup的Idx=1-4,无材料填0)
|
||||
Material1 int64 `gorm:"not null;comment:'材料1ID(如400030)'" json:"material1"`
|
||||
Material2 int64 `gorm:"not null;comment:'材料2ID(如400030)'" json:"material2"`
|
||||
Material3 int64 `gorm:"not null;comment:'材料3ID(如400028)'" json:"material3"`
|
||||
Material4 int64 `gorm:"not null;comment:'材料4ID(如400030)'" json:"material4"`
|
||||
|
||||
// 4个特性ID(对应XML MaterialGroup的特性索引,4-4对应)
|
||||
Trait1Idx int32 `gorm:"not null;comment:'特性1索引(如1008)'" json:"trait1_idx"`
|
||||
Trait2Idx int32 `gorm:"not null;comment:'特性2索引(如1018)'" json:"trait2_idx"`
|
||||
Trait3Idx int32 `gorm:"not null;comment:'特性3索引(如1023)'" json:"trait3_idx"`
|
||||
Trait4Idx int32 `gorm:"not null;comment:'特性4索引(如1031)'" json:"trait4_idx"`
|
||||
|
||||
IsEnable int32 `gorm:"not null;default:1;comment:'是否启用该组合(1:启用,0:禁用)'" json:"is_enable"`
|
||||
}
|
||||
|
||||
// TableName 指定子表名
|
||||
func (*PetFusionMaterial) TableName() string {
|
||||
return TableNamePetFusionMaterial
|
||||
}
|
||||
|
||||
// GroupName 表分组(与主表一致)
|
||||
func (*PetFusionMaterial) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewPetFusionMaterial 创建材料实例
|
||||
func NewPetFusionMaterial() *PetFusionMaterial {
|
||||
return &PetFusionMaterial{
|
||||
Model: cool.NewModel(),
|
||||
}
|
||||
}
|
||||
|
||||
// init 初始化子表结构
|
||||
func init() {
|
||||
cool.CreateTable(&PetFusionMaterial{})
|
||||
}
|
||||
20
modules/blazing/service/pet_fusion_material_service.go
Normal file
20
modules/blazing/service/pet_fusion_material_service.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
// PetFusionMaterialService 宠物融合材料子表Service(对应pet_fusion_material表)
|
||||
type PetFusionMaterialService struct {
|
||||
*cool.Service // 嵌入通用Service(继承基础CRUD方法)
|
||||
}
|
||||
|
||||
// NewPetFusionMaterialService 创建PetFusionMaterialService实例
|
||||
func NewPetFusionMaterialService() *PetFusionMaterialService {
|
||||
return &PetFusionMaterialService{
|
||||
&cool.Service{
|
||||
Model: model.NewPetFusionMaterial(), // 绑定PetFusionMaterial模型(默认参数占位)
|
||||
},
|
||||
}
|
||||
}
|
||||
20
modules/blazing/service/pet_fusion_service.go
Normal file
20
modules/blazing/service/pet_fusion_service.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
// PetFusionService 宠物融合配方主表Service(对应pet_fusion表)
|
||||
type PetFusionService struct {
|
||||
*cool.Service // 嵌入通用Service(继承基础CRUD方法)
|
||||
}
|
||||
|
||||
// NewPetFusionService 创建PetFusionService实例
|
||||
func NewPetFusionService() *PetFusionService {
|
||||
return &PetFusionService{
|
||||
&cool.Service{
|
||||
Model: model.NewPetFusion(), // 绑定PetFusion模型
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user