I've been working on an auto-win system (Earthbound-style) that's turning out to be more difficult than I thought, possibly because I can't work the methods correctly. The specific issue I'm having is dropping Combatants' inventory items in the field without entering a battle, wherein I can get some to drop but not all.

Context:
Combatants have a script (FieldEnemy) that checks if the player group meets the requirements of an automatic victory should they interact and otherwise trigger a battle (Turn-Based). When the conditions are met, the CombatantController component is disabled to prevent a battle taking place and sets a private variable (aw) to 'true' - all this is working fine and is not the focus of this question.
When the player touches an enemy in this state, it determines what the player would otherwise have earned from the battle (currency, exp) and grants them, as well as dropping every item in the enemy's CombatantController group members' inventories.

Code:
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player" && aw) // checks if the auto-win conditions are met
{
if (!dropped) // a private variable to ensure no repeated activations
{
ORK.GlobalEvents.Get(0).Call(gameObject); // global event to 'kill' the enemy in the field
int cash = 0; int xp = 0; // initialise 'totals' to be added
List<IShortcut> list = new List<IShortcut>(); // list of items to be dropped

foreach (Combatant c in troop)
{
cash += c.Inventory.GetMoney(0); xp += c.Status[9].GetValue(); // track totals

// Fill 'list' with the currently iterating combatant's inventory
c.Inventory.GetAll(false, false, true, false, true, false, false, false, -1, true, ref list);

foreach (IShortcut item in list)
{
print(item.GetName()); // debugging: make sure the entire inventory is listed
c.Inventory.Drop(item, 1, false, false); // drop the item for the player to collect
}
}

foreach (Combatant pc in player_group)
{
// Grant each ally the total EXP gain only showing one batch of flying text
if (pc.ID == 0)
pc.Status[9].AddValue(xp, false, false, true, false, true, false, null);
else
pc.Status[9].AddValue(xp, false, false, true, false, false, false, null);
}
ORK.Game.ActiveGroup.Inventory.AddMoney(0, cash, true, false); // gain currency total
dropped = true; // prevent repeated activations
}
}
}
What usually happens is that when an enemy is 'auto-defeated', it SHOULD be dropping several items (as determined in the print call during tests) but only one item collecter is created (containing only one item), and occasionally - though usually after one has already been generated - won't drop anything at all.

I've tried dropping items one at a time and dropping an entire Combatant's inventory list at once but results don't differ. Am I misusing the drop method or is there more to it than I think? I've looked through the API documentation and struggled with a lot of different uses and variations and I can't find anything that contradicts my assumptions.
  • edited January 2020
    Hm, that's strange ... the items do have a prefab set up, I assume?

    There's a Drop function in the inventory that takes the item list as parameter and drops them all - it's the same that's used by the Drop Items node and just calls the function you're using for each item.
    I haven't tested your code, but I've just tested that event node, and that works fine.

    Also, you can pass on -1 (instead of 1) to drop the actual quantity of the item, instead of just 1 :)

    Edit: Are you using individual or group inventory? If you're using group inventory, going through the whole troop would be useless, as the first already dropped the whole inventory.
    Post edited by gamingislove on
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thank you for the quantity tip! And I am using individual group inventories.
    The item prefabs are set up, I've only been testing with the one item for the moment so haven't even encountered a situation where it would have come up yet.
    As I said in my original post, I have tried dropping the whole list at once. To be sure I've tested it again and still had the same issue - only one item prefab is dropped, containing a single item, and occasionally for no observable reason drop nothing at all.
    I thought it might be an issue with calling the drop method multiple times in a single frame, so I tried putting the iteration through a coroutine that waited briefly after each drop (and after each list drop) but no change.

    I have considered using an Event to drop the inventory, a Select Items node could store the combatants' inventories but I found the Drop Items node could only drop specific items rather than any saved data, is there a workaround for that I'm not seeing?
  • Ah, sorry, I meant the Remove From Inventory node - that one also supports selected data and drops the items. The Drop Items node only drops defined items and has nothing to do with inventory items :)
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • I've only just had the chance to test it today, a Remove From Inventory node works wonderfully! The only issue I'm still having with it is that the physics bounce the item prefabs around a bit, but that's an issue that comes with any quickfire prefab generation. I'm sure there's a workaround someone's figured somewhere.
    Thank you very much!
Sign In or Register to comment.