//Parameters: // type1 and type2 define the type of flask you wanna drink. // reason: is just for debugging output to see where does the drinking flask request came from // minRequiredCharges: Min number of charges a flask must have to consider it a valid flask to drink. // shouldDrinkAll: if you want to drink all the flasks of type1,type2 (true) or just first in the list(false). private bool FindDrinkFlask(FlaskActions type1, FlaskActions type2, string reason, int minRequiredCharge = 0, bool shouldDrinkAll = false) { var hasDrunk = false; var flaskList = _playerFlaskList.FindAll(x => (x.FlaskAction1 == type1 || x.FlaskAction2 == type2 || x.FlaskAction1 == type2 || x.FlaskAction2 == type1) && x.IsEnabled && x.IsValid); flaskList.Sort((x, y) => x.TotalTimeUsed.CompareTo(y.TotalTimeUsed)); foreach (var flask in flaskList) { UpdateFlaskChargesInfo(flask.Slot); if (flask.CurrentCharges < flask.UseCharges || flask.CurrentCharges < minRequiredCharge) { continue; } _keyboard.SetLatency(GameController.Game.IngameState.CurLatency); if (!_keyboard.KeyPressRelease(_keyInfo.K[flask.Slot])) { LogError("Warning: High latency ( more than 1000 millisecond ), plugin will fail to work properly.", ErrmsgTime); } if (Settings.DebugMode.Value) { LogMessage("Just Drank Flask on key " + _keyInfo.K[flask.Slot] + " cuz of " + reason, LogmsgTime); } flask.TotalTimeUsed = (flask.IsInstant) ? 100000 : flask.TotalTimeUsed + 1; // if there are multiple flasks, drinking 1 of them at a time is enough. hasDrunk = true; if (!shouldDrinkAll) { return(true); } } return(hasDrunk); }
private PlayerFlask FindFlaskMatchingAnyAction(FlaskActions flaskAction, Boolean?instant = null, Boolean ignoreBuffs = false, Func <List <FlaskActions> > ignoreFlasksWithAction = null, Boolean isCleansing = false) { return(FindFlaskMatchingAnyAction(new List <FlaskActions> { flaskAction }, instant, ignoreBuffs, ignoreFlasksWithAction, isCleansing)); }
private Composite CreateUseFlaskAction(FlaskActions flaskAction, Boolean?instant = null, Boolean ignoreBuffs = false, Func <List <FlaskActions> > ignoreFlasksWithAction = null, Boolean isCleansing = false) { return(CreateUseFlaskAction(new List <FlaskActions> { flaskAction }, instant, ignoreBuffs, ignoreFlasksWithAction, isCleansing)); }
private bool GettingAllFlaskInfo() { try { for (var j = 0; j < 5; j++) { //InventoryItemIcon flask = flasksEquipped[j].AsObject<InventoryItemIcon>(); var flaskItem = GameController.Game.IngameState.IngameUi.InventoryPanel[InventoryIndex.Flask][j, 0, 0]; if (flaskItem == null || flaskItem.Address == 0) { _playerFlaskList[j].IsValid = false; continue; } var flaskCharges = flaskItem.GetComponent <Charges>(); var flaskMods = flaskItem.GetComponent <Mods>(); _playerFlaskList[j].IsInstant = false; float tmpUseCharges = flaskCharges.ChargesPerUse; _playerFlaskList[j].CurrentCharges = flaskCharges.NumCharges; _playerFlaskList[j].FlaskRarity = flaskMods.ItemRarity; _playerFlaskList[j].FlaskName = GameController.Files.BaseItemTypes.Translate(flaskItem.Path).BaseName; _playerFlaskList[j].FlaskAction2 = FlaskActions.None; _playerFlaskList[j].FlaskAction1 = FlaskActions.None; //Checking flask action based on flask name type. if (!_flaskInfo.FlaskTypes.TryGetValue(_playerFlaskList[j].FlaskName, out _playerFlaskList[j].FlaskAction1)) { LogError("Error: " + _playerFlaskList[j].FlaskName + " name not found. Report this error message.", ErrmsgTime); } if (Settings.ChargeReduction.Value > 0) { tmpUseCharges = ((100 - Settings.ChargeReduction.Value) / 100) * tmpUseCharges; } //Checking flask mods. FlaskActions action2 = FlaskActions.Ignore; foreach (var mod in flaskMods.ItemMods) { if (mod.Name.ToLower().Contains("flaskchargesused")) { tmpUseCharges = ((100 + (float)mod.Value1) / 100) * tmpUseCharges; } if (mod.Name.ToLower().Contains("instant")) { _playerFlaskList[j].IsInstant = true; } // We have already decided action2 for unique flasks. if (flaskMods.ItemRarity == ItemRarity.Unique) { continue; } if (!_flaskInfo.FlaskMods.TryGetValue(mod.Name, out action2)) { LogError("Error: " + mod.Name + " mod not found. Is it unique flask? If not, report this error message.", ErrmsgTime); } else if (action2 != FlaskActions.Ignore) { _playerFlaskList[j].FlaskAction2 = action2; } } // Speedrun mod on mana/life flask wouldn't work when full mana/life is full respectively, // So we will ignore speedrun mod from mana/life flask. Other mods // on mana/life flasks will work. if (_playerFlaskList[j].FlaskAction2 == FlaskActions.Speedrun && (_playerFlaskList[j].FlaskAction1 == FlaskActions.Life || _playerFlaskList[j].FlaskAction1 == FlaskActions.Mana || _playerFlaskList[j].FlaskAction1 == FlaskActions.Hybrid)) { _playerFlaskList[j].FlaskAction2 = FlaskActions.None; if (_warnFlaskSpeed) { LogError("Warning: Speed Run mod is ignored on mana/life/hybrid flasks. Use Alt Orbs on those flasks.", ErrmsgTime); _warnFlaskSpeed = false; } } if (Settings.DisableLifeSecUse.Value) { if (_playerFlaskList[j].FlaskAction1 == FlaskActions.Life || _playerFlaskList[j].FlaskAction1 == FlaskActions.Hybrid) { if (_playerFlaskList[j].FlaskAction2 == FlaskActions.Offense || _playerFlaskList[j].FlaskAction2 == FlaskActions.Defense) { _playerFlaskList[j].FlaskAction2 = FlaskActions.None; } } } _playerFlaskList[j].UseCharges = (int)Math.Floor(tmpUseCharges); _playerFlaskList[j].IsValid = true; } } catch (Exception e) { if (Settings.DebugMode.Value) { LogError("Warning: Error getting all flask Informations.", ErrmsgTime); LogError(e.Message + e.StackTrace, ErrmsgTime); } _playerFlaskList.Clear(); for (var i = 0; i < 5; i++) { _playerFlaskList.Add(new PlayerFlask(i)); } return(false); } return(true); }
private void handleFlaskMods(PlayerFlask flask) { FlaskActions flaskActionOut; if (Core.Cache.FlaskInfo == null) { Core.LogErr(Core.PluginName + ": Error: Flask Info cache was never initialized. This method will not function properly.", Core.ErrmsgTime); return; } //Checking flask action based on flask name type. if (!Core.Cache.FlaskInfo.FlaskTypes.TryGetValue(flask.Name, out flaskActionOut)) { Core.LogErr(Core.PluginName + ": Error: " + flask.Name + " name not found. Add to config/flaskinfo.json and report this error message.", Core.ErrmsgTime); } else { flask.Action1 = flaskActionOut; } //Checking for unique flasks. if (flask.Mods.ItemRarity == ItemRarity.Unique) { flask.Name = flask.Mods.UniqueName; //Enabling Unique flask action 2. if (!Core.Cache.FlaskInfo.UniqueFlaskNames.TryGetValue(flask.Name, out flaskActionOut)) { Core.LogErr(Core.PluginName + ": Error: " + flask.Name + " unique name not found. Add to config/flaskinfo.json and report this error message.", Core.ErrmsgTime); } else { flask.Action2 = flaskActionOut; } } //Checking flask mods. FlaskActions action2 = FlaskActions.Ignore; foreach (var mod in flask.Mods.ItemMods) { if (mod.Name.ToLower().Contains("instant")) { if (mod.Name.Contains("FlaskPartialInstantRecovery")) { flask.InstantType = FlaskInstantType.Partial; } else if (mod.Name.Contains("FlaskInstantRecoveryOnLowLife")) { flask.InstantType = FlaskInstantType.LowLife; } else if (mod.Name.Contains("FlaskFullInstantRecovery")) { flask.InstantType = FlaskInstantType.Full; } } // We have already decided action2 for unique flasks. if (flask.Mods.ItemRarity == ItemRarity.Unique) { continue; } if (!Core.Cache.FlaskInfo.FlaskMods.TryGetValue(mod.Name, out action2)) { Core.LogErr(Core.PluginName + ": Error: " + mod.Name + " mod not found. Is it unique flask? If not, report this error message.", Core.ErrmsgTime); } else if (action2 != FlaskActions.Ignore) { flask.Action2 = action2; } } }
private PlayerFlask findFlaskMatchingAnyAction(FlaskActions flaskAction, Boolean?instant = null, Func <List <FlaskActions> > ignoreFlasksWithAction = null) { return(findFlaskMatchingAnyAction(new List <FlaskActions> { flaskAction }, instant, ignoreFlasksWithAction)); }
private Composite createUseFlaskAction(FlaskActions flaskAction, Boolean?instant = null, Func <List <FlaskActions> > ignoreFlasksWithAction = null) { return(createUseFlaskAction(new List <FlaskActions> { flaskAction }, instant, ignoreFlasksWithAction)); }