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
14 changes: 13 additions & 1 deletion src/GameLogic/PlayerActions/Craftings/BaseEventTicketCrafting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MUnique.OpenMU.GameLogic.PlayerActions.Craftings;

using MUnique.OpenMU.DataModel.Configuration.Items;
using MUnique.OpenMU.GameLogic.Crywolf;
using MUnique.OpenMU.GameLogic.PlayerActions.Items;
using MUnique.OpenMU.GameLogic.Views.NPC;
Expand Down Expand Up @@ -110,8 +111,8 @@ protected sealed override int GetPrice(byte successRate, IList<CraftingRequiredI
protected override async ValueTask<List<Item>> CreateOrModifyResultItemsAsync(IList<CraftingRequiredItemLink> requiredItems, Player player, byte socketIndex, byte successRate)
{
var item = player.PersistenceContext.CreateNew<Item>();
item.Definition = player.GameContext.Configuration.Items.First(i => i.Name.ValueInNeutralLanguage == this._resultItemName);
item.Level = this.GetEventLevel(requiredItems);
item.Definition = this.GetResultItemDefinition(player, item.Level);
item.Durability = 1;
if (player.TemporaryStorage is { } temporaryStorage)
{
Expand All @@ -121,6 +122,17 @@ protected override async ValueTask<List<Item>> CreateOrModifyResultItemsAsync(IL
return new List<Item> { item };
}

/// <summary>
/// Gets the item definition of the ticket which the crafting creates.
/// </summary>
/// <param name="player">The player.</param>
/// <param name="eventLevel">The event level, which is the item level of the ticket.</param>
/// <returns>The item definition with the name of the result item.</returns>
protected virtual ItemDefinition GetResultItemDefinition(Player player, byte eventLevel)
{
return player.GameContext.Configuration.Items.First(i => i.Name.ValueInNeutralLanguage == this._resultItemName);
}

private byte GetEventLevel(IList<CraftingRequiredItemLink> requiredItems)
{
var item = requiredItems.First(ri => ri.Items.Any(i => i.Definition?.Name.ValueInNeutralLanguage == this._requiredEventItemName1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,41 @@

namespace MUnique.OpenMU.GameLogic.PlayerActions.Craftings;

using MUnique.OpenMU.DataModel.Configuration.Items;
using MUnique.OpenMU.GameLogic.Views.NPC;

/// <summary>
/// Crafting for Illusion Temple Event Tickets.
/// Crafting for Illusion Temple Event Tickets, the Scroll of Blood, which is combined from an Old Scroll and an
/// Illusion Sorcerer Covenant of the same level.
/// </summary>
public class IllusionTempleTicketCrafting : BaseEventTicketCrafting
{
/// <summary>
/// Initializes a new instance of the <see cref="IllusionTempleTicketCrafting"/> class.
/// </summary>
public IllusionTempleTicketCrafting()
: base("Illusion Sorcerer Covenant", "Old Scroll", "Scroll of Blood")
: base("Scroll of Blood", "Old Scroll", "Illusion Sorcerer Covenant")
{
}

/// <inheritdoc />
protected override byte MaximumSuccessRate => 80;

/// <inheritdoc />
/// <remarks>
/// The ticket which the temple of the level accepts, so the crafting and the temples stay in step when the
/// server owner selects another ticket item. Only without such a temple, the item named "Scroll of Blood".
/// </remarks>
protected override ItemDefinition GetResultItemDefinition(Player player, byte eventLevel)
{
return player.GameContext.Configuration.MiniGameDefinitions
.Where(definition => definition.Type == MiniGameType.IllusionTemple && definition.TicketItemLevel == eventLevel)
.OrderBy(definition => definition.GameLevel)
.Select(definition => definition.TicketItem)
.FirstOrDefault(ticket => ticket is not null)
?? base.GetResultItemDefinition(player, eventLevel);
}

/// <inheritdoc />
protected override int GetPrice(int eventLevel)
{
Expand Down
151 changes: 121 additions & 30 deletions src/Persistence/Initialization/Updates/IllusionTempleDataUpdatePlugIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public class IllusionTempleDataUpdatePlugIn : UpdatePlugInBase
/// <summary>
/// The plug in description.
/// </summary>
internal const string PlugInDescription = "This update creates the configuration data for the illusion temple event and assigns the event dialog to the Mirage NPC.";
internal const string PlugInDescription = "This update creates the configuration data for the illusion temple event and assigns the event dialog to the Mirage NPC. "
+ "If the items 13/50 and 13/51 have swapped data (Scroll of Blood and Illusion Sorcerer Covenant), it gives them their original data back: "
+ "names, sizes, durability, levels and drops, the drop item groups, the temple tickets and the merchant items of 13/51. "
+ "If only one of the two has the swapped name, it changes neither. "
+ "References to the two items which you added yourself (craftings, quests, item drops, plug-in settings) stay as they are: check them after the update.";

/// <summary>
/// The number of the Mirage NPC, which opens the illusion temple dialog.
Expand Down Expand Up @@ -93,6 +97,32 @@ public class IllusionTempleDataUpdatePlugIn : UpdatePlugInBase
/// </summary>
private const int DefaultMinimumPlayerCount = 2;

/// <summary>
/// The item group of the illusion temple ticket items.
/// </summary>
private const byte TicketItemGroup = 13;

/// <summary>
/// The number of the Illusion Sorcerer Covenant, which drops from monsters.
/// </summary>
private const short CovenantItemNumber = 50;

/// <summary>
/// The number of the Scroll of Blood, the ticket, which the chaos goblin combines from an Old Scroll and an
/// Illusion Sorcerer Covenant.
/// </summary>
private const short ScrollOfBloodItemNumber = 51;

/// <summary>
/// The neutral name of the Illusion Sorcerer Covenant.
/// </summary>
private const string CovenantName = "Illusion Sorcerer Covenant";

/// <summary>
/// The neutral name of the Scroll of Blood.
/// </summary>
private const string ScrollOfBloodName = "Scroll of Blood";

/// <summary>
/// The map numbers of the six illusion temples, and the arena monster NPC number range (base id and
/// how many ids to cycle through) which each of them roams with - temple 6 has none.
Expand Down Expand Up @@ -188,15 +218,22 @@ private static readonly (short Number, int Level, int Hp, int MinDmg, int MaxDmg
public override bool IsMandatory => true;

/// <inheritdoc />
public override int Version => 2;
public override int Version => 3;

/// <inheritdoc />
public override DateTime CreatedAt => new(2026, 07, 29, 20, 0, 0, DateTimeKind.Utc);

/// <inheritdoc />
public override DateTime UpdatedAt => new(2026, 11, 5, 0, 0, 0, DateTimeKind.Utc);
public override DateTime UpdatedAt => new(2026, 11, 8, 0, 0, 0, DateTimeKind.Utc);

/// <inheritdoc />
/// <remarks>
/// Version one swapped the numbers of the Illusion Sorcerer Covenant and the Scroll of Blood, believing the
/// covenant was the ticket. It's the other way around, so version three leaves the original numbers as they
/// are, and gives a database which got the swap the original item data back (see <see cref="RestoreTicketItems"/>).
/// The ticket binding repair of version two pointed the temples which reference 13/50 at 13/51, then named the
/// covenant; the restoration still makes that move, as 13/51 becomes the Scroll of Blood.
/// </remarks>
protected override async ValueTask ApplyAsync(IContext context, GameConfiguration gameConfiguration, int? installedVersion)
{
// Replaying version one's content changes could overwrite owner-customized spawns or safezones.
Expand All @@ -205,15 +242,14 @@ protected override async ValueTask ApplyAsync(IContext context, GameConfiguratio
await this.ApplyAsync(context, gameConfiguration).ConfigureAwait(false);
}

this.FixTicketBindings(gameConfiguration);
RestoreTicketItems(gameConfiguration);
}

/// <inheritdoc />
#pragma warning disable CS1998
protected override async ValueTask ApplyAsync(IContext context, GameConfiguration gameConfiguration)
#pragma warning restore CS1998
{
this.FixTicketItemNumbers(gameConfiguration);
this.AddRelicItem(context, gameConfiguration);
this.AddArenaMonsterDefinitions(context, gameConfiguration);
this.AddMapSpawns(context, gameConfiguration);
Expand Down Expand Up @@ -243,47 +279,102 @@ protected override async ValueTask ApplyAsync(IContext context, GameConfiguratio
}

/// <summary>
/// The illusion temple ticket ("Illusion Sorcerer Covenant") and the "Scroll of Blood" item used to
/// have their numbers swapped (50/51) - <see cref="IllusionTempleInitializer"/> looks the ticket up
/// by Group 13, Number 51, so an existing database still using the old numbering needs the two
/// numbers corrected. Only the Number field is touched, so already-owned instances of either item
/// keep referencing the same, unchanged, item definition entity.
/// Gives the items 13/50 and 13/51 their original data back, if the configuration has the data of the
/// two swapped, and points the mini game definitions which reference 13/50 at the ticket 13/51.
/// </summary>
private void FixTicketItemNumbers(GameConfiguration gameConfiguration)
/// <remarks>
/// Version one of this update swapped the numbers of the two item definitions, and the data initialization of
/// the same time created them with swapped data. The game client knows the items by their numbers, so the
/// numbers stay and the data is swapped back instead: an owned item which the client shows as the Scroll of
/// Blood stays the ticket, and the item 13/50 drops again. The swapped state is recognized by the names, so
/// nothing changes on a configuration which has the original data.
/// </remarks>
/// <param name="gameConfiguration">The game configuration.</param>
private static void RestoreTicketItems(GameConfiguration gameConfiguration)
{
// The names are matched in the neutral language: item names became a LocalizedString, whose
// serialized value carries the translations and the resource metadata, so comparing it to a
// plain string would never match on a database which has been localized.
var covenant = gameConfiguration.Items.FirstOrDefault(item => item.Group == 13 && item.Name.ValueInNeutralLanguage == "Illusion Sorcerer Covenant");
var scrollOfBlood = gameConfiguration.Items.FirstOrDefault(item => item.Group == 13 && item.Name.ValueInNeutralLanguage == "Scroll of Blood");
if (covenant is { Number: 50 } && scrollOfBlood is { Number: 51 })
// The items are named by their numbers, which is what they are after the restoration.
var ticket = gameConfiguration.Items.FirstOrDefault(item => item.Group == TicketItemGroup && item.Number == ScrollOfBloodItemNumber && item.Name.ValueInNeutralLanguage == CovenantName);
var covenant = gameConfiguration.Items.FirstOrDefault(item => item.Group == TicketItemGroup && item.Number == CovenantItemNumber && item.Name.ValueInNeutralLanguage == ScrollOfBloodName);
if (ticket is null || covenant is null)
{
// Not swapped, or the server owner changed one of the two: the data of one item alone can't be swapped,
// and the description of the update tells the owner to check the items.
return;
}

RepairTicketBindings(gameConfiguration, ticket, covenant);
RepairMerchantStoreItems(gameConfiguration, ticket, covenant);
SwapData(ticket, covenant);
SwapDropItemGroups(gameConfiguration, ticket, covenant);
}

/// <summary>
/// Points the mini game definitions which reference the item 13/50 at the ticket 13/51.
/// A database which had temple definitions before version one of this update renumbered the items kept
/// them on the item definition which got the number 50, and a server owner who chose a ticket in the
/// swapped state chose 13/50 as the Scroll of Blood. That item definition becomes the Illusion Sorcerer
/// Covenant, so every definition follows the Scroll of Blood to 13/51, also one with an own id or ticket
/// level. A ticket of another item, or of an item definition of another configuration, stays.
/// </summary>
private static void RepairTicketBindings(GameConfiguration gameConfiguration, ItemDefinition ticket, ItemDefinition covenant)
{
foreach (var definition in gameConfiguration.MiniGameDefinitions.Where(definition => ReferenceEquals(definition.TicketItem, covenant)))
{
covenant.Number = 51;
scrollOfBlood.Number = 50;
definition.TicketItem = ticket;
}
}

/// <summary>
/// Repairs the seeded ticket references left pointing at the Scroll of Blood after version one's renumbering.
/// Only owned item instances and the unchanged default temple definition ids and ticket levels are recognized.
/// Points the items of the merchant stores which reference the ticket 13/51 at the item 13/50.
/// No merchant sells the ticket, but a merchant of the original data sells the Illusion Sorcerer Covenant,
/// whose item definition version one of this update renumbered to 51.
/// </summary>
private void FixTicketBindings(GameConfiguration gameConfiguration)
private static void RepairMerchantStoreItems(GameConfiguration gameConfiguration, ItemDefinition ticket, ItemDefinition covenant)
{
var covenant = gameConfiguration.Items.FirstOrDefault(item => item.Group == 13 && item.Number == 51 && item.Name.ValueInNeutralLanguage == "Illusion Sorcerer Covenant");
var scrollOfBlood = gameConfiguration.Items.FirstOrDefault(item => item.Group == 13 && item.Number == 50 && item.Name.ValueInNeutralLanguage == "Scroll of Blood");
if (covenant is null || scrollOfBlood is null)
foreach (var item in gameConfiguration.Monsters
.SelectMany(monster => monster.MerchantStore?.Items ?? Enumerable.Empty<Item>())
.Where(item => ReferenceEquals(item.Definition, ticket)))
{
return;
item.Definition = covenant;
}
}

foreach (var definition in gameConfiguration.MiniGameDefinitions.Where(definition =>
definition.Type == MiniGameType.IllusionTemple
&& definition.GameLevel is >= 1 and <= 6
&& definition.TicketItemLevel == definition.GameLevel
&& definition.GetId() == GuidHelper.CreateGuid<MiniGameDefinition>((short)MiniGameType.IllusionTemple, definition.GameLevel)
&& ReferenceEquals(definition.TicketItem, scrollOfBlood)))
/// <summary>
/// Swaps the data which the data initialization sets for each event item, except the number.
/// The other data, like the item rules, the price definition and the game version, is set by the number,
/// so it already fits.
/// </summary>
private static void SwapData(ItemDefinition first, ItemDefinition second)
{
(first.Name, second.Name) = (second.Name, first.Name);
(first.Width, second.Width) = (second.Width, first.Width);
(first.Height, second.Height) = (second.Height, first.Height);
(first.Durability, second.Durability) = (second.Durability, first.Durability);
(first.MaximumItemLevel, second.MaximumItemLevel) = (second.MaximumItemLevel, first.MaximumItemLevel);
(first.DropsFromMonsters, second.DropsFromMonsters) = (second.DropsFromMonsters, first.DropsFromMonsters);
(first.DropLevel, second.DropLevel) = (second.DropLevel, first.DropLevel);
(first.MaximumDropLevel, second.MaximumDropLevel) = (second.MaximumDropLevel, first.MaximumDropLevel);
}

/// <summary>
/// Swaps the two item definitions in the drop item groups which contain one of them, which are the groups of
/// the Illusion Sorcerer Covenant, one for each item level.
/// </summary>
private static void SwapDropItemGroups(GameConfiguration gameConfiguration, ItemDefinition first, ItemDefinition second)
{
foreach (var group in gameConfiguration.DropItemGroups)
{
definition.TicketItem = covenant;
var containsFirst = group.PossibleItems.Contains(first);
if (containsFirst == group.PossibleItems.Contains(second))
{
continue;
}

group.PossibleItems.Remove(containsFirst ? first : second);
group.PossibleItems.Add(containsFirst ? second : first);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ public override void Initialize()
// Chaos Castle:
this.CreateEventItem(29, 13, 2, 2, LocalizedString.FromResource(() => ItemNames.ArmorOfGuardsman), false);

// Illusion Temple:
// Illusion Temple: the Old Scroll and the Illusion Sorcerer Covenant drop from monsters, and the chaos goblin
// combines them into the Scroll of Blood, which is the ticket.
this.CreateEventItem(49, 13, 1, 1, LocalizedString.FromResource(() => ItemNames.OldScroll), false, 6, 66, 72, 78, 84, 90, 96);
this.CreateEventItem(51, 13, 1, 2, LocalizedString.FromResource(() => ItemNames.IllusionSorcererCovenant), false, 6, 70, 76, 82, 88, 94, 100);
this.CreateEventItem(50, 13, 2, 2, LocalizedString.FromResource(() => ItemNames.ScrollOfBlood), false, 6);
this.CreateEventItem(50, 13, 1, 2, LocalizedString.FromResource(() => ItemNames.IllusionSorcererCovenant), false, 6, 70, 76, 82, 88, 94, 100);
this.CreateEventItem(51, 13, 2, 2, LocalizedString.FromResource(() => ItemNames.ScrollOfBlood), false, 6);

// Kalima:
this.CreateKalimaTicket();
Expand Down
Loading
Loading