From 3c415dab316b7293e319bbeb225e8af0b9ad0d71 Mon Sep 17 00:00:00 2001 From: Dramoor Date: Sun, 11 Feb 2024 03:57:38 +0000 Subject: [PATCH] Added Info to Attack Items with Player.Attack(). (#131) * Added Info to Attack Items with Player.Attack(). Added new commands in Target and Player: AttackType() TargetType() * Fix for 'contents' with UOSteam. --- Razor/RazorEnhanced/Player.cs | 186 ++++++++++++++++++++++++++- Razor/RazorEnhanced/Target.cs | 72 +++++++++++ Razor/RazorEnhanced/UOSteamEngine.cs | 18 ++- 3 files changed, 266 insertions(+), 10 deletions(-) diff --git a/Razor/RazorEnhanced/Player.cs b/Razor/RazorEnhanced/Player.cs index 0150570d..f4d45346 100644 --- a/Razor/RazorEnhanced/Player.cs +++ b/Razor/RazorEnhanced/Player.cs @@ -2105,12 +2105,28 @@ public static void Attack(int serial) return; Target.AttackMessage(serial, true); - if (Targeting.LastAttack != serial) + + Item it = Items.FindBySerial(serial); + + if (it != null) { - Assistant.Client.Instance.SendToClientWait(new ChangeCombatant(serial)); - Targeting.LastAttack = (uint)serial; + if (!WarMode) + SetWarMode(true); + + Thread.Sleep(RazorEnhanced.Settings.General.ReadInt("ObjectDelay")); + + Assistant.Client.Instance.SendToServerWait(new DoubleClick(it.Serial)); + } + else + { + if (Targeting.LastAttack != serial) + { + Assistant.Client.Instance.SendToClientWait(new ChangeCombatant(serial)); + Targeting.LastAttack = (uint)serial; + } + + Assistant.Client.Instance.SendToServerWait(new AttackReq(serial)); } - Assistant.Client.Instance.SendToServerWait(new AttackReq(serial)); } public static void Attack(Mobile mobile) @@ -2118,8 +2134,6 @@ public static void Attack(Mobile mobile) Attack(mobile.Serial); } - - /// /// Attack last target. /// @@ -2136,6 +2150,166 @@ public static void AttackLast() Assistant.Client.Instance.SendToServerWait(new AttackReq(Targeting.LastAttack)); } + /// + /// Attack the Entity with a specific Graphic. + /// + /// Graphic of an Entity. + /// Max Range to scan for an Entity. + /// Selector for sorting the Entity. + /// Color of an Entity. + /// Notorieties of an Entity. + /// if the attack was achieved. (empty: line not found) + public static bool AttackType(int graphic, int rangemax, string selector, List color = null, List notoriety = null) + { + Mobiles.Filter filter = new Mobiles.Filter(); + filter.RangeMin = 0; + filter.RangeMax = rangemax; + + if (graphic > 0) + filter.Bodies.Add(graphic); + + if (color != null && color.Count > 0) + { + foreach (int i in color) + { + filter.Hues.Add(i); + } + } + + if (notoriety != null && notoriety.Count > 0) + { + foreach (byte i in notoriety) + { + if (i >= 1 && i < 7) + filter.Notorieties.Add(i); + } + } + Mobile atMobile = null; + var list = Mobiles.ApplyFilter(filter); + if (list.Count > 0) + atMobile = Mobiles.Select(list, selector); + + if(atMobile != null) + { + Target.SetLast(atMobile.Serial); //Attempt to highlight + + Attack(atMobile.Serial); + return true; + } + + Items.Filter itfilter = new Items.Filter(); + itfilter.RangeMin = 0; + itfilter.RangeMax = rangemax; + + if (graphic > 0) + itfilter.Graphics.Add(graphic); + + if (color != null && color.Count > 0) + { + foreach (int i in color) + { + itfilter.Hues.Add(i); + } + } + + Item atItem = null; + var itlist = Items.ApplyFilter(itfilter); + if (itlist.Count > 0) + atItem = Items.Select(itlist, selector); + + if (atItem != null) + { + Target.SetLast(atItem.Serial); //Attempt to highlight + + Attack(atItem.Serial); + return true; + } + + return false; + } + + /// + /// Attack the Mobile with a specific Graphic. + /// + /// Graphics of Entities. + /// Max Range to scan for an Entity. + /// Selector for sorting the Entity. + /// Graphic of an Entity. + /// Notorieties of an Entity. + /// if the attack was achieved. (empty: line not found) + public static bool AttackType(List graphics, int rangemax, string selector, List color = null, List notoriety = null) + { + Mobiles.Filter filter = new Mobiles.Filter(); + filter.RangeMin = 0; + filter.RangeMax = rangemax; + + if (graphics != null && graphics.Count > 0) + filter.Bodies = graphics; + + if (color != null && color.Count > 0) + { + foreach (int i in color) + { + filter.Hues.Add(i); + } + } + + if (notoriety != null && notoriety.Count > 0) + { + foreach (byte i in notoriety) + { + if (i >= 1 && i < 7) + filter.Notorieties.Add(i); + } + } + + Mobile atMobile = null; + var list = Mobiles.ApplyFilter(filter); + if (list.Count > 0) + atMobile = Mobiles.Select(list, selector); + + if (atMobile != null) + { + Target.SetLast(atMobile.Serial); //Attempt to highlight + + Attack(atMobile.Serial); + return true; + } + + Items.Filter itfilter = new Items.Filter(); + itfilter.RangeMin = 0; + itfilter.RangeMax = rangemax; + + if (graphics != null && graphics.Count > 0) + itfilter.Graphics = graphics; + + if (color != null && color.Count > 0) + { + foreach (int i in color) + { + itfilter.Hues.Add(i); + } + } + + Item atItem = null; + var itlist = Items.ApplyFilter(itfilter); + + if (itlist.Count > 0) + atItem = Items.Select(itlist, selector); + + if (atItem != null) + { + Target.SetLast(atItem.Serial); //Attempt to highlight + + Attack(atItem.Serial); + return true; + } + + return false; + } + + + // Virtue /// /// Invoke a virtue by name. diff --git a/Razor/RazorEnhanced/Target.cs b/Razor/RazorEnhanced/Target.cs index 426492c7..f7458f59 100644 --- a/Razor/RazorEnhanced/Target.cs +++ b/Razor/RazorEnhanced/Target.cs @@ -121,6 +121,78 @@ public static void TargetExecute(RazorEnhanced.Mobile mobile) } } + /// + /// Targets the entity of a specific Graphic. + /// + /// Graphic of an Entity. + /// Color of an Entity. + /// Range to scan for an Entity. + /// Selector for sorting the Entity. + /// Notorieties of an Entity. + /// if the attack was achieved. (empty: line not found) + public static bool TargetType(int graphic, int color, int range, string selector, List notoriety = null) + { + Item itm = null; + + if (range > 18) + { + itm = Items.FindByID(graphic, color, -1, range); + } + else + { + var options = new Items.Filter(); + options.Graphics.Add(graphic); + if (color != -1) + options.Hues.Add(color); + options.RangeMin = -1; + options.RangeMax = range; + options.OnGround = 1; + + var item_list = Items.ApplyFilter(options); + + itm = Items.Select(item_list, selector); + } + + if (itm == null) + { + Mobile mob = null; + // Container (Range: Container Serial) + var options = new Mobiles.Filter(); + + options.Bodies.Add(graphic); + if (color != -1) + options.Hues.Add(color); + + if (notoriety != null && notoriety.Count > 0) + { + foreach (byte i in notoriety) + { + if (i >= 1 && i < 7) + options.Notorieties.Add(i); + } + } + + options.RangeMin = -1; + options.RangeMax = range; + + var mob_list = Mobiles.ApplyFilter(options); + + mob = Mobiles.Select(mob_list, selector); + + if (mob != null) + { + TargetExecute(mob); + return true; + } + } + else + { + TargetExecute(itm); + return true; + } + + return false; + } static internal HashSet CaveTiles = new HashSet() { 0xae, 0x5, 0x3, 0xc1, 0xc2, 0xc3, 0xbd, 0x0016, 0x0017, 0x0018, 0x0019, 0x244, 0x245, 0x246, 0x247, 0x248, 0x249, 0x22b, 0x22c, 0x22d, 0x22e, 0x22f, diff --git a/Razor/RazorEnhanced/UOSteamEngine.cs b/Razor/RazorEnhanced/UOSteamEngine.cs index d9ee8c75..e396ed21 100644 --- a/Razor/RazorEnhanced/UOSteamEngine.cs +++ b/Razor/RazorEnhanced/UOSteamEngine.cs @@ -605,10 +605,20 @@ private static IComparable CountContents(string expression, Argument[] args, boo Item container = Items.FindBySerial((int)serial); if (container != null) { - if (!container.IsContainer) - return 0; - List list = container.Contains; - return list.Count; + Items.WaitForProps(container, 1000); + + string content = Items.GetPropValueString(container.Serial, "contents"); + if(string.IsNullOrEmpty(content)) + { + if (!container.IsContainer) + return 0; + List list = container.Contains; + return list.Count; + } + + var contents = content.Split('/'); + + return Utility.ToInt32(contents[0], 0); } return 0; }