Пример #1
0
        /*The await sleeps shouldn't be necessary but if they aren't there the game crashes some times since
         * it tries to send commands to a window that isn't open even though it reports it as open (guess it didn't load yet)*/

        private async Task <bool> RetainerTest()
        {
            if (done)
            {
                return(true);
            }

            Log(" ");
            Log("==================================================");
            Log("====================Retainers=====================");
            Log("==================================================");
            Log(" ");

            var count = await HelperFunctions.GetNumberOfRetainers();

            var rets = Core.Memory.ReadArray <RetainerInfo>(Offsets.RetainerData, count);


            //var retainerIndex = 0;

            //Settings variables
            debug = RetainerSettings.Instance.DebugLogging;
            var bell = await GoToSummoningBell();

            if (bell == false)
            {
                LogCritical("No summoning bell near by");
                TreeRoot.Stop("Done playing with retainers");
                return(false);
            }
            await UseSummoningBell();

            await Coroutine.Wait(5000, () => RetainerList.Instance.IsOpen);

            if (!RetainerList.Instance.IsOpen)
            {
                LogCritical("Can't Open Bell");
                TreeRoot.Stop("Done playing with retainers");
                return(false);
            }

            if (SelectString.IsOpen)
            {
                await RetainerRoutine.DeSelectRetainer();
            }
            var ordered      = RetainerList.Instance.OrderedRetainerList.ToArray();
            var numRetainers = ordered.Where(i => i.Active).Count(); //GetNumberOfRetainers();

            var retList         = new List <RetainerInventory>();
            var moveToOrder     = new List <KeyValuePair <uint, int> >();
            var masterInventory = new Dictionary <uint, List <KeyValuePair <int, uint> > >();

            var retainerNames = new Dictionary <int, string>();

            if (numRetainers <= 0)
            {
                LogCritical("Can't find number of retainers either you have none or not near a bell");
                RetainerList.Instance.Close();

                TreeRoot.Stop("Failed: Find a bell or some retainers");
                return(true);
            }

            //Moves
            var moveFrom = new List <uint> [numRetainers];

            for (var retainerIndex = 0; retainerIndex < numRetainers; retainerIndex++)
            {
                moveFrom[retainerIndex] = new List <uint>();
            }

            ventures = RetainerList.Instance.NumberOfVentures;

            for (var retainerIndex = 0; retainerIndex < ordered.Length; retainerIndex++)
            {
                if (!ordered[retainerIndex].Active)
                {
                    continue;
                }
                if (!retainerNames.ContainsKey(retainerIndex))
                {
                    retainerNames.Add(retainerIndex, RetainerList.Instance.RetainerName(retainerIndex));
                }
                bool hasJob = RetainerList.Instance.RetainerHasJob(retainerIndex);
                Log($"Selecting {RetainerList.Instance.RetainerName(retainerIndex)}");
                await RetainerRoutine.SelectRetainer(retainerIndex);

                var inventory = new RetainerInventory();

                if (RetainerSettings.Instance.GetGil)
                {
                    GetRetainerGil();
                }

                LogVerbose("Inventory open");
                foreach (var item in InventoryManager.GetBagsByInventoryBagId(RetainerBagIds).Select(i => i.FilledSlots).SelectMany(x => x).Where(FilterStackable))
                {
                    try
                    {
                        inventory.AddItem(item);
                        if (masterInventory.ContainsKey(item.TrueItemId))
                        {
                            masterInventory[item.TrueItemId]
                            .Add(new KeyValuePair <int, uint>(retainerIndex, item.Count));
                        }
                        else
                        {
                            masterInventory.Add(item.TrueItemId, new List <KeyValuePair <int, uint> >());
                            masterInventory[item.TrueItemId]
                            .Add(new KeyValuePair <int, uint>(retainerIndex, item.Count));
                        }
                    }
                    catch (Exception e)
                    {
                        LogCritical("SHIT:" + e);
                        throw;
                    }
                }

                LogVerbose("Inventory done");

                Log("Checking retainer[{0}] against player inventory", retainerNames[retainerIndex]);

                if (RetainerSettings.Instance.DepositFromPlayer)
                {
                    await RetainerRoutine.DumpItems();
                }

                Log("Done checking against player inventory");

                if (RetainerSettings.Instance.ReassignVentures && (ordered[retainerIndex].Job != ClassJobType.Adventurer) && ventures > 2 && (ordered[retainerIndex].VentureEndTimestamp - UnixTimestamp) <= 0)
                {
                    Log("Checking Ventures");
                    await RetainerHandleVentures(); //CheckVentures();
                }
                else if ((ordered[retainerIndex].VentureEndTimestamp - UnixTimestamp) > 0)
                {
                    Log($"Venture will be done in {(ordered[retainerIndex].VentureEndTimestamp - UnixTimestamp)/60} minutes");
                }
                else
                {
                    Log("Retainer has no job");
                }

                await RetainerRoutine.DeSelectRetainer();

                LogVerbose("Should be back at retainer list by now");

                // await Coroutine.Sleep(200);
                // }

                retList.Add(inventory);
            }

            //await Coroutine.Sleep(1000);

            if (RetainerSettings.Instance.DontOrganizeRetainers || !RetainerSettings.Instance.DepositFromPlayer)
            {
                RetainerList.Instance.Close();

                TreeRoot.Stop("Done playing with retainers (Don't organize or don't deposit items.)");
                return(true);
            }

            if (debug)
            {
                foreach (var itemId in masterInventory)
                {
                    var retainers = "";

                    foreach (var retainerId in itemId.Value)
                    {
                        retainers += $"Retainer[{retainerNames[retainerId.Key]}] has {retainerId.Value} ";
                    }

                    Log("Item {0}: {1}", itemId.Key, retainers);
                }
            }

            LogCritical("Duplicate items Found:");

            if (debug)
            {
                foreach (var itemId in masterInventory.Where(r => r.Value.Count > 1))
                {
                    var retainers  = "";
                    var retListInv = new List <KeyValuePair <int, uint> >(itemId.Value.OrderByDescending(r => r.Value));

                    foreach (var retainerId in retListInv)
                    {
                        retainers += $"Retainer[{retainerNames[retainerId.Key]}] has {retainerId.Value} ";
                    }

                    Log("Item {0}: {1}", itemId.Key, retainers);
                }
            }

            /*
             * Same as above but before the second foreach save retainer/count
             * remove that one since it's where we're going to move stuff to
             */
            var numOfMoves = 0;

            foreach (var itemId in masterInventory.Where(r => r.Value.Count > 1))
            {
                var retListInv = new List <KeyValuePair <int, uint> >(itemId.Value.OrderByDescending(r => r.Value));

                var retainerTemp = retListInv[0].Key;
                var countTemp    = retListInv[0].Value;

                var retainers = "";

                retListInv.RemoveAt(0);

                foreach (var retainerId in retListInv)
                {
                    retainers += $"Retainer[{retainerNames[retainerId.Key]}] has {retainerId.Value} ";
                    countTemp += retainerId.Value;
                }

                Log($"Item: {DataManager.GetItem(NormalRawId(itemId.Key))} ({itemId.Key}) Total:{countTemp} should be in {retainerNames[retainerTemp]} and {retainers}");

                if (countTemp > 999)
                {
                    LogCritical("This item will have a stack size over 999: {0}", itemId.Key);
                }
                else if (numOfMoves < InventoryManager.FreeSlots - 1)
                {
                    numOfMoves++;
                    foreach (var retainerIdTemp in retListInv)
                    {
                        moveFrom[retainerIdTemp.Key].Add(itemId.Key);
                    }
                }
            }

            LogCritical("Looks like we need to do {0} moves", numOfMoves);

            if (numOfMoves < InventoryManager.FreeSlots && numOfMoves > 0)
            {
                LogCritical($"Looks like we have {InventoryManager.FreeSlots} free spaces in inventory so we can just dump into player inventory");

                //First loop
                for (var retainerIndex = 0; retainerIndex < numRetainers; retainerIndex++)
                {
                    var inventory = new RetainerInventory();

                    if (!RetainerList.Instance.IsOpen)
                    {
                        await UseSummoningBell();

                        await Coroutine.Wait(5000, () => RetainerList.Instance.IsOpen);

                        //await Coroutine.Sleep(1000);
                    }

                    if (!RetainerList.Instance.IsOpen)
                    {
                        Log("Failed opening retainer list");
                    }

                    LogVerbose("Open:" + RetainerList.Instance.IsOpen);

                    await RetainerList.Instance.SelectRetainer(retainerIndex);

                    Log($"Selected Retainer: {retainerNames[retainerIndex]}");

                    await Coroutine.Wait(5000, () => RetainerTasks.IsOpen);

                    RetainerTasks.OpenInventory();
                    //
                    await Coroutine.Wait(5000, RetainerTasks.IsInventoryOpen);

                    if (!RetainerTasks.IsInventoryOpen())
                    {
                        continue;
                    }
                    await Coroutine.Sleep(500);

                    Log("Checking retainer[{0}] against move list", retainerNames[retainerIndex]);

                    foreach (var item in moveFrom[retainerIndex])
                    {
                        if (!InventoryManager.GetBagsByInventoryBagId(RetainerBagIds).Select(i => i.FilledSlots).SelectMany(x => x).Any(i => i.TrueItemId == item))
                        {
                            continue;
                        }

                        Log("Moved: " + InventoryManager.GetBagsByInventoryBagId(RetainerBagIds).Select(i => i.FilledSlots).SelectMany(x => x).First(i => i.TrueItemId == item)
                            .Move(InventoryManager.GetBagsByInventoryBagId(inventoryBagId_0).First(bag => bag.FreeSlots > 0).GetFirstFreeSlot()));
                        await Coroutine.Sleep(200);
                    }

                    Log("Done checking against player inventory");

                    RetainerTasks.CloseInventory();

                    await Coroutine.Wait(3000, () => RetainerTasks.IsOpen);

                    RetainerTasks.CloseTasks();

                    await Coroutine.Wait(3000, () => DialogOpen);

                    if (DialogOpen)
                    {
                        Next();
                    }

                    await Coroutine.Wait(3000, () => RetainerList.Instance.IsOpen);

                    LogVerbose("Should be back at retainer list by now");
                }
            }
            else
            {
                if (numOfMoves <= 0)
                {
                    LogCritical("No duplicate stacks found so no moved needed.");
                    RetainerList.Instance.Close();

                    TreeRoot.Stop("Done playing with retainers");
                    return(true);
                }

                LogCritical("Crap, we don't have enough player inventory to dump it all here");
                RetainerList.Instance.Close();

                TreeRoot.Stop("Done playing with retainers");
                return(false);
            }


            for (var retainerIndex = 0; retainerIndex < numRetainers; retainerIndex++)
            {
                Log($"Selecting {RetainerList.Instance.RetainerName(retainerIndex)}");
                await RetainerRoutine.SelectRetainer(retainerIndex);

                await RetainerRoutine.DumpItems();

                await RetainerRoutine.DeSelectRetainer();

                Log($"Done with {RetainerList.Instance.RetainerName(retainerIndex)}");
            }
            //   await RetainerRoutine.ReadRetainers(RetainerRoutine.DumpItems());

            LogVerbose("Closing Retainer List");

            RetainerList.Instance.Close();

            TreeRoot.Stop("Done playing with retainers");

            done = true;

            return(true);
        }
Пример #2
0
        public static async Task CheckVentureTask()
        {
            var verified = await VerifiedRetainerData();

            if (!verified)
            {
                return;
            }

            var count = await HelperFunctions.GetNumberOfRetainers();

            var rets = Core.Memory.ReadArray <RetainerInfo>(Offsets.RetainerData, count);
            var now  = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;

            if (rets.Any(i => i.Active && i.VentureTask != 0 && (i.VentureEndTimestamp - now) <= 0 && SpecialCurrencyManager.GetCurrencyCount(SpecialCurrency.Venture) > 2))
            {
                if (FishingManager.State != FishingState.None)
                {
                    var quit = ActionManager.CurrentActions.Values.FirstOrDefault(i => i.Id == 299);
                    if (quit != default(SpellData))
                    {
                        Log($"Exiting Fishing");
                        if (ActionManager.CanCast(quit, Core.Me))
                        {
                            ActionManager.DoAction(quit, Core.Me);
                            await Coroutine.Wait(6000, () => FishingManager.State == FishingState.None);
                        }
                    }
                }

                if (CraftingLog.IsOpen)
                {
                    Log($"Closing Crafting Window");
                    await Lisbeth.ExitCrafting();

                    await Coroutine.Wait(6000, () => !CraftingLog.IsOpen);

                    await Coroutine.Wait(6000, () => !CraftingManager.IsCrafting && !MovementManager.IsOccupied);
                }

                if (DutyManager.InInstance)
                {
                    Log($"Leaving Diadem");
                    DutyManager.LeaveActiveDuty();

                    if (await Coroutine.Wait(30000, () => CommonBehaviors.IsLoading))
                    {
                        await Coroutine.Yield();

                        await Coroutine.Wait(Timeout.Infinite, () => !CommonBehaviors.IsLoading);

                        await Coroutine.Sleep(5000);
                    }
                }

                if (DutyManager.InInstance || CraftingLog.IsOpen || FishingManager.State != FishingState.None || MovementManager.IsOccupied || CraftingManager.IsCrafting)
                {
                    Log("Something went wrong");
                    return;
                }

                var bell = await GoToSummoningBell();

                if (bell == false)
                {
                    LogCritical("No summoning bell near by");
                    return;
                }
                await RetainerRoutine.ReadRetainers(RetainerCheckOnlyVenture);
            }
            else
            {
                Log("No Ventures Complete");
            }
        }