diff --git a/API.cs b/API.cs index 850feb9..f9f3a01 100644 --- a/API.cs +++ b/API.cs @@ -4,10 +4,6 @@ namespace Wormholes { public static partial class WormholesAPI { - public static WormholeModContext GetModContext() { - return WormholesMod.Instance.Context; - } - public static WormholesConfigData GetModSettings() { return WormholesMod.Instance.Config; } diff --git a/API_Call.cs b/API_Call.cs index 7669161..537fd1a 100644 --- a/API_Call.cs +++ b/API_Call.cs @@ -9,8 +9,6 @@ internal static object Call( string call_type, params object[] args ) { Color color; switch( call_type ) { - case "GetModContext": - return WormholesAPI.GetModContext(); case "GetModSettings": return WormholesAPI.GetModSettings(); case "WormholesFinishedSpawning": diff --git a/Config.cs b/Config.cs index ed39e59..f5bf18c 100644 --- a/Config.cs +++ b/Config.cs @@ -4,7 +4,7 @@ namespace Wormholes { public class WormholesConfigData : ConfigurationDataBase { - public static readonly Version ConfigVersion = new Version( 1, 7, 2 ); + public static readonly Version ConfigVersion = new Version( 1, 8, 0 ); public readonly static string ConfigFileName = "Wormholes Config.json"; @@ -23,7 +23,9 @@ public class WormholesConfigData : ConfigurationDataBase { public int HugeWorldPortals = 27; public bool CraftableTownPortalScrolls = true; + public int TownPortalRecipeQuantity = 5; public int TownPortalDuration = 60 * 60; // 1 hour + public bool TownPortalConsumesOnReturn = true; public float WormholeSoundVolume = 0.45f; public float WormholeLightScale = 1.25f; diff --git a/Items/TownPortalScrollItem.cs b/Items/TownPortalScrollItem.cs index 8099e43..ac9bd4a 100644 --- a/Items/TownPortalScrollItem.cs +++ b/Items/TownPortalScrollItem.cs @@ -7,13 +7,13 @@ namespace Wormholes.Items { class TownPortalScrollItem : ModItem { - public static void OpenPortal( WormholesMod mymod, Player player, Vector2 to, Vector2 fro ) { + public static void OpenPortal( WormholesMod mymod, Player player, Vector2 right_pos, Vector2 left_pos ) { WormholesPlayer modplayer = player.GetModPlayer( mymod ); if( modplayer.MyPortal != null ) { modplayer.MyPortal.Close(); } - var link = new WormholeLink( Color.Cyan, to, fro ); + var link = new TownPortalLink( Color.Cyan, right_pos, left_pos ); link.LeftPortal.AnimateOpen(); link.RightPortal.AnimateOpen(); @@ -87,13 +87,15 @@ 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, 3 ); + this.SetResult( moditem, mymod.Config.TownPortalRecipeQuantity ); } public override bool RecipeAvailable() { diff --git a/Projectiles/ChaosBombProjectile.cs b/Projectiles/ChaosBombProjectile.cs index bbff88c..ab67244 100644 --- a/Projectiles/ChaosBombProjectile.cs +++ b/Projectiles/ChaosBombProjectile.cs @@ -62,7 +62,7 @@ public override void AI() { if( link.DetectCollision(rect) != 0 ) { proj.Kill(); if( rand == 0 ) { - link.ApplyChaosHit( mymod.Context ); + link.ApplyChaosHit(); return; } } diff --git a/Wormholes.csproj b/Wormholes.csproj index 0f9f17f..f86ecc9 100644 --- a/Wormholes.csproj +++ b/Wormholes.csproj @@ -63,6 +63,7 @@ + diff --git a/Wormholes/WormholeLink.cs b/Wormholes/WormholeLink.cs index f021280..bf7422f 100644 --- a/Wormholes/WormholeLink.cs +++ b/Wormholes/WormholeLink.cs @@ -282,7 +282,7 @@ public void ChangePosition( Vector2 right_pos, Vector2 left_pos ) { //////////////// - public void DrawForMe( WormholeModContext ctx ) { + public void DrawForMe() { // Clients and single only if( Main.netMode == 2 ) { return; } if( this.IsClosed ) { return; } @@ -290,8 +290,8 @@ public void DrawForMe( WormholeModContext ctx ) { this.LeftPortal.DrawForMe(); this.RightPortal.DrawForMe(); - this.LeftPortal.LightFX( ctx ); - this.RightPortal.LightFX( ctx ); + this.LeftPortal.LightFX(); + this.RightPortal.LightFX(); } } } diff --git a/Wormholes/WormholeLink_Interact.cs b/Wormholes/WormholeLink_Interact.cs index 5beee67..e1226c2 100644 --- a/Wormholes/WormholeLink_Interact.cs +++ b/Wormholes/WormholeLink_Interact.cs @@ -8,7 +8,7 @@ namespace Wormholes { public partial class WormholeLink { - public void UpdateInteractions( WormholeModContext ctx, Player player, bool is_obstructed, out bool is_upon_portal ) { + internal void UpdateInteractions( Player player, bool is_obstructed, out bool is_upon_portal ) { is_upon_portal = false; if( this.IsClosed ) { return; } @@ -16,16 +16,16 @@ public void UpdateInteractions( WormholeModContext ctx, Player player, bool is_o if( !is_obstructed ) { if( side == 1 ) { - this.TeleportToLeft( ctx, player ); + this.TeleportToLeft( player ); } else if( side == -1 ) { - this.TeleportToRight( ctx, player ); + this.TeleportToRight( player ); } } is_upon_portal = side != 0; } - public void UpdateBehavior( WormholeModContext ctx, Player player ) { + internal void UpdateBehavior( Player player ) { if( this.IsClosed ) { return; } if( Main.myPlayer != player.whoAmI ) { return; } @@ -38,8 +38,8 @@ public void UpdateBehavior( WormholeModContext ctx, Player player ) { this.RightPortal.AnimateOpen( l_open_anim ); } - this.LeftPortal.SoundFX( ctx ); - this.RightPortal.SoundFX( ctx ); + this.LeftPortal.SoundFX(); + this.RightPortal.SoundFX(); } } @@ -72,10 +72,12 @@ public int DetectCollision( Rectangle rect ) { return on_portal; } - - public void ApplyChaosHit( WormholeModContext ctx ) { + + public virtual void ApplyChaosHit() { + var mymod = WormholesMod.Instance; + if( Main.netMode == 0 ) { // Single - var mngr = ctx.MyMod.GetModWorld().Wormholes; + var mngr = mymod.GetModWorld().Wormholes; mngr.Reroll( this ); } else { // Non-single WormholeRerollProtocol.ClientRequestReroll( this.ID ); @@ -84,7 +86,7 @@ public void ApplyChaosHit( WormholeModContext ctx ) { //////////////// - public void TeleportToLeft( WormholeModContext ctx, Player player ) { + protected virtual void TeleportToLeft( Player player ) { // Clients and single only if( Main.netMode == 2 ) { return; } if( this.IsClosed ) { return; } @@ -93,10 +95,10 @@ public void TeleportToLeft( WormholeModContext ctx, Player player ) { this.LeftPortal.Pos.X + (WormholePortal.Width / 2) - player.width, this.LeftPortal.Pos.Y + (WormholePortal.Height / 2) - player.height ); - this.Teleport( ctx, player, dest ); + this.Teleport( player, dest ); } - public void TeleportToRight( WormholeModContext ctx, Player player ) { + protected virtual void TeleportToRight( Player player ) { // Clients and single only if( Main.netMode == 2 ) { return; } if( this.IsClosed ) { return; } @@ -105,12 +107,14 @@ public void TeleportToRight( WormholeModContext ctx, Player player ) { this.RightPortal.Pos.X + (WormholePortal.Width / 2) - player.width, this.RightPortal.Pos.Y + (WormholePortal.Height / 2) - player.height ); - this.Teleport( ctx, player, dest ); + this.Teleport( player, dest ); } - private void Teleport( WormholeModContext ctx, Player player, Vector2 dest ) { - WormholesPlayer myplayer = player.GetModPlayer( ctx.MyMod ); + protected virtual void Teleport( Player player, Vector2 dest ) { + var mymod = WormholesMod.Instance; + WormholesPlayer myplayer = player.GetModPlayer( mymod ); + if( myplayer.MyPortal == null || (myplayer.MyPortal != null && this.ID != myplayer.MyPortal.ID) ) { myplayer.ChartedLinks.Add( this.ID ); } @@ -140,7 +144,7 @@ private void Teleport( WormholeModContext ctx, Player player, Vector2 dest ) { } //Main.PlaySound( 2, player.position, 100 ); - var snd = SoundID.Item100.WithVolume( ctx.MyMod.Config.WormholeEntrySoundVolume ); + var snd = SoundID.Item100.WithVolume( mymod.Config.WormholeEntrySoundVolume ); Main.PlaySound( snd, player.position ); } } diff --git a/Wormholes/WormholeLink_TownPortal.cs b/Wormholes/WormholeLink_TownPortal.cs new file mode 100644 index 0000000..6daf787 --- /dev/null +++ b/Wormholes/WormholeLink_TownPortal.cs @@ -0,0 +1,21 @@ +using Microsoft.Xna.Framework; +using Terraria; + + +namespace Wormholes { + public class TownPortalLink : WormholeLink { + public TownPortalLink( Color color, Vector2 left_node_pos, Vector2 right_node_pos ) : + base( color, left_node_pos, right_node_pos ) { } + + + protected override void TeleportToLeft( Player player ) { + base.TeleportToLeft( player ); + + var mymod = WormholesMod.Instance; + + if( mymod.Config.TownPortalConsumesOnReturn ) { + this.Close(); + } + } + } +} diff --git a/Wormholes/WormholeManager.cs b/Wormholes/WormholeManager.cs index 07dbc80..8e2ce20 100644 --- a/Wormholes/WormholeManager.cs +++ b/Wormholes/WormholeManager.cs @@ -54,7 +54,7 @@ public bool Load( WormholesMod mymod, TagCompound tags ) { int holes = tags.GetInt( "wormhole_count" ); if( holes == 0 ) { return false; } - if( mymod.IsDebugInfoMode() ) { + if( mymod.Config.DebugModeInfo ) { LogHelpers.Log( "Loading world ids (" + Main.netMode + "): " + holes ); } @@ -69,7 +69,7 @@ public bool Load( WormholesMod mymod, TagCompound tags ) { } string id = tags.GetString( "wormhole_id_" + i ); - if( mymod.IsDebugInfoMode() ) { + if( mymod.Config.DebugModeInfo ) { LogHelpers.Log( " world load id: " + id + " (" + i + ")" ); } @@ -93,13 +93,14 @@ public bool Load( WormholesMod mymod, TagCompound tags ) { public TagCompound Save() { + var mymod = WormholesMod.Instance; string[] ids = new string[WormholeManager.PortalCount]; int[] worm_l_x = new int[WormholeManager.PortalCount]; int[] worm_l_y = new int[WormholeManager.PortalCount]; int[] worm_r_x = new int[WormholeManager.PortalCount]; int[] worm_r_y = new int[WormholeManager.PortalCount]; - if( WormholesMod.Instance.IsDebugInfoMode() ) { + if( mymod.Config.DebugModeInfo ) { LogHelpers.Log( "Save world ids (" + Main.netMode + "): " + WormholeManager.PortalCount ); } @@ -126,7 +127,8 @@ public TagCompound Save() { for( i = 0; i < this.Links.Count; i++ ) { tags.Set( "wormhole_id_" + i, ids[i] ); - if( WormholesMod.Instance.IsDebugInfoMode() ) { + + if( mymod.Config.DebugModeInfo ) { LogHelpers.Log( " world save id: " + ids[i] + " (" + i + ") = " + worm_l_x[i] + "," + worm_l_y[i] + " | " + worm_r_x[i] + "," + worm_r_y[i] ); } @@ -248,8 +250,10 @@ public void FinishSettingUpWormholes() { ///////////////// - public void RunAll( WormholeModContext ctx, Player player ) { + public void RunAll( Player player ) { + var mymod = WormholesMod.Instance; int who = player.whoAmI; + if( !this.BlockPortalCountdown.Keys.Contains( who ) ) { this.BlockPortalCountdown[who] = 0; } @@ -257,23 +261,23 @@ public void RunAll( WormholeModContext ctx, Player player ) { bool is_upon_a_portal = false; bool is_upon_my_portal = false; int block_countdown = this.BlockPortalCountdown[who]; - WormholeLink town_portal = player.GetModPlayer( ctx.MyMod ).MyPortal; + WormholeLink town_portal = player.GetModPlayer( mymod ).MyPortal; - if( !ctx.MyMod.Config.DisableNaturalWormholes ) { + if( !mymod.Config.DisableNaturalWormholes ) { for( int i = 0; i < this.Links.Count; i++ ) { WormholeLink link = this.Links[i]; if( link == null ) { break; } - link.UpdateInteractions( ctx, player, (block_countdown > 0), out is_upon_a_portal ); - link.UpdateBehavior( ctx, player ); + link.UpdateInteractions( player, (block_countdown > 0), out is_upon_a_portal ); + link.UpdateBehavior( player ); if( is_upon_a_portal ) { break; } } } if( town_portal != null ) { - town_portal.UpdateInteractions( ctx, player, (block_countdown > 0 || is_upon_a_portal), out is_upon_my_portal ); - town_portal.UpdateBehavior( ctx, player ); + town_portal.UpdateInteractions( player, (block_countdown > 0 || is_upon_a_portal), out is_upon_my_portal ); + town_portal.UpdateBehavior( player ); } if( (is_upon_a_portal || is_upon_my_portal) && block_countdown == 0 ) { @@ -284,17 +288,19 @@ public void RunAll( WormholeModContext ctx, Player player ) { } } - public void DrawAll( WormholeModContext ctx, WormholeLink town_portal ) { - if( !ctx.MyMod.Config.DisableNaturalWormholes ) { + public void DrawAll( WormholeLink town_portal ) { + var mymod = WormholesMod.Instance; + + if( !mymod.Config.DisableNaturalWormholes ) { for( int i = 0; i < this.Links.Count; i++ ) { WormholeLink link = this.Links[i]; if( link == null ) { break; } - link.DrawForMe( ctx ); + link.DrawForMe(); } } if( town_portal != null ) { - town_portal.DrawForMe( ctx ); + town_portal.DrawForMe(); } } } diff --git a/Wormholes/WormholePortal.cs b/Wormholes/WormholePortal.cs index 721babb..ec1564e 100644 --- a/Wormholes/WormholePortal.cs +++ b/Wormholes/WormholePortal.cs @@ -133,24 +133,28 @@ public void DrawForMe() { Dust.NewDust( this.Pos, this.Rect.Width, this.Rect.Height, 15, 0, 0, 150, color, 1f ); } - public void SoundFX( WormholeModContext ctx ) { + public void SoundFX() { if( this.IsClosed ) { return; } + var mymod = WormholesMod.Instance; + // Loop audio if( this.SoundLoopTimer++ > 12 ) { - Main.PlaySound( SoundID.Item24.WithVolume( ctx.MyMod.Config.WormholeSoundVolume), this.Pos ); + Main.PlaySound( SoundID.Item24.WithVolume( mymod.Config.WormholeSoundVolume), this.Pos ); this.SoundLoopTimer = 0; } } - public void LightFX( WormholeModContext ctx ) { + 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 flicker_scale = 0.5f + ctx.MyMod.Config.WormholeLightScale * Main.rand.NextFloat(); + float flicker_scale = 0.5f + mymod.Config.WormholeLightScale * Main.rand.NextFloat(); float r = flicker_scale * this.BaseColor.R / 255f; float g = flicker_scale * this.BaseColor.G / 255f; float b = flicker_scale * this.BaseColor.B / 255f; diff --git a/WormholesMod.cs b/WormholesMod.cs index 0ed4fdb..400ef15 100644 --- a/WormholesMod.cs +++ b/WormholesMod.cs @@ -8,13 +8,6 @@ namespace Wormholes { - public class WormholeModContext { - internal WormholesMod MyMod; - internal WormholeModContext( WormholesMod mymod ) { this.MyMod = mymod; } - } - - - class WormholesMod : Mod { public static WormholesMod Instance { get; private set; } @@ -33,9 +26,7 @@ public static void ReloadConfigFromFile() { //////////////// - - public WormholeModContext Context { get; private set; } - + public JsonConfig JsonConfig { get; private set; } public WormholesConfigData Config { get { return this.JsonConfig.Data; } } @@ -45,8 +36,6 @@ public static void ReloadConfigFromFile() { //////////////// public WormholesMod() : base() { - this.Context = new WormholeModContext( this ); - this.Properties = new ModProperties() { Autoload = true, AutoloadGores = true, @@ -176,9 +165,9 @@ private void DrawMiniMap( SpriteBatch sb ) { if( link == null ) { break; } if( Main.mapStyle == 1 ) { - this.UI.DrawMiniMap( this.Context, link, sb ); + this.UI.DrawMiniMap( link, sb ); } else { - this.UI.DrawOverlayMap( this.Context, link, sb ); + this.UI.DrawOverlayMap( link, sb ); } } } @@ -186,9 +175,9 @@ private void DrawMiniMap( SpriteBatch sb ) { if( curr_modplayer.MyPortal != null ) { if( Main.mapStyle == 1 ) { - this.UI.DrawMiniMap( this.Context, curr_modplayer.MyPortal, sb ); + this.UI.DrawMiniMap( curr_modplayer.MyPortal, sb ); } else { - this.UI.DrawOverlayMap( this.Context, curr_modplayer.MyPortal, sb ); + this.UI.DrawOverlayMap( curr_modplayer.MyPortal, sb ); } } } @@ -206,29 +195,14 @@ private void DrawFullMap( SpriteBatch sb ) { WormholeLink link = modworld.Wormholes.Links[i]; if( link == null ) { break; } - this.UI.DrawFullscreenMap( this.Context, link, sb ); + this.UI.DrawFullscreenMap( link, sb ); } } } if( curr_modplayer.MyPortal != null ) { - this.UI.DrawFullscreenMap( this.Context, curr_modplayer.MyPortal, sb ); + this.UI.DrawFullscreenMap( curr_modplayer.MyPortal, sb ); } } - - - //////////////// - - public bool IsDebugInfoMode() { - return this.Config.DebugModeInfo; - } - - public bool IsDebugWormholeViewMode() { - return this.Config.DebugModeMapCheat; - } - - public bool IsDebuResetMode() { - return this.Config.DebugModeReset; - } } } diff --git a/WormholesPlayer.cs b/WormholesPlayer.cs index a1d9837..753cde2 100644 --- a/WormholesPlayer.cs +++ b/WormholesPlayer.cs @@ -7,9 +7,10 @@ using Wormholes.Items; using Wormholes.NetProtocols; + namespace Wormholes { class WormholesPlayer : ModPlayer { - public WormholeLink MyPortal; + public WormholeLink MyPortal { get; internal set; } public ISet ChartedLinks { get; private set; } private IDictionary TownPortalRightPositions = new Dictionary(); @@ -160,7 +161,7 @@ public override void PreUpdate() { WormholesWorld modworld = mymod.GetModWorld(); if( modworld.Wormholes == null ) { return; } - modworld.Wormholes.RunAll( mymod.Context, this.player ); + modworld.Wormholes.RunAll( this.player ); } } } diff --git a/WormholesUI.cs b/WormholesUI.cs index e97f4cd..247f49b 100644 --- a/WormholesUI.cs +++ b/WormholesUI.cs @@ -40,9 +40,9 @@ public void Update() { //////////////// - public void DrawMiniMap( WormholeModContext ctx, WormholeLink link, SpriteBatch sb ) { - var mymod = ctx.MyMod; - if( !link.IsCharted( Main.LocalPlayer ) && !mymod.IsDebugWormholeViewMode() ) { return; } + public void DrawMiniMap( WormholeLink link, SpriteBatch sb ) { + var mymod = WormholesMod.Instance; + if( !link.IsCharted( Main.LocalPlayer ) && !mymod.Config.DebugModeMapCheat ) { return; } float scale = Main.mapMinimapScale / 1.5f; Texture2D tex = WormholesUI.Tex; @@ -63,9 +63,9 @@ public void DrawMiniMap( WormholeModContext ctx, WormholeLink link, SpriteBatch } } - public void DrawOverlayMap( WormholeModContext ctx, WormholeLink link, SpriteBatch sb ) { - var mymod = ctx.MyMod; - if( !link.IsCharted( Main.LocalPlayer ) && !mymod.IsDebugWormholeViewMode() ) { return; } + public void DrawOverlayMap( WormholeLink link, SpriteBatch sb ) { + var mymod = WormholesMod.Instance; + if( !link.IsCharted( Main.LocalPlayer ) && !mymod.Config.DebugModeMapCheat ) { return; } float scale = Main.mapOverlayScale / 1.5f; Texture2D tex = WormholesUI.Tex; @@ -86,9 +86,9 @@ public void DrawOverlayMap( WormholeModContext ctx, WormholeLink link, SpriteBat } } - public void DrawFullscreenMap( WormholeModContext ctx, WormholeLink link, SpriteBatch sb ) { - var mymod = ctx.MyMod; - if( !link.IsCharted( Main.LocalPlayer ) && !mymod.IsDebugWormholeViewMode() ) { return; } + public void DrawFullscreenMap( WormholeLink link, SpriteBatch sb ) { + var mymod = WormholesMod.Instance; + if( !link.IsCharted( Main.LocalPlayer ) && !mymod.Config.DebugModeMapCheat ) { return; } float scale = Main.mapFullscreenScale / 1.5f; Texture2D tex = WormholesUI.Tex; diff --git a/WormholesWorld.cs b/WormholesWorld.cs index 21c38f8..4293322 100644 --- a/WormholesWorld.cs +++ b/WormholesWorld.cs @@ -101,7 +101,7 @@ public override void PostDrawTiles() { Main.spriteBatch.Begin( SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, rasterizer, (Effect)null, Main.GameViewMatrix.TransformationMatrix ); try { - this.Wormholes.DrawAll( mymod.Context, myplayer.MyPortal ); + this.Wormholes.DrawAll( myplayer.MyPortal ); } catch( Exception e ) { ErrorLogger.Log( "PostDrawTiles: " + e.ToString() ); throw e;