Exemple #1
0
        // method copied from RoR2.Inventory::GiveRandomItems
        private void BoostPlayerWithRandomItem(NetworkUser user)
        {
            if (!user || !user.master || !user.master.inventory)
            {
                return;
            }

            var inventory = user.master.inventory;

            try
            {
                WeightedSelection <List <PickupIndex> > weightedSelection = new WeightedSelection <List <PickupIndex> >(8);
                weightedSelection.AddChoice(Run.instance.availableTier1DropList, 100f);
                weightedSelection.AddChoice(Run.instance.availableTier2DropList, 20f);

                List <PickupIndex> list      = weightedSelection.Evaluate(UnityEngine.Random.value);
                PickupDef          pickupDef = PickupCatalog.GetPickupDef(list[UnityEngine.Random.Range(0, list.Count)]);
                inventory.GiveItem((pickupDef != null) ? pickupDef.itemIndex : ItemIndex.None, 1);

                ChatHelper.PlayerBoostedWithItem(user.userName, pickupDef.nameToken, pickupDef.baseColor);
            }
            catch (System.ArgumentException)
            {
            }
        }
        private static void ScrappingToIdle_OnEnter(On.EntityStates.Scrapper.ScrappingToIdle.orig_OnEnter orig, EntityStates.Scrapper.ScrappingToIdle self)
        {
            if (!(ShareSuite.PrinterCauldronFixEnabled.Value && NetworkServer.active && GeneralHooks.IsMultiplayer()))
            {
                orig(self);
                return;
            }

            _itemLock = true;
            orig(self);

            ScrapperController scrapperController = GetInstanceField(typeof(ScrapperBaseState), self, "scrapperController") as ScrapperController;

            Debug.Log(scrapperController);
            if (scrapperController)
            {
                PickupIndex pickupIndex = PickupIndex.none;
                ItemDef     itemDef     = ItemCatalog.GetItemDef(scrapperController.lastScrappedItemIndex);
                if (itemDef != null)
                {
                    switch (itemDef.tier)
                    {
                    case ItemTier.Tier1:
                        pickupIndex = PickupCatalog.FindPickupIndex("ItemIndex.ScrapWhite");
                        break;

                    case ItemTier.Tier2:
                        pickupIndex = PickupCatalog.FindPickupIndex("ItemIndex.ScrapGreen");
                        break;

                    case ItemTier.Tier3:
                        pickupIndex = PickupCatalog.FindPickupIndex("ItemIndex.ScrapRed");
                        break;

                    case ItemTier.Boss:
                        pickupIndex = PickupCatalog.FindPickupIndex("ItemIndex.ScrapYellow");
                        break;
                    }
                }

                if (pickupIndex == PickupIndex.none)
                {
                    return;
                }

                var interactor = GetInstanceField(typeof(ScrapperController), scrapperController, "interactor") as Interactor;
                Debug.Log("Interactor Established");

                PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);

                if (!interactor)
                {
                    return;
                }

                CharacterBody component = interactor.GetComponent <CharacterBody>();
                component.inventory.GiveItem(pickupDef.itemIndex, scrapperController.itemsEaten);
                ChatHandler.SendRichCauldronMessage(component.inventory.GetComponent <CharacterMaster>(), pickupIndex);
            }
        }
Exemple #3
0
        internal static void GiveScavsLunarsAndBossItems(On.RoR2.ScavengerItemGranter.orig_Start orig, RoR2.ScavengerItemGranter self)
        {
            orig(self);
            Inventory inventory = self.GetComponent <Inventory>();

            if (inventory.GetTotalItemCountOfTier(ItemTier.Lunar) == 0)
            {
                var list        = Run.instance.availableLunarDropList.Where(new System.Func <PickupIndex, bool>(PickupIsNonBlacklistedItem)).ToList();
                var randomIndex = Random.Range(0, list.Count);
                inventory.GiveItem(PickupCatalog.GetPickupDef(list[randomIndex]).itemIndex, 2);
            }

            if (inventory.GetTotalItemCountOfTier(ItemTier.Boss) == 0)
            {
                var list        = PickupCatalog.allPickups.Where(def => def.isBoss).ToList();
                var randomIndex = Random.Range(0, list.Count);
                inventory.GiveItem(list[randomIndex].itemIndex, 1);
            }


            bool PickupIsNonBlacklistedItem(PickupIndex pickupIndex)
            {
                PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
                ItemDef   itemDef   = ItemCatalog.GetItemDef(pickupDef != null ? pickupDef.itemIndex : ItemIndex.None);

                if (itemDef == null)
                {
                    return(false);
                }
                return(itemDef.DoesNotContainTag(ItemTag.AIBlacklist));
            }
        }
Exemple #4
0
        static bool Prefix(CharacterMaster master, PickupIndex pickupIndex)
        {
            if (!NetworkServer.active)
            {
                Debug.LogWarning("[Server] function 'System.Void RoR2.GenericPickupController::SendPickupMessage(RoR2.CharacterMaster,RoR2.PickupIndex)' called on client");
                return(false);
            }

            var highStacks = Precipitation.RainServer.GetToggle("high_stacks");

            uint pickupQuantity = highStacks ? 10u : 1u;

            if (master.inventory && !highStacks)
            {
                PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
                ItemIndex itemIndex = (pickupDef != null) ? pickupDef.itemIndex : ItemIndex.None;
                if (itemIndex != ItemIndex.None)
                {
                    pickupQuantity = (uint)master.inventory.GetItemCount(itemIndex);
                }
            }

            var msg = new PickupMessage
            {
                masterGameObject = master.gameObject,
                pickupIndex      = pickupIndex,
                pickupQuantity   = pickupQuantity
            };

            NetworkServer.SendByChannelToAll(57, msg, RoR2.Networking.QosChannelIndex.chat.intVal);

            return(false);
        }
Exemple #5
0
        private void GenericPickupController_GrantItem(On.RoR2.GenericPickupController.orig_GrantItem orig, GenericPickupController self, CharacterBody body, Inventory inventory)
        {
            orig(self, body, inventory);
            PickupDef pickupDef = PickupCatalog.GetPickupDef(self.pickupIndex);

            body.master?.GetBodyObject().GetComponent <DropInventoryOnDeath>()?.AddItem((pickupDef != null) ? pickupDef.itemIndex : ItemIndex.None, 1);
        }
Exemple #6
0
        private void AddPickupNameToHologram(On.RoR2.Hologram.HologramProjector.orig_BuildHologram orig, HologramProjector self)
        {
            orig(self);

            var chestBehav = self.GetComponent <ChestBehavior>();

            if (ShouldIgnoreChestBehaviour(chestBehav))
            {
                return;
            }

            var       netId  = chestBehav.netId;
            PickupDef pickup = null;

            if (!NetworkChestSync.instance.TryGetPickup(netId, out pickup))
            {
                Debug.LogWarning($"Failed getting pickup for chest {netId}");
                return;
            }

            var contentObj = self.GetFieldValue <GameObject>("hologramContentInstance");

            if (!contentObj)
            {
                Debug.LogWarning($"No content instance for chest {netId}'s hologram projector");
                return;
            }

            var txtCopy = Instantiate(contentObj.transform.GetChild(2).gameObject);

            txtCopy.GetComponent <TextMeshPro>().text = GetStylizedPickupName(pickup);
            txtCopy.transform.SetParent(contentObj.transform, false);
            txtCopy.GetComponent <RectTransform>().anchoredPosition = new Vector2(pickupNameXPos, pickNameYPos);
        }
Exemple #7
0
        private void MaybeAwardLoot(On.RoR2.CharacterBody.orig_OnInventoryChanged orig, CharacterBody self)
        {
            orig(self);
            var amount = self.inventory.GetItemCount(Definition.itemIndex);

            if (amount > 0 && amount % 3 == 0)
            {
                self.inventory.RemoveItem(Definition.itemIndex, 3);
                PickupIndex loot;
                if (Util.CheckRoll(5, self.master))
                {
                    loot = Run.instance.treasureRng.NextElementUniform(Run.instance.availableTier3DropList);
                }
                else
                {
                    loot = Run.instance.treasureRng.NextElementUniform(Run.instance.availableTier2DropList);
                }
                if (self.isPlayerControlled)
                {
                    PickupDropletController.CreatePickupDroplet(loot, self.corePosition, Vector3.up * 5);
                }
                else
                {
                    PickupDef def = PickupCatalog.GetPickupDef(loot);
                    self.inventory.GiveItem(def.itemIndex);
                    var lootCount = self.inventory.GetItemCount(def.itemIndex);
                    Chat.AddPickupMessage(self, def.nameToken, ColorCatalog.GetColor(ItemCatalog.GetItemDef(def.itemIndex).colorIndex), (uint)lootCount);
                }
            }
        }
        private void CreateTooltip(Transform parent, PickupDef pickupDefinition, int count)
        {
            ItemDef      itemDefinition = ItemCatalog.GetItemDef(pickupDefinition.itemIndex);
            EquipmentDef equipmentDef   = EquipmentCatalog.GetEquipmentDef(pickupDefinition.equipmentIndex);
            bool         isItem         = itemDefinition != null;

            TooltipContent content = new TooltipContent();

            content.titleColor = pickupDefinition.darkColor;
            content.titleToken = isItem ? itemDefinition.nameToken : equipmentDef.nameToken;
            content.bodyToken  = isItem ? itemDefinition.descriptionToken : equipmentDef.descriptionToken;

            if (isItem && ItemStatsMod.enabled)
            {
                CharacterMaster master = PlayerCharacterMasterController.instances[0].master;

                string stats = ItemStatsMod.GetStats(itemDefinition.itemIndex, count, master);

                if (stats != null)
                {
                    content.overrideBodyText = $"{Language.GetString(content.bodyToken)}{stats}";
                }
            }

            TooltipProvider tooltipProvider = parent.gameObject.AddComponent <TooltipProvider>();

            tooltipProvider.SetContent(content);
        }
        public void UpdatePickupTooltip(TooltipProvider tooltip, PickupIndex pickupIdx, int itemCount = 1)
        {
            PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIdx);

            string descToken;

            if (pickupDef.itemIndex != ItemIndex.None)
            {
                descToken = ItemCatalog.GetItemDef(pickupDef.itemIndex).descriptionToken;
            }
            else if (pickupDef.equipmentIndex != EquipmentIndex.None)
            {
                descToken = EquipmentCatalog.GetEquipmentDef(pickupDef.equipmentIndex).descriptionToken;
            }
            else
            {
                return;
            }

            string pickupDesc = Language.IsTokenInvalid(descToken) ? Language.GetString(pickupDef.nameToken) : Language.GetString(descToken);

            pickupDesc += "\n\n" + PickupStatsProvider.GetStatsForPickup(pickupIdx, itemCount);

            tooltip.overrideBodyText = pickupDesc;
        }
        private static IEnumerable <ItemIndex> GetItemIndicesByNames(IEnumerable <string> itemNames)
        {
            if (itemNames == null || itemNames.Count() == 0)
            {
                return(new ItemIndex[0]);
            }

            List <ItemIndex> itemIndexes = new List <ItemIndex>();

            foreach (string itemName in itemNames)
            {
                // Language thing makes it easier to make the list using display names, or use internal name
                // to make the list transferable between different language configurations
                PickupDef pickupDef = PickupCatalog.allPickups.FirstOrDefault(pickup =>
                                                                              pickup.internalName.Equals("ItemIndex." + itemName) ||
                                                                              // Replace commas because we need them for comma seperated values
                                                                              Language.GetString(pickup.nameToken).Replace(",", "").Equals(itemName, StringComparison.InvariantCultureIgnoreCase));

                if (pickupDef == null || !pickupDef.pickupIndex.isValid || pickupDef.pickupIndex == PickupIndex.none)
                {
                    Debug.LogWarning($"Could not find item with name {itemName} to blacklist");
                    continue;
                }
                itemIndexes.Add(pickupDef.itemIndex);
            }

            return(itemIndexes);
        }
        private void GenericPickupController_AttemptGrant(On.RoR2.GenericPickupController.orig_AttemptGrant orig, GenericPickupController self, CharacterBody body)
        {
            if (!NetworkServer.active)
            {
                Debug.LogWarning("[Server] function 'System.Void RoR2.GenericPickupController::AttemptGrant(RoR2.CharacterBody)' called on client");
                return;
            }
            if (!ArtifactEnabled)
            {
                return;
            }

            if (!body.masterObject)
            {
                return;
            }

            TeamComponent component = body.GetComponent <TeamComponent>();

            if (component)
            {
                Inventory inventory = body.inventory;
                if (inventory)
                {
                    PlayerCharacterMasterController isPlayer = body.masterObject.GetComponent <PlayerCharacterMasterController>();

                    self.consumed = true;
                    PickupDef            pickupDef = PickupCatalog.GetPickupDef(self.pickupIndex);
                    DropInventoryOnDeath comp      = null;
                    if (!isPlayer && body.teamComponent.teamIndex != TeamIndex.Player)
                    {
                        comp = body.gameObject.GetComponent <DropInventoryOnDeath>();
                        if (!comp)
                        {
                            comp = body.gameObject.AddComponent <DropInventoryOnDeath>();
                        }
                    }
                    if (pickupDef.itemIndex != ItemIndex.None)
                    {
                        self.GrantItem(body, inventory);
                    }
                    if (pickupDef.coinValue != 0U)
                    {
                        self.GrantLunarCoin(body, pickupDef.coinValue);
                    }
                    if (isPlayer)
                    {
                        if (pickupDef.equipmentIndex != EquipmentIndex.None)
                        {
                            self.GrantEquipment(body, inventory);
                        }
                        if (pickupDef.artifactIndex != ArtifactIndex.None)
                        {
                            self.GrantArtifact(body, pickupDef.artifactIndex);
                        }
                    }
                }
            }
        }
        private void Buy(ChestTier chestTier)
        {
            // Get drop list
            List <PickupIndex> dropList = null;

            switch (chestTier)
            {
            case ChestTier.WHITE:
                if (this.master.inventory.currentEquipmentIndex == EquipmentIndex.None && PlayerBotManager.EquipmentBuyChance.Value > UnityEngine.Random.Range(0, 100))
                {
                    dropList = Run.instance.availableEquipmentDropList;
                    break;
                }
                dropList = Run.instance.smallChestDropTierSelector.Evaluate(UnityEngine.Random.value);
                break;

            case ChestTier.GREEN:
                dropList = Run.instance.mediumChestDropTierSelector.Evaluate(UnityEngine.Random.value);
                break;

            case ChestTier.RED:
                dropList = Run.instance.largeChestDropTierSelector.Evaluate(UnityEngine.Random.value);
                break;
            }

            // Pickup
            if (dropList != null && dropList.Count > 0)
            {
                PickupIndex dropPickup = Run.instance.treasureRng.NextElementUniform <PickupIndex>(dropList);
                PickupDef   pickup     = PickupCatalog.GetPickupDef(dropPickup);
                if (pickup.itemIndex != ItemIndex.None)
                {
                    this.master.inventory.GiveItem(pickup.itemIndex, 1);
                }
                else if (pickup.equipmentIndex != EquipmentIndex.None)
                {
                    this.master.inventory.SetEquipmentIndex(pickup.equipmentIndex);
                }
                else
                {
                    // Neither item nor valid equipment
                    return;
                }
                // Chat
                if (PlayerBotManager.ShowBuyMessages.Value)
                {
                    PickupDef pickupDef = PickupCatalog.GetPickupDef(dropPickup);
                    Chat.SendBroadcastChat(new Chat.PlayerPickupChatMessage
                    {
                        subjectAsCharacterBody = this.master.GetBody(),
                        baseToken      = "PLAYER_PICKUP",
                        pickupToken    = ((pickupDef != null) ? pickupDef.nameToken : null) ?? PickupCatalog.invalidPickupToken,
                        pickupColor    = (pickupDef != null) ? pickupDef.baseColor : Color.black,
                        pickupQuantity = pickup.itemIndex != ItemIndex.None ? (uint)this.master.inventory.GetItemCount(pickup.itemIndex) : 1
                    });
                }
            }
        }
Exemple #13
0
 // Token: 0x060021BB RID: 8635 RVA: 0x00091F9C File Offset: 0x0009019C
 private void SetPickups(PickupIndex[] pickupIndices)
 {
     this.pickupIconAllocator.AllocateElements(pickupIndices.Length);
     for (int i = 0; i < pickupIndices.Length; i++)
     {
         PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndices[i]);
         this.pickupIconAllocator.elements[i].texture = ((pickupDef != null) ? pickupDef.iconTexture : null);
     }
 }
        /// <summary>
        /// Adds text labels for various interactables to a <see cref="PingIndicator"/>
        /// </summary>
        /// <param name="pingIndicator">Target <see cref="PingIndicator"/> that should have the text added</param>
        private static void AddLootText(RoR2.UI.PingIndicator pingIndicator)
        {
            const string         textStart    = "<size=70%>\n";
            string               price        = GetPrice(pingIndicator.pingTarget);
            ShopTerminalBehavior shopTerminal = pingIndicator.pingTarget.GetComponent <ShopTerminalBehavior>();

            if (shopTerminal && _config.ShowShopText.Value)
            {
                string      text        = textStart;
                PickupIndex pickupIndex = shopTerminal.CurrentPickupIndex();
                PickupDef   pickup      = PickupCatalog.GetPickupDef(pickupIndex);
                text += shopTerminal.pickupIndexIsHidden
                    ? "?"
                    : $"{Language.GetString(pickup.nameToken)}";
                pingIndicator.pingText.text += $"{text} ({price})";
                return;
            }

            GenericPickupController pickupController = pingIndicator.pingTarget.GetComponent <GenericPickupController>();

            if (pickupController && _config.ShowPickupText.Value)
            {
                PickupDef pickup = PickupCatalog.GetPickupDef(pickupController.pickupIndex);
                pingIndicator.pingText.text += $"{textStart}{Language.GetString(pickup.nameToken)}";
            }

            ChestBehavior chest = pingIndicator.pingTarget.GetComponent <ChestBehavior>();

            if (chest && _config.ShowChestText.Value)
            {
                pingIndicator.pingText.text += $"{textStart}{Util.GetBestBodyName(pingIndicator.pingTarget)} ({price})";
                return;
            }

            string name = "";

            PurchaseInteraction purchaseInteraction = pingIndicator.pingTarget.GetComponent <PurchaseInteraction>();

            if (purchaseInteraction)
            {
                name = Language.GetString(purchaseInteraction.displayNameToken);
            }

            // Drones
            SummonMasterBehavior summonMaster = pingIndicator.pingTarget.GetComponent <SummonMasterBehavior>();

            if (summonMaster && _config.ShowDroneText.Value)
            {
                pingIndicator.pingText.text += $"{textStart}{name} ({price})";
                return;
            }

            if (_config.ShowShrineText.Value)
            {
                pingIndicator.pingText.text += $"{textStart}{name}";
            }
        }
Exemple #15
0
        /// <summary>
        /// Method to get the interactable tier color from a ping target
        /// </summary>
        /// <param name="gameObject">The ping target</param>
        /// <returns>An Color instance of the tier color</returns>
        private Color GetTargetTierColor(GameObject gameObject)
        {
            Color color = Color.black;

            ShopTerminalBehavior shopTerminal = gameObject.GetComponent <ShopTerminalBehavior>();

            if (shopTerminal)
            {
                PickupIndex pickupIndex = shopTerminal.CurrentPickupIndex();
                PickupDef   pickup      = PickupCatalog.GetPickupDef(pickupIndex);

                if (pickup != null)
                {
                    color = pickup.baseColor;
                }
            }

            GenericPickupController pickupController = gameObject.GetComponent <GenericPickupController>();

            if (pickupController)
            {
                PickupDef pickup = PickupCatalog.GetPickupDef(pickupController.pickupIndex);

                if (pickup != null)
                {
                    color = pickup.baseColor;
                }
            }

            PurchaseInteraction purchaseInteraction = gameObject.GetComponent <PurchaseInteraction>();

            if (purchaseInteraction)
            {
                CostTypeDef costType = CostTypeCatalog.GetCostTypeDef(purchaseInteraction.costType);
                color = ColorCatalog.GetColor(costType.colorIndex);
            }

            PickupIndexNetworker pickupIndexNetworker = gameObject.GetComponent <PickupIndexNetworker>();

            if (pickupIndexNetworker)
            {
                PickupDef pickup = PickupCatalog.GetPickupDef(pickupIndexNetworker.NetworkpickupIndex);

                if (pickup != null)
                {
                    color = pickup.baseColor;
                }
            }

            if (color == Color.black)
            {
                color = _colors["InteractablePingColor"];
            }

            return(color);
        }
Exemple #16
0
        private static void AspectCommandDroplet(PickupDef pickupDef, Vector3 position, Quaternion rotation, ref bool shouldSpawn)
        {
            GameObject gameObject = UnityEngine.Object.Instantiate(Catalog.CommandCubePrefab, position, rotation);

            gameObject.GetComponent <PickupIndexNetworker>().NetworkpickupIndex = pickupDef.pickupIndex;
            SetPickupPickerControllerAspectOptions(gameObject.GetComponent <PickupPickerController>(), pickupDef);
            NetworkServer.Spawn(gameObject);

            shouldSpawn = false;
        }
Exemple #17
0
        public static void SendRichPickupMessage(CharacterMaster player, PickupDef pickupDef)
        {
            var body = player.hasBody ? player.GetBody() : null;

            if (!GeneralHooks.IsMultiplayer() || body == null ||
                !ShareSuite.RichMessagesEnabled.Value)
            {
                if (ShareSuite.RichMessagesEnabled.Value)
                {
                    SendPickupMessage(player, pickupDef.pickupIndex);
                }
                return;
            }

            var pickupColor = pickupDef.baseColor;
            var pickupName  = Language.GetString(pickupDef.nameToken);
            var playerColor = GetPlayerColor(player.playerCharacterMasterController);
            var itemCount   = player.inventory.GetItemCount(pickupDef.itemIndex);

            if (pickupDef.coinValue > 0)
            {
                var coinMessage =
                    $"<color=#{playerColor}>{body.GetUserName()}</color> <color=#{GrayColor}>picked up</color> " +
                    $"<color=#{ColorUtility.ToHtmlStringRGB(pickupColor)}>" +
                    $"{pickupName ?? "???"} ({pickupDef.coinValue})</color> <color=#{GrayColor}>for themselves.</color>";
                Chat.SendBroadcastChat(new Chat.SimpleChatMessage {
                    baseToken = coinMessage
                });
                return;
            }

            if (Blacklist.HasItem(pickupDef.itemIndex) ||
                !ItemSharingHooks.IsValidItemPickup(pickupDef.pickupIndex))
            {
                var singlePickupMessage =
                    $"<color=#{playerColor}>{body.GetUserName()}</color> <color=#{GrayColor}>picked up</color> " +
                    $"<color=#{ColorUtility.ToHtmlStringRGB(pickupColor)}>" +
                    $"{pickupName ?? "???"} ({itemCount})</color> <color=#{GrayColor}>for themselves. </color>" +
                    $"<color=#{NotSharingColor}>(Item Set to NOT be Shared)</color>";
                Chat.SendBroadcastChat(new Chat.SimpleChatMessage {
                    baseToken = singlePickupMessage
                });
                return;
            }

            var pickupMessage =
                $"<color=#{playerColor}>{body.GetUserName()}</color> <color=#{GrayColor}>picked up</color> " +
                $"<color=#{ColorUtility.ToHtmlStringRGB(pickupColor)}>" +
                $"{pickupName ?? "???"} ({itemCount})</color> <color=#{GrayColor}>for themselves</color>" +
                $"{ItemPickupFormatter(body)}<color=#{GrayColor}>.</color>";

            Chat.SendBroadcastChat(new Chat.SimpleChatMessage {
                baseToken = pickupMessage
            });
        }
Exemple #18
0
        public static int GetPickupCount(this Inventory inv, PickupIndex pickupIndex)
        {
            PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);

            if (inv is null || pickupDef is null)
            {
                return(0);
            }

            return(inv.GetItemCount(pickupDef.itemIndex));
        }
Exemple #19
0
        private string GetStylizedPickupName(PickupDef pickup)
        {
            var(nameToken, colorIndex) = pickup switch
            {
                PickupDef _ when EquipmentCatalog.GetEquipmentDef(pickup.equipmentIndex) is EquipmentDef def => (def.nameToken, def.colorIndex),
                PickupDef _ when ItemCatalog.GetItemDef(pickup.itemIndex) is ItemDef def => (def.nameToken, def.colorIndex),
                _ => ("", ColorCatalog.ColorIndex.None),
            };

            var color = ColorCatalog.GetColorHexString(colorIndex);
            return($"<color=#{color}>{Language.GetString(nameToken)}</color>");
        }
Exemple #20
0
        static bool Prefix(ref PickupDef.GrantContext context)
        {
            var highStacks = Precipitation.RainServer.GetToggle("high_stacks");

            Inventory inventory = context.body.inventory;
            PickupDef pickupDef = PickupCatalog.GetPickupDef(context.controller.pickupIndex);

            inventory.GiveItem((pickupDef != null) ? pickupDef.itemIndex : ItemIndex.None, highStacks ? 10 : 1);
            context.shouldDestroy = true;
            context.shouldNotify  = true;
            return(false);
        }
Exemple #21
0
        // Token: 0x06002C6A RID: 11370 RVA: 0x000BB74C File Offset: 0x000B994C
        public override void OnEnter()
        {
            base.OnEnter();
            this.duration = FindItem.baseDuration / this.attackSpeedStat;
            base.PlayCrossfade("Body", "SitRummage", "Sit.playbackRate", this.duration, 0.1f);
            Util.PlaySound(FindItem.sound, base.gameObject);
            if (base.isAuthority)
            {
                WeightedSelection <List <PickupIndex> > weightedSelection = new WeightedSelection <List <PickupIndex> >(8);
                weightedSelection.AddChoice((from v in Run.instance.availableTier1DropList
                                             where ItemCatalog.GetItemDef(v.itemIndex) != null && ItemCatalog.GetItemDef(v.itemIndex).DoesNotContainTag(ItemTag.AIBlacklist)
                                             select v).ToList <PickupIndex>(), FindItem.tier1Chance);
                weightedSelection.AddChoice((from v in Run.instance.availableTier2DropList
                                             where ItemCatalog.GetItemDef(v.itemIndex) != null && ItemCatalog.GetItemDef(v.itemIndex).DoesNotContainTag(ItemTag.AIBlacklist)
                                             select v).ToList <PickupIndex>(), FindItem.tier2Chance);
                weightedSelection.AddChoice((from v in Run.instance.availableTier3DropList
                                             where ItemCatalog.GetItemDef(v.itemIndex) != null && ItemCatalog.GetItemDef(v.itemIndex).DoesNotContainTag(ItemTag.AIBlacklist)
                                             select v).ToList <PickupIndex>(), FindItem.tier3Chance);
                List <PickupIndex> list = weightedSelection.Evaluate(UnityEngine.Random.value);
                this.dropPickup = list[UnityEngine.Random.Range(0, list.Count)];
                PickupDef pickupDef = PickupCatalog.GetPickupDef(this.dropPickup);
                if (pickupDef != null)
                {
                    ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex);
                    if (itemDef != null)
                    {
                        this.itemsToGrant = 0;
                        switch (itemDef.tier)
                        {
                        case ItemTier.Tier1:
                            this.itemsToGrant = FindItem.tier1Count;
                            break;

                        case ItemTier.Tier2:
                            this.itemsToGrant = FindItem.tier2Count;
                            break;

                        case ItemTier.Tier3:
                            this.itemsToGrant = FindItem.tier3Count;
                            break;

                        default:
                            this.itemsToGrant = 1;
                            break;
                        }
                    }
                }
            }
            Transform transform = base.FindModelChild("PickupDisplay");

            this.pickupDisplay = transform.GetComponent <PickupDisplay>();
            this.pickupDisplay.SetPickupIndex(this.dropPickup, false);
        }
Exemple #22
0
        private bool PickupIsNonBlacklistedItem(PickupIndex pickupIndex)
        {
            PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);

            if (pickupDef == null)
            {
                return(false);
            }

            ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex);

            return(itemDef != null && itemDef.DoesNotContainTag(ItemTag.AIBlacklist));
        }
Exemple #23
0
        public static void DropLastItem(CharacterMaster charMaster)
        {
            if (NetworkServer.active)
            {
                var    inv           = charMaster.inventory;
                var    pcmc          = charMaster.playerCharacterMasterController;
                string requesterName = pcmc.GetDisplayName();
                if (LastPickedUpItem.ContainsKey(inv) && LastPickedUpItem[inv] != PickupIndex.none && inv.itemAcquisitionOrder.Any())
                {
                    PickupDef pickupDef = PickupCatalog.GetPickupDef(LastPickedUpItem[inv]);
                    LastPickedUpItem[inv] = PickupIndex.none;

                    if (pickupDef.equipmentIndex != EquipmentIndex.None)
                    {
                        if (inv.GetEquipmentIndex() != pickupDef.equipmentIndex)
                        {
                            Logger.LogWarning($"'{requesterName}' tried to drop an equipment item they don't have! ({pickupDef.equipmentIndex})");
                            return;
                        }
                        inv.SetEquipmentIndex(EquipmentIndex.None);
                    }
                    else
                    {
                        if (inv.GetItemCount(pickupDef.itemIndex) <= 0)
                        {
                            Logger.LogWarning($"'{requesterName}' tried to drop an item they don't have! ({pickupDef.itemIndex})");
                            return;
                        }
                        inv.RemoveItem(pickupDef.itemIndex, 1);
                    }

                    var transform = charMaster.GetBody()?.coreTransform;
                    if (transform != null)
                    {
                        PickupDropletController.CreatePickupDroplet(pickupDef.pickupIndex,
                                                                    transform.position,
                                                                    transform.up * 15f + transform.forward * 10f);
                    }

                    Logger.LogInfo($"'{requesterName}' dropped '{Language.GetString(pickupDef.nameToken)}'");
                }
                else
                {
                    Logger.LogDebug($"'{requesterName}' tried to drop an item but is not allowed.");
                }
            }
            else
            {
                Logger.LogWarning("DropLastItem called on client!");
            }
        }
Exemple #24
0
        private static EquipmentIndex GetRandomNonBlacklistEquipment()
        {
            IEnumerable <PickupIndex> blacklistEquips       = EquipmentToPickupIndices(AIBlacklisterConfig.AIEquipBlacklist);
            List <PickupIndex>        equipsExceptBlacklist = Run.instance?.availableEquipmentDropList.Except(blacklistEquips).ToList();

            if (equipsExceptBlacklist is null)
            {
                Logger.LogError("Run equipment excepting blacklist was null!");
                return(EquipmentIndex.None);
            }

            PickupDef randomEquip = PickupCatalog.GetPickupDef(equipsExceptBlacklist[UnityEngine.Random.Range(0, equipsExceptBlacklist.Count)]);

            return(randomEquip.equipmentIndex);
        }
Exemple #25
0
        internal string GenericPickupController_GetContextString(On.RoR2.GenericPickupController.orig_GetContextString orig, GenericPickupController self, Interactor activator)
        {
            PickupDef pickupDef  = PickupCatalog.GetPickupDef(self.pickupIndex);
            string    pickupText = string.Format(Language.GetString(((pickupDef != null) ? pickupDef.interactContextToken : null) ?? string.Empty), Language.GetString(pickupDef.nameToken));

            if (pickupDef.itemIndex != ItemIndex.None)
            {
                ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex);
                pickupText += $"\n\n{Language.GetString( mod.config.MiscPickupDescriptionAdvanced.Value ? itemDef.descriptionToken : itemDef.pickupToken)}";
            }
            else if (pickupDef.equipmentIndex != EquipmentIndex.None)
            {
                EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(pickupDef.equipmentIndex);
                pickupText += $"\n\n{Language.GetString(mod.config.MiscPickupDescriptionAdvanced.Value ? equipmentDef.descriptionToken : equipmentDef.pickupToken)}";
            }
            return(pickupText);
        }
        private void GenericPickupController_OnTriggerStay(On.RoR2.GenericPickupController.orig_OnTriggerStay orig, GenericPickupController self, Collider other)
        {
            if (!ArtifactEnabled)
            {
                orig(self, other);
                return;
            }

            if (NetworkServer.active && self.waitStartTime.timeSince >= self.waitDuration && !self.consumed)
            {
                CharacterBody component = other.GetComponent <CharacterBody>();
                if (component)
                {
                    PickupDef pickupDef = PickupCatalog.GetPickupDef(self.pickupIndex);
                    ItemIndex itemIndex = (pickupDef != null) ? pickupDef.itemIndex : ItemIndex.None;
                    if (itemIndex != ItemIndex.None && ItemCatalog.GetItemDef(itemIndex).tier == ItemTier.Lunar && component.isPlayerControlled)
                    {
                        return;
                    }
                    EquipmentIndex equipmentIndex = (pickupDef != null) ? pickupDef.equipmentIndex : EquipmentIndex.None;
                    if (equipmentIndex != EquipmentIndex.None)
                    {
                        if (EquipmentCatalog.GetEquipmentDef(equipmentIndex).isLunar)
                        {
                            return;
                        }
                        if (component.inventory && component.inventory.currentEquipmentIndex != EquipmentIndex.None)
                        {
                            return;
                        }
                    }
                    if (pickupDef != null && pickupDef.coinValue != 0U && component.isPlayerControlled)
                    {
                        return;
                    }
                    if (GenericPickupController.BodyHasPickupPermission(component))
                    {
                        self.AttemptGrant(component);
                    }
                }
            }
        }
Exemple #27
0
        public static string LogDropItemsToFile(string baseFolderPath = null)
        {
            baseFolderPath = baseFolderPath ?? System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "RiskOfRain2Items");

            Directory.CreateDirectory(baseFolderPath);

            foreach (ItemTier itemTier in ItemsHelper.ItemTiers)
            {
                IEnumerable <PickupIndex> items   = ItemsHelper.GetDropListForTier(itemTier, true);
                StringBuilder             builder = new StringBuilder();
                builder.AppendLine("Display Name,Internal Name");
                foreach (PickupIndex item in items)
                {
                    PickupDef pickupDef = PickupCatalog.GetPickupDef(item);
                    // Removing ItemIndex. because its automatically added, and removing commas because we need commas for comma seperated values
                    builder.AppendLine($"{Language.GetString(pickupDef.nameToken).Replace(",","")},{pickupDef.internalName.Replace("ItemIndex.", "")}");
                }
                File.WriteAllText(System.IO.Path.Combine(baseFolderPath, $"{itemTier}.csv"), builder.ToString());
            }

            return(baseFolderPath);
        }
Exemple #28
0
        private void GiveRandomRed(On.RoR2.CharacterBody.orig_OnInventoryChanged orig, CharacterBody self) //ripped from harbcrate, i did credit though.
        {
            orig(self);
            var amount = GetCount(self);

            if (amount > 1)
            {
                self.inventory.RemoveItem(catalogIndex);
                PickupIndex loot = Run.instance.treasureRng.NextElementUniform(Run.instance.availableTier3DropList);
                if (self.isPlayerControlled)
                {
                    PickupDropletController.CreatePickupDroplet(loot, self.corePosition, Vector3.up * 5);
                }
                else
                {
                    PickupDef def = PickupCatalog.GetPickupDef(loot);
                    self.inventory.GiveItem(def.itemIndex);
                    var lootCount = self.inventory.GetItemCount(def.itemIndex);
                    Chat.AddPickupMessage(self, def.nameToken, ColorCatalog.GetColor(ItemCatalog.GetItemDef(def.itemIndex).colorIndex), (uint)lootCount);
                }
            }
        }
Exemple #29
0
        private static void CommandGroupInterceptHook(On.RoR2.Artifacts.CommandArtifactManager.orig_OnDropletHitGroundServer orig, ref GenericPickupController.CreatePickupInfo createPickupInfo, ref bool shouldSpawn)
        {
            if (!shouldSpawn)
            {
                return;
            }

            PickupIndex pickupIndex = createPickupInfo.pickupIndex;

            if (pickupIndex != PickupIndex.none)
            {
                PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
                if (pickupDef != null)
                {
                    if (pickupDef.itemIndex != ItemIndex.None && Catalog.aspectItemIndexes.Contains(pickupDef.itemIndex))
                    {
                        if (Configuration.AspectWorldUnique.Value && Configuration.AspectCommandGroupItems.Value)
                        {
                            AspectCommandDroplet(pickupDef, createPickupInfo.position, createPickupInfo.rotation, ref shouldSpawn);
                        }
                    }

                    if (pickupDef.equipmentIndex != EquipmentIndex.None && Catalog.aspectEquipIndexes.Contains(pickupDef.equipmentIndex))
                    {
                        if (Configuration.AspectCommandGroupEquip.Value)
                        {
                            AspectCommandDroplet(pickupDef, createPickupInfo.position, createPickupInfo.rotation, ref shouldSpawn);
                        }
                    }
                }
            }

            if (!shouldSpawn)
            {
                return;
            }

            orig(ref createPickupInfo, ref shouldSpawn);
        }
        private void BuildNotification(PickupIndex pickupIndex, RoR2.UI.PingIndicator pingIndicator)
        {
            LocalUser localUser = LocalUserManager.GetFirstLocalUser();

            if (localUser.currentNetworkUser.userName ==
                Util.GetBestMasterName(pingIndicator.pingOwner.GetComponent <CharacterMaster>()))
            {
                if (localUser.userProfile.HasDiscoveredPickup(pickupIndex))
                {
                    PickupDef pickup = PickupCatalog.GetPickupDef(pickupIndex);

                    ItemDef      item     = ItemCatalog.GetItemDef(pickup.itemIndex);
                    EquipmentDef equip    = EquipmentCatalog.GetEquipmentDef(pickup.equipmentIndex);
                    ArtifactDef  artifact = ArtifactCatalog.GetArtifactDef(pickup.artifactIndex);

                    GenericNotification notification = Object
                                                       .Instantiate(Resources.Load <GameObject>("Prefabs/NotificationPanel2"))
                                                       .GetComponent <GenericNotification>();

                    if (item != null)
                    {
                        notification.SetItem(item);
                    }
                    else if (equip != null)
                    {
                        notification.SetEquipment(equip);
                    }
                    else if (artifact != null)
                    {
                        notification.SetArtifact(artifact);
                    }

                    notification.transform.SetParent(RoR2Application.instance.mainCanvas.transform, false);
                    notification.transform.position = new Vector3(notification.transform.position.x + 2, 95, 0);
                }
            }
        }