Skip to content

Commit

Permalink
Merge pull request #133 from rayrobdod/terrain-res
Browse files Browse the repository at this point in the history
Make terrain have separate DEF and RES bonuses
  • Loading branch information
HamaIndustries committed Dec 13, 2016
2 parents 7306571 + ed639b7 commit ce6689f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 55 deletions.
87 changes: 36 additions & 51 deletions src/net/fe/overworldStage/Terrain.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package net.fe.overworldStage;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import static java.util.Collections.unmodifiableList;

import net.fe.Player;
import net.fe.unit.Class;
import net.fe.unit.Statistics;
import net.fe.unit.Unit;
import net.fe.unit.WeaponFactory;
import chu.engine.Entity;
Expand All @@ -16,93 +17,95 @@
public enum Terrain {

/** The plain. */
PLAIN(1,0,0,0),
PLAIN(1,0,0,0,0),

/** The path. */
PATH(1,0,0,0),
PATH(1,0,0,0,0),

/** The forest. */
FOREST(2,1,20,0),
FOREST(2,1,1,20,0),

/** The floor. */
FLOOR(1,0,0,0),
FLOOR(1,0,0,0,0),

/** The pillar. */
PILLAR(2,1,20,0),
PILLAR(2,1,1,20,0),

/** The mountain. */
MOUNTAIN(4,2,30,0),
MOUNTAIN(4,2,2,30,0),

/** The village. */
VILLAGE(1,0,10,0),
VILLAGE(1,0,0,10,0),

/** The peak. */
PEAK(127,2,40,0),
PEAK(127,2,2,40,0),

/** The fort. */
FORT(2,1,15,10),
FORT(2,1,1,15,10),

/** The sea. */
SEA(127,0,10,0),
SEA(127,0,0,10,0),

/** The desert. */
DESERT(2,0,5,0),
DESERT(2,0,0,5,0),

/** The wall. */
WALL(127,0,0,0),
WALL(127,0,0,0,0),

/** The fence. */
FENCE(127,0,0,0),
FENCE(127,0,0,0,0),

/** The none. */
NONE(127,0,0,0),
NONE(127,0,0,0,0),

/** The cliff. */
CLIFF(127,0,0,0),
CLIFF(127,0,0,0,0),

/** The throne. */
THRONE(1,3,30,10),
THRONE(1,3,5,30,10),

/** The hill. */
HILL(4,2,30,0),
HILL(4,2,2,30,0),

/** The house. */
HOUSE(127,0,10,0);
HOUSE(127,0,0,10,0);

/** The base move cost. */
private int baseMoveCost;
private final int baseMoveCost;

/** The avoid bonus. */
private final int avoidBonus;

/** The defense bonus. */
private final int defenseBonus;
private final Statistics defenseBonus;

/** The health bonus. */
public final int healthBonus;

/** The triggers. */
private CopyOnWriteArrayList<TerrainTrigger> triggers;
private final List<TerrainTrigger> triggers;



/**
* Instantiates a new terrain.
*
* @param baseMoveCost the base move cost
* @param def the def
* @param avo the avo
* @param def the DEF gained by a unit while standing on this space
* @param res the RES gained by a unit while standing on this space
* @param avo the AVOID gained by a unit while standing on this space
* @param health the health
*/
Terrain(int baseMoveCost, int def, int avo, int health) {
Terrain(int baseMoveCost, int def, int res, int avo, int health) {
this.baseMoveCost = baseMoveCost;
avoidBonus = avo;
defenseBonus = def;
defenseBonus = new Statistics().copy("Def", def).copy("Res", res);
healthBonus = health;
triggers = new CopyOnWriteArrayList<TerrainTrigger>();
List<TerrainTrigger> tmpTriggers = new java.util.ArrayList<>();
if(healthBonus > 0){
triggers.add(new Healing(healthBonus));
tmpTriggers.add(new Healing(healthBonus));
}
triggers = unmodifiableList(tmpTriggers);
}

/**
Expand Down Expand Up @@ -157,24 +160,6 @@ else if(name.equals("Paladin")) {
return baseMoveCost;
}

/**
* Adds the trigger.
*
* @param e the e
*/
public void addTrigger(TerrainTrigger e){
triggers.add(e);
}

/**
* Removes the trigger.
*
* @param e the e
*/
public void removeTrigger(TerrainTrigger e){
triggers.remove(e);
}

/**
* Gets the triggers.
*
Expand All @@ -187,7 +172,7 @@ public List<TerrainTrigger> getTriggers(){
/**
* Gets the avoid bonus.
*
* @param u the u
* @param u the unit to check, or null if a generic answer
* @return the avoid bonus
*/
public int getAvoidBonus(Unit u) {
Expand All @@ -199,19 +184,19 @@ public int getAvoidBonus(Unit u) {
/**
* Gets the defense bonus.
*
* @param u the u
* @param u the unit to check, or null if a generic answer
* @return the defense bonus
*/
public int getDefenseBonus(Unit u) {
public Statistics getDefenseBonus(Unit u) {
if(u == null) return defenseBonus;
if(WeaponFactory.fliers.contains(u.getTheClass().name)) return 0;
if(WeaponFactory.fliers.contains(u.getTheClass().name)) return new Statistics();
return defenseBonus;
}

/**
* The Class Healing.
*/
public class Healing extends TerrainTrigger{
public final class Healing extends TerrainTrigger{

/** The percent. */
private int percent;
Expand Down
8 changes: 6 additions & 2 deletions src/net/fe/overworldStage/TerrainInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ public void render() {
Renderer.render(dragons, 0, 0, 1, 1,
x+7, y+28, x+45, y+37, renderDepth);
//Terrain stats
String defenseBonusString = (terrain.getDefenseBonus(null).def == terrain.getDefenseBonus(null).res ?
terrain.getDefenseBonus(null).def + "" :
terrain.getDefenseBonus(null).def + " | " + terrain.getDefenseBonus(null).res);

Renderer.drawString("default_med", "AVO", x+5, y+40, renderDepth);
Renderer.drawString("default_med", terrain.getAvoidBonus(null),
x+46-def.getStringWidth(terrain.getAvoidBonus(null)+""), y+40, renderDepth);
Renderer.drawString("default_med", "DEF", x+5, y+53, renderDepth);
Renderer.drawString("default_med", terrain.getDefenseBonus(null),
x+46-def.getStringWidth(terrain.getDefenseBonus(null)+""), y+53, renderDepth);
Renderer.drawString("default_med", defenseBonusString,
x+46-def.getStringWidth(defenseBonusString), y+53, renderDepth);
Renderer.drawString("default_med", "HP", x+5, y+66, renderDepth);
Renderer.drawString("default_med", terrain.healthBonus,
x+46-def.getStringWidth(terrain.healthBonus+""), y+66, renderDepth);
Expand Down
3 changes: 1 addition & 2 deletions src/net/fe/unit/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,7 @@ public Statistics getStats() {
Statistics retVal = this.stats;
if (this.getWeapon() != null) {retVal = retVal.plus(this.getWeapon().modifiers);}
retVal = retVal.plus(new Statistics(tempMods));
retVal = retVal.copy("Def", retVal.def + this.getTerrain().getDefenseBonus(this));
retVal = retVal.copy("Res", retVal.res + this.getTerrain().getDefenseBonus(this));
retVal = retVal.plus(this.getTerrain().getDefenseBonus(this));
if (rescuedUnit != null) {
retVal = retVal.copy("Spd", retVal.spd / 2);
retVal = retVal.copy("Skl", retVal.skl / 2);
Expand Down

0 comments on commit ce6689f

Please sign in to comment.