示例#1
0
        private List <ItemCount> getAllCurrentItems(Inventory inv)
        {
            List <ItemCount> list = new List <ItemCount>();

            foreach (ItemIndex itemIndex in inv.itemAcquisitionOrder)
            {
                ItemCount itemCount = new ItemCount(itemIndex, inv.GetItemCount(itemIndex));
                list.Add(itemCount);
            }
            return(list);
        }
示例#2
0
        private string constructItemsLostString(List <ItemCount> difference)
        {
            string result = "<color=#8296ae>You gave up ";

            for (int i = 0; i < difference.Count; i++)
            {
                ItemCount   diffItem    = difference[i];
                PickupIndex pickupIndex = new PickupIndex(diffItem.itemIndex);
                string      itemName    = Language.GetString(ItemCatalog.GetItemDef(diffItem.itemIndex).nameToken);
                string      hexColor    = "#" + ColorUtility.ToHtmlStringRGB(pickupIndex.GetPickupColor());

                result += "x" + diffItem.count + " " + "<color=" + hexColor + ">" + itemName + "</color>";
                if (i + 1 < difference.Count)
                {
                    result += ", ";
                }
                else
                {
                    result += "</color>";
                }
            }

            return(result);
        }
示例#3
0
        public void Awake()
        {
            On.RoR2.PurchaseInteraction.OnInteractionBegin += (orig, self, activator) =>
            {
                if (!self.CanBeAffordedByInteractor(activator))
                {
                    return;
                }
                switch (self.costType)
                {
                case CostTypeIndex.WhiteItem:
                case CostTypeIndex.GreenItem:
                case CostTypeIndex.RedItem:
                {
                    CharacterBody component = activator.GetComponent <CharacterBody>();
                    if (component)
                    {
                        Inventory inventory = component.inventory;
                        if (inventory)
                        {
                            List <ItemCount> listBefore = new List <ItemCount>();
                            List <ItemCount> listAfter  = new List <ItemCount>();

                            listBefore = getAllCurrentItems(inventory);

                            orig(self, activator);

                            listAfter = getAllCurrentItems(inventory);

                            if (listBefore.Count > 0)
                            {
                                List <ItemCount> difference = new List <ItemCount>();
                                foreach (ItemCount beforeItem in listBefore)
                                {
                                    bool itemAppears = false;
                                    foreach (ItemCount afterItem in listAfter)
                                    {
                                        if (beforeItem.itemIndex == afterItem.itemIndex)
                                        {
                                            itemAppears = true;
                                            if (beforeItem.count > afterItem.count)
                                            {
                                                ItemCount differenceItem = new ItemCount(beforeItem.itemIndex, beforeItem.count - afterItem.count);
                                                difference.Add(differenceItem);
                                            }
                                            break;
                                        }
                                    }
                                    if (!itemAppears)
                                    {
                                        ItemCount differenceItem = new ItemCount(beforeItem.itemIndex, beforeItem.count);
                                        difference.Add(differenceItem);
                                    }
                                }
                                string tradeInMessage = constructItemsLostString(difference);
                                SendCustomMessage(activator, tradeInMessage);
                            }
                        }
                        else
                        {
                            orig(self, activator);
                        }
                    }
                    else
                    {
                        orig(self, activator);
                    }
                    break;
                }

                default:
                {
                    orig(self, activator);
                    break;
                }
                }
            };
        }