forked from hollowstrawberry/Virtuous
-
Notifications
You must be signed in to change notification settings - Fork 1
/
OrbitalItem.cs
184 lines (148 loc) · 7.03 KB
/
OrbitalItem.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Localization;
using Virtuous.Orbitals;
namespace Virtuous
{
public abstract class OrbitalItem : ModItem
{
public override bool CloneNewInstances => true; // The defaults are copied to new items
// Traits set in defaults
public int type = OrbitalID.None; // The orbital this item spawns. Failing to provide a valid one will cause an exception
public int duration = 5 * 60; // How long the summoned orbital will last, in ticks
public int amount = 1; // The amount of orbitals that will be spawned in a circle
public SpecialType specialType = SpecialType.None; // If and how an orbital special effect triggers
public enum SpecialType
{
None,
Reuse,
RightClick,
}
public virtual void SetOrbitalDefaults()
{
}
public sealed override void SetDefaults() // Safe way of setting standard default values
{
item.width = 30;
item.height = 30;
item.useStyle = 4;
item.useTime = 40;
item.useAnimation = item.useTime;
item.UseSound = SoundID.Item8;
item.noMelee = true;
item.autoReuse = false;
item.useTurn = true;
SetOrbitalDefaults();
if (type < 0 || type >= OrbitalID.Orbital.Length)
{
throw new Exception($"Virtuous: The type of the orbital item {item.Name} was set to the orbital ID {type}, " +
$"which is either invalid or doesn't have any matching orbital.");
}
item.shoot = mod.OrbitalProjectileType(type); //Sets the orbital projectile to shoot
if (specialType != SpecialType.None) item.autoReuse = true;
//Overwrites
item.crit = 0;
item.melee = false;
item.ranged = false;
item.magic = false;
item.thrown = false;
item.summon = false;
}
public override bool AltFunctionUse(Player player)
{
return specialType == SpecialType.RightClick;
}
public override void GetWeaponDamage(Player player, ref int damage)
{
var orbitalPlayer = player.GetModPlayer<OrbitalPlayer>();
float highestDamage = Math.Max(player.meleeDamage, player.magicDamage);
damage = (int)(item.damage * orbitalPlayer.damageMultiplier * (highestDamage - orbitalPlayer.damageBuffFromOrbitals));
if (specialType == SpecialType.RightClick)
{
Tools.HandleAltUseAnimation(player);
}
}
public override bool CanUseItem(Player player)
{
var orbitalPlayer = player.GetModPlayer<OrbitalPlayer>();
// Can't use the right click special function with the orbital not active
if (specialType == SpecialType.RightClick && player.altFunctionUse == 2 && !orbitalPlayer.active[this.type])
{
return false;
}
// Can't use an orbital if any other orbital is in the process of dying
if (Enumerable.Range(0, OrbitalID.Orbital.Length)
.Any(id => orbitalPlayer.active[id] && orbitalPlayer.time <= OrbitalID.Orbital[id].DyingTime))
{
return false;
}
return base.CanUseItem(player);
}
public sealed override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
var orbitalPlayer = player.GetModPlayer<OrbitalPlayer>();
if (orbitalPlayer.active[this.type]) // The orbital is already active
{
if (specialType != SpecialType.None) // Alternate use mechanics
{
if (specialType == SpecialType.RightClick)
{
// Left-click resets duration, right-click activates special
if (player.altFunctionUse != 2) orbitalPlayer.time = orbitalPlayer.ModifiedOrbitalTime(this);
else orbitalPlayer.SpecialFunctionActive = true;
}
else if (specialType == SpecialType.Reuse)
{
// Activates special and resets duration
orbitalPlayer.SpecialFunctionActive = true;
orbitalPlayer.time = orbitalPlayer.ModifiedOrbitalTime(this);
}
}
}
else // The orbital is not active
{
orbitalPlayer.ResetOrbitals();
orbitalPlayer.active[this.type] = true;
orbitalPlayer.time = orbitalPlayer.ModifiedOrbitalTime(this);
for (int i = 0; i < this.amount; i++)
{
// The desired rotation will be passed as velocity
Vector2 rotation = Vector2.UnitX.RotatedBy(Tools.FullCircle * i / this.amount);
Projectile.NewProjectile(position, rotation, type, damage, knockBack, player.whoAmI);
}
}
return false; // Doesn't shoot normally
}
public override void ModifyTooltips(List<TooltipLine> tooltips)
{
var orbitalPlayer = Main.player[item.owner].GetModPlayer<OrbitalPlayer>();
TooltipLine critLine = tooltips.FirstOrDefault(line => line.mod == "Terraria" && line.Name == "CritChance");
if (critLine != null) tooltips.Remove(critLine); // Removes the critical chance line
TooltipLine damageLine = tooltips.FirstOrDefault(line => line.mod == "Terraria" && line.Name == "Damage");
if (damageLine != null)
{
string damage = damageLine.text.Split(' ')[0];
if (Language.ActiveCulture == GameCulture.Spanish) damageLine.text = $"{damage} daño orbital";
else damageLine.text = $"{damage} orbital damage";
}
string durationText = ((orbitalPlayer.ModifiedOrbitalTime(this) - OrbitalID.Orbital[type].DyingTime) / 60).ToString();
durationText += Language.ActiveCulture == GameCulture.Spanish ? " segundos de duración" : " seconds duration";
int durationIndex;
if (damageLine == null) // Above mana
{
durationIndex = tooltips.IndexOf(tooltips.FirstOrDefault(line => line.mod == "Teraria" && line.Name == "UseMana"));
}
else // Replaces speed
{
durationIndex = tooltips.IndexOf(tooltips.FirstOrDefault(line => line.mod == "Terraria" && line.Name == "Speed"));
tooltips.RemoveAt(durationIndex);
}
tooltips.Insert(Math.Max(durationIndex, 0), new TooltipLine(mod, "OrbitalDuration", durationText));
}
}
}