```
refactor(controller): 优化战斗和道具购买控制器的代码结构 - 为函数添加详细的参数和返回值注释说明 - 将参数名从通用的 'c' 重命名为更具描述性的 'player' - 重命名局部变量以提高代码可读性,如 mo -> monster, moinfo -> monsterInfo - 修复变量命名不一致问题,如 taskid -> taskID, cancpet -> canCapture - 统一变量命名规范,使用驼峰命名法 - 为 processMonID 函数添加功能说明注释 - 重命名 handleNPCFightSpecial 函数参数 petid -> petID ```
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
// processMonID 处理怪物ID字符串,如果是多个ID则随机选择一个
|
||||
func processMonID(bm string) string {
|
||||
// 按空格分割字符串
|
||||
monid := strings.Split(bm, " ")
|
||||
@@ -47,16 +48,19 @@ func processMonID(bm string) string {
|
||||
}
|
||||
|
||||
// PlayerFightBoss 挑战地图boss
|
||||
func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
if !c.CanFight() {
|
||||
// data: 包含挑战Boss信息的输入数据
|
||||
// player: 当前玩家对象
|
||||
// 返回: 战斗结果和错误码
|
||||
func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, p *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
if !p.CanFight() {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
var mo *model.PetInfo
|
||||
moinfo := &model.PlayerInfo{}
|
||||
var monster *model.PetInfo
|
||||
monsterInfo := &model.PlayerInfo{}
|
||||
|
||||
var taskid int
|
||||
var cancpet int
|
||||
mdata, ok := xmlres.MonsterMap[int(c.Info.MapID)]
|
||||
var taskID int
|
||||
var canCapture int
|
||||
mdata, ok := xmlres.MonsterMap[int(p.Info.MapID)]
|
||||
if !ok {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
@@ -72,21 +76,21 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *pla
|
||||
|
||||
if (bc.Id == nil && data.BossId == 0) || uint32(*bc.Id) == data.BossId { //打默认第一个boss
|
||||
if bc.TaskID != nil {
|
||||
taskid = *bc.TaskID
|
||||
taskID = *bc.TaskID
|
||||
}
|
||||
|
||||
for i, bm := range bc.BossMon {
|
||||
|
||||
mo = model.GenPetInfo(
|
||||
monster = model.GenPetInfo(
|
||||
gconv.Int(processMonID(bm.MonID)), 24, //24个体
|
||||
-1,
|
||||
0, //野怪没特性
|
||||
|
||||
bm.Lv, nil)
|
||||
mo.CatchTime = uint32(i)
|
||||
monster.CatchTime = uint32(i)
|
||||
if bm.Hp != 0 {
|
||||
mo.Hp = uint32(bm.Hp)
|
||||
mo.MaxHp = uint32(bm.Hp)
|
||||
monster.Hp = uint32(bm.Hp)
|
||||
monster.MaxHp = uint32(bm.Hp)
|
||||
}
|
||||
|
||||
for _, v := range strings.Split(bm.NewSeIdxs, " ") {
|
||||
@@ -98,54 +102,54 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *pla
|
||||
}
|
||||
|
||||
EID, args := service.NewEffectService().Args(uint32(idx))
|
||||
mo.EffectInfo = append(mo.EffectInfo, model.PetEffectInfo{
|
||||
monster.EffectInfo = append(monster.EffectInfo, model.PetEffectInfo{
|
||||
Idx: idx,
|
||||
EID: gconv.Uint16(EID),
|
||||
Args: gconv.Ints(args),
|
||||
})
|
||||
}
|
||||
moinfo.PetList = append(moinfo.PetList, *mo)
|
||||
monsterInfo.PetList = append(monsterInfo.PetList, *monster)
|
||||
}
|
||||
if bc.BossCatchable == 1 {
|
||||
cancpet = xmlres.PetMAP[int(mo.ID)].CatchRate
|
||||
canCapture = xmlres.PetMAP[int(monster.ID)].CatchRate
|
||||
}
|
||||
moinfo.Nick = bc.Name //xmlres.PetMAP[int(mo.ID)].DefName
|
||||
monsterInfo.Nick = bc.Name //xmlres.PetMAP[int(monster.ID)].DefName
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
if len(moinfo.PetList) == 0 {
|
||||
if len(monsterInfo.PetList) == 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
c.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC
|
||||
c.Fightinfo.Mode = info.BattleMode.MULTI_MODE
|
||||
p.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC
|
||||
p.Fightinfo.Mode = info.BattleMode.MULTI_MODE
|
||||
|
||||
ai := player.NewAI_player(moinfo)
|
||||
ai.CanCapture = cancpet
|
||||
ai := player.NewAI_player(monsterInfo)
|
||||
ai.CanCapture = canCapture
|
||||
ai.Prop[0] = 2
|
||||
fight.NewFight(c, ai, func(foi *info.FightOverInfo) {
|
||||
if taskid != 0 {
|
||||
if foi.Reason == 0 && foi.WinnerId == c.Info.UserID {
|
||||
if c.Info.GetTask(taskid) == model.Unaccepted {
|
||||
c.Info.SetTask(taskid, model.Completed) //设置完成任务
|
||||
fight.NewFight(p, ai, func(foi *info.FightOverInfo) {
|
||||
if taskID != 0 {
|
||||
if foi.Reason == 0 && foi.WinnerId == p.Info.UserID {
|
||||
if p.Info.GetTask(taskID) == model.Unaccepted {
|
||||
p.Info.SetTask(taskID, model.Completed) //设置完成任务
|
||||
|
||||
moinfo.PetList[0].Downgrade(1)
|
||||
PetID := moinfo.PetList[0].ID
|
||||
monsterInfo.PetList[0].Downgrade(1)
|
||||
petID := monsterInfo.PetList[0].ID
|
||||
|
||||
newm1 := model.GenPetInfo(int(PetID), -1, -1, 0, 1, nil)
|
||||
c.Service.Pet.PetAdd(newm1)
|
||||
newPet := model.GenPetInfo(int(petID), -1, -1, 0, 1, nil)
|
||||
p.Service.Pet.PetAdd(newPet)
|
||||
|
||||
c.SendPackCmd(8004, &info.S2C_GET_BOSS_MONSTER{
|
||||
BonusID: uint32(taskid),
|
||||
PetID: PetID,
|
||||
CaptureTm: newm1.CatchTime,
|
||||
p.SendPackCmd(8004, &info.S2C_GET_BOSS_MONSTER{
|
||||
BonusID: uint32(taskID),
|
||||
PetID: petID,
|
||||
CaptureTm: newPet.CatchTime,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
c.Done.Exec(model.MilestoneMode.BOSS, []uint32{c.Info.MapID, data.BossId, uint32(foi.Reason)}, nil)
|
||||
p.Done.Exec(model.MilestoneMode.BOSS, []uint32{p.Info.MapID, data.BossId, uint32(foi.Reason)}, nil)
|
||||
|
||||
})
|
||||
|
||||
@@ -153,73 +157,78 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *pla
|
||||
}
|
||||
|
||||
// OnPlayerFightNpcMonster 战斗野怪
|
||||
func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
if !c.CanFight() {
|
||||
// data: 包含战斗野怪信息的输入数据
|
||||
// player: 当前玩家对象
|
||||
// 返回: 战斗结果和错误码
|
||||
func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, p *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
if !p.CanFight() {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
refpet := c.OgreInfo.Data[data.Number]
|
||||
if refpet.Id == 0 {
|
||||
refPet := p.OgreInfo.Data[data.Number]
|
||||
if refPet.Id == 0 {
|
||||
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
if refpet.Ext != 0 {
|
||||
refpet.Id = refpet.Ext
|
||||
if refPet.Ext != 0 {
|
||||
refPet.Id = refPet.Ext
|
||||
}
|
||||
mo := model.GenPetInfo(
|
||||
int(refpet.Id), -1,
|
||||
monster := model.GenPetInfo(
|
||||
int(refPet.Id), -1,
|
||||
-1,
|
||||
0, //野怪没特性
|
||||
|
||||
int(refpet.Lv),
|
||||
refpet.ShinyInfo)
|
||||
int(refPet.Lv),
|
||||
refPet.ShinyInfo)
|
||||
|
||||
moinfo := &model.PlayerInfo{}
|
||||
moinfo.Nick = xmlres.PetMAP[int(mo.ID)].DefName
|
||||
moinfo.PetList = append(moinfo.PetList, *mo)
|
||||
ai := player.NewAI_player(moinfo)
|
||||
ai.CanCapture = handleNPCFightSpecial(mo.ID)
|
||||
monsterInfo := &model.PlayerInfo{}
|
||||
monsterInfo.Nick = xmlres.PetMAP[int(monster.ID)].DefName
|
||||
monsterInfo.PetList = append(monsterInfo.PetList, *monster)
|
||||
ai := player.NewAI_player(monsterInfo)
|
||||
ai.CanCapture = handleNPCFightSpecial(monster.ID)
|
||||
|
||||
c.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC //打野怪
|
||||
c.Fightinfo.Mode = info.BattleMode.MULTI_MODE //多人模式
|
||||
p.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC //打野怪
|
||||
p.Fightinfo.Mode = info.BattleMode.MULTI_MODE //多人模式
|
||||
|
||||
fight.NewFight(c, ai, func(foi *info.FightOverInfo) {
|
||||
c.Done.Exec(model.MilestoneMode.Moster, []uint32{c.Info.MapID, moinfo.PetList[0].ID, uint32(foi.Reason)}, nil)
|
||||
if foi.Reason == 0 && foi.WinnerId == c.Info.UserID {
|
||||
fight.NewFight(p, ai, func(foi *info.FightOverInfo) {
|
||||
p.Done.Exec(model.MilestoneMode.Moster, []uint32{p.Info.MapID, monsterInfo.PetList[0].ID, uint32(foi.Reason)}, nil)
|
||||
if foi.Reason == 0 && foi.WinnerId == p.Info.UserID {
|
||||
|
||||
if !c.CanGetExp() {
|
||||
if !p.CanGetExp() {
|
||||
return
|
||||
}
|
||||
exp := uint32(xmlres.PetMAP[int(mo.ID)].YieldingExp) * mo.Level / 7
|
||||
exp := uint32(xmlres.PetMAP[int(monster.ID)].YieldingExp) * monster.Level / 7
|
||||
items := &info.S2C_GET_BOSS_MONSTER{
|
||||
//EV: 45,
|
||||
EXP: exp * 2,
|
||||
}
|
||||
if refpet.Item != 0 {
|
||||
c.ItemAdd(refpet.Item, uint32(grand.Intn(2)+1))
|
||||
if refPet.Item != 0 {
|
||||
p.ItemAdd(refPet.Item, uint32(grand.Intn(2)+1))
|
||||
items.ItemList = append(items.ItemList, model.ItemInfo{
|
||||
ItemId: refpet.Item,
|
||||
ItemId: refPet.Item,
|
||||
ItemCnt: uint32(grand.Intn(2) + 1),
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
evs := gconv.Uint32s(strings.Split(xmlres.PetMAP[int(mo.ID)].YieldingEV, " "))
|
||||
evs := gconv.Uint32s(strings.Split(xmlres.PetMAP[int(monster.ID)].YieldingEV, " "))
|
||||
items.EV = lo.Sum(evs) - 1
|
||||
c.Info.EVPool += lo.Sum(evs) //给予累计学习力
|
||||
p.Info.EVPool += lo.Sum(evs) //给予累计学习力
|
||||
foi.Winpet.AddEV(evs)
|
||||
|
||||
c.Info.ExpPool += exp * 4
|
||||
c.AddPetExp(foi.Winpet, uint32(exp)*2)
|
||||
c.SendPackCmd(8004, items)
|
||||
p.Info.ExpPool += exp * 4
|
||||
p.AddPetExp(foi.Winpet, uint32(exp)*2)
|
||||
p.SendPackCmd(8004, items)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
return nil, -1
|
||||
}
|
||||
func handleNPCFightSpecial(petid uint32) int {
|
||||
|
||||
npcPetID := int(petid)
|
||||
// handleNPCFightSpecial 处理NPC战斗特殊情况
|
||||
func handleNPCFightSpecial(petID uint32) int {
|
||||
|
||||
npcPetID := int(petID)
|
||||
petCfg, ok := xmlres.PetMAP[npcPetID]
|
||||
if !ok {
|
||||
// log.Error(context.Background(), "NPC宠物配置不存在", "petID", npcPetID)
|
||||
|
||||
@@ -13,48 +13,54 @@ import (
|
||||
// 防止封包通过领取来获取道具
|
||||
|
||||
// BuyItem 购买单个道具
|
||||
func (h Controller) BuyItem(data *item.BuyInboundInfo, c *player.Player) (result *item.BuyOutboundInfo, err errorcode.ErrorCode) {
|
||||
// data: 包含购买道具信息的输入数据
|
||||
// player: 当前玩家对象
|
||||
// 返回: 购买结果和错误码
|
||||
func (h Controller) BuyItem(data *item.BuyInboundInfo, player *player.Player) (result *item.BuyOutboundInfo, err errorcode.ErrorCode) {
|
||||
itemInfo, exists := xmlres.ItemsMAP[int(data.ItemId)]
|
||||
if !exists {
|
||||
return &item.BuyOutboundInfo{Coins: c.Info.Coins}, 0
|
||||
return &item.BuyOutboundInfo{Coins: player.Info.Coins}, 0
|
||||
}
|
||||
|
||||
// 免费道具直接添加
|
||||
if itemInfo.Price == 0 {
|
||||
if c.ItemAdd(data.ItemId, data.Count) {
|
||||
if player.ItemAdd(data.ItemId, data.Count) {
|
||||
return &item.BuyOutboundInfo{
|
||||
ItemId: data.ItemId,
|
||||
Level: 1,
|
||||
Count: data.Count,
|
||||
Coins: c.Info.Coins,
|
||||
Coins: player.Info.Coins,
|
||||
}, 0
|
||||
}
|
||||
return &item.BuyOutboundInfo{Coins: c.Info.Coins}, 0
|
||||
return &item.BuyOutboundInfo{Coins: player.Info.Coins}, 0
|
||||
}
|
||||
|
||||
// 需要付费的道具
|
||||
totalCost := data.Count * uint32(itemInfo.Price)
|
||||
if !c.UseCoins(totalCost) {
|
||||
return &item.BuyOutboundInfo{Coins: c.Info.Coins}, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
||||
if !player.UseCoins(totalCost) {
|
||||
return &item.BuyOutboundInfo{Coins: player.Info.Coins}, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
||||
}
|
||||
|
||||
if c.ItemAdd(data.ItemId, data.Count) {
|
||||
c.Info.Coins -= totalCost
|
||||
if player.ItemAdd(data.ItemId, data.Count) {
|
||||
player.Info.Coins -= totalCost
|
||||
return &item.BuyOutboundInfo{
|
||||
ItemId: data.ItemId,
|
||||
Level: 1,
|
||||
Count: data.Count,
|
||||
Coins: c.Info.Coins,
|
||||
Coins: player.Info.Coins,
|
||||
}, 0
|
||||
}
|
||||
|
||||
// 购买失败,返还赛尔豆
|
||||
c.Info.Coins += totalCost
|
||||
return &item.BuyOutboundInfo{Coins: c.Info.Coins}, 0
|
||||
player.Info.Coins += totalCost
|
||||
return &item.BuyOutboundInfo{Coins: player.Info.Coins}, 0
|
||||
}
|
||||
|
||||
// BuyMultipleItems 批量购买道具
|
||||
func (h Controller) BuyMultipleItems(data *item.BuyMultiInboundInfo, c *player.Player) (result *item.BuyMultiOutboundInfo, err errorcode.ErrorCode) {
|
||||
// data: 包含批量购买道具信息的输入数据
|
||||
// player: 当前玩家对象
|
||||
// 返回: 批量购买结果和错误码
|
||||
func (h Controller) BuyMultipleItems(data *item.BuyMultiInboundInfo, player *player.Player) (result *item.BuyMultiOutboundInfo, err errorcode.ErrorCode) {
|
||||
for _, itemID := range data.ItemIds {
|
||||
itemInfo, exists := xmlres.ItemsMAP[int(itemID)]
|
||||
if !exists {
|
||||
@@ -63,54 +69,57 @@ func (h Controller) BuyMultipleItems(data *item.BuyMultiInboundInfo, c *player.P
|
||||
|
||||
// 免费道具直接添加
|
||||
if itemInfo.Price == 0 {
|
||||
c.ItemAdd(itemID, 1)
|
||||
player.ItemAdd(itemID, 1)
|
||||
continue
|
||||
}
|
||||
|
||||
// 需要付费的道具
|
||||
if !c.UseCoins(uint32(itemInfo.Price)) {
|
||||
if !player.UseCoins(uint32(itemInfo.Price)) {
|
||||
break
|
||||
}
|
||||
|
||||
if c.ItemAdd(itemID, 1) {
|
||||
c.Info.Coins -= uint32(itemInfo.Price)
|
||||
if player.ItemAdd(itemID, 1) {
|
||||
player.Info.Coins -= uint32(itemInfo.Price)
|
||||
}
|
||||
}
|
||||
|
||||
return &item.BuyMultiOutboundInfo{
|
||||
Coins: c.Info.Coins,
|
||||
Coins: player.Info.Coins,
|
||||
}, 0
|
||||
}
|
||||
|
||||
// BuyGoldItem 使用金豆购买商品
|
||||
func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, c *player.Player) (result *item.S2C_GoldBuyProductInfo, err errorcode.ErrorCode) {
|
||||
// data: 包含金豆购买商品信息的输入数据
|
||||
// player: 当前玩家对象
|
||||
// 返回: 金豆购买结果和错误码
|
||||
func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, player *player.Player) (result *item.S2C_GoldBuyProductInfo, err errorcode.ErrorCode) {
|
||||
product, exists := xmlres.GoldProductMap[int(data.ProductID)]
|
||||
if !exists {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
|
||||
useGold := uint32(data.Count) * uint32(gconv.Float64(product.Price)*100)
|
||||
if !c.UseGold(useGold) {
|
||||
if !player.UseGold(useGold) {
|
||||
return &item.S2C_GoldBuyProductInfo{
|
||||
Gold: c.User.GetGold(uint(c.Info.UserID)),
|
||||
Gold: player.User.GetGold(uint(player.Info.UserID)),
|
||||
PayGold: 0,
|
||||
Reserved: 0,
|
||||
}, errorcode.ErrorCodes.ErrXinDouInsufficient
|
||||
}
|
||||
|
||||
addSuccess := c.ItemAdd(uint32(gconv.Uint32(product.ItemID)), uint32(data.Count))
|
||||
addSuccess := player.ItemAdd(uint32(gconv.Uint32(product.ItemID)), uint32(data.Count))
|
||||
if addSuccess {
|
||||
c.User.UpdateGold(c.Info.UserID, -int64(useGold))
|
||||
player.User.UpdateGold(player.Info.UserID, -int64(useGold))
|
||||
return &item.S2C_GoldBuyProductInfo{
|
||||
Gold: c.User.GetGold(uint(c.Info.UserID)),
|
||||
Gold: player.User.GetGold(uint(player.Info.UserID)),
|
||||
PayGold: useGold,
|
||||
Reserved: 0,
|
||||
}, 0
|
||||
}
|
||||
|
||||
return &item.S2C_GoldBuyProductInfo{
|
||||
Gold: c.User.GetGold(uint(c.Info.UserID)),
|
||||
Gold: player.User.GetGold(uint(player.Info.UserID)),
|
||||
PayGold: 0,
|
||||
Reserved: 0,
|
||||
}, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user