public override GraphicsEngineObjects.Abstract.ActionFeedback[] PerformAction(ActionType actionType, Actor actor, object[] args)
{
if (actionType == ActionType.TAKE)
{
if (Math.Abs(actor.MapCharacter.Coordinate - this.Coordinate) < 2)
{
if (actionType == ActionType.TAKE)
{
//take it
this.Coordinate = new MapCoordinate(999, 999, 0, MapType.CONTAINER); //Dummy - this will cause the block to reject and delete it
//Is the item stackable ?
if (this.Stackable)
{
//Do we have an item with the same name in the inventory?
var item = actor.Inventory.Inventory.GetObjectsByGroup(this.Category).Where(g => g.Name.Equals(this.Name)).FirstOrDefault();
if (item != null)
{
//Instead we increment the total in that item in the inventory
item.TotalAmount++;
}
else
{
actor.Inventory.Inventory.Add(this.Category, this);
this.InInventory = true;
}
}
else
{
actor.Inventory.Inventory.Add(this.Category, this);
this.InInventory = true;
}
return new ActionFeedback[1] { new LogFeedback(InterfaceSpriteName.MAN, Color.Black, "You pick up the " + this.Name) };
}
}
}
else if (actionType == ActionType.DROP)
{
//Drop it.
//Since we can't access GameState from out here, we'll need to use an ActionFeedback
this.Coordinate = actor.MapCharacter.Coordinate;
this.InInventory = false;
return new ActionFeedback[1] { new DropItemFeedback() { ItemToDrop = this } };
}
else if (actionType == ActionType.EQUIP && this.IsEquippable && this.EquippableLocation.HasValue)
{
//Equip it
this.IsEquipped = true;
//Equip the item
List<EquipmentLocation> possibleLocation = new List<EquipmentLocation>();
//Is this a ring ? - they have two places where they can fit
if (this.EquippableLocation == EquipmentLocation.RING)
{
possibleLocation.Add(EquipmentLocation.RING1);
possibleLocation.Add(EquipmentLocation.RING2);
}
else
{
possibleLocation.Add(this.EquippableLocation.Value);
}
EquipmentLocation? clearLocation = null;
//So, do we have a clear area?
foreach (var possible in possibleLocation)
{
if (!actor.Inventory.EquippedItems.ContainsKey(possible))
{
clearLocation = possible;
break;
}
}
if (!clearLocation.HasValue)
{
//We need to move the existing item
actor.Inventory.EquippedItems[possibleLocation[0]].IsEquipped = false;
actor.Inventory.EquippedItems.Remove(possibleLocation[0]);
clearLocation = possibleLocation[0];
}
//And put the item there
this.IsEquipped = true;
actor.Inventory.EquippedItems.Add(clearLocation.Value, this);
}
else if (actionType == ActionType.UNEQUIP && this.IsEquipped)
{
this.IsEquipped = false;
//Find the item and remove it from the inventory
var item = actor.Inventory.EquippedItems.First(kvp => kvp.Value == this);
actor.Inventory.EquippedItems.Remove(item.Key);
}
else
{
return base.PerformAction(actionType, actor, args);
}
return new ActionFeedback[0] { };
}