Exemple #1
0
        /// <summary>
        /// Drop first item in inventory back into the world
        /// </summary>
        /// <param name="world"></param>
        public void DropItem(World world)
        {
            PointF dropLocation = GetLocationInFrontOfPlayer();
            // Check if item can be dropped on target from dropLocation
            bool isLand = world.getTerraintile(dropLocation).IsWalkable;
            bool hasSolidEntitiesOnTarget = world.checkCollision(this, dropLocation);
            List<Entity> entitiesOnTerrainTile = world.getEntitiesOnTerrainTile(location);
            List<Entity> entitiesOnTargetTerrainTile = world.getEntitiesOnTerrainTile(dropLocation);
            bool hasWaterlilyOnTarget = entitiesOnTargetTerrainTile.Exists(e => e.getSpriteID() == (int) SPRITES.waterlily);

            // If no item exists in inventory or
            //      there is a solid target on dropLocation or
            //      targettile is not land, return
            if (!Inventory.Any() || hasSolidEntitiesOnTarget ||
                (!isLand && !hasWaterlilyOnTarget))
                return;
            // If item is key, lock door
            if (Inventory[0].Entity is Key)
            {
                // If player is standing in a door, cancel action
                if (entitiesOnTerrainTile.Exists(e => e is Door))
                    return;
                world.LockDoor((Key)Inventory[0].Entity);
            }

            // Set droplocation on item
            Inventory[0].Entity.setLocation(dropLocation);
            // Push item in world objects list
            world.getEntities().Add(Inventory[0].Entity);
            // Remove item from inventory
            Inventory.RemoveAt(0);
        }