Passivity to Factions

This commit is contained in:
Kam committed 2025-03-06 17:33:44 -05:00
1 parent 4ba1358af2
commit 73594e46c0
5 files changed
+207 -180

No files matched your search

@@ -22,15 +22,15 @@ import java.util.*;
public class GuiNPCManageFactions extends GuiNPCInterface2 implements IScrollData,ICustomScrollListener,ITextfieldListener, IGuiData, ISubGuiListener, GuiYesNoCallback
{
private GuiCustomScroll scrollFactions;
private HashMap<String,Integer> data = new HashMap<String,Integer>();
private Faction faction = new Faction();
private String selected = null;
private String search = "";
private GuiCustomScroll scrollFactions;
private HashMap<String,Integer> data = new HashMap<String,Integer>();
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<String> hostileList = new ArrayList<String>(scrollFactions.getList());
hostileList.remove(faction.name);
y += 23;
HashSet<String> set = new HashSet<String>();
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<String> hostileList = new ArrayList<String>(scrollFactions.getList());
hostileList.remove(faction.name);
HashSet<String> set = new HashSet<String>();
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<String> getSearchList(){
if(search.isEmpty()){
return new ArrayList<String>(this.data.keySet());
}
List<String> list = new ArrayList<String>();
for(String name : this.data.keySet()){
if(name.toLowerCase().contains(search))
list.add(name);
}
return list;
}
private List<String> getSearchList(){
if(search.isEmpty()){
return new ArrayList<String>(this.data.keySet());
}
List<String> list = new ArrayList<String>();
for(String name : this.data.keySet()){
if(name.toLowerCase().contains(search))
list.add(name);
}
return list;
}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
String name = scrollFactions.getSelected();
this.data = data;
scrollFactions.setList(getSearchList());
@Override
public void setData(Vector<String> list, HashMap<String, Integer> 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<Integer> set = new HashSet<Integer>();
for(String s : guiCustomScroll.getSelectedList()){
if(data.containsKey(s))
set.add(data.get(s));
}
faction.attackFactions = set;
save();
}
}
}
else if(guiCustomScroll.id == 1)
{
HashSet<Integer> set = new HashSet<Integer>();
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) {
@@ -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<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 boolean isPassive = false;
public Faction(){
attackFactions = new HashSet<Integer>();
}
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;
}
@@ -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) {