Items now have cooldowns and play anims

Grenades, heal stims, heavy weapons.

Heavy weapons seem to be considered usable items and it calls the heavy
weapon command dependent on the template in template_command_mapping.

You can't fire it from the toolbar due to a checkbox.
This commit is contained in:
Treeku
2014-04-14 11:55:40 +01:00
parent db33827e18
commit db3f0368a0
3 changed files with 63 additions and 11 deletions
+51 -9
View File
@@ -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);
}