From b10ffc3bd2dc9ef6c4a8e411b0906ec9e6f8e9cb Mon Sep 17 00:00:00 2001 From: Waverunner Date: Mon, 8 Jun 2015 20:18:17 -0400 Subject: [PATCH] Added handling of option flags, fixes HAM bars showing on static objects --- .../objects/building/BuildingObject.java | 1 - .../objects/creature/CreatureObject.java | 2 + .../objects/tangible/OptionFlag.java | 82 +++++++++++++++++++ .../objects/tangible/TangibleObject.java | 61 +++++++++++--- 4 files changed, 133 insertions(+), 13 deletions(-) create mode 100644 src/resources/objects/tangible/OptionFlag.java diff --git a/src/resources/objects/building/BuildingObject.java b/src/resources/objects/building/BuildingObject.java index fb35c0c6f..bab13ebbd 100644 --- a/src/resources/objects/building/BuildingObject.java +++ b/src/resources/objects/building/BuildingObject.java @@ -36,7 +36,6 @@ public class BuildingObject extends TangibleObject { public BuildingObject(long objectId) { super(objectId, BaselineType.BUIO); - setOptionsBitmask(256); } } diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index 6c4f6de33..9a7a0bbe6 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -39,6 +39,7 @@ import resources.encodables.player.Equipment; import resources.network.BaselineBuilder; import resources.objects.SWGObject; import resources.objects.player.PlayerObject; +import resources.objects.tangible.OptionFlag; import resources.objects.tangible.TangibleObject; import resources.objects.weapon.WeaponObject; import resources.player.Player; @@ -108,6 +109,7 @@ public class CreatureObject extends TangibleObject { initMaxAttributes(); initCurrentAttributes(); initBaseAttributes(); + setOptionFlags(OptionFlag.HAM_BAR); } public void removeEquipment(SWGObject obj) { diff --git a/src/resources/objects/tangible/OptionFlag.java b/src/resources/objects/tangible/OptionFlag.java new file mode 100644 index 000000000..8f505f129 --- /dev/null +++ b/src/resources/objects/tangible/OptionFlag.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2015 /// Project SWG /// www.projectswg.com + * + * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on + * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. + * Our goal is to create an emulator which will provide a server for players to + * continue playing a game similar to the one they used to play. We are basing + * it on the final publish of the game prior to end-game events. + * + * This file is part of Holocore. + * + * -------------------------------------------------------------------------------- + * + * Holocore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Holocore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Holocore. If not, see + ******************************************************************************/ + +package resources.objects.tangible; + +import java.util.EnumSet; + +public enum OptionFlag { + ON_OFF(0x00000001), + VENDOR(0x00000002), + INSURED(0x00000004), + CONVERSABLE(0x00000008), + HIBERNATING(0x00000010), + MAGIC_ITEM(0x00000020), + AGGRESSIVE(0x00000040), + HAM_BAR(0x00000080), + INVULNERABLE(0x00000100), + DISABLED(0x00000200), + UNINSURABLE(0x00000400), + INTERESTING(0x00000800), + MOUNT(0x00001000), + CRAFTED(0x00002000), + WINGS_OPENED(0x00004000), + SPACE_INTERESTING(0x00008000), + DOCKING(0x00010000), // JTL? + DESTROYING(0x00020000), // JTL? + COMMABLE(0x00040000), + DOCKABLE(0x00080000), + EJECT(0x00100000), + INSPECTABLE(0x00200000), + TRANSFERABLE(0x00400000), + SHOW_FLIGHT_TUTORIAL(0x00800000), + SPACE_COMBAT_MUSIC(0x01000000), + ENCOUNTER_LOCKED(0x02000000), + SPAWNED_CREATURE(0x04000000), + HOLIDAY_INTERESTING(0x08000000), + LOCKED(0x10000000); + + int flag; + + OptionFlag(int flag) { + this.flag = flag; + } + + public int getFlag() { + return flag; + } + + public static EnumSet toEnumSet(int flags) { + EnumSet enumSet = EnumSet.noneOf(OptionFlag.class); + for (OptionFlag optionFlag : OptionFlag.values()) { + if ((flags & optionFlag.getFlag()) == optionFlag.getFlag()) + enumSet.add(optionFlag); + } + + return enumSet; + } +} diff --git a/src/resources/objects/tangible/TangibleObject.java b/src/resources/objects/tangible/TangibleObject.java index c585ca8fb..235aa7720 100644 --- a/src/resources/objects/tangible/TangibleObject.java +++ b/src/resources/objects/tangible/TangibleObject.java @@ -47,10 +47,11 @@ public class TangibleObject extends SWGObject { private int pvpFactionId = 0; private boolean visibleGmOnly = false; private byte [] objectEffects = new byte[0]; - private int optionsBitmask = 128; + private int optionFlags = 0; public TangibleObject(long objectId) { super(objectId, BaselineType.TANO); + addOptionFlags(OptionFlag.INVULNERABLE); } public TangibleObject(long objectId, BaselineType objectType) { @@ -145,8 +146,44 @@ public class TangibleObject extends SWGObject { this.objectEffects = objectEffects; } - public void setOptionsBitmask(int optionsBitmask) { - this.optionsBitmask = optionsBitmask; + public void setOptionFlags(int optionsBitmask) { + this.optionFlags = optionsBitmask; + } + + public void setOptionFlags(OptionFlag ... options) { + optionFlags = 0; + addOptionFlags(options); + } + + public void addOptionFlags(OptionFlag ... options) { + for (OptionFlag flag : options) { + optionFlags |= flag.getFlag(); + } + sendDelta(3, 8, optionFlags); + } + + public void toggleOptionFlags(OptionFlag ... options) { + for (OptionFlag option : options) { + optionFlags ^= option.getFlag(); + } + sendDelta(3, 8, optionFlags); + } + + public void removeOptionFlags(OptionFlag ... options) { + for (OptionFlag option : options) { + optionFlags &= ~option.getFlag(); + } + sendDelta(3, 8, optionFlags); + } + + public boolean hasOptionFlags(OptionFlag ... options) { + int passCount = 0; + for (OptionFlag option : options) { + if ((optionFlags & option.getFlag()) == option.getFlag()) + passCount++; + } + + return passCount == options.length; } @Override @@ -161,16 +198,16 @@ public class TangibleObject extends SWGObject { public void createBaseline3(Player target, BaselineBuilder bb) { super.createBaseline3(target, bb); // 4 variables - BASE3 (4) - bb.addInt(0); // Faction - bb.addInt(0); // Faction Status - bb.addArray(appearanceData); - bb.addInt(0); // Component customization (Set, Integer) + bb.addInt(0); // Faction - 4 + bb.addInt(0); // Faction Status - 5 + bb.addArray(appearanceData); // - 6 + bb.addInt(0); // Component customization (Set, Integer) - 7 bb.addInt(0); //updates - bb.addInt(optionsBitmask); // Options Bitmask (128 = Attackable) // TODO: Fix this for buildings - bb.addInt(0); // Generic Counter -- use count and incap timer - bb.addInt(condition); - bb.addInt(100); // maxHitPoints - bb.addBoolean(true); // isVisible + bb.addInt(optionFlags); // 8 + bb.addInt(0); // Generic Counter -- use count and incap timer - 9 + bb.addInt(condition); // 10 + bb.addInt(100); // maxHitPoints - 11 + bb.addBoolean(true); // isVisible - 12 bb.incrementOperandCount(9); }