refactor(controller): 优化战斗和道具购买控制器的代码结构

- 为函数添加详细的参数和返回值注释说明
- 将参数名从通用的 'c' 重命名为更具描述性的 'player'
- 重命名局部变量以提高代码可读性,如 mo -> monster, moinfo -> monsterInfo
- 修复变量命名不一致问题,如 taskid -> taskID, cancpet -> canCapture
- 统一变量命名规范,使用驼峰命名法
- 为 processMonID 函数添加功能说明注释
- 重命名 handleNPCFightSpecial 函数参数 petid -> petID
```
This commit is contained in:
2025-12-25 12:26:18 +08:00
parent d84100a52f
commit 99b1e9495c
3 changed files with 189 additions and 137 deletions

View File

@@ -10,119 +10,153 @@ import (
"blazing/modules/blazing/model"
)
// PlayerAim 射击
func (h Controller) PlayerAim(data *user.AimatInboundInfo, c *player.Player) (result *user.AimatOutboundInfo, err errorcode.ErrorCode) {
// PlayerAim 玩家射击操作
// data: 包含射击信息的输入数据
// player: 当前玩家对象
// 返回: 射击结果和错误码
func (h Controller) PlayerAim(data *user.AimatInboundInfo, player *player.Player) (result *user.AimatOutboundInfo, err errorcode.ErrorCode) {
result = &user.AimatOutboundInfo{
ItemId: data.ItemId,
Point: data.Point,
ShootType: data.ShootType,
UserId: c.Info.UserID,
UserId: player.Info.UserID,
}
c.GetSpace().Broadcast(c, data.Head.CMD, result)
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
func (h Controller) PlayerChat(data *user.ChatInboundInfo, c *player.Player) (result *user.ChatOutboundInfo, err errorcode.ErrorCode) {
// PlayerChat 玩家聊天功能
// data: 包含聊天消息的输入数据
// player: 当前玩家对象
// 返回: 聊天结果和错误码
func (h Controller) PlayerChat(data *user.ChatInboundInfo, player *player.Player) (result *user.ChatOutboundInfo, err errorcode.ErrorCode) {
result = &user.ChatOutboundInfo{
Message: utils.RemoveLast(data.Message),
SenderNickname: c.Info.Nick,
SenderId: c.Info.UserID,
SenderNickname: player.Info.Nick,
SenderId: player.Info.UserID,
}
result.Message = cool.Filter.Replace(result.Message, '*')
c.GetSpace().Broadcast(c, data.Head.CMD, result)
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
// ChangePlayerColor 修改玩家颜色消耗50赛尔豆
func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, c *player.Player) (result *user.ChangeColorOutboundInfo, err errorcode.ErrorCode) {
// data: 包含颜色信息的输入数据
// player: 当前玩家对象
// 返回: 颜色更改结果和错误码
func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, player *player.Player) (result *user.ChangeColorOutboundInfo, err errorcode.ErrorCode) {
const changeColorCost = 50
if !c.UseCoins(changeColorCost) {
if !player.UseCoins(changeColorCost) {
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
c.Info.Coins -= changeColorCost
c.Info.Color = data.Color
c.Info.Texture = 0
player.Info.Coins -= changeColorCost
player.Info.Color = data.Color
player.Info.Texture = 0
result = &user.ChangeColorOutboundInfo{
UserId: c.Info.UserID,
UserId: player.Info.UserID,
Color: data.Color,
Coins: c.Info.Coins,
Texture: c.Info.Texture,
Coins: player.Info.Coins,
Texture: player.Info.Texture,
}
c.GetSpace().Broadcast(c, data.Head.CMD, result)
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
// ChangePlayerDoodle 修改玩家涂鸦消耗50赛尔豆
func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, c *player.Player) (result *user.ChangeDoodleOutboundInfo, err errorcode.ErrorCode) {
// data: 包含涂鸦信息的输入数据
// player: 当前玩家对象
// 返回: 涂鸦更改结果和错误码
func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, player *player.Player) (result *user.ChangeDoodleOutboundInfo, err errorcode.ErrorCode) {
const changeDoodleCost = 50
if !c.UseCoins(changeDoodleCost) {
if !player.UseCoins(changeDoodleCost) {
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
c.Info.Coins -= changeDoodleCost
c.Info.Texture = data.Id
c.Info.Color = data.Color
player.Info.Coins -= changeDoodleCost
player.Info.Texture = data.Id
player.Info.Color = data.Color
result = &user.ChangeDoodleOutboundInfo{
UserId: c.Info.UserID,
Color: c.Info.Color,
Coins: c.Info.Coins,
Texture: c.Info.Texture,
UserId: player.Info.UserID,
Color: player.Info.Color,
Coins: player.Info.Coins,
Texture: player.Info.Texture,
}
c.GetSpace().Broadcast(c, data.Head.CMD, result)
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
func (h Controller) ChangeNONOColor(data *user.ChangeNONOColorInboundInfo, c *player.Player) (result *user.ChangeNONOColorOutboundInfo, err errorcode.ErrorCode) {
//c.Info.Coins -= 200
c.Info.NONO.NonoColor = data.Color
// ChangeNONOColor 修改NONO颜色
// data: 包含NONO颜色信息的输入数据
// player: 当前玩家对象
// 返回: NONO颜色更改结果和错误码
func (h Controller) ChangeNONOColor(data *user.ChangeNONOColorInboundInfo, player *player.Player) (result *user.ChangeNONOColorOutboundInfo, err errorcode.ErrorCode) {
//player.Info.Coins -= 200
player.Info.NONO.NonoColor = data.Color
result = &user.ChangeNONOColorOutboundInfo{
Sataus: c.Info.UserID,
Color: c.Info.Color,
Sataus: player.Info.UserID,
Color: player.Info.Color,
}
c.GetSpace().Broadcast(c, data.Head.CMD, result)
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
func (h Controller) DanceAction(data *user.C2SDanceAction, c *player.Player) (result *user.S2CDanceAction, err errorcode.ErrorCode) {
// DanceAction 跳舞动作
// data: 包含跳舞类型信息的输入数据
// player: 当前玩家对象
// 返回: 跳舞动作结果和错误码
func (h Controller) DanceAction(data *user.C2SDanceAction, player *player.Player) (result *user.S2CDanceAction, err errorcode.ErrorCode) {
result = &user.S2CDanceAction{
Type: data.Type,
UserID: c.Info.UserID,
UserID: player.Info.UserID,
}
c.GetSpace().Broadcast(c, data.Head.CMD, result)
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
func (h Controller) PeopleTransform(data *user.C2SPEOPLE_TRANSFROM, c *player.Player) (result *user.S2CPEOPLE_TRANSFROM, err errorcode.ErrorCode) {
// PeopleTransform 人物变形
// data: 包含变形信息的输入数据
// player: 当前玩家对象
// 返回: 变形结果和错误码
func (h Controller) PeopleTransform(data *user.C2SPEOPLE_TRANSFROM, player *player.Player) (result *user.S2CPEOPLE_TRANSFROM, err errorcode.ErrorCode) {
result = &user.S2CPEOPLE_TRANSFROM{
SuitID: data.SuitID,
UserID: c.Info.UserID,
UserID: player.Info.UserID,
}
c.GetSpace().Broadcast(c, data.Head.CMD, result)
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
func (h Controller) ChangePlayerCloth(data *item.ChangePlayerClothInboundInfo, c *player.Player) (result *item.ChangePlayerClothOutboundInfo, err errorcode.ErrorCode) {
// ChangePlayerCloth 更换玩家服装
// data: 包含服装信息的输入数据
// player: 当前玩家对象
// 返回: 服装更改结果和错误码
func (h Controller) ChangePlayerCloth(data *item.ChangePlayerClothInboundInfo, player *player.Player) (result *item.ChangePlayerClothOutboundInfo, err errorcode.ErrorCode) {
result = &item.ChangePlayerClothOutboundInfo{
UserID: c.Info.UserID,
UserID: player.Info.UserID,
ClothList: make([]model.PeopleItemInfo, 0),
}
for _, clothID := range data.ClothList {
result.ClothList = append(result.ClothList, model.PeopleItemInfo{ID: clothID, Level: 1})
}
c.Info.Clothes = result.ClothList
player.Info.Clothes = result.ClothList
c.GetSpace().Broadcast(c, data.Head.CMD, result)
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
}