All pastes #905696 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-02-15 23:35 UTC
rendered paste body
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Threading;

using PRCoreLibrary;
using PRCoreInterface;
using InnerSpaceAPI;
using LavishNavAPI;
using LavishNavAPI.Pathfinders;
using LavishNavAPI.Regions;
using LavishScriptAPI;
using LavishVMAPI;

using GreySoft.GreyNav;

namespace PRCoreLibrary
{
    public enum NAVIGATIONBRAIN_STATE
    {
        NONE,
        LEFT_BLIND,
        RIGHT_BLIND,
        BLIND,
        STUCK,
        PUSHED,
        GOOD
    }
    public partial class PRNavigationBrain
    {
        
        private NAVIGATIONBRAIN_STATE _CurrentState = NAVIGATIONBRAIN_STATE.NONE;
        public PRPoint FeelPoint;
        public LavishScriptAPI.Point3f TestPoint;
        public PRPoint CharPoint;
        public double FeelAhead=10;
        public int Rot;
        public int SteadyTurn;
        public NAVIGATIONBRAIN_STATE CurrentState 
        { 
            get { return _CurrentState; }
            set { _CurrentState = value; }
        }
        
        public void BrainPulse()
        {
           CurrentState =  GetState();
            StateSwitch();
        }

        void StateSwitch()
    {
        if (SteadyTurn > 0)
        {
            if (SteadyTurn == 8)
            {
                SteadyTurn = 0;
                Rot = 0;
            }
           
        }

        switch (CurrentState)
        {
           
            case NAVIGATIONBRAIN_STATE.LEFT_BLIND:
                InnerSpaceAPI.InnerSpace.Echo("LEFT BLIND!");
                if (Rot != 1 && SteadyTurn > 0)
                    return;
                if (IPOCheck(PRCore.Character.Location, FeelPoint) < 5)
                {
                    StepRight();
                    return;
                }
               TurnRight();
               Rot = 1;
                
                break;
            case NAVIGATIONBRAIN_STATE.RIGHT_BLIND:
                InnerSpaceAPI.InnerSpace.Echo("RIGHT BLIND!");
                if (Rot != 2 && SteadyTurn > 0)
                    return;
                Rot = 2;
               
                if (IPOCheck(PRCore.Character.Location, FeelPoint) < 5)
                {
                    StepLeft();
                    return;
                }
                TurnLeft();
                break;
            case NAVIGATIONBRAIN_STATE.BLIND:
                InnerSpaceAPI.InnerSpace.Echo("FRONT BLIND!");
                return;
                if (Rot != 3 && SteadyTurn > 0)
                    return;
                if (Rot == 3)
                    return;
                Rot = 3;
               
                if (IPOCheck(PRCore.Character.Location, FeelPoint) < .5)
                {
                    StepBack();
                    return;
                }
                TurnAround();
                break;
            case NAVIGATIONBRAIN_STATE.GOOD:
                Rot =0;
                InnerSpaceAPI.InnerSpace.Echo("GROOVY!");
                break;
                

           
               
        }
    }

    

      private NAVIGATIONBRAIN_STATE GetState()
        {

            if (Blind(0))
            {
                SteadyTurn++;
                return NAVIGATIONBRAIN_STATE.BLIND;
            }
            //if (Blind(-10))
           //{
               // SteadyTurn++; ;
                //return NAVIGATIONBRAIN_STATE.LEFT_BLIND;
            //}
           //if (Blind(40))
            //{
               // //return NAVIGATIONBRAIN_STATE.RIGHT_BLIND;
            //}
          

            return NAVIGATIONBRAIN_STATE.GOOD;
          
        }

        private void NewBearing()
        {
        
        }

       
        private double DegreeOut(double bearing)
        {
           
            if (bearing>360)
            {

            bearing=bearing-360;
                
            }
            if (bearing<0)
            {
                bearing=bearing+360;
                
            }
            return bearing;
        }

        private void TurnLeft()
        {
            InnerSpaceAPI.InnerSpace.Echo("TURN LEFT!");
            PRCore.WoW.FaceHeading(DegreeOut(PRCore.Character.Heading - 10));
        }

       
        private void TurnRight()
        {
            InnerSpaceAPI.InnerSpace.Echo("TURN RIGHT!");
            PRCore.WoW.FaceHeading(DegreeOut(PRCore.Character.Heading + 10));
        }

        private void TurnAround()
        {
            InnerSpaceAPI.InnerSpace.Echo("TURN AROUND!");
            PRCore.WoW.FaceHeading(DegreeOut(PRCore.Character.Heading - 30));  
        }
        
        private void StepLeft()
        {
            LavishScriptAPI.LavishScript.ExecuteCommand(String.Format("move left 100"));
        }
        private void StepRight()
        {
            LavishScriptAPI.LavishScript.ExecuteCommand(String.Format("move right 100"));
        }

        private void StepBack()
        {
            LavishScriptAPI.LavishScript.ExecuteCommand(String.Format("wowpress JUMP"));
        }

        private bool Blind(double mod)
        {
            FeelAhead = 2;
            //TestPoint = new LavishScriptAPI.Point3f();
            CharPoint = PRCore.Character.Location;
            double Distance;

            if (mod == 0)
            {
                FeelAhead = FeelAhead + 2;
            }
            else
            {
                FeelAhead = 2;
            }
            FeelPoint = new PRPoint(1, 1, PRCore.Character.Z);
            double bearing;
            bearing = PRCore.Character.Heading - mod;
            bearing = DegreeOut(bearing);
            double Rads = bearing * Math.PI / 180;


            InnerSpaceAPI.InnerSpace.Echo(".NET Bearing:" + Convert.ToString(bearing));
            //new_x = x * cos (angle) - y * sin (angle)
            //new_y = x * sin (angle) + y * cos (angle)
            FeelPoint.X = (PRCore.Character.X + Math.Sin(Rads) * FeelAhead);
            FeelPoint.Y = (PRCore.Character.Y - Math.Cos(Rads) * FeelAhead);


            InnerSpaceAPI.InnerSpace.Echo(".NET CHAR location: " + Convert.ToString(CharPoint.X) + " " + Convert.ToString(CharPoint.Y) + " " + Convert.ToString(CharPoint.Z));
            InnerSpaceAPI.InnerSpace.Echo(".NET Heading : " + mod.ToString() + " New Point:" + FeelPoint.ToString());
            //TestPoint = PRCore.WoW.CollisionTest(CharPoint,FeelPoint);
            //TestPoint = PRCore.WoW.IsPathObstructedOCD(CharPoint, FeelPoint);
            PRPoint TestPoint = new PRPoint(PRCore.WoW.WoW.IsPathObstructed(CharPoint.X, CharPoint.Y, CharPoint.Z + 1, FeelPoint.X, FeelPoint.Y, FeelPoint.Z + 1, 2));
            Distance = TestPoint.Distance(PRCore.Character.Location);

            if (Distance < FeelAhead)
            {
                return true;
            }
            return false;

            // return PRCore.Character.IsPathObstructed(FeelPoint.X,FeelPoint.Y,FeelPoint.Z+10,FeelAhead);
            // if (IPOCheck(PRCore.Character.Location, FeelPoint))
            // return true;
            //  return false;
        }

        private double IPOCheck(PRPoint From,PRPoint To)
        {
          PRPoint Vector1  = new PRPoint();
          From.Z=From.Z + 1;
            
           Vector1 = PRCore.WoW.IsPathObstructed(From,To,.65);

           return (Math.Sqrt((Math.Pow((Vector1.X - PRCore.Character.X), 2) + Math.Pow((Vector1.Y - PRCore.Character.Y), 2))));
                
            
        }
        private bool RightBlind()
        {
            double bearing;
            FeelPoint = new PRPoint(1, 1, PRCore.Character.Z);
            bearing = PRCore.Character.Heading + 45;
            bearing = DegreeOut(bearing);
            FeelPoint.X = PRCore.Character.X + Math.Cos(bearing) * FeelAhead;
            FeelPoint.Y = PRCore.Character.Y - Math.Sin(bearing) * FeelAhead;
            InnerSpaceAPI.InnerSpace.Echo("RIGHT: " + FeelPoint.ToString());
            //if (IPOCheck(PRCore.Character.Location, FeelPoint))
               // return true;
            return false;
        }

       
    }

}