diff --git a/src/main/java/pl/uj/io/cuteanimals/action/BuffCharacter.java b/src/main/java/pl/uj/io/cuteanimals/action/BuffCharacter.java index 8832489..18e23bb 100644 --- a/src/main/java/pl/uj/io/cuteanimals/action/BuffCharacter.java +++ b/src/main/java/pl/uj/io/cuteanimals/action/BuffCharacter.java @@ -21,12 +21,14 @@ public IResult actionBody(IPlayer player) { player.getAttributes().addHealth(attributes.getHealth()); player.getAttributes().addAttack(attributes.getAttack()); player.getAttributes().addDefence(attributes.getDefence()); + player.getAttributes().addMana(attributes.getMana()); var message = ""; message += (attributes.getHealth() != 0 ? "+" + attributes.getHealth() + " health " : ""); message += (attributes.getAttack() != 0 ? "+" + attributes.getAttack() + " attack " : ""); message += (attributes.getDefence() != 0 ? "+" + attributes.getDefence() + " defence " : ""); + message += (attributes.getMana() != 0 ? "+" + attributes.getMana() + " mana " : ""); return new Result(message, Color.GREEN); } diff --git a/src/main/java/pl/uj/io/cuteanimals/action/ability/Focus.java b/src/main/java/pl/uj/io/cuteanimals/action/ability/Focus.java index 7284919..d82e7b8 100644 --- a/src/main/java/pl/uj/io/cuteanimals/action/ability/Focus.java +++ b/src/main/java/pl/uj/io/cuteanimals/action/ability/Focus.java @@ -24,7 +24,7 @@ protected IResult actionBody(IPlayer player) { Color.YELLOW); } - if (player.getFightManager().getState() instanceof Focus) { + if (player.getFightManager().getState() instanceof IAbility) { return new FightLog("You are already focusing.", Color.YELLOW); } diff --git a/src/main/java/pl/uj/io/cuteanimals/model/DefaultLocation.java b/src/main/java/pl/uj/io/cuteanimals/model/DefaultLocation.java index b63867c..4a06a35 100644 --- a/src/main/java/pl/uj/io/cuteanimals/model/DefaultLocation.java +++ b/src/main/java/pl/uj/io/cuteanimals/model/DefaultLocation.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.springframework.stereotype.Component; import pl.uj.io.cuteanimals.model.interfaces.*; /** @@ -12,6 +13,7 @@ * @version %I% * @since 0.0.1-SNAPSHOT */ +@Component public class DefaultLocation implements ILocation { protected String description; protected Map actionMap; diff --git a/src/main/java/pl/uj/io/cuteanimals/model/Player.java b/src/main/java/pl/uj/io/cuteanimals/model/Player.java index 615bff0..a36b349 100644 --- a/src/main/java/pl/uj/io/cuteanimals/model/Player.java +++ b/src/main/java/pl/uj/io/cuteanimals/model/Player.java @@ -29,7 +29,7 @@ public Player(int id, WorldMap world) { this.stats = new PlayerAttributes(this); this.currentLocation = world.getLocation("town"); this.armorBackpack = new ArmorBackpack(this); - this.backpack = new PlayerBackpack(this); + this.backpack = new PlayerBackpack(this.stats); this.gameState = GameState.LIMBO; this.fightManager = new FightManager(this); this.playerClass = new Slave(); @@ -57,6 +57,10 @@ public IAttributes getAttributes() { @Override public IResult use(IItem item) { + if (item.getType() != ItemType.USABLE) { + return new Result("You can't use that."); + } + var eatingResult = new BuffCharacter(item.getAttributes()).execute(this); getEquipment().removeItem(item); var attackResult = fightManager.contrAttack(); diff --git a/src/main/java/pl/uj/io/cuteanimals/model/PlayerBackpack.java b/src/main/java/pl/uj/io/cuteanimals/model/PlayerBackpack.java index 81ad68e..3191ed3 100644 --- a/src/main/java/pl/uj/io/cuteanimals/model/PlayerBackpack.java +++ b/src/main/java/pl/uj/io/cuteanimals/model/PlayerBackpack.java @@ -1,6 +1,6 @@ package pl.uj.io.cuteanimals.model; -import pl.uj.io.cuteanimals.model.interfaces.ICharacter; +import pl.uj.io.cuteanimals.model.interfaces.IAttributes; import pl.uj.io.cuteanimals.model.interfaces.IItem; /** @@ -10,12 +10,12 @@ * @since 0.2.0-SNAPSHOT */ public class PlayerBackpack extends Backpack { - private final ICharacter owner; + private final IAttributes ownerAttrs; private int currentWeight; - public PlayerBackpack(ICharacter owner) { + public PlayerBackpack(IAttributes ownerAttrs) { super(); - this.owner = owner; + this.ownerAttrs = ownerAttrs; this.currentWeight = 0; } @@ -34,7 +34,6 @@ public boolean putItem(IItem item) { public boolean removeItem(IItem item) { getItems().remove(item); currentWeight -= item.getSize(); - // TODO: check of possible (e.g. soul bounded items?) return true; } @@ -45,7 +44,7 @@ public boolean removeItem(IItem item) { */ public int getCapacity() { int baseCapacity = 10; - return baseCapacity + 3 * owner.getAttributes().getAttack(); + return baseCapacity + 3 * ownerAttrs.getAttack(); } /** diff --git a/src/main/java/pl/uj/io/cuteanimals/plot/actions/DungeonEntranceGoAction.java b/src/main/java/pl/uj/io/cuteanimals/plot/actions/DungeonEntranceGoAction.java index ade857d..cfbd6f7 100644 --- a/src/main/java/pl/uj/io/cuteanimals/plot/actions/DungeonEntranceGoAction.java +++ b/src/main/java/pl/uj/io/cuteanimals/plot/actions/DungeonEntranceGoAction.java @@ -2,13 +2,10 @@ import java.util.List; import java.util.Map; -import java.util.Random; import pl.uj.io.cuteanimals.model.GameState; +import pl.uj.io.cuteanimals.model.RandomIntegerImpl; import pl.uj.io.cuteanimals.model.Result; -import pl.uj.io.cuteanimals.model.interfaces.ContainerArgumentAction; -import pl.uj.io.cuteanimals.model.interfaces.ILocation; -import pl.uj.io.cuteanimals.model.interfaces.IPlayer; -import pl.uj.io.cuteanimals.model.interfaces.IResult; +import pl.uj.io.cuteanimals.model.interfaces.*; /** * Provides methods that moves Character to the MedicalCabin in case of him falling from the bridge. @@ -16,9 +13,18 @@ * @version %I% * @since 0.0.1-SNAPSHOT */ +// @Component public class DungeonEntranceGoAction extends ContainerArgumentAction { + private final RandomInteger rand; + public DungeonEntranceGoAction(Map wheres) { super(wheres); + this.rand = new RandomIntegerImpl(); + } + + public DungeonEntranceGoAction(Map wheres, RandomInteger rand) { + super(wheres); + this.rand = rand; } @Override @@ -29,9 +35,7 @@ public IResult actionBody(IPlayer player, String toGoName) { return new Result("You want to go... where?"); } - Random rand = new Random(); - int result = rand.nextInt(10); - if (result < 4) { + if (rand.nextInt(10) < 4) { toGo = player.getWorld().getLocation("medical"); } diff --git a/src/main/java/pl/uj/io/cuteanimals/plot/actions/DungeonInvestigateAction.java b/src/main/java/pl/uj/io/cuteanimals/plot/actions/DungeonInvestigateAction.java index 2d198c1..a1b3cbe 100644 --- a/src/main/java/pl/uj/io/cuteanimals/plot/actions/DungeonInvestigateAction.java +++ b/src/main/java/pl/uj/io/cuteanimals/plot/actions/DungeonInvestigateAction.java @@ -29,7 +29,7 @@ public IResult actionBody(IPlayer player) { } for (IItem item : player.getArmor().getItems()) { - if (item.getName().equals("torch")) { + if (item.getName().toLowerCase().equals("torch")) { return new Result(infoMessage); } } diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 796a1fd..aa7b3de 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -21,9 +21,9 @@