Skip to content

Commit

Permalink
v1.8.1.2
Browse files Browse the repository at this point in the history
* Update for MHv4
  • Loading branch information
hamstar0 committed Dec 18, 2018
1 parent c7606cf commit 0c084c5
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 34 deletions.
8 changes: 4 additions & 4 deletions NetProtocols/SettingsAndWormholesProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


namespace Wormholes.NetProtocols {
class SettingsAndWormholesProtocol : PacketProtocol {
class SettingsAndWormholesProtocol : PacketProtocolRequestToServer {
public WormholesConfigData ModSettings;
public string[] Ids;
public float[] RightPosX;
Expand All @@ -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<WormholesWorld>();

Expand Down Expand Up @@ -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<WormholesWorld>();

Expand Down
33 changes: 25 additions & 8 deletions NetProtocols/WormholeRerollProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,26 @@


namespace Wormholes.NetProtocols {
class WormholeRerollProtocol : PacketProtocol {
class WormholeRerollProtocol : PacketProtocolSentToEither {
protected class MyFactory : Factory<WormholeRerollProtocol> {
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 );
}
Expand All @@ -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<WormholesWorld>();
var mngr = myworld.Wormholes;
Expand Down
50 changes: 38 additions & 12 deletions NetProtocols/WormholeUpdateProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,35 @@


namespace Wormholes.NetProtocols {
class WormholeUpdateProtocol : PacketProtocol {
class WormholeUpdateProtocol : PacketProtocolSentToEither {
protected class MyFactory : Factory<WormholeUpdateProtocol> {
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<WormholesWorld>();
Expand All @@ -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 );
}

Expand All @@ -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<WormholesWorld>();
var mngr = mymod.GetModWorld<WormholesWorld>().Wormholes;
Expand All @@ -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();
}
}
}
3 changes: 1 addition & 2 deletions WormholesPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
12 changes: 6 additions & 6 deletions WormholesUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
}
}
Expand Down
4 changes: 2 additions & 2 deletions build.txt
Original file line number Diff line number Diff line change
@@ -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/

0 comments on commit 0c084c5

Please sign in to comment.