Ejemplo n.º 1
0
        internal static void Engine()
        {
            // Check Bag
            Assistant.Item sbag = Assistant.World.FindItem(m_sourcebag);
            if (sbag == null)
            {
                if (Settings.General.ReadBool("ShowAgentMessageCheckBox"))
                {
                    Misc.SendMessage("Organizer: Invalid Source Bag", 945, true);
                }
                AddLog("Invalid Source Bag");
                Assistant.Engine.MainWindow.OrganizerFinishWork();
                return;
            }
            Assistant.Item dbag = Assistant.World.FindItem(m_destinationbag);
            if (dbag == null)
            {
                if (Settings.General.ReadBool("ShowAgentMessageCheckBox"))
                {
                    Misc.SendMessage("Organizer: Invalid Destination Bag", 945, true);
                }
                AddLog("Invalid Destination Bag");
                Assistant.Engine.MainWindow.OrganizerFinishWork();
                return;
            }

            int exit = Engine(Settings.Organizer.ItemsRead(m_organizerlist), m_dragdelay, m_sourcebag, m_destinationbag);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Get current Scravenger destination container.
 /// </summary>
 /// <returns>Serial of the container.</returns>
 public static uint GetScavengerBag()
 {
     // Check bag
     Assistant.Item bag = Assistant.World.FindItem(Scavenger.ScavengerBag);
     if (bag != null)
     {
         if (!bag.IsLootableTarget)
         {
             if (!lootChangeMsgSent)
             {
                 Misc.SendMessage("Scavenger: Invalid Bag, Switch to backpack", 945, true);
                 AddLog("Invalid Bag, Switch to backpack");
                 lootChangeMsgSent = true;
             }
             return(World.Player.Backpack.Serial.Value);
         }
     }
     else
     {
         if (!lootChangeMsgSent)
         {
             Misc.SendMessage("Scavenger: Invalid Bag, Switch to backpack", 945, true);
             AddLog("Invalid Bag, Switch to backpack");
             lootChangeMsgSent = true;
         }
         return(World.Player.Backpack.Serial.Value);
     }
     lootChangeMsgSent = false;
     return(bag.Serial.Value);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Prompt a target in-game, wait for the Player to select an Item or a Mobile. Can also specific a text message for prompt.
        /// </summary>
        /// <param name="message">Hint on what to select.</param>
        /// <param name="color">Color of the message. (default: 945, gray)</param>
        /// <returns>Serial of the selected object.</returns>
        public int PromptTarget(string message = "Select Item or Mobile", int color = 945)
        {
            m_ptarget = -1;
            Misc.SendMessage(message, color, true);
            Targeting.OneTimeTarget(false, new Targeting.TargetResponseCallback(PromptTargetExex_Callback));

            while (!Targeting.HasTarget)
            {
                Thread.Sleep(30);
            }

            while (m_ptarget == -1 && Targeting.HasTarget)
            {
                Thread.Sleep(30);
            }

            Thread.Sleep(100);

            if (m_ptarget == -1)
            {
                Misc.SendMessage("Prompt Target Cancelled", color, true);
            }

            return(m_ptarget);
        }
Ejemplo n.º 4
0
        public int PromptTarget()
        {
            m_ptarget = -1;
            Misc.SendMessage("Select Item or Mobile", 945);
            Targeting.OneTimeTarget(false, new Targeting.TargetResponseCallback(PromptTargetExex_Callback));

            while (!Targeting.HasTarget)
            {
                Thread.Sleep(2);
            }

            while (m_ptarget == -1 && Targeting.HasTarget)
            {
                Thread.Sleep(30);
            }

            Thread.Sleep(100);

            if (m_ptarget == -1)
            {
                Misc.SendMessage("PromptTarget Cancelled", 945);
            }
            else
            {
                Misc.SendMessage("PromptTarget on Serial: " + m_ptarget, 945);
            }

            return(m_ptarget);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Prompt a target in-game, wait for the Player to select the ground. Can also specific a text message for prompt.
        /// </summary>
        /// <param name="message">Hint on what to select.</param>
        /// <param name="color">Color of the message. (default: 945, gray)</param>
        /// <returns>A Point3D object, containing the X,Y,Z coordinate</returns>
        public Point3D PromptGroundTarget(string message = "Select Ground Position", int color = 945)
        {
            m_pgtarget = Point3D.MinusOne;

            Misc.SendMessage(message, color, true);
            Targeting.OneTimeTarget(true, new Targeting.TargetResponseCallback(PromptGroundTargetExex_Callback));

            while (!Targeting.HasTarget)
            {
                Thread.Sleep(30);
            }

            while (m_pgtarget.X == -1 && Targeting.HasTarget)
            {
                Thread.Sleep(30);
            }

            Thread.Sleep(100);

            if (m_pgtarget.X == -1)
            {
                Misc.SendMessage("Prompt Gorund Target Cancelled", color, true);
            }

            return(m_pgtarget);
        }
Ejemplo n.º 6
0
        internal static void AutoRun()
        {
            if (!Assistant.Engine.Running)
            {
                return;
            }

            m_corpsefilter.RangeMax = MaxRange;

            // Check bag
            Assistant.Item bag = Assistant.World.FindItem(AutoLootBag);
            if (bag != null)
            {
                if (bag.RootContainer != World.Player)
                {
                    if (Settings.General.ReadBool("ShowMessageFieldCheckBox"))
                    {
                        Misc.SendMessage("Autoloot: Invalid Bag, Switch to backpack", 945);
                    }
                    AddLog("Invalid Bag, Switch to backpack");
                    AutoLootBag = (int)World.Player.Backpack.Serial.Value;
                }
            }
            else
            {
                if (Settings.General.ReadBool("ShowMessageFieldCheckBox"))
                {
                    Misc.SendMessage("Autoloot: Invalid Bag, Switch to backpack", 945);
                }
                AddLog("Invalid Bag, Switch to backpack");
                AutoLootBag = (int)World.Player.Backpack.Serial.Value;
            }
            Engine(Settings.AutoLoot.ItemsRead(AutoLootListName), AutoLootDelay, m_corpsefilter);
        }
Ejemplo n.º 7
0
        internal static void Engine()
        {
            // Check Bag
            Assistant.Item sbag = Assistant.World.FindItem(RestockSource);
            if (sbag == null)
            {
                if (Settings.General.ReadBool("ShowAgentMessageCheckBox"))
                {
                    Misc.SendMessage("Restock: Invalid Source Bag", 945);
                }
                AddLog("Invalid Source Bag");
                Assistant.Engine.MainWindow.RestockFinishWork();
                return;
            }
            Assistant.Item dbag = Assistant.World.FindItem(RestockDestination);
            if (dbag == null)
            {
                if (Settings.General.ReadBool("ShowAgentMessageCheckBox"))
                {
                    Misc.SendMessage("Restock: Invalid Destination Bag", 945);
                }
                AddLog("Invalid Destination Bag");
                Assistant.Engine.MainWindow.RestockFinishWork();
                return;
            }

            int exit = Engine(Settings.Restock.ItemsRead(RestockListName), RestockDelay, RestockSource, RestockDestination);
        }
Ejemplo n.º 8
0
        public void Execute(Assembly assembly)
        {
            // This is important for methods visibility. Check if all of these flags are really needed.
            BindingFlags bf = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod;

            MethodInfo run = null;

            // Search trough all methods and finds Run then calls it
            foreach (Type mt in assembly.GetTypes())
            {
                if (mt != null)
                {
                    run = mt.GetMethod("Run", bf);
                    if (run != null)
                    {
                        break;
                    }
                }
            }

            // If Run method does not exists would be rised an exception later but better to throw a
            // SyntaxErrorException now and log it too
            if (run == null)
            {
                string error = "Required method 'public void Run() missing from script.";
                Misc.SendMessage(error);
                throw new Microsoft.Scripting.SyntaxErrorException(error, null, new SourceSpan(), 0, Severity.FatalError);
            }

            // Creates an instance of the class runs the Run method
            object scriptInstance = Activator.CreateInstance(run.DeclaringType);

            run.Invoke(scriptInstance, null);
        }
Ejemplo n.º 9
0
        private static bool Run(Direction d, bool debug)
        {
            if (debug)
            {
                Misc.SendMessage("PathFind: Move to direction: " + d.ToString(), 55);
            }

            return(Player.Run(d.ToString()));
        }
Ejemplo n.º 10
0
        private static void Rotate(Direction d, bool debug)
        {
            if ((World.Player.Direction & Direction.mask) != d)
            {
                Player.Run(d.ToString());

                if (debug)
                {
                    Misc.SendMessage("PathFind: Rotate in direction: " + d.ToString(), 55);
                }
            }
        }
Ejemplo n.º 11
0
 internal static void AddItemByTarger(Assistant.Item dressItem)
 {
     if (dressItem.Layer != Layer.Invalid)
     {
         RazorEnhanced.Dress.DressItemNew toinsert = new RazorEnhanced.Dress.DressItemNew(dressItem.Name, dressItem.Layer, dressItem.Serial, true);
         RazorEnhanced.Settings.Dress.ItemInsertByLayer(Assistant.Engine.MainWindow.DressListSelect.Text, toinsert);
         RazorEnhanced.Dress.RefreshItems();
     }
     else
     {
         Misc.SendMessage("This item not have valid layer", false);
     }
 }
Ejemplo n.º 12
0
        internal static void UndressEngine()
        {
            // Check bag
            Assistant.Item bag = Assistant.World.FindItem(DressBag);
            if (bag == null)
            {
                Misc.SendMessage("Dress: Invalid Bag, Switch to backpack");
                AddLog("Invalid Bag, Switch to backpack");
                DressBag = (int)World.Player.Backpack.Serial.Value;
                RazorEnhanced.Settings.Dress.ListUpdate(DressListName, RazorEnhanced.Dress.DressDelay, (int)World.Player.Backpack.Serial.Value, DressConflict, true);
            }

            int exit = UndressEngine(Dress.DressDelay, Dress.DressBag);
        }
Ejemplo n.º 13
0
        internal static void DressEngine()
        {
            List <Dress.DressItem> items = Settings.Dress.ItemsRead(Dress.DressListName);

            // Check bag
            Assistant.Item bag = Assistant.World.FindItem(DressBag);
            if (bag == null)
            {
                Misc.SendMessage("Dress: Invalid Bag, Switch to backpack", 945);
                AddLog("Invalid Bag, Switch to backpack");
                DressBag = (int)World.Player.Backpack.Serial.Value;
            }

            int exit = DressEngine(items, Dress.DressDelay, Dress.DressBag, Dress.DressConflict);
        }
Ejemplo n.º 14
0
        internal static void AddItemByTarger(Assistant.Item dressItem)
        {
            int layertoinsert = LayerLayerToInt(dressItem.Layer);

            if (layertoinsert != -1)
            {
                RazorEnhanced.Dress.DressItem toinsert = new RazorEnhanced.Dress.DressItem(dressItem.Name, LayerLayerToInt(dressItem.Layer), dressItem.Serial, true);
                RazorEnhanced.Settings.Dress.ItemInsertByLayer(Assistant.Engine.MainWindow.DressListSelect.Text, toinsert);
                RazorEnhanced.Dress.RefreshItems();
            }
            else
            {
                Misc.SendMessage("This item not have valid layer: " + layertoinsert);
            }
        }
Ejemplo n.º 15
0
 public static ConfigData Load(string fullpath, Type configModel)
 {
     try
     {
         var json_text = File.ReadAllText(fullpath);
         return((ConfigData)JsonConvert.DeserializeObject(json_text, configModel));
     }
     catch (Exception e)
     {
         //TODO: show sensible output
         var msg = String.Format("ConfigData.Load FAILED:\nPATH: {0}\nMESSAGE: {1}\n", fullpath, e.Message);
         Console.Out.Write(msg);
         Misc.SendMessage(msg, 138);
     }
     return(null);
 }
Ejemplo n.º 16
0
 private static void FriendPlayerTarget_Callback(bool loc, Assistant.Serial serial, Assistant.Point3D pt, ushort itemid)
 {
     Assistant.Mobile friendplayer = World.FindMobile(serial);
     if (friendplayer != null && friendplayer.Serial.IsMobile && friendplayer.Serial != World.Player.Serial)
     {
         Engine.MainWindow.SafeAction(s => { Friend.AddPlayerToList(friendplayer.Name, friendplayer.Serial); });
     }
     else
     {
         if (Engine.MainWindow.ShowAgentMessageCheckBox.Checked)
         {
             Misc.SendMessage("Invalid target", false);
         }
         Friend.AddLog("Invalid target");
     }
 }
Ejemplo n.º 17
0
        public static void TargetResource(int item_serial, string resource_name)
        {
            Assistant.Item item = Assistant.World.FindItem(item_serial);
            if (item == null)
            {
                Scripts.SendMessageScriptError("Script Error: UseItem: Invalid Use Serial");
                return;
            }

            int number;

            switch (resource_name)
            {
            case "ore":
                number = 0;
                break;

            case "sand":
                number = 1;
                break;

            case "wood":
                number = 2;
                break;

            case "graves":
                number = 3;
                break;

            case "red_mushroom":
                number = 4;
                break;

            default:
                System.Int32.TryParse(resource_name, out number);
                break;
            }
            if (number >= 0)
            {
                TargetResource(item_serial, number);
            }
            else
            {
                Misc.SendMessage("Valid resource types are ore, sand, wood, graves, red mushroom, or a number");
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Given an AutoLoot list name, return a list of AutoLootItem associated.
 /// </summary>
 /// <param name="lootListName">Name of the AutoLoot list.</param>
 /// <returns></returns>
 public static List <AutoLootItem> GetList(string lootListName)
 {
     if (Settings.AutoLoot.ListExists(lootListName))
     {
         List <AutoLootItem> retList = new List <AutoLootItem>();
         var lootDict = Settings.AutoLoot.ItemsRead(lootListName);
         foreach (KeyValuePair <int, List <AutoLootItem> > entry in lootDict)
         {
             foreach (AutoLootItem lootItem in entry.Value.FindAll(item => item.Graphics != -1))
             {
                 retList.Add(lootItem);
             }
         }
         return(retList);
     }
     Misc.SendMessage("Autoloot: Invalid Loot List Name", 945, true);
     return(null);
 }
Ejemplo n.º 19
0
        internal static void DressEngine()
        {
            try
            {
                List <Dress.DressItemNew> items = Settings.Dress.ItemsRead(Dress.DressListName);

                // Check bag
                Assistant.Item bag = Assistant.World.FindItem(m_dressbag);
                if (bag == null)
                {
                    if (Assistant.Engine.MainWindow.ShowAgentMessageCheckBox.Checked)
                    {
                        Misc.SendMessage("Dress: Invalid Bag, Switch to backpack", 945, true);
                    }
                    AddLog("Invalid Bag, Switch to backpack");
                    DressBag = (int)World.Player.Backpack.Serial.Value;
                }

                DressEngine(items, m_dressdelay, m_dressbag, m_dressconflict);
            }
            catch { }
        }
Ejemplo n.º 20
0
 public static uint GetLootBag()
 {
     // Check bag
     Assistant.Item bag = Assistant.World.FindItem(AutoLoot.AutoLootBag);
     if (bag != null)
     {
         if (bag.RootContainer != World.Player)
         {
             if (!lootChangeMsgSent)
             {
                 Misc.SendMessage("Autoloot: Invalid Bag, Switch to backpack", 945, true);
                 AddLog("Invalid Bag, Switch to backpack");
                 lootChangeMsgSent = true;
             }
             if (World.Player == null || World.Player.Backpack == null || World.Player.Backpack.Serial == null)
             {
                 return(0);
             }
             return(World.Player.Backpack.Serial.Value);
         }
     }
     else
     {
         if (!lootChangeMsgSent)
         {
             Misc.SendMessage("Autoloot: Invalid Bag, Switch to backpack", 945, true);
             AddLog("Invalid Bag, Switch to backpack");
             lootChangeMsgSent = true;
         }
         if (World.Player == null || World.Player.Backpack == null || World.Player.Backpack.Serial == null)
         {
             return(0);
         }
         return(World.Player.Backpack.Serial.Value);
     }
     lootChangeMsgSent = false;
     return(bag.Serial.Value);
 }
Ejemplo n.º 21
0
        internal static void AutoRun()
        {
            if (!Assistant.Engine.Running)
            {
                return;
            }

            // Genero filtro item
            m_itemfilter.RangeMax = MaxRange;

            // Check bag
            Assistant.Item bag = Assistant.World.FindItem(ScavengerBag);
            if (bag != null)
            {
                if (bag.RootContainer != World.Player)
                {
                    if (Settings.General.ReadBool("ShowMessageFieldCheckBox"))
                    {
                        Misc.SendMessage("Scavenger: Invalid Bag, Switch to backpack", 945);
                    }
                    AddLog("Invalid Bag, Switch to backpack");
                    ScavengerBag = (int)World.Player.Backpack.Serial.Value;
                }
            }
            else
            {
                if (Settings.General.ReadBool("ShowMessageFieldCheckBox"))
                {
                    Misc.SendMessage("Scavenger: Invalid Bag, Switch to backpack", 945);
                }
                AddLog("Invalid Bag, Switch to backpack");
                ScavengerBag = (int)World.Player.Backpack.Serial.Value;
            }

            Engine(Settings.Scavenger.ItemsRead(ScavengerListName), ScavengerDelay, m_itemfilter);
        }
Ejemplo n.º 22
0
 private void Log(object messageString)
 {
     Misc.SendMessage(messageString, 201);
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Use reflection to generete the Python API List
        /// </summary>
        public static DocContainer GetPythonAPI()
        {
            if (cachedDocs != null)
            {
                return(cachedDocs);
            }

            Misc.SendMessage("AutoDoc v0.01", 20);
            var docSections = new List <Type> {
                // Test
                typeof(AutoDoc),
                // API
                typeof(Misc),
                typeof(Item),
                typeof(Items),
                typeof(Mobile),
                typeof(Mobiles),
                typeof(Player),
                typeof(Spells),
                typeof(Gumps),
                typeof(Journal),
                typeof(Target),
                typeof(Statics),

                // API Agents
                typeof(AutoLoot),
                typeof(Scavenger),
                typeof(SellAgent),
                typeof(BuyAgent),
                typeof(Organizer),
                typeof(Dress),
                typeof(Friend),
                typeof(Restock),
                typeof(BandageHeal),
                typeof(PathFinding),
                typeof(DPSMeter),
                typeof(Timer),
                typeof(Vendor),

                // Other classes
                typeof(Point2D),
                typeof(Point3D),
                typeof(Tile),
                typeof(Property),
                typeof(PathFinding.Route),
                typeof(Items.Filter),
                typeof(Mobiles.Filter),
                typeof(HotKeyEvent),
            };


            BindingFlags flags = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;

            cachedDocs = new DocContainer();

            foreach (var docSection in docSections)
            {
                var classDocs = AutoDoc.ReadClass(docSection, flags);
                cachedDocs.AddRange(classDocs);
            }

            return(cachedDocs);
        }
Ejemplo n.º 24
0
        private static bool Engine(Route r)
        {
            List <Tile> road = PathMove.GetPath(r.X, r.Y, r.IgnoreMobile);

            if (road == null) // No way to destination
            {
                Misc.SendMessage("PathFind: Destination not valid", 33);
                return(false);
            }

            foreach (Tile step in road)
            {
                if (Player.Position.X == r.X && Player.Position.Y == r.Y)
                {
                    Misc.SendMessage("PathFind: Destination reached", 66);
                    return(true);
                }
                bool walkok = false;
                if (step.X > Player.Position.X && step.Y == Player.Position.Y) //East
                {
                    Rotate(Direction.East, r.DebugMessage);
                    walkok = Run(Direction.East, r.DebugMessage);
                }
                else if (step.X < Player.Position.X && step.Y == Player.Position.Y) // West
                {
                    Rotate(Direction.West, r.DebugMessage);
                    walkok = Run(Direction.West, r.DebugMessage);
                }
                else if (step.X == Player.Position.X && step.Y < Player.Position.Y) //North
                {
                    Rotate(Direction.North, r.DebugMessage);
                    walkok = Run(Direction.North, r.DebugMessage);
                }
                else if (step.X == Player.Position.X && step.Y > Player.Position.Y) //South
                {
                    Rotate(Direction.South, r.DebugMessage);
                    walkok = Run(Direction.South, r.DebugMessage);
                }
                else if (step.X > Player.Position.X && step.Y > Player.Position.Y) //Down
                {
                    Rotate(Direction.Down, r.DebugMessage);
                    walkok = Run(Direction.Down, r.DebugMessage);
                }
                else if (step.X < Player.Position.X && step.Y < Player.Position.Y) //UP
                {
                    Rotate(Direction.Up, r.DebugMessage);
                    walkok = Run(Direction.Up, r.DebugMessage);
                }
                else if (step.X > Player.Position.X && step.Y < Player.Position.Y) //Right
                {
                    Rotate(Direction.Right, r.DebugMessage);
                    walkok = Run(Direction.Right, r.DebugMessage);
                }
                else if (step.X < Player.Position.X && step.Y > Player.Position.Y) //Left
                {
                    Rotate(Direction.Left, r.DebugMessage);
                    walkok = Run(Direction.Left, r.DebugMessage);
                }
                else if (Player.Position.X == step.X && Player.Position.Y == step.Y) // no action
                {
                    walkok = true;
                }

                if (!walkok)
                {
                    if (r.DebugMessage)
                    {
                        Misc.SendMessage("PathFind: Move action FAIL", 33);
                    }

                    if (r.UseResync)
                    {
                        Misc.Resync();
                        Misc.Pause(200);
                    }

                    return(false);
                }
                else
                {
                    if (r.DebugMessage)
                    {
                        Misc.SendMessage("PathFind: Move action OK", 66);
                    }
                }
            }

            if (Player.Position.X == r.X && Player.Position.Y == r.Y)
            {
                Misc.SendMessage("PathFind: Destination reached", 66);
                return(true);
            }
            else
            {
                Go(r);
                return(false);
            }
        }
Ejemplo n.º 25
0
            private void AsyncStart()
            {
                if (World.Player == null)
                {
                    return;
                }

                try
                {
                    string fullpath = Settings.GetFullPathForScript(m_Filename);
                    string ext      = Path.GetExtension(fullpath);

                    if (ext.Equals(".cs", StringComparison.InvariantCultureIgnoreCase))
                    {
                        CSharpEngine csharpEngine  = CSharpEngine.Instance;
                        bool         compileErrors = csharpEngine.CompileFromFile(fullpath, true, out StringBuilder compileMessages, out Assembly assembly);
                        if (compileMessages.Length > 0)
                        {
                            Misc.SendMessage(compileMessages.ToString());
                        }
                        if (compileErrors == true)
                        {
                            Stop();
                            return;
                        }
                        csharpEngine.Execute(assembly);
                    }
                    else if (ext.Equals(".uos", StringComparison.InvariantCultureIgnoreCase))
                    {
                        // Using // only will be deprecated instead of //UOS
                        var text = System.IO.File.ReadAllLines(fullpath);
                        if ((text[0].Substring(0, 2) == "//") && text[0].Length < 5)
                        {
                            string message = "WARNING: // header for UOS scripts is going to be deprecated. Please use //UOS instead";
                            Misc.SendMessage(message);
                        }

                        UOSteamEngine uosteam = UOSteamEngine.Instance;
                        uosteam.Execute(fullpath);
                    }
                    else
                    {
                        DateTime lastModified = System.IO.File.GetLastWriteTime(fullpath);
                        if (FileChangeDate < lastModified)
                        {
                            ReadText(fullpath);
                            FileChangeDate = System.IO.File.GetLastWriteTime(fullpath);
                            Create(null);
                        }

                        /*Dalamar: BEGIN "fix python env" */
                        //EXECUTION OF THE SCRIPT
                        //Refactoring option, the whole block can be replaced by:
                        //
                        //m_pe.Execute(m_Text);

                        m_Source = m_Engine.CreateScriptSourceFromString(m_Text);
                        // "+": USE PythonCompilerOptions in order to initialize Python modules correctly, without it the Python env is half broken
                        PythonCompilerOptions pco = (PythonCompilerOptions)m_Engine.GetCompilerOptions(m_Scope);
                        pco.ModuleName = "__main__";
                        pco.Module    |= ModuleOptions.Initialize;
                        CompiledCode compiled = m_Source.Compile(pco);
                        Journal      journal  = m_Engine.Runtime.Globals.GetVariable("Journal") as Journal;
                        journal.Active = true;
                        compiled.Execute(m_Scope);
                        journal.Active = false;
                        // "-": DONT execute directly, unless you are not planning to import external modules.
                        //m_Source.Execute(m_Scope);

                        /*Dalamar: END*/
                    }
                }
                catch (IronPython.Runtime.Exceptions.SystemExitException)
                {
                    Stop();
                    // sys.exit - terminate the thread
                }
                catch (Exception ex)
                {
                    if (ex is System.Threading.ThreadAbortException)
                    {
                        return;
                    }

                    string display_error = ex.Message;
                    if (m_Engine != null)
                    {
                        display_error = m_Engine.GetService <ExceptionOperations>().FormatException(ex);
                    }
                    SendMessageScriptError("ERROR " + m_Filename + ":" + display_error.Replace("\n", " | "));

                    if (ScriptErrorLog) // enabled log of error
                    {
                        StringBuilder log = new StringBuilder();
                        log.Append(Environment.NewLine + "============================ START REPORT ============================ " + Environment.NewLine);

                        DateTime dt = DateTime.Now;
                        log.Append("---> Time: " + String.Format("{0:F}", dt) + Environment.NewLine);
                        log.Append(Environment.NewLine);

                        if (ex is SyntaxErrorException)
                        {
                            SyntaxErrorException se = ex as SyntaxErrorException;
                            log.Append("----> Syntax Error:" + Environment.NewLine);
                            log.Append("-> LINE: " + se.Line + Environment.NewLine);
                            log.Append("-> COLUMN: " + se.Column + Environment.NewLine);
                            log.Append("-> SEVERITY: " + se.Severity + Environment.NewLine);
                            log.Append("-> MESSAGE: " + se.Message + Environment.NewLine);
                        }
                        else
                        {
                            log.Append("----> Generic Error:" + Environment.NewLine);
                            log.Append(display_error);
                        }

                        log.Append(Environment.NewLine);
                        log.Append("============================ END REPORT ============================ ");
                        log.Append(Environment.NewLine);

                        try // For prevent crash in case of file are busy or inaccessible
                        {
                            File.AppendAllText(Assistant.Engine.RootPath + "\\" + m_Filename + ".ERROR", log.ToString());
                        }
                        catch { }
                        log.Clear();
                    }
                }
            }
Ejemplo n.º 26
0
            private void OnTick(object state)
            {
                foreach (EnhancedScript script in EnhancedScripts.Values.ToList())
                {
                    if (script.Run)
                    {
                        if (ScriptStartStopMessage && script.StartMessage)
                        {
                            Misc.SendMessage("START: " + script.Filename, 70, false);
                            script.StartMessage = false;
                            script.StopMessage  = true;
                        }

                        if (script.Loop)
                        {
                            if (script.IsStopped)
                            {
                                script.Reset();
                            }

                            if (script.IsUnstarted)
                            {
                                script.Start();
                            }
                        }
                        else
                        {
                            if (script.IsStopped)
                            {
                                script.Reset();
                            }
                            else if (script.IsUnstarted)
                            {
                                script.Start();
                            }
                        }
                    }
                    else
                    {
                        if (ScriptStartStopMessage && script.StopMessage)
                        {
                            Misc.SendMessage("HALT: " + script.Filename, 70, false);
                            script.StartMessage = true;
                            script.StopMessage  = false;
                        }

                        if (script.IsRunning)
                        {
                            script.Stop();
                        }

                        if (script.IsStopped)
                        {
                            script.Reset();
                        }
                    }
                }

                if (World.Player != null && Client.Running)                 // Parte agent
                {
                    if (AutoLoot.AutoMode && !IsRunningThread(m_AutoLootThread))
                    {
                        try
                        {
                            m_AutoLootThread = new Thread(AutoLoot.AutoRun);
                            m_AutoLootThread.Start();
                        }
                        catch { }
                    }

                    if (Scavenger.AutoMode && !IsRunningThread(m_ScavengerThread))
                    {
                        try
                        {
                            m_ScavengerThread = new Thread(Scavenger.AutoRun);
                            m_ScavengerThread.Start();
                        }
                        catch { }
                    }

                    if (BandageHeal.AutoMode && !IsRunningThread(m_BandageHealThread))
                    {
                        try
                        {
                            m_BandageHealThread = new Thread(BandageHeal.AutoRun);
                            m_BandageHealThread.Start();
                        }
                        catch { }
                    }

                    if ((Scavenger.AutoMode || AutoLoot.AutoMode || Filters.AutoCarver) && !IsRunningThread(m_DragDropThread))
                    {
                        try
                        {
                            m_DragDropThread = new Thread(DragDropManager.AutoRun);
                            m_DragDropThread.Start();
                        }
                        catch { }
                    }

                    if (Filters.AutoCarver && !IsRunningThread(m_AutoCarverThread))
                    {
                        try
                        {
                            m_AutoCarverThread = new Thread(Filters.CarveAutoRun);
                            m_AutoCarverThread.Start();
                        }
                        catch { }
                    }

                    if (Filters.BoneCutter && !IsRunningThread(m_BoneCutterThread))
                    {
                        try
                        {
                            m_BoneCutterThread = new Thread(Filters.BoneCutterRun);
                            m_BoneCutterThread.Start();
                        }
                        catch { }
                    }

                    if (Filters.AutoModeRemount && !IsRunningThread(m_AutoRemountThread))
                    {
                        try
                        {
                            m_AutoRemountThread = new Thread(Filters.RemountAutoRun);
                            m_AutoRemountThread.Start();
                        }
                        catch { }
                    }
                }
            }
Ejemplo n.º 27
0
        public static void TestRoute(int startx, int starty, int startz, int endx, int endy, int endz)
        {
            if (!m_loaded)
            {
                LoadTileLandData();
            }

            multidata = Assistant.World.Multis.Values.ToList();

            //Calcolo l'asse più lungo
            int xAxis    = Math.Abs(startx - endx);
            int yAxis    = Math.Abs(starty - endy);
            int range    = xAxis > yAxis ? xAxis + 20 : yAxis + 20;
            int gridSize = range * 2;
            Dictionary <int, int> coordsX = new Dictionary <int, int>();
            Dictionary <int, int> coordsY = new Dictionary <int, int>();
            Dictionary <int, int> coordsZ = new Dictionary <int, int>();

            //Crea la griglia 3D
            WorldGrid walkgrid = new WorldGrid(gridSize, gridSize, 256);

            Misc.SendMessage("Grid dim: " + gridSize + "x" + gridSize);

            int minx = startx > endx ? endx : startx;
            int maxx = startx > endx ? startx : endx;
            int miny = starty > endy ? starty : endy;
            int maxy = starty > endy ? endy : starty;

            Misc.SendMessage("Min x: " + minx + " Max x: " + maxx);
            Misc.SendMessage("Min y: " + miny + " Max y: " + maxy);

            int mediumXPoint = (startx + endx) / 2;
            int mediumYPoint = (starty + endy) / 2;

            for (int x = 0, xx = mediumXPoint - range; x < walkgrid.Right; x++, xx++)
            {
                coordsX.Add(x, xx);
            }
            for (int y = 0, yy = mediumYPoint - range; y < walkgrid.Top; y++, yy++)
            {
                coordsY.Add(y, yy);
            }
            for (int z = 0, zz = -127; z < walkgrid.Back; z++, zz++)
            {
                coordsZ.Add(z, zz);
            }

            //Riempie la griglia
            for (int x = 0, xx = mediumXPoint - range; x < walkgrid.Right; x++, xx++)
            {
                for (int y = 0, yy = mediumYPoint - range; y < walkgrid.Top; y++, yy++)
                {
                    //Controllo che non sia una casa
                    if (CheckHouse(xx, yy))
                    {
                        //Se in queste x-y c'è una casa, setta tutta la Z a False
                        for (int z = 0; z < walkgrid.Back; z++)
                        {
                            walkgrid.MarkPosition(new PathFinderAStar3D.Point3D(x, y, z), true);
                        }
                    }
                    else
                    {
                        Dictionary <int, bool> zResults = CheckStatic(xx, yy);

                        if (zResults.Count > 0)
                        {
                            //Se in queste x-y c'è roba statica, setta tutta la Z a False
                            for (int z = 0, zz = -127; z < walkgrid.Back; z++, zz++)
                            {
                                if (zResults.ContainsKey(zz))
                                {
                                    walkgrid.MarkPosition(new PathFinderAStar3D.Point3D(x, y, z), zResults[zz]);
                                }
                                else
                                {
                                    walkgrid.MarkPosition(new PathFinderAStar3D.Point3D(x, y, z), true);
                                }
                            }
                        }
                        else
                        {
                            //Se in queste x-y c'è roba statica, setta tutta la Z a False
                            for (int z = 0; z < walkgrid.Back; z++)
                            {
                                walkgrid.MarkPosition(new PathFinderAStar3D.Point3D(x, y, z), true);
                            }
                        }

                        zResults = CheckDynamic(xx, yy);

                        if (zResults.Count > 0)
                        {
                            //Se in queste x-y c'è roba statica, setta tutta la Z a False
                            for (int z = 0, zz = -127; z < walkgrid.Back; z++, zz++)
                            {
                                if (zResults.ContainsKey(zz))
                                {
                                    walkgrid.MarkPosition(new PathFinderAStar3D.Point3D(x, y, z), zResults[zz]);
                                }
                                else
                                {
                                    walkgrid.MarkPosition(new PathFinderAStar3D.Point3D(x, y, z), true);
                                }
                            }
                        }
                    }
                }
            }

            var StartX = coordsX.First(x => x.Value == startx).Key;
            var StartY = coordsY.First(y => y.Value == starty).Key;
            var StartZ = coordsZ.First(z => z.Value == startz).Key;

            PathFinderAStar3D.Point3D startPos = new PathFinderAStar3D.Point3D(StartX, StartY, StartZ);

            var EndX = coordsX.First(x => x.Value == endx).Key;
            var EndY = coordsY.First(y => y.Value == endy).Key;
            var EndZ = coordsZ.First(z => z.Value == endz).Key;

            PathFinderAStar3D.Point3D endPos = new PathFinderAStar3D.Point3D(EndX, EndY, EndZ);

            //Calcola il percorso
            SearchNode PathList = PathFinder.FindPath(walkgrid, startPos, endPos);

            Console.WriteLine("Posizione Corrente - X: " + PathList.position.X + " - Y:  " + PathList.position.Y);

            PathFinderAStar3D.Point3D oldstep = PathList.position;

            bool skippedMovement = false;

            while (PathList.next != null)
            {
                PathFinderAStar3D.Point3D step = PathList.next.position;

                int newStepX = step.X - oldstep.X;
                int newStepY = step.Y - oldstep.Y;


                for (int x = 0, xx = mediumXPoint - range; x < walkgrid.Right; x++, xx++)
                {
                    for (int y = 0, yy = mediumYPoint - range; y < walkgrid.Top; y++, yy++)
                    {
                        Dictionary <int, bool> zResult = CheckDynamic(xx, yy);
                        if (zResult.Count > 0)
                        {
                            //Se in queste x-y c'è roba statica, setta tutta la Z a False
                            for (int z = 0, zz = -127; z < walkgrid.Back; z++, zz++)
                            {
                                if (zResult.ContainsKey(zz))
                                {
                                    walkgrid.MarkPosition(new PathFinderAStar3D.Point3D(x, y, z), zResult[zz]);
                                }
                                else
                                {
                                    walkgrid.MarkPosition(new PathFinderAStar3D.Point3D(x, y, z), true);
                                }
                            }

                            PathList = PathFinder.FindPath(walkgrid, oldstep, endPos);
                        }
                    }
                }


                if (oldstep.X != step.X && oldstep.Y != step.Y && IsSurrounded(walkgrid, oldstep, newStepX, newStepY))
                {
                    //Movimento diagonale

                    Assistant.Point3D   pp2 = Assistant.World.Player.Position;
                    Assistant.Direction dd2 = Assistant.World.Player.Direction;

                    //SE
                    if (newStepX == 1 && newStepY == 1)
                    {
                        if (walkgrid.PositionIsFree(new PathFinderAStar3D.Point3D(oldstep.X + 1, oldstep.Y,
                                                                                  coordsZ.First(z => z.Value == World.Player.Position.Z).Key)))
                        {
                            Console.WriteLine("East e' libera!");

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "East")
                            {
                                RazorEnhanced.Player.Walk("East");
                                while (RazorEnhanced.Player.Direction != "East")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("East");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }

                            //Reset della posizione corrente
                            pp2 = Assistant.World.Player.Position;

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "South")
                            {
                                RazorEnhanced.Player.Walk("South");
                                while (RazorEnhanced.Player.Direction != "South")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("South");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }
                        }
                        else if (walkgrid.PositionIsFree(new PathFinderAStar3D.Point3D(oldstep.X, oldstep.Y + 1,
                                                                                       coordsZ.First(z => z.Value == World.Player.Position.Z).Key)))
                        {
                            Console.WriteLine("South e' libera!");

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "South")
                            {
                                RazorEnhanced.Player.Walk("South");
                                while (RazorEnhanced.Player.Direction != "South")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("South");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }

                            //Reset della posizione corrente
                            pp2 = Assistant.World.Player.Position;

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "East")
                            {
                                RazorEnhanced.Player.Walk("East");
                                while (RazorEnhanced.Player.Direction != "East")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("East");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }
                        }
                        else
                        {
                            walkgrid.MarkPosition(new PathFinderAStar3D.Point3D(step.X, step.Y, step.Z), true);
                            PathList        = PathFinder.FindPath(walkgrid, oldstep, endPos);
                            skippedMovement = true;
                        }
                    }
                    //NW
                    else if (newStepX == -1 && newStepY == -1)
                    {
                        if (
                            walkgrid.PositionIsFree(new PathFinderAStar3D.Point3D(oldstep.X - 1, oldstep.Y,
                                                                                  coordsZ.First(z => z.Value == World.Player.Position.Z).Key)))
                        {
                            Console.WriteLine("West e' libera!");

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "West")
                            {
                                RazorEnhanced.Player.Walk("West");
                                while (RazorEnhanced.Player.Direction != "West")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("West");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }

                            //Reset della posizione corrente
                            pp2 = Assistant.World.Player.Position;

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "North")
                            {
                                RazorEnhanced.Player.Walk("North");
                                while (RazorEnhanced.Player.Direction != "North")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("North");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }
                        }
                        else if (
                            walkgrid.PositionIsFree(new PathFinderAStar3D.Point3D(oldstep.X, oldstep.Y - 1,
                                                                                  coordsZ.First(z => z.Value == World.Player.Position.Z).Key)))
                        {
                            Console.WriteLine("North e' libera!");

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "North")
                            {
                                RazorEnhanced.Player.Walk("North");
                                while (RazorEnhanced.Player.Direction != "North")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("North");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }

                            //Reset della posizione corrente
                            pp2 = Assistant.World.Player.Position;

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "West")
                            {
                                RazorEnhanced.Player.Walk("West");
                                while (RazorEnhanced.Player.Direction != "West")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("West");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }
                        }
                        else
                        {
                            walkgrid.MarkPosition(new PathFinderAStar3D.Point3D(step.X, step.Y, step.Z), true);
                            PathList        = PathFinder.FindPath(walkgrid, oldstep, endPos);
                            skippedMovement = true;
                        }
                    }
                    //NE
                    else if (newStepX == 1 && newStepY == -1)
                    {
                        if (
                            walkgrid.PositionIsFree(new PathFinderAStar3D.Point3D(oldstep.X + 1, oldstep.Y,
                                                                                  coordsZ.First(z => z.Value == World.Player.Position.Z).Key)))
                        {
                            Console.WriteLine("East e' libera!");

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "East")
                            {
                                RazorEnhanced.Player.Walk("East");
                                while (RazorEnhanced.Player.Direction != "East")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("East");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }

                            //Reset della posizione corrente
                            pp2 = Assistant.World.Player.Position;

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "North")
                            {
                                RazorEnhanced.Player.Walk("North");
                                while (RazorEnhanced.Player.Direction != "North")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("North");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }
                        }
                        else if (
                            walkgrid.PositionIsFree(new PathFinderAStar3D.Point3D(oldstep.X, oldstep.Y - 1,
                                                                                  coordsZ.First(z => z.Value == World.Player.Position.Z).Key)))
                        {
                            Console.WriteLine("North e' libera!");

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "North")
                            {
                                RazorEnhanced.Player.Walk("North");
                                while (RazorEnhanced.Player.Direction != "North")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("North");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }

                            //Reset della posizione corrente
                            pp2 = Assistant.World.Player.Position;

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "East")
                            {
                                RazorEnhanced.Player.Walk("East");
                                while (RazorEnhanced.Player.Direction != "East")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("East");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }
                        }
                        else
                        {
                            walkgrid.MarkPosition(new PathFinderAStar3D.Point3D(step.X, step.Y, step.Z), true);
                            PathList        = PathFinder.FindPath(walkgrid, oldstep, endPos);
                            skippedMovement = true;
                        }
                    }
                    //SW
                    else if (newStepX == -1 && newStepY == 1)
                    {
                        if (
                            walkgrid.PositionIsFree(new PathFinderAStar3D.Point3D(oldstep.X - 1, oldstep.Y,
                                                                                  coordsZ.First(z => z.Value == World.Player.Position.Z).Key)))
                        {
                            Console.WriteLine("West e' libera!");

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "West")
                            {
                                RazorEnhanced.Player.Walk("West");
                                while (RazorEnhanced.Player.Direction != "West")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("West");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }

                            //Reset della posizione corrente
                            pp2 = Assistant.World.Player.Position;

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "South")
                            {
                                RazorEnhanced.Player.Walk("South");
                                while (RazorEnhanced.Player.Direction != "South")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("South");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }
                        }
                        else if (
                            walkgrid.PositionIsFree(new PathFinderAStar3D.Point3D(oldstep.X, oldstep.Y + 1,
                                                                                  coordsZ.First(z => z.Value == World.Player.Position.Z).Key)))
                        {
                            Console.WriteLine("South e' libera!");

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "South")
                            {
                                RazorEnhanced.Player.Walk("South");
                                while (RazorEnhanced.Player.Direction != "South")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("South");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }

                            //Reset della posizione corrente
                            pp2 = Assistant.World.Player.Position;

                            //Switcha la direzione
                            if (RazorEnhanced.Player.Direction != "West")
                            {
                                RazorEnhanced.Player.Walk("West");
                                while (RazorEnhanced.Player.Direction != "West")
                                {
                                    Misc.Pause(10);
                                }
                            }

                            //Si muove
                            RazorEnhanced.Player.Run("West");
                            while (pp2 == Assistant.World.Player.Position)
                            {
                                Misc.Pause(10);
                            }
                        }
                        else
                        {
                            walkgrid.MarkPosition(new PathFinderAStar3D.Point3D(step.X, step.Y, step.Z), true);
                            PathList        = PathFinder.FindPath(walkgrid, oldstep, endPos);
                            skippedMovement = true;
                        }
                    }
                    else
                    {
                        int xx1 = step.X - oldstep.X;
                        int yy1 = step.Y - oldstep.Y;
                        Assistant.Point3D oldplayerpos = Assistant.World.Player.Position;

                        while (Assistant.World.Player.Position.X != oldplayerpos.X + xx1 ||
                               Assistant.World.Player.Position.Y != oldplayerpos.Y + yy1)
                        {
                            pp2 = Assistant.World.Player.Position;
                            dd2 = Assistant.World.Player.Direction;

                            if (xx1 <= -1 && yy1 <= -1)
                            {
                                RazorEnhanced.Player.Run("Up");
                            }
                            else if (xx1 <= -1 && yy1 == 0)
                            {
                                RazorEnhanced.Player.Run("West");
                            }
                            else if (xx1 <= -1 && yy1 >= 1)
                            {
                                RazorEnhanced.Player.Run("Left");
                            }
                            else if (xx1 == 0 && yy1 >= 1)
                            {
                                RazorEnhanced.Player.Run("South");
                            }
                            else if (xx1 >= 1 && yy1 >= 1)
                            {
                                RazorEnhanced.Player.Run("Down");
                            }
                            else if (xx1 >= 1 && yy1 == 0)
                            {
                                RazorEnhanced.Player.Run("East");
                            }
                            else if (xx1 >= 1 && yy1 <= -1)
                            {
                                RazorEnhanced.Player.Run("Right");
                            }
                            else if (xx1 == 0 && yy1 <= -1)
                            {
                                RazorEnhanced.Player.Run("North");
                            }

                            while (pp2 == Assistant.World.Player.Position && dd2 == Assistant.World.Player.Direction)
                            {
                                Misc.Pause(10);
                            }
                        }
                    }
                }
                else
                {
                    int xx1 = step.X - oldstep.X;
                    int yy1 = step.Y - oldstep.Y;
                    Assistant.Point3D oldplayerpos = Assistant.World.Player.Position;

                    while (Assistant.World.Player.Position.X != oldplayerpos.X + xx1 ||
                           Assistant.World.Player.Position.Y != oldplayerpos.Y + yy1)
                    {
                        Assistant.Point3D   pp2 = Assistant.World.Player.Position;
                        Assistant.Direction dd2 = Assistant.World.Player.Direction;

                        if (xx1 <= -1 && yy1 <= -1)
                        {
                            RazorEnhanced.Player.Run("Up");
                        }
                        else if (xx1 <= -1 && yy1 == 0)
                        {
                            RazorEnhanced.Player.Run("West");
                        }
                        else if (xx1 <= -1 && yy1 >= 1)
                        {
                            RazorEnhanced.Player.Run("Left");
                        }
                        else if (xx1 == 0 && yy1 >= 1)
                        {
                            RazorEnhanced.Player.Run("South");
                        }
                        else if (xx1 >= 1 && yy1 >= 1)
                        {
                            RazorEnhanced.Player.Run("Down");
                        }
                        else if (xx1 >= 1 && yy1 == 0)
                        {
                            RazorEnhanced.Player.Run("East");
                        }
                        else if (xx1 >= 1 && yy1 <= -1)
                        {
                            RazorEnhanced.Player.Run("Right");
                        }
                        else if (xx1 == 0 && yy1 <= -1)
                        {
                            RazorEnhanced.Player.Run("North");
                        }

                        while (pp2 == Assistant.World.Player.Position && dd2 == Assistant.World.Player.Direction)
                        {
                            Misc.Pause(10);
                        }
                    }
                }

                Console.WriteLine("Prossimo Step - X: " + step.X + " - Y:  " + step.Y);

                if (!skippedMovement)
                {
                    oldstep  = step;
                    PathList = PathList.next;
                }
                else
                {
                    skippedMovement = false;
                }

                //Controllo se è cambiato il multidata
                if (multidata != Assistant.World.Multis.Values.ToList())
                {
                    multidata = Assistant.World.Multis.Values.ToList();

                    for (int x = 0, xx = mediumXPoint - range; x < walkgrid.Right; x++, xx++)
                    {
                        for (int y = 0, yy = mediumYPoint - range; y < walkgrid.Top; y++, yy++)
                        {
                            //Controllo che non sia una casa
                            if (CheckHouse(xx, yy))
                            {
                                //Se in queste x-y c'è una casa, setta tutta la Z a False
                                for (int z = 0; z < walkgrid.Back; z++)
                                {
                                    walkgrid.MarkPosition(new PathFinderAStar3D.Point3D(x, y, z), true);
                                }
                            }
                        }
                    }

                    PathList = PathFinder.FindPath(walkgrid, oldstep, endPos);
                }
            }


            Console.WriteLine("Posizione Finale - X: " + PathList.position.X + " - Y:  " + PathList.position.Y);
        }
Ejemplo n.º 28
0
 private void button1_Click(object sender, EventArgs e)
 {
     Misc.SendMessage("Hello, my name is " + Player.Name);
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Run a given path, represented as list of Tile (see PathFindig.GetPath).
        /// </summary>
        /// <param name="path">List of coordinates as Tile objects.</param>
        /// <param name="timeout">Maximum amount of time to run the path. (default: -1, no limit)</param>
        /// <param name="debugMessage">Outputs a debug message.</param>
        /// <param name="useResync">ReSyncs the path calculation.</param>
        /// <returns>True: if it finish the path in time. False: otherwise</returns>
        public static bool RunPath(List <Tile> path, float timeout = -1, bool debugMessage = false, bool useResync = true)
        {
            if (path == null)
            {
                return(false);
            }
            DateTime timeStart, timeEnd;

            timeStart = DateTime.Now;
            timeEnd   = (timeout < 0) ? timeStart.AddDays(1) : timeStart.AddSeconds(timeout);

            Tile dst = path.Last();

            foreach (Tile step in path)
            {
                if (Player.Position.X == dst.X && Player.Position.Y == dst.Y)
                {
                    Misc.SendMessage("PathFind: Destination reached", 66);
                    return(true);
                }
                bool walkok = false;
                if (step.X > Player.Position.X && step.Y == Player.Position.Y) //East
                {
                    Rotate(Direction.east, debugMessage);
                    walkok = Run(Direction.east, debugMessage);
                }
                else if (step.X < Player.Position.X && step.Y == Player.Position.Y) // West
                {
                    Rotate(Direction.west, debugMessage);
                    walkok = Run(Direction.west, debugMessage);
                }
                else if (step.X == Player.Position.X && step.Y < Player.Position.Y) //North
                {
                    Rotate(Direction.north, debugMessage);
                    walkok = Run(Direction.north, debugMessage);
                }
                else if (step.X == Player.Position.X && step.Y > Player.Position.Y) //South
                {
                    Rotate(Direction.south, debugMessage);
                    walkok = Run(Direction.south, debugMessage);
                }
                else if (step.X > Player.Position.X && step.Y > Player.Position.Y) //Down
                {
                    Rotate(Direction.down, debugMessage);
                    walkok = Run(Direction.down, debugMessage);
                }
                else if (step.X < Player.Position.X && step.Y < Player.Position.Y) //UP
                {
                    Rotate(Direction.up, debugMessage);
                    walkok = Run(Direction.up, debugMessage);
                }
                else if (step.X > Player.Position.X && step.Y < Player.Position.Y) //Right
                {
                    Rotate(Direction.right, debugMessage);
                    walkok = Run(Direction.right, debugMessage);
                }
                else if (step.X < Player.Position.X && step.Y > Player.Position.Y) //Left
                {
                    Rotate(Direction.left, debugMessage);
                    walkok = Run(Direction.left, debugMessage);
                }
                else if (Player.Position.X == step.X && Player.Position.Y == step.Y) // no action
                {
                    walkok = true;
                }

                if (timeout >= 0 && DateTime.Now.CompareTo(timeEnd) > 0)
                {
                    if (debugMessage)
                    {
                        Misc.SendMessage("PathFind: RunPath run TIMEOUT", 33);
                    }
                    return(false);
                }

                if (!walkok)
                {
                    if (debugMessage)
                    {
                        Misc.SendMessage("PathFind: Move action FAIL", 33);
                    }

                    if (useResync)
                    {
                        Misc.Resync();
                        Misc.Pause(200);
                    }

                    return(false);
                }
                else
                {
                    if (debugMessage)
                    {
                        Misc.SendMessage("PathFind: Move action OK", 66);
                    }
                }
            }

            if (Player.Position.X == dst.X && Player.Position.Y == dst.Y)
            {
                Misc.SendMessage("PathFind: Destination reached", 66);
                return(true);
            }
            else
            {
                return(false);
            }
        }