Skip to content

Commit

Permalink
Plugin retry fixes and refactoring (#377)
Browse files Browse the repository at this point in the history
- Closes #244, a.k.a. [Golden Experience
Requiem](https://www.youtube.com/watch?v=r_mfpy2ZyQQ) bug by returning
players to the lobby when retrying after at least one player has given
up.
- Retries when failing a quest are still a bit glitchy -- it's supposed
to remove players who voted no and allow players who voted yes to
optionally rejoin the room similar to the prompt on a successful clear.
Currently any retry where all players are dead will go back to the
lobby. #378 raised to track.

Plugin refactoring:
- Remove HeroParam and other custom actor properties and persist this
state in the plugin class, since only the plugin needs to know about
these. It's tidier and avoids Photon having to serialize them (and
crashing in the case of HeroParam since we didn't register this type).
- Use enums for event codes.
- Improve logging and add info logs which can provide basic diagnostics,
particularly around potential problem areas such as GoToIngameState
  • Loading branch information
SapiensAnatis authored Aug 9, 2023
1 parent 388cb94 commit 863d732
Show file tree
Hide file tree
Showing 11 changed files with 330 additions and 218 deletions.
13 changes: 0 additions & 13 deletions DragaliaAPI.Photon.Plugin/Constants/ActorPropertyKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ namespace DragaliaAPI.Photon.Plugin.Constants
/// <summary>
/// Actor property keys.
/// </summary>
/// <remarks>
/// The PLUGIN_ prefix denotes properties that are used for plugin logic and not by the game.
/// </remarks>
public class ActorPropertyKeys
{
public const string PlayerId = "PlayerId";
Expand All @@ -21,15 +18,5 @@ public class ActorPropertyKeys
public const string UsePartySlot = "UsePartySlot";

public const string GoToIngameState = "GoToIngameState";

public const string StartQuest = "PLUGIN_StartQuest";

public const string RemovedFromRedis = "PLUGIN_RemovedFromRedis";

public const string HeroParam = "PLUGIN_HeroParam";

public const string HeroParamCount = "PLUGIN_HeroParamCount";

public const string MemberCount = "PLUGIN_MemberCount";
}
}
45 changes: 0 additions & 45 deletions DragaliaAPI.Photon.Plugin/Constants/Event.cs

This file was deleted.

63 changes: 63 additions & 0 deletions DragaliaAPI.Photon.Plugin/Event.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace DragaliaAPI.Photon.Plugin
{
/// <summary>
/// Dragalia Lost event codes.
/// </summary>
public enum Event : byte
{
/// <summary>
/// Event sent by clients when it has finished loading.
/// </summary>
Ready = 0x3,

/// <summary>
/// Event sent by the server containing other player's loadout information.
/// </summary>
CharacterData = 0x14,

/// <summary>
/// Event sent by the server when players should be allowed to start moving.
/// </summary>
StartQuest = 0x15,

/// <summary>
/// Event sent by the server when the room should be destroyed.
/// </summary>
RoomBroken = 0x17,

/// <summary>
/// Event sent by clients and the server when re-using a room.
/// </summary>
GameSucceed = 0x18,

/// <summary>
/// Event sent by the server containing information about how many units each player will control.
/// </summary>
Party = 0x3e,

/// <summary>
/// Event sent by clients when clearing a quest successfully.
/// </summary>
ClearQuestRequest = 0x3f,

/// <summary>
/// Event sent by the server after forwarding a <see cref="ClearQuestRequest"/> event.
/// </summary>
ClearQuestResponse = 0x40,

/// <summary>
/// Event sent by clients when failing/retrying a quest.
/// </summary>
FailQuestRequest = 0x43,

/// <summary>
/// Event sent by the server after acknowledging a <see cref="FailQuestRequest"/> event.
/// </summary>
FailQuestResponse = 0x44,

/// <summary>
/// Event sent by clients when their character dies.
/// </summary>
Dead = 0x48,
}
}
29 changes: 13 additions & 16 deletions DragaliaAPI.Photon.Plugin/GluonPlugin.Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,40 @@ namespace DragaliaAPI.Photon.Plugin
/// </summary>
public partial class GluonPlugin
{
private const int EventDataKey = 245;
private const int EventActorNrKey = 254;

/// <summary>
/// Helper method to raise events.
/// </summary>
/// <param name="eventCode">The event code to raise.</param>
/// <param name="eventData">The event data.</param>
/// <param name="target">The actor to target -- if null, all actors will be targeted.</param>
public void RaiseEvent(byte eventCode, object eventData, int? target = null)
public void RaiseEvent(Event eventCode, object eventData, int? target = null)
{
byte[] serializedEvent = MessagePackSerializer.Serialize(
eventData,
MessagePackSerializerOptions.Standard.WithCompression(
MessagePackCompression.Lz4Block
)
);
byte[] serializedEvent = MessagePackSerializer.Serialize(eventData, MessagePackOptions);
Dictionary<byte, object> props = new Dictionary<byte, object>()
{
{ 245, serializedEvent },
{ 254, 0 } // Server actor number
{ EventDataKey, serializedEvent },
{ EventActorNrKey, 0 }
};

this.logger.DebugFormat(
"Raising event 0x{0} with data {1}",
eventCode.ToString("X"),
JsonConvert.SerializeObject(eventData)
);
this.logger.InfoFormat("Raising event {0} (0x{1})", eventCode, eventCode.ToString("X"));
#if DEBUG
this.logger.DebugFormat("Event data: {0}", JsonConvert.SerializeObject(eventData));
#endif

if (target is null)
{
this.BroadcastEvent(eventCode, props);
this.BroadcastEvent((byte)eventCode, props);
}
else
{
this.logger.DebugFormat("Event will target actor {0}", target);
this.PluginHost.BroadcastEvent(
new List<int>() { target.Value },
0,
eventCode,
(byte)eventCode,
props,
CacheOperations.DoNotCache
);
Expand Down
Loading

0 comments on commit 863d732

Please sign in to comment.