Skip to content

Commit

Permalink
fix non-1f slots summoning with the books (spider staff)
Browse files Browse the repository at this point in the history
  • Loading branch information
direwolf420 committed Jul 26, 2020
1 parent 3086832 commit b16a0b6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
5 changes: 5 additions & 0 deletions Models/ItemModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class ItemModel : TagSerializable, IComparable<ItemModel>
/// </summary>
public byte SummonCount { get; set; }

/// <summary>
/// How many minion slots the weapon "creates" on use, hardcoded for vanilla, modded assumes SlotsNeeded
/// </summary>
public float SlotsFilledPerUse => SummonersAssociation.SlotsFilledPerUse.TryGetValue(ItemType, out float value) ? value : SlotsNeeded;

/// <summary>
///If this ItemModel corresponds to an item in the players inventory
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions SummonersAssociation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ namespace SummonersAssociation
public class SummonersAssociation : Mod
{
private static List<MinionModel> SupportedMinions;
/// <summary>
/// Hardcoded special vanilla minions that summon a non-1f amount of minions on use
/// </summary>
internal static Dictionary<int, float> SlotsFilledPerUse;
private bool SupportedMinionsFinalized = false;

internal static UserInterface HistoryBookUIInterface;
Expand Down Expand Up @@ -64,6 +68,11 @@ public override void Load() {
new MinionModel(ItemID.StardustCellStaff, BuffID.StardustMinion, new List<int>() { 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<int, float> {
[ItemID.SpiderStaff] = 0.75f
};

MinionControlRod.LoadHooks();
}

Expand All @@ -83,6 +92,7 @@ public override void Unload() {
HistoryBookUI.itemModels.Clear();

SupportedMinions = null;
SlotsFilledPerUse = null;
BookTypes = null;

MinionControlRod.UnloadHooks();
Expand Down
2 changes: 1 addition & 1 deletion SummonersAssociationPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
21 changes: 11 additions & 10 deletions UI/HistoryBookUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ class HistoryBookUI : UIState
internal static Vector2 spawnPosition = default(Vector2);

/// <summary>
/// Number of casts in total (player.numMinions)
/// Number of casts in total (player.maxMinions)
/// </summary>
internal static int summonCountTotal = -1;

/// <summary>
/// Difference of summonCountTotal - SumSummonCounts()
/// Difference of summonCountTotal - sum of SlotsFilledPerUse
/// </summary>
internal static int summonCountDelta = 0;
internal static float summonCountDelta = 0;

/// <summary>
/// Held item index
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -539,15 +539,16 @@ public static void UpdateHistoryBook(MinionHistoryBookSimple book) {
/// <summary>
/// summonCountTotal minus all the summon counts weighted with the slots needed
/// </summary>
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;
}

/// <summary>
Expand Down

0 comments on commit b16a0b6

Please sign in to comment.