forked from NotSoEpic/TrueEndless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEndlessItem.cs
118 lines (108 loc) · 4.85 KB
/
EndlessItem.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
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using System.Linq;
using static Terraria.ModLoader.ModContent;
namespace TrueEndless
{
class EndlessItem : GlobalItem
{
public override bool InstancePerEntity => true;
public override bool CloneNewInstances => true;
public bool wasConsumable = false;
public int properStack = 0;
private bool HasInfinity() => Main.player[Main.myPlayer].GetModPlayer<EndlessPlayer>().infinity;
private bool HasInfinity(Player player) => player.GetModPlayer<EndlessPlayer>().infinity;
public bool IsEndlessAmmo(Item item) => (item.stack >= item.maxStack || item.stack >= 999) && item.maxStack > 1 && item.ammo != AmmoID.None;
public bool IsEndlessPotion(Item item) => (item.stack >= item.maxStack || item.stack >= 30) && item.maxStack > 1 && item.buffType != 0;
public bool IsEndlessConsumable(Item item) => (item.stack >= item.maxStack || item.stack >= 999) && item.maxStack > 1 && (item.consumable || wasConsumable) && item.createTile == -1 && item.createWall == -1;
public bool IsEndlessSpecific(Item item)
{
int[] ids = new int[]
{
ItemID.Torch,
ItemID.TikiTorch,
ItemID.BlueTorch,
ItemID.RedTorch,
ItemID.GreenTorch,
ItemID.PurpleTorch,
ItemID.WhiteTorch,
ItemID.YellowTorch,
ItemID.DemonTorch,
ItemID.CursedTorch,
ItemID.IceTorch,
ItemID.OrangeTorch,
ItemID.IchorTorch,
ItemID.UltrabrightTorch,
ItemID.BoneTorch,
ItemID.RainbowTorch,
ItemID.PinkTorch,
ItemID.BeachBall,
ItemID.WaterCandle,
ItemID.PeaceCandle,
};
return (item.stack >= item.maxStack || item.stack >= 30) && ids.Contains(item.type);
}
public bool IsEndlessExempt(Item item)
{
int[] ids = new int[]
{
};
return (ids.Contains(item.type));
}
// THIS IS CALLED IN THE MAIN MENU
// WTF
public override bool PreDrawInInventory(Item item, SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale)
{
if (properStack != 0)
{
item.stack = properStack;
properStack = 0;
}
if ((Main.gameMenu || HasInfinity()) && GetInstance<EndlessConfigClient>().RainbowSprite && !IsEndlessExempt(item) && ((IsEndlessAmmo(item) && !item.notAmmo) || IsEndlessConsumable(item) || IsEndlessPotion(item) || IsEndlessSpecific(item)))
{
Texture2D texture = Main.itemTexture[item.type];
spriteBatch.Draw(texture, position, null, Main.DiscoColor, 0, origin, scale, SpriteEffects.None, 0f);
return false;
}
return true;
}
private bool IsEndlessTooltip(TooltipLine tooltip) => tooltip.mod == mod.Name && tooltip.Name == "EndlessNotice";
public override void ModifyTooltips(Item item, List<TooltipLine> tooltips)
{
tooltips.RemoveAll(IsEndlessTooltip);
if (HasInfinity() && !IsEndlessExempt(item) && ((IsEndlessAmmo(item) && !item.notAmmo) || IsEndlessConsumable(item) || IsEndlessPotion(item) || IsEndlessSpecific(item)))
{
string text = "Endless";
if (GetInstance<EndlessConfigClient>().RainbowTooltip)
{
text = "[c/" + Main.DiscoColor.Hex3() + ":" + text + "]";
}
tooltips.Add(new TooltipLine(mod, "EndlessNotice", text));
}
}
public override void UpdateInventory(Item item, Player player)
{
if (HasInfinity(player) && !IsEndlessExempt(item) && (IsEndlessConsumable(item) || IsEndlessPotion(item) || IsEndlessSpecific(item)))
{
wasConsumable = true;
item.consumable = false;
}
else if (wasConsumable)
{
item.consumable = true;
}
if (HasInfinity(player) && !IsEndlessExempt(item) && (IsEndlessPotion(item) || IsEndlessConsumable(item) && item.buffType != 0))
{
player.AddBuff(item.buffType, 2);
}
}
public override void GetHealLife(Item item, Player player, bool quickHeal, ref int healValue)
{
properStack = item.stack;
}
}
}