Worked on Factions and factions prefabs
This commit is contained in:
parent
86ad98a2fb
commit
92a0c5248f
9 changed files with 282 additions and 63 deletions
13
src/minecraft/dark/faction/api/IFactionObject.java
Normal file
13
src/minecraft/dark/faction/api/IFactionObject.java
Normal file
|
@ -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);
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package dark.faction.core;
|
||||||
|
|
||||||
|
public class FactionCreationEvent
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
package dark.library.team;
|
package dark.faction.core;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
@ -18,11 +19,11 @@ import dark.library.helpers.Time;
|
||||||
*/
|
*/
|
||||||
public class FactionInstance
|
public class FactionInstance
|
||||||
{
|
{
|
||||||
List<UserAccess> userList;
|
public List<UserAccess> userList;
|
||||||
String name;
|
public String name;
|
||||||
String creator;
|
public String creator;
|
||||||
String date = "unkown";
|
public String date = "unkown";
|
||||||
String prefix;
|
public String prefix;
|
||||||
|
|
||||||
public FactionInstance(String prefix, String name, String maker, Pair<String, Date> date)
|
public FactionInstance(String prefix, String name, String maker, Pair<String, Date> date)
|
||||||
{
|
{
|
||||||
|
@ -104,4 +105,20 @@ public class FactionInstance
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
48
src/minecraft/dark/faction/core/FactionManager.java
Normal file
48
src/minecraft/dark/faction/core/FactionManager.java
Normal file
|
@ -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<FactionInstance> cachedFactions = new ArrayList<FactionInstance>();
|
||||||
|
/* LIST OF CURRENTLY OR RECENTLY LOADED PLAYERS AND THERE FACTIONS */
|
||||||
|
public static HashMap<String, String> cachedAllegance = new HashMap<String, String>();
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
13
src/minecraft/dark/faction/entity/CharStats.java
Normal file
13
src/minecraft/dark/faction/entity/CharStats.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
129
src/minecraft/dark/faction/entity/EntityNpc.java
Normal file
129
src/minecraft/dark/faction/entity/EntityNpc.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
47
src/minecraft/dark/library/math/MathHelper.java
Normal file
47
src/minecraft/dark/library/math/MathHelper.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package dark.library.npc;
|
package dark.library.npc;
|
||||||
|
|
||||||
import dark.library.team.FactionInstance;
|
import dark.faction.core.FactionInstance;
|
||||||
import net.minecraft.entity.INpc;
|
import net.minecraft.entity.INpc;
|
||||||
|
|
||||||
public interface IAdvancedNpc extends INpc
|
public interface IAdvancedNpc extends INpc
|
||||||
|
|
|
@ -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);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue