2022-05-24 01:07:50 -05:00
|
|
|
package noppes.npcs.controllers.data;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2022-07-01 23:26:47 -05:00
|
|
|
import java.util.ArrayList;
|
2018-09-13 12:03:28 -04:00
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import noppes.npcs.NBTTags;
|
2022-05-24 01:07:50 -05:00
|
|
|
import noppes.npcs.controllers.FactionController;
|
|
|
|
|
import noppes.npcs.controllers.PlayerDataController;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
2022-11-15 15:25:53 -05:00
|
|
|
import noppes.npcs.api.handler.data.IFaction;
|
|
|
|
|
import noppes.npcs.api.entity.ICustomNpc;
|
|
|
|
|
import noppes.npcs.api.entity.IPlayer;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2022-01-10 15:21:48 -06:00
|
|
|
public class Faction implements IFaction {
|
2018-09-13 12:03:28 -04:00
|
|
|
public String name = "";
|
|
|
|
|
public int color = Integer.parseInt("FF00", 16);
|
|
|
|
|
|
|
|
|
|
public HashSet<Integer> attackFactions;
|
|
|
|
|
public int id = -1;
|
|
|
|
|
|
|
|
|
|
public int neutralPoints = 500;
|
|
|
|
|
public int friendlyPoints = 1500;
|
|
|
|
|
|
|
|
|
|
public int defaultPoints = 1000;
|
|
|
|
|
|
|
|
|
|
public boolean hideFaction = false;
|
|
|
|
|
public boolean getsAttacked = false;
|
|
|
|
|
|
|
|
|
|
public Faction(){
|
|
|
|
|
attackFactions = new HashSet<Integer>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Faction(int id, String name,int color, int defaultPoints){
|
|
|
|
|
this.name = name;
|
|
|
|
|
this.color = color;
|
|
|
|
|
this.defaultPoints = defaultPoints;
|
|
|
|
|
this.id = id;
|
|
|
|
|
attackFactions = new HashSet<Integer>();
|
|
|
|
|
}
|
|
|
|
|
public static String formatName(String name){
|
|
|
|
|
name = name.toLowerCase().trim();
|
|
|
|
|
return name.substring(0, 1).toUpperCase() + name.substring(1);
|
|
|
|
|
}
|
|
|
|
|
public void readNBT(NBTTagCompound compound){
|
|
|
|
|
name = compound.getString("Name");
|
|
|
|
|
color = compound.getInteger("Color");
|
|
|
|
|
id = compound.getInteger("Slot");
|
|
|
|
|
|
|
|
|
|
neutralPoints= compound.getInteger("NeutralPoints");
|
|
|
|
|
friendlyPoints = compound.getInteger("FriendlyPoints");
|
|
|
|
|
defaultPoints = compound.getInteger("DefaultPoints");
|
|
|
|
|
|
|
|
|
|
hideFaction = compound.getBoolean("HideFaction");
|
|
|
|
|
getsAttacked = compound.getBoolean("GetsAttacked");
|
|
|
|
|
|
|
|
|
|
attackFactions = NBTTags.getIntegerSet(compound.getTagList("AttackFactions", 10));
|
|
|
|
|
}
|
|
|
|
|
public void writeNBT(NBTTagCompound compound){
|
|
|
|
|
compound.setInteger("Slot", id);
|
|
|
|
|
compound.setString("Name", name);
|
|
|
|
|
compound.setInteger("Color", color);
|
|
|
|
|
|
|
|
|
|
compound.setInteger("NeutralPoints", neutralPoints);
|
|
|
|
|
compound.setInteger("FriendlyPoints", friendlyPoints);
|
|
|
|
|
compound.setInteger("DefaultPoints", defaultPoints);
|
|
|
|
|
|
|
|
|
|
compound.setBoolean("HideFaction", hideFaction);
|
|
|
|
|
compound.setBoolean("GetsAttacked", getsAttacked);
|
|
|
|
|
|
|
|
|
|
compound.setTag("AttackFactions", NBTTags.nbtIntegerSet(attackFactions));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isFriendlyToPlayer(EntityPlayer player) {
|
2022-05-24 01:07:50 -05:00
|
|
|
PlayerFactionData data = PlayerDataController.instance.getPlayerData(player).factionData;
|
2018-09-13 12:03:28 -04:00
|
|
|
return data.getFactionPoints(id) >= friendlyPoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isAggressiveToPlayer(EntityPlayer player) {
|
|
|
|
|
PlayerFactionData data = PlayerDataController.instance.getPlayerData(player).factionData;
|
|
|
|
|
return data.getFactionPoints(id) < neutralPoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isNeutralToPlayer(EntityPlayer player) {
|
|
|
|
|
PlayerFactionData data = PlayerDataController.instance.getPlayerData(player).factionData;
|
|
|
|
|
int points = data.getFactionPoints(id);
|
|
|
|
|
return points >= neutralPoints && points < friendlyPoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isAggressiveToNpc(EntityNPCInterface entity) {
|
|
|
|
|
return attackFactions.contains(entity.faction.id);
|
|
|
|
|
}
|
2022-01-10 15:21:48 -06:00
|
|
|
|
|
|
|
|
public int getId() {
|
|
|
|
|
return this.id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
|
return this.name;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 23:26:47 -05:00
|
|
|
public void setName(String name) { this.name = name; }
|
|
|
|
|
|
|
|
|
|
public void setDefaultPoints(int points) {
|
|
|
|
|
this.defaultPoints = points;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 15:21:48 -06:00
|
|
|
public int getDefaultPoints() {
|
|
|
|
|
return this.defaultPoints;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 23:26:47 -05:00
|
|
|
public void setFriendlyPoints(int points) {
|
|
|
|
|
this.friendlyPoints = points;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getFriendlyPoints() {
|
|
|
|
|
return this.friendlyPoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setNeutralPoints(int points) {
|
|
|
|
|
this.neutralPoints = points;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNeutralPoints() {
|
|
|
|
|
return this.neutralPoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setColor(int color) { this.color = color; }
|
|
|
|
|
|
2022-01-10 15:21:48 -06:00
|
|
|
public int getColor() {
|
|
|
|
|
return this.color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int playerStatus(IPlayer player) {
|
|
|
|
|
PlayerFactionData data = PlayerData.get((EntityPlayer) player.getMCEntity()).factionData;
|
|
|
|
|
int points = data.getFactionPoints(this.id);
|
|
|
|
|
if (points >= this.friendlyPoints) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return points < this.neutralPoints ? -1 : 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 23:26:47 -05:00
|
|
|
public boolean isAggressiveToNpc(ICustomNpc npc) {
|
2022-01-10 15:21:48 -06:00
|
|
|
return this.attackFactions.contains(npc.getFaction().getId());
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 23:26:47 -05:00
|
|
|
public boolean isEnemyFaction(IFaction faction) {
|
|
|
|
|
return this.attackFactions.contains(faction.getId());
|
2022-01-10 15:21:48 -06:00
|
|
|
}
|
|
|
|
|
|
2022-07-01 23:26:47 -05:00
|
|
|
public IFaction[] getEnemyFactions() {
|
|
|
|
|
ArrayList<IFaction> enemyFactions = new ArrayList<>();
|
2022-01-10 15:21:48 -06:00
|
|
|
|
2022-07-01 23:26:47 -05:00
|
|
|
for (int id : this.attackFactions) {
|
|
|
|
|
enemyFactions.add(FactionController.getInstance().get(id));
|
2022-01-10 15:21:48 -06:00
|
|
|
}
|
|
|
|
|
|
2022-07-01 23:26:47 -05:00
|
|
|
return enemyFactions.toArray(new IFaction[]{});
|
2022-01-10 15:21:48 -06:00
|
|
|
}
|
|
|
|
|
|
2022-07-01 23:26:47 -05:00
|
|
|
public void addEnemyFaction(IFaction faction) {
|
2022-07-07 01:15:22 -05:00
|
|
|
this.attackFactions.add(faction.getId());
|
2022-01-10 15:21:48 -06:00
|
|
|
}
|
|
|
|
|
|
2022-07-01 23:26:47 -05:00
|
|
|
public void removeEnemyFaction(IFaction faction) {
|
|
|
|
|
this.attackFactions.remove(faction.getId());
|
2022-01-10 15:21:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getIsHidden() {
|
|
|
|
|
return this.hideFaction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setIsHidden(boolean bo) {
|
|
|
|
|
this.hideFaction = bo;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 23:26:47 -05:00
|
|
|
public boolean attackedByMobs() {
|
2022-01-10 15:21:48 -06:00
|
|
|
return this.getsAttacked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setAttackedByMobs(boolean bo) {
|
|
|
|
|
this.getsAttacked = bo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void save() {
|
|
|
|
|
FactionController.getInstance().saveFaction(this);
|
|
|
|
|
}
|
2022-07-01 23:26:47 -05:00
|
|
|
|
|
|
|
|
public boolean isFriendlyToPlayer(IPlayer player) {
|
|
|
|
|
return this.isFriendlyToPlayer((EntityPlayer) player.getMCEntity());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isNeutralToPlayer(IPlayer player) {
|
|
|
|
|
return this.isNeutralToPlayer((EntityPlayer) player.getMCEntity());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isAggressiveToPlayer(IPlayer player) {
|
|
|
|
|
return this.isAggressiveToPlayer((EntityPlayer) player.getMCEntity());
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|