refactor: 重构战斗系统为统一动作包结构
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
113
logic/service/fight/unified_test.go
Normal file
113
logic/service/fight/unified_test.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package fight
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/logic/service/common"
|
||||
fightinfo "blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
spaceinfo "blazing/logic/service/space/info"
|
||||
"blazing/modules/player/model"
|
||||
)
|
||||
|
||||
type stubPlayer struct {
|
||||
info model.PlayerInfo
|
||||
}
|
||||
|
||||
func (*stubPlayer) ApplyPetDisplayInfo(*spaceinfo.SimpleInfo) {}
|
||||
func (*stubPlayer) GetPlayerCaptureContext() *fightinfo.PlayerCaptureContext { return nil }
|
||||
func (*stubPlayer) Roll(int, int) (bool, float64, float64) { return false, 0, 0 }
|
||||
func (*stubPlayer) Getfightinfo() fightinfo.Fightinfo { return fightinfo.Fightinfo{} }
|
||||
func (*stubPlayer) ItemAdd(int64, int64) bool { return false }
|
||||
func (p *stubPlayer) GetInfo() *model.PlayerInfo { return &p.info }
|
||||
func (*stubPlayer) InvitePlayer(common.PlayerI) {}
|
||||
func (*stubPlayer) SetFightC(common.FightI) {}
|
||||
func (*stubPlayer) QuitFight() {}
|
||||
func (*stubPlayer) MessWin(bool) {}
|
||||
func (*stubPlayer) CanFight() errorcode.ErrorCode { return 0 }
|
||||
func (*stubPlayer) SendPackCmd(uint32, any) {}
|
||||
func (*stubPlayer) GetPetInfo(uint32) []model.PetInfo { return nil }
|
||||
|
||||
func TestFightActionEnvelopeEncodedTargetIndex(t *testing.T) {
|
||||
self := NewSkillActionEnvelope(1, 2, 0, SkillTargetSelf, 0)
|
||||
if got := self.EncodedTargetIndex(); got != EncodeTargetIndex(2, false) {
|
||||
t.Fatalf("expected self target to encode actor slot, got %d", got)
|
||||
}
|
||||
|
||||
ally := NewSkillActionEnvelope(1, 0, 1, SkillTargetAlly, 0)
|
||||
if got := ally.EncodedTargetIndex(); got != EncodeTargetIndex(1, false) {
|
||||
t.Fatalf("expected ally target to keep friendly slot, got %d", got)
|
||||
}
|
||||
|
||||
fallbackSelf := NewSkillActionEnvelope(1, 3, 0, 9, 3)
|
||||
if got := fallbackSelf.EncodedTargetIndex(); got != EncodeTargetIndex(3, false) {
|
||||
t.Fatalf("expected atkType=3 to fall back to self target, got %d", got)
|
||||
}
|
||||
|
||||
opponent := NewSkillActionEnvelope(1, 0, 2, SkillTargetOpponent, 0)
|
||||
if got := opponent.EncodedTargetIndex(); got != EncodeTargetIndex(2, true) {
|
||||
t.Fatalf("expected opponent target to stay on opposite side, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildFightStateStartEnvelope(t *testing.T) {
|
||||
ourPlayer := &stubPlayer{info: model.PlayerInfo{UserID: 1001}}
|
||||
oppPlayer := &stubPlayer{info: model.PlayerInfo{UserID: 2002}}
|
||||
|
||||
our := input.NewInput(nil, ourPlayer)
|
||||
our.InitAttackValue()
|
||||
our.AttackValue.Prop[0] = 2
|
||||
our.AttackValue.Status[1] = 1
|
||||
ourPet := fightinfo.CreateBattlePetEntity(model.PetInfo{
|
||||
ID: 11,
|
||||
Name: "Alpha",
|
||||
Level: 20,
|
||||
Hp: 88,
|
||||
MaxHp: 100,
|
||||
CatchTime: 101,
|
||||
SkillList: []model.SkillInfo{{ID: 300, PP: 10}},
|
||||
})
|
||||
ourPet.BindController(ourPlayer.info.UserID)
|
||||
our.SetCurPetAt(0, ourPet)
|
||||
|
||||
opp := input.NewInput(nil, oppPlayer)
|
||||
opp.InitAttackValue()
|
||||
oppPet := fightinfo.CreateBattlePetEntity(model.PetInfo{
|
||||
ID: 22,
|
||||
Name: "Beta",
|
||||
Level: 21,
|
||||
Hp: 77,
|
||||
MaxHp: 110,
|
||||
CatchTime: 202,
|
||||
SkillList: []model.SkillInfo{{ID: 400, PP: 5}},
|
||||
})
|
||||
oppPet.BindController(oppPlayer.info.UserID)
|
||||
opp.SetCurPetAt(0, oppPet)
|
||||
|
||||
fc := &FightC{
|
||||
Our: []*input.Input{our},
|
||||
Opp: []*input.Input{opp},
|
||||
}
|
||||
fc.Round = 7
|
||||
|
||||
envelope := fc.BuildFightStateStartEnvelope()
|
||||
if envelope.Phase != fightinfo.FightStatePhaseStart {
|
||||
t.Fatalf("expected start phase, got %s", envelope.Phase)
|
||||
}
|
||||
if envelope.Meta.Round != 7 {
|
||||
t.Fatalf("expected round 7, got %d", envelope.Meta.Round)
|
||||
}
|
||||
if len(envelope.Left) != 1 || len(envelope.Right) != 1 {
|
||||
t.Fatalf("expected one fighter on each side, got left=%d right=%d", len(envelope.Left), len(envelope.Right))
|
||||
}
|
||||
if envelope.Left[0].UserID != 1001 || envelope.Left[0].PetID != 11 {
|
||||
t.Fatalf("unexpected left fighter snapshot: %+v", envelope.Left[0])
|
||||
}
|
||||
if envelope.Left[0].Prop[0] != 2 || envelope.Left[0].Status[1] != 1 {
|
||||
t.Fatalf("expected prop/status snapshot to be copied, got %+v %+v", envelope.Left[0].Prop, envelope.Left[0].Status)
|
||||
}
|
||||
if envelope.Right[0].UserID != 2002 || envelope.Right[0].CatchTime != 202 {
|
||||
t.Fatalf("unexpected right fighter snapshot: %+v", envelope.Right[0])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user