Skip to content

Commit

Permalink
Should have a Banishment spell
Browse files Browse the repository at this point in the history
Closed #412
  • Loading branch information
Bernardo Sulzbach committed Oct 30, 2017
1 parent 6057b12 commit dd93609
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/java/org/mafagafogigante/dungeon/spells/SpellData.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mafagafogigante.dungeon.spells;

import org.mafagafogigante.dungeon.entity.creatures.Creature;
import org.mafagafogigante.dungeon.entity.creatures.HealthState;
import org.mafagafogigante.dungeon.entity.creatures.Hero;
import org.mafagafogigante.dungeon.entity.creatures.HeroUtils;
import org.mafagafogigante.dungeon.entity.items.Item;
Expand Down Expand Up @@ -186,6 +187,43 @@ public void operate(Hero hero, String[] targetMatcher) {
}
}
});
putSpell(new Spell("BANISH", "Banish") {

static final int SECONDS_TO_CAST = 10;

@Override
public void operate(Hero hero, String[] targetMatcher) {
if (targetMatcher.length == 0) {
Writer.getDefaultWriter().write("Provide a target.");
} else {
Creature target = hero.findCreature(targetMatcher);
if (target != null) {
if (target == hero) {
Writer.getDefaultWriter().write("You cannot cast banish on yourself.");
return;
}
Game.getGameState().getEngine().rollDateAndRefresh(SECONDS_TO_CAST);
Writer.getDefaultWriter().write("You casted " + getName() + " on " + target.getName().getSingular() + ".");
if (target.getHealth().getHealthState() == HealthState.DEAD) {
Writer.getDefaultWriter().write("Your target seems to be already dead.");
} else {
double missingRatio = 1.0 - target.getHealth().getCurrent() / (double) target.getHealth().getMaximum();
double successProbability = 0.1 + Math.pow(Math.sqrt(0.9) * missingRatio, 2);
if (Random.roll(successProbability)) {
hero.getLocation().removeCreature(target);
Writer.getDefaultWriter().write("You banished " + target.getName().getSingular() + "!");
} else {
RichStringSequence stringSequence = new RichStringSequence();
stringSequence.append("You failed to banish " + target.getName().getSingular() + ".");
stringSequence.append("\n");
stringSequence.append("Try damaging " + target.getName().getSingular() + " so it is less resistant.");
Writer.getDefaultWriter().write(stringSequence);
}
}
}
}
}
});
putSpell(new Spell("DISPLACE", "Displace") {

static final int SECONDS_TO_CAST_DISPLACE = 15;
Expand Down
24 changes: 24 additions & 0 deletions src/main/resources/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,30 @@
"nutrition": -5,
"integrityDecrementOnEat": 10
},
{
"id": "TOME_OF_BANISH",
"type": "Book",
"name": {
"singular": "Tome of Banish",
"plural": "Tomes of Banish"
},
"rarity": "UNCOMMON",
"tags": [
"WEAPON",
"BOOK"
],
"integrity": {
"current": 20,
"maximum": 20
},
"weight": 0.6,
"visibility": "60.00%",
"damage": 6,
"hitRate": "70.00%",
"integrityDecrementOnHit": 4,
"text": "The Banish spell permanently banishes a weak creature from this plane.",
"spell": "BANISH"
},
{
"id": "TOME_OF_HEAL",
"type": "Book",
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
"id": "TOME_OF_UNVEIL",
"probability": 0.15
},
{
"id": "TOME_OF_BANISH",
"probability": 0.15
},
{
"id": "DAGGER",
"probability": 0.2
Expand Down

0 comments on commit dd93609

Please sign in to comment.