public void MoveWithModifiers(string internalClusterName, Vector3 <float> destination) { var area = new Vector3f(0.0f, 0.0f, 0.0f).Expand(3.0f, 3.0f, 3.0f); var pfc = new PointPathFindConfig(); // make black clusters a last resort pfc.ClusterModifiers.Add(c => { if (c.Type == Meta.ClusterType.PvpBlack) { return(100000.0f); } return(0.0f); }); // set tiles around the area to unwalkable pfc.ClippingModifiers.Add(c => { for (var x = area.Start.X; x < area.End.X + 1; x++) { for (var z = area.Start.Z; z < area.End.Z + 1; z++) { var conv = Collision.LocToGrid(x, z); c[conv.X, conv.Y] = false; } } }); // add a random weighting to each tile, making paths 'random' pfc.WeightingModifiers.Add((x, y) => { return((float)RandomUtils.NextDouble() * 10.0f); }); pfc.Point = destination; pfc.ClusterName = internalClusterName; Movement.PathFindTo(pfc); }
public override int OnLoop(IScriptEngine se) { if (config.RepairDest != null && Api.HasBrokenItems()) { parent.EnterState("repair"); return(0); } var localPlayer = Players.LocalPlayer; if (localPlayer == null) { context.State = "Failed to find local player!"; Logging.Log("Failed to find local player!", LogLevel.Error); return(10_000); } if (localPlayer.IsUnderAttack) { Logging.Log("Local player under attack, fight back!", LogLevel.Atom); parent.EnterState("combat"); return(0); } var localLocation = localPlayer.ThreadSafeLocation; if (!config.ResourceArea.RealArea(Api).Contains(localLocation)) { context.State = "Walking to gather area..."; Logging.Log("Local player not in gather area, walk there!", LogLevel.Atom); var moveConfig = new PointPathFindConfig(); moveConfig.UseWeb = false; moveConfig.ClusterName = config.ResourceClusterName; if (Movement.PathFindTo(moveConfig) != PathFindResult.Success) { Logging.Log("Local player failed to find path to resource area!", LogLevel.Error); return(10_000); } return(0); } var heldWeight = localPlayer.TotalHoldWeight; if (heldWeight >= config.MaxHoldWeight) { Logging.Log("Local player has too much weight, banking!", LogLevel.Atom); parent.EnterState("bank"); return(0); } if (NeedsNew()) { if (!FindResource(localLocation)) { var point = RandomRoamPoint(); if (point == null) { context.State = "Failed to find roam point!"; Logging.Log("Cannot roam as roam points were not added!"); return(15000); } context.State = "Roaming"; var moveConfig = new PointPathFindConfig(); moveConfig.UseWeb = false; moveConfig.ClusterName = config.ResourceClusterName; moveConfig.Point = point; moveConfig.UseMount = true; moveConfig.ExitHook = (() => { var local = Players.LocalPlayer; if (local != null) { return(FindResource(local.ThreadSafeLocation)); } return(false); }); if (Movement.PathFindTo(moveConfig) != PathFindResult.Success) { context.State = "Failed to find path to roaming point..."; return(10_000); } return(5000); } } if (harvestableTarget != null) { var area = harvestableTarget.InteractBounds; if (area.Contains(localLocation)) { if (localPlayer.IsMounted) { localPlayer.ToggleMount(false); } context.State = "Attempting to gather " + harvestableTarget.Id + " (" + gatherAttempts + ")"; harvestableTarget.Click(); Time.SleepUntil(() => { return(localPlayer.IsHarvesting); }, 3000); if (!localPlayer.IsHarvesting) { gatherAttempts = gatherAttempts + 1; } return(100); } else { context.State = "Walking to resource..."; var dist = localLocation.SimpleDistance(harvestableTarget.ThreadSafeLocation); var config = new ResourcePathFindConfig(); config.ClusterName = this.config.ResourceClusterName; config.UseWeb = false; config.Target = harvestableTarget; config.UseMount = ShouldUseMount(heldWeight, dist); config.ExitHook = (() => { var lpo = Players.LocalPlayer; if (lpo == null) { return(false); } if (!lpo.IsMounted && lpo.IsUnderAttack) { parent.EnterState("combat"); return(true); } if (!harvestableTarget.IsValid || harvestableTarget.Depleted) { return(true); } return(false); }); var result = Movement.PathFindTo(config); if (result == PathFindResult.Failed) { context.State = "Failed to path find to resource!"; blacklist.Add(harvestableTarget.Id); Reset(); } return(0); } } else if (mobTarget != null) { var mobGatherArea = mobTarget.ThreadSafeLocation.Expand(3, 3, 3); if (mobGatherArea.Contains(localLocation)) { context.State = "Attempting to kill mob"; if (localPlayer.IsMounted) { localPlayer.ToggleMount(false); } localPlayer.SetSelectedObject(mobTarget); localPlayer.AttackSelectedObject(); Time.SleepUntil(() => { return(localPlayer.IsUnderAttack); }, 3000); if (localPlayer.IsUnderAttack) { parent.EnterState("combat"); } else { gatherAttempts = gatherAttempts + 1; } return(100); } else { context.State = "Walking to mob..."; var dist = localLocation.SimpleDistance(mobTarget.ThreadSafeLocation); var config = new PointPathFindConfig(); config.ClusterName = this.config.ResourceClusterName; config.UseWeb = false; config.Point = mobTarget.ThreadSafeLocation; config.UseMount = ShouldUseMount(heldWeight, dist); config.ExitHook = (() => { var lpo = Players.LocalPlayer; if (lpo == null) { return(false); } if (!lpo.IsMounted && lpo.IsUnderAttack) { parent.EnterState("combat"); return(true); } if (!mobTarget.IsValid || mobTarget.CurrentHealth <= 0) { return(true); } return(false); }); if (Movement.PathFindTo(config) == PathFindResult.Failed) { context.State = "Failed to path find to mob!"; blacklist.Add(mobTarget.Id); Reset(); } return(0); } } return(100); }
public override int OnLoop(IScriptEngine se) { var localPlayer = Players.LocalPlayer; if (localPlayer == null) { context.State = "Failed to find local player!"; return(10_000); } if (!config.VaultArea.RealArea(Api).Contains(localPlayer.ThreadSafeLocation)) { context.State = "Walking to vault..."; var config = new PointPathFindConfig(); config.ClusterName = this.config.VaultClusterName; config.UseWeb = false; config.Point = this.config.VaultDest.RealVector3(); config.UseMount = true; Movement.PathFindTo(config); return(0); } if (config.FleeOnLowHealth && localPlayer.HealthPercentage <= config.FleeHealthPercent) { return(1000); } if (!Banking.IsOpen) { context.State = "Opening vault..."; var bank = Objects.BankChain.Closest(localPlayer.ThreadSafeLocation); if (bank == null) { context.State = "Failed to find vault!"; return(5000); } bank.Click(); Time.SleepUntil(() => { return(Banking.IsOpen); }, 4000); } if (Banking.IsOpen) { context.State = "FDepositing items..."; var beginWeight = localPlayer.WeighedDownPercent; var allItems = Inventory.GetItemsBySubstring("_ROCK", "_ORE", "_HIDE", "_WOOD", "_FIBER"); var toDeposit = new List <IItemStack>(); foreach (var stack in allItems) { if (!stack.UniqueName.Contains("JOURNAL")) { toDeposit.Add(stack); } } if (toDeposit.Count == 0 || Banking.Deposit(toDeposit.ToArray())) { if (localPlayer.TotalHoldWeight < 99) { if (config.RepairDest != null && Api.HasBrokenItems()) { parent.EnterState("repair"); } else { parent.EnterState("gather"); } return(0); } } } return(100); }
public override int OnLoop(IScriptEngine se) { var localPlayer = Players.LocalPlayer; if (localPlayer == null) { context.State = "Failed to find local player!"; return(10_000); } if (!config.RepairArea.RealArea(Api).Contains(localPlayer.ThreadSafeLocation)) { context.State = "Walking to repair area..."; var config = new PointPathFindConfig(); config.ClusterName = this.config.RepairClusterName; config.Point = this.config.RepairDest.RealVector3(); config.UseWeb = false; config.UseMount = true; Movement.PathFindTo(config); return(0); } if (localPlayer.IsMounted) { localPlayer.ToggleMount(false); } if (!Api.HasBrokenItems()) { if (localPlayer.WeighedDownPercent >= 30) { parent.EnterState("bank"); } else { parent.EnterState("gather"); } } if (!RepairWindow.IsOpen) { context.State = "Opening repair building..."; var building = Objects.RepairChain.Closest(localPlayer.ThreadSafeLocation); if (building == null) { context.State = "Failed to find repair building!"; return(5000); } building.Click(); Time.SleepUntil(() => { return(RepairWindow.IsOpen); }, 4000); } if (RepairWindow.IsOpen) { context.State = "Repairing..."; if (RepairWindow.RepairAll()) { Time.SleepUntil(() => { return(!Api.HasBrokenItems()); }, 60000); } } return(100); }