2025-11-14 23:09:16 +08:00
|
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"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"
|
|
|
|
|
|
|
|
|
|
|
|
"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-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-11-14 23:09:16 +08:00
|
|
|
|
// 挑战地图boss
|
|
|
|
|
|
func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-12-01 23:31:48 +08:00
|
|
|
|
if !c.CanFight() {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
|
}
|
2025-11-14 23:09:16 +08:00
|
|
|
|
var mo *model.PetInfo
|
|
|
|
|
|
moinfo := &model.PlayerInfo{}
|
|
|
|
|
|
|
2025-11-22 22:57:32 +08:00
|
|
|
|
var taskid int
|
|
|
|
|
|
var cancpet int
|
2025-11-16 11:56:57 +08:00
|
|
|
|
mdata, ok := xmlres.MonsterMap[int(c.Info.MapID)]
|
|
|
|
|
|
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 {
|
|
|
|
|
|
taskid = *bc.TaskID
|
|
|
|
|
|
}
|
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-11-25 12:29:50 +08:00
|
|
|
|
mo = model.GenPetInfo(
|
2025-11-16 11:56:57 +08:00
|
|
|
|
gconv.Int(processMonID(bm.MonID)), 24, //24个体
|
|
|
|
|
|
-1,
|
|
|
|
|
|
0, //野怪没特性
|
|
|
|
|
|
0,
|
|
|
|
|
|
bm.Lv)
|
2025-11-26 15:25:10 +08:00
|
|
|
|
mo.CatchTime = uint32(i)
|
2025-11-16 11:56:57 +08:00
|
|
|
|
mo.Hp = uint32(bm.Hp)
|
|
|
|
|
|
mo.MaxHp = uint32(bm.Hp)
|
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)
|
|
|
|
|
|
eff := xmlres.EffectMAP[int(idx)]
|
|
|
|
|
|
args := strings.Split(eff.Args, " ")
|
2025-11-25 18:25:52 +08:00
|
|
|
|
mo.EffectInfo = append(mo.EffectInfo, model.PetEffectInfo{
|
2025-11-26 15:25:10 +08:00
|
|
|
|
Idx: idx,
|
|
|
|
|
|
EID: gconv.Uint16(eff.Eid),
|
|
|
|
|
|
Args: gconv.Ints(args),
|
2025-11-25 18:25:52 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-11-26 15:25:10 +08:00
|
|
|
|
moinfo.PetList = append(moinfo.PetList, *mo)
|
2025-11-14 23:09:16 +08:00
|
|
|
|
}
|
2025-11-25 02:35:36 +08:00
|
|
|
|
if bc.BossCatchable == 1 {
|
|
|
|
|
|
cancpet = xmlres.PetMAP[int(mo.ID)].CatchRate
|
|
|
|
|
|
}
|
2025-11-16 11:56:57 +08:00
|
|
|
|
moinfo.Nick = xmlres.PetMAP[int(mo.ID)].DefName
|
|
|
|
|
|
break
|
2025-11-14 23:09:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-11-25 18:25:52 +08:00
|
|
|
|
if len(moinfo.PetList) == 0 {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
2025-11-21 02:40:27 +08:00
|
|
|
|
c.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC
|
2025-11-19 16:11:02 +08:00
|
|
|
|
c.Fightinfo.Mode = info.BattleMode.MULTI_MODE
|
|
|
|
|
|
|
2025-11-14 23:09:16 +08:00
|
|
|
|
ai := player.NewAI_player(moinfo)
|
2025-11-22 22:57:32 +08:00
|
|
|
|
ai.CanCapture = cancpet
|
2025-11-26 15:25:10 +08:00
|
|
|
|
ai.Prop[0] = 2
|
2025-11-16 20:30:17 +00:00
|
|
|
|
fight.NewFight(c, ai, func(foi *info.FightOverInfo) {
|
2025-11-26 15:25:10 +08:00
|
|
|
|
if taskid != 0 {
|
2025-11-22 22:57:32 +08:00
|
|
|
|
if foi.Reason == 0 && foi.WinnerId == c.Info.UserID {
|
2025-11-26 15:25:10 +08:00
|
|
|
|
if c.Info.TaskList[taskid-1] != 3 {
|
2025-11-22 22:57:32 +08:00
|
|
|
|
c.Info.TaskList[taskid-1] = 3
|
|
|
|
|
|
|
|
|
|
|
|
moinfo.PetList[0].Downgrade(1)
|
|
|
|
|
|
PetID := moinfo.PetList[0].ID
|
|
|
|
|
|
|
|
|
|
|
|
newm1 := model.GenPetInfo(int(PetID), -1, -1, 0, 0, 1)
|
|
|
|
|
|
c.Service.Pet.PetAdd(*newm1)
|
|
|
|
|
|
|
|
|
|
|
|
c.SendPackCmd(8004, &info.S2C_GET_BOSS_MONSTER{
|
|
|
|
|
|
BonusID: uint32(taskid),
|
|
|
|
|
|
PetID: PetID,
|
|
|
|
|
|
CaptureTm: newm1.CatchTime,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
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-11-26 15:25:10 +08:00
|
|
|
|
c.Done.Exec(model.MilestoneMode.BOSS, []uint32{c.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
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 战斗野怪
|
|
|
|
|
|
func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-12-01 23:31:48 +08:00
|
|
|
|
if !c.CanFight() {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
|
}
|
2025-11-14 23:09:16 +08:00
|
|
|
|
refpet := c.OgreInfo.Data[data.Number]
|
|
|
|
|
|
if refpet.Id == 0 {
|
|
|
|
|
|
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
2025-11-25 12:29:50 +08:00
|
|
|
|
mo := model.GenPetInfo(
|
2025-11-14 23:09:16 +08:00
|
|
|
|
int(refpet.Id), -1,
|
|
|
|
|
|
-1,
|
|
|
|
|
|
0, //野怪没特性
|
|
|
|
|
|
int(refpet.Shiny),
|
|
|
|
|
|
int(refpet.Lv))
|
|
|
|
|
|
|
|
|
|
|
|
moinfo := &model.PlayerInfo{}
|
|
|
|
|
|
moinfo.Nick = xmlres.PetMAP[int(mo.ID)].DefName
|
|
|
|
|
|
moinfo.PetList = append(moinfo.PetList, *mo)
|
|
|
|
|
|
ai := player.NewAI_player(moinfo)
|
2025-11-21 02:40:27 +08:00
|
|
|
|
ai.CanCapture = handleNPCFightSpecial(mo.ID)
|
2025-11-19 16:11:02 +08:00
|
|
|
|
|
2025-11-21 02:40:27 +08:00
|
|
|
|
c.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC //打野怪
|
|
|
|
|
|
c.Fightinfo.Mode = info.BattleMode.MULTI_MODE //多人模式
|
2025-11-14 23:09:16 +08:00
|
|
|
|
|
2025-11-16 20:30:17 +00:00
|
|
|
|
fight.NewFight(c, ai, func(foi *info.FightOverInfo) {
|
2025-12-01 23:31:48 +08:00
|
|
|
|
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 {
|
2025-11-25 00:55:10 +08:00
|
|
|
|
|
2025-12-01 23:31:48 +08:00
|
|
|
|
if !c.CanGetExp() {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
exp := uint32(xmlres.PetMAP[int(mo.ID)].YieldingExp) * mo.Level / 7
|
|
|
|
|
|
items := &info.S2C_GET_BOSS_MONSTER{
|
|
|
|
|
|
//EV: 45,
|
|
|
|
|
|
EXP: exp * 2,
|
|
|
|
|
|
}
|
|
|
|
|
|
if refpet.Item != 0 {
|
|
|
|
|
|
|
|
|
|
|
|
items.ItemList = c.ItemAdd(model.ItemInfo{
|
|
|
|
|
|
ItemId: refpet.Item,
|
|
|
|
|
|
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-01 23:31:48 +08:00
|
|
|
|
evs := gconv.Uint32s(strings.Split(xmlres.PetMAP[int(mo.ID)].YieldingEV, " "))
|
|
|
|
|
|
items.EV = lo.Sum(evs)
|
|
|
|
|
|
c.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)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
func handleNPCFightSpecial(petid uint32) int {
|
|
|
|
|
|
|
|
|
|
|
|
npcPetID := int(petid)
|
|
|
|
|
|
petCfg, ok := xmlres.PetMAP[npcPetID]
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
// log.Error(context.Background(), "NPC宠物配置不存在", "petID", npcPetID)
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
catchRate := gconv.Int(petCfg.CatchRate)
|
|
|
|
|
|
return catchRate
|
|
|
|
|
|
}
|