Artifact of Sequencing

This commit is contained in:
Chev 2021-04-13 00:38:23 -07:00
parent 0f22caa3d6
commit 2f8f6f7b0d
7 changed files with 391 additions and 17 deletions

View file

@ -0,0 +1,151 @@
using BepInEx;
using BepInEx.Configuration;
using R2API;
using R2API.Utils;
using RoR2;
using System;
using System.Linq;
using UnityEngine;
namespace Chev
{
[BepInDependency("com.bepis.r2api")]
[BepInPlugin("com.Chev.ArtifactOfSequencing", "Artifact of Sequencing", "1.0.0")]
[NetworkCompatibility(CompatibilityLevel.EveryoneMustHaveMod, VersionStrictness.EveryoneNeedSameModVersion)]
[R2APISubmoduleDependency(nameof(ArtifactAPI))]
public class ArtifactOfSequencingMod : BaseUnityPlugin
{
public static ArtifactDef Artifact;
public static ItemDef CommonItem;
public static ItemDef UncommonItem;
public static ItemDef LegendaryItem;
public static ItemDef BossItem;
public static ItemDef LunarItem;
private static readonly System.Random _random = new System.Random();
public static ConfigEntry<int> CommonItemCount { get; set; }
public static ConfigEntry<int> UncommonItemCount { get; set; }
public static ConfigEntry<int> LegendaryItemCount { get; set; }
public static ConfigEntry<int> BossItemCount { get; set; }
public static ConfigEntry<int> LunarItemCount { get; set; }
public void Awake()
{
// Initialize config
CommonItemCount = Config.Bind("Quantities", "CommonItemCount", 1, "Quantity of the common (white) item to start with.");
UncommonItemCount = Config.Bind("Quantities", "UncommonItemCount", 1, "Quantity of the uncommon (green) item to start with.");
LegendaryItemCount = Config.Bind("Quantities", "LegendaryItemCount", 1, "Quantity of the legendary (red) item to start with.");
BossItemCount = Config.Bind("Quantities", "BossItemCount", 1, "Quantity of the boss (yellow) item to start with.");
LunarItemCount = Config.Bind("Quantities", "LunarItemCount", 1, "Quantity of the lunar (blue) item to start with.");
// Initialize the artifact
Artifact = ScriptableObject.CreateInstance<ArtifactDef>();
// Artifact info
Artifact.nameToken = "Artifact of Sequencing";
Artifact.descriptionToken = "Spawn with a single item of every tier. Any picked up items will be converted to the starting item of the same tier.";
Artifact.smallIconSelectedSprite = LoadIcon(ArtifactOfSequencing.Properties.Resources.texArtifactSequencingEnabled);
Artifact.smallIconDeselectedSprite = LoadIcon(ArtifactOfSequencing.Properties.Resources.texArtifactSequencingDisabled);
// Add our custom artifact to the artifact list
// This uses the ArtifactAPI submodule in R2API
ArtifactAPI.Add(Artifact);
// On stage start event
// This is when we add our items
//Stage.onStageStartGlobal += AddBeginningItems;
Run.onRunStartGlobal += AddBeginningItems;
Logger.LogMessage("Loaded mod com.Chev.ArtifactOfSequencing");
}
/// <summary>
/// Loads a Unity Sprite from resources.
/// </summary>
/// <param name="resourceBytes">The byte array of the resource.</param>
/// <returns></returns>
private Sprite LoadIcon(Byte[] resourceBytes)
{
if (resourceBytes == null)
throw new ArgumentNullException(nameof(resourceBytes));
Texture2D iconTex = new Texture2D(64, 64, TextureFormat.RGBA32, false);
iconTex.LoadImage(resourceBytes);
return Sprite.Create(iconTex, new Rect(0f, 0f, iconTex.width, iconTex.height), new Vector2(0.5f, 0.5f));
}
/// <summary>
/// Gets a random item from a chosen tier.
/// </summary>
/// <param name="tier">The item tier, e.g. common, uncommon, legendary, lunar, boss</param>
/// <returns></returns>
private ItemDef RandomItem(ItemTier tier)
{
ItemDef[] itemDefs = typeof(ItemCatalog).GetFieldValue<ItemDef[]>("itemDefs");
ItemDef[] itemsOfTier = itemDefs.Where(item => item.tier == tier).ToArray();
return itemsOfTier[_random.Next(0, itemsOfTier.Length)];
}
private ItemDef ItemFromTier(ItemTier tier)
{
switch (tier)
{
case ItemTier.Tier1:
return CommonItem;
case ItemTier.Tier2:
return UncommonItem;
case ItemTier.Tier3:
return LegendaryItem;
case ItemTier.Boss:
return BossItem;
case ItemTier.Lunar:
return LunarItem;
default:
return null;
}
}
public void AddBeginningItems(Run run)
{
CharacterMaster master = PlayerCharacterMasterController.instances[0].master;
if (master)
{
// 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);
// If they are different items
if (starterItemToCompare != null && starterItemToCompare.itemIndex != itemIndex)
{
int itemCount = inv.GetItemCount(itemIndex);
inv.RemoveItem(itemIndex, itemCount);
inv.GiveItem(starterItemToCompare, itemCount);
}
};
}
}
}
}

View file

@ -2,34 +2,29 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>RoR2_SacrificeDropRate</RootNamespace>
<AssemblyName>SacrificeDropRate</AssemblyName>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\BepInEx\core\0Harmony.dll</HintPath>
</Reference>
<Reference Include="0Harmony20">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\BepInEx\core\0Harmony20.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\Risk of Rain 2_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp.R2API.mm">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\BepInEx\monomod\Assembly-CSharp.R2API.mm.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\BepInEx\core\BepInEx.dll</HintPath>
</Reference>
<Reference Include="BepInEx.Harmony">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\BepInEx\core\BepInEx.Harmony.dll</HintPath>
</Reference>
<Reference Include="BepInEx.MonoMod.Loader">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\BepInEx\patchers\BepInEx.MonoMod.Loader\BepInEx.MonoMod.Loader.dll</HintPath>
</Reference>
<Reference Include="BepInEx.Preloader">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\BepInEx\core\BepInEx.Preloader.dll</HintPath>
</Reference>
<Reference Include="MMHOOK_Assembly-CSharp">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\BepInEx\plugins\R2API\MMHOOK_Assembly-CSharp.dll</HintPath>
<Reference Include="HarmonyXInterop">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\BepInEx\core\HarmonyXInterop.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\BepInEx\core\Mono.Cecil.dll</HintPath>
@ -58,9 +53,27 @@
<Reference Include="UnityEngine.CoreModule">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\Risk of Rain 2_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.ImageConversionModule">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\Risk of Rain 2_Data\Managed\UnityEngine.ImageConversionModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Networking">
<HintPath>H:\SteamLibrary\steamapps\common\Risk of Rain 2\Risk of Rain 2_Data\Managed\UnityEngine.Networking.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View file

@ -1,9 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30204.135
VisualStudioVersion = 16.0.31005.135
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoR2-SacrificeDropRate", "RoR2-SacrificeDropRate\RoR2-SacrificeDropRate.csproj", "{85B9C64B-B9FD-474F-89B4-9590529E677F}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArtifactOfSequencing", "ArtifactOfSequencing.csproj", "{F79372C6-A1F3-4F5E-A784-F6C06D2ED0C4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -11,15 +11,15 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{85B9C64B-B9FD-474F-89B4-9590529E677F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85B9C64B-B9FD-474F-89B4-9590529E677F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85B9C64B-B9FD-474F-89B4-9590529E677F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85B9C64B-B9FD-474F-89B4-9590529E677F}.Release|Any CPU.Build.0 = Release|Any CPU
{F79372C6-A1F3-4F5E-A784-F6C06D2ED0C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F79372C6-A1F3-4F5E-A784-F6C06D2ED0C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F79372C6-A1F3-4F5E-A784-F6C06D2ED0C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F79372C6-A1F3-4F5E-A784-F6C06D2ED0C4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {10D54B89-E06E-428E-AE42-911FF165AE02}
SolutionGuid = {1CBC6AD0-C30C-49DF-8722-593A8A0F9DC8}
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,83 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ArtifactOfSequencing.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ArtifactOfSequencing.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] texArtifactSequencingDisabled {
get {
object obj = ResourceManager.GetObject("texArtifactSequencingDisabled", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] texArtifactSequencingEnabled {
get {
object obj = ResourceManager.GetObject("texArtifactSequencingEnabled", resourceCulture);
return ((byte[])(obj));
}
}
}
}

View file

@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="texArtifactSequencingDisabled" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>texArtifactSequencingDisabled.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="texArtifactSequencingEnabled" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>texArtifactSequencingEnabled.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB