private static void btnClick_MassConvertRareToMagic(object sender, RoutedEventArgs routedEventArgs) { try { Logger.Log("Starting Conversion of Backpack VeiledCrystals to ArcaneDust"); if (Trinity.Settings.Loot.Pickup.MiscItemQuality > TrinityItemQuality.Common) { Logger.LogError("Aborting - Too dangerous to put crafting items into backpack when MiscItemQuality setting is set above common"); return; } var from = InventoryItemType.VeiledCrystal; var to = InventoryItemType.ArcaneDust; if (!UIElements.TransmuteItemsDialog.IsVisible || !ConvertMaterials.CanRun(from, to)) { Logger.LogError("You need to have the cube window open and all the required materials in your backpack."); return; } LastStartedConvert = DateTime.UtcNow; CoroutineHelper.RunCoroutine(() => ConvertMaterials.Execute(from, to), result => !ConvertMaterials.CanRun(from, to) || CheckConvertTimeout()); Logger.Log("Finished"); } catch (Exception ex) { Logger.LogError("Exception: " + ex); } }
/// <summary> /// Decodes an export code and applies it to the current state. /// </summary> public ItemListSettings ImportFromCode(string code) { if (string.IsNullOrEmpty(code) || string.IsNullOrWhiteSpace(code)) { ValidationMessage = "You must enter an import/export code"; Logger.Log("You must enter an import/export code"); } try { var decompressedXml = ExportHelper.Decompress(ExportCode); var newSettings = TrinitySetting.GetSettingsInstance <ItemListSettings>(decompressedXml); Grouping = newSettings.Grouping; using (Collection.DeferRefresh()) { SelectedItems = newSettings.SelectedItems; UpdateSelectedItems(); } } catch (Exception ex) { ValidationMessage = string.Format("Error importing itemlist. {0} {1}", ex.Message, ex.InnerException); Logger.Log("Error importing itemlist. {0} {1}", ex.Message, ex.InnerException); } return(this); }
private static void btnClick_Test1(object sender, RoutedEventArgs routedEventArgs) { try { Logger.Log("Starting"); using (ZetaDia.Memory.AcquireFrame()) { ZetaDia.Actors.Update(); foreach (var item in ZetaDia.Me.Inventory.Backpack) { var stackHi = item.GetAttribute <int>(ActorAttributeType.ItemStackQuantityHi); var stackLo = item.GetAttribute <int>(ActorAttributeType.ItemStackQuantityLo); Logger.Log("Item: {0} {1} ItemStackQuantity={2} StackHi={3} StackLo={4}", item.Name, item.ACDGuid, item.ItemStackQuantity, stackHi, stackLo); } } Logger.Log("Finished"); } catch (Exception ex) { Logger.LogError("Exception: " + ex); } }
public static PluginCommunicationResponse Receive(IPlugin sender, string command, params object[] args) { switch (command) { case "PING": return(Respond("PONG")); case "MOVETO": var destination = (Vector3)args[0]; var moveResult = Navigator.NavigationProvider.MoveTo(destination); return(Respond(moveResult)); case "COMBATMODE": CombatMode mode; if (TryGetEnum <CombatMode>(args[0], out mode)) { Logger.Log("Setting Combat Mode to {0} at request of {0}", sender.Name); CombatBase.CombatMode = mode; return(Respond(true)); } return(Respond(false)); case "ResetInactivity": Logger.Log("Resetting Gold/XP Inactivity at request of {0}", sender.Name); GoldInactivity.Instance.ResetCheckGold(); XpInactivity.Instance.ResetCheckXp(); return(Respond(true)); } return(Respond(PluginCommunicationResult.InvalidCommand)); }
public void LoadCommands() { ResetFilterCommand = new RelayCommand(parameter => { FilterText = string.Empty; }); LoadModalCommand = new RelayCommand(parameter => { if (parameter == null) { return; } ModalPage page; if (Enum.TryParse(parameter.ToString(), out page)) { if (page != ModalPage.None) { SelectedModalPage = page; IsModalVisible = true; } ExportCode = string.Empty; if (page == ModalPage.Export) { ExportCommand.Execute(parameter); } } Logger.Log("Selecting modal content... {0}", parameter.ToString()); }); CloseModalCommand = new RelayCommand(parameter => { IsModalVisible = false; }); ImportCommand = new RelayCommand(parameter => { Logger.Log("Importing ItemList..."); var oldSlected = _selectedItems.Count; ImportFromCode(ExportCode); Logger.Log("Selected Before = {0} After = {1}", oldSlected, _selectedItems.Count); IsModalVisible = false; }); ExportCommand = new RelayCommand(parameter => { Logger.Log("Exporting ItemList... {0}", parameter); ExportCode = CreateExportCode(); }); }
/************** * * WARNING * * ALWAYS surround your RoutedEventHandlers in try/catch. Failure to do so will result in Demonbuddy CRASHING if an exception is thrown. * * WARNING * *************/ private static void btnClick_LogRunTime(object sender, RoutedEventArgs routedEventArgs) { try { Logger.Log("Bot {0} has been running for {1} hours {2} minutes and {3} seconds", ZetaDia.CPlayer.HeroName, GameStats.Instance.RunTime.Hours, GameStats.Instance.RunTime.Minutes, GameStats.Instance.RunTime.Seconds); } catch (Exception ex) { Logger.LogError("Exception {0}", ex); } }
private static void CacheTestCacheEventHandler(object sender, RoutedEventArgs routedEventArgs) { try { Logger.Log("Finished Cache Test"); } catch (Exception ex) { Logger.LogError("Exception {0}", ex); } }
public static async Task <bool> ReturnToStashTask() { if (ZetaDia.Me.IsInCombat) { Logger.LogDebug("Cannot return to stash while in combat"); return(false); } if (!ZetaDia.IsInTown && ZetaDia.Me.IsFullyValid() && !ZetaDia.Me.IsInCombat && UIElements.BackgroundScreenPCButtonRecall.IsEnabled) { StartedOutOfTown = true; await CommonCoroutines.UseTownPortal("Returning to stash"); return(true); } if (!GameUI.IsElementVisible(GameUI.StashDialogMainPage) && ZetaDia.IsInTown) { // Move to Stash if (TownRun.StashLocation.Distance2D(ZetaDia.Me.Position) > 10f) { await MoveTo(TownRun.StashLocation, "Shared Stash"); return(true); } if (TownRun.StashLocation.Distance2D(ZetaDia.Me.Position) <= 10f && TownRun.SharedStash == null) { Logger.LogError("Shared Stash actor is null!"); return(false); } // Open Stash if (TownRun.StashLocation.Distance2D(ZetaDia.Me.Position) <= 10f && TownRun.SharedStash != null && !GameUI.IsElementVisible(GameUI.StashDialogMainPage)) { while (ZetaDia.Me.Movement.IsMoving) { Navigator.PlayerMover.MoveStop(); await Coroutine.Yield(); } Logger.Log("Opening Stash"); TownRun.SharedStash.Interact(); await Coroutine.Sleep(200); await Coroutine.Yield(); if (GameUI.IsElementVisible(GameUI.StashDialogMainPage)) { return(true); } return(true); } } return(true); }
/// <summary> /// Updates the DisplayItems collection to match the Selected collection. /// </summary> public void UpdateSelectedItems() { if (_selectedItems == null || _displayItems == null || _collection == null || _collection.View == null || _collection.View.SourceCollection == null) { Logger.Log("Skipping UpdateSelectedItems due to Null"); return; } // Prevent the collection from updating until outside of the using block. using (Collection.DeferRefresh()) { var selectedDictionary = _selectedItems.DistinctBy(i => i.Id).ToDictionary(k => k.Id, v => v); var castView = _collection.View.SourceCollection.Cast <LItem>(); castView.ForEach(item => { // After XML settings load _selectedItems will contain LItem husks that are lacking useful information, just what was saved. // We want to take the saved information and make an object that is fully populated and linked with the UI collection. LItem selectedItem; if (selectedDictionary.TryGetValue(item.Id, out selectedItem)) { //if(!item.IsSelected) //Logger.LogVerbose("Update: Selecting {0} ({1}) with {2} rules", item.Name, item.Id, item.Rules.Count); selectedItem.Rules.ForEach(r => { r.TrinityItemType = item.TrinityItemType; r.ItemStatRange = item.GetItemStatRange(r.ItemProperty); }); item.IsSelected = true; item.Rules = selectedItem.Rules; item.Ops = selectedItem.Ops; // Replacing the reference to automatically receive changes from UI. _selectedItems.Remove(selectedItem); _selectedItems.Add(item); } else { if (item.IsSelected) { Logger.LogVerbose("Update: Deselecting {0}", item.Name); item.IsSelected = false; } } }); } }
private static void btnClick_MoveToCube(object sender, RoutedEventArgs routedEventArgs) { try { Logger.Log("Starting"); CoroutineHelper.RunCoroutine(() => Navigator.MoveTo(Town.Locations.KanaisCube)); Logger.Log("Finished"); } catch (Exception ex) { Logger.LogError("Exception: " + ex); } }
private static void btnClick_HijackTest(object sender, RoutedEventArgs routedEventArgs) { try { Logger.Log("HijackTest Started"); CoroutineHelper.ForceRunCoroutine(() => CubeRaresToLegendary.Execute(), result => !CubeRaresToLegendary.CanRun()); Logger.Log("HijackTest Finished"); } catch (Exception ex) { Logger.LogError("Exception: " + ex); } }
private static void btnClick_UpgradeRares(object sender, RoutedEventArgs routedEventArgs) { try { Logger.Log("Starting"); CoroutineHelper.RunCoroutine(() => CubeRaresToLegendary.Execute()); Logger.Log("Finished"); } catch (Exception ex) { Logger.LogError("Exception: " + ex); } }
private static void btnClick_BuyVendorBlues(object sender, RoutedEventArgs routedEventArgs) { try { Logger.Log("Starting"); CoroutineHelper.RunCoroutine(() => BuyItemsFromVendor.Execute(ItemQualityColor.Yellow), ret => BuyItemsFromVendor.CanRun(ItemQualityColor.Yellow)); Logger.Log("Finished"); } catch (Exception ex) { Logger.LogError("Exception: " + ex); } }
private static void btnClick_SpecialTestHandler(object sender, RoutedEventArgs routedEventArgs) { try { Logger.Log("Starting"); // A1 Open World Stash Location var stashlocation = new Vector3(388.16f, 509.63f, 23.94531f); CoroutineHelper.RunCoroutine(() => Navigator.MoveTo(TownRun.StashLocation)); Logger.Log("Finished"); } catch (Exception ex) { Logger.LogError("Exception: " + ex); } }
/// <summary> /// Set skill to use an SkillMeta object /// </summary> public static void SetSkillMeta(SkillMeta newMeta) { if (newMeta.Skill == null) { Logger.Log("SkillInfo set attempt without a reference to a skill"); return; } SkillMeta oldMeta; if (_skillMetas.TryGetValue(newMeta.Skill, out oldMeta)) { oldMeta.Apply(newMeta); } else { _skillMetas.Add(newMeta.Skill, newMeta); } }
/// <summary> /// Moves to a position, finds actor by Id and interacts with it /// </summary> /// <param name="actorId">id of actor to interact with</param> /// <param name="range">how close to get</param> /// <param name="position">position from which to interact</param> /// <param name="interactLimit">maximum number of times to interact</param> public static async Task <bool> Execute(Vector3 position, int actorId, float range = -1f, int interactLimit = 5) { if (position == Vector3.Zero) { return(false); } if (interactLimit < 1) { interactLimit = 5; } if (range < 0) { range = 2f; } if (position.Distance(ZetaDia.Me.Position) > range) { if (!await MoveTo.Execute(position, position.ToString())) { Logger.Log("MoveTo Failed for {0} Distance={1}", position, position.Distance(ZetaDia.Me.Position)); return(false); } } var actor = ZetaDia.Actors.GetActorsOfType <DiaObject>(true).FirstOrDefault(a => a.ActorSNO == actorId); if (actor == null) { Logger.LogVerbose("Interaction Failed: Actor not found with Id={0}", actorId); return(false); } var distance = position.Distance(ZetaDia.Me.Position); if (distance <= range || distance - actor.CollisionSphere.Radius <= range) { for (int i = 1; i <= interactLimit; i++) { Logger.Log("Interacting with {0} ({1}) Attempt={2}", actor.Name, actor.ActorSNO, i); if (actor.Interact() && i > 1) { break; } await Coroutine.Sleep(100); await Coroutine.Yield(); } } // Better to be redundant than failing to interact. Navigator.PlayerMover.MoveTowards(actor.Position); await Coroutine.Sleep(250); actor.Interact(); Navigator.PlayerMover.MoveStop(); await Coroutine.Sleep(1000); await Interact(actor); return(true); }
/// <summary> /// Moves to something and interacts with it /// </summary> /// <param name="obj">object to interact with</param> /// <param name="range">how close to get</param> /// <param name="interactLimit">maximum number of times to interact</param> public static async Task <bool> Execute(DiaObject obj, float range = -1f, int interactLimit = 5) { if (obj == null) { return(false); } if (!obj.IsFullyValid()) { return(false); } if (interactLimit < 1) { interactLimit = 5; } if (range < 0) { range = obj.CollisionSphere.Radius; } if (obj.Position.Distance(ZetaDia.Me.Position) > range) { if (!await MoveTo.Execute(obj.Position, obj.Name)) { Logger.Log("MoveTo Failed for {0} ({1}) Distance={2}", obj.Name, obj.ActorSNO, obj.Distance); return(false); } } var distance = obj.Position.Distance(ZetaDia.Me.Position); if (distance <= range || distance - obj.CollisionSphere.Radius <= range) { for (int i = 1; i <= interactLimit; i++) { Logger.LogVerbose("Interacting with {0} ({1}) Attempt={2}", obj.Name, obj.ActorSNO, i); if (obj.Interact() && i > 1) { break; } await Coroutine.Sleep(500); await Coroutine.Yield(); } } // Better to be redundant than failing to interact. Navigator.PlayerMover.MoveTowards(obj.Position); await Coroutine.Sleep(500); obj.Interact(); Navigator.PlayerMover.MoveStop(); await Coroutine.Sleep(1000); await Interact(obj); return(true); }
/// <summary> /// Moves items from the Stash to the Backpack /// </summary> /// <param name="itemIds">list of items to withdraw</param> /// <param name="maxAmount">amount to withdraw up to (including counts already in backpack)</param> /// <returns></returns> public static async Task <bool> Execute(IEnumerable <int> itemIds, int maxAmount) { Logger.Log("TakeItemsFromStash Started!"); if (!ZetaDia.IsInGame || !ZetaDia.IsInTown) { return(true); } if (Town.Locations.Stash.Distance(ZetaDia.Me.Position) > 3f) { await MoveToAndInteract.Execute(Town.Locations.Stash, Town.ActorIds.Stash, 8f); } var stash = Town.Actors.Stash; if (stash == null) { Logger.Log("Unable to find Stash"); return(false); } if (!UIElements.StashWindow.IsVisible && Town.Locations.Stash.Distance(ZetaDia.Me.Position) <= 10f) { Logger.Log("Stash window not open, interacting"); stash.Interact(); } var itemIdsHashSet = new HashSet <int>(itemIds); var amountWithdrawn = itemIdsHashSet.ToDictionary(k => k, v => (long)0); var overageTaken = itemIdsHashSet.ToDictionary(k => k, v => false); var lastStackTaken = itemIdsHashSet.ToDictionary(k => k, v => default(ACDItem)); foreach (var item in ZetaDia.Me.Inventory.Backpack.Where(i => i.ACDGuid != 0 && i.IsValid && itemIdsHashSet.Contains(i.ActorSNO)).ToList()) { amountWithdrawn[item.ActorSNO] += item.ItemStackQuantity; lastStackTaken[item.ActorSNO] = item; } foreach (var item in ZetaDia.Me.Inventory.StashItems.Where(i => i.ACDGuid != 0 && i.IsValid && itemIdsHashSet.Contains(i.ActorSNO)).ToList()) { try { if (!item.IsValid || item.IsDisposed) { continue; } var stackSize = item.ItemStackQuantity; var numTakenAlready = amountWithdrawn[item.ActorSNO]; // We have enough of this material already var alreadyTakenEnough = numTakenAlready >= maxAmount; if (alreadyTakenEnough) { continue; } // We have enough of everything already. if (amountWithdrawn.All(i => i.Value >= maxAmount)) { break; } // Only take up to the required amount. var willBeOverMax = numTakenAlready + stackSize > maxAmount; if (!willBeOverMax || !overageTaken[item.ActorSNO]) { var lastItem = lastStackTaken[item.ActorSNO]; var amountRequiredToMax = maxAmount - numTakenAlready; if (willBeOverMax && lastItem != null && lastItem.IsValid && !lastItem.IsDisposed && stackSize > amountRequiredToMax) { // Tried InventoryManager.SplitStack but it didnt work, reverting to moving onto existing stacks. var amountToSplit = stackSize - lastItem.ItemStackQuantity; Logger.Log("Merging Stash Stack {0} onto Backpack Stack. StackSize={1} WithdrawnAlready={2}", item.Name, amountToSplit, numTakenAlready); ZetaDia.Me.Inventory.MoveItem(item.DynamicId, ZetaDia.Me.CommonData.DynamicId, InventorySlot.BackpackItems, lastItem.InventoryColumn, lastItem.InventoryRow); amountWithdrawn[item.ActorSNO] += amountToSplit; overageTaken[item.ActorSNO] = true; } else { Logger.Log("Removing {0} ({3}) from stash. StackSize={1} WithdrawnAlready={2}", item.Name, stackSize, numTakenAlready, item.ActorSNO); if (item.IsValid && !item.IsDisposed) { ZetaDia.Me.Inventory.QuickWithdraw(item); amountWithdrawn[item.ActorSNO] += stackSize; lastStackTaken[item.ActorSNO] = item; } } await Coroutine.Sleep(25); await Coroutine.Yield(); } } catch (Exception ex) { Logger.LogError(ex.ToString()); } } await Coroutine.Sleep(1000); Logger.Log("TakeItemsFromStash Finished!"); return(true); }
public static async Task <bool> ReverseItems(InventorySlot inventorySlot) { try { Logger.LogDebug("Initiating sort task 2"); var myDynamicId = ZetaDia.Me.CommonData.DynamicId; int currentRow = 5; int currentCol = 9; int maxCol = 0, maxRow = 0; switch (inventorySlot) { case InventorySlot.BackpackItems: currentCol = maxCol = 9; currentRow = maxRow = 5; break; case InventorySlot.SharedStash: currentCol = maxCol = 6; currentRow = maxRow = (ZetaDia.Me.Inventory.NumSharedStashSlots / 7) - 1; break; } Logger.Log("Using max columns of {0}, max rows of {1}", maxCol, maxRow); while (_reverseSortedItemsQueue.Any()) { var i = _reverseSortedItemsQueue.Dequeue(); if (inventorySlot == InventorySlot.BackpackItems && CharacterSettings.Instance.ProtectedBagSlots.Any(pbs => pbs.IsItemInSquare(i.Item))) { Logger.LogDebug("Item {0} is protected!", i.Name); continue; } if (currentCol < 0) { currentCol = maxCol; currentRow--; } while (_usedGrid[currentCol, currentRow]) { Logger.LogDebug("Grid location {0},{1} is used already", currentCol, currentRow); currentCol--; if (currentCol < 0) { currentCol = maxCol; currentRow--; } } if (i.Item.InventoryColumn == currentCol && i.Item.InventoryRow == currentRow) { Logger.LogDebug("Item {0} is already sorted at {1},{2}", i.Name, i.Item.InventoryColumn, i.Item.InventoryRow); MarkCellAsUsed(currentRow, currentCol, i); currentCol--; continue; } int desiredStashPage = await SetStashpage(currentRow); if (i.Item.MaxStackCount > 1 && ZetaDia.Me.Inventory.CanStackItemInStashPage(i.Item, desiredStashPage) && GetNumberOfStacks(i.Item, inventorySlot) > 1) { ZetaDia.Me.Inventory.QuickWithdraw(i.Item); await Coroutine.Sleep(50); await Coroutine.Yield(); var sameItem = ZetaDia.Me.Inventory.Backpack.FirstOrDefault(item => item.ActorSNO == i.ActorSNO && item.Name.StartsWith(i.Name.Substring(0, 4))); if (sameItem != null) { ZetaDia.Me.Inventory.QuickStash(sameItem); await Coroutine.Sleep(50); } continue; } await ClearSpot(inventorySlot, currentCol, currentRow, i.IsTwoSquareItem, isForward : false); string msg = String.Format("Moving item {0} from {1},{2} to {3},{4}", i.Name, i.Item.InventoryColumn, i.Item.InventoryRow, currentCol, currentRow); BotMain.StatusText = msg; Logger.LogDebug(msg); ZetaDia.Me.Inventory.MoveItem(i.DynamicId, myDynamicId, inventorySlot, currentCol, currentRow); MarkCellAsUsed(currentRow, currentCol, i); currentCol--; await Coroutine.Sleep(ItemMovementDelay); await Coroutine.Yield(); } } catch (Exception ex) { Logger.LogError("Error sorting " + inventorySlot + " " + ex); RemoveBehavior(); } return(false); }
public static async Task <bool> SortItems(InventorySlot inventorySlot) { try { Logger.LogDebug("Initiating sort task 1"); var myDynamicId = ZetaDia.Me.CommonData.DynamicId; int currentRow = 0; int currentCol = 0; int maxCol = 0, maxRow = 0; switch (inventorySlot) { case InventorySlot.BackpackItems: maxCol = 9; maxRow = 5; break; case InventorySlot.SharedStash: maxCol = 6; maxRow = (ZetaDia.Me.Inventory.NumSharedStashSlots / 7) - 1; break; } Logger.Log("Using max columns of {0}, max rows of {1}", maxCol, maxRow); while (_sortedItemsQueue.Any()) { var i = _sortedItemsQueue.Dequeue(); if (inventorySlot == InventorySlot.BackpackItems && CharacterSettings.Instance.ProtectedBagSlots.Any(pbs => pbs.IsItemInSquare(i.Item))) { Logger.LogDebug("Item {0} is protected!", i.Name); continue; } if (currentCol > maxCol) { currentCol = 0; currentRow++; } while (_usedGrid[currentCol, currentRow]) { Logger.LogDebug("Grid location {0},{1} is already used", currentCol, currentRow); currentCol++; if (currentCol > maxCol) { currentCol = 0; currentRow++; } } if (i.Item.InventoryColumn == currentCol && i.Item.InventoryRow == currentRow) { Logger.LogDebug("Item {0} is already sorted at {1},{2}", i.Name, i.Item.InventoryColumn, i.Item.InventoryRow); MarkCellAsUsed(currentRow, currentCol, i); currentCol++; continue; } await SetStashpage(currentRow); await ClearSpot(inventorySlot, currentCol, currentRow, i.IsTwoSquareItem, isForward : true); string msg = String.Format("Moving item {0} from {1},{2} to {3},{4}", i.Name, i.Item.InventoryColumn, i.Item.InventoryRow, currentCol, currentRow); BotMain.StatusText = msg; Logger.LogDebug(msg); ZetaDia.Me.Inventory.MoveItem(i.DynamicId, myDynamicId, inventorySlot, currentCol, currentRow); MarkCellAsUsed(currentRow, currentCol, i); currentCol++; await Coroutine.Sleep(ItemMovementDelay); await Coroutine.Yield(); } } catch (Exception ex) { Logger.LogError("Error sorting " + inventorySlot + " " + ex); RemoveBehavior(); } return(false); }
private static void StartTestHandler(object sender, RoutedEventArgs routedEventArgs) { try { var unitAtts = new Dictionary <int, HashSet <ActorAttributeType> >(); var unitLastDamage = new Dictionary <int, float>(); if (!ZetaDia.IsInGame) { return; } Worker.Start(() => { using (new MemoryHelper()) { Func <DiaUnit, bool> isValid = u => u != null && u.IsValid && u.CommonData != null && u.CommonData.IsValid && !u.CommonData.IsDisposed; var testunits = ZetaDia.Actors.GetActorsOfType <DiaUnit>().Where(u => isValid(u) && u.RActorGuid != ZetaDia.Me.RActorGuid).ToList(); if (!testunits.Any()) { return(false); } var testunit = testunits.OrderBy(u => u.Distance).FirstOrDefault(); if (testunit == null || testunit.CommonData == null) { testunit = ZetaDia.Me; } //PowerBuff0VisualEffectNone (1) Power=MonsterAffix_ReflectsDamage //if(PowerBuff3VisualEffectNone (1) Power=MonsterAffix_ReflectsDamageCast) if (testunit.CommonData.GetAttribute <int>(((int)SNOPower.MonsterAffix_ReflectsDamageCast << 12) + ((int)ActorAttributeType.PowerBuff3VisualEffectNone & 0xFFF)) == 1) { Logger.Log("Unit {0} has has reflect buff", testunit.Name); } //var attrs = new HashSet<ActorAttributeType> //{ // ActorAttributeType.CustomTargetWeight, // ActorAttributeType.Hunter, // ActorAttributeType.PlatinumCapLastGain, //}; //foreach (var att in attrs) //{ // Logger.Log("Unit {0} attr {1} ival={2} fval={3}", testunit.Name, att, testunit.CommonData.GetAttribute<int>(att), testunit.CommonData.GetAttribute<float>(att)); //} var existingAtts = unitAtts.GetOrCreateValue(testunit.ACDGuid, new HashSet <ActorAttributeType>()); var atts = Enum.GetValues(typeof(ActorAttributeType)).Cast <ActorAttributeType>().ToList(); foreach (var att in atts) { //if (!att.ToString().ToLower().Contains("buff")) // continue; try { var attiResult = testunit.CommonData.GetAttribute <int>(att); var attfResult = testunit.CommonData.GetAttribute <float>(att); var hasValue = attiResult > 0 || !float.IsNaN(attfResult) && attfResult > 0; if (hasValue) { if (!existingAtts.Contains(att)) { Logger.Log("Unit {0} has gained {1} (i:{2} f:{3:00.00000})", testunit.Name, att.ToString(), attiResult, attfResult); existingAtts.Add(att); //if (att == ActorAttributeType.LastDamageACD) //{ // //var idmg = testunit.CommonData.GetAttribute<int>((attiResult << 12) + ((int) ActorAttributeType.LastDamageAmount & 0xFFF)); // //var fdmg = testunit.CommonData.GetAttribute<float>((attiResult << 12) + ((int) ActorAttributeType.LastDamageAmount & 0xFFF)); // //Logger.Log("DamageByUnit To LastACD {0} has gained {1} (i:{2} f:{3:00.00000})", testunit.Name, "LastDamageAmount", idmg, fdmg); // var idmg = ZetaDia.Me.CommonData.GetAttribute<int>((attiResult << 12) + ((int)ActorAttributeType.LastDamageAmount & 0xFFF)); // var fdmg = ZetaDia.Me.CommonData.GetAttribute<float>((attiResult << 12) + ((int)ActorAttributeType.LastDamageAmount & 0xFFF)); // Logger.Log("DamageToPlayer By Unit {0} has gained {1} (i:{2} f:{3:00.00000})", testunit.Name, "LastDamageAmount", idmg, fdmg); //} //foreach (var type in atts) //{ // //if (!att.ToString().ToLower().Contains("buff")) // // continue; // try // { // var ari = ZetaDia.Me.CommonData.GetAttribute<int>((testunit.ACDGuid << 12) + ((int)type & 0xFFF)); // var arf = ZetaDia.Me.CommonData.GetAttribute<float>((testunit.ACDGuid << 12) + ((int)type & 0xFFF)); // var hv = ari > 0 || !float.IsNaN(arf) && arf > 0; // if (hv) // { // Logger.Log("PlayerOffset {0} has gained {1} (i:{2} f:{3:00.00000})", testunit.Name, type.ToString(), ari, arf); // } // } // catch (Exception ex) // { // } //} } } else { if (existingAtts.Contains(att)) { Logger.Log("Unit {0} has lost {1} (i:{2} f:{3:00.00000})", testunit.Name, att.ToString(), attiResult, attfResult); existingAtts.Remove(att); } } } catch (Exception) { } } //if (testunit.CommonData.GetAttribute<int>(((int) SNOPower.MonsterAffix_ReflectsDamage << 12) + ((int) ActorAttributeType.PowerBuff0VisualEffectNone & 0xFFF)) == 1) //{ // Logger.Log("Unit {0} has reflect damage", testunit.Name); //} //MonsterAffix_ReflectsDamageCast var allpowers = Enum.GetValues(typeof(SNOPower)).Cast <SNOPower>().ToList(); var allBuffAttributes = Enum.GetValues(typeof(ActorAttributeType)).Cast <ActorAttributeType>().Where(a => a.ToString().StartsWith("PowerBuff")).ToList(); var checkpowers = new HashSet <SNOPower> { SNOPower.MonsterAffix_ReflectsDamage, SNOPower.MonsterAffix_ReflectsDamageCast, SNOPower.Monk_ExplodingPalm }; foreach (var power in allpowers) { foreach (var buffattr in allBuffAttributes) { try { if (testunit.CommonData.GetAttribute <int>(((int)power << 12) + ((int)buffattr & 0xFFF)) == 1) { Logger.Log("Unit {0} has {1} ({2})", testunit.Name, power, buffattr); } } catch (Exception) { } } //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff0VisualEffect & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff0VisualEffectNone & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff0VisualEffectA & 0xFFF)) == 1) // result = true; //// Exploding Palm //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff0VisualEffectB & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff0VisualEffectC & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff0VisualEffectD & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff0VisualEffectE & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff1VisualEffect & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff1VisualEffectNone & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff1VisualEffectA & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff1VisualEffectB & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff11VisualEffectC & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff1VisualEffectD & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff1VisualEffectE & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff2VisualEffect & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff2VisualEffectNone & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff2VisualEffectA & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff2VisualEffectB & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff2VisualEffectC & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff2VisualEffectD & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff2VisualEffectE & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff3VisualEffect & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff3VisualEffectNone & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff3VisualEffectA & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff3VisualEffectB & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff3VisualEffectC & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff3VisualEffectD & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff3VisualEffectE & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff4VisualEffect & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff4VisualEffectNone & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff4VisualEffectA & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff4VisualEffectB & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff4VisualEffectC & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff4VisualEffectD & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff4VisualEffectE & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff5VisualEffect & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff5VisualEffectNone & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff5VisualEffectA & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff5VisualEffectB & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff5VisualEffectC & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff5VisualEffectD & 0xFFF)) == 1) // result = true; //if (testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) ActorAttributeType.PowerBuff5VisualEffectE & 0xFFF)) == 1) // result = true; } //} //var atts = Enum.GetValues(typeof(ActorAttributeType)).Cast<ActorAttributeType>().ToList(); //var powers = Enum.GetValues(typeof(SNOPower)).Cast<SNOPower>().ToList(); //foreach (var att in atts) //{ // //if (!att.ToString().ToLower().Contains("buff")) // // continue; // try // { // var attResult = testunit.CommonData.GetAttribute<int>(att); // if (attResult > 0) // { // if (existingAtts.Contains(att)) // { // Logger.Log("Unit {0} has lost {1} ({2})", testunit.Name, att.ToString(), attResult); // existingAtts.Remove(att); // } // } // else // { // if (!existingAtts.Contains(att)) // { // Logger.Log("Unit {0} has gained {1} ({2})", testunit.Name, att.ToString(), attResult); // existingAtts.Add(att); // } // } // foreach (var power in powers) // { // try // { // var attPowerResult = testunit.CommonData.GetAttribute<int>(((int) power << 12) + ((int) att & 0xFFF)); // if (attPowerResult > 0) // { // if (existingAtts.Contains(att)) // { // Logger.Log("Unit {0} has lost {1} ({2}) Power={3}", testunit.Name, att.ToString(), attPowerResult, power); // existingAtts.Remove(att); // } // } // else // { // if (!existingAtts.Contains(att)) // { // Logger.Log("Unit {0} has gained {1} ({2}) Power={3}", testunit.Name, att.ToString(), attPowerResult, power); // existingAtts.Add(att); // } // } // } // catch (Exception) // { // } // } //foreach (var power in powers) //{ // var attIntPowerResult = testunit.CommonData.GetAttribute<int>(((int)power << 12) + ((int)att & 0xFFF)); //} //var attIntResult = testunit.CommonData.GetAttribute<int>(((int) debuffSNO << 12) + ((int) att & 0xFFF)); //if(attIntResult > 0) // Logger.Log("Unit {0} has {1}", testunit.Name, att.ToString()); // } // catch (Exception) // { // } //} } return(false); }); //CacheManager.Start(); } catch (Exception ex) { Logger.LogError("Error Starting LazyCache: " + ex); } }
internal static async Task <bool> SortTask(InventorySlot inventorySlot) { IsSorting = true; if (!ZetaDia.IsInGame) { return(false); } if (ZetaDia.IsLoadingWorld) { return(false); } if (!ZetaDia.Me.IsFullyValid()) { return(false); } if (ZetaDia.Me.IsParticipatingInTieredLootRun) { Logger.LogNormal("Cannot sort while in trial/greater rift"); RemoveBehavior(); return(false); } if (inventorySlot == InventorySlot.SharedStash && !await TrinityCoroutines.Common.ReturnToStashTask()) { return(true); } Logger.Log("Starting sort task for {0}", inventorySlot); List <ItemWrapper> wrappedItems; // Setup grid if (inventorySlot == InventorySlot.BackpackItems) { wrappedItems = ZetaDia.Me.Inventory.Backpack.Where(i => i.IsValid).Select(i => new ItemWrapper(i)).ToList(); _usedGrid = new bool[10, 6]; // Block off the entire of any "protected bag slots" foreach (InventorySquare square in CharacterSettings.Instance.ProtectedBagSlots) { _usedGrid[square.Column, square.Row] = true; Logger.LogDebug("Slot {0},{1} is protected", square.Column, square.Row); } } else if (inventorySlot == InventorySlot.SharedStash) { wrappedItems = ZetaDia.Me.Inventory.StashItems.Where(i => i.IsValid).Select(i => new ItemWrapper(i)).ToList(); int maxStashRow = ZetaDia.Me.Inventory.NumSharedStashSlots / 7; // 7 columns, 10 rows x 5 pages _usedGrid = new bool[7, maxStashRow]; } else { Logger.LogError("Unsupported Inventory Slot {0}", inventorySlot); return(false); } var equipment = wrappedItems.Where(i => i.IsEquipment).OrderByDescending(i => i); _sortedItemsQueue = new Queue <ItemWrapper>(equipment); Logger.LogDebug("Queued {0} items for forward sort", _sortedItemsQueue.Count()); foreach (var item in equipment) { Logger.LogDebug("{0}", item.Name); } var misc = wrappedItems.Where(i => !i.IsEquipment).OrderByDescending(i => i); _reverseSortedItemsQueue = new Queue <ItemWrapper>(misc); Logger.LogDebug("Queued {0} items for reverse sort", _reverseSortedItemsQueue.Count()); foreach (var item in misc) { Logger.LogDebug("{0}", item.Name); } if (!_reverseSortedItemsQueue.Any() && !_sortedItemsQueue.Any()) { _reverseSortedItemsQueue = null; _sortedItemsQueue = null; Logger.Log("No items found to sort?"); RemoveBehavior(); return(false); } if (!UIElements.InventoryWindow.IsVisible && inventorySlot == InventorySlot.BackpackItems) { Logger.Log("Opening inventory window"); var inventoryButton = UIElement.FromName("Root.NormalLayer.game_dialog_backgroundScreenPC.button_inventory"); if (inventoryButton != null && inventoryButton.IsEnabled && inventoryButton.IsVisible) { inventoryButton.Click(); await Coroutine.Sleep(50); await Coroutine.Yield(); } else { Logger.LogError("Derp - couldn't find inventory Button!"); } } Logger.Log("Executing sort task"); if (GameUI.IsElementVisible(GameUI.StashDialogMainPage) && inventorySlot == InventorySlot.SharedStash) { await SortItems(inventorySlot); await ReverseItems(inventorySlot); Logger.Log("Waiting 5 seconds..."); BotMain.StatusText = "Waiting 5 seconds..."; await Coroutine.Sleep(5000); if (TrinityCoroutines.Common.StartedOutOfTown && ZetaDia.IsInTown) { await CommonBehaviors.TakeTownPortalBack().ExecuteCoroutine(); } } else if (inventorySlot == InventorySlot.BackpackItems) { await SortItems(inventorySlot); await ReverseItems(inventorySlot); } RemoveBehavior(); return(true); }
public static async Task <bool> CleanTask() { try { if (!ZetaDia.IsInGame) { return(false); } if (ZetaDia.IsLoadingWorld) { return(false); } if (!ZetaDia.Me.IsFullyValid()) { return(false); } if (ZetaDia.Me.IsParticipatingInTieredLootRun) { Logger.LogNormal("Cannot clean stash while in trial/greater rift"); RemoveBehavior("Cannot clean stash while in trial/greater rift"); return(false); } if (TrinityItemManager.FindValidBackpackLocation(true) == new Vector2(-1, -1)) { Trinity.ForceVendorRunASAP = true; return(false); } if (!await TrinityCoroutines.Common.ReturnToStashTask()) { _isFinished = true; return(false); } if (GameUI.IsElementVisible(GameUI.StashDialogMainPage)) { Logger.Log("Cleaning stash..."); foreach (var item in ZetaDia.Me.Inventory.StashItems.Where(i => i.ACDGuid != 0 && i.IsValid).ToList()) { CachedACDItem cItem = CachedACDItem.GetCachedItem(item); // Don't take potions from the stash if (cItem.TrinityItemType == TrinityItemType.HealthPotion) { continue; } try { if (!ItemManager.Current.ShouldStashItem(item)) { Logger.Log("Removing {0} from stash", item.Name); ZetaDia.Me.Inventory.QuickWithdraw(item); await Coroutine.Sleep(ItemMovementDelay); await Coroutine.Yield(); if (TrinityItemManager.FindValidBackpackLocation(true) == new Vector2(-1, -1)) { Trinity.ForceVendorRunASAP = true; return(false); } } } catch (Exception ex) { Logger.LogError(ex.ToString()); } } _isFinished = true; Trinity.ForceVendorRunASAP = true; Logger.Log("Waiting 5 seconds..."); BotMain.StatusText = "Waiting 5 seconds..."; await Coroutine.Sleep(5000); if (TrinityCoroutines.Common.StartedOutOfTown && ZetaDia.IsInTown) { await CommonBehaviors.TakeTownPortalBack().ExecuteCoroutine(); } } if (_isFinished) { RemoveBehavior("finished!"); } return(true); } catch (Exception ex) { _isFinished = true; Logger.LogError(ex.ToString()); return(false); } }