Skip to content

Commit

Permalink
Add use of new RequestMove API, Move now working.
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkLotus committed Apr 21, 2019
1 parent e841bec commit f857200
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CEasyUO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<ApplicationIcon>icons\easyuo2.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="cuoapi, Version=1.1.0.0, Culture=neutral, processorArchitecture=AMD64">
<Reference Include="cuoapi, Version=1.2.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\cuoapi.dll</HintPath>
</Reference>
Expand Down
51 changes: 49 additions & 2 deletions Core/Geometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,55 @@ public override string ToString()
{
return String.Format( "({0}, {1}, {2})", m_X, m_Y, m_Z );
}

public override bool Equals( object o )
public Direction GetDirectionTo( int x, int y )
{
int dx = m_X - x;
int dy = m_Y - y;

int rx = ( dx - dy ) * 44;
int ry = ( dx + dy ) * 44;

int ax = Math.Abs( rx );
int ay = Math.Abs( ry );

Direction ret;

if ( ( ( ay >> 1 ) - ax ) >= 0 )
ret = ( ry > 0 ) ? Direction.Up : Direction.Down;
else if ( ( ( ax >> 1 ) - ay ) >= 0 )
ret = ( rx > 0 ) ? Direction.Left : Direction.Right;
else if ( rx >= 0 && ry >= 0 )
ret = Direction.West;
else if ( rx >= 0 && ry < 0 )
ret = Direction.South;
else if ( rx < 0 && ry < 0 )
ret = Direction.East;
else
ret = Direction.North;

return ret;
}

public Direction GetDirectionTo( Point2D p )
{
return GetDirectionTo( p.m_X, p.m_Y );
}

public Direction GetDirectionTo( Point3D p )
{
return GetDirectionTo( p.m_X, p.m_Y );
}

public Direction GetDirectionTo( IPoint2D p )
{
if ( p == null )
return Direction.North;

return GetDirectionTo( p.X, p.Y );
}


public override bool Equals( object o )
{
if ( o == null || !(o is IPoint3D) ) return false;

Expand Down
7 changes: 5 additions & 2 deletions Network/ClientCommunication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public unsafe sealed class ClientCommunication
private static OnFocusLost _onFocusLost;

private static OnTick _onTick;
private static RequestMove _requestMove;

internal static bool InstallHooks( PluginHeader* header )
{
Expand All @@ -40,6 +41,7 @@ internal static bool InstallHooks( PluginHeader* header )
_getPlayerPosition = Marshal.GetDelegateForFunctionPointer<OnGetPlayerPosition>( header->GetPlayerPosition );
_castSpell = Marshal.GetDelegateForFunctionPointer<OnCastSpell>( header->CastSpell );
_getStaticImage = Marshal.GetDelegateForFunctionPointer<OnGetStaticImage>( header->GetStaticImage );
_requestMove = Marshal.GetDelegateForFunctionPointer<RequestMove>( header->RequestMove );
ClientWindow = header->HWND;
_onTick = Tick;
_recv = OnRecv;
Expand All @@ -65,7 +67,7 @@ internal static bool InstallHooks( PluginHeader* header )
header->OnDisconnected = Marshal.GetFunctionPointerForDelegate( _onDisconnected );
// header->OnFocusGained = Marshal.GetFunctionPointerForDelegate( _onFocusGained );
// header->OnFocusLost = Marshal.GetFunctionPointerForDelegate( _onFocusLost );
header->Tick = Marshal.GetFunctionPointerForDelegate( _onTick );
header->Tick = Marshal.GetFunctionPointerForDelegate( _onTick );

return true;
}
Expand All @@ -84,6 +86,7 @@ private static void OnClientClosing()
Console.WriteLine( "Closing EasyUO instance" );
Console.BackgroundColor = last;
Console.ForegroundColor = lastFore;
Engine.m_MainForm.Close();

}

Expand Down Expand Up @@ -184,7 +187,7 @@ private static bool OnSend( byte[] data, int length )
}

public static void CastSpell( int idx ) => _castSpell?.Invoke( idx );

public static void RequestMove( int dir ) => _requestMove?.Invoke( dir, true );
public static bool GetPlayerPosition( out int x, out int y, out int z )
=> _getPlayerPosition( out x, out y, out z );

Expand Down
3 changes: 1 addition & 2 deletions Scripting/AST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ public override bool Execute()
timeout = Params[3].GetValueInt();
while(Utility.Distance(World.Player.Position,new Point2D(x,y)) > tolerance )
{
ClientCommunication.SendToServer( new WalkRequest( World.Player.GetDirectionTo(x,y), World.Player.WalkSequence ) );
ClientCommunication.SendToClient( new MobileUpdate( World.Player ) );
ClientCommunication.RequestMove( (int)World.Player.Position.GetDirectionTo( new Point2D( x, y ) ) );
Thread.Sleep( 400 );
}

Expand Down
Binary file modified cuoapi.dll
Binary file not shown.

0 comments on commit f857200

Please sign in to comment.