Ejemplo n.º 1
0
        /// <summary>
        /// Hides/shows point-of-interest pin
        /// </summary>
        /// <param name="item">Item associated with the point-of-interest pin</param>
        /// <param name="highlight">Flag indicating whether point-of-interest pin should be highlighted or unhighlighted</param>
        public static void HighlightPointOfInterestPin(this Map m, IMappable item, Boolean highlight)
        {
            MapLayer poiLayer = PoiLayer(m);

            if ((poiLayer != null) && (item != null))
            {
                // search for pin in the layer matching by id - some defensive programming here to not assume everything
                // in this layer is a point-of-interest pin (but it should be!)
                PointOfInterestPin poiPin = poiLayer.Children.Where((c) =>
                {
                    var p = c as PointOfInterestPin;
                    return((p != null) && (p.PointOfInterest.Id == item.Id));
                }).FirstOrDefault() as PointOfInterestPin;

                // if pin is found
                if (poiPin != null)
                {
                    // set highlight appropriately
                    poiPin.IsHighlighted = highlight;

                    // if it's highlighted, bring to top by removing and adding back in
                    if (highlight)
                    {
                        poiLayer.Children.Remove(poiPin);
                        poiLayer.Children.Add(poiPin);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public TDestination MapListDeepParallel <TSource, TDestination>(TSource source)
            where TDestination : class, new()
        {
            IMappable instance = Configuration.GetMapList <TSource, TDestination>();

            return(instance.ConvertToListMiltiTreadedDeepCopy(source) as TDestination);
        }
        /// <summary>
        /// Hides/shows point-of-interest pin
        /// </summary>
        /// <param name="item">Item associated with the point-of-interest pin</param>
        /// <param name="highlight">Flag indicating whether point-of-interest pin should be highlighted or unhighlighted</param>
        public static void HighlightPointOfInterestPin(this Map m, IMappable item, Boolean highlight)
        {
            MapLayer poiLayer = PoiLayer(m);
            if ((poiLayer != null) && (item != null))
            {
                // search for pin in the layer matching by id - some defensive programming here to not assume everything 
                // in this layer is a point-of-interest pin (but it should be!)
                PointOfInterestPin poiPin = poiLayer.Children.Where((c) =>
                {
                    var p = c as PointOfInterestPin;
                    return ((p != null) && (p.PointOfInterest.Id == item.Id));
                }).FirstOrDefault() as PointOfInterestPin;

                // if pin is found
                if (poiPin != null)
                {
                    // set highlight appropriately
                    poiPin.IsHighlighted = highlight;

                    // if it's highlighted, bring to top by removing and adding back in
                    if (highlight)
                    {
                        poiLayer.Children.Remove(poiPin);
                        poiLayer.Children.Add(poiPin);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void PathfindTo(MapPoint finalDestination)
        {
            Console.Clear();
            bool moveDone = false;

            while (_movementRemaining > 0 && !moveDone)
            {
                IMappable obstruction = Location.Map.Objects.FirstOrDefault(o =>
                                                                            MapPoint.IsPointOnLineSegment(this.Location, finalDestination, o.Location) &&
                                                                            o != this);
                var destination = obstruction != null ? obstruction.Location : finalDestination;

                string direction = Location.DirectionTo(destination);
                int    distance  = Location.DistanceTo(destination);

                // if distance is greater than movement remaining, only move up to remaining movement:
                Move($"{direction} {(distance <= _movementRemaining ? distance : _movementRemaining)}");

                // attempt to move around obstruction if present:
                if (obstruction != null && _movementRemaining >= 5)
                {
                    var openSpace = Location.Map.GetOpenSpaces(Location.GetAdjacentCoordinates())
                                    .RandomElement().ToMapPoint(Location.Map);
                    var tempLocation = Location.ShallowCopy;
                    Move($"{Location.DirectionTo(openSpace)} {5}");
                }
                else
                {
                    moveDone = true;
                }
            }
            Location.Map.PrintMap();
        }
Ejemplo n.º 5
0
 public void Set(IMappable mappable, Point position)
 {
     if (tilemap.ContainsPosition(position))
     {
         mappables[position.X, position.Y] = mappable;
     }
 }
Ejemplo n.º 6
0
        public void Update(IMappable building)
        {
            using (IDbConnection db = new SqlConnection(_configuration.ConnectionString))
            {
                db.Update <TownBuildingDto>(building.ToTownBuildingDto());

                if (building is IStorable)
                {
                    // Check if the inventory has changed and update it
                    var inventoryItemDtoList = db.Query <BuildingInventoryItemDto>("SELECT * FROM [BuildingInventory] WHERE BuildingId = @BuildingId", new { BuildingId = building.Id }).ToList();
                    foreach (var inventoryItem in ((IStorable)building).Inventory?.Items == null ? new List <InventoryItem>() : ((IStorable)building).Inventory.Items)
                    {
                        if (inventoryItemDtoList.Any(x => inventoryItem.ItemType.GetType().Name == x.ItemType) &&
                            inventoryItemDtoList.First(x => inventoryItem.ItemType.GetType().Name == x.ItemType).Quantity != inventoryItem.Quantity)
                        {
                            db.Update <BuildingInventoryItemDto>(inventoryItem.ToBuildingInventoryItemDto(building.Id));
                        }
                        else if (!inventoryItemDtoList.Any(x => inventoryItem.ItemType.GetType().Name == x.ItemType))
                        {
                            db.Insert <BuildingInventoryItemDto>(inventoryItem.ToBuildingInventoryItemDto(building.Id));
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public static TownBuildingDto ToTownBuildingDto(this IMappable building)
        {
            var buildingDto = new TownBuildingDto
            {
                Id           = building.Id,
                TownId       = building.TownId,
                XCoordinate  = building.XCoordinate,
                YCoordinate  = building.YCoordinate,
                Name         = building.Name,
                BuildingType = building.GetType().Name
            };

            if (building is IOwnable)
            {
                buildingDto.OwnerId   = ((IOwnable)building).OwnerId;
                buildingDto.IsForSale = ((IOwnable)building).IsForSale;
                buildingDto.Price     = ((IOwnable)building).Price;
            }

            if (building is WritableEntity)
            {
                buildingDto.ModifiedDate = ((WritableEntity)building).ModifiedDate;
                buildingDto.CreatedDate  = ((WritableEntity)building).CreatedDate;
            }

            return(buildingDto);
        }
Ejemplo n.º 8
0
        public TDestination MapDeep <TSource, TDestination>(TSource source) where TDestination : class, new()
        {
            IMappable instance = Configuration.GetMap <TSource, TDestination>();

            instance.Source = source;
            return(instance.ConvertToDeepCopy() as TDestination);
        }
Ejemplo n.º 9
0
        public TDestination MapList <TSource, TDestination>(TSource source)
            where TDestination : class, new()
        {
            IMappable instance = Configuration.GetMapList <TSource, TDestination>();

            return(instance.ConvertToList(source) as TDestination);
        }
Ejemplo n.º 10
0
 public static void MoveAwayFrom(IMoveable moveable, IMappable mapObject)
 {
     if (moveable.Position != null && mapObject.Position != null && OpenNeighbors(moveable).Any())
     {
         moveable.Move(OpenNeighbors(moveable).FirstOrDefault(p => MovementCost(moveable.Position,
                                                                                p, mapObject.Position) == GetMaxCost(moveable, mapObject)));
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a new push pin marking a point of interest on the map
        /// </summary>
        /// <param name="poi">Reference to an IMappable instance</param>
        public PointOfInterestPin(IMappable poi)
        {
            this.InitializeComponent();
            PointOfInterest = poi;

            // track label as a separate property, but it's populated on creation from the point-of-interest info
            Label = poi.Label;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// If <paramref name="service"/> doesn't implement <typeparamref name="T"/>, an exception is thrown.
 /// </summary>
 /// <param name="service">The service that must implement <typeparamref name="T"/>.</param>
 /// <typeparam name="T">The type that <paramref name="service"/> must implement.</typeparam>
 /// <returns></returns>
 /// <exception cref="FulcrumNotImplementedException">Thrown if <paramref name="service"/> doesn't implement <typeparamref name="T"/>.</exception>
 public static T GetImplementationOrThrow <T>(IMappable service) where T : IMappable
 {
     if (service is T implemented)
     {
         return(implemented);
     }
     throw new FulcrumNotImplementedException($"The service {service.GetType()} does not implement {typeof(T).Name}");
 }
Ejemplo n.º 13
0
        public void AddObject(IMappable obj)
        {
            List <IMappable> tempObjects = Objects;

            tempObjects.Add(obj);
            validateObjects(tempObjects);
            Objects.Add(obj);
        }
Ejemplo n.º 14
0
        public TDestination Map <TSource, TDestination>(TSource source, TDestination destination) where TDestination : class
        {
            IMappable instance = Configuration.GetMap <TSource, TDestination>();
            var       mapInfo  = Configuration.GetMapInfo <TSource, TDestination>();
            var       result   = instance.ConvertTo(source, destination) as TDestination;

            mapInfo.ExecuteCustomMappings(source, result);
            return(result);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates a new push pin marking a point of interest on the map
        /// </summary>
        /// <param name="poi">Reference to an IMappable instance</param>
        public PointOfInterestPin(IMappable poi)
        {
            this.InitializeComponent();
            PointOfInterest = poi;

            // track label as a separate property, but it's populated on creation from the point-of-interest info
            Label = poi.Label;

            this.PointerPressed += (s, e) => { OnSelected(new SelectedEventArgs(PointOfInterest)); };
        }
    public static T AutoMap <T>(this IMappable payLoad)
        where T : new()
    {
        ICustomMapContext <T>?context = CustomMapperHelpers <T> .MasterContext;

        if (context is null)
        {
            throw new CustomBasicException($"There was no mappings found at {typeof(T)}.  Try to use source generators to create it");
        }
        return(context.AutoMap(payLoad)); //decided to do away with the dictionary way of doing it to improve performance.
    }
Ejemplo n.º 17
0
        public static void Load(IMappable memory, string Filename)
        {
            int bank    = 0;
            int address = 0;

            if (!System.IO.File.Exists(Filename))
            {
                throw new System.IO.FileNotFoundException("Could not find Hex file \"" + Filename + "\"");
            }

            string[] lines = System.IO.File.ReadAllLines(Filename);

            foreach (string l in lines)
            {
                string mark     = l.Substring(0, 1);
                string reclen   = l.Substring(1, 2);
                string offset   = l.Substring(3, 4);
                string rectype  = l.Substring(7, 2);
                string data     = l.Substring(9, l.Length - 11);
                string checksum = l.Substring(l.Length - 2);

                switch (rectype)
                {
                // data row. The next n bytes are data to be loaded into memory
                case "00":
                    address = GetByte(offset, 0, 2);
                    for (int i = 0; i < data.Length; i += 2)
                    {
                        int b = GetByte(data, i, 1);
                        memory.WriteByte(bank + address, (byte)b);
                        address++;
                    }
                    break;

                // end of file - just ignore
                case "01":
                    break;

                // extended linear address
                // lower byte will populate the bank number.
                case "04":
                    bank = GetByte(data, 0, 2) << 16;
                    break;

                // extended linear start address
                // set the initial bank register value. Not used in the simulator.
                case "05":
                    break;

                default:
                    throw new NotImplementedException("Record type not implemented: " + rectype);
                }
            }
        }
Ejemplo n.º 18
0
        public static void LoadPlugins()
        {
            GameEngine.SayToServer(" - Scanning for plugins...");
            foreach (string dll in Directory.GetFiles(".", "*.dll"))
            {
                // Prevent snagging on self when running as deployed executable
                if (dll.Contains(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name))
                {
                    continue;
                }

                Assembly asm = Assembly.LoadFrom(dll);
                foreach (Type type in asm.GetTypes())
                {
                    if (type.GetInterface("IPluggable") == typeof(IPluggable))
                    {
                        IPluggable thisPlugin = Activator.CreateInstance(type) as IPluggable;
                        GameEngine.SayToServer($"{thisPlugin.Name}...");
                        AllPlugins.Add(thisPlugin);
                        if (type.GetInterface("IMappable") == typeof(IMappable))
                        {
                            IMappable mapPlugin = Activator.CreateInstance(type) as IMappable;
                            Mappers.Add(mapPlugin);
                        }
                        if (type.GetInterface("ISpawnable") == typeof(ISpawnable))
                        {
                            ISpawnable spawnPlugin = Activator.CreateInstance(type) as ISpawnable;
                            Spawners.Add(spawnPlugin);
                        }
                        if (type.GetInterface("IPlayerModifiable") == typeof(IPlayerModifiable))
                        {
                            IPlayerModifiable playerPlugin = Activator.CreateInstance(type) as IPlayerModifiable;
                            PlayerMods.Add(playerPlugin);
                        }
                        if (type.GetInterface("ICanOverrideAttackMethod") == typeof(ICanOverrideAttackMethod))
                        {
                            ICanOverrideAttackMethod combatPlugin = Activator.CreateInstance(type) as ICanOverrideAttackMethod;
                            AttackMod = combatPlugin;
                        }
                        if (type.GetInterface("ISpeakable") == typeof(ISpeakable))
                        {
                            ISpeakable speechMod = Activator.CreateInstance(type) as ISpeakable;
                            SpeechMods.Add(speechMod);
                        }
                        if (type.GetInterface("IFabricable") == typeof(IFabricable))
                        {
                            IFabricable templateMod = Activator.CreateInstance(type) as IFabricable;
                            TemplateMods.Add(templateMod);
                        }
                    }
                }
            }
            GameEngine.SayToServer("done.\n");
        }
Ejemplo n.º 19
0
 public void RemoveObject(IMappable obj)
 {
     if (Objects.Contains(obj))
     {
         Objects.Remove(obj);
     }
     else
     {
         Console.WriteLine("Map does not contain object.");
     }
 }
Ejemplo n.º 20
0
 public FileUploadController(
     IImportMedicFile importMedicFile,
     IMedicXmlParser medicXmlParser,
     IMappable mapper,
     MedicDataLocalization medicDataLocalization,
     IMedicLoggerService medicLoggerService,
     ICacheable medicCache)
 {
     ImportMedicFile       = importMedicFile ?? throw new ArgumentNullException(nameof(importMedicFile));
     MedicXmlParser        = medicXmlParser ?? throw new ArgumentNullException(nameof(medicXmlParser));
     Mapper                = mapper ?? throw new ArgumentNullException(nameof(mapper));
     MedicDataLocalization = medicDataLocalization ?? throw new ArgumentNullException(nameof(MedicBaseController));
     MedicLoggerService    = medicLoggerService ?? throw new ArgumentNullException(nameof(medicLoggerService));
     MedicCache            = medicCache ?? throw new ArgumentNullException(nameof(medicCache));
 }
Ejemplo n.º 21
0
        public void RemoveDeatAtPosition(Point pos)
        {
            IMappable o = Get(pos);

            if (o != null)
            {
                if (o.IsDead)
                {
                    Remove(o);
                }
                else
                {
                    tilemap.ToUpdate.Add(o);
                }
            }
        }
Ejemplo n.º 22
0
        // synchronize changes in the view model collection with the map push pins
        void Results_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            // the synchronization requires a reference to a Bing.Maps object on the Main page
            if (Map == null)
            {
                throw new System.NullReferenceException("An instance of Bing.Maps is required here, yet the Map property was found to be null.");
            }

            // only additions and wholesale reset of the ObservableCollection are currently supported
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (var item in e.NewItems)
                {
                    IMappable mapItem = (IMappable)item;

                    PointOfInterestPin poiPin = new PointOfInterestPin(mapItem);
                    poiPin.Selected += (s, e2) =>
                    {
                        MappableListView.SelectedItem = MappableListView.Items.Where((c) => (c as IMappable).Id == e2.PointOfInterest.Id).FirstOrDefault();
                    };

                    Map.AddPointOfInterestPin(poiPin, mapItem.Position);
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                Map.ClearPointOfInterestPins();
                break;

                // case NotifyCollectionChangedAction.Remove:
                //
                // TODO: (optional) if your application allows items to be selectively removed from the view model
                //       code to remove a single associated push pin will be required.
                //
                //
                //
                // break;


                // not implemented in this context
                // case NotifyCollectionChangedAction.Replace:
                // case NotifyCollectionChangedAction.Move:
            }
        }
Ejemplo n.º 23
0
        public static IMappable Map(this IMappable sourceMap, IMappable destMap)
        {
            destMap.GetType().GetFields().ToList().ForEach(
                            f =>
                            {
                                f.SetValue(destMap, sourceMap.GetType().GetField(f.Name)?.GetValue(sourceMap));
                            }
                );

            destMap.GetType().GetProperties().ToList().ForEach(
                            p =>
                            {
                                p.SetValue(destMap, sourceMap.GetType().GetProperty(p.Name)?.GetValue(sourceMap));
                            }
                );

            return destMap;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Synchronizes changes to the ApiViewModel's Results collection. The elements of that collection are assumed
        /// to implement IMappable (see the APIMASH_TomTom.TomTomCameraViewModel implementation for a sample reference).
        /// This code should require no changed regardless as long as the items in the Results collection implement IMappable.
        /// </summary>
        void Results_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            // only additions and wholesale reset of the ObservableCollection are currently supported
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (var item in e.NewItems)
                {
                    IMappable mapItem = (IMappable)item;

                    PointOfInterestPin poiPin = new PointOfInterestPin(mapItem);
                    poiPin.Tap += async(s, e2) =>
                    {
                        TheMap.HighlightPointOfInterestPin(DefaultViewModel.SelectedItem, false);
                        TheMap.HighlightPointOfInterestPin(poiPin.PointOfInterest, true);

                        await ProcessSelectedItem(item);
                    };

                    TheMap.AddPointOfInterestPin(poiPin, mapItem.Position);
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                TheMap.ClearPointOfInterestPins();
                break;

                // case NotifyCollectionChangedAction.Remove:
                //
                // TODO: (optional) if your application allows items to be selectively removed from the view model
                //       code to remove a single associated push pin will be required.
                //
                //
                //
                // break;


                // not implemented in this context
                // case NotifyCollectionChangedAction.Replace:
                // case NotifyCollectionChangedAction.Move:
            }
        }
Ejemplo n.º 25
0
        public void PathfindTo(IMappable target)
        {
            bool moveDone = false;

            while (_movementRemaining > 0 && !moveDone)
            {
                // Console.WriteLine("pathfinding");
                IMappable obstruction = Location.Map.Objects.FirstOrDefault(o =>
                                                                            MapPoint.IsPointOnLineSegment(this.Location, target.Location, o.Location) &&
                                                                            o != this && o != target);
                MapPoint destination = (obstruction == null ? target : obstruction).Location;

                string direction = Location.DirectionTo(destination);

                // move up to 5 feet if item, up to attack range if entity:
                int distance = (Location.DistanceTo(destination) * 5) - (target is Entity ? _attackRangeFeet : 5);

                // if distance is greater than movement remaining, only move up to remaining movement:
                Move($"{direction} {(distance < _movementRemaining ? distance : _movementRemaining)}");
                Location.Map.PrintMap();
                PressAnyKeyToContinue();
                Console.Clear();

                // attempt to move around obstruction if present:
                if (obstruction != null && _movementRemaining >= 5)
                {
                    Console.WriteLine("obstruction encounted");
                    var openSpace = Location.Map.GetOpenSpaces(Location.GetAdjacentCoordinates())
                                    .RandomElement().ToMapPoint(Location.Map);
                    var tempLocation = Location.ShallowCopy;
                    Move($"{Location.DirectionTo(openSpace)} {5}");
                    Location.Map.PrintMap();
                    PressAnyKeyToContinue();
                    Console.Clear();
                }
                else
                {
                    moveDone = true;
                }
            }
        }
Ejemplo n.º 26
0
        private static void ReadCLPRFiles(IMappable mapper, DbContextOptionsBuilder <MedicContext> builder, string directoryPath)
        {
            string invalidCLPRFileMessage = "Invalid CLPR file.";


            string[]        files          = Directory.GetFiles(directoryPath, "*.xml");
            IMedicXmlParser medicXmlParser = new DefaultMedicXmlParser(new GetXmlParameters());

            int counter = 1;

            foreach (string file in files)
            {
                using FileStream sr = new FileStream(file, FileMode.Open, FileAccess.Read);

                CLPR.HospitalPractice clprFile = medicXmlParser.ParseXML <CLPR.HospitalPractice>(sr);

                if (clprFile != default)
                {
                    HospitalPractice hospitalPracticeEntity = mapper.Map <HospitalPractice, CLPR.HospitalPractice>(clprFile);

                    if (hospitalPracticeEntity != default)
                    {
                        using MedicContext medicContext        = new MedicContext(builder.Options);
                        using IImportMedicFile importMedicFile = new ImportMedicFile(medicContext);

                        importMedicFile.ImportHospitalPractice(hospitalPracticeEntity);

                        consoleWriter.Notify($"{file} - imported, ({counter++}/{files.Length}).");
                    }
                    else
                    {
                        consoleWriter.Notify(invalidCLPRFileMessage);
                    }
                }
                else
                {
                    consoleWriter.Notify(invalidCLPRFileMessage);
                }
            }
        }
Ejemplo n.º 27
0
        public void Engage(IMappable target)
        {
            int range = target is Entity ? _attackRangeFeet / 5 : 1;

            while (_movementRemaining > 0)
            {
                if (Location.InRangeOf(target.Location, range))
                {
                    if (target is Entity)
                    {
                        Attack((target as Entity).Name);
                    }
                    else if (target is Item)
                    {
                        TakeItem((target as Item).Name);
                    }
                    break;
                }
                else
                {
                    PathfindTo(target);
                }
            }
        }
Ejemplo n.º 28
0
 public BonusPoolController(IBonusPoolService service, IMappable <ApiMapperProfile> mappable)
 {
     _service  = service;
     _mappable = mappable;
 }
Ejemplo n.º 29
0
 public object Ap(IMappable m)
 {
     return(m.Map(Value));
 }
 public ItemSelectedEventArgs(object newItem, object oldItem)
 {
     NewItem = newItem as IMappable;            
     OldItem = oldItem as IMappable;
 }
Ejemplo n.º 31
0
 private void DrawOverhead(IMappable mappable, Point pos, Graphics render)
 {
     render.DrawString(mappable.Overhead, pos);
 }
Ejemplo n.º 32
0
 public void SetTo(IMappable to)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Creates a new push pin marking a point of interest on the map
        /// </summary>
        /// <param name="poi">Reference to an IMappable instance</param>
        public PointOfInterestPin(IMappable poi)
        {
            this.InitializeComponent();
            PointOfInterest = poi;

            // track label as a separate property, but it's populated on creation from the point-of-interest info
            Label = poi.Label;

            this.PointerPressed += (s, e) => { OnSelected(new SelectedEventArgs(PointOfInterest)); };
        }
Ejemplo n.º 34
0
 public SelectedEventArgs(IMappable poi) 
 { 
     PointOfInterest = poi; 
 }
Ejemplo n.º 35
0
 public void SetFrom(IMappable @from)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Creates a new push pin marking a point of interest on the map
        /// </summary>
        /// <param name="poi">Reference to an IMappable instance</param>
        public PointOfInterestPin(IMappable poi)
        {
            this.InitializeComponent();
            PointOfInterest = poi;

            // track label as a separate property, but it's populated on creation from the point-of-interest info
            Label = poi.Label;
        }