Skip to content

Commit

Permalink
v0.4.2, SupportedMinionsFinalized barrier, use float, Automatically r…
Browse files Browse the repository at this point in the history
…egister MinionModels
  • Loading branch information
JavidPack committed Sep 24, 2019
1 parent c904b61 commit 5d0c32d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
12 changes: 6 additions & 6 deletions Models/MinionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class MinionModel
public int BuffID { get; set; }
public List<int> ProjectileIDs { get; set; }
//Double because it's needed in Math.Floor and I cba to cast float to double every tick
public List<double> Slots { get; set; }
public List<float> Slots { get; set; }

public override string ToString() => Terraria.ID.ItemID.GetUniqueKey(ItemID);

Expand All @@ -24,7 +24,7 @@ public MinionModel(int itemID, int buffID, int projectileID, float slot) {
ItemID = itemID;
BuffID = buffID;
ProjectileIDs = new List<int> { projectileID };
Slots = new List<double> { slot };
Slots = new List<float> { slot };
}

public MinionModel(int itemID, int buffID, List<int> projectileIDs) {
Expand All @@ -38,11 +38,11 @@ public MinionModel(int itemID, int buffID, List<int> projectileIDs, List<float>
ItemID = itemID;
BuffID = buffID;
ProjectileIDs = projectileIDs;
Slots = slots.ConvertAll(s => (double)s);
Slots = slots;
}

private List<double> GetSlotsPerProjectile() {
var slots = new List<double>();
private List<float> GetSlotsPerProjectile() {
var slots = new List<float>();
foreach (int type in ProjectileIDs) {
try {
var proj = new Projectile();
Expand All @@ -51,7 +51,7 @@ private List<double> GetSlotsPerProjectile() {
}
catch {
// In case it gets called before PostSetupContent for whatever reason, default to 1
slots.Add(1d);
slots.Add(1f);
}
}
return slots;
Expand Down
25 changes: 23 additions & 2 deletions SummonersAssociation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace SummonersAssociation
public class SummonersAssociation : Mod
{
private static List<MinionModel> SupportedMinions;
private bool SupportedMinionsFinalized = false;

private static List<int> ModdedSummonerWeaponsWithExistingBuff;

Expand Down Expand Up @@ -89,6 +90,23 @@ public override void Unload() {
}

public override void AddRecipeGroups() {
// Automatically register MinionModels
var item = new Item();
var projectile = new Projectile();
for (int i = ItemID.Count; i < ItemLoader.ItemCount; i++) {
item = ItemLoader.GetItem(i).item;
if(item.buffType > 0 && item.shoot >= ProjectileID.Count) {
projectile = ProjectileLoader.GetProjectile(item.shoot).projectile;
if (projectile.minionSlots > 0) {
// Avoid automatic support for manually supported
if (!SupportedMinions.Any(x => x.ItemID == i || x.ProjectileIDs.Contains(projectile.type) || x.BuffID == item.buffType)) {
AddMinion(new MinionModel(item.type, item.buffType, projectile.type));
}
}
}
}
SupportedMinionsFinalized = true;

var itemList = new List<int>();
foreach (MinionModel minion in SupportedMinions) {
itemList.Add(minion.ItemID);
Expand Down Expand Up @@ -180,7 +198,6 @@ private void UpdateBuffText(SpriteBatch spriteBatch, Player player) {
MinionModel minion = SupportedMinions.SingleOrDefault(minionEntry => minionEntry.BuffID == buffID);
if (minion != null) {
List<int> projectileList = minion.ProjectileIDs;
List<double> slotList = minion.Slots;

for (int i = 0; i < minion.ProjectileIDs.Count; i++) {
int num = player.ownedProjectileCounts[minion.ProjectileIDs[i]];
Expand All @@ -194,9 +211,10 @@ private void UpdateBuffText(SpriteBatch spriteBatch, Player player) {

//Use lowestSlots so the highest possible minion count is shown for this buff
//edge case 0, if for whatever reason a mod manually assigns 0 as the slot, it will turn it to 1
double lowestSlots = minion.Slots.Min(x => x == 0 ? 1 : x);
float lowestSlots = minion.Slots.Min(x => x == 0 ? 1 : x);
int newMaxMinions = (int)Math.Floor(player.maxMinions / lowestSlots);
string ratio = number + " / " + newMaxMinions;
// TODO: 7/8 shown for spider minions with stardust armor. Technically there is .75 slots left, but StaffMinionSlotsRequired defaults to 1 and is an int. Might need to do the math and show 1 less if available minion slots is less than 1.
workingMinions += slots;
spriteBatch.DrawString(Main.fontItemStack, ratio, new Vector2(xPosition, yPosition), color, 0f, Vector2.Zero, 0.8f, SpriteEffects.None, 0f);
}
Expand Down Expand Up @@ -336,6 +354,9 @@ public override object Call(params object[] args) {
try {
string message = args[0] as string;
if (message == "AddMinionInfo") {
if (SupportedMinionsFinalized)
throw new Exception($"{Name} Call Error: The attempted message, \"{message}\", was sent too late. {Name} expects Call messages to happen during Mod.PostSetupContent.");

int itemID = Convert.ToInt32(args[1]);
int buffID = Convert.ToInt32(args[2]);

Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
author = jopojelly, direwolf420
version = 0.4.1
version = 0.4.2
displayName = Summoners Association
homepage = http://forums.terraria.org/index.php?threads/summoners-association.30041/
buildIgnore = .vs\*, *.csproj, *.user, obj\*, bin\*, *.config, .git\*, README.md, .gitignore

0 comments on commit 5d0c32d

Please sign in to comment.