Beispiel #1
0
 public void StopMove()
 {
     moving = false;
     state  = new AI.EntityState.StopMove(PosX, PosY, new Packet.SendPacketHandlers.MoveStop(PlayerPID, PosX, PosY));
     newX   = newY = 0;
     Map.Nod curNod = GameServer.world.GetTileAddress((uint)PosX, (uint)PosY);
     if (curNod.X != MapPosition.X || curNod.Y != MapPosition.Y)
     {
         MapPosition.X = curNod.X;
         MapPosition.Y = curNod.Y;
         GameServer.world.MovePlayerOnMap(this, OldMapPosition, MapPosition);
         OldMapPosition.X = curNod.X;
         OldMapPosition.Y = curNod.Y;
     }
     sw.Stop();
 }
Beispiel #2
0
        private void Goto()
        {
            float elapsed = sw.ElapsedMilliseconds / 1000f;

            sw.Restart();
            if (Con != null && newX != 0 && newY != 0)
            {
                if ((newX != PosX) || (newY != PosY))
                {
                    if (moveTarget.X != newX || moveTarget.Y != newY)
                    {
                        moveTarget.X = newX;
                        moveTarget.Y = newY;
                        // On starting movement
                        //Output.WriteLine("MOVING TO : [" + newX.ToString() + "," + newY.ToString() + ",0]");
                        distance = (float)(Math.Sqrt(Math.Pow(newX - PosX, 2) + Math.Pow(newY - PosY, 2)));
                        //Output.WriteLine("Distance: " + distance.ToString());
                        directionX = (float)(newX - PosX) / distance;
                        directionY = (float)(newY - PosY) / distance;
                        mX         = PosX;
                        mY         = PosY;
                        startX     = mX;
                        startY     = mY;
                        tstartX    = mX;
                        tstartY    = mY;
                        moving     = true;
                        //pl.Con.Send(new Packet.SendPacketHandlers.MoveStart(pl.PlayerPID, pl.newX, pl.newY));// send to client info that server start moving avatar
                        //con.Player.StartMove(con.newX, con.newY, 0);// -> send to all info about move start...
                        //GameServer.world.BroadcastPacket(PosX, PosY, World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.MoveStart(PlayerPID, newX, newY));
                        state = new AI.EntityState.StartMove(PosX, PosY, new Packet.SendPacketHandlers.MoveStart(PlayerPID, newX, newY));
                        sw.Restart();
                        elapsed = 0;
                        return;
                    }
                    // On update
                    if (moving)
                    {
                        mX       = directionX * speed * elapsed;
                        mY       = directionY * speed * elapsed;
                        tstartX += mX;
                        tstartY += mY;
                        tmX      = (int)(tstartX * 1000);
                        tmY      = (int)(tstartY * 1000);
                        //Output.WriteLine("speed " + speed.ToString() + " elapsed " + elapsed.ToString());
                        //Output.WriteLine("mx,my [" + mX.ToString() + ":" + mY.ToString() + "] tstart [" + tstartX.ToString() + ":" + tstartY.ToString() + "]");
                        float tmpDistance = (float)(Math.Sqrt(Math.Pow(tstartX - startX, 2) + Math.Pow(tstartY - startY, 2)));
                        //Output.WriteLine("tmpDistance: " + tmpDistance.ToString());
                        if (tmpDistance >= distance)
                        {
                            PosX   = newX;
                            PosY   = newY;
                            moving = false;
                            //pl.Con.Send(new Packet.SendPacketHandlers.MoveStop(pl.PlayerPID, pl.tmX, pl.tmY));//send stop packet to user
                            //GameServer.world.BroadcastPacket(PosX, PosY, World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.MoveStop(PlayerPID, tmX, tmY));
                            state = new AI.EntityState.StopMove(PosX, PosY, new Packet.SendPacketHandlers.MoveStop(PlayerPID, PosX, PosY));
                            newX  = newY = 0;
                            //Output.WriteLine(":1 MOV STOP [" + PosX.ToString() + "," + PosY.ToString() + "]");
                            Map.Nod curNod = GameServer.world.GetTileAddress((uint)PosX, (uint)PosY);
                            if (curNod.X != MapPosition.X || curNod.Y != MapPosition.Y)
                            {
                                //player moved to new map tile
                                MapPosition.X = curNod.X;
                                MapPosition.Y = curNod.Y;
                                GameServer.world.MovePlayerOnMap(this, OldMapPosition, MapPosition);
                                OldMapPosition.X = curNod.X;
                                OldMapPosition.Y = curNod.Y;
                            }
                            sw.Stop();
                        }
                        else
                        {
                            if (PosX == newX && PosY == newY)
                            {
                                moving = false;
                                //pl.Con.Send(new Packet.SendPacketHandlers.MoveStop(pl.PlayerPID, pl.tmX, pl.tmY));
                                //GameServer.world.BroadcastPacket(PosX, PosY, World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.MoveStop(PlayerPID, tmX, tmY));
                                state = new AI.EntityState.StopMove(PosX, PosY, new Packet.SendPacketHandlers.MoveStop(PlayerPID, PosX, PosY));
                                newX  = newY = 0;
                                //Output.WriteLine(":2 MOV STOP : [" + PosX.ToString() + "," + PosY.ToString() + "]");
                                Map.Nod curNod = GameServer.world.GetTileAddress((uint)PosX, (uint)PosY);
                                if (curNod.X != MapPosition.X || curNod.Y != MapPosition.Y)
                                {
                                    //player moved to new map tile
                                    MapPosition.X = curNod.X;
                                    MapPosition.Y = curNod.Y;
                                    GameServer.world.MovePlayerOnMap(this, OldMapPosition, MapPosition);
                                    OldMapPosition.X = curNod.X;
                                    OldMapPosition.Y = curNod.Y;
                                }
                                sw.Stop();
                                return;
                            }
                            //Output.WriteLine("[" + mX.ToString() +"," + mY.ToString() + "] to [" + tstartX.ToString() + "," + tstartY.ToString() + "]");
                            //Con.Send(new Packet.SendPacketHandlers.Move(PlayerPID, tmX, tmY));
                            //GameServer.world.BroadcastPacket(PosX, PosY, World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.Move(PlayerPID, tmX, tmY));
                            //state = new AI.EntityState.Move(PosX, PosY, new Packet.SendPacketHandlers.Move(PlayerPID, tmX, tmY));
                            //Output.WriteLine("MOV [" + tmX.ToString() + "," + tmY.ToString() + "]");
                            int bX = (int)tstartX - PosX;
                            int bY = (int)tstartY - PosY;
                            if (bX != 0 || bY != 0)
                            {
                                //con.Player.Move(bX, bY, 0);//update player position in sever
                                //for test we do it here....
                                // update the own position
                                PosX += bX;
                                PosY += bY;
                                PosZ += 0;
                                Map.Nod curNod = GameServer.world.GetTileAddress((uint)PosX, (uint)PosY);
                                if (curNod.X != MapPosition.X || curNod.Y != MapPosition.Y)
                                {
                                    //player moved to new map tile
                                    MapPosition.X = curNod.X;
                                    MapPosition.Y = curNod.Y;
                                    GameServer.world.MovePlayerOnMap(this, OldMapPosition, MapPosition);
                                    OldMapPosition.X = curNod.X;
                                    OldMapPosition.Y = curNod.Y;
                                }
                            }
                        }
                    }
                }
                else
                {
                    moving = false;
                    //pl.Con.Send(new Packet.SendPacketHandlers.MoveStop(pl.PlayerPID, pl.tmX, pl.tmY));
                    //GameServer.world.BroadcastPacket(PosX, PosY, World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.MoveStop(PlayerPID, tmX, tmY));
                    state = new AI.EntityState.StopMove(PosX, PosY, new Packet.SendPacketHandlers.MoveStop(PlayerPID, PosX, PosY));
                    newX  = newY = 0;
                    //Output.WriteLine(":2 MOV STOP : [" + PosX.ToString() + "," + PosY.ToString() + "]");
                    Map.Nod curNod = GameServer.world.GetTileAddress((uint)PosX, (uint)PosY);
                    if (curNod.X != MapPosition.X || curNod.Y != MapPosition.Y)
                    {
                        //player moved to new map tile
                        MapPosition.X = curNod.X;
                        MapPosition.Y = curNod.Y;
                        GameServer.world.MovePlayerOnMap(this, OldMapPosition, MapPosition);
                        OldMapPosition.X = curNod.X;
                        OldMapPosition.Y = curNod.Y;
                    }
                    sw.Stop();
                    return;
                }
            }
        }
Beispiel #3
0
        private void Goto()
        {
            if (Program.DEBUG_MOB_STOP)
            {
                if (currentState == EntityState.STATE.START_MOVE || currentState == EntityState.STATE.MOVE)
                {
                    state = new AI.EntityState.StopMove(PosX, PosY, new Packet.SendPacketHandlers.MobMoveStop(InternalID, PosX, PosY));
                }
                currentState = EntityState.STATE.STOP_MOVE;
                cSM.SetState = AI.CoreStateMachine.State.STAND;
                sw.Stop();
                return;
            }
            float elapsed = sw.ElapsedMilliseconds / 1000f;

            sw.Restart();
            if (newX != 0 && newY != 0)
            {
                if ((newX != PosX) || (newY != PosY))
                {
                    if (moveTarget.X != newX || moveTarget.Y != newY)
                    {
                        moveTarget.X = newX;
                        moveTarget.Y = newY;
                        // On starting movement
                        //Output.WriteLine("MOVING TO : [" + newX.ToString() + "," + newY.ToString() + ",0]");
                        distance = (float)(Math.Sqrt(Math.Pow(newX - PosX, 2) + Math.Pow(newY - PosY, 2)));
                        //Output.WriteLine("Distance: " + distance.ToString());
                        directionX = (float)(newX - PosX) / distance;
                        directionY = (float)(newY - PosY) / distance;
                        mX         = PosX;
                        mY         = PosY;
                        startX     = mX;
                        startY     = mY;
                        tstartX    = mX;
                        tstartY    = mY;
                        moving     = true;
                        //pl.Con.Send(new Packet.SendPacketHandlers.MoveStart(pl.PlayerPID, pl.newX, pl.newY));// send to client info that server start moving avatar
                        //GameServer.world.BroadcastPacket(PosX, PosY, World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.MobMoveStart(uniqueID, newX, newY));
                        currentState = EntityState.STATE.START_MOVE;
                        state        = new AI.EntityState.StartMove(PosX, PosY, new Packet.SendPacketHandlers.MobMoveStart(InternalID, newX, newY));
                        sw.Restart();
                        elapsed = 0;
                        return;
                    }
                    // On update
                    if (moving)
                    {
                        mX       = directionX * speed * elapsed;
                        mY       = directionY * speed * elapsed;
                        tstartX += mX;
                        tstartY += mY;
                        tmX      = (int)(tstartX * 1000);
                        tmY      = (int)(tstartY * 1000);
                        if (Math.Sqrt(Math.Pow(tstartX - startX, 2) + Math.Pow(tstartY - startY, 2)) >= distance)
                        {
                            PosX   = newX;
                            PosY   = newY;
                            moving = false;
                            //pl.Con.Send(new Packet.SendPacketHandlers.MoveStop(pl.PlayerPID, pl.tmX, pl.tmY));//send stop packet to user
                            //GameServer.world.BroadcastPacket(PosX, PosY, World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.MobMoveStop(uniqueID, tmX, tmY));
                            currentState = EntityState.STATE.STOP_MOVE;
                            state        = new AI.EntityState.StopMove(PosX, PosY, new Packet.SendPacketHandlers.MobMoveStop(InternalID, PosX, PosY));
                            newX         = newY = 0;
                            Map.Nod curNod = GameServer.world.GetTileAddress((uint)PosX, (uint)PosY);
                            if (curNod == null)
                            {
                                curNod = GameServer.world.GetPositionAtTile(MapPosition.X, MapPosition.Y);
                                if (curNod == null)
                                {
                                    Output.WriteLine(ConsoleColor.Red, "Mob::Goto Nod null!");
                                    Despawn(null);
                                    return;
                                }
                                PosX = (int)curNod.X;
                                PosY = (int)curNod.Y;
                                Despawn(null);
                                return;
                            }
                            if (curNod.X != MapPosition.X || curNod.Y != MapPosition.Y)
                            {
                                //player moved to new map tile
                                if (PosX > GameServer.world.WorldMaxX || PosX < GameServer.world.WorldMinX || PosY > GameServer.world.WorldMaxY || PosY < GameServer.world.WorldMinY)
                                {
                                    Despawn(null);
                                    return;
                                }
                                MapPosition.X = curNod.X;
                                MapPosition.Y = curNod.Y;
                                GameServer.world.MoveMobOnMap(this, OldMapPosition, MapPosition);
                                OldMapPosition.X = curNod.X;
                                OldMapPosition.Y = curNod.Y;
                            }
                            cSM.SetState = AI.CoreStateMachine.State.STAND;
                            sw.Stop();
                        }
                        else
                        {
                            if (PosX == newX && PosY == newY)
                            {
                                moving = false;
                                //pl.Con.Send(new Packet.SendPacketHandlers.MoveStop(pl.PlayerPID, pl.tmX, pl.tmY));
                                //GameServer.world.BroadcastPacket(PosX, PosY, World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.MobMoveStop(uniqueID, tmX, tmY));
                                currentState = EntityState.STATE.STOP_MOVE;
                                state        = new AI.EntityState.StopMove(PosX, PosY, new Packet.SendPacketHandlers.MobMoveStop(InternalID, PosX, PosY));
                                Map.Nod curNod = GameServer.world.GetTileAddress((uint)PosX, (uint)PosY);
                                newX = newY = 0;
                                if (curNod == null)
                                {
                                    curNod = GameServer.world.GetPositionAtTile(MapPosition.X, MapPosition.Y);
                                    if (curNod == null)
                                    {
                                        Output.WriteLine(ConsoleColor.Red, "Mob::Goto Nod null!");
                                        Despawn(null);
                                        return;
                                    }
                                    Despawn(null);
                                    return;
                                }
                                if (curNod.X != MapPosition.X || curNod.Y != MapPosition.Y)
                                {
                                    //player moved to new map tile
                                    if (PosX > GameServer.world.WorldMaxX || PosX < GameServer.world.WorldMinX || PosY > GameServer.world.WorldMaxY || PosY < GameServer.world.WorldMinY)
                                    {
                                        Despawn(null);
                                        return;
                                    }
                                    MapPosition.X = curNod.X;
                                    MapPosition.Y = curNod.Y;
                                    GameServer.world.MoveMobOnMap(this, OldMapPosition, MapPosition);
                                    OldMapPosition.X = curNod.X;
                                    OldMapPosition.Y = curNod.Y;
                                }
                                cSM.SetState = AI.CoreStateMachine.State.STAND;
                                sw.Stop();
                                return;
                            }
                            //Output.WriteLine("[" + mX.ToString() +"," + mY.ToString() + "] to [" + tstartX.ToString() + "," + tstartY.ToString() + "]");
                            //GameServer.world.BroadcastPacket(PosX, PosY, World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.MobMove(uniqueID, tmX, tmY));
                            currentState = EntityState.STATE.MOVE;
                            state        = new AI.EntityState.Move(PosX, PosY, null);//new AI.EntityState.Move(PosX, PosY, new Packet.SendPacketHandlers.MobMove(InternalID, tmX, tmY));
                            int bX = (int)tstartX - PosX;
                            int bY = (int)tstartY - PosY;
                            if (bX != 0 || bY != 0)
                            {
                                // update the own position
                                PosX += bX;
                                PosY += bY;
                                PosZ += 0;
                                Map.Nod curNod = GameServer.world.GetTileAddress((uint)PosX, (uint)PosY);
                                if (curNod == null)
                                {
                                    curNod = GameServer.world.GetPositionAtTile(MapPosition.X, MapPosition.Y);
                                    if (curNod == null)
                                    {
                                        Output.WriteLine(ConsoleColor.Red, "Mob::Goto Nod null!");
                                        Despawn(null);
                                        return;
                                    }
                                    Despawn(null);
                                    return;
                                }
                                if (curNod.X != MapPosition.X || curNod.Y != MapPosition.Y)
                                {
                                    //player moved to new map tile
                                    if (PosX > GameServer.world.WorldMaxX || PosX < GameServer.world.WorldMinX || PosY > GameServer.world.WorldMaxY || PosY < GameServer.world.WorldMinY)
                                    {
                                        Despawn(null);
                                        return;
                                    }
                                    MapPosition.X = curNod.X;
                                    MapPosition.Y = curNod.Y;
                                    GameServer.world.MoveMobOnMap(this, OldMapPosition, MapPosition);
                                    OldMapPosition.X = curNod.X;
                                    OldMapPosition.Y = curNod.Y;
                                }
                            }
                        }
                    }
                }
                else
                {
                    moving = false;
                    //pl.Con.Send(new Packet.SendPacketHandlers.MoveStop(pl.PlayerPID, pl.tmX, pl.tmY));
                    //GameServer.world.BroadcastPacket(PosX, PosY, World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.MobMoveStop(uniqueID, tmX, tmY));
                    currentState = EntityState.STATE.STOP_MOVE;
                    state        = new AI.EntityState.StopMove(PosX, PosY, new Packet.SendPacketHandlers.MobMoveStop(InternalID, PosX, PosY));
                    Map.Nod curNod = GameServer.world.GetTileAddress((uint)PosX, (uint)PosY);
                    newX = newY = 0;
                    if (curNod == null)
                    {
                        curNod = GameServer.world.GetPositionAtTile(MapPosition.X, MapPosition.Y);
                        if (curNod == null)
                        {
                            Output.WriteLine(ConsoleColor.Red, "Mob::Goto Nod null!");
                            Despawn(null);
                            return;
                        }
                        Despawn(null);
                        return;
                    }
                    if (curNod.X != MapPosition.X || curNod.Y != MapPosition.Y)
                    {
                        //player moved to new map tile
                        if (PosX > GameServer.world.WorldMaxX || PosX < GameServer.world.WorldMinX || PosY > GameServer.world.WorldMaxY || PosY < GameServer.world.WorldMinY)
                        {
                            Despawn(null);
                            return;
                        }
                        MapPosition.X = curNod.X;
                        MapPosition.Y = curNod.Y;
                        GameServer.world.MoveMobOnMap(this, OldMapPosition, MapPosition);
                        OldMapPosition.X = curNod.X;
                        OldMapPosition.Y = curNod.Y;
                    }
                    cSM.SetState = AI.CoreStateMachine.State.STAND;
                    sw.Stop();
                    return;
                }
            }
        }