2025-11-14 23:09:16 +08:00
|
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2025-12-26 20:38:08 +08:00
|
|
|
|
"blazing/common/data"
|
2025-11-14 23:09:16 +08:00
|
|
|
|
"blazing/common/data/xmlres"
|
|
|
|
|
|
"blazing/common/socket/errorcode"
|
2025-11-16 11:56:57 +08:00
|
|
|
|
"strings"
|
2025-11-15 22:17:43 +00:00
|
|
|
|
|
2025-11-14 23:09:16 +08:00
|
|
|
|
"blazing/logic/service/fight"
|
|
|
|
|
|
"blazing/logic/service/fight/info"
|
2025-11-15 22:17:43 +00:00
|
|
|
|
|
2025-11-14 23:09:16 +08:00
|
|
|
|
"blazing/logic/service/player"
|
|
|
|
|
|
"blazing/modules/blazing/model"
|
2025-12-21 17:18:33 +00:00
|
|
|
|
"blazing/modules/config/service"
|
2025-11-14 23:09:16 +08:00
|
|
|
|
|
|
|
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
2025-11-22 22:57:32 +08:00
|
|
|
|
"github.com/gogf/gf/v2/util/grand"
|
2025-11-25 00:55:10 +08:00
|
|
|
|
"github.com/samber/lo"
|
2025-11-14 23:09:16 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
// processMonID 处理怪物ID字符串,如果是多个ID则随机选择一个
|
2025-11-16 11:56:57 +08:00
|
|
|
|
func processMonID(bm string) string {
|
|
|
|
|
|
// 按空格分割字符串
|
|
|
|
|
|
monid := strings.Split(bm, " ")
|
|
|
|
|
|
|
|
|
|
|
|
// 过滤分割后可能的空字符串(如连续空格导致的空元素)
|
|
|
|
|
|
filtered := make([]string, 0, len(monid))
|
|
|
|
|
|
for _, m := range monid {
|
|
|
|
|
|
if m != "" {
|
|
|
|
|
|
filtered = append(filtered, m)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
monid = filtered
|
|
|
|
|
|
|
|
|
|
|
|
var selected string
|
|
|
|
|
|
switch len(monid) {
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
// 无元素时,可返回空或默认值(根据业务需求调整)
|
|
|
|
|
|
selected = ""
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
// 长度为1时,取第一个(唯一的元素)
|
|
|
|
|
|
selected = monid[0]
|
|
|
|
|
|
default:
|
|
|
|
|
|
// 长度大于1时,随机选取一个
|
2025-11-23 23:38:03 +00:00
|
|
|
|
randomIdx := grand.Intn(len(monid))
|
2025-11-16 11:56:57 +08:00
|
|
|
|
selected = monid[randomIdx]
|
|
|
|
|
|
}
|
|
|
|
|
|
return selected
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-23 10:46:17 +08:00
|
|
|
|
// PlayerFightBoss 挑战地图boss
|
2025-12-25 12:26:18 +08:00
|
|
|
|
// data: 包含挑战Boss信息的输入数据
|
|
|
|
|
|
// player: 当前玩家对象
|
|
|
|
|
|
// 返回: 战斗结果和错误码
|
|
|
|
|
|
func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, p *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
|
|
if !p.CanFight() {
|
2025-12-01 23:31:48 +08:00
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
var monster *model.PetInfo
|
|
|
|
|
|
monsterInfo := &model.PlayerInfo{}
|
2025-11-14 23:09:16 +08:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
var taskID int
|
|
|
|
|
|
var canCapture int
|
|
|
|
|
|
mdata, ok := xmlres.MonsterMap[int(p.Info.MapID)]
|
2025-11-16 11:56:57 +08:00
|
|
|
|
if !ok {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
|
|
|
|
|
if len(mdata.Bosses) == 0 {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
|
|
|
|
|
for _, bc := range mdata.Bosses {
|
2025-11-20 15:19:13 +08:00
|
|
|
|
|
|
|
|
|
|
if bc.Id == nil {
|
|
|
|
|
|
|
|
|
|
|
|
bc.Id = gconv.PtrInt(0)
|
|
|
|
|
|
}
|
2025-11-14 23:09:16 +08:00
|
|
|
|
|
2025-11-22 22:57:32 +08:00
|
|
|
|
if (bc.Id == nil && data.BossId == 0) || uint32(*bc.Id) == data.BossId { //打默认第一个boss
|
|
|
|
|
|
if bc.TaskID != nil {
|
2025-12-25 12:26:18 +08:00
|
|
|
|
taskID = *bc.TaskID
|
2025-11-22 22:57:32 +08:00
|
|
|
|
}
|
2025-11-25 02:35:36 +08:00
|
|
|
|
|
2025-11-26 15:25:10 +08:00
|
|
|
|
for i, bm := range bc.BossMon {
|
2025-11-14 23:09:16 +08:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
monster = model.GenPetInfo(
|
2025-11-16 11:56:57 +08:00
|
|
|
|
gconv.Int(processMonID(bm.MonID)), 24, //24个体
|
|
|
|
|
|
-1,
|
|
|
|
|
|
0, //野怪没特性
|
2025-12-14 19:23:26 +08:00
|
|
|
|
|
|
|
|
|
|
bm.Lv, nil)
|
2025-12-25 12:26:18 +08:00
|
|
|
|
monster.CatchTime = uint32(i)
|
2025-12-09 14:52:55 +08:00
|
|
|
|
if bm.Hp != 0 {
|
2025-12-25 12:26:18 +08:00
|
|
|
|
monster.Hp = uint32(bm.Hp)
|
|
|
|
|
|
monster.MaxHp = uint32(bm.Hp)
|
2025-12-09 14:52:55 +08:00
|
|
|
|
}
|
2025-11-14 23:09:16 +08:00
|
|
|
|
|
2025-11-25 18:25:52 +08:00
|
|
|
|
for _, v := range strings.Split(bm.NewSeIdxs, " ") {
|
2025-11-26 15:25:10 +08:00
|
|
|
|
idx := gconv.Uint16(v)
|
2025-12-08 00:17:04 +08:00
|
|
|
|
// eff := xmlres.EffectMAP[int(idx)]
|
|
|
|
|
|
// args := strings.Split(eff.Args, " ")
|
2025-12-09 11:19:15 +08:00
|
|
|
|
if idx == 0 {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
2025-12-08 00:17:04 +08:00
|
|
|
|
|
2025-12-22 14:10:22 +00:00
|
|
|
|
EID, args := service.NewEffectService().Args(uint32(idx))
|
2025-12-25 12:26:18 +08:00
|
|
|
|
monster.EffectInfo = append(monster.EffectInfo, model.PetEffectInfo{
|
2025-11-26 15:25:10 +08:00
|
|
|
|
Idx: idx,
|
2025-12-08 00:17:04 +08:00
|
|
|
|
EID: gconv.Uint16(EID),
|
2025-11-26 15:25:10 +08:00
|
|
|
|
Args: gconv.Ints(args),
|
2025-11-25 18:25:52 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
monsterInfo.PetList = append(monsterInfo.PetList, *monster)
|
2025-11-14 23:09:16 +08:00
|
|
|
|
}
|
2025-11-25 02:35:36 +08:00
|
|
|
|
if bc.BossCatchable == 1 {
|
2025-12-25 12:26:18 +08:00
|
|
|
|
canCapture = xmlres.PetMAP[int(monster.ID)].CatchRate
|
2025-11-25 02:35:36 +08:00
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
monsterInfo.Nick = bc.Name //xmlres.PetMAP[int(monster.ID)].DefName
|
2025-11-16 11:56:57 +08:00
|
|
|
|
break
|
2025-11-14 23:09:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
if len(monsterInfo.PetList) == 0 {
|
2025-11-25 18:25:52 +08:00
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
p.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC
|
|
|
|
|
|
p.Fightinfo.Mode = info.BattleMode.MULTI_MODE
|
2025-11-19 16:11:02 +08:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
ai := player.NewAI_player(monsterInfo)
|
|
|
|
|
|
ai.CanCapture = canCapture
|
2025-11-26 15:25:10 +08:00
|
|
|
|
ai.Prop[0] = 2
|
2025-12-25 12:26:18 +08:00
|
|
|
|
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) //设置完成任务
|
|
|
|
|
|
|
|
|
|
|
|
monsterInfo.PetList[0].Downgrade(1)
|
|
|
|
|
|
petID := monsterInfo.PetList[0].ID
|
|
|
|
|
|
|
|
|
|
|
|
newPet := model.GenPetInfo(int(petID), -1, -1, 0, 1, nil)
|
|
|
|
|
|
p.Service.Pet.PetAdd(newPet)
|
|
|
|
|
|
|
|
|
|
|
|
p.SendPackCmd(8004, &info.S2C_GET_BOSS_MONSTER{
|
|
|
|
|
|
BonusID: uint32(taskID),
|
|
|
|
|
|
PetID: petID,
|
|
|
|
|
|
CaptureTm: newPet.CatchTime,
|
2025-11-22 22:57:32 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-11-26 15:25:10 +08:00
|
|
|
|
|
2025-11-22 22:57:32 +08:00
|
|
|
|
}
|
2025-11-26 15:25:10 +08:00
|
|
|
|
}
|
2025-11-22 22:57:32 +08:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
p.Done.Exec(model.MilestoneMode.BOSS, []uint32{p.Info.MapID, data.BossId, uint32(foi.Reason)}, nil)
|
2025-11-15 23:02:46 +00:00
|
|
|
|
|
|
|
|
|
|
})
|
2025-11-14 23:09:16 +08:00
|
|
|
|
|
|
|
|
|
|
return nil, -1
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-23 10:46:17 +08:00
|
|
|
|
// OnPlayerFightNpcMonster 战斗野怪
|
2025-12-25 12:26:18 +08:00
|
|
|
|
// data: 包含战斗野怪信息的输入数据
|
|
|
|
|
|
// player: 当前玩家对象
|
|
|
|
|
|
// 返回: 战斗结果和错误码
|
2025-12-26 20:38:08 +08:00
|
|
|
|
func (h Controller) OnPlayerFightNpcMonster(data1 *fight.FightNpcMonsterInboundInfo, p *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-12-25 12:26:18 +08:00
|
|
|
|
if !p.CanFight() {
|
2025-12-01 23:31:48 +08:00
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
|
}
|
2025-12-28 23:16:59 +08:00
|
|
|
|
refPet := p.OgreInfo.Data[data1.Number]
|
2025-12-25 12:26:18 +08:00
|
|
|
|
if refPet.Id == 0 {
|
2025-11-14 23:09:16 +08:00
|
|
|
|
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
if refPet.Ext != 0 {
|
|
|
|
|
|
refPet.Id = refPet.Ext
|
2025-12-10 13:54:51 +00:00
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
monster := model.GenPetInfo(
|
|
|
|
|
|
int(refPet.Id), -1,
|
2025-11-14 23:09:16 +08:00
|
|
|
|
-1,
|
|
|
|
|
|
0, //野怪没特性
|
2025-12-14 19:23:26 +08:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
int(refPet.Lv),
|
|
|
|
|
|
refPet.ShinyInfo)
|
2025-11-14 23:09:16 +08:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
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)
|
2025-11-19 16:11:02 +08:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
p.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC //打野怪
|
|
|
|
|
|
p.Fightinfo.Mode = info.BattleMode.MULTI_MODE //多人模式
|
2025-11-14 23:09:16 +08:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
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 {
|
2025-11-25 00:55:10 +08:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
if !p.CanGetExp() {
|
2025-12-01 23:31:48 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
exp := uint32(xmlres.PetMAP[int(monster.ID)].YieldingExp) * monster.Level / 7
|
2025-12-01 23:31:48 +08:00
|
|
|
|
items := &info.S2C_GET_BOSS_MONSTER{
|
|
|
|
|
|
//EV: 45,
|
|
|
|
|
|
EXP: exp * 2,
|
|
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
if refPet.Item != 0 {
|
|
|
|
|
|
p.ItemAdd(refPet.Item, uint32(grand.Intn(2)+1))
|
2025-12-26 20:38:08 +08:00
|
|
|
|
items.ItemList = append(items.ItemList, data.ItemInfo{
|
2025-12-25 12:26:18 +08:00
|
|
|
|
ItemId: refPet.Item,
|
2025-12-01 23:31:48 +08:00
|
|
|
|
ItemCnt: uint32(grand.Intn(2) + 1),
|
|
|
|
|
|
})
|
2025-11-25 00:55:10 +08:00
|
|
|
|
|
2025-11-22 22:57:32 +08:00
|
|
|
|
}
|
2025-11-15 23:02:46 +00:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
evs := gconv.Uint32s(strings.Split(xmlres.PetMAP[int(monster.ID)].YieldingEV, " "))
|
2025-12-03 22:05:28 +08:00
|
|
|
|
items.EV = lo.Sum(evs) - 1
|
2025-12-25 12:26:18 +08:00
|
|
|
|
p.Info.EVPool += lo.Sum(evs) //给予累计学习力
|
2025-12-01 23:31:48 +08:00
|
|
|
|
foi.Winpet.AddEV(evs)
|
|
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
p.Info.ExpPool += exp * 4
|
|
|
|
|
|
p.AddPetExp(foi.Winpet, uint32(exp)*2)
|
|
|
|
|
|
p.SendPackCmd(8004, items)
|
2025-12-01 23:31:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-15 23:02:46 +00:00
|
|
|
|
})
|
2025-11-14 23:09:16 +08:00
|
|
|
|
|
|
|
|
|
|
return nil, -1
|
|
|
|
|
|
}
|
2025-11-21 02:40:27 +08:00
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
// handleNPCFightSpecial 处理NPC战斗特殊情况
|
|
|
|
|
|
func handleNPCFightSpecial(petID uint32) int {
|
|
|
|
|
|
|
|
|
|
|
|
npcPetID := int(petID)
|
2025-11-21 02:40:27 +08:00
|
|
|
|
petCfg, ok := xmlres.PetMAP[npcPetID]
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
// log.Error(context.Background(), "NPC宠物配置不存在", "petID", npcPetID)
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
catchRate := gconv.Int(petCfg.CatchRate)
|
|
|
|
|
|
return catchRate
|
|
|
|
|
|
}
|