2025-09-20 00:17:29 +08:00
|
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"blazing/common/socket/errorcode"
|
2025-11-25 16:36:55 +08:00
|
|
|
|
"blazing/common/utils"
|
2025-10-24 00:31:38 +08:00
|
|
|
|
"blazing/cool"
|
2025-11-25 12:29:50 +08:00
|
|
|
|
"blazing/logic/service/item"
|
2025-09-20 00:17:29 +08:00
|
|
|
|
"blazing/logic/service/player"
|
|
|
|
|
|
"blazing/logic/service/user"
|
2026-01-19 18:51:56 +08:00
|
|
|
|
"blazing/modules/player/model"
|
|
|
|
|
|
"strings"
|
2025-09-20 00:17:29 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
// PlayerAim 玩家射击操作
|
|
|
|
|
|
// data: 包含射击信息的输入数据
|
|
|
|
|
|
// player: 当前玩家对象
|
|
|
|
|
|
// 返回: 射击结果和错误码
|
|
|
|
|
|
func (h Controller) PlayerAim(data *user.AimatInboundInfo, player *player.Player) (result *user.AimatOutboundInfo, err errorcode.ErrorCode) {
|
2025-11-18 20:52:04 +00:00
|
|
|
|
result = &user.AimatOutboundInfo{
|
2025-10-20 01:39:07 +08:00
|
|
|
|
|
2025-11-18 20:52:04 +00:00
|
|
|
|
ItemId: data.ItemId,
|
|
|
|
|
|
Point: data.Point,
|
|
|
|
|
|
ShootType: data.ShootType,
|
2025-12-25 12:26:18 +08:00
|
|
|
|
UserId: player.Info.UserID,
|
2025-11-18 20:52:04 +00:00
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
player.GetSpace().Broadcast(player, data.Head.CMD, result)
|
2025-10-20 01:39:07 +08:00
|
|
|
|
|
2025-11-18 20:52:04 +00:00
|
|
|
|
return
|
2025-10-20 01:39:07 +08:00
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
|
|
|
|
|
|
// PlayerChat 玩家聊天功能
|
|
|
|
|
|
// data: 包含聊天消息的输入数据
|
|
|
|
|
|
// player: 当前玩家对象
|
|
|
|
|
|
// 返回: 聊天结果和错误码
|
|
|
|
|
|
func (h Controller) PlayerChat(data *user.ChatInboundInfo, player *player.Player) (result *user.ChatOutboundInfo, err errorcode.ErrorCode) {
|
2025-10-23 01:02:19 +08:00
|
|
|
|
|
2025-11-18 20:52:04 +00:00
|
|
|
|
result = &user.ChatOutboundInfo{
|
2025-10-24 00:31:38 +08:00
|
|
|
|
|
2025-11-25 16:36:55 +08:00
|
|
|
|
Message: utils.RemoveLast(data.Message),
|
2025-12-25 12:26:18 +08:00
|
|
|
|
SenderNickname: player.Info.Nick,
|
|
|
|
|
|
SenderId: player.Info.UserID,
|
2025-11-18 20:52:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
result.Message = cool.Filter.Replace(result.Message, '*')
|
2025-12-25 12:26:18 +08:00
|
|
|
|
player.GetSpace().Broadcast(player, data.Head.CMD, result)
|
2025-11-18 20:52:04 +00:00
|
|
|
|
return
|
2025-10-24 00:31:38 +08:00
|
|
|
|
}
|
2025-12-23 10:46:17 +08:00
|
|
|
|
|
|
|
|
|
|
// ChangePlayerColor 修改玩家颜色,消耗50赛尔豆
|
2025-12-25 12:26:18 +08:00
|
|
|
|
// data: 包含颜色信息的输入数据
|
|
|
|
|
|
// player: 当前玩家对象
|
|
|
|
|
|
// 返回: 颜色更改结果和错误码
|
|
|
|
|
|
func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, player *player.Player) (result *user.ChangeColorOutboundInfo, err errorcode.ErrorCode) {
|
2025-12-23 10:46:17 +08:00
|
|
|
|
const changeColorCost = 50
|
2025-11-13 21:36:18 +08:00
|
|
|
|
|
2026-01-03 13:53:38 +00:00
|
|
|
|
if !player.GetCoins(changeColorCost) {
|
2025-12-16 02:50:10 +08:00
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
2025-11-13 21:36:18 +08:00
|
|
|
|
}
|
2025-12-23 10:46:17 +08:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
player.Info.Coins -= changeColorCost
|
|
|
|
|
|
player.Info.Color = data.Color
|
|
|
|
|
|
player.Info.Texture = 0
|
2025-12-23 10:46:17 +08:00
|
|
|
|
|
2025-11-18 20:52:04 +00:00
|
|
|
|
result = &user.ChangeColorOutboundInfo{
|
2025-12-25 12:26:18 +08:00
|
|
|
|
UserId: player.Info.UserID,
|
2025-11-18 20:52:04 +00:00
|
|
|
|
Color: data.Color,
|
2025-12-25 12:26:18 +08:00
|
|
|
|
Coins: player.Info.Coins,
|
|
|
|
|
|
Texture: player.Info.Texture,
|
2025-11-18 20:52:04 +00:00
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
player.GetSpace().Broadcast(player, data.Head.CMD, result)
|
2025-10-23 01:02:19 +08:00
|
|
|
|
|
2025-11-18 20:52:04 +00:00
|
|
|
|
return
|
2025-10-24 00:31:38 +08:00
|
|
|
|
}
|
2025-12-23 10:46:17 +08:00
|
|
|
|
|
|
|
|
|
|
// ChangePlayerDoodle 修改玩家涂鸦,消耗50赛尔豆
|
2025-12-25 12:26:18 +08:00
|
|
|
|
// data: 包含涂鸦信息的输入数据
|
|
|
|
|
|
// player: 当前玩家对象
|
|
|
|
|
|
// 返回: 涂鸦更改结果和错误码
|
|
|
|
|
|
func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, player *player.Player) (result *user.ChangeDoodleOutboundInfo, err errorcode.ErrorCode) {
|
2025-12-23 10:46:17 +08:00
|
|
|
|
const changeDoodleCost = 50
|
|
|
|
|
|
|
2026-01-03 13:53:38 +00:00
|
|
|
|
if !player.GetCoins(changeDoodleCost) {
|
2025-12-16 02:50:10 +08:00
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
2025-11-13 21:36:18 +08:00
|
|
|
|
}
|
2025-12-23 10:46:17 +08:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
player.Info.Coins -= changeDoodleCost
|
|
|
|
|
|
player.Info.Texture = data.Id
|
|
|
|
|
|
player.Info.Color = data.Color
|
2025-12-23 10:46:17 +08:00
|
|
|
|
|
2025-11-18 20:52:04 +00:00
|
|
|
|
result = &user.ChangeDoodleOutboundInfo{
|
2025-12-25 12:26:18 +08:00
|
|
|
|
UserId: player.Info.UserID,
|
|
|
|
|
|
Color: player.Info.Color,
|
|
|
|
|
|
Coins: player.Info.Coins,
|
|
|
|
|
|
Texture: player.Info.Texture,
|
2025-11-18 20:52:04 +00:00
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
player.GetSpace().Broadcast(player, data.Head.CMD, result)
|
2025-11-18 20:52:04 +00:00
|
|
|
|
|
|
|
|
|
|
return
|
2025-10-23 01:02:19 +08:00
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 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
|
2025-10-24 00:31:38 +08:00
|
|
|
|
|
|
|
|
|
|
result = &user.ChangeNONOColorOutboundInfo{
|
2025-12-25 12:26:18 +08:00
|
|
|
|
Sataus: player.Info.UserID,
|
|
|
|
|
|
Color: player.Info.Color,
|
2025-10-24 00:31:38 +08:00
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
player.GetSpace().Broadcast(player, data.Head.CMD, result)
|
2025-11-20 05:57:29 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
|
|
|
|
|
|
// DanceAction 跳舞动作
|
|
|
|
|
|
// data: 包含跳舞类型信息的输入数据
|
|
|
|
|
|
// player: 当前玩家对象
|
|
|
|
|
|
// 返回: 跳舞动作结果和错误码
|
|
|
|
|
|
func (h Controller) DanceAction(data *user.C2SDanceAction, player *player.Player) (result *user.S2CDanceAction, err errorcode.ErrorCode) {
|
2025-10-24 00:31:38 +08:00
|
|
|
|
|
2025-11-20 05:57:29 +08:00
|
|
|
|
result = &user.S2CDanceAction{
|
|
|
|
|
|
Type: data.Type,
|
2025-12-25 12:26:18 +08:00
|
|
|
|
UserID: player.Info.UserID,
|
2025-11-20 05:57:29 +08:00
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
player.GetSpace().Broadcast(player, data.Head.CMD, result)
|
2025-11-20 05:57:29 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
|
|
|
|
|
|
// PeopleTransform 人物变形
|
|
|
|
|
|
// data: 包含变形信息的输入数据
|
|
|
|
|
|
// player: 当前玩家对象
|
|
|
|
|
|
// 返回: 变形结果和错误码
|
|
|
|
|
|
func (h Controller) PeopleTransform(data *user.C2SPEOPLE_TRANSFROM, player *player.Player) (result *user.S2CPEOPLE_TRANSFROM, err errorcode.ErrorCode) {
|
2025-11-20 05:57:29 +08:00
|
|
|
|
|
|
|
|
|
|
result = &user.S2CPEOPLE_TRANSFROM{
|
|
|
|
|
|
SuitID: data.SuitID,
|
2025-12-25 12:26:18 +08:00
|
|
|
|
UserID: player.Info.UserID,
|
2025-11-20 05:57:29 +08:00
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
player.GetSpace().Broadcast(player, data.Head.CMD, result)
|
2025-11-20 05:57:29 +08:00
|
|
|
|
return
|
2025-10-24 00:31:38 +08:00
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
|
|
|
|
|
|
// ChangePlayerCloth 更换玩家服装
|
|
|
|
|
|
// data: 包含服装信息的输入数据
|
|
|
|
|
|
// player: 当前玩家对象
|
|
|
|
|
|
// 返回: 服装更改结果和错误码
|
|
|
|
|
|
func (h Controller) ChangePlayerCloth(data *item.ChangePlayerClothInboundInfo, player *player.Player) (result *item.ChangePlayerClothOutboundInfo, err errorcode.ErrorCode) {
|
2025-11-25 12:29:50 +08:00
|
|
|
|
|
|
|
|
|
|
result = &item.ChangePlayerClothOutboundInfo{
|
2025-12-25 12:26:18 +08:00
|
|
|
|
UserID: player.Info.UserID,
|
2025-11-25 12:29:50 +08:00
|
|
|
|
ClothList: make([]model.PeopleItemInfo, 0),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
for _, clothID := range data.ClothList {
|
|
|
|
|
|
result.ClothList = append(result.ClothList, model.PeopleItemInfo{ID: clothID, Level: 1})
|
2025-11-25 12:29:50 +08:00
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
player.Info.Clothes = result.ClothList
|
2025-11-25 12:29:50 +08:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
player.GetSpace().Broadcast(player, data.Head.CMD, result)
|
2025-11-25 12:29:50 +08:00
|
|
|
|
|
|
|
|
|
|
return
|
2026-01-03 13:53:38 +00:00
|
|
|
|
}
|
2026-01-19 18:51:56 +08:00
|
|
|
|
|
|
|
|
|
|
func (h Controller) ChangePlayerName(data *user.ChangePlayerNameInboundInfo, c *player.Player) (result *user.ChangePlayerNameOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
|
|
newNickname := cool.Filter.Replace(strings.Trim(data.Nickname, "\x00"), '*')
|
|
|
|
|
|
|
|
|
|
|
|
c.Info.Nick = newNickname
|
|
|
|
|
|
result = &user.ChangePlayerNameOutboundInfo{
|
|
|
|
|
|
Nickname: newNickname,
|
|
|
|
|
|
UserID: c.Info.UserID,
|
|
|
|
|
|
}
|
|
|
|
|
|
c.GetSpace().Broadcast(c, data.Head.CMD, result)
|
|
|
|
|
|
|
|
|
|
|
|
return result, 0
|
|
|
|
|
|
}
|
|
|
|
|
|
func (h Controller) ChangeTile(data *user.ChangeTitleInboundInfo, c *player.Player) (result *user.ChangeTitleOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
|
|
result = &user.ChangeTitleOutboundInfo{
|
|
|
|
|
|
|
|
|
|
|
|
UserID: c.Info.UserID,
|
|
|
|
|
|
}
|
|
|
|
|
|
if data.TileID == 0 {
|
|
|
|
|
|
return result, 0
|
|
|
|
|
|
}
|
|
|
|
|
|
if !c.Service.Title.Can(data.TileID) {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
|
}
|
|
|
|
|
|
c.Info.Title = data.TileID
|
|
|
|
|
|
result.TileID = data.TileID
|
|
|
|
|
|
|
|
|
|
|
|
c.GetSpace().Broadcast(c, data.Head.CMD, result)
|
|
|
|
|
|
|
|
|
|
|
|
return result, 0
|
|
|
|
|
|
}
|