public static void CheckItems()
 {
     foreach (string text in Game.Items.IDs)
     {
         if (Game.Items[text.Replace("gungeon:", "")] != null && Game.Items[text.Replace("gungeon:", "")] is PickupObject)
         {
             PickupObject item = Game.Items[text.Replace("gungeon:", "")];
             foreach (Component component in item.GetComponents <Component>())
             {
                 if (component.GetType().ToString().Contains("BoomhildrItemPool"))
                 {
                     Boomhildr.BoomhildrLootTable.AddItemToPool(item.PickupObjectId);
                 }
                 else if (component.GetType().ToString().Contains("IronsideItemPool"))
                 {
                     Ironside.IronsideLootTable.AddItemToPool(item.PickupObjectId);
                 }
                 else if (component.GetType().ToString().Contains("RustyItemPool"))
                 {
                     Rusty.RustyLootTable.AddItemToPool(item.PickupObjectId);
                 }
             }
         }
     }
 }
Esempio n. 2
0
        public static IEnumerator postStart(AdvancedChamberGunController newProcessor, string modName)
        {
            yield return(null);

            //These variables are for debugging to keep track of how many things were added to the gun
            int newFormesAdded    = 0;
            int masterRoundsAdded = 0;

            //Define a master list
            List <int> FormestoCheck    = new List <int>();
            List <int> MasteriesToCheck = new List <int>();

            //Nullchecks 4-ever
            if (ETGModMainBehaviour.Instance == null || ETGModMainBehaviour.Instance.gameObject == null)
            {
                Debug.LogError($"ChamberGunAPI ({modName}): ETGModMainBehaviour.Instance OR ETGModMainBehaviour.Instance.gameObject was NULL.");
                yield break;
            }
            //Here we check the ETGMod main object for any components with the name of the delivery component.
            foreach (Component component in ETGModMainBehaviour.Instance.gameObject.GetComponents <Component>())
            {
                if (component.GetType().ToString().ToLower().Contains("etgmodchambergundeliverycomponent"))
                {
                    //If the component is present we use reflection to get the lists it contains and adds them to the master list we defined earlier
                    List <int> formeIDsInComp   = (List <int>)ReflectionHelper.GetValue(component.GetType().GetField("chamberGunFormIDs"), component);
                    List <int> masteryIDsInComp = (List <int>)ReflectionHelper.GetValue(component.GetType().GetField("chamberGunMasteryIDs"), component);
                    string     compModName      = (string)ReflectionHelper.GetValue(component.GetType().GetField("modName"), component);
                    if (formeIDsInComp != null && formeIDsInComp.Count > 0)
                    {
                        //Add the list of Forme IDs to the master list
                        FormestoCheck.AddRange(formeIDsInComp);
                    }
                    if (masteryIDsInComp != null && masteryIDsInComp.Count > 0)
                    {
                        //Add the list of Mastery IDs to the master list.
                        MasteriesToCheck.AddRange(masteryIDsInComp);
                    }
                    Debug.Log($"ChamberGunAPI ({modName}): Detected Delivery Component from Mod '{compModName}' with {formeIDsInComp.Count} formes and {masteryIDsInComp.Count} additional masteries.");
                }
            }

            //If the formes to check master list is not empty or null, we iterate through it
            if (FormestoCheck != null && FormestoCheck.Count > 0)
            {
                foreach (int id in FormestoCheck)
                {
                    //Get the pickupobject corresponding to the ID
                    PickupObject gunPickObj = PickupObjectDatabase.GetById(id);
                    if (gunPickObj == null)
                    {
                        Debug.LogError($"ChamberGunAPI ({modName}): A mod attempted to add item ID {id} as a forme, but that ID does not exist!");
                    }
                    if (!(gunPickObj is Gun))
                    {
                        Debug.LogError($"ChamberGunAPI ({modName}): A mod attempted to add item ID {id} as a forme, but that ID does not correspond to a Gun.");
                    }

                    //Iterate through each component in the pickupobject looking for the one containing all the actual info on the forme
                    bool foundCompOnThisID = false;
                    foreach (Component component in gunPickObj.GetComponents <Component>())
                    {
                        if (component.GetType().ToString().ToLower().Contains("customchambergunform"))
                        {
                            foundCompOnThisID = true;

                            //Use reflection to get all the necessary values off the component
                            string     modname           = (string)ReflectionHelper.GetValue(component.GetType().GetField("modName"), component);
                            int        desiredTileset    = (int)ReflectionHelper.GetValue(component.GetType().GetField("floorTilesetID"), component);
                            List <int> validMasterRounds = (List <int>)ReflectionHelper.GetValue(component.GetType().GetField("viableMasterRounds"), component);
                            int        correspondingForm = (int)ReflectionHelper.GetValue(component.GetType().GetField("correspondingFormeID"), component);
                            float      index             = (float)ReflectionHelper.GetValue(component.GetType().GetField("indexValue"), component);

                            //Some debugging messages for when shit inevitably goes wrong
                            Debug.Log($"ChamberGunAPI ({modName}): Adding cross mod chamber gun form with the following criteria -> ModName({modName}), TilesetID({desiredTileset}), GunID({correspondingForm}), Index({index})");
                            if (string.IsNullOrEmpty(modname) || modname == "Unset")
                            {
                                Debug.LogWarning($"ChamberGunAPI ({modName}): Trying to add a form with no modname set, this may make things difficult to debug!");
                            }

                            if (validMasterRounds == null)
                            {
                                validMasterRounds = new List <int>()
                                {
                                };
                            }

                            //Actually Add forms to the processor
                            AdvancedChamberGunController.floorFormeDatas.Add(new AdvancedChamberGunController.ChamberGunData()
                            {
                                modName              = modname,
                                floorTilesetID       = desiredTileset,
                                indexValue           = index,
                                correspondingFormeID = correspondingForm,
                                viableMasterRounds   = validMasterRounds,
                            });
                            newFormesAdded += 1;
                        }
                    }
                    if (foundCompOnThisID == false)
                    {
                        //If iterating through every component on the gun didn't find a proper component, we shit out an error here
                        Debug.LogError($"ChamberGunAPI ({modName}): A mod attempted to add item ID {id} as a forme, but that ID did not possess a data component?");
                    }
                }
            }
            //Do the same with the Masteries list
            if (MasteriesToCheck != null && MasteriesToCheck.Count > 0)
            {
                foreach (int id in MasteriesToCheck)
                {
                    //Get the pickupobject corresponding to the ID
                    PickupObject masteryObj = PickupObjectDatabase.GetById(id);
                    if (masteryObj == null)
                    {
                        Debug.LogError($"ChamberGunAPI ({modName}): A mod attempted to add item ID {id} as a custom mastery, but that ID does not exist!");
                    }

                    //Iterate through each component on the item
                    bool foundCompOnThisID = false;
                    foreach (Component component in masteryObj.GetComponents <Component>())
                    {
                        if (component.GetType().ToString().ToLower().Contains("customchambergunmasterround"))
                        {
                            foundCompOnThisID = true;
                            string modname      = (string)ReflectionHelper.GetValue(component.GetType().GetField("modName"), component);
                            int    tilesetID    = (int)ReflectionHelper.GetValue(component.GetType().GetField("floorTilesetID"), component);
                            bool   foundTileset = false;

                            //Iterate through each form data in the list to see if there's a form that matches the set tileset id of the mastery
                            foreach (AdvancedChamberGunController.ChamberGunData data in AdvancedChamberGunController.floorFormeDatas)
                            {
                                if (data.floorTilesetID == tilesetID)
                                {
                                    //If the ids match, add the mastery id to that form's list of valid mastery IDs
                                    if (data.viableMasterRounds == null)
                                    {
                                        data.viableMasterRounds = new List <int>()
                                        {
                                        }
                                    }
                                    ;
                                    data.viableMasterRounds.Add(masteryObj.PickupObjectId);
                                    Debug.Log($"ChamberGunAPI ({modName}): Mod '{modname}' added a viable Master round with the Id {masteryObj.PickupObjectId} to the viable master rounds of floor tileset id {tilesetID}.");
                                    masterRoundsAdded++;
                                    foundTileset = true;
                                }
                            }
                            if (!foundTileset)
                            {
                                //If the code is unable to find a valid id in the form list, spit out this error
                                Debug.LogError($"ChamberGunAPI ({modName}): Mod {modname} failed to add viable Master Round with ID {masteryObj.PickupObjectId} because the target floor id ({tilesetID}) does not exist in the custom forme list.");
                            }
                        }
                    }
                    if (!foundCompOnThisID)
                    {
                        //Shit out an error if we didn't find the component
                        Debug.LogError($"ChamberGunAPI ({modName}): A mod attempted to add item ID {id} as a custom mastery, but the item at that ID does not have a data component?");
                    }
                }
            }

            Debug.Log($"Mod '{modName}' correctly completed postStart, adding {newFormesAdded} new formes and {masterRoundsAdded} new valid master rounds.");
            yield break;
        }
    }