1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-09-20 02:05:55 -04:00
OpenDiablo2/d2core/d2map/d2mapentity/item.go
lord 78ecc3557e
simple item spawning in map (#651)
* wip d2items system and item properties

* added loader for TreasureClassEx.txt

* wip item spawn from treasure class records

* wip items

* add call to init item equivalencies, remove treasure class test from d2app

* made item affix records global var a map of affix codes to the records

* changed how item to item common record equivalency is determined

* changed set items records export to a map of their codes to the records, grouped property params into a struct

* changed property parameter field from calcstring to string

* fixed bug in stat value clone

* adding equipper interface as part of stat context, eventually to be used to resolve set bonus (among other things)

* made the item interface simpler, only needs name and description methods

* adding equipper interface, for anything that will equip or have active items

* handle case where min and max are swapped, removed commented code

* added property/stat resolution for magic, rare, set, and unique items

* adding item generator which can roll for items using treasure class records

* fixed item equivalency func being called in the wrong spot

* added item spawning

- added packet type for spawning items
- added client/server handlers for SpawnItem packets
- added map entity for items
- added simpler item provider function in diablo2item package
- added debug terminal command for spawning items
2020-07-30 15:04:05 -04:00

57 lines
1.1 KiB
Go

package d2mapentity
import (
"errors"
"fmt"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2item/diablo2item"
)
const (
errInvalidItemCodes = "invalid item codes supplied"
)
type Item struct {
*AnimatedEntity
Item *diablo2item.Item
}
func (i *Item) GetPosition() d2vector.Position {
return i.AnimatedEntity.Position
}
func (i *Item) GetVelocity() d2vector.Vector {
return i.AnimatedEntity.velocity
}
func CreateItem(x, y int, codes ...string) (*Item, error) {
item := diablo2item.NewItem(codes...)
if item == nil {
return nil, errors.New(errInvalidItemCodes)
}
animation, err := d2asset.LoadAnimation(
fmt.Sprintf("%s/%s.DC6", d2resource.ItemGraphics, item.CommonRecord().FlippyFile),
d2resource.PaletteUnits,
)
if err != nil {
return nil, err
}
animation.PlayForward()
animation.SetPlayLoop(false)
entity := CreateAnimatedEntity(x*5, y*5, animation)
result := &Item{
AnimatedEntity: entity,
Item: item,
}
return result, nil
}