Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
v3.0.0-beta.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Chasmical committed Jul 9, 2021
1 parent 08a7408 commit 0639af4
Show file tree
Hide file tree
Showing 23 changed files with 623 additions and 296 deletions.
3 changes: 2 additions & 1 deletion RogueLibsCore.Test/RogueLibsCore.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Smoker.cs" />
<Compile Include="Tests\GiantAbility.cs" />
<Compile Include="Tests\Smoker.cs" />
<Compile Include="TestPlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tests\Duplicator.cs" />
Expand Down
3 changes: 3 additions & 0 deletions RogueLibsCore.Test/TestPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ public void Awake()
{
Log = Logger;
Instance = this;

LootBox.Test();
Converter.Test();
Duplicator.Test();
NuclearBriefcase.Test();

GiantAbility.Test();

Smoker.Test();
}
}
Expand Down
43 changes: 43 additions & 0 deletions RogueLibsCore.Test/Tests/GiantAbility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace RogueLibsCore.Test
{
public class GiantAbility : CustomAbility, IDoUpdate
{
public static void Test()
{
RogueLibs.CreateCustomAbility<GiantAbility>()
.WithName(new CustomNameInfo("Giant"))
.WithDescription(new CustomNameInfo("Transform into a giant and crush your enemies!"))
.WithSprite(Properties.Resources.Batteries)
.WithUnlock(new AbilityUnlock { UnlockCost = 15, CharacterCreationCost = 10, });
}

public override void SetupDetails() { }
public override string GetCountString() => recharge != 0f ? recharge.ToString() : base.GetCountString();

public override void OnAdded() { }
public override void OnHeld(OnAbilityHeldArgs e) { }
public override void OnReleased(OnAbilityReleasedArgs e) { }
public override void OnUpdated(OnAbilityUpdatedArgs e) { }
public override PlayfieldObject FindTarget() => null;

private float recharge;
public void Update() => recharge = Mathf.Max(recharge - Time.deltaTime, 0f);

public override void OnPressed()
{
if (recharge > 0f) return;

Owner.statusEffects.AddStatusEffect("Giant", 15);
Owner.statusEffects.AddStatusEffect("Enraged", 15);

recharge = 30f;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static void Test()

public override void OnAdded()
{
RogueFramework.LogDebug("");
Owner.SetEndurance(Owner.enduranceStatMod - 1);
Owner.SetSpeed(Owner.speedStatMod - 1);
}
Expand Down
8 changes: 7 additions & 1 deletion RogueLibsCore/CustomName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ public static void RegisterLanguageCode(string languageName, LanguageCode code)
if (languageName is null) throw new ArgumentNullException(nameof(languageName));
if (languages.ContainsKey(languageName))
throw new ArgumentException($"The specified {nameof(languageName)} is already taken.", nameof(languageName));
RogueFramework.Logger.LogDebug($"Registered \"{languageName}\" language ({(int)code})");

if (RogueFramework.IsDebugEnabled(DebugFlags.Names))
RogueFramework.Logger.LogDebug($"Registered \"{languageName}\" language ({(int)code})");

languages.Add(languageName, code);
languageNames.Add(code, languageName);
}
Expand All @@ -165,6 +168,9 @@ public void GetName(string name, string type, ref string result)
}
public CustomName AddName(string name, string type, CustomNameInfo info)
{
if (RogueFramework.IsDebugEnabled(DebugFlags.Names))
RogueFramework.LogDebug($"Added \"{name}\" name ({type}): {info.English}");

CustomName customName = new CustomName(name, type, info);
if (!CustomNames.TryGetValue(type, out Dictionary<string, CustomName> category))
CustomNames.Add(type, category = new Dictionary<string, CustomName>());
Expand Down
2 changes: 2 additions & 0 deletions RogueLibsCore/Hooks/Effects/CustomEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public override bool TryCreate(StatusEffect instance, out IHook<StatusEffect> ho
public EffectInfo AddEffect<T>() where T : CustomEffect, new()
{
EffectInfo info = EffectInfo.Get<T>();
if (RogueFramework.IsDebugEnabled(DebugFlags.Effects))
RogueFramework.LogDebug($"Created custom effect {typeof(T)} ({info.Name}).");
effectsDict.Add(info.Name, new EffectEntry { Initializer = () => new T(), EffectInfo = info });
return info;
}
Expand Down
2 changes: 2 additions & 0 deletions RogueLibsCore/Hooks/Items/CustomItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public override bool TryCreate(InvItem instance, out IHook<InvItem> hook)
public ItemInfo AddItem<T>() where T : CustomItem, new()
{
ItemInfo info = ItemInfo.Get<T>();
if (RogueFramework.IsDebugEnabled(DebugFlags.Items))
RogueFramework.LogDebug($"Created custom item {typeof(T)} ({info.Name}).");
itemsDict.Add(info.Name, new ItemEntry { Initializer = () => new T(), ItemInfo = info });
return info;
}
Expand Down
39 changes: 36 additions & 3 deletions RogueLibsCore/Hooks/Items/InventoryChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace RogueLibsCore
{
Expand All @@ -11,13 +12,32 @@ public static class InventoryChecks
internal static readonly RogueEvent<OnItemUsingArgs> onItemUsing = new RogueEvent<OnItemUsingArgs>();
internal static readonly RogueEvent<OnItemsCombiningArgs> onItemsCombining = new RogueEvent<OnItemsCombiningArgs>();
internal static readonly RogueEvent<OnItemTargetingArgs> onItemTargeting = new RogueEvent<OnItemTargetingArgs>();
internal static readonly RogueEvent<OnItemTargetingAnywhereArgs> onItemTargetingAnywhere = new RogueEvent<OnItemTargetingAnywhereArgs>();

public static void AddItemUsingCheck(string name, RogueEventHandler<OnItemUsingArgs> check)
=> onItemUsing.Subscribe(name, check);
{
if (RogueFramework.IsDebugEnabled(DebugFlags.Items))
RogueFramework.LogDebug($"Added \"{name}\" usage inventory check.");
onItemUsing.Subscribe(name, check);
}
public static void AddItemsCombiningCheck(string name, RogueEventHandler<OnItemsCombiningArgs> check)
=> onItemsCombining.Subscribe(name, check);
{
if (RogueFramework.IsDebugEnabled(DebugFlags.Items))
RogueFramework.LogDebug($"Added \"{name}\" combining inventory check.");
onItemsCombining.Subscribe(name, check);
}
public static void AddItemTargetingCheck(string name, RogueEventHandler<OnItemTargetingArgs> check)
=> onItemTargeting.Subscribe(name, check);
{
if (RogueFramework.IsDebugEnabled(DebugFlags.Items))
RogueFramework.LogDebug($"Added \"{name}\" targeting inventory check.");
onItemTargeting.Subscribe(name, check);
}
public static void AddItemTargetingAnywhereCheck(string name, RogueEventHandler<OnItemTargetingAnywhereArgs> check)
{
if (RogueFramework.IsDebugEnabled(DebugFlags.Items))
RogueFramework.LogDebug($"Added \"{name}\" targeting anywhere inventory check.");
onItemTargetingAnywhere.Subscribe(name, check);
}

public static bool IsCheckAllowed(InvItem item, string checkName) => IsCheckAllowed(item?.GetHook<CustomItem>(), checkName);
public static bool IsCheckAllowed(CustomItem customItem, string checkName)
Expand Down Expand Up @@ -60,6 +80,19 @@ public OnItemTargetingArgs(InvItem item, PlayfieldObject targetObject, Agent use
public PlayfieldObject Target { get; set; }
public Agent User { get; set; }
}
public class OnItemTargetingAnywhereArgs : RogueEventArgs
{
public OnItemTargetingAnywhereArgs(InvItem item, Vector2 position, Agent user)
{
Item = item;
Target = position;
User = user;
}
public InvDatabase Inventory => Item.database;
public InvItem Item { get; }
public Vector2 Target { get; set; }
public Agent User { get; set; }
}
public class RogueEvent<TArgs> where TArgs : RogueEventArgs
{
private readonly List<RogueEventSubscriber<TArgs>> list = new List<RogueEventSubscriber<TArgs>>(0);
Expand Down
2 changes: 2 additions & 0 deletions RogueLibsCore/Hooks/Traits/CustomTrait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public override bool TryCreate(Trait instance, out IHook<Trait> hook)
public TraitInfo AddTrait<T>() where T : CustomTrait, new()
{
TraitInfo info = TraitInfo.Get<T>();
if (RogueFramework.IsDebugEnabled(DebugFlags.Traits))
RogueFramework.LogDebug($"Created custom trait {typeof(T)} ({info.Name}).");
traitsDict.Add(info.Name, new TraitEntry { Initializer = () => new T(), TraitInfo = info });
return info;
}
Expand Down
44 changes: 20 additions & 24 deletions RogueLibsCore/Patches/Patches_Abilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public static void StatusEffects_GiveSpecialAbility(StatusEffects __instance)
CustomAbility custom = __instance.agent.GetAbility();
if (custom is null) return;

if (RogueFramework.IsDebugEnabled(DebugFlags.Abilities))
RogueFramework.LogDebug($"Giving ability {custom} ({__instance.agent.specialAbility}, {__instance.agent.agentName}).");

try { custom.OnAdded(); }
catch (Exception e)
{
RogueFramework.Logger.LogError($"Error in CustomAbility.OnAdded() - {custom} ({__instance.agent.specialAbility})");
RogueFramework.Logger.LogError(e);
}
catch (Exception e) { RogueFramework.LogError(e, "CustomAbility.OnAdded", custom, __instance.agent); }

__instance.SpecialAbilityInterfaceCheck();
__instance.RechargeSpecialAbility(custom.ItemInfo.Name);
}
Expand All @@ -45,12 +45,11 @@ public static void StatusEffects_PressedSpecialAbility(StatusEffects __instance)
CustomAbility custom = __instance.agent.GetAbility();
if (custom is null) return;

try { custom?.OnPressed(); }
catch (Exception e)
{
RogueFramework.Logger.LogError($"Error in CustomAbility.OnPressed() - {custom} ({__instance.agent.specialAbility})");
RogueFramework.Logger.LogError(e);
}
if (RogueFramework.IsDebugEnabled(DebugFlags.Abilities))
RogueFramework.LogDebug($"Pressing ability ability {custom} ({__instance.agent.specialAbility}, {__instance.agent.agentName}).");

try { custom.OnPressed(); }
catch (Exception e) { RogueFramework.LogError(e, "CustomAbility.OnPressed", custom, __instance.agent); }
}
public static void StatusEffects_HeldSpecialAbility(StatusEffects __instance)
{
Expand All @@ -60,18 +59,16 @@ public static void StatusEffects_HeldSpecialAbility(StatusEffects __instance)
ref float held = ref GameController.gameController.playerControl.pressedSpecialAbilityTime[__instance.agent.isPlayer - 1];
float prevHeld = held;

if (RogueFramework.IsDebugEnabled(DebugFlags.Abilities))
RogueFramework.LogDebug($"Holding ability {custom} for {prevHeld}s ({__instance.agent.specialAbility}, {__instance.agent.agentName}).");

OnAbilityHeldArgs args = new OnAbilityHeldArgs { HeldTime = prevHeld };
try { custom.OnHeld(args); }
catch (Exception e)
{
RogueFramework.Logger.LogError($"Error in CustomAbility.OnHeld() - {custom} ({__instance.agent.specialAbility})");
RogueFramework.Logger.LogError(e);
}
catch (Exception e) { RogueFramework.LogError(e, "CustomAbility.OnHeld", custom, __instance.agent); }

held = args.HeldTime;
custom.lastHeld = args.HeldTime;

if (held is 0f) custom.OnReleased(new OnAbilityReleasedArgs(prevHeld));
custom.lastHeld = prevHeld;
__instance.ReleasedSpecialAbility();
}
public static void StatusEffects_ReleasedSpecialAbility(StatusEffects __instance)
{
Expand All @@ -81,13 +78,12 @@ public static void StatusEffects_ReleasedSpecialAbility(StatusEffects __instance
float prevHeld = custom.lastHeld;
if (prevHeld is 0f) return;

if (RogueFramework.IsDebugEnabled(DebugFlags.Abilities))
RogueFramework.LogDebug($"Releasing ability {custom} - {prevHeld}s ({__instance.agent.specialAbility}, {__instance.agent.agentName}).");

custom.lastHeld = 0f;
try { custom.OnReleased(new OnAbilityReleasedArgs(prevHeld)); }
catch (Exception e)
{
RogueFramework.Logger.LogError($"Error in CustomAbility.OnReleased() - {custom} ({__instance.agent.specialAbility})");
RogueFramework.Logger.LogError(e);
}
catch (Exception e) { RogueFramework.LogError(e, "CustomAbility.OnReleased", custom, __instance.agent); }
}
}
}
16 changes: 14 additions & 2 deletions RogueLibsCore/Patches/Patches_CharacterCreation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using UnityEngine.UI;
using BepInEx;
using HarmonyLib;
using static UnityEngine.Random;
using System.Diagnostics;

namespace RogueLibsCore
{
Expand Down Expand Up @@ -41,6 +43,8 @@ public static bool CharacterCreation_SortUnlocks(CharacterCreation __instance, L

displayedList.Sort();
CustomCharacterCreation menu = new CustomCharacterCreation(__instance, displayedList);
if (RogueFramework.IsDebugEnabled(DebugFlags.UnlockMenus))
RogueFramework.LogDebug($"Setting up \"{menu.Type}\" menu.");

List<Unlock> listUnlocks = unlockType == "Item" ? __instance.listUnlocksItems
: unlockType == "Trait" ? __instance.listUnlocksTraits
Expand Down Expand Up @@ -72,7 +76,14 @@ public static bool CharacterCreation_SortUnlocks(CharacterCreation __instance, L

public static bool CharacterCreation_PushedButton(CharacterCreation __instance, ButtonHelper myButton)
{
if (__instance.selectedSpace == "Load") return true;
bool debug = RogueFramework.IsDebugEnabled(DebugFlags.UnlockMenus);
if (__instance.selectedSpace == "Load")
{
if (debug) RogueFramework.LogDebug("Redirecting the button push to the original method.");
return true;
}

if (debug) RogueFramework.LogDebug($"Pressing \"{myButton.myText.text}\" ({myButton.scrollingButtonNum}, {myButton.scrollingButtonType}) button.");

string type = myButton.scrollingButtonUnlock.unlockType;
List<ButtonData> buttonsData = type == "Item" ? __instance.buttonsDataItems
Expand All @@ -83,7 +94,8 @@ public static bool CharacterCreation_PushedButton(CharacterCreation __instance,
ButtonData buttonData = buttonsData[myButton.scrollingButtonNum];
DisplayedUnlock du = (DisplayedUnlock)buttonData.__RogueLibsCustom;

du.OnPushedButton();
try { du.OnPushedButton(); }
catch (Exception e) { RogueFramework.LogError(e, "DisplayedUnlock.OnPushedButton", du, du.Menu); }
__instance.curSelectedButton = myButton;
__instance.curSelectedButtonNum = myButton.scrollingButtonNum;
return false;
Expand Down
Loading

0 comments on commit 0639af4

Please sign in to comment.