2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
|
|
|
|
import noppes.npcs.constants.EnumJobType;
|
|
|
|
|
import noppes.npcs.constants.EnumRoleType;
|
2022-06-12 01:26:23 -05:00
|
|
|
import noppes.npcs.controllers.GlobalDataController;
|
2022-05-24 01:07:50 -05:00
|
|
|
import noppes.npcs.controllers.data.DialogOption;
|
|
|
|
|
import noppes.npcs.controllers.data.FactionOptions;
|
|
|
|
|
import noppes.npcs.controllers.data.Line;
|
|
|
|
|
import noppes.npcs.controllers.data.Lines;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
|
|
|
|
import noppes.npcs.roles.JobBard;
|
|
|
|
|
import noppes.npcs.roles.JobChunkLoader;
|
|
|
|
|
import noppes.npcs.roles.JobConversation;
|
|
|
|
|
import noppes.npcs.roles.JobFollower;
|
|
|
|
|
import noppes.npcs.roles.JobGuard;
|
|
|
|
|
import noppes.npcs.roles.JobHealer;
|
|
|
|
|
import noppes.npcs.roles.JobItemGiver;
|
|
|
|
|
import noppes.npcs.roles.JobSpawner;
|
|
|
|
|
import noppes.npcs.roles.RoleBank;
|
|
|
|
|
import noppes.npcs.roles.RoleCompanion;
|
|
|
|
|
import noppes.npcs.roles.RoleFollower;
|
|
|
|
|
import noppes.npcs.roles.RolePostman;
|
|
|
|
|
import noppes.npcs.roles.RoleTrader;
|
|
|
|
|
import noppes.npcs.roles.RoleTransporter;
|
|
|
|
|
|
|
|
|
|
public class DataAdvanced {
|
|
|
|
|
|
|
|
|
|
public Lines interactLines = new Lines();
|
|
|
|
|
public Lines worldLines = new Lines();
|
|
|
|
|
public Lines attackLines = new Lines();
|
|
|
|
|
public Lines killedLines = new Lines();
|
|
|
|
|
public Lines killLines = new Lines();
|
|
|
|
|
|
|
|
|
|
public boolean orderedLines = false;
|
|
|
|
|
|
|
|
|
|
public String idleSound = "";
|
|
|
|
|
public String angrySound = "";
|
|
|
|
|
public String hurtSound = "minecraft:game.player.hurt";
|
|
|
|
|
public String deathSound = "minecraft:game.player.hurt";
|
|
|
|
|
public String stepSound = "";
|
|
|
|
|
|
|
|
|
|
private EntityNPCInterface npc;
|
|
|
|
|
public FactionOptions factions = new FactionOptions();
|
|
|
|
|
|
|
|
|
|
public EnumRoleType role = EnumRoleType.None;
|
|
|
|
|
public EnumJobType job = EnumJobType.None;
|
|
|
|
|
|
|
|
|
|
public boolean attackOtherFactions = false;
|
|
|
|
|
public boolean defendFaction = false;
|
|
|
|
|
public boolean disablePitch = false;
|
2022-05-28 23:40:01 -05:00
|
|
|
|
2022-05-29 14:42:28 -05:00
|
|
|
public String soulStonePlayerName = "";
|
2022-06-07 12:31:49 -05:00
|
|
|
public boolean refuseSoulStone = false;
|
|
|
|
|
public boolean soulStoneInit = false;
|
2022-06-08 22:13:30 -05:00
|
|
|
public int minFactionPointsToSoulStone = -1;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
public DataAdvanced(EntityNPCInterface npc) {
|
|
|
|
|
this.npc = npc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
|
|
|
|
compound.setTag("NpcLines", worldLines.writeToNBT());
|
|
|
|
|
compound.setTag("NpcKilledLines", killedLines.writeToNBT());
|
|
|
|
|
compound.setTag("NpcInteractLines", interactLines.writeToNBT());
|
|
|
|
|
compound.setTag("NpcAttackLines", attackLines.writeToNBT());
|
|
|
|
|
compound.setTag("NpcKillLines", killLines.writeToNBT());
|
|
|
|
|
|
|
|
|
|
compound.setString("NpcIdleSound", idleSound);
|
|
|
|
|
compound.setString("NpcAngrySound", angrySound);
|
|
|
|
|
compound.setString("NpcHurtSound", hurtSound);
|
|
|
|
|
compound.setString("NpcDeathSound", deathSound);
|
|
|
|
|
compound.setString("NpcStepSound", stepSound);
|
|
|
|
|
|
|
|
|
|
compound.setBoolean("OrderedLines", orderedLines);
|
|
|
|
|
|
|
|
|
|
compound.setInteger("FactionID", npc.getFaction().id);
|
|
|
|
|
compound.setBoolean("AttackOtherFactions", attackOtherFactions);
|
|
|
|
|
compound.setBoolean("DefendFaction", defendFaction);
|
|
|
|
|
compound.setBoolean("DisablePitch", disablePitch);
|
|
|
|
|
|
|
|
|
|
compound.setInteger("Role", role.ordinal());
|
|
|
|
|
compound.setInteger("NpcJob", job.ordinal());
|
|
|
|
|
compound.setTag("FactionPoints", factions.writeToNBT(new NBTTagCompound()));
|
|
|
|
|
|
|
|
|
|
compound.setTag("NPCDialogOptions", nbtDialogs(npc.dialogs));
|
|
|
|
|
|
2022-05-29 02:46:24 -05:00
|
|
|
compound.setBoolean("RefuseSoulStone", refuseSoulStone);
|
2022-05-28 23:40:01 -05:00
|
|
|
compound.setString("SoulStonePlayerName", soulStonePlayerName);
|
2022-06-08 22:13:30 -05:00
|
|
|
compound.setInteger("MinFactionPointsToSoulStone", minFactionPointsToSoulStone);
|
2022-05-28 23:40:01 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void readToNBT(NBTTagCompound compound) {
|
|
|
|
|
interactLines.readNBT(compound.getCompoundTag("NpcInteractLines"));
|
|
|
|
|
worldLines.readNBT(compound.getCompoundTag("NpcLines"));
|
|
|
|
|
attackLines.readNBT(compound.getCompoundTag("NpcAttackLines"));
|
|
|
|
|
killedLines.readNBT(compound.getCompoundTag("NpcKilledLines"));
|
|
|
|
|
killLines.readNBT(compound.getCompoundTag("NpcKillLines"));
|
|
|
|
|
|
|
|
|
|
idleSound = compound.getString("NpcIdleSound");
|
|
|
|
|
angrySound = compound.getString("NpcAngrySound");
|
|
|
|
|
hurtSound = compound.getString("NpcHurtSound");
|
|
|
|
|
deathSound = compound.getString("NpcDeathSound");
|
|
|
|
|
stepSound = compound.getString("NpcStepSound");
|
|
|
|
|
|
|
|
|
|
orderedLines = compound.getBoolean("OrderedLines");
|
|
|
|
|
|
|
|
|
|
npc.setFaction(compound.getInteger("FactionID"));
|
|
|
|
|
npc.faction = npc.getFaction();
|
|
|
|
|
attackOtherFactions = compound.getBoolean("AttackOtherFactions");
|
|
|
|
|
defendFaction = compound.getBoolean("DefendFaction");
|
|
|
|
|
disablePitch = compound.getBoolean("DisablePitch");
|
|
|
|
|
|
|
|
|
|
setRole(compound.getInteger("Role"));
|
|
|
|
|
setJob(compound.getInteger("NpcJob"));
|
|
|
|
|
|
|
|
|
|
factions.readFromNBT(compound.getCompoundTag("FactionPoints"));
|
|
|
|
|
|
|
|
|
|
npc.dialogs = getDialogs(compound.getTagList("NPCDialogOptions", 10));
|
2022-05-28 23:40:01 -05:00
|
|
|
|
2022-05-29 02:46:24 -05:00
|
|
|
refuseSoulStone = compound.getBoolean("RefuseSoulStone");
|
2022-05-28 23:40:01 -05:00
|
|
|
soulStonePlayerName = compound.getString("SoulStonePlayerName");
|
2022-06-08 22:13:30 -05:00
|
|
|
minFactionPointsToSoulStone = compound.getInteger("MinFactionPointsToSoulStone");
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private HashMap<Integer, DialogOption> getDialogs(NBTTagList tagList) {
|
|
|
|
|
HashMap<Integer, DialogOption> map = new HashMap<Integer, DialogOption>();
|
|
|
|
|
for (int i = 0; i < tagList.tagCount(); i++) {
|
|
|
|
|
NBTTagCompound nbttagcompound = tagList.getCompoundTagAt(i);
|
|
|
|
|
int slot = nbttagcompound.getInteger("DialogSlot");
|
|
|
|
|
DialogOption option = new DialogOption();
|
|
|
|
|
option.readNBT(nbttagcompound.getCompoundTag("NPCDialog"));
|
|
|
|
|
map.put(slot, option);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private NBTTagList nbtDialogs(HashMap<Integer, DialogOption> dialogs2) {
|
|
|
|
|
NBTTagList nbttaglist = new NBTTagList();
|
|
|
|
|
for (int slot : dialogs2.keySet()) {
|
|
|
|
|
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
|
|
|
|
nbttagcompound.setInteger("DialogSlot", slot);
|
|
|
|
|
nbttagcompound.setTag("NPCDialog", dialogs2.get(slot)
|
|
|
|
|
.writeNBT());
|
|
|
|
|
nbttaglist.appendTag(nbttagcompound);
|
|
|
|
|
}
|
|
|
|
|
return nbttaglist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Line getInteractLine() {
|
|
|
|
|
return interactLines.getLine(!orderedLines);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Line getAttackLine() {
|
|
|
|
|
return attackLines.getLine(!orderedLines);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Line getKilledLine() {
|
|
|
|
|
return killedLines.getLine(!orderedLines);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Line getKillLine() {
|
|
|
|
|
return killLines.getLine(!orderedLines);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Line getWorldLine() {
|
|
|
|
|
return worldLines.getLine(!orderedLines);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setRole(int i) {
|
|
|
|
|
if (EnumRoleType.values().length <= i) {
|
|
|
|
|
i -= 2;
|
|
|
|
|
}
|
|
|
|
|
role = EnumRoleType.values()[i];
|
|
|
|
|
if(role == EnumRoleType.None)
|
|
|
|
|
npc.roleInterface = null;
|
|
|
|
|
else if(role == EnumRoleType.Bank && !(npc.roleInterface instanceof RoleBank))
|
|
|
|
|
npc.roleInterface = new RoleBank(npc);
|
|
|
|
|
else if(role == EnumRoleType.Follower && !(npc.roleInterface instanceof RoleFollower))
|
|
|
|
|
npc.roleInterface = new RoleFollower(npc);
|
|
|
|
|
else if(role == EnumRoleType.Postman && !(npc.roleInterface instanceof RolePostman))
|
|
|
|
|
npc.roleInterface = new RolePostman(npc);
|
|
|
|
|
else if(role == EnumRoleType.Trader && !(npc.roleInterface instanceof RoleTrader))
|
|
|
|
|
npc.roleInterface = new RoleTrader(npc);
|
|
|
|
|
else if(role == EnumRoleType.Transporter && !(npc.roleInterface instanceof RoleTransporter))
|
|
|
|
|
npc.roleInterface = new RoleTransporter(npc);
|
|
|
|
|
else if(role == EnumRoleType.Companion && !(npc.roleInterface instanceof RoleCompanion))
|
|
|
|
|
npc.roleInterface = new RoleCompanion(npc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setJob(int i) {
|
|
|
|
|
if(npc.jobInterface != null && !npc.worldObj.isRemote)
|
|
|
|
|
npc.jobInterface.reset();
|
|
|
|
|
|
|
|
|
|
job = EnumJobType.values()[i % EnumJobType.values().length];
|
|
|
|
|
if (job == EnumJobType.None)
|
|
|
|
|
npc.jobInterface = null;
|
|
|
|
|
else if (job == EnumJobType.Bard && !(npc.jobInterface instanceof JobBard))
|
|
|
|
|
npc.jobInterface = new JobBard(npc);
|
|
|
|
|
else if (job == EnumJobType.Healer && !(npc.jobInterface instanceof JobHealer))
|
|
|
|
|
npc.jobInterface = new JobHealer(npc);
|
|
|
|
|
else if (job == EnumJobType.Guard && !(npc.jobInterface instanceof JobGuard))
|
|
|
|
|
npc.jobInterface = new JobGuard(npc);
|
2022-06-12 01:26:23 -05:00
|
|
|
else if (job == EnumJobType.ItemGiver && !(npc.jobInterface instanceof JobItemGiver)) {
|
|
|
|
|
if (!npc.isRemote()) {
|
|
|
|
|
if (npc.itemGiverId > 0 && GlobalDataController.instance.itemGivers.containsKey(npc.itemGiverId)) {
|
|
|
|
|
GlobalDataController.instance.itemGivers.get(npc.itemGiverId).npc = npc;
|
|
|
|
|
npc.jobInterface = GlobalDataController.instance.itemGivers.get(npc.itemGiverId);
|
|
|
|
|
} else {
|
|
|
|
|
npc.jobInterface = new JobItemGiver(npc);
|
|
|
|
|
if (npc.itemGiverId == -1) {
|
|
|
|
|
((JobItemGiver) npc.jobInterface).itemGiverId = GlobalDataController.instance.incrementItemGiverId();
|
|
|
|
|
} else {
|
|
|
|
|
((JobItemGiver) npc.jobInterface).itemGiverId = npc.itemGiverId;
|
|
|
|
|
}
|
|
|
|
|
GlobalDataController.instance.itemGivers.put(((JobItemGiver) npc.jobInterface).itemGiverId, (JobItemGiver) npc.jobInterface);
|
|
|
|
|
npc.itemGiverId = ((JobItemGiver) npc.jobInterface).itemGiverId;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
npc.jobInterface = new JobItemGiver(npc);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
else if (job == EnumJobType.Follower && !(npc.jobInterface instanceof JobFollower))
|
|
|
|
|
npc.jobInterface = new JobFollower(npc);
|
|
|
|
|
else if (job == EnumJobType.Spawner && !(npc.jobInterface instanceof JobSpawner))
|
|
|
|
|
npc.jobInterface = new JobSpawner(npc);
|
|
|
|
|
else if (job == EnumJobType.Conversation && !(npc.jobInterface instanceof JobConversation))
|
|
|
|
|
npc.jobInterface = new JobConversation(npc);
|
|
|
|
|
else if (job == EnumJobType.ChunkLoader && !(npc.jobInterface instanceof JobChunkLoader))
|
|
|
|
|
npc.jobInterface = new JobChunkLoader(npc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasWorldLines() {
|
|
|
|
|
return !worldLines.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
}
|