Esempio n. 1
0
 public override void OnKill()
 {
     foreach (Point16 storageUnit in storageUnits)
     {
         TEAbstractStorageUnit unit = (TEAbstractStorageUnit)TileEntity.ByPosition[storageUnit];
         unit.Unlink();
         NetHelper.SendTEUpdate(unit.ID, unit.Position);
     }
 }
Esempio n. 2
0
        public void ResetAndSearch()
        {
            List <Point16> oldStorageUnits = new List <Point16>(storageUnits);

            storageUnits.Clear();
            HashSet <Point16> hashStorageUnits = new HashSet <Point16>();
            HashSet <Point16> explored         = new HashSet <Point16>();

            explored.Add(Position);
            Queue <Point16> toExplore = new Queue <Point16>();

            foreach (Point16 point in AdjacentComponents())
            {
                toExplore.Enqueue(point);
            }
            bool changed = false;

            while (toExplore.Count > 0)
            {
                Point16 explore = toExplore.Dequeue();
                if (!explored.Contains(explore) && explore != StorageComponent.killTile)
                {
                    explored.Add(explore);
                    if (TileEntity.ByPosition.ContainsKey(explore) && TileEntity.ByPosition[explore] is TEAbstractStorageUnit)
                    {
                        TEAbstractStorageUnit storageUnit = (TEAbstractStorageUnit)TileEntity.ByPosition[explore];
                        if (storageUnit.Link(Position))
                        {
                            NetHelper.SendTEUpdate(storageUnit.ID, storageUnit.Position);
                            changed = true;
                        }
                        storageUnits.Add(explore);
                        hashStorageUnits.Add(explore);
                    }
                    foreach (Point16 point in AdjacentComponents(explore))
                    {
                        toExplore.Enqueue(point);
                    }
                }
            }

            foreach (Point16 oldStorageUnit in oldStorageUnits)
            {
                if (!hashStorageUnits.Contains(oldStorageUnit))
                {
                    if (TileEntity.ByPosition.ContainsKey(oldStorageUnit) && TileEntity.ByPosition[oldStorageUnit] is TEAbstractStorageUnit)
                    {
                        TileEntity storageUnit = TileEntity.ByPosition[oldStorageUnit];
                        ((TEAbstractStorageUnit)storageUnit).Unlink();
                        NetHelper.SendTEUpdate(storageUnit.ID, storageUnit.Position);
                    }
                    changed = true;
                }
            }

            if (changed)
            {
                TEStorageHeart heart = GetHeart();
                if (heart != null)
                {
                    heart.ResetCompactStage();
                }
                NetHelper.SendTEUpdate(ID, Position);
            }
        }