//The main function! This EXACT coroutine will be executed, even across frames. //See GameAction.cs for more information on how this function should work! public override IEnumerator TakeAction() { if (caller.inventory == null) { Debug.LogError($"{caller.name} cannot drop without an inventory! Skipping turn to prevent deadlock.", caller); caller.energy = 0; yield break; } if (indices.Count == 0) { Debug.Log($"{caller.name} tried to drop no items."); yield break; } //Collect all removables, dump them in one go List <int> needsToBeRemoved = new List <int>(); foreach (int index in indices) { if (index < 0 || index > caller.inventory.capacity) { continue; } //For each item, check if it's equipped. If so, remove it. ItemStack item = caller.inventory[index]; if (item == null) { continue; } EquipableItem equip = item.held[0].equipable; if (equip && equip.isEquipped) { needsToBeRemoved.Add(index); } } if (needsToBeRemoved.Count > 0) { RemoveAction secondaryAction = new RemoveAction(needsToBeRemoved); secondaryAction.Setup(caller); while (secondaryAction.action.MoveNext()) { yield return(secondaryAction.action.Current); } } foreach (int index in indices) { caller.inventory.Drop(index); } caller.energy -= 100; caller.inventory.GetFloor().Collapse(); }
//The main function! This EXACT coroutine will be executed, even across frames. //See GameAction.cs for more information on how this function should work! public override IEnumerator TakeAction() { if (!caller.equipment.CanEquip(itemIndex, equipIndex)) { yield break; } //Quick check: Are we trying to do something redundant? if (!caller.equipment.RequiresReequip(itemIndex, equipIndex)) { Debug.Log("You can't re-equip an item to its own slot. Why would you want to do this?"); yield break; } //We can attempt to move forward here! List <int> neededSlots = caller.equipment.SlotsNeededToEquip(itemIndex, equipIndex); ItemStack item = caller.inventory[itemIndex]; if (item.held[0].equipable.isEquipped) { RemoveAction remove = new RemoveAction(item); remove.Setup(caller); while (remove.action.MoveNext()) { yield return(remove.action.Current); } } if (neededSlots.Count > 0) { //We need to remove those slots! RemoveAction remove = new RemoveAction(neededSlots); remove.Setup(caller); while (remove.action.MoveNext()) { yield return(remove.action.Current); } } //We can now Equip! //TODO: Make this energy cost item dependent caller.equipment.Equip(itemIndex, equipIndex); caller.energy -= 100; }