Consumable class and it's subclasses completed (+ Bonus subclasses for Flask.)
This commit is contained in:
@@ -13,4 +13,10 @@ public interface Entity {
|
|||||||
int getMaxHP();
|
int getMaxHP();
|
||||||
|
|
||||||
int getMaxMP();
|
int getMaxMP();
|
||||||
|
|
||||||
|
int getHp();
|
||||||
|
|
||||||
|
int getMp();
|
||||||
|
|
||||||
|
String getName();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,28 @@
|
|||||||
package org.project.item.consumables;
|
package org.project.item.consumables;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import org.project.item.Item;
|
||||||
public abstract class Consumable {
|
|
||||||
/*
|
public abstract class Consumable implements Item {
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
protected String name;
|
||||||
*/
|
protected int healingPercent;
|
||||||
|
|
||||||
|
public Consumable(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Consumable(String name, int healingPercent) {
|
||||||
|
this(name);
|
||||||
|
this.healingPercent = healingPercent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHealingPercent() {
|
||||||
|
return healingPercent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract void use(org.project.entity.Entity target);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,37 @@ package org.project.item.consumables;
|
|||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public class Flask extends Consumable {
|
||||||
public class Flask {
|
public Flask(int healingPersent) {
|
||||||
/*
|
super("Healing Flask");
|
||||||
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
|
this.healingPercent = 25;
|
||||||
*/
|
}
|
||||||
|
|
||||||
// TODO: UPDATE USE METHOD
|
|
||||||
@Override
|
@Override
|
||||||
public void use(Entity target) {
|
public void use(Entity target) {
|
||||||
target.heal(target.getMaxHP() / 10);
|
//Checking if the target is alive
|
||||||
|
if (target == null || target.getHp() <= 0) {
|
||||||
|
System.out.println("❌ Target is dead already!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int healAmount = target.getMaxHP() * healingPercent / 100;
|
||||||
|
if (healAmount < 10) {
|
||||||
|
healAmount = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
int oldHp = target.getHp();
|
||||||
|
target.heal(healAmount);
|
||||||
|
int actualHeal = target.getHp() - oldHp;
|
||||||
|
|
||||||
|
System.out.println("🧪🧪🧪 ============== 🧪🧪🧪");
|
||||||
|
System.out.println("💚 " + target.getName() + " drinks the Healing Flask!");
|
||||||
|
System.out.println("✨ Restored " + actualHeal + " HP!");
|
||||||
|
System.out.println("💚 HP: " + target.getHp() + "/" + target.getMaxHP());
|
||||||
|
|
||||||
|
if (target.getHp() == target.getMaxHP()) {
|
||||||
|
System.out.println("💪 " + target.getName() + " is fully healed!");
|
||||||
|
}
|
||||||
|
System.out.println("🧪🧪🧪 ============== 🧪🧪🧪");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package org.project.item.consumables;
|
||||||
|
|
||||||
|
public class GreatFlask extends Flask {
|
||||||
|
public GreatFlask() {
|
||||||
|
super(50); //50% healing
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package org.project.item.consumables;
|
||||||
|
|
||||||
|
public class HealthFlask extends Flask {
|
||||||
|
public HealthFlask() {
|
||||||
|
super(25); //25% healing
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.project.item.consumables;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
|
import org.project.entity.players.Player;
|
||||||
|
|
||||||
|
public class ManaFlask extends Flask {
|
||||||
|
public ManaFlask() {
|
||||||
|
super(30); //30% mana increasing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void use(Entity target) {
|
||||||
|
if (target instanceof Player) {
|
||||||
|
Player player = (Player) target;
|
||||||
|
int manaAmount = player.getMaxMP() / 3;
|
||||||
|
player.setMp(Math.min(player.getMp() + manaAmount, player.getMaxMP()));
|
||||||
|
System.out.println("💙 Restored " + manaAmount + " Mana!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user