fetch static data from txt files and properly get all the item stats... maybe?

This commit is contained in:
Héctor Giménez
2024-05-08 21:31:40 +09:00
parent c03c40d385
commit aa2a1aaeb3
34 changed files with 3539 additions and 96663 deletions

View File

@@ -1,107 +1,106 @@
package nip
var typeAliases = map[string]int{
"shield": 2,
"armor": 3,
"gold": 4,
"bowquiver": 5,
"crossbowquiver": 6,
"playerbodypart": 7,
"herb": 8,
"potion": 9,
"ring": 10,
"elixir": 11,
"amulet": 12,
"charm": 13,
"notused1": 14,
"boots": 15,
"gloves": 16,
"notused2": 17,
"book": 18,
"belt": 19,
"gem": 20,
"torch": 21,
"scroll": 22,
"notused3": 23,
"scepter": 24,
"wand": 25,
"staff": 26,
"bow": 27,
"axe": 28,
"club": 29,
"sword": 30,
"hammer": 31,
"knife": 32,
"spear": 33,
"polearm": 34,
"crossbow": 35,
"mace": 36,
"helm": 37,
"missilepotion": 38,
"quest": 39,
"bodypart": 40,
"key": 41,
"throwingknife": 42,
"throwingaxe": 43,
"javelin": 44,
"weapon": 45,
"meleeweapon": 46,
"missileweapon": 47,
"thrownweapon": 48,
"comboweapon": 49,
"anyarmor": 50,
"anyshield": 51,
"miscellaneous": 52,
"socketfiller": 53,
"secondhand": 54,
"stavesandrods": 55,
"missile": 56,
"blunt": 57,
"jewel": 58,
"classspecific": 59,
"amazonitem": 60,
"barbarianitem": 61,
"necromanceritem": 62,
"paladinitem": 63,
"sorceressitem": 64,
"assassinitem": 65,
"druiditem": 66,
"handtohand": 67,
"orb": 68,
"voodooheads": 69,
"auricshields": 70,
"primalhelm": 71,
"pelt": 72,
"cloak": 73,
"rune": 74,
"circlet": 75,
"healingpotion": 76,
"manapotion": 77,
"rejuvpotion": 78,
"staminapotion": 79,
"antidotepotion": 80,
"thawingpotion": 81,
"smallcharm": 82,
"mediumcharm": 83,
"largecharm": 84,
"amazonbow": 85,
"amazonspear": 86,
"amazonjavelin": 87,
"assassinclaw": 88,
"magicbowquiv": 89,
"magicxbowquiv": 90,
"chippedgem": 91,
"flawedgem": 92,
"standardgem": 93,
"flawlessgem": 94,
"perfectgem": 95,
"amethyst": 96,
"diamond": 97,
"emerald": 98,
"ruby": 99,
"sapphire": 100,
"topaz": 101,
"skull": 102,
import "github.com/hectorgimenez/d2go/pkg/data/item"
var typeAliases = map[string]string{
"shield": item.TypeShield,
"armor": item.TypeArmor,
"gold": item.TypeGold,
"bowquiver": item.TypeBowQuiver,
"crossbowquiver": item.TypeCrossbowQuiver,
"playerbodypart": item.TypePlayerBodyPart,
"herb": item.TypeHerb,
"potion": item.TypePotion,
"ring": item.TypeRing,
"elixir": item.TypeElixir,
"amulet": item.TypeAmulet,
"charm": item.TypeCharm,
"boots": item.TypeBoots,
"gloves": item.TypeGloves,
"book": item.TypeBook,
"belt": item.TypeBelt,
"gem": item.TypeGem,
"torch": item.TypeTorch,
"scroll": item.TypeScroll,
"scepter": item.TypeScepter,
"wand": item.TypeWand,
"staff": item.TypeStaff,
"bow": item.TypeBow,
"axe": item.TypeAxe,
"club": item.TypeClub,
"sword": item.TypeSword,
"hammer": item.TypeHammer,
"knife": item.TypeKnife,
"spear": item.TypeSpear,
"polearm": item.TypePolearm,
"crossbow": item.TypeCrossbow,
"mace": item.TypeMace,
"helm": item.TypeHelm,
"missilepotion": item.TypeMissilePotion,
"quest": item.TypeQuest,
"bodypart": item.TypeBodyPart,
"key": item.TypeKey,
"throwingknife": item.TypeThrowingKnife,
"throwingaxe": item.TypeThrowingAxe,
"javelin": item.TypeJavelin,
"weapon": item.TypeWeapon,
"meleeweapon": item.TypeMeleeWeapon,
"missileweapon": item.TypeMissileWeapon,
"thrownweapon": item.TypeThrownWeapon,
"comboweapon": item.TypeComboWeapon,
"anyarmor": item.TypeAnyArmor,
"anyshield": item.TypeAnyShield,
"miscellaneous": item.TypeMiscellaneous,
"socketfiller": item.TypeSocketFiller,
"secondhand": item.TypeSecondHand,
"stavesandrods": item.TypeStavesAndRods,
"missile": item.TypeMissile,
"blunt": item.TypeBlunt,
"jewel": item.TypeJewel,
"classspecific": item.TypeClassSpecific,
"amazonitem": item.TypeAmazonItem,
"barbarianitem": item.TypeBarbarianItem,
"necromanceritem": item.TypeNecromancerItem,
"paladinitem": item.TypePaladinItem,
"sorceressitem": item.TypeSorceressItem,
"assassinitem": item.TypeAssassinItem,
"druiditem": item.TypeDruidItem,
"handtohand": item.TypeHandtoHand,
"orb": item.TypeOrb,
"voodooheads": item.TypeVoodooHeads,
"auricshields": item.TypeAuricShields,
"primalhelm": item.TypePrimalHelm,
"pelt": item.TypePelt,
"cloak": item.TypeCloak,
"rune": item.TypeRune,
"circlet": item.TypeCirclet,
"healingpotion": item.TypeHealingPotion,
"manapotion": item.TypeManaPotion,
"rejuvpotion": item.TypeRejuvPotion,
"staminapotion": item.TypeStaminaPotion,
"antidotepotion": item.TypeAntidotePotion,
"thawingpotion": item.TypeThawingPotion,
"smallcharm": item.TypeSmallCharm,
"mediumcharm": item.TypeMediumCharm,
"largecharm": item.TypeLargeCharm,
"amazonbow": item.TypeAmazonBow,
"amazonspear": item.TypeAmazonSpear,
"amazonjavelin": item.TypeAmazonJavelin,
"assassinclaw": item.TypeHandtoHand2,
"magicbowquiv": item.TypeMagicBowQuiv,
"magicxbowquiv": item.TypeMagicXbowQuiv,
"chippedgem": item.TypeChippedGem,
"flawedgem": item.TypeFlawedGem,
"standardgem": item.TypeStandardGem,
"flawlessgem": item.TypeFlawlessGem,
"perfectgem": item.TypePerfectGem,
"amethyst": item.TypeAmethyst,
"diamond": item.TypeDiamond,
"emerald": item.TypeEmerald,
"ruby": item.TypeRuby,
"sapphire": item.TypeSapphire,
"topaz": item.TypeTopaz,
"skull": item.TypeSkull,
}
var qualityAliases = map[string]int{
@@ -575,7 +574,7 @@ var statAliases = map[string][]int{
"unused184": {184},
"unused185": {185},
"unused186": {186},
"unused187": {187},
"itempiercecoldimmunity": {187},
"itemaddskilltab": {188},
"itemaddbowandcrossbowskilltab": {188, 0}, "bowandcrossbowskilltab": {188, 0},
@@ -600,12 +599,12 @@ var statAliases = map[string][]int{
"itemaddshadowdisciplinesskilltab": {188, 49}, "shadowdisciplinesskilltab": {188, 49},
"itemaddmartialartsskilltab": {188, 50}, "martialartsskilltab": {188, 50},
"unused189": {189},
"unused190": {190},
"unused191": {191},
"unused192": {192},
"unused193": {193},
"itemnumsockets": {194}, "sockets": {194},
"itempiercefireimmunity": {189},
"itempiercelightimmunity": {190},
"itempiercepoisonimmunity": {191},
"itempiercedamageimmunity": {192},
"itempiercemagicimmunity": {193},
"itemnumsockets": {194}, "sockets": {194},
"itemskillonattack": {195, 1},
"itemskillonattacklevel": {195, 2},
"itemskillonkill": {196, 1},
@@ -783,6 +782,8 @@ var statAliases = map[string][]int{
"questitemdifficulty": {356},
"passivemagmastery": {357},
"passivemagpierce": {358},
"skillcooldown": {359},
"skillmissiledamagescale": {360},
// Doesnt really exists, but is calculated in getStatEx
"allres": {555},

View File

@@ -35,13 +35,13 @@ func ReadDir(path string) (Rules, error) {
}
func ParseNIPFile(filePath string) (Rules, error) {
fileReader, err := os.Open(filePath)
fileToRead, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer fileReader.Close()
defer fileToRead.Close()
fileScanner := bufio.NewScanner(fileReader)
fileScanner := bufio.NewScanner(fileToRead)
fileScanner.Split(bufio.ScanLines)
rules := make([]Rule, 0)

View File

@@ -1,25 +0,0 @@
package nip
// These stats are currently NOT supported, rules can not contain them otherwise it will return an error
var notSupportedStats = []string{
"plusmindamage",
"plusmaxdamage",
"itemarmorpercent",
"itemmindamagepercent",
"itemslashdamage",
"itemslashdamagepercent",
"itemcrushdamage",
"itemcrushdamagepercent",
"itemthrustdamage",
"itemthrustdamagepercent",
"secondarymindamage",
"secondarymaxdamage",
"damagepercent",
}
// These stats are partially supported, rules can contain them but the ones matching the item type in this list will be blocked
var blockedStatsForItemType = map[string][]string{
"mindamage": {"axe", "wand", "club", "scepter", "mace", "hammer", "sword", "knife", "thrownweapon", "throwingaxe", "javelin", "spear", "polearm", "staff", "bow", "crossbow", "assassinclaw", "orb", "amazonbow", "amazonspear", "amazonjavelin"},
"maxdamage": {"axe", "wand", "club", "scepter", "mace", "hammer", "sword", "knife", "thrownweapon", "throwingaxe", "javelin", "spear", "polearm", "staff", "bow", "crossbow", "assassinclaw", "orb", "amazonbow", "amazonspear", "amazonjavelin"},
"enhanceddamage": {"axe", "wand", "club", "scepter", "mace", "hammer", "sword", "knife", "thrownweapon", "throwingaxe", "javelin", "spear", "polearm", "staff", "bow", "crossbow", "assassinclaw", "orb", "amazonbow", "amazonspear", "amazonjavelin"},
}

View File

@@ -3,7 +3,6 @@ package nip
import (
"fmt"
"regexp"
"slices"
"strconv"
"strings"
@@ -119,10 +118,6 @@ func NewRule(rawRule string, filename string, lineNumber int) (Rule, error) {
statsMap := make(map[string]int)
for _, prop := range r.requiredStats {
statsMap[prop] = 0
// Check for not supported stats
if slices.Contains(notSupportedStats, prop) {
return Rule{}, fmt.Errorf("property %s is not supported, please remove it", prop)
}
}
line = strings.ReplaceAll(line, "[", "")
@@ -146,7 +141,7 @@ func (r Rule) Evaluate(it data.Item) (RuleResult, error) {
for prop := range fixedPropsList {
switch prop {
case "type":
stage1Props["type"] = typeAliases[it.TypeAsString()]
stage1Props["type"] = it.Type().ID
case "quality":
stage1Props["quality"] = int(it.Quality)
case "class":
@@ -187,12 +182,6 @@ func (r Rule) Evaluate(it data.Item) (RuleResult, error) {
continue
}
if itemTypes, found := blockedStatsForItemType[statName]; found {
if slices.Contains(itemTypes, it.TypeAsString()) {
return RuleResultNoMatch, fmt.Errorf("property %s is not supported for item type %s", statName, it.TypeAsString())
}
}
layer := 0
if len(statData) > 1 {
layer = statData[1]
@@ -226,7 +215,7 @@ func replaceStringPropertiesInStage1(stage1 string) (string, error) {
replaceWith := ""
switch prop[2] {
case "type":
replaceWith = strings.ReplaceAll(prop[0], prop[4], fmt.Sprintf("%d", typeAliases[prop[4]]))
replaceWith = strings.ReplaceAll(prop[0], prop[4], fmt.Sprintf("%d", item.ItemTypes[typeAliases[prop[4]]].ID))
case "quality":
replaceWith = strings.ReplaceAll(prop[0], prop[4], fmt.Sprintf("%d", qualityAliases[prop[4]]))
case "class":
@@ -277,7 +266,7 @@ func (r Rule) calculateEnhancedDefense(i data.Item) int {
return 0
}
if i.TypeAsString() != "armor" {
if !i.Type().IsType(item.TypeArmor) {
return 0
}

View File

@@ -155,42 +155,6 @@ func TestRule_Evaluate(t *testing.T) {
},
want: RuleResultFullMatch,
},
{
name: "enhanceddamage should not work for weapons",
fields: fields{
RawLine: "[type] == axe && [quality] == superior # [enhanceddamage] >= 15 #",
Enabled: true,
},
args: args{
item: data.Item{
Identified: true,
ID: 0,
Name: "handaxe",
Quality: item.QualitySuperior,
Stats: []stat.Data{},
},
},
wantErr: true,
},
{
name: "enhanceddamage should work for charms and not damage items",
fields: fields{
RawLine: "[name] == grandcharm && [quality] == magic # [enhanceddamage] >= 15 #",
Enabled: true,
},
args: args{
item: data.Item{
Identified: true,
ID: 605,
Name: "grandcharm",
Quality: item.QualityMagic,
Stats: []stat.Data{
{ID: stat.EnhancedDamage, Value: 15},
},
},
},
want: RuleResultFullMatch,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -219,13 +183,6 @@ func TestNew(t *testing.T) {
want Rule
wantErr bool
}{
{
name: "itemthrustdamage should throw an error",
args: args{
rawRule: "[type] == axe # [itemthrustdamage] >= 15",
},
wantErr: true,
},
{
name: "Ensure [color] returns error, not supported yet",
args: args{