diff --git a/src/minecraft/dark/faction/api/IFactionObject.java b/src/minecraft/dark/faction/api/IFactionObject.java new file mode 100644 index 000000000..7b149035a --- /dev/null +++ b/src/minecraft/dark/faction/api/IFactionObject.java @@ -0,0 +1,13 @@ +package dark.faction.api; + +import dark.faction.core.FactionInstance; + +public interface IFactionObject +{ + /** + * Gets the faction this is linked too. Will return Neutral rather than null + */ + public FactionInstance getFactinon(); + + public boolean setFaction(FactionInstance faction, boolean override); +} diff --git a/src/minecraft/dark/faction/core/FactionCreationEvent.java b/src/minecraft/dark/faction/core/FactionCreationEvent.java new file mode 100644 index 000000000..99d974e8f --- /dev/null +++ b/src/minecraft/dark/faction/core/FactionCreationEvent.java @@ -0,0 +1,6 @@ +package dark.faction.core; + +public class FactionCreationEvent +{ + +} diff --git a/src/minecraft/dark/library/team/FactionInstance.java b/src/minecraft/dark/faction/core/FactionInstance.java similarity index 77% rename from src/minecraft/dark/library/team/FactionInstance.java rename to src/minecraft/dark/faction/core/FactionInstance.java index 3a97c774c..a9431840b 100644 --- a/src/minecraft/dark/library/team/FactionInstance.java +++ b/src/minecraft/dark/faction/core/FactionInstance.java @@ -1,7 +1,8 @@ -package dark.library.team; +package dark.faction.core; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import net.minecraft.nbt.NBTTagCompound; @@ -18,11 +19,11 @@ import dark.library.helpers.Time; */ public class FactionInstance { - List userList; - String name; - String creator; - String date = "unkown"; - String prefix; + public List userList; + public String name; + public String creator; + public String date = "unkown"; + public String prefix; public FactionInstance(String prefix, String name, String maker, Pair date) { @@ -99,9 +100,25 @@ public class FactionInstance tag.setString("creator", this.creator); return tag; } - + public void read(NBTTagCompound tag) { - + + } + + public boolean isEqual(FactionInstance faction) + { + + return faction != null && faction.name.equalsIgnoreCase(this.name) && faction.creator.equalsIgnoreCase(this.creator); + } + + public boolean isInvalid() + { + return this.wasPlayerCreated() && this.userList.isEmpty(); + } + + public boolean wasPlayerCreated() + { + return !this.creator.equalsIgnoreCase("World"); } } diff --git a/src/minecraft/dark/faction/core/FactionManager.java b/src/minecraft/dark/faction/core/FactionManager.java new file mode 100644 index 000000000..53db01bbc --- /dev/null +++ b/src/minecraft/dark/faction/core/FactionManager.java @@ -0,0 +1,48 @@ +package dark.faction.core; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import dark.faction.api.IFactionObject; + +public class FactionManager +{ + + /* LIST OF FACTION CURRENTLY OR RECNETLY LOADED */ + public static List cachedFactions = new ArrayList(); + /* LIST OF CURRENTLY OR RECENTLY LOADED PLAYERS AND THERE FACTIONS */ + public static HashMap cachedAllegance = new HashMap(); + + public static FactionInstance NEUTRIAL = new FactionInstance("NAN", "Neutrial", "World", null); + public static FactionInstance GUARDSMAN = new FactionInstance("GSM", "GUARDSMAN", "DARKGUARDSMAN", null); + public static FactionInstance DARK = new FactionInstance("DARK", "DARK", "DARKGUARDSMAN", null); + + public boolean isPartOfFaction(Object entity, FactionInstance faction) + { + if (faction == null || entity == null) + { + return false; + } + if (entity instanceof IFactionObject) + { + return faction.isEqual(((IFactionObject) entity).getFactinon()); + } + return false; + } + + public static FactionInstance loadFaction(String name) + { + if (name != null && !name.isEmpty()) + { + + } + return NEUTRIAL; + + } + + public static void saveFaction(FactionInstance faction) + { + + } +} diff --git a/src/minecraft/dark/faction/entity/CharStats.java b/src/minecraft/dark/faction/entity/CharStats.java new file mode 100644 index 000000000..526679aa2 --- /dev/null +++ b/src/minecraft/dark/faction/entity/CharStats.java @@ -0,0 +1,13 @@ +package dark.faction.entity; + +public enum CharStats +{ + Strength("Strength"), endurance("endurance"), dexterity("dexterity"), Intelligence("intelligence"), wit("wits"), memor("recall"), willpower("Will"), perception("charm"), luck("Luck"); + + public String name; + + private CharStats(String name) + { + this.name = name; + } +} diff --git a/src/minecraft/dark/faction/entity/EntityNpc.java b/src/minecraft/dark/faction/entity/EntityNpc.java new file mode 100644 index 000000000..fcbd1d597 --- /dev/null +++ b/src/minecraft/dark/faction/entity/EntityNpc.java @@ -0,0 +1,129 @@ +package dark.faction.entity; + +import java.util.Random; + +import net.minecraft.entity.EntityCreature; +import net.minecraft.entity.EntityLiving; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import dark.faction.api.IFactionObject; +import dark.faction.core.FactionInstance; +import dark.faction.core.FactionManager; +import dark.library.math.MathHelper; +import dark.library.npc.IAdvancedNpc; + +/** + * NPC that simulate being players in an empire controlled environment + * + * @author Darkguardsman + */ +public class EntityNpc extends EntityCreature implements IAdvancedNpc, IFactionObject +{ + protected Random random = new Random(); + + /* FACTION STUFF */ + protected FactionInstance faction; + protected String factionName = "NEUTRIAL"; + + /* CHARACTER STUFF */ + protected String humanName = "NPC"; + protected boolean female; + protected int[] stats; + + public EntityNpc(World world) + { + super(world); + this.stats = MathHelper.generateRandomIntArray(random, 100, 8); + this.female = random.nextBoolean(); + } + + /** + * @param stats - Strength, endurance, dexterity, Intelligence, wit, memory, willpower, + * perception, luck http://en.wikipedia.org/wiki/Attribute_(role-playing_games) + */ + public EntityNpc(World world, int... stats) + { + this(world); + this.stats = MathHelper.generateRandomIntArray(random, 100, 8); + for (int i = 0; i < stats.length && i < stats.length; i++) + { + if (stats[i] != -1) + { + this.stats[i] = stats[i]; + } + } + } + + /** + * Gets the value of the stat + */ + public int getStat(CharStats stat) + { + if (this.stats == null) + { + this.stats = MathHelper.generateRandomIntArray(random, 100, 8); + } + return stat.ordinal() < this.stats.length ? this.stats[stat.ordinal()] : 10; + + } + + @Override + public int getMaxHealth() + { + return 10 + this.getStat(CharStats.endurance); + } + + @Override + public FactionInstance getFaction() + { + if(this.faction == null) + { + this.faction = FactionManager.loadFaction(this.factionName); + } + return this.faction; + } + + @Override + public String getName() + { + return humanName; + } + + @Override + public void writeEntityToNBT(NBTTagCompound nbt) + { + super.writeEntityToNBT(nbt); + nbt.setString("humanName", this.humanName); + nbt.setString("factionName", this.faction != null ? this.faction.name : "NEUTRIAL"); + } + + @Override + public void readEntityFromNBT(NBTTagCompound nbt) + { + super.readEntityFromNBT(nbt); + this.humanName = nbt.getString("humanName"); + this.factionName = nbt.getString("factionName"); + } + + @Override + public FactionInstance getFactinon() + { + if (this.faction == null || this.faction.isInvalid()) + { + this.faction = FactionManager.loadFaction(this.factionName); + } + return this.faction != null ? this.faction : FactionManager.NEUTRIAL; + } + + @Override + public boolean setFaction(FactionInstance faction, boolean override) + { + if (override || this.faction == null || this.faction.isInvalid()) + { + this.faction = faction; + return true; + } + return false; + } + +} diff --git a/src/minecraft/dark/library/math/MathHelper.java b/src/minecraft/dark/library/math/MathHelper.java new file mode 100644 index 000000000..c3a6c86e3 --- /dev/null +++ b/src/minecraft/dark/library/math/MathHelper.java @@ -0,0 +1,47 @@ +package dark.library.math; + +import java.util.Random; + +public class MathHelper +{ + /** + * Generates an array of random numbers + * + * @param random - random instance to be used + * @param maxNumber - max size of the int to use + * @param arraySize - length of the array + * @return array of random numbers + */ + public static int[] generateRandomIntArray(Random random, int maxNumber, int arraySize) + { + return MathHelper.generateRandomIntArray(random, 0, maxNumber, arraySize); + } + + /** + * Generates an array of random numbers + * + * @param random - random instance to be used + * @param minNumber - smallest random Integer to use. Warning can lead to longer than normal + * delay in returns + * @param maxNumber - max size of the int to use + * @param arraySize - length of the array + * @return array of random numbers + */ + public static int[] generateRandomIntArray(Random random, int minNumber, int maxNumber, int arraySize) + { + int[] array = new int[arraySize]; + for (int i = 0; i < array.length; i++) + { + int number = random.nextInt(maxNumber); + if (minNumber != 0) + { + while (number < minNumber) + { + number = random.nextInt(maxNumber); + } + } + array[i] = number; + } + return array; + } +} diff --git a/src/minecraft/dark/library/npc/IAdvancedNpc.java b/src/minecraft/dark/library/npc/IAdvancedNpc.java index a09b57ca7..1dc94f128 100644 --- a/src/minecraft/dark/library/npc/IAdvancedNpc.java +++ b/src/minecraft/dark/library/npc/IAdvancedNpc.java @@ -1,6 +1,6 @@ package dark.library.npc; -import dark.library.team.FactionInstance; +import dark.faction.core.FactionInstance; import net.minecraft.entity.INpc; public interface IAdvancedNpc extends INpc diff --git a/src/minecraft/dark/library/npc/prefab/EntityNpc.java b/src/minecraft/dark/library/npc/prefab/EntityNpc.java deleted file mode 100644 index fe6db27d1..000000000 --- a/src/minecraft/dark/library/npc/prefab/EntityNpc.java +++ /dev/null @@ -1,54 +0,0 @@ -package dark.library.npc.prefab; - -import net.minecraft.entity.EntityCreature; -import net.minecraft.entity.EntityLiving; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; -import dark.library.npc.IAdvancedNpc; -import dark.library.team.FactionInstance; - -public class EntityNpc extends EntityCreature implements IAdvancedNpc -{ - private FactionInstance faction; - private String humanName = ""; - - public EntityNpc(World par1World) - { - super(par1World); - } - - @Override - public int getMaxHealth() - { - return 20; - } - - @Override - public FactionInstance getFaction() - { - return this.faction; - } - - @Override - public String getName() - { - return humanName; - } - - @Override - public void writeEntityToNBT(NBTTagCompound nbt) - { - super.writeEntityToNBT(nbt); - nbt.setString("humanName", this.humanName); - nbt.setTag("faction", faction.write()); - } - - @Override - public void readEntityFromNBT(NBTTagCompound nbt) - { - super.readEntityFromNBT(nbt); - - - } - -}