feat(xmlres): 实装性格重塑,实装性格指定
fix(fight): 使用模型层方法生成精灵信息 refactor(controller): 移除冗余变量与内联XML读取逻辑 refactor(pet): 重构经验更新与进化逻辑 refactor(item): 校验并扣减使用道具数量 feat(item): 新增金豆购买商品协议结构体 feat(user): 迁移角色服装变更逻辑至user控制器 feat(pet): 增加技能排序协议定义 refactor(utils): 移除未使用的工具函数引用 chore(config): 更新地图怪物配置信息 详细变更内容包括: - 在`xmlres/file.go`中初始化`GoldProductMap`并加载相关配置。 - 将`GenPetInfo`方法从玩家服务迁移至`model`包以统一管理。 - 合并部分不必要的局部变量声明,并优化XML资源加载方式。 - 拆分精灵升级与进化方法,明确调用职责。 - 在战斗和治疗等操作前增加货币校验及扣除逻辑。 - 补充金豆购买相关的客户端/服务端通信结构体。 - 调整技能选择逻辑避免潜在索引越界问题。 - 更新部分注释说明和代码结构以提升可维护性。
This commit is contained in:
74
logic/controller/item_buy.go
Normal file
74
logic/controller/item_buy.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/common/socket/errorcode"
|
||||
|
||||
"blazing/logic/service/item"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/blazing/model"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
func (h Controller) BuyItem(data *item.BuyInboundInfo, c *player.Player) (result *item.BuyOutboundInfo, err errorcode.ErrorCode) {
|
||||
tt, ok := xmlres.ItemsMAP[int(data.ItemId)]
|
||||
if ok && tt.Price != 0 && c.UseCoins(data.Count*uint32(tt.Price)) {
|
||||
|
||||
r := c.ItemAdd(model.ItemInfo{ItemId: data.ItemId, ItemCnt: data.Count})
|
||||
if len(r) != 0 {
|
||||
return &item.BuyOutboundInfo{
|
||||
ItemId: data.ItemId,
|
||||
Level: 1,
|
||||
Count: data.Count,
|
||||
Coins: c.Info.Coins,
|
||||
}, 0
|
||||
}
|
||||
//购买失败,返还豆子
|
||||
c.Info.Coins += data.Count * uint32(tt.Price)
|
||||
}
|
||||
|
||||
return &item.BuyOutboundInfo{
|
||||
|
||||
Coins: c.Info.Coins,
|
||||
}, 0
|
||||
}
|
||||
func (h Controller) BuyMItem(data *item.BuyMultiInboundInfo, c *player.Player) (result *item.BuyMultiOutboundInfo, err errorcode.ErrorCode) {
|
||||
var rrr []model.ItemInfo
|
||||
for _, v := range data.ItemIds {
|
||||
_, ok := xmlres.ItemsMAP[int(v)]
|
||||
|
||||
if ok {
|
||||
rrr = append(rrr, model.ItemInfo{ItemId: uint32(v), ItemCnt: 1})
|
||||
|
||||
}
|
||||
}
|
||||
r := c.ItemAdd(rrr...)
|
||||
if len(r) != 0 {
|
||||
return &item.BuyMultiOutboundInfo{
|
||||
|
||||
Coins: c.Info.Coins,
|
||||
}, 0
|
||||
}
|
||||
return &item.BuyMultiOutboundInfo{
|
||||
|
||||
Coins: c.Info.Coins,
|
||||
}, 0
|
||||
}
|
||||
func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, c *player.Player) (result *item.S2C_GoldBuyProductInfo, err errorcode.ErrorCode) {
|
||||
r := xmlres.GoldProductMap[int(data.ProductID)]
|
||||
|
||||
if uint32(data.Count)*uint32(gconv.Uint32(r.Price)) > c.Info.GoldBean {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
c.ItemAdd(model.ItemInfo{ItemId: uint32(gconv.Uint32(r.ItemID)), ItemCnt: uint32(data.Count)})
|
||||
c.Info.GoldBean -= gconv.Uint32(r.Price)
|
||||
|
||||
result = &item.S2C_GoldBuyProductInfo{
|
||||
Gold: c.Info.GoldBean,
|
||||
PayGold: uint32(data.Count) * uint32(gconv.Uint32(r.Price)),
|
||||
Reserved: 0,
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user