feat: capture in-game battle damage statistics & add battle_report API endpoints
This commit is contained in:
1 parent
5c4d0d4149
commit
365e66ffe0
5 files changed
+415
No files matched your search
@@ -0,0 +1,103 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
goproto "gac-hkrpg-go/protocol/proto"
|
||||
)
|
||||
|
||||
func TestBattleReportSerialization(t *testing.T) {
|
||||
defer os.Remove(BattleReportFile)
|
||||
|
||||
stt := &goproto.BattleStatistics{
|
||||
TotalBattleTurns: 12,
|
||||
TotalAutoTurns: 0,
|
||||
RoundCnt: 2,
|
||||
CostTime: 45.5,
|
||||
ChallengeScore: 1000,
|
||||
BattleAvatarList: []*goproto.AvatarBattleInfo{
|
||||
{
|
||||
Id: 1310,
|
||||
AvatarLevel: 80,
|
||||
AvatarRank: 2,
|
||||
TotalDamage: 500000,
|
||||
TotalDamageTaken: 2500,
|
||||
TotalHeal: 0,
|
||||
TotalBreakDamage: 400000,
|
||||
TotalTurns: 6,
|
||||
AttackTypeDamage: []*goproto.AttackDamageProperty{
|
||||
{AttackType: "Normal", Damage: 20000},
|
||||
{AttackType: "BPSkill", Damage: 80000},
|
||||
{AttackType: "BreakDamage", Damage: 400000},
|
||||
},
|
||||
AttackTypeMaxDamage: []*goproto.AttackDamageProperty{
|
||||
{AttackType: "BreakDamage", Damage: 250000},
|
||||
},
|
||||
SkillTimes: []*goproto.SkillUseProperty{
|
||||
{SkillId: 131001, SkillType: "Normal", SkillUseCount: 1},
|
||||
{SkillId: 131002, SkillType: "BPSkill", SkillUseCount: 4},
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: 1001,
|
||||
AvatarLevel: 80,
|
||||
AvatarRank: 6,
|
||||
TotalDamage: 50000,
|
||||
TotalDamageTaken: 1200,
|
||||
TotalShield: 4500,
|
||||
TotalTurns: 6,
|
||||
AttackTypeDamage: []*goproto.AttackDamageProperty{
|
||||
{AttackType: "Normal", Damage: 50000},
|
||||
},
|
||||
},
|
||||
},
|
||||
MonsterList: []*goproto.MonsterBattleInfo{
|
||||
{
|
||||
EntityId: 101,
|
||||
MonsterId: 3024010,
|
||||
TotalTurns: 3,
|
||||
TotalDamageTaken: 550000,
|
||||
TotalDamage: 3700,
|
||||
Wave: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
report := BattleReportFromStatistics(stt, 999, 1001, "WIN")
|
||||
if report == nil {
|
||||
t.Fatal("expected report, got nil")
|
||||
}
|
||||
if report.TeamTotalDamage != 550000 {
|
||||
t.Fatalf("expected team total damage 550000, got %f", report.TeamTotalDamage)
|
||||
}
|
||||
if len(report.Avatars) != 2 {
|
||||
t.Fatalf("expected 2 avatars, got %d", len(report.Avatars))
|
||||
}
|
||||
if report.Avatars[0].DamagePercent < 90 || report.Avatars[0].DamagePercent > 91 {
|
||||
t.Fatalf("unexpected damage percent %f", report.Avatars[0].DamagePercent)
|
||||
}
|
||||
|
||||
if err := SaveBattleReport(report); err != nil {
|
||||
t.Fatalf("failed to save report: %v", err)
|
||||
}
|
||||
|
||||
loaded, err := LoadLatestBattleReport()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to load report: %v", err)
|
||||
}
|
||||
if loaded.BattleID != 999 {
|
||||
t.Fatalf("expected battle id 999, got %d", loaded.BattleID)
|
||||
}
|
||||
if loaded.TeamTotalDamage != 550000 {
|
||||
t.Fatalf("expected team damage 550000, got %f", loaded.TeamTotalDamage)
|
||||
}
|
||||
|
||||
if err := ClearBattleReport(); err != nil {
|
||||
t.Fatalf("failed to clear report: %v", err)
|
||||
}
|
||||
_, err = LoadLatestBattleReport()
|
||||
if err == nil {
|
||||
t.Fatal("expected error after clearing report, got nil")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user