Skip to content

Commit

Permalink
Finditem for 2 letter ID's now works.
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkLotus committed May 10, 2019
1 parent 8b7ce71 commit ec8bfa3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Scripting/AST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public virtual bool Execute() {
Console.WriteLine( $"Executing Statement on Line: {Line} " );
return true;
}

internal void Debug(object msg)
{
if ( DEBUG )
Console.WriteLine( $"{msg.ToString()}" );
}
}

abstract class Expr
Expand Down Expand Up @@ -99,7 +105,7 @@ public override bool Execute()
var ids = Find.GetValue().ToString().Split( new[] { '_' } );
foreach ( var id in ids )
{
if ( id.Length == 3 )
if ( id.Length <= 3 )
FindTypes.Add( Utility.EUO2StealthType( id ) );
else
FindIDs.Add( Utility.EUO2StealthID( id ) );
Expand All @@ -124,11 +130,16 @@ public override bool Execute()
foreach ( var i in FindTypes )
results.AddRange( World.Items.Values.Where( t => t.GraphicID == i ) );

foreach ( var i in FindTypes )
results.AddRange( World.Mobiles.Values.Where( t => t.GraphicID == i ) );


if ( ContainerOnly )
results = results.Where( t => t.Parent != null ).ToList();
if ( GroundOnly )
results = results.Where( t => t.Parent == null ).ToList();
var res = results.FirstOrDefault();
Debug( $"Found:{results.Count} items" );

EUOInterpreter.Setvariable( "#FINDID", Utility.UintToEUO( res?.Serial ?? 0) );
EUOInterpreter.Setvariable( "#FINDTYPE", Utility.UintToEUO( res?.GraphicID ?? 0) );
Expand Down Expand Up @@ -391,8 +402,8 @@ public override bool Execute()
}
break;
case "contextmenu":
uint serial = Utility.EUO2StealthID( Params[1].GetValue().ToString() );
ushort index = (ushort)Params[2].GetValueInt();
uint serial = Utility.EUO2StealthID( Params[0].GetValue().ToString() );
ushort index = (ushort)Params[1].GetValueInt();
ClientCommunication.SendToServer( new ContextMenuRequest( serial ) );
ClientCommunication.SendToServer( new ContextMenuResponse( serial, index ) );
break;
Expand Down Expand Up @@ -577,11 +588,14 @@ public override bool Execute()
if ( ident is Ident i )
{
varName = i.value.ToLowerInvariant();
Debug( "Executing Assign for " + varName );

EUOInterpreter.Setvariable( varName, value.GetValue() );
}
else
{
varName = ident.GetValue().ToString().ToLowerInvariant();
Debug( "Executing Assign for " + varName );
EUOInterpreter.Setvariable( varName, value );
}
return base.Execute();
Expand Down
10 changes: 10 additions & 0 deletions Scripting/EUOInterpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ public static T GetVariable<T>(string name)

public static void Setvariable(string key, object value )
{
Console.WriteLine( $"Set: {key} : {value} " );
key = key.ToLowerInvariant();
if ( Variables.ContainsKey( key ) )
Variables[key] = value;
Expand All @@ -530,6 +531,15 @@ public static void Setvariable(string key, object value )
case "#ltargetid":
EUOVars.LastTarget.Serial = Utility.EUO2StealthID( value.ToString() );
break;
case "#ltargettype":
EUOVars.LastTarget.Gfx = Utility.EUO2StealthType( value.ToString() );
break;
case "#ltargetkind":
EUOVars.LastTarget.Type = byte.Parse( value.ToString() );
break;
case "#ltargettile":
EUOVars.LastTarget.Gfx = ushort.Parse( value.ToString() );
break;
}
}
private void Set()
Expand Down

0 comments on commit ec8bfa3

Please sign in to comment.