refactor(fight): 重构战斗模式与状态枚举,新增加载进度功能并优化战斗初始化逻辑
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
// 挑战地图boss
|
||||
func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
var petid int
|
||||
var mo *model.PetInfo
|
||||
@@ -41,7 +42,7 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *pla
|
||||
moinfo.Nick = xmlres.PetMAP[int(mo.ID)].DefName
|
||||
moinfo.PetList = append(moinfo.PetList, *mo)
|
||||
ai := player.NewAI_player(moinfo)
|
||||
fight.NewFight(info.BattleMode.PVE, c, ai)
|
||||
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_BOSS, c, ai)
|
||||
|
||||
return nil, -1
|
||||
}
|
||||
@@ -69,7 +70,7 @@ func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundIn
|
||||
moinfo.PetList = append(moinfo.PetList, *mo)
|
||||
ai := player.NewAI_player(moinfo)
|
||||
|
||||
fight.NewFight(info.BattleMode.PVE, c, ai)
|
||||
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_NPC, c, ai)
|
||||
|
||||
return nil, -1
|
||||
}
|
||||
@@ -85,7 +86,7 @@ func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *playe
|
||||
func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
|
||||
if ok, p1 := c.AgreeBattle(data.UserID, data.Flag, data.Mode); ok {
|
||||
fight.NewFight(info.EnumBattleMode(data.Mode), p1, c) ///开始对战,房主方以及被邀请方
|
||||
fight.NewFight(data.Mode, info.BattleStatus.FIGHT_WITH_PLAYER, p1, c) ///开始对战,房主方以及被邀请方
|
||||
}
|
||||
return nil, -1
|
||||
}
|
||||
@@ -98,7 +99,7 @@ func (h Controller) OnPlayerInviteOtherFight(data *fight.InviteToFightInboundInf
|
||||
}
|
||||
|
||||
// 使用技能包
|
||||
func (h Controller) UseSkill(data *fight.UseSkillInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
func (h Controller) UseSkill(data *fight.UseSkillInInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
c.FightC.UseSkill(c, int32(data.SkillId))
|
||||
return nil, 0
|
||||
}
|
||||
@@ -106,7 +107,7 @@ func (h Controller) UseSkill(data *fight.UseSkillInboundInfo, c *player.Player)
|
||||
// 战斗逃跑
|
||||
func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
|
||||
c.FightC.Over(c,info.BattleOverReason.PlayerEscape)
|
||||
c.FightC.Over(c, info.BattleOverReason.PlayerEscape)
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
@@ -123,3 +124,10 @@ func (h Controller) Capture(data *fight.CatchMonsterInboundInfo, c *player.Playe
|
||||
c.FightC.Capture(c, (data.CapsuleId))
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
// 切换精灵
|
||||
func (h Controller) LoadPercent(data *fight.LoadPercentInboundInfo, c *player.Player) (result *info.LoadPercentOutboundInfo, err errorcode.ErrorCode) {
|
||||
|
||||
c.FightC.LoadPercent(c, (int32(data.Percent)))
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
@@ -14,4 +14,5 @@ type FightI interface {
|
||||
ChangePet(c PlayerI, id uint32)
|
||||
Capture(c PlayerI, id uint32)
|
||||
GetRand() *rand.Rand
|
||||
LoadPercent(c PlayerI, percent int32)
|
||||
}
|
||||
|
||||
@@ -15,5 +15,6 @@ type PlayerI interface {
|
||||
GetInfo() *model.PlayerInfo
|
||||
SendAttackValue(info.AttackValueS)
|
||||
SendChangePet(info.ChangePetInfo)
|
||||
SendLoadPercent(info.LoadPercentOutboundInfo)
|
||||
SetFightC(FightI)
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ type EscapeFightInboundInfo struct {
|
||||
// HandleFightInviteInboundInfo 处理战斗邀请的入站消息
|
||||
|
||||
type HandleFightInviteInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2403" struc:"[0]pad"`
|
||||
UserID uint32 `json:"userId" codec:"userId,uint"` // 邀请我对战人的userid
|
||||
Flag uint32 `json:"flag" codec:"flag,uint"` // 1为同意对战 0为取消对战
|
||||
Mode uint32 `json:"mode" codec:"mode,uint"` // 战斗类型 1 = 1v1 2 = 6v6
|
||||
Head player.TomeeHeader `cmd:"2403" struc:"[0]pad"`
|
||||
UserID uint32 `json:"userId" codec:"userId,uint"` // 邀请我对战人的userid
|
||||
Flag uint32 `json:"flag" codec:"flag,uint"` // 1为同意对战 0为取消对战
|
||||
Mode info.EnumBattleMode `json:"mode" codec:"mode,uint"` // 战斗类型 1 = 1v1 2 = 6v6
|
||||
}
|
||||
|
||||
type InviteToFightInboundInfo struct {
|
||||
@@ -56,7 +56,7 @@ type NoteHandleFightInviteOutboundInfo struct {
|
||||
Result uint32 // 0=拒绝 1=同意 2=在线超6小时 3=无出战精灵 4=不在线
|
||||
}
|
||||
|
||||
type UseSkillInboundInfo struct {
|
||||
type UseSkillInInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2405" struc:"[0]pad"`
|
||||
// 技能id,
|
||||
SkillId uint32
|
||||
@@ -72,3 +72,8 @@ type CatchMonsterInboundInfo struct {
|
||||
|
||||
CapsuleId uint32 `json:"capsuleId" fieldDescription:"胶囊id" uint:"true"`
|
||||
}
|
||||
|
||||
type LoadPercentInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2441" struc:"[0]pad"`
|
||||
Percent uint32 `fieldDescription:"加载百分比"`
|
||||
}
|
||||
|
||||
@@ -14,30 +14,30 @@ type Effect10 struct {
|
||||
func init() {
|
||||
//n%令对方麻痹
|
||||
input.InitEffect(input.EffectType.Skill, 10, &Effect10{
|
||||
Status: info.BattleStatus.Paralysis,
|
||||
Status: info.PetStatus.Paralysis,
|
||||
})
|
||||
|
||||
// n%令对方中毒
|
||||
input.InitEffect(input.EffectType.Skill, 11, &Effect10{
|
||||
Status: info.BattleStatus.Poisoned,
|
||||
Status: info.PetStatus.Poisoned,
|
||||
})
|
||||
//n%令对方烧伤
|
||||
input.InitEffect(input.EffectType.Skill, 12, &Effect10{
|
||||
Status: info.BattleStatus.Burned,
|
||||
Status: info.PetStatus.Burned,
|
||||
})
|
||||
//n回合吸取对方最大体力的1/8(草系无效)
|
||||
|
||||
//n%令对方冻伤
|
||||
input.InitEffect(input.EffectType.Skill, 12, &Effect10{
|
||||
Status: info.BattleStatus.Frozen,
|
||||
Status: info.PetStatus.Frozen,
|
||||
})
|
||||
//n%令对方害怕
|
||||
input.InitEffect(input.EffectType.Skill, 12, &Effect10{
|
||||
Status: info.BattleStatus.Fear,
|
||||
Status: info.PetStatus.Fear,
|
||||
})
|
||||
//n%令对手睡眠
|
||||
input.InitEffect(input.EffectType.Skill, 12, &Effect10{
|
||||
Status: info.BattleStatus.Sleep,
|
||||
Status: info.PetStatus.Sleep,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ func init() {
|
||||
f.Status = t
|
||||
input.InitEffect(input.EffectType.Status, int(t), f)
|
||||
}
|
||||
tt(info.BattleStatus.Paralysis, &EffectStatusNotSkill{})
|
||||
tt(info.BattleStatus.Tired, &EffectStatusNotSkill{})
|
||||
tt(info.BattleStatus.Sleep, &EffectStatusNotSkill{})
|
||||
tt(info.BattleStatus.Petrified, &EffectStatusNotSkill{})
|
||||
tt(info.PetStatus.Paralysis, &EffectStatusNotSkill{})
|
||||
tt(info.PetStatus.Tired, &EffectStatusNotSkill{})
|
||||
tt(info.PetStatus.Sleep, &EffectStatusNotSkill{})
|
||||
tt(info.PetStatus.Petrified, &EffectStatusNotSkill{})
|
||||
|
||||
}
|
||||
|
||||
@@ -75,6 +75,14 @@ func (f *FightC) GetRand() *rand.Rand {
|
||||
|
||||
}
|
||||
|
||||
// 加载进度
|
||||
func (f *FightC) LoadPercent(c common.PlayerI, percent int32) {
|
||||
f.GetInputByPlayer(c, true).Player.SendLoadPercent(info.LoadPercentOutboundInfo{
|
||||
Id: c.GetInfo().UserID,
|
||||
Percent: uint32(percent),
|
||||
})
|
||||
}
|
||||
|
||||
func (f *FightC) initplayer(c common.PlayerI, opp bool) {
|
||||
|
||||
temp := input.NewInput(f, c)
|
||||
@@ -138,21 +146,21 @@ func (f *FightC) initplayer(c common.PlayerI, opp bool) {
|
||||
}
|
||||
|
||||
// 创建新战斗,邀请方和被邀请方,或者玩家和野怪方
|
||||
func NewFight(i info.EnumBattleMode, p1 common.PlayerI, p2 common.PlayerI) *FightC {
|
||||
func NewFight(mode, status info.EnumBattleMode, p1 common.PlayerI, p2 common.PlayerI) *FightC {
|
||||
f := &FightC{}
|
||||
f.ownerID = p1.GetInfo().UserID
|
||||
f.Info.FightId = i //房主
|
||||
switch i {
|
||||
case info.BattleMode.PVP_6V6:
|
||||
f.Info.MAXPET = 6
|
||||
case info.BattleMode.PVP_1V1:
|
||||
f.Info.Status = status //房主
|
||||
f.Info.Mode = mode
|
||||
switch mode {
|
||||
case info.BattleMode.SINGLE_MODE:
|
||||
f.Info.MAXPET = 1
|
||||
default:
|
||||
}
|
||||
seed := f.StartTime.UnixNano() ^ int64(p1.GetInfo().UserID) ^ int64(p2.GetInfo().UserID) // ^ int64(f.Round) // 用异或运算混合多维度信息
|
||||
f.rand = rand.New(rand.NewSource(seed))
|
||||
f.Info = info.NoteReadyToFightInfo{
|
||||
|
||||
FightId: i,
|
||||
Status: status,
|
||||
}
|
||||
f.initplayer(p1, false)
|
||||
|
||||
@@ -258,7 +266,7 @@ func (f *FightC) battleLoop() {
|
||||
|
||||
}
|
||||
|
||||
if action.GetPlayerID() != 0 && f.Info.FightId == 3 {
|
||||
if action.GetPlayerID() != 0 && f.Info.Status == 3 {
|
||||
|
||||
f.GetInputByAction(action, true).GetAction(f.Our)
|
||||
|
||||
|
||||
@@ -26,9 +26,15 @@ import (
|
||||
type EnumBattleMode int
|
||||
|
||||
var BattleMode = enum.New[struct {
|
||||
PVE EnumBattleMode `enum:"3"`
|
||||
PVP_6V6 EnumBattleMode `enum:"2"`
|
||||
PVP_1V1 EnumBattleMode `enum:"1"`
|
||||
SINGLE_MODE EnumBattleMode `enum:"1"` // 单人模式
|
||||
MULTI_MODE EnumBattleMode `enum:"2"` // 多人模式
|
||||
}]()
|
||||
var BattleStatus = enum.New[struct {
|
||||
// 原ActionScript中的常量映射
|
||||
FIGHT_WITH_NPC EnumBattleMode `enum:"0"` // 与NPC战斗
|
||||
FIGHT_WITH_BOSS EnumBattleMode `enum:"1"` // 与BOSS战斗
|
||||
FIGHT_WITH_PLAYER EnumBattleMode `enum:"2"` // 与玩家战斗(PVP)
|
||||
|
||||
}]()
|
||||
|
||||
// 玩家离线数据
|
||||
|
||||
@@ -123,9 +123,9 @@ type WeakenedS struct {
|
||||
}
|
||||
|
||||
// 定义战斗状态枚举
|
||||
var BattleStatus = enum.New[struct {
|
||||
var PetStatus = enum.New[struct {
|
||||
// 麻痹
|
||||
Paralysis EnumBattleStatus `enum:"0"`
|
||||
Paralysis EnumBattleStatus `enum:"0"`
|
||||
Poisoned EnumBattleStatus `enum:"1"` // 中毒
|
||||
Burned EnumBattleStatus `enum:"2"` // 烧伤
|
||||
DrainHP EnumBattleStatus `enum:"3"` // 吸取对方的体力
|
||||
@@ -201,8 +201,8 @@ type NoteReadyToFightInfo struct {
|
||||
MAXPET uint32 `struc:"skip"` // 最大精灵数 struc:"skip"`
|
||||
// 战斗类型ID(与野怪战斗为3,与人战斗为1,前端似乎未使用)
|
||||
// @UInt long
|
||||
FightId EnumBattleMode `fieldDesc:"战斗类型ID 但前端好像没有用到 与野怪战斗为3,与人战斗似乎是1" `
|
||||
|
||||
Status EnumBattleMode `fieldDesc:"战斗类型ID 但前端好像没有用到 与野怪战斗为3,与人战斗似乎是1" `
|
||||
Mode EnumBattleMode `struc:"skip"`
|
||||
// 我方信息
|
||||
OurInfo FightUserInfo `fieldDesc:"我方信息" serialize:"struct"`
|
||||
// Our *socket.Player `struc:"skip"`
|
||||
@@ -282,3 +282,9 @@ type CatchMonsterOutboundInfo struct {
|
||||
|
||||
PetId uint32 `json:"petId" `
|
||||
}
|
||||
type LoadPercentOutboundInfo struct {
|
||||
// 玩家userId,使用结构体标签模拟注解
|
||||
Id uint32 `fieldDescription:"玩家userId" autoCodec:"true"`
|
||||
// 加载百分比,使用结构体标签模拟注解
|
||||
Percent uint32 `fieldDescription:"加载百分比" autoCodec:"true"`
|
||||
}
|
||||
|
||||
@@ -66,9 +66,9 @@ func (i *Input) GetPet(id uint32) (ii *info.BattlePetEntity, Reason info.ChangeP
|
||||
func (i *Input) GetStatusBonus() float64 {
|
||||
// 异常状态倍率映射表(状态索引 -> 倍率)
|
||||
var statusBonuses = map[info.EnumBattleStatus]float64{
|
||||
info.BattleStatus.Paralysis: 1.5,
|
||||
info.BattleStatus.Poisoned: 1.5,
|
||||
info.BattleStatus.Sleep: 2.0,
|
||||
info.PetStatus.Paralysis: 1.5,
|
||||
info.PetStatus.Poisoned: 1.5,
|
||||
info.PetStatus.Sleep: 2.0,
|
||||
// /info.BattleStatus.Frozen: 2.0,
|
||||
}
|
||||
maxBonus := 1.0 // 默认无状态倍率
|
||||
|
||||
@@ -109,7 +109,7 @@ func (f *FightC) ReadyFight(c common.PlayerI) {
|
||||
f.Opp.Player.SendReadyToFightInfo(rett)
|
||||
}
|
||||
|
||||
switch f.Info.FightId {
|
||||
switch f.Info.Status {
|
||||
case 1: // 1v1
|
||||
|
||||
f.GetInputByPlayer(c, false).Finished = true
|
||||
|
||||
@@ -44,3 +44,6 @@ func (p *AI_player) SendAttackValue(info.AttackValueS) {
|
||||
func (p *AI_player) SendChangePet(info.ChangePetInfo) {
|
||||
|
||||
}
|
||||
func (lw *AI_player) SendLoadPercent(info.LoadPercentOutboundInfo) {
|
||||
|
||||
}
|
||||
|
||||
@@ -473,9 +473,14 @@ func (lw *Player) CanBattle() bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
func (p *Player) SendLoadPercent(b info.LoadPercentOutboundInfo) {
|
||||
t1 := NewTomeeHeader(2441, p.Info.UserID)
|
||||
|
||||
p.SendPack(t1.Pack(&b)) //准备包由各自发,因为协议不一样
|
||||
}
|
||||
|
||||
// 同意对战
|
||||
func (lw *Player) AgreeBattle(userid, flag, mode uint32) (bool, common.PlayerI) {
|
||||
func (lw *Player) AgreeBattle(userid, flag uint32, mode info.EnumBattleMode) (bool, common.PlayerI) {
|
||||
|
||||
defer func(p *Player) {
|
||||
p.HavePVPinfo = make([]*Player, 0)
|
||||
@@ -503,7 +508,7 @@ func (lw *Player) AgreeBattle(userid, flag, mode uint32) (bool, common.PlayerI)
|
||||
v.SendPack(t1.Pack(ret))
|
||||
return false, nil
|
||||
}
|
||||
if v.PVPinfo.PlayerID == userid && uint32(v.PVPinfo.Mode) == mode { //成功找到,同意对战
|
||||
if v.PVPinfo.PlayerID == userid && v.PVPinfo.Mode == mode { //成功找到,同意对战
|
||||
if lw.CanBattle() {
|
||||
ret.Result = 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user