Esempio n. 1
0
        /// <summary>
        /// Returns a reference to an equipment agent based on the map object passed. Will assign the map cells position to the created agent.
        /// </summary>
        /// <param name="mapObject"></param>
        /// <param name="mapCell"></param>
        /// <returns></returns>
        private Equipment CreateEquipmentFromEquipmentObjectSubtype(MapObject mapObject, MapCell mapCell)
        {
            if (mapObject == null)
            {
                throw new ArgumentNullException("mapObject");
            }
            if (mapCell == null)
            {
                throw new ArgumentNullException("mapCell");
            }

            Equipment       equipment       = null;
            EquipmentObject equipmentObject = (EquipmentObject)mapObject;

            switch (equipmentObject.Subtype)
            {
            case EquipmentObjectType.SnackMachine:
                equipment = agentFactory.CreateSnackMachine(TimeSpan.Zero, mapCell.WorldPosition);
                break;

            case EquipmentObjectType.SodaMachine:
                equipment = agentFactory.CreateSodaMachine(TimeSpan.Zero, mapCell.WorldPosition);
                break;

            case EquipmentObjectType.OfficeDesk:
                equipment = agentFactory.CreateOfficeDesk(TimeSpan.Zero, mapCell.WorldPosition);
                break;

            case EquipmentObjectType.WaterFountain:
                equipment = agentFactory.CreateWaterFountain(TimeSpan.Zero, mapCell.WorldPosition);
                break;
            }

            return(equipment);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the proper map object layer based on the layer name such as collidables and path nodes.
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="orientation"></param>
        /// <returns></returns>
        private MapObjectLayer CreateObjectLayer(LayerContent layer, Orientation orientation)
        {
            if (layer == null)
            {
                throw new ArgumentNullException("layer");
            }

            ObjectLayerContent objectLayerContent = layer as ObjectLayerContent;

            MapObjectLayerType mapObjectLayerType;
            MapObjectType      mapObjectType;

            if (objectLayerContent.Name == "DeadZones")
            {
                mapObjectLayerType = MapObjectLayerType.DeadZone;
                mapObjectType      = MapObjectType.DeadZone;
            }
            else if (objectLayerContent.Name == "PathNodes")
            {
                mapObjectLayerType = MapObjectLayerType.PathNode;
                mapObjectType      = MapObjectType.PathNode;
            }
            else if (objectLayerContent.Name == "Equipment")
            {
                mapObjectLayerType = MapObjectLayerType.Equipment;
                mapObjectType      = MapObjectType.Equipment;
            }
            else
            {
                throw new Exception("Unknown map object layer type. Did you name your layer correctly? \"DeadZones\", \"PathNodes\", and \"Equipment\" are valid layers.");
            }

            MapObjectLayer mapObjectLayer = new MapObjectLayer(objectLayerContent.Name, mapObjectLayerType);

            foreach (ObjectContent objectContent in objectLayerContent.MapObjects)
            {
                if (mapObjectLayer.Type == MapObjectLayerType.PathNode)
                {
                    PathNode pathNode = new PathNode(objectContent.Name, objectContent.Bounds, orientation, objectContent.Properties);
                    mapObjectLayer.AddMapObject(pathNode);
                }
                else if (mapObjectLayer.Type == MapObjectLayerType.Equipment)
                {
                    EquipmentObjectType equipmentObjectType = GetEquipmentObjectType(objectContent);
                    EquipmentObject     equipmentObject     = new EquipmentObject(objectContent.Name, objectContent.Bounds, orientation, objectContent.Properties, equipmentObjectType);
                    mapObjectLayer.AddMapObject(equipmentObject);
                }
                else
                {
                    MapObject mapObject = new MapObject(objectContent.Name, objectContent.Bounds, orientation, mapObjectType, objectContent.Properties);
                    mapObjectLayer.AddMapObject(mapObject);
                }
            }

            return(mapObjectLayer);
        }