Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions src/main/java/calculationEngine/entities/CeInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class CeInventory {
CeItem equippedArmorHead;
CeItem equippedWeapon;

CeStats playerStats;

int maxItemSlots = 10;
CeSlot[] slots = new CeSlot[maxItemSlots];

Expand All @@ -31,10 +33,11 @@ public void loadSaveInventory(CeItem armorShoulder, CeItem armorShoes, CeItem ar
this.equippedWeapon = weapon;
}

public CeInventory() {
public CeInventory(CeStats ceStats) {
for (int i = 0; i < slots.length; i++) {
slots[i] = new CeSlot();
}
this.playerStats = ceStats;
}

public void addItemToInventory(CeItem item) throws NoPlaceInInventoryException {
Expand Down Expand Up @@ -72,6 +75,7 @@ public void useItem(CeItem item) throws ItemNotInInventoryException {
if (slotItem != null) {
if (slotItem.compareTo(item)) {
matchingItem = true;
slotItem.use(this.playerStats);
int remainingAmount = slot.decreaseAmount();
if (remainingAmount <= 0) {
slot.reset();
Expand Down Expand Up @@ -131,56 +135,74 @@ public void setEquippedItem(CeItem equippedItem) throws WrongItemException {
}

private void setEquippedArmorShoulder(CeItem equippedArmorShoulder) throws WrongItemException {
if (this.equippedArmorShoulder != null)
if (this.equippedArmorShoulder != null) {
this.playerStats.removeBonusStats(this.equippedArmorShoulder.getItemBonusStats());
this.equippedArmorShoulder.unequip();
}
if (equippedArmorShoulder.getType() == armorShoulder) {
this.equippedArmorShoulder = equippedArmorShoulder;
this.equippedArmorShoulder.equip();
this.playerStats.applyBonusStats(equippedArmorShoulder.getItemBonusStats());
} else throw new WrongItemException(equippedArmorShoulder, "Armor type shoulderArmor");
}

private void setEquippedArmorShoes(CeItem equippedArmorShoes) throws WrongItemException {
if (this.equippedArmorShoes != null)
if (this.equippedArmorShoes != null) {
this.playerStats.removeBonusStats(this.equippedArmorShoes.getItemBonusStats());
this.equippedArmorShoes.unequip();
}
if (equippedArmorShoes.getType() == armorShoes) {
this.equippedArmorShoes = equippedArmorShoes;
this.equippedArmorShoes.equip();
this.playerStats.applyBonusStats(equippedArmorShoes.getItemBonusStats());
} else throw new WrongItemException(equippedArmorShoes, "Armor type armorShoes");
}

private void setEquippedArmorLegs(CeItem equippedArmorLegs) throws WrongItemException {
if (this.equippedArmorLegs != null)
if (this.equippedArmorLegs != null) {
this.playerStats.removeBonusStats(this.equippedArmorLegs.getItemBonusStats());
this.equippedArmorLegs.unequip();
}
if (equippedArmorLegs.getType() == armorLegs) {
this.equippedArmorLegs = equippedArmorLegs;
this.equippedArmorLegs.equip();
this.playerStats.applyBonusStats(equippedArmorLegs.getItemBonusStats());
} else throw new WrongItemException(equippedArmorLegs, "Armor type ArmorLegs");
}

private void setEquippedArmorChest(CeItem equippedArmorChest) throws WrongItemException {
if (this.equippedArmorChest != null)
if (this.equippedArmorChest != null) {
this.playerStats.removeBonusStats(this.equippedArmorChest.getItemBonusStats());
this.equippedArmorChest.unequip();
}
if (equippedArmorChest.getType() == armorChest) {
this.equippedArmorChest = equippedArmorChest;
this.equippedArmorChest.equip();
this.playerStats.applyBonusStats(equippedArmorChest.getItemBonusStats());
} else throw new WrongItemException(equippedArmorChest, "Armor type ArmorChest");
}

private void setEquippedArmorHead(CeItem equippedArmorHead) throws WrongItemException {
if (this.equippedArmorHead != null)
if (this.equippedArmorHead != null) {
this.playerStats.removeBonusStats(this.equippedArmorHead.getItemBonusStats());
this.equippedArmorHead.unequip();
}
if (equippedArmorHead.getType() == armorHead) {
this.equippedArmorHead = equippedArmorHead;
this.equippedArmorHead.equip();
this.playerStats.applyBonusStats(equippedArmorHead.getItemBonusStats());
} else throw new WrongItemException(equippedArmorHead, "Armor type armorHead");
}

private void setEquippedWeapon(CeItem equippedWeapon) throws WrongItemException {
if (this.equippedWeapon != null)
if (this.equippedWeapon != null) {
this.playerStats.removeBonusStats(this.equippedWeapon.getItemBonusStats());
this.equippedWeapon.unequip();
}
if (equippedWeapon.getType() == weapon) {
this.equippedWeapon = equippedWeapon;
this.equippedWeapon.equip();
this.playerStats.applyBonusStats(equippedWeapon.getItemBonusStats());
} else throw new WrongItemException(equippedWeapon, "Armor type weapon");
}

Expand Down Expand Up @@ -215,4 +237,8 @@ public CeSlot[] getSlots() {
public int getMaxItemSlots() {
return maxItemSlots;
}

public void setPlayerStats(CeStats playerStats) {
this.playerStats = playerStats;
}
}
2 changes: 1 addition & 1 deletion src/main/java/calculationEngine/entities/CePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public CePlayer(CeStats ceStats, List<CeAttack> ceAttacks, List<CeEntity> team,
super(ceStats, ceAttacks, Integer.MAX_VALUE, false);
this.team = team;
this.isAI = isAI;
this.inventory = new CeInventory();
this.inventory = new CeInventory(this.getCeStats());
}

// Constructor for AI
Expand Down
75 changes: 71 additions & 4 deletions src/main/java/calculationEngine/entities/CeStats.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package calculationEngine.entities;

import calculationEngine.environment.CeItem;
import calculationEngine.environment.CeItemBonusStats;
import config.AiConstants;
import config.EntityConstants;
import config.PlayerConfig;
Expand All @@ -18,6 +20,7 @@ public class CeStats {
private int attack;
private int defense;
private int friendshipPoints;
private int critBonus = 0;

private Random random = new Random();

Expand All @@ -36,7 +39,7 @@ public CeStats(CeBeastTypes type, CeNature nature, int level, int currentHitPoin
}

// Constructor for a new random Beast
public CeStats(CeBeasts beast, int playerLvl){
public CeStats(CeBeasts beast, int playerLvl) {
// calculate Level
this.level = calcLvl(playerLvl);
this.nature = CeNature.getRandomNature();
Expand All @@ -50,7 +53,7 @@ public CeStats(CeBeasts beast, int playerLvl){
this.defense = scaleOnLvl(beast.getBaseDefense(), this.level, beast.getDefenseLvlScaling()) + (random.nextInt(EntityConstants.DEFENSE_RANGE * 2) - EntityConstants.DEFENSE_RANGE);
}

public CeStats(CeBeasts beast){ // dev constructor
public CeStats(CeBeasts beast) { // dev constructor
this.type = beast.getType();
this.nature = CeNature.getRandomNature();
this.currentHitPoints = beast.getBaseHp();
Expand All @@ -64,7 +67,7 @@ public CeStats(CeBeasts beast){ // dev constructor
}

// AI NPC Constructor
public CeStats(int playerLvl, CeBeastTypes type){
public CeStats(int playerLvl, CeBeastTypes type) {
this.level = calcLvl(playerLvl);
this.type = type;
this.nature = CeNature.getRandomNature();
Expand All @@ -78,7 +81,7 @@ public CeStats(int playerLvl, CeBeastTypes type){
this.friendshipPoints = 0;
}

public CeStats(CeStats ceStats){
public CeStats(CeStats ceStats) {
this.level = ceStats.getLevel();
this.currentHitPoints = ceStats.getCurrentHitPoints();
this.maxHitPoints = ceStats.getMaxHitPoints();
Expand All @@ -98,6 +101,24 @@ private int calcLvl(int playerLvl) {

}

public void applyBonusStats(CeItemBonusStats ceItemBonusStats) {
this.attack += ceItemBonusStats.getAttack();
this.defense += ceItemBonusStats.getDefense();
this.maxHitPoints += ceItemBonusStats.getHealthPoints();
this.speed += ceItemBonusStats.getSpeed();
this.stamina += ceItemBonusStats.getStamina();
this.critBonus += ceItemBonusStats.getCritBonus();
}

public void removeBonusStats(CeItemBonusStats ceItemBonusStats) {
this.attack -= ceItemBonusStats.getAttack();
this.defense -= ceItemBonusStats.getDefense();
this.maxHitPoints -= ceItemBonusStats.getHealthPoints();
this.speed -= ceItemBonusStats.getSpeed();
this.stamina -= ceItemBonusStats.getStamina();
this.critBonus -= ceItemBonusStats.getCritBonus();
}

public static int scaleOnLvl(int base, int lvl, int lvlScaling) {
return base + lvl * lvlScaling;
}
Expand Down Expand Up @@ -153,4 +174,50 @@ public void setCurrentHitPoints(int currentHitPoints) {
public void setMaxHitPoints(int maxHitPoints) {
this.maxHitPoints = maxHitPoints;
}

public int getCritBonus() {
return critBonus;
}

public void setSpeed(int speed) {
this.speed = speed;
}

public void setStamina(int stamina) {
this.stamina = stamina;
}

public void setAttack(int attack) {
this.attack = attack;
}

public void setDefense(int defense) {
this.defense = defense;
}

public void setFriendshipPoints(int friendshipPoints) {
this.friendshipPoints = friendshipPoints;
}

public void setCritBonus(int critBonus) {
this.critBonus = critBonus;
}

@Override
public String toString() {
return "CeStats{" +
"type=" + type +
", nature=" + nature +
", level=" + level +
", currentHitPoints=" + currentHitPoints +
", maxHitPoints=" + maxHitPoints +
", speed=" + speed +
", stamina=" + stamina +
", attack=" + attack +
", defense=" + defense +
", friendshipPoints=" + friendshipPoints +
", critBonus=" + critBonus +
", random=" + random +
'}';
}
}
6 changes: 5 additions & 1 deletion src/main/java/calculationEngine/environment/CeItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package calculationEngine.environment;

import calculationEngine.entities.CeStats;
import org.json.JSONObject;

public class CeItem {
Expand All @@ -12,6 +13,7 @@ public class CeItem {
private int uses;
private CeItemBonusStats itemBonusStats;
private String description;
private CeItemEffects effect;

public CeItem() {
}
Expand All @@ -34,6 +36,7 @@ private void setItem(JSONObject itemJson) {
this.uses = itemJson.getInt("uses");
this.itemBonusStats = new CeItemBonusStats(CeLoot.jsonArrayToIntArray(itemJson.getJSONArray("bonusStats")));
this.description = itemJson.getString("description");
this.effect = new CeItemEffects(itemJson.getJSONObject("effects"));
}

public void equip() {
Expand All @@ -44,7 +47,8 @@ public void unequip() {
this.equipped = false;
}

public int use() {
public int use(CeStats ceStats) {
this.effect.use(ceStats);
this.uses--;
return this.uses; //return remaining uses, so they can be handled in the iventory handler
}
Expand Down
74 changes: 74 additions & 0 deletions src/main/java/calculationEngine/environment/CeItemEffects.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package calculationEngine.environment;

import calculationEngine.entities.CeStats;
import config.BattleConstants;
import config.LootConfig;
import org.json.JSONObject;

public class CeItemEffects {

private effects effect;
private String description;
private int value;

private static final boolean debug = BattleConstants.battleDebug;

private enum effects{
healing,
increaseSpeed,
increaseAttack,
increaseCritBonus,
increaseDefense,
catchBeast,
defaultEffect
}

public CeItemEffects(JSONObject effectObject){
this.effect = effects.valueOf(effectObject.getString("type"));
this.value = effectObject.getInt("value");
this.description = effectObject.getString("description");
}

public void use(CeStats ceStats){
switch (this.effect.name()){
case "healing":
int hitPoints = ceStats.getCurrentHitPoints();
hitPoints += this.value;
ceStats.setCurrentHitPoints(hitPoints);
if (debug) System.out.println("[CeItemEffects] healing by " + this.value + " points");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could create a method, "addToStat" in which you say to which stat you want to add (perhaps with ENUM) and how much you want to add.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's neccessary, because it doens't change the problem. For every stat that has to change, you have to call different methods. So if i add another Method this will result in a switch case which has another switch case in it. So you just duplicate the whole thing and you have it twice. IMO it makes it even worse.

break;
case "increaseSpeed":
int speed = ceStats.getSpeed();
speed += this.value;
ceStats.setSpeed(speed);
break;
case "increaseAttack":
int attack = ceStats.getAttack();
attack += this.value;
ceStats.setAttack(attack);
break;
case "increaseCritBonus":
int critBonus = ceStats.getCritBonus();
critBonus += this.value;
ceStats.setCritBonus(critBonus);
break;
case "increaseDefense":
int defense = ceStats.getDefense();
defense += this.value;
ceStats.setDefense(defense);
break;
}
Comment thread
lkno0705 marked this conversation as resolved.
}

public effects getEffect() {
return effect;
}

public String getDescription() {
return description;
}

public int getValue() {
return value;
}
}
Loading