private void ExecuteTake(ITaker unit, TakeAction action) { var obj = State.FindObject(action.ObjectId); if (obj == null) { throw new BadActionException($"Unit {unit} cannot take a non-existing object {action.ObjectId}"); } if (!IsAdjacent((Unit)unit, obj)) { throw new BadActionException($"Unit {unit} not adjacent to the object it desires to take {obj}"); } if (obj is ITransferable transferable) { if (transferable.HasOwner) { throw new BadActionException($"Unit {unit} cannot take a currently-owned object {action.ObjectId}"); } unit.Take(transferable); transferable.TransferTo(((Unit)unit).Id); } else { throw new BadActionException($"Unit {unit} cannot take a non-transferable object {action.ObjectId}"); } }
public virtual void Accept(ITaker <A> ia) { ia.Take(this); }