Skip to content

Commit

Permalink
[1.4] Reintroduce several 1.3 thrower fields (tModLoader#2553)
Browse files Browse the repository at this point in the history
* Reintroduce several 1.3 thrower fields

* adjust docs, reset fields

* tmodporter
  • Loading branch information
direwolf420 authored Jun 14, 2022
1 parent be3497f commit d050a79
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 4 deletions.
27 changes: 27 additions & 0 deletions patches/tModLoader/Terraria/Player.TML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,34 @@ public float GetWeaponAttackSpeed(Item sItem) {
return attackSpeed;
}

// Legacy Thrower properties (uppercase+property in TML)

/// <summary>
/// Multiplier to shot projectile velocity before throwing. Result will be capped to 16f.
/// <br/>Only applies to items counted as the <see cref="DamageClass.Throwing"/> damage type
/// </summary>
public float ThrownVelocity { get; set; }

/// <summary>
/// If true, player has a 33% chance of not consuming the thrown item.
/// <br/>Only applies to consumable items and projectiles counted as the <see cref="DamageClass.Throwing"/> damage type.
/// <br/>Projectiles spawned from a player who holds such item will set <see cref="Projectile.noDropItem"/> to prevent duplication.
/// <br/>Stacks with <see cref="ThrownCost50"/> multiplicatively
/// </summary>
public bool ThrownCost33 { get; set; }

/// <summary>
/// If true, player has a 50% chance of not consuming the thrown item.
/// <br/>Only applies to consumable items counted as the <see cref="DamageClass.Throwing"/> damage type.
/// <br/>Projectiles spawned from a player who holds such item will set <see cref="Projectile.noDropItem"/> to prevent duplication.
/// <br/>Stacks with <see cref="ThrownCost33"/> multiplicatively
/// </summary>
public bool ThrownCost50 { get; set; }

/// <summary>
/// Returns true if either <see cref="ThrownCost33"/> or <see cref="ThrownCost50"/> are true
/// </summary>
public bool AnyThrownCostReduction => ThrownCost33 || ThrownCost50;

/// <summary>
/// Container for current SceneEffect client properties such as: Backgrounds, music, and water styling
Expand Down
27 changes: 24 additions & 3 deletions patches/tModLoader/Terraria/Player.cs.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2347,8 +2347,13 @@
hasFootball = false;
drawingFootball = false;
minionKB = 0f;
@@ -13118,9 +_,14 @@
@@ -13116,11 +_,19 @@
huntressAmmoCost90 = false;
ammoCost80 = false;
ammoCost75 = false;
+ ThrownCost50 = false;
+ ThrownCost33 = false;
+ ThrownVelocity = 1f;
manaRegenBuff = false;
hasCreditsSceneMusicBox = false;
+ arrowDamage = StatModifier.Default;
Expand Down Expand Up @@ -4592,7 +4597,7 @@
if (sItem.stack <= 0)
sItem.SetDefaults();
}
@@ -33081,16 +_,21 @@
@@ -33081,16 +_,28 @@
}

private void ItemCheck_Shoot(int i, Item sItem, int weaponDamage) {
Expand All @@ -4605,6 +4610,13 @@
if (sItem.melee && projToShoot != 699 && projToShoot != 707 && (uint)(projToShoot - 877) > 2u)
- speed /= meleeSpeed;
+ speed /= inverseMeleeSpeed;
+
+ // Copied as-is from 1.3
+ if (sItem.CountsAsClass(DamageClass.Throwing) && speed < 16f) {
+ speed *= ThrownVelocity;
+ if (speed > 16f)
+ speed = 16f;
+ }

bool canShoot = false;
int Damage = weaponDamage;
Expand Down Expand Up @@ -5200,10 +5212,19 @@

if (huntressAmmoCost90 && Main.rand.Next(10) == 0)
flag2 = true;
@@ -37226,6 +_,7 @@
@@ -37226,6 +_,16 @@
if (ammoCost75 && Main.rand.Next(4) == 0)
flag2 = true;

+ // Copied as-is from 1.3
+ if (item.CountsAsClass(DamageClass.Throwing)) {
+ if (ThrownCost50 && Main.rand.Next(100) < 50)
+ flag2 = true;
+
+ if (ThrownCost33 && Main.rand.Next(100) < 33)
+ flag2 = true;
+ }
+
+ /* Flamethrower + Elf Melter (handled by consumeAmmoOnFirstShotOnly) + Clentaminator (handled by consumeAmmoOnFirstShotOnly)
if (projToShoot == 85 && itemAnimation < itemAnimationMax - 2)
flag2 = true;
Expand Down
14 changes: 13 additions & 1 deletion patches/tModLoader/Terraria/Projectile.cs.patch
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,19 @@

if (Owner == Main.myPlayer) {
if (ProjectileID.Sets.IsAGolfBall[Type] && Damage <= 0) {
@@ -8330,6 +_,11 @@
@@ -8325,11 +_,23 @@

if (Type == 777 || Type == 781 || Type == 794 || Type == 797 || Type == 800 || Type == 785 || Type == 788 || Type == 791 || Type == 903 || Type == 904 || Type == 905 || Type == 906 || Type == 910 || Type == 911)
projectile.timeLeft = 180;
+
+ // Copied from 1.3, adjusted to check for actual player (servers never shoot thrower projectiles)
+ if (Main.netMode != NetmodeID.Server) {
+ Player throwingPlayer = Main.player[Owner];
+ if (throwingPlayer.AnyThrownCostReduction && throwingPlayer.HeldItem.CountsAsClass(DamageClass.Throwing))
+ projectile.noDropItem = true;
+ }
}

if (Type == 249)
projectile.frame = Main.rand.Next(5);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ void Method() {
var hasBanner = Main.SceneMetrics.hasBanner;
var bannerBuff = Main.SceneMetrics.NPCBannerBuff;
var extraAccessorySlots = player.GetAmountOfExtraAccessorySlotsToShow();
var thrownCost33 = player.ThrownCost33;
var thrownCost50 = player.ThrownCost50;
var thrownVelocity = player.ThrownVelocity;

Main.PlayerRenderer.DrawPlayer(Main.Camera, player, Vector2.Zero, 0f, Vector2.Zero, 1f);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ void Method() {
var hasBanner = player.hasBanner;
var bannerBuff = player.NPCBannerBuff;
var extraAccessorySlots = player.extraAccessorySlots;
var thrownCost33 = player.thrownCost33;
var thrownCost50 = player.thrownCost50;
var thrownVelocity = player.thrownVelocity;

Main.DrawPlayer(player, Vector2.Zero, 0f, Vector2.Zero, 1f);

Expand Down
3 changes: 3 additions & 0 deletions tModPorter/tModPorter/Config.Terraria.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ private static void AddTerrariaRefactors() {
RenameInstanceField("Terraria.Player", from: "doubleJumpSail", to: "hasJumpOption_Sail");
RenameInstanceField("Terraria.Player", from: "doubleJumpSandstorm",to: "hasJumpOption_Sandstorm");
RenameInstanceField("Terraria.Player", from: "doubleJumpUnicorn", to: "hasJumpOption_Unicorn");
RenameInstanceField("Terraria.Player", from: "thrownCost33", to: "ThrownCost33");
RenameInstanceField("Terraria.Player", from: "thrownCost50", to: "ThrownCost50");
RenameInstanceField("Terraria.Player", from: "thrownVelocity", to: "ThrownVelocity");

RenameMethod("Terraria.Item", from: "IsNotTheSameAs", to: "IsNotSameTypePrefixAndStack");
RenameMethod("Terraria.Lighting", from: "BlackOut", to: "Clear");
Expand Down

0 comments on commit d050a79

Please sign in to comment.