Skip to content

Commit

Permalink
v1.8.1
Browse files Browse the repository at this point in the history
* Restructured ModPlayer class a bit
  • Loading branch information
hamstar0 committed Aug 8, 2018
1 parent b6ec662 commit 8d1f18d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 25 deletions.
16 changes: 9 additions & 7 deletions NetProtocols/WormholeRerollProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
namespace Wormholes.NetProtocols {
class WormholeRerollProtocol : PacketProtocol {
public static void ClientRequestReroll( string id ) {
var protocol = new WormholeRerollProtocol {
Id = id
};
var protocol = new WormholeRerollProtocol( id );

protocol.SendToServer( false );
}
Expand All @@ -17,12 +15,16 @@ public static void ClientRequestReroll( string id ) {

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

public string Id;
public string ID;


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

private WormholeUpdateProtocol( PacketProtocolDataConstructorLock ctor_lock ) { }
private WormholeRerollProtocol( PacketProtocolDataConstructorLock ctor_lock ) { }

private WormholeRerollProtocol( string id ) {
this.ID = id;
}

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

Expand All @@ -31,10 +33,10 @@ protected override void ReceiveWithServer( int from_who ) {
var myworld = mymod.GetModWorld<WormholesWorld>();
var mngr = myworld.Wormholes;

var link = mngr.GetLinkById( this.Id );
var link = mngr.GetLinkById( this.ID );
mngr.Reroll( link );

WormholeUpdateProtocol.BroadcastToClients( this.Id );
WormholeUpdateProtocol.BroadcastToClients( this.ID );
}
}
}
2 changes: 1 addition & 1 deletion Projectiles/ChaosBombProjectile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void ScatterTiles( int tile_x, int tile_y, int radius, int scatter_radius
if( !TileHelpers.IsSolid( fro_tile, true, true ) ) { continue; }
if( TileHelpers.IsWire( fro_tile ) ) { continue; }
if( fro_tile.lava() ) { continue; }
if( TileHelpers.IsNotBombable(i, j) ) { continue; }
if( TileHelpers.IsNotVanillaBombable(i, j) ) { continue; }

var tile_data = TileObjectData.GetTileData( fro_tile );
if( tile_data != null && (tile_data.Width > 1 || tile_data.Height > 1) ) { continue; }
Expand Down
82 changes: 65 additions & 17 deletions WormholesPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HamstarHelpers.Components.Network;
using HamstarHelpers.Helpers.PlayerHelpers;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria;
Expand Down Expand Up @@ -40,6 +41,7 @@ public override void clientClone( ModPlayer clone ) {
myclone.HasLoadedTownPortals = this.HasLoadedTownPortals;
}

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

public override void Load( TagCompound tag ) {
var modworld = this.mod.GetModWorld<WormholesWorld>();
Expand Down Expand Up @@ -113,33 +115,78 @@ public override TagCompound Save() {

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

public override void SyncPlayer( int to_who, int from_who, bool new_player ) {
var mymod = (WormholesMod)this.mod;

if( Main.netMode == 2 ) {
if( to_who == -1 && from_who == this.player.whoAmI ) {
this.OnServerConnect();
}
}
}

public override void OnEnterWorld( Player player ) {
if( Main.netMode == 2 ) { return; } // Not server
if( player.whoAmI != this.player.whoAmI ) { return; }

if( player.whoAmI == this.player.whoAmI ) { // Current player
var mymod = (WormholesMod)this.mod;
var modworld = this.mod.GetModWorld<WormholesWorld>();
var mymod = (WormholesMod)this.mod;

if( Main.netMode == 0 ) {
if( !mymod.ConfigJson.LoadFile() ) {
mymod.ConfigJson.SaveFile();
ErrorLogger.Log( "Wormholes config " + WormholesConfigData.ConfigVersion.ToString() + " created (ModPlayer.OnEnterWorld())." );
}

if( modworld.HasCorrectID ) {
this.ReopenTownPortal();
} else {
this.HasLoadedTownPortals = false;
}
}

if( Main.netMode == 1 ) { // Client
PacketProtocol.QuickRequestFromServer<SettingsAndWormholesProtocol>();
} else if( Main.netMode == 0 ) { // Single
modworld.SetupWormholes();
}
if( mymod.Config.DebugModeInfo ) {
bool _;
ErrorLogger.Log( "Wormholes.WormholesPlayer.OnEnterWorld - " + player.name + " joined (" + PlayerIdentityHelpers.GetUniqueId( player, out _ ) + ")" );
}

if( Main.netMode == 0 ) {
this.OnSingleConnect();
}
if( Main.netMode == 1 ) {
this.OnClientConnect();
}
}

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

this.HasEnteredWorld = true;
private void OnLocalConnect() {
var mymod = (WormholesMod)this.mod;
var myworld = this.mod.GetModWorld<WormholesWorld>();

if( myworld.HasCorrectID ) {
this.ReopenTownPortal();
} else {
this.HasLoadedTownPortals = false;
}
}


private void OnSingleConnect() {
var myworld = this.mod.GetModWorld<WormholesWorld>();

this.OnLocalConnect();

myworld.SetupWormholes();

this.HasEnteredWorld = true;
}

private void OnClientConnect() {
this.OnLocalConnect();

PacketProtocol.QuickRequestToServer<SettingsAndWormholesProtocol>();

this.HasEnteredWorld = true;
}

private void OnServerConnect() { }


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

public void ReopenTownPortal() {
var mymod = (WormholesMod)this.mod;
var modworld = this.mod.GetModWorld<WormholesWorld>();
Expand All @@ -153,7 +200,8 @@ public void ReopenTownPortal() {

this.HasLoadedTownPortals = true;
}



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

public override void PreUpdate() {
Expand Down

0 comments on commit 8d1f18d

Please sign in to comment.