From b16a0b668978aee148b548614139467bc4cc9a18 Mon Sep 17 00:00:00 2001 From: direwolf420 Date: Sun, 26 Jul 2020 10:25:03 +0200 Subject: [PATCH] fix non-1f slots summoning with the books (spider staff) --- Models/ItemModel.cs | 5 +++++ SummonersAssociation.cs | 10 ++++++++++ SummonersAssociationPlayer.cs | 2 +- UI/HistoryBookUI.cs | 21 +++++++++++---------- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Models/ItemModel.cs b/Models/ItemModel.cs index 11d4830..daa18ac 100644 --- a/Models/ItemModel.cs +++ b/Models/ItemModel.cs @@ -35,6 +35,11 @@ public class ItemModel : TagSerializable, IComparable /// public byte SummonCount { get; set; } + /// + /// How many minion slots the weapon "creates" on use, hardcoded for vanilla, modded assumes SlotsNeeded + /// + public float SlotsFilledPerUse => SummonersAssociation.SlotsFilledPerUse.TryGetValue(ItemType, out float value) ? value : SlotsNeeded; + /// ///If this ItemModel corresponds to an item in the players inventory /// diff --git a/SummonersAssociation.cs b/SummonersAssociation.cs index 61cb760..20b2744 100644 --- a/SummonersAssociation.cs +++ b/SummonersAssociation.cs @@ -20,6 +20,10 @@ namespace SummonersAssociation public class SummonersAssociation : Mod { private static List SupportedMinions; + /// + /// Hardcoded special vanilla minions that summon a non-1f amount of minions on use + /// + internal static Dictionary SlotsFilledPerUse; private bool SupportedMinionsFinalized = false; internal static UserInterface HistoryBookUIInterface; @@ -64,6 +68,11 @@ public override void Load() { new MinionModel(ItemID.StardustCellStaff, BuffID.StardustMinion, new List() { ProjectileID.StardustCellMinion }) }; + //For SlotsFilledPerUse we can't use MinionModel.GetSlotsPerProjectile because thats just a list of projectiles, and not those that are summoned once on use + SlotsFilledPerUse = new Dictionary { + [ItemID.SpiderStaff] = 0.75f + }; + MinionControlRod.LoadHooks(); } @@ -83,6 +92,7 @@ public override void Unload() { HistoryBookUI.itemModels.Clear(); SupportedMinions = null; + SlotsFilledPerUse = null; BookTypes = null; MinionControlRod.UnloadHooks(); diff --git a/SummonersAssociationPlayer.cs b/SummonersAssociationPlayer.cs index e4d1755..547a61c 100644 --- a/SummonersAssociationPlayer.cs +++ b/SummonersAssociationPlayer.cs @@ -136,7 +136,7 @@ private void UpdateHistoryBookUI() { PlayerInput.ScrollWheelDelta = 0; //Only allow to increase if total summon count differential is above or //equal to the number of slots needed to summon - if (HistoryBookUI.summonCountDelta >= highlighted.SlotsNeeded) { + if (HistoryBookUI.summonCountDelta >= highlighted.SlotsFilledPerUse) { triggered = true; highlighted.SummonCount++; diff --git a/UI/HistoryBookUI.cs b/UI/HistoryBookUI.cs index 5750730..e66166e 100644 --- a/UI/HistoryBookUI.cs +++ b/UI/HistoryBookUI.cs @@ -59,14 +59,14 @@ class HistoryBookUI : UIState internal static Vector2 spawnPosition = default(Vector2); /// - /// Number of casts in total (player.numMinions) + /// Number of casts in total (player.maxMinions) /// internal static int summonCountTotal = -1; /// - /// Difference of summonCountTotal - SumSummonCounts() + /// Difference of summonCountTotal - sum of SlotsFilledPerUse /// - internal static int summonCountDelta = 0; + internal static float summonCountDelta = 0; /// /// Held item index @@ -204,8 +204,8 @@ public override void Update(GameTime gameTime) { #region Setup weapon tooltip tooltip.Add(itemModel.Name); - if (itemModel.SlotsNeeded > 1) { - tooltip.Add("Slots required: " + itemModel.SlotsNeeded); + if (itemModel.SlotsFilledPerUse > 1) { + tooltip.Add("Slots required: " + itemModel.SlotsFilledPerUse); } if (simple && selected == done) { @@ -343,7 +343,7 @@ protected override void DrawSelf(SpriteBatch spriteBatch) { drawPos = new Vector2((int)TopLeftCorner.X, (int)TopLeftCorner.Y + height) + new Vector2(-4, mainRadius - 20); if (summonCountDelta < 0) fontColor = Color.Red; - middleTip = summonCountDelta.ToString() + "/" + summonCountTotal.ToString(); + middleTip = Math.Round(summonCountDelta, 2).ToString() + "/" + summonCountTotal.ToString(); DrawText(spriteBatch, middleTip, drawPos, fontColor); } @@ -539,15 +539,16 @@ public static void UpdateHistoryBook(MinionHistoryBookSimple book) { /// /// summonCountTotal minus all the summon counts weighted with the slots needed /// - public static int GetSummonCountDelta() { - int sum = summonCountTotal; + public static float GetSummonCountDelta() { + float sum = summonCountTotal; + float newSum = 0; for (int i = 0; i < itemModels.Count; i++) { ItemModel itemModel = itemModels[i]; if (itemModel.Active) { - sum -= itemModel.SummonCount * itemModel.SlotsNeeded; + newSum += itemModel.SummonCount * itemModel.SlotsFilledPerUse; } } - return sum; + return sum - newSum; } ///