76 lines
1.8 KiB
Java
76 lines
1.8 KiB
Java
package items;
|
|
import items.interfaces.CanBeShooted;
|
|
import items.interfaces.Suspicious;
|
|
import persons.Person;
|
|
|
|
import java.util.UUID;
|
|
|
|
public abstract class Item implements CanBeShooted, Suspicious {
|
|
private double weight;
|
|
private Person owner;
|
|
private boolean isBroken;
|
|
boolean isLost = false;
|
|
|
|
// partNumber shenanigans
|
|
private final String partNumber = UUID.randomUUID().toString();
|
|
|
|
public Item(Person owner, Double weight, Boolean isBroken) {
|
|
this.weight = weight;
|
|
this.owner = owner;
|
|
this.isBroken = isBroken;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (this == o) return true;
|
|
if (!(o instanceof Item)) return false;
|
|
Item item = (Item) o;
|
|
return partNumber == item.getPartNumber();
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return partNumber.hashCode();
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "%s %f %b".formatted(owner.toString(), weight, isBroken);
|
|
}
|
|
|
|
// suspicious
|
|
public boolean getIsSuspicious() {
|
|
return false;
|
|
}
|
|
|
|
// lost&find
|
|
public boolean getIsLost() {
|
|
return this.isLost;
|
|
}
|
|
|
|
abstract public void setIsLost(boolean isLost);
|
|
|
|
// part number
|
|
public String getPartNumber() {return partNumber;}
|
|
|
|
// weight
|
|
public double getWeight() { return weight; }
|
|
public void setWeight(double weight) { this.weight = weight; }
|
|
|
|
// owner
|
|
public Person getOwner() {return owner;}
|
|
public void setOwner(Person owner) {this.owner = owner;}
|
|
|
|
// break
|
|
public void doBreak() {this.isBroken = !this.isBroken;}
|
|
|
|
public boolean fix() {
|
|
if (Math.random() > 0.7 && this.isBroken) {
|
|
this.isBroken = false;
|
|
}
|
|
return isBroken;
|
|
}
|
|
|
|
public boolean getIsBroken() { return this.isBroken; }
|
|
}
|