public override void AreaChange(AreaInstance area) { if (GameController.Player != null) { if (!WillBot.isBotPaused) { lock (MyLocks.UpdateTerrainDataLock) { WillBot.LogMessageCombo("AreaChange: Updating terrain data STARTED"); mover.UpdateTerrainData(doNotUpdateIfAlreadyExists: true); WillBot.LogMessageCombo("AreaChange: Updating terrain data FINISHED"); } } if (Settings.Enable.Value && area != null) { Cache.InHideout = area.IsHideout; Cache.InTown = area.IsTown; if (Cache.InHideout == true) { WillBot.Me.HasStashedItemsThisTownCycle = false; WillBot.Me.HasSoldItemsThisTownCycle = false; WillBot.Me.enemies.BlackListedMonsterAddresses.Clear(); ChaosRecipeBehavior.ResetData(); } } } }
public static Composite DoExploringComposite() { return(new Decorator(delegate { float areaExplored = WillBot.Mover.GetPercentOfCurrentSubMapExplored(); WillBot.LogMessageCombo($"Area explored: {areaExplored}"); if (DoExploreZone() == true) { return true; } return false; }, new Sequence( new Action(delegate { var foundPos = WillBot.Mover.GetUnexploredPosition(); WillBot.LogMessageCombo($"Unexplored coordinates {foundPos}"); if (foundPos.Item1) { CouldNotFindValidPositionToExplore = false; WillBot.Me.IsCurrentPositionToExploreValid = true; WillBot.Me.CurrentPositionToExplore = foundPos.Item2; return RunStatus.Success; } else { WillBot.Me.IsCurrentPositionToExploreValid = false; CouldNotFindValidPositionToExplore = true; return RunStatus.Failure; } }), MoveTo(ret => WillBot.Me.CurrentPositionToExplore, spec: CommonBehavior.DefaultMovementSpec) ) )); }
// Can this handle both moving to some valid monster + moving towards some unique monster with isTargetable == false etc public static bool DoMoveToMonster() { if (DoCombat() == true) { return(false); } Vector3 playerWorldPos = WillBot.gameController.Player.Pos; bool isZDifferenceOk = false; var closestKillableMonster = WillBot.Me.enemies.ClosestMonsterEntity; if (closestKillableMonster != null) { isZDifferenceOk = Math.Abs(playerWorldPos.Z - closestKillableMonster.Pos.Z) < WillBot.Settings.NavigateToMonsterMaxZDifference; WillBot.LogMessageCombo($"In do move to monster. Z difference is {isZDifferenceOk} "); if (isZDifferenceOk) { return(true); } } return(false); }
public override void ReceiveEvent(string eventId, object args) { WillBot.LogMessageCombo($"Recived event {eventId}"); switch (eventId) { case "stashie_done": WillBot.Me.StashieHasCompletedStashing = true; WillBot.Me.IsPlayerInventoryFull = false; break; //case "stashie_stop_drop_items": // WillBot.Me.StashieHasCompletedStashing = true; // break; } }
public IEnumerator MainWorkCoroutine() { while (true) { if (runTestMove) { InputWrapper.ResetMouseButtons(); WillBot.LogMessageCombo($"Running test move"); runTestMove = false; // yield return mover.MovePlayerToGridPos(testMovePosition); } yield return(new WaitTime(1)); } }
private Composite CreateTree() { return(new PrioritySelector( new Decorator(x => GameController.Game.IsPreGame == true, LoginBehavior.TryEnterGameFromLoginScreen(x => 3)), new Decorator(x => TreeHelper.CanTickTown(), CommonBehavior.TownToHideout()), new Decorator(x => TreeHelper.CanTickHideout(), new PrioritySelector( new Decorator(x => (DateTime.Now.Subtract(previousBreakTime) > breakInterval), new Action(delegate { previousBreakTime = DateTime.Now; var breakLength = new TimeSpan(hours: 0, minutes: MathHepler.Randomizer.Next(8, 15), seconds: 0); Thread.Sleep(breakLength); return RunStatus.Failure; } )), //new Inverter(CommonBehavior.CloseOpenPanels()), CommonBehavior.HandleDestroyItemPopup(), CharacterAbilityTrees.ActivateNecroAuras(), new Action(delegate { CommonBehavior.CouldNotFindValidPositionToExplore = false; WillBot.Me.enemies.LastKilledMonsterTime = DateTime.Now; return RunStatus.Failure; }), SellBehavior.SellItems(sellUnidCrItems: true), TownBehavior.IdentifyUniquesInPlayerInventory(), TownBehavior.Stashie(), //ChaosRecipeBehavior.ChaosRecipeHandler(), // TownBehavior.EnterBloodAquaducts())), MapPrepBehavior.GetOpenAndEnterMap())), new Decorator(x => TreeHelper.CanTickDead(), AreaBehavior.DiedBehavior()), new Decorator(x => TreeHelper.CanTickMap(),// !PlayerHelper.isPlayerDead(), new PrioritySelector( //new Inverter(CommonBehavior.CloseOpenPanels()), new Inverter(CommonBehavior.CloseOpenPanelsIfOpenPanels()), new Decorator(delegate { // if not killed a monster in the last x seconds -> exit map if (DateTime.Now.Subtract(WillBot.Me.enemies.LastKilledMonsterTime).TotalSeconds > 60) { return true; } return false; }, CommonBehavior.OpenAndEnterTownPortal() ), CharacterAbilityTrees.CreateNecroBuffTree(), new Decorator(ret => CommonBehavior.DoCombat(), NecroCombat.NecroCombatComposite()), LevelGemsBehavior.LevelGems(), LootBehavior.BuildLootComposite(), ChestBehavior.DoOpenNearbyChest(), AreaBehavior.InteractWithLabelOnGroundOpenable(() => WillBot.Me.TimelessMonolith), AreaBehavior.InteractWithLabelOnGroundOpenable(() => WillBot.Me.EssenceMonsterMonolith), AreaBehavior.InteractWithLabelOnGroundOpenable(() => WillBot.Me.HarvestChest), AreaBehavior.InteractWithLabelOnGroundOpenable(() => WillBot.Me.StrongBox), AreaBehavior.InteractWithLabelOnGroundOpenable(() => WillBot.Me.BlightPumpInMap), //AreaBehavior.DefendBlightPumpMap(), AreaBehavior.OpenDeliriumMirror(), CommonBehavior.MoveToUnkillableUniqueMonster(), //CommonBehavior.MoveToDeliriumPause(), new Decorator(x => CommonBehavior.DoMoveToMonster(), CommonBehavior.MoveTo(ret => WillBot.Me.enemies.ClosestMonsterEntity?.GridPos, x => WillBot.Me.enemies.ClosestMonsterEntity?.Pos, CommonBehavior.DefaultMovementSpec)), new Action(delegate { AreaBehavior.UpdateAreaTransitions(); return RunStatus.Failure; }), new Decorator(delegate { if (CommonBehavior.DoMoveToMonster() == false && CommonBehavior.DoCombat() == false && CommonBehavior.DoMoveToNonKillableUniqueMonster() == false) { WillBot.LogMessageCombo($"Checking for exit/area transitions"); return true; } return false; }, new PrioritySelector( CommonBehavior.HandleDestroyItemPopup(), AreaBehavior.TryDoAreaTransition(), new Decorator(delegate { if (CommonBehavior.MapComplete()) { WillBot.LogMessageCombo($"Exiting map due to map complete criterias fulfilled, explored more than {WillBot.Settings.MapAreaExploration}"); return true; } return false; }, CommonBehavior.OpenAndEnterTownPortal() ), new Decorator(delegate { if (CommonBehavior.CouldNotFindValidPositionToExplore == true) { WillBot.LogMessageCombo("Exiting map due to not finding a valid position to explore"); return true; } return false; }, CommonBehavior.OpenAndEnterTownPortal() ), new Decorator( delegate { if (WillBot.Me.IsPlayerInventoryFull == true) { WillBot.LogMessageCombo("Exiting map due to inventory full."); return true; } return false; }, CommonBehavior.OpenAndEnterTownPortal()) )), CommonBehavior.DoExploringComposite() )))); }
public static Composite MoveTo(PositionDelegate positionDelegate, XyzPositionDelegate xyzPositionDelegate = null, MovementSpec spec = null) { return(new Sequence( new Action(delegate(object context) { var position = positionDelegate(context); if (position == null) { WillBot.LogMessageCombo($"Unable to set path to null position"); return RunStatus.Failure; } bool didSetPath = WillBot.Mover.SetPath((Vector2)position); if (didSetPath == false) { WillBot.LogMessageCombo($"Unable to set path to {position}"); return RunStatus.Failure; } else { WillBot.LogMessageCombo($"Successfully found path to {position}"); ControlTimer.Restart(); return RunStatus.Success; } }), new Action(delegate(object context) { bool isZDifferenceOk = true; var entityPos = xyzPositionDelegate?.Invoke(context); var entityGridPos = positionDelegate?.Invoke(context); if (entityPos != null) { isZDifferenceOk = Math.Abs(GameController.Player.Pos.Z - entityPos.GetValueOrDefault().Z) < WillBot.Settings.MovementCancelingForLootZThreshold; } // if zdifferencenotOk, but the path is relatively straight to the object and close -> use movement skill WillBot.LogMessageCombo($"Remaining path distance squared : {WillBot.Mover.pathFindingWrapper.RemainingPathDistanceSquaredToTarget}"); var airDistanceSquared = entityGridPos.GetValueOrDefault().DistanceSquared(WillBot.gameController.Player.GridPos); if (isZDifferenceOk == false && (WillBot.Mover.pathFindingWrapper.RemainingPathDistanceSquaredToTarget < 1300) && WillBot.Mover.pathFindingWrapper.RemainingPathDistanceSquaredToTarget < 1.07 * airDistanceSquared) { WillBot.LogMessageCombo($"Using movement skill to most likely jump a cliff which incorrectly is set to walkable"); InputWrapper.ResetMouseButtons(); var screenPos = Camera.WorldToScreen((Vector3)entityPos); Mouse.SetCursorPosAndLeftOrRightClick(screenPos, 10, clickType: Mouse.MyMouseClicks.NoClick); InputWrapper.KeyPress(Keys.E); //MoverHelper.ClickToStopCharacter(); return RunStatus.Failure; } switch (spec.cancelReason) { case CancelReason.None: break; case CancelReason.PathDistanceLessThanRange: if ((WillBot.Mover.pathFindingWrapper.RemainingPathDistanceSquaredToTarget < (spec.cancelRangeSquared)) && isZDifferenceOk) { WillBot.LogMessageCombo($"Canceled movement in range to object {spec.cancelRange}"); InputWrapper.ResetMouseButtons(); //MoverHelper.ClickToStopCharacter(); return RunStatus.Failure; } break; case CancelReason.PathDistanceLessThanRangeIfStraightPath: /* Cancel pathfinding if path distance to object is less than X and distance to object and path distance are roughly equal * use 1: Looting, avoid having to pathfind really close to loot before clicking the label. */ //var airDistanceSquared = entityGridPos.GetValueOrDefault().DistanceSquared(WillBot.gameController.Player.GridPos); if ((WillBot.Mover.pathFindingWrapper.RemainingPathDistanceSquaredToTarget < spec.cancelRangeSquared) && WillBot.Mover.pathFindingWrapper.RemainingPathDistanceSquaredToTarget < 1.07 * airDistanceSquared) { WillBot.LogMessageCombo($"Canceled movement in range to object with straight line {spec.cancelRange}"); InputWrapper.ResetMouseButtons(); //MoverHelper.ClickToStopCharacter(); return RunStatus.Failure; } break; } if (spec.cancelForMonster && DoCombat()) { WillBot.LogMessageCombo($"Canceled movement to do combat"); InputWrapper.ResetMouseButtons(); return RunStatus.Failure; } if (spec.cancelForLoot && DoLooting()) { WillBot.LogMessageCombo($"Canceled movement to do looting"); InputWrapper.ResetMouseButtons(); return RunStatus.Failure; } if (spec.cancelForOpenables && (WillBot.Me.StrongBox != null || WillBot.Me.HarvestChest != null || WillBot.Me.EssenceMonsterMonolith != null)) { InputWrapper.ResetMouseButtons(); WillBot.LogMessageCombo($"Canceled movement to do openables"); return RunStatus.Failure; } if (ControlTimer.ElapsedMilliseconds > 3500 && StuckTracker.GetDistanceMoved() < 40) { InputWrapper.ResetMouseButtons(); WillBot.LogMessageCombo($"Canceled movement due to being stuck!. Using movement ability"); InputWrapper.KeyPress(WillBot.Settings.MovementAbilityKey); return RunStatus.Failure; } // If movement last x duration less than .. return return WillBot.Mover.FollowPath(); }) )); }
public static bool SetCursorPosAndLeftOrRightClick(RectangleF rect, int extraDelay, MyMouseClicks clickType = MyMouseClicks.LeftClick, bool randomClick = false) { try { var gameWindowRect = GameController.Window.GetWindowRectangle(); int posX = 0; int posY = 0; if (randomClick) { // Constrain to center +- x percent of width and height int xRandomStart = (int)(rect.Center.X - 0.1f * rect.Width); int xRandomStop = (int)(rect.Center.X + 0.1f * rect.Width); int yRandomStart = (int)(rect.Center.Y - 0.1f * rect.Height); int yRandomStop = (int)(rect.Center.Y + 0.1f * rect.Height); posX = (int)gameWindowRect.TopLeft.X + ExileCore.Shared.Helpers.MathHepler.Randomizer.Next(xRandomStart, xRandomStop); posY = (int)gameWindowRect.TopLeft.Y + ExileCore.Shared.Helpers.MathHepler.Randomizer.Next(yRandomStart, yRandomStop); } else { posX = (int)gameWindowRect.TopLeft.X + (int)rect.Center.X; posY = (int)gameWindowRect.TopLeft.Y + (int)rect.Center.Y; } var inventory = GameController.Game.IngameState.IngameUi.InventoryPanel[InventoryIndex.PlayerInventory]; var inventoryRect = inventory.GetClientRectCache; RectangleF blacklistedRectangleIfPlayerInventoryVisible = new RectangleF(inventoryRect.TopRight.X, 0, inventoryRect.Width, inventoryRect.TopLeft.Y); var inputRect = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height); if (inventory.IsVisible == true && blacklistedRectangleIfPlayerInventoryVisible.Contains(inputRect) == true) { WillBot.LogMessageCombo("Player inventory is visible and you tried to click inside the active items rectangle."); return(false); } // Clamp away x percent of screen height and width float clampFactor = 0.1f; posX = (int)MyExtensions.Clamp <float>(posX, gameWindowRect.TopLeft.X + 5, gameWindowRect.TopRight.X - 5); posY = (int)MyExtensions.Clamp <float>(posY, gameWindowRect.TopLeft.Y + 0.05f * gameWindowRect.Height, gameWindowRect.BottomLeft.Y - clampFactor * gameWindowRect.Height); SetCursorPos(posX, posY); Thread.Sleep(MovementDelay + extraDelay); switch (clickType) { case MyMouseClicks.LeftClick: LeftClick(ClickDelay); break; case MyMouseClicks.RightClick: RightClick(ClickDelay); break; case MyMouseClicks.NoClick: break; case MyMouseClicks.MiddleClick: break; } return(true); } catch { return(false); } }