Skip to content

Commit

Permalink
Merge pull request #3326 from wowsims/apl
Browse files Browse the repository at this point in the history
Refactor stat result protos to include pet and targets spells/auras i…
  • Loading branch information
jimmyt857 authored Jul 16, 2023
2 parents 414b1d4 + f026ee3 commit fdebb3b
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 32 deletions.
20 changes: 17 additions & 3 deletions proto/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ message APLStats {
repeated APLActionStats prepull_actions = 1;
repeated APLActionStats priority_list = 2;
}
message UnitMetadata {
repeated SpellStats spells = 1;
repeated AuraStats auras = 2;
}
message PetStats {
UnitMetadata metadata = 1;
}
message PlayerStats {
// Stats
UnitStats base_stats = 6;
Expand All @@ -326,19 +333,26 @@ message PlayerStats {
repeated string sets = 3;
IndividualBuffs buffs = 4;

repeated SpellStats spells = 10;
repeated AuraStats auras = 11;

UnitMetadata metadata = 10;
APLStats rotation_stats = 12;

repeated PetStats pets = 11;
}
message PartyStats {
repeated PlayerStats players = 1;
}
message RaidStats {
repeated PartyStats parties = 1;
}
message TargetStats {
UnitMetadata metadata = 1;
}
message EncounterStats {
repeated TargetStats targets = 1;
}
message ComputeStatsResult {
RaidStats raid_stats = 1;
EncounterStats encounter_stats = 3;
string error_result = 2;
}

Expand Down
5 changes: 3 additions & 2 deletions sim/core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ func ComputeStats(csr *proto.ComputeStatsRequest) *proto.ComputeStatsResult {
if encounter == nil {
encounter = &proto.Encounter{}
}
_, raidStats := NewEnvironment(csr.Raid, encounter)
_, raidStats, encounterStats := NewEnvironment(csr.Raid, encounter)

return &proto.ComputeStatsResult{
RaidStats: raidStats,
RaidStats: raidStats,
EncounterStats: encounterStats,
}
}

Expand Down
27 changes: 6 additions & 21 deletions sim/core/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,27 +503,12 @@ func (character *Character) FillPlayerStats(playerStats *proto.PlayerStats) {
character.clearBuildPhaseAuras(CharacterBuildPhaseAll)
playerStats.Sets = character.GetActiveSetBonusNames()

playerStats.Spells = MapSlice(character.Spellbook, func(spell *Spell) *proto.SpellStats {
return &proto.SpellStats{
Id: spell.ActionID.ToProto(),

IsCastable: spell.Flags.Matches(SpellFlagAPL),
IsMajorCooldown: spell.Flags.Matches(SpellFlagMCD),
HasDot: spell.dots != nil || spell.aoeDot != nil,
PrepullOnly: spell.Flags.Matches(SpellFlagPrepullOnly),
}
})

aplAuras := FilterSlice(character.auras, func(aura *Aura) bool {
return !aura.ActionID.IsEmptyAction()
})
playerStats.Auras = MapSlice(aplAuras, func(aura *Aura) *proto.AuraStats {
return &proto.AuraStats{
Id: aura.ActionID.ToProto(),
MaxStacks: aura.MaxStacks,
HasIcd: aura.Icd != nil,
}
})
playerStats.Metadata = character.GetMetadata()
for _, petAgent := range character.Pets {
playerStats.Pets = append(playerStats.Pets, &proto.PetStats{
Metadata: petAgent.GetPet().GetMetadata(),
})
}

if character.Rotation != nil {
playerStats.RotationStats = character.Rotation.getStats()
Expand Down
11 changes: 9 additions & 2 deletions sim/core/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Environment struct {
prepullActions []PrepullAction
}

func NewEnvironment(raidProto *proto.Raid, encounterProto *proto.Encounter) (*Environment, *proto.RaidStats) {
func NewEnvironment(raidProto *proto.Raid, encounterProto *proto.Encounter) (*Environment, *proto.RaidStats, *proto.EncounterStats) {
env := &Environment{
State: Created,
}
Expand All @@ -54,7 +54,14 @@ func NewEnvironment(raidProto *proto.Raid, encounterProto *proto.Encounter) (*En
raidStats := env.initialize(raidProto, encounterProto)
env.finalize(raidProto, encounterProto, raidStats)

return env, raidStats
encounterStats := &proto.EncounterStats{}
for _, target := range env.Encounter.Targets {
encounterStats.Targets = append(encounterStats.Targets, &proto.TargetStats{
Metadata: target.GetMetadata(),
})
}

return env, raidStats, encounterStats
}

// The construction phase.
Expand Down
2 changes: 1 addition & 1 deletion sim/core/sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func NewSim(rsr *proto.RaidSimRequest) *Simulation {
rseed = time.Now().UnixNano()
}

env, _ := NewEnvironment(rsr.Raid, rsr.Encounter)
env, _, _ := NewEnvironment(rsr.Raid, rsr.Encounter)
return &Simulation{
Environment: env,
Options: simOptions,
Expand Down
28 changes: 28 additions & 0 deletions sim/core/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,31 @@ func (unit *Unit) GetSpellsMatchingSchool(school SpellSchool) []*Spell {
}
return spells
}

func (unit *Unit) GetMetadata() *proto.UnitMetadata {
metadata := &proto.UnitMetadata{}

metadata.Spells = MapSlice(unit.Spellbook, func(spell *Spell) *proto.SpellStats {
return &proto.SpellStats{
Id: spell.ActionID.ToProto(),

IsCastable: spell.Flags.Matches(SpellFlagAPL),
IsMajorCooldown: spell.Flags.Matches(SpellFlagMCD),
HasDot: spell.dots != nil || spell.aoeDot != nil,
PrepullOnly: spell.Flags.Matches(SpellFlagPrepullOnly),
}
})

aplAuras := FilterSlice(unit.auras, func(aura *Aura) bool {
return !aura.ActionID.IsEmptyAction()
})
metadata.Auras = MapSlice(aplAuras, func(aura *Aura) *proto.AuraStats {
return &proto.AuraStats{
Id: aura.ActionID.ToProto(),
MaxStacks: aura.MaxStacks,
HasIcd: aura.Icd != nil,
}
})

return metadata
}
2 changes: 1 addition & 1 deletion sim/rogue/rogue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func GenerateCriticalDamageMultiplierTestCase(
TalentsString: talents,
}, spec), nil, nil, nil)
encounter := core.MakeSingleTargetEncounter(0.0)
env, _ := core.NewEnvironment(raid, encounter)
env, _, _ := core.NewEnvironment(raid, encounter)
agent := env.Raid.Parties[0].Players[0]
rog := agent.(RogueAgent).GetRogue()
actualMultiplier := 0.0
Expand Down
4 changes: 2 additions & 2 deletions ui/core/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@ export class Player<SpecType extends Spec> {
}

private async updateSpellsAndAuras(eventID: EventID) {
let newSpells = this.currentStats.spells.map(spell => {
let newSpells = this.currentStats.metadata!.spells.map(spell => {
return {
data: spell,
id: ActionId.fromProto(spell.id!),
};
});
let newAuras = this.currentStats.auras.map(aura => {
let newAuras = this.currentStats.metadata!.auras.map(aura => {
return {
data: aura,
id: ActionId.fromProto(aura.id!),
Expand Down

0 comments on commit fdebb3b

Please sign in to comment.