package items import ( "fmt" "lab.zaar.be/thefish/alchemyst-go/engine/ecs" ) var ( ErrorInvTooHeavy = fmt.Errorf("too heavy") ErrorInvTooBulky = fmt.Errorf("too bulky") ) 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) error { 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 { return ErrorInvTooHeavy } if totalBulk >= b.MaxBulk { return ErrorInvTooBulky } return nil } func (b *Backpack) GetItems() []ecs.Entity { return b.items }