public override void Execute() { base.Execute(); MapManager mapManager = Locator.Get <MapManager>(); Inventory inventory = Actor.GetComponent <Inventory>(); Item itemComponent = Item.GetComponent <Item>(); if (inventory != null && itemComponent != null) { InventorySlotType slot = itemComponent.ItemInfo.InventorySlot; Item presentItem = inventory.GetItem(slot); if (presentItem != null) { inventory.RemoveItem(presentItem); Entity itemEntity = presentItem.GetComponent <Entity>(); mapManager.AddItem(itemEntity, Item.CellTransform.Position); } mapManager.RemoveItem(Item, Item.CellTransform.Position); inventory.AddItem(itemComponent); } }
public void Drop(int2 dropSpot) { Entity entityToDrop = null; if (alwaysDropTable.Count > 0) { entityToDrop = entityManager.Spawn(alwaysDropTable[0].EntityName); } if (entityToDrop == null) { int totalWeight = 0; for (int i = 0; i < lootTable.Count; i++) { totalWeight += lootTable[i].Weight; } int cumulativeWeight = 0; int randomNumber = Random.Range(0, totalWeight); string entityName = null; int j = 0; while (entityName == null && j < lootTable.Count) { cumulativeWeight += lootTable[j].Weight; if (cumulativeWeight > randomNumber) { entityName = lootTable[j].EntityName; } j++; } if (string.IsNullOrEmpty(entityName) == false) { entityToDrop = entityManager.Spawn(entityName); } } if (entityToDrop != null) { if (entityToDrop.GetComponent <Item>() != null) { mapManager.AddItem(entityToDrop, dropSpot); } else if (entityToDrop.GetComponent <Actor>() != null) { mapManager.AddActor(entityToDrop, dropSpot); } else { mapManager.AddProp(entityToDrop, dropSpot); } DOTween.Sequence() .Append ( entityToDrop.transform.DOLocalMoveY(entityToDrop.transform.localPosition.y + 1f, 0.3f) .SetEase(Ease.OutBack) ) .Append ( entityToDrop.transform.DOLocalMoveY(entityToDrop.transform.localPosition.y, 0.4f) .SetEase(Ease.OutBounce) ); } }