Beispiel #1
0
        public override void Execute()
        {
            if (!(Actor is AbstractPlayer))
            {
                return;
            }

            AbstractPlayer player       = (AbstractPlayer)Actor;
            MapBlock       currentBlock = player.Position;

            if (currentBlock == null || currentBlock.Item == null)
            {
                throw new NoItemToPickUpException(player);
            }
            else if (currentBlock.Item is AbstractInventoryItem)
            {
                // normal item, just pick it up
                if (player.IsInventoryFull())
                {
                    throw new InventoryIsFullException(player);
                }

                player.AddItemToInventory((AbstractInventoryItem)(currentBlock.PickUpItem()));
            }
            else if (currentBlock.Item is AbstractWeapon)
            {
                // weapon
                AbstractWeapon oldWeapon = player.SwapWeapon((AbstractWeapon)(currentBlock.PickUpItem()));
                currentBlock.Item = oldWeapon;
            }
            else if (currentBlock.Item is AbstractArmor)
            {
                // armor
                AbstractArmor oldArmor = player.SwapArmor((AbstractArmor)(currentBlock.PickUpItem()));
                currentBlock.Item = oldArmor;
            }
            else
            {
                throw new PickUpUnknownItemException(player, currentBlock.Item);
            }
        }