forked from GabeHasWon/VerdantMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SacrificeAutoloader.cs
56 lines (49 loc) · 1.97 KB
/
SacrificeAutoloader.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
using System;
using System.Linq;
using Terraria;
using Terraria.GameContent.Creative;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.Core;
using Verdant.Items.Verdant;
namespace Verdant;
/// <summary>Copied from my implementation of the same name in Spirit.</summary>
public class SacrificeAutoloader
{
public static void Load(Mod mod)
{
var types = AssemblyManager.GetLoadableTypes(mod.Code).Where(x => typeof(ModItem).IsAssignableFrom(x) && !x.IsAbstract);
foreach (var info in types)
{
if (!mod.TryFind(info.Name, out ModItem modItem))
continue;
int type = modItem.Type;
if (Attribute.IsDefined(info, typeof(SacrificeAttribute)))
{
SacrificeAttribute attr = Attribute.GetCustomAttribute(info, typeof(SacrificeAttribute)) as SacrificeAttribute;
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[type] = attr.Count;
continue;
}
Item item = new Item(type);
bool placesTile = item.createTile >= TileID.Dirt;
bool placesWall = item.createWall > WallID.None;
bool isWeapon = item.damage > 0 || item.mana > 0;
bool accessoryOrArmor = item.accessory || item.defense > 0 || Attribute.IsDefined(info, typeof(AutoloadEquip));
if (placesTile) //Tiles
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[type] = 100;
else if (placesWall) //Walls
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[type] = 400;
else if (isWeapon) //Weapons
{
if (item.consumable) //Consumable weapons
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[type] = 99;
else //Non-consumable weapons
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[type] = 1;
}
else if (accessoryOrArmor) //Accessories or armor
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[type] = 1;
else //Everything else, namely materials
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[type] = 25;
}
}
}