private void OnGotLocationInfo(object sender, BasicCommunication.MessageParser.Got_LocationInfo_EventArgs e) { if (myThread.IsAlive) { myThread.Abort(); myThread.Join(); } objectID = 0; if (username != "") { TheTCPWrapper.Send(CommandCreator.SEND_PM(username, "I am in " + Settings.LocationInfo)); } if (commandGiven != "" && keepGoing) { ActorHandler.position currentPosition = TheActorHandler.GetMyPosition(); int myX = 0; int myY = 0; ActorHandler.position nextPosition = new ActorHandler.position(); if (commandGiven == "home" && MainClass.mapName == MainClass.myHome.mapName) { nextPosition = TheMySqlManager.getDestination(MainClass.mapName, commandGiven, out objectID, out useWithObject, ref lastMoveNumber); if (nextPosition.x == -1) { myX = MainClass.myHome.x; myY = MainClass.myHome.y; } else { myX = nextPosition.x; myY = nextPosition.y; } } else { nextPosition = TheMySqlManager.getDestination(MainClass.mapName, commandGiven, out objectID, out useWithObject, ref lastMoveNumber); myX = nextPosition.x; myY = nextPosition.y; } makeMoves(myX, myY); } else if (commandGiven == "home") { ActorHandler.position currentPosition = TheActorHandler.GetMyPosition(); orientSelf( currentPosition, TheTCPWrapper ); } gettingLocationInfo = false; }
private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e) { string Message = e.Message.ToLower(); if (Message[0] != '#') { Message = "#" + Message; } Message = Message.Replace(',', ' '); string[] CommandArray = Message.Split(' '); if (CommandArray[0] == "#goto") { if (CommandArray.Length < 2) //if (CommandArray.Length < 2 || CommandArray[1].Contains(",")) { goto WrongArguments; } bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#goto", Settings.botid); if (disabled == true) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled")); return; } if (TheMySqlManager.GetUserRank(e.username, Settings.botid) < TheMySqlManager.GetCommandRank("#goto", Settings.botid)) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!")); return; } TradeHandler.storageOpen = false; username = e.username; keepGoing = false; objectID = 0; commandGiven = ""; TheMySqlManager.getHomeInfo(); ActorHandler.position currentLocation = TheActorHandler.GetMyPosition(); int myX = -1; int myY = -1; string searchWord = ""; //Console.WriteLine(CommandArray.Length); if (CommandArray.Length == 3) { try { myX = int.Parse(CommandArray[1]); myY = int.Parse(CommandArray[2]); } catch { } finally { } } //loading the map, hold on a sec... //write out the values here, something's wrong... //Console.WriteLine((searchWord == "" && myX >= 0 && myY >= 0)); if (searchWord == "" && myX >= 0 && myY >= 0) { makeMoves(myX, myY); } else if ((string)CommandArray.GetValue(1) == "abort") { keepMoving = false; } else if ((string)CommandArray.GetValue(1) == "storage" || (string)CommandArray.GetValue(1) == "home") { ActorHandler.position currentPosition = TheActorHandler.GetMyPosition(); commandGiven = (string)CommandArray.GetValue(1); lastMoveNumber = 0; if (commandGiven == "storage") { Settings.IsTradeBot = false; MainClass.atHome = false; } keepGoing = true; //need to find our path to storage... this path will be a series of maps and exits to take to get to the next map //may be able to generalize this to any destination (storage, home, whatever...) //probably wanna do a loop here, looking for the destinations until we find our final map //the map change will use the fact that we're moving to storage/home to set our destination ActorHandler.position nextPosition = new ActorHandler.position(); if (commandGiven == "home" && MainClass.mapName == MainClass.myHome.mapName) { nextPosition = TheMySqlManager.getDestination(MainClass.mapName, commandGiven, out objectID, out useWithObject, ref lastMoveNumber); if (nextPosition.x == -1) { myX = MainClass.myHome.x; myY = MainClass.myHome.y; } else { myX = nextPosition.x; myY = nextPosition.y; } } else { nextPosition = TheMySqlManager.getDestination(MainClass.mapName, commandGiven, out objectID, out useWithObject, ref lastMoveNumber); myX = nextPosition.x; myY = nextPosition.y; } makeMoves(myX, myY); } else { myPathing.resetMap(); ArrayList myMatches = new ArrayList(); if (CommandArray.Length == 3) { searchWord = (string)CommandArray.GetValue(2); myMatches = myPathing.listObjects(searchWord); } else { myMatches = myPathing.listObjects(currentLocation); } //list objects with the serach word in them foreach (pathing.object3D myMatch in myMatches) { string filename = new string(myMatch.objectFileName).Replace('\0', ' '); filename = filename.Substring(filename.IndexOf(searchWord)); int thisX = (int)Math.Round(myMatch.x_pos, 0); int thisY = (int)Math.Round(myMatch.y_pos, 0); string outputLine = myMatch.object_id + "|" + filename.Trim() + "|" + thisX + "," + thisY; TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outputLine)); } } } return; WrongArguments: TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #goto command: ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#goto x y (or goto x,y) ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#goto home / storage ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[------------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #goto 192,168 ")); return; }
private void makeMoves() { ActorHandler.position previousPosition = new ActorHandler.position(); //pathing.TILE previousMove = (pathing.TILE)myMoves[0]; string moveString = ""; ActorHandler.position currentPosition = TheActorHandler.GetMyPosition(); previousPosition = currentPosition; //start a loop through the moves array, it's our path foreach (pathing.TILE myMove in myMoves) { //we may want to save the "best" move along the way in case we don't find any moves that suit this condition... //if (difference(myMove.x, previousPosition.x) < 12 && difference(myMove.y, previousPosition.y) < 12) if (difference(myMove.x, previousPosition.x) + difference(myMove.y, previousPosition.y) < 12) { continue; } else { //this might be the place to check for actors in the way //if one's in the way, just keep looking? hrm... string actorName = ""; bool actorInWay = actorInTheWay(myMove, out actorName); ; ActorHandler.position myPosition = TheActorHandler.GetMyPosition(); if (actorInWay) { Console.WriteLine("actor in the way: " + actorName + " " + myPosition.x + "," + myPosition.y); TheTCPWrapper.Send(CommandCreator.SEND_PM(username, "trying to move around " + actorName)); continue; } } currentPosition = TheActorHandler.GetMyPosition(); moveString = "Moving from " + currentPosition.x + "," + currentPosition.y; moveString += " to " + myMove.x + "," + myMove.y; TheTCPWrapper.Send(CommandCreator.SEND_PM(username, moveString)); TheTCPWrapper.Send(CommandCreator.MOVE_TO(myMove.x, myMove.y)); //wait until the move is done or the time expires DateTime startTime = DateTime.Now; bool keepStepping = true; while (keepStepping && keepMoving) { TimeSpan timeElapsed = DateTime.Now - startTime; currentPosition = TheActorHandler.GetMyPosition(); if ((currentPosition.x == myMove.x && currentPosition.y == myMove.y) || timeElapsed.Seconds > 10) { //got to the spot, stop moving keepStepping = false; } Thread.Sleep(10); } if (currentPosition.x == previousPosition.x && currentPosition.y == previousPosition.y && keepMoving) { keepMoving = false; TheTCPWrapper.Send(CommandCreator.SEND_PM(username, "I seem to be stuck :P")); } else { previousPosition = currentPosition; } if (!keepMoving) { break; } } //we'e either at the end by now, or we're stuck :P if (keepMoving) { pathing.TILE endMove = new pathing.TILE(); string actorName = ""; ActorHandler.position myPosition = TheActorHandler.GetMyPosition(); endMove.x = destX; endMove.y = destY; bool actorInWay = actorInTheWay(endMove, out actorName); if (actorInWay && actorName.ToLower()!= TheActorHandler.GetUsernameFromID((short)TheActorHandler.MyActorID).ToLower()) { Console.WriteLine("actor in the way at final destination, move next to if possible: " + actorName + " " + destX + "," + destY); moveLoc currentLoc = new moveLoc(); currentLoc.x = endMove.x; currentLoc.y = endMove.y; currentLoc.distance = 0; moveLoc adjustedMove = adjustMove(currentLoc); destX = adjustedMove.x; destY = adjustedMove.y; } TheTCPWrapper.Send(CommandCreator.MOVE_TO(destX, destY)); moveString = "Moving from " + currentPosition.x + "," + currentPosition.y; moveString += " to end " + destX + "," + destY; TheTCPWrapper.Send(CommandCreator.SEND_PM(username, moveString)); DateTime startTime = DateTime.Now; bool keepStepping = true; while (keepStepping && keepMoving) { TimeSpan timeElapsed = DateTime.Now - startTime; currentPosition = TheActorHandler.GetMyPosition(); if ((currentPosition.x == destX && currentPosition.y == destY) || timeElapsed.Seconds > 10) { //got to the spot, stop moving keepStepping = false; } Thread.Sleep(10); } } else { TheTCPWrapper.Send(CommandCreator.SEND_PM(username, "Moving aborted.")); } if (objectID > 0 && keepMoving) { gettingLocationInfo = true; TheTCPWrapper.Send(CommandCreator.USE_MAP_OBJECT((uint)objectID, TheMySqlManager.getItemPos(useWithObject))); useObjectPathing = true; System.Threading.Thread.Sleep(3000); TheTCPWrapper.Send(CommandCreator.LOCATE_ME()); objectID = 0; //keepMoving = false; } else { useObjectPathing = false; keepGoing = false; if (keepMoving) { currentPosition = TheActorHandler.GetMyPosition(); TheTCPWrapper.Send(CommandCreator.SEND_PM(username, "I should be at my final destination!")); //experimental, not sure.... Thread.Sleep(1000); gettingLocationInfo = true; TheTCPWrapper.Send(CommandCreator.LOCATE_ME()); if (commandGiven == "home" && MainClass.botType == 1) { MainClass.atHome = true; Settings.IsTradeBot = true; } } myPathing.clearMap(); } }