Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 46 additions & 15 deletions src/GameLogic/MiniGames/IllusionTempleContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="IllusionTempleContext.cs" company="MUnique">
// <copyright file="IllusionTempleContext.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

Expand All @@ -9,6 +9,7 @@ namespace MUnique.OpenMU.GameLogic.MiniGames;
using MUnique.OpenMU.DataModel.Configuration.Items;
using MUnique.OpenMU.GameLogic.Attributes;
using MUnique.OpenMU.GameLogic.NPC;
using MUnique.OpenMU.GameLogic.Views;
using MUnique.OpenMU.GameLogic.Views.Inventory;
using MUnique.OpenMU.Pathfinding;

Expand Down Expand Up @@ -71,7 +72,7 @@ public sealed class IllusionTempleContext : MiniGameContext
/// <summary>
/// The highest NPC number of the roaming "Illusion Sorc. Spirit" arena monsters, across all temples.
/// </summary>
private const short ArenaMonsterRangeEnd = 399;
private const short ArenaMonsterRangeEnd = 403;

/// <summary>
/// The skill points a player starts a match with.
Expand Down Expand Up @@ -356,7 +357,7 @@ public async ValueTask TalkToNpcStoneStatueAsync(Player player)
}

await this.ForEachPlayerAsync(p => p.InvokeViewPlugInAsync<IIllusionTempleHolyItemRelicsViewPlugIn>(
vp => vp.ShowHolyItemRelicsAsync(player.Id, player.Name)).AsTask()).ConfigureAwait(false);
vp => vp.ShowHolyItemRelicsAsync(player.GetId(p), player.Name)).AsTask()).ConfigureAwait(false);
}
catch
{
Expand Down Expand Up @@ -457,11 +458,12 @@ public async ValueTask UseSkillAsync(Player player, ushort skillNumber, ushort t
if (this._skillPoints.GetValueOrDefault(player, InitialSkillPoints) < SkillCost(skillNumber))
{
await player.InvokeViewPlugInAsync<IIllusionTempleSkillUsageResultViewPlugin>(
p => p.ShowSkillUsageResultAsync(false, skillNumber, player.Id, targetObjectIndex)).ConfigureAwait(false);
p => p.ShowSkillUsageResultAsync(false, skillNumber, player.GetId(player), targetObjectIndex)).ConfigureAwait(false);
return;
}

var target = player.CurrentMap?.GetObject(targetObjectIndex) as IAttackable;
// The client names itself by the constant player id, not by the id of its player on this map.
var target = player.GetObject(targetObjectIndex) as IAttackable;
var success = skillNumber switch
{
OrderOfProtectionSkillNumber => await this.UseOrderOfProtectionAsync(player).ConfigureAwait(false),
Expand All @@ -477,7 +479,7 @@ await player.InvokeViewPlugInAsync<IIllusionTempleSkillUsageResultViewPlugin>(
}

await player.InvokeViewPlugInAsync<IIllusionTempleSkillUsageResultViewPlugin>(
p => p.ShowSkillUsageResultAsync(success, skillNumber, player.Id, target?.Id ?? 0)).ConfigureAwait(false);
p => p.ShowSkillUsageResultAsync(success, skillNumber, player.GetId(player), target?.GetId(player) ?? 0)).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -575,8 +577,8 @@ protected override async ValueTask OnGameStartAsync(ICollection<Player> players)
await base.OnGameStartAsync(players).ConfigureAwait(false);

// The client keeps its event interface closed and the arena barriers up until it's told that
// the battle started - the barrier areas are hardcoded at client side, so this is the only way
// to open them. The two states are deliberately separated by a short delay, so the players
// the battle started - that's the only way to open them at client side (the server's terrain is
// opened by OpenArenaBarriers at the same time). The two states are deliberately separated by a short delay, so the players
// actually get to see the preparation phase before the barriers drop - sending both back to
// back made the client skip straight to the battle without any noticeable wait.
var templeNumber = (byte)this.Definition.GameLevel;
Expand All @@ -594,6 +596,8 @@ await this.ForEachPlayerAsync(player => player.InvokeViewPlugInAsync<IIllusionTe
return;
}

// Opened before the clients are told, so a player who walks off right away isn't set back.
this.OpenArenaBarriers();
await this.ForEachPlayerAsync(player => player.InvokeViewPlugInAsync<IIllusionTempleEventStateViewPlugIn>(
p => p.ChangeEventStateAsync(templeNumber, IllusionTempleEventStatus.BattleStarted)).AsTask()).ConfigureAwait(false);
await this.ShowGoldenMessageAsync(nameof(PlayerMessage.IllusionTempleBattleStartedMessage)).ConfigureAwait(false);
Expand Down Expand Up @@ -644,7 +648,7 @@ protected override async void OnPlayerDied(object? sender, DeathInformation e)

/// <inheritdoc />
/// <remarks>
/// Killing one of the roaming "Illusion Sorc. Spirit" arena monsters (386 to 399) grants the killer
/// Killing one of the roaming "Illusion Sorc. Spirit" arena monsters (386 to 403) grants the killer
/// skill points for the event's special skills.
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "Catching all Exceptions.")]
Expand Down Expand Up @@ -682,7 +686,9 @@ protected override async void OnMonsterDied(object? sender, DeathInformation e)
/// warps and leave the player on two maps with duplicate map-change packets. Leaving the event is
/// handled by <see cref="ClaimRewardAsync"/> and by the base class's exit handling, both of which
/// respect the map's configured safezone. If fewer than <see cref="MinimumPlayerCount"/> players
/// remain afterwards, the match can't continue and is ended right away.
/// remain afterwards while the match is running, it can't continue and is ended right away. Before the
/// start that's not checked here: a player may leave the waiting room again, and the others can still
/// come in. If too few players are left at the start, the event isn't started.
/// </remarks>
protected override async ValueTask OnObjectRemovedFromMapAsync((GameMap Map, ILocateable Object) args)
{
Expand All @@ -702,7 +708,7 @@ protected override async ValueTask OnObjectRemovedFromMapAsync((GameMap Map, ILo

await base.OnObjectRemovedFromMapAsync(args).ConfigureAwait(false);

if (args.Object is Player && this.PlayerCount < this.MinimumPlayerCount)
if (args.Object is Player && this.State == MiniGameState.Playing && this.PlayerCount < this.MinimumPlayerCount)
{
this.FinishEvent();
}
Expand Down Expand Up @@ -754,7 +760,7 @@ protected async override ValueTask OnPlayerPickedUpItemAsync((Player Picker, ILo
// The client needs to be told who the new carrier is - otherwise it keeps showing the
// previous one (or nobody) as the hero on its mini map.
await this.ForEachPlayerAsync(p => p.InvokeViewPlugInAsync<IIllusionTempleHolyItemRelicsViewPlugIn>(
vp => vp.ShowHolyItemRelicsAsync(args.Picker.Id, args.Picker.Name)).AsTask()).ConfigureAwait(false);
vp => vp.ShowHolyItemRelicsAsync(args.Picker.GetId(p), args.Picker.Name)).AsTask()).ConfigureAwait(false);
}
}

Expand Down Expand Up @@ -1069,7 +1075,7 @@ private void NotifyWhenSkillEffectEnds(MagicEffect magicEffect, ushort skillNumb
{
magicEffect.EffectTimeOut += _ => this.ForEachPlayerAsync(
p => p.InvokeViewPlugInAsync<IIllusionTempleSkillEndedViewPlugin>(
view => view.ShowSkillEndedAsync(skillNumber, affectedObject.Id)).AsTask());
view => view.ShowSkillEndedAsync(skillNumber, affectedObject.GetId(p))).AsTask());
}

/// <summary>
Expand All @@ -1094,6 +1100,31 @@ private async ValueTask RemoveRelicFromInventoryAsync(Player player)
await player.InvokeViewPlugInAsync<IItemDropResultPlugIn>(p => p.ItemDropResultAsync(relicItem.ItemSlot, true)).ConfigureAwait(false);
}

/// <summary>
/// Opens the barriers between the bases of the teams and the arena on the server's terrain.
/// </summary>
/// <remarks>
/// The barriers are the water tiles of the temple map. The client opens its own copy when it's told that
/// the battle started, by clearing every water tile of the map; the server does the same, so that both
/// agree on the configured terrain. Until then the tiles aren't walkable, and every step into the arena
/// is set back. They aren't closed again: the map belongs to this game and is discarded with it.
/// </remarks>
private void OpenArenaBarriers()
{
var terrain = this.Map.Terrain;
var attributes = terrain.AttributeMap;
for (var x = 0; x < attributes.GetLength(0); x++)
{
for (var y = 0; y < attributes.GetLength(1); y++)
{
if ((attributes[x, y] & (byte)TerrainAttributeType.Water) != 0)
{
terrain.ApplyTerrainAttribute((byte)x, (byte)y, TerrainAttributeType.Water, false);
}
}
}
}

/// <summary>
/// Moves a player to his team's starting chamber.
/// </summary>
Expand Down Expand Up @@ -1159,14 +1190,14 @@ private ValueTask UpdateStateAsync(Player player)
var teamMembers = this._teams
.Where(entry => entry.Value == ownTeam && entry.Key != player)
.Select(entry => (
PlayerId: entry.Key.Id,
PlayerId: entry.Key.GetId(player),
MapNumber: (byte)(entry.Key.CurrentMap?.Definition.Number ?? 0),
PositionX: entry.Key.Position.X,
PositionY: entry.Key.Position.Y))
.ToList();

(ushort PlayerId, byte PositionX, byte PositionY)? relicCarrier = this._relicCarrier is { } carrier
? (carrier.Id, carrier.Position.X, carrier.Position.Y)
? (carrier.GetId(player), carrier.Position.X, carrier.Position.Y)
: null;

return player.InvokeViewPlugInAsync<IIllusionTempleStateViewPlugin>(
Expand Down
4 changes: 2 additions & 2 deletions src/GameLogic/MiniGames/Kanturu/KanturuContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ public KanturuContext(
/// Tower entrants spawn at the tower entry instead of the event start.
/// </summary>
/// <param name="player">The player which enters.</param>
/// <returns>The tower entry point, or <c>null</c> to keep the warp target.</returns>
/// <returns>The tower entry point, or the one of the base class.</returns>
internal override Point? GetEntrySpawnPosition(Player player)
{
if (this.TowerMode || this.CurrentKanturuState == KanturuState.Tower)
{
return this.TowerEntryPoint;
}

return null;
return base.GetEntrySpawnPosition(player);
}

/// <inheritdoc/>
Expand Down
20 changes: 19 additions & 1 deletion src/GameLogic/MiniGames/MiniGameContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,25 @@ internal async ValueTask<bool> TryRejoinAsync(Player player)
/// </summary>
/// <param name="player">The player which enters.</param>
/// <returns>The spawn position, or <c>null</c> to keep the warp target.</returns>
internal virtual Point? GetEntrySpawnPosition(Player player) => null;
/// <remarks>
/// The warp picks a random tile of the entrance gate without looking at the terrain, and some gates contain
/// blocked tiles (e.g. the pillars in the entrance of the illusion temples). A player who lands on one would
/// be warped to the safezone, out of the game he just paid for, so he gets a random walkable tile of the
/// entrance gate instead.
/// </remarks>
internal virtual Point? GetEntrySpawnPosition(Player player)
{
if (player.SelectedCharacter is not { } character
|| this.Map.Terrain.WalkMap[character.PositionX, character.PositionY]
|| this.Definition.Entrance is not { } entrance)
{
return null;
}

var walkMap = this.Map.Terrain.WalkMap;
var walkablePoints = entrance.GetPossibleLandingPoints().Where(point => walkMap[point.X, point.Y]).ToList();
return walkablePoints.Count > 0 ? walkablePoints[Rand.NextInt(0, walkablePoints.Count)] : null;
}

/// <summary>
/// Starts the game loop, unless it was started before. It can't start in the
Expand Down
6 changes: 5 additions & 1 deletion src/GameLogic/PlayerActions/TalkNpcAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ public async ValueTask TalkToNpcAsync(Player player, NonPlayerCharacter npc)
/// </summary>
/// <param name="npc">The NPC whose dialog is about to be opened.</param>
/// <returns>A value indicating whether this action advances the player state to <see cref="PlayerState.NpcDialogOpened" />.</returns>
protected virtual bool AdvancePlayerState(NonPlayerCharacter npc) => true;
/// <remarks>
/// Not for the illusion temple entrance: its window is closed by the client without a close request (the original
/// client did the same), so the player would stay in the dialog state and couldn't talk to any other npc.
/// </remarks>
protected virtual bool AdvancePlayerState(NonPlayerCharacter npc) => npc.Definition.NpcWindow != NpcWindow.IllusionTemple;

private async ValueTask ShowDialogOfOpenedNpcAsync(Player player)
{
Expand Down
12 changes: 7 additions & 5 deletions src/GameServer/RemoteView/MiniGames/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,21 @@ public static DoppelgangerEnterResult.EnterResult ToDoppelgangerEnterResult(this
/// <param name="enterResult">The enter result.</param>
/// <returns>The converted result.</returns>
/// <remarks>
/// The client uses distinct result bytes for admission and ticket failures (3), a full event (4),
/// and a player-killer rejection (7). Preserve these messages instead of collapsing every failure
/// into the not-open result (1).
/// The client shows a text of its own for a character level which doesn't fit the temple of the ticket (3), a full
/// event (4) and a player-killer rejection (7), and none for the other result bytes. The server tells every refusal
/// in words before sending the result, so the other outcomes (a missing ticket, not enough zen, any other failure) get
/// a result byte without a client text (1); with 3 the client added "The admission and scroll levels do not match",
/// which is wrong for them.
/// </remarks>
public static byte ToIllusionTempleEnterResult(this EnterResult enterResult)
{
return enterResult switch
{
EnterResult.Success => 0,
EnterResult.NotOpen => 1,
EnterResult.CharacterLevelTooHigh or EnterResult.CharacterLevelTooLow => 3,
EnterResult.Full => 4,
EnterResult.PlayerKillerCantEnter => 7,
_ => 3,
_ => 1,
};
}

Expand Down
Loading