diff --git a/logic/controller/Controller.go b/logic/controller/Controller.go index 6b17d1169..12101fbe8 100644 --- a/logic/controller/Controller.go +++ b/logic/controller/Controller.go @@ -1,3 +1,6 @@ +// Package controller 提供游戏逻辑的控制器层,负责处理各种游戏功能的请求分发。 +// 包含用户、宠物、战斗、物品、地图、任务等各个模块的控制器方法。 +// 通过反射和标签系统自动注册 cmd 处理方法,实现请求到处理函数的映射。 package controller import ( @@ -18,7 +21,7 @@ import ( var Maincontroller = &Controller{} //注入service -// 分发cmd逻辑实现Controller +// Controller 分发cmd逻辑实现 type Controller struct { Port uint16 RPCClient struct { @@ -28,8 +31,11 @@ type Controller struct { } } +// ParseCmd 将字节数组数据解析到指定类型的变量中 +// 该函数使用struc库进行数据解包操作 func ParseCmd[T any](a T, data []byte) T { // := info.NewLoginSidInfo() + // 使用struc.Unpack将字节数据解包到变量a中 struc.Unpack(bytes.NewBuffer(data), &a) return a //fmt.Println(pinfo) @@ -52,31 +58,31 @@ func Init(isgame bool) { //默认初始化扫描 //fmt.Println("找到注册方法", method.Name) methodValue.Type().NumIn() - for _, func_cmd := range getCmd(methodValue.Type().In(0)) { - if func_cmd == 0 { //说明不是注册方法 + for _, funcCmd := range getCmd(methodValue.Type().In(0)) { + if funcCmd == 0 { //说明不是注册方法 glog.Warning(context.Background(), "方法参数必须包含CMD参数", method.Name, "跳过注册") continue } - if !isgame && func_cmd > 1000 { //判断login服务器 + if !isgame && funcCmd > 1000 { //判断login服务器 continue } - if isgame && func_cmd < 1000 { //判断login服务器 + if isgame && funcCmd < 1000 { //判断login服务器 continue } - glog.Debug(context.Background(), "注册方法", func_cmd, method.Name) + glog.Debug(context.Background(), "注册方法", funcCmd, method.Name) - _, ok := cool.CmdCache.LoadOrStore(func_cmd, cool.Cmd{ + _, ok := cool.CmdCache.LoadOrStore(funcCmd, cool.Cmd{ Func: methodValue, Req: methodValue.Type().In(0).Elem(), // Res: , }) //TODO 待实现对不同用户初始化方法以取消全局cmdcache if ok { //方法已存在init - glog.Error(context.Background(), "方法已存在init,不会初始化后面的方法", func_cmd) + glog.Error(context.Background(), "方法已存在init,不会初始化后面的方法", funcCmd) } } diff --git a/logic/controller/active_xiyou_in1.go b/logic/controller/active_xiyou_in1.go index bf51a5399..75ca1d37a 100644 --- a/logic/controller/active_xiyou_in1.go +++ b/logic/controller/active_xiyou_in1.go @@ -8,7 +8,7 @@ import ( "github.com/gogf/gf/v2/util/grand" ) -// 传送仓抓稀有 +// Cacthpet 传送仓抓稀有 func (h Controller) Cacthpet(data *pet.C2S_9756, c *player.Player) (result *pet.S2C_9756, err errorcode.ErrorCode) { result = &pet.S2C_9756{ UseEV: uint32(grand.N(1, 13)), diff --git a/logic/controller/fight_base.go b/logic/controller/fight_base.go index d088f5b8d..5547c3d3d 100644 --- a/logic/controller/fight_base.go +++ b/logic/controller/fight_base.go @@ -9,87 +9,91 @@ import ( "blazing/logic/service/player" ) -// 准备战斗 -func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { +// checkFightStatus 检查战斗状态 +func (h Controller) checkFightStatus(c *player.Player) errorcode.ErrorCode { if c.FightC == nil { - return nil, errorcode.ErrorCodes.ErrBattleEnded + return errorcode.ErrorCodes.ErrBattleEnded + } + return 0 +} + +// OnReadyToFight 准备战斗 +func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { + if err := h.checkFightStatus(c); err != 0 { + return nil, err } defer c.FightC.ReadyFight(c) return nil, -1 } -// 使用技能包 +// UseSkill 使用技能包 func (h Controller) UseSkill(data *fight.UseSkillInInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { - if c.FightC == nil { - return nil, errorcode.ErrorCodes.ErrBattleEnded + if err := h.checkFightStatus(c); err != 0 { + return nil, err } defer c.FightC.UseSkill(c, data.SkillId) return nil, 0 } -// 战斗逃跑 +// Escape 战斗逃跑 func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { - - if c.FightC == nil { - return nil, errorcode.ErrorCodes.ErrBattleEnded + if err := h.checkFightStatus(c); err != 0 { + return nil, err } - if atomic.LoadUint32(&c.Fightinfo.Mode) == 0 { - - return nil, errorcode.ErrorCodes.ErrBattleNotStarted //,没开始对战 + battleMode := atomic.LoadUint32(&c.Fightinfo.Mode) + if battleMode == 0 { + return nil, errorcode.ErrorCodes.ErrBattleNotStarted } - if atomic.LoadUint32(&c.Fightinfo.Mode) == 1 { //用户对战不能逃跑 - + if battleMode == 1 { return nil, errorcode.ErrorCodes.ErrCannotFleePlayerBattle } + defer c.FightC.Over(c, info.BattleOverReason.PlayerEscape) return nil, 0 } -// 切换精灵 +// ChangePet 切换精灵 func (h Controller) ChangePet(data *fight.ChangePetInboundInfo, c *player.Player) (result *info.ChangePetInfo, err errorcode.ErrorCode) { - if c.FightC == nil { - return nil, errorcode.ErrorCodes.ErrBattleEnded + if err := h.checkFightStatus(c); err != 0 { + return nil, err } - defer c.FightC.ChangePet(c, data.CatchTime) return nil, -1 } -// 切换精灵 +// Capture 捕捉精灵 func (h Controller) Capture(data *fight.CatchMonsterInboundInfo, c *player.Player) (result *info.CatchMonsterOutboundInfo, err errorcode.ErrorCode) { - if c.FightC == nil { - return nil, errorcode.ErrorCodes.ErrBattleEnded + if err := h.checkFightStatus(c); err != 0 { + return nil, err } defer c.FightC.Capture(c, data.CapsuleId) return nil, -1 } -// 加载进度 +// LoadPercent 加载进度 func (h Controller) LoadPercent(data *fight.LoadPercentInboundInfo, c *player.Player) (result *info.LoadPercentOutboundInfo, err errorcode.ErrorCode) { if c.FightC == nil { return nil, -1 } - defer c.FightC.LoadPercent(c, int32(data.Percent)) return nil, -1 } + +// UsePetItemInboundInfo 使用宠物道具 func (h Controller) UsePetItemInboundInfo(data *fight.UsePetItemInboundInfo, c *player.Player) (result *info.UsePetIteminfo, err errorcode.ErrorCode) { - - if c.FightC == nil { - return nil, errorcode.ErrorCodes.ErrBattleEnded + if err := h.checkFightStatus(c); err != 0 { + return nil, err } - defer c.FightC.UseItem(c, data.CatchTime, data.ItemId) - return nil, -1 } + +// FightChat 战斗聊天 func (h Controller) FightChat(data *fight.ChatInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { - if c.FightC == nil { - return nil, errorcode.ErrorCodes.ErrBattleEnded + if err := h.checkFightStatus(c); err != 0 { + return nil, err } - defer c.FightC.Chat(c, data.Message) - return nil, -1 } diff --git a/logic/controller/fight_boss.go b/logic/controller/fight_boss.go index 1baee8846..2ae043335 100644 --- a/logic/controller/fight_boss.go +++ b/logic/controller/fight_boss.go @@ -46,7 +46,7 @@ func processMonID(bm string) string { return selected } -// 挑战地图boss +// PlayerFightBoss 挑战地图boss func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { if !c.CanFight() { return nil, errorcode.ErrorCodes.ErrSystemError @@ -152,7 +152,7 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *pla return nil, -1 } -// 战斗野怪 +// OnPlayerFightNpcMonster 战斗野怪 func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { if !c.CanFight() { return nil, errorcode.ErrorCodes.ErrSystemError diff --git a/logic/controller/fight_leitai.go b/logic/controller/fight_leitai.go index cbf78a630..10f51099e 100644 --- a/logic/controller/fight_leitai.go +++ b/logic/controller/fight_leitai.go @@ -10,12 +10,13 @@ import ( "blazing/logic/service/space" ) +// ArenaSetOwner 处理玩家占据擂台的请求 // public static const ARENA_SET_OWENR:uint = 2417; // 如果星际擂台上无人,站到星际擂台的包 // 前端到后端无数据内容 空包 // 后端到前端无数据内容 空包 // 都需要通过2419包广播更新擂台状态 -func (h Controller) ARENA_SET_OWENR(data *fight.ARENA_SET_OWENR, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { +func (h Controller) ArenaSetOwner(data *fight.ARENA_SET_OWENR, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { if !c.CanFight() { return nil, errorcode.ErrorCodes.ErrPokemonNotEligible @@ -32,13 +33,12 @@ func (h Controller) ARENA_SET_OWENR(data *fight.ARENA_SET_OWENR, c *player.Playe return nil, errorcode.ErrorCodes.ErrChampionExists } -// public static const ARENA_FIGHT_OWENR:uint = 2418; -// 挑战擂台的包 +// ArenaFightOwner 挑战擂台的包 // 前端到后端无数据内容 空包 // 后端到前端无数据内容 空包 // 还是后端主动发送2503的包给双方前端后 等待前端加载完毕 主动发送2404包通知后端开始战斗 // 并不会通知对方是否接受挑战。只要有人挑战就直接进入对战 -func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { +func (h Controller) ArenaFightOwner(data *fight.ARENA_FIGHT_OWENR, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { if !c.CanFight() { return nil, errorcode.ErrorCodes.ErrNoEligiblePokemon @@ -105,21 +105,20 @@ func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.P } -// 获取星际擂台信息的包 进入空间站地图前端会发送请求包 或者 有人站到星际擂台上后 广播回包 +// ArenaGetInfo 获取星际擂台信息的包 进入空间站地图前端会发送请求包 或者 有人站到星际擂台上后 广播回包 // 前端到后端无数据内容 // 后端到前端 -func (h Controller) ARENA_GET_INFO(data *fight.ARENA_GET_INFO, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) { +func (h Controller) ArenaGetInfo(data *fight.ARENA_GET_INFO, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) { result = &c.GetSpace().Owner return } -// public static const ARENA_UPFIGHT:uint = 2420; -// 放弃擂台挑战的包 +// ArenaUpfight 放弃擂台挑战的包 // 前端到后端无数据内容 // 后端到前端无数据内容 // 都需要通过2419包广播更新擂台状态 -func (h Controller) ARENA_UPFIGHT(data *fight.ARENA_UPFIGHT, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { +func (h Controller) ArenaUpfight(data *fight.ARENA_UPFIGHT, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { //原子操作,修改擂台状态 if atomic.LoadUint32(&c.GetSpace().Owner.UserID) != c.GetInfo().UserID { //说明已经有人了 return nil, errorcode.ErrorCodes.ErrChampionCannotCancel @@ -136,13 +135,12 @@ func (h Controller) ARENA_UPFIGHT(data *fight.ARENA_UPFIGHT, c *player.Player) ( } -// public static const ARENA_OWENR_ACCE:uint = 2422; -// 此包为擂台战对战结束后 胜方前端会发送给后端 具体作用为通知后端发送2419包更新擂台信息。 +// ArenaOwnerAcce 此包为擂台战对战结束后 胜方前端会发送给后端 具体作用为通知后端发送2419包更新擂台信息。 // 前端到后端无数据内容 // 后端到前端无数据内容 // public static const ARENA_OWENR_OUT:uint = 2423; // 此包不清楚具体怎么触发 但已知此包为后端主动发送。不清楚什么情况下回用到 -func (h Controller) ARENA_OWENR_ACCE(data *fight.ARENA_OWENR_ACCE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { +func (h Controller) ArenaOwnerAcce(data *fight.ARENA_OWENR_ACCE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { s := c.GetSpace() @@ -157,4 +155,4 @@ func (h Controller) ARENA_OWENR_ACCE(data *fight.ARENA_OWENR_ACCE, c *player.Pla c.SendPackCmd(2419, &c.GetSpace().Owner) return nil, -1 -} +} \ No newline at end of file diff --git a/logic/controller/fight_pvp_king.go b/logic/controller/fight_pvp_king.go index b35b02dc4..becf45493 100644 --- a/logic/controller/fight_pvp_king.go +++ b/logic/controller/fight_pvp_king.go @@ -11,7 +11,7 @@ import ( //大乱斗 -func (h Controller) PET_MELEE(data *fight.StartPetWarInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { +func (h Controller) PetMelee(data *fight.StartPetWarInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { c.Fightinfo.Mode = info.BattleMode.PET_MELEE c.Fightinfo.Status = info.BattleMode.PET_MELEE @@ -29,17 +29,12 @@ func (h Controller) PET_MELEE(data *fight.StartPetWarInboundInfo, c *player.Play } }) ///开始对战,房主方以及被邀请方 - if err > 0 { //说明有报错 - - return false - } - - return true + return err <= 0 }) return } -func (h Controller) PET_King(data *fight.PetKingJoinInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { +func (h Controller) PETKing(data *fight.PetKingJoinInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { c.Fightinfo.Status = info.BattleMode.PET_TOPLEVEL @@ -60,11 +55,7 @@ func (h Controller) PET_King(data *fight.PetKingJoinInboundInfo, c *player.Playe } }) ///开始对战,房主方以及被邀请方 - if err > 0 { //说明有报错 - - return false - } - return true + return err <= 0 }) return diff --git a/logic/controller/fight_tawor.go b/logic/controller/fight_tawor.go index 3c4484fdc..3eb45cd99 100644 --- a/logic/controller/fight_tawor.go +++ b/logic/controller/fight_tawor.go @@ -30,7 +30,7 @@ func (h Controller) FRESH_CHOICE_FIGHT_LEVEL(data *fight.C2S_FRESH_CHOICE_FIGHT_ defer c.GetSpace().EnterMap(c) return result, 0 } -func (h Controller) FRESH_LEAVE_FIGHT_LEVEL(data *fight.FRESH_LEAVE_FIGHT_LEVEL, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { +func (h Controller) FreshLeaveFightLevel(data *fight.FRESH_LEAVE_FIGHT_LEVEL, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { switch data.Head.CMD { case 2430: //试炼之塔 diff --git a/logic/controller/item_buy.go b/logic/controller/item_buy.go index 08c6544bb..08d08c8fe 100644 --- a/logic/controller/item_buy.go +++ b/logic/controller/item_buy.go @@ -12,13 +12,16 @@ import ( // 防止封包通过领取来获取道具 -// 领取道具包校验价格 +// BuyItem 购买单个道具 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)) { + itemInfo, exists := xmlres.ItemsMAP[int(data.ItemId)] + if !exists { + return &item.BuyOutboundInfo{Coins: c.Info.Coins}, 0 + } - r := c.ItemAdd(data.ItemId, data.Count) - if r { + // 免费道具直接添加 + if itemInfo.Price == 0 { + if c.ItemAdd(data.ItemId, data.Count) { return &item.BuyOutboundInfo{ ItemId: data.ItemId, Level: 1, @@ -26,59 +29,88 @@ func (h Controller) BuyItem(data *item.BuyInboundInfo, c *player.Player) (result Coins: c.Info.Coins, }, 0 } - //购买失败,返还豆子 - - c.Info.Coins += data.Count * uint32(tt.Price) + return &item.BuyOutboundInfo{Coins: c.Info.Coins}, 0 } - return &item.BuyOutboundInfo{ + // 需要付费的道具 + totalCost := data.Count * uint32(itemInfo.Price) + if !c.UseCoins(totalCost) { + return &item.BuyOutboundInfo{Coins: c.Info.Coins}, errorcode.ErrorCodes.ErrSunDouInsufficient10016 + } - Coins: c.Info.Coins, - }, 0 + if c.ItemAdd(data.ItemId, data.Count) { + c.Info.Coins -= totalCost + return &item.BuyOutboundInfo{ + ItemId: data.ItemId, + Level: 1, + Count: data.Count, + Coins: c.Info.Coins, + }, 0 + } + + // 购买失败,返还赛尔豆 + c.Info.Coins += totalCost + return &item.BuyOutboundInfo{Coins: c.Info.Coins}, 0 } + +// BuyMItem 批量购买道具 func (h Controller) BuyMItem(data *item.BuyMultiInboundInfo, c *player.Player) (result *item.BuyMultiOutboundInfo, err errorcode.ErrorCode) { + for _, itemID := range data.ItemIds { + itemInfo, exists := xmlres.ItemsMAP[int(itemID)] + if !exists { + continue + } - for _, v := range data.ItemIds { - iteminfo, ok := xmlres.ItemsMAP[int(v)] + // 免费道具直接添加 + if itemInfo.Price == 0 { + c.ItemAdd(itemID, 1) + continue + } - if ok { - if !c.UseCoins(uint32(iteminfo.Price)) { - break - } - if c.ItemAdd(v, 1) { - c.Info.Coins -= uint32(iteminfo.Price) - - } + // 需要付费的道具 + if !c.UseCoins(uint32(itemInfo.Price)) { + break + } + if c.ItemAdd(itemID, 1) { + c.Info.Coins -= uint32(itemInfo.Price) } } return &item.BuyMultiOutboundInfo{ - Coins: c.Info.Coins, }, 0 } + +// BuyGoldItem 使用金豆购买商品 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)] - usegold := uint32(data.Count) * uint32(gconv.Float64(r.Price)*100) - if !c.UseGold(usegold) { + product, exists := xmlres.GoldProductMap[int(data.ProductID)] + if !exists { return nil, errorcode.ErrorCodes.ErrSystemError } - isbuycot := c.ItemAdd(uint32(gconv.Uint32(r.ItemID)), uint32(data.Count)) - if isbuycot { - c.User.UpdateGold(c.Info.UserID, -int64(usegold)) - result = &item.S2C_GoldBuyProductInfo{ + useGold := uint32(data.Count) * uint32(gconv.Float64(product.Price)*100) + if !c.UseGold(useGold) { + return &item.S2C_GoldBuyProductInfo{ Gold: c.User.GetGold(uint(c.Info.UserID)), - PayGold: usegold, + PayGold: 0, Reserved: 0, - } + }, errorcode.ErrorCodes.ErrXinDouInsufficient } - result = &item.S2C_GoldBuyProductInfo{ + + addSuccess := c.ItemAdd(uint32(gconv.Uint32(product.ItemID)), uint32(data.Count)) + if addSuccess { + c.User.UpdateGold(c.Info.UserID, -int64(useGold)) + return &item.S2C_GoldBuyProductInfo{ + Gold: c.User.GetGold(uint(c.Info.UserID)), + PayGold: useGold, + Reserved: 0, + }, 0 + } + + return &item.S2C_GoldBuyProductInfo{ Gold: c.User.GetGold(uint(c.Info.UserID)), PayGold: 0, Reserved: 0, - } - return - + }, errorcode.ErrorCodes.ErrSystemError } diff --git a/logic/controller/pet_skill.go b/logic/controller/pet_skill.go index b166764f5..1505bef92 100644 --- a/logic/controller/pet_skill.go +++ b/logic/controller/pet_skill.go @@ -12,14 +12,19 @@ import ( "github.com/samber/lo" ) +// SetPetSkill 设置宠物技能,消耗50赛尔豆 func (h Controller) SetPetSkill(data *pet.ChangeSkillInfo, c *player.Player) (result *pet.ChangeSkillOutInfo, err errorcode.ErrorCode) { - if !c.UseCoins(100) { - return result, errorcode.ErrorCodes.ErrSunDouInsufficient10016 + const setSkillCost = 50 + + if !c.UseCoins(setSkillCost) { + return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016 } - c.Info.Coins -= 50 + + c.Info.Coins -= setSkillCost + _, onpet, ok := c.FindPet(data.CatchTime) if !ok { - return result, errorcode.ErrorCodes.ErrSystemBusy + return nil, errorcode.ErrorCodes.ErrSystemBusy } canleaernskill := onpet.GetLevelRangeCanLearningSkills(1, onpet.Level) @@ -33,40 +38,46 @@ func (h Controller) SetPetSkill(data *pet.ChangeSkillInfo, c *player.Player) (re _, _, ok = utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool { //已经存在技能 return item.ID == data.ReplaceSkill }) - if ok { - return result, errorcode.ErrorCodes.ErrSystemBusy + return nil, errorcode.ErrorCodes.ErrSystemBusy } - _, hasskill, ok := utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool { //已经存在技能 + + // 查找要学习的技能并替换 + _, hasSkill, ok := utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool { return item.ID == data.HasSkill }) - if ok { - hasskill.ID = data.ReplaceSkill - hasskill.PP = uint32(xmlres.SkillMap[int(hasskill.ID)].MaxPP) + hasSkill.ID = data.ReplaceSkill + hasSkill.PP = uint32(xmlres.SkillMap[int(hasSkill.ID)].MaxPP) } + return &pet.ChangeSkillOutInfo{ CatchTime: data.CatchTime, }, 0 } -func (h Controller) Skill_Sort(data *pet.C2S_Skill_Sort, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { - if !c.UseCoins(100) { - return result, errorcode.ErrorCodes.ErrSystemBusy + +// SkillSort 排序宠物技能,消耗50赛尔豆 +func (h Controller) SkillSort(data *pet.C2S_Skill_Sort, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { + const skillSortCost = 50 + + if !c.UseCoins(skillSortCost) { + return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016 } - c.Info.Coins -= 50 + + c.Info.Coins -= skillSortCost + _, onpet, ok := c.FindPet(data.CapTm) if ok { - var newskill []model.SkillInfo - for _, v := range data.Skill { - _, HasSkill, ok := utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool { //已经存在技能 - return item.ID == v + var newSkillList []model.SkillInfo + for _, skillID := range data.Skill { + _, skill, found := utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool { + return item.ID == skillID }) - if ok { - newskill = append(newskill, *HasSkill) - + if found { + newSkillList = append(newSkillList, *skill) } } - onpet.SkillList = newskill + onpet.SkillList = newSkillList } return nil, 0 diff --git a/logic/controller/user_action.go b/logic/controller/user_action.go index f6eb0a6e2..8484657d5 100644 --- a/logic/controller/user_action.go +++ b/logic/controller/user_action.go @@ -35,14 +35,19 @@ func (h Controller) Chat(data *user.ChatInboundInfo, c *player.Player) (result * c.GetSpace().Broadcast(c, data.Head.CMD, result) return } -func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, c *player.Player) (result *user.ChangeColorOutboundInfo, err errorcode.ErrorCode) { - if !c.UseCoins(200) { //如果花不了200,直接返回 +// ChangePlayerColor 修改玩家颜色,消耗50赛尔豆 +func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, c *player.Player) (result *user.ChangeColorOutboundInfo, err errorcode.ErrorCode) { + const changeColorCost = 50 + + if !c.UseCoins(changeColorCost) { return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016 } - c.Info.Coins -= 50 + + c.Info.Coins -= changeColorCost c.Info.Color = data.Color c.Info.Texture = 0 + result = &user.ChangeColorOutboundInfo{ UserId: c.Info.UserID, Color: data.Color, @@ -53,13 +58,19 @@ func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, c *play return } + +// ChangePlayerDoodle 修改玩家涂鸦,消耗50赛尔豆 func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, c *player.Player) (result *user.ChangeDoodleOutboundInfo, err errorcode.ErrorCode) { - if !c.UseCoins(200) { //如果花不了200,直接返回 + const changeDoodleCost = 50 + + if !c.UseCoins(changeDoodleCost) { return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016 } - c.Info.Coins -= 50 + + c.Info.Coins -= changeDoodleCost c.Info.Texture = data.Id c.Info.Color = data.Color + result = &user.ChangeDoodleOutboundInfo{ UserId: c.Info.UserID, Color: c.Info.Color, diff --git a/logic/controller/user_task.go b/logic/controller/user_task.go index 16c886a84..c99d0e0d9 100644 --- a/logic/controller/user_task.go +++ b/logic/controller/user_task.go @@ -8,9 +8,7 @@ import ( "blazing/modules/blazing/model" ) -/** - * 接受任务 - */ +// AcceptTask 接受任务 func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *player.Player) (result *task.AcceptTaskOutboundInfo, err errorcode.ErrorCode) { //isdaliy := false // if data.Head.CMD != 2201 { //判断是每日任务 @@ -32,9 +30,7 @@ func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *player.Playe return result, 0 } -/** - * 更新任务步骤 - */ +// AddTaskBuf 更新任务步骤 func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *player.Player) (result *task.AddTaskBufOutboundInfo, err errorcode.ErrorCode) { // isdaliy := false // if data.Head.CMD != 2204 { //判断是每日任务 @@ -49,9 +45,7 @@ func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *player.Playe return result, 0 } -/** - * 完成任务 - */ +// Complete_Task 完成任务 func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.Player) (result *task.CompleteTaskOutboundInfo, err errorcode.ErrorCode) { if c.Info.GetTask(int(data.TaskId)) != model.Accepted { //如果任务没有接受或者已经完成Complete_Task return result, 0 @@ -92,9 +86,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player. return result, 0 //通过PUB/SUB回包 } -/** - * 获取任务状态 - */ +// Get_Task_Buf 获取任务状态 func (h Controller) Get_Task_Buf(data *task.GetTaskBufInboundInfo, c *player.Player) (result *task.GetTaskBufOutboundInfo, err errorcode.ErrorCode) { result = &task.GetTaskBufOutboundInfo{ TaskId: data.TaskId, @@ -108,9 +100,7 @@ func (h Controller) Get_Task_Buf(data *task.GetTaskBufInboundInfo, c *player.Pla return result, 0 } -/** - * 删除任务 - */ +// Delete_Task 删除任务 func (h Controller) Delete_Task(data *task.DeleteTaskInboundInfo, c *player.Player) (result *task.DeleteTaskOutboundInfo, err errorcode.ErrorCode) { if c.Info.GetTask(int(data.TaskId)) == model.Accepted {