• Visit Rebornbuddy
  • Problem with condition on Grind Tag

    Discussion in 'Community Developer Forum' started by mistahmikey, Oct 24, 2015.

    1. mistahmikey

      mistahmikey New Member

      Joined:
      Jun 29, 2015
      Messages:
      161
      Likes Received:
      3
      Trophy Points:
      0
      I decided to make an Orderbot profile to grind mobs and spiritbond some gear. In the profile, I included the following tag:

      <Grind grindRef="Plasmoids" while="InventoryManager.FilledArmorySlots.Where(bs=>bs.SpiritBond!=100&amp;&amp;bs.Item.Convertible!=0).Count()!=0" />

      The idea was to grind until all the spiritbondable armor in my armory was 100% spiritbonded (was using agil to manage the gear swapping automatically).

      However, when I run the script, the condition was rejected as having a syntax error at the '>' character; I made sure the syntax was in fact correct by running it in the rebornbuddy console.

      So I then decided I would finesse the problem by creating a class to act as a wrapper for the condition. I put the .cs file and the orderbot profile in RebornBuddy\Profiles\mistahmikey. However, it appears that ordinary c# files are not loaded when rebornbuddy starts. So, I changed the .cs file to include a bogus Tag definition, thus:

      Code:
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Linq;
      using System.Runtime.InteropServices;
      using System.Text;
      using System.Threading;
      using System.Threading.Tasks;
      using System.Windows.Forms;
      using Clio.Utilities;
      using Clio.XmlEngine;
      using ff14bot.Behavior;
      using ff14bot.Helpers;
      using ff14bot.Managers;
      using ff14bot.Navigation;
      using ff14bot.NeoProfiles;
      using ff14bot.RemoteWindows;
      using TreeSharp;
      using Action = TreeSharp.Action;
      
      namespace ff14bot.NeoProfiles.Tags
      {
          [XmlElement("DummyTag")]
      
          class DummyTag : TalkToTag
          {
              protected override Composite CreateBehavior()
              {
                  return null;
              }
          }
      	
      	public static class SpiritBond
      	{
      		public static bool IsSpiritBondPossible()
      		{
      			return InventoryManager.FilledArmorySlots.Where(bs=>bs.SpiritBond!=100&&bs.Item.Convertible!=0).Count()!=0;
      		}
      	}
      }
      and the orderbot profile to:

      Code:
      <?xml version="1.0" encoding="utf-8"?>
      
      <Profile>
      	<Name>[O] B Grind</Name>
      	<KillRadius>100</KillRadius>
      	<Order>
      		<If Condition="not IsOnMap(155) and not IsOnMap(395)">
      			<TeleportTo Name="Camp Dragonhead" AetheryteId="23" />
      		</If>
      		
      		<Grind grindRef="Plasmoids" while="ff14bot.NeoProfiles.Tags.SpiritBond.IsSpiritBondPossible()" />
      
      	</Order>
      	<GrindAreas>
      		<GrindArea name="Plasmoids">
      			<Hotspots>
      				<Hotspot Radius="250" XYZ="-703.2631, 253.8442, 515.9333" name="Plasmoids" />
      			</Hotspots>
      			<TargetMobs>
      				<TargetMob Id="46" />
      			</TargetMobs>
      		</GrindArea>
      	</GrindAreas>
      </Profile>
      This worked fine when I ran the profile.

      So, my questions are:

      1) Is the inability to use the anonymous lamba syntax a bug in the ConditionParser? Or must I use a different syntax?
      2) Is there a way to inform reborn buddy that I would like it to load a regular c# file (i.e, one that does not contain any botbases, plugins, tags, etc.) so it gets parsed and its contents added to the namespace?
       
    2. mastahg

      mastahg Administrator Staff Member

      Joined:
      Feb 27, 2011
      Messages:
      5,232
      Likes Received:
      364
      Trophy Points:
      83
      > is not valid xml you need to use &lt;

      2) Maybe just try dropping it into a plugin folder.
       
    3. mistahmikey

      mistahmikey New Member

      Joined:
      Jun 29, 2015
      Messages:
      161
      Likes Received:
      3
      Trophy Points:
      0
      I think you meant &gt; ? I am not getting an XML error; according to the internet, using > in an attribute string is allowed. In any case, I changed the tag to:

      Code:
      <Grind grindRef="Plasmoids" while="InventoryManager.FilledArmorySlots.Where(bs=&gt;bs.SpiritBond!=100&amp;&amp;bs.Item.Convertible!=0)" />
      
      An still get the same C# compilation error:

      Code:
      [12:27:54.577 D]   File "", line 4
           return bool(InventoryManager.FilledArmorySlots.Where(bs=>bs.SpiritBond!=100&&bs.Item.Convertible!=0))
                                                                   ^
      SyntaxError: unexpected token '>'
      
      [12:27:54.577 N] Stopping the bot. Reason:Unable to compile condition for GrindTag!
      [12:27:54.578 D] Exception during scheduling Pulse: Microsoft.Scripting.SyntaxErrorException: unexpected token '>'
         at Microsoft.Scripting.ErrorSink.Add(SourceUnit source, String message, SourceSpan span, Int32 errorCode, Severity severity)
         at IronPython.Compiler.Parser.ReportSyntaxError(Int32 start, Int32 end, String message, Int32 errorCode)
         at IronPython.Compiler.Parser.ReportSyntaxError(Token t, IndexSpan span, Int32 errorCode, Boolean allowIncomplete)
         at IronPython.Compiler.Parser.ParsePrimary()
         at IronPython.Compiler.Parser.ParsePower()
         at IronPython.Compiler.Parser.ParseFactor()
         at IronPython.Compiler.Parser.ParseExpr(Int32 precedence)
         at IronPython.Compiler.Parser.ParseComparison()
         at IronPython.Compiler.Parser.ParseNotTest()
         at IronPython.Compiler.Parser.ParseAndTest()
         at IronPython.Compiler.Parser.ParseOrTest()
         at IronPython.Compiler.Parser.ParseExpression()
         at IronPython.Compiler.Parser.FinishKeywordArgument(Expression t)
         at IronPython.Compiler.Parser.FinishArgListOrGenExpr()
         at IronPython.Compiler.Parser.AddTrailers(Expression ret, Boolean allowGeneratorExpression)
         at IronPython.Compiler.Parser.ParsePower()
         at IronPython.Compiler.Parser.ParseFactor()
         at IronPython.Compiler.Parser.ParseExpr(Int32 precedence)
         at IronPython.Compiler.Parser.ParseComparison()
         at IronPython.Compiler.Parser.ParseNotTest()
         at IronPython.Compiler.Parser.ParseAndTest()
         at IronPython.Compiler.Parser.ParseOrTest()
         at IronPython.Compiler.Parser.ParseExpression()
         at IronPython.Compiler.Parser.FinishArgListOrGenExpr()
         at IronPython.Compiler.Parser.AddTrailers(Expression ret, Boolean allowGeneratorExpression)
         at IronPython.Compiler.Parser.ParsePower()
         at IronPython.Compiler.Parser.ParseFactor()
         at IronPython.Compiler.Parser.ParseExpr(Int32 precedence)
         at IronPython.Compiler.Parser.ParseComparison()
         at IronPython.Compiler.Parser.ParseNotTest()
         at IronPython.Compiler.Parser.ParseAndTest()
         at IronPython.Compiler.Parser.ParseOrTest()
         at IronPython.Compiler.Parser.ParseExpression()
         at IronPython.Compiler.Parser.ParseTestListAsExpr()
         at IronPython.Compiler.Parser.ParseReturnStmt()
         at IronPython.Compiler.Parser.ParseSmallStmt()
         at IronPython.Compiler.Parser.ParseSimpleStmt()
         at IronPython.Compiler.Parser.ParseStmt()
         at IronPython.Compiler.Parser.ParseSuite()
         at IronPython.Compiler.Parser.ParseClassOrFuncBody()
         at IronPython.Compiler.Parser.ParseFuncDef()
         at IronPython.Compiler.Parser.ParseStmt()
         at IronPython.Compiler.Parser.ParseFileWorker(Boolean makeModule, Boolean returnValue)
         at IronPython.Compiler.Parser.ParseFile(Boolean makeModule, Boolean returnValue)
         at IronPython.Runtime.PythonContext.ParseAndBindAst(CompilerContext context)
         at IronPython.Runtime.PythonContext.CompilePythonCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
         at IronPython.Runtime.PythonContext.CompileSourceCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
         at Microsoft.Scripting.SourceUnit.Compile(CompilerOptions options, ErrorSink errorSink)
         at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
         at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
         at Clio.Utilities.ScriptManager.GetCondition(String expression)
         at ff14bot.NeoProfiles.GrindTag.()
         at ff14bot.NeoProfiles.GrindTag.get_IsDone()
         at ff14bot.NeoProfiles.ProfileBehavior.get_IsDoneCache()
         at ff14bot.NeoProfiles.TreeNode`1.Find()
         at ..()
         at ff14bot.NeoProfiles.NeoProfileManager.UpdateCurrentProfileBehavior()
         at ff14bot.BotBases.OrderBot.(Object , EventArgs )
         at ff14bot.Behavior.BrainBehavior.()
      
       
    4. mastahg

      mastahg Administrator Staff Member

      Joined:
      Feb 27, 2011
      Messages:
      5,232
      Likes Received:
      364
      Trophy Points:
      83
      Sorry I didn't have enough time to really look at what you were doing. The conditions do not compile to C# but rather ironpython which I don't think has access to LINQ.
       
    5. kagepande

      kagepande Community Developer

      Joined:
      Oct 20, 2014
      Messages:
      289
      Likes Received:
      11
      Trophy Points:
      18
      Just extend your Grind tag, or make a whole new tag if you really want to. Then make sure to load the custom tag with the correct Behavior Directory in the XML file.

      As Mastahg said, conditions inside the actual XML don't compile as C# but rather IronPython, and doesn't have access to LINQ. Best way to keep this mostly the same is to extend the tag or create a new tag and load it.

      You can also add a new attribute to the Grind tag if you want.


      Code:
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Linq;
      using System.Runtime.InteropServices;
      using System.Text;
      using System.Threading;
      using System.Threading.Tasks;
      using System.Windows.Forms;
      using Clio.Utilities;
      using Clio.XmlEngine;
      using ff14bot.Behavior;
      using ff14bot.Helpers;
      using ff14bot.Managers;
      using ff14bot.Navigation;
      using ff14bot.NeoProfiles;
      using ff14bot.RemoteWindows;
      using TreeSharp;
      using Action = TreeSharp.Action;
      
      namespace ff14bot.NeoProfiles.Tags
      {
          [XmlElement("SBGrind")]
      
          public class SBGrind : Grind
          {
              protected override Composite CreateBehavior()
              {
                  return null;
              }
          }
      	
      	public static class SpiritBond
      	{
      		public static bool IsSpiritBondPossible()
      		{
      			return InventoryManager.FilledArmorySlots.Where(bs=>bs.SpiritBond!=100&&bs.Item.Convertible!=0).Count()!=0;
      		}
      	}
      }
      
      So now instead of <Grind> use <SBGrind> it has all the same attributes as <Grind>.
       
    6. mistahmikey

      mistahmikey New Member

      Joined:
      Jun 29, 2015
      Messages:
      161
      Likes Received:
      3
      Trophy Points:
      0
      Yep, I actually just put this into another tag I created to do bulk materia assimilation from my inventory. Thanks for the suggestion, however :)
       
    7. ExMatt

      ExMatt Active Member

      Joined:
      Jul 5, 2015
      Messages:
      1,030
      Likes Received:
      14
      Trophy Points:
      38
      Have you tried

      Edit:
      Condition="Enumerable.Count(InventoryManager.FilledArmorySlots, lambda bs: bs.SpiritBond != 100 and bs.Item.Convertible !=0) != 0"
      ^
      this works, I have tested it.

      This should work...the script manager is compiling with

      import clr
      clr.ImportExtensions(System.Linq)

      and the proper 'using' statements are also there to support it.
       
      Last edited: Nov 8, 2015
    8. mistahmikey

      mistahmikey New Member

      Joined:
      Jun 29, 2015
      Messages:
      161
      Likes Received:
      3
      Trophy Points:
      0
      Will give it a try - thanks for the tip.
       

    Share This Page