Skip to content

Commit

Permalink
Merge branch 'develop' into quest-even-group-tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeFZ authored Aug 10, 2023
2 parents a394125 + 640a641 commit 9eda0df
Show file tree
Hide file tree
Showing 6 changed files with 507 additions and 42 deletions.
1 change: 1 addition & 0 deletions DragaliaAPI.Photon.Plugin/DragaliaAPI.Photon.Plugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net461</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<AssemblyVersion>2.1.0</AssemblyVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
50 changes: 40 additions & 10 deletions DragaliaAPI.Photon.Plugin/GluonPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ public override void OnCreateGame(ICreateGameCallInfo info)
/// <param name="info">Event information.</param>
public override void OnJoin(IJoinGameCallInfo info)
{
int currentActorCount = this.PluginHost.GameActors.Count(
x => x.ActorNr != info.ActorNr
);
if (currentActorCount >= 4)
{
this.logger.WarnFormat(
"Player attempted to join game which already had {0} actors",
currentActorCount
);

info.Fail();
return;
}

info.Request.ActorProperties.InitializeViewerId();
this.actorState[info.ActorNr] = new ActorState();

Expand Down Expand Up @@ -180,7 +194,8 @@ public override void OnLeave(ILeaveGameCallInfo info)
)
{
this.logger.InfoFormat(
"Viewer ID {0} left game {1}",
"Actor {0} with viewer ID {1} left game {2}",
info.ActorNr,
viewerId,
this.PluginHost.GameId
);
Expand All @@ -200,6 +215,22 @@ public override void OnLeave(ILeaveGameCallInfo info)
// Prevent duplicate requests by setting a flag.
actorState.RemovedFromRedis = true;
}

if (this.roomState.MinGoToIngameState > 0)
{
int newMinGoToIngameState = this.PluginHost.GameActors
.Where(x => x.ActorNr != info.ActorNr)
.Select(x => x.Properties.GetIntOrDefault(ActorPropertyKeys.GoToIngameState))
.Min();

this.roomState.MinGoToIngameState = newMinGoToIngameState;
this.OnSetGoToIngameState(info);

if (this.actorState.Where(x => x.Key != info.ActorNr).All(x => x.Value.Ready))
{
this.RaiseEvent(Event.StartQuest, new Dictionary<string, string> { });
}
}
}

/// <summary>
Expand Down Expand Up @@ -426,8 +457,6 @@ private void OnActorReady(IRaiseEventCallInfo info)

if (this.actorState.All(x => x.Value.Ready))
{
this.logger.Info("All clients were ready, raising StartQuest");

this.RaiseEvent(Event.StartQuest, new Dictionary<string, string> { });

this.roomState.StartActorCount = this.PluginHost.GameActors.Count;
Expand Down Expand Up @@ -486,8 +515,8 @@ private void OnSetEntryConditions(ISetPropertiesCallInfo info)
/// <remarks>
/// Represents various stages of loading into a quest, during which events/properties need to be raised/set.
/// </remarks>
/// <param name="info">Info from <see cref="BeforeSetProperties(IBeforeSetPropertiesCallInfo)"/>.</param>
private void OnSetGoToIngameState(IBeforeSetPropertiesCallInfo info)
/// <param name="info">Call info.</param>
private void OnSetGoToIngameState(ICallInfo info)
{
this.logger.InfoFormat(
"OnSetGoToIngameState: updating with value {0}",
Expand Down Expand Up @@ -574,8 +603,8 @@ private void SetGoToIngameInfo()
/// <summary>
/// Makes an outgoing request for <see cref="HeroParamData"/> for each player in the room.
/// </summary>
/// <param name="info">Info from <see cref="OnSetProperties(ISetPropertiesCallInfo)"/>.</param>
private void RequestHeroParam(IBeforeSetPropertiesCallInfo info)
/// <param name="info">Call info.</param>
private void RequestHeroParam(ICallInfo info)
{
IEnumerable<ActorInfo> heroParamRequest = this.PluginHost.GameActors.Select(
x =>
Expand Down Expand Up @@ -649,7 +678,7 @@ private void RaisePartyEvent()
/// <param name="roomId">The new room ID.</param>
private void SetRoomId(ICallInfo info, int roomId)
{
this.logger.DebugFormat("Setting room ID to {0}", roomId);
this.logger.InfoFormat("Setting room ID to {0}", roomId);

this.PluginHost.SetProperties(
0,
Expand Down Expand Up @@ -678,7 +707,7 @@ private void SetRoomId(ICallInfo info, int roomId)
/// <param name="visible">The new visibility.</param>
private void SetRoomVisibility(ICallInfo info, bool visible)
{
this.logger.DebugFormat("Setting room visibility to {0}", visible);
this.logger.InfoFormat("Setting room visibility to {0}", visible);

this.PostStateManagerRequest(
VisibleEndpoint,
Expand Down Expand Up @@ -751,9 +780,10 @@ private Dictionary<int, int> GetMemberCountTable()
{
if (
this.PluginHost.GameProperties.TryGetInt(GamePropertyKeys.QuestId, out int questId)
&& QuestHelper.GetDungeonType(questId) == DungeonTypes.Raid
&& QuestHelper.GetIsRaid(questId)
)
{
logger.InfoFormat("GetMemberCountTable: Quest {0} is a raid", questId);
// Everyone uses all of their units in a raid
return this.PluginHost.GameActors.ToDictionary(
x => x.ActorNr,
Expand Down
Loading

0 comments on commit 9eda0df

Please sign in to comment.