Beispiel #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(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);
        }
Beispiel #2
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);
        }