2018-03-14 00:00:52 +01:00
|
|
|
package inf101.v18.rogue101.items;
|
|
|
|
|
|
|
|
import inf101.v18.rogue101.game.IGame;
|
|
|
|
import inf101.v18.rogue101.objects.IItem;
|
|
|
|
|
2018-03-14 14:00:48 +01:00
|
|
|
import java.util.ArrayList;
|
2018-03-19 19:11:09 +01:00
|
|
|
import java.util.Collections;
|
2018-03-14 00:00:52 +01:00
|
|
|
import java.util.List;
|
2018-03-20 21:41:18 +01:00
|
|
|
import java.util.Random;
|
2018-03-14 00:00:52 +01:00
|
|
|
|
2018-03-15 00:16:26 +01:00
|
|
|
public class Chest implements IContainer, IStatic {
|
2018-03-20 01:10:30 +01:00
|
|
|
private final List<IItem> container;
|
|
|
|
private final int MAX_SIZE = 10;
|
2018-03-15 00:16:26 +01:00
|
|
|
|
|
|
|
public Chest() {
|
|
|
|
this.container = new ArrayList<>();
|
|
|
|
}
|
|
|
|
|
2018-03-19 19:11:09 +01:00
|
|
|
/**
|
|
|
|
* Randomly fills chest with random items based on dungeon level.
|
|
|
|
*
|
|
|
|
* @param lvl The current dungeon level
|
|
|
|
*/
|
2018-03-20 21:41:18 +01:00
|
|
|
public void fill (int lvl) {
|
|
|
|
Random random = new Random();
|
|
|
|
int itemChance = 5;
|
|
|
|
List<IItem> items = new ArrayList<>();
|
|
|
|
items.add(new Staff());
|
|
|
|
items.add(new Sword());
|
|
|
|
items.add(new Bow());
|
|
|
|
items.add(new Binoculars());
|
|
|
|
items.add(new Shield());
|
|
|
|
for (int i = 0; i < MAX_SIZE; i++) {
|
|
|
|
int num = random.nextInt(100);
|
|
|
|
boolean added = false;
|
|
|
|
for (int j = 0; j < items.size(); j++) {
|
|
|
|
if (num < (itemChance * (j + 1)) + ((j + 1) * lvl)) {
|
|
|
|
addItem(items.get(j));
|
|
|
|
items.remove(j); //We don't want duplicates
|
|
|
|
added = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!added && num > 70) {
|
|
|
|
addItem(new HealthPotion());
|
|
|
|
}
|
|
|
|
}
|
2018-03-19 19:11:09 +01:00
|
|
|
}
|
|
|
|
|
2018-03-14 00:00:52 +01:00
|
|
|
@Override
|
|
|
|
public IItem get(int i) {
|
2018-03-20 21:41:18 +01:00
|
|
|
return container.get(i);
|
2018-03-14 00:00:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-19 19:11:09 +01:00
|
|
|
public List<IItem> getContent() {
|
|
|
|
return Collections.unmodifiableList(container);
|
2018-03-14 00:00:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isFull() {
|
2018-03-19 19:11:09 +01:00
|
|
|
return container.size() >= MAX_SIZE;
|
2018-03-14 00:00:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-20 01:10:30 +01:00
|
|
|
@Override
|
|
|
|
public IItem getFirst(Class<?> clazz) {
|
|
|
|
for (IItem item : container) {
|
|
|
|
if (clazz.isInstance(item)) {
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-03-14 00:00:52 +01:00
|
|
|
@Override
|
|
|
|
public int getCurrentHealth() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxHealth() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
2018-03-14 14:00:48 +01:00
|
|
|
return "Chest";
|
2018-03-14 00:00:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSize() {
|
2018-03-14 14:00:48 +01:00
|
|
|
return 10000;
|
2018-03-14 00:00:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getPrintSymbol() {
|
2018-03-19 19:11:09 +01:00
|
|
|
return "\u001b[94m" + "\uD83D\uDDC3" + "\u001b[0m";
|
2018-03-14 00:00:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getSymbol() {
|
|
|
|
return "C";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int handleDamage(IGame game, IItem source, int amount) {
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-19 19:11:09 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean addItem(IItem item) {
|
|
|
|
if (container.size() < MAX_SIZE) {
|
|
|
|
container.add(item);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-03-20 01:10:30 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remove(int i) {
|
|
|
|
container.remove(i);
|
|
|
|
}
|
2018-03-14 00:00:52 +01:00
|
|
|
}
|