public static async Task <CoroutineResult> RunCombat() { if (!ZetaDia.IsInGame || ZetaDia.Globals.IsLoadingWorld || ZetaDia.Globals.IsPlayingCutscene || !ZetaDia.Me.IsFullyValid() || ZetaDia.Me.IsDead) { return(CoroutineResult.NoAction); } if (ZetaDia.IsInTown && BrainBehavior.IsVendoring) { return(CoroutineResult.NoAction); } if (Core.Scenes.CurrentWorldSceneIds.Count == 0) { return(CoroutineResult.NoAction); } await UsePotion.DrinkPotion(); // TODO: Why is OpenTreasureBags called during combat? Move to Townrun. await OpenTreasureBags.Execute(); if (!await VacuumItems.Execute()) { return(CoroutineResult.Running); } var target = Weighting.WeightActors(Core.Targets); if (await CastBuffs()) { return(CoroutineResult.Running); } if (await Routines.Current.HandleBeforeCombat()) { return(CoroutineResult.Running); } // When combat is disabled, we're still allowing trinity to handle non-unit targets. if (!IsCombatAllowed && IsUnitOrInvalid(target)) { return(CoroutineResult.NoAction); } // Sometimes it is standing still and stuck - need to handle that before we are entering // the target one. if (Navigator.StuckHandler.IsStuck) { await Navigator.StuckHandler.DoUnstick(); return(CoroutineResult.Running); } if (await Targeting.HandleTarget(target)) { return(CoroutineResult.Running); } // We're not in combat at this point. if (await Routines.Current.HandleOutsideCombat()) { return(CoroutineResult.Running); } if (!ZetaDia.Me.IsCasting && (!TargetUtil.AnyMobsInRange(20f) || !Core.Player.IsTakingDamage)) { await AutoEquipSkills.Instance.Execute(); await AutoEquipItems.Instance.Execute(); return(CoroutineResult.NoAction); } // Allow Profile to Run. return(CoroutineResult.NoAction); }
/// <summary> /// Combat Hook entry-point, manages when lower-level hooks can run and executes trinity features. /// </summary> public static async Task <bool> MainCombatTask() { if (!ZetaDia.IsInGame || ZetaDia.Globals.IsLoadingWorld || !ZetaDia.Me.IsValid) { return(false); } if (Core.IsOutOfGame || Core.Player.IsDead) { return(false); } if (!Core.Scenes.CurrentWorldScenes.Any()) { return(false); } // Allow a 'false' return in routine (to continue with profile) and skip default behavior. var startHookResult = await Routines.Current.HandleStart(); if (Routines.Current.ShouldReturnStartResult) { return(startHookResult); } await UsePotion.Execute(); await OpenTreasureBags.Execute(); await VacuumItems.Execute(); var target = Weighting.WeightActors(Core.Targets); if (await CastBuffs()) { return(true); } if (await Routines.Current.HandleBeforeCombat()) { return(true); } // When combat is disabled, we're still allowing trinity to handle non-unit targets. if (!IsCombatAllowed && IsUnitOrInvalid(target)) { return(false); } if (await Targeting.HandleTarget(target)) { return(true); } // We're not in combat at this point. if (await Routines.Current.HandleOutsideCombat()) { return(true); } if (!Core.Player.IsCasting && (!TargetUtil.AnyMobsInRange(20f) || !Core.Player.IsTakingDamage)) { await EmergencyRepair.Execute(); await AutoEquipSkills.Instance.Execute(); await AutoEquipItems.Instance.Execute(); return(false); } // Allow Profile to Run. return(false); }