118 lines
4.1 KiB
Go
118 lines
4.1 KiB
Go
package input
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"blazing/common/socket/errorcode"
|
|
"blazing/logic/service/common"
|
|
fightinfo "blazing/logic/service/fight/info"
|
|
spaceinfo "blazing/logic/service/space/info"
|
|
"blazing/modules/player/model"
|
|
)
|
|
|
|
type teamTestPlayer struct {
|
|
info model.PlayerInfo
|
|
fightInfo fightinfo.Fightinfo
|
|
}
|
|
|
|
func (p *teamTestPlayer) ApplyPetDisplayInfo(*spaceinfo.SimpleInfo) {}
|
|
func (p *teamTestPlayer) GetPlayerCaptureContext() *fightinfo.PlayerCaptureContext { return nil }
|
|
func (p *teamTestPlayer) Roll(int, int) (bool, float64, float64) { return false, 0, 0 }
|
|
func (p *teamTestPlayer) Getfightinfo() fightinfo.Fightinfo { return p.fightInfo }
|
|
func (p *teamTestPlayer) ItemAdd(int64, int64) bool { return false }
|
|
func (p *teamTestPlayer) GetInfo() *model.PlayerInfo { return &p.info }
|
|
func (p *teamTestPlayer) InvitePlayer(common.PlayerI) {}
|
|
func (p *teamTestPlayer) SetFightC(common.FightI) {}
|
|
func (p *teamTestPlayer) QuitFight() {}
|
|
func (p *teamTestPlayer) MessWin(bool) {}
|
|
func (p *teamTestPlayer) CanFight() errorcode.ErrorCode { return 0 }
|
|
func (p *teamTestPlayer) SendPackCmd(uint32, any) {}
|
|
func (p *teamTestPlayer) GetPetInfo(uint32) []model.PetInfo { return nil }
|
|
|
|
func TestLivingTeammatesFiltersSelfAndDeadSlots(t *testing.T) {
|
|
owner := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 10}}}}
|
|
aliveMate := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 5}}}}
|
|
deadMate := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 0}}}}
|
|
|
|
team := []*Input{owner, aliveMate, deadMate}
|
|
owner.Team = team
|
|
aliveMate.Team = team
|
|
deadMate.Team = team
|
|
|
|
teammates := owner.LivingTeammates()
|
|
if len(teammates) != 1 {
|
|
t.Fatalf("expected 1 living teammate, got %d", len(teammates))
|
|
}
|
|
if teammates[0] != aliveMate {
|
|
t.Fatalf("expected alive teammate to be returned")
|
|
}
|
|
if owner.HasLivingTeammate() != true {
|
|
t.Fatalf("expected owner to detect living teammate")
|
|
}
|
|
}
|
|
|
|
func TestTeamSlotIndexKeepsOriginalSlot(t *testing.T) {
|
|
first := &Input{}
|
|
second := &Input{}
|
|
third := &Input{}
|
|
|
|
team := []*Input{first, second, third}
|
|
first.Team = team
|
|
second.Team = team
|
|
third.Team = team
|
|
|
|
if got := third.TeamSlotIndex(); got != 2 {
|
|
t.Fatalf("expected slot index 2, got %d", got)
|
|
}
|
|
}
|
|
|
|
func TestRandomOpponentSlotIndexPrefersLivingTarget(t *testing.T) {
|
|
owner := &Input{}
|
|
deadOpp := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 0}}}}
|
|
liveOpp := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 12}}}}
|
|
|
|
owner.OppTeam = []*Input{deadOpp, liveOpp}
|
|
|
|
if got := owner.RandomOpponentSlotIndex(); got != 1 {
|
|
t.Fatalf("expected living opponent slot 1, got %d", got)
|
|
}
|
|
if got := owner.OpponentSlotAt(1); got != liveOpp {
|
|
t.Fatalf("expected opponent slot 1 to return live opponent")
|
|
}
|
|
}
|
|
|
|
func TestInputModeHelpers(t *testing.T) {
|
|
playerA := &teamTestPlayer{info: model.PlayerInfo{UserID: 1001}}
|
|
playerB := &teamTestPlayer{info: model.PlayerInfo{UserID: 1002}}
|
|
|
|
solo := &Input{}
|
|
soloMate := &Input{}
|
|
groupMate := &Input{}
|
|
|
|
solo.Player = playerA
|
|
soloMate.Player = playerA
|
|
groupMate.Player = playerB
|
|
|
|
solo.Team = []*Input{solo}
|
|
solo.OppTeam = []*Input{{}}
|
|
if solo.IsMultiInputBattle() {
|
|
t.Fatalf("expected single-input battle to be false")
|
|
}
|
|
|
|
solo.Team = []*Input{solo, soloMate}
|
|
if !solo.IsMultiInputBattle() {
|
|
t.Fatalf("expected multi-input battle to be true")
|
|
}
|
|
if !solo.IsSingleControllerMultiInputSide() {
|
|
t.Fatalf("expected same-controller double side to be single-controller multi-input")
|
|
}
|
|
|
|
solo.Team = []*Input{solo, groupMate}
|
|
if solo.TeamControllerCount() != 2 {
|
|
t.Fatalf("expected group side controller count 2, got %d", solo.TeamControllerCount())
|
|
}
|
|
if solo.IsSingleControllerMultiInputSide() {
|
|
t.Fatalf("expected grouped side not to be single-controller multi-input")
|
|
}
|
|
}
|