diff --git a/Projects/Server/Localization/Localization.cs b/Projects/Server/Localization/Localization.cs index f5440cb23..cae4e93b5 100644 --- a/Projects/Server/Localization/Localization.cs +++ b/Projects/Server/Localization/Localization.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright 2019-2023 - ModernUO Development Team * + * Copyright 2019-2024 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Localization.cs * * * @@ -44,7 +44,7 @@ public static class Localization public static void Add(string lang, int number, string text) { - lang = lang.ToLower(); + lang = lang?.ToLower() ?? FallbackLanguage; var entry = new LocalizationEntry(lang, number, text); if (!_localizations.TryGetValue(lang, out var entries)) { @@ -61,7 +61,7 @@ public static class Localization public static bool Remove(string lang, int number) { - lang = lang.ToLower(); + lang = lang?.ToLower() ?? FallbackLanguage; if (!_localizations.TryGetValue(lang, out var entries) || !entries.Remove(number)) { return false; @@ -86,7 +86,7 @@ public static class Localization private static Dictionary LoadClilocs(string lang, string file) { - lang = lang.ToLower(); + lang = lang?.ToLower() ?? FallbackLanguage; Dictionary entries = _localizations[lang] = new Dictionary(); if (lang == FallbackLanguage) { @@ -132,7 +132,7 @@ public static class Localization /// /// Localization number /// Language in ISO 639‑2 format - /// Original text for the localizaton entry + /// Original text for the localization entry public static string GetText(int number, string lang = FallbackLanguage) => TryGetLocalization(lang, number, out var entry) ? entry.Text : null; @@ -154,7 +154,7 @@ public static class Localization /// True if the entry exists, otherwise false. public static bool TryGetLocalization(string lang, int number, out LocalizationEntry entry) { - lang = lang.ToLower(); + lang = lang?.ToLower() ?? FallbackLanguage; if (lang != FallbackLanguage) { if (!_localizations.TryGetValue(lang, out var entries)) diff --git a/Projects/UOContent/Spells/First/CreateFood.cs b/Projects/UOContent/Spells/First/CreateFood.cs index ab98b5ec0..506be0e25 100644 --- a/Projects/UOContent/Spells/First/CreateFood.cs +++ b/Projects/UOContent/Spells/First/CreateFood.cs @@ -1,88 +1,65 @@ -using System; using Server.Items; -using Server.Utilities; -namespace Server.Spells.First +namespace Server.Spells.First; + +public class CreateFoodSpell : MagerySpell { - public class CreateFoodSpell : MagerySpell - { - private static readonly SpellInfo _info = new( - "Create Food", - "In Mani Ylem", - 224, - 9011, - Reagent.Garlic, - Reagent.Ginseng, - Reagent.MandrakeRoot - ); + private static readonly SpellInfo _info = new( + "Create Food", + "In Mani Ylem", + 224, + 9011, + Reagent.Garlic, + Reagent.Ginseng, + Reagent.MandrakeRoot + ); - private static readonly FoodInfo[] m_Food = + private static Item CreateRandomFood() => + Utility.Random(10) switch { - new(typeof(Grapes), "a grape bunch"), - new(typeof(Ham), "a ham"), - new(typeof(CheeseWedge), "a wedge of cheese"), - new(typeof(Muffins), "muffins"), - new(typeof(FishSteak), "a fish steak"), - new(typeof(Ribs), "cut of ribs"), - new(typeof(CookedBird), "a cooked bird"), - new(typeof(Sausage), "sausage"), - new(typeof(Apple), "an apple"), - new(typeof(Peach), "a peach") + 0 => new Grapes(), + 1 => new Ham(), + 2 => new CheeseWedge(), + 3 => new Muffins(), + 4 => new FishSteak(), + 5 => new Ribs(), + 6 => new CookedBird(), + 7 => new Sausage(), + 8 => new Apple(), + 9 => new Peach(), + _ => null }; - public CreateFoodSpell(Mobile caster, Item scroll = null) : base(caster, scroll, _info) - { - } - - public override SpellCircle Circle => SpellCircle.First; - - public override void OnCast() - { - if (CheckSequence()) - { - var foodInfo = m_Food.RandomElement(); - var food = foodInfo.Create(); - - if (food != null) - { - Caster.AddToBackpack(food); - - // You magically create food in your backpack: - Caster.SendLocalizedMessage(1042695, true, $" {foodInfo.Name}"); - - Caster.FixedParticles(0, 10, 5, 2003, EffectLayer.RightHand); - Caster.PlaySound(0x1E2); - } - } - - FinishSequence(); - } + public CreateFoodSpell(Mobile caster, Item scroll = null) : base(caster, scroll, _info) + { } - public class FoodInfo + public override SpellCircle Circle => SpellCircle.First; + + public override void OnCast() { - public FoodInfo(Type type, string name) + if (CheckSequence()) { - Type = type; - Name = name; + var food = CreateRandomFood(); + + if (food != null) + { + Caster.AddToBackpack(food); + + if (Caster.NetState != null) + { + var foodName = Localization.GetText(food.LabelNumber, Caster.Language); + + // Note: On OSI, the food name is not localized. + // You magically create food in your backpack: + Caster.SendLocalizedMessage(1042695, true, $" {foodName}"); + } + + Caster.FixedParticles(0, 10, 5, 2003, EffectLayer.RightHand); + Caster.PlaySound(0x1E2); + } } - public Type Type { get; set; } - - public string Name { get; set; } - - public Item Create() - { - try - { - return Type.CreateInstance(); - } - catch - { - // ignored - } - - return null; - } + FinishSequence(); } }