public void RemoveConveyor(TransportPipeInfo info) { conveyors.Remove(info); bool electric = true; foreach (TransportPipeInfo i in conveyors) { if (i.type == PIPETYPE.Wooden) { if (linkerPipeType != PIPETYPE.Wooden) { linkerPipeType = PIPETYPE.Wooden; UpdateElectricityType(); } electric = false; break; } } if (electric) { if (linkerPipeType != PIPETYPE.Electric) { linkerPipeType = PIPETYPE.Electric; UpdateElectricityType(); } } UpdateElectricityCost(); }
public void UpdateInfo(TransportPipeInfo info) { if (info.type == PIPETYPE.Wooden) { if (linkerPipeType != PIPETYPE.Wooden) { linkerPipeType = PIPETYPE.Wooden; UpdateElectricityType(); } } else if (info.type == PIPETYPE.Electric) { if (linkerPipeType == PIPETYPE.Wooden) { linkerPipeType = PIPETYPE.Electric; foreach (TransportPipeInfo conv in conveyors) { if (conv.type == PIPETYPE.Wooden) { linkerPipeType = PIPETYPE.Wooden; break; } } UpdateElectricityType(); } } UpdateElectricityCost(); }
public TransportPipeLinker() { conveyors = new ThreadSafeList <TransportPipeInfo>(); inputConveyors = new ThreadSafeList <ConnectorObject>(); outputConveyors = new ThreadSafeList <ConnectorObject>(); id = TransportPipeManager.idLinker; TransportPipeManager.idLinker++; linkerPipeType = PIPETYPE.Electric; }
public void AddConveyor(TransportPipeInfo info) { if (info.type == PIPETYPE.Wooden) { if (linkerPipeType != PIPETYPE.Wooden) { linkerPipeType = PIPETYPE.Wooden; UpdateElectricityType(); } } conveyors.Add(info); UpdateElectricityCost(); }
private int GetPipeType(PIPETYPE type) { int counter = 0; foreach (TransportPipeInfo p in conveyors) { if (p.type == type) { counter++; } } return(counter); }
public override void Tick() { if (doInit) { Init(); } if (callUpdate) { InitInputOutput(); callUpdate = false; } base.Tick(); if (timeStampMillis + 500f < (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds) { if (info != null && info.type != previousType) { SetAnimatedState("SetWood", info.type == PIPETYPE.Wooden); previousType = info.type; } timeStampMillis = (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds; // If text change if (textComp.Text != lastText) { string goodTextName = ""; // Make a copy of the filter in case we need to revert the filter Filter copy = new Filter(); copy.acceptItemList.AddRange(filter.acceptItemList); copy.refusedItemList.AddRange(filter.refusedItemList); filter.acceptItemList.Clear(); filter.refusedItemList.Clear(); string newText = textComp.Text; // In case the current text is null set the previous text if (lastPlayer != null && newText == null) { textComp.SetText(lastPlayer, lastText); newText = lastText; } foreach (string itemName in newText.Split(',')) { string blacklistItem = null; if (itemName.Length > 0 && itemName[0] == '!') { blacklistItem = itemName.Remove(0, 1); } if (blacklistItem != null) { var blackItems = typeof(Item).CreatableTypes().Where(x => x.Name.ContainsCaseInsensitive(blacklistItem)); // Search for the items if (blackItems.Count() > 1) { var lessItemsBlack = blackItems.Where(i => i.Name.Remove(i.Name.Length - "Item".Length).CompareCaseInsensitive(blacklistItem) == 0); if (lessItemsBlack.Any()) { blackItems = lessItemsBlack; } } //If the item is found if (blackItems.Count() == 1) { filter.refusedItemList.Add(blackItems.First()); if (goodTextName != "") { goodTextName += ","; } goodTextName += "!" + blackItems.First().ToString().Split('.').Last().Remove(blackItems.First().ToString().Split('.').Last().Length - "Item".Length); continue; } } string testedItem = itemName; if (blacklistItem != null) { testedItem = testedItem.Remove(0, 1); } var items = typeof(Item).CreatableTypes().Where(x => x.Name.ContainsCaseInsensitive(testedItem)); // Search for the items if (items.Count() > 1) { var lessItems = items.Where(i => i.Name.Remove(i.Name.Length - "Item".Length).CompareCaseInsensitive(testedItem) == 0); if (lessItems.Any()) { items = lessItems; } } //If the item is found if (items.Count() == 1) { filter.acceptItemList.Add(items.First()); if (goodTextName != "") { goodTextName += ","; } goodTextName += items.First().ToString().Split('.').Last().Remove(items.First().ToString().Split('.').Last().Length - "Item".Length); continue; } // If no item found and if it's not All if (lastPlayer != null && !itemName.Equals("All", StringComparison.InvariantCultureIgnoreCase)) { // show error message to the player if (items.Count() == 0) { lastPlayer.SendTemporaryMessage($"Couldn't find any items matching {testedItem}", ChatCategory.Error); } else { lastPlayer.SendTemporaryMessage($"Multiple items found matching, use more specific string: {string.Join(", ", items.Select(x => x.Name))}", ChatCategory.Error); } // Back to the last working filter filter.acceptItemList.Clear(); filter.refusedItemList.Clear(); filter.acceptItemList.AddRange(copy.acceptItemList); filter.refusedItemList.AddRange(copy.refusedItemList); // Back to the previous text textComp.SetText(lastPlayer, lastText); newText = lastText; goodTextName = ""; break; } } // If good text exist and if player exist change text if (goodTextName.IsEmpty() == false && lastPlayer != null) { textComp.SetText(lastPlayer, goodTextName); newText = goodTextName; } // Changing the lastText to the next text. That permit to check when text changes lastText = newText; } } if (info != null && info.beltLinker != null) { info.beltLinker.testUpdate(this); } }
public void InitInputOutput() { info.beltLinker.RemoveConnector(this); if (TransportPipeManager.pipesInfo.ContainsKey(Utils.MakeWorldMod(Position3i))) { info = TransportPipeManager.pipesInfo[Utils.MakeWorldMod(Position3i)]; } if (mode == CONNECTOR_MODE.Input) { WorldObject obj = Utils.SearchForConnectedStorageObject(Utils.MakeWorldMod(Position3i)); if (obj != null) { Input = obj; InvInput = Utils.SearchInventoryFromObject(obj); info.beltLinker.AddConnector(true, this); SetAnimatedState("SetModeInput", true); } if (Input == null || InvInput == null) { mode = CONNECTOR_MODE.None; } } if (mode == CONNECTOR_MODE.Output) { WorldObject obj = Utils.SearchForConnectedStorageObject(Utils.MakeWorldMod(Position3i)); if (obj != null) { Output = obj; InvOutput = Utils.SearchInventoryFromObject(obj); info.beltLinker.AddConnector(false, this); SetAnimatedState("SetModeOutput", true); } if (Output == null || InvOutput == null) { mode = CONNECTOR_MODE.None; } } if (mode == CONNECTOR_MODE.InOut) { WorldObject obj = Utils.SearchForConnectedStorageObject(Utils.MakeWorldMod(Position3i)); if (obj != null) { Input = obj; Output = obj; InvOutput = Utils.SearchInventoryFromObject(obj); InvInput = InvOutput; info.beltLinker.AddConnector(false, this); info.beltLinker.AddConnector(true, this); SetAnimatedState("SetModeIOput", true); } if (Input == null || InvOutput == null) { mode = CONNECTOR_MODE.None; } } // If it's in an unknow state - remove the connector if (mode == CONNECTOR_MODE.None) { CleanDestroy(); return; } if (info != null && info.beltLinker != null) { info.beltLinker.UpdateElectricityType(); } if (info != null) { SetAnimatedState("SetWood", info.type == PIPETYPE.Wooden); previousType = info.type; } }