From 0c084c544dfe2b632bdcb42f0c17c93d3a6236ba Mon Sep 17 00:00:00 2001 From: hamstar0 Date: Tue, 18 Dec 2018 03:36:06 -0800 Subject: [PATCH] v1.8.1.2 * Update for MHv4 --- NetProtocols/SettingsAndWormholesProtocol.cs | 8 ++-- NetProtocols/WormholeRerollProtocol.cs | 33 +++++++++---- NetProtocols/WormholeUpdateProtocol.cs | 50 +++++++++++++++----- WormholesPlayer.cs | 3 +- WormholesUI.cs | 12 ++--- build.txt | 4 +- 6 files changed, 76 insertions(+), 34 deletions(-) diff --git a/NetProtocols/SettingsAndWormholesProtocol.cs b/NetProtocols/SettingsAndWormholesProtocol.cs index 177813c..e934aa4 100644 --- a/NetProtocols/SettingsAndWormholesProtocol.cs +++ b/NetProtocols/SettingsAndWormholesProtocol.cs @@ -4,7 +4,7 @@ namespace Wormholes.NetProtocols { - class SettingsAndWormholesProtocol : PacketProtocol { + class SettingsAndWormholesProtocol : PacketProtocolRequestToServer { public WormholesConfigData ModSettings; public string[] Ids; public float[] RightPosX; @@ -16,11 +16,11 @@ class SettingsAndWormholesProtocol : PacketProtocol { //////////////// - private SettingsAndWormholesProtocol( PacketProtocolDataConstructorLock ctor_lock ) { } + protected SettingsAndWormholesProtocol( PacketProtocolDataConstructorLock ctor_lock ) : base( ctor_lock ) { } //////////////// - protected override void SetServerDefaults( int who ) { + protected override void InitializeServerSendData( int who ) { var mymod = WormholesMod.Instance; var modworld = mymod.GetModWorld(); @@ -50,7 +50,7 @@ protected override void SetServerDefaults( int who ) { //////////////// - protected override void ReceiveWithClient() { + protected override void ReceiveReply() { var mymod = WormholesMod.Instance; var myworld = mymod.GetModWorld(); diff --git a/NetProtocols/WormholeRerollProtocol.cs b/NetProtocols/WormholeRerollProtocol.cs index 1c62bb2..8f5201d 100644 --- a/NetProtocols/WormholeRerollProtocol.cs +++ b/NetProtocols/WormholeRerollProtocol.cs @@ -4,9 +4,26 @@ namespace Wormholes.NetProtocols { - class WormholeRerollProtocol : PacketProtocol { + class WormholeRerollProtocol : PacketProtocolSentToEither { + protected class MyFactory : Factory { + public string ID; + + public MyFactory( string id ) { + this.ID = id; + } + + protected override void Initialize( WormholeRerollProtocol data ) { + data.ID = this.ID; + } + } + + + + //////////////// + public static void ClientRequestReroll( string id ) { - var protocol = new WormholeRerollProtocol( id ); + var factory = new MyFactory( id ); + WormholeRerollProtocol protocol = factory.Create(); protocol.SendToServer( false ); } @@ -20,15 +37,15 @@ public static void ClientRequestReroll( string id ) { //////////////// - private WormholeRerollProtocol( PacketProtocolDataConstructorLock ctor_lock ) { } - - private WormholeRerollProtocol( string id ) { - this.ID = id; - } + protected WormholeRerollProtocol( PacketProtocolDataConstructorLock ctor_lock ) : base( ctor_lock ) { } //////////////// - protected override void ReceiveWithServer( int from_who ) { + protected override void ReceiveOnClient() { + throw new System.NotImplementedException(); + } + + protected override void ReceiveOnServer( int from_who ) { var mymod = WormholesMod.Instance; var myworld = mymod.GetModWorld(); var mngr = myworld.Wormholes; diff --git a/NetProtocols/WormholeUpdateProtocol.cs b/NetProtocols/WormholeUpdateProtocol.cs index c3abc3a..9efafd5 100644 --- a/NetProtocols/WormholeUpdateProtocol.cs +++ b/NetProtocols/WormholeUpdateProtocol.cs @@ -5,7 +5,35 @@ namespace Wormholes.NetProtocols { - class WormholeUpdateProtocol : PacketProtocol { + class WormholeUpdateProtocol : PacketProtocolSentToEither { + protected class MyFactory : Factory { + public string Id; + public float RightPosX; + public float RightPosY; + public float LeftPosX; + public float LeftPosY; + + public MyFactory( string id, float r_pos_x, float r_pos_y, float l_pos_x, float l_pos_y ) { + this.Id = id; + this.RightPosX = r_pos_x; + this.RightPosY = r_pos_y; + this.LeftPosX = l_pos_x; + this.LeftPosY = l_pos_y; + } + + protected override void Initialize( WormholeUpdateProtocol data ) { + data.Id = this.Id; + data.RightPosX = this.RightPosX; + data.RightPosY = this.RightPosY; + data.LeftPosX = this.LeftPosX; + data.LeftPosY = this.LeftPosY; + } + } + + + + //////////////// + public static void BroadcastToClients( string id ) { var mymod = WormholesMod.Instance; var myworld = mymod.GetModWorld(); @@ -16,7 +44,9 @@ public static void BroadcastToClients( string id ) { return; } - var protocol = new WormholeUpdateProtocol( id, link.RightPortal.Pos.X, link.RightPortal.Pos.Y, link.LeftPortal.Pos.X, link.LeftPortal.Pos.Y ); + var factory = new MyFactory( id, link.RightPortal.Pos.X, link.RightPortal.Pos.Y, link.LeftPortal.Pos.X, link.LeftPortal.Pos.Y ); + WormholeUpdateProtocol protocol = factory.Create(); + protocol.SendToClient( -1, -1 ); } @@ -32,20 +62,12 @@ public static void BroadcastToClients( string id ) { //////////////// - private WormholeUpdateProtocol( PacketProtocolDataConstructorLock ctor_lock ) { } - - private WormholeUpdateProtocol( string id, float r_pos_x, float r_pos_y, float l_pos_x, float l_pos_y ) { - this.Id = id; - this.RightPosX = r_pos_x; - this.RightPosY = r_pos_y; - this.LeftPosX = l_pos_x; - this.LeftPosY = l_pos_y; - } + protected WormholeUpdateProtocol( PacketProtocolDataConstructorLock ctor_lock ) : base( ctor_lock ) { } //////////////// - protected override void ReceiveWithClient() { + protected override void ReceiveOnClient() { var mymod = WormholesMod.Instance; var myworld = mymod.GetModWorld(); var mngr = mymod.GetModWorld().Wormholes; @@ -56,5 +78,9 @@ protected override void ReceiveWithClient() { var link = mngr.GetLinkById( this.Id ); link.ChangePosition( pos_r, pos_l ); } + + protected override void ReceiveOnServer( int fromWho ) { + throw new System.NotImplementedException(); + } } } diff --git a/WormholesPlayer.cs b/WormholesPlayer.cs index c3038cb..8fa1bb0 100644 --- a/WormholesPlayer.cs +++ b/WormholesPlayer.cs @@ -140,8 +140,7 @@ public override void OnEnterWorld( Player player ) { } if( mymod.Config.DebugModeInfo ) { - bool _; - ErrorLogger.Log( "Wormholes.WormholesPlayer.OnEnterWorld - " + player.name + " joined (" + PlayerIdentityHelpers.GetUniqueId( player, out _ ) + ")" ); + ErrorLogger.Log( "Wormholes.WormholesPlayer.OnEnterWorld - " + player.name + " joined (" + PlayerIdentityHelpers.GetProperUniqueId( player ) + ")" ); } if( Main.netMode == 0 ) { diff --git a/WormholesUI.cs b/WormholesUI.cs index 26f0088..0c83381 100644 --- a/WormholesUI.cs +++ b/WormholesUI.cs @@ -50,13 +50,13 @@ public void DrawMiniMap( WormholeLink link, SpriteBatch sb ) { Rectangle l_rect = new Rectangle( (int)link.LeftPortal.Pos.X, (int)link.LeftPortal.Pos.Y, tex.Width, tex.Height ); Rectangle r_rect = new Rectangle( (int)link.RightPortal.Pos.X, (int)link.RightPortal.Pos.Y, tex.Width, tex.Height ); - Vector2? l_pos = HudMapHelpers.GetMiniMapPosition( l_rect ); + Vector2? l_pos = HudMapHelpers.GetMiniMapScreenPosition( l_rect ).Item1; if( l_pos != null ) { Color l_color = link.LeftPortal.BaseColor * Main.mapMinimapAlpha; sb.Draw( tex, (Vector2)l_pos, this.TexAnim.Frame, l_color, 0f, new Vector2(), scale, SpriteEffects.None, 1f ); } - Vector2? r_pos = HudMapHelpers.GetMiniMapPosition( r_rect ); + Vector2? r_pos = HudMapHelpers.GetMiniMapScreenPosition( r_rect ).Item1; if( r_pos != null ) { Color r_color = link.RightPortal.BaseColor * Main.mapMinimapAlpha; sb.Draw( tex, (Vector2)r_pos, this.TexAnim.Frame, r_color, 0f, new Vector2(), scale, SpriteEffects.None, 1f ); @@ -73,13 +73,13 @@ public void DrawOverlayMap( WormholeLink link, SpriteBatch sb ) { Rectangle l_rect = new Rectangle( (int)link.LeftPortal.Pos.X, (int)link.LeftPortal.Pos.Y, tex.Width, tex.Height ); Rectangle r_rect = new Rectangle( (int)link.RightPortal.Pos.X, (int)link.RightPortal.Pos.Y, tex.Width, tex.Height ); - Vector2? l_pos = HudMapHelpers.GetOverlayMapPosition( l_rect ); + Vector2? l_pos = HudMapHelpers.GetOverlayMapScreenPosition( l_rect ).Item1; if( l_pos != null ) { Color l_color = link.LeftPortal.BaseColor * Main.mapOverlayAlpha; sb.Draw( tex, (Vector2)l_pos, this.TexAnim.Frame, l_color, 0f, new Vector2(), scale, SpriteEffects.None, 1f ); } - Vector2? r_pos = HudMapHelpers.GetOverlayMapPosition( r_rect ); + Vector2? r_pos = HudMapHelpers.GetOverlayMapScreenPosition( r_rect ).Item1; if( r_pos != null ) { Color r_color = link.RightPortal.BaseColor * Main.mapOverlayAlpha; sb.Draw( tex, (Vector2)r_pos, this.TexAnim.Frame, r_color, 0f, new Vector2(), scale, SpriteEffects.None, 1f ); @@ -94,11 +94,11 @@ public void DrawFullscreenMap( WormholeLink link, SpriteBatch sb ) { Texture2D tex = WormholesUI.Tex; Rectangle l_rect = new Rectangle( (int)link.LeftPortal.Pos.X, (int)link.LeftPortal.Pos.Y, tex.Width, tex.Height ); - Vector2 l_pos = HudMapHelpers.GetFullMapPosition( l_rect ); + Vector2 l_pos = HudMapHelpers.GetFullMapScreenPosition( l_rect ).Item1; sb.Draw( tex, l_pos, this.TexAnim.Frame, link.LeftPortal.BaseColor, 0f, new Vector2 { }, scale, SpriteEffects.None, 1f ); Rectangle r_rect = new Rectangle( (int)link.RightPortal.Pos.X, (int)link.RightPortal.Pos.Y, tex.Width, tex.Height ); - Vector2 r_pos = HudMapHelpers.GetFullMapPosition( r_rect ); + Vector2 r_pos = HudMapHelpers.GetFullMapScreenPosition( r_rect ).Item1; sb.Draw( tex, r_pos, this.TexAnim.Frame, link.RightPortal.BaseColor, 0f, new Vector2 { }, scale, SpriteEffects.None, 1f ); } } diff --git a/build.txt b/build.txt index 77f5a3e..1baf179 100644 --- a/build.txt +++ b/build.txt @@ -1,7 +1,7 @@ author = hamstar -version = 1.8.1.1 +version = 1.8.1.2 displayName = Wormholes -modReferences = HamstarHelpers@2.0.3 +modReferences = HamstarHelpers@4.0.0 buildIgnore = *.csproj, *.user, *.bat, obj\*, bin\*, .vs\*, .git\* languageVersion = 6 homepage = https://forums.terraria.org/index.php?threads/wormholes-and-also-scroll-of-town-portal.52701/ \ No newline at end of file