Beispiel #1
0
 public static void PrintAllWalls()
 {
     //RemoveUnusedWalls();
     for (int i = Walls.Count - 1; i >= 0; i--)
     {
         WallOfField wof = Walls[i];
         wof.PrintTime();
     }
 }
Beispiel #2
0
        //---------------------------------------------------------------------------------------------

        protected static void RemoveUnusedWalls()
        {
            for (int i = Walls.Count - 1; i >= 0; i--)
            {
                WallOfField wof = Walls[i];
                if (wof.ElapsedTime > 180)
                {
                    if (Game.Debug)
                    {
                        Game.PrintMessage("WallRemove " + wof.ID);
                    }

                    Walls.RemoveAt(i);
                    continue;
                }
            }
        }
Beispiel #3
0
        public static bool TryFoundAddWall()
        {
            World.FindDistance = 20;
            List <UOItem> itemsAll = World.Ground.Where(i =>
                                                        i.Graphic == VAL_WoS ||
                                                        i.Graphic == VAL_EF1 ||
                                                        i.Graphic == VAL_EF2 //||
                                                                             /*i.Graphic == VAL_PF1*/
                                                        ).ToList();


            if (Game.Debug)
            {
                Game.PrintMessage("TryFoundAddWall " + itemsAll.Count);
            }

            bool result = false;


            List <UOItem> items = new List <UOItem>();

            foreach (UOItem allItem in itemsAll)
            {
                string positionKey = allItem.X + "|" + allItem.Y;

                try
                {
                    if (UniqueCounter.ContainsKey(allItem.Serial) && !UniqueCounter[allItem.Serial].Contains(positionKey))
                    {
                        UniqueCounter[allItem.Serial].Add(positionKey);

                        if (Game.Debug)
                        {
                            Game.PrintMessage("Duplicate ID " + allItem.Serial);
                        }
                    }
                    else if (!UniqueCounter.ContainsKey(allItem.Serial))
                    {
                        UniqueCounter.Add(allItem.Serial, new List <string>()
                        {
                            positionKey
                        });
                    }
                }
                catch (Exception ex)
                {
                    if (Game.Debug)
                    {
                        Game.PrintMessage(ex.Message);
                    }
                }

                bool isExisting = false;
                //  RemoveUnusedWalls();
                for (int i = Walls.Count - 1; i >= 0; i--)
                {
                    WallOfField wof = Walls[i];
                    for (int b = 0; b < wof.Bricks.Length; b++)//each (//uint s in wof.Bricks)
                    {
                        //UOItem brick = new UOItem(s);
                        if (wof.BrickExist(b) && allItem.Serial == wof.Bricks[b])
                        {
                            isExisting = true;
                            break;
                        }
                    }

                    if (isExisting)
                    {
                        break;
                    }
                }
                if (!isExisting)
                {
                    items.Add(allItem);
                }
            }

            if (Game.Debug)
            {
                Game.PrintMessage("TryFoundAddWall 1 " + items.Count);
            }

            if (items.Count > 0)
            {
                List <ushort> xs = new List <ushort>();
                List <ushort> ys = new List <ushort>();

                foreach (UOItem itm in items)
                {
                    if (!xs.Contains(itm.X))
                    {
                        xs.Add(itm.X);
                    }

                    if (!ys.Contains(itm.Y))
                    {
                        ys.Add(itm.Y);
                    }
                }

                Dictionary <string, List <UOItem> > posibleWalls = new Dictionary <string, List <UOItem> >();

                foreach (ushort x in xs)
                {
                    posibleWalls.Add("X:" + x, items.Where(i => i.X == x /*&& i.Graphic == xItem.Graphic*/).OrderBy(i => i.Y).ToList());
                }

                foreach (ushort y in ys)
                {
                    posibleWalls.Add("Y:" + y, items.Where(i => i.Y == y /*&& i.Graphic == yItem.Graphic*/).OrderBy(i => i.X).ToList());
                }

                //List<UOItem> snItems = items.Where(i => i.X == items[0].X && i.Graphic == items[0].Graphic).OrderBy(i => i.Y).ToList();
                //List<UOItem> weItems = items.Where(i => i.Y == items[0].Y && i.Graphic == items[0].Graphic).OrderBy(i => i.X).ToList();

                if (Game.Debug)
                {
                    Game.PrintMessage("TryFoundAddWall 3 " + posibleWalls.Count);
                }

                foreach (KeyValuePair <string, List <UOItem> > kvp in posibleWalls)
                {
                    try
                    {
                        WallOfField wof = null;
                        WallType    wt  = kvp.Key.StartsWith("X") ? WallType.SN : WallType.WE;

                        if (Game.Debug)
                        {
                            Game.PrintMessage("TryFoundAddWall 4 [" + kvp.Key + "] " + kvp.Value.Count);
                        }

                        if (kvp.Value.Count > 2)
                        {
                            wof      = new WallOfField(++WallIDCounter);
                            wof.Type = wt;

                            for (int i = 0; i < kvp.Value.Count; i++)
                            {
                                wof.Bricks[i]          = kvp.Value[i];
                                wof.BricksPositions[i] = kvp.Value[i].X + "." + kvp.Value[i].Y;
                            }
                        }

                        if (wof != null)
                        {
                            Walls.Add(wof);
                            wof.PrintInit();
                        }
                    }
                    catch (Exception ex)
                    {
                        if (Game.Debug)
                        {
                            Game.PrintMessage("Ex: " + ex);
                        }
                    }
                }
            }

            return(result);
        }