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"
|
2025-12-21 17:18:33 +00:00
|
|
|
|
"blazing/modules/config/service"
|
2026-01-19 18:51:56 +08:00
|
|
|
|
"blazing/modules/player/model"
|
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-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: 当前玩家对象
|
|
|
|
|
|
// 返回: 战斗结果和错误码
|
2026-01-25 03:40:29 +08:00
|
|
|
|
func (Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, p *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-12-25 12:26:18 +08:00
|
|
|
|
if !p.CanFight() {
|
2026-01-20 02:25:02 +08:00
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNoStamina
|
2025-12-01 23:31:48 +08:00
|
|
|
|
}
|
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
|
|
|
|
|
2026-02-14 03:05:51 +08:00
|
|
|
|
dv := 24
|
|
|
|
|
|
if bc.BossCatchable == 1 {
|
|
|
|
|
|
dv = -1
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-25 12:26:18 +08:00
|
|
|
|
monster = model.GenPetInfo(
|
2026-02-14 03:05:51 +08:00
|
|
|
|
gconv.Int(processMonID(bm.MonID)), dv, //24个体
|
2025-11-16 11:56:57 +08:00
|
|
|
|
-1,
|
|
|
|
|
|
0, //野怪没特性
|
2025-12-14 19:23:26 +08:00
|
|
|
|
|
2026-02-08 17:57:42 +08:00
|
|
|
|
bm.Lv, nil, 0)
|
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-30 00:10:59 +08:00
|
|
|
|
|
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
|
2026-02-21 17:32:40 +08:00
|
|
|
|
if grand.Meet(1, 500) {
|
|
|
|
|
|
monsterInfo.PetList[0].RandomByWeightShiny()
|
|
|
|
|
|
}
|
2025-12-30 00:10:59 +08:00
|
|
|
|
|
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
|
2026-01-03 02:18:31 +08:00
|
|
|
|
fight.NewFight(p, ai, func(foi info.FightOverInfo) {
|
2025-12-25 12:26:18 +08:00
|
|
|
|
if taskID != 0 {
|
|
|
|
|
|
if foi.Reason == 0 && foi.WinnerId == p.Info.UserID {
|
2026-01-20 04:40:36 +08:00
|
|
|
|
p.SptCompletedTask(taskID, 1)
|
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
|
|
|
|
|
2026-01-19 18:51:56 +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: 当前玩家对象
|
|
|
|
|
|
// 返回: 战斗结果和错误码
|
2026-01-25 03:40:29 +08:00
|
|
|
|
func (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
|
|
|
|
|
|
}
|
2026-02-09 01:29:33 +08:00
|
|
|
|
if data1.Number > 9 {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
|
}
|
2026-02-23 04:12:12 +08:00
|
|
|
|
refPet := p.Data[data1.Number]
|
2026-02-08 17:57:42 +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 {
|
2026-02-08 17:57:42 +08:00
|
|
|
|
refPet.ID = refPet.Ext
|
2026-01-01 00:30:09 +08:00
|
|
|
|
|
2025-12-10 13:54:51 +00:00
|
|
|
|
}
|
2025-12-25 12:26:18 +08:00
|
|
|
|
monster := model.GenPetInfo(
|
2026-02-08 17:57:42 +08:00
|
|
|
|
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),
|
2026-02-08 17:57:42 +08:00
|
|
|
|
refPet.ShinyInfo, -1)
|
2026-02-18 22:07:50 +08:00
|
|
|
|
monster.CatchMap = p.Info.MapID //设置当前地图
|
2026-01-01 00:30:09 +08:00
|
|
|
|
if refPet.Ext != 0 {
|
2026-02-21 17:32:40 +08:00
|
|
|
|
if grand.Meet(1, 500) {
|
|
|
|
|
|
monster.RandomByWeightShiny()
|
|
|
|
|
|
}
|
2026-01-01 00:30:09 +08:00
|
|
|
|
}
|
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
|
|
|
|
|
2026-01-03 02:18:31 +08:00
|
|
|
|
fight.NewFight(p, ai, func(foi info.FightOverInfo) {
|
2026-01-19 18:51:56 +08:00
|
|
|
|
//p.Done.Exec(model.MilestoneMode.Moster, []uint32{p.Info.MapID, monsterInfo.PetList[0].ID, uint32(foi.Reason)}, nil)
|
2025-12-25 12:26:18 +08:00
|
|
|
|
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
|
|
|
|
exp := uint32(xmlres.PetMAP[int(monster.ID)].YieldingExp) * monster.Level / 7
|
2026-02-16 03:02:59 +08:00
|
|
|
|
addlevel, poolevel := p.CanGetExp()
|
2026-02-16 03:33:41 +08:00
|
|
|
|
addexp := gconv.Float32(addlevel * gconv.Float32(exp))
|
2026-02-19 16:02:23 +08:00
|
|
|
|
if addexp != 0 {
|
|
|
|
|
|
poolexp := gconv.Float32(poolevel) * gconv.Float32((exp))
|
|
|
|
|
|
items := &info.S2C_GET_BOSS_MONSTER{}
|
|
|
|
|
|
|
|
|
|
|
|
p.ItemAdd(3, int64(poolexp+addexp))
|
2025-12-26 20:38:08 +08:00
|
|
|
|
items.ItemList = append(items.ItemList, data.ItemInfo{
|
2026-02-19 16:02:23 +08:00
|
|
|
|
ItemId: 3,
|
|
|
|
|
|
ItemCnt: int64(poolexp),
|
2025-12-01 23:31:48 +08:00
|
|
|
|
})
|
2026-02-19 16:02:23 +08:00
|
|
|
|
p.AddPetExp(foi.Winpet, int64(addexp))
|
2026-02-23 03:56:27 +08:00
|
|
|
|
for _, v := range refPet.Item {
|
2026-02-19 16:02:23 +08:00
|
|
|
|
count := int64(grand.Intn(2) + 1)
|
2026-02-23 03:56:27 +08:00
|
|
|
|
ok := p.ItemAdd(v, count)
|
|
|
|
|
|
if ok {
|
|
|
|
|
|
items.ItemList = append(items.ItemList, data.ItemInfo{
|
|
|
|
|
|
ItemId: v,
|
|
|
|
|
|
ItemCnt: count,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-11-25 00:55:10 +08:00
|
|
|
|
|
2026-02-19 16:02:23 +08:00
|
|
|
|
}
|
2026-02-23 03:56:27 +08:00
|
|
|
|
|
2026-02-19 16:02:23 +08:00
|
|
|
|
p.SendPackCmd(8004, items)
|
2025-11-22 22:57:32 +08:00
|
|
|
|
}
|
2025-11-15 23:02:46 +00:00
|
|
|
|
|
2026-02-12 04:28:20 +08:00
|
|
|
|
evs := gconv.Int64s(strings.Split(xmlres.PetMAP[int(monster.ID)].YieldingEV, " "))
|
2026-02-13 03:34:37 +08:00
|
|
|
|
|
2025-12-01 23:31:48 +08:00
|
|
|
|
foi.Winpet.AddEV(evs)
|
2026-02-13 22:57:05 +08:00
|
|
|
|
//取消累计学习力掉落
|
|
|
|
|
|
// if leve == 8 {
|
|
|
|
|
|
// items.EV = lo.Sum(evs) - 1
|
|
|
|
|
|
// p.Info.EVPool += lo.Sum(evs) //给予累计学习力
|
|
|
|
|
|
// }
|
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
|
|
|
|
|
|
}
|