diff --git a/scripts/commands/giveitem.py b/scripts/commands/giveitem.py index 8279dc05..2d5aba72 100644 --- a/scripts/commands/giveitem.py +++ b/scripts/commands/giveitem.py @@ -13,6 +13,9 @@ def run(core, actor, target, commandString): object = core.objectService.createObject(commandString, actor.getPlanet()) + #object.setCustomizationVariable('/private/index_color_blade', 0x02) + #object.setCustomizationVariable('private/alternate_shader_blade', 0x02) + if not object: return diff --git a/src/resources/objects/tangible/TangibleObject.java b/src/resources/objects/tangible/TangibleObject.java index b00537a1..dce95545 100644 --- a/src/resources/objects/tangible/TangibleObject.java +++ b/src/resources/objects/tangible/TangibleObject.java @@ -21,35 +21,40 @@ ******************************************************************************/ package resources.objects.tangible; +import java.io.ByteArrayOutputStream; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.Vector; -import main.NGECore; +import javax.xml.bind.DatatypeConverter; +import main.NGECore; import protocol.swg.ObjControllerMessage; import protocol.swg.PlayClientEffectObjectMessage; import protocol.swg.StopClientEffectObjectByLabel; import protocol.swg.UpdatePVPStatusMessage; import protocol.swg.objectControllerObjects.ShowFlyText; - import resources.common.RGB; import resources.objects.creature.CreatureObject; +import resources.visitors.IDManagerVisitor; import services.ai.AIActor; import com.sleepycat.persist.model.NotPersistent; import com.sleepycat.persist.model.Persistent; +import engine.clientdata.ClientFileManager; import engine.clients.Client; import engine.resources.objects.SWGObject; import engine.resources.scene.Planet; import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; -@Persistent(version=0) +@Persistent(version=1) public class TangibleObject extends SWGObject { // TODO: Thread safety @@ -59,6 +64,7 @@ public class TangibleObject extends SWGObject { protected int pvpBitmask = 0; protected byte[] customization; private List componentCustomizations = new ArrayList(); + private Map customizationVariables = new HashMap(); protected int optionsBitmask = 0; private int maxDamage = 1000; private boolean staticObject = true; @@ -241,6 +247,50 @@ public class TangibleObject extends SWGObject { } } + public void setCustomizationVariable(String type, byte value) + { + if(customizationVariables.containsKey(type)) customizationVariables.replace(type, value); + else customizationVariables.put(type, value); + + buildCustomizationBytes(); + } + + public void removeCustomizationVariable(String type) + { + if(customizationVariables.containsKey(type)) + { + customizationVariables.remove(type); + buildCustomizationBytes(); + } + } + + private void buildCustomizationBytes() + { + //if(customizationVariables.size() == 0) customization = { 0x00 }; + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + try + { + IDManagerVisitor visitor = ClientFileManager.loadFile("customization/customization_id_manager.iff", IDManagerVisitor.class); + + stream.write((byte)0x02); // Unk + stream.write((byte)customizationVariables.size()); // Number of customization attributes + + for(String type : customizationVariables.keySet()) + { + stream.write(visitor.getAttributeIndex(type)); // Index of palette type within "customization/customization_id_manager.iff" + stream.write(customizationVariables.get(type)); // Value/Index within palette + + // Seperator/Footer + stream.write((byte) 0xC3); + stream.write((byte) 0xBF); + stream.write((byte) 0x03); + } + customization = stream.toByteArray(); + } + catch (Exception e) { e.printStackTrace(); } + } + public String getFaction() { synchronized(objectMutex) { return faction; diff --git a/src/resources/visitors/IDManagerVisitor.java b/src/resources/visitors/IDManagerVisitor.java index 2ad1ad46..3c7a1617 100644 --- a/src/resources/visitors/IDManagerVisitor.java +++ b/src/resources/visitors/IDManagerVisitor.java @@ -31,11 +31,11 @@ import engine.clientdata.VisitorInterface; public class IDManagerVisitor implements VisitorInterface { - private ConcurrentHashMap customizationMap; + private ConcurrentHashMap customizationMap; private CharsetDecoder charsetDecoder; public IDManagerVisitor() { - customizationMap = new ConcurrentHashMap(); + customizationMap = new ConcurrentHashMap(); charsetDecoder = Charset.forName("US-ASCII").newDecoder(); } @@ -46,21 +46,28 @@ public class IDManagerVisitor implements VisitorInterface { return; while(data.hasRemaining()) { - short designNumber = data.getShort(); + + byte designNumber = data.get(); + data.get(); String customizationType = data.getString(charsetDecoder); charsetDecoder.reset(); - + customizationMap.put(customizationType, designNumber); //System.out.println(designNumber + ": " + customizationType); } } + + public byte getAttributeIndex(String type) + { + return customizationMap.get(type); + } @Override public void notifyFolder(String node, int depth) throws Exception { } - public ConcurrentHashMap getCustomizationMap() { + public ConcurrentHashMap getCustomizationMap() { return this.customizationMap; } } diff --git a/src/services/DevService.java b/src/services/DevService.java index 6359957d..aaa5e21e 100644 --- a/src/services/DevService.java +++ b/src/services/DevService.java @@ -231,27 +231,33 @@ public class DevService implements INetworkDispatch { return; // [Items] Weapons case 30: // Jedi Weapons - SWGObject lightsaber1 = core.objectService.createObject("object/weapon/melee/sword/crafted_saber/shared_sword_lightsaber_one_handed_gen5.iff", planet); + TangibleObject lightsaber1 = (TangibleObject) core.objectService.createObject("object/weapon/melee/sword/crafted_saber/shared_sword_lightsaber_one_handed_gen5.iff", planet); lightsaber1.setIntAttribute("required_combat_level", 90); lightsaber1.setFloatAttribute("cat_wpn_damage.wpn_attack_speed", 1); lightsaber1.setStringAttribute("class_required", "Jedi"); lightsaber1.setStringAttribute("cat_wpn_damage.wpn_damage_type", "Energy"); lightsaber1.setStringAttribute("cat_wpn_damage.damage", "689-1379"); - SWGObject lightsaber2 = core.objectService.createObject("object/weapon/melee/2h_sword/crafted_saber/shared_sword_lightsaber_two_handed_gen5.iff", planet); + TangibleObject lightsaber2 = (TangibleObject) core.objectService.createObject("object/weapon/melee/2h_sword/crafted_saber/shared_sword_lightsaber_two_handed_gen5.iff", planet); lightsaber2.setIntAttribute("required_combat_level", 90); lightsaber2.setFloatAttribute("cat_wpn_damage.wpn_attack_speed", 1); lightsaber2.setStringAttribute("class_required", "Jedi"); lightsaber2.setStringAttribute("cat_wpn_damage.wpn_damage_type", "Energy"); lightsaber2.setStringAttribute("cat_wpn_damage.damage", "689-1379"); - SWGObject lightsaber3 = core.objectService.createObject("object/weapon/melee/polearm/crafted_saber/shared_sword_lightsaber_polearm_gen5.iff", planet); + TangibleObject lightsaber3 = (TangibleObject) core.objectService.createObject("object/weapon/melee/polearm/crafted_saber/shared_sword_lightsaber_polearm_gen5.iff", planet); lightsaber3.setIntAttribute("required_combat_level", 90); lightsaber3.setFloatAttribute("cat_wpn_damage.wpn_attack_speed", 1); lightsaber3.setStringAttribute("class_required", "Jedi"); lightsaber3.setStringAttribute("cat_wpn_damage.wpn_damage_type", "Energy"); lightsaber3.setStringAttribute("cat_wpn_damage.damage", "689-1379"); + Random random = new Random(); + + lightsaber1.setCustomizationVariable("/private/index_color_blade", (byte) random.nextInt(47)); + lightsaber2.setCustomizationVariable("/private/index_color_blade", (byte) random.nextInt(47)); + lightsaber3.setCustomizationVariable("/private/index_color_blade", (byte) random.nextInt(47)); + inventory.add(lightsaber1); inventory.add(lightsaber2); inventory.add(lightsaber3); diff --git a/src/services/EntertainmentService.java b/src/services/EntertainmentService.java index 8b64175e..a523b5e5 100644 --- a/src/services/EntertainmentService.java +++ b/src/services/EntertainmentService.java @@ -65,7 +65,7 @@ public class EntertainmentService implements INetworkDispatch { private ConcurrentHashMap performancesByIndex = new ConcurrentHashMap(); private ConcurrentHashMap danceMap = new ConcurrentHashMap(); - private ConcurrentHashMap designMap = new ConcurrentHashMap(); + private ConcurrentHashMap designMap = new ConcurrentHashMap(); private Random ranWorkshop = new Random(); @@ -932,7 +932,7 @@ public class EntertainmentService implements INetworkDispatch { public String getCustomizationString(int number){ synchronized (designMap) { - for (Entry entry : designMap.entrySet()) { + for (Entry entry : designMap.entrySet()) { if (entry.getValue().intValue() == number) { return entry.getKey(); } @@ -943,7 +943,7 @@ public class EntertainmentService implements INetworkDispatch { public int getCustomizationValue(String customizationString) { synchronized(designMap){ - for(Entry entry : designMap.entrySet()) { + for(Entry entry : designMap.entrySet()) { if (entry.getKey().equals(customizationString)) { return entry.getValue().intValue(); }