/// <summary> /// Completes the transfer of an object to a new container /// </summary> /// <param name="containerObject">The container to which the object will be transferred</param> public void In(ContainerObject containerObject) { if (!ReferenceEquals(_avatar, _objectToMove.ParentContainerObject)) { throw new LawsOfPhysicsViolationException("You do not have telekinesis! You need to pick the item up first."); } _avatar.Transfer(_objectToMove).To(containerObject); }
/// <summary> /// Attempts to fill the container with beer /// </summary> /// <param name="container"></param> public void Into(ContainerObject container) { IEnumerable<Guid> idsForObjectsBeingHeld = _avatar.Contents.Select(x => x.ObjectId); IEnumerable<Guid> containerObjectIds = new[] { container }.Select(x => x.ObjectId); bool tryingToUseContainerNotBeingHeld = containerObjectIds.Except(idsForObjectsBeingHeld).Any(); if (tryingToUseContainerNotBeingHeld) { throw new LawsOfPhysicsViolationException("You do not have telekinesis! You need to pick the item(s) up first."); } _fridge.DispenseBeerInto(container); }
/// <summary> /// Completes the transfer of an object to a new container /// </summary> /// <param name="newContainerObject">The container to which the object will be transferred</param> public void To(ContainerObject newContainerObject) { ContainerObject oldContainerObject = _objectToMove.ParentContainerObject; if (ReferenceEquals(oldContainerObject, newContainerObject) || (newContainerObject == null && oldContainerObject == null)) { throw new LawsOfPhysicsViolationException("Can't transfer this item to the same container more than once."); } if (oldContainerObject != null) { if (oldContainerObject is ICanBeLocked) { ICanBeLocked lockableContainer = oldContainerObject as ICanBeLocked; if (lockableContainer.IsLocked) { throw new LockedException("The item you want to pick up is locked inside a container. Sorry!"); } } oldContainerObject.InternalContainer.RemoveTheseObjects(x => x.ObjectId == _objectToMove.ObjectId); } _objectToMove.ParentContainerObject = newContainerObject; if (newContainerObject != null) { newContainerObject.InternalContainer.AddObject(_objectToMove); } }