49 lines
1.6 KiB
Go
49 lines
1.6 KiB
Go
package sdkserver
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
|
|
"gac-hkrpg-go/internal/common"
|
|
)
|
|
|
|
// Final packets omit detailed statistics on this Client. Attach the native
|
|
// snapshot only to an already received result with the same counters and team.
|
|
// Keep the server's outcome, scene identity and monster analysis.
|
|
func saveFinalBattleDetails(details *common.BattleReport) error {
|
|
base, err := common.LoadLatestBattleReport()
|
|
if err != nil {
|
|
return fmt.Errorf("completed battle result is not available yet")
|
|
}
|
|
if details == nil || details.TotalBattleTurns != base.TotalBattleTurns ||
|
|
math.Abs(details.CostTime-base.CostTime) > 0.001 ||
|
|
(details.StageID != 0 && details.StageID != base.StageID) ||
|
|
(details.BattleID != 0 && details.BattleID != base.BattleID) ||
|
|
len(details.Avatars) != len(base.Avatars) {
|
|
return fmt.Errorf("native statistics do not match the completed battle")
|
|
}
|
|
ids := make(map[uint32]bool, len(base.Avatars))
|
|
slots := make(map[uint32]*uint32, len(base.Avatars))
|
|
for _, a := range base.Avatars {
|
|
if a != nil {
|
|
ids[a.AvatarID] = true
|
|
slots[a.AvatarID] = a.Slot
|
|
}
|
|
}
|
|
for _, a := range details.Avatars {
|
|
if a == nil || !ids[a.AvatarID] {
|
|
return fmt.Errorf("native statistics team does not match the completed battle")
|
|
}
|
|
delete(ids, a.AvatarID)
|
|
if a.Slot == nil {
|
|
a.Slot = slots[a.AvatarID]
|
|
}
|
|
}
|
|
if len(ids) != 0 {
|
|
return fmt.Errorf("native statistics team is incomplete")
|
|
}
|
|
base.Avatars = details.Avatars
|
|
base.TeamTotalDamage, base.TeamTotalHeal, base.TeamTotalShield = details.TeamTotalDamage, details.TeamTotalHeal, details.TeamTotalShield
|
|
return common.SaveBattleReport(base)
|
|
}
|