```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(common/utils): 添加时间范围检查工具函数

添加了 IsCurrentTimeInRange 函数用于判断当前时间是否在指定的 HH:MM
时间区间内,支持当前日期的时间比较功能。

refactor(logic/controller): 重构 Boss 挑战逻辑并集成配置服务

- 集成 service 模块替代原有硬编码逻辑
- 重构 PlayerFightBoss 方法,使用新的配置数据结构
- 移除已废弃的 processMonID 函数和相关注释代码

refactor(logic/space): 优化地图 Boss 信息管理和天气系统

- 更新地图 Boss 数据
This commit is contained in:
昔念
2026-02-25 19:05:50 +08:00
parent 7c1540ff6d
commit dc4835f14c
11 changed files with 307 additions and 237 deletions

View File

@@ -10,145 +10,155 @@ import (
"blazing/logic/service/fight/info"
"blazing/logic/service/player"
"blazing/modules/config/service"
"blazing/modules/player/model"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/grand"
)
// processMonID 处理怪物ID字符串如果是多个ID则随机选择一个
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时随机选取一个
randomIdx := grand.Intn(len(monid))
selected = monid[randomIdx]
}
return selected
}
// PlayerFightBoss 挑战地图boss
// data: 包含挑战Boss信息的输入数据
// player: 当前玩家对象
// 返回: 战斗结果和错误码
// func (Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, p *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
// r := p.CanFight()
// if p.CanFight() != 0 {
// return nil, r
// }
// var monster *model.PetInfo
// monsterInfo := &model.PlayerInfo{}
func (Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, p *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
r := p.CanFight()
if p.CanFight() != 0 {
return nil, r
}
var monster *model.PetInfo
monsterInfo := &model.PlayerInfo{}
// var taskID int
// var canCapture int
// mdata, ok := xmlres.MonsterMap[int(p.Info.MapID)]
// if !ok {
// return nil, errorcode.ErrorCodes.ErrPokemonNotExists
// }
// if len(mdata.Bosses) == 0 {
// return nil, errorcode.ErrorCodes.ErrPokemonNotExists
// }
// for _, bc := range mdata.Bosses {
var taskID int
var canCapture int
mdata := service.NewMapNodeService().GetDataNode(p.Info.MapID, data.BossId)
if mdata == nil {
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
}
// if bc.Id == nil {
bosinfo := service.NewBossService().Get(mdata.BossIds[0])
if bosinfo == nil {
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
}
dv := 24
if bosinfo[0].IsCapture == 1 {
dv = -1
}
for i, bm := range bosinfo {
// bc.Id = gconv.PtrInt(0)
// }
monster = model.GenPetInfo(
gconv.Int(bm.MonID), dv, //24个体
-1,
0, //野怪没特性
// if (bc.Id == nil && data.BossId == 0) || uint32(*bc.Id) == data.BossId { //打默认第一个boss
// if bc.TaskID != nil {
// taskID = *bc.TaskID
// }
int(bm.Lv), nil, 0)
monster.CatchTime = uint32(i)
if bm.Hp != 0 {
monster.Hp = uint32(bm.Hp)
monster.MaxHp = uint32(bm.Hp)
}
// for i, bm := range bc.BossMon {
for _, v := range bm.Effect {
idx := gconv.Uint16(v)
// dv := 24
// if bc.BossCatchable == 1 {
// dv = -1
// }
if idx == 0 {
continue
}
// monster = model.GenPetInfo(
// gconv.Int(processMonID(bm.MonID)), dv, //24个体
// -1,
// 0, //野怪没特性
EID, args := service.NewEffectService().Args(uint32(idx))
monster.EffectInfo = append(monster.EffectInfo, model.PetEffectInfo{
Idx: idx,
EID: gconv.Uint16(EID),
Args: gconv.Ints(args),
})
}
monsterInfo.PetList = append(monsterInfo.PetList, *monster)
}
if bosinfo[0].IsCapture == 1 {
canCapture = xmlres.PetMAP[int(monster.ID)].CatchRate
if grand.Meet(1, 500) {
monsterInfo.PetList[0].RandomByWeightShiny()
}
// bm.Lv, nil, 0)
// monster.CatchTime = uint32(i)
// if bm.Hp != 0 {
// monster.Hp = uint32(bm.Hp)
// monster.MaxHp = uint32(bm.Hp)
// }
}
monsterInfo.Nick = mdata.NodeName //xmlres.PetMAP[int(monster.ID)].DefName
// for _, bc := range mdata.Bosses {
// for _, v := range strings.Split(bm.NewSeIdxs, " ") {
// idx := gconv.Uint16(v)
// if bc.Id == nil {
// if idx == 0 {
// continue
// }
// bc.Id = gconv.PtrInt(0)
// }
// EID, args := service.NewEffectService().Args(uint32(idx))
// monster.EffectInfo = append(monster.EffectInfo, model.PetEffectInfo{
// Idx: idx,
// EID: gconv.Uint16(EID),
// Args: gconv.Ints(args),
// })
// }
// monsterInfo.PetList = append(monsterInfo.PetList, *monster)
// }
// if bc.BossCatchable == 1 {
// canCapture = xmlres.PetMAP[int(monster.ID)].CatchRate
// if grand.Meet(1, 500) {
// monsterInfo.PetList[0].RandomByWeightShiny()
// }
// if (bc.Id == nil && data.BossId == 0) || uint32(*bc.Id) == data.BossId { //打默认第一个boss
// if bc.TaskID != nil {
// taskID = *bc.TaskID
// }
// }
// monsterInfo.Nick = bc.Name //xmlres.PetMAP[int(monster.ID)].DefName
// break
// }
// for i, bm := range bc.BossMon {
// }
// if len(monsterInfo.PetList) == 0 {
// return nil, errorcode.ErrorCodes.ErrPokemonNotExists
// }
// p.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC
// p.Fightinfo.Mode = info.BattleMode.MULTI_MODE
// monster = model.GenPetInfo(
// gconv.Int(processMonID(bm.MonID)), dv, //24个体
// -1,
// 0, //野怪没特性
// ai := player.NewAI_player(monsterInfo)
// ai.CanCapture = canCapture
// ai.Prop[0] = 2
// fight.NewFight(p, ai, func(foi info.FightOverInfo) {
// if taskID != 0 {
// if foi.Reason == 0 && foi.WinnerId == p.Info.UserID {
// p.SptCompletedTask(taskID, 1)
// bm.Lv, nil, 0)
// monster.CatchTime = uint32(i)
// if bm.Hp != 0 {
// monster.Hp = uint32(bm.Hp)
// monster.MaxHp = uint32(bm.Hp)
// }
// }
// }
// for _, v := range strings.Split(bm.NewSeIdxs, " ") {
// idx := gconv.Uint16(v)
// //p.Done.Exec(model.MilestoneMode.BOSS, []uint32{p.Info.MapID, data.BossId, uint32(foi.Reason)}, nil)
// if idx == 0 {
// continue
// }
// })
// EID, args := service.NewEffectService().Args(uint32(idx))
// monster.EffectInfo = append(monster.EffectInfo, model.PetEffectInfo{
// Idx: idx,
// EID: gconv.Uint16(EID),
// Args: gconv.Ints(args),
// })
// }
// monsterInfo.PetList = append(monsterInfo.PetList, *monster)
// }
// if bc.BossCatchable == 1 {
// canCapture = xmlres.PetMAP[int(monster.ID)].CatchRate
// if grand.Meet(1, 500) {
// monsterInfo.PetList[0].RandomByWeightShiny()
// }
// return nil, -1
// }
// }
// monsterInfo.Nick = bc.Name //xmlres.PetMAP[int(monster.ID)].DefName
// break
// }
// }
if len(monsterInfo.PetList) == 0 {
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
}
p.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC
p.Fightinfo.Mode = info.BattleMode.MULTI_MODE
ai := player.NewAI_player(monsterInfo)
ai.CanCapture = canCapture
ai.Prop[0] = 2
fight.NewFight(p, ai, func(foi info.FightOverInfo) {
if taskID != 0 {
if foi.Reason == 0 && foi.WinnerId == p.Info.UserID {
p.SptCompletedTask(taskID, 1)
}
}
//p.Done.Exec(model.MilestoneMode.BOSS, []uint32{p.Info.MapID, data.BossId, uint32(foi.Reason)}, nil)
})
return nil, -1
}
// OnPlayerFightNpcMonster 战斗野怪
// data: 包含战斗野怪信息的输入数据