This commit is contained in:
Evil Factory
2022-04-28 12:36:24 -03:00
91 changed files with 1140 additions and 491 deletions
@@ -838,7 +838,7 @@ namespace Barotrauma
if (container == null) { return 0; }
if (!container.Inventory.CanBePut(containableItem)) { return 0; }
var rootContainer = container.Item.GetRootContainer();
if (rootContainer?.GetComponent<Fabricator>() != null || rootContainer?.GetComponent<Fabricator>() != null) { return 0; }
if (rootContainer?.GetComponent<Fabricator>() != null || rootContainer?.GetComponent<Deconstructor>() != null) { return 0; }
if (container.ShouldBeContained(containableItem, out bool isRestrictionsDefined))
{
if (isRestrictionsDefined)
@@ -57,8 +57,6 @@ namespace Barotrauma
private readonly int speakerIndex;
private readonly ImmutableHashSet<Identifier> allowedSpeakerTags;
private readonly bool requireNextLine;
// used primarily for team1 characters interacting with escorted personnel (TODO: not used anywhere)
private readonly bool requireSight;
public NPCConversation(XElement element)
{
@@ -75,7 +73,6 @@ namespace Barotrauma
Responses = element.Elements().Select(s => new NPCConversation(s)).ToImmutableArray();
requireNextLine = element.GetAttributeBool("requirenextline", false);
requireSight = element.GetAttributeBool("requiresight", false);
}
private static List<Identifier> GetCurrentFlags(Character speaker)
@@ -162,23 +159,38 @@ namespace Barotrauma
return currentFlags;
}
private static List<NPCConversation> previousConversations = new List<NPCConversation>();
private static readonly List<NPCConversation> previousConversations = new List<NPCConversation>();
public static List<Pair<Character, string>> CreateRandom(List<Character> availableSpeakers)
public static List<(Character speaker, string line)> CreateRandom(List<Character> availableSpeakers)
{
Dictionary<int, Character> assignedSpeakers = new Dictionary<int, Character>();
List<Pair<Character, string>> lines = new List<Pair<Character, string>>();
List<(Character speaker, string line)> lines = new List<(Character speaker, string line)>();
var language = GameSettings.CurrentConfig.Language;
if (language != TextManager.DefaultLanguage && !NPCConversationCollection.Collections.ContainsKey(language))
{
DebugConsole.AddWarning($"Could not find NPC conversations for the language \"{language}\". Using \"{TextManager.DefaultLanguage}\" instead..");
language = TextManager.DefaultLanguage;
}
CreateConversation(availableSpeakers, assignedSpeakers, null, lines,
availableConversations: NPCConversationCollection.Collections[GameSettings.CurrentConfig.Language].SelectMany(cc => cc.Conversations).ToList());
availableConversations: NPCConversationCollection.Collections[language].SelectMany(cc => cc.Conversations).ToList());
return lines;
}
public static List<Pair<Character, string>> CreateRandom(List<Character> availableSpeakers, IEnumerable<Identifier> requiredFlags)
public static List<(Character speaker, string line)> CreateRandom(List<Character> availableSpeakers, IEnumerable<Identifier> requiredFlags)
{
Dictionary<int, Character> assignedSpeakers = new Dictionary<int, Character>();
List<Pair<Character, string>> lines = new List<Pair<Character, string>>();
var availableConversations = NPCConversationCollection.Collections[GameSettings.CurrentConfig.Language]
List<(Character speaker, string line)> lines = new List<(Character speaker, string line)>();
var language = GameSettings.CurrentConfig.Language;
if (language != TextManager.DefaultLanguage && !NPCConversationCollection.Collections.ContainsKey(language))
{
DebugConsole.AddWarning($"Could not find NPC conversations for the language \"{language}\". Using \"{TextManager.DefaultLanguage}\" instead..");
language = TextManager.DefaultLanguage;
}
var availableConversations = NPCConversationCollection.Collections[language]
.SelectMany(cc => cc.Conversations.Where(c => requiredFlags.All(f => c.Flags.Contains(f)))).ToList();
if (availableConversations.Count > 0)
{
@@ -191,7 +203,7 @@ namespace Barotrauma
List<Character> availableSpeakers,
Dictionary<int, Character> assignedSpeakers,
NPCConversation baseConversation,
IList<Pair<Character, string>> lineList,
IList<(Character speaker, string line)> lineList,
IList<NPCConversation> availableConversations,
bool ignoreFlags = false)
{
@@ -271,7 +283,7 @@ namespace Barotrauma
previousConversations.Insert(0, selectedConversation);
if (previousConversations.Count > MaxPreviousConversations) previousConversations.RemoveAt(MaxPreviousConversations);
}
lineList.Add(new Pair<Character, string>(speaker, selectedConversation.Line));
lineList.Add((speaker, selectedConversation.Line));
CreateConversation(availableSpeakers, assignedSpeakers, selectedConversation, lineList, availableConversations);
}
@@ -2749,12 +2749,15 @@ namespace Barotrauma
if (!Enabled) { return; }
if (Level.Loaded != null && WorldPosition.Y < Level.MaxEntityDepth ||
(Submarine != null && Submarine.WorldPosition.Y < Level.MaxEntityDepth))
if (Level.Loaded != null)
{
Enabled = false;
Kill(CauseOfDeathType.Pressure, null);
return;
if (WorldPosition.Y < Level.MaxEntityDepth ||
(Submarine != null && Submarine.WorldPosition.Y < Level.MaxEntityDepth))
{
Enabled = false;
Kill(CauseOfDeathType.Pressure, null);
return;
}
}
ApplyStatusEffects(ActionType.Always, deltaTime);
@@ -130,15 +130,15 @@ namespace Barotrauma
head = value;
HeadSprite = null;
AttachmentSprites = null;
IsMale = value.Preset?.TagSet?.Contains("Male".ToIdentifier()) ?? false;
IsFemale = value.Preset?.TagSet?.Contains("Female".ToIdentifier()) ?? false;
}
}
}
public bool IsMale { get; private set; }
private readonly Identifier maleIdentifier = "Male".ToIdentifier();
private readonly Identifier femaleIdentifier = "Female".ToIdentifier();
public bool IsFemale { get; private set; }
public bool IsMale { get { return head?.Preset?.TagSet?.Contains(maleIdentifier) ?? false; } }
public bool IsFemale { get { return head?.Preset?.TagSet?.Contains(femaleIdentifier) ?? false; } }
public CharacterInfoPrefab Prefab => CharacterPrefab.Prefabs[SpeciesName].CharacterInfoPrefab;
public class HeadPreset : ISerializableEntity
@@ -1033,7 +1033,7 @@ namespace Barotrauma
if (Name == null || Job == null) { return 0; }
int salary = 0;
foreach (Skill skill in Job.Skills)
foreach (Skill skill in Job.GetSkills())
{
salary += (int)(skill.Level * skill.PriceMultiplier);
}
@@ -1076,10 +1076,10 @@ namespace Barotrauma
{
if (Job == null) { return; }
var skill = Job.Skills.Find(s => s.Identifier == skillIdentifier);
var skill = Job.GetSkill(skillIdentifier);
if (skill == null)
{
Job.Skills.Add(new Skill(skillIdentifier, level));
Job.IncreaseSkillLevel(skillIdentifier, level, increasePastMax: false);
OnSkillChanged(skillIdentifier, 0.0f, level);
}
else
@@ -384,7 +384,7 @@ namespace Barotrauma
foreach (var itemPrefab in ItemPrefab.Prefabs)
{
float suitability = Math.Max(itemPrefab.GetTreatmentSuitability(Identifier), itemPrefab.GetTreatmentSuitability(AfflictionType));
if (suitability > 0.0f)
if (!MathUtils.NearlyEqual(suitability, 0.0f))
{
yield return new KeyValuePair<Identifier, float>(itemPrefab.Identifier, suitability);
}
@@ -154,10 +154,14 @@ namespace Barotrauma
public void GiveItems(Character character, Submarine submarine, Rand.RandSync randSync = Rand.RandSync.Unsynced, bool createNetworkEvents = true)
{
if (ItemSets == null || !ItemSets.Any()) { return; }
var spawnItems = ToolBox.SelectWeightedRandom(ItemSets.Keys.ToList(), ItemSets.Values.ToList(), randSync);
foreach (XElement itemElement in spawnItems.GetChildElements("item"))
if (spawnItems != null)
{
InitializeItem(character, itemElement, submarine, this, createNetworkEvents: createNetworkEvents);
foreach (XElement itemElement in spawnItems.GetChildElements("item"))
{
InitializeItem(character, itemElement, submarine, this, createNetworkEvents: createNetworkEvents);
}
}
}
@@ -17,8 +17,6 @@ namespace Barotrauma
public JobPrefab Prefab => prefab;
public List<Skill> Skills => skills.Values.ToList();
public int Variant;
public Skill PrimarySkill { get; }
@@ -80,7 +78,12 @@ namespace Barotrauma
var prefab = JobPrefab.Random(randSync);
var variant = Rand.Range(0, prefab.Variants, randSync);
return new Job(prefab, randSync, variant);
}
}
public IEnumerable<Skill> GetSkills()
{
return skills.Values;
}
public float GetSkillLevel(Identifier skillIdentifier)
{
@@ -89,6 +92,22 @@ namespace Barotrauma
return skill?.Level ?? 0.0f;
}
public Skill GetSkill(Identifier skillIdentifier)
{
if (skillIdentifier.IsEmpty) { return null; }
skills.TryGetValue(skillIdentifier, out Skill skill);
return skill;
}
public void OverrideSkills(Dictionary<Identifier, float> newSkills)
{
skills.Clear();
foreach (var newSkill in newSkills)
{
skills.Add(newSkill.Key, new Skill(newSkill.Key, newSkill.Value));
}
}
public void IncreaseSkillLevel(Identifier skillIdentifier, float increase, bool increasePastMax)
{
if (skills.TryGetValue(skillIdentifier, out Skill skill))
@@ -171,7 +190,7 @@ namespace Barotrauma
character.Inventory.TryPutItem(item, null, item.AllowedSlots);
}
Wearable wearable = ((List<ItemComponent>)item.Components)?.Find(c => c is Wearable) as Wearable;
Wearable wearable = item.GetComponent<Wearable>();
if (wearable != null)
{
if (Variant > 0 && Variant <= wearable.Variants)
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace Barotrauma
@@ -12,7 +11,7 @@ namespace Barotrauma
public readonly List<string> AllowedDialogTags;
private float commonness;
private readonly float commonness;
public float Commonness
{
get { return commonness; }
@@ -20,12 +19,22 @@ namespace Barotrauma
public static IEnumerable<NPCPersonalityTrait> GetAll(LanguageIdentifier language)
{
if (language != TextManager.DefaultLanguage && !NPCConversationCollection.Collections.ContainsKey(language))
{
DebugConsole.AddWarning($"Could not find NPC personality traits for the language \"{language}\". Using \"{TextManager.DefaultLanguage}\" instead..");
language = TextManager.DefaultLanguage;
}
return NPCConversationCollection.Collections[language]
.SelectMany(cc => cc.PersonalityTraits.Values);
}
public static NPCPersonalityTrait Get(LanguageIdentifier language, Identifier traitName)
{
if (language != TextManager.DefaultLanguage && !NPCConversationCollection.Collections.ContainsKey(language))
{
DebugConsole.AddWarning($"Could not find NPC personality traits for the language \"{language}\". Using \"{TextManager.DefaultLanguage}\" instead..");
language = TextManager.DefaultLanguage;
}
return NPCConversationCollection.Collections[language]
.FirstOrDefault(cc => cc.PersonalityTraits.ContainsKey(traitName))
.PersonalityTraits[traitName];
@@ -293,6 +293,10 @@ namespace Barotrauma
{
return Create<HumanSwimFastParams>(fullPath, speciesName, animationType);
}
if (type == typeof(HumanCrouchParams))
{
return Create<HumanCrouchParams>(fullPath, speciesName, animationType);
}
if (type == typeof(FishWalkParams))
{
return Create<FishWalkParams>(fullPath, speciesName, animationType);
@@ -47,7 +47,7 @@ namespace Barotrauma.Abilities
{
if (skillIdentifier == "random")
{
var skill = character.Info?.Job?.Skills?.GetRandomUnsynced();
var skill = character.Info?.Job?.GetSkills()?.GetRandomUnsynced();
if (skill == null) { return; }
character.Info?.IncreaseSkillLevel(skill.Identifier, skillIncrease, gainedFromAbility: true);
}
@@ -30,11 +30,12 @@ namespace Barotrauma.Abilities
if (useAll && Character.Info?.Job != null)
{
foreach (Skill skill in Character.Info.Job.Skills)
var skills = Character.Info.Job.GetSkills();
foreach (Skill skill in skills)
{
skillTotal += Character.GetSkillLevel(skill.Identifier);
}
skillTotal /= Character.Info.Job.Skills.Count;
skillTotal /= skills.Count();
}
else
{