ws and pruner done!!!

This commit is contained in:
41666 2024-10-28 13:46:52 -07:00
parent c5cc245e25
commit 74add408e6
34 changed files with 1455 additions and 221 deletions

View file

@ -8,3 +8,18 @@ const (
TR
NSO
)
// func (f Faction) UnmarshalJSON(b []byte) error {
// switch b[0] {
// case '1':
// f = VS
// case '2':
// f = NC
// case '3':
// f = TR
// case '4':
// f = NSO
// }
// return nil
// }

27
types/internal.go Normal file
View file

@ -0,0 +1,27 @@
package types
import "time"
type Player struct {
CharacterID string `json:"character_id"`
LastUpdated time.Time `json:"last_updated"`
WorldID uint16 `json:"world_id"`
FactionID Faction `json:"faction_id"`
ZoneID uint32 `json:"zone_id"`
ClassName string `json:"class_name"`
}
type Vehicle struct {
CharacterID string `json:"character_id"`
LastUpdated time.Time `json:"last_updated"`
WorldID uint16 `json:"world_id"`
FactionID Faction `json:"faction_id"`
ZoneID uint32 `json:"zone_id"`
VehicleName string `json:"vehicle_name"`
}
type AnalyticEvent struct {
Time time.Time `json:"time"`
WorldID uint16 `json:"world_id"`
EventName string `json:"event_name"`
}

View file

@ -6,18 +6,23 @@ type ESSData struct {
type ESSEvent struct {
EventName string `json:"event_name"`
WorldID uint16 `json:"world_id"`
ZoneID uint32 `json:"zone_id"`
WorldID uint16 `json:"world_id,string"`
ZoneID uint32 `json:"zone_id,string"`
CharacterID string `json:"character_id"`
LoadoutID string `json:"loadout_id"`
VehicleID string `json:"vehicle_id"`
TeamID Faction `json:"team_id"`
CharacterID string `json:"character_id"`
// On Death
VehicleID string `json:"vehicle_id"`
TeamID Faction `json:"team_id,string"`
CharacterLoadoutID uint16 `json:"character_loadout_id,string"`
AttackerCharacterID string `json:"attacker_character_id"`
AttackerLoadoutID string `json:"attacker_loadout_id"`
AttackerLoadoutID uint16 `json:"attacker_loadout_id,string"`
AttackerVehicleID string `json:"attacker_vehicle_id"`
AttackerTeamID Faction `json:"attacker_team_id"`
AttackerTeamID Faction `json:"attacker_team_id,string"`
ExperienceID uint32
// On GainExperience
ExperienceID uint32 `json:"experience_id,string"`
LoadoutID uint16 `json:"loadout_id,string"`
}

56
types/pop_event.go Normal file
View file

@ -0,0 +1,56 @@
// TODO: tests
package types
import (
"github.com/genudine/saerro-go/translators"
)
type PopEvent struct {
WorldID uint16
ZoneID uint32
CharacterID string
LoadoutID uint16
TeamID Faction
VehicleID string
VehicleName translators.Vehicle
ClassName translators.Class
}
func PopEventFromESSEvent(event ESSEvent, attacker bool) PopEvent {
pe := PopEvent{
WorldID: event.WorldID,
ZoneID: event.ZoneID,
}
if !attacker {
pe.CharacterID = event.CharacterID
pe.LoadoutID = event.CharacterLoadoutID
pe.TeamID = event.TeamID
pe.VehicleID = event.VehicleID
} else {
pe.CharacterID = event.AttackerCharacterID
pe.LoadoutID = event.AttackerLoadoutID
pe.TeamID = event.AttackerTeamID
pe.VehicleID = event.AttackerVehicleID
}
if pe.LoadoutID == 0 {
pe.LoadoutID = event.LoadoutID
}
pe.ClassName = translators.ClassFromLoadout(pe.LoadoutID)
pe.VehicleName = translators.VehicleNameFromID(pe.VehicleID)
return pe
}
func (pe PopEvent) ToPlayer() *Player {
return &Player{
CharacterID: pe.CharacterID,
ClassName: string(pe.ClassName),
FactionID: pe.TeamID,
ZoneID: pe.ZoneID,
WorldID: pe.WorldID,
}
}

72
types/pop_event_test.go Normal file
View file

@ -0,0 +1,72 @@
package types_test
import (
"testing"
"github.com/genudine/saerro-go/types"
"github.com/stretchr/testify/assert"
)
var (
deathEvent = types.ESSEvent{
EventName: "Death",
WorldID: 17,
ZoneID: 4,
CharacterID: "LyytisDoll",
TeamID: types.NC,
CharacterLoadoutID: 4,
AttackerCharacterID: "Lyyti",
AttackerTeamID: types.TR,
AttackerLoadoutID: 3,
}
expEvent = types.ESSEvent{
EventName: "GainExperience",
WorldID: 17,
ZoneID: 4,
CharacterID: "LyytisDoll",
TeamID: types.NC,
LoadoutID: 3,
ExperienceID: 55,
}
)
func TestPopEventFromDeath(t *testing.T) {
victim := types.PopEventFromESSEvent(deathEvent, false)
assert.Equal(t, deathEvent.CharacterID, victim.CharacterID)
assert.Equal(t, deathEvent.TeamID, victim.TeamID)
assert.Equal(t, deathEvent.CharacterLoadoutID, victim.LoadoutID)
assert.Equal(t, "combat_medic", string(victim.ClassName))
attacker := types.PopEventFromESSEvent(deathEvent, true)
assert.Equal(t, deathEvent.AttackerCharacterID, attacker.CharacterID)
assert.Equal(t, deathEvent.AttackerTeamID, attacker.TeamID)
assert.Equal(t, deathEvent.AttackerLoadoutID, attacker.LoadoutID)
assert.Equal(t, "light_assault", string(attacker.ClassName))
}
func TestPopEventFromExperienceGain(t *testing.T) {
pe := types.PopEventFromESSEvent(expEvent, false)
assert.Equal(t, expEvent.CharacterID, pe.CharacterID)
assert.Equal(t, expEvent.TeamID, pe.TeamID)
assert.Equal(t, expEvent.LoadoutID, pe.LoadoutID)
assert.Equal(t, "light_assault", string(pe.ClassName))
}
func TestPopEventFromVehicleDestroy(t *testing.T) {
t.SkipNow()
}
func TestPopEventToPlayer(t *testing.T) {
pe := types.PopEventFromESSEvent(deathEvent, false)
player := pe.ToPlayer()
assert.Equal(t, pe.CharacterID, player.CharacterID)
assert.Equal(t, pe.TeamID, player.FactionID)
assert.Equal(t, pe.ZoneID, player.ZoneID)
assert.Equal(t, string(pe.ClassName), player.ClassName)
assert.Equal(t, pe.WorldID, player.WorldID)
}