``refactor(player): 统一将UseCoins方法重命名为GetCoins并优化宠物融合扣费逻辑``

This commit is contained in:
1
2026-01-03 13:53:38 +00:00
parent 3cce8738cf
commit 77baefef11
7 changed files with 23 additions and 21 deletions

View File

@@ -37,7 +37,7 @@ func (h Controller) BuyItem(data *item.BuyInboundInfo, player *player.Player) (r
// 需要付费的道具
totalCost := data.Count * uint32(itemInfo.Price)
if !player.UseCoins(totalCost) {
if !player.GetCoins(totalCost) {
return &item.BuyOutboundInfo{Coins: player.Info.Coins}, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
@@ -74,7 +74,7 @@ func (h Controller) BuyMultipleItems(data *item.BuyMultiInboundInfo, player *pla
}
// 需要付费的道具
if !player.UseCoins(uint32(itemInfo.Price)) {
if !player.GetCoins(uint32(itemInfo.Price)) {
break
}
@@ -122,4 +122,4 @@ func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, player *player.
PayGold: 0,
Reserved: 0,
}, errorcode.ErrorCodes.ErrSystemError
}
}

View File

@@ -54,7 +54,7 @@ func (h *Controller) PlayerPetCure(data *nono.PetCureInboundInfo, c *player.Play
if c.GetSpace().Owner.UserID == c.Info.UserID {
return result, errorcode.ErrorCodes.ErrChampionCannotHeal
}
if !c.UseCoins(50) {
if !c.GetCoins(50) {
return result, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
for i := 0; i < len(c.Info.PetList); i++ {

View File

@@ -14,9 +14,10 @@ import (
)
func (h Controller) PetFusion(data *pet.C2S_PetFusion, c *player.Player) (result *pet.PetFusionInfo, err errorcode.ErrorCode) {
if !c.UseCoins(1000) {
if !c.GetCoins(1000) {
return result, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
c.Info.Coins -= 1000
// g.Dump(c.Info.PetList)
//防止同一只
@@ -49,6 +50,16 @@ func (h Controller) PetFusion(data *pet.C2S_PetFusion, c *player.Player) (result
resid := int(service.NewPetFusionService().Data(Mcatchpetinfo.ID, Auxpetinfo.ID, Mcatchpetinfo.Level+Auxpetinfo.Level))
for _, v := range data.Item1 {
if c.Service.Item.CheakItem(v) == 0 {
return &pet.PetFusionInfo{}, 0
}
}
for _, v := range data.Item1 {
c.Service.Item.UPDATE(v, -1)
}
if resid == 0 {
_, ok := lo.Find(data.GoldItem1[:], func(item uint32) bool {
@@ -69,12 +80,6 @@ func (h Controller) PetFusion(data *pet.C2S_PetFusion, c *player.Player) (result
return &pet.PetFusionInfo{}, 0
}
for _, v := range data.Item1 {
if c.Service.Item.CheakItem(v) == 0 {
return &pet.PetFusionInfo{}, 0
}
}
effect := int(service.NewPetFusionMaterialService().Data(data.Item1))
@@ -114,10 +119,7 @@ func (h Controller) PetFusion(data *pet.C2S_PetFusion, c *player.Player) (result
c.PetDel(data.Auxcatchtime)
}
for _, v := range data.Item1 {
c.Service.Item.UPDATE(v, -1)
}
//todo材料扣除
return &pet.PetFusionInfo{
ObtainTime: r.CatchTime,

View File

@@ -16,7 +16,7 @@ import (
func (h Controller) SetPetSkill(data *pet.ChangeSkillInfo, c *player.Player) (result *pet.ChangeSkillOutInfo, err errorcode.ErrorCode) {
const setSkillCost = 50
if !c.UseCoins(setSkillCost) {
if !c.GetCoins(setSkillCost) {
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
@@ -60,7 +60,7 @@ func (h Controller) SetPetSkill(data *pet.ChangeSkillInfo, c *player.Player) (re
func (h Controller) SortPetSkills(data *pet.C2S_Skill_Sort, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
const skillSortCost = 50
if !c.UseCoins(skillSortCost) {
if !c.GetCoins(skillSortCost) {
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}

View File

@@ -17,7 +17,7 @@ func (h Controller) BuyFitment(data *room.C2S_BUY_FITMENT, c *player.Player) (re
itemConfig := xmlres.ItemsMAP[int(data.ID)]
totalCost := itemConfig.Price * int(data.Count)
if !c.UseCoins(uint32(totalCost)) {
if !c.GetCoins(uint32(totalCost)) {
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
c.Service.Room.Add(data.ID, data.Count)

View File

@@ -51,7 +51,7 @@ func (h Controller) PlayerChat(data *user.ChatInboundInfo, player *player.Player
func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, player *player.Player) (result *user.ChangeColorOutboundInfo, err errorcode.ErrorCode) {
const changeColorCost = 50
if !player.UseCoins(changeColorCost) {
if !player.GetCoins(changeColorCost) {
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
@@ -77,7 +77,7 @@ func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, player
func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, player *player.Player) (result *user.ChangeDoodleOutboundInfo, err errorcode.ErrorCode) {
const changeDoodleCost = 50
if !player.UseCoins(changeDoodleCost) {
if !player.GetCoins(changeDoodleCost) {
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
@@ -159,4 +159,4 @@ func (h Controller) ChangePlayerCloth(data *item.ChangePlayerClothInboundInfo, p
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
}