Skip to content

Commit

Permalink
Merge pull request #19 from nokka/parse_item_interface
Browse files Browse the repository at this point in the history
Parse item interface
  • Loading branch information
nokka authored Apr 24, 2021
2 parents 0b32be8 + ff41416 commit c6eeccb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
13 changes: 5 additions & 8 deletions d2s.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func parseItems(bfr io.ByteReader, char *Character) error {
return errors.New("failed to find the items header")
}

items, err := parseItemList(bfr, int(itemHeaderData.Count))
items, err := ParseItemList(bfr, int(itemHeaderData.Count))
if err != nil {
return err
}
Expand Down Expand Up @@ -296,7 +296,7 @@ func parseCorpse(bfr io.ByteReader, char *Character) error {
return errors.New("failed to find the merc items header")
}

corpseItems, err := parseItemList(bfr, int(itemHeaderData.Count))
corpseItems, err := ParseItemList(bfr, int(itemHeaderData.Count))
if err != nil {
return err
}
Expand Down Expand Up @@ -342,7 +342,7 @@ func parseMercItems(bfr io.ByteReader, char *Character) error {
return errors.New("failed to find the merc items header")
}

items, err := parseItemList(bfr, int(itemHeaderData.Count))
items, err := ParseItemList(bfr, int(itemHeaderData.Count))
if err != nil {
return err
}
Expand Down Expand Up @@ -376,7 +376,7 @@ func parseIronGolem(bfr io.ByteReader, char *Character) error {
}

if golemHeaderData.HasGolem == 1 {
item, err := parseItemList(bfr, 1)
item, err := ParseItemList(bfr, 1)
if err != nil {
return err
}
Expand All @@ -387,7 +387,7 @@ func parseIronGolem(bfr io.ByteReader, char *Character) error {
return nil
}

func parseItemList(bfr io.ByteReader, itemCount int) ([]Item, error) {
func ParseItemList(bfr io.ByteReader, itemCount int) ([]Item, error) {
var itemList []Item

ibr := bitReader{r: bfr}
Expand Down Expand Up @@ -447,7 +447,6 @@ func parseItemList(bfr io.ByteReader, itemCount int) ([]Item, error) {
}

switch parsed.Quality {

case lowQuality:
parsed.LowQualityID = reverseBits(ibr.ReadBits64(3, true), 3)
readBits += 3
Expand Down Expand Up @@ -699,7 +698,6 @@ func parseItemList(bfr io.ByteReader, itemCount int) ([]Item, error) {
bitsToAlign := uint(8 - remainder)
_ = reverseBits(ibr.ReadBits64(bitsToAlign, true), bitsToAlign)
}

}

return itemList, nil
Expand Down Expand Up @@ -998,7 +996,6 @@ func parseMagicalList(ibr *bitReader) ([]MagicAttribute, int, error) {

var values []int64
for _, bitLength := range prop.Bits {

val := reverseBits(ibr.ReadBits64(bitLength, true), bitLength)
readBits += int(bitLength)

Expand Down
81 changes: 42 additions & 39 deletions item.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Item struct {
RunewordID uint64 `json:"runeword_id,omitempty"`
RunewordName string `json:"runeword_name,omitempty"`
RunewordAttributes []MagicAttribute `json:"runeword_attributes"`
SetID uint64 `json:"set_id,omitempty"`
SetID uint64 `json:"set_id"`
SetName string `json:"set_name,omitempty"`
SetListCount uint64 `json:"set_list_count"`
SetAttributes [][]MagicAttribute `json:"set_attributes"`
Expand All @@ -52,7 +52,7 @@ type Item struct {
RareName string `json:"rare_name,omitempty"`
RareName2 string `json:"rare_name2,omitempty"`
MagicalNameIDs []uint64 `json:"magical_name_ids,omitempty"`
UniqueID uint64 `json:"unique_id,omitempty"`
UniqueID uint64 `json:"unique_id"`
UniqueName string `json:"unique_name,omitempty"`
MagicAttributes []MagicAttribute `json:"magic_attributes"`
SocketedItems []Item `json:"socketed_items"`
Expand Down Expand Up @@ -774,36 +774,38 @@ type WeaponDamage struct {

var weaponDamageMap = map[string]WeaponDamage{
// Axes
HandAxe: {Min: 3, Max: 6},
Axe: {Min: 4, Max: 11},
DoubleAxe: {Min: 5, Max: 13},
MilitaryPick: {Min: 7, Max: 11},
WarAxe: {Min: 10, Max: 18},
LargeAxe: {Min: 6, Max: 13},
BroadAxe: {Min: 10, Max: 18},
BattleAxe: {Min: 12, Max: 32},
GreatAxe: {Min: 9, Max: 30},
GiantAxe: {Min: 22, Max: 45},
Hatchet: {Min: 10, Max: 21},
Cleaver: {Min: 10, Max: 33},
TwinAxe: {Min: 13, Max: 38},
Crowbill: {Min: 14, Max: 34},
Naga: {Min: 16, Max: 45},
MilitaryAxe: {Min: 14, Max: 34},
BeardedAxe: {Min: 21, Max: 49},
Tabar: {Min: 24, Max: 77},
GothicAxe: {Min: 18, Max: 70},
AncientAxe: {Min: 43, Max: 85},
Tomahawk: {Min: 33, Max: 58},
SmallCrescent: {Min: 38, Max: 60},
EttinAxe: {Min: 33, Max: 66},
WarSpike: {Min: 30, Max: 48},
BerserkerAxe: {Min: 24, Max: 71},
FeralAxe: {Min: 25, Max: 123},
SilverEdgedAxe: {Min: 62, Max: 110},
Decapitator: {Min: 49, Max: 137},
ChampionAxe: {Min: 59, Max: 94},
GloriousAxe: {Min: 60, Max: 124},
HandAxe: {Min: 3, Max: 6},
Axe: {Min: 4, Max: 11},
DoubleAxe: {Min: 5, Max: 13},
MilitaryPick: {Min: 7, Max: 11},
WarAxe: {Min: 10, Max: 18},
LargeAxe: {Min: 6, Max: 13},
BroadAxe: {Min: 10, Max: 18},
Hatchet: {Min: 10, Max: 21},
Cleaver: {Min: 10, Max: 33},
TwinAxe: {Min: 13, Max: 38},
Crowbill: {Min: 14, Max: 34},
Naga: {Min: 16, Max: 45},
MilitaryAxe: {Min: 14, Max: 34},
Tomahawk: {Min: 33, Max: 58},
SmallCrescent: {Min: 38, Max: 60},
EttinAxe: {Min: 33, Max: 66},
WarSpike: {Min: 30, Max: 48},
BerserkerAxe: {Min: 24, Max: 71},

// Two-Handed Axes
BattleAxe: {TwoMin: 12, TwoMax: 32},
GreatAxe: {TwoMin: 9, TwoMax: 30},
GiantAxe: {TwoMin: 22, TwoMax: 45},
BeardedAxe: {TwoMin: 21, TwoMax: 49},
Tabar: {TwoMin: 24, TwoMax: 77},
GothicAxe: {TwoMin: 18, TwoMax: 70},
AncientAxe: {TwoMin: 43, TwoMax: 85},
FeralAxe: {TwoMin: 25, TwoMax: 123},
SilverEdgedAxe: {TwoMin: 62, TwoMax: 110},
Decapitator: {TwoMin: 49, TwoMax: 137},
ChampionAxe: {TwoMin: 59, TwoMax: 94},
GloriousAxe: {TwoMin: 60, TwoMax: 124},

// Maces
Club: {Min: 1, Max: 6},
Expand All @@ -812,24 +814,26 @@ var weaponDamageMap = map[string]WeaponDamage{
MorningStar: {Min: 7, Max: 16},
Flail: {Min: 1, Max: 24},
WarHammer: {Min: 19, Max: 29},
Maul: {Min: 30, Max: 43},
GreatMaul: {Min: 38, Max: 58},
Cudgel: {Min: 6, Max: 21},
BarbedClub: {Min: 13, Max: 25},
FlangedMace: {Min: 15, Max: 23},
JaggedStar: {Min: 20, Max: 31},
Knout: {Min: 13, Max: 35},
BattleHammer: {Min: 35, Max: 58},
WarClub: {Min: 53, Max: 78},
MarteldeFer: {Min: 61, Max: 99},
Truncheon: {Min: 35, Max: 43},
TyrantClub: {Min: 32, Max: 58},
ReinforcedMace: {Min: 41, Max: 49},
DevilStar: {Min: 42, Max: 53},
Scourge: {Min: 3, Max: 80},
LegendaryMallet: {Min: 50, Max: 61},
OgreMaul: {Min: 77, Max: 106},
ThunderMaul: {Min: 33, Max: 180},

// Two-Handed Maces
Maul: {TwoMin: 30, TwoMax: 43},
GreatMaul: {TwoMin: 38, TwoMax: 58},
WarClub: {TwoMin: 53, TwoMax: 78},
MarteldeFer: {TwoMin: 61, TwoMax: 99},
OgreMaul: {TwoMin: 77, TwoMax: 106},
ThunderMaul: {TwoMin: 33, TwoMax: 180},

// Polearms
Bardiche: {TwoMin: 1, TwoMax: 27},
Expand Down Expand Up @@ -890,7 +894,6 @@ var weaponDamageMap = map[string]WeaponDamage{
GothicSword: {Min: 14, Max: 40, TwoMin: 39, TwoMax: 60},
Zweihander: {Min: 19, Max: 35, TwoMin: 29, TwoMax: 54},
ExecutionerSword: {Min: 24, Max: 40, TwoMin: 47, TwoMax: 80},
"7sh": {Min: 22, Max: 56, TwoMin: 50, TwoMax: 94},
HighlandBlade: {Min: 22, Max: 62, TwoMin: 67, TwoMax: 96},
BalrogBlade: {Min: 15, Max: 75, TwoMin: 55, TwoMax: 118},
ChampionSword: {Min: 24, Max: 54, TwoMin: 71, TwoMax: 83},
Expand Down

0 comments on commit c6eeccb

Please sign in to comment.