Example #1
0
 public static void UpdateDynamicText(this CustomTextComponent comp)
 {
     if (comp.Text.Contains("[TIME]"))
     {
         comp.SetText(comp.Parent.OwnerUser.Player, "<size=0>[TIME]</size>" + DateTime.Now.ToString("hh:mm:ss"));
     }
     else if (comp.Text.Contains("[HOUSERANK]"))
     {
         comp.SetText(comp.Parent.OwnerUser.Player, "<size=0>[HOUSERANK]</size>" + MiscUtils.GetHouseRanking(10));
     }
 }
Example #2
0
        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);
            }
        }