Exemplo n.º 1
0
        public async Task <bool> RetainerCheck(RetainerInfo retainer)
        {
            if (RetainerSettings.Instance.ReassignVentures && retainer.Active && retainer.Job != ClassJobType.Adventurer)
            {
                if (retainer.VentureTask != 0)
                {
                    var now      = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                    var timeLeft = retainer.VentureEndTimestamp - now;

                    if (timeLeft <= 0 && SpecialCurrencyManager.GetCurrencyCount(SpecialCurrency.Venture) > 2)
                    {
                        await RetainerHandleVentures();
                    }
                    else
                    {
                        Log($"Venture will be done at {RetainerInfo.UnixTimeStampToDateTime(retainer.VentureEndTimestamp)}");
                    }
                }
            }

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

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

            return(true);
        }
Exemplo n.º 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))
            {
                await GeneralFunctions.StopBusy(dismount : false);

                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");
            }
        }
Exemplo n.º 3
0
        public static async Task <bool> ExitRetainer(bool exitList = false)
        {
            if (RetainerTasks.IsInventoryOpen())
            {
                RetainerTasks.CloseInventory();

                await Coroutine.Wait(3000, () => RetainerTasks.IsOpen);
            }
            if (RetainerTasks.IsOpen)
            {
                RetainerTasks.CloseTasks();

                await Coroutine.Wait(3000, () => Talk.DialogOpen);
            }
            if (Talk.DialogOpen)
            {
                Talk.Next();
                await Coroutine.Wait(3000, () => RetainerList.Instance.IsOpen);
            }

            if (!exitList)
            {
                return(RetainerList.Instance.IsOpen);
            }

            if (!RetainerList.Instance.IsOpen)
            {
                return(true);
            }

            await RetainerRoutine.CloseRetainers();

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

            return(!RetainerList.Instance.IsOpen);
        }
Exemplo n.º 4
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(rets).Where(i => i.Active).ToArray();
            var numRetainers = ordered.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 < numRetainers; retainerIndex++)
            {
                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);
        }
Exemplo n.º 5
0
        public static async Task RetainerSellItems(IEnumerable <BagSlot> items)
        {
            if (await HelperFunctions.GetNumberOfRetainers() == 0)
            {
                Log("No retainers found to sell items to.");

                return;
            }

            List <BagSlot> bagSlots = items.ToList();

            if (!bagSlots.Any())
            {
                Log("No items found to sell.");
                return;
            }

            await StopBusy();

            if (!await HelperFunctions.UseSummoningBell())
            {
                Log("Couldn't get to summoning bell.");
                return;
            }

            await RetainerRoutine.SelectRetainer(0);

            RetainerTasks.OpenInventory();
            if (!await Coroutine.Wait(3000, RetainerTasks.IsInventoryOpen))
            {
                Log("Couldn't get Retainer inventory open.");
                RetainerTasks.CloseInventory();
                await Coroutine.Wait(3000, () => RetainerTasks.IsOpen);

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

                if (Talk.DialogOpen)
                {
                    Talk.Next();
                }
                await Coroutine.Wait(3000, () => RetainerList.Instance.IsOpen);

                await RetainerRoutine.CloseRetainers();

                return;
            }

            int itemCount = bagSlots.Count;
            int i         = 1;

            foreach (var bagSlot in bagSlots)
            {
                if (!bagSlot.IsValid || !bagSlot.IsFilled)
                {
                    Log("BagSlot isn't valid or filled.");
                    i++;
                    continue;
                }

                string name = bagSlot.Name;
                Log($"Attempting to sell #{i++} of {itemCount}: {name}");
                int waitTime = 600;

                bagSlot.RetainerSellItem();

                if (await Coroutine.Wait(500, () => SelectYesno.IsOpen))
                {
                    SelectYesno.ClickYes();
                }
                else
                {
                    waitTime -= 500;
                }

                if (!await Coroutine.Wait(5000, () => !bagSlot.IsValid || !bagSlot.IsFilled))
                {
                    Log($"We couldn't sell {name}.");
                }
                else
                {
                    Log($"Sold {name}.");
                }

                await Coroutine.Sleep(waitTime);
            }

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

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

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

            if (Talk.DialogOpen)
            {
                Talk.Next();
            }
            await Coroutine.Wait(3000, () => RetainerList.Instance.IsOpen);

            await RetainerRoutine.CloseRetainers();
        }
Exemplo n.º 6
0
        public async Task RetainerRun()
        {
            var bell = await GoToSummoningBell();

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

            await RetainerRoutine.ReadRetainers(RetainerCheck);

            await Coroutine.Sleep(1000);

            if (!RetainerSettings.Instance.Loop || !RetainerSettings.Instance.ReassignVentures)
            {
                LogCritical($"Loop Setting {RetainerSettings.Instance.Loop} ReassignVentures {RetainerSettings.Instance.ReassignVentures}");
                TreeRoot.Stop("Done playing with retainers");
            }

            if (RetainerSettings.Instance.Loop && InventoryManager.FreeSlots < 2)
            {
                LogCritical($"I am overburdened....free up some space you hoarder");
                TreeRoot.Stop("Done playing with retainers");
            }

            var count = await GetNumberOfRetainers();

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

            if (!rets.Any(i => i.VentureTask != 0 && i.Active))
            {
                LogCritical($"No ventures assigned or completed");
                TreeRoot.Stop("Done playing with retainers");
            }

            var nextVenture = rets.Where(i => i.VentureTask != 0 && i.Active).OrderBy(i => i.VentureEndTimestamp).First();

            if (nextVenture.VentureEndTimestamp == 0)
            {
                LogCritical($"No ventures running");
                TreeRoot.Stop("Done playing with retainers");
            }

            if (SpecialCurrencyManager.GetCurrencyCount(SpecialCurrency.Venture) <= 2)
            {
                LogCritical($"Get more venture tokens...bum");
                TreeRoot.Stop("Done playing with retainers");
            }

            var now      = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
            var timeLeft = nextVenture.VentureEndTimestamp - now;

            Log($"Waiting till {RetainerInfo.UnixTimeStampToDateTime(nextVenture.VentureEndTimestamp)}");
            await Coroutine.Sleep(timeLeft * 1000);

            await Coroutine.Sleep(30000);

            Log($"{nextVenture.Name} Venture should be done");
        }
Exemplo n.º 7
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 retainerIndex = 0;

            //Settings variables
            debug = RetainerSettings.Instance.DebugLogging;

            await UseSummoningBell();

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

/*            while (RetainerList.Instance.IsOpen)
 *          {
 *              Log($"{Core.Memory.Read<uint>(RetainerList.Instance.WindowByName.Pointer + 0x180) & 0xF00000u}");
 *              await Coroutine.Sleep(50);
 *          }*/
            await Coroutine.Wait(5000, () => RetainerList.Instance.IsOpen);

            //Log("Visible:" + RetainerList.Instance.IsOpen);
            //await Coroutine.Sleep(1000);

            var numRetainers = RetainerList.Instance.NumberOfRetainers; //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>();
            }

            for (var retainerIndex = 0; retainerIndex < numRetainers; retainerIndex++)
            {
                if (!retainerNames.ContainsKey(retainerIndex))
                {
                    retainerNames.Add(retainerIndex, RetainerList.Instance.RetainerName(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");

/*                   AgentModule.ToggleAgentInterfaceById(274);
 *                  await Coroutine.Sleep(200);
 *                  var cho1 = InventoryManager.GetBagByInventoryBagId((InventoryBagId)4000);
 *                  var cho2 = InventoryManager.GetBagByInventoryBagId((InventoryBagId)4001);
 *                  if (cho1 != null && cho2 != null)
 *                  {
 *                      var chocobags = (cho1.FilledSlots).Concat(cho2.FilledSlots);
 *                      foreach (var item in chocobags.Where(FilterStackable).Where(item => inventory.HasItem(item.TrueItemId)))
 *                      {
 *                          Log($"Chocobo AND RETAINER both have Name: {item.Item.CurrentLocaleName}\tId: {item.Item.Id}");
 *                          Log("Moved: " + MoveItem(item, inventory.GetItem(item.TrueItemId)));
 *                          await Coroutine.Sleep(100);
 *                      }
 *                  }*/

                //RetainerTasks.CloseInventory();

                //await Coroutine.Sleep(200);

                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
                {
                    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);
        }
Exemplo n.º 8
0
        private static async Task SortLoop(int index)
        {
            LogDebug($"We're gonna go try to sort {ItemSortStatus.GetByIndex(index).Name}!");

            if (index < ItemSortStatus.PlayerInventoryIndex)
            {
                LogCritical($"Tried to sort index of #{index.ToString()} but that's out of range...");
                return;
            }

            if (index < ItemSortStatus.SaddlebagInventoryIndex)
            {
                LogCritical($"Tried to sort the player's inventory, but we can't do anything with that alone...");
                return;
            }

            if (InventoryManager.FreeSlots == 0 && ItemSortStatus.GetByIndex(index).FreeSlots == 0)
            {
                LogCritical($"Both our player inventory and {ItemSortStatus.GetByIndex(index).Name} are completely full! Can't move anything around like this.");
                return;
            }

            bool openingSaddlebag = index == ItemSortStatus.SaddlebagInventoryIndex;
            await GeneralFunctions.ExitRetainer(openingSaddlebag);

            if (openingSaddlebag)
            {
                await InventoryBuddy.Instance.Open();

                if (!InventoryBuddy.Instance.IsOpen)
                {
                    LogCritical($"We were unable to open the saddlebag!");
                    return;
                }
            }
            else
            {
                await RetainerRoutine.SelectRetainer(index);

                RetainerTasks.OpenInventory();
                await Coroutine.Wait(3000, RetainerTasks.IsInventoryOpen);

                if (!RetainerTasks.IsInventoryOpen())
                {
                    LogCritical($"We were unable to open Retainer #{index.ToString()}!");
                    return;
                }
            }

            await Coroutine.Sleep(200);

            await CombineStacks(GeneralFunctions.MainBagsFilledSlots());
            await CombineStacks(InventoryManager.GetBagsByInventoryBagId(BagIdsByIndex(index)).SelectMany(x => x.FilledSlots));

            while (ShouldSortLoop(index))
            {
                bool depositResult = await DepositLoop(index);

                UpdatePlayerInventory();
                UpdateOpenedInventory(index);

                bool retrieveResult = await RetrieveLoop(index);

                UpdatePlayerInventory();
                UpdateOpenedInventory(index);

                await Coroutine.Sleep(250);

                if (!depositResult || !retrieveResult)
                {
                    break;
                }
            }

            if (openingSaddlebag)
            {
                InventoryBuddy.Instance.Close();
            }
            else
            {
                await GeneralFunctions.ExitRetainer();
            }

            await Coroutine.Sleep(250);
        }
Exemplo n.º 9
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");
            }
        }