37 lines
775 B
Go
37 lines
775 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
|
|
}
|
|
|
|
func (b *Backpack) GetItems() []ecs.Entity {
|
|
return b.items
|
|
} |