periodic / foundryvtt-summoner

A module to help with summoning tokens in the Foundry Virtual Tabletop
MIT License
4 stars 1 forks source link

ability-use-dialog.js:28 Uncaught (in promise) Error: You cannot display an ability usage dialog for an unowned item #12

Open Merudo opened 3 years ago

Merudo commented 3 years ago

I'm trying to launch my Flaming Sphere macro from Dynamical Active Effects.

I have the following macro in Item Macro of the Flaming Sphere spell:

let macroItem  = args[0].item || item;
let macroActor = item.options.actor;

Summoner.placeAndSummonFromSpell(
macroActor,
macroItem,
"Flaming Sphere",
{ setSpellBonuses: true }
);

The macro works fine when launched manually. However, when I use it through Dynamic Active Effect, nothing gets summoned and I get the message:

ability-use-dialog.js:28 Uncaught (in promise) Error: You cannot display an ability usage dialog for an unowned item
    at Function.create (ability-use-dialog.js:28)
    at Object.placeAndSummonFromSpell (summoner.js:42)
    at Workflow.eval (eval at callMacro (workflow.js:790), <anonymous>:8:10)
    at Workflow.callMacro (workflow.js:793)
    at Workflow.callMacros (workflow.js:760)
    at Workflow._next (workflow.js:612)
    at workflow.js:323

What is going on?

Merudo commented 3 years ago

I did some tests - it seems the spell loses it's actor property along the way. With no actor field, item.isOwned returns false, and therefore the ownership test fails.

Merudo commented 3 years ago

Thanks to @tposney, I figured out how to do:

let macroActor = game.actors.get(args[0].actor._id); let macroItem = macroActor.items.get(args[0].item._id);

Summoner.placeAndSummonFromSpell(macroActor,macroItem, "Flaming Sphere");

However, I get the prompt for the spell slots twice. I wonder if there is a way to only show it once?

Merudo commented 3 years ago

Ok I managed to make it work using this code:

let macroActor = game.actors.get(args[0].actor._id);
let macroLevel = args[0].spellLevel;

Summoner.placeAndSummon(
  macroActor,
  "Flaming Sphere", 
  {
  actorData: { data: { 
        attributes: {spellLevel: macroLevel}
             }       }
  },
  { setSpellBonuses: true }
);
periodic commented 3 years ago

Interesting. So it looks like it worked once you passed in the actor, but for some reason the item.options.actor wasn't working? I've never pulled out the actor that way.

Thanks for debugging and putting your findings here.

I'm not sure about the double spell dialog. I notice you have a args[0].spellLevel. Do you have any other mods that affect how item macros are invoked? My testing showed that having an item macro totally replaces the spell invocation, including the spell dialog. Maybe itemMacro was updated and I need to update my instructions to handle that.

Merudo commented 3 years ago

In my case I disabled the Item Macro hooks, and instead use the On Macro Use option in Midi-QoL.

That resulted in a duplicated spell dialog, until I changed placeAndSummonFromSpell to placeAndSummon.

Also item.options.actor is an Item Macro function; it's not usable if the Item Macro is launched through Midi-QoL.