コード例 #1
0
ファイル: CSBot.cs プロジェクト: perryh/Diablo2Clientless1.09
        private static async Task <bool> WaitForBo(Client client)
        {
            var initialLocation = client.Game.Me.Location;
            var stopWatch       = new Stopwatch();

            stopWatch.Start();
            while (stopWatch.Elapsed < TimeSpan.FromSeconds(10) && ClassHelpers.AnyPlayerIsMissingShouts(client))
            {
                await Task.Delay(TimeSpan.FromSeconds(0.5));

                await client.Game.MoveToAsync(initialLocation.Add((short)new Random().Next(-5, 5), (short)new Random().Next(-5, 5)));
            }

            if (stopWatch.Elapsed >= TimeSpan.FromSeconds(10))
            {
                Log.Warning($"Client {client.Game.Me.Name} Failed waiting for bo at area {client.Game.Area} at location {client.Game.Me.Location}");
                return(false);
            }

            client.Game.UseHealthPotion();

            return(true);
        }
コード例 #2
0
ファイル: CSBot.cs プロジェクト: perryh/Diablo2Clientless1.09
        private async Task <bool> BaseCsBot(CSManager csManager, Func <uint> getTeleportId,
                                            CancellationTokenSource nextGameCancellation, Client client,
                                            Func <CSManager, List <AliveMonster>, List <AliveMonster>, Task> action)
        {
            var localTeleportId = 0U;

            while (!nextGameCancellation.IsCancellationRequested && client.Game.IsInGame())
            {
                await Task.Delay(100);

                if (localTeleportId != getTeleportId() && !client.Game.IsInTown())
                {
                    Log.Information($"Client {client.Game.Me.Name} Taking town portal to town");
                    if (!await _townManagementService.TakeTownPortalToTown(client))
                    {
                        continue;
                    }
                }

                if (client.Game.IsInTown() && getTeleportId() != 0 && getTeleportId() != localTeleportId)
                {
                    Log.Information($"Client {client.Game.Me.Name} taking town portal to chaos");
                    var teleportPlayer = client.Game.Players.First(p => p.Name.Equals(_csconfig.TeleportCharacterName, StringComparison.CurrentCultureIgnoreCase));
                    if (!await _townManagementService.TakeTownPortalToArea(client, teleportPlayer, Area.ChaosSanctuary))
                    {
                        continue;
                    }

                    localTeleportId = getTeleportId();
                }

                if (!client.Game.IsInTown())
                {
                    var anyPlayersWithoutShouts = ClassHelpers.AnyPlayerIsMissingShouts(client);
                    if (anyPlayersWithoutShouts && client.Game.Me.Class == CharacterClass.Barbarian)
                    {
                        await ClassHelpers.CastAllShouts(client);
                    }
                    else if (ClassHelpers.IsMissingShouts(client.Game.Me))
                    {
                        Log.Information($"Client {client.Game.Me.Name} waiting for bo");
                        await WaitForBo(client);
                    }
                    else
                    {
                        await Task.Delay(100);

                        if (!await KillBosses(client, csManager, nextGameCancellation, client.Game.Me.Location, action, localTeleportId, getTeleportId))
                        {
                            return(false);
                        }
                    }
                }
            }

            if (!nextGameCancellation.IsCancellationRequested && !client.Game.IsInGame())
            {
                return(false);
            }

            return(true);
        }