Beispiel #1
0
        private void Sync(WarpChest stat, WarpChest change)
        {
            //Monitor.Log("Syncing Chests.", LogLevel.Debug);
            IList <Item> removes = new List <Item>();

            foreach (Item item in stat.container.items)
            {
                if (!change.HasItem(item))
                {
                    removes.Add(item);
                    //Monitor.Log("Removing Item: " + item.DisplayName, LogLevel.Debug);
                }
            }
            foreach (Item item in removes)
            {
                stat.container.items.Remove(item);
            }
            foreach (Item item in change.container.items)
            {
                if (!stat.HasItem(item))
                {
                    stat.container.addItem(item);
                    //Monitor.Log("Adding Item: " + item.DisplayName, LogLevel.Debug);
                }
            }
        }
Beispiel #2
0
        private void DualSync(WarpChest warp1, WarpChest warp2)
        {
            //Monitor.Log("Syncing Chests.", LogLevel.Debug);

            IEnumerable <Item> warp1Added   = warp1.state.Where(item => !warp1.HasItem(item));
            IEnumerable <Item> warp1Removed = warp1.container.items.Where(item => !warp1.HadItem(item));

            IEnumerable <Item> warp2Added   = warp2.state.Where(item => !warp2.HasItem(item));
            IEnumerable <Item> warp2Removed = warp2.container.items.Where(item => !warp2.HadItem(item));

            foreach (Item item in warp1Removed)
            {
                warp2.container.items.Remove(item);
                //Monitor.Log("Removing Item: " + item.DisplayName, LogLevel.Debug);
            }
            foreach (Item item in warp2Removed)
            {
                warp1.container.items.Remove(item);
                //Monitor.Log("Removing Item: " + item.DisplayName, LogLevel.Debug);
            }

            foreach (Item item in warp1Added)
            {
                warp2.container.addItem(item);
            }
            foreach (Item item in warp2Added)
            {
                warp1.container.addItem(item);
            }
        }
Beispiel #3
0
        public bool LinkGroup(Color group)
        {
            bool      didLink = false;
            WarpChest master  = null;

            foreach (WarpChest wc in chestList)
            {
                if (wc.isMain && wc.group == group)
                {
                    master = wc;
                    break;
                }
            }
            foreach (WarpChest wc in chestList)
            {
                if (wc.group == group && !wc.isMain)
                {
                    didLink = true;
                    if (wc.SlaveCheckRequirements() && !wc.HasInventoryChanged() && !master.HasInventoryChanged())
                    {
                        wc.container.items.Clear();
                        foreach (Item item in master.container.items)
                        {
                            wc.container.addItem(item);
                        }
                    }
                    else if (master.HasInventoryChanged() && !wc.HasInventoryChanged())
                    {
                        Sync(wc, master);
                    }
                    else if (!master.HasInventoryChanged() && wc.HasInventoryChanged())
                    {
                        Sync(master, wc);
                    }
                    else
                    {
                        DualSync(wc, master);
                    }
                }
            }
            foreach (WarpChest wc in chestList)
            {
                if (wc.group == group)
                {
                    wc.ResetInventoryCheck();
                }
            }
            if (!master.MeetsRequirements())
            {
                didLink = false;
                UnlinkGroup(master.group);
            }
            return(didLink);
        }
Beispiel #4
0
        public void LinkChests()
        {
            Monitor.Log("Linking Chests", LogLevel.Debug);
            chestList.Clear();
            IEnumerable <Chest> chests = GetAllChests();

            foreach (Chest chest in chests)
            {
                WarpChest wc = new WarpChest(chest, chest.playerChoiceColor, mod, true);
                if (wc.MeetsRequirements())
                {
                    chestList.Add(wc);
                }
            }
            //DebugSearch();
            foreach (WarpChest ch in chestList)
            {
                chestList = chestList.Where(chest => !chest.SameGroup(ch) || chest == ch).ToList();
            }
            IList <WarpChest> slaveList = new List <WarpChest>();

            foreach (Chest chest in chests)
            {
                foreach (WarpChest wc in chestList)
                {
                    WarpChest nc = new WarpChest(chest, chest.playerChoiceColor, mod, true);
                    if (wc.isMain && wc.container != nc.container && nc.group == wc.group && nc.SlaveCheckRequirements())
                    {
                        slaveList.Add(new WarpChest(chest, chest.playerChoiceColor, mod));
                    }
                }
            }
            chestList = chestList.Concat(slaveList).ToList();
            chestList = chestList.Where(wc => wc.SameGroup(chestList.Aggregate((c1, c2) => (c1.SameGroup(wc) && c1 != wc)?c1:c2))).ToList();
            foreach (WarpChest wc in chestList)
            {
                if (wc.isMain)
                {
                    bool attempt = LinkGroup(wc.group);
                    if (attempt)
                    {
                        Monitor.Log("Linking group: " + wc.group, LogLevel.Debug);
                    }
                }
            }
        }
Beispiel #5
0
 public bool SameGroup(WarpChest other)
 {
     return(this.group == other.group);
 }