Example #1
0
        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)
                {
                    var interactor = GetInstanceField(typeof(ScrapperController), scrapperController, "interactor") as Interactor;
                    Debug.Log("Interactor Established");

                    PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
                    if (interactor)
                    {
                        CharacterBody component = interactor.GetComponent <CharacterBody>();
                        component.inventory.GiveItem(pickupDef.itemIndex);
                        ChatHandler.SendRichCauldronMessage(component.inventory.GetComponent <CharacterMaster>(), pickupIndex);
                        scrapperController.itemsEaten -= 1;
                    }
                }
            }
        }
Example #2
0
        private void ReloadHooks(object _ = null, EventArgs __ = null)
        {
            if (_previouslyEnabled && !ModIsEnabled.Value)
            {
                GeneralHooks.UnHook();
                MoneySharingHooks.UnHook();
                ItemSharingHooks.UnHook();
                EquipmentSharingHooks.UnHook();
                ChatHandler.UnHook();
                _previouslyEnabled = false;
            }

            if (!_previouslyEnabled && ModIsEnabled.Value)
            {
                _previouslyEnabled = true;
                GeneralHooks.Hook();
                MoneySharingHooks.Hook();
                ItemSharingHooks.Hook();
                EquipmentSharingHooks.Hook();
                ChatHandler.Hook();
            }
        }
Example #3
0
        private static void OnGrantItem(On.RoR2.GenericPickupController.orig_GrantItem orig,
                                        GenericPickupController self, CharacterBody body, Inventory inventory)
        {
            var item    = PickupCatalog.GetPickupDef(self.pickupIndex);
            var itemDef = ItemCatalog.GetItemDef(item.itemIndex);
            var randomizedPlayerDict = new Dictionary <CharacterMaster, PickupDef>();

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

                foreach (var player in PlayerCharacterMasterController.instances.Select(p => p.master))
                {
                    // Ensure character is not original player that picked up item
                    if (player.inventory == 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);
                    }
                }
                ChatHandler.SendRichRandomizedPickupMessage(body.master, item, randomizedPlayerDict);
                orig(self, body, inventory);
                return;
            }

            ChatHandler.SendRichPickupMessage(body.master, item);
            orig(self, body, inventory);
        }
Example #4
0
        private static void OnShopPurchase(On.RoR2.PurchaseInteraction.orig_OnInteractionBegin orig,
                                           PurchaseInteraction self, Interactor activator)
        {
            if (!self.CanBeAffordedByInteractor(activator))
            {
                return;
            }

            if (!GeneralHooks.IsMultiplayer())
            {
                orig(self, activator);
                return;
            }

            var shop = self.GetComponent <ShopTerminalBehavior>();

            #region Cauldronfix

            if (ShareSuite.PrinterCauldronFixEnabled.Value)
            {
                var characterBody = activator.GetComponent <CharacterBody>();
                var inventory     = characterBody.inventory;

                if (self.costType == CostTypeIndex.WhiteItem ||
                    self.costType == CostTypeIndex.GreenItem ||
                    self.costType == CostTypeIndex.RedItem ||
                    self.costType == CostTypeIndex.BossItem ||
                    self.costType == CostTypeIndex.LunarItemOrEquipment)
                {
                    var item = PickupCatalog.GetPickupDef(shop.CurrentPickupIndex()).itemIndex;
                    inventory.GiveItem(item);
                    ChatHandler.SendRichCauldronMessage(inventory.GetComponent <CharacterMaster>(),
                                                        shop.CurrentPickupIndex());
                    orig(self, activator);
                    return;
                }
            }

            #endregion Cauldronfix

            #region EquipDronefix

            if (ShareSuite.EquipmentShared.Value)
            {
                var rng       = self.GetComponent <Xoroshiro128Plus>();
                var itemIndex = ItemIndex.None;

                var costTypeDef = CostTypeCatalog.GetCostTypeDef(self.costType);
                if (shop)
                {
                    itemIndex = PickupCatalog.GetPickupDef(shop.CurrentPickupIndex()).itemIndex;
                }

                var payCostResults = costTypeDef.PayCost(self.cost,
                                                         activator, self.gameObject, rng, itemIndex);

                foreach (var equipmentIndex in payCostResults.equipmentTaken)
                {
                    //TODO fix equipment drones here
                }
            }
            #endregion EquipDronefix

            orig(self, activator);
        }
        private static void OnGrantEquipment(On.RoR2.GenericPickupController.orig_GrantEquipment orig,
                                             GenericPickupController self, CharacterBody body, Inventory inventory)
        {
            #region Sharedequipment

            if (!ShareSuite.EquipmentShared.Value || !GeneralHooks.IsMultiplayer() || !NetworkServer.active)
            {
                orig(self, body, inventory);
                return;
            }

            // Get the old and new equipment's index
            var oldEquip            = body.inventory.currentEquipmentIndex;
            var oldEquipPickupIndex = GetPickupIndex(oldEquip);
            var newEquip            = PickupCatalog.GetPickupDef(self.pickupIndex).equipmentIndex;

            // Send the pickup message
            ChatHandler.SendPickupMessage(body.master, self.pickupIndex);

            // Give the equipment to the picker
            inventory.SetEquipmentIndex(newEquip);

            // Destroy the object
            Object.Destroy(self.gameObject);

            // If the old equipment was not shared and the new one is, drop the blacklisted equipment and any other
            // shared equipment that the other players have
            if (!EquipmentShared(oldEquip) && EquipmentShared(newEquip))
            {
                CreateDropletIfExists(oldEquipPickupIndex, self.transform.position);
                DropAllOtherSharedEquipment(self, body, oldEquip);
            }
            // If the old equipment was shared and the new one isn't, but the picker is the only one alive with the
            // shared equipment, drop it on the ground and return
            else if (EquipmentShared(oldEquip) && !EquipmentShared(newEquip) && GetLivingPlayersWithEquipment(oldEquip) < 1 ||
                     !EquipmentShared(oldEquip) && !EquipmentShared(newEquip))
            {
                CreateDropletIfExists(oldEquipPickupIndex, self.transform.position);
                return;
            }
            // If the new equip is shared, create a droplet of the old one.
            else if (EquipmentShared(newEquip))
            {
                CreateDropletIfExists(oldEquipPickupIndex, self.transform.position);
            }
            // If the equipment they're picking up is not shared and someone else is alive with the shared equipment,
            // return
            else
            {
                return;
            }

            // Loop over everyone who has an inventory and isn't the picker
            foreach (var player in PlayerCharacterMasterController.instances.Select(p => p.master)
                     .Where(p => p.inventory && p != body.master))
            {
                var playerInventory     = player.inventory;
                var playerOrigEquipment = playerInventory.currentEquipmentIndex;

                // If the player currently has an equipment that's blacklisted
                if (!EquipmentShared(playerOrigEquipment))
                {
                    // And the config option is set so that they will drop the item when shared
                    if (!ShareSuite.DropBlacklistedEquipmentOnShare.Value)
                    {
                        continue;
                    }
                    // Create a droplet of their current blacklisted equipment on the ground
                    var transform   = player.GetBodyObject().transform;
                    var pickupIndex = PickupCatalog.FindPickupIndex(playerOrigEquipment);
                    PickupDropletController.CreatePickupDroplet(pickupIndex, transform.position,
                                                                transform.forward * 20f);
                }

                // Give the player the new equipment
                playerInventory.SetEquipmentIndex(newEquip);
                self.NetworkpickupIndex = PickupCatalog.FindPickupIndex(newEquip);

                // Sync the equipment if they're playing MUL-T
                SyncToolbotEquip(player, ref newEquip);
            }

            #endregion
        }
Example #6
0
        private static void OnShopPurchase(On.RoR2.PurchaseInteraction.orig_OnInteractionBegin orig,
                                           PurchaseInteraction self, Interactor activator)
        {
            if (!self.CanBeAffordedByInteractor(activator))
            {
                return;
            }

            if (!GeneralHooks.IsMultiplayer())
            {
                orig(self, activator);
                return;
            }

            if (self.costType == CostTypeIndex.None)
            {
                orig(self, activator);
                return;
            }

            var shop = self.GetComponent <ShopTerminalBehavior>();

            #region Cauldronfix

            if (printerCosts.Contains(self.costType))
            {
                if (ShareSuite.PrinterCauldronFixEnabled.Value)
                {
                    var characterBody = activator.GetComponent <CharacterBody>();
                    var inventory     = characterBody.inventory;


                    var item = PickupCatalog.GetPickupDef(shop.CurrentPickupIndex())?.itemIndex;

                    if (item == null)
                    {
                        RoR2.Console.print("ShareSuite: PickupCatalog is null.");
                    }
                    else
                    {
                        inventory.GiveItem(item.Value);
                    }

                    orig(self, activator);
                    ChatHandler.SendRichCauldronMessage(inventory.GetComponent <CharacterMaster>(),
                                                        shop.CurrentPickupIndex());
                    return;
                }
            }

            #endregion Cauldronfix

            #region EquipDronefix

            if (ShareSuite.EquipmentShared.Value)
            {
                if (self.costType == CostTypeIndex.Equipment)
                {
                    var rng       = self.GetComponent <Xoroshiro128Plus>();
                    var itemIndex = ItemIndex.None;

                    var costTypeDef = CostTypeCatalog.GetCostTypeDef(self.costType);
                    if (shop)
                    {
                        itemIndex = PickupCatalog.GetPickupDef(shop.CurrentPickupIndex()).itemIndex;
                    }

                    var payCostResults = costTypeDef.PayCost(self.cost,
                                                             activator, self.gameObject, rng, itemIndex);

                    if (payCostResults.equipmentTaken.Count >= 1)
                    {
                        orig(self, activator);
                        EquipmentSharingHooks.RemoveAllUnBlacklistedEquipment();
                        return;
                    }
                }
            }

            #endregion

            orig(self, activator);
        }