```
refactor(item_use): 重构道具使用逻辑并提取常量 - 添加 ItemDefaultLeftTime 和 ItemNeuronID 常量定义 - 使用结构体字面量初始化 itemInfo,替换手动赋值 - 将神经元道具处理逻辑提取为独立方法 handleNeuronItem - 将普通宠物道具处理逻辑提取为独立方法 handleRegularPetItem - 优化 UsePetItemOutOfFight 方法的条件判断结构 fix(NewSeIdx_700): 修复Boss技能伤害计算参数错误 - 修正 Skill_Useed 方法中 Div 方法的参数索引,从 Args()[1]
This commit is contained in:
@@ -10,6 +10,13 @@ import (
|
|||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// ItemDefaultLeftTime 道具默认剩余时间(毫秒)
|
||||||
|
ItemDefaultLeftTime = 360000
|
||||||
|
// ItemNeuronID 神经元道具ID
|
||||||
|
ItemNeuronID = 300036
|
||||||
|
)
|
||||||
|
|
||||||
// GetUserItemList 获取用户道具列表
|
// GetUserItemList 获取用户道具列表
|
||||||
// data: 包含分页参数的输入信息
|
// data: 包含分页参数的输入信息
|
||||||
// c: 当前玩家对象
|
// c: 当前玩家对象
|
||||||
@@ -20,10 +27,11 @@ func (h Controller) GetUserItemList(data *item.ItemListInboundInfo, c *player.Pl
|
|||||||
|
|
||||||
items := c.Service.Item.Get(data.Param1, data.Param2)
|
items := c.Service.Item.Get(data.Param1, data.Param2)
|
||||||
for _, itemData := range items {
|
for _, itemData := range items {
|
||||||
var itemInfo model.SingleItemInfo
|
itemInfo := model.SingleItemInfo{
|
||||||
itemInfo.ItemId = itemData.ItemId
|
ItemId: itemData.ItemId,
|
||||||
itemInfo.ItemCnt = itemData.ItemCnt
|
ItemCnt: itemData.ItemCnt,
|
||||||
itemInfo.LeftTime = 360000
|
LeftTime: ItemDefaultLeftTime,
|
||||||
|
}
|
||||||
if itemInfo.ItemCnt != 0 {
|
if itemInfo.ItemCnt != 0 {
|
||||||
result.ItemList = append(result.ItemList, itemInfo)
|
result.ItemList = append(result.ItemList, itemInfo)
|
||||||
}
|
}
|
||||||
@@ -45,27 +53,14 @@ func (h Controller) UsePetItemOutOfFight(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGH
|
|||||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.ItemID == 300036 {
|
var errcode errorcode.ErrorCode
|
||||||
// 神经元需要特殊处理
|
if data.ItemID == ItemNeuronID {
|
||||||
if currentPet.OldCatchTime == 0 {
|
errcode = h.handleNeuronItem(currentPet, c)
|
||||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
||||||
}
|
|
||||||
oldPetCatchTime := currentPet.CatchTime
|
|
||||||
oldPet := c.Service.Pet.PetInfo_One_Unscoped(currentPet.OldCatchTime)
|
|
||||||
println(c.Info.UserID, "还原", len(c.Info.PetList), currentPet.ID, oldPet.Data.ID)
|
|
||||||
|
|
||||||
copier.CopyWithOption(currentPet, oldPet.Data, copier.Option{DeepCopy: true})
|
|
||||||
currentPet.CatchTime = oldPetCatchTime
|
|
||||||
println(c.Info.UserID, "还原后", len(c.Info.PetList), currentPet.ID, oldPet.Data.ID)
|
|
||||||
} else {
|
} else {
|
||||||
handler := item.PetItemRegistry.GetHandler(data.ItemID)
|
errcode = h.handleRegularPetItem(data.ItemID, currentPet)
|
||||||
if handler == nil {
|
}
|
||||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
if errcode != 0 {
|
||||||
}
|
return nil, errcode
|
||||||
success := handler(data.ItemID, currentPet)
|
|
||||||
if !success {
|
|
||||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Service.Item.UPDATE(data.ItemID, -1)
|
c.Service.Item.UPDATE(data.ItemID, -1)
|
||||||
@@ -76,19 +71,49 @@ func (h Controller) UsePetItemOutOfFight(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGH
|
|||||||
return result, 0
|
return result, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleNeuronItem 处理神经元道具的特殊逻辑
|
||||||
|
func (h Controller) handleNeuronItem(currentPet *model.PetInfo, c *player.Player) errorcode.ErrorCode {
|
||||||
|
if currentPet.OldCatchTime == 0 {
|
||||||
|
return errorcode.ErrorCodes.ErrSystemError
|
||||||
|
}
|
||||||
|
|
||||||
|
originalCatchTime := currentPet.CatchTime
|
||||||
|
oldPet := c.Service.Pet.PetInfo_One_Unscoped(currentPet.OldCatchTime)
|
||||||
|
|
||||||
|
copier.CopyWithOption(currentPet, oldPet.Data, copier.Option{DeepCopy: true})
|
||||||
|
currentPet.CatchTime = originalCatchTime
|
||||||
|
currentPet.ShinyInfo = oldPet.Data.ShinyInfo
|
||||||
|
currentPet.EffectInfo = oldPet.Data.EffectInfo
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleRegularPetItem 处理普通宠物道具
|
||||||
|
func (h Controller) handleRegularPetItem(itemID uint32, currentPet *model.PetInfo) errorcode.ErrorCode {
|
||||||
|
handler := item.PetItemRegistry.GetHandler(itemID)
|
||||||
|
if handler == nil {
|
||||||
|
return errorcode.ErrorCodes.ErrSystemError
|
||||||
|
}
|
||||||
|
if !handler(itemID, currentPet) {
|
||||||
|
return errorcode.ErrorCodes.ErrSystemError
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
// ResetNature 重置宠物性格
|
// ResetNature 重置宠物性格
|
||||||
// data: 包含道具ID和宠物捕获时间的输入信息
|
// data: 包含道具ID和宠物捕获时间的输入信息
|
||||||
// c: 当前玩家对象
|
// c: 当前玩家对象
|
||||||
// 返回: 无数据和错误码
|
// 返回: 无数据和错误码
|
||||||
func (h Controller) ResetNature(data *item.C2S_PET_RESET_NATURE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) ResetNature(data *item.C2S_PET_RESET_NATURE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||||
if c.Service.Item.CheakItem(data.ItemId) <= 0 {
|
|
||||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
||||||
}
|
|
||||||
_, currentPet, found := c.FindPet(data.CatchTime)
|
_, currentPet, found := c.FindPet(data.CatchTime)
|
||||||
if !found {
|
if !found {
|
||||||
return nil, errorcode.ErrorCodes.Err10401
|
return nil, errorcode.ErrorCodes.Err10401
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.Service.Item.CheakItem(data.ItemId) <= 0 {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||||
|
}
|
||||||
|
|
||||||
currentPet.Nature = data.Nature
|
currentPet.Nature = data.Nature
|
||||||
currentPet.CalculatePetPane(false)
|
currentPet.CalculatePetPane(false)
|
||||||
c.Service.Item.UPDATE(data.ItemId, -1)
|
c.Service.Item.UPDATE(data.ItemId, -1)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func (e *NewSel700) Skill_Useed() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
e.Input.Heal(
|
e.Input.Heal(
|
||||||
e.Ctx().Our, &action.SelectSkillAction{}, e.Ctx().Our.SumDamage.Div(e.Args()[1]),
|
e.Ctx().Our, &action.SelectSkillAction{}, e.Ctx().Our.SumDamage.Div(e.Args()[0]),
|
||||||
)
|
)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
48
modules/config/model/TaskConfig.go
Normal file
48
modules/config/model/TaskConfig.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"blazing/cool"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 表名常量定义:任务配置表
|
||||||
|
const (
|
||||||
|
TableNameTaskConfig = "task_config" // 任务配置表(记录任务ID、类型、目标、奖励、状态等核心信息)
|
||||||
|
)
|
||||||
|
|
||||||
|
// TaskConfig 任务核心配置模型
|
||||||
|
type TaskConfig struct {
|
||||||
|
*cool.Model
|
||||||
|
|
||||||
|
// 核心字段
|
||||||
|
TaskId uint32 `gorm:"not null;uniqueIndex;comment:'任务唯一ID'" json:"task_id" description:"任务唯一ID"`
|
||||||
|
TaskName string `gorm:"not null;size:128;comment:'任务名称'" json:"task_name" description:"任务名称"`
|
||||||
|
|
||||||
|
// 奖励配置
|
||||||
|
ItemRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励物品ID数组,关联item_gift表主键'" json:"item_reward_ids" description:"奖励物品数组"`
|
||||||
|
ElfRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励精灵ID数组,关联config_pet_boss表主键'" json:"elf_reward_ids" description:"奖励精灵数组"`
|
||||||
|
|
||||||
|
// 任务状态和周期
|
||||||
|
IsEnabled uint32 `gorm:"not null;default:1;comment:'是否启用该任务(0-禁用 1-启用)'" json:"is_enabled" description:"是否启用"`
|
||||||
|
|
||||||
|
Remark string `gorm:"size:512;default:'';comment:'任务备注'" json:"remark" description:"备注信息"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------- 核心配套方法(遵循项目规范)--------------------------
|
||||||
|
func (*TaskConfig) TableName() string {
|
||||||
|
return TableNameTaskConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*TaskConfig) GroupName() string {
|
||||||
|
return "default"
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTaskConfig() *TaskConfig {
|
||||||
|
return &TaskConfig{
|
||||||
|
Model: cool.NewModel(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------- 表结构自动同步 --------------------------
|
||||||
|
func init() {
|
||||||
|
cool.CreateTable(&TaskConfig{})
|
||||||
|
}
|
||||||
@@ -2,8 +2,6 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -56,59 +54,6 @@ func NewCDKConfig() *CDKConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------- 业务操作方法(适配可兑换次数 != 0 需求)--------------------------
|
|
||||||
|
|
||||||
// SetExchangeTotalCount 设置总可兑换次数(确保不为0,满足where !=0 约束)
|
|
||||||
func (c *CDKConfig) SetExchangeTotalCount(total uint32) error {
|
|
||||||
if total == 0 {
|
|
||||||
return errors.New("CDK总可兑换次数不能为0,请设置大于0的数值")
|
|
||||||
}
|
|
||||||
// 若剩余次数大于新的总次数,同步更新剩余次数为总次数
|
|
||||||
if c.ExchangeRemainCount > total {
|
|
||||||
c.ExchangeRemainCount = total
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeductRemainCount 扣减剩余可兑换次数(扣减后仍保证非负,且仅当剩余次数>0时可扣减)
|
|
||||||
func (c *CDKConfig) DeductRemainCount(deductNum uint32) error {
|
|
||||||
if deductNum <= 0 {
|
|
||||||
return errors.New("扣减的兑换次数必须大于0")
|
|
||||||
}
|
|
||||||
// 校验剩余次数是否大于0(满足where !=0 前置条件)
|
|
||||||
if c.ExchangeRemainCount == 0 {
|
|
||||||
return errors.New("CDK剩余可兑换次数为0,无法继续扣减")
|
|
||||||
}
|
|
||||||
// 校验扣减后是否为负
|
|
||||||
if c.ExchangeRemainCount < deductNum {
|
|
||||||
return fmt.Errorf("剩余可兑换次数不足(当前剩余%d,需扣减%d)", c.ExchangeRemainCount, deductNum)
|
|
||||||
}
|
|
||||||
c.ExchangeRemainCount -= deductNum
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsAvailable 判断CDK是否可用(剩余次数!=0 + 启用 + 在有效期内)
|
|
||||||
func (c *CDKConfig) IsAvailable() (bool, string) {
|
|
||||||
now := time.Now()
|
|
||||||
// 校验剩余次数是否!=0
|
|
||||||
if c.ExchangeRemainCount == 0 {
|
|
||||||
return false, "CDK剩余可兑换次数为0,已失效"
|
|
||||||
}
|
|
||||||
// 校验是否启用
|
|
||||||
if c.IsEnabled == 0 {
|
|
||||||
return false, "CDK已被禁用,无法使用"
|
|
||||||
}
|
|
||||||
// 校验有效期
|
|
||||||
if now.Before(c.ValidStartTime) {
|
|
||||||
return false, "CDK尚未到有效时间,暂无法使用"
|
|
||||||
}
|
|
||||||
if now.After(c.ValidEndTime) {
|
|
||||||
return false, "CDK已过有效期,已失效"
|
|
||||||
}
|
|
||||||
return true, "CDK可用"
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------- 表结构自动同步 --------------------------
|
// -------------------------- 表结构自动同步 --------------------------
|
||||||
func init() {
|
func init() {
|
||||||
cool.CreateTable(&CDKConfig{})
|
cool.CreateTable(&CDKConfig{})
|
||||||
|
|||||||
Reference in New Issue
Block a user