Skip to content

Commit

Permalink
v1.8.0 (RC1; untested)
Browse files Browse the repository at this point in the history
* Removed contexts; too complex for what I'm trying to do
* Town portal scrolls now craft in bundles of 5
* Town portal scrolls are consumed when the exit portal is used (e.g. to return back into the caves from home)
  • Loading branch information
hamstar0 committed May 3, 2018
1 parent d40c1ae commit 1808b74
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 94 deletions.
4 changes: 0 additions & 4 deletions API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions API_Call.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
4 changes: 3 additions & 1 deletion Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";


Expand All @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions Items/TownPortalScrollItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WormholesPlayer>( 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();

Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion Projectiles/ChaosBombProjectile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
1 change: 1 addition & 0 deletions Wormholes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<Compile Include="Utils\SpriteAnimator.cs" />
<Compile Include="API.cs" />
<Compile Include="Wormholes\WormholeLink_Interact.cs" />
<Compile Include="Wormholes\WormholeLink_TownPortal.cs" />
<Compile Include="Wormholes\WormholeManager.cs" />
<Compile Include="Wormholes\WormholeLink.cs" />
<Compile Include="WormholesMod.cs" />
Expand Down
6 changes: 3 additions & 3 deletions Wormholes/WormholeLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,16 @@ 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; }

this.LeftPortal.DrawForMe();
this.RightPortal.DrawForMe();

this.LeftPortal.LightFX( ctx );
this.RightPortal.LightFX( ctx );
this.LeftPortal.LightFX();
this.RightPortal.LightFX();
}
}
}
36 changes: 20 additions & 16 deletions Wormholes/WormholeLink_Interact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@

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; }

int side = this.DetectCollision( player.getRect() );

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; }

Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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<WormholesWorld>().Wormholes;
var mngr = mymod.GetModWorld<WormholesWorld>().Wormholes;
mngr.Reroll( this );
} else { // Non-single
WormholeRerollProtocol.ClientRequestReroll( this.ID );
Expand All @@ -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; }
Expand All @@ -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; }
Expand All @@ -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<WormholesPlayer>( ctx.MyMod );
protected virtual void Teleport( Player player, Vector2 dest ) {
var mymod = WormholesMod.Instance;
WormholesPlayer myplayer = player.GetModPlayer<WormholesPlayer>( mymod );

if( myplayer.MyPortal == null || (myplayer.MyPortal != null && this.ID != myplayer.MyPortal.ID) ) {
myplayer.ChartedLinks.Add( this.ID );
}
Expand Down Expand Up @@ -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 );
}
}
Expand Down
21 changes: 21 additions & 0 deletions Wormholes/WormholeLink_TownPortal.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
}
36 changes: 21 additions & 15 deletions Wormholes/WormholeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand All @@ -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 + ")" );
}

Expand All @@ -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 );
}

Expand All @@ -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] );
}
Expand Down Expand Up @@ -248,32 +250,34 @@ 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;
}

bool is_upon_a_portal = false;
bool is_upon_my_portal = false;
int block_countdown = this.BlockPortalCountdown[who];
WormholeLink town_portal = player.GetModPlayer<WormholesPlayer>( ctx.MyMod ).MyPortal;
WormholeLink town_portal = player.GetModPlayer<WormholesPlayer>( 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 ) {
Expand All @@ -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();
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions Wormholes/WormholePortal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 1808b74

Please sign in to comment.