first commit
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Abilities;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network.Packets;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class AbilitiesCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Abilities ) )]
|
||||
public static void ClearAbility()
|
||||
{
|
||||
AbilitiesManager manager = AbilitiesManager.GetInstance();
|
||||
|
||||
if ( manager.IsPrimaryEnabled )
|
||||
{
|
||||
manager.SetAbility( AbilityType.Primary );
|
||||
}
|
||||
else if ( manager.IsSecondaryEnabled )
|
||||
{
|
||||
manager.SetAbility( AbilityType.Secondary );
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Abilities ),
|
||||
Parameters = new[] { nameof( ParameterType.Ability ), nameof( ParameterType.OnOff ) } )]
|
||||
public static void SetAbility( string ability, string onOff = "toggle" )
|
||||
{
|
||||
AbilitiesManager manager = AbilitiesManager.GetInstance();
|
||||
|
||||
if ( ability.ToLower().Equals( "stun" ) )
|
||||
{
|
||||
Engine.SendPacketToServer( new StunRequest() );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ability.ToLower().Equals( "disarm" ) )
|
||||
{
|
||||
Engine.SendPacketToServer( new DisarmRequest() );
|
||||
return;
|
||||
}
|
||||
|
||||
bool primary;
|
||||
|
||||
switch ( ability.ToLower() )
|
||||
{
|
||||
case "primary":
|
||||
primary = true;
|
||||
break;
|
||||
default:
|
||||
primary = false;
|
||||
break;
|
||||
}
|
||||
|
||||
string onOffNormalized = onOff.Trim().ToLower();
|
||||
|
||||
if ( onOffNormalized != "toggle" )
|
||||
{
|
||||
switch ( onOffNormalized )
|
||||
{
|
||||
case "on":
|
||||
{
|
||||
if ( primary && manager.IsPrimaryEnabled || !primary && manager.IsSecondaryEnabled )
|
||||
{
|
||||
if ( !MacroManager.QuietMode )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Ability_already_set___, 0x3F );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "off":
|
||||
{
|
||||
if ( primary && !manager.IsPrimaryEnabled || !primary && !manager.IsSecondaryEnabled )
|
||||
{
|
||||
if ( !MacroManager.QuietMode )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Ability_not_set___, 0x3F );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UOC.SystemMessage( string.Format( Strings.Setting_ability___0_____, ability ), 0x3F );
|
||||
manager.SetAbility( primary ? AbilityType.Primary : AbilityType.Secondary );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Abilities ) )]
|
||||
public static void Fly()
|
||||
{
|
||||
PlayerMobile player = Engine.Player;
|
||||
|
||||
if ( player == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !player.Status.HasFlag( MobileStatus.Flying ) )
|
||||
{
|
||||
UOC.ToggleGargoyleFlying();
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Abilities ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Flying( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
Mobile mobile = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( mobile == null )
|
||||
{
|
||||
// TODO better message
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
return mobile.Status.HasFlag( MobileStatus.Flying );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Abilities ) )]
|
||||
public static void Land()
|
||||
{
|
||||
PlayerMobile player = Engine.Player;
|
||||
|
||||
if ( player == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( player.Status.HasFlag( MobileStatus.Flying ) )
|
||||
{
|
||||
UOC.ToggleGargoyleFlying();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,553 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Regions;
|
||||
using ClassicAssist.Misc;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network;
|
||||
using ClassicAssist.UO.Network.PacketFilter;
|
||||
using ClassicAssist.UO.Network.Packets;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class ActionCommands
|
||||
{
|
||||
public static UseOnceList UseOnceList { get; set; } = new UseOnceList();
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.Timeout ) } )]
|
||||
public static bool WaitForContents( object obj, int timeout = 5000 )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
return UOC.WaitForContainerContents( serial, timeout );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int Contents( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return 0;
|
||||
}
|
||||
|
||||
Item container = Engine.Items.GetItem( serial );
|
||||
|
||||
if ( container?.Container != null )
|
||||
{
|
||||
return container.Container.GetTotalItemCount();
|
||||
}
|
||||
|
||||
UOC.SystemMessage( Strings.Invalid_container___ );
|
||||
return 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ) )]
|
||||
public static void EquipLastWeapon()
|
||||
{
|
||||
Engine.SendPacketToServer( new EquipLastWeapon() );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.ItemID ), nameof( ParameterType.Hue ) } )]
|
||||
public static bool UseOnce( int graphic, int hue = -1 )
|
||||
{
|
||||
//TODO hue?
|
||||
if ( Engine.Player?.Backpack?.Container == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Item backpack = Engine.Player.Backpack;
|
||||
|
||||
Item match = backpack.Container.SelectEntity( i =>
|
||||
i.ID == graphic && !UseOnceList.Contains( i.Serial ) && ( hue == -1 || hue == i.Hue ) );
|
||||
|
||||
if ( match == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.UseOnce__Cannot_find_type___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
UseOnceList.Add( match );
|
||||
|
||||
ObjectCommands.UseObject( match.Serial );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ) )]
|
||||
public static void ClearUseOnce()
|
||||
{
|
||||
UseOnceList?.Clear();
|
||||
UOC.SystemMessage( Strings.UseOnce_cleared___ );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void Attack( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( Options.CurrentOptions.PreventAttackingInnocentsInGuardzone )
|
||||
{
|
||||
Mobile mobile = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( mobile != null && mobile.Notoriety == Notoriety.Innocent &&
|
||||
mobile.GetRegion().Attributes.HasFlag( RegionAttributes.Guarded ) )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Attack_request_blocked___ );
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Engine.SendPacketToClient( new ChangeCombatant( serial ) );
|
||||
Engine.SendPacketToServer( new AttackRequest( serial ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.LeftRightBoth ) } )]
|
||||
public static void ClearHands( string hand = "both" )
|
||||
{
|
||||
hand = hand.ToLower();
|
||||
List<Layer> unequipLayers = new List<Layer>();
|
||||
|
||||
switch ( hand )
|
||||
{
|
||||
case "left":
|
||||
unequipLayers.Add( Layer.OneHanded );
|
||||
break;
|
||||
case "right":
|
||||
unequipLayers.Add( Layer.TwoHanded );
|
||||
break;
|
||||
case "both":
|
||||
unequipLayers.Add( Layer.OneHanded );
|
||||
unequipLayers.Add( Layer.TwoHanded );
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException( nameof( hand ) );
|
||||
}
|
||||
|
||||
PlayerMobile player = Engine.Player;
|
||||
|
||||
List<int> serials = unequipLayers.Select( unequipLayer => Engine.Player.GetLayer( unequipLayer ) )
|
||||
.Where( serial => serial != 0 ).ToList();
|
||||
|
||||
foreach ( int serial in serials )
|
||||
{
|
||||
ActionPacketQueue.EnqueueDragDrop( serial, 1, player.Backpack?.Serial ?? 0 );
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void ClickObject( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.SendPacketToServer( new LookRequest( serial ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ) )]
|
||||
public static void ToggleMounted()
|
||||
{
|
||||
PlayerMobile player = Engine.Player;
|
||||
|
||||
if ( player == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( player.IsMounted )
|
||||
{
|
||||
ObjectCommands.UseObject( player.Serial );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !AliasCommands.FindAlias( "mount" ) )
|
||||
{
|
||||
int serial = UOC.GetTargeSerialAsync( Strings.Target_new_mount___ ).Result;
|
||||
|
||||
if ( serial == -1 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_mount___ );
|
||||
return;
|
||||
}
|
||||
|
||||
AliasCommands.SetAlias( "mount", serial );
|
||||
}
|
||||
|
||||
int mountSerial = AliasCommands.GetAlias( "mount" );
|
||||
|
||||
ObjectCommands.UseObject( mountSerial );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.ItemID ),
|
||||
nameof( ParameterType.Amount ), nameof( ParameterType.Hue )
|
||||
} )]
|
||||
public static void Feed( object obj, int graphic, int amount = 1, int hue = -1 )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( Engine.Player?.Backpack == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Error__Cannot_find_player_backpack );
|
||||
return;
|
||||
}
|
||||
|
||||
Item foodItem =
|
||||
Engine.Player.Backpack?.Container.SelectEntity( i => i.ID == graphic && ( hue == -1 || i.Hue == hue ) );
|
||||
|
||||
if ( foodItem == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return;
|
||||
}
|
||||
|
||||
ActionPacketQueue.EnqueueDragDrop( foodItem.Serial, amount, serial );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.Name ) } )]
|
||||
public static void Rename( object obj, string name )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
UOC.RenameRequest( serial, name );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.ShowType ) } )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { nameof( ShowNamesType ) } )]
|
||||
public static void ShowNames( string showType )
|
||||
{
|
||||
const int MAX_DISTANCE = 32;
|
||||
const int corpseType = 0x2006;
|
||||
|
||||
ShowNamesType enumValue = Utility.GetEnumValueByName<ShowNamesType>( showType );
|
||||
|
||||
switch ( enumValue )
|
||||
{
|
||||
case ShowNamesType.Mobiles:
|
||||
|
||||
Mobile[] mobiles = Engine.Mobiles.SelectEntities( m => m.Distance < MAX_DISTANCE );
|
||||
|
||||
if ( mobiles == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( Mobile mobile in mobiles )
|
||||
{
|
||||
Engine.SendPacketToServer( new LookRequest( mobile.Serial ) );
|
||||
}
|
||||
|
||||
break;
|
||||
case ShowNamesType.Corpses:
|
||||
|
||||
Item[] corpses = Engine.Items.SelectEntities( i =>
|
||||
UOMath.Distance( i.X, i.Y, Engine.Player.X, Engine.Player.Y ) < MAX_DISTANCE &&
|
||||
i.ID == corpseType );
|
||||
|
||||
if ( corpses == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( Item corpse in corpses )
|
||||
{
|
||||
Engine.SendPacketToServer( new LookRequest( corpse.Serial ) );
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.ItemID ), nameof( ParameterType.Layer ) } )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { null, nameof( Layer ) } )]
|
||||
public static void EquipType( int id, object layer )
|
||||
{
|
||||
Layer layerValue = Layer.Invalid;
|
||||
|
||||
switch ( layer )
|
||||
{
|
||||
case string s:
|
||||
layerValue = Utility.GetEnumValueByName<Layer>( s );
|
||||
break;
|
||||
case int i:
|
||||
layerValue = (Layer) i;
|
||||
break;
|
||||
case Layer l:
|
||||
layerValue = l;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( layerValue == Layer.Invalid )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_layer_value___ );
|
||||
return;
|
||||
}
|
||||
|
||||
UOC.EquipType( id, layerValue );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.Layer ) } )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { null, nameof( Layer ) } )]
|
||||
public static void EquipItem( object obj, object layer )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
Layer layerValue = Layer.Invalid;
|
||||
|
||||
switch ( layer )
|
||||
{
|
||||
case string s:
|
||||
layerValue = Utility.GetEnumValueByName<Layer>( s );
|
||||
break;
|
||||
case int i:
|
||||
layerValue = (Layer) i;
|
||||
break;
|
||||
case Layer l:
|
||||
layerValue = l;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( layerValue == Layer.Invalid )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_layer_value___ );
|
||||
return;
|
||||
}
|
||||
|
||||
Item item = Engine.Items.GetItem( serial );
|
||||
|
||||
if ( item == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return;
|
||||
}
|
||||
|
||||
UOC.EquipItem( item, layerValue );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.Layer ), nameof( ParameterType.SerialOrAlias ) } )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { nameof( Layer ), null } )]
|
||||
public static bool FindLayer( object layer, object obj = null )
|
||||
{
|
||||
if ( obj == null )
|
||||
{
|
||||
obj = "self";
|
||||
}
|
||||
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
Layer layerValue = Layer.Invalid;
|
||||
|
||||
switch ( layer )
|
||||
{
|
||||
case string s:
|
||||
layerValue = Utility.GetEnumValueByName<Layer>( s );
|
||||
break;
|
||||
case int i:
|
||||
layerValue = (Layer) i;
|
||||
break;
|
||||
case Layer l:
|
||||
layerValue = l;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( layerValue == Layer.Invalid )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_layer_value___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !UOMath.IsMobile( serial ) )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
Mobile mobile = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
int layerSerial = mobile?.GetLayer( layerValue ) ?? 0;
|
||||
|
||||
if ( layerSerial == 0 )
|
||||
{
|
||||
AliasCommands.UnsetAlias( "found" );
|
||||
return false;
|
||||
}
|
||||
|
||||
AliasCommands.SetMacroAlias( "found", layerSerial );
|
||||
|
||||
if ( MacroManager.QuietMode )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
UOC.SystemMessage( string.Format( Strings.Object___0___updated___, "found" ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ) )]
|
||||
public static long Ping()
|
||||
{
|
||||
Random random = new Random();
|
||||
|
||||
byte value = (byte) random.Next( 1, byte.MaxValue );
|
||||
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
PacketWaitEntry we = Engine.PacketWaitEntries.Add(
|
||||
new PacketFilterInfo( 0x73, new[] { new PacketFilterCondition( 1, new[] { value }, 1 ) } ),
|
||||
PacketDirection.Incoming, true );
|
||||
|
||||
Engine.SendPacketToServer( new Ping( value ) );
|
||||
|
||||
bool result = we.Lock.WaitOne( 5000 );
|
||||
|
||||
sw.Stop();
|
||||
|
||||
if ( result )
|
||||
{
|
||||
return sw.ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.ContextMenuIndex ) } )]
|
||||
public static void ContextMenu( object obj, int entry )
|
||||
{
|
||||
if ( obj == null )
|
||||
{
|
||||
obj = "self";
|
||||
}
|
||||
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.SendPacketToServer( new ContextMenuRequest( serial ) );
|
||||
Thread.Sleep( 400 );
|
||||
Engine.SendPacketToServer( new ContextMenuClick( serial, entry ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.ContextMenuIndex ),
|
||||
nameof( ParameterType.Timeout )
|
||||
} )]
|
||||
public static bool WaitForContext( object obj, int entry, int timeout )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
PacketFilterInfo pfi = new PacketFilterInfo( 0xBF,
|
||||
new[]
|
||||
{
|
||||
PacketFilterConditions.ShortAtPositionCondition( 0x14, 3 ),
|
||||
PacketFilterConditions.IntAtPositionCondition( serial, 7 )
|
||||
}, ( bytes, info ) =>
|
||||
{
|
||||
Engine.SendPacketToServer( new ContextMenuClick( serial, entry ) );
|
||||
are.Set();
|
||||
} );
|
||||
|
||||
Engine.AddReceiveFilter( pfi );
|
||||
|
||||
Engine.SendPacketToServer( new ContextMenuRequest( serial ) );
|
||||
|
||||
try
|
||||
{
|
||||
bool result = are.WaitOne( timeout );
|
||||
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Engine.RemoveReceiveFilter( pfi );
|
||||
}
|
||||
}
|
||||
|
||||
private enum ShowNamesType
|
||||
{
|
||||
Mobiles,
|
||||
Corpses
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
using System.Linq;
|
||||
using ClassicAssist.Data.Autoloot;
|
||||
using ClassicAssist.Data.Counters;
|
||||
using ClassicAssist.Data.Dress;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class AgentCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Agents ),
|
||||
Parameters = new[] { nameof( ParameterType.AgentEntryName ) } )]
|
||||
public static void Dress( string name = null )
|
||||
{
|
||||
DressManager manager = DressManager.GetInstance();
|
||||
|
||||
DressAgentEntry dressAgentEntry;
|
||||
|
||||
if ( string.IsNullOrEmpty( name ) )
|
||||
{
|
||||
if ( manager.TemporaryDress == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.No_temporary_dress_layout_configured___ );
|
||||
return;
|
||||
}
|
||||
|
||||
dressAgentEntry = manager.TemporaryDress;
|
||||
}
|
||||
else
|
||||
{
|
||||
dressAgentEntry = manager.Items.FirstOrDefault( dae => dae.Name == name );
|
||||
}
|
||||
|
||||
if ( dressAgentEntry == null )
|
||||
{
|
||||
UOC.SystemMessage( string.Format( Strings.Unknown_dress_agent___0___, name ) );
|
||||
return;
|
||||
}
|
||||
|
||||
dressAgentEntry.Action( dressAgentEntry );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Agents ),
|
||||
Parameters = new[] { nameof( ParameterType.AgentEntryName ) } )]
|
||||
public static void Undress( string name )
|
||||
{
|
||||
DressManager manager = DressManager.GetInstance();
|
||||
|
||||
DressAgentEntry dressAgentEntry = manager.Items.FirstOrDefault( dae => dae.Name == name );
|
||||
|
||||
if ( dressAgentEntry == null )
|
||||
{
|
||||
UOC.SystemMessage( string.Format( Strings.Unknown_dress_agent___0___, name ) );
|
||||
return;
|
||||
}
|
||||
|
||||
dressAgentEntry.Undress().Wait();
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Agents ) )]
|
||||
public static bool Dressing()
|
||||
{
|
||||
DressManager manager = DressManager.GetInstance();
|
||||
|
||||
return manager.IsDressing;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Agents ) )]
|
||||
public static void DressConfig()
|
||||
{
|
||||
DressManager manager = DressManager.GetInstance();
|
||||
manager.TemporaryDress = new DressAgentEntry();
|
||||
manager.TemporaryDress.Action = async hks => await manager.DressAllItems( manager.TemporaryDress, false );
|
||||
manager.ImportItems( manager.TemporaryDress );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Agents ),
|
||||
Parameters = new[] { nameof( ParameterType.AgentEntryName ) } )]
|
||||
public static int Counter( string name )
|
||||
{
|
||||
CountersManager manager = CountersManager.GetInstance();
|
||||
|
||||
CountersAgentEntry entry = manager.Items.FirstOrDefault( cae => cae.Name.ToLower() == name.ToLower() );
|
||||
|
||||
if ( entry != null )
|
||||
{
|
||||
return entry.Count;
|
||||
}
|
||||
|
||||
UOC.SystemMessage( Strings.Invalid_counter_agent_name___ );
|
||||
return 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Agents ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void SetAutolootContainer( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
AutolootHelpers.SetAutolootContainer?.Invoke( serial );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
using System.Collections.Generic;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class AliasCommands
|
||||
{
|
||||
public static Dictionary<string, int> _aliases = new Dictionary<string, int>();
|
||||
|
||||
internal static void SetDefaultAliases()
|
||||
{
|
||||
PlayerMobile player = Engine.Player;
|
||||
|
||||
if ( player == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SetAlias( "bank", player.GetLayer( Layer.Bank ) );
|
||||
SetAlias( "backpack", player.GetLayer( Layer.Backpack ) );
|
||||
SetAlias( "self", player.Serial );
|
||||
}
|
||||
|
||||
internal static int ResolveSerial( object obj )
|
||||
{
|
||||
int serial;
|
||||
|
||||
switch ( obj )
|
||||
{
|
||||
case string str:
|
||||
serial = GetAlias( str );
|
||||
|
||||
if ( serial == -1 && !MacroManager.QuietMode )
|
||||
{
|
||||
UOC.SystemMessage( string.Format( Strings.Unknown_alias___0___, str ) );
|
||||
}
|
||||
|
||||
break;
|
||||
case int i:
|
||||
serial = i;
|
||||
break;
|
||||
case uint i:
|
||||
serial = (int) i;
|
||||
break;
|
||||
case Entity i:
|
||||
serial = i.Serial;
|
||||
break;
|
||||
case null:
|
||||
serial = Engine.Player == null ? 0 : Engine.Player.Serial;
|
||||
|
||||
break;
|
||||
default:
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return -1;
|
||||
}
|
||||
|
||||
return serial;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Aliases ),
|
||||
Parameters = new[] { nameof( ParameterType.AliasName ), nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void SetAlias( string aliasName, object obj )
|
||||
{
|
||||
aliasName = aliasName.ToLower();
|
||||
|
||||
int value = ResolveSerial( obj );
|
||||
|
||||
if ( _aliases.ContainsKey( aliasName ) )
|
||||
{
|
||||
_aliases[aliasName] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_aliases.Add( aliasName, value );
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Aliases ),
|
||||
Parameters = new[] { nameof( ParameterType.AliasName ), nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void SetMacroAlias( string aliasName, object obj )
|
||||
{
|
||||
aliasName = aliasName.ToLower();
|
||||
|
||||
int value = ResolveSerial( obj );
|
||||
|
||||
MacroEntry macro = MacroManager.GetInstance().GetCurrentMacro();
|
||||
|
||||
if ( macro == null )
|
||||
{
|
||||
SetAlias( aliasName, obj );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( macro.Aliases.ContainsKey( aliasName ) )
|
||||
{
|
||||
macro.Aliases[aliasName] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
macro.Aliases.Add( aliasName, value );
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Aliases ),
|
||||
Parameters = new[] { nameof( ParameterType.AliasName ) } )]
|
||||
public static void UnsetAlias( string aliasName )
|
||||
{
|
||||
aliasName = aliasName.ToLower();
|
||||
|
||||
MacroEntry macro = MacroManager.GetInstance().GetCurrentMacro();
|
||||
|
||||
if ( macro != null )
|
||||
{
|
||||
if ( macro.Aliases.ContainsKey( aliasName ) )
|
||||
{
|
||||
macro.Aliases.Remove( aliasName );
|
||||
}
|
||||
}
|
||||
|
||||
if ( _aliases.ContainsKey( aliasName ) )
|
||||
{
|
||||
_aliases.Remove( aliasName );
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Aliases ),
|
||||
Parameters = new[] { nameof( ParameterType.AliasName ) } )]
|
||||
public static int GetAlias( string aliasName )
|
||||
{
|
||||
aliasName = aliasName.ToLower();
|
||||
|
||||
MacroEntry macro = MacroManager.GetInstance().GetCurrentMacro();
|
||||
|
||||
if ( macro != null )
|
||||
{
|
||||
if ( macro.Aliases.ContainsKey( aliasName ) )
|
||||
{
|
||||
return macro.Aliases[aliasName];
|
||||
}
|
||||
}
|
||||
|
||||
if ( _aliases.ContainsKey( aliasName ) )
|
||||
{
|
||||
return _aliases[aliasName];
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static Dictionary<string, int> GetAllAliases()
|
||||
{
|
||||
return _aliases;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Aliases ),
|
||||
Parameters = new[] { nameof( ParameterType.AliasName ) } )]
|
||||
public static int PromptAlias( string aliasName )
|
||||
{
|
||||
int serial = UOC.GetTargeSerialAsync( string.Format( Strings.Target_object___0_____, aliasName ) ).Result;
|
||||
SetAlias( aliasName, serial );
|
||||
return serial;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Aliases ),
|
||||
Parameters = new[] { nameof( ParameterType.AliasName ) } )]
|
||||
public static bool FindAlias( string aliasName )
|
||||
{
|
||||
aliasName = aliasName.ToLower();
|
||||
|
||||
int serial;
|
||||
|
||||
if ( ( serial = GetAlias( aliasName ) ) == -1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( UOMath.IsMobile( serial ) )
|
||||
{
|
||||
return Engine.Mobiles.GetMobile( serial ) != null;
|
||||
}
|
||||
|
||||
return Engine.Items.GetItem( serial ) != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Linq;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO.Network.PacketFilter;
|
||||
using ClassicAssist.UO.Network.Packets;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using static ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class ConsumeCommands
|
||||
{
|
||||
private const int TIMEOUT = 5000;
|
||||
private static readonly int[] _bandageTypes = { 0xe21 };
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ) )]
|
||||
public static bool BandageSelf()
|
||||
{
|
||||
PlayerMobile player = Engine.Player;
|
||||
|
||||
if ( player == null )
|
||||
{
|
||||
SystemMessage( Strings.Error__No_Player );
|
||||
return false;
|
||||
}
|
||||
|
||||
Item backpack = player.Backpack;
|
||||
|
||||
if ( backpack == null )
|
||||
{
|
||||
SystemMessage( Strings.Error__Cannot_find_player_backpack );
|
||||
return false;
|
||||
}
|
||||
|
||||
Item bandage = backpack.Container?.SelectEntity( i => _bandageTypes.Contains( i.ID ) );
|
||||
|
||||
if ( bandage == null )
|
||||
{
|
||||
SystemMessage( Strings.Error__Cannot_find_type );
|
||||
return false;
|
||||
}
|
||||
|
||||
ObjectCommands.UseObject( bandage.Serial );
|
||||
|
||||
PacketWaitEntry we = Engine.PacketWaitEntries.Add( new PacketFilterInfo( 0x6C ), PacketDirection.Incoming );
|
||||
|
||||
bool result = we.Lock.WaitOne( TIMEOUT );
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
SystemMessage( Strings.Target_timeout___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
byte[] packet = we.Packet;
|
||||
|
||||
int senderSerial = ( packet[2] << 24 ) | ( packet[3] << 16 ) | ( packet[4] << 8 ) | packet[5];
|
||||
|
||||
Engine.SendPacketToServer( new Target( senderSerial, player, true ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class DummyCommands
|
||||
{
|
||||
public static int Dummy( int a, int b )
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
using System.Reflection;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.BuffIcons;
|
||||
using ClassicAssist.Data.SpecialMoves;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class EntityCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int Distance( object obj = null )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return 0;
|
||||
}
|
||||
|
||||
Entity entity = Engine.Items.GetItem( serial ) ?? (Entity) Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
return entity?.Distance ?? int.MaxValue;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.Distance ) } )]
|
||||
public static bool InRange( object obj, int distance )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
Entity entity = Engine.Items.GetItem( serial ) ?? (Entity) Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( entity != null )
|
||||
{
|
||||
return entity.Distance < distance;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int Hue( object obj = null )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return 0;
|
||||
}
|
||||
|
||||
Entity entity = UOMath.IsMobile( serial )
|
||||
? Engine.Mobiles.GetMobile( serial )
|
||||
: Engine.Items.GetItem( serial ) as Entity;
|
||||
|
||||
if ( entity != null )
|
||||
{
|
||||
return entity.Hue;
|
||||
}
|
||||
|
||||
if ( !MacroManager.QuietMode )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Entity_not_found___ );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int Graphic( object obj = null )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return 0;
|
||||
}
|
||||
|
||||
Entity entity = UOMath.IsMobile( serial )
|
||||
? Engine.Mobiles.GetMobile( serial )
|
||||
: Engine.Items.GetItem( serial ) as Entity;
|
||||
|
||||
if ( entity != null )
|
||||
{
|
||||
return entity.ID;
|
||||
}
|
||||
|
||||
if ( !MacroManager.QuietMode )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Entity_not_found___ );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int X( object obj = null )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return 0;
|
||||
}
|
||||
|
||||
Entity entity = UOMath.IsMobile( serial )
|
||||
? Engine.Mobiles.GetMobile( serial )
|
||||
: Engine.Items.GetItem( serial ) as Entity;
|
||||
|
||||
if ( entity != null )
|
||||
{
|
||||
return entity.X;
|
||||
}
|
||||
|
||||
if ( !MacroManager.QuietMode )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Entity_not_found___ );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int Y( object obj = null )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return 0;
|
||||
}
|
||||
|
||||
Entity entity = UOMath.IsMobile( serial )
|
||||
? Engine.Mobiles.GetMobile( serial )
|
||||
: Engine.Items.GetItem( serial ) as Entity;
|
||||
|
||||
if ( entity != null )
|
||||
{
|
||||
return entity.Y;
|
||||
}
|
||||
|
||||
if ( !MacroManager.QuietMode )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Entity_not_found___ );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int Z( object obj = null )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return 0;
|
||||
}
|
||||
|
||||
Entity entity = UOMath.IsMobile( serial )
|
||||
? Engine.Mobiles.GetMobile( serial )
|
||||
: Engine.Items.GetItem( serial ) as Entity;
|
||||
|
||||
if ( entity != null )
|
||||
{
|
||||
return entity.Z;
|
||||
}
|
||||
|
||||
if ( !MacroManager.QuietMode )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Entity_not_found___ );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.BuffName ) } )]
|
||||
public static bool BuffExists( string name )
|
||||
{
|
||||
return BuffIconManager.GetInstance().BuffExists( name );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.BuffName ) } )]
|
||||
public static double BuffTime( string name )
|
||||
{
|
||||
return BuffIconManager.GetInstance().BuffTime( name );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SpecialMoveName ) } )]
|
||||
public static bool SpecialMoveExists( string name )
|
||||
{
|
||||
return SpecialMovesManager.GetInstance().SpecialMoveExists( name );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static string DirectionTo( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
return Direction.Invalid.ToString();
|
||||
}
|
||||
|
||||
Entity entity = UOMath.IsMobile( serial )
|
||||
? Engine.Mobiles.GetMobile( serial )
|
||||
: Engine.Items.GetItem( serial ) as Entity;
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
return Direction.Invalid.ToString();
|
||||
}
|
||||
|
||||
return UOMath.MapDirection( Engine.Player.X, Engine.Player.Y, entity.X, entity.Y ).ToString();
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static string Name( object obj = null )
|
||||
{
|
||||
return GetEntityProperty<string>( obj, nameof( Entity.Name ) )?.Trim() ?? string.Empty;
|
||||
}
|
||||
|
||||
private static T GetEntityProperty<T>( object obj, string propertyName )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial <= 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return default;
|
||||
}
|
||||
|
||||
Entity entity = UOMath.IsMobile( serial )
|
||||
? Engine.Mobiles.GetMobile( serial )
|
||||
: (Entity) Engine.Items.GetItem( serial );
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Entity_not_found___ );
|
||||
return default;
|
||||
}
|
||||
|
||||
PropertyInfo property = entity.GetType().GetProperty( propertyName );
|
||||
|
||||
if ( property == null )
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
T val = (T) property.GetValue( entity );
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Main ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void HideEntity( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return;
|
||||
}
|
||||
|
||||
UOC.RemoveObject( serial );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
using System.Linq;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO.Network.Packets;
|
||||
using ClassicAssist.UO.Objects.Gumps;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class GumpCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Gumps ),
|
||||
Parameters = new[] { nameof( ParameterType.ItemID ), nameof( ParameterType.Timeout ) } )]
|
||||
public static bool WaitForGump( uint gumpId = 0, int timeout = 30000 )
|
||||
{
|
||||
bool result = UOC.WaitForGump( gumpId, timeout );
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Timeout___ );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Gumps ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.ItemID ), nameof( ParameterType.GumpButtonIndex ),
|
||||
nameof( ParameterType.IntegerValue )
|
||||
} )]
|
||||
public static void ReplyGump( uint gumpId, int buttonId, int[] switches = null )
|
||||
{
|
||||
UOC.GumpButtonClick( gumpId, buttonId, switches );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Gumps ) )]
|
||||
public static bool GumpExists( uint gumpId )
|
||||
{
|
||||
return Engine.GumpList.ContainsKey( gumpId );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Gumps ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.String ) } )]
|
||||
public static bool InGump( uint gumpId, string text )
|
||||
{
|
||||
if ( Engine.Gumps.GetGump( gumpId, out Gump gump ) )
|
||||
{
|
||||
return gump.GumpElements.Any( ge => ge.Text != null && ge.Text.ToLower().Contains( text.ToLower() ) );
|
||||
}
|
||||
|
||||
UOC.SystemMessage( Strings.Invalid_gump___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Gumps ), Parameters = new[] { nameof( ParameterType.Serial ) } )]
|
||||
public static void CloseGump( int serial )
|
||||
{
|
||||
if ( Engine.Gumps.FindGump( serial, out Gump gump ) )
|
||||
{
|
||||
gump.CloseGump();
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Gumps ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void OpenVirtueGump( object obj = null )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Mobile_not_found___ );
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.SendPacketToServer( new GumpButtonClick( 0x1CD, Engine.Player.Serial, 1, new[] { serial } ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Gumps ) )]
|
||||
public static void OpenGuildGump()
|
||||
{
|
||||
Engine.SendPacketToServer( new GuildButtonRequest() );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Gumps ) )]
|
||||
public static void OpenQuestsGump()
|
||||
{
|
||||
Engine.SendPacketToServer( new QuestsButtonRequest() );
|
||||
}
|
||||
|
||||
//[CommandsDisplay( Category = nameof( Strings.Gumps ) )]
|
||||
//public static bool ConfirmPrompt( string message, bool closable = false )
|
||||
//{
|
||||
// return ConfirmPromptGump.ConfirmPrompt( message, closable );
|
||||
//}
|
||||
|
||||
//public static int SendCustomGump( Gump gump )
|
||||
//{
|
||||
// PacketFilterInfo pfi = new PacketFilterInfo( 0xB1,
|
||||
// new[] { PacketFilterConditions.IntAtPositionCondition( (int) gump.ID, 7 ) } );
|
||||
|
||||
// Engine.AddSendFilter( pfi );
|
||||
// gump.SendGump();
|
||||
|
||||
// PacketWaitEntry we = Engine.PacketWaitEntries.Add( pfi, PacketDirection.Outgoing, true, true );
|
||||
|
||||
// we.Lock.WaitOne();
|
||||
|
||||
// if ( we.Packet == null )
|
||||
// {
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// PacketReader reader = new PacketReader( we.Packet, we.Packet.Length, false );
|
||||
// reader.ReadInt32();
|
||||
// reader.ReadInt32();
|
||||
// int buttonId = reader.ReadInt32();
|
||||
// return buttonId;
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class JournalCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Journal ) )]
|
||||
public static bool InJournal( string text, string author = "", int hue = -1 )
|
||||
{
|
||||
bool match;
|
||||
|
||||
if ( author.ToLower().Equals( "system" ) )
|
||||
{
|
||||
match = Engine.Journal.GetBuffer().Any( je =>
|
||||
je.Text.ToLower().Contains( text.ToLower() ) &&
|
||||
( je.SpeechType == JournalSpeech.System || je.Name == "System" ) &&
|
||||
( hue == -1 || je.SpeechHue == hue ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
match = Engine.Journal.GetBuffer().Any( je =>
|
||||
je.Text.ToLower().Contains( text.ToLower() ) &&
|
||||
( string.IsNullOrEmpty( author ) || string.Equals( je.Name, author,
|
||||
StringComparison.CurrentCultureIgnoreCase ) ) && ( hue == -1 || je.SpeechHue == hue ) );
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Journal ) )]
|
||||
public static void ClearJournal()
|
||||
{
|
||||
Engine.Journal.Clear();
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Journal ) )]
|
||||
public static bool WaitForJournal( string text, int timeout, string author = "" )
|
||||
{
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
void OnIncomingPacketHandlersOnJournalEntryAddedEvent( JournalEntry je )
|
||||
{
|
||||
bool match;
|
||||
|
||||
if ( author.ToLower().Equals( "system" ) )
|
||||
{
|
||||
match = je.Text.ToLower().Contains( text.ToLower() ) &&
|
||||
( je.SpeechType == JournalSpeech.System || je.Name == "System" );
|
||||
}
|
||||
else
|
||||
{
|
||||
match = je.Text.ToLower().Contains( text.ToLower() ) &&
|
||||
( string.IsNullOrEmpty( author ) || string.Equals( je.Name, author,
|
||||
StringComparison.CurrentCultureIgnoreCase ) );
|
||||
}
|
||||
|
||||
if ( match )
|
||||
{
|
||||
are.Set();
|
||||
}
|
||||
}
|
||||
|
||||
IncomingPacketHandlers.JournalEntryAddedEvent += OnIncomingPacketHandlersOnJournalEntryAddedEvent;
|
||||
|
||||
bool result;
|
||||
|
||||
try
|
||||
{
|
||||
result = are.WaitOne( timeout );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IncomingPacketHandlers.JournalEntryAddedEvent -= OnIncomingPacketHandlersOnJournalEntryAddedEvent;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class ListCommands
|
||||
{
|
||||
private static readonly Dictionary<string, List<int>> _lists = new Dictionary<string, List<int>>();
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Lists ), Parameters = new[] { nameof( ParameterType.ListName ) } )]
|
||||
public static void CreateList( string listName )
|
||||
{
|
||||
if ( ListExists( listName ) )
|
||||
{
|
||||
RemoveList( listName );
|
||||
}
|
||||
|
||||
_lists.Add( listName, new List<int>() );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Lists ), Parameters = new[] { nameof( ParameterType.ListName ) } )]
|
||||
public static bool ListExists( string listName )
|
||||
{
|
||||
return _lists.ContainsKey( listName );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Lists ), Parameters = new[] { nameof( ParameterType.ListName ) } )]
|
||||
public static int List( string listName )
|
||||
{
|
||||
return ListExists( listName ) ? _lists[listName].Count : 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Lists ),
|
||||
Parameters = new[] { nameof( ParameterType.ListName ), nameof( ParameterType.IntegerValue ) } )]
|
||||
public static void PushList( string listName, int value )
|
||||
{
|
||||
if ( !ListExists( listName ) )
|
||||
{
|
||||
CreateList( listName );
|
||||
}
|
||||
|
||||
_lists[listName].Add( value );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Lists ), Parameters = new[] { nameof( ParameterType.ListName ) } )]
|
||||
public static int[] GetList( string listName )
|
||||
{
|
||||
return _lists[listName].ToArray();
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Lists ), Parameters = new[] { nameof( ParameterType.ListName ) } )]
|
||||
public static void RemoveList( string listName )
|
||||
{
|
||||
_lists.Remove( listName );
|
||||
}
|
||||
|
||||
public static Dictionary<string, List<int>> GetAllLists()
|
||||
{
|
||||
return _lists;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Lists ), Parameters = new[] { nameof( ParameterType.ListName ) } )]
|
||||
public static void ClearList( string listName )
|
||||
{
|
||||
if ( !_lists.ContainsKey( listName ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_lists[listName].Clear();
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Lists ),
|
||||
Parameters = new[] { nameof( ParameterType.ListName ), nameof( ParameterType.IntegerValue ) } )]
|
||||
public static bool InList( string listName, int value )
|
||||
{
|
||||
int[] list;
|
||||
|
||||
return ( list = GetList( listName ) ) != null && list.Contains( value );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class MacroCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Macros ),
|
||||
Parameters = new[] { nameof( ParameterType.MacroName ) } )]
|
||||
public static void PlayMacro( string name )
|
||||
{
|
||||
MacroManager manager = MacroManager.GetInstance();
|
||||
|
||||
MacroEntry macro = manager.Items.FirstOrDefault( m => m.Name == name );
|
||||
|
||||
if ( macro == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Unknown_macro___ );
|
||||
return;
|
||||
}
|
||||
|
||||
Task.Run( () => macro.Action( macro ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Macros ), Parameters = new[] { nameof( ParameterType.String ) } )]
|
||||
public static void Stop( string name = null )
|
||||
{
|
||||
MacroManager.GetInstance().Stop( name );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Macros ) )]
|
||||
public static void StopAll()
|
||||
{
|
||||
MacroManager.GetInstance().StopAll();
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Macros ) )]
|
||||
public static void Replay()
|
||||
{
|
||||
MacroManager manager = MacroManager.GetInstance();
|
||||
|
||||
MacroEntry current = manager?.GetCurrentMacro();
|
||||
|
||||
if ( current?.Action == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
manager.Replay = true;
|
||||
|
||||
Task.Run( () => current.Action( current ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Hotkeys;
|
||||
using ClassicAssist.Misc;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network.Packets;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class MainCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Main ), Parameters = new[] { nameof( ParameterType.OnOff ) } )]
|
||||
public static void SetQuietMode( bool onOff )
|
||||
{
|
||||
MacroManager.QuietMode = onOff;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Main ), Parameters = new[] { nameof( ParameterType.String ) } )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { nameof( Virtues ) } )]
|
||||
public static void InvokeVirtue( string virtue )
|
||||
{
|
||||
Virtues v = Utility.GetEnumValueByName<Virtues>( virtue );
|
||||
|
||||
if ( v == Virtues.None )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.SendPacketToServer( new InvokeVirtue( v ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Main ) )]
|
||||
public static void Resync()
|
||||
{
|
||||
UOC.Resync();
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Main ), Parameters = new[] { nameof( ParameterType.Timeout ) } )]
|
||||
public static void Pause( int milliseconds )
|
||||
{
|
||||
Thread.Sleep( milliseconds );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Main ),
|
||||
Parameters = new[] { nameof( ParameterType.String ), nameof( ParameterType.Hue ) } )]
|
||||
public static void SysMessage( string text, int hue = 0x03b2 )
|
||||
{
|
||||
UOC.SystemMessage( text, hue );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Main ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void Info( object obj = null )
|
||||
{
|
||||
int serial = 0;
|
||||
|
||||
if ( obj == null )
|
||||
{
|
||||
serial = UOC.GetTargeSerialAsync( Strings.Target_object___ ).Result;
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
serial = AliasCommands.ResolveSerial( serial != 0 ? serial : obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = UOMath.IsMobile( serial )
|
||||
? Engine.Mobiles.GetMobile( serial )
|
||||
: (Entity) Engine.Items.GetItem( serial );
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return;
|
||||
}
|
||||
|
||||
Thread t = new Thread( () =>
|
||||
{
|
||||
//TODO Window
|
||||
//ObjectInspectorWindow window =
|
||||
// new ObjectInspectorWindow { DataContext = new ObjectInspectorViewModel( entity ) };
|
||||
|
||||
//window.ShowDialog();
|
||||
} )
|
||||
{ IsBackground = true };
|
||||
|
||||
t.SetApartmentState( ApartmentState.STA );
|
||||
t.Start();
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Main ) )]
|
||||
public static void Hotkeys()
|
||||
{
|
||||
HotkeyManager manager = HotkeyManager.GetInstance();
|
||||
|
||||
manager.Enabled = !manager.Enabled;
|
||||
|
||||
UOC.SystemMessage( manager.Enabled ? Strings.Hotkeys_enabled___ : Strings.Hotkeys_disabled___,
|
||||
manager.Enabled ? 0x3F : 36 );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Main ), Parameters = new[] { nameof( ParameterType.OnOff ) } )]
|
||||
public static void WarMode( string onOff = "toggle" )
|
||||
{
|
||||
if ( Engine.Player == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string onOffNormalized = onOff.Trim().ToLower();
|
||||
|
||||
if ( onOffNormalized != "toggle" )
|
||||
{
|
||||
switch ( onOffNormalized )
|
||||
{
|
||||
case "on" when Engine.Player.Status.HasFlag( MobileStatus.WarMode ):
|
||||
case "off" when !Engine.Player.Status.HasFlag( MobileStatus.WarMode ):
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Engine.SendPacketToServer( Engine.Player.Status.HasFlag( MobileStatus.WarMode )
|
||||
? new WarMode( false )
|
||||
: new WarMode( true ) );
|
||||
}
|
||||
|
||||
//[CommandsDisplay( Category = nameof( Strings.Main ),
|
||||
// Parameters = new[] { nameof( ParameterType.String ), nameof( ParameterType.String ) } )]
|
||||
//public static void MessageBox( string title, string body )
|
||||
//{
|
||||
// System.Windows.MessageBox.Show( body, title, MessageBoxButton.OK, MessageBoxImage.Information );
|
||||
//}
|
||||
|
||||
//[CommandsDisplay( Category = nameof( Strings.Main ) )]
|
||||
//public static void PlaySound( object param )
|
||||
//{
|
||||
// switch ( param )
|
||||
// {
|
||||
// case int id:
|
||||
// Engine.SendPacketToClient( new PlaySound( id ) );
|
||||
// break;
|
||||
// case string soundFile:
|
||||
// {
|
||||
// string fullPath = Path.Combine( Engine.StartupPath, "Sounds", soundFile );
|
||||
|
||||
// if ( !File.Exists( fullPath ) )
|
||||
// {
|
||||
// UOC.SystemMessage( Strings.Cannot_find_sound_file___ );
|
||||
// return;
|
||||
// }
|
||||
|
||||
// SoundPlayer soundPlayer = new SoundPlayer( fullPath );
|
||||
// soundPlayer.PlaySync();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Main ) )]
|
||||
public static bool Playing()
|
||||
{
|
||||
MacroManager manager = MacroManager.GetInstance();
|
||||
|
||||
return manager.CurrentMacro != null && ( manager.CurrentMacro.IsRunning || manager.Replay );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Main ), Parameters = new[] { nameof( ParameterType.MacroName ) } )]
|
||||
public static bool Playing( string macroName )
|
||||
{
|
||||
MacroManager manager = MacroManager.GetInstance();
|
||||
|
||||
MacroEntry macro = manager.Items.FirstOrDefault( m => m.Name.Equals( macroName ) );
|
||||
|
||||
return macro != null && ( macro.IsRunning || manager.Replay );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
#region License
|
||||
|
||||
// Copyright (C) 2020 Reetus
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO.Network.Packets;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class MenuCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Menus ),
|
||||
Parameters = new[] { nameof( ParameterType.ItemID ), nameof( ParameterType.Timeout ) } )]
|
||||
public static bool WaitForMenu( int gumpId = 0, int timeout = 30000 )
|
||||
{
|
||||
bool result = UOC.WaitForMenu( gumpId, timeout );
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Timeout___ );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Menus ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.ItemID ), nameof( ParameterType.GumpButtonIndex ),
|
||||
nameof( ParameterType.ItemID ), nameof( ParameterType.Hue )
|
||||
} )]
|
||||
public static void ReplyMenu( int gumpId, int buttonId, int itemId = 0, int hue = 0 )
|
||||
{
|
||||
Engine.SendPacketToServer( new MenuButtonClick( gumpId, -1, buttonId, itemId, hue ) );
|
||||
Engine.SendPacketToClient( new CloseClientGump( (uint) gumpId ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Menu ), Parameters = new[] { nameof( ParameterType.ItemID ) } )]
|
||||
public static void CloseMenu( int gumpId )
|
||||
{
|
||||
if ( Engine.Menus.GetMenu( gumpId, out Menu menu ) )
|
||||
{
|
||||
Engine.SendPacketToServer( new MenuButtonClick( gumpId, menu.Serial, 0 ) );
|
||||
}
|
||||
|
||||
Engine.SendPacketToClient( new CloseClientGump( (uint) gumpId ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Menus ),
|
||||
Parameters = new[] { nameof( ParameterType.ItemID ), nameof( ParameterType.String ) } )]
|
||||
public static bool InMenu( int gumpId, string text )
|
||||
{
|
||||
text = text.ToLower();
|
||||
|
||||
if ( !Engine.Menus.GetMenu( gumpId, out Menu menu ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( menu.Title.ToLower().Contains( text ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return menu.Entries.Any( l => l.Title.ToLower().Contains( text ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Menus ) )]
|
||||
public static bool MenuExists( int gumpId )
|
||||
{
|
||||
return Engine.Menus.GetMenu( gumpId, out _ );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Friends;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class MobileCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool InFriendList( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial != 0 )
|
||||
{
|
||||
bool result = Options.CurrentOptions.Friends.Any( fe => fe.Serial == serial );
|
||||
|
||||
if ( result )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( Options.CurrentOptions.IncludePartyMembersInFriends )
|
||||
{
|
||||
result = Engine.Player?.Party?.Contains( serial ) ?? false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int AddFriend( object obj = null )
|
||||
{
|
||||
int serial = obj != null
|
||||
? AliasCommands.ResolveSerial( obj )
|
||||
: UOC.GetTargeSerialAsync( Strings.Target_new_friend___ ).Result;
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return 0;
|
||||
}
|
||||
|
||||
Mobile m = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( m == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return 0;
|
||||
}
|
||||
|
||||
FriendEntry fe = new FriendEntry { Name = m.Name?.Trim(), Serial = m.Serial };
|
||||
|
||||
if ( !Options.CurrentOptions.Friends.Contains( fe ) )
|
||||
{
|
||||
Engine.Dispatcher?.Invoke( () =>
|
||||
{
|
||||
Options.CurrentOptions.Friends.Add( fe );
|
||||
|
||||
if ( Options.CurrentOptions.RehueFriends )
|
||||
{
|
||||
MainCommands.Resync();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
return m.Serial;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void RemoveFriend( object obj = null )
|
||||
{
|
||||
int serial = obj != null
|
||||
? AliasCommands.ResolveSerial( obj )
|
||||
: UOC.GetTargeSerialAsync( Strings.Target_friend_to_remove___ ).Result;
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
FriendEntry entry = Options.CurrentOptions.Friends.FirstOrDefault( i => i.Serial == serial );
|
||||
|
||||
if ( entry == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.Dispatcher?.Invoke( () =>
|
||||
{
|
||||
bool result = Options.CurrentOptions.Friends.Remove( entry );
|
||||
|
||||
if ( !Options.CurrentOptions.RehueFriends )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.RehueList.Remove( serial );
|
||||
MainCommands.Resync();
|
||||
|
||||
return;
|
||||
} );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Dead( object obj = null )
|
||||
{
|
||||
return GetMobileProperty<bool>( obj, nameof( Mobile.IsDead ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Hidden( object obj = null )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial <= 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
Mobile mobile = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( mobile != null )
|
||||
{
|
||||
return mobile.Status.HasFlag( MobileStatus.Hidden );
|
||||
}
|
||||
|
||||
UOC.SystemMessage( Strings.Mobile_not_found___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
private static T GetMobileProperty<T>( object obj, string propertyName )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial <= 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return default;
|
||||
}
|
||||
|
||||
Mobile mobile = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( mobile == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Mobile_not_found___ );
|
||||
return default;
|
||||
}
|
||||
|
||||
PropertyInfo property = mobile.GetType().GetProperty( propertyName );
|
||||
|
||||
if ( property == null )
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
T val = (T) property.GetValue( mobile );
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int MaxMana( object obj = null )
|
||||
{
|
||||
return GetMobileProperty<int>( obj, nameof( Mobile.ManaMax ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int MaxStam( object obj = null )
|
||||
{
|
||||
return GetMobileProperty<int>( obj, nameof( Mobile.StaminaMax ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int Hits( object obj = null )
|
||||
{
|
||||
return GetMobileProperty<int>( obj, nameof( Mobile.Hits ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ) )]
|
||||
public static int Str()
|
||||
{
|
||||
return GetMobileProperty<int>( "self", nameof( PlayerMobile.Strength ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ) )]
|
||||
public static int Dex()
|
||||
{
|
||||
return GetMobileProperty<int>( "self", nameof( PlayerMobile.Dex ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ) )]
|
||||
public static int Int()
|
||||
{
|
||||
return GetMobileProperty<int>( "self", nameof( PlayerMobile.Int ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int MaxHits( object obj = null )
|
||||
{
|
||||
return GetMobileProperty<int>( obj, nameof( Mobile.HitsMax ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int DiffHits( object obj = null )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial <= 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return 0;
|
||||
}
|
||||
|
||||
Mobile mobile = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( mobile != null )
|
||||
{
|
||||
return mobile.HitsMax - mobile.Hits;
|
||||
}
|
||||
|
||||
UOC.SystemMessage( Strings.Mobile_not_found___ );
|
||||
return 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int Stam( object obj = null )
|
||||
{
|
||||
return GetMobileProperty<int>( obj, nameof( Mobile.Stamina ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static int Mana( object obj = null )
|
||||
{
|
||||
return GetMobileProperty<int>( obj, nameof( Mobile.Mana ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool War( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial != 0 )
|
||||
{
|
||||
return Engine.Mobiles.GetMobile( serial )?.Status.HasFlag( MobileStatus.WarMode ) ?? false;
|
||||
}
|
||||
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ) )]
|
||||
public static int Followers()
|
||||
{
|
||||
return Engine.Player?.Followers ?? 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ) )]
|
||||
public static int MaxFollowers()
|
||||
{
|
||||
return Engine.Player?.FollowersMax ?? 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ) )]
|
||||
public static int Weight()
|
||||
{
|
||||
return Engine.Player?.Weight ?? 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ) )]
|
||||
public static int MaxWeight()
|
||||
{
|
||||
return Engine.Player?.WeightMax ?? 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ) )]
|
||||
public static int DiffWeight()
|
||||
{
|
||||
PlayerMobile player = Engine.Player;
|
||||
|
||||
if ( player == null )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return player.WeightMax - player.Weight;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ) )]
|
||||
public static int Gold()
|
||||
{
|
||||
return Engine.Player?.Gold ?? 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ) )]
|
||||
public static int Luck()
|
||||
{
|
||||
return Engine.Player?.Luck ?? 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ) )]
|
||||
public static int TithingPoints()
|
||||
{
|
||||
return Engine.Player?.TithingPoints ?? 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Poisoned( object obj )
|
||||
{
|
||||
return GetMobileProperty<bool>( obj, nameof( Mobile.IsPoisoned ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool YellowHits( object obj )
|
||||
{
|
||||
return GetMobileProperty<bool>( obj, nameof( Mobile.IsYellowHits ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Paralyzed( object obj )
|
||||
{
|
||||
return GetMobileProperty<bool>( obj, nameof( Mobile.IsFrozen ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Mounted( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
Mobile mobile = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( mobile != null )
|
||||
{
|
||||
return mobile.IsMounted;
|
||||
}
|
||||
|
||||
UOC.SystemMessage( Strings.Mobile_not_found___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool InParty( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial != 0 )
|
||||
{
|
||||
return Engine.Player?.Party != null && Engine.Player.Party.Contains( serial );
|
||||
}
|
||||
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using ClassicAssist.Misc;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.UO;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network.PacketFilter;
|
||||
using ClassicAssist.UO.Network.Packets;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class MovementCommands
|
||||
{
|
||||
private const int MOVEMENT_TIMEOUT = 500;
|
||||
private const int PATHFIND_MAX_DISTANCE = 32;
|
||||
private static bool _forceWalk;
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Movement ),
|
||||
Parameters = new[] { nameof( ParameterType.Direction ) } )]
|
||||
public static bool Walk( string direction )
|
||||
{
|
||||
return Move( direction, false );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Movement ) )]
|
||||
public static void SetForceWalk( bool force )
|
||||
{
|
||||
UOC.SetForceWalk( force );
|
||||
UOC.SystemMessage( force ? Strings.Force_Walk_On : Strings.Force_Walk_Off );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Movement ) )]
|
||||
public static void ToggleForceWalk()
|
||||
{
|
||||
_forceWalk = !_forceWalk;
|
||||
|
||||
UOC.SetForceWalk( _forceWalk );
|
||||
UOC.SystemMessage( _forceWalk ? Strings.Force_Walk_On : Strings.Force_Walk_Off );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Movement ),
|
||||
Parameters = new[] { nameof( ParameterType.Direction ) } )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { nameof( Direction ) } )]
|
||||
public static void Turn( string direction )
|
||||
{
|
||||
Direction directionEnum = Utility.GetEnumValueByName<Direction>( direction );
|
||||
|
||||
if ( Engine.Player.Direction == directionEnum )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.Move( directionEnum, false );
|
||||
UOC.WaitForIncomingPacket( new PacketFilterInfo( 22 ), MOVEMENT_TIMEOUT );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Movement ),
|
||||
Parameters = new[] { nameof( ParameterType.Direction ) } )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { nameof( Direction ) } )]
|
||||
public static bool Run( string direction )
|
||||
{
|
||||
return Move( direction, true );
|
||||
}
|
||||
|
||||
private static bool Move( string direction, bool run )
|
||||
{
|
||||
Direction directionEnum = Utility.GetEnumValueByName<Direction>( direction );
|
||||
|
||||
if ( directionEnum == Direction.Invalid )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
bool result = Engine.Move( directionEnum, run );
|
||||
UOC.WaitForIncomingPacket( new PacketFilterInfo( 22 ), MOVEMENT_TIMEOUT );
|
||||
return result;
|
||||
}
|
||||
catch ( IndexOutOfRangeException )
|
||||
{
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Movement ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.XCoordinate ), nameof( ParameterType.YCoordinate ),
|
||||
nameof( ParameterType.ZCoordinate )
|
||||
} )]
|
||||
public static void Pathfind( int x, int y, int z )
|
||||
{
|
||||
int distance = Math.Max( Math.Abs( x - Engine.Player?.X ?? x ), Math.Abs( y - Engine.Player?.Y ?? y ) );
|
||||
|
||||
if ( distance > PATHFIND_MAX_DISTANCE )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Maximum_distance_exceeded_ );
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.SendPacketToClient( new Pathfind( x, y, z ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Movement ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.SerialOrAlias )
|
||||
} )]
|
||||
public static void Pathfind( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Entity_not_found___ );
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = UOMath.IsMobile( serial )
|
||||
? (Entity) Engine.Mobiles.GetMobile( serial )
|
||||
: Engine.Items.GetItem( serial );
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Entity_not_found___ );
|
||||
return;
|
||||
}
|
||||
|
||||
Pathfind( entity.X, entity.Y, entity.Z );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network.PacketFilter;
|
||||
using ClassicAssist.UO.Network.Packets;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class MsgCommands
|
||||
{
|
||||
private const int DEFAULT_SPEAK_HUE = 34;
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Messages ),
|
||||
Parameters = new[] { nameof( ParameterType.String ), nameof( ParameterType.Hue ) } )]
|
||||
public static void Msg( string message, int hue = DEFAULT_SPEAK_HUE )
|
||||
{
|
||||
UOC.Speak( message, hue );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Messages ),
|
||||
Parameters = new[] { nameof( ParameterType.String ) } )]
|
||||
public static void YellMsg( string message )
|
||||
{
|
||||
UOC.Speak( message, DEFAULT_SPEAK_HUE, JournalSpeech.Yell );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Messages ),
|
||||
Parameters = new[] { nameof( ParameterType.String ) } )]
|
||||
public static void WhisperMsg( string message )
|
||||
{
|
||||
UOC.Speak( message, DEFAULT_SPEAK_HUE, JournalSpeech.Whisper );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Messages ),
|
||||
Parameters = new[] { nameof( ParameterType.String ) } )]
|
||||
public static void EmoteMsg( string message )
|
||||
{
|
||||
UOC.Speak( message, DEFAULT_SPEAK_HUE, JournalSpeech.Emote );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Messages ),
|
||||
Parameters = new[] { nameof( ParameterType.String ) } )]
|
||||
public static void GuildMsg( string message )
|
||||
{
|
||||
UOC.Speak( message, DEFAULT_SPEAK_HUE, JournalSpeech.Guild );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Messages ),
|
||||
Parameters = new[] { nameof( ParameterType.String ) } )]
|
||||
public static void AllyMsg( string message )
|
||||
{
|
||||
UOC.Speak( message, DEFAULT_SPEAK_HUE, JournalSpeech.Alliance );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Messages ),
|
||||
Parameters = new[] { nameof( ParameterType.String ) } )]
|
||||
public static void PartyMsg( string message )
|
||||
{
|
||||
UOC.PartyMessage( message );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Messages ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.String ), nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.Hue )
|
||||
} )]
|
||||
public static void HeadMsg( string message, object obj = null, int hue = DEFAULT_SPEAK_HUE )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
UOC.OverheadMessage( message, hue, serial );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Messages ),
|
||||
Parameters = new[] { nameof( ParameterType.String ) } )]
|
||||
public static void PromptMsg( string message )
|
||||
{
|
||||
Engine.SendPacketToServer( new UnicodePromptResponse( Engine.LastPromptSerial, Engine.LastPromptID,
|
||||
message ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Messages ),
|
||||
Parameters = new[] { nameof( ParameterType.Timeout ) } )]
|
||||
public static bool WaitForPrompt( int timeout )
|
||||
{
|
||||
PacketFilterInfo pfi = new PacketFilterInfo( 0xC2 );
|
||||
|
||||
PacketWaitEntry packetWaitEntry = Engine.PacketWaitEntries.Add( pfi, PacketDirection.Incoming, true );
|
||||
|
||||
try
|
||||
{
|
||||
bool result = packetWaitEntry.Lock.WaitOne( timeout );
|
||||
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Engine.PacketWaitEntries.Remove( packetWaitEntry );
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Messages ) )]
|
||||
public static void CancelPrompt()
|
||||
{
|
||||
Engine.SendPacketToServer( new UnicodePromptCancel( Engine.LastPromptSerial, Engine.LastPromptID ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Messages ),
|
||||
Parameters = new[] { nameof( ParameterType.String ) } )]
|
||||
public static void ChatMsg( string message )
|
||||
{
|
||||
UOC.ChatMsg( message );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class NotorietyCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Criminal( object obj )
|
||||
{
|
||||
return CheckNotoriety( obj, Notoriety.Criminal );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Gray( object obj )
|
||||
{
|
||||
return CheckNotoriety( obj, Notoriety.Attackable );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Ally( object obj )
|
||||
{
|
||||
return CheckNotoriety( obj, Notoriety.Ally );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Enemy( object obj )
|
||||
{
|
||||
return CheckNotoriety( obj, Notoriety.Enemy );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Invulnerable( object obj )
|
||||
{
|
||||
return CheckNotoriety( obj, Notoriety.Invulnerable );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Innocent( object obj )
|
||||
{
|
||||
return CheckNotoriety( obj, Notoriety.Innocent );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Murderer( object obj )
|
||||
{
|
||||
return CheckNotoriety( obj, Notoriety.Murderer );
|
||||
}
|
||||
|
||||
private static bool CheckNotoriety( object obj, Notoriety notoriety )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
Mobile m = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( m == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
return m.Notoriety == notoriety;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,602 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Abilities;
|
||||
using ClassicAssist.Misc;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network;
|
||||
using ClassicAssist.UO.Network.Packets;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class ObjectCommands
|
||||
{
|
||||
public static List<int> IgnoreList { get; set; } = new List<int>();
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void IgnoreObject( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !IgnoreList.Contains( serial ) )
|
||||
{
|
||||
IgnoreList.Add( serial );
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ) )]
|
||||
public static void ClearIgnoreList()
|
||||
{
|
||||
IgnoreList.Clear();
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void UseObject( object obj, bool skipQueue = false )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ActionPacketQueue.EnqueueActionPacket( new UseObject( serial ),
|
||||
skipQueue ? QueuePriority.Immediate : QueuePriority.Low );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.Hue ),
|
||||
nameof( ParameterType.SerialOrAlias )
|
||||
} )]
|
||||
public static void UseType( object type, int hue = -1, object container = null )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( type );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( container == null )
|
||||
{
|
||||
container = Engine.Player?.Backpack?.Serial;
|
||||
}
|
||||
|
||||
int containerSerial = AliasCommands.ResolveSerial( container );
|
||||
|
||||
if ( !Engine.Items.GetItem( containerSerial, out Item containerItem ) )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_container___ );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Item useItem = hue == -1
|
||||
? containerItem.Container?.SelectEntity( i => i.ID == serial )
|
||||
: containerItem.Container?.SelectEntity( i => i.ID == serial && i.Hue == hue );
|
||||
|
||||
if ( useItem == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !AbilitiesManager.GetInstance().CheckHands( useItem.Serial ) )
|
||||
{
|
||||
Engine.SendPacketToServer( new UseObject( useItem.Serial ) );
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void UseTargetedItem( object item, object target )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( item );
|
||||
int targetSerial = AliasCommands.ResolveSerial( target );
|
||||
|
||||
if ( serial == 0 || targetSerial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.SendPacketToServer( new UseTargetedItem( serial, targetSerial ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.ItemID ), nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.Hue )
|
||||
} )]
|
||||
public static int CountType( int graphic, object source = null, int hue = -1 )
|
||||
{
|
||||
if ( source == null )
|
||||
{
|
||||
source = "backpack";
|
||||
}
|
||||
|
||||
int sourceSerial = AliasCommands.ResolveSerial( source );
|
||||
|
||||
Item countainerItem = Engine.Items.GetItem( sourceSerial );
|
||||
|
||||
if ( countainerItem?.Container == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_container___ );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Item[] matches =
|
||||
countainerItem.Container.SelectEntities( i => i.ID == graphic && ( hue == -1 || i.Hue == hue ) );
|
||||
|
||||
return matches?.Sum( i => i.Count ) ?? 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.ItemID ), nameof( ParameterType.Hue ), nameof( ParameterType.Range )
|
||||
} )]
|
||||
public static int CountTypeGround( int graphic, int hue = -1, int range = -1 )
|
||||
{
|
||||
IEnumerable<Item> matches = Engine.Items.Where( i =>
|
||||
i.ID == graphic && ( hue == -1 || hue == i.ID ) && ( range == -1 || i.Distance <= range ) );
|
||||
|
||||
int count = matches.Sum( match => match.Count );
|
||||
|
||||
if ( count > 0 )
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
IEnumerable<Mobile> mobileMatches = Engine.Mobiles.Where( i =>
|
||||
i.ID == graphic && ( hue == -1 || hue == i.ID ) && ( range == -1 || i.Distance <= range ) );
|
||||
|
||||
count += mobileMatches.Count();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.ItemID ), nameof( ParameterType.Range ),
|
||||
nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.Hue )
|
||||
} )]
|
||||
public static bool FindType( int graphic, int range = -1, object findLocation = null, int hue = -1 )
|
||||
{
|
||||
int owner = 0;
|
||||
|
||||
if ( findLocation != null )
|
||||
{
|
||||
owner = AliasCommands.ResolveSerial( findLocation );
|
||||
}
|
||||
|
||||
Entity entity;
|
||||
|
||||
bool Predicate( Entity i )
|
||||
{
|
||||
return i.ID == graphic && ( hue == -1 || i.Hue == hue ) && !IgnoreList.Contains( i.Serial );
|
||||
}
|
||||
|
||||
if ( owner != 0 )
|
||||
{
|
||||
entity = Engine.Items.SelectEntities( i => Predicate( i ) && i.IsDescendantOf( owner, range ) )
|
||||
?.FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
entity =
|
||||
(Entity) Engine.Mobiles
|
||||
.SelectEntities( i => Predicate( i ) && ( range == -1 || i.Distance < range ) )
|
||||
?.FirstOrDefault() ?? Engine.Items.SelectEntities( i =>
|
||||
Predicate( i ) && ( range == -1 || i.Distance < range ) && i.Owner == 0 )?.FirstOrDefault();
|
||||
}
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
AliasCommands.UnsetAlias( "found" );
|
||||
return false;
|
||||
}
|
||||
|
||||
AliasCommands.SetMacroAlias( "found", entity.Serial );
|
||||
|
||||
if ( MacroManager.QuietMode )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
UOC.SystemMessage( string.Format( Strings.Object___0___updated___, "found" ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.Range ),
|
||||
nameof( ParameterType.SerialOrAlias )
|
||||
} )]
|
||||
public static bool FindObject( object obj, int range = -1, object findLocation = null )
|
||||
{
|
||||
int owner = 0;
|
||||
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( findLocation != null )
|
||||
{
|
||||
owner = AliasCommands.ResolveSerial( findLocation );
|
||||
}
|
||||
|
||||
Entity entity;
|
||||
|
||||
bool Predicate( Entity i )
|
||||
{
|
||||
return i.Serial == serial;
|
||||
}
|
||||
|
||||
if ( owner != 0 )
|
||||
{
|
||||
entity = Engine.Items.SelectEntities( i => Predicate( i ) && i.IsDescendantOf( owner, range ) )
|
||||
?.FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
entity =
|
||||
(Entity) Engine.Mobiles
|
||||
.SelectEntities( i => Predicate( i ) && ( range == -1 || i.Distance < range ) )
|
||||
?.FirstOrDefault() ?? Engine.Items.SelectEntities( i =>
|
||||
Predicate( i ) && ( range == -1 || i.Distance < range ) && i.Owner == 0 )?.FirstOrDefault();
|
||||
}
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
AliasCommands.UnsetAlias( "found" );
|
||||
return false;
|
||||
}
|
||||
|
||||
AliasCommands.SetMacroAlias( "found", entity.Serial );
|
||||
|
||||
if ( MacroManager.QuietMode )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
UOC.SystemMessage( string.Format( Strings.Object___0___updated___, "found" ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.SerialOrAlias ),
|
||||
nameof( ParameterType.Amount ), nameof( ParameterType.XCoordinate ),
|
||||
nameof( ParameterType.YCoordinate )
|
||||
} )]
|
||||
public static void MoveItem( object item, object destination, int amount = -1, int x = -1, int y = -1 )
|
||||
{
|
||||
int itemSerial = AliasCommands.ResolveSerial( item );
|
||||
|
||||
if ( itemSerial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
Item itemObj = Engine.Items.GetItem( itemSerial );
|
||||
|
||||
if ( itemObj == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( amount == -1 )
|
||||
{
|
||||
amount = itemObj.Count;
|
||||
}
|
||||
|
||||
int containerSerial = AliasCommands.ResolveSerial( destination );
|
||||
|
||||
if ( containerSerial == 0 )
|
||||
{
|
||||
//TODO
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
ActionPacketQueue.EnqueueDragDrop( itemSerial, amount, containerSerial, QueuePriority.Low, false, true,
|
||||
false, x, y );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.XCoordinateOffset ),
|
||||
nameof( ParameterType.YCoordinateOffset ), nameof( ParameterType.ZCoordinateOffset ),
|
||||
nameof( ParameterType.Amount )
|
||||
} )]
|
||||
public static void MoveItemOffset( object obj, int xOffset, int yOffset, int zOffset, int amount = -1 )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerMobile player = Engine.Player;
|
||||
|
||||
if ( player == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int x = player.X + xOffset;
|
||||
int y = player.Y + yOffset;
|
||||
int z = player.Z + zOffset;
|
||||
|
||||
ActionPacketQueue.EnqueueDragDropGround( serial, amount, x, y, z );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.ItemID ), nameof( ParameterType.SerialOrAlias ),
|
||||
nameof( ParameterType.XCoordinateOffset ), nameof( ParameterType.YCoordinateOffset ),
|
||||
nameof( ParameterType.ZCoordinateOffset ), nameof( ParameterType.Amount )
|
||||
} )]
|
||||
public static bool MoveTypeOffset( int id, object findLocation, int xOffset, int yOffset, int zOffset,
|
||||
int amount = -1 )
|
||||
{
|
||||
if ( findLocation == null ||
|
||||
( (string) findLocation ).Equals( "ground", StringComparison.InvariantCultureIgnoreCase ) )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_container___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
int owner = AliasCommands.ResolveSerial( findLocation );
|
||||
|
||||
bool Predicate( Item i )
|
||||
{
|
||||
return i.ID == id && i.IsDescendantOf( owner );
|
||||
}
|
||||
|
||||
Item entity = Engine.Items.SelectEntities( Predicate )?.FirstOrDefault();
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
PlayerMobile player = Engine.Player;
|
||||
|
||||
if ( player == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int x = player.X + xOffset;
|
||||
int y = player.Y + yOffset;
|
||||
int z = player.Z + zOffset;
|
||||
|
||||
ActionPacketQueue.EnqueueDragDropGround( entity.Serial, amount, x, y, z );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.ItemID ), nameof( ParameterType.SerialOrAlias ),
|
||||
nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.XCoordinate ),
|
||||
nameof( ParameterType.YCoordinate ), nameof( ParameterType.ZCoordinate ),
|
||||
nameof( ParameterType.Hue ), nameof( ParameterType.Amount )
|
||||
} )]
|
||||
public static void MoveType( int id, object sourceContainer, object destinationContainer, int x = -1,
|
||||
int y = -1, int z = 0, int hue = -1, int amount = -1 )
|
||||
{
|
||||
int sourceSerial = AliasCommands.ResolveSerial( sourceContainer );
|
||||
|
||||
if ( sourceSerial == -1 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_source_container___ );
|
||||
return;
|
||||
}
|
||||
|
||||
int destinationSerial;
|
||||
|
||||
if ( destinationContainer is int destSerial )
|
||||
{
|
||||
destinationSerial = destSerial;
|
||||
}
|
||||
else
|
||||
{
|
||||
destinationSerial = AliasCommands.ResolveSerial( destinationContainer );
|
||||
}
|
||||
|
||||
Item sourceItem = Engine.Items.GetItem( sourceSerial );
|
||||
|
||||
if ( sourceItem == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( sourceItem.Container == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_container___ );
|
||||
return;
|
||||
}
|
||||
|
||||
Item entity = sourceItem.Container.SelectEntities( i => i.ID == id && ( hue == -1 || i.Hue == hue ) )
|
||||
?.FirstOrDefault();
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( amount == -1 )
|
||||
{
|
||||
amount = entity.Count;
|
||||
}
|
||||
|
||||
if ( amount > entity.Count )
|
||||
{
|
||||
amount = entity.Count;
|
||||
}
|
||||
|
||||
if ( destinationSerial == -1 )
|
||||
{
|
||||
ActionPacketQueue.EnqueueDragDropGround( entity.Serial, amount, x, y, z );
|
||||
}
|
||||
else
|
||||
{
|
||||
ActionPacketQueue.EnqueueDragDrop( entity.Serial, amount, destinationSerial );
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.Layer ), nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool UseLayer( object layer, object obj = null )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 || !UOMath.IsMobile( serial ) )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
Layer layerValue = Layer.Invalid;
|
||||
|
||||
switch ( layer )
|
||||
{
|
||||
case string s:
|
||||
layerValue = Utility.GetEnumValueByName<Layer>( s );
|
||||
break;
|
||||
case int i:
|
||||
layerValue = (Layer) i;
|
||||
break;
|
||||
case Layer l:
|
||||
layerValue = l;
|
||||
break;
|
||||
}
|
||||
|
||||
Mobile mobile = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( mobile == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Mobile_not_found___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
int layerSerial = mobile.GetLayer( layerValue );
|
||||
|
||||
if ( layerSerial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
UseObject( layerSerial );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool InIgnoreList( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial > 0 )
|
||||
{
|
||||
return IgnoreList.Contains( serial );
|
||||
}
|
||||
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.Hue ) } )]
|
||||
public static void Rehue( object obj, int hue )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial > 0 )
|
||||
{
|
||||
if ( hue > 0 )
|
||||
{
|
||||
Engine.RehueList.Add( serial, hue );
|
||||
}
|
||||
else
|
||||
{
|
||||
Engine.RehueList.Remove( serial );
|
||||
}
|
||||
|
||||
if ( UOMath.IsMobile( serial ) )
|
||||
{
|
||||
Mobile m = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( m == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.SendPacketToClient( new MobileIncoming( m, m.Equipment, hue ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Item i = Engine.Items.GetItem( serial );
|
||||
|
||||
if ( i == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.RehueList.CheckItem( i );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System.Linq;
|
||||
using ClassicAssist.Data.Organizer;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class OrganizerCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Agents ) )]
|
||||
public static bool Organizing()
|
||||
{
|
||||
OrganizerManager manager = OrganizerManager.GetInstance();
|
||||
|
||||
bool organizing = manager.Items.Any( o => o.IsRunning() );
|
||||
|
||||
return organizing;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Agents ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.AgentEntryName ), nameof( ParameterType.SerialOrAlias ),
|
||||
nameof( ParameterType.SerialOrAlias )
|
||||
} )]
|
||||
public static void Organizer( string name, object sourceContainer = null, object destinationContainer = null )
|
||||
{
|
||||
OrganizerManager manager = OrganizerManager.GetInstance();
|
||||
|
||||
OrganizerEntry entry = manager.Items.FirstOrDefault( oa => oa.Name.ToLower().Equals( name.ToLower() ) );
|
||||
|
||||
if ( entry == null )
|
||||
{
|
||||
UOC.SystemMessage( string.Format( Strings.Organizer___0___not_found___, name ) );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( sourceContainer != null && destinationContainer != null )
|
||||
{
|
||||
int sourceContainerSerial = AliasCommands.ResolveSerial( sourceContainer );
|
||||
int destinatinContainerSerial = AliasCommands.ResolveSerial( destinationContainer );
|
||||
|
||||
manager.Organize( entry, sourceContainerSerial, destinatinContainerSerial ).Wait();
|
||||
}
|
||||
else
|
||||
{
|
||||
manager.Organize( entry ).Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO.Network.PacketFilter;
|
||||
using ClassicAssist.UO.Network.Packets;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class PropertiesCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Properties ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.Timeout ) } )]
|
||||
public static bool WaitForProperties( object obj, int timeout )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
PacketFilterInfo pfi = new PacketFilterInfo( 0xD6,
|
||||
new[] { PacketFilterConditions.IntAtPositionCondition( serial, 5 ) } );
|
||||
|
||||
PacketWaitEntry we = Engine.PacketWaitEntries.Add( pfi, PacketDirection.Incoming, true );
|
||||
|
||||
Engine.SendPacketToServer( new BatchQueryProperties( serial ) );
|
||||
|
||||
try
|
||||
{
|
||||
bool result = we.Lock.WaitOne( timeout );
|
||||
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Engine.PacketWaitEntries.Remove( we );
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Properties ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.String ) } )]
|
||||
public static bool Property( object obj, string value )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) Engine.Items.GetItem( serial ) ?? Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( entity?.Properties != null )
|
||||
{
|
||||
return entity.Properties.Any( pe => pe.Text.ToLower().Contains( value.ToLower() ) );
|
||||
}
|
||||
|
||||
UOC.SystemMessage( Strings.Item_properties_null_or_not_loaded___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Properties ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.String ),
|
||||
nameof( ParameterType.IntegerValue )
|
||||
} )]
|
||||
public static T PropertyValue<T>( object obj, string property, int argument = 0 )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return default;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) Engine.Items.GetItem( serial ) ?? Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( entity?.Properties != null )
|
||||
{
|
||||
Property p = entity.Properties.FirstOrDefault( pe => pe.Text.ToLower().Contains( property.ToLower() ) );
|
||||
|
||||
if ( p == null )
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
if ( p.Arguments[0].Trim().Equals( string.Empty ) )
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
return (T) Convert.ChangeType( p?.Arguments?[argument], typeof( T ) );
|
||||
}
|
||||
|
||||
UOC.SystemMessage( Strings.Item_properties_null_or_not_loaded___ );
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Regions;
|
||||
using ClassicAssist.Misc;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class RegionCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Actions ),
|
||||
Parameters = new[] { nameof( ParameterType.String ), nameof( ParameterType.SerialOrAlias ) } )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { nameof( RegionAttributes ) } )]
|
||||
public static bool InRegion( string attribute, object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) Engine.Items.GetItem( serial ) ?? Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
RegionAttributes attr = Utility.GetEnumValueByName<RegionAttributes>( attribute );
|
||||
|
||||
Region region = entity.GetRegion();
|
||||
|
||||
return region != null && region.Attributes.HasFlag( attr );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Skills;
|
||||
using ClassicAssist.Misc;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network.Packets;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class SkillCommands
|
||||
{
|
||||
[CommandsDisplay( Category = nameof( Strings.Skills ),
|
||||
Parameters = new[] { nameof( ParameterType.SkillName ) } )]
|
||||
public static void UseSkill( string skill )
|
||||
{
|
||||
int id = GetSkillID( skill );
|
||||
|
||||
if ( id == -1 )
|
||||
{
|
||||
UOC.SystemMessage( string.Format( Strings.Invalid_skill_name___0__, skill ) );
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.SendPacketToServer( new UseSkill( id ) );
|
||||
}
|
||||
|
||||
private static int GetSkillID( string skill )
|
||||
{
|
||||
skill = skill.ToLower().Replace( '_', ' ' );
|
||||
|
||||
KeyValuePair<int, SkillData> sk = UO.Data.Skills.GetSkills()
|
||||
.FirstOrDefault( s => s.Value.Name.ToLower().Equals( skill ) );
|
||||
|
||||
if ( sk.Value == null )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sk.Key;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Skills ),
|
||||
Parameters = new[] { nameof( ParameterType.SkillName ) } )]
|
||||
public static double Skill( string name )
|
||||
{
|
||||
SkillManager manager = SkillManager.GetInstance();
|
||||
|
||||
SkillEntry s = manager.Items.FirstOrDefault( se => se.Skill.Name.ToLower().Contains( name.ToLower() ) );
|
||||
|
||||
return s?.Value ?? 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Skills ),
|
||||
Parameters = new[] { nameof( ParameterType.SkillName ) } )]
|
||||
public static double SkillCap( string name )
|
||||
{
|
||||
SkillManager manager = SkillManager.GetInstance();
|
||||
|
||||
SkillEntry s = manager.Items.FirstOrDefault( se => se.Skill.Name.ToLower().Contains( name.ToLower() ) );
|
||||
|
||||
return s?.Cap ?? 0;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Skills ),
|
||||
Parameters = new[] { nameof( ParameterType.SkillName ) } )]
|
||||
public static string SkillState( string name )
|
||||
{
|
||||
SkillManager manager = SkillManager.GetInstance();
|
||||
|
||||
SkillEntry s = manager.Items.FirstOrDefault( se => se.Skill.Name.ToLower().Contains( name.ToLower() ) );
|
||||
|
||||
return s?.LockStatus.ToString().ToLower() ?? "up";
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Skills ),
|
||||
Parameters = new[] { nameof( ParameterType.SkillName ), nameof( ParameterType.UpDownLocked ) } )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { null, nameof( LockStatus ) } )]
|
||||
public static void SetSkill( string skill, string status )
|
||||
{
|
||||
SkillManager manager = SkillManager.GetInstance();
|
||||
|
||||
SkillEntry s = manager.Items.FirstOrDefault( se => se.Skill.Name.ToLower().Contains( skill.ToLower() ) );
|
||||
|
||||
if ( s == null )
|
||||
{
|
||||
UOC.SystemMessage( string.Format( Strings.Invalid_skill_name___0__, skill ) );
|
||||
return;
|
||||
}
|
||||
|
||||
LockStatus ls = Utility.GetEnumValueByName<LockStatus>( status );
|
||||
|
||||
UOC.ChangeSkillLock( s, ls );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Skills ),
|
||||
Parameters = new[] { nameof( ParameterType.String ), nameof( ParameterType.UpDownLocked ) } )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { nameof( StatType ), nameof( LockStatus ) } )]
|
||||
public static void SetStatus( string stat, string lockStatus )
|
||||
{
|
||||
StatType st = Utility.GetEnumValueByName<StatType>( stat );
|
||||
LockStatus ls = Utility.GetEnumValueByName<LockStatus>( lockStatus );
|
||||
|
||||
UOC.ChangeStatLock( st, ls );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using System.Diagnostics;
|
||||
using ClassicAssist.Data.Spells;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class SpellCommands
|
||||
{
|
||||
private static readonly SpellManager _manager = SpellManager.GetInstance();
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Spells ),
|
||||
Parameters = new[] { nameof( ParameterType.SpellName ) } )]
|
||||
public static void Cast( string name )
|
||||
{
|
||||
_manager?.CastSpell( name );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Spells ),
|
||||
Parameters = new[] { nameof( ParameterType.SpellName ), nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static bool Cast( string name, object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return false;
|
||||
}
|
||||
|
||||
SpellData sd = _manager.GetSpellData( name ) ?? _manager.GetMasteryData( name );
|
||||
|
||||
if ( sd == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Unknown_spell___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Debugging only
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
//
|
||||
|
||||
_manager.CastSpell( sd.ID );
|
||||
|
||||
int index = 0;
|
||||
bool result;
|
||||
|
||||
if ( Options.CurrentOptions.UseExperimentalFizzleDetection )
|
||||
{
|
||||
( index, result ) = UOC.WaitForTargetOrFizzle( sd.Timeout + 1000 );
|
||||
}
|
||||
else
|
||||
{
|
||||
result = TargetCommands.WaitForTarget( sd.Timeout + 500 );
|
||||
}
|
||||
|
||||
if ( index == 0 && !result )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Timeout___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Debugging only
|
||||
sw.Stop();
|
||||
|
||||
if ( Options.CurrentOptions.Debug )
|
||||
{
|
||||
UOC.SystemMessage(
|
||||
$"Target received in {sw.ElapsedMilliseconds}ms, Spell data timeout: {sd.Timeout}ms" );
|
||||
}
|
||||
//
|
||||
|
||||
TargetCommands.Target( serial );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,603 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Regions;
|
||||
using ClassicAssist.Data.Targeting;
|
||||
using ClassicAssist.Misc;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network.Packets;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using TargetTypeEnum = ClassicAssist.UO.Data.TargetType;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class TargetCommands
|
||||
{
|
||||
public enum TargetExistsType
|
||||
{
|
||||
Any,
|
||||
Beneficial,
|
||||
Harmful,
|
||||
Neutral
|
||||
}
|
||||
|
||||
public enum TargetResourceType
|
||||
{
|
||||
Ore,
|
||||
Sand,
|
||||
Wood,
|
||||
Graves,
|
||||
Red_Mushrooms
|
||||
}
|
||||
|
||||
private static readonly ushort[] _treeTiles =
|
||||
{
|
||||
0x0CCA, 0x0CCB, 0x0CCC, 0x0CCD, 0x0CD0, 0x0CD3, 0x0CD6, 0x0CD8, 0x0CDA, 0x0CDD, 0x0CE0, 0x0CE3, 0x0CE6,
|
||||
0x0D41, 0x0D42, 0x0D43, 0x0D44, 0x0D57, 0x0D58, 0x0D59, 0x0D5A, 0x0D5B, 0x0D6E, 0x0D6F, 0x0D70, 0x0D71,
|
||||
0x0D72, 0x0D84, 0x0D85, 0x0D86, 0x0D94, 0x0D98, 0x0D9C, 0x0DA0, 0x0DA4, 0x0DA8, 0x0C9E, 0x0CA8, 0x0CAA,
|
||||
0x0CAB, 0x0CC9, 0x0CF8, 0x0CFB, 0x0CFE, 0x0D01, 0x12B6, 0x12B7, 0x12B8, 0x12B9, 0x12BA, 0x12BB, 0x12BC,
|
||||
0x12BD
|
||||
};
|
||||
|
||||
private static readonly ushort[] _caveTiles =
|
||||
{
|
||||
1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349, 1350, 1351, 1352, 1353, 1354, 1355,
|
||||
1356, 1357, 1358, 1359, 1361, 1362, 1363
|
||||
};
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ) )]
|
||||
public static void CancelTarget()
|
||||
{
|
||||
Engine.SendPacketToServer( new Target( TargetTypeEnum.Object, -1, TargetFlags.Cancel, -1, -1, -1, 0, 0,
|
||||
true ) );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ), Parameters = new[] { nameof( ParameterType.Timeout ) } )]
|
||||
public static bool WaitForTarget( int timeout = 5000 )
|
||||
{
|
||||
return UOC.WaitForTarget( timeout );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void Target( object obj, bool checkRange = false, bool useQueue = false )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( checkRange && UOMath.IsMobile( serial ) && Engine.TargetExists )
|
||||
{
|
||||
Mobile mobile = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( mobile != null )
|
||||
{
|
||||
if ( mobile.Distance > Options.CurrentOptions.RangeCheckLastTargetAmount )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Target_out_of_range__try_again___ );
|
||||
UOC.ResendTargetToClient();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UOC.SystemMessage( Strings.Target_out_of_range__try_again___ );
|
||||
UOC.ResendTargetToClient();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( Options.CurrentOptions.PreventTargetingInnocentsInGuardzone && Engine.TargetExists )
|
||||
{
|
||||
Mobile mobile = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( mobile != null && mobile.Notoriety == Notoriety.Innocent &&
|
||||
mobile.Serial != Engine.Player?.Serial && Engine.TargetFlags == TargetFlags.Harmful &&
|
||||
mobile.GetRegion().Attributes.HasFlag( RegionAttributes.Guarded ) )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Target_blocked____try_again___ );
|
||||
UOC.ResendTargetToClient();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( useQueue && !Engine.TargetExists )
|
||||
{
|
||||
MsgCommands.HeadMsg( Strings.Target_Queued, Engine.Player?.Serial );
|
||||
Engine.LastTargetQueue.Enqueue( obj );
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.SendPacketToServer( new Target( TargetTypeEnum.Object, -1, TargetFlags.None, serial, -1, -1, -1, 0,
|
||||
true ) );
|
||||
Engine.TargetExists = false;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.String ) } )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { null, nameof( TargetResourceType ) } )]
|
||||
public static void TargetByResource( object toolObj, string resourceType )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( toolObj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TargetResourceType resourceEnum = Utility.GetEnumValueByName<TargetResourceType>( resourceType );
|
||||
|
||||
Engine.SendPacketToServer( new TargetByResource( serial, (int) resourceEnum ) );
|
||||
}
|
||||
catch ( InvalidOperationException )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.IntegerValue ),
|
||||
nameof( ParameterType.Boolean ), nameof( ParameterType.ItemID )
|
||||
} )]
|
||||
public static void TargetTileRelative( object obj, int distance, bool reverse = false, int itemID = 0 )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Mobile_not_found___ );
|
||||
return;
|
||||
}
|
||||
|
||||
int x = entity.X;
|
||||
int y = entity.Y;
|
||||
|
||||
int offsetX = 0;
|
||||
int offsetY = 0;
|
||||
|
||||
// TODO
|
||||
Direction direction = (Direction) ( (int) entity.Direction & ~0x80 );
|
||||
|
||||
switch ( direction )
|
||||
{
|
||||
case Direction.North:
|
||||
offsetY = -1;
|
||||
break;
|
||||
case Direction.Northeast:
|
||||
offsetY = -1;
|
||||
offsetX = 1;
|
||||
break;
|
||||
case Direction.East:
|
||||
offsetX = 1;
|
||||
break;
|
||||
case Direction.Southeast:
|
||||
offsetX = 1;
|
||||
offsetY = 1;
|
||||
break;
|
||||
case Direction.South:
|
||||
offsetY = 1;
|
||||
break;
|
||||
case Direction.Southwest:
|
||||
offsetY = 1;
|
||||
offsetX = -1;
|
||||
break;
|
||||
case Direction.West:
|
||||
offsetX = -1;
|
||||
break;
|
||||
case Direction.Northwest:
|
||||
offsetX = -1;
|
||||
offsetY = -1;
|
||||
break;
|
||||
case Direction.Invalid:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
int totalOffsetX = offsetX * distance;
|
||||
int totalOffsetY = offsetY * distance;
|
||||
|
||||
if ( reverse )
|
||||
{
|
||||
totalOffsetX = -totalOffsetX;
|
||||
totalOffsetY = -totalOffsetY;
|
||||
}
|
||||
|
||||
int destinationX = x + totalOffsetX;
|
||||
int destinationY = y + totalOffsetY;
|
||||
|
||||
( int surfaceZ, int surfaceID ) =
|
||||
MapInfo.GetMapSurface( (int) Engine.Player.Map, destinationX, destinationY );
|
||||
|
||||
if ( itemID == 0 )
|
||||
{
|
||||
itemID = surfaceID;
|
||||
}
|
||||
|
||||
TargetXYZ( destinationX, destinationY, surfaceZ, itemID );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.XCoordinateOffset ), nameof( ParameterType.YCoordinateOffset ),
|
||||
nameof( ParameterType.YCoordinateOffset ), nameof( ParameterType.ItemID )
|
||||
} )]
|
||||
public static void TargetTileOffset( int xOffset, int yOffset, int zOffset, int itemID = 0 )
|
||||
{
|
||||
TargetXYZ( Engine.Player.X + xOffset, Engine.Player.Y + yOffset, Engine.Player.Z + zOffset, itemID );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.XCoordinateOffset ), nameof( ParameterType.YCoordinateOffset ),
|
||||
nameof( ParameterType.YCoordinateOffset ), nameof( ParameterType.ItemID )
|
||||
} )]
|
||||
public static void TargetTileOffsetResource( int xOffset, int yOffset, int zOffset, int itemID = 0 )
|
||||
{
|
||||
int x = Engine.Player.X + xOffset;
|
||||
int y = Engine.Player.Y + yOffset;
|
||||
int z = Engine.Player.Z + zOffset;
|
||||
|
||||
if ( itemID == 0 )
|
||||
{
|
||||
StaticTile[] staticTiles = Statics.GetStatics( (int) Engine.Player.Map, x, y );
|
||||
|
||||
if ( staticTiles != null )
|
||||
{
|
||||
StaticTile selectedStatic = staticTiles.FirstOrDefault( i =>
|
||||
_treeTiles.Contains( i.ID ) || _caveTiles.Contains( i.ID ) ||
|
||||
i.Flags.HasFlag( TileFlags.Wet ) );
|
||||
|
||||
if ( selectedStatic.ID == 0 )
|
||||
{
|
||||
selectedStatic = staticTiles.FirstOrDefault();
|
||||
}
|
||||
|
||||
itemID = selectedStatic.ID;
|
||||
z = selectedStatic.Z;
|
||||
}
|
||||
}
|
||||
|
||||
TargetXYZ( x, y, z, itemID );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.Empty ), nameof( ParameterType.Empty ), nameof( ParameterType.Empty ),
|
||||
nameof( ParameterType.Empty )
|
||||
} )]
|
||||
[CommandsDisplayStringSeeAlso( new[]
|
||||
{
|
||||
nameof( TargetNotoriety ), nameof( TargetBodyType ), nameof( TargetDistance ),
|
||||
nameof( TargetInfliction )
|
||||
} )]
|
||||
public static bool GetEnemy( IEnumerable<string> notorieties, string bodyType = "Any", string distance = "Next",
|
||||
string infliction = "Any" )
|
||||
{
|
||||
TargetNotoriety notoFlags = TargetNotoriety.None;
|
||||
|
||||
foreach ( string noto in notorieties )
|
||||
{
|
||||
if ( Enum.TryParse( noto, true, out TargetNotoriety flag ) )
|
||||
{
|
||||
notoFlags |= flag;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !Enum.TryParse( bodyType, true, out TargetBodyType bt ) )
|
||||
{
|
||||
bt = TargetBodyType.Any;
|
||||
}
|
||||
|
||||
if ( !Enum.TryParse( distance, true, out TargetDistance td ) )
|
||||
{
|
||||
td = TargetDistance.Next;
|
||||
}
|
||||
|
||||
if ( !Enum.TryParse( infliction, true, out TargetInfliction ti ) )
|
||||
{
|
||||
ti = TargetInfliction.Any;
|
||||
}
|
||||
|
||||
return TargetManager.GetInstance().GetEnemy( notoFlags, bt, td, TargetFriendType.None, ti );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.Empty ), nameof( ParameterType.Empty ), nameof( ParameterType.Empty )
|
||||
} )]
|
||||
[CommandsDisplayStringSeeAlso( new[]
|
||||
{
|
||||
nameof( TargetDistance ), nameof( TargetInfliction ), nameof( TargetBodyType )
|
||||
} )]
|
||||
public static bool GetFriendListOnly( string distance = "Next", string targetInfliction = "Any",
|
||||
string bodyType = "Any" )
|
||||
{
|
||||
if ( !Enum.TryParse( distance, true, out TargetDistance td ) )
|
||||
{
|
||||
td = TargetDistance.Next;
|
||||
}
|
||||
|
||||
if ( !Enum.TryParse( targetInfliction, true, out TargetInfliction ti ) )
|
||||
{
|
||||
ti = TargetInfliction.Any;
|
||||
}
|
||||
|
||||
if ( !Enum.TryParse( bodyType, true, out TargetBodyType bt ) )
|
||||
{
|
||||
bt = TargetBodyType.Any;
|
||||
}
|
||||
|
||||
return TargetManager.GetInstance().GetFriend( TargetNotoriety.Any, bt, td, TargetFriendType.Only, ti );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.Empty ), nameof( ParameterType.Empty ), nameof( ParameterType.Empty ),
|
||||
nameof( ParameterType.Empty )
|
||||
} )]
|
||||
[CommandsDisplayStringSeeAlso( new[]
|
||||
{
|
||||
nameof( TargetNotoriety ), nameof( TargetBodyType ), nameof( TargetDistance ),
|
||||
nameof( TargetInfliction )
|
||||
} )]
|
||||
public static bool GetFriend( IEnumerable<string> notorieties, string bodyType = "Any",
|
||||
string distance = "Next", string infliction = "Any" )
|
||||
{
|
||||
TargetNotoriety notoFlags = TargetNotoriety.None;
|
||||
|
||||
foreach ( string noto in notorieties )
|
||||
{
|
||||
if ( Enum.TryParse( noto, true, out TargetNotoriety flag ) )
|
||||
{
|
||||
notoFlags |= flag;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !Enum.TryParse( bodyType, true, out TargetBodyType bt ) )
|
||||
{
|
||||
bt = TargetBodyType.Any;
|
||||
}
|
||||
|
||||
if ( !Enum.TryParse( distance, true, out TargetDistance td ) )
|
||||
{
|
||||
td = TargetDistance.Next;
|
||||
}
|
||||
|
||||
if ( !Enum.TryParse( infliction, true, out TargetInfliction ti ) )
|
||||
{
|
||||
ti = TargetInfliction.Any;
|
||||
}
|
||||
|
||||
return TargetManager.GetInstance().GetFriend( notoFlags, bt, td, TargetFriendType.Include, ti );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[] { nameof( ParameterType.BeneficialHarmfulNeutral ) } )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { nameof( TargetExistsType ) } )]
|
||||
public static bool TargetExists( string targetExistsType = "Any" )
|
||||
{
|
||||
if ( !Enum.TryParse( targetExistsType, out TargetExistsType enumValue ) )
|
||||
{
|
||||
enumValue = TargetExistsType.Any;
|
||||
}
|
||||
|
||||
switch ( enumValue )
|
||||
{
|
||||
case TargetExistsType.Any:
|
||||
|
||||
return Engine.TargetExists;
|
||||
|
||||
case TargetExistsType.Beneficial:
|
||||
|
||||
return Engine.TargetExists && Engine.TargetFlags == TargetFlags.Beneficial;
|
||||
|
||||
case TargetExistsType.Harmful:
|
||||
|
||||
return Engine.TargetExists && Engine.TargetFlags == TargetFlags.Harmful;
|
||||
|
||||
case TargetExistsType.Neutral:
|
||||
|
||||
return Engine.TargetExists && Engine.TargetFlags == TargetFlags.None;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ) )]
|
||||
public static bool WaitingForTarget()
|
||||
{
|
||||
return Engine.WaitingForTarget;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ) )]
|
||||
public static void ClearTargetQueue()
|
||||
{
|
||||
Engine.LastTargetQueue?.Clear();
|
||||
UOC.SystemMessage( Strings.Target_queue_cleared___ );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.Hue ), nameof( ParameterType.Range )
|
||||
} )]
|
||||
public static void TargetType( object obj, int hue = -1, int range = -1 )
|
||||
{
|
||||
int id = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( id == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( Engine.Player?.Backpack == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Error__Cannot_find_player_backpack );
|
||||
return;
|
||||
}
|
||||
|
||||
Item item = Engine.Items.SelectEntity( i =>
|
||||
i.ID == id && ( hue == -1 || i.Hue == hue ) &&
|
||||
i.IsDescendantOf( Engine.Player.Backpack.Serial, range ) );
|
||||
|
||||
if ( item == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return;
|
||||
}
|
||||
|
||||
Target( item.Serial, false, Options.CurrentOptions.QueueLastTarget );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.Hue ), nameof( ParameterType.Range )
|
||||
} )]
|
||||
public static void TargetGround( object obj, int hue = -1, int range = -1 )
|
||||
{
|
||||
int id = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( id == 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity =
|
||||
(Entity) Engine.Items.SelectEntity( i =>
|
||||
i.ID == id && ( hue == -1 || i.Hue == hue ) && ( range == -1 || i.Distance < range ) ) ??
|
||||
Engine.Mobiles.SelectEntity( m =>
|
||||
m.ID == id && ( hue == -1 || m.Hue == hue ) && ( range == -1 || m.Distance < range ) );
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return;
|
||||
}
|
||||
|
||||
Target( entity.Serial, false, Options.CurrentOptions.QueueLastTarget );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void SetEnemy( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial <= 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = Engine.Items.GetItem( serial ) ?? (Entity) Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
TargetManager.GetInstance().SetEnemy( entity );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void SetFriend( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial <= 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = Engine.Items.GetItem( serial ) ?? (Entity) Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
TargetManager.GetInstance().SetFriend( entity );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ) } )]
|
||||
public static void SetLastTarget( object obj )
|
||||
{
|
||||
int serial = AliasCommands.ResolveSerial( obj );
|
||||
|
||||
if ( serial <= 0 )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = Engine.Items.GetItem( serial ) ?? (Entity) Engine.Mobiles.GetMobile( serial );
|
||||
|
||||
if ( entity == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Invalid_or_unknown_object_id );
|
||||
return;
|
||||
}
|
||||
|
||||
TargetManager.GetInstance().SetLastTarget( entity );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ), Parameters = new[] { nameof( ParameterType.Timeout ) } )]
|
||||
public static bool WaitForTargetOrFizzle( int timeout )
|
||||
{
|
||||
( _, bool result ) = UOC.WaitForTargetOrFizzle( timeout );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Target ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.XCoordinate ), nameof( ParameterType.YCoordinate ),
|
||||
nameof( ParameterType.ZCoordinate ), nameof( ParameterType.ItemID )
|
||||
} )]
|
||||
public static void TargetXYZ( int x, int y, int z, int itemID = 0 )
|
||||
{
|
||||
Engine.SendPacketToServer( new Target( TargetTypeEnum.Tile, -1, Engine.TargetFlags, 0, x, y, z, itemID,
|
||||
true ) );
|
||||
Engine.TargetExists = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ClassicAssist.Misc;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class TimerCommands
|
||||
{
|
||||
private static readonly ConcurrentDictionary<string, OffsetStopwatch> _timers =
|
||||
new ConcurrentDictionary<string, OffsetStopwatch>();
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Timers ),
|
||||
Parameters = new[] { nameof( ParameterType.TimerName ) } )]
|
||||
public static void CreateTimer( string name )
|
||||
{
|
||||
OffsetStopwatch timer = new OffsetStopwatch( TimeSpan.Zero );
|
||||
|
||||
_timers.AddOrUpdate( name, t => timer, ( t, o ) => timer );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Timers ),
|
||||
Parameters = new[] { nameof( ParameterType.TimerName ) } )]
|
||||
public static bool TimerExists( string name )
|
||||
{
|
||||
return _timers.ContainsKey( name );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Timers ),
|
||||
Parameters = new[] { nameof( ParameterType.TimerName ) } )]
|
||||
public static void RemoveTimer( string name )
|
||||
{
|
||||
if ( _timers.TryGetValue( name, out OffsetStopwatch sw ) )
|
||||
{
|
||||
sw?.Stop();
|
||||
}
|
||||
|
||||
_timers.TryRemove( name, out _ );
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Timers ),
|
||||
Parameters = new[] { nameof( ParameterType.SerialOrAlias ), nameof( ParameterType.IntegerValue ) } )]
|
||||
public static void SetTimer( string name, int milliseconds = 0 )
|
||||
{
|
||||
if ( !TimerExists( name ) )
|
||||
{
|
||||
CreateTimer( name );
|
||||
}
|
||||
|
||||
if ( _timers.TryGetValue( name, out OffsetStopwatch sw ) )
|
||||
{
|
||||
sw?.Reset( TimeSpan.FromMilliseconds( milliseconds ) );
|
||||
}
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Timers ),
|
||||
Parameters = new[] { nameof( ParameterType.TimerName ) } )]
|
||||
public static long Timer( string name )
|
||||
{
|
||||
return !_timers.ContainsKey( name ) ? 0 : _timers[name].ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Timers ),
|
||||
Parameters = new[] { nameof( ParameterType.TimerName ) } )]
|
||||
public static void TimerMsg( string name )
|
||||
{
|
||||
if ( !_timers.ContainsKey( name ) )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Unknown_timer___ );
|
||||
return;
|
||||
}
|
||||
|
||||
UOC.SystemMessage( _timers[name].ToString() );
|
||||
}
|
||||
|
||||
public static Dictionary<string, OffsetStopwatch> GetAllTimers()
|
||||
{
|
||||
return _timers.ToDictionary( t => t.Key, t => t.Value );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
#region License
|
||||
|
||||
// Copyright (C) 2020 Reetus
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Misc;
|
||||
using ClassicAssist.Shared.Resources;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network.PacketFilter;
|
||||
using ClassicAssist.UO.Network.Packets;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using UOC = ClassicAssist.Shared.UO.Commands;
|
||||
|
||||
namespace ClassicAssist.Data.Macros.Commands
|
||||
{
|
||||
public static class WandCommands
|
||||
{
|
||||
public enum WandTypes
|
||||
{
|
||||
Clumsy,
|
||||
Identification,
|
||||
Heal,
|
||||
Feeblemind,
|
||||
Weaken,
|
||||
Magic_Arrow,
|
||||
Harm,
|
||||
Fireball,
|
||||
Greater_Heal,
|
||||
Lightning,
|
||||
Mana_Drain
|
||||
}
|
||||
|
||||
private static readonly Dictionary<WandTypes, int[]> _wandClilocs = new Dictionary<WandTypes, int[]>
|
||||
{
|
||||
{ WandTypes.Clumsy, new[] { 3002011, 1017326 } },
|
||||
{ WandTypes.Identification, new[] { 1044063, 1017350 } },
|
||||
{ WandTypes.Heal, new[] { 3002014, 1017329 } },
|
||||
{ WandTypes.Feeblemind, new[] { 3002013, 1017327 } },
|
||||
{ WandTypes.Weaken, new[] { 3002018, 1017328 } },
|
||||
{ WandTypes.Magic_Arrow, new[] { 3002015, 1060492 } },
|
||||
{ WandTypes.Harm, new[] { 3002022, 1017334 } },
|
||||
{ WandTypes.Fireball, new[] { 3002028, 1060487 } },
|
||||
{ WandTypes.Greater_Heal, new[] { 3002039, 1017330 } },
|
||||
{ WandTypes.Lightning, new[] { 3002040, 1060491 } },
|
||||
{ WandTypes.Mana_Drain, new[] { 3002041, 1017339 } }
|
||||
};
|
||||
|
||||
private static readonly int[] _wandIds = { 0xDF2, 0xDF3, 0xDF4, 0xDF5 };
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[] { nameof( ParameterType.WandName ), nameof( ParameterType.IntegerValue ) } )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { nameof( WandTypes ) } )]
|
||||
public static bool EquipWand( string wandName, int minimumCharges = -1 )
|
||||
{
|
||||
try
|
||||
{
|
||||
WandTypes wandType = Utility.GetEnumValueByName<WandTypes>( wandName );
|
||||
|
||||
int containerSerial = AliasCommands.ResolveSerial( "backpack" );
|
||||
|
||||
Item[] matches = FindWands( wandType, containerSerial, minimumCharges ).Result;
|
||||
|
||||
if ( matches == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
ActionCommands.EquipItem( matches.First().Serial, Layer.OneHanded );
|
||||
|
||||
return true;
|
||||
}
|
||||
catch ( InvalidOperationException )
|
||||
{
|
||||
UOC.SystemMessage( string.Format( Strings.Invalid_skill_name___0__, wandName ) );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[CommandsDisplay( Category = nameof( Strings.Entity ),
|
||||
Parameters = new[]
|
||||
{
|
||||
nameof( ParameterType.WandName ), nameof( ParameterType.SerialOrAlias ),
|
||||
nameof( ParameterType.IntegerValue )
|
||||
} )]
|
||||
[CommandsDisplayStringSeeAlso( new[] { nameof( WandTypes ) } )]
|
||||
public static bool FindWand( string wandName, object containerSource = null, int minimumCharges = -1 )
|
||||
{
|
||||
try
|
||||
{
|
||||
WandTypes wandType = Utility.GetEnumValueByName<WandTypes>( wandName );
|
||||
|
||||
int containerSerial = AliasCommands.ResolveSerial( containerSource );
|
||||
|
||||
if ( containerSource == null )
|
||||
{
|
||||
containerSerial = -1;
|
||||
}
|
||||
|
||||
Item[] matches = FindWands( wandType, containerSerial, minimumCharges ).Result;
|
||||
|
||||
if ( matches == null )
|
||||
{
|
||||
UOC.SystemMessage( Strings.Cannot_find_item___ );
|
||||
return false;
|
||||
}
|
||||
|
||||
AliasCommands.SetMacroAlias( "found", matches.First().Serial );
|
||||
|
||||
if ( MacroManager.QuietMode )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
UOC.SystemMessage( string.Format( Strings.Object___0___updated___, "found" ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
catch ( InvalidOperationException )
|
||||
{
|
||||
UOC.SystemMessage( string.Format( Strings.Invalid_skill_name___0__, wandName ) );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static async Task<Item[]> FindWands( WandTypes wandType, int containerSerial, int minimumCharges )
|
||||
{
|
||||
if ( !Engine.Features.HasFlag( FeatureFlags.AOS ) )
|
||||
{
|
||||
Item[] allWands = Engine.Items.SelectEntities( i =>
|
||||
_wandIds.Contains( i.ID ) && ( containerSerial == -1 || i.IsDescendantOf( containerSerial ) ) );
|
||||
|
||||
if ( allWands == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ( Item wand in allWands )
|
||||
{
|
||||
Engine.SendPacketToServer( new LookRequest( wand.Serial ) );
|
||||
await UOC.WaitForIncomingPacketFilterAsync(
|
||||
new PacketFilterInfo( 0xBF,
|
||||
new[]
|
||||
{
|
||||
PacketFilterConditions.ShortAtPositionCondition( 0x10, 3 ),
|
||||
PacketFilterConditions.IntAtPositionCondition( wand.Serial, 5 )
|
||||
} ), 2500 );
|
||||
}
|
||||
}
|
||||
|
||||
Item[] matches = Engine.Items.SelectEntities( i =>
|
||||
_wandIds.Contains( i.ID ) && ( containerSerial == -1 || i.IsDescendantOf( containerSerial ) ) &&
|
||||
i.Properties != null && i.Properties.Any( p =>
|
||||
_wandClilocs[wandType].Contains( p.Cliloc ) &&
|
||||
( minimumCharges == -1 || int.Parse( p.Arguments[0] ) >= minimumCharges ) ) );
|
||||
|
||||
return matches;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user