Some checks failed
.NET Core / build (push) Has been cancelled
Ownership reward: only members of the current castle-owning guild may warp into Land of Trials (map 31); sealed while unowned; GMs bypass. Enforced in both WarpAction and WarpGateAction (// ADAMU-CUSTOM). Tax system deferred per user. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
85 lines
2.6 KiB
C#
85 lines
2.6 KiB
C#
// <copyright file="WarpAction.cs" company="MUnique">
|
|
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
|
// </copyright>
|
|
|
|
namespace MUnique.OpenMU.GameLogic.PlayerActions;
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using MUnique.OpenMU.GameLogic.Attributes;
|
|
using MUnique.OpenMU.GameLogic.Views;
|
|
using MUnique.OpenMU.Interfaces;
|
|
|
|
/// <summary>
|
|
/// Action to warp to another place.
|
|
/// </summary>
|
|
public class WarpAction
|
|
{
|
|
/// <summary>
|
|
/// Warps the player.
|
|
/// </summary>
|
|
/// <param name="player">The player.</param>
|
|
/// <param name="warpInfo">The warp information.</param>
|
|
public async ValueTask WarpToAsync(Player player, WarpInfo warpInfo)
|
|
{
|
|
// ADAMU-CUSTOM: Castle Siege hunting-map access (Land of Trials, owner guild only).
|
|
var (allowed, csError) = await CastleSiege.CastleSiegeMapAccess
|
|
.CanEnterMapAsync(player, warpInfo.Gate?.Map?.Number ?? 0).ConfigureAwait(false);
|
|
if (!allowed)
|
|
{
|
|
await player.ShowBlueMessageAsync(csError!).ConfigureAwait(false);
|
|
return;
|
|
}
|
|
|
|
if (this.CheckRequirements(player, warpInfo, out var errorMessage))
|
|
{
|
|
await player.WarpToAsync(warpInfo.Gate!).ConfigureAwait(false);
|
|
}
|
|
else
|
|
{
|
|
await player.ShowBlueMessageAsync(errorMessage).ConfigureAwait(false);
|
|
}
|
|
}
|
|
|
|
private bool CheckRequirements(Player player, WarpInfo warpInfo, [MaybeNullWhen(true)] out string errorMessage)
|
|
{
|
|
errorMessage = null;
|
|
|
|
var requirement = player.SelectedCharacter?.GetEffectiveMoveLevelRequirement(warpInfo.LevelRequirement);
|
|
if (requirement > player.Attributes?[Stats.Level])
|
|
{
|
|
errorMessage = $"You need to be level {requirement} in order to warp";
|
|
return false;
|
|
}
|
|
|
|
if (warpInfo.Gate?.Map is null)
|
|
{
|
|
errorMessage = "The warp target is not initialized";
|
|
return false;
|
|
}
|
|
|
|
if (warpInfo.Gate.Map.TryGetRequirementError(player, out var message))
|
|
{
|
|
errorMessage = message;
|
|
return false;
|
|
}
|
|
|
|
// Money check should be last to avoid getting zen when other checks failed
|
|
if (!this.CheckMoneyRequirement(player, warpInfo))
|
|
{
|
|
errorMessage = $"You need {warpInfo.Costs} in order to warp";
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private bool CheckMoneyRequirement(Player player, WarpInfo warpInfo)
|
|
{
|
|
if (player.TryRemoveMoney(warpInfo.Costs))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |