mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 22:42:19 +00:00
Proper Reformating
This commit is contained in:
1 parent
ce75880aba
commit
180d257024
1179 files changed
+59847
-61583
No files matched your search
@@ -15,230 +15,235 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class JobConversation extends JobInterface{
|
||||
public Availability availability = new Availability();
|
||||
public class JobConversation extends JobInterface {
|
||||
public Availability availability = new Availability();
|
||||
|
||||
private ArrayList<String> names = new ArrayList<String>();
|
||||
private HashMap<String, EntityNPCInterface> npcs = new HashMap<String, EntityNPCInterface>();
|
||||
|
||||
public HashMap<Integer,ConversationLine> lines = new HashMap<Integer,ConversationLine>();
|
||||
private ArrayList<String> names = new ArrayList<String>();
|
||||
private HashMap<String, EntityNPCInterface> npcs = new HashMap<String, EntityNPCInterface>();
|
||||
|
||||
public int quest = -1;
|
||||
public String questTitle = "";
|
||||
public int generalDelay = 400;
|
||||
public int ticks = 100;
|
||||
public int range = 20;
|
||||
|
||||
private ConversationLine nextLine;
|
||||
|
||||
private boolean hasStarted = false;
|
||||
private int startedTicks = 20;
|
||||
public int mode = 0; //0:Always, 1:Player near
|
||||
public HashMap<Integer, ConversationLine> lines = new HashMap<Integer, ConversationLine>();
|
||||
|
||||
public JobConversation(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
}
|
||||
public int quest = -1;
|
||||
public String questTitle = "";
|
||||
public int generalDelay = 400;
|
||||
public int ticks = 100;
|
||||
public int range = 20;
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setTag("ConversationAvailability", availability.writeToNBT(new NBTTagCompound()));
|
||||
compound.setInteger("ConversationQuest", quest);
|
||||
compound.setInteger("ConversationDelay", generalDelay);
|
||||
compound.setInteger("ConversationRange", range);
|
||||
compound.setInteger("ConversationMode", mode);
|
||||
private ConversationLine nextLine;
|
||||
|
||||
private boolean hasStarted = false;
|
||||
private int startedTicks = 20;
|
||||
public int mode = 0; //0:Always, 1:Player near
|
||||
|
||||
public JobConversation(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setTag("ConversationAvailability", availability.writeToNBT(new NBTTagCompound()));
|
||||
compound.setInteger("ConversationQuest", quest);
|
||||
compound.setInteger("ConversationDelay", generalDelay);
|
||||
compound.setInteger("ConversationRange", range);
|
||||
compound.setInteger("ConversationMode", mode);
|
||||
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
for(int slot : lines.keySet()){
|
||||
ConversationLine line = lines.get(slot);
|
||||
for (int slot : lines.keySet()) {
|
||||
ConversationLine line = lines.get(slot);
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.setInteger("Slot", slot);
|
||||
line.writeEntityToNBT(nbttagcompound);
|
||||
|
||||
|
||||
nbttaglist.appendTag(nbttagcompound);
|
||||
}
|
||||
|
||||
compound.setTag("ConversationLines", nbttaglist);
|
||||
if(hasQuest())
|
||||
compound.setString("ConversationQuestTitle", getQuest().title);
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
names.clear();
|
||||
availability.readFromNBT(compound.getCompoundTag("ConversationAvailability"));
|
||||
quest = compound.getInteger("ConversationQuest");
|
||||
generalDelay = compound.getInteger("ConversationDelay");
|
||||
questTitle = compound.getString("ConversationQuestTitle");
|
||||
range = compound.getInteger("ConversationRange");
|
||||
mode = compound.getInteger("ConversationMode");
|
||||
compound.setTag("ConversationLines", nbttaglist);
|
||||
if (hasQuest())
|
||||
compound.setString("ConversationQuestTitle", getQuest().title);
|
||||
|
||||
NBTTagList nbttaglist = compound.getTagList("ConversationLines", 10);
|
||||
HashMap<Integer, ConversationLine> map = new HashMap<Integer, ConversationLine>();
|
||||
for(int i = 0; i < nbttaglist.tagCount(); i++){
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
names.clear();
|
||||
availability.readFromNBT(compound.getCompoundTag("ConversationAvailability"));
|
||||
quest = compound.getInteger("ConversationQuest");
|
||||
generalDelay = compound.getInteger("ConversationDelay");
|
||||
questTitle = compound.getString("ConversationQuestTitle");
|
||||
range = compound.getInteger("ConversationRange");
|
||||
mode = compound.getInteger("ConversationMode");
|
||||
|
||||
NBTTagList nbttaglist = compound.getTagList("ConversationLines", 10);
|
||||
HashMap<Integer, ConversationLine> map = new HashMap<Integer, ConversationLine>();
|
||||
for (int i = 0; i < nbttaglist.tagCount(); i++) {
|
||||
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
|
||||
ConversationLine line = new ConversationLine();
|
||||
line.readEntityFromNBT(nbttagcompound);
|
||||
if(!line.npc.isEmpty() && !names.contains(line.npc.toLowerCase()))
|
||||
names.add(line.npc.toLowerCase());
|
||||
|
||||
if (!line.npc.isEmpty() && !names.contains(line.npc.toLowerCase()))
|
||||
names.add(line.npc.toLowerCase());
|
||||
|
||||
map.put(nbttagcompound.getInteger("Slot"), line);
|
||||
}
|
||||
lines = map;
|
||||
ticks = generalDelay;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasQuest() {
|
||||
return getQuest() != null;
|
||||
}
|
||||
public Quest getQuest() {
|
||||
if(npc.isRemote())
|
||||
return null;
|
||||
return QuestController.Instance.quests.get(quest);
|
||||
}
|
||||
@Override
|
||||
public void aiUpdateTask() {
|
||||
ticks--;
|
||||
if(ticks > 0 || nextLine == null)
|
||||
return;
|
||||
say(nextLine);
|
||||
boolean seenNext = false;
|
||||
ConversationLine compare = nextLine;
|
||||
nextLine = null;
|
||||
for(ConversationLine line : lines.values()){
|
||||
if(line.isEmpty())
|
||||
continue;
|
||||
if(seenNext){
|
||||
nextLine = line;
|
||||
break;
|
||||
}
|
||||
if(line == compare){
|
||||
seenNext = true;
|
||||
}
|
||||
}
|
||||
if(nextLine != null)
|
||||
ticks = nextLine.delay;
|
||||
else if(hasQuest()){
|
||||
List<EntityPlayer> inRange = npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class, npc.boundingBox.expand(range, range, range));
|
||||
public boolean hasQuest() {
|
||||
return getQuest() != null;
|
||||
}
|
||||
|
||||
for (EntityPlayer player : inRange){
|
||||
if(availability.isAvailable(player))
|
||||
PlayerQuestController.addActiveQuest(new QuestData(getQuest()), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Quest getQuest() {
|
||||
if (npc.isRemote())
|
||||
return null;
|
||||
return QuestController.Instance.quests.get(quest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean aiShouldExecute() {
|
||||
if(lines.isEmpty() || npc.isKilled() || npc.isAttacking() || !shouldRun())
|
||||
return false;
|
||||
if(!hasStarted && mode == 1){
|
||||
if(startedTicks-- > 0)
|
||||
return false;
|
||||
startedTicks = 10;
|
||||
if(npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class, npc.boundingBox.expand(range, range, range)).isEmpty()){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for(ConversationLine line : lines.values()){
|
||||
if(line == null || line.isEmpty())
|
||||
continue;
|
||||
nextLine = line;
|
||||
break;
|
||||
}
|
||||
return nextLine != null;
|
||||
}
|
||||
@Override
|
||||
public void aiUpdateTask() {
|
||||
ticks--;
|
||||
if (ticks > 0 || nextLine == null)
|
||||
return;
|
||||
say(nextLine);
|
||||
boolean seenNext = false;
|
||||
ConversationLine compare = nextLine;
|
||||
nextLine = null;
|
||||
for (ConversationLine line : lines.values()) {
|
||||
if (line.isEmpty())
|
||||
continue;
|
||||
if (seenNext) {
|
||||
nextLine = line;
|
||||
break;
|
||||
}
|
||||
if (line == compare) {
|
||||
seenNext = true;
|
||||
}
|
||||
}
|
||||
if (nextLine != null)
|
||||
ticks = nextLine.delay;
|
||||
else if (hasQuest()) {
|
||||
List<EntityPlayer> inRange = npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class, npc.boundingBox.expand(range, range, range));
|
||||
|
||||
private boolean shouldRun() {
|
||||
ticks--;
|
||||
if(ticks > 0)
|
||||
return false;
|
||||
npcs.clear();
|
||||
List<EntityNPCInterface> list = npc.worldObj.getEntitiesWithinAABB(EntityNPCInterface.class, npc.boundingBox.expand(10, 10, 10));
|
||||
for(EntityNPCInterface npc : list){
|
||||
if(!npc.isKilled() && !npc.isAttacking() && names.contains(npc.getCommandSenderName().toLowerCase()))
|
||||
npcs.put(npc.getCommandSenderName().toLowerCase(), npc);
|
||||
}
|
||||
boolean bo = names.size() == npcs.size();
|
||||
if(!bo)
|
||||
ticks = 20;
|
||||
return bo;
|
||||
}
|
||||
for (EntityPlayer player : inRange) {
|
||||
if (availability.isAvailable(player))
|
||||
PlayerQuestController.addActiveQuest(new QuestData(getQuest()), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean aiContinueExecute() {
|
||||
for(EntityNPCInterface npc : npcs.values()){
|
||||
if(npc.isKilled() || npc.isAttacking())
|
||||
return false;
|
||||
}
|
||||
return nextLine != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTask() {
|
||||
nextLine = null;
|
||||
ticks = generalDelay;
|
||||
hasStarted = false;
|
||||
}
|
||||
@Override
|
||||
public boolean aiShouldExecute() {
|
||||
if (lines.isEmpty() || npc.isKilled() || npc.isAttacking() || !shouldRun())
|
||||
return false;
|
||||
if (!hasStarted && mode == 1) {
|
||||
if (startedTicks-- > 0)
|
||||
return false;
|
||||
startedTicks = 10;
|
||||
if (npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class, npc.boundingBox.expand(range, range, range)).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void aiStartExecuting() {
|
||||
startedTicks = 20;
|
||||
hasStarted = true;
|
||||
}
|
||||
|
||||
private void say(ConversationLine line) {
|
||||
List<EntityPlayer> inRange = npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class, npc.boundingBox.expand(range, range, range));
|
||||
for (ConversationLine line : lines.values()) {
|
||||
if (line == null || line.isEmpty())
|
||||
continue;
|
||||
nextLine = line;
|
||||
break;
|
||||
}
|
||||
return nextLine != null;
|
||||
}
|
||||
|
||||
EntityNPCInterface npc = npcs.get(line.npc.toLowerCase());
|
||||
if(npc == null)
|
||||
return;
|
||||
for (EntityPlayer player : inRange){
|
||||
if(availability.isAvailable(player))
|
||||
npc.say(player, line);
|
||||
}
|
||||
}
|
||||
private boolean shouldRun() {
|
||||
ticks--;
|
||||
if (ticks > 0)
|
||||
return false;
|
||||
npcs.clear();
|
||||
List<EntityNPCInterface> list = npc.worldObj.getEntitiesWithinAABB(EntityNPCInterface.class, npc.boundingBox.expand(10, 10, 10));
|
||||
for (EntityNPCInterface npc : list) {
|
||||
if (!npc.isKilled() && !npc.isAttacking() && names.contains(npc.getCommandSenderName().toLowerCase()))
|
||||
npcs.put(npc.getCommandSenderName().toLowerCase(), npc);
|
||||
}
|
||||
boolean bo = names.size() == npcs.size();
|
||||
if (!bo)
|
||||
ticks = 20;
|
||||
return bo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
hasStarted = false;
|
||||
resetTask();
|
||||
ticks = 60;
|
||||
}
|
||||
@Override
|
||||
public void killed() {
|
||||
reset();
|
||||
}
|
||||
public class ConversationLine extends Line{
|
||||
public String npc = "";
|
||||
public int delay = 40;
|
||||
|
||||
public void writeEntityToNBT(NBTTagCompound compound) {
|
||||
compound.setString("Line", text);
|
||||
compound.setString("Npc", npc);
|
||||
compound.setString("Sound", sound);
|
||||
compound.setInteger("Delay", delay);
|
||||
}
|
||||
@Override
|
||||
public boolean aiContinueExecute() {
|
||||
for (EntityNPCInterface npc : npcs.values()) {
|
||||
if (npc.isKilled() || npc.isAttacking())
|
||||
return false;
|
||||
}
|
||||
return nextLine != null;
|
||||
}
|
||||
|
||||
public void readEntityFromNBT(NBTTagCompound compound) {
|
||||
text = compound.getString("Line");
|
||||
npc = compound.getString("Npc");
|
||||
sound = compound.getString("Sound");
|
||||
delay = compound.getInteger("Delay");
|
||||
}
|
||||
|
||||
public boolean isEmpty(){
|
||||
return npc.isEmpty() || text.isEmpty();
|
||||
}
|
||||
}
|
||||
public ConversationLine getLine(int slot) {
|
||||
if(lines.containsKey(slot))
|
||||
return lines.get(slot);
|
||||
ConversationLine line = new ConversationLine();
|
||||
lines.put(slot, line);
|
||||
return line;
|
||||
}
|
||||
@Override
|
||||
public void resetTask() {
|
||||
nextLine = null;
|
||||
ticks = generalDelay;
|
||||
hasStarted = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void aiStartExecuting() {
|
||||
startedTicks = 20;
|
||||
hasStarted = true;
|
||||
}
|
||||
|
||||
private void say(ConversationLine line) {
|
||||
List<EntityPlayer> inRange = npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class, npc.boundingBox.expand(range, range, range));
|
||||
|
||||
EntityNPCInterface npc = npcs.get(line.npc.toLowerCase());
|
||||
if (npc == null)
|
||||
return;
|
||||
for (EntityPlayer player : inRange) {
|
||||
if (availability.isAvailable(player))
|
||||
npc.say(player, line);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
hasStarted = false;
|
||||
resetTask();
|
||||
ticks = 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void killed() {
|
||||
reset();
|
||||
}
|
||||
|
||||
public class ConversationLine extends Line {
|
||||
public String npc = "";
|
||||
public int delay = 40;
|
||||
|
||||
public void writeEntityToNBT(NBTTagCompound compound) {
|
||||
compound.setString("Line", text);
|
||||
compound.setString("Npc", npc);
|
||||
compound.setString("Sound", sound);
|
||||
compound.setInteger("Delay", delay);
|
||||
}
|
||||
|
||||
public void readEntityFromNBT(NBTTagCompound compound) {
|
||||
text = compound.getString("Line");
|
||||
npc = compound.getString("Npc");
|
||||
sound = compound.getString("Sound");
|
||||
delay = compound.getInteger("Delay");
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return npc.isEmpty() || text.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public ConversationLine getLine(int slot) {
|
||||
if (lines.containsKey(slot))
|
||||
return lines.get(slot);
|
||||
ConversationLine line = new ConversationLine();
|
||||
lines.put(slot, line);
|
||||
return line;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user