Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
* Added BeamDamageScale config setting
* Pre-configured ProjectilesAsConsecutiveHittingAndCooldown to let molotov fires "melt" tiles at a rate of ~3/4s per hit
* Toned down beam weapons by using the same "can consecutive hit" code as regular projectiles
  • Loading branch information
hamstar0 committed Jun 1, 2019
1 parent 13b29b9 commit bee968f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 40 deletions.
10 changes: 6 additions & 4 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public class DestructibleTilesConfigData : ConfigurationDataBase {
//public IDictionary<string, float> ProjectilesAsPhysicsObjectsAndMaxVelocity = new Dictionary<string, float>();

public IDictionary<string, float> TileDamageScaleOverrides = new Dictionary<string, float>();
public IDictionary<string, float> TileArmor = new Dictionary<string, float>();
public IDictionary<string, float> TileArmor = new Dictionary<string, float>();

public float BeamDamageScale = 1f / 30f;


////
Expand Down Expand Up @@ -81,9 +83,9 @@ public void SetDefaults() {
this.ProjectileTileDamageDefaults["Terraria.517"] = 65; //Bouncy Grenade
this.ProjectileTileDamageDefaults["Terraria.588"] = 30; //Happy Grenade

this.ProjectilesAsConsecutiveHittingAndCooldown["Terraria."+ProjectileID.MolotovFire] = 60 * 2;
this.ProjectilesAsConsecutiveHittingAndCooldown["Terraria."+ProjectileID.MolotovFire2] = 60 * 2;
this.ProjectilesAsConsecutiveHittingAndCooldown["Terraria."+ProjectileID.MolotovFire3] = 60 * 2;
this.ProjectilesAsConsecutiveHittingAndCooldown["Terraria."+ProjectileID.MolotovFire] = 45;
this.ProjectilesAsConsecutiveHittingAndCooldown["Terraria."+ProjectileID.MolotovFire2] = 45;
this.ProjectilesAsConsecutiveHittingAndCooldown["Terraria."+ProjectileID.MolotovFire3] = 45;
}

public void SetProjectileDefaults() {
Expand Down
76 changes: 47 additions & 29 deletions MyProjectile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,61 @@ partial class DestructibleTilesProjectile : GlobalProjectile {



////////////////

public static bool CanHitTiles( Projectile projectile, out bool hasCooldown ) {
var mymod = DestructibleTilesMod.Instance;
string projName = ProjectileIdentityHelpers.GetProperUniqueId( projectile.type );
string timerName = "PTH_" + projectile.whoAmI;
bool isConsecutive = Timers.GetTimerTickDuration( timerName ) > 0;

hasCooldown = mymod.Config.ProjectilesAsConsecutiveHittingAndCooldown.ContainsKey( projName );

Timers.SetTimer( timerName, 2, () => false );

if( isConsecutive ) {
if( hasCooldown ) {
string repeatTimerName = timerName + "_repeat";
int cooldown = mymod.Config.ProjectilesAsConsecutiveHittingAndCooldown[projName];

if( Timers.GetTimerTickDuration( repeatTimerName ) <= 0 ) {
Timers.SetTimer( repeatTimerName, cooldown, () => false );
isConsecutive = false;
}
}
}

return !isConsecutive;
}



////////////////

public override void AI( Projectile projectile ) {
if( projectile.aiStyle == 84 ) {
Vector2 projPos = projectile.Center + projectile.velocity * projectile.localAI[1];
Point? tilePosNull = TileFinderHelpers.GetNearestSolidTile( projPos, 32, false, false );
if( projectile.aiStyle == 84 ) { // <- Beam weapons!
bool hasCooldown;

if( DestructibleTilesProjectile.CanHitTiles(projectile, out hasCooldown) || !hasCooldown ) {
Vector2 projPos = projectile.Center + projectile.velocity * projectile.localAI[1];
Point? tilePosNull = TileFinderHelpers.GetNearestSolidTile( projPos, 32, false, false );

//DebugHelpers.Print("proj_"+projectile.whoAmI,
// "ai: "+string.Join(", ", projectile.ai.Select(f=>f.ToString("N1")))+
// ", localAi: "+string.Join(", ", projectile.localAI.Select(f=>f.ToString("N1"))),
//20);
if( tilePosNull.HasValue ) {
var tilePos = tilePosNull.Value;
int damage = DestructibleTilesProjectile.ComputeProjectileDamage( projectile );

if( DestructibleTilesProjectile.HitTile( damage, tilePos.X, tilePos.Y, 1 ) ) {
bool _;
projectile.localAI[1] = CollisionHelpers.MeasureWorldDistanceToTile( projectile.Center, projectile.velocity, 2400f, out _ );
}
if( tilePosNull.HasValue ) {
var tilePos = tilePosNull.Value;
int damage = DestructibleTilesProjectile.ComputeBeamProjectileDamage( projectile );

if( DestructibleTilesProjectile.HitTile( damage, tilePos.X, tilePos.Y, 1 ) ) {
bool _;
projectile.localAI[1] = CollisionHelpers.MeasureWorldDistanceToTile( projectile.Center, projectile.velocity, 2400f, out _ );
}
//var pos1 = tilePos.ToVector2() * 16f;
//var pos2 = new Vector2( pos1.X + 16, pos1.Y + 16 );
//Dust.QuickBox( pos1, pos2, 0, Color.Red, d => { } );
}
}
}
}
Expand Down Expand Up @@ -72,28 +105,13 @@ public override bool OnTileCollide( Projectile projectile, Vector2 oldVelocity )
var mymod = DestructibleTilesMod.Instance;
string projName = ProjectileIdentityHelpers.GetProperUniqueId( projectile.type );

// Explosives are handled elsewhere
if( mymod.Config.ProjectilesAsExplosivesAndRadius.ContainsKey( projName ) ) {
return base.OnTileCollide( projectile, oldVelocity );
}

string timerName = "PTH_" + projectile.whoAmI;
bool isConsecutive = Timers.GetTimerTickDuration( timerName ) > 0;

Timers.SetTimer( timerName, 2, () => false );

if( isConsecutive ) {
if( mymod.Config.ProjectilesAsConsecutiveHittingAndCooldown.ContainsKey( projName ) ) {
string repeatTimerName = timerName + "_repeat";
int cooldown = mymod.Config.ProjectilesAsConsecutiveHittingAndCooldown[projName];

if( Timers.GetTimerTickDuration(repeatTimerName) <= 0 ) {
Timers.SetTimer( repeatTimerName, cooldown, () => false );
isConsecutive = false;
}
}
}

if( !isConsecutive ) {
bool _;
if( DestructibleTilesProjectile.CanHitTiles(projectile, out _) ) {
var rect = new Rectangle( (int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height );
rect.X += (int)oldVelocity.X;
rect.Y += (int)oldVelocity.Y;
Expand Down
4 changes: 0 additions & 4 deletions MyProjectile_Data.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DestructibleTiles.Helpers.CollisionHelpers;
using DestructibleTiles.Helpers.TileHelpers;
using HamstarHelpers.Helpers.DebugHelpers;
using HamstarHelpers.Helpers.ProjectileHelpers;
using HamstarHelpers.Services.Timers;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
Expand Down
16 changes: 13 additions & 3 deletions MyProjectile_TileHp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,26 @@ public static int ComputeProjectileDamage( Projectile projectile ) {
}

if( projectile.damage > 0 ) {
return (int)((float)projectile.damage * mymod.Config.AllDamagesScale);
return (int)( (float)projectile.damage * mymod.Config.AllDamagesScale );
}

if( mymod.Config.ProjectileTileDamageDefaults.ContainsKey( projName ) ) {
return (int)((float)mymod.Config.ProjectileTileDamageDefaults[projName] * mymod.Config.AllDamagesScale);
return (int)( (float)mymod.Config.ProjectileTileDamageDefaults[projName] * mymod.Config.AllDamagesScale );
}

return (int)((float)projectile.damage * mymod.Config.AllDamagesScale );
return (int)( (float)projectile.damage * mymod.Config.AllDamagesScale );
}

public static int ComputeBeamProjectileDamage( Projectile projectile ) {
var mymod = DestructibleTilesMod.Instance;
int damage = DestructibleTilesProjectile.ComputeProjectileDamage( projectile );

return (int)((float)damage * mymod.Config.BeamDamageScale);
}


////

public static float ComputeHitDamage( Tile tile, int baseDamage, int totalHits ) {
var mymod = DestructibleTilesMod.Instance;
float dmg = (float)baseDamage / (float)totalHits;
Expand Down

0 comments on commit bee968f

Please sign in to comment.