public async Task <bool> TakeWaypoint(Client client, Waypoint waypoint) { var movementMode = GetMovementMode(client.Game); var pathToTownWayPoint = await _pathingService.ToTownWayPoint(client.Game, movementMode); if (!await MovementHelpers.TakePathOfLocations(client.Game, pathToTownWayPoint, movementMode)) { Log.Information($"Walking to {client.Game.Act} waypoint failed"); return(false); } WorldObject townWaypoint = null; GeneralHelpers.TryWithTimeout((retryCount) => { townWaypoint = client.Game.GetEntityByCode(client.Game.Act.MapTownWayPointCode()).Single(); return(townWaypoint != null); }, TimeSpan.FromSeconds(2)); if (townWaypoint == null) { Log.Error("No waypoint found"); return(false); } if (!await GeneralHelpers.TryWithTimeout(async(retryCount) => { while (client.Game.Me.Location.Distance(townWaypoint.Location) > 5) { if (client.Game.Me.HasSkill(Skill.Teleport)) { await client.Game.TeleportToLocationAsync(townWaypoint.Location); } else { await client.Game.MoveToAsync(townWaypoint); } } client.Game.TakeWaypoint(townWaypoint, waypoint); return(GeneralHelpers.TryWithTimeout((retryCount) => client.Game.Area == waypoint.ToArea(), TimeSpan.FromSeconds(2))); }, TimeSpan.FromSeconds(5))) { return(false); } if (!await GeneralHelpers.TryWithTimeout(async(retryCount) => { client.Game.RequestUpdate(client.Game.Me.Id); var isValidPoint = await _pathingService.IsNavigatablePointInArea(client.Game.MapId, Difficulty.Normal, waypoint.ToArea(), client.Game.Me.Location); return(isValidPoint); }, TimeSpan.FromSeconds(3.5))) { Log.Error("Checking whether moved to area failed"); return(false); } return(true); }
private async Task <bool> KillTopSeal(Client client, CSManager csManager, Action <uint> setTeleportId) { Log.Information($"Teleporting to {EntityCode.TopSeal}"); var pathToTopSeal = await _pathingService.GetPathToObject(client.Game.MapId, Difficulty.Normal, Area.ChaosSanctuary, client.Game.Me.Location, EntityCode.TopSeal, MovementMode.Teleport); if (!await MovementHelpers.TakePathOfLocations(client.Game, pathToTopSeal, MovementMode.Teleport)) { Log.Warning($"Teleporting to {EntityCode.TopSeal} failed at location {client.Game.Me.Location}"); return(false); } var topSeal = client.Game.GetEntityByCode(EntityCode.TopSeal).First(); var toLeftOfSealIsValid = await _pathingService.IsNavigatablePointInArea(client.Game.MapId, Difficulty.Normal, Area.ChaosSanctuary, topSeal.Location.Add(-20, 0)); var killLocation = toLeftOfSealIsValid ? topSeal.Location.Add(-37, 31) : topSeal.Location.Add(0, 70); var pathToKillingLocation = await _pathingService.GetPathToLocation(client.Game, killLocation, MovementMode.Teleport); if (!await MovementHelpers.TakePathOfLocations(client.Game, pathToKillingLocation, MovementMode.Teleport)) { Log.Warning($"Teleporting to {pathToKillingLocation} failed at location {client.Game.Me.Location}"); return(false); } if (!_townManagementService.CreateTownPortal(client)) { return(false); } var myPortal = client.Game.GetEntityByCode(EntityCode.TownPortal).First(t => t.TownPortalOwnerId == client.Game.Me.Id); setTeleportId.Invoke(myPortal.Id); var pathToTopSeal2 = await _pathingService.GetPathToObject(client.Game.MapId, Difficulty.Normal, Area.ChaosSanctuary, client.Game.Me.Location, EntityCode.TopSeal, MovementMode.Teleport); if (!await MovementHelpers.TakePathOfLocations(client.Game, pathToTopSeal2, MovementMode.Teleport)) { Log.Warning($"Teleporting to {pathToKillingLocation} failed at location {client.Game.Me.Location}"); return(false); } if (!await GeneralHelpers.TryWithTimeout(async(_) => { client.Game.InteractWithEntity(topSeal); await Task.Delay(100); return(client.Game.GetEntityByCode(EntityCode.TopSeal).First().State == EntityState.Enabled); }, TimeSpan.FromSeconds(5))) { Log.Warning($"Opening {EntityCode.TopSeal} failed at location {client.Game.Me.Location}"); return(false); } if (!await MovementHelpers.TakePathOfLocations(client.Game, pathToKillingLocation, MovementMode.Teleport)) { Log.Warning($"Teleporting to {pathToKillingLocation} failed at location {client.Game.Me.Location}"); return(false); } var action = GetSorceressKillAction(client); if (!await KillBosses(client, csManager, null, killLocation, action, 0, () => 0)) { return(false); } return(true); }
protected override async Task <bool> RunSingleGame(Client client) { Log.Information("In game"); client.Game.RequestUpdate(client.Game.Me.Id); if (!GeneralHelpers.TryWithTimeout( (_) => client.Game.Me.Location.X != 0 && client.Game.Me.Location.Y != 0, TimeSpan.FromSeconds(10))) { return(false); } if (client.Game.Me.Class != CharacterClass.Sorceress) { throw new NotSupportedException("Only sorceress is supported on Mephisto"); } /* * while (client.Game.Players.Count < 2) * { * Thread.Sleep(TimeSpan.FromMilliseconds(100)); * } */ var townManagementOptions = new TownManagementOptions() { Act = Act.Act3 }; await _townManagementService.PerformTownTasks(client, townManagementOptions); NeedsMule = client.Game.Inventory.Items.Any(i => i.IsIdentified && Pickit.Pickit.ShouldKeepItem(client.Game, i) && Pickit.Pickit.CanTouchInventoryItem(client.Game, i)) || client.Game.Cube.Items.Any(i => i.IsIdentified && Pickit.Pickit.ShouldKeepItem(client.Game, i)); if (NeedsMule) { return(true); } Log.Information("Taking DuranceOfHateLevel2 Waypoint"); if (!await _townManagementService.TakeWaypoint(client, Waypoint.DuranceOfHateLevel2)) { Log.Information("Taking DuranceOfHateLevel2 waypoint failed"); return(false); } var path2 = await _pathingService.GetPathFromWaypointToArea(client.Game.MapId, Difficulty.Normal, Area.DuranceOfHateLevel2, Waypoint.DuranceOfHateLevel2, Area.DuranceOfHateLevel3, MovementMode.Teleport); if (!await MovementHelpers.TakePathOfLocations(client.Game, path2, MovementMode.Teleport)) { Log.Warning($"Teleporting to DuranceOfHateLevel3 warp failed at location {client.Game.Me.Location}"); return(false); } var warp = client.Game.GetNearestWarp(); if (warp == null || warp.Location.Distance(client.Game.Me.Location) > 20) { Log.Warning($"Warp not close enough at location {warp?.Location} while at location {client.Game.Me.Location}"); return(false); } Log.Information($"Taking warp to Durance 3"); if (!GeneralHelpers.TryWithTimeout((_) => client.Game.TakeWarp(warp) && client.Game.Area == Area.DuranceOfHateLevel3, TimeSpan.FromSeconds(2))) { Log.Warning($"Taking warp failed at location {client.Game.Me.Location} to warp at location {warp.Location}"); return(false); } if (!await GeneralHelpers.TryWithTimeout(async(retryCount) => { client.Game.RequestUpdate(client.Game.Me.Id); var isValidPoint = await _pathingService.IsNavigatablePointInArea(client.Game.MapId, Difficulty.Normal, Area.DuranceOfHateLevel3, client.Game.Me.Location); return(isValidPoint); }, TimeSpan.FromSeconds(3.5))) { Log.Error("Checking whether moved to area failed"); return(false); } Log.Information($"Teleporting to Mephisto"); var path3 = await _pathingService.GetPathToLocation(client.Game, new Point(17566, 8070), MovementMode.Teleport); if (!await MovementHelpers.TakePathOfLocations(client.Game, path3, MovementMode.Teleport)) { Log.Warning($"Teleporting to Mephisto failed at location {client.Game.Me.Location}"); return(false); } if (!GeneralHelpers.TryWithTimeout((_) => client.Game.GetNPCsByCode(NPCCode.Mephisto).Count > 0, TimeSpan.FromSeconds(2))) { Log.Warning($"Finding Mephisto failed while at location {client.Game.Me.Location}"); return(false); } var mephisto = client.Game.GetNPCsByCode(NPCCode.Mephisto).Single(); Log.Information($"Killing Mephisto"); if (!GeneralHelpers.TryWithTimeout((retryCount) => { if (!client.Game.IsInGame()) { return(true); } if (mephisto.Location.Distance(client.Game.Me.Location) < 30) { client.Game.RepeatRightHandSkillOnLocation(Skill.StaticField, client.Game.Me.Location); } Thread.Sleep(200); if (retryCount % 5 == 0) { client.Game.UseRightHandSkillOnEntity(Skill.FrozenOrb, mephisto); } return(mephisto.LifePercentage < 30); }, TimeSpan.FromSeconds(30))) { Log.Warning($"Killing Mephisto failed at location {client.Game.Me.Location}"); return(false); } if (!GeneralHelpers.TryWithTimeout((_) => { client.Game.UseRightHandSkillOnEntity(Skill.FrozenOrb, mephisto); if (!client.Game.IsInGame()) { return(true); } return(GeneralHelpers.TryWithTimeout((_) => mephisto.State == EntityState.Dead, TimeSpan.FromSeconds(0.7))); }, TimeSpan.FromSeconds(30))) { Log.Warning($"Killing Mephisto failed at location {client.Game.Me.Location}"); return(false); } if (!PickupNearbyItems(client)) { Log.Warning($"Failed to pickup items at location {client.Game.Me.Location}"); return(false); } return(true); }