public bool Add(IEntitySkill value) { if (this.Skills.ContainsKey(value.Name)) { return(false); } this.Skills.Add(value.Name, value); return(true); }
public IEnumerable <IEntityTemplate> Load() { List <IEntityTemplate> entities = new List <IEntityTemplate>(); string[] files = Directory.GetFiles( Directory.GetCurrentDirectory() + GlobalConstants.ASSETS_FOLDER + GlobalConstants.DATA_FOLDER + "Entities", "*.json", SearchOption.AllDirectories); foreach (string file in files) { JSONParseResult result = JSON.Parse(File.ReadAllText(file)); if (result.Error != Error.Ok) { GlobalConstants.ActionLog.Log("Could not load entity templates from " + file, LogLevel.Warning); GlobalConstants.ActionLog.Log(result.ErrorString, LogLevel.Warning); GlobalConstants.ActionLog.Log("On line: " + result.ErrorLine, LogLevel.Warning); continue; } if (!(result.Result is Dictionary dictionary)) { GlobalConstants.ActionLog.Log("Could not parse JSON to Dictionary from " + file, LogLevel.Warning); continue; } Array templateArray = this.ValueExtractor.GetValueFromDictionary <Array>(dictionary, "Entities"); foreach (Dictionary templateDict in templateArray) { string creatureType = this.ValueExtractor.GetValueFromDictionary <string>(templateDict, "CreatureType"); string type = this.ValueExtractor.GetValueFromDictionary <string>(templateDict, "Type"); string visionType = this.ValueExtractor.GetValueFromDictionary <string>(templateDict, "VisionType") ?? "diurnal vision"; IVision vision = this.VisionProviderHandler.Get(visionType); string description = this.ValueExtractor.GetValueFromDictionary <string>(templateDict, "Description"); IDictionary <string, IEntityStatistic> statistics = new System.Collections.Generic.Dictionary <string, IEntityStatistic>(); ICollection <Dictionary> statisticsCollection = this.ValueExtractor.GetCollectionFromArray <Dictionary>( this.ValueExtractor.GetValueFromDictionary <Array>(templateDict, "Statistics")); foreach (Dictionary innerDict in statisticsCollection) { string statName = this.ValueExtractor.GetValueFromDictionary <string>(innerDict, "Name"); int statValue = this.ValueExtractor.GetValueFromDictionary <int>(innerDict, "Value"); int threshold = innerDict.Contains("Threshold") ? this.ValueExtractor.GetValueFromDictionary <int>(innerDict, "Threshold") : GlobalConstants.DEFAULT_SUCCESS_THRESHOLD; IEntityStatistic statistic = GlobalConstants.GameManager.StatisticHandler.Get(statName); statistic.SetValue(statValue); statistic.SetThreshold(threshold); statistics.Add( statName, statistic); } IDictionary <string, IEntitySkill> skills = new System.Collections.Generic.Dictionary <string, IEntitySkill>(); if (templateDict.Contains("Skills")) { ICollection <Dictionary> skillCollection = this.ValueExtractor.GetCollectionFromArray <Dictionary>( this.ValueExtractor.GetValueFromDictionary <Array>(templateDict, "Skills")); foreach (Dictionary innerDict in skillCollection) { string skillName = this.ValueExtractor.GetValueFromDictionary <string>(innerDict, "Name"); int skillValue = this.ValueExtractor.GetValueFromDictionary <int>(innerDict, "Value"); int threshold = innerDict.Contains("Threshold") ? this.ValueExtractor.GetValueFromDictionary <int>(innerDict, "Threshold") : GlobalConstants.DEFAULT_SUCCESS_THRESHOLD; IEntitySkill skill = GlobalConstants.GameManager.SkillHandler.Get(skillName); skill.SetValue(skillValue); skill.SetThreshold(threshold); skills.Add( skillName, skill); } } ICollection <string> tags = this.ValueExtractor.GetCollectionFromArray <string>( this.ValueExtractor.GetValueFromDictionary <Array>(templateDict, "Tags")); ICollection <string> slots = this.ValueExtractor.GetCollectionFromArray <string>( this.ValueExtractor.GetValueFromDictionary <Array>(templateDict, "Slots")); ICollection <string> needs = this.ValueExtractor.GetCollectionFromArray <string>( this.ValueExtractor.GetValueFromDictionary <Array>(templateDict, "Needs")); ICollection <IAbility> abilities = new List <IAbility>(); if (templateDict.Contains("Abilities")) { ICollection <string> abilityNames = this.ValueExtractor.GetCollectionFromArray <string>( this.ValueExtractor.GetValueFromDictionary <Array>(templateDict, "Abilities")); foreach (string name in abilityNames) { abilities.Add(this.AbilityHandler.Get(name)); } } int size = this.ValueExtractor.GetValueFromDictionary <int>(templateDict, "Size"); entities.Add( new EntityTemplate( statistics, skills, needs.ToArray(), abilities.ToArray(), slots.ToArray(), size, vision, creatureType, type, description, tags.ToArray())); } } return(entities); }
protected virtual void SetUpUi() { if (this.Player is null) { return; } this.SetExperienceRemaining(); var derivedValues = this.Player.DerivedValues.Values.ToList(); var statistics = this.Player.Statistics.Values.ToList(); var skills = this.Player.Skills.Values.ToList(); var abilities = this.CurrentJob.Abilities.Where(pair => this.Player.Abilities.Contains(pair.Key) == false) .Select(pair => new Tuple <IAbility, int>(pair.Key, pair.Value)) .ToList(); bool addedChildren = false; if (this.DerivedValueList.GetChildCount() < derivedValues.Count) { for (int i = this.DerivedValueList.GetChildCount(); i < derivedValues.Count; i++) { var instance = this.ValueItemPrefab.Instance(); this.DerivedValueList.AddChild(instance); } addedChildren = true; } if (this.StatisticList.GetChildCount() < statistics.Count) { for (int i = this.StatisticList.GetChildCount(); i < statistics.Count; i++) { var instance = this.ValueItemPrefab.Instance(); this.StatisticList.AddChild(instance); } addedChildren = true; } if (this.SkillList.GetChildCount() < skills.Count) { for (int i = this.SkillList.GetChildCount(); i < skills.Count; i++) { var instance = this.ValueItemPrefab.Instance(); this.SkillList.AddChild(instance); } addedChildren = true; } if (this.AbilityList.GetChildCount() < abilities.Count) { for (int i = this.AbilityList.GetChildCount(); i < abilities.Count; i++) { var instance = this.AbilityItemPrefab.Instance() as ConstrainedManagedTextButton; instance.ElementName = "AccentBackground"; instance.RectMinSize = new Vector2(0, 24); instance.ToggleMode = true; this.AbilityList.AddChild(instance); } addedChildren = true; } for (int i = derivedValues.Count; i < this.DerivedValueList.GetChildCount(); i++) { this.DerivedValueList.GetChild <Control>(i).Visible = false; } for (int i = skills.Count; i < this.SkillList.GetChildCount(); i++) { this.SkillList.GetChild <Control>(i).Visible = false; } for (int i = statistics.Count; i < this.StatisticList.GetChildCount(); i++) { this.StatisticList.GetChild <Control>(i).Visible = false; } for (int i = abilities.Count; i < this.AbilityList.GetChildCount(); i++) { this.AbilityList.GetChild <Control>(i).Visible = false; } if (abilities.Count == 0) { if (this.AbilityList.GetChildCount() == 0) { var instance = this.AbilityItemPrefab.Instance() as ConstrainedManagedTextButton; instance.ElementName = "AccentBackground"; instance.RectMinSize = new Vector2(0, 24); this.AbilityList.AddChild(instance); } var item = this.AbilityList.GetChild(0) as ConstrainedManagedTextButton; item.Name = "No Abilities Available"; item.Text = item.Name; } for (int i = 0; i < derivedValues.Count; i++) { var child = this.DerivedValueList.GetChild(i) as IntValueItem; IDerivedValue derivedValue = derivedValues[i]; child.ValueName = derivedValue.Name; child.Value = derivedValue.Maximum; child.Minimum = derivedValue.Maximum; child.Maximum = child.Minimum + 50; child.UseRestriction = true; child.IncreaseCost = 10; child.DecreaseCost = -10; if (child.IsConnected("ValueChanged", this, nameof(this.OnDerivedValueChange))) { child.Disconnect("ValueChanged", this, nameof(this.OnDerivedValueChange)); } child.Connect("ValueChanged", this, nameof(this.OnDerivedValueChange)); } for (int i = 0; i < statistics.Count; i++) { var child = this.StatisticList.GetChild(i) as IntValueItem; IEntityStatistic statistic = statistics[i]; child.ValueName = statistic.Name; child.Value = statistic.Value; child.Minimum = statistic.Value; child.Maximum = 10; child.UseRestriction = true; child.Tooltip = new List <string>(statistic.Tooltip) { "Cost: " + child.IncreaseCost }; if (child.IsConnected("ValueChanged", this, nameof(this.OnStatisticChange))) { child.Disconnect("ValueChanged", this, nameof(this.OnStatisticChange)); } child.Connect("ValueChanged", this, nameof(this.OnStatisticChange)); } for (int i = 0; i < skills.Count; i++) { var child = this.SkillList.GetChild(i) as IntValueItem; IEntitySkill skill = skills[i]; child.ValueName = skill.Name; child.Value = skill.Value; child.Minimum = skill.Value; child.Maximum = 10; child.UseRestriction = true; child.Tooltip = new List <string>(skill.Tooltip) { "Cost: " + child.IncreaseCost }; if (child.IsConnected("ValueChanged", this, nameof(this.OnSkillChange))) { child.Disconnect("ValueChanged", this, nameof(this.OnSkillChange)); } child.Connect("ValueChanged", this, nameof(this.OnSkillChange)); } for (int i = 0; i < abilities.Count; i++) { var child = this.AbilityList.GetChild(i) as ConstrainedManagedTextButton; IAbility ability = abilities[i].Item1; child.Name = ability.Name; child.Text = ability.Name; child.IncreaseCost = abilities[i].Item2; child.DecreaseCost = -abilities[i].Item2; child.UseRestriction = true; child.Visible = true; child.Tooltip = new List <string> { ability.Description, "Cost: " + child.IncreaseCost }; if (child.IsConnected("ValuePress", this, nameof(this.OnAbilityChange))) { child.Disconnect("ValuePress", this, nameof(this.OnAbilityChange)); } child.Connect("ValuePress", this, nameof(this.OnAbilityChange)); } if (addedChildren) { this.GUIManager.SetupManagedComponents(this); } this.SetChildPoints(); this.OpenPageOne(); }
protected virtual void SetUpUi() { if (this.Player is null) { return; } var derivedValues = this.Player.DerivedValues.Values.ToList(); var statistics = this.Player.Statistics.Values.ToList(); var skills = this.Player.Skills.Values.ToList(); var abilities = this.Player.Abilities; var data = this.Player.GetData( new string[] { "gender", "biosex", "sexuality", "romance" }) .ToList(); bool addedChildren = false; if (this.DerivedValueList.GetChildCount() < derivedValues.Count) { for (int i = this.DerivedValueList.GetChildCount(); i < derivedValues.Count; i++) { var instance = this.ValueItemPrefab.Instance() as StaticValueItem; instance.TitleCase = true; this.DerivedValueList.AddChild(instance); } addedChildren = true; } if (this.StatisticList.GetChildCount() < statistics.Count) { for (int i = this.StatisticList.GetChildCount(); i < statistics.Count; i++) { var instance = this.ValueItemPrefab.Instance() as StaticValueItem; instance.TitleCase = true; this.StatisticList.AddChild(instance); } addedChildren = true; } if (this.SkillList.GetChildCount() < skills.Count) { for (int i = this.SkillList.GetChildCount(); i < skills.Count; i++) { var instance = this.ValueItemPrefab.Instance() as StaticValueItem; instance.TitleCase = true; this.SkillList.AddChild(instance); } addedChildren = true; } if (this.AbilityList.GetChildCount() < abilities.Count) { for (int i = this.AbilityList.GetChildCount(); i < abilities.Count; i++) { var instance = this.AbilityItemPrefab.Instance() as ManagedLabel; instance.ElementName = "AccentBackground"; instance.RectMinSize = new Vector2(0, 24); instance.TitleCase = true; this.AbilityList.AddChild(instance); } addedChildren = true; } if (this.MiscStatisticList.GetChildCount() < data.Count) { for (int i = this.MiscStatisticList.GetChildCount(); i < data.Count; i++) { var instance = this.AbilityItemPrefab.Instance() as ManagedLabel; instance.ElementName = "AccentBackground"; instance.RectMinSize = new Vector2(0, 24); instance.TitleCase = true; this.MiscStatisticList.AddChild(instance); } } for (int i = 0; i < derivedValues.Count; i++) { var child = this.DerivedValueList.GetChild(i) as StaticValueItem; IDerivedValue derivedValue = derivedValues[i]; child.ValueName = derivedValue.Name; child.Value = derivedValue.Value + "/" + derivedValue.Maximum; child.Tooltip = derivedValue.Tooltip; } for (int i = 0; i < statistics.Count; i++) { var child = this.StatisticList.GetChild(i) as StaticValueItem; IEntityStatistic statistic = statistics[i]; child.ValueName = statistic.Name; child.Value = statistic.Value.ToString(); child.Tooltip = statistic.Tooltip; } for (int i = 0; i < skills.Count; i++) { var child = this.SkillList.GetChild(i) as StaticValueItem; IEntitySkill skill = skills[i]; child.ValueName = skill.Name; child.Value = skill.Value.ToString(); child.Tooltip = skill.Tooltip; } for (int i = 0; i < abilities.Count; i++) { var child = this.AbilityList.GetChild(i) as ManagedLabel; IAbility ability = abilities[i]; child.Name = ability.Name; child.Text = ability.Name; child.Tooltip = new List <string> { ability.Description }; } for (int i = 0; i < data.Count; i++) { var child = this.MiscStatisticList.GetChild(i) as ManagedLabel; child.Name = data[i].Item1; child.Text = data[i].CombineToString(); } if (addedChildren) { this.GUIManager.SetupManagedComponents(this); } this.OpenPageOne(); }