Artifact of Sequencing v1.0.2

This commit is contained in:
Chev 2021-04-20 21:36:21 -07:00
parent 0c2b6e085d
commit 7c5eb929db
3 changed files with 51 additions and 37 deletions

View file

@ -1,3 +1,7 @@
1.0.2 --
- Artifact should now apply to all connected players
- Fixed a bug where the artifact would still attempt to convert items when the artifact is disabled after a run
1.0.1 --
- Fixed an error in RandomItem() preventing starting items from properly spawning

View file

@ -1,10 +1,10 @@
{
"name": "ArtifactOfSequencing",
"version_number": "1.0.1",
"version_number": "1.0.2",
"website_url": "https://github.com/chev2/RoR2-Mods",
"description": "Spawn with a starting item of every tier. Any picked up items will be converted to the starting item of the same tier.",
"dependencies": [
"bbepis-BepInExPack-5.4.9",
"tristanmcpherson-R2API-3.0.25"
"tristanmcpherson-R2API-3.0.30"
]
}

View file

@ -10,7 +10,7 @@ using UnityEngine;
namespace Chev
{
[BepInDependency("com.bepis.r2api")]
[BepInPlugin("com.Chev.ArtifactOfSequencing", "Artifact of Sequencing", "1.0.1")]
[BepInPlugin("com.Chev.ArtifactOfSequencing", "Artifact of Sequencing", "1.0.2")]
[NetworkCompatibility(CompatibilityLevel.EveryoneMustHaveMod, VersionStrictness.EveryoneNeedSameModVersion)]
[R2APISubmoduleDependency(nameof(ArtifactAPI))]
public class ArtifactOfSequencingMod : BaseUnityPlugin
@ -56,8 +56,6 @@ namespace Chev
// On run start event
// This is when we add our items
Run.onRunStartGlobal += AddBeginningItems;
Logger.LogMessage("Loaded mod com.Chev.ArtifactOfSequencing");
}
/// <summary>
@ -110,45 +108,57 @@ namespace Chev
}
}
/// <summary>
/// Converts any potential items to their corresponding starter item
/// </summary>
private void ConvertPotentialItems(Inventory inv, ItemIndex itemIndex, int count)
{
ItemDef starterItemToCompare = ItemFromTier(ItemCatalog.GetItemDef(itemIndex).tier);
// If they are different items
if (starterItemToCompare != null && starterItemToCompare.itemIndex != itemIndex)
{
int itemCount = inv.GetItemCount(itemIndex);
inv.RemoveItem(itemIndex, itemCount);
inv.GiveItem(starterItemToCompare, itemCount);
}
}
public void AddBeginningItems(Run run)
{
// If our artifact is not enabled
if (!RunArtifactManager.instance.IsArtifactEnabled(Artifact.artifactIndex))
return;
CharacterMaster master = PlayerCharacterMasterController.instances[0].master;
if (master)
// If our artifact is enabled
if (RunArtifactManager.instance.IsArtifactEnabled(Artifact.artifactIndex))
{
// Set starting items
CommonItem = RandomItem(ItemTier.Tier1);
UncommonItem = RandomItem(ItemTier.Tier2);
LegendaryItem = RandomItem(ItemTier.Tier3);
BossItem = RandomItem(ItemTier.Boss);
LunarItem = RandomItem(ItemTier.Lunar);
// Give the starting items
master.inventory.GiveItem(CommonItem, CommonItemCount.Value);
master.inventory.GiveItem(UncommonItem, UncommonItemCount.Value);
master.inventory.GiveItem(LegendaryItem, LegendaryItemCount.Value);
master.inventory.GiveItem(BossItem, BossItemCount.Value);
master.inventory.GiveItem(LunarItem, LunarItemCount.Value);
// Called every time an item is given
// If the item is not a starter item, remove it and give the starter item
Inventory.onServerItemGiven += (inv, itemIndex, count) =>
{
ItemDef starterItemToCompare = ItemFromTier(ItemCatalog.GetItemDef(itemIndex).tier);
Inventory.onServerItemGiven += ConvertPotentialItems;
}
// Else, if our artifact isn't enabled
else
{
// Unsubscribe from the event if the artifact is disabled
Inventory.onServerItemGiven -= ConvertPotentialItems;
return;
}
// If they are different items
if (starterItemToCompare != null && starterItemToCompare.itemIndex != itemIndex)
{
int itemCount = inv.GetItemCount(itemIndex);
// Set starting items
CommonItem = RandomItem(ItemTier.Tier1);
UncommonItem = RandomItem(ItemTier.Tier2);
LegendaryItem = RandomItem(ItemTier.Tier3);
BossItem = RandomItem(ItemTier.Boss);
LunarItem = RandomItem(ItemTier.Lunar);
inv.RemoveItem(itemIndex, itemCount);
inv.GiveItem(starterItemToCompare, itemCount);
}
};
// Give the starting items to every palyer
for (int i = 0; i < CharacterMaster.readOnlyInstancesList.Count; i++)
{
CharacterMaster character = CharacterMaster.readOnlyInstancesList[i];
character.inventory.GiveItem(CommonItem, CommonItemCount.Value);
character.inventory.GiveItem(UncommonItem, UncommonItemCount.Value);
character.inventory.GiveItem(LegendaryItem, LegendaryItemCount.Value);
character.inventory.GiveItem(BossItem, BossItemCount.Value);
character.inventory.GiveItem(LunarItem, LunarItemCount.Value);
}
}
}