Ejemplo n.º 1
0
        private void OnEnable()
        {
            dropTable     = Resources.Load <PickupDropTable>("DropTables/dtSacrificeArtifact");
            body          = gameObject.GetComponent <CharacterBody>();
            maxItemsGiven = body.inventory.GetItemCount(StayDownItem.index) * softCapStep;
            CalculateScrapValues();

            On.RoR2.GlobalEventManager.OnCharacterDeath += GlobalEventManager_OnCharacterDeath;
            On.RoR2.Run.EndStage += Run_EndStage;
        }
Ejemplo n.º 2
0
        private void On_RunBuildDropTable(On.RoR2.Run.orig_BuildDropTable orig, Run self)
        {
            var newItemMask = self.availableItems;
            var newEqpMask  = self.availableEquipment;

            foreach (CatalogBoilerplate bpl in allInstances)
            {
                if (bpl is Item item)
                {
                    bool shouldDrop = item.enabled && item.itemDef.DoesNotContainTag(ItemTag.WorldUnique);
                    if (shouldDrop)
                    {
                        newItemMask.Add(item.catalogIndex);
                    }
                    else
                    {
                        newItemMask.Remove(item.catalogIndex);
                    }
                }
                else if (bpl is Equipment equipment)
                {
                    bool shouldDrop = equipment.enabled;
                    if (shouldDrop)
                    {
                        newEqpMask.Add(equipment.catalogIndex);
                    }
                    else
                    {
                        newEqpMask.Remove(equipment.catalogIndex);
                    }
                }
            }
            self.availableItems     = newItemMask;
            self.availableEquipment = newEqpMask;
            orig(self);
            //should force-update most cached drop tables
            PickupDropTable.RegenerateAll(Run.instance);
        }
Ejemplo n.º 3
0
            private static void InitItemAndEquipmentDisabling()
            {
                Run.onRunSetRuleBookGlobal += (run, rulebook) =>
                {
                    foreach (var disabledItem in disabledItems.Keys)
                    {
                        if (run.availableItems.Contains(disabledItem))
                        {
                            run.availableItems.Remove(disabledItem);
                        }
                    }
                    foreach (var equipmentIndex in disabledEquipment.Keys)
                    {
                        if (run.availableEquipment.Contains(equipmentIndex))
                        {
                            run.availableEquipment.Remove(equipmentIndex);
                        }
                    }
                    PickupDropTable.RegenerateAll(run);
                };

                On.RoR2.Artifacts.EnigmaArtifactManager.OnRunStartGlobal += (orig, run) =>
                {
                    orig(run);
                    if (NetworkServer.active)
                    {
                        RoR2.Artifacts.EnigmaArtifactManager.validEquipment.RemoveAll(x => disabledEquipment.ContainsKey(x));
                    }
                };

                RoR2Application.onLoad += () =>
                {
                    var itemDefs = typeof(MysticsItemsContent.Items).GetFields().Select(x => x.GetValue(null) as ItemDef)
                                   .Where(x => !x.hidden && x.inDroppableTier).ToList();
                    var equipmentDefs = typeof(MysticsItemsContent.Equipment).GetFields().Select(x => x.GetValue(null) as EquipmentDef)
                                        .Where(x => x.canDrop).ToList();

                    List <string> richTags = new List <string>()
                    {
                        "align", "color", "alpha", "b", "i", "cspace", "font", "indent", "line-height", "line-indent", "link",
                        "lowercase", "uppercase", "smallcaps", "margin", "mark", "mspace", "noparse", "nobr", "page", "pos", "size",
                        "space", "sprite", "s", "u", "style", "sub", "sup", "voffset", "width"
                    };
                    string GetSanitizedStringFromToken(string token)
                    {
                        var initialString = Language.english.GetLocalizedStringByToken(token);
                        var finalString   = "";

                        var inRichTag    = false;
                        var wasInRichTag = false;

                        while (initialString.Length > 0)
                        {
                            var chr = initialString[0];
                            switch (chr)
                            {
                            case '<':
                                foreach (var richTag in richTags)
                                {
                                    if ((initialString.IndexOf(richTag, StringComparison.InvariantCulture) == 1 || initialString.IndexOf("/" + richTag, StringComparison.InvariantCulture) == 1) && initialString.Contains(">"))
                                    {
                                        inRichTag    = true;
                                        wasInRichTag = true;
                                        break;
                                    }
                                }
                                break;

                            case '>':
                                inRichTag = false;
                                break;
                            }
                            if (!inRichTag)
                            {
                                if (!wasInRichTag)
                                {
                                    switch (chr)
                                    {
                                    case '=':
                                    case '\n':
                                    case '\t':
                                    case '\\':
                                    case '"':
                                    case '\'':
                                    case '[':
                                    case ']':
                                        finalString += " ";
                                        break;

                                    default:
                                        finalString += chr;
                                        break;
                                    }
                                }
                                wasInRichTag = false;
                            }
                            initialString = initialString.Remove(0, 1);
                        }

                        return(finalString);
                    }

                    foreach (var itemDef in itemDefs)
                    {
                        ConfigOptions.ConfigurableValue.CreateBool(
                            categoryGUID,
                            categoryName,
                            config,
                            "Enabled Items",
                            GetSanitizedStringFromToken(itemDef.nameToken),
                            true,
                            "Should this item be enabled? Changes to this value take effect only at the start of a run. Item description: " + GetSanitizedStringFromToken(itemDef.pickupToken),
                            onChanged: (newValue) =>
                        {
                            if (!newValue)
                            {
                                disabledItems.Add(itemDef.itemIndex, new DisabledItem
                                {
                                    previousTier   = itemDef.tier,
                                    wasWorldUnique = itemDef.ContainsTag(ItemTag.WorldUnique)
                                });
                                itemDef.tier           = ItemTier.NoTier;
                                itemDef.deprecatedTier = ItemTier.NoTier;
                                HG.ArrayUtils.ArrayAppend(ref itemDef.tags, ItemTag.WorldUnique);
                            }
                            else
                            {
                                if (disabledItems.ContainsKey(itemDef.itemIndex))
                                {
                                    var disabledItem       = disabledItems[itemDef.itemIndex];
                                    itemDef.tier           = disabledItem.previousTier;
                                    itemDef.deprecatedTier = disabledItem.previousTier;
                                    if (!disabledItem.wasWorldUnique)
                                    {
                                        HG.ArrayUtils.ArrayRemoveAtAndResize(ref itemDef.tags, Array.IndexOf(itemDef.tags, ItemTag.WorldUnique));
                                    }
                                    disabledItems.Remove(itemDef.itemIndex);
                                }
                            }
                        }
                            );
                    }

                    foreach (var equipmentDef in equipmentDefs)
                    {
                        ConfigOptions.ConfigurableValue.CreateBool(
                            categoryGUID,
                            categoryName,
                            config,
                            "Enabled Equipment",
                            GetSanitizedStringFromToken(equipmentDef.nameToken),
                            true,
                            "Should this equipment be enabled? Changes to this value take effect only at the start of a run. Equipment description: " + GetSanitizedStringFromToken(equipmentDef.pickupToken),
                            onChanged: (newValue) =>
                        {
                            if (!newValue)
                            {
                                disabledEquipment.Add(equipmentDef.equipmentIndex, new DisabledEquipment
                                {
                                    appearedInSinglePlayer = equipmentDef.appearsInSinglePlayer,
                                    appearedInMultiPlayer  = equipmentDef.appearsInMultiPlayer
                                });

                                equipmentDef.canDrop = false;
                                equipmentDef.appearsInMultiPlayer  = false;
                                equipmentDef.appearsInSinglePlayer = false;
                            }
                            else
                            {
                                if (disabledEquipment.ContainsKey(equipmentDef.equipmentIndex))
                                {
                                    var _disabledEquipment             = disabledEquipment[equipmentDef.equipmentIndex];
                                    equipmentDef.canDrop               = true;
                                    equipmentDef.appearsInSinglePlayer = _disabledEquipment.appearedInSinglePlayer;
                                    equipmentDef.appearsInMultiPlayer  = _disabledEquipment.appearedInMultiPlayer;
                                    disabledEquipment.Remove(equipmentDef.equipmentIndex);
                                }
                            }
                        }
                            );
                    }
                };
            }
Ejemplo n.º 4
0
        private void ModifyDropList(ItemIndex itemIndex, bool add)
        {
            Run      run      = RoR2.Run.instance;
            ItemDef  itemDef  = ItemCatalog.GetItemDef(itemIndex);
            ItemTier itemTier = itemDef.tier;

            if (itemDef.hidden || itemTier == ItemTier.NoTier)
            {
                return;
            }


            var pickupIndex = PickupCatalog.FindPickupIndex(itemIndex);

            bool runHasItem   = run.availableItems.array[(int)itemIndex];
            bool tier1Has     = run.availableTier1DropList.Contains(pickupIndex);
            bool tier2Has     = run.availableTier2DropList.Contains(pickupIndex);
            bool tier3Has     = run.availableTier3DropList.Contains(pickupIndex);
            bool tierBossHas  = run.availableBossDropList.Contains(pickupIndex);
            bool tierLunarHas = run.availableLunarDropList.Contains(pickupIndex);


            if (add)
            {
                if (!runHasItem)
                {
                    //run.availableItems.array[(int)itemIndex] = true;
                    run.availableItems.Add(itemIndex);
                    switch (itemTier)
                    {
                    case ItemTier.Tier1:
                        if (!tier1Has)
                        {
                            run.availableTier1DropList.Add(pickupIndex);
                        }
                        break;

                    case ItemTier.Tier2:
                        if (!tier2Has)
                        {
                            run.availableTier2DropList.Add(pickupIndex);
                        }
                        break;

                    case ItemTier.Tier3:
                        if (!tier3Has)
                        {
                            run.availableTier3DropList.Add(pickupIndex);
                        }
                        break;

                    case ItemTier.Lunar:
                        if (!tierLunarHas)
                        {
                            run.availableLunarDropList.Add(pickupIndex);
                        }
                        break;

                    case ItemTier.Boss:
                        if (!tierBossHas)
                        {
                            run.availableBossDropList.Add(pickupIndex);
                        }
                        break;
                    }
                }
            }
            else
            {
                if (runHasItem)
                {
                    //run.availableItems.array[(int)itemIndex] = false;
                    run.availableItems.Remove(itemIndex);
                    switch (itemTier)
                    {
                    case ItemTier.Tier1:
                        if (tier1Has)
                        {
                            run.availableTier1DropList.Remove(pickupIndex);
                        }
                        break;

                    case ItemTier.Tier2:
                        if (tier2Has)
                        {
                            run.availableTier2DropList.Remove(pickupIndex);
                        }
                        break;

                    case ItemTier.Tier3:
                        if (tier3Has)
                        {
                            run.availableTier3DropList.Remove(pickupIndex);
                        }
                        break;

                    case ItemTier.Lunar:
                        if (tierLunarHas)
                        {
                            run.availableLunarDropList.Remove(pickupIndex);
                        }
                        break;

                    case ItemTier.Boss:
                        if (tierBossHas)
                        {
                            run.availableBossDropList.Remove(pickupIndex);
                        }
                        break;
                    }
                }
            }
            run.BuildDropTable();
            PickupDropTable.RegenerateAll(run);
            bool tier1Available  = ItemTierAvailable(ItemTier.Tier1);
            bool tier2Available  = ItemTierAvailable(ItemTier.Tier2);
            bool tier3Available  = ItemTierAvailable(ItemTier.Tier3);
            bool noTierAvailable = !tier1Available && !tier2Available && !tier3Available;

            //Debug.Log($"Tier Availability: {tier1Available} {tier2Available} {tier3Available}");

            void DestroyAndSpawnGold(GameObject gameObject, int count = 0)
            {
                if (gameObject)
                {
                    GameObject gameObject9 = UnityEngine.Object.Instantiate <GameObject>(Resources.Load <GameObject>("Prefabs/NetworkedObjects/BonusMoneyPack"), gameObject.transform.position, UnityEngine.Random.rotation);
                    gameObject9.GetComponent <TeamFilter>().teamIndex = TeamIndex.Player;
                    for (int i = 0; i < count; i++)
                    {
                        NetworkServer.Spawn(gameObject9);
                    }
                    Destroy(gameObject);
                }
            }

            void HandleTerminalBehaviors()
            {
                foreach (var shopTerminalBehavior in InstanceTracker.GetInstancesList <ShopTerminalBehavior>())
                {
                    if (noTierAvailable)
                    {
                        if (shopTerminalBehavior.GetComponent <PurchaseInteraction>().Networkavailable)
                        {
                            DestroyAndSpawnGold(shopTerminalBehavior.gameObject, 3);
                        }
                    }
                    else
                    if (shopTerminalBehavior.pickupIndex == pickupIndex)
                    {
                        shopTerminalBehavior.GenerateNewPickupServer();
                        shopTerminalBehavior.UpdatePickupDisplayAndAnimations();
                    }
                }
            }

            HandleTerminalBehaviors();

            void HandleChestBehaviors()
            {
                List <ChestBehavior> chestBehaviorsToRemove = new List <ChestBehavior>();

                foreach (var chestBehavior in InstanceTracker.GetInstancesList <ChestBehavior>())
                {
                    bool notPurchased = chestBehavior.GetComponent <PurchaseInteraction>().Networkavailable;
                    void DestroyGold()
                    {
                        if (notPurchased)
                        {
                            DestroyAndSpawnGold(chestBehavior.gameObject, 1);
                            chestBehaviorsToRemove.Add(chestBehavior);
                        }
                    }

                    if (noTierAvailable)
                    {
                        DestroyGold();
                    }
                    else
                    {
                        chestBehavior.tier1Chance *= (tier1Available ? 1 : 0);
                        chestBehavior.tier2Chance *= (tier2Available ? 1 : 0);
                        chestBehavior.tier3Chance *= (tier3Available ? 1 : 0);

                        var availableItemTiers = new List <ItemTier>();
                        if (chestBehavior.tier1Chance != 0)
                        {
                            availableItemTiers.Add(ItemTier.Tier1);
                        }
                        if (chestBehavior.tier2Chance != 0)
                        {
                            availableItemTiers.Add(ItemTier.Tier2);
                        }
                        if (chestBehavior.tier3Chance != 0)
                        {
                            availableItemTiers.Add(ItemTier.Tier3);
                        }
                        bool itemTagAvailable = chestBehavior.requiredItemTag == ItemTag.Any ? true : Availability.ItemTagAvailable(availableItemTiers.ToArray(), chestBehavior.requiredItemTag);

                        if (!itemTagAvailable || (chestBehavior.tier1Chance == 0 && chestBehavior.tier2Chance == 0 && chestBehavior.tier3Chance == 0))
                        {
                            DestroyGold();
                        }
                        else
                        {
                            if (chestBehavior.dropPickup == pickupIndex)
                            {
                                chestBehavior.Start();
                            }
                        }
                    }
                }
                if (chestBehaviorsToRemove.Count > 0)
                {
                    foreach (var cb in chestBehaviorsToRemove)
                    {
                        if (cb)
                        {
                            InstanceTracker.Remove(cb);
                        }
                    }
                }
            }

            HandleChestBehaviors();
        }
Ejemplo n.º 5
0
 public static bool IsLunarDropTable(this PickupDropTable table) => table is LunarScrap.LunarPrinter.LunarDropTable;
        private void On_RunBuildDropTable(On.RoR2.Run.orig_BuildDropTable orig, Run self)
        {
            var newItemMask = self.availableItems;
            var newEqpMask  = self.availableEquipment;

            foreach (CatalogBoilerplate bpl in allInstances)
            {
                if (!bpl.enabled)
                {
                    if (bpl is Equipment_V2 eqp)
                    {
                        newEqpMask.Remove(eqp.catalogIndex);
                    }
                    else if (bpl is Item_V2 item)
                    {
                        newItemMask.Remove(item.catalogIndex);
                    }
                }
                else
                {
                    if (bpl is Equipment_V2 eqp)
                    {
                        newEqpMask.Add(eqp.catalogIndex);
                    }
                    else if (bpl is Item_V2 item)
                    {
                        newItemMask.Add(item.catalogIndex);
                    }
                }
            }

            //ItemDropAPI completely overwrites drop tables; need to perform separate removal
            if (ItemDropAPI.Loaded)
            {
                ItemDropAPI.RemoveFromDefaultByTier(
                    allInstances.Where(bpl => bpl is Item_V2 && !bpl.enabled)
                    .Select(bpl => {
                    return(new KeyValuePair <ItemIndex, ItemTier>(((Item_V2)bpl).catalogIndex, ((Item_V2)bpl).itemTier));
                })
                    .ToArray());
                ItemDropAPI.RemoveFromDefaultEquipment(
                    allInstances.Where(bpl => bpl is Equipment_V2 && !bpl.enabled)
                    .Select(bpl => ((Equipment_V2)bpl).catalogIndex)
                    .ToArray());

                ItemDropAPI.AddToDefaultByTier(
                    allInstances.Where(bpl => bpl is Item_V2 && bpl.enabled)
                    .Select(bpl => {
                    return(new KeyValuePair <ItemIndex, ItemTier>(((Item_V2)bpl).catalogIndex, ((Item_V2)bpl).itemTier));
                })
                    .ToArray());
                ItemDropAPI.AddToDefaultEquipment(
                    allInstances.Where(bpl => bpl is Equipment_V2 && bpl.enabled)
                    .Select(bpl => ((Equipment_V2)bpl).catalogIndex)
                    .ToArray());
            }
            orig(self);
            //should force-update most cached drop tables
            PickupDropTable.RegenerateAll(Run.instance);
            //update existing Command droplets. part of an effort to disable items mid-stage, may not be necessary while that's prevented
            foreach (var picker in UnityEngine.Object.FindObjectsOfType <PickupPickerController>())
            {
                picker.SetOptionsFromPickupForCommandArtifact(picker.options[0].pickupIndex);
            }
        }