protected override RunStatus Run(object context)
        {
            RunStatus result;

            if (!base.Fighter.CanMove())
            {
                result = RunStatus.Failure;
            }
            else
            {
                Lozenge lozenge = new Lozenge(0, (byte)base.Fighter.MP);
                Cell[]  array   = (
                    from entry in lozenge.GetCells(base.Fighter.Cell, base.Fighter.Fight.Map)
                    where base.Fighter.Fight.IsCellFree(entry)
                    select entry).ToArray <Cell>();
                if (array.Length == 0)
                {
                    result = RunStatus.Failure;
                }
                else
                {
                    System.Random random          = new System.Random();
                    Cell          destinationCell = array[random.Next(array.Length)];
                    MoveAction    moveAction      = new MoveAction(base.Fighter, destinationCell);
                    result = moveAction.YieldExecute(context);
                }
            }
            return(result);
        }
Example #2
0
        public void sink(int PM)
        {
            zone = new Lozenge(0, (byte)PM);
            List <Cell> cells   = zone.GetCells(Fight.finder.matrix[Player.PlayerBaseInformations.CellId], Fight.finder).ToList();
            Cell        farCell = cells.OrderBy(placementCell => Fight.GetEnnemies().Select(fighter => Fight.finder.matrix[fighter.CellId]).ToList().Min(cell => cell.ManhattanDistanceTo(placementCell))).FirstOrDefault();

            MoveToCell((short)farCell.Id);
            mBrain.Fight.mHost.SendMessage(new ShowCellMessage(Player.PlayerBaseInformations.Id, (ushort)farCell.Id), Engine.Enums.DestinationEnum.CLIENT);
        }
Example #3
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     // need to set the allowed lines for the dragging lozenge
     // only do this once
     if (!flag)
     {
         Lozenge lozenge = ResourcesClient.Controls.Utility.Helper.FindVisualChild <Lozenge>(canvas);
         lozenge.AllowedLines = allowedLines;
         flag = true;
     }
     base.OnRender(drawingContext);
 }
Example #4
0
        public void flee(int PM)
        {
            if (Player == null)
            {
                return;
            }
            zone = new Lozenge(0, (byte)PM);
            Cell        farCell;
            List <Cell> cells = zone.GetCells(Fight.finder.matrix[Player.PlayerBaseInformations.CellId], Fight.finder).ToList();

            farCell = cells.OrderBy(placementCell => Fight.GetEnnemies().Select(fighter => Fight.finder.matrix[fighter.CellId]).ToList().Min(cell => cell.ManhattanDistanceTo(placementCell))).LastOrDefault();
            MoveToCell((short)farCell.Id);
        }
Example #5
0
        public Cell[] GetMovementCells(int mp)
        {
            if (mp <= 0)
            {
                return(new Cell[0]);
            }

            if (mp > 63)
            {
                return(Fight.Map.Cells);
            }

            var circle = new Lozenge(0, (byte)mp);

            return(circle.GetCells(Fighter.Cell, Fight.Map));
        }
Example #6
0
        public void RandomMapMove()
        {
            Lozenge lozenge = new Lozenge(1, 4);
            short   cellId  = lozenge.GetCells((short)this.CellId, Map).Where((short entry) => Map.Walkable((ushort)entry)).Random();

            if (cellId != 0)
            {
                Pathfinder pathfinder = new Pathfinder(Map, (short)this.CellId, cellId);
                var        cells      = pathfinder.FindPath();

                if (cells != null && cells.Count > 0)
                {
                    cells.Insert(0, (short)this.CellId);
                    this.Move(cells);
                }
            }
        }
Example #7
0
        private void MoveFar()
        {
            var ennemies = m_character.GetOpposedTeam().Fighters;

            var shape         = new Lozenge(0, (byte)m_character.Stats.CurrentMP);
            var possibleCells = shape.GetCells(m_character.Cell, m_character.Map);
            var orderedCells  = from cell in possibleCells
                                where m_character.Fight.IsCellWalkable(cell, false, m_character.Cell)
                                orderby ennemies.Sum(x => cell.ManhattanDistanceTo(x.Cell)) descending
                                select cell;

            var dest = orderedCells.FirstOrDefault();

            if (dest == null)
            {
                return;
            }

            m_character.Move(dest);
        }
 public Cell[] GetMovementCells(int mp)
 {
     Cell[] result;
     if (mp <= 0)
     {
         result = new Cell[0];
     }
     else
     {
         if (mp > 63)
         {
             result = this.Fight.Map.Cells;
         }
         else
         {
             Lozenge lozenge = new Lozenge(0, (byte)mp);
             result = lozenge.GetCells(this.Fighter.Cell, this.Fight.Map);
         }
     }
     return(result);
 }
Example #9
0
        protected override RunStatus Run(object context)
        {
            if (!Fighter.CanMove())
            {
                return(RunStatus.Failure);
            }

            var lozenge = new Lozenge(0, (byte)Fighter.MP);
            var cells   = lozenge.GetCells(Fighter.Cell, Fighter.Fight.Map).Where(entry => Fighter.Fight.IsCellFree(entry)).ToArray();

            if (cells.Length == 0)
            {
                return(RunStatus.Failure);
            }

            var rand = new Random();
            var cell = cells[rand.Next(cells.Length)];

            var moveAction = new MoveAction(Fighter, cell);

            return(moveAction.YieldExecute(context));
        }
Example #10
0
        //   [StartupInvoke(StartupInvokePriority.Modules)]
        public static void ApplyFix()
        {
            logger.Gray("Fixing Map Placement...");

            List <PlacementPattern> patterns = new List <PlacementPattern>();
            Dictionary <PlacementPattern, string> patternsNames = new Dictionary <PlacementPattern, string>();

            foreach (string file in Directory.EnumerateFiles(PlacementPatternDirectory, "*.xml", SearchOption.AllDirectories))
            {
                try
                {
                    PlacementPattern pattern = (PlacementPattern)File.ReadAllText(file).XMLDeserialize(typeof(PlacementPattern));

                    if (SortByComplexity)
                    {
                        PlacementComplexityCalculator calc = new PlacementComplexityCalculator(pattern.Blues.Concat(pattern.Reds).ToArray <System.Drawing.Point>());
                        pattern.Complexity = calc.Compute();
                    }
                    patterns.Add(pattern);
                    patternsNames.Add(pattern, System.IO.Path.GetFileNameWithoutExtension(file));
                }
                catch
                {
                    logger.Error("Unable to load pattern " + System.IO.Path.GetFileNameWithoutExtension(file));
                }
            }

            Random rand = new Random();

            MapRecord[] maps = MapRecord.Maps.ToArray();

            int succesCount = 0;

            foreach (var map in MapRecord.Maps)
            {
                if (map.BlueCells.Count == 0 || map.RedCells.Count == 0)
                {
                    int[] relativePatternsComplx = (from entry in patterns
                                                    where entry.Relativ
                                                    select entry.Complexity).ToArray <int>();
                    PlacementPattern[] relativPatterns = (from entry in patterns
                                                          where entry.Relativ
                                                          select entry).ShuffleWithProbabilities(relativePatternsComplx).ToArray <PlacementPattern>();
                    Lozenge searchZone = new Lozenge(0, SearchDeep);

                    short[] cells = searchZone.GetCells(300, map);

                    for (int j = 0; j < cells.Length; j++)
                    {
                        short center = cells[j];
                        var   pt     = MapPoint.CellIdToCoord((uint)center);
                        System.Drawing.Point centerPt = new System.Drawing.Point(pt.X, pt.Y);
                        var success = relativPatterns.FirstOrDefault((PlacementPattern entry) => entry.TestPattern(centerPt, map));
                        if (success != null)
                        {
                            map.BlueCells = (from entry in success.Blues
                                             select(short) MapPoint.CoordToCellId(entry.X + centerPt.X, entry.Y + centerPt.Y)).ToList <short>();
                            map.RedCells = (from entry in success.Reds
                                            select(short) MapPoint.CoordToCellId(entry.X + centerPt.X, entry.Y + centerPt.Y)).ToList <short>();

                            map.UpdateInstantElement();
                            succesCount++;
                            break;
                        }
                    }
                }
            }



            logger.Gray(string.Format("{0} on {1} maps fixed ({2:0.0}%)", succesCount, MapRecord.Maps.Count, (double)succesCount / (double)MapRecord.Maps.Count * 100.0));
        }