-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSummonersAssociationAPI.cs
148 lines (136 loc) · 5.6 KB
/
SummonersAssociationAPI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using SummonersAssociation.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ModLoader;
namespace SummonersAssociation
{
/// <summary>
/// Class that provides access to the data of all supported minions by this mod. Use <see cref="GetSupportedMinions"/> to get the raw data and operate on it how you want.
/// Or use the helper methods to circumvent working with the MinionModel class (not the full scope though).
/// </summary>
public static class SummonersAssociationAPI
{
/// <summary>
/// Returns an List[MinionModel] that is a copy of this mod's data.
/// For best results, call it once in Mod.PostAddRecipes and cache the result
/// </summary>
/// <param name="mod">Your mod</param>
/// <returns>Data of all supported minions by this mod</returns>
public static List<MinionModel> GetSupportedMinions(Mod mod) {
const string method = nameof(GetSupportedMinions);
if (mod == null) {
throw new Exception($"Call Error: The Mod argument for {method} is null.");
}
var saMod = SummonersAssociation.Instance;
var logger = saMod.Logger;
logger.Info($"{(mod.DisplayName ?? "A mod")} has registered for {method} via API");
if (!saMod.SupportedMinionsFinalized) {
logger.Warn($"Call Warning: The attempted method \"{method}\" is called early. Expect the method to return incomplete data. For best results, call in PostAddRecipes.");
}
return SummonersAssociation.SupportedMinions.Select(model => new MinionModel(model)).ToList();
}
/// <summary>
/// Returns the number of "minion" buffs currently active on the player.
/// </summary>
/// <param name="player">The player</param>
/// <returns>Number of "minion" buffs</returns>
public static int GetActiveMinionBuffs(Player player) {
int count = 0;
foreach (var model in SummonersAssociation.SupportedMinions) {
if (model.BuffID > 0 && player.HasBuff(model.BuffID))
count++;
}
return count;
}
/// <summary>
/// Get a list of projectile IDs that are associated with a given buff type.
/// For example, this will return two IDs if you provide BuffID.TwinEyesMinion
/// </summary>
/// <param name="buffType">Buff type</param>
/// <returns>List of projectile IDs. Empty list if buff is not associated with a minion</returns>
public static List<int> GetProjectileIDsAssociatedWithBuff(int buffType) {
List<int> projectileIDs = new List<int>();
foreach (var model in SummonersAssociation.SupportedMinions) {
if (model.ItemID > 0 && model.BuffID == buffType) {
projectileIDs = model.ProjData.Select(d => d.ProjID).ToList();
break;
}
}
return projectileIDs;
}
/// <summary>
/// Get a list of projectile IDs that are associated with a given item type.
/// For example, this will return two IDs if you provide ItemID.OpticStaff
/// </summary>
/// <param name="itemType">Item type</param>
/// <returns>List of projectile IDs. Empty list if item is not associated with a minion</returns>
public static List<int> GetProjectileIDsAssociatedWithItem(int itemType) {
List<int> projectileIDs = new List<int>();
foreach (var model in SummonersAssociation.SupportedMinions) {
if (model.BuffID > 0 && model.ItemID == itemType) {
projectileIDs = model.ProjData.Select(d => d.ProjID).ToList();
break;
}
}
return projectileIDs;
}
/// <summary>
/// Get the item ID that is associated with a given buff type.
/// For example, this will return the value of ItemID.OpticStaff if you provide BuffID.TwinEyesMinion
/// </summary>
/// <param name="buffType">Buff type</param>
/// <returns>Item ID. 0 if buff is not associated with a minion</returns>
public static int GetItemIDAssociatedWithBuff(int buffType) {
foreach (var model in SummonersAssociation.SupportedMinions) {
if (model.ItemID > 0 && model.BuffID == buffType) {
return model.ItemID;
}
}
return 0;
}
/// <summary>
/// Get the buff ID that is associated with a given item type.
/// For example, this will return the value of BuffID.TwinEyesMinion if you provide ItemID.OpticStaff
/// </summary>
/// <param name="itemType">Item type</param>
/// <returns>Buff ID. 0 if item is not associated with a minion</returns>
public static int GetBuffIDAssociatedWithItem(int itemType) {
foreach (var model in SummonersAssociation.SupportedMinions) {
if (model.BuffID > 0 && model.ItemID == itemType) {
return model.BuffID;
}
}
return 0;
}
/// <summary>
/// Get the buff ID that is associated with a given projectile type.
/// For example, this will return the value of BuffID.TwinEyesMinion if you provide ProjectileID.Spazmamini
/// </summary>
/// <param name="projType">Projectile type</param>
/// <returns>Buff ID. 0 if projectile is not associated with a minion</returns>
public static int GetBuffIDAssociatedWithProjectile(int projType) {
foreach (var model in SummonersAssociation.SupportedMinions) {
if (model.BuffID > 0 && model.ContainsProjID(projType)) {
return model.BuffID;
}
}
return 0;
}
/// <summary>
/// Get the item ID that is associated with a given projectile type.
/// For example, this will return the value of ItemID.OpticStaff if you provide ProjectileID.Spazmamini
/// </summary>
/// <param name="projType">Projectile type</param>
/// <returns>Item ID. 0 if projectile is not associated with a minion</returns>
public static int GetItemIDAssociatedWithProjectile(int projType) {
foreach (var model in SummonersAssociation.SupportedMinions) {
if (model.ItemID > 0 && model.ContainsProjID(projType)) {
return model.ItemID;
}
}
return 0;
}
}
}