public Recipe(ItemInfo[] input, ItemInfo[] output, Scp914Knob setting, int weight = 1) { Input = input; Output = output; Setting = setting; Weight = weight; }
/// <summary> /// Initializes a new instance of the <see cref="UpgradingItemsEventArgs"/> class. /// </summary> /// <param name="scp914"><inheritdoc cref="Scp914"/></param> /// <param name="players"><inheritdoc cref="Players"/></param> /// <param name="items"><inheritdoc cref="Items"/></param> /// <param name="knobSetting"><inheritdoc cref="KnobSetting"/></param> /// <param name="isAllowed"><inheritdoc cref="IsAllowed"/></param> public UpgradingItemsEventArgs(Scp914Machine scp914, List <Player> players, List <Pickup> items, Scp914Knob knobSetting, bool isAllowed = true) { Scp914 = scp914; Players = players; Items = items; KnobSetting = knobSetting; IsAllowed = isAllowed; }
public static bool Prefix(PlayerInteract __instance) { if (EventPlugin.Scp914KnobChangeEventPatchDisable) { return(true); } try { if (!__instance._playerInteractRateLimit.CanExecute(true) || __instance._hc.CufferId > 0 && !__instance.CanDisarmedInteract || (Scp914Machine.singleton.working || !__instance.ChckDis(Scp914Machine.singleton.knob.position))) { return(false); } Scp914Knob knobSetting = Scp914Machine.singleton.knobState; if (knobSetting + 1 > Scp914Machine.knobStateMax) { knobSetting = Scp914Machine.knobStateMin; } else { knobSetting += 1; } bool allow = true; Events.InvokeScp914KnobChange(__instance.gameObject, ref allow, ref knobSetting); if (allow) { Scp914Machine.singleton.ChangeKnobStatus(); __instance.OnInteract(); } return(false); } catch (Exception exception) { Log.Error($"Scp914KnobChangeEvent error: {exception}"); return(true); } }
public static void InvokeScp914KnobChange(GameObject player, ref bool allow, ref Scp914Knob knobSetting) { if (Scp914KnobChangeEvent == null) { return; } Scp914KnobChangeEvent ev = new Scp914KnobChangeEvent { Player = player.GetPlayer(), Allow = allow, KnobSetting = knobSetting }; Scp914KnobChangeEvent.InvokeSafely(ev); allow = ev.Allow; knobSetting = ev.KnobSetting; }
public static void InvokeScp914KnobChange(GameObject player, ref bool allow, ref Scp914Knob knobSetting) { Scp914KnobChange scp914KnobChange = Scp914KnobChangeEvent; if (scp914KnobChange == null) { return; } ReferenceHub hub = Player.GetPlayer(player); Scp914KnobChangeEvent ev = new Scp914KnobChangeEvent { Player = hub, Allow = allow, KnobSetting = knobSetting }; scp914KnobChange.Invoke(ref ev); allow = ev.Allow; knobSetting = ev.KnobSetting; }
public static bool Prefix(Scp914Machine __instance) { if (!PluginConfig.Cfg.Enabled) { return(true); } if (!PluginConfig.Cfg.CanChangeKnobWhileWorking && __instance.working || Math.Abs(__instance.curKnobCooldown) > 0.001f) { return(false); } //if (Plugin.KnobBlockade) return false; __instance.curKnobCooldown = __instance.knobCooldown; Scp914Knob knob = __instance.knobState + 1; if (knob > Scp914Machine.knobStateMax) { knob = Scp914Machine.knobStateMin; } __instance.NetworkknobState = knob; return(false); }
/// <summary> /// Initializes a new instance of the <see cref="ChangingKnobSettingEventArgs"/> class. /// </summary> /// <param name="player"><inheritdoc cref="Player"/></param> /// <param name="knobSetting"><inheritdoc cref="KnobSetting"/></param> /// <param name="isAllowed"><inheritdoc cref="IsAllowed"/></param> public ChangingKnobSettingEventArgs(Player player, Scp914Knob knobSetting, bool isAllowed = true) { Player = player; KnobSetting = knobSetting; IsAllowed = isAllowed; }
internal void Parse914Settings() { foreach (KeyValuePair <string, List <string> > setting in Scp914ItemChanges) { try { Scp914Knob knob = (Scp914Knob)Enum.Parse(typeof(Scp914Knob), setting.Key); foreach (string chances in setting.Value) { if (string.IsNullOrEmpty(chances)) { continue; } string[] split = chances.Split(':'); if (split.Length < 3) { Log.Error($"Unable to parse SCP-914 class chance: {chances}. Invalid number of splits."); continue; } ItemType originalRole; ItemType newRole; try { originalRole = (ItemType)Enum.Parse(typeof(ItemType), split[0]); } catch (Exception) { Log.Warn($"Unable to parse role: {split[0]} for {chances}."); continue; } try { newRole = (ItemType)Enum.Parse(typeof(ItemType), split[1]); } catch (Exception) { Log.Warn($"Unable to parse role: {split[1]} for {chances}."); continue; } if (!int.TryParse(split[2], out int chance)) { Log.Warn($"Unable to parse chance {split[2]} for {chance}. Invalid integer."); continue; } if (!Scp914Configs.ContainsKey(knob)) { Scp914Configs.Add(knob, new List <Tuple <ItemType, ItemType, int> >()); } Scp914Configs[knob].Add(new Tuple <ItemType, ItemType, int>(originalRole, newRole, chance)); } } catch (Exception) { Log.Warn($"Unable to parse {setting.Key} as a SCP-914 knob setting."); } } }
public static void MyAdd(this List <Recipe> list, ItemType input, ItemType output, Scp914Knob setting) { Recipe recipe; if ((recipe = list.FirstOrDefault(r => r.Setting == setting && r.Input.Contains(input.GetItemInfo()) && r.Output.Contains(output.GetItemInfo()))) != null) { recipe.Weight++; } else { list.Add(new Recipe(input.GetItemInfo(), output.GetItemInfo(), setting)); counter++; } }
public static ItemType GetItem(Scp914Knob knobStateRaw, ItemType item) { var recipe = Plugin.Recipes.Where(e => e.item == item).FirstOrDefault(); if (recipe == null || recipe == default) { recipe = Plugin.CreateDefaultRecipe(item); } int knobState = (int)knobStateRaw - 2; var upgradeLevel = knobState; if (knobState == -1) { if (CheckPercent(PluginConfig.Cfg.Level_2Chance)) { upgradeLevel = -2; } } else if (knobState == -2) { if (CheckPercent(PluginConfig.Cfg.Level_3Chance)) { upgradeLevel = -3; } if (CheckPercent(PluginConfig.Cfg.Level_4Chance)) { upgradeLevel = -4; } } else if (knobState == 1) { if (CheckPercent(PluginConfig.Cfg.Level2Chance)) { upgradeLevel = 2; } } else if (knobState == 2) { if (CheckPercent(PluginConfig.Cfg.Level3Chance)) { upgradeLevel = 3; } if (CheckPercent(PluginConfig.Cfg.Level4Chance)) { upgradeLevel = 4; } } var options = (upgradeLevel == -4) ? recipe.level__4 : (upgradeLevel == -3) ? recipe.level__3 : (upgradeLevel == -2) ? recipe.level__2 : (upgradeLevel == -1) ? recipe.level__1 : (upgradeLevel == 0) ? recipe.level_0 : (upgradeLevel == 1) ? recipe.level_1 : (upgradeLevel == 2) ? recipe.level_2 : (upgradeLevel == 3) ? recipe.level_3 : (upgradeLevel == 4) ? recipe.level_4 : new ItemType[] { }; ItemType selectedItem; if (options.Length > 0) { if (upgradeLevel == 1 || upgradeLevel == 0 || upgradeLevel == -1) { if (CheckPercent(PluginConfig.Cfg.SameItemChance)) { selectedItem = item; } else { selectedItem = options[options.Length > 1 ? Random.Range(0, options.Length - 1) : 0]; } } else { selectedItem = options[options.Length > 1 ? Random.Range(0, options.Length - 1) : 0]; } } else { selectedItem = item; } return(selectedItem); }
internal void Parse914Settings() { foreach (PropertyInfo configSetting in GetType().GetProperties()) { if (!configSetting.Name.Contains("Scp914") || configSetting.Name == nameof(Scp914ClassChanges)) { continue; } string configName = configSetting.Name; List <string> list = (List <string>)configSetting.GetValue(this); Scp914Knob knobSetting = Scp914Knob.Rough; switch (configName) { case nameof(Scp914RoughChances): knobSetting = Scp914Knob.Rough; break; case nameof(Scp914CoarseChances): knobSetting = Scp914Knob.Coarse; break; case nameof(Scp914OnetoOneChances): knobSetting = Scp914Knob.OneToOne; break; case nameof(Scp914FineChances): knobSetting = Scp914Knob.Fine; break; case nameof(Scp914VeryFineChances): knobSetting = Scp914Knob.VeryFine; break; } if (list == null) { Log.Warn($"This list for {configName} is empty. Only base-game recipies will be used for this setting."); if (Scp914Configs.ContainsKey(knobSetting)) { Scp914Configs.Remove(knobSetting); } continue; } foreach (string unparsedRaw in list) { ItemType sourceItem; ItemType destinationItem; string[] rawChances = unparsedRaw.Split(':'); try { sourceItem = (ItemType)Enum.Parse(typeof(ItemType), rawChances[0]); } catch (Exception) { Log.Error($"Unable to parse source item: {rawChances[0]}."); continue; } try { destinationItem = (ItemType)Enum.Parse(typeof(ItemType), rawChances[1]); } catch (Exception) { Log.Error($"Unable to parse destination item: {rawChances[1]}"); continue; } if (!int.TryParse(rawChances[2], out int chance)) { Log.Error($"Unable to parse conversion chance: {rawChances[2]} for {rawChances[0]} -> {rawChances[1]}."); continue; } Log.Debug($"Scp914 recipe added: {rawChances[0]} -> {rawChances[1]}, {rawChances[2]}%.", Debug); if (!Scp914Configs.ContainsKey(knobSetting)) { Scp914Configs.Add(knobSetting, new List <Tuple <ItemType, ItemType, int> >()); } Scp914Configs[knobSetting].Add(new Tuple <ItemType, ItemType, int>(sourceItem, destinationItem, chance)); } } }
/// <summary> /// Sets SCP-914 knob state. /// </summary> /// <returns></returns> public static void SetKnobStatus(Scp914Knob scp914Knob) => Scp914Machine.singleton.knobState = scp914Knob;
/// <summary> /// Initializes a new instance of the <see cref="UpgradingEventArgs"/> class. /// </summary> /// <param name="item"><inheritdoc cref="Item"/></param> /// <param name="scp914"><inheritdoc cref="UpgradingItemsEventArgs.Scp914"/></param> /// <param name="players"><inheritdoc cref="UpgradingItemsEventArgs.Players"/></param> /// <param name="items"><inheritdoc cref="UpgradingItemsEventArgs.Items"/></param> /// <param name="knobSetting"><inheritdoc cref="UpgradingItemsEventArgs.KnobSetting"/></param> /// <param name="isAllowed"><inheritdoc cref="UpgradingItemsEventArgs.IsAllowed"/></param> public UpgradingEventArgs(Inventory.SyncItemInfo item, Scp914Machine scp914, List <Player> players, List <Pickup> items, Scp914Knob knobSetting, bool isAllowed = true) : base(scp914, players, items, knobSetting, isAllowed) { Item = item; }
public Recipe(ItemInfo input, ItemInfo output, Scp914Knob setting, int weight = 1) : this(new ItemInfo[] { input }, new ItemInfo[] { output }, setting, weight) { }