refactor(common/data/xmlres): 注释掉未使用的MonsterMap配置变量 - 将MonsterMap配置变量注释掉,因为当前不再使用该配置 - 相应地注释掉了初始化代码中的MonsterMap赋值逻辑 feat(logic/controller): 统一CanFight方法返回值为ErrorCode - 修改PlayerFightBoss等战斗控制器中的Can
This commit is contained in:
@@ -3,8 +3,8 @@ package player
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
"blazing/modules/config/service"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@@ -13,11 +13,18 @@ import (
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
// 2. 从 string 类型 slice 随机选一个元素
|
||||
func RandomStringFromSlice(s []string) string {
|
||||
func (p *Player) IsMatch(t model.Event) bool {
|
||||
_, ok := lo.Find(t.Weather, func(item int32) bool {
|
||||
return item == int32(p.GetSpace().Weather)
|
||||
})
|
||||
if !ok {
|
||||
// 不在同一天气下
|
||||
return false
|
||||
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
randomIdx := grand.Intn(len(s))
|
||||
return s[randomIdx]
|
||||
}
|
||||
|
||||
// 应该根据怪物信息决定后端生成
|
||||
@@ -43,33 +50,29 @@ func (p *Player) GenMonster() {
|
||||
}
|
||||
p.MapNPC.Reset(10 * time.Second)
|
||||
p.Data[oldnum] = OgrePetInfo{} //切地图清空
|
||||
mapss, ok := xmlres.MonsterMap[gconv.Int(p.Info.MapID)]
|
||||
|
||||
if ok && mapss.Monsters != nil {
|
||||
for _, i := range replce {
|
||||
ogreconfig := service.NewMapPitService().GetData(p.Info.MapID, uint32(i))
|
||||
|
||||
for i, m := range mapss.Monsters.Monsters { //这里是9个
|
||||
for _, v := range ogreconfig {
|
||||
|
||||
_, rok := lo.Find(replce, func(it int) bool {
|
||||
return it == i
|
||||
})
|
||||
|
||||
if !rok {
|
||||
if !p.IsMatch(*v.Event) {
|
||||
continue
|
||||
}
|
||||
|
||||
id := strings.Split(m.ID, " ")
|
||||
lv := strings.Split(m.Lv, " ")
|
||||
|
||||
p.Data[i] = OgrePetInfo{}
|
||||
p.Data[i].ID = gconv.Uint32(RandomStringFromSlice(id))
|
||||
p.Data[i].ID = uint32(v.RefreshID[grand.Intn(len(v.RefreshID))])
|
||||
|
||||
if p.Data[i].ID != 0 {
|
||||
|
||||
p.Data[i].Lv = gconv.Uint32(RandomStringFromSlice(lv))
|
||||
p.Data[i].Lv = uint32(grand.N(v.MinLevel, v.MaxLevel))
|
||||
p.Data[i].IsCapture = v.IsCapture //实现捕捉限制
|
||||
if handleNPCFightSpecial(p.Data[i].ID) == 0 {
|
||||
p.Data[i].IsCapture = 0
|
||||
}
|
||||
if len(v.RefreshID) == 1 { //说明这里只固定刷一个,概率变尼尔尼奥,不是稀有精灵
|
||||
|
||||
if len(id) == 1 { //说明这里只固定刷一个,概率变尼尔尼奥,不是稀有精灵
|
||||
|
||||
nieo, _, _ := p.Roll(20, 1000)
|
||||
nieo, _, _ := p.Roll(1, 25)
|
||||
if nieo {
|
||||
p.Data[i].Ext = 77
|
||||
if grand.Meet(1, 2) {
|
||||
@@ -77,13 +80,15 @@ func (p *Player) GenMonster() {
|
||||
}
|
||||
|
||||
p.Data[i].Lv = 16
|
||||
p.Data[i].IsCapture = 1 //解除捕捉限制
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if cool.Config.ServerInfo.IsVip != 0 { //测试服,百分百异色
|
||||
p.Data[i].FixSHiny()
|
||||
} else {
|
||||
if xmlres.PetMAP[int(p.Data[i].ID)].CatchRate != 0 && grand.Meet(1, 500) {
|
||||
if p.Data[i].IsCapture == 1 && grand.Meet(1, 500) {
|
||||
|
||||
p.Data[i].RandomByWeightShiny()
|
||||
|
||||
@@ -96,10 +101,10 @@ func (p *Player) GenMonster() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if p != nil {
|
||||
p.SendPackCmd(2004, &p.OgrePet)
|
||||
}
|
||||
@@ -192,3 +197,17 @@ func GenerateNormalizedColorMatrix() [20]uint8 {
|
||||
|
||||
return matrix
|
||||
}
|
||||
|
||||
// handleNPCFightSpecial 处理NPC战斗特殊情况
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package player
|
||||
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/modules/player/model"
|
||||
)
|
||||
@@ -39,6 +40,6 @@ func (lw *AI_player) SendLoadPercent(info.LoadPercentOutboundInfo) {
|
||||
|
||||
}
|
||||
|
||||
func (p *AI_player) CanFight() bool {
|
||||
return true
|
||||
func (p *AI_player) CanFight() errorcode.ErrorCode {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
|
||||
// JoinFight 加入战斗队列
|
||||
func (p *Player) JoinFight(handler func(p common.PlayerI) bool) errorcode.ErrorCode {
|
||||
//加入队列前就开始判断一次
|
||||
if !p.CanFight() {
|
||||
return errorcode.ErrorCodes.ErrNoEligiblePokemon
|
||||
r := p.CanFight()
|
||||
if p.CanFight() != 0 {
|
||||
return r
|
||||
}
|
||||
if p.GetSpace().Owner.UserID == p.Info.UserID {
|
||||
return errorcode.ErrorCodes.ErrSystemError
|
||||
@@ -20,7 +20,7 @@ func (p *Player) JoinFight(handler func(p common.PlayerI) bool) errorcode.ErrorC
|
||||
p.GetSpace().User.Range(func(key uint32, opponent common.PlayerI) bool {
|
||||
if opponent.GetInfo().UserID != p.Info.UserID {
|
||||
//确认是乱斗模式
|
||||
if opponent.Getfightinfo() == p.Getfightinfo() && p.CanFight() {
|
||||
if opponent.Getfightinfo() == p.Getfightinfo() && p.CanFight() == 0 {
|
||||
success := handler(opponent)
|
||||
if success {
|
||||
atomic.StoreUint32(&opponent.(*Player).Fightinfo.Mode, 0)
|
||||
|
||||
@@ -36,6 +36,7 @@ type OgrePetInfo struct {
|
||||
Lv uint32 `struc:"skip"` //等级
|
||||
Item []int64 `struc:"skip"` //奖励,如果有的话
|
||||
Ext uint32 `struc:"skip"` //是否变尼尔尼奥
|
||||
IsCapture int `struc:"skip"`
|
||||
}
|
||||
|
||||
func (o *OgrePetInfo) FixSHiny() {
|
||||
@@ -146,26 +147,26 @@ func (p *Player) GetSpace() *space.Space {
|
||||
|
||||
// CanFight 检查玩家是否可以进行战斗
|
||||
// 0无战斗,1PVP,2,BOOS,3PVE
|
||||
func (p *Player) CanFight() bool {
|
||||
func (p *Player) CanFight() errorcode.ErrorCode {
|
||||
if len(p.Info.PetList) == 0 {
|
||||
atomic.StoreUint32(&p.Fightinfo.Mode, 0)
|
||||
return false
|
||||
return errorcode.ErrorCodes.ErrBattleCancelled
|
||||
}
|
||||
|
||||
if p.FightC != nil {
|
||||
atomic.StoreUint32(&p.Fightinfo.Mode, 0)
|
||||
return false
|
||||
return errorcode.ErrorCodes.ErrBattleEnded
|
||||
}
|
||||
|
||||
for _, pet := range p.Info.PetList {
|
||||
if pet.Hp > 0 { // 只要找到一个血量大于0的宠物,就可以战斗
|
||||
return true
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历完所有宠物,都没有血量大于0的,才不能战斗
|
||||
atomic.StoreUint32(&p.Fightinfo.Mode, 0)
|
||||
return false
|
||||
return errorcode.ErrorCodes.ErrPokemonNoStamina
|
||||
}
|
||||
|
||||
func (p *Player) SendPack(b []byte) error {
|
||||
|
||||
Reference in New Issue
Block a user