From 73594e46c0ecd32c9a10992bbcf7a229b4b53d5c Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 6 Mar 2025 17:33:44 -0500 Subject: [PATCH] Passivity to Factions --- src/api | 2 +- .../gui/global/GuiNPCManageFactions.java | 332 +++++++++--------- .../noppes/npcs/controllers/data/Faction.java | 35 +- .../npcs/entity/EntityNPCInterface.java | 16 +- .../assets/customnpcs/lang/en_US.lang | 2 + 5 files changed, 207 insertions(+), 180 deletions(-) diff --git a/src/api b/src/api index a876b4d19..7d81fc13b 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit a876b4d191412dcd0738778ec38b8c6721c24aea +Subproject commit 7d81fc13b50bb6b4fac9f91184ea44cadfdc47a9 diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageFactions.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageFactions.java index 3a8c05c1a..6d1f7f9c5 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageFactions.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageFactions.java @@ -22,15 +22,15 @@ import java.util.*; public class GuiNPCManageFactions extends GuiNPCInterface2 implements IScrollData,ICustomScrollListener,ITextfieldListener, IGuiData, ISubGuiListener, GuiYesNoCallback { - private GuiCustomScroll scrollFactions; - private HashMap data = new HashMap(); - private Faction faction = new Faction(); - private String selected = null; - private String search = ""; + private GuiCustomScroll scrollFactions; + private HashMap data = new HashMap(); + private Faction faction = new Faction(); + private String selected = null; + private String search = ""; public GuiNPCManageFactions(EntityNPCInterface npc) { - super(npc); + super(npc); PacketClient.sendClient(new FactionsGetPacket()); } @@ -38,216 +38,228 @@ public class GuiNPCManageFactions extends GuiNPCInterface2 implements IScrollDat { super.initGui(); - this.addButton(new GuiNpcButton(0,guiLeft + 368, guiTop + 8, 45, 20, "gui.add")); - this.addButton(new GuiNpcButton(1,guiLeft + 368, guiTop + 32, 45, 20, "gui.remove")); + this.addButton(new GuiNpcButton(0,guiLeft + 368, guiTop + 8, 45, 20, "gui.add")); + this.addButton(new GuiNpcButton(1,guiLeft + 368, guiTop + 32, 45, 20, "gui.remove")); - if(scrollFactions == null){ - scrollFactions = new GuiCustomScroll(this,0, 0); - scrollFactions.setSize(143, 185); - } + if(scrollFactions == null){ + scrollFactions = new GuiCustomScroll(this,0, 0); + scrollFactions.setSize(143, 185); + } scrollFactions.guiLeft = guiLeft + 220; scrollFactions.guiTop = guiTop + 4; - addScroll(scrollFactions); - addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 220, guiTop + 4 + 3 + 185, 143, 20, search)); + addScroll(scrollFactions); + addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 220, guiTop + 4 + 3 + 185, 143, 20, search)); - if (faction.id == -1) - return; + if (faction.id == -1) + return; - this.addTextField(new GuiNpcTextField(0, this, guiLeft + 40, guiTop + 4, 136, 20, faction.name)); - getTextField(0).setMaxStringLength(20); - addLabel(new GuiNpcLabel(0,"gui.name", guiLeft + 8, guiTop + 9)); + this.addTextField(new GuiNpcTextField(0, this, guiLeft + 40, guiTop + 4, 136, 20, faction.name)); + getTextField(0).setMaxStringLength(20); + addLabel(new GuiNpcLabel(0,"gui.name", guiLeft + 8, guiTop + 9)); - addLabel(new GuiNpcLabel(10,"ID", guiLeft + 178, guiTop + 4)); - addLabel(new GuiNpcLabel(11, faction.id + "", guiLeft + 178, guiTop + 14)); + addLabel(new GuiNpcLabel(10,"ID", guiLeft + 178, guiTop + 4)); + addLabel(new GuiNpcLabel(11, faction.id + "", guiLeft + 178, guiTop + 14)); - String color = Integer.toHexString(faction.color); - while(color.length() < 6) - color = "0" + color; - addButton(new GuiNpcButton(10, guiLeft + 40, guiTop + 26, 60, 20, color)); - addLabel(new GuiNpcLabel(1,"gui.color", guiLeft + 8, guiTop + 31)); - getButton(10).setTextColor(faction.color); + String color = Integer.toHexString(faction.color); + while(color.length() < 6) + color = "0" + color; + addButton(new GuiNpcButton(10, guiLeft + 40, guiTop + 26, 60, 20, color)); + addLabel(new GuiNpcLabel(1,"gui.color", guiLeft + 8, guiTop + 31)); + getButton(10).setTextColor(faction.color); - addLabel(new GuiNpcLabel(2,"faction.points", guiLeft + 8, guiTop + 53)); - this.addButton(new GuiNpcButton(2,guiLeft + 100, guiTop + 48, 45, 20, "selectServer.edit")); + addLabel(new GuiNpcLabel(2,"faction.points", guiLeft + 105, guiTop + 31)); + this.addButton(new GuiNpcButton(2,guiLeft + 156, guiTop + 26, 45, 20, "selectServer.edit")); - addLabel(new GuiNpcLabel(3,"faction.hidden", guiLeft + 8, guiTop + 75)); - this.addButton(new GuiNpcButton(3,guiLeft + 100, guiTop + 70, 45, 20, new String[]{"gui.no","gui.yes"},faction.hideFaction?1:0)); + int y = guiTop + 48; + addLabel(new GuiNpcLabel(3,"faction.hidden", guiLeft + 8, y + 5)); + this.addButton(new GuiNpcButton(3,guiLeft + 100, y, 45, 20, new String[]{"gui.no","gui.yes"},faction.hideFaction?1:0)); - addLabel(new GuiNpcLabel(4,"faction.attacked", guiLeft + 8, guiTop + 97)); - this.addButton(new GuiNpcButton(4,guiLeft + 100, guiTop + 92, 45, 20, new String[]{"gui.no","gui.yes"},faction.getsAttacked?1:0)); + y += 23; - addLabel(new GuiNpcLabel(6,"faction.hostiles", guiLeft + 8, guiTop + 120)); + addLabel(new GuiNpcLabel(4,"faction.attacked", guiLeft + 8, y + 5)); + this.addButton(new GuiNpcButton(4,guiLeft + 100, y, 45, 20, new String[]{"gui.no","gui.yes"},faction.getsAttacked?1:0)); - ArrayList hostileList = new ArrayList(scrollFactions.getList()); - hostileList.remove(faction.name); + y += 23; - HashSet set = new HashSet(); - for(String s : data.keySet()){ - if(!s.equals(faction.name) && faction.attackFactions.contains(data.get(s))) - set.add(s); - } + addLabel(new GuiNpcLabel(5,"faction.passive", guiLeft + 8, y + 5)); + this.addButton(new GuiNpcButton(5,guiLeft + 100, y, 45, 20, new String[]{"gui.no","gui.yes"},faction.isPassive?1:0)); + getButton(5).setHoverText("faction.passive.hover"); - GuiCustomScroll scrollHostileFactions = new GuiCustomScroll(this,1,true); + addLabel(new GuiNpcLabel(6,"faction.hostiles", guiLeft + 8, guiTop + 120)); + + ArrayList hostileList = new ArrayList(scrollFactions.getList()); + hostileList.remove(faction.name); + + HashSet set = new HashSet(); + for(String s : data.keySet()){ + if(!s.equals(faction.name) && faction.attackFactions.contains(data.get(s))) + set.add(s); + } + + GuiCustomScroll scrollHostileFactions = new GuiCustomScroll(this,1,true); scrollHostileFactions.setSize(163, 78); scrollHostileFactions.guiLeft = guiLeft + 4; scrollHostileFactions.guiTop = guiTop + 134; - scrollHostileFactions.setList(hostileList); - scrollHostileFactions.setSelectedList(set); + scrollHostileFactions.setList(hostileList); + scrollHostileFactions.setSelectedList(set); addScroll(scrollHostileFactions); } @Override - protected void actionPerformed(GuiButton guibutton){ - GuiNpcButton button = (GuiNpcButton) guibutton; + protected void actionPerformed(GuiButton guibutton){ + GuiNpcButton button = (GuiNpcButton) guibutton; if(button.id == 0){ - save(); - String name = "New"; - while(data.containsKey(name)) - name += "_"; - Faction faction = new Faction(-1, name, 0x00FF00, 1000); + save(); + String name = "New"; + while(data.containsKey(name)) + name += "_"; + Faction faction = new Faction(-1, name, 0x00FF00, 1000); - NBTTagCompound compound = new NBTTagCompound(); - faction.writeNBT(compound); + NBTTagCompound compound = new NBTTagCompound(); + faction.writeNBT(compound); PacketClient.sendClient(new FactionSavePacket(compound)); } if(button.id == 1){ - if(data.containsKey(scrollFactions.getSelected())) { + if(data.containsKey(scrollFactions.getSelected())) { GuiYesNo guiyesno = new GuiYesNo(this, scrollFactions.getSelected(), StatCollector.translateToLocal("gui.delete"), 1); displayGuiScreen(guiyesno); - } + } } if(button.id == 2){ - this.setSubGui(new SubGuiNpcFactionPoints(faction)); + this.setSubGui(new SubGuiNpcFactionPoints(faction)); } if(button.id == 3){ - faction.hideFaction = button.getValue() == 1; + faction.hideFaction = button.getValue() == 1; } if(button.id == 4){ - faction.getsAttacked = button.getValue() == 1; + faction.getsAttacked = button.getValue() == 1; + } + if(button.id == 4){ + faction.isPassive = button.getValue() == 1; } if(button.id == 10){ - this.setSubGui(new SubGuiColorSelector(faction.color)); + this.setSubGui(new SubGuiColorSelector(faction.color)); } } - @Override - public void setGuiData(NBTTagCompound compound) { - this.faction = new Faction(); - faction.readNBT(compound); + @Override + public void setGuiData(NBTTagCompound compound) { + this.faction = new Faction(); + faction.readNBT(compound); - setSelected(faction.name); - initGui(); - } + setSelected(faction.name); + initGui(); + } - @Override - public void keyTyped(char c, int i) - { - super.keyTyped(c, i); - if(getTextField(55) != null){ - if(getTextField(55).isFocused()){ - if(search.equals(getTextField(55).getText())) - return; - search = getTextField(55).getText().toLowerCase(); + @Override + public void keyTyped(char c, int i) + { + super.keyTyped(c, i); + if(getTextField(55) != null){ + if(getTextField(55).isFocused()){ + if(search.equals(getTextField(55).getText())) + return; + search = getTextField(55).getText().toLowerCase(); scrollFactions.resetScroll(); - scrollFactions.setList(getSearchList()); - } - } - } + scrollFactions.setList(getSearchList()); + } + } + } - private List getSearchList(){ - if(search.isEmpty()){ - return new ArrayList(this.data.keySet()); - } - List list = new ArrayList(); - for(String name : this.data.keySet()){ - if(name.toLowerCase().contains(search)) - list.add(name); - } - return list; - } + private List getSearchList(){ + if(search.isEmpty()){ + return new ArrayList(this.data.keySet()); + } + List list = new ArrayList(); + for(String name : this.data.keySet()){ + if(name.toLowerCase().contains(search)) + list.add(name); + } + return list; + } - @Override - public void setData(Vector list, HashMap data, EnumScrollData type) { - String name = scrollFactions.getSelected(); - this.data = data; - scrollFactions.setList(getSearchList()); + @Override + public void setData(Vector list, HashMap data, EnumScrollData type) { + String name = scrollFactions.getSelected(); + this.data = data; + scrollFactions.setList(getSearchList()); - if(name != null) - scrollFactions.setSelected(name); - } + if(name != null) + scrollFactions.setSelected(name); + } - @Override - public void setSelected(String selected) { - this.selected = selected; - scrollFactions.setSelected(selected); - } + @Override + public void setSelected(String selected) { + this.selected = selected; + scrollFactions.setSelected(selected); + } - @Override - public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { - if(guiCustomScroll.id == 0) - { - save(); - selected = scrollFactions.getSelected(); + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + if(guiCustomScroll.id == 0) + { + save(); + selected = scrollFactions.getSelected(); FactionGetPacket.getFaction(data.get(selected)); - } - else if(guiCustomScroll.id == 1) - { - HashSet set = new HashSet(); - for(String s : guiCustomScroll.getSelectedList()){ - if(data.containsKey(s)) - set.add(data.get(s)); - } - faction.attackFactions = set; - save(); - } - } + } + else if(guiCustomScroll.id == 1) + { + HashSet set = new HashSet(); + for(String s : guiCustomScroll.getSelectedList()){ + if(data.containsKey(s)) + set.add(data.get(s)); + } + faction.attackFactions = set; + save(); + } + } - public void save() { - if(selected != null && data.containsKey(selected) && faction != null){ - NBTTagCompound compound = new NBTTagCompound(); - faction.writeNBT(compound); + public void save() { + if(selected != null && data.containsKey(selected) && faction != null){ + NBTTagCompound compound = new NBTTagCompound(); + faction.writeNBT(compound); PacketClient.sendClient(new FactionSavePacket(compound)); - } - } + } + } - @Override - public void unFocused(GuiNpcTextField guiNpcTextField) { - if(faction.id == -1) - return; + @Override + public void unFocused(GuiNpcTextField guiNpcTextField) { + if(faction.id == -1) + return; - if(guiNpcTextField.id == 0) { - String name = guiNpcTextField.getText(); - if(!name.isEmpty() && !data.containsKey(name)){ - String old = faction.name; - data.remove(faction.name); - faction.name = name; - data.put(faction.name, faction.id); - selected = name; - scrollFactions.replace(old,faction.name); - } - } else if(guiNpcTextField.id == 1) { - int color = 0; - try{ - color = Integer.parseInt(guiNpcTextField.getText(),16); - } - catch(NumberFormatException e){ - color = 0; - } - faction.color = color; - guiNpcTextField.setTextColor(faction.color); - } + if(guiNpcTextField.id == 0) { + String name = guiNpcTextField.getText(); + if(!name.isEmpty() && !data.containsKey(name)){ + String old = faction.name; + data.remove(faction.name); + faction.name = name; + data.put(faction.name, faction.id); + selected = name; + scrollFactions.replace(old,faction.name); + } + } else if(guiNpcTextField.id == 1) { + int color = 0; + try{ + color = Integer.parseInt(guiNpcTextField.getText(),16); + } + catch(NumberFormatException e){ + color = 0; + } + faction.color = color; + guiNpcTextField.setTextColor(faction.color); + } - } + } - @Override - public void subGuiClosed(SubGuiInterface subgui) { - if(subgui instanceof SubGuiColorSelector){ - faction.color = ((SubGuiColorSelector)subgui).color; - initGui(); - } - } + @Override + public void subGuiClosed(SubGuiInterface subgui) { + if(subgui instanceof SubGuiColorSelector){ + faction.color = ((SubGuiColorSelector)subgui).color; + initGui(); + } + } @Override public void confirmClicked(boolean result, int id) { diff --git a/src/main/java/noppes/npcs/controllers/data/Faction.java b/src/main/java/noppes/npcs/controllers/data/Faction.java index 024f1c62b..6b9f39903 100644 --- a/src/main/java/noppes/npcs/controllers/data/Faction.java +++ b/src/main/java/noppes/npcs/controllers/data/Faction.java @@ -17,22 +17,23 @@ import java.util.HashSet; public class Faction implements IFaction { public String name = ""; public int color = Integer.parseInt("FF00", 16); - + public HashSet 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 boolean isPassive = false; + public Faction(){ attackFactions = new HashSet(); } - + public Faction(int id, String name,int color, int defaultPoints){ this.name = name; this.color = color; @@ -48,28 +49,30 @@ public class Faction implements IFaction { 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"); - + isPassive = compound.getBoolean("IsPassive"); + 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.setBoolean("IsPassive", isPassive); + compound.setTag("AttackFactions", NBTTags.nbtIntegerSet(attackFactions)); } @@ -82,7 +85,7 @@ public class Faction implements IFaction { 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); @@ -177,7 +180,15 @@ public class Faction implements IFaction { this.hideFaction = bo; } - public boolean attackedByMobs() { + public boolean isPassive() { + return isPassive; + } + + public void setIsPassive(boolean passive) { + this.isPassive = passive; + } + + public boolean attackedByMobs() { return this.getsAttacked; } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 8ea868ead..b028da4c8 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -726,12 +726,14 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti if (isKilled()) return; - IEntitySelector attackEntitySelector = new NPCAttackSelector(this); - this.targetTasks.addTask(0, new EntityAIClearTarget(this)); - this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); - this.targetTasks.addTask(2, new EntityAIClosestTarget(this, EntityLivingBase.class, 4, this.ais.directLOS, false, attackEntitySelector)); - this.targetTasks.addTask(3, new EntityAIOwnerHurtByTarget(this)); - this.targetTasks.addTask(4, new EntityAIOwnerHurtTarget(this)); + if(!faction.isPassive()){ + IEntitySelector attackEntitySelector = new NPCAttackSelector(this); + this.targetTasks.addTask(0, new EntityAIClearTarget(this)); + this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false)); + this.targetTasks.addTask(2, new EntityAIClosestTarget(this, EntityLivingBase.class, 4, this.ais.directLOS, false, attackEntitySelector)); + this.targetTasks.addTask(3, new EntityAIOwnerHurtByTarget(this)); + this.targetTasks.addTask(4, new EntityAIOwnerHurtTarget(this)); + } if (canFly()) { this.getNavigator().setCanSwim(true); @@ -770,7 +772,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIPanic(this, 1.2F)); else if (this.ais.onAttack == 2) { this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIAvoidTarget(this)); - } else if (this.ais.onAttack == 0) { + } else if (this.ais.onAttack == 0 && !faction.isPassive()) { this.setLeapTask(); if (this.inventory.getProjectile() == null || this.ais.useRangeMelee == 2) { switch (this.ais.tacticalVariant) { diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 131ff872a..453e3268e 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -539,6 +539,8 @@ faction.options=Faction Options faction.increasepoints=Faction %s increased by %s points faction.decreasepoints=Faction %s decreased by %s points faction.attacked=Attacked by mobs +faction.passive=Is Passive +faction.passive.hover=Passive factions will not queue any attacking tasks [Good for Performance] menu.inventory=Inventory menu.display=Display