Adds item storage and more NPC behavior

Makes NPC look for and pick up items of specified types.
Adds a Backpack and IContainer interface.
Lets items use separate sounds. Not completed.
This commit is contained in:
2018-03-12 21:26:36 +01:00
parent d1b4f4a316
commit 7d0f0dc4f8
13 changed files with 369 additions and 74 deletions

View File

@ -0,0 +1,129 @@
package inf101.v18.rogue101.items;
import inf101.v18.rogue101.game.IGame;
import inf101.v18.rogue101.objects.IItem;
import java.util.ArrayList;
import java.util.List;
public class Backpack<T extends IItem> implements IContainer {
/**
* A list containing everything in the backpack.
*/
private List<T> content = new ArrayList<>();
/**
* The maximum amount of items allowed in a single backpack.
*/
private final int MAX_SIZE = 5;
@Override
public int getCurrentHealth() {
return 0;
}
@Override
public int getDefence() {
return 0;
}
@Override
public int getMaxHealth() {
return 0;
}
@Override
public String getName() {
return "Backpack";
}
@Override
public int getSize() {
return 20;
}
@Override
public String getSymbol() {
return "B";
}
@Override
public int handleDamage(IGame game, IItem source, int amount) {
return 0;
}
/**
* Retrieves the current size of the Backpack.
*
* @return
*/
public int size() {
return content.size();
}
/**
* Checks if the Backpack is empty
*
* @return True if empty. False otherwise
*/
public boolean isEmpty() {
return content.isEmpty();
}
/**
* Tries to add an item to the Backpack
*
* @param item The item to add
* @return
*/
public boolean add(T item) {
if (content.size() < MAX_SIZE) {
content.add(item);
return true;
} else {
return false;
}
}
/**
* Removes an element at index i
*
* @param i The index of an element
*/
public void remove(int i) {
content.remove(i);
}
/**
* Gets a T at index i,
*
* @param i The index of an element
* @return An object of type T
*/
public T get(int i) {
return content.get(i);
}
/**
* Gets the content List for direct manipulation.
*
* @return A list of T
*/
public List<T> getContent() {
return content;
}
@Override
public boolean isFull() {
if (content.size() >= MAX_SIZE) {
return true;
} else {
return false;
}
}
//This shows as an error, but is necessary to compile.
@Override
public int compareTo(Object o) {
return compareTo((IItem)o);
}
}

View File

@ -2,7 +2,7 @@ package inf101.v18.rogue101.items;
import inf101.v18.rogue101.objects.IItem;
interface IBuffItem extends IItem {
public interface IBuffItem extends IItem {
/**
* Retrieve damage increase done by the buff item.
*

View File

@ -0,0 +1,38 @@
package inf101.v18.rogue101.items;
import inf101.v18.rogue101.objects.IItem;
import java.util.List;
/**
* A container for storing anything extending IItem.
*
* @param <T> The item type to store
*/
public interface IContainer<T extends IItem> extends IItem {
/**
* Retrieves an item from a container in index i
*
* @param i The index of an element
* @return An IItem
* @throws IndexOutOfBoundsException If the index is out of range.
*/
IItem get(int i);
/**
* Gets a list with everything inside a container.
*
* @return A list of Objects extending IItem
*/
List<T> getContent();
/**
* Checks if we can add anything at all to the container.
*
* @return True if it has no space left
*/
boolean isFull();
}

View File

@ -1,12 +1,12 @@
package inf101.v18.rogue101.items;
import inf101.v18.rogue101.objects.IItem;
/**
* An interface to extinguish different weapons for specific NPC.
*/
public interface IMagicWeapon extends IWeapon {
interface IMagicWeapon extends IItem {
/**
* Retrieves the damage points of a weapon.
*
* @return
*/
int getWeaponDamage();
@Override
default String getSound() {
return "audio/Bow_Fire_Arrow-Stephan_Schutze-2133929391.wav";
}
}

View File

@ -1,12 +1,12 @@
package inf101.v18.rogue101.items;
import inf101.v18.rogue101.objects.IItem;
/**
* An interface to extinguish different weapons for specific NPC.
*/
public interface IMeleeWeapon extends IWeapon {
interface IMeleeWeapon extends IItem {
/**
* Retrieves the damage points of a weapon.
*
* @return
*/
int getWeaponDamage();
@Override
default String getSound() {
return "audio/Sword Swing-SoundBible.com-639083727.wav";
}
}

View File

@ -1,12 +1,12 @@
package inf101.v18.rogue101.items;
import inf101.v18.rogue101.objects.IItem;
/**
* An interface to extinguish different weapons for specific NPC.
*/
public interface IRangedWeapon extends IWeapon {
interface IRangedWeapon extends IItem {
/**
* Retrieves the damage points of a weapon.
*
* @return
*/
int getWeaponDamage();
@Override
default String getSound() {
return "audio/Bow_Fire_Arrow-Stephan_Schutze-2133929391.wav";
}
}

View File

@ -0,0 +1,19 @@
package inf101.v18.rogue101.items;
import inf101.v18.rogue101.objects.IItem;
public interface IWeapon extends IItem {
/**
* Retrieves the damage points of a weapon.
*
* @return
*/
int getWeaponDamage();
/**
* Retrieves the string path of the sound to play upon an attack.
*
* @return A string path
*/
String getSound();
}