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-15 22:17:43 +00:00
|
|
|
|
2025-11-14 23:09:16 +08:00
|
|
|
"blazing/logic/service/fight"
|
2026-03-31 08:19:53 +08:00
|
|
|
fightinfo "blazing/logic/service/fight/info"
|
2026-03-21 00:57:18 +08:00
|
|
|
"blazing/logic/service/fight/input"
|
2025-11-14 23:09:16 +08:00
|
|
|
"blazing/logic/service/player"
|
2026-02-26 17:16:38 +08:00
|
|
|
configmodel "blazing/modules/config/model"
|
2026-02-25 19:05:50 +08: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
|
|
|
)
|
|
|
|
|
|
2026-04-05 07:28:39 +08:00
|
|
|
const (
|
2026-04-08 01:28:55 +08:00
|
|
|
rewardItemExpPool = 3
|
|
|
|
|
groupBossSlotLimit = 3
|
2026-04-05 07:28:39 +08:00
|
|
|
)
|
|
|
|
|
|
2026-02-25 19:05:50 +08:00
|
|
|
// PlayerFightBoss 挑战地图boss
|
2026-04-05 07:24:36 +08:00
|
|
|
func (Controller) PlayerFightBoss(req *ChallengeBossInboundInfo, p *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2026-03-31 08:19:53 +08:00
|
|
|
if err = p.CanFight(); err != 0 {
|
|
|
|
|
return nil, err
|
2026-02-26 00:05:43 +08:00
|
|
|
}
|
2026-02-26 17:16:38 +08:00
|
|
|
|
2026-04-06 05:24:14 +08:00
|
|
|
mapNode := p.GetSpace().GetMatchedMapNode(req.BossId)
|
|
|
|
|
if mapNode == nil {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
}
|
2026-03-31 08:19:53 +08:00
|
|
|
bossConfigs, err := loadMapBossConfigs(mapNode)
|
|
|
|
|
if err != 0 {
|
|
|
|
|
return nil, err
|
2026-02-25 19:05:50 +08:00
|
|
|
}
|
2026-03-31 08:19:53 +08:00
|
|
|
|
|
|
|
|
monsterInfo, leadMonsterID, err := buildBossMonsterInfo(mapNode.NodeName, bossConfigs)
|
|
|
|
|
if err != 0 {
|
|
|
|
|
return nil, err
|
2026-02-25 19:05:50 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
p.Fightinfo.Status = fightinfo.BattleMode.FIGHT_WITH_NPC
|
|
|
|
|
p.Fightinfo.Mode = fightinfo.BattleMode.MULTI_MODE
|
2026-02-25 19:05:50 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
ai := player.NewAI_player(monsterInfo)
|
|
|
|
|
ai.CanCapture = resolveBossCaptureRate(bossConfigs[0].IsCapture, leadMonsterID)
|
2026-04-05 21:59:22 +08:00
|
|
|
ai.BossScript = bossConfigs[0].Script
|
2026-04-06 03:11:38 +08:00
|
|
|
ai.AddBattleProp(0, 2)
|
2026-03-31 08:19:53 +08:00
|
|
|
|
|
|
|
|
var fightC *fight.FightC
|
2026-04-08 01:28:55 +08:00
|
|
|
fightC, err = startMapBossFight(mapNode, p, ai, func(foi model.FightOverInfo) {
|
2026-03-31 08:19:53 +08:00
|
|
|
if mapNode.WinBonusID == 0 {
|
|
|
|
|
return
|
2026-03-07 13:54:42 +08:00
|
|
|
}
|
2026-03-31 08:19:53 +08:00
|
|
|
if shouldGrantBossWinBonus(fightC, p.Info.UserID, bossConfigs[0], foi) {
|
|
|
|
|
p.SptCompletedTask(mapNode.WinBonusID, 1)
|
2026-02-25 19:05:50 +08:00
|
|
|
}
|
2026-03-31 08:19:53 +08:00
|
|
|
})
|
|
|
|
|
if err != 0 {
|
|
|
|
|
return nil, err
|
2025-11-16 11:56:57 +08:00
|
|
|
}
|
2026-02-25 19:46:31 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
return nil, -1
|
|
|
|
|
}
|
2026-02-25 19:05:50 +08:00
|
|
|
|
2026-04-08 01:28:55 +08:00
|
|
|
func startMapBossFight(
|
|
|
|
|
mapNode *configmodel.MapNode,
|
|
|
|
|
p *player.Player,
|
|
|
|
|
ai *player.AI_player,
|
|
|
|
|
fn func(model.FightOverInfo),
|
|
|
|
|
) (*fight.FightC, errorcode.ErrorCode) {
|
|
|
|
|
ourPets := p.GetPetInfo(100)
|
|
|
|
|
oppPets := ai.GetPetInfo(0)
|
|
|
|
|
if mapNode != nil && mapNode.IsGroupBoss != 0 {
|
|
|
|
|
ourSlots := buildGroupBossPetSlots(ourPets, groupBossSlotLimit)
|
|
|
|
|
oppSlots := buildGroupBossPetSlots(oppPets, groupBossSlotLimit)
|
|
|
|
|
if len(ourSlots) > 0 && len(oppSlots) > 0 {
|
|
|
|
|
return fight.NewLegacyGroupFightSingleControllerN(p, ai, ourSlots, oppSlots, fn)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fight.NewFight(p, ai, ourPets, oppPets, fn)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func buildGroupBossPetSlots(pets []model.PetInfo, slotLimit int) [][]model.PetInfo {
|
|
|
|
|
if len(pets) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slots := make([][]model.PetInfo, 0, slotLimit)
|
|
|
|
|
for _, pet := range pets {
|
|
|
|
|
if pet.Hp == 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if slotLimit <= 0 {
|
|
|
|
|
slotLimit = 3
|
|
|
|
|
}
|
|
|
|
|
if len(slots) < slotLimit {
|
|
|
|
|
slots = append(slots, []model.PetInfo{pet})
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
if len(slots) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
var idx int = 0
|
|
|
|
|
for _, pet := range pets[len(slots):] {
|
|
|
|
|
if pet.Hp == 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
for step := 0; step < len(slots); step++ {
|
|
|
|
|
slotIdx := (idx + step) % len(slots)
|
|
|
|
|
if len(slots[slotIdx]) < 6 {
|
|
|
|
|
slots[slotIdx] = append(slots[slotIdx], pet)
|
|
|
|
|
idx = (slotIdx + 1) % len(slots)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return slots
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
// OnPlayerFightNpcMonster 战斗野怪
|
2026-04-05 07:24:36 +08:00
|
|
|
func (Controller) OnPlayerFightNpcMonster(req *FightNpcMonsterInboundInfo, p *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2026-03-31 08:19:53 +08:00
|
|
|
if err = p.CanFight(); err != 0 {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if req.Number > 9 {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
2026-02-25 19:46:31 +08:00
|
|
|
}
|
2026-02-26 00:05:43 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
refPet := p.Data[req.Number]
|
|
|
|
|
monster, monsterInfo, err := buildNpcMonsterInfo(refPet, p.Info.MapID)
|
|
|
|
|
if err != 0 {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2026-03-21 00:57:18 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
ai := player.NewAI_player(monsterInfo)
|
|
|
|
|
ai.CanCapture = refPet.IsCapture
|
2025-11-16 11:56:57 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
p.Fightinfo.Status = fightinfo.BattleMode.FIGHT_WITH_NPC
|
|
|
|
|
p.Fightinfo.Mode = fightinfo.BattleMode.MULTI_MODE
|
2026-02-25 19:05:50 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
_, err = fight.NewFight(p, ai, p.GetPetInfo(100), ai.GetPetInfo(0), func(foi model.FightOverInfo) {
|
|
|
|
|
handleNpcFightRewards(p, foi, monster)
|
2026-02-25 19:05:50 +08:00
|
|
|
})
|
2026-03-31 08:19:53 +08:00
|
|
|
if err != 0 {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2026-02-25 19:05:50 +08:00
|
|
|
|
|
|
|
|
return nil, -1
|
|
|
|
|
}
|
2025-11-14 23:09:16 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
func loadMapBossConfigs(mapNode *configmodel.MapNode) ([]configmodel.BossConfig, errorcode.ErrorCode) {
|
|
|
|
|
if mapNode == nil || len(mapNode.BossIds) == 0 {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bossID := mapNode.BossIds[0]
|
|
|
|
|
if len(mapNode.BossIds) > 1 {
|
|
|
|
|
bossID = mapNode.BossIds[grand.Intn(len(mapNode.BossIds))]
|
2026-02-09 01:29:33 +08:00
|
|
|
}
|
2025-11-14 23:09:16 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
bossConfigs := service.NewBossService().Get(bossID)
|
|
|
|
|
if len(bossConfigs) == 0 {
|
2025-11-14 23:09:16 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
}
|
2026-01-01 00:30:09 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
return bossConfigs, 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func buildBossMonsterInfo(nodeName string, bossConfigs []configmodel.BossConfig) (*model.PlayerInfo, uint32, errorcode.ErrorCode) {
|
|
|
|
|
monsterInfo := &model.PlayerInfo{Nick: nodeName}
|
|
|
|
|
var leadMonsterID uint32
|
2025-12-14 19:23:26 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
for i, bossConfig := range bossConfigs {
|
|
|
|
|
dv, generation := bossFightPetArgs(bossConfig.IsCapture)
|
|
|
|
|
monster := model.GenPetInfo(
|
|
|
|
|
gconv.Int(bossConfig.MonID),
|
|
|
|
|
dv,
|
|
|
|
|
-1,
|
|
|
|
|
0,
|
|
|
|
|
int(bossConfig.Lv),
|
|
|
|
|
nil,
|
|
|
|
|
generation,
|
|
|
|
|
)
|
|
|
|
|
if monster == nil {
|
|
|
|
|
return nil, 0, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
}
|
|
|
|
|
monster.CatchTime = uint32(i)
|
|
|
|
|
monster.ConfigBoss(bossConfig.PetBaseConfig)
|
|
|
|
|
appendPetEffects(monster, bossConfig.Effect)
|
|
|
|
|
|
|
|
|
|
if i == 0 {
|
|
|
|
|
leadMonsterID = monster.ID
|
|
|
|
|
}
|
|
|
|
|
monsterInfo.PetList = append(monsterInfo.PetList, *monster)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(monsterInfo.PetList) == 0 {
|
|
|
|
|
return nil, 0, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if bossConfigs[0].IsCapture == 1 {
|
|
|
|
|
monsterInfo.PetList[0].ShinyInfo = make([]data.GlowFilter, 0)
|
2026-02-21 17:32:40 +08:00
|
|
|
if grand.Meet(1, 500) {
|
2026-03-31 08:19:53 +08:00
|
|
|
monsterInfo.PetList[0].RandomByWeightShiny()
|
2026-02-21 17:32:40 +08:00
|
|
|
}
|
2026-01-01 00:30:09 +08:00
|
|
|
}
|
2025-11-14 23:09:16 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
return monsterInfo, leadMonsterID, 0
|
|
|
|
|
}
|
2026-02-25 16:18:10 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
func bossFightPetArgs(canCapture int) (dv int, generation int) {
|
|
|
|
|
if canCapture == 1 {
|
|
|
|
|
return -1, -1
|
|
|
|
|
}
|
|
|
|
|
return 24, 0
|
|
|
|
|
}
|
2025-11-19 16:11:02 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
func appendPetEffects(monster *model.PetInfo, effectIDs []uint32) {
|
|
|
|
|
effects := service.NewEffectService().Args(effectIDs)
|
|
|
|
|
for _, effect := range effects {
|
|
|
|
|
monster.EffectInfo = append(monster.EffectInfo, model.PetEffectInfo{
|
2026-04-02 07:49:49 +08:00
|
|
|
Idx: uint16(effect.ID),
|
2026-03-31 08:19:53 +08:00
|
|
|
EID: gconv.Uint16(effect.Eid),
|
|
|
|
|
Args: gconv.Ints(effect.Args),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-14 23:09:16 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
func resolveBossCaptureRate(canCapture int, petID uint32) int {
|
|
|
|
|
if canCapture == 0 {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
2025-11-25 00:55:10 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
petCfg, ok := xmlres.PetMAP[int(petID)]
|
|
|
|
|
if !ok || petCfg.CatchRate == 0 {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
2026-02-27 14:48:10 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
return petCfg.CatchRate
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func shouldGrantBossWinBonus(fightC *fight.FightC, playerID uint32, bossConfig configmodel.BossConfig, foi model.FightOverInfo) bool {
|
|
|
|
|
if len(bossConfig.Rule) == 0 {
|
|
|
|
|
return foi.Reason == 0 && foi.WinnerId == playerID
|
|
|
|
|
}
|
2026-02-27 14:48:10 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
for _, ruleConfig := range service.NewFightRuleService().GetByRuleIdxs(bossConfig.Rule) {
|
|
|
|
|
rule := input.GetRule(int64(ruleConfig.RuleIdx))
|
|
|
|
|
if rule == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
rule.SetArgs(ruleConfig.Args...)
|
|
|
|
|
if !rule.Exec(fightC, &foi) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-27 14:48:10 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
return true
|
|
|
|
|
}
|
2026-02-27 14:48:10 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
func buildNpcMonsterInfo(refPet player.OgrePetInfo, mapID uint32) (*model.PetInfo, *model.PlayerInfo, errorcode.ErrorCode) {
|
|
|
|
|
if refPet.ID == 0 {
|
|
|
|
|
return nil, nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
}
|
2026-02-27 14:48:10 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
monster := model.GenPetInfo(
|
|
|
|
|
refPet.GetID(),
|
|
|
|
|
-1,
|
|
|
|
|
-1,
|
|
|
|
|
0,
|
|
|
|
|
refPet.GetLevel(),
|
|
|
|
|
refPet.ShinyInfo,
|
|
|
|
|
-1,
|
|
|
|
|
)
|
|
|
|
|
if monster == nil {
|
|
|
|
|
return nil, nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
}
|
|
|
|
|
monster.CatchMap = mapID
|
|
|
|
|
if refPet.Ext != 0 && grand.Meet(1, 500) {
|
|
|
|
|
monster.RandomByWeightShiny()
|
|
|
|
|
}
|
2026-02-23 03:56:27 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
petCfg, ok := xmlres.PetMAP[int(monster.ID)]
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
}
|
2025-11-15 23:02:46 +00:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
monsterInfo := &model.PlayerInfo{
|
|
|
|
|
Nick: petCfg.DefName,
|
|
|
|
|
PetList: []model.PetInfo{*monster},
|
|
|
|
|
}
|
|
|
|
|
return monster, monsterInfo, 0
|
|
|
|
|
}
|
2026-02-27 14:48:10 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
func handleNpcFightRewards(p *player.Player, foi model.FightOverInfo, monster *model.PetInfo) {
|
|
|
|
|
if foi.Reason != 0 || foi.WinnerId != p.Info.UserID || !p.CanGet() {
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-02-13 03:34:37 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
petCfg, ok := xmlres.PetMAP[int(monster.ID)]
|
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-12-01 23:31:48 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
exp := uint32(petCfg.YieldingExp) * monster.Level / 7
|
|
|
|
|
addlevel, poolevel := p.CanGetExp()
|
|
|
|
|
addexp := gconv.Float32(addlevel * gconv.Float32(exp))
|
|
|
|
|
poolexp := gconv.Float32(poolevel) * gconv.Float32(exp)
|
|
|
|
|
rewards := &fightinfo.S2C_GET_BOSS_MONSTER{}
|
|
|
|
|
|
|
|
|
|
p.ItemAdd(3, int64(poolexp+addexp))
|
2026-04-05 07:28:39 +08:00
|
|
|
rewards.AddItem(rewardItemExpPool, uint32(poolexp))
|
2026-03-31 08:19:53 +08:00
|
|
|
p.AddPetExp(foi.Winpet, int64(addexp))
|
|
|
|
|
|
|
|
|
|
if p.CanGetItem() {
|
|
|
|
|
itemID := p.GetSpace().GetDrop()
|
|
|
|
|
if itemID != 0 {
|
|
|
|
|
count := uint32(grand.N(1, 2))
|
|
|
|
|
if p.ItemAdd(itemID, int64(count)) {
|
2026-04-05 07:28:39 +08:00
|
|
|
rewards.AddItem(uint32(itemID), count)
|
2026-03-31 08:19:53 +08:00
|
|
|
}
|
2025-12-01 23:31:48 +08:00
|
|
|
}
|
2026-03-31 08:19:53 +08:00
|
|
|
}
|
2025-12-01 23:31:48 +08:00
|
|
|
|
2026-03-31 08:19:53 +08:00
|
|
|
petType := int64(petCfg.Type)
|
|
|
|
|
if monster.IsShiny() && p.CanGetXUAN() && petType < 16 {
|
|
|
|
|
xuanID := uint32(400686 + petType)
|
|
|
|
|
count := uint32(grand.N(1, 2))
|
|
|
|
|
if p.ItemAdd(int64(xuanID), int64(count)) {
|
2026-04-05 07:28:39 +08:00
|
|
|
rewards.AddItem(xuanID, count)
|
2026-03-31 08:19:53 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-11-14 23:09:16 +08:00
|
|
|
|
2026-04-05 07:28:39 +08:00
|
|
|
if rewards.HasReward() {
|
|
|
|
|
p.SendPackCmd(8004, rewards)
|
|
|
|
|
}
|
2026-04-05 07:30:55 +08:00
|
|
|
foi.Winpet.AddEV(petCfg.YieldingEVValues)
|
2025-11-14 23:09:16 +08:00
|
|
|
}
|