Skip to content

Commit

Permalink
Revert "Merge pull request #1781 from wowsims/fixes"
Browse files Browse the repository at this point in the history
This reverts commit 39fbfde, reversing
changes made to df938cc.
  • Loading branch information
Watcher7 committed Nov 20, 2022
1 parent 04ab3c8 commit 7250b72
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 97 deletions.
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ sim/core/items/all_items.go: tools/generate_items/*.go $(call rwildcard,sim/core

.PHONY: test
test: $(OUT_DIR)/lib.wasm binary_dist/dist.go
go test --tags=with_db ./...
go test ./...

.PHONY: update-tests
update-tests:
Expand Down
7 changes: 4 additions & 3 deletions proto/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,20 @@ message Player {
TankDeathknight tank_deathknight = 32;
}

// Only used by the UI. Sim uses talents within the spec protos.
string talentsString = 17;

Glyphs glyphs = 28;

Profession profession1 = 29;
Profession profession2 = 30;

Cooldowns cooldowns = 19;

bool in_front_of_target = 23;
double distance_from_target = 33;

HealingModel healing_model = 27;

// Items/enchants/gems/etc to include in the database.
SimDatabase database = 35;
}

message Party {
Expand Down
4 changes: 0 additions & 4 deletions sim/core/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ type Character struct {
}

func NewCharacter(party *Party, partyIndex int, player *proto.Player) Character {
if player.Database != nil {
addToDatabase(player.Database)
}

character := Character{
Unit: Unit{
Type: PlayerUnit,
Expand Down
6 changes: 1 addition & 5 deletions sim/core/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ import (
"google.golang.org/protobuf/encoding/protojson"
)

var WITH_DB = false

var ItemsByID = map[int32]Item{}
var GemsByID = map[int32]Gem{}
var EnchantsByItemByID = map[proto.ItemType]map[int32]Enchant{}

func addToDatabase(newDB *proto.SimDatabase) {
for _, v := range newDB.Items {
if _, ok := ItemsByID[v.Id]; !ok {
item := ItemFromProto(v)
ItemsByID[v.Id] = item
AddItemToSets(item)
ItemsByID[v.Id] = ItemFromProto(v)
}
}

Expand Down
5 changes: 0 additions & 5 deletions sim/core/database_load.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Only include this file in the build when we specify the 'with_db' tag.
// Without the tag, the database will start out completely empty.
//go:build with_db

package core

import (
Expand All @@ -11,7 +7,6 @@ import (

func init() {
db := database.Load()
WITH_DB = true

simDB := &proto.SimDatabase{
Items: make([]*proto.SimItem, len(db.Items)),
Expand Down
44 changes: 19 additions & 25 deletions sim/core/item_effects.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ func HasEnchantEffect(id int32) bool {
// Registers an ApplyEffect function which will be called before the Sim
// starts, for any Agent that is wearing the item.
func NewItemEffect(id int32, itemEffect ApplyEffect) {
if WITH_DB {
if _, hasItem := ItemsByID[id]; !hasItem {
if _, hasGem := GemsByID[id]; !hasGem {
panic(fmt.Sprintf("No item with ID: %d", id))
}
if _, hasItem := ItemsByID[id]; !hasItem {
if _, hasGem := GemsByID[id]; !hasGem {
panic(fmt.Sprintf("No item with ID: %d", id))
}
}

Expand All @@ -73,18 +71,16 @@ func NewItemEffect(id int32, itemEffect ApplyEffect) {
}

func NewEnchantEffect(id int32, enchantEffect ApplyEffect) {
if WITH_DB {
found := false
for _, enchantsByID := range EnchantsByItemByID {
if _, ok := enchantsByID[id]; ok {
found = true
break
}
}
if !found {
panic(fmt.Sprintf("No enchant with ID: %d", id))
found := false
for _, enchantsByID := range EnchantsByItemByID {
if _, ok := enchantsByID[id]; ok {
found = true
break
}
}
if !found {
panic(fmt.Sprintf("No enchant with ID: %d", id))
}

if HasEnchantEffect(id) {
panic(fmt.Sprintf("Cannot add multiple effects for one enchant: %d, %#v", id, enchantEffect))
Expand All @@ -94,18 +90,16 @@ func NewEnchantEffect(id int32, enchantEffect ApplyEffect) {
}

func AddWeaponEffect(id int32, weaponEffect ApplyWeaponEffect) {
if WITH_DB {
found := false
for _, enchantsByID := range EnchantsByItemByID {
if _, ok := enchantsByID[id]; ok {
found = true
break
}
}
if !found {
panic(fmt.Sprintf("No enchant with ID: %d", id))
found := false
for _, enchantsByID := range EnchantsByItemByID {
if _, ok := enchantsByID[id]; ok {
found = true
break
}
}
if !found {
panic(fmt.Sprintf("No enchant with ID: %d", id))
}
if HasWeaponEffect(id) {
panic(fmt.Sprintf("Cannot add multiple effects for one item: %d, %#v", id, weaponEffect))
}
Expand Down
21 changes: 5 additions & 16 deletions sim/core/item_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,11 @@ func NewItemSet(setStruct ItemSet) *ItemSet {
}
}
}

if WITH_DB {
if !foundName {
panic("No items found for set " + set.Name)
}
if len(set.AlternativeName) > 0 && !foundAlternativeName {
panic("No items found for set alternative " + set.AlternativeName)
}
if !foundName {
panic("No items found for set " + set.Name)
}
if len(set.AlternativeName) > 0 && !foundAlternativeName {
panic("No items found for set alternative " + set.AlternativeName)
}

sets = append(sets, set)
Expand All @@ -87,14 +84,6 @@ func NewItemSet(setStruct ItemSet) *ItemSet {
return set
}

func AddItemToSets(item Item) {
for _, set := range sets {
if set.Name == item.SetName || set.AlternativeName == item.SetName {
set.Items[item.ID] = struct{}{}
}
}
}

func (character *Character) HasSetBonus(itemSet *ItemSet, numItems int32) bool {
if character.Env != nil && character.Env.IsFinalized() {
panic("HasSetBonus is very slow and should never be called after finalization. Try caching the value during construction instead!")
Expand Down
9 changes: 3 additions & 6 deletions sim/core/test_generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,9 @@ func (filter *ItemFilter) FindAllSets() []*ItemSet {
filteredSets := []*ItemSet{}

for _, set := range GetAllItemSets() {
itemIDs := set.ItemIDs()
if len(itemIDs) > 0 {
firstItem := ItemsByID[itemIDs[0]]
if filter.Matches(firstItem, true) {
filteredSets = append(filteredSets, set)
}
firstItem := ItemsByID[set.ItemIDs()[0]]
if filter.Matches(firstItem, true) {
filteredSets = append(filteredSets, set)
}
}

Expand Down
9 changes: 3 additions & 6 deletions ui/core/player.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {
Class,
Consumes,
Cooldowns,
Faction,
Consumes,
GemColor,
Glyphs,
HandType,
Expand All @@ -13,8 +12,8 @@ import {
Race,
RaidTarget,
RangedWeaponType,
SimDatabase,
Spec,
Faction,
Stat,
WeaponType,
} from './proto/common.js';
Expand Down Expand Up @@ -796,14 +795,13 @@ export class Player<SpecType extends Spec> {
}

toProto(forExport?: boolean): PlayerProto {
const gear = this.getGear();
return withSpecProto(
this.spec,
PlayerProto.create({
name: this.getName(),
race: this.getRace(),
class: this.getClass(),
equipment: gear.asSpec(),
equipment: this.getGear().asSpec(),
consumes: this.getConsumes(),
bonusStats: this.getBonusStats().asArray(),
buffs: this.getBuffs(),
Expand All @@ -815,7 +813,6 @@ export class Player<SpecType extends Spec> {
inFrontOfTarget: this.getInFrontOfTarget(),
distanceFromTarget: this.getDistanceFromTarget(),
healingModel: this.getHealingModel(),
database: forExport ? SimDatabase.create() : gear.toDatabase(),
}),
this.getRotation(),
forExport ? this.specTypeFunctions.talentsCreate() : this.getTalents(),
Expand Down
27 changes: 1 addition & 26 deletions ui/core/proto_utils/gear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ import { GemColor } from '../proto/common.js';
import { ItemSlot } from '../proto/common.js';
import { ItemSpec } from '../proto/common.js';
import { Profession } from '../proto/common.js';
import { SimDatabase } from '../proto/common.js';
import { SimItem } from '../proto/common.js';
import { SimEnchant } from '../proto/common.js';
import { SimGem } from '../proto/common.js';
import { WeaponType } from '../proto/common.js';
import { equalsOrBothNull } from '../utils.js';
import { distinct, getEnumValues } from '../utils.js';
import { getEnumValues } from '../utils.js';
import { isBluntWeaponType, isSharpWeaponType } from '../proto_utils/utils.js';
import {
UIEnchant as Enchant,
Expand Down Expand Up @@ -239,25 +235,4 @@ export class Gear {
.map(ei => ei.getFailedProfessionRequirements(professions))
.flat();
}

toDatabase(): SimDatabase {
const equippedItems = this.asArray().filter(ei => ei != null) as Array<EquippedItem>;
return SimDatabase.create({
items: distinct(equippedItems.map(ei => Gear.itemToDB(ei.item))),
enchants: distinct(equippedItems.filter(ei => ei.enchant).map(ei => Gear.enchantToDB(ei.enchant!))),
gems: distinct(equippedItems.map(ei => ei.curGems(true).map(gem => Gear.gemToDB(gem))).flat()),
});
}

private static itemToDB(item: Item): SimItem {
return SimItem.fromJson(Item.toJson(item), { ignoreUnknownFields: true });
}

private static enchantToDB(enchant: Enchant): SimEnchant {
return SimEnchant.fromJson(Enchant.toJson(enchant), { ignoreUnknownFields: true });
}

private static gemToDB(gem: Gem): SimGem {
return SimGem.fromJson(Gem.toJson(gem), { ignoreUnknownFields: true });
}
}

0 comments on commit 7250b72

Please sign in to comment.