Skip to content

Commit

Permalink
v1.10.2 - Added MinimumTileDistanceBetweenWormholes config setting
Browse files Browse the repository at this point in the history
  • Loading branch information
hamstar0 committed May 7, 2020
1 parent d203430 commit 4637907
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 67 deletions.
16 changes: 14 additions & 2 deletions Wormholes/Config.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using HamstarHelpers.Classes.UI.ModConfig;
using System;
using System;
using System.ComponentModel;
using Terraria.ModLoader;
using Terraria.ModLoader.Config;
using HamstarHelpers.Classes.UI.ModConfig;


namespace Wormholes {
Expand All @@ -11,6 +12,12 @@ class MyFloatInputElement : FloatInputElement { }


public class WormholesConfig : ModConfig {
public static WormholesConfig Instance => ModContent.GetInstance<WormholesConfig>();



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

public override ConfigScope Mode => ConfigScope.ServerSide;


Expand Down Expand Up @@ -44,6 +51,11 @@ public class WormholesConfig : ModConfig {
public int HugeWorldPortals = 27;


[Range( 0, 8000 )]
[DefaultValue( 128 )]
public int MinimumTileDistanceBetweenWormholes = 128;


[DefaultValue( true )]
public bool CraftableTownPortalScrolls = true;

Expand Down
9 changes: 3 additions & 6 deletions Wormholes/Items/ChaosBombItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ public override void AddRecipes() {

class ChaosBombRecipe : ModRecipe {
public ChaosBombRecipe( ChaosBombItem moditem ) : base( moditem.mod ) {
var mymod = (WormholesMod)this.mod;

this.AddTile( 18 ); // Crafting bench

this.AddRecipeGroup( "WormholesMod:EvacPotions", 1 );
this.AddIngredient( ItemID.BouncyBomb, mymod.Config.ChaosBombRecipeBouncyBombCost );
this.AddIngredient( ItemID.BouncyBomb, WormholesConfig.Instance.ChaosBombRecipeBouncyBombCost );
this.AddIngredient( ItemID.Amethyst, 1 );
this.AddIngredient( ItemID.Topaz, 1 );
this.AddIngredient( ItemID.Sapphire, 1 );
Expand All @@ -54,12 +52,11 @@ public ChaosBombRecipe( ChaosBombItem moditem ) : base( moditem.mod ) {
this.AddIngredient( ItemID.Diamond, 1 );
this.AddIngredient( ItemID.Amber, 1 );
//this.AddIngredient( ItemID.Glass, 10 );
this.SetResult( moditem, mymod.Config.ChaosBombRecipeQuantity );
this.SetResult( moditem, WormholesConfig.Instance.ChaosBombRecipeQuantity );
}

public override bool RecipeAvailable() {
var mymod = (WormholesMod)this.mod;
return mymod.Config.CraftableTownPortalScrolls;
return WormholesConfig.Instance.CraftableTownPortalScrolls;
}
}
}
7 changes: 2 additions & 5 deletions Wormholes/Items/TownPortalScrollItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,17 @@ public override void AddRecipes() {

class TownPortalScrollRecipe : ModRecipe {
public TownPortalScrollRecipe( TownPortalScrollItem moditem ) : base( moditem.mod ) {
var mymod = (WormholesMod)this.mod;

this.AddTile( 18 ); // Crafting bench

this.AddRecipeGroup( "WormholesMod:EvacPotions", 3 );
this.AddRecipeGroup( "WormholesMod:BasicBooks", 1 );
//this.AddIngredient( ItemID.WormholePotion, 1 );
this.AddIngredient( ItemID.ManaCrystal, 1 );
this.SetResult( moditem, mymod.Config.TownPortalRecipeQuantity );
this.SetResult( moditem, WormholesConfig.Instance.TownPortalRecipeQuantity );
}

public override bool RecipeAvailable() {
var mymod = (WormholesMod)this.mod;
return mymod.Config.CraftableTownPortalScrolls;
return WormholesConfig.Instance.CraftableTownPortalScrolls;
}
}
}
2 changes: 0 additions & 2 deletions Wormholes/MyMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ partial class WormholesMod : Mod {

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

public WormholesConfig Config => ModContent.GetInstance<WormholesConfig>();

private WormholesUI UI;


Expand Down
4 changes: 2 additions & 2 deletions Wormholes/MyMod_Draw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private void DrawMiniMap( SpriteBatch sb ) {
WormholesWorld myworld = ModContent.GetInstance<WormholesWorld>();
WormholesPlayer myplayer = Main.LocalPlayer.GetModPlayer<WormholesPlayer>();

if( !this.Config.DisableNaturalWormholes ) {
if( !WormholesConfig.Instance.DisableNaturalWormholes ) {
if( myworld.Wormholes != null ) {
for( int i = 0; i < myworld.Wormholes.Links.Count; i++ ) {
WormholeLink link = myworld.Wormholes.Links[i];
Expand Down Expand Up @@ -73,7 +73,7 @@ private void DrawFullMap( SpriteBatch sb ) {
WormholesWorld myworld = ModContent.GetInstance<WormholesWorld>();
WormholesPlayer myplayer = Main.LocalPlayer.GetModPlayer<WormholesPlayer>();

if( !this.Config.DisableNaturalWormholes ) {
if( !WormholesConfig.Instance.DisableNaturalWormholes ) {
if( myworld.Wormholes != null ) {
for( int i = 0; i < myworld.Wormholes.Links.Count; i++ ) {
WormholeLink link = myworld.Wormholes.Links[i];
Expand Down
4 changes: 1 addition & 3 deletions Wormholes/MyWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ public static (int minTileX, int maxTileX, int minTileY, int maxTileY) GetTileBo
////////////////

public override void Initialize() {
var mymod = (WormholesMod)this.mod;

this.Wormholes = new WormholeManager();
this.ID = Guid.NewGuid().ToString( "D" );
this.HasCorrectID = false;

if( mymod.Config.DebugModeReset ) {
if( WormholesConfig.Instance.DebugModeReset ) {
WormholeManager.ForceRegenWormholes = true;
}
}
Expand Down
8 changes: 3 additions & 5 deletions Wormholes/Projectiles/ChaosBombProjectile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ public override bool CanDamage() {


public override void AI() {
var mymod = (WormholesMod)this.mod;
var modworld = ModContent.GetInstance<WormholesWorld>();
var modplayer = Main.player[Main.myPlayer].GetModPlayer<WormholesPlayer>();
var rect = this.projectile.getRect();
int rand = Main.rand.Next( mymod.Config.ChaosBombWormholeCloseOdds );
int rand = Main.rand.Next( WormholesConfig.Instance.ChaosBombWormholeCloseOdds );
var proj = this.projectile;

if( proj.owner == Main.myPlayer && proj.timeLeft <= 3 ) {
Expand Down Expand Up @@ -81,7 +80,6 @@ public override void AI() {


public override void Kill( int timeLeft ) {
var mymod = (WormholesMod)this.mod;
Projectile proj = this.projectile;
Main.PlaySound( SoundID.Item14, proj.position );
var vec = default( Vector2 );
Expand Down Expand Up @@ -127,8 +125,8 @@ public override void Kill( int timeLeft ) {
if( timeLeft == 0 && proj.owner == Main.myPlayer ) {
int tileX = (int)this.projectile.Center.X / 16;
int tileY = (int)this.projectile.Center.Y / 16;
int radius = mymod.Config.ChaosBombRadius;
this.ScatterTiles( tileX, tileY, radius, mymod.Config.ChaosBombScatterRadius );
int radius = WormholesConfig.Instance.ChaosBombRadius;
this.ScatterTiles( tileX, tileY, radius, WormholesConfig.Instance.ChaosBombScatterRadius );

if( Main.netMode != 0 ) {
NetMessage.SendData( MessageID.KillProjectile, -1, -1, null, proj.identity, (float)proj.owner, 0f, 0f, 0, 0, 0 );
Expand Down
3 changes: 1 addition & 2 deletions Wormholes/Wormholes/WormholeLink_Interact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ protected virtual void TeleportToRight( Player player ) {


protected virtual void Teleport( Player player, Vector2 dest ) {
var mymod = WormholesMod.Instance;
WormholesPlayer myplayer = player.GetModPlayer<WormholesPlayer>();

if( myplayer.MyPortal == null || (myplayer.MyPortal != null && this.ID != myplayer.MyPortal.ID) ) {
Expand Down Expand Up @@ -145,7 +144,7 @@ protected virtual void Teleport( Player player, Vector2 dest ) {
}

//Main.PlaySound( 2, player.position, 100 );
var snd = SoundID.Item100.WithVolume( mymod.Config.WormholeEntrySoundVolume );
var snd = SoundID.Item100.WithVolume( WormholesConfig.Instance.WormholeEntrySoundVolume );
Main.PlaySound( snd, player.position );
}
}
Expand Down
4 changes: 1 addition & 3 deletions Wormholes/Wormholes/WormholeLink_TownPortal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ public TownPortalLink( Color color, Vector2 leftNodePos, Vector2 rightNodePos )
protected override void TeleportToLeft( Player player ) {
base.TeleportToLeft( player );

var mymod = WormholesMod.Instance;

if( mymod.Config.TownPortalConsumesOnReturn ) {
if( WormholesConfig.Instance.TownPortalConsumesOnReturn ) {
this.Close();
}
}
Expand Down
49 changes: 25 additions & 24 deletions Wormholes/Wormholes/WormholeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@ class WormholeManager {
////////////////

public WormholeManager() {
var mymod = WormholesMod.Instance;

switch( WorldHelpers.GetSize() ) {
case WorldSize.SubSmall:
WormholeManager.PortalCount = mymod.Config.TinyWorldPortals;
WormholeManager.PortalCount = WormholesConfig.Instance.TinyWorldPortals;
break;
case WorldSize.Small:
WormholeManager.PortalCount = mymod.Config.SmallWorldPortals;
WormholeManager.PortalCount = WormholesConfig.Instance.SmallWorldPortals;
break;
case WorldSize.Medium:
WormholeManager.PortalCount = mymod.Config.MediumWorldPortals;
WormholeManager.PortalCount = WormholesConfig.Instance.MediumWorldPortals;
break;
case WorldSize.Large:
WormholeManager.PortalCount = mymod.Config.LargeWorldPortals;
WormholeManager.PortalCount = WormholesConfig.Instance.LargeWorldPortals;
break;
case WorldSize.SuperLarge:
WormholeManager.PortalCount = mymod.Config.HugeWorldPortals;
WormholeManager.PortalCount = WormholesConfig.Instance.HugeWorldPortals;
break;
}

Expand All @@ -50,15 +48,13 @@ public WormholeManager() {
/////////////////

public bool Load( TagCompound tags ) {
var mymod = WormholesMod.Instance;

if( mymod.Config.DisableNaturalWormholes ) { return false; }
if( WormholesConfig.Instance.DisableNaturalWormholes ) { return false; }
if( !tags.ContainsKey("wormhole_count") ) { return false; }

int holes = tags.GetInt( "wormhole_count" );
if( holes == 0 ) { return false; }

if( mymod.Config.DebugModeInfo ) {
if( WormholesConfig.Instance.DebugModeInfo ) {
LogHelpers.Log( "Loading world ids (" + Main.netMode + "): " + holes );
}

Expand All @@ -73,7 +69,7 @@ public bool Load( TagCompound tags ) {
}

string id = tags.GetString( "wormhole_id_" + i );
if( mymod.Config.DebugModeInfo ) {
if( WormholesConfig.Instance.DebugModeInfo ) {
LogHelpers.Log( " world load id: " + id + " (" + i + ")" );
}

Expand All @@ -97,14 +93,13 @@ public bool Load( TagCompound tags ) {


public TagCompound Save() {
var mymod = WormholesMod.Instance;
string[] ids = new string[WormholeManager.PortalCount];
int[] wormLeftX = new int[WormholeManager.PortalCount];
int[] wormLeftY = new int[WormholeManager.PortalCount];
int[] wormRightX = new int[WormholeManager.PortalCount];
int[] wormRightY = new int[WormholeManager.PortalCount];

if( mymod.Config.DebugModeInfo ) {
if( WormholesConfig.Instance.DebugModeInfo ) {
LogHelpers.Log( "Save world ids (" + Main.netMode + "): " + WormholeManager.PortalCount );
}

Expand Down Expand Up @@ -132,7 +127,7 @@ public TagCompound Save() {
for( i = 0; i < this.Links.Count; i++ ) {
tags.Set( "wormhole_id_" + i, ids[i] );

if( mymod.Config.DebugModeInfo ) {
if( WormholesConfig.Instance.DebugModeInfo ) {
LogHelpers.Log( " world save id: " + ids[i] + " (" + i + ") = "
+ wormLeftX[i] + "," + wormLeftY[i] + " | " + wormRightX[i] + "," + wormRightY[i] );
}
Expand Down Expand Up @@ -169,6 +164,8 @@ private Vector2 GetRandomClearMapPos() {
Vector2 randPos;
int worldX, worldY;
bool found = false, isEmpty = false;
int minWldDistSqr = WormholesConfig.Instance.MinimumTileDistanceBetweenWormholes * 16;
minWldDistSqr *= minWldDistSqr;

(int minX, int maxX, int minY, int maxY) bounds = WormholesWorld.GetTileBoundsForWormholes();

Expand Down Expand Up @@ -199,14 +196,14 @@ private Vector2 GetRandomClearMapPos() {
for( int i = 0; i < this.Links.Count; i++ ) {
var link = this.Links[i];

float dist = Vector2.Distance( link.LeftPortal.Pos, randPos );
if( dist < 2048 ) {
float distSqr = Vector2.DistanceSquared( link.LeftPortal.Pos, randPos );
if( distSqr < minWldDistSqr ) {
found = false;
break;
}

dist = Vector2.Distance( link.RightPortal.Pos, randPos );
if( dist < 2048 ) {
distSqr = Vector2.DistanceSquared( link.RightPortal.Pos, randPos );
if( distSqr < minWldDistSqr ) {
found = false;
break;
}
Expand All @@ -218,6 +215,13 @@ private Vector2 GetRandomClearMapPos() {


public WormholeLink CreateRandomWormholePair( Color color ) {
if( (Main.maxTilesX + 4) <= (WormholesConfig.Instance.MinimumTileDistanceBetweenWormholes) ) {
return null;
}
if( (Main.maxTilesY + 4) <= (WormholesConfig.Instance.MinimumTileDistanceBetweenWormholes) ) {
return null;
}

int retries = 0;
Vector2 randPos1, randPos2;

Expand Down Expand Up @@ -267,7 +271,6 @@ public void FinishSettingUpWormholes() {
/////////////////

public void RunAll( Player player ) {
var mymod = WormholesMod.Instance;
int who = player.whoAmI;

if( !this.BlockPortalCountdown.Keys.Contains( who ) ) {
Expand All @@ -279,7 +282,7 @@ public void RunAll( Player player ) {
int blockCountdown = this.BlockPortalCountdown[who];
WormholeLink townPortal = player.GetModPlayer<WormholesPlayer>().MyPortal;

if( !mymod.Config.DisableNaturalWormholes ) {
if( !WormholesConfig.Instance.DisableNaturalWormholes ) {
for( int i = 0; i < this.Links.Count; i++ ) {
WormholeLink link = this.Links[i];
if( link == null ) { break; }
Expand All @@ -305,9 +308,7 @@ public void RunAll( Player player ) {
}

public void DrawAll( WormholeLink townPortal ) {
var mymod = WormholesMod.Instance;

if( !mymod.Config.DisableNaturalWormholes ) {
if( !WormholesConfig.Instance.DisableNaturalWormholes ) {
for( int i = 0; i < this.Links.Count; i++ ) {
WormholeLink link = this.Links[i];
if( link == null ) { break; }
Expand Down
8 changes: 2 additions & 6 deletions Wormholes/Wormholes/WormholePortal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,9 @@ public void DrawForMe() {
public void SoundFX() {
if( this.IsClosed ) { return; }

var mymod = WormholesMod.Instance;

// Loop audio
if( this.SoundLoopTimer++ > 12 ) {
Main.PlaySound( SoundID.Item24.WithVolume( mymod.Config.WormholeSoundVolume), this.Pos );
Main.PlaySound( SoundID.Item24.WithVolume( WormholesConfig.Instance.WormholeSoundVolume), this.Pos );
this.SoundLoopTimer = 0;
}
}
Expand All @@ -159,12 +157,10 @@ public void LightFX() {
if( this.IsClosed ) { return; }
if( Main.rand == null ) { return; }

var mymod = WormholesMod.Instance;

int x = (int)((this.Pos.X + (WormholePortal.Width / 2)) / 16f);
int y = (int)((this.Pos.Y + (WormholePortal.Height / 2)) / 16f);

float flickerScale = 0.5f + mymod.Config.WormholeLightScale * Main.rand.NextFloat();
float flickerScale = 0.5f + WormholesConfig.Instance.WormholeLightScale * Main.rand.NextFloat();
float r = flickerScale * this.BaseColor.R / 255f;
float g = flickerScale * this.BaseColor.G / 255f;
float b = flickerScale * this.BaseColor.B / 255f;
Expand Down
9 changes: 3 additions & 6 deletions Wormholes/WormholesUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public void Update() {
////////////////

public void DrawMiniMap( WormholeLink link, SpriteBatch sb ) {
var mymod = WormholesMod.Instance;
if( !link.IsCharted( Main.LocalPlayer ) && !mymod.Config.DebugModeMapCheat ) { return; }
if( !link.IsCharted( Main.LocalPlayer ) && !WormholesConfig.Instance.DebugModeMapCheat ) { return; }

float scale = Main.mapMinimapScale / 1.5f;
Texture2D tex = WormholesUI.Tex;
Expand All @@ -64,8 +63,7 @@ public void DrawMiniMap( WormholeLink link, SpriteBatch sb ) {
}

public void DrawOverlayMap( WormholeLink link, SpriteBatch sb ) {
var mymod = WormholesMod.Instance;
if( !link.IsCharted( Main.LocalPlayer ) && !mymod.Config.DebugModeMapCheat ) { return; }
if( !link.IsCharted( Main.LocalPlayer ) && !WormholesConfig.Instance.DebugModeMapCheat ) { return; }

float scale = Main.mapOverlayScale / 1.5f;
Texture2D tex = WormholesUI.Tex;
Expand All @@ -87,8 +85,7 @@ public void DrawOverlayMap( WormholeLink link, SpriteBatch sb ) {
}

public void DrawFullscreenMap( WormholeLink link, SpriteBatch sb ) {
var mymod = WormholesMod.Instance;
if( !link.IsCharted( Main.LocalPlayer ) && !mymod.Config.DebugModeMapCheat ) { return; }
if( !link.IsCharted( Main.LocalPlayer ) && !WormholesConfig.Instance.DebugModeMapCheat ) { return; }

float scale = Main.mapFullscreenScale / 1.5f;
Texture2D tex = WormholesUI.Tex;
Expand Down
Loading

0 comments on commit 4637907

Please sign in to comment.