diff --git a/src/resources/objects/tangible/TangibleMessageBuilder.java b/src/resources/objects/tangible/TangibleMessageBuilder.java index 44ae16ff..44bedab4 100644 --- a/src/resources/objects/tangible/TangibleMessageBuilder.java +++ b/src/resources/objects/tangible/TangibleMessageBuilder.java @@ -51,7 +51,7 @@ public class TangibleMessageBuilder extends ObjectMessageBuilder { buffer.put(getUnicodeString(object.getCustomName())); buffer.putInt(object.getVolume()); buffer.putInt(0); - buffer.putInt(0); // faction vars + buffer.putInt(tangible.getFactionStatus()); // faction vars if(tangible.getCustomization() == null || tangible.getCustomization().length <= 0) buffer.putShort((short) 0); @@ -67,7 +67,7 @@ public class TangibleMessageBuilder extends ObjectMessageBuilder { if(tangible.getOptionsBitmask() == 0) tangible.setOptionsBitmask(0x100); buffer.putInt(tangible.getOptionsBitmask()); - buffer.putInt(0); // number of item uses + buffer.putInt(tangible.getUses()); // number of item uses buffer.putInt(tangible.getConditionDamage()); buffer.putInt(tangible.getMaxDamage()); buffer.put((byte) (tangible.isStaticObject() ? 1 : 0)); diff --git a/src/resources/objects/tangible/TangibleObject.java b/src/resources/objects/tangible/TangibleObject.java index 6c6fdb68..4d8d18fc 100644 --- a/src/resources/objects/tangible/TangibleObject.java +++ b/src/resources/objects/tangible/TangibleObject.java @@ -66,6 +66,7 @@ public class TangibleObject extends SWGObject { private List componentCustomizations = new ArrayList(); private Map customizationVariables = new HashMap(); protected int optionsBitmask = 0; + private int uses = 0; private int maxDamage = 1000; private boolean staticObject = true; protected String faction = ""; // Says you're "Imperial Special Forces" if it's 0 for some reason @@ -118,6 +119,15 @@ public class TangibleObject extends SWGObject { public void setIncapTimer(int incapTimer) { this.incapTimer = incapTimer; } + + public int getUses() { + return uses; + } + + public void setUses(int uses) { + this.uses = uses; + setIntAttribute("uses", uses); + } public synchronized int getConditionDamage() { return conditionDamage; diff --git a/src/services/object/ObjectService.java b/src/services/object/ObjectService.java index e1fa31b6..f39729ad 100644 --- a/src/services/object/ObjectService.java +++ b/src/services/object/ObjectService.java @@ -116,6 +116,8 @@ import resources.objects.tangible.TangibleObject; import resources.objects.tool.SurveyTool; import resources.objects.waypoint.WaypointObject; import resources.objects.weapon.WeaponObject; +import services.command.BaseSWGCommand; +import services.command.CombatCommand; @SuppressWarnings("unused") @@ -713,21 +715,61 @@ public class ObjectService implements INetworkDispatch { } public void useObject(CreatureObject creature, SWGObject object) { - if (object == null) { + if (creature == null || object == null) { return; } - if(object.getStringAttribute("proc_name") != null) - { - if(object.getAttachment("tempUseCount") != null) - { - int useCount = (int)object.getAttachment("tempUseCount"); // Seefo: Placeholder until delta for stack count/use count + if (object.getIntAttribute("reuse_time") > 0) { + try { + DatatableVisitor visitor = ClientFileManager.loadFile("datatables/timer/template_command_mapping.iff", DatatableVisitor.class); - if((useCount - 1) == 0) destroyObject(object); - else object.setAttachment("tempUseCount", useCount--); + for (int i = 0; i < visitor.getRowCount(); i++) { + if (visitor.getObject(i, 0) != null && ((String) (visitor.getObject(i, 0))).equalsIgnoreCase(object.getTemplate())) { + String commandName = (String) visitor.getObject(i, 1); + String cooldownGroup = (String) visitor.getObject(i, 2); + String animation = (String) visitor.getObject(i, 3); + + if (commandName.length() > 0) { + BaseSWGCommand command = core.commandService.getCommandByName(commandName); + + if (command instanceof CombatCommand && animation.length() > 0) { + ((CombatCommand) command).setDefaultAnimations(new String[] { animation }); + } + + if (core.commandService.callCommand(creature, object, command, 0, "")) { + core.commandService.removeCommand(creature, 0, command); + return; + } + } else if (cooldownGroup.length() > 0) { + if (creature.hasCooldown(cooldownGroup)) { + return; + } + + creature.addCooldown(cooldownGroup, object.getIntAttribute("reuse_item")); + } + + break; + } + } + } catch (Exception e) { + e.printStackTrace(); } + } + + if (object instanceof TangibleObject) { + TangibleObject item = (TangibleObject) object; + int uses = item.getUses(); - // Seefo: We need to add cool downs for buff items + if (uses > 0) { + item.setUses(uses--); + + if (item.getUses() == 0) { + destroyObject(object); + } + } + } + + if (object.getStringAttribute("proc_name") != null) { core.buffService.addBuffToCreature(creature, object.getStringAttribute("proc_name").replace("@ui_buff:", ""), creature); }