Skip to content

Commit

Permalink
Copied in other code
Browse files Browse the repository at this point in the history
  • Loading branch information
Serneum committed Jul 16, 2013
1 parent f713bcb commit 202a234
Show file tree
Hide file tree
Showing 17 changed files with 547 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bin/
dist/
build/

.classpath
.project
*.jar
4 changes: 0 additions & 4 deletions README.md

This file was deleted.

2 changes: 2 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RPG Core
This project is a base library that can be used to develop libraries that use tabletop RPG rule sets
40 changes: 40 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<project name="rpg-core" default="dist" basedir=".">
<!--
PROPERTIES
-->
<property name="project.name" value="${ant.project.name}"/>
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="build.classes.dir" value="${build.dir}/classes"/>
<property name="dist.dir" value="dist"/>

<!--
BASE TARGETS
-->
<target name="dist" depends="compile, dist-main"/>
<target name="compile" depends="compile-main"/>

<!--
MAIN TARGETS
-->
<target name="dist-main" depends="compile-main">
<jar destfile="${dist.dir}/${project.name}.jar" basedir="${build.classes.dir}"/>
</target>

<target name="compile-main" depends="clean">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${build.classes.dir}" includeantruntime="false"/>
</target>

<!--
CLEAN TARGETS
-->
<target name="clean">
<delete dir="${build.dir}" failonerror="false"/>
</target>

<target name="clean-all" depends="clean">
<delete dir="${dist.dir}" failonerror="false"/>
</target>
</project>
107 changes: 107 additions & 0 deletions src/main/java/com/sern/rpg/core/character/Character.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.sern.rpg.core.character;

import java.util.Set;

import com.sern.rpg.core.character.modifier.Modifier;
import com.sern.rpg.core.character.special.Special;

public class Character {
private String name;
protected int level = 0;
private int maxHealth = 0;
private int currentHealth = 0;
private int bonus = 0;
private Set<Modifier> modifiers;
private Special special;

public Character(int level, String name, int health) {
setName(name);
setMaxHealth(health);
this.currentHealth = health;
}

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void addModifier(Modifier modifier) {
modifiers.add(modifier);
}

public Set<Modifier> getModifiers() {
return modifiers;
}

/**
* Set the health of the generated character. This is only called on character creation
* @param maxHealth The character's starting maximum health
*/
protected void setMaxHealth(int maxHealth) {
this.maxHealth = maxHealth;
}

/**
* Adjust the maximum health of a character. Ex: Update on level, modifier
* @param amount The value to adjust the maximum health with. Positive values to increase, negative to decrease
*/
public void adjustMaxHealth(int amount) {
maxHealth += amount;
}

public int getMaxHealth() {
return maxHealth;
}

/**
* Adjust the current health of a character. Ex: Update on damage
* @param amount The value to adjust the current health with. Positive values to increase, negative to decrease
*/
public void adjustHealth(int amount) {
currentHealth += amount;
}

public int getCurrentHealth() {
return currentHealth;
}

protected void setBonus(int bonus) {
this.bonus = bonus;
}

public int getBonus() {
return bonus;
}

/**
* Set the special ability for the character. This can only be set at creation time.
* @param special The special ability to set on the character
*/
protected void setSpecial(Special special) {
this.special = special;
}

public Special getSpecial() {
return special;
}

/**
* Check to see if the character has a special they can use
* @return True if the special attribute is not null, false otherwise
*/
public boolean hasSpecial() {
return special != null;
}

protected void setLevel(int level) {
this.level = level;
}

public int getLevel() {
return level;
}

}
11 changes: 11 additions & 0 deletions src/main/java/com/sern/rpg/core/character/enemy/Enemy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sern.rpg.core.character.enemy;

import com.sern.rpg.core.character.Character;

public abstract class Enemy extends Character {

public Enemy(int level, String name, int health) {
super(level, name, health);
}

}
30 changes: 30 additions & 0 deletions src/main/java/com/sern/rpg/core/character/enemy/EnemyFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.sern.rpg.core.character.enemy;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.sern.rpg.core.service.EnemyServiceFactory;

public class EnemyFactory {
static private EnemyFactory instance = new EnemyFactory();

static public EnemyFactory getInstance() {
return instance;
}

public Enemy getEnemy(String name) {
Map<String, Enemy> enemies = EnemyServiceFactory.getInstance().getEnemies();
return enemies.get(name);
}

public Enemy getRandomEnemy() {
Map<String, Enemy> enemies = EnemyServiceFactory.getInstance().getEnemies();
Random rand = new Random();
int index = rand.nextInt(enemies.size());
List<String> keys = new ArrayList<String>(enemies.keySet());
String key = keys.get(index);
return enemies.get(key);
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/sern/rpg/core/character/modifier/Modifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.sern.rpg.core.character.modifier;

import com.sern.rpg.core.character.special.Special;

public class Modifier {
private String name;
private Special special;

/**
* Set the name of the modifier. The name will be prepended to modified characters. This is only called on creation
* @param name The name of the modifier that will be applied to modified characters
*/
protected void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}

/**
* Set the special ability for the modifier. This ability can later be applied to a character. This is only called on creation
* @param special The special ability to apply with the modifier
*/
protected void setSpecial(Special special) {
this.special = special;
}

public Special getSpecial() {
return special;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.sern.rpg.core.character.modifier;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.sern.rpg.core.service.ModifierServiceFactory;

public class ModifierFactory {
static private ModifierFactory instance = new ModifierFactory();

static public ModifierFactory getInstance() {
return instance;
}

public Modifier getModifier(String name) {
Map<String, Modifier> modifiers = ModifierServiceFactory.getInstance().getModifiers();
return modifiers.get(name);
}

public Modifier getRandomModifier() {
Map<String, Modifier> modifiers = ModifierServiceFactory.getInstance().getModifiers();
Random rand = new Random();
int index = rand.nextInt(modifiers.size());
List<String> keys = new ArrayList<String>(modifiers.keySet());
String key = keys.get(index);
return modifiers.get(key);
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/sern/rpg/core/character/player/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.sern.rpg.core.character.player;

import com.sern.rpg.core.character.Character;

public class Player extends Character {

public Player(int level, String name, int health) {
super(level, name, health);
}

public void levelUp() {
this.level++;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sern.rpg.core.character.special;

public interface Special {
public void execute();

public boolean isConditionMet();
}
67 changes: 67 additions & 0 deletions src/main/java/com/sern/rpg/core/dm/Dice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.sern.rpg.core.dm;

import java.util.Random;

/**
* The Dice class contains all standard and non-standard dice from the D2 to the D100
*
* You can roll a die by calling Dice.roll(die) with one of the die that are available. Multiple dice can be rolled with
* Dice.roll(count, die). Modifiers can be used to adjust the value of rolls with Dice.roll(count, die, modifier)
*
*/
public class Dice {
static public int D2 = 2;
static public int D3 = 3;
static public int D4 = 4;
static public int D5 = 5;
static public int D6 = 6;
static public int D7 = 7;
static public int D8 = 8;
static public int D10 = 10;
static public int D12 = 12;
static public int D14 = 14;
static public int D16 = 16;
static public int D20 = 20;
static public int D24 = 24;
static public int D30 = 30;
static public int D34 = 34;
static public int D50 = 50;
static public int D60 = 60;
static public int D100 = 100;

static private Random rand = new Random();

/**
* Roll a die and get the value
* @param die The die to roll
* @return The value determined by rolling the die. Ex: roll(Dice.D6) will return a value between 1 and 6
*/
static public int roll(int die) {
return rand.nextInt(die) + 1;
}

/**
* Roll a set of dice and get the total value
* @param count The number of dice to roll
* @param die The die to roll
* @return The value determined by rolling the dice. Ex: roll(2, Dice.D6) will return a value between 2 and 12
*/
static public int roll(int count, int die) {
int total = 0;
for (int i = 0; i < count; i++) {
total += roll(die);
}
return total;
}

/**
* Roll a set of dice and get the total value after being adjusted by a modifier
* @param count The number of dice to roll
* @param die The die to roll
* @param modifier The amount to add (or remove) from the dice roll value
* @return The value determined by rolling the dice. Ex: roll(2, Dice.D6, -3) will return a value between -1 and 9
*/
static public int roll(int count, int die, int modifier) {
return roll(count, die) + modifier;
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/sern/rpg/core/dm/DungeonMaster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sern.rpg.core.dm;

import com.sern.rpg.core.character.enemy.Enemy;
import com.sern.rpg.core.character.enemy.EnemyFactory;

public abstract class DungeonMaster {

public Enemy generateEnemy() {
return EnemyFactory.getInstance().getRandomEnemy();
}
}
Loading

0 comments on commit 202a234

Please sign in to comment.