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

@@ -21,6 +21,7 @@ import inf101.v18.rogue101.enemies.Girl;
import inf101.v18.rogue101.examples.Carrot;
import inf101.v18.rogue101.items.Manga;
import inf101.v18.rogue101.examples.Rabbit;
import inf101.v18.rogue101.items.Sword;
import inf101.v18.rogue101.map.GameMap;
import inf101.v18.rogue101.map.IGameMap;
import inf101.v18.rogue101.map.IMapView;
@@ -124,8 +125,10 @@ public class Game implements IGame {
if (!map.has(loc, target)) {
throw new IllegalMoveException("Target isn't there!");
}
//TODO: Add attack and defence power when appropriate items are equipped.
int damage = currentActor.getAttack() + random.nextInt(20) + 1;
if (damage >= target.getDefence() + 10) {
int defence = target.getDefence() + 10;
if (damage >= defence) {
int actualDamage = target.handleDamage(this, target, damage);
formatMessage("%s hits %s for %d damage", currentActor.getName(), target.getName(), actualDamage);
} else {
@@ -268,6 +271,7 @@ public class Game implements IGame {
itemFactories.put("M", Manga::new);
itemFactories.put("G", Girl::new);
itemFactories.put(".", Dust::new);
itemFactories.put("S", Sword::new);
}
@Override