Movement

Skripty týkající se tohoto externího programu

Moderátor: Caleb

Odpovědět
Uživatelský avatar
Leny-m
Book Snake
Book Snake
Příspěvky: 123
Registrován: 12 říj 2006 22:18
Kontaktovat uživatele:

Movement

Příspěvek od Leny-m »

Skript visi tady

Chodi trochu kostrbate, ale chodi ^^

,movetoposition x y

Enjoy!

Kód: Vybrat vše

using System;
using System.Collections.Generic;
using System.Text;
using Phoenix;
using Phoenix.WorldData;
using System.Windows.Forms;

// made by Leny-m

namespace Phoenix.Scripts
{
    public class Movement
    {
    
        private Keys NORTH = System.Windows.Forms.Keys.PageUp;
        private Keys SOUTH = System.Windows.Forms.Keys.End;
        private Keys WEST = System.Windows.Forms.Keys.Home;
        private Keys EAST = System.Windows.Forms.Keys.PageDown;
        
        private Keys UP = System.Windows.Forms.Keys.Up;
        private Keys DOWN = System.Windows.Forms.Keys.Down;
        private Keys LEFT = System.Windows.Forms.Keys.Left;
        private Keys RIGHT = System.Windows.Forms.Keys.Right;

        [Command]
        public void moveToPosition(int x, int y)
        {
            int px = World.Player.X;
            int py = World.Player.Y;
                        
			UO.Print("Moving to {0},{1}",x,y);
			
            while(!inPosition(x, y))
            { 
                if(py == y)
                {
                    if(px > x)
                    {
						while(!inPosition(x, y) && px > x)
						{
							moveWest();
							px = World.Player.X;
							py = World.Player.Y;	
						}								
                    } else
                    {
						while(!inPosition(x, y) && px < x)
						{
							moveEast();
							px = World.Player.X;
							py = World.Player.Y;	
						}								
                    }
                } else if(px == x)
                {
                    if(py > y)
                    {
						while(!inPosition(x, y) && py > y)
						{
							moveNorth();
							px = World.Player.X;
							py = World.Player.Y;	
						}								
                    } else
                    {
						while(!inPosition(x, y) && py < y)
						{
							moveSouth();
							px = World.Player.X;
							py = World.Player.Y;	
						}								
                    }
                } else if(py > y)
                {
                    if(px > x)
                    {
						while(!inPosition(x, y) && px > x && py > y)
						{
							moveUp();
							px = World.Player.X;
							py = World.Player.Y;	
						}								
                    } else
                    {
						while(!inPosition(x, y) && px < x && py > y)
						{
							moveRight();
							px = World.Player.X;
							py = World.Player.Y;	
						}								
                    }
                } else if(py < y)
                {
                    if(px > x)
                    {
						while(!inPosition(x, y) && px > x && py < y)
						{
							moveLeft();
							px = World.Player.X;
							py = World.Player.Y;	
						}								
                    } else
                    {
						while(!inPosition(x, y) && px < x && py < y)
						{
							moveDown();
							px = World.Player.X;
							py = World.Player.Y;	
						}							
                    }
                }

                px = World.Player.X;
                py = World.Player.Y;
            } 
			UO.Print("In position!");
        }
        
        public bool inPosition(int x, int y)
        {
            int px = World.Player.X;
            int py = World.Player.Y;
            if(px > x + 1 || py > y + 1 || px < x - 1 || py < y - 1)
            {
                return false;
            }
            return true;
        }  
        
        private void move(Keys direction)
        {
            int px = World.Player.X;
            int py = World.Player.Y;
                        
            Keys dir = intToDirection(World.Player.Direction);
            if(dir == direction)
            {
                UO.Press(direction);
                UO.Wait(250);
            }
            else
            {
                UO.Press(direction);
                UO.Press(direction);
                UO.Wait(250);
            }
            if(px == World.Player.X && py == World.Player.Y)
            {
                move(changeDirection(direction));
            }
        }
        
        private Keys changeDirection(Keys direction)
        {
            
            if(direction == NORTH)
            {
                return EAST;
            }
            
            if(direction == SOUTH)
            {
                return WEST;
            }
            
            if(direction == WEST)
            {
                return NORTH;
            }
            
            if(direction == EAST)
            {
                return SOUTH;
            }
            
            if(direction == RIGHT)
            {
                return DOWN;
            }
            
            if(direction == DOWN)
            {
                return LEFT;
            }
            
            if(direction == LEFT)
            {
                return UP;
            }
            
            return RIGHT;           
        }
        
        private Keys intToDirection(int dir)
        {
            if(dir == 0)
            {
                return NORTH;
            }
            if(dir == 1)
            {
                return RIGHT;
            }             
            if(dir == 2)
            {
                return EAST;
            }  
            if(dir == 3)
            {
                return DOWN;
            }             
            if(dir == 4)
            {
                return SOUTH;
            }
            if(dir == 5)
            {
                return LEFT;
            }             
            if(dir == 6)
            {
                return WEST;
            }  
            
            return UP;
        }
        
        /*
            West(Home)   North(PageUp)
                       x
            South(End)   East(PageDown)
        */
        public void moveNorth()
        {
            move(NORTH);
        }
        
        public void moveSouth()
        {
            move(SOUTH);
        }
        
        public void moveWest()
        {
            move(WEST);
        }
        
        public void moveEast()
        {
            move(EAST);
        } 
        
        public void moveRight()
        {
            move(RIGHT);
        }
        
        public void moveLeft()
        {
            move(LEFT);
        }
        
        public void moveDown()
        {
            move(DOWN);
        }
        
        public void moveUp()
        {
            move(UP);
        }        

    }
}
Odpovědět