From ea53c8fd3490d7099861e7ba6327bd6bd894934c Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Tue, 26 Nov 2024 19:05:46 -0800 Subject: [PATCH 1/3] feat: Adds better young restrictions and messaging --- Projects/Server/Mobiles/Mobile.cs | 20 +++++------- .../Items/Skill Items/Misc/Bandage.cs | 4 +++ Projects/UOContent/Misc/Notoriety.cs | 21 +++---------- Projects/UOContent/Mobiles/PlayerMobile.cs | 7 ++--- Projects/UOContent/Skills/Stealing.cs | 31 +++++++++++++------ Projects/UOContent/Spells/Base/Spell.cs | 6 ++++ 6 files changed, 45 insertions(+), 44 deletions(-) diff --git a/Projects/Server/Mobiles/Mobile.cs b/Projects/Server/Mobiles/Mobile.cs index d6b9eb9a24..66064b87b9 100644 --- a/Projects/Server/Mobiles/Mobile.cs +++ b/Projects/Server/Mobiles/Mobile.cs @@ -7105,23 +7105,17 @@ public virtual bool CanSee(Item item) return false; } - if (item.Parent != null) + if (item.Parent is Item parent) { - if (item.Parent is Item parent) + if (!(CanSee(parent) && parent.IsChildVisibleTo(this, item))) { - if (!(CanSee(parent) && parent.IsChildVisibleTo(this, item))) - { - return false; - } - } - else if (item.Parent is Mobile mobile) - { - if (!CanSee(mobile)) - { - return false; - } + return false; } } + else if (item.Parent is Mobile mobile && !CanSee(mobile)) + { + return false; + } if (item is BankBox box && m_AccessLevel <= AccessLevel.Counselor && (box.Owner != this || !box.Opened)) { diff --git a/Projects/UOContent/Items/Skill Items/Misc/Bandage.cs b/Projects/UOContent/Items/Skill Items/Misc/Bandage.cs index 68f9b35801..77a7997e22 100644 --- a/Projects/UOContent/Items/Skill Items/Misc/Bandage.cs +++ b/Projects/UOContent/Items/Skill Items/Misc/Bandage.cs @@ -466,6 +466,10 @@ public static BandageContext BeginHeal(Mobile healer, Mobile patient) { healer.SendLocalizedMessage(501042); // Target cannot be resurrected at that location. } + else if ((healer as PlayerMobile)?.Young == true && (patient as PlayerMobile)?.Young == false) + { + healer.SendLocalizedMessage(500952); // As a young player, you may not use beneficial skills on older players. + } else if (healer.CanBeBeneficial(patient, true, true)) { healer.DoBeneficial(patient); diff --git a/Projects/UOContent/Misc/Notoriety.cs b/Projects/UOContent/Misc/Notoriety.cs index e86c81ecc0..126b419d65 100644 --- a/Projects/UOContent/Misc/Notoriety.cs +++ b/Projects/UOContent/Misc/Notoriety.cs @@ -44,15 +44,8 @@ private static GuildStatus GetGuildStatus(Mobile m) return GuildStatus.Waring; } - private static bool CheckBeneficialStatus(GuildStatus from, GuildStatus target) - { - if (from == GuildStatus.Waring || target == GuildStatus.Waring) - { - return false; - } - - return true; - } + private static bool CheckBeneficialStatus(GuildStatus from, GuildStatus target) => + from != GuildStatus.Waring && target != GuildStatus.Waring; /*private static bool CheckHarmfulStatus( GuildStatus from, GuildStatus target ) { @@ -239,13 +232,9 @@ public static bool Mobile_AllowHarmful(Mobile from, Mobile target) if (!from.Player && !(from is BaseCreature bc && bc.GetMaster() != null && bc.GetMaster().AccessLevel == AccessLevel.Player)) { - if (!CheckAggressor(from.Aggressors, target) && !CheckAggressed(from.Aggressed, target) && - pmTarg?.CheckYoungProtection(from) == true) - { - return false; - } - - return true; // Uncontrolled NPCs are only restricted by the young system + // Uncontrolled NPCs are only restricted by the young system + return CheckAggressor(from.Aggressors, target) || CheckAggressed(from.Aggressed, target) || + pmTarg?.CheckYoungProtection(from) != true; } var fromGuild = GetGuildFor(from.Guild as Guild, from); diff --git a/Projects/UOContent/Mobiles/PlayerMobile.cs b/Projects/UOContent/Mobiles/PlayerMobile.cs index c29772d429..3efb322b9f 100644 --- a/Projects/UOContent/Mobiles/PlayerMobile.cs +++ b/Projects/UOContent/Mobiles/PlayerMobile.cs @@ -2621,12 +2621,9 @@ public override void OnDeath(Container c) } } - if (Young && DuelContext == null) + if (Young && DuelContext == null && YoungDeathTeleport()) { - if (YoungDeathTeleport()) - { - Timer.StartTimer(TimeSpan.FromSeconds(2.5), SendYoungDeathNotice); - } + Timer.StartTimer(TimeSpan.FromSeconds(2.5), SendYoungDeathNotice); } if (DuelContext?.Registered != true || !DuelContext.Started || m_DuelPlayer?.Eliminated != false) diff --git a/Projects/UOContent/Skills/Stealing.cs b/Projects/UOContent/Skills/Stealing.cs index c0459a6215..cd2cca7a4a 100644 --- a/Projects/UOContent/Skills/Stealing.cs +++ b/Projects/UOContent/Skills/Stealing.cs @@ -18,6 +18,7 @@ public static class Stealing { public static readonly bool ClassicMode = false; public static readonly bool SuspendOnMurder = false; + private const int MaxWeightToSteal = 10; public static void Initialize() { @@ -80,6 +81,8 @@ private Item TryStealItem(Item toSteal, ref bool caught) var root = toSteal.RootParent; var mobRoot = root as Mobile; + var rootIsPlayer = mobRoot?.Player == true; + var vendor = root as BaseVendor; StealableArtifacts.StealableInstance si = toSteal.Parent == null || !toSteal.Movable ? StealableArtifacts.GetStealableInstance(toSteal) @@ -93,16 +96,23 @@ private Item TryStealItem(Item toSteal, ref bool caught) { m_Thief.SendMessage("You may not steal in this area."); } - else if (mobRoot?.Player == true && !IsInGuild(m_Thief)) + else if ((m_Thief as PlayerMobile)?.Young == true && (rootIsPlayer || vendor == null && mobRoot is BaseCreature)) + { + m_Thief.SendLocalizedMessage(502700); // You cannot steal from people or monsters right now. Practice on chests and barrels. + } + else if (rootIsPlayer && !IsInGuild(m_Thief)) { m_Thief.SendLocalizedMessage(1005596); // You must be in the thieves guild to steal from other players. } - else if (SuspendOnMurder && mobRoot?.Player == true && IsInGuild(m_Thief) && - m_Thief.Kills > 0) + else if (SuspendOnMurder && rootIsPlayer && IsInGuild(m_Thief) && m_Thief.Kills > 0) { m_Thief.SendLocalizedMessage(502706); // You are currently suspended from the thieves guild. } - else if (root is BaseVendor vendor && vendor.IsInvulnerable) + else if ((mobRoot as PlayerMobile)?.Young == true) + { + m_Thief.SendLocalizedMessage(502699); // You cannot steal from the Young. + } + else if (vendor?.IsInvulnerable == true) { m_Thief.SendLocalizedMessage(1005598); // You can't steal from shopkeepers. } @@ -114,10 +124,6 @@ private Item TryStealItem(Item toSteal, ref bool caught) { m_Thief.SendLocalizedMessage(500237); // Target can not be seen. } - else if (m_Thief.Backpack?.CheckHold(m_Thief, toSteal, false, true) != true) - { - m_Thief.SendLocalizedMessage(1048147); // Your backpack can't hold anything else. - } else if (toSteal is Sigil sig) { var pl = PlayerState.Find(m_Thief); @@ -206,6 +212,10 @@ private Item TryStealItem(Item toSteal, ref bool caught) m_Thief.SendLocalizedMessage(1005588); // You must join a faction to do that } } + else if (m_Thief.Backpack?.CheckHold(m_Thief, toSteal, false, true) != true) + { + m_Thief.SendLocalizedMessage(1048147); // Your backpack can't hold anything else. + } else if (si == null && (toSteal.Parent == null || !toSteal.Movable)) { m_Thief.SendLocalizedMessage(502710); // You can't steal that! @@ -250,9 +260,10 @@ private Item TryStealItem(Item toSteal, ref bool caught) { var w = toSteal.Weight + toSteal.TotalWeight; - if (w > 10) + if (w > MaxWeightToSteal) { - m_Thief.SendMessage("That is too heavy to steal."); + // This item is too heavy to steal from someone's backpack. + m_Thief.SendLocalizedMessage(502722); } else { diff --git a/Projects/UOContent/Spells/Base/Spell.cs b/Projects/UOContent/Spells/Base/Spell.cs index ec04e9158b..16af9faf8e 100644 --- a/Projects/UOContent/Spells/Base/Spell.cs +++ b/Projects/UOContent/Spells/Base/Spell.cs @@ -831,6 +831,12 @@ public bool CheckBSequence(Mobile target, bool allowDead = false) return false; } + if ((Caster as PlayerMobile)?.Young == true && (target as PlayerMobile)?.Young == false) + { + Caster.SendLocalizedMessage(500278); // As a young player, you may not cast beneficial spells onto older players. + return false; + } + if (Caster.CanBeBeneficial(target, true, allowDead) && CheckSequence()) { Caster.DoBeneficial(target); From 15c948abec657fee810ca0267e4c86ee73b766ce Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Tue, 26 Nov 2024 19:26:41 -0800 Subject: [PATCH 2/3] Fixes notoriety --- Projects/UOContent/Misc/Notoriety.cs | 82 +++++++++++----------------- 1 file changed, 32 insertions(+), 50 deletions(-) diff --git a/Projects/UOContent/Misc/Notoriety.cs b/Projects/UOContent/Misc/Notoriety.cs index 126b419d65..5b3540112b 100644 --- a/Projects/UOContent/Misc/Notoriety.cs +++ b/Projects/UOContent/Misc/Notoriety.cs @@ -63,20 +63,16 @@ public static bool Mobile_AllowBeneficial(Mobile from, Mobile target) return true; } - var bcFrom = from as BaseCreature; - var bcTarg = target as BaseCreature; - var pmFrom = from as PlayerMobile; - var pmTarg = target as PlayerMobile; - - if (pmFrom == null && bcFrom?.Summoned == true) + if (from.Region.IsPartOf() || target.Region.IsPartOf()) { - pmFrom = bcFrom.SummonMaster as PlayerMobile; + return false; } - if (pmTarg == null && bcTarg?.Summoned == true) - { - pmTarg = bcTarg.SummonMaster as PlayerMobile; - } + var bcFrom = from as BaseCreature; + var bcTarg = target as BaseCreature; + + var pmFrom = (bcFrom?.GetMaster() ?? from) as PlayerMobile; + var pmTarg = (bcTarg?.GetMaster() ?? target) as PlayerMobile; if (pmFrom != null && pmTarg != null) { @@ -117,11 +113,6 @@ public static bool Mobile_AllowBeneficial(Mobile from, Mobile target) return false; } - if (from.Region.IsPartOf() || target.Region.IsPartOf()) - { - return false; - } - var map = from.Map; var targetFaction = Faction.Find(target, true); @@ -136,7 +127,7 @@ public static bool Mobile_AllowBeneficial(Mobile from, Mobile target) return true; // In felucca, anything goes } - if (!from.Player) + if (!from.Player && pmFrom?.AccessLevel != AccessLevel.Player) { return true; // NPCs have no restrictions } @@ -148,7 +139,7 @@ public static bool Mobile_AllowBeneficial(Mobile from, Mobile target) if (pmFrom?.Young == true && pmTarg?.Young != true) { - return false; // Young players cannot perform beneficial actions towards older players + return false; // Young players cannot perform beneficial actions towards non-young players or pets } if (from.Guild is Guild fromGuild && target.Guild is Guild targetGuild && @@ -168,20 +159,16 @@ public static bool Mobile_AllowHarmful(Mobile from, Mobile target) return true; } - var bcFrom = from as BaseCreature; - var pmFrom = from as PlayerMobile; - var pmTarg = target as PlayerMobile; - var bcTarg = target as BaseCreature; - - if (pmFrom == null && bcFrom?.Summoned == true) + if (from.Region.IsPartOf() || target.Region.IsPartOf()) { - pmFrom = bcFrom.SummonMaster as PlayerMobile; + return false; } - if (pmTarg == null && bcTarg?.Summoned == true) - { - pmTarg = bcTarg.SummonMaster as PlayerMobile; - } + var bcFrom = from as BaseCreature; + var bcTarg = target as BaseCreature; + + var pmFrom = (bcFrom?.GetMaster() ?? from) as PlayerMobile; + var pmTarg = (bcTarg?.GetMaster() ?? target) as PlayerMobile; if (pmFrom != null && pmTarg != null) { @@ -217,11 +204,6 @@ public static bool Mobile_AllowHarmful(Mobile from, Mobile target) return false; } - if (from.Region.IsPartOf() || target.Region.IsPartOf()) - { - return false; - } - var map = from.Map; if ((map?.Rules & MapRules.HarmfulRestrictions) == 0) @@ -229,12 +211,11 @@ public static bool Mobile_AllowHarmful(Mobile from, Mobile target) return true; // In felucca, anything goes } - if (!from.Player && !(from is BaseCreature bc && bc.GetMaster() != null && - bc.GetMaster().AccessLevel == AccessLevel.Player)) + if (!from.Player && pmFrom?.AccessLevel != AccessLevel.Player) { // Uncontrolled NPCs are only restricted by the young system return CheckAggressor(from.Aggressors, target) || CheckAggressed(from.Aggressed, target) || - pmTarg?.CheckYoungProtection(from) != true; + (target as PlayerMobile)?.CheckYoungProtection(from) != true; } var fromGuild = GetGuildFor(from.Guild as Guild, from); @@ -247,7 +228,7 @@ public static bool Mobile_AllowHarmful(Mobile from, Mobile target) } if (bcTarg?.Controlled == true - || (bcTarg?.Summoned == true && bcTarg.SummonMaster != from && bcTarg.SummonMaster.Player)) + || bcTarg?.Summoned == true && bcTarg.SummonMaster != from && bcTarg.SummonMaster.Player) { return false; // Cannot harm other controlled mobiles from players } @@ -267,23 +248,24 @@ public static bool Mobile_AllowHarmful(Mobile from, Mobile target) public static Guild GetGuildFor(Guild def, Mobile m) { - var g = def; + if (m is not BaseCreature c || !c.Controlled || c.ControlMaster == null) + { + return def; + } - if (m is BaseCreature c && c.Controlled && c.ControlMaster != null) + c.DisplayGuildTitle = false; + + if (c.Map != Map.Internal && (Core.AOS || Guild.NewGuildSystem || c.ControlOrder is OrderType.Attack or OrderType.Guard)) { - c.DisplayGuildTitle = false; + return (Guild)(c.Guild = c.ControlMaster.Guild); + } - if (c.Map != Map.Internal && (Core.AOS || Guild.NewGuildSystem || c.ControlOrder is OrderType.Attack or OrderType.Guard)) - { - g = (Guild)(c.Guild = c.ControlMaster.Guild); - } - else if (c.Map == Map.Internal || c.ControlMaster.Guild == null) - { - g = (Guild)(c.Guild = null); - } + if (c.Map == Map.Internal || c.ControlMaster.Guild == null) + { + return (Guild)(c.Guild = null); } - return g; + return def; } public static int CorpseNotoriety(Mobile source, Corpse target) From 4d29edf0e2820a4b06e95a40288a240fcb874d8a Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Mon, 20 Jan 2025 11:27:20 -0800 Subject: [PATCH 3/3] Cleanup --- Projects/UOContent/Misc/Notoriety.cs | 2 +- Projects/UOContent/Skills/Stealing.cs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Projects/UOContent/Misc/Notoriety.cs b/Projects/UOContent/Misc/Notoriety.cs index 5b3540112b..3d8a5b6c60 100644 --- a/Projects/UOContent/Misc/Notoriety.cs +++ b/Projects/UOContent/Misc/Notoriety.cs @@ -137,7 +137,7 @@ public static bool Mobile_AllowBeneficial(Mobile from, Mobile target) return false; // Players cannot heal uncontrolled mobiles } - if (pmFrom?.Young == true && pmTarg?.Young != true) + if (pmFrom?.Young == true && pmTarg?.Young == false) { return false; // Young players cannot perform beneficial actions towards non-young players or pets } diff --git a/Projects/UOContent/Skills/Stealing.cs b/Projects/UOContent/Skills/Stealing.cs index cd2cca7a4a..f2f270b29e 100644 --- a/Projects/UOContent/Skills/Stealing.cs +++ b/Projects/UOContent/Skills/Stealing.cs @@ -82,7 +82,6 @@ private Item TryStealItem(Item toSteal, ref bool caught) var root = toSteal.RootParent; var mobRoot = root as Mobile; var rootIsPlayer = mobRoot?.Player == true; - var vendor = root as BaseVendor; StealableArtifacts.StealableInstance si = toSteal.Parent == null || !toSteal.Movable ? StealableArtifacts.GetStealableInstance(toSteal) @@ -96,7 +95,7 @@ private Item TryStealItem(Item toSteal, ref bool caught) { m_Thief.SendMessage("You may not steal in this area."); } - else if ((m_Thief as PlayerMobile)?.Young == true && (rootIsPlayer || vendor == null && mobRoot is BaseCreature)) + else if ((m_Thief as PlayerMobile)?.Young == true && (rootIsPlayer || mobRoot is BaseCreature)) { m_Thief.SendLocalizedMessage(502700); // You cannot steal from people or monsters right now. Practice on chests and barrels. } @@ -112,7 +111,7 @@ private Item TryStealItem(Item toSteal, ref bool caught) { m_Thief.SendLocalizedMessage(502699); // You cannot steal from the Young. } - else if (vendor?.IsInvulnerable == true) + else if ((root as BaseVendor)?.IsInvulnerable == true) { m_Thief.SendLocalizedMessage(1005598); // You can't steal from shopkeepers. }