Inheritance: GameAction
示例#1
0
        public void PickupResolveAddsToInventory()
        {
            Mock<IAtlas> atlas = new Mock<IAtlas>();
            Mock<GameActor> actor = new Mock<GameActor>();
            Mock<ICanPickGameObject> picker = actor.As<ICanPickGameObject>();
            picker.Setup(x => x.AddToInventory(It.IsAny<IPickableGameActor>()));

            Mock<GameActor> targetActor = new Mock<GameActor>();
            targetActor.As<IPickableGameActor>();

            PickUp pickUp = new PickUp(actor.Object);

            // Act
            pickUp.Resolve(new GameActorPosition(targetActor.Object, new Vector2(), LayerType.ObstacleInteractable), atlas.Object, It.IsAny<ITilesetTable>());

            // Assert
            picker.Verify(x => x.AddToInventory(It.IsAny<IPickableGameActor>()));
        }
示例#2
0
        private bool PerformPickup(IAtlas atlas, ITilesetTable tilesetTable)
        {
            // check tile in front of
            List<GameActorPosition> targets = GetInteractableTilesInFrontOf(atlas);
            // if no tile, check objects
            if (targets.Count == 0)
            {
                targets = GetInteractableObjectsInFrontOf(atlas);
            }
            if (targets.Count == 0) return false;

            foreach (GameActorPosition target in targets)
            {
                IPickableGameActor interactableTarget = target.Actor as IPickableGameActor;
                if (interactableTarget == null) continue;
                GameAction pickUpAction = new PickUp(this);
                interactableTarget.PickUp(atlas, pickUpAction, target.Position, tilesetTable);

                RemoveSpeed(target);
                return true;
            }
            return false;
        }