alchemyst/engine/items/backpack.go
2019-11-15 21:24:42 +03:00

33 lines
711 B
Go

package items
import "lab.zaar.be/thefish/alchemyst-go/engine/ecs"
type Backpack struct {
MaxNumber int
MaxBulk int
MaxMass int
items []ecs.Entity
}
func (b Backpack) Type() string {
return ecs.BackpackComponent
}
func (b *Backpack) HasFreeSpace(Bulk, Mass int) bool {
totalBulk, totalMass := 0, 0
for i, _ := range b.items {
tmp := Controller.GetComponent(b.items[i], Carried{}.Type()).(Carried)
carried := tmp
totalBulk += carried.Bulk
totalMass += carried.Mass
}
if totalMass >= b.MaxMass {
//fixme return message along - 'too heavy'
return false
}
if totalBulk >= b.MaxMass {
//fixme return message along - 'doesnt fit to your backpack'
return false
}
return true
}