fix: more code is apparently better
This commit is contained in:
@ -104,6 +104,7 @@ public class Character extends Entity {
|
||||
", rangedDamage=" + rangedDamage +
|
||||
", meleeDamage=" + meleeDamage +
|
||||
", inventory=" + inventory +
|
||||
", position=" + position +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ public class InfinityStone extends Entity {
|
||||
public String toString() {
|
||||
return "InfinityStone{" +
|
||||
"type=" + type +
|
||||
", position=" + position +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,10 @@ public class Inventory implements Iterable<StoneType> {
|
||||
}
|
||||
|
||||
for(StoneType stone: content) {
|
||||
if(content.contains(stone)) {
|
||||
if(this.content.contains(stone)) {
|
||||
throw new IllegalArgumentException("Attempted to construct an inventory with duplicate entries.");
|
||||
}
|
||||
content.add(stone);
|
||||
this.content.add(stone);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,21 +2,66 @@ package uulm.teamname.marvelous.gamelibrary.entities;
|
||||
|
||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/** Represents an NPC inside the game. */
|
||||
public class NPC extends Entity {
|
||||
/** The {@link StatType#MP} of the NPC */
|
||||
public final Stat mp;
|
||||
|
||||
/** The {@link Inventory} of the NPC */
|
||||
public final Inventory inventory;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link NPC}.
|
||||
* @param id The {@link EntityID} of the NPC
|
||||
* @param position The position of the NPC
|
||||
* @param inventory The starting inventory the NPC should have
|
||||
*/
|
||||
public NPC(EntityID id, IntVector2 position, int maxMP, ArrayList<StoneType> inventory) {
|
||||
super(id, position);
|
||||
solid = false;
|
||||
opaque = true;
|
||||
this.inventory = new Inventory(inventory);
|
||||
this.mp = new Stat(StatType.MP, maxMP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link NPC} with an empty inventory.
|
||||
* @param id The {@link EntityID} of the NPC
|
||||
* @param position The position of the NPC
|
||||
* @param maxMP The maximum MP of the NPC
|
||||
*/
|
||||
public NPC(EntityID id, IntVector2 position, int maxMP) {
|
||||
this(id, position, maxMP, new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link NPC} with an empty inventory.
|
||||
* @param id The {@link EntityID} of the NPC
|
||||
* @param position The position of the NPC
|
||||
* @param inventory The starting inventory of the NPC
|
||||
*/
|
||||
public NPC(EntityID id, IntVector2 position, ArrayList<StoneType> inventory) {
|
||||
this(id, position, 0, inventory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link NPC} with an empty inventory.
|
||||
* @param id The {@link EntityID} of the NPC
|
||||
* @param position The position of the NPC
|
||||
*/
|
||||
public NPC(EntityID id, IntVector2 position) {
|
||||
super(id, position);
|
||||
solid = false;
|
||||
opaque = true;
|
||||
this(id, position, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC clone() {
|
||||
return new NPC(id, position);
|
||||
NPC clone = new NPC(id, position, mp.getMax());
|
||||
clone.mp.setValue(mp.getValue());
|
||||
for(StoneType stone: inventory) {
|
||||
clone.inventory.addStone(stone);
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ public class Rock extends Entity {
|
||||
return "Rock{" +
|
||||
"maxHP=" + maxHP +
|
||||
", hp=" + hp +
|
||||
", position=" + position +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user