public static async Task <bool> DesynthesizeAllItems( IEnumerable <BagSlot> bagSlots, ushort maxWait = 5000, bool desynthUniqueUntradeable = false) { foreach (var bagSlot in bagSlots) { if (!desynthUniqueUntradeable && bagSlot.Item != null && (bagSlot.Item.Unique || bagSlot.Item.Untradeable)) { continue; } if (bagSlot != null) { var startingId = bagSlot.TrueItemId; //Check to make sure the bagslots contents doesn't change while (bagSlot.TrueItemId == startingId && bagSlot.Count > 0) { var result = await CommonTasks.Desynthesize(bagSlot, maxWait); if (result.HasFlag(DesynthesisResult.Failure)) { Logger.Instance.Error(Localization.Localization.SalvageDialog, result); break; } } } await Behaviors.Sleep(500); } return(true); }
protected override async Task <bool> Main() { if (!Core.Player.DesynthesisUnlocked) { Log("You have not unlocked the desynthesis ability."); return(isDone = true); } IEnumerable <BagSlot> desynthables; if (ItemIds != null) { desynthables = InventoryManager.FilledSlots.Where(bs => Array.Exists(ItemIds, e => e == bs.RawItemId) && bs.IsDesynthesizable && bs.CanDesynthesize); } else { Log("You didn't specify anything to desynthesize."); return(isDone = true); } IEnumerable <BagSlot> bagSlots = desynthables as IList <BagSlot> ?? desynthables.ToList(); var numItems = bagSlots.Count(); if (numItems == 0) { Log("None of the items you requested can be desynthesized."); return(isDone = true); } var i = 1; foreach (var bagSlot in bagSlots) { var name = bagSlot.Name; Log("Attempting to desynthesize item {0} (\"{1}\") of {2}.", i++, name, numItems); var result = await CommonTasks.Desynthesize(bagSlot, DesynthDelay); if (result != DesynthesisResult.Success) { Log("Unable to desynthesize \"{0}\" due to {1}.", name, result); continue; } await Coroutine.Wait(DesynthTimeout * 1000, () => !bagSlot.IsFilled || !bagSlot.Name.Equals(name)); if (bagSlot.IsFilled && bagSlot.EnglishName.Equals(name)) { Log("Timed out awaiting desynthesis of \"{0}\" ({1} seconds).", name, DesynthTimeout); } else { Log("Desynthed \"{0}\".", name); } } return(isDone = true); }
protected static async Task <bool> DesynthMethod() { if (!Core.Player.DesynthesisUnlocked) { Logger.SyntgohtLog("You have not unlocked the desynthesis ability."); Done = true; return(true); } IEnumerable <BagSlot> desynthables = null; var havedDsynthables = InventoryManager.FilledSlots.Any(bs => bs.IsDesynthesizable && bs.CanDesynthesize); if (havedDsynthables) { desynthables = InventoryManager.FilledSlots.Where(bs => bs.IsDesynthesizable && bs.CanDesynthesize); } else { Logger.SyntgohtLog("You don't have anything to desynthesize."); Done = true; return(true); } var numItems = desynthables.Count(); foreach (var bagSlot in desynthables) { var name = bagSlot.EnglishName; var stackSize = bagSlot.Count; var stackIndex = 1; var consecutiveTimeouts = 0; var desythClass = (ClassJobType)bagSlot.Item.RepairClass; Logger.SyntgohtLog("You have {0} items in {1} to desynthesize.", stackSize, bagSlot.BagId); while (bagSlot.Count > 0 && !MainSettingsModel.Instance.UsePause) { var desynthLevel = Core.Player.GetDesynthesisLevel(desythClass); var desynthTarget = "\"" + name + "\", " + stackIndex + " of " + numItems + ","; Logger.SyntgohtLog("Attempting to desynthesize {0} - success chance is {1}%.", desynthTarget, await CommonTasks.GetDesynthesisChance(bagSlot)); var currentStackSize = bagSlot.Item.StackSize; var result = await CommonTasks.Desynthesize(bagSlot, MainSettingsModel.Instance.DesynthDelay); RetryDesynth: if (result != DesynthesisResult.Success) { Logger.SyntgohtLog("Unable to desynthesize {0} due to {1} - moving to next bag slot.", desynthTarget, result); goto RetryDesynth; } await Coroutine.Wait(MainSettingsModel.Instance.DesynthTimeout * 1000, () => (!bagSlot.IsFilled || !bagSlot.EnglishName.Equals(name) || bagSlot.Count != currentStackSize)); if (bagSlot.IsFilled && bagSlot.EnglishName.Equals(name) && bagSlot.Count == currentStackSize) { consecutiveTimeouts++; Logger.SyntgohtLog("Timed out awaiting desynthesis of {0} ({1} seconds, attempt {2} of {3}).", desynthTarget, MainSettingsModel.Instance.DesynthTimeout, consecutiveTimeouts, MainSettingsModel.Instance.ConsecutiveDesynthTimeoutLimit); if (consecutiveTimeouts >= MainSettingsModel.Instance.ConsecutiveDesynthTimeoutLimit) { Logger.SyntgohtLog("While desynthesizing {0), exceeded consecutive timeout limit - moving to next bag slot.", desynthTarget); goto RetryDesynth; } } else { var desynthLevelPost = Core.Player.GetDesynthesisLevel(desythClass) - desynthLevel; Logger.SyntgohtLog("Desynthed {0} Sucessfully!. Gained {1} {2} Desyth levels, {2}'s desynthesis level is now {3}.", desynthTarget, desynthLevelPost, desythClass, Core.Player.GetDesynthesisLevel(desythClass)); consecutiveTimeouts = 0; stackIndex++; } } } return(true); }