Пример #1
0
        private static PickupIndex?GetRandomItemOfTier(ItemTier tier, PickupIndex orDefault)
        {
            switch (tier)
            {
            case ItemTier.Tier1:
                return(PickRandomOf(Blacklist.AvailableTier1DropList));

            case ItemTier.Tier2:
                return(PickRandomOf(Blacklist.AvailableTier2DropList));

            case ItemTier.Tier3:
                return(PickRandomOf(Blacklist.AvailableTier3DropList));

            case ItemTier.Lunar:
                if (ShareSuite.LunarItemsRandomized.Value)
                {
                    return(PickRandomOf(Blacklist.AvailableLunarDropList));
                }
                break;

            case ItemTier.Boss:
                if (ShareSuite.BossItemsRandomized.Value)
                {
                    return(PickRandomOf(Blacklist.AvailableBossDropList));
                }
                break;
            }
            var pickupDef = PickupCatalog.GetPickupDef(orDefault);

            if (Blacklist.HasItem(pickupDef.itemIndex))
            {
                return(null);
            }
            return(orDefault);
        }
Пример #2
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
            });
        }
Пример #3
0
        private static void OnGrantItem(On.RoR2.GenericPickupController.orig_AttemptGrant orig,
                                        GenericPickupController self, CharacterBody body)
        {
            var item    = PickupCatalog.GetPickupDef(self.pickupIndex);
            var itemDef = ItemCatalog.GetItemDef(item.itemIndex);
            var randomizedPlayerDict = new Dictionary <CharacterMaster, PickupDef>();

            // If the player is dead, they might not have a body. The game uses inventory.GetComponent, avoiding the issue entirely.
            var master = body?.master ?? body.inventory?.GetComponent <CharacterMaster>();

            if (( //ShareSuite.RandomizeSharedPickups.Value ||
                    !Blacklist.HasItem(item.itemIndex)) &&
                NetworkServer.active &&
                IsValidItemPickup(self.pickupIndex) &&
                GeneralHooks.IsMultiplayer())
            {
                if (ShareSuite.RandomizeSharedPickups.Value)
                {
                    randomizedPlayerDict.Add(master, item);
                }

                foreach (var player in PlayerCharacterMasterController.instances.Select(p => p.master))
                {
                    // Ensure character is not original player that picked up item
                    if (body != null && player.inventory == body.inventory)
                    {
                        continue;
                    }

                    // Do not reward dead players if not required
                    if (!ShareSuite.DeadPlayersGetItems.Value && player.IsDeadAndOutOfLivesServer())
                    {
                        continue;
                    }

                    if (ShareSuite.RandomizeSharedPickups.Value)
                    {
                        var pickupIndex = GetRandomItemOfTier(itemDef.tier, item.pickupIndex);
                        if (pickupIndex == null)
                        {
                            // Could not find any not blacklisted item in that tier. You get nothing! Good day, sir!
                            continue;
                        }

                        var giveItem = PickupCatalog.GetPickupDef(pickupIndex.Value);

                        player.inventory.GiveItem(giveItem.itemIndex);
                        // Alternative: Only show pickup text for yourself
                        // var givePickupDef = PickupCatalog.GetPickupDef(givePickupIndex);
                        // Chat.AddPickupMessage(body, givePickupDef.nameToken, givePickupDef.baseColor, 1);

                        // Legacy -- old normal pickup message handler
                        //SendPickupMessage(player, giveItem);

                        randomizedPlayerDict.Add(player, giveItem);
                    }
                    // Otherwise give everyone the same item
                    else
                    {
                        player.inventory.GiveItem(item.itemIndex);
                    }
                }

                if (ShareSuite.RandomizeSharedPickups.Value)
                {
                    orig(self, body);
                    ChatHandler.SendRichRandomizedPickupMessage(master, item, randomizedPlayerDict);
                    return;
                }
            }

            orig(self, body);
            ChatHandler.SendRichPickupMessage(master, item);
        }