Feature/load misc items (#424)

* Add InventoryItemMisc struct

* Add GetMiscItemByCode function

* Implement InventoryItem interface for InventoryItemMisc

* Add rings and amulets to the example items loading.

* Fix Y of LeftHand and RightHand equipment slots.

* Add "Ripolak" name to CONTRIBUTORS

* Remove double item
This commit is contained in:
Ripolak 2020-06-23 22:28:03 +03:00 committed by GitHub
parent 897de61006
commit f729ff6101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 2 deletions

View File

@ -16,6 +16,7 @@ Dylan "Gravestench" Knuth
Intyre
Gürkan Kaymak
Maxime "malavv" Lavigne
Ripolak
* DIABLO2 LOGO
Jose Pardilla (th3-prophetman)

View File

@ -0,0 +1,64 @@
package d2inventory
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"log"
)
type InventoryItemMisc struct {
InventorySizeX int `json:"inventorySizeX"`
InventorySizeY int `json:"inventorySizeY"`
InventorySlotX int `json:"inventorySlotX"`
InventorySlotY int `json:"inventorySlotY"`
ItemName string `json:"itemName"`
ItemCode string `json:"itemCode"`
}
func GetMiscItemByCode(code string) *InventoryItemMisc {
result := d2datadict.MiscItems[code]
if result == nil {
log.Fatalf("Could not find misc item entry for code '%s'", code)
}
return &InventoryItemMisc{
InventorySizeX: result.InventoryWidth,
InventorySizeY: result.InventoryHeight,
ItemName: result.Name,
ItemCode: result.Code,
}
}
func (v *InventoryItemMisc) InventoryItemName() string {
if v == nil {
return ""
}
return v.ItemName
}
func (v *InventoryItemMisc) InventoryItemType() d2enum.InventoryItemType {
return d2enum.InventoryItemTypeItem
}
func (v *InventoryItemMisc) InventoryGridSize() (int, int) {
return v.InventorySizeX, v.InventorySizeY
}
func (v *InventoryItemMisc) InventoryGridSlot() (int, int) {
return v.InventorySlotX, v.InventorySlotY
}
func (v *InventoryItemMisc) SetInventoryGridSlot(x int, y int) {
v.InventorySlotX, v.InventorySlotY = x, y
}
func (v *InventoryItemMisc) Serialize() []byte {
return []byte{}
}
func (v *InventoryItemMisc) GetItemCode() string {
if v == nil {
return ""
}
return v.ItemCode
}

View File

@ -57,14 +57,14 @@ func genEquipmentSlotsMap() map[d2enum.EquippedSlotType]EquipmentSlot {
d2enum.LeftHand: {
item: nil,
x: 491,
y: 268,
y: 270,
width: 32,
height: 32,
},
d2enum.RightHand: {
item: nil,
x: 606,
y: 268,
y: 270,
width: 32,
height: 32,
},

View File

@ -65,6 +65,9 @@ func (g *Inventory) Load() {
g.grid.ChangeEquippedSlot(d2enum.Legs, d2inventory.GetArmorItemByCode("vbt"))
g.grid.ChangeEquippedSlot(d2enum.Belt, d2inventory.GetArmorItemByCode("vbl"))
g.grid.ChangeEquippedSlot(d2enum.Gloves, d2inventory.GetArmorItemByCode("lgl"))
g.grid.ChangeEquippedSlot(d2enum.LeftHand, d2inventory.GetMiscItemByCode("rin"))
g.grid.ChangeEquippedSlot(d2enum.RightHand, d2inventory.GetMiscItemByCode("rin"))
g.grid.ChangeEquippedSlot(d2enum.Neck, d2inventory.GetMiscItemByCode("amu"))
// TODO: Load the player's actual items
g.grid.Add(items...)
}