Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AscensionGameDev/Intersect-Engine#810 - Introduce option to fade between warps #811

Closed
wants to merge 9 commits into from
Expand Up @@ -593,6 +593,7 @@ public class WarpCommand : EventCommand

public WarpDirection Direction { get; set; } = WarpDirection.Retain;

public bool FadeOnWarp { get; set; } = false;
}

public class SetMoveRouteCommand : EventCommand
Expand Down
4 changes: 3 additions & 1 deletion Intersect (Core)/GameObjects/Maps/MapAttribute.cs
Expand Up @@ -123,14 +123,16 @@ public class MapWarpAttribute : MapAttribute

public WarpDirection Direction { get; set; } = WarpDirection.Retain;

public bool FadeOnWarp { get; set; } = false;

public override MapAttribute Clone()
{
var att = (MapWarpAttribute) base.Clone();
att.MapId = MapId;
att.X = X;
att.Y = Y;
att.Direction = Direction;

att.FadeOnWarp = FadeOnWarp;
return att;
}

Expand Down
3 changes: 3 additions & 0 deletions Intersect (Core)/Intersect (Core).csproj
Expand Up @@ -384,6 +384,7 @@
<Compile Include="Network\Packets\Client\EnterGamePacket.cs" />
<Compile Include="Network\Packets\Client\EventInputVariablePacket.cs" />
<Compile Include="Network\Packets\Client\EventResponsePacket.cs" />
<Compile Include="Network\Packets\Client\MapTransitionReadyPacket.cs" />
<Compile Include="Network\Packets\Client\ForgetSpellPacket.cs" />
<Compile Include="Network\Packets\Client\FriendRequestResponsePacket.cs" />
<Compile Include="Network\Packets\Client\GuildInviteAcceptPacket.cs" />
Expand All @@ -397,6 +398,7 @@
<Compile Include="Network\Packets\Client\PictureClosedPacket.cs" />
<Compile Include="Network\Packets\Server\ActionMsgPackets.cs" />
<Compile Include="Network\Packets\Server\EntityMovementPackets.cs" />
<Compile Include="Network\Packets\Server\MapFadePacket.cs" />
<Compile Include="Network\Packets\Server\GuildInvitePacket.cs" />
<Compile Include="Network\Packets\Server\GuildPacket.cs" />
<Compile Include="Network\Packets\Server\MapEntityStatusPacket.cs" />
Expand All @@ -405,6 +407,7 @@
<Compile Include="Network\Packets\Server\AnnouncementPacket.cs" />
<Compile Include="Network\Packets\Server\CancelCastPacket.cs" />
<Compile Include="Network\Packets\Server\PlayAnimationPackets.cs" />
<Compile Include="Network\Packets\Server\UpdateFutureWarpPacket.cs" />
<Compile Include="Network\Packets\SlotQuantityPacket.cs" />
<Compile Include="Network\Packets\Client\SwapBankItemsPacket.cs" />
<Compile Include="Network\Packets\Client\MovePacket.cs" />
Expand Down
@@ -0,0 +1,28 @@
using MessagePack;

namespace Intersect.Network.Packets.Client
{
[MessagePackObject]
public class MapTransitionReadyPacket : IntersectPacket
{
public MapTransitionReadyPacket(System.Guid mapId, float x, float y, byte dir)
{
NewMapId = mapId;
X = x;
Y = y;
Dir = dir;
}

[Key(0)]
public System.Guid NewMapId { get; set; }

[Key(1)]
public float X { get; set; }

[Key(2)]
public float Y { get; set; }

[Key(3)]
public byte Dir { get; set; }
}
}
27 changes: 27 additions & 0 deletions Intersect (Core)/Network/Packets/Server/MapFadePacket.cs
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using MessagePack;

namespace Intersect.Network.Packets.Server
{
[MessagePackObject]
public class MapFadePacket : IntersectPacket
{
public MapFadePacket()
{
FadeIn = false;
}

public MapFadePacket(bool fadeIn)
{
FadeIn = fadeIn;
}

[Key(0)]
public bool FadeIn { get; set; }
}
}
28 changes: 28 additions & 0 deletions Intersect (Core)/Network/Packets/Server/UpdateFutureWarpPacket.cs
@@ -0,0 +1,28 @@
using MessagePack;

namespace Intersect.Network.Packets.Server
{
[MessagePackObject]
public class UpdateFutureWarpPacket : IntersectPacket
{
public UpdateFutureWarpPacket(System.Guid mapId, float x, float y, byte dir)
{
NewMapId = mapId;
X = x;
Y = y;
Dir = dir;
}

[Key(0)]
public System.Guid NewMapId { get; set; }

[Key(1)]
public float X { get; set; }

[Key(2)]
public float Y { get; set; }

[Key(3)]
public byte Dir { get; set; }
}
}
18 changes: 16 additions & 2 deletions Intersect.Client/Core/Fade.cs
Expand Up @@ -5,6 +5,8 @@ namespace Intersect.Client.Core

public static class Fade
{
private const float STANDARD_FADE_RATE = 3000f;
private const float FAST_FADE_RATE = 800f;

public enum FadeType
{
Expand All @@ -25,18 +27,25 @@ public enum FadeType

private static long sLastUpdate;

public static void FadeIn()
private static bool sAlertServerWhenFaded;

public static void FadeIn(bool fast = false)
{
sFadeRate = fast ? FAST_FADE_RATE : STANDARD_FADE_RATE;

sCurrentAction = FadeType.In;
sFadeAmt = 255f;
sLastUpdate = Globals.System.GetTimeMs();
}

public static void FadeOut()
public static void FadeOut(bool alertServerWhenFaded = false, bool fast = false)
{
sFadeRate = fast ? FAST_FADE_RATE : STANDARD_FADE_RATE;

sCurrentAction = FadeType.Out;
sFadeAmt = 0f;
sLastUpdate = Globals.System.GetTimeMs();
sAlertServerWhenFaded = alertServerWhenFaded;
}

public static bool DoneFading()
Expand Down Expand Up @@ -66,6 +75,11 @@ public static void Update()
if (sFadeAmt >= 255f)
{
sCurrentAction = FadeType.None;
if (sAlertServerWhenFaded)
{
Networking.PacketSender.SendMapTransitionReady(Globals.futureWarpMapId, Globals.futureWarpX, Globals.futureWarpY, Globals.futureWarpDir);
}
sAlertServerWhenFaded = false;
sFadeAmt = 255f;
}
}
Expand Down
6 changes: 6 additions & 0 deletions Intersect.Client/Entities/Player.cs
Expand Up @@ -1641,6 +1641,12 @@ private void ProcessDirectionalInput()
return;
}

// Check if the player is currently transitioning between maps with a fade
if (Globals.InMapTransition == true)
{
return;
}

//check if player is stunned or snared, if so don't let them move.
for (var n = 0; n < Status.Count; n++)
{
Expand Down
11 changes: 11 additions & 0 deletions Intersect.Client/General/Globals.cs
Expand Up @@ -151,6 +151,17 @@ public static GameStates GameState
//Scene management
public static bool WaitingOnServer = false;

public static bool InMapTransition = false;

// Used for when a warp is using a transition - we want to transition them AFTER the client has "faded out"
public static Guid futureWarpMapId;

public static float futureWarpX;

public static float futureWarpY;

public static byte futureWarpDir;

public static Entity GetEntity(Guid id, EntityTypes type)
{
if (Entities.ContainsKey(id))
Expand Down
25 changes: 25 additions & 0 deletions Intersect.Client/Networking/PacketHandler.cs
Expand Up @@ -2045,6 +2045,31 @@ public void HandlePacket(IPacketSender packetSender, GuildInvitePacket packet)
);
}

// Map fading in/out packet
public void HandlePacket(IPacketSender packetSender, MapFadePacket packet)
{
if (packet.FadeIn)
{
if (Fade.GetFade() > 0)
{
Fade.FadeIn(true);
}
Globals.InMapTransition = false;
} else
{
Fade.FadeOut(true, true);
Globals.InMapTransition = true;
}
}

// Update future warp position packet
public void HandlePacket(IPacketSender packetSender, UpdateFutureWarpPacket packet)
{
Globals.futureWarpMapId = packet.NewMapId;
Globals.futureWarpX = packet.X;
Globals.futureWarpY = packet.Y;
Globals.futureWarpDir = packet.Dir;
}
}

}
4 changes: 4 additions & 0 deletions Intersect.Client/Networking/PacketSender.cs
Expand Up @@ -425,6 +425,10 @@ public static void SendClosePicture(Guid eventId)
}
}

public static void SendMapTransitionReady(Guid newMapId, float x, float y, byte dir)
{
Network.SendPacket(new MapTransitionReadyPacket(newMapId, x, y, dir));
}
}

}