Item refactor and more (#1)
This commit is contained in:
@@ -11,6 +11,23 @@ func (a Area) IsTown() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (a Area) Act() int {
|
||||
if a < 40 {
|
||||
return 1
|
||||
}
|
||||
if a >= 40 && a < 75 {
|
||||
return 2
|
||||
}
|
||||
if a >= 75 && a < 103 {
|
||||
return 3
|
||||
}
|
||||
if a >= 103 && a < 109 {
|
||||
return 4
|
||||
}
|
||||
|
||||
return 5
|
||||
}
|
||||
|
||||
const (
|
||||
Abaddon Area = 125
|
||||
AncientTunnels Area = 65
|
||||
|
||||
@@ -40,6 +40,7 @@ type Data struct {
|
||||
Rooms []Room
|
||||
OpenMenus OpenMenus
|
||||
Roster Roster
|
||||
HoverData HoverData
|
||||
}
|
||||
|
||||
type Room struct {
|
||||
@@ -48,6 +49,12 @@ type Room struct {
|
||||
Height int
|
||||
}
|
||||
|
||||
type HoverData struct {
|
||||
IsHovered bool
|
||||
UnitID
|
||||
UnitType int
|
||||
}
|
||||
|
||||
func (r Room) GetCenter() Position {
|
||||
return Position{
|
||||
X: r.Position.X + r.Width/2,
|
||||
@@ -98,10 +105,9 @@ func (r Roster) FindByName(name string) (RosterMember, bool) {
|
||||
}
|
||||
|
||||
type Level struct {
|
||||
Area area.Area
|
||||
Position Position
|
||||
IsGoodExit bool
|
||||
CanInteract bool
|
||||
Area area.Area
|
||||
Position Position
|
||||
IsEntrance bool // This means the area can not be accessed just walking through it, needs to be clicked
|
||||
}
|
||||
|
||||
type Class uint
|
||||
@@ -129,6 +135,7 @@ type Position struct {
|
||||
|
||||
type PlayerUnit struct {
|
||||
Name string
|
||||
ID UnitID
|
||||
Area area.Area
|
||||
Position Position
|
||||
Stats map[stat.ID]int
|
||||
@@ -226,4 +233,5 @@ type OpenMenus struct {
|
||||
QuitMenu bool
|
||||
Cube bool
|
||||
SkillSelect bool
|
||||
Anvil bool
|
||||
}
|
||||
|
||||
18
pkg/data/item/location.go
Normal file
18
pkg/data/item/location.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package item
|
||||
|
||||
type Location string
|
||||
|
||||
const (
|
||||
LocationEquipped Location = "equipped"
|
||||
LocationStash Location = "stash"
|
||||
LocationSharedStash1 Location = "shared_stash_1"
|
||||
LocationSharedStash2 Location = "shared_stash_2"
|
||||
LocationSharedStash3 Location = "shared_stash_3"
|
||||
LocationBelt Location = "belt"
|
||||
LocationInventory Location = "inventory"
|
||||
LocationCube Location = "cube"
|
||||
LocationVendor Location = "vendor"
|
||||
LocationGround Location = "ground"
|
||||
LocationSocket Location = "socket"
|
||||
LocationUnknown Location = "unknown"
|
||||
)
|
||||
@@ -41,6 +41,26 @@ var typeMapping = map[string][]string{
|
||||
"voodooheads": {"PreservedHead", "ZombieHead", "UnravellerHead", "GargoyleHead", "DemonHeadShield", "MummifiedTrophy", "FetishTrophy", "SextonTrophy", "CantorTrophy", "HierophantTrophy", "MinionSkull", "HellspawnSkull", "OverseerSkull", "SuccubusSkull", "BloodlordSkull"},
|
||||
}
|
||||
|
||||
var QuestItems = []string{
|
||||
"TheGidbinn",
|
||||
"WirtsLeg",
|
||||
"HoradricMalus",
|
||||
"HellforgeHammer",
|
||||
"HoradricStaff",
|
||||
"StaffOfKings",
|
||||
"KhalimsFlail",
|
||||
"AmuletOfTheViper",
|
||||
"KhalimsEye",
|
||||
"KhalimsHeart",
|
||||
"KhalimsBrain",
|
||||
"KhalimsWill",
|
||||
"ScrollOfInifuss",
|
||||
"HoradricCube",
|
||||
"HoradricScroll",
|
||||
"MephistosSoulstone",
|
||||
"BookOfSkill",
|
||||
}
|
||||
|
||||
func TypeForItemName(itemName string) (string, bool) {
|
||||
for t, itemNames := range typeMapping {
|
||||
for _, name := range itemNames {
|
||||
|
||||
@@ -8,14 +8,43 @@ import (
|
||||
)
|
||||
|
||||
type Items struct {
|
||||
Belt Belt
|
||||
Inventory Inventory
|
||||
Shop []Item
|
||||
Ground []Item
|
||||
Equipped []Item
|
||||
Belt Belt
|
||||
AllItems []Item
|
||||
}
|
||||
|
||||
func (i Items) Find(name item.Name, locations ...item.Location) (Item, bool) {
|
||||
for _, it := range i.AllItems {
|
||||
if strings.EqualFold(string(it.Name), string(name)) {
|
||||
// If no locations are specified, return the first item found
|
||||
if len(locations) == 0 {
|
||||
return it, true
|
||||
}
|
||||
|
||||
for _, l := range locations {
|
||||
if it.Location == l {
|
||||
return it, true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Item{}, false
|
||||
}
|
||||
|
||||
func (i Items) ByLocation(locations ...item.Location) []Item {
|
||||
var items []Item
|
||||
|
||||
for _, it := range i.AllItems {
|
||||
for _, l := range locations {
|
||||
if it.Location == l {
|
||||
items = append(items, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
type Inventory []Item
|
||||
type UnitID int
|
||||
|
||||
type Item struct {
|
||||
@@ -23,11 +52,11 @@ type Item struct {
|
||||
Name item.Name
|
||||
Quality item.Quality
|
||||
Position Position
|
||||
Location item.Location
|
||||
Ethereal bool
|
||||
IsHovered bool
|
||||
Stats map[stat.ID]stat.Data
|
||||
Identified bool
|
||||
IsVendor bool
|
||||
}
|
||||
|
||||
func (i Item) Type() string {
|
||||
@@ -47,6 +76,17 @@ func (i Item) IsHealingPotion() bool {
|
||||
func (i Item) IsManaPotion() bool {
|
||||
return strings.Contains(string(i.Name), string(ManaPotion))
|
||||
}
|
||||
|
||||
func (i Item) IsRejuvPotion() bool {
|
||||
return strings.Contains(string(i.Name), string(RejuvenationPotion))
|
||||
}
|
||||
|
||||
func (i Item) IsFromQuest() bool {
|
||||
for _, q := range item.QuestItems {
|
||||
if strings.EqualFold(string(i.Name), q) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func (m Monsters) FindOne(id npc.ID, t MonsterType) (Monster, bool) {
|
||||
func (m Monsters) Enemies(filters ...MonsterFilter) []Monster {
|
||||
monsters := make([]Monster, 0)
|
||||
for _, mo := range m {
|
||||
if !mo.IsMerc() && !mo.IsGoodNPC() {
|
||||
if !mo.IsMerc() && !mo.IsGoodNPC() && mo.Stats[stat.Life] > 0 {
|
||||
monsters = append(monsters, mo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,16 @@ func (o Object) IsWaypoint() bool {
|
||||
object.Act2Waypoint,
|
||||
object.Act3TownWaypoint,
|
||||
object.PandamoniumFortressWaypoint,
|
||||
object.Act2CellerWaypoint,
|
||||
object.Act2SewerWaypoint,
|
||||
object.Act3TravincalWaypoint,
|
||||
object.ValleyWaypoint,
|
||||
object.WorldstoneWaypoint,
|
||||
object.ExpansionWildernessWaypoint,
|
||||
object.IceCaveWaypoint,
|
||||
object.TempleWaypoint,
|
||||
object.InnerHellWaypoint,
|
||||
object.WaypointH,
|
||||
object.ExpansionWaypoint:
|
||||
return true
|
||||
}
|
||||
@@ -85,7 +95,8 @@ func (o Object) IsDoor() bool {
|
||||
object.AndarielDoor,
|
||||
object.PenBreakableDoor,
|
||||
object.ArreatSummitDoorToWorldstone,
|
||||
object.SecretDoor1:
|
||||
object.SecretDoor1,
|
||||
object.ExpansionTownGate:
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user