From fce02347f663ec661cf40e2a3031b83916fddca7 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Mon, 5 Mar 2018 00:54:27 +0100 Subject: [PATCH 1/4] Added customization variables --- .../TerminalCharacterBuilderRadial.groovy | 39 +++++++++++++++++++ .../objects/tangible/TangibleObject.java | 22 +++++++---- .../services/objects/StaticItemService.java | 15 ++++++- .../player/creation/CharacterCreation.java | 3 +- 4 files changed, 69 insertions(+), 10 deletions(-) diff --git a/src/main/groovy/com/projectswg/holocore/scripts/radial/terminal/TerminalCharacterBuilderRadial.groovy b/src/main/groovy/com/projectswg/holocore/scripts/radial/terminal/TerminalCharacterBuilderRadial.groovy index 0e5c4eaa5..161c7004d 100644 --- a/src/main/groovy/com/projectswg/holocore/scripts/radial/terminal/TerminalCharacterBuilderRadial.groovy +++ b/src/main/groovy/com/projectswg/holocore/scripts/radial/terminal/TerminalCharacterBuilderRadial.groovy @@ -27,19 +27,25 @@ package com.projectswg.holocore.scripts.radial.terminal +import com.projectswg.common.data.customization.PaletteCustomizationVariable import com.projectswg.common.data.location.Location import com.projectswg.common.data.location.Terrain import com.projectswg.common.data.radial.RadialItem import com.projectswg.common.data.radial.RadialOption import com.projectswg.common.data.sui.SuiEvent import com.projectswg.holocore.intents.object.CreateStaticItemIntent +import com.projectswg.holocore.intents.object.ObjectCreatedIntent import com.projectswg.holocore.intents.object.ObjectTeleportIntent import com.projectswg.holocore.resources.containers.ContainerPermissionsType import com.projectswg.holocore.resources.objects.SWGObject +import com.projectswg.holocore.resources.objects.tangible.TangibleObject +import com.projectswg.holocore.resources.objects.weapon.WeaponObject +import com.projectswg.holocore.resources.objects.weapon.WeaponType import com.projectswg.holocore.resources.player.Player import com.projectswg.holocore.resources.sui.SuiButtons import com.projectswg.holocore.resources.sui.SuiListBox import com.projectswg.holocore.scripts.radial.RadialHandlerInterface +import com.projectswg.holocore.services.objects.ObjectCreator import com.projectswg.holocore.services.objects.StaticItemService class TerminalCharacterBuilderRadial implements RadialHandlerInterface { @@ -59,6 +65,7 @@ class TerminalCharacterBuilderRadial implements RadialHandlerInterface { listBox.addListItem("Wearables") listBox.addListItem("Tools") listBox.addListItem("Travel") + listBox.addListItem("Test Lightsaber") listBox.addCallback(SuiEvent.OK_PRESSED, "handleCategorySelection", { event, parameters -> handleCategorySelection(player, parameters) }) listBox.display(player) @@ -76,6 +83,7 @@ class TerminalCharacterBuilderRadial implements RadialHandlerInterface { case 2: handleWearables(player); break case 3: handleTools(player); break case 4: handleTravel(player); break + case 5: handleTestLightsaber(player); break } } @@ -1174,6 +1182,37 @@ class TerminalCharacterBuilderRadial implements RadialHandlerInterface { listBox.display(player) } + static def handleTestLightsaber(Player player) { + def lightsaber = ObjectCreator.createObjectFromTemplate("object/weapon/melee/polearm/crafted_saber/shared_sword_lightsaber_polearm_pvp_bf.iff", WeaponObject.class) + def goggles = ObjectCreator.createObjectFromTemplate("object/tangible/wearables/goggles/shared_goggles_s01.iff", TangibleObject.class) + def inventory = player.getCreatureObject().getSlottedObject("inventory") + def bladeColor = new PaletteCustomizationVariable() + def gogglesPrimary = new PaletteCustomizationVariable() + def gogglesSecondary = new PaletteCustomizationVariable() + + // LS config + lightsaber.setAttackSpeed(1) + lightsaber.setMinDamage(1) + lightsaber.setMaxDamage(2) + lightsaber.setType(WeaponType.TWO_HANDED_SABER) + bladeColor.setColor(0, 29) // Palette #0 (wp_lightsaber.pal), color at index 29 + lightsaber.putCustomization("/private/index_color_blade", bladeColor) // private/alternate_shader_blade for lava, permafrost etc + + // Goggles config + gogglesPrimary.setColor(0, 6) // Teal + gogglesSecondary.setColor(0, 1) // Silver + goggles.putCustomization("/private/index_color_1", gogglesPrimary) + goggles.putCustomization("/private/index_color_2", gogglesPrimary) + + // Create items + ObjectCreatedIntent.broadcast(lightsaber) + ObjectCreatedIntent.broadcast(goggles) + + // Move items to inventory + lightsaber.moveToContainer(inventory) + goggles.moveToContainer(inventory) + } + static def handleTravelSelection(Player player, Map parameters) { def selection = SuiListBox.getSelectedRow(parameters) diff --git a/src/main/java/com/projectswg/holocore/resources/objects/tangible/TangibleObject.java b/src/main/java/com/projectswg/holocore/resources/objects/tangible/TangibleObject.java index aa50ef934..ada02af1e 100644 --- a/src/main/java/com/projectswg/holocore/resources/objects/tangible/TangibleObject.java +++ b/src/main/java/com/projectswg/holocore/resources/objects/tangible/TangibleObject.java @@ -30,6 +30,8 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.util.Set; +import com.projectswg.common.data.customization.CustomizationString; +import com.projectswg.common.data.customization.CustomizationVariable; import com.projectswg.common.data.encodables.tangible.PvpFaction; import com.projectswg.common.data.encodables.tangible.PvpFlag; import com.projectswg.common.data.encodables.tangible.PvpStatus; @@ -49,7 +51,7 @@ import com.projectswg.holocore.resources.player.Player; public class TangibleObject extends SWGObject { - private byte [] appearanceData = new byte[0]; + private CustomizationString appearanceData = new CustomizationString(); private int maxHitPoints = 1000; private int components = 0; private boolean inCombat = false; @@ -83,7 +85,7 @@ public class TangibleObject extends SWGObject { inCombat = false; } - public byte [] getAppearanceData() { + public CustomizationString getAppearanceData() { // TODO a getter for this isn't a good idea return appearanceData; } @@ -153,8 +155,14 @@ public class TangibleObject extends SWGObject { return objectEffects; } - public void setAppearanceData(byte [] appearanceData) { + public void putCustomization(String name, CustomizationVariable value) { + appearanceData.put(name, value); + } + + public void setAppearanceData(CustomizationString appearanceData) { this.appearanceData = appearanceData; + + sendDelta(3, 6, appearanceData); } public void setMaxHitPoints(int maxHitPoints) { @@ -295,7 +303,7 @@ public class TangibleObject extends SWGObject { super.createBaseline3(target, bb); // 4 variables - BASE3 (4) bb.addInt(pvpFaction.getCrc()); // Faction - 4 bb.addInt(pvpStatus.getValue()); // Faction Status - 5 - bb.addArray(appearanceData); // - 6 + bb.addObject(appearanceData); // - 6 bb.addInt(0); // Component customization (Set, Integer) - 7 bb.addInt(0); bb.addInt(optionFlags); // 8 @@ -327,7 +335,7 @@ public class TangibleObject extends SWGObject { super.parseBaseline3(buffer); pvpFaction = PvpFaction.getFactionForCrc(buffer.getInt()); pvpStatus = PvpStatus.getStatusForValue(buffer.getInt()); - appearanceData = buffer.getArray(); + appearanceData.decode(buffer); SWGSet.getSwgSet(buffer, 3, 7, Integer.class); optionFlags = buffer.getInt(); buffer.getInt(); @@ -358,7 +366,7 @@ public class TangibleObject extends SWGObject { public void save(NetBufferStream stream) { super.save(stream); stream.addByte(0); - stream.addArray(appearanceData); + appearanceData.save(stream); stream.addInt(maxHitPoints); stream.addInt(components); stream.addBoolean(inCombat); @@ -379,7 +387,7 @@ public class TangibleObject extends SWGObject { public void read(NetBufferStream stream) { super.read(stream); stream.getByte(); - appearanceData = stream.getArray(); + appearanceData.read(stream); maxHitPoints = stream.getInt(); components = stream.getInt(); inCombat = stream.getBoolean(); diff --git a/src/main/java/com/projectswg/holocore/services/objects/StaticItemService.java b/src/main/java/com/projectswg/holocore/services/objects/StaticItemService.java index 07124af5d..2a9239314 100644 --- a/src/main/java/com/projectswg/holocore/services/objects/StaticItemService.java +++ b/src/main/java/com/projectswg/holocore/services/objects/StaticItemService.java @@ -33,6 +33,7 @@ import java.util.Map; import com.projectswg.common.control.Service; import com.projectswg.common.data.combat.DamageType; +import com.projectswg.common.data.customization.PaletteCustomizationVariable; import com.projectswg.common.data.info.RelationalServerData; import com.projectswg.common.data.info.RelationalServerFactory; import com.projectswg.common.data.swgfile.ClientFactory; @@ -47,6 +48,7 @@ import com.projectswg.holocore.resources.config.ConfigFile; import com.projectswg.holocore.resources.containers.ContainerPermissionsType; import com.projectswg.holocore.resources.objects.SWGObject; import com.projectswg.holocore.resources.objects.creature.CreatureObject; +import com.projectswg.holocore.resources.objects.tangible.TangibleObject; import com.projectswg.holocore.resources.objects.weapon.WeaponObject; import com.projectswg.holocore.resources.objects.weapon.WeaponType; import com.projectswg.holocore.resources.player.Player; @@ -335,8 +337,7 @@ public final class StaticItemService extends Service { private boolean wearableByRodians; private boolean wearableByTrandoshans; private boolean wearableByRest; - - // TODO customisation variables, ie. for colours + private int colorIndex; public WearableAttributes(String itemName, String iffTemplate) { super(itemName, iffTemplate); @@ -380,6 +381,7 @@ public final class StaticItemService extends Service { wearableByRodians = resultSet.getInt("race_rodian") != 0; wearableByTrandoshans = resultSet.getInt("race_trandoshan") != 0; wearableByRest = resultSet.getInt("race_rest") != 0; + colorIndex = resultSet.getInt("index_color"); return true; } @@ -402,6 +404,15 @@ public final class StaticItemService extends Service { // Add the race restrictions only if there are any if (!wearableByWookiees || !wearableByIthorians || !wearableByRodians || !wearableByTrandoshans || !wearableByRest) object.addAttribute("species_restrictions.species_name", buildRaceRestrictionString()); + + if (colorIndex != 0 && object instanceof TangibleObject) { // All wearables should be TangibleObjects, but oh well... + PaletteCustomizationVariable color = new PaletteCustomizationVariable(); + + color.setColor(0, colorIndex); + + ((TangibleObject) object).putCustomization("/private/index_color_1", color); + //((TangibleObject) object).putCustomization("/private/index_color_2", color); + } } private String buildRaceRestrictionString() { diff --git a/src/main/java/com/projectswg/holocore/services/player/creation/CharacterCreation.java b/src/main/java/com/projectswg/holocore/services/player/creation/CharacterCreation.java index 51f0beac7..85cdeb619 100644 --- a/src/main/java/com/projectswg/holocore/services/player/creation/CharacterCreation.java +++ b/src/main/java/com/projectswg/holocore/services/player/creation/CharacterCreation.java @@ -28,6 +28,7 @@ package com.projectswg.holocore.services.player.creation; import java.util.Calendar; +import com.projectswg.common.data.customization.CustomizationString; import com.projectswg.common.data.encodables.tangible.PvpFlag; import com.projectswg.common.data.encodables.tangible.Race; import com.projectswg.common.data.swgfile.ClientFactory; @@ -135,7 +136,7 @@ public class CharacterCreation { return createTangible(container, ContainerPermissionsType.INVENTORY, template); } - private void createHair(CreatureObject creatureObj, String hair, byte [] customization) { + private void createHair(CreatureObject creatureObj, String hair, CustomizationString customization) { if (hair.isEmpty()) return; TangibleObject hairObj = createDefaultObject(creatureObj, ClientFactory.formatToSharedFile(hair)); From fdf3e8292b14ed205c83a91123e68fd12d2af910 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Tue, 6 Mar 2018 07:04:18 +0100 Subject: [PATCH 2/4] Removed some object customization debugging code --- PSWGCommon | 2 +- .../TerminalCharacterBuilderRadial.groovy | 39 ------------------- .../services/objects/StaticItemService.java | 10 ++--- 3 files changed, 6 insertions(+), 45 deletions(-) diff --git a/PSWGCommon b/PSWGCommon index 3934cc12a..a28744123 160000 --- a/PSWGCommon +++ b/PSWGCommon @@ -1 +1 @@ -Subproject commit 3934cc12aa8c83a4467f22a19345daa4d207ae56 +Subproject commit a287441236ed82a671d076db0bbdc6d8853e3748 diff --git a/src/main/groovy/com/projectswg/holocore/scripts/radial/terminal/TerminalCharacterBuilderRadial.groovy b/src/main/groovy/com/projectswg/holocore/scripts/radial/terminal/TerminalCharacterBuilderRadial.groovy index 161c7004d..0e5c4eaa5 100644 --- a/src/main/groovy/com/projectswg/holocore/scripts/radial/terminal/TerminalCharacterBuilderRadial.groovy +++ b/src/main/groovy/com/projectswg/holocore/scripts/radial/terminal/TerminalCharacterBuilderRadial.groovy @@ -27,25 +27,19 @@ package com.projectswg.holocore.scripts.radial.terminal -import com.projectswg.common.data.customization.PaletteCustomizationVariable import com.projectswg.common.data.location.Location import com.projectswg.common.data.location.Terrain import com.projectswg.common.data.radial.RadialItem import com.projectswg.common.data.radial.RadialOption import com.projectswg.common.data.sui.SuiEvent import com.projectswg.holocore.intents.object.CreateStaticItemIntent -import com.projectswg.holocore.intents.object.ObjectCreatedIntent import com.projectswg.holocore.intents.object.ObjectTeleportIntent import com.projectswg.holocore.resources.containers.ContainerPermissionsType import com.projectswg.holocore.resources.objects.SWGObject -import com.projectswg.holocore.resources.objects.tangible.TangibleObject -import com.projectswg.holocore.resources.objects.weapon.WeaponObject -import com.projectswg.holocore.resources.objects.weapon.WeaponType import com.projectswg.holocore.resources.player.Player import com.projectswg.holocore.resources.sui.SuiButtons import com.projectswg.holocore.resources.sui.SuiListBox import com.projectswg.holocore.scripts.radial.RadialHandlerInterface -import com.projectswg.holocore.services.objects.ObjectCreator import com.projectswg.holocore.services.objects.StaticItemService class TerminalCharacterBuilderRadial implements RadialHandlerInterface { @@ -65,7 +59,6 @@ class TerminalCharacterBuilderRadial implements RadialHandlerInterface { listBox.addListItem("Wearables") listBox.addListItem("Tools") listBox.addListItem("Travel") - listBox.addListItem("Test Lightsaber") listBox.addCallback(SuiEvent.OK_PRESSED, "handleCategorySelection", { event, parameters -> handleCategorySelection(player, parameters) }) listBox.display(player) @@ -83,7 +76,6 @@ class TerminalCharacterBuilderRadial implements RadialHandlerInterface { case 2: handleWearables(player); break case 3: handleTools(player); break case 4: handleTravel(player); break - case 5: handleTestLightsaber(player); break } } @@ -1182,37 +1174,6 @@ class TerminalCharacterBuilderRadial implements RadialHandlerInterface { listBox.display(player) } - static def handleTestLightsaber(Player player) { - def lightsaber = ObjectCreator.createObjectFromTemplate("object/weapon/melee/polearm/crafted_saber/shared_sword_lightsaber_polearm_pvp_bf.iff", WeaponObject.class) - def goggles = ObjectCreator.createObjectFromTemplate("object/tangible/wearables/goggles/shared_goggles_s01.iff", TangibleObject.class) - def inventory = player.getCreatureObject().getSlottedObject("inventory") - def bladeColor = new PaletteCustomizationVariable() - def gogglesPrimary = new PaletteCustomizationVariable() - def gogglesSecondary = new PaletteCustomizationVariable() - - // LS config - lightsaber.setAttackSpeed(1) - lightsaber.setMinDamage(1) - lightsaber.setMaxDamage(2) - lightsaber.setType(WeaponType.TWO_HANDED_SABER) - bladeColor.setColor(0, 29) // Palette #0 (wp_lightsaber.pal), color at index 29 - lightsaber.putCustomization("/private/index_color_blade", bladeColor) // private/alternate_shader_blade for lava, permafrost etc - - // Goggles config - gogglesPrimary.setColor(0, 6) // Teal - gogglesSecondary.setColor(0, 1) // Silver - goggles.putCustomization("/private/index_color_1", gogglesPrimary) - goggles.putCustomization("/private/index_color_2", gogglesPrimary) - - // Create items - ObjectCreatedIntent.broadcast(lightsaber) - ObjectCreatedIntent.broadcast(goggles) - - // Move items to inventory - lightsaber.moveToContainer(inventory) - goggles.moveToContainer(inventory) - } - static def handleTravelSelection(Player player, Map parameters) { def selection = SuiListBox.getSelectedRow(parameters) diff --git a/src/main/java/com/projectswg/holocore/services/objects/StaticItemService.java b/src/main/java/com/projectswg/holocore/services/objects/StaticItemService.java index 2a9239314..09894dc71 100644 --- a/src/main/java/com/projectswg/holocore/services/objects/StaticItemService.java +++ b/src/main/java/com/projectswg/holocore/services/objects/StaticItemService.java @@ -33,7 +33,7 @@ import java.util.Map; import com.projectswg.common.control.Service; import com.projectswg.common.data.combat.DamageType; -import com.projectswg.common.data.customization.PaletteCustomizationVariable; +import com.projectswg.common.data.customization.CustomizationVariable; import com.projectswg.common.data.info.RelationalServerData; import com.projectswg.common.data.info.RelationalServerFactory; import com.projectswg.common.data.swgfile.ClientFactory; @@ -405,13 +405,13 @@ public final class StaticItemService extends Service { if (!wearableByWookiees || !wearableByIthorians || !wearableByRodians || !wearableByTrandoshans || !wearableByRest) object.addAttribute("species_restrictions.species_name", buildRaceRestrictionString()); - if (colorIndex != 0 && object instanceof TangibleObject) { // All wearables should be TangibleObjects, but oh well... - PaletteCustomizationVariable color = new PaletteCustomizationVariable(); + if (colorIndex != 0 && object instanceof TangibleObject) { + CustomizationVariable color = new CustomizationVariable(); - color.setColor(0, colorIndex); + color.setValue(colorIndex); ((TangibleObject) object).putCustomization("/private/index_color_1", color); - //((TangibleObject) object).putCustomization("/private/index_color_2", color); + // TODO our item SDB has no way of defining multiple colors for a single item } } From 8f54b8b000298d4c560e55828133bdda871c4ca8 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Tue, 6 Mar 2018 07:08:50 +0100 Subject: [PATCH 3/4] Prevent object customization changes without deltas --- .../holocore/resources/objects/tangible/TangibleObject.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/com/projectswg/holocore/resources/objects/tangible/TangibleObject.java b/src/main/java/com/projectswg/holocore/resources/objects/tangible/TangibleObject.java index ad5db9406..a12d06bf7 100644 --- a/src/main/java/com/projectswg/holocore/resources/objects/tangible/TangibleObject.java +++ b/src/main/java/com/projectswg/holocore/resources/objects/tangible/TangibleObject.java @@ -85,10 +85,6 @@ public class TangibleObject extends SWGObject { inCombat = false; } - public CustomizationString getAppearanceData() { // TODO a getter for this isn't a good idea - return appearanceData; - } - public int getMaxHitPoints() { return maxHitPoints; } From c44e7c7446709338ecfb39ab8cbdaede55e94037 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Tue, 6 Mar 2018 18:05:25 +0100 Subject: [PATCH 4/4] Added way to retrieve value for customization key --- PSWGCommon | 2 +- .../holocore/resources/objects/tangible/TangibleObject.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/PSWGCommon b/PSWGCommon index a28744123..9236f68e5 160000 --- a/PSWGCommon +++ b/PSWGCommon @@ -1 +1 @@ -Subproject commit a287441236ed82a671d076db0bbdc6d8853e3748 +Subproject commit 9236f68e56b6bc2412c3625f046d53e88b899c10 diff --git a/src/main/java/com/projectswg/holocore/resources/objects/tangible/TangibleObject.java b/src/main/java/com/projectswg/holocore/resources/objects/tangible/TangibleObject.java index a12d06bf7..23ae85671 100644 --- a/src/main/java/com/projectswg/holocore/resources/objects/tangible/TangibleObject.java +++ b/src/main/java/com/projectswg/holocore/resources/objects/tangible/TangibleObject.java @@ -155,6 +155,10 @@ public class TangibleObject extends SWGObject { appearanceData.put(name, value); } + public CustomizationVariable getCustomization(String name) { + return appearanceData.get(name); + } + public void setAppearanceData(CustomizationString appearanceData) { this.appearanceData = appearanceData;