Unstable 0.17.4.0

This commit is contained in:
Markus Isberg
2022-03-30 00:08:09 +09:00
parent 2968e23ae8
commit c1b8e5a341
177 changed files with 3388 additions and 1977 deletions
@@ -32,7 +32,7 @@ namespace Barotrauma
public ArtifactEvent(EventPrefab prefab)
: base(prefab)
{
if (prefab.ConfigElement.Attribute("itemname") != null)
if (prefab.ConfigElement.GetAttribute("itemname") != null)
{
DebugConsole.ThrowError("Error in ArtifactEvent - use item identifier instead of the name of the item.");
string itemName = prefab.ConfigElement.GetAttributeString("itemname", "");
@@ -30,7 +30,7 @@ namespace Barotrauma
public SubactionGroup(ScriptedEvent scriptedEvent, ContentXElement elem)
{
Text = elem.Attribute("text")?.Value ?? "";
Text = elem.GetAttribute("text")?.Value ?? "";
Actions = new List<EventAction>();
EndConversation = elem.GetAttributeBool("endconversation", false);
foreach (var e in elem.Elements())
@@ -153,6 +153,13 @@ namespace Barotrauma
swarmSpawned = true;
}
#if DEBUG || UNSTABLE
if (State == 1 && !level.CheckBeaconActive())
{
DebugConsole.ThrowError("Beacon became inactive!");
State = 2;
}
#endif
}
public override void End()
@@ -248,7 +248,7 @@ namespace Barotrauma
{
if (Submarine.MainSub != null && Submarine.MainSub.AtEndExit)
{
int deliveredItemCount = items.Count(i => i.CurrentHull != null && !i.Removed && i.Condition > 0.0f);
int deliveredItemCount = items.Count(it => IsItemDelivered(it));
if (deliveredItemCount / (float)items.Count >= requiredDeliveryAmount)
{
GiveReward();
@@ -267,5 +267,12 @@ namespace Barotrauma
items.Clear();
failed = !completed;
}
private bool IsItemDelivered(Item item)
{
if (item.Removed || item.Condition <= 0.0f || Submarine.MainSub == null) { return false; }
var submarine = item.Submarine ?? item.GetRootContainer()?.Submarine;
return submarine == Submarine.MainSub || Submarine.MainSub.GetConnectedSubs().Contains(submarine);
}
}
}
@@ -419,17 +419,17 @@ namespace Barotrauma
public static int DistributeRewardsToCrew(IEnumerable<Character> crew, int totalReward)
{
int remainingRewards = totalReward;
HashSet<Character> nonBotCrew = crew.Where(c => !c.IsBot).ToHashSet();
float sum = nonBotCrew.Sum(c => c.Wallet.RewardDistribution);
if (sum == 0) { return remainingRewards; }
foreach (Character character in nonBotCrew)
float sum = GetRewardDistibutionSum(crew);
if (MathUtils.NearlyEqual(sum, 0)) { return remainingRewards; }
foreach (Character character in crew)
{
float rewardWeight = character.Wallet.RewardDistribution / sum;
int reward = (int)Math.Floor(totalReward * rewardWeight);
reward = Math.Max(remainingRewards, reward);
int rewardDistribution = character.Wallet.RewardDistribution;
float rewardWeight = sum > 100 ? rewardDistribution / sum : rewardDistribution / 100f;
int reward = (int)(totalReward * rewardWeight);
reward = Math.Min(remainingRewards, reward);
character.Wallet.Give(reward);
remainingRewards -= reward;
if (0 >= remainingRewards) { break; }
if (remainingRewards <= 0) { break; }
}
return remainingRewards;
@@ -442,26 +442,27 @@ namespace Barotrauma
IEnumerable<Character> characters = crewManager.GetCharacters();
#if SERVER
return GameMain.Server.ConnectedClients.Select(c => c.Character).Where(IsAlive).Concat(characters);
return GameMain.Server.ConnectedClients.Select(c => c.Character).Where(c => c?.Info != null && !c.IsDead).Concat(characters);
#elif CLIENT
return characters;
#endif
static bool IsAlive(Character c) { return c?.Info != null && !c.IsDead; }
}
public static int GetRewardDistibutionSum(IEnumerable<Character> crew, int rewardDistribution = 0) => crew.Sum(c => c.Wallet.RewardDistribution) + rewardDistribution;
public static (int Amount, int Percentage) GetRewardShare(int rewardDistribution, IEnumerable<Character> crew, Option<int> reward)
public static (int Amount, int Percentage, float Sum) GetRewardShare(int rewardDistribution, IEnumerable<Character> crew, Option<int> reward)
{
float sum = crew.Sum(c => c.Wallet.RewardDistribution) + rewardDistribution;
if (sum == 0) { return (0, 0); }
float sum = GetRewardDistibutionSum(crew, rewardDistribution);
if (MathUtils.NearlyEqual(sum, 0)) { return (0, 0, sum); }
float rewardWeight = rewardDistribution / sum;
float rewardWeight = sum > 100 ? rewardDistribution / sum : rewardDistribution / 100f;
int rewardPercentage = (int)(rewardWeight * 100);
return reward switch
{
Some<int> { Value: var amount } => ((int)(amount * rewardWeight), rewardPercentage),
None<int> _ => (0, rewardPercentage),
Some<int> { Value: var amount } => ((int)(amount * rewardWeight), rewardPercentage, sum),
None<int> _ => (0, rewardPercentage, sum),
_ => throw new ArgumentOutOfRangeException()
};
}
@@ -209,7 +209,7 @@ namespace Barotrauma
break;
case "locationtype":
case "connectiontype":
if (subElement.Attribute("identifier") != null)
if (subElement.GetAttribute("identifier") != null)
{
AllowedLocationTypes.Add(subElement.GetAttributeIdentifier("identifier", ""));
}
@@ -228,7 +228,7 @@ namespace Barotrauma
}
GiveReward();
completed = true;
if (level?.LevelData != null && Prefab.Tags.Any(t => t.Equals("huntinggrounds", StringComparison.OrdinalIgnoreCase) || t.Equals("huntinggroundsnoreward", StringComparison.OrdinalIgnoreCase)))
if (level?.LevelData != null && Prefab.Tags.Any(t => t.Equals("huntinggrounds", StringComparison.OrdinalIgnoreCase)))
{
level.LevelData.HasHuntingGrounds = false;
}
@@ -48,7 +48,7 @@ namespace Barotrauma
{
containerTag = prefab.ConfigElement.GetAttributeString("containertag", "");
if (prefab.ConfigElement.Attribute("itemname") != null)
if (prefab.ConfigElement.GetAttribute("itemname") != null)
{
DebugConsole.ThrowError("Error in SalvageMission - use item identifier instead of the name of the item.");
string itemName = prefab.ConfigElement.GetAttributeString("itemname", "");