Skip to content

Commit

Permalink
Added Info to Attack Items with Player.Attack(). (#131)
Browse files Browse the repository at this point in the history
* Added Info to Attack Items with Player.Attack().

Added new commands in Target and Player:
AttackType()
TargetType()

* Fix for 'contents' with UOSteam.
  • Loading branch information
Dramoor authored Feb 11, 2024
1 parent 9f72f99 commit 3c415da
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 10 deletions.
186 changes: 180 additions & 6 deletions Razor/RazorEnhanced/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2105,21 +2105,35 @@ 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)
{
Attack(mobile.Serial);
}



/// <summary>
/// Attack last target.
/// </summary>
Expand All @@ -2136,6 +2150,166 @@ public static void AttackLast()
Assistant.Client.Instance.SendToServerWait(new AttackReq(Targeting.LastAttack));
}

/// <summary>
/// Attack the Entity with a specific Graphic.
/// </summary>
/// <param name="graphic">Graphic of an Entity.</param>
/// <param name="rangemax">Max Range to scan for an Entity.</param>
/// <param name="selector">Selector for sorting the Entity.</param>
/// <param name="color">Color of an Entity.</param>
/// <param name="notoriety">Notorieties of an Entity.</param>
/// <returns>if the attack was achieved. (empty: line not found)</returns>
public static bool AttackType(int graphic, int rangemax, string selector, List<int> color = null, List<byte> 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;
}

/// <summary>
/// Attack the Mobile with a specific Graphic.
/// </summary>
/// <param name="graphics">Graphics of Entities.</param>
/// <param name="rangemax">Max Range to scan for an Entity.</param>
/// <param name="selector">Selector for sorting the Entity.</param>
/// <param name="color">Graphic of an Entity.</param>
/// <param name="notoriety">Notorieties of an Entity.</param>
/// <returns>if the attack was achieved. (empty: line not found)</returns>
public static bool AttackType(List<int> graphics, int rangemax, string selector, List<int> color = null, List<byte> 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
/// <summary>
/// Invoke a virtue by name.
Expand Down
72 changes: 72 additions & 0 deletions Razor/RazorEnhanced/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,78 @@ public static void TargetExecute(RazorEnhanced.Mobile mobile)
}
}

/// <summary>
/// Targets the entity of a specific Graphic.
/// </summary>
/// <param name="graphic">Graphic of an Entity.</param>
/// <param name="color">Color of an Entity.</param>
/// <param name="range">Range to scan for an Entity.</param>
/// <param name="selector">Selector for sorting the Entity.</param>
/// <param name="notoriety">Notorieties of an Entity.</param>
/// <returns>if the attack was achieved. (empty: line not found)</returns>
public static bool TargetType(int graphic, int color, int range, string selector, List<byte> 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<int> CaveTiles = new HashSet<int>() { 0xae, 0x5, 0x3, 0xc1, 0xc2, 0xc3, 0xbd, 0x0016, 0x0017, 0x0018, 0x0019,
0x244, 0x245, 0x246, 0x247, 0x248, 0x249, 0x22b, 0x22c, 0x22d, 0x22e, 0x22f,
Expand Down
18 changes: 14 additions & 4 deletions Razor/RazorEnhanced/UOSteamEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item> 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<Item> list = container.Contains;
return list.Count;
}

var contents = content.Split('/');

return Utility.ToInt32(contents[0], 0);
}
return 0;
}
Expand Down

0 comments on commit 3c415da

Please sign in to comment.