first commit
This commit is contained in:
@@ -0,0 +1,227 @@
|
||||
using System.Threading;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Abilities;
|
||||
using ClassicAssist.Data.Macros.Commands;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ClassicAssist.Tests.MacroCommands
|
||||
{
|
||||
[TestClass]
|
||||
public class AbilitiesCommandsTest
|
||||
{
|
||||
private readonly AutoResetEvent _are = new AutoResetEvent( false );
|
||||
|
||||
[TestMethod]
|
||||
public void WillOnlySetPrimaryAbilityOnce()
|
||||
{
|
||||
AbilitiesManager manager = AbilitiesManager.GetInstance();
|
||||
|
||||
Engine.Player = new PlayerMobile( 0x01 );
|
||||
|
||||
Engine.InternalPacketSentEvent += ExpectAbilityPacket;
|
||||
|
||||
AbilitiesCommands.SetAbility( "primary", "on" );
|
||||
|
||||
bool result = _are.WaitOne( 5000 );
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
Assert.AreEqual( AbilityType.Primary, manager.Enabled );
|
||||
Assert.IsTrue( manager.IsPrimaryEnabled );
|
||||
|
||||
Engine.InternalPacketSentEvent -= ExpectAbilityPacket;
|
||||
Engine.InternalPacketSentEvent += NotExpectAbilityPacket;
|
||||
|
||||
AbilitiesCommands.SetAbility( "primary", "on" );
|
||||
|
||||
Engine.InternalPacketSentEvent -= NotExpectAbilityPacket;
|
||||
|
||||
AbilitiesCommands.ClearAbility();
|
||||
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillTogglePrimaryAbility()
|
||||
{
|
||||
AbilitiesManager manager = AbilitiesManager.GetInstance();
|
||||
|
||||
Engine.Player = new PlayerMobile( 0x01 );
|
||||
|
||||
Engine.InternalPacketSentEvent += ExpectAbilityPacket;
|
||||
|
||||
AbilitiesCommands.SetAbility( "primary" );
|
||||
|
||||
bool result = _are.WaitOne( 5000 );
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
Assert.AreEqual( AbilityType.Primary, manager.Enabled );
|
||||
Assert.IsTrue( manager.IsPrimaryEnabled );
|
||||
|
||||
AbilitiesCommands.SetAbility( "primary" );
|
||||
|
||||
result = _are.WaitOne( 5000 );
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
Assert.AreEqual( AbilityType.None, manager.Enabled );
|
||||
Assert.IsFalse( manager.IsPrimaryEnabled );
|
||||
|
||||
Engine.InternalPacketSentEvent -= ExpectAbilityPacket;
|
||||
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillOnlySetSecondaryAbilityOnce()
|
||||
{
|
||||
AbilitiesManager manager = AbilitiesManager.GetInstance();
|
||||
|
||||
Engine.Player = new PlayerMobile( 0x01 );
|
||||
|
||||
Engine.InternalPacketSentEvent += ExpectAbilityPacket;
|
||||
|
||||
AbilitiesCommands.SetAbility( "secondary", "on" );
|
||||
|
||||
bool result = _are.WaitOne( 5000 );
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
Assert.AreEqual( AbilityType.Secondary, manager.Enabled );
|
||||
Assert.IsTrue( manager.IsSecondaryEnabled );
|
||||
|
||||
Engine.InternalPacketSentEvent -= ExpectAbilityPacket;
|
||||
Engine.InternalPacketSentEvent += NotExpectAbilityPacket;
|
||||
|
||||
AbilitiesCommands.SetAbility( "secondary", "on" );
|
||||
|
||||
Engine.InternalPacketSentEvent -= NotExpectAbilityPacket;
|
||||
|
||||
AbilitiesCommands.ClearAbility();
|
||||
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillToggleSecondaryAbility()
|
||||
{
|
||||
AbilitiesManager manager = AbilitiesManager.GetInstance();
|
||||
|
||||
Engine.Player = new PlayerMobile( 0x01 );
|
||||
|
||||
Engine.InternalPacketSentEvent += ExpectAbilityPacket;
|
||||
|
||||
AbilitiesCommands.SetAbility( "secondary" );
|
||||
|
||||
bool result = _are.WaitOne( 5000 );
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
Assert.AreEqual( AbilityType.Secondary, manager.Enabled );
|
||||
Assert.IsTrue( manager.IsSecondaryEnabled );
|
||||
|
||||
AbilitiesCommands.SetAbility( "secondary" );
|
||||
|
||||
result = _are.WaitOne( 5000 );
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
Assert.AreEqual( AbilityType.None, manager.Enabled );
|
||||
Assert.IsFalse( manager.IsSecondaryEnabled );
|
||||
|
||||
Engine.InternalPacketSentEvent -= ExpectAbilityPacket;
|
||||
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillClearAbilities()
|
||||
{
|
||||
Engine.Player = new PlayerMobile( 0x01 );
|
||||
|
||||
AbilitiesManager manager = AbilitiesManager.GetInstance();
|
||||
|
||||
Engine.InternalPacketSentEvent += ExpectAbilityPacket;
|
||||
|
||||
manager.Enabled = AbilityType.Primary;
|
||||
|
||||
AbilitiesCommands.ClearAbility();
|
||||
|
||||
bool result = _are.WaitOne( 5000 );
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
Assert.AreEqual( AbilityType.None, manager.Enabled );
|
||||
|
||||
manager.Enabled = AbilityType.Secondary;
|
||||
|
||||
AbilitiesCommands.ClearAbility();
|
||||
|
||||
result = _are.WaitOne( 5000 );
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
Assert.AreEqual( AbilityType.None, manager.Enabled );
|
||||
|
||||
Engine.InternalPacketSentEvent -= ExpectAbilityPacket;
|
||||
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WontSetAbilitySetOff()
|
||||
{
|
||||
Engine.Player = new PlayerMobile( 0x01 );
|
||||
|
||||
Engine.InternalPacketSentEvent += NotExpectAbilityPacket;
|
||||
|
||||
AbilitiesCommands.SetAbility( "primary", "off" );
|
||||
|
||||
Assert.AreEqual( AbilityType.None, AbilitiesManager.GetInstance().Enabled );
|
||||
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
private static void NotExpectAbilityPacket( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] == 0xD7 && data[8] == 0x19 )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
|
||||
private void ExpectAbilityPacket( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] == 0xD7 && data[8] == 0x19 )
|
||||
{
|
||||
_are.Set();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,368 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Macros.Commands;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ClassicAssist.Tests.MacroCommands
|
||||
{
|
||||
[TestClass]
|
||||
public class ActionCommandTests
|
||||
{
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
Engine.ClientVersion = new Version( 7, 0, 45, 1 );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AttackWillSendAttackPacket()
|
||||
{
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
void OnInternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] != 0x05 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
|
||||
Assert.AreEqual( 0x00aabbcc, serial );
|
||||
|
||||
are.Set();
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
|
||||
|
||||
ActionCommands.Attack( 0x00aabbcc );
|
||||
|
||||
bool result = are.WaitOne( 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ClearHandsWillSendDragPacket()
|
||||
{
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
void OnInternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] != 0x07 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
|
||||
Assert.AreEqual( 0x00aabbcc, serial );
|
||||
|
||||
are.Set();
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
|
||||
|
||||
Engine.Player = new PlayerMobile( 0x01 );
|
||||
Engine.Player.SetLayer( Layer.OneHanded, 0x00aabbcc );
|
||||
|
||||
ActionCommands.ClearHands( "left" );
|
||||
|
||||
bool result = are.WaitOne( 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ClickObjectWillSendPacket()
|
||||
{
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
void OnInternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] != 0x09 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
|
||||
Assert.AreEqual( 0x00aabbcc, serial );
|
||||
|
||||
are.Set();
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
|
||||
|
||||
AliasCommands.SetAlias( "thing", 0x00aabbcc );
|
||||
ActionCommands.ClickObject( "thing" );
|
||||
|
||||
bool result = are.WaitOne( 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MoveItemWillSendDragPacket()
|
||||
{
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
void OnInternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] != 0x07 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
|
||||
Assert.AreEqual( 0x00aabbcc, serial );
|
||||
|
||||
are.Set();
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
|
||||
|
||||
Engine.Items.Add( new Item( 0x00aabbcc ) { Count = 50 } );
|
||||
|
||||
ObjectCommands.MoveItem( 0x00aabbcc, 0xaabbdd );
|
||||
|
||||
bool result = are.WaitOne( 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FeedWillSendDragPacket()
|
||||
{
|
||||
PlayerMobile player = new PlayerMobile( 0x01 );
|
||||
Item backpack = new Item( 0x02 )
|
||||
{
|
||||
Container = new ItemCollection( 0x02 ) { new Item( 0x00aabbcc ) { ID = 0xff, Count = 1 } },
|
||||
Owner = 0x01,
|
||||
Layer = Layer.Backpack
|
||||
};
|
||||
|
||||
player.SetLayer( Layer.Backpack, 0x02 );
|
||||
|
||||
Engine.Player = player;
|
||||
Engine.Items.Add( backpack );
|
||||
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
void OnInternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] != 0x07 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
|
||||
Assert.AreEqual( 0x00aabbcc, serial );
|
||||
|
||||
are.Set();
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
|
||||
|
||||
ActionCommands.Feed( 0x01, 0xff );
|
||||
|
||||
bool result = are.WaitOne( 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
|
||||
|
||||
Engine.Items.Clear();
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RenameWillSendRenamePacket()
|
||||
{
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
void OnInternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
|
||||
Assert.AreEqual( 0x00aabbcc, serial );
|
||||
|
||||
string name = Encoding.ASCII.GetString( data, 5, 30 ).TrimEnd( '\0' );
|
||||
|
||||
Assert.AreEqual( "Snorlax", name );
|
||||
|
||||
are.Set();
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
|
||||
|
||||
ActionCommands.Rename( 0x00aabbcc, "Snorlax" );
|
||||
|
||||
bool result = are.WaitOne( 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShowNamesWillSendLookRequest()
|
||||
{
|
||||
PlayerMobile player = new PlayerMobile( 0x01 );
|
||||
Mobile mobile = new Mobile( 0x00aabbcc );
|
||||
|
||||
Engine.Player = player;
|
||||
Engine.Mobiles.Add( mobile );
|
||||
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
void OnInternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
Assert.AreEqual( 0x09, data[0] );
|
||||
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
|
||||
Assert.AreEqual( 0x00aabbcc, serial );
|
||||
|
||||
are.Set();
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
|
||||
|
||||
ActionCommands.ShowNames( "mobiles" );
|
||||
|
||||
bool result = are.WaitOne( 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.Mobiles.Remove( mobile );
|
||||
|
||||
Engine.Items.Add( new Item( 0x00aabbcc ) { ID = 0x2006 } );
|
||||
|
||||
ActionCommands.ShowNames( "corpses" );
|
||||
|
||||
result = are.WaitOne( 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
|
||||
Engine.Player = null;
|
||||
Engine.Mobiles.Clear();
|
||||
Engine.Items.Clear();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EquipItemWillSendDragPacket()
|
||||
{
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
void OnInternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] != 0x07 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
|
||||
Assert.AreEqual( 0x00aabbcc, serial );
|
||||
|
||||
are.Set();
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
|
||||
|
||||
Engine.Items.Add( new Item( 0x00aabbcc ) );
|
||||
|
||||
Engine.Player = new PlayerMobile( 0x01 );
|
||||
|
||||
ActionCommands.EquipItem( 0x00aabbcc, Layer.OneHanded );
|
||||
|
||||
bool result = are.WaitOne( 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
|
||||
Engine.Player = null;
|
||||
Engine.Items.Clear();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EquipTypeWillSendDragPacket()
|
||||
{
|
||||
Item backpack = new Item( 0x40000000 ) { Owner = 1, Container = new ItemCollection( 0x40000000 ) };
|
||||
|
||||
Engine.Player = new PlayerMobile( 1 ) { Equipment = { backpack } };
|
||||
Engine.Player.SetLayer( Layer.Backpack, backpack.Serial );
|
||||
Engine.Items.Add( backpack );
|
||||
|
||||
Item item = new Item( 0x40000001, backpack.Serial ) { ID = 0xff };
|
||||
backpack.Container.Add( item );
|
||||
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
void OnInternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] != 0x07 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
|
||||
Assert.AreEqual( item.Serial, serial );
|
||||
|
||||
are.Set();
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
|
||||
|
||||
ActionCommands.EquipType( item.ID, Layer.OneHanded );
|
||||
|
||||
bool result = are.WaitOne( 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
|
||||
Engine.Player = null;
|
||||
Engine.Items.Clear();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillFindLayer()
|
||||
{
|
||||
Engine.Player = new PlayerMobile( 1 );
|
||||
Engine.Player.SetLayer( Layer.OneHanded, 0x40000001 );
|
||||
AliasCommands.SetAlias( "self", Engine.Player.Serial );
|
||||
|
||||
Assert.IsTrue( ActionCommands.FindLayer( "OneHanded" ) );
|
||||
Assert.IsFalse( ActionCommands.FindLayer( "TwoHanded" ) );
|
||||
|
||||
AliasCommands.UnsetAlias( "self" );
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void Cleanup()
|
||||
{
|
||||
ActionPacketQueue.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Counters;
|
||||
using ClassicAssist.Data.Macros.Commands;
|
||||
using ClassicAssist.Data.Organizer;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network.PacketFilter;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ClassicAssist.Tests.MacroCommands
|
||||
{
|
||||
[TestClass]
|
||||
public class AgentTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void CounterWillCountType()
|
||||
{
|
||||
PlayerMobile player = new PlayerMobile( 0x01 );
|
||||
Item backpack = new Item( 0x02 ) { Layer = Layer.Backpack, Container = new ItemCollection( 0x02 ) };
|
||||
player.SetLayer( Layer.Backpack, backpack.Serial );
|
||||
Engine.Items.Add( backpack );
|
||||
Engine.Player = player;
|
||||
|
||||
CountersManager manager = CountersManager.GetInstance();
|
||||
manager.Items.Add( new CountersAgentEntry { Name = "test", Color = -1, Graphic = 0xff } );
|
||||
|
||||
backpack.Container.Add( new Item( 0x03 ) { ID = 0xff, Owner = 0x02, Count = 1 } );
|
||||
|
||||
manager.RecountAll = () =>
|
||||
{
|
||||
foreach ( CountersAgentEntry entry in manager.Items )
|
||||
{
|
||||
entry.Recount();
|
||||
}
|
||||
};
|
||||
|
||||
manager.RecountAll();
|
||||
|
||||
int count = AgentCommands.Counter( "test" );
|
||||
|
||||
Assert.AreEqual( 1, count );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillOrganizeLimitAmount()
|
||||
{
|
||||
AppDomain appDomain = AppDomain.CreateDomain( "WillOrganizeLimitAmount", AppDomain.CurrentDomain.Evidence,
|
||||
AppDomain.CurrentDomain.SetupInformation );
|
||||
|
||||
appDomain.DoCallBack( () =>
|
||||
{
|
||||
Dictionary<int, int> serialAmount = new Dictionary<int, int>();
|
||||
|
||||
void OnInternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] == 0x07 )
|
||||
{
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
int amount = ( data[5] << 8 ) | data[6];
|
||||
|
||||
if ( serialAmount.ContainsKey( serial ) )
|
||||
{
|
||||
serialAmount.Remove( serial );
|
||||
}
|
||||
|
||||
serialAmount.Add( serial, amount );
|
||||
}
|
||||
|
||||
if ( data[0] == 0x08 )
|
||||
{
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
int containerSerial = ( data[11] << 24 ) | ( data[12] << 16 ) | ( data[13] << 8 ) | data[14];
|
||||
|
||||
Item sourceItem = Engine.Items.GetItem( serial );
|
||||
Item containerItem = Engine.Items.GetItem( containerSerial );
|
||||
|
||||
if ( serialAmount.ContainsKey( serial ) )
|
||||
{
|
||||
sourceItem.Count = serialAmount[serial];
|
||||
}
|
||||
|
||||
containerItem.Container.Add( sourceItem );
|
||||
}
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
|
||||
|
||||
OrganizerEntry entry = new OrganizerEntry();
|
||||
|
||||
entry.Items.Add( new OrganizerItem { ID = 0xff, Item = "Shmoo", Amount = 10 } );
|
||||
|
||||
Item sourceContainer = new Item( 0x40000004 ) { Container = new ItemCollection( 0x40000004 ) };
|
||||
sourceContainer.Container.Add(
|
||||
new Item( 0x40000005, 0x40000004 ) { ID = 0xff, Count = 5, Owner = 0x40000004 } );
|
||||
sourceContainer.Container.Add(
|
||||
new Item( 0x40000006, 0x40000004 ) { ID = 0xff, Count = 100, Owner = 0x40000004 } );
|
||||
|
||||
Engine.Items.Add( sourceContainer );
|
||||
|
||||
Item destinationContainer = new Item( 0x40000007 ) { Container = new ItemCollection( 0x40000007 ) };
|
||||
|
||||
Engine.Items.Add( destinationContainer );
|
||||
|
||||
entry.SourceContainer = sourceContainer.Serial;
|
||||
entry.DestinationContainer = destinationContainer.Serial;
|
||||
|
||||
Engine.PacketWaitEntries = new PacketWaitEntries();
|
||||
|
||||
OrganizerManager.GetInstance().Organize( entry ).Wait();
|
||||
|
||||
Item[] destinationItems = destinationContainer.Container.GetItems();
|
||||
|
||||
Assert.AreEqual( entry.Items[0].Amount,
|
||||
destinationItems.Sum( i => i.ID == entry.Items[0].ID ? i.Count : 0 ) );
|
||||
|
||||
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
|
||||
Engine.Items.Clear();
|
||||
Engine.PacketWaitEntries = null;
|
||||
} );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillOrganizeNoLimit()
|
||||
{
|
||||
AppDomain appDomain = AppDomain.CreateDomain( "WillOrganizeNoLimit", AppDomain.CurrentDomain.Evidence,
|
||||
AppDomain.CurrentDomain.SetupInformation );
|
||||
|
||||
appDomain.DoCallBack( () =>
|
||||
{
|
||||
Dictionary<int, int> serialAmount = new Dictionary<int, int>();
|
||||
|
||||
void OnInternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] == 0x07 )
|
||||
{
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
int amount = ( data[5] << 8 ) | data[6];
|
||||
|
||||
if ( serialAmount.ContainsKey( serial ) )
|
||||
{
|
||||
serialAmount.Remove( serial );
|
||||
}
|
||||
|
||||
serialAmount.Add( serial, amount );
|
||||
}
|
||||
|
||||
if ( data[0] == 0x08 )
|
||||
{
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
int containerSerial = ( data[11] << 24 ) | ( data[12] << 16 ) | ( data[13] << 8 ) | data[14];
|
||||
|
||||
Item sourceItem = Engine.Items.GetItem( serial );
|
||||
Item containerItem = Engine.Items.GetItem( containerSerial );
|
||||
|
||||
if ( serialAmount.ContainsKey( serial ) )
|
||||
{
|
||||
sourceItem.Count = serialAmount[serial];
|
||||
}
|
||||
|
||||
containerItem.Container.Add( sourceItem );
|
||||
}
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
|
||||
|
||||
OrganizerEntry entry = new OrganizerEntry();
|
||||
|
||||
entry.Items.Add( new OrganizerItem { ID = 0xff, Item = "Shmoo", Amount = -1 } );
|
||||
|
||||
int amnt = 13013;
|
||||
|
||||
Item sourceContainer = new Item( 0x40000004 ) { Container = new ItemCollection( 0x40000004 ) };
|
||||
sourceContainer.Container.Add(
|
||||
new Item( 0x40000005, 0x40000004 ) { ID = 0xff, Count = amnt, Owner = 0x40000004 } );
|
||||
|
||||
Engine.Items.Add( sourceContainer );
|
||||
|
||||
Item destinationContainer = new Item( 0x40000007 ) { Container = new ItemCollection( 0x40000007 ) };
|
||||
|
||||
Engine.Items.Add( destinationContainer );
|
||||
|
||||
entry.SourceContainer = sourceContainer.Serial;
|
||||
entry.DestinationContainer = destinationContainer.Serial;
|
||||
|
||||
Engine.PacketWaitEntries = new PacketWaitEntries();
|
||||
|
||||
OrganizerManager.GetInstance().Organize( entry ).Wait();
|
||||
|
||||
Item[] destinationItems = destinationContainer.Container.GetItems();
|
||||
|
||||
Assert.AreEqual( amnt, destinationItems.Sum( i => i.Count ) );
|
||||
|
||||
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
|
||||
Engine.Items.Clear();
|
||||
Engine.PacketWaitEntries = null;
|
||||
} );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillOrganizeNoLimitMultiple()
|
||||
{
|
||||
AppDomain appDomain = AppDomain.CreateDomain( "WillOrganizeNoLimitMultiple",
|
||||
AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
|
||||
|
||||
appDomain.DoCallBack( () =>
|
||||
{
|
||||
Dictionary<int, int> serialAmount = new Dictionary<int, int>();
|
||||
|
||||
void OnInternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] == 0x07 )
|
||||
{
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
int amount = ( data[5] << 8 ) | data[6];
|
||||
|
||||
if ( serialAmount.ContainsKey( serial ) )
|
||||
{
|
||||
serialAmount.Remove( serial );
|
||||
}
|
||||
|
||||
serialAmount.Add( serial, amount );
|
||||
}
|
||||
|
||||
if ( data[0] == 0x08 )
|
||||
{
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
int containerSerial = ( data[11] << 24 ) | ( data[12] << 16 ) | ( data[13] << 8 ) | data[14];
|
||||
|
||||
Item sourceItem = Engine.Items.GetItem( serial );
|
||||
Item containerItem = Engine.Items.GetItem( containerSerial );
|
||||
|
||||
if ( serialAmount.ContainsKey( serial ) )
|
||||
{
|
||||
sourceItem.Count = serialAmount[serial];
|
||||
}
|
||||
|
||||
containerItem.Container.Add( sourceItem );
|
||||
}
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
|
||||
|
||||
OrganizerEntry entry = new OrganizerEntry();
|
||||
|
||||
entry.Items.Add( new OrganizerItem { ID = 0xff, Item = "Shmoo", Amount = -1 } );
|
||||
entry.Items.Add( new OrganizerItem { ID = 0xfe, Item = "Shmoo", Amount = -1 } );
|
||||
|
||||
int amnt = 13013;
|
||||
|
||||
Item sourceContainer = new Item( 0x40000004 ) { Container = new ItemCollection( 0x40000004 ) };
|
||||
sourceContainer.Container.Add(
|
||||
new Item( 0x40000005, 0x40000004 ) { ID = 0xff, Count = amnt, Owner = 0x40000004 } );
|
||||
sourceContainer.Container.Add(
|
||||
new Item( 0x40000006, 0x40000004 ) { ID = 0xfe, Count = amnt, Owner = 0x40000004 } );
|
||||
|
||||
Engine.Items.Add( sourceContainer );
|
||||
|
||||
Item destinationContainer = new Item( 0x40000007 ) { Container = new ItemCollection( 0x40000007 ) };
|
||||
|
||||
Engine.Items.Add( destinationContainer );
|
||||
|
||||
entry.SourceContainer = sourceContainer.Serial;
|
||||
entry.DestinationContainer = destinationContainer.Serial;
|
||||
|
||||
Engine.PacketWaitEntries = new PacketWaitEntries();
|
||||
|
||||
OrganizerManager.GetInstance().Organize( entry ).Wait();
|
||||
|
||||
Item[] destinationItems = destinationContainer.Container.GetItems();
|
||||
|
||||
Assert.AreEqual( 2, destinationContainer.Container.GetTotalItemCount() );
|
||||
Assert.AreEqual( amnt * 2, destinationItems.Sum( i => i.Count ) );
|
||||
|
||||
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
|
||||
Engine.Items.Clear();
|
||||
Engine.PacketWaitEntries = null;
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Macros.Commands;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ClassicAssist.Tests.MacroCommands
|
||||
{
|
||||
[TestClass]
|
||||
public class AliasCommandTests
|
||||
{
|
||||
private PlayerMobile _player;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_player = new PlayerMobile( 0x01 );
|
||||
Engine.Player = _player;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillSetDefaultAliases()
|
||||
{
|
||||
AliasCommands.SetDefaultAliases();
|
||||
|
||||
Assert.AreEqual( _player.Serial, AliasCommands.GetAlias( "self" ) );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillChangeLastAliasOnTargetSent()
|
||||
{
|
||||
_player.LastTargetSerial = 0x02;
|
||||
|
||||
AliasCommands.SetDefaultAliases();
|
||||
|
||||
Assert.AreEqual( 0x02, AliasCommands.GetAlias( "last" ) );
|
||||
|
||||
OutgoingPacketHandlers.Initialize();
|
||||
PacketHandler handler = OutgoingPacketHandlers.GetHandler( 0x6C );
|
||||
|
||||
byte[] packet =
|
||||
{
|
||||
0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
handler?.OnReceive( new PacketReader( packet, packet.Length, true ) );
|
||||
|
||||
Assert.AreEqual( 0xAABBCCDD, (uint) AliasCommands.GetAlias( "last" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data;
|
||||
using ClassicAssist.Data.Macros.Commands;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ClassicAssist.Tests.MacroCommands
|
||||
{
|
||||
[TestClass]
|
||||
public class JournalCommandsTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void WillMatchSystem()
|
||||
{
|
||||
Engine.Journal.Write( new JournalEntry
|
||||
{
|
||||
Text = "You are now under the protection of town guards.", SpeechType = JournalSpeech.System
|
||||
} );
|
||||
|
||||
Assert.IsTrue( JournalCommands.InJournal( "town guards", "system" ) );
|
||||
|
||||
Engine.Journal.Clear();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillMatchSystemRegular()
|
||||
{
|
||||
const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
|
||||
|
||||
if ( !Directory.Exists( localPath ) )
|
||||
{
|
||||
Debug.WriteLine( "Not running test, requires Cliloc.enu" );
|
||||
return;
|
||||
}
|
||||
|
||||
Cliloc.Initialize( localPath );
|
||||
|
||||
byte[] packet =
|
||||
{
|
||||
0xC1, 0x00, 0x32, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x03, 0xB2, 0x00, 0x03, 0x00, 0x07,
|
||||
0xA4, 0xE1, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00
|
||||
};
|
||||
|
||||
IncomingPacketHandlers.Initialize();
|
||||
|
||||
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xc1 );
|
||||
|
||||
Assert.IsNotNull( handler );
|
||||
|
||||
handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
|
||||
|
||||
Assert.IsTrue( JournalCommands.InJournal( "fingers slip!", "system" ) );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillMatchAuthor()
|
||||
{
|
||||
Engine.Journal.Write( new JournalEntry
|
||||
{
|
||||
Text = "The quick brown bow jumped over the lazy dog.",
|
||||
SpeechType = JournalSpeech.Say,
|
||||
Name = "Tony"
|
||||
} );
|
||||
|
||||
Assert.IsTrue( JournalCommands.InJournal( "lazy dog", "tony" ) );
|
||||
|
||||
Engine.Journal.Clear();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillMatchAny()
|
||||
{
|
||||
Engine.Journal.Write( new JournalEntry
|
||||
{
|
||||
Text = "You are now under the protection of town guards.", SpeechType = JournalSpeech.System
|
||||
} );
|
||||
|
||||
Engine.Journal.Write( new JournalEntry
|
||||
{
|
||||
Text = "The quick brown bow jumped over the lazy dog.",
|
||||
SpeechType = JournalSpeech.Say,
|
||||
Name = "Tony"
|
||||
} );
|
||||
|
||||
Assert.IsTrue( JournalCommands.InJournal( "town guards" ) );
|
||||
|
||||
Assert.IsTrue( JournalCommands.InJournal( "lazy dog" ) );
|
||||
|
||||
Engine.Journal.Clear();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillClearJournal()
|
||||
{
|
||||
Engine.Journal.Write( new JournalEntry
|
||||
{
|
||||
Text = "The quick brown bow jumped over the lazy dog.",
|
||||
SpeechType = JournalSpeech.Say,
|
||||
Name = "Tony"
|
||||
} );
|
||||
|
||||
JournalCommands.ClearJournal();
|
||||
|
||||
Assert.AreEqual( 0, Engine.Journal.Count );
|
||||
|
||||
Engine.Journal.Clear();
|
||||
}
|
||||
|
||||
//[TestMethod]
|
||||
//public void WaitForJournalWillMatch()
|
||||
//{
|
||||
// const string text = "You are now under the protection of town guards.";
|
||||
|
||||
// byte[] textBytes = Encoding.Unicode.GetBytes( text );
|
||||
|
||||
// PacketWriter pw = new PacketWriter( 48 + textBytes.Length );
|
||||
|
||||
// pw.Write( (byte) 0xAE );
|
||||
// pw.Write( (short) ( 48 + textBytes.Length ));
|
||||
// pw.Write((int)0 );
|
||||
// pw.Write( (short) 0 );
|
||||
// pw.Write((byte)1 ); // system
|
||||
// pw.Seek( 39, SeekOrigin.Current );
|
||||
// pw.Write(textBytes, 0, textBytes.Length );
|
||||
|
||||
// IncomingPacketHandlers.Initialize();
|
||||
|
||||
// PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xAE );
|
||||
|
||||
// Task<bool> t = Task.Run(() => JournalCommands.WaitForJournal("town guards", 20000, "system"));
|
||||
|
||||
// handler?.OnReceive(new PacketReader( pw.ToArray(), pw.ToArray().Length, false ));
|
||||
|
||||
// bool finished = t.Wait( 20000 );
|
||||
|
||||
// Assert.IsTrue( finished );
|
||||
|
||||
// bool result = t.Result;
|
||||
|
||||
// Assert.IsTrue( result );
|
||||
|
||||
// Engine.Journal.Clear();
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using static ClassicAssist.Data.Macros.Commands.ListCommands;
|
||||
|
||||
namespace ClassicAssist.Tests.MacroCommands
|
||||
{
|
||||
[TestClass]
|
||||
public class ListCommandTests
|
||||
{
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
CreateList( "shmoo" );
|
||||
PushList( "shmoo", 0 );
|
||||
PushList( "shmoo", 1 );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ListExistsWillReturnTrue()
|
||||
{
|
||||
Assert.IsTrue( ListExists( "shmoo" ) );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetListWillReturnArray()
|
||||
{
|
||||
Assert.IsTrue( GetList( "shmoo" ) is int[] _ );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ListCountWillReturnCorrect()
|
||||
{
|
||||
Assert.AreEqual( 2, List( "shmoo" ) );
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void Cleanup()
|
||||
{
|
||||
RemoveList( "shmoo" );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Macros.Commands;
|
||||
using ClassicAssist.Data.SpecialMoves;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ClassicAssist.Tests.MacroCommands
|
||||
{
|
||||
[TestClass]
|
||||
public class MobileCommandTests
|
||||
{
|
||||
private PlayerMobile _player;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_player = new PlayerMobile( 0x01 ) { Name = "Shmoo", Notoriety = Notoriety.Murderer };
|
||||
Engine.Player = _player;
|
||||
AliasCommands.SetAlias( "self", 0x01 );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillGetName()
|
||||
{
|
||||
string name = EntityCommands.Name( "self" );
|
||||
|
||||
Assert.AreEqual( "Shmoo", name );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillTrimNameItem()
|
||||
{
|
||||
Engine.Items.Add( new Item( 0x40000000 ) { Name = " need trim " } );
|
||||
|
||||
Assert.AreEqual( "need trim", EntityCommands.Name( 0x40000000 ) );
|
||||
|
||||
Assert.AreEqual( string.Empty, EntityCommands.Name( 0x40000001 ) );
|
||||
|
||||
Engine.Items.Remove( 0x40000000 );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillGetNotoriety()
|
||||
{
|
||||
Assert.IsTrue( NotorietyCommands.Murderer( "self" ) );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillGetHitsNoParam()
|
||||
{
|
||||
_player.Hits = 100;
|
||||
|
||||
int val = MobileCommands.Hits();
|
||||
|
||||
Assert.AreEqual( 100, val );
|
||||
|
||||
_player.Hits = 0;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillGetHitsSerialParam()
|
||||
{
|
||||
Mobile mobile = new Mobile( 2 ) { Hits = 200 };
|
||||
|
||||
Engine.Mobiles.Add( mobile );
|
||||
|
||||
int val = MobileCommands.Hits( mobile.Serial );
|
||||
|
||||
Assert.AreEqual( 200, val );
|
||||
|
||||
Engine.Mobiles.Remove( mobile );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillGetHitsStringParam()
|
||||
{
|
||||
Mobile mobile = new Mobile( 2 ) { Hits = 250 };
|
||||
|
||||
Engine.Mobiles.Add( mobile );
|
||||
|
||||
AliasCommands.SetAlias( "mobile", mobile.Serial );
|
||||
|
||||
int val = MobileCommands.Hits( "mobile" );
|
||||
|
||||
Assert.AreEqual( 250, val );
|
||||
|
||||
Engine.Mobiles.Remove( mobile );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillGetHiddenNoParam()
|
||||
{
|
||||
_player.Status |= MobileStatus.Hidden;
|
||||
_player.Status |= MobileStatus.Female;
|
||||
|
||||
bool hidden = MobileCommands.Hidden();
|
||||
|
||||
Assert.IsTrue( hidden );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillGetDead()
|
||||
{
|
||||
Assert.IsFalse( MobileCommands.Dead() );
|
||||
|
||||
_player.ID = 0x192;
|
||||
|
||||
Assert.IsTrue( MobileCommands.Dead() );
|
||||
|
||||
_player.ID = 0x190;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillGetDeadParam()
|
||||
{
|
||||
Mobile m = new Mobile( 2 );
|
||||
|
||||
Engine.Mobiles.Add( m );
|
||||
|
||||
Assert.IsFalse( MobileCommands.Dead( 2 ) );
|
||||
|
||||
m.ID = 0x192;
|
||||
|
||||
Assert.IsTrue( MobileCommands.Dead( 2 ) );
|
||||
|
||||
Engine.Mobiles.Remove( m );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillGetMountedParam()
|
||||
{
|
||||
Item mount = new Item( 2 );
|
||||
|
||||
Engine.Items.Add( mount );
|
||||
|
||||
AliasCommands.SetAlias( "self", 1 );
|
||||
AliasCommands.SetAlias( "mount", 2 );
|
||||
|
||||
Assert.IsFalse( MobileCommands.Mounted( "self" ) );
|
||||
|
||||
_player.SetLayer( Layer.Mount, 2 );
|
||||
|
||||
Assert.IsTrue( MobileCommands.Mounted( "self" ) );
|
||||
|
||||
Engine.Items.Remove( mount );
|
||||
_player.SetLayer( Layer.Mount, 0 );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillGetMaxHits()
|
||||
{
|
||||
_player.HitsMax = 100;
|
||||
|
||||
Assert.AreEqual( 100, MobileCommands.MaxHits( _player.Serial ) );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillGetHits()
|
||||
{
|
||||
_player.Hits = 100;
|
||||
|
||||
Assert.AreEqual( 100, MobileCommands.Hits( _player.Serial ) );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillGetDiffHits()
|
||||
{
|
||||
_player.Hits = 90;
|
||||
_player.HitsMax = 100;
|
||||
|
||||
Assert.AreEqual( 10, MobileCommands.DiffHits( _player.Serial ) );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillGetStats()
|
||||
{
|
||||
_player.Strength = 100;
|
||||
_player.Int = 90;
|
||||
_player.Dex = 25;
|
||||
|
||||
Assert.AreEqual( 100, MobileCommands.Str() );
|
||||
Assert.AreEqual( 90, MobileCommands.Int() );
|
||||
Assert.AreEqual( 25, MobileCommands.Dex() );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillEnableDisableSpecialMove()
|
||||
{
|
||||
SpecialMovesManager manager = SpecialMovesManager.GetInstance();
|
||||
|
||||
byte[] enablePacket = { 0xBF, 0x00, 0x08, 0x00, 0x25, 0x01, 0xF6, 0x01 };
|
||||
byte[] disablePacket = { 0xBF, 0x00, 0x08, 0x00, 0x25, 0x01, 0xF6, 0x00 };
|
||||
|
||||
IncomingPacketHandlers.Initialize();
|
||||
|
||||
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xBF );
|
||||
|
||||
handler?.OnReceive( new PacketReader( enablePacket, enablePacket.Length, false ) );
|
||||
|
||||
bool result = EntityCommands.SpecialMoveExists( "Death Strike" );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
handler?.OnReceive( new PacketReader( disablePacket, disablePacket.Length, false ) );
|
||||
|
||||
result = EntityCommands.SpecialMoveExists( "Death Strike" );
|
||||
|
||||
Assert.IsFalse( result );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
using System.Threading;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Macros.Commands;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ClassicAssist.Tests.MacroCommands
|
||||
{
|
||||
[TestClass]
|
||||
public class ObjectCommandTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void WillFindTypeGround()
|
||||
{
|
||||
Engine.Items.Add( new Item( 0x40000001 ) { ID = 0xdda } );
|
||||
|
||||
bool result = ObjectCommands.FindType( 0xdda );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
int val = AliasCommands.GetAlias( "found" );
|
||||
|
||||
Assert.AreEqual( 0x40000001, val );
|
||||
|
||||
Engine.Items.Clear();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillFindTypeGroundMobile()
|
||||
{
|
||||
Engine.Mobiles.Add( new Mobile( 0x02 ) { ID = 0x190 } );
|
||||
|
||||
bool result = ObjectCommands.FindType( 0x190 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
int val = AliasCommands.GetAlias( "found" );
|
||||
|
||||
Assert.AreEqual( 0x02, val );
|
||||
|
||||
Engine.Mobiles.Clear();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillFindTypeSubcontainer()
|
||||
{
|
||||
Item container = new Item( 1 )
|
||||
{
|
||||
Container = new ItemCollection( 1 ) { new Item( 0x02 ) { ID = 0xdda, Owner = 1 } }
|
||||
};
|
||||
|
||||
Engine.Items.Add( container );
|
||||
|
||||
AliasCommands.SetAlias( "cont", 1 );
|
||||
|
||||
bool result = ObjectCommands.FindType( 0xdda, -1, "cont" );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
int val = AliasCommands.GetAlias( "found" );
|
||||
|
||||
Assert.AreEqual( 0x02, val );
|
||||
|
||||
Engine.Items.Clear();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillFindTypeInRange()
|
||||
{
|
||||
Engine.Player = new PlayerMobile( 1 );
|
||||
Engine.Mobiles.Add( new Mobile( 0x02 ) { ID = 0x190, X = 5, Y = 5 } );
|
||||
|
||||
bool result = ObjectCommands.FindType( 0x190, 8 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.Mobiles.Clear();
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WontFindTypeOutOfRange()
|
||||
{
|
||||
Engine.Player = new PlayerMobile( 1 );
|
||||
Engine.Mobiles.Add( new Mobile( 0x02 ) { ID = 0x190, X = 5, Y = 5 } );
|
||||
|
||||
bool result = ObjectCommands.FindType( 0x190, 1 );
|
||||
|
||||
Assert.IsFalse( result );
|
||||
|
||||
Engine.Mobiles.Clear();
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillIgnoreObject()
|
||||
{
|
||||
Engine.Mobiles.Add( new Mobile( 0x02 ) { ID = 0x190, X = 5, Y = 5 } );
|
||||
|
||||
bool result = ObjectCommands.FindType( 0x190 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
ObjectCommands.IgnoreObject( "found" );
|
||||
|
||||
result = ObjectCommands.FindType( 0x190 );
|
||||
|
||||
Assert.IsFalse( result );
|
||||
|
||||
Engine.Mobiles.Clear();
|
||||
ObjectCommands.ClearIgnoreList();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillCountType()
|
||||
{
|
||||
PlayerMobile player = new PlayerMobile( 1 );
|
||||
Item backpack =
|
||||
new Item( 0x40000001 ) { ID = 0xff, Owner = 0x01, Container = new ItemCollection( 0x40000001 ) };
|
||||
|
||||
Engine.Player = player;
|
||||
Engine.Items.Add( backpack );
|
||||
|
||||
player.SetLayer( Layer.Backpack, 0x40000001 );
|
||||
|
||||
backpack.Container.Add( new Item( 0x40000002 ) { ID = 0xFE, Owner = 0x40000001 } );
|
||||
|
||||
int count = ObjectCommands.CountType( 0xfe, 0x40000001 );
|
||||
|
||||
Assert.AreEqual( 1, count );
|
||||
|
||||
Engine.Items.Clear();
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillCountMobileGround()
|
||||
{
|
||||
Engine.Player = new PlayerMobile( 0x01 );
|
||||
|
||||
Mobile mobile = new Mobile( 0x02 ) { ID = 0x190 };
|
||||
Mobile mobile2 = new Mobile( 0x03 ) { ID = 0x191 };
|
||||
|
||||
Engine.Mobiles.Add( mobile );
|
||||
Engine.Mobiles.Add( mobile2 );
|
||||
|
||||
int count = ObjectCommands.CountTypeGround( 0x190, -1, 5 );
|
||||
|
||||
Assert.AreEqual( 1, count );
|
||||
|
||||
Engine.Mobiles.Clear();
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillSendUseObjectPacket()
|
||||
{
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
void InternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] != 0x06 )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
int serial = ( data[1] << 24 ) | ( data[2] << 16 ) | ( data[3] << 8 ) | data[4];
|
||||
|
||||
Assert.AreEqual( 0x40000001, serial );
|
||||
|
||||
are.Set();
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += InternalPacketSentEvent;
|
||||
|
||||
Engine.Items.Add( new Item( 0x40000001 ) );
|
||||
|
||||
AliasCommands.SetAlias( "item", 0x40000001 );
|
||||
|
||||
ObjectCommands.UseObject( "item" );
|
||||
|
||||
bool result = are.WaitOne( 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.InternalPacketSentEvent -= InternalPacketSentEvent;
|
||||
Engine.Items.Clear();
|
||||
AliasCommands.UnsetAlias( "item" );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillFindObjectInContainer()
|
||||
{
|
||||
Item container = new Item( 0x55 ) { Container = new ItemCollection( 0x55 ) };
|
||||
|
||||
Engine.Items.Add( container );
|
||||
|
||||
container.Container.Add( new Item( 0x56 ) { Owner = 0x55 } );
|
||||
|
||||
bool result = ObjectCommands.FindObject( 0x56, -1, 0x55 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Item subContainer = new Item( 0x57 ) { Container = new ItemCollection( 0x57 ), Owner = 0x55 };
|
||||
|
||||
container.Container.Add( subContainer );
|
||||
subContainer.Container.Add( new Item( 0x58 ) { Owner = 0x57 } );
|
||||
|
||||
result = ObjectCommands.FindObject( 0x57, -1, 0x55 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.Items.Remove( container );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillFindObjectGround()
|
||||
{
|
||||
Engine.Player = new PlayerMobile( 0x01 ) { X = 0, Y = 0 };
|
||||
|
||||
Item item1 = new Item( 0x40000001 );
|
||||
Item item2 = new Item( 0x40000002 ) { X = 100, Y = 100 };
|
||||
|
||||
Engine.Items.Add( item1 );
|
||||
Engine.Items.Add( item2 );
|
||||
|
||||
Assert.IsTrue( ObjectCommands.FindObject( item1.Serial ) );
|
||||
Assert.IsTrue( ObjectCommands.FindObject( item2.Serial ) );
|
||||
Assert.IsFalse( ObjectCommands.FindObject( item2.Serial, 5 ) );
|
||||
|
||||
Engine.Items.Remove( item2 );
|
||||
Engine.Items.Remove( item1 );
|
||||
|
||||
Engine.Player = null;
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void Cleanup()
|
||||
{
|
||||
ActionPacketQueue.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Macros.Commands;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network;
|
||||
using ClassicAssist.UO.Network.PacketFilter;
|
||||
using ClassicAssist.UO.Objects;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ClassicAssist.Tests.MacroCommands
|
||||
{
|
||||
[TestClass]
|
||||
public class PropertiesCommandTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void WillWaitForProperties()
|
||||
{
|
||||
Engine.PacketWaitEntries = new PacketWaitEntries();
|
||||
|
||||
void OnInternalPacketSentEvent( byte[] data, int length )
|
||||
{
|
||||
if ( data[0] != 0xD6 )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
int serial = ( data[3] << 24 ) | ( data[4] << 16 ) | ( data[5] << 8 ) | data[6];
|
||||
|
||||
byte[] packet = { 0xD6, 0x00, 0x09, 0x00, 0x01, data[3], data[4], data[5], data[6] };
|
||||
|
||||
Engine.PacketWaitEntries.CheckWait( packet, PacketDirection.Incoming );
|
||||
}
|
||||
|
||||
Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;
|
||||
|
||||
bool result = PropertiesCommands.WaitForProperties( 0x00aabbcc, 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.PacketWaitEntries = null;
|
||||
Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory( "Data" )]
|
||||
public void WillReturnTrueOnPropertyName()
|
||||
{
|
||||
const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
|
||||
|
||||
if ( !Directory.Exists( localPath ) )
|
||||
{
|
||||
Debug.WriteLine( "Not running test, requires Cliloc.enu" );
|
||||
return;
|
||||
}
|
||||
|
||||
Cliloc.Initialize( localPath );
|
||||
|
||||
byte[] packet =
|
||||
{
|
||||
0xD6, 0x00, 0x43, 0x00, 0x01, 0x40, 0xC5, 0xF6, 0x09, 0x00, 0x00, 0x02, 0xA0, 0x3B, 0xCF, 0x00,
|
||||
0x0F, 0x9E, 0xD5, 0x00, 0x00, 0x00, 0x10, 0x5E, 0x95, 0x00, 0x04, 0x37, 0x00, 0x34, 0x00, 0x00,
|
||||
0x10, 0x5C, 0x71, 0x00, 0x1A, 0x34, 0x00, 0x39, 0x00, 0x09, 0x00, 0x31, 0x00, 0x32, 0x00, 0x35,
|
||||
0x00, 0x09, 0x00, 0x37, 0x00, 0x31, 0x00, 0x09, 0x00, 0x35, 0x00, 0x35, 0x00, 0x30, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
Item item = new Item( 0x40c5f609 );
|
||||
|
||||
Engine.Items.Add( item );
|
||||
|
||||
IncomingPacketHandlers.Initialize();
|
||||
|
||||
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xD6 );
|
||||
|
||||
handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
|
||||
|
||||
Assert.IsNotNull( item.Properties );
|
||||
|
||||
bool result = PropertiesCommands.Property( item.Serial, "Contents" );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
result = PropertiesCommands.Property( item.Serial, "Donkey" );
|
||||
|
||||
Assert.IsFalse( result );
|
||||
|
||||
Engine.Items.Clear();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory( "Data" )]
|
||||
public void WillGetPropertyValue()
|
||||
{
|
||||
const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
|
||||
|
||||
if ( !Directory.Exists( localPath ) )
|
||||
{
|
||||
Debug.WriteLine( "Not running test, requires Cliloc.enu" );
|
||||
return;
|
||||
}
|
||||
|
||||
Cliloc.Initialize( localPath );
|
||||
|
||||
byte[] packet =
|
||||
{
|
||||
0xD6, 0x00, 0x43, 0x00, 0x01, 0x40, 0xC5, 0xF6, 0x09, 0x00, 0x00, 0x02, 0xA0, 0x3B, 0xCF, 0x00,
|
||||
0x0F, 0x9E, 0xD5, 0x00, 0x00, 0x00, 0x10, 0x5E, 0x95, 0x00, 0x04, 0x37, 0x00, 0x34, 0x00, 0x00,
|
||||
0x10, 0x5C, 0x71, 0x00, 0x1A, 0x34, 0x00, 0x39, 0x00, 0x09, 0x00, 0x31, 0x00, 0x32, 0x00, 0x35,
|
||||
0x00, 0x09, 0x00, 0x37, 0x00, 0x31, 0x00, 0x09, 0x00, 0x35, 0x00, 0x35, 0x00, 0x30, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
Item item = new Item( 0x40c5f609 );
|
||||
|
||||
Engine.Items.Add( item );
|
||||
|
||||
IncomingPacketHandlers.Initialize();
|
||||
|
||||
PacketHandler handler = IncomingPacketHandlers.GetHandler( 0xD6 );
|
||||
|
||||
handler.OnReceive( new PacketReader( packet, packet.Length, false ) );
|
||||
|
||||
Assert.IsNotNull( item.Properties );
|
||||
|
||||
int value = PropertiesCommands.PropertyValue<int>( item.Serial, "Contents" );
|
||||
|
||||
Assert.AreEqual( 49, value );
|
||||
|
||||
value = PropertiesCommands.PropertyValue<int>( item.Serial, "Contents", 2 );
|
||||
|
||||
Assert.AreEqual( 71, value );
|
||||
|
||||
Engine.Items.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using ClassicAssist.Data.Macros.Commands;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ClassicAssist.Tests.MacroCommands
|
||||
{
|
||||
[TestClass]
|
||||
public class TimerTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void WillAddOffset()
|
||||
{
|
||||
TimerCommands.CreateTimer( "shmoo" );
|
||||
TimerCommands.SetTimer( "shmoo", (int) TimeSpan.FromMinutes( 2 ).TotalMilliseconds );
|
||||
|
||||
long timerValue = TimerCommands.Timer( "shmoo" );
|
||||
|
||||
TimeSpan timespan = TimeSpan.FromMilliseconds( timerValue );
|
||||
|
||||
Assert.AreEqual( 2, (int) timespan.TotalMinutes );
|
||||
|
||||
TimerCommands.RemoveTimer( "shmoo" );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillCreateTimer()
|
||||
{
|
||||
TimerCommands.CreateTimer( "shmoo2" );
|
||||
|
||||
Assert.IsTrue( TimerCommands.TimerExists( "shmoo2" ) );
|
||||
|
||||
TimerCommands.RemoveTimer( "shmoo2" );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillRemoveTimer()
|
||||
{
|
||||
TimerCommands.CreateTimer( "shmoo3" );
|
||||
TimerCommands.RemoveTimer( "shmoo3" );
|
||||
|
||||
Assert.IsFalse( TimerCommands.TimerExists( "shmoo3" ) );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillCreateTimerSetTimer()
|
||||
{
|
||||
TimerCommands.SetTimer( "shmoo4" );
|
||||
Assert.IsTrue( TimerCommands.TimerExists( "shmoo4" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user