internal static double vehicleDegreeToPoint(Point np, Vehicle myTank) { double degree_diff = TBMath.RadianToDegree(Math.Atan2(np.y - myTank.pos.y, np.x - myTank.pos.x)) - myTank.direction + 90 + 720; while (degree_diff > 180) degree_diff -= 360; return degree_diff; }
internal static double cameraDegreeToEnemy(Vehicle et, Vehicle myTank) { double degree_diff = TBMath.RadianToDegree(Math.Atan2(et.pos.y - myTank.pos.y, et.pos.x - myTank.pos.x)) - myTank.cameraDirection + 90 + 360; while (degree_diff > 180) degree_diff -= 360; return degree_diff; }
private TankBot() { Helper.LogInfo("TankBot initialization"); if (!CheckSetting.checkSetting()) { Helper.LogInfo("check setting fail"); Environment.Exit(0); } status = Status.IN_HANGAR; for (int i = 0; i < allyTank.Length; i++) allyTank[i] = new Vehicle(); for (int i = 0; i < enemyTank.Length; i++) enemyTank[i] = new Vehicle(); }
/// <summary> /// trying to aim the tank et /// return true if we get to that position /// </summary> /// <param name="et"></param> /// <param name="arg_x"></param> /// <param name="arg_y"></param> /// <param name="farAway"></param> /// <returns></returns> internal void aimToTankArgxArgy(Vehicle et, double arg_x, double arg_y) { if (et.visible_on_screen == false) { throw new NotVisibleOnScreenException(); } if (!et.posScreenUpdated) return; if (!tb.myTank.directionUpdated) return; if (!tb.myTank.cameraDirectionUpdated) return; // force everything to update to correct double cameraDirectionBeforeMouseMove = tb.myTank.cameraDirection; Point beforeMouseMove = et.posScreen; Helper.LogDebug("aimToTank arg_x:" + arg_x + " arg_y:" + arg_y + " direction:" + tb.myTank.direction + " cameraDirection:" + tb.myTank.cameraDirection); double degree_diff = 0; int x_move = 0, y_move = 0; degree_diff = TBMath.cameraDegreeToEnemy(et, tb.myTank); // if too far away, just move horizontal. if (et.posScreen.x > TBConst.screen_width / 2 + 400 || et.posScreen.x < TBConst.screen_width / 2 - 400) { x_move = Convert.ToInt32(degree_diff / tb.mouseHorizonRatio[SniperMode.sniper_level]); } else // the tank is almost near in horizontal view { //---------------------------move horizontal degree_diff = (et.posScreen.x - TBConst.screen_width / 2); double dis = TBMath.distance(tb.myTank.pos, et.pos) * tb.mapSacle; degree_diff = arg_x + tb.meterPerPixel[SniperMode.sniper_level] * degree_diff / 100 * dis; // meter from center to screen; degree_diff = degree_diff / (2 * Math.PI * dis) * 360; x_move = Convert.ToInt32(degree_diff / tb.mouseHorizonRatio[SniperMode.sniper_level]); //----------------------------------move vertical double pixel_diff = 0; if (SniperMode.sniper_level >= 6) pixel_diff = (et.posScreen.y - TBConst.screen_height / 2); // positive then move down pixel diff on screen else pixel_diff = (et.posScreen.y - TBConst.screen_height / 2 + 58); // f**k this 58 mm dis = TBMath.distance(tb.myTank.pos, et.pos) * tb.mapSacle; double meter_diff = arg_y + tb.meterPerPixel[SniperMode.sniper_level] * pixel_diff / 100 * dis; // meter from center to screen; arg_y meter's away degree_diff = meter_diff / (2 * Math.PI * dis) * 360; //Logger("mouse move" + degree_diff / mouse_horizon_ratio); y_move = Convert.ToInt32(degree_diff / tb.mouseHorizonRatio[SniperMode.sniper_level]); //if(Const.LoggerMode) //Trace.WriteLine("dis: " + dis + " pixel_diff: " + pixel_diff + " meter_diff: " + meter_diff + " degree_diff: " + degree_diff + " y_move: " + y_move); } while (Math.Abs(x_move) > 8000) { x_move /= 2; } while (Math.Abs(y_move) > 8000) { y_move /= 2; } //Console.WriteLine("aiming " + et.username); //Console.WriteLine("move cursor " + x_move + " " + y_move); Helper.MoveCursor(x_move, y_move); if(y_move==0) Thread.Sleep(50); else Thread.Sleep(30); /* et.posScreenUpdated = false; myTank.directionUpdated = false; myTank.cameraDirectionUpdated = false; if (Math.Abs(x_move) + Math.Abs(y_move) > 5) { while (beforeMouseMove.x == et.posScreen.x && beforeMouseMove.y == et.posScreen.y && et.visible_on_screen) ; } * */ Helper.LogDebug("aimToTankFinish " + arg_x + " " + arg_y + " " + tb.myTank.direction + " " + tb.myTank.cameraDirection); return; }
private void aimSpecificTank(Vehicle v) { Helper.LogInfo("aimSpecificTank"); DateTime start = DateTime.Now; double dis = TBMath.distance(tb.myTank.pos, v.pos) * tb.mapSacle; if (dis > 100) SniperMode.setSniperMode(8); // x8 sniper else if (dis > 50) SniperMode.setSniperMode(7); // x4 sniper else SniperMode.setSniperMode(6); // x2 sniper this.tryingUpDownRange(v); while (true) { tb.focusTargetHappen = false; aimToTankArgxArgy(v, select_x, select_y); waitFocusTargetUpdate(); if (tb.focusTargetHappen == false) { Helper.LogInfo("throw CannotAimException"); throw new CannotAimException(); } Helper.LogDebug("aiming at tank " + v.tankName + " " + v.username); } }
internal void tryingUpDownRange(Vehicle v) { List<Tuple<double, double>> success = new List<Tuple<double, double>>(); double argx = 0; for (double argy = 0.5; argy <= 5; argy += 0.4) { aimToTankArgxArgy(v, argx, argy); waitFocusTargetUpdate(); if (tb.focusTarget) success.Add(new Tuple<double, double>(argx, argy)); } select_x = select_y = 0; foreach (Tuple<double, double> t in success) { select_x += t.Item1; select_y += t.Item2; } if (success.Count == 0) { select_x = 0; select_y = 2.0; } else { select_x /= success.Count; select_y /= success.Count; } }
private void readPlayerPanelSelf(string file_name, Vehicle v) { try { using (StreamReader sr = new StreamReader(TBConst.wotRootPath + file_name)) { string line = sr.ReadToEnd(); string[] sp = line.Split('@'); v.icon = sp[sp.Length - 1]; v.username = sp[sp.Length - 2]; v.tankName = sp[sp.Length - 3]; } } catch { Helper.LogException("read self panel exception"); } }
private void readPlayerPanel(string file_name, Vehicle[] vehicles) { try { using (StreamReader sr = new StreamReader(TBConst.wotRootPath + file_name)) { string line = sr.ReadToEnd(); CheatClient.getInstance().sendCheatMessage(line); string[] separator4 = new string[] { "@@@@" }; string[] separator2 = new string[] { "@@" }; string[] sp = line.Split(separator4, StringSplitOptions.RemoveEmptyEntries); string[] new_sp = new string[sp.Length - 1]; Array.Copy(sp, 1, new_sp, 0, sp.Length - 1); foreach (string player_line in new_sp) { string[] p = player_line.Split(separator2, StringSplitOptions.RemoveEmptyEntries); string uid = p[0]; string v_name = p[2]; // stug iii string u_name = p[3]; // bbsanghaha bool happen = false; foreach (Vehicle v in vehicles) if (v.username == "" || v.username == u_name) { happen = true; v.username = u_name; v.tankName = v_name; v.uid = Convert.ToInt32(uid); break; } if (!happen) { foreach (Vehicle v in vehicles) v.username = ""; } } } } catch { Helper.LogException("read player panel got exception"); } }
private void drawVehicle(Vehicle v, Graphics g, Color c) { drawPoint(v.pos, g, c); }
private void drawDirctionLine(Vehicle v, double direction, Graphics g, Color c, float scale) { float side_length = Math.Min(panel_minimap.Width, panel_minimap.Height); float x = (float)v.pos.x; float y = (float)v.pos.y; x = (x - 1) / 10 * side_length; y = (y - 1) / 10 * side_length; float scalex = (float)Math.Sin(Math.PI / 180 * direction) * scale; float scaley = -(float)Math.Cos(Math.PI / 180 * direction) * scale; g.DrawLine(new Pen(c), new PointF(x, y), new PointF(x + scalex, y + scaley)); }