Unstable 1.8.4.0

This commit is contained in:
Markus Isberg
2025-03-12 12:56:27 +00:00
parent a4c3e868e4
commit a4a3427e4e
627 changed files with 29860 additions and 10018 deletions
@@ -1,4 +1,4 @@
using Barotrauma.Extensions;
using Barotrauma.Extensions;
using Barotrauma.Items.Components;
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
@@ -45,7 +45,8 @@ namespace Barotrauma
public float HappyThreshold { get; set; }
public float MaxHappiness { get; set; }
public bool HideStatusIndicators { get; set; }
/// <summary>
/// At which point is the pet considered "hungry" (playing unhappy sounds and showing the icon)
@@ -59,6 +60,14 @@ namespace Barotrauma
public float PlayForce { get; set; }
public float PlayTimer { get; set; }
public float PlayCooldown { get; set; }
/// <summary>
/// Should the pet lose ownership (and stop following) when the same character interacts with it twice? Unlike with other pets, if another character interacts with the pet, they will become the owner.
/// </summary>
public bool ToggleOwner { get; set; }
private float? UnstunY { get; set; }
public EnemyAIController AIController { get; private set; } = null;
@@ -151,7 +160,8 @@ namespace Barotrauma
aggregate += Items[i].Commonness;
if (aggregate >= r && Items[i].Prefab != null)
{
GameAnalyticsManager.AddDesignEvent("MicroInteraction:" + (GameMain.GameSession?.GameMode?.Preset.Identifier.Value ?? "null") + ":PetProducedItem:" + pet.AIController.Character.SpeciesName + ":" + Items[i].Prefab.Identifier);
//disabled to reduce the amount of data we collect through GA
//GameAnalyticsManager.AddDesignEvent("MicroInteraction:" + (GameMain.GameSession?.GameMode?.Preset.Identifier.Value ?? "null") + ":PetProducedItem:" + pet.AIController.Character.SpeciesName + ":" + Items[i].Prefab.Identifier);
Entity.Spawner?.AddItemToSpawnQueue(Items[i].Prefab, pet.AIController.Character.WorldPosition);
break;
}
@@ -162,7 +172,7 @@ namespace Barotrauma
private class Food
{
public string Tag;
public Identifier Tag;
public Vector2 HungerRange;
public float Hunger;
public float Happiness;
@@ -182,6 +192,7 @@ namespace Barotrauma
MaxHappiness = element.GetAttributeFloat(nameof(MaxHappiness), 100.0f);
UnhappyThreshold = element.GetAttributeFloat(nameof(UnhappyThreshold), MaxHappiness * 0.25f);
HappyThreshold = element.GetAttributeFloat(nameof(HappyThreshold), MaxHappiness * 0.8f);
HideStatusIndicators = element.GetAttributeBool(nameof(HideStatusIndicators), false);
MaxHunger = element.GetAttributeFloat(nameof(MaxHunger), 100.0f);
HungryThreshold = element.GetAttributeFloat(nameof(HungryThreshold), MaxHunger * 0.5f);
@@ -192,7 +203,9 @@ namespace Barotrauma
HappinessDecreaseRate = element.GetAttributeFloat(nameof(HappinessDecreaseRate), 0.1f);
HungerIncreaseRate = element.GetAttributeFloat(nameof(HungerIncreaseRate), 0.25f);
PlayForce = element.GetAttributeFloat("playforce", 15.0f);
PlayForce = element.GetAttributeFloat(nameof(PlayForce), 15.0f);
PlayCooldown = element.GetAttributeFloat(nameof(PlayCooldown), 5.0f);
ToggleOwner = element.GetAttributeBool(nameof(ToggleOwner), false);
foreach (var subElement in element.Elements())
{
@@ -204,7 +217,7 @@ namespace Barotrauma
case "eat":
Food food = new Food
{
Tag = subElement.GetAttributeString("tag", ""),
Tag = subElement.GetAttributeIdentifier("tag", Identifier.Empty),
Hunger = subElement.GetAttributeFloat("hunger", -1),
Happiness = subElement.GetAttributeFloat("happiness", 1),
Priority = subElement.GetAttributeFloat("priority", 100),
@@ -227,6 +240,7 @@ namespace Barotrauma
public StatusIndicatorType GetCurrentStatusIndicatorType()
{
if (HideStatusIndicators) { return StatusIndicatorType.None; }
if (Hunger > HungryThreshold) { return StatusIndicatorType.Hungry; }
if (Happiness > HappyThreshold) { return StatusIndicatorType.Happy; }
if (Happiness < UnhappyThreshold) { return StatusIndicatorType.Sad; }
@@ -280,17 +294,30 @@ namespace Barotrauma
return false;
}
public bool CanPlayWith(Character player)
{
return AIController.Character.IsOnFriendlyTeam(player);
}
public void Play(Character player)
{
if (PlayTimer > 0.0f) { return; }
Owner ??= player;
PlayTimer = 5.0f;
if (!CanPlayWith(player)) { return; }
if (ToggleOwner)
{
Owner = Owner == player ? null : player;
}
else
{
Owner ??= player;
}
PlayTimer = PlayCooldown;
AIController.Character.IsRagdolled = true;
Happiness += 10.0f;
AIController.Character.AnimController.MainLimb.body.LinearVelocity += new Vector2(0, PlayForce);
UnstunY = AIController.Character.SimPosition.Y;
#if CLIENT
AIController.Character.PlaySound(CharacterSound.SoundType.Happy, 0.9f);
AIController.Character.PlaySound(Owner == null ? CharacterSound.SoundType.Unhappy : CharacterSound.SoundType.Happy);
#endif
}
@@ -318,7 +345,7 @@ namespace Barotrauma
if (UnstunY.HasValue)
{
if (PlayTimer > 4.0f)
if (PlayTimer > PlayCooldown - 1.0f)
{
float extent = character.AnimController.MainLimb.body.GetMaxExtent();
if (character.SimPosition.Y < (UnstunY.Value + extent * 3.0f) &&
@@ -354,9 +381,12 @@ namespace Barotrauma
{
if (food.TargetParams == null)
{
if (AIController.AIParams.TryGetTarget(food.Tag, out TargetParams target))
if (AIController.AIParams.TryGetTargets(food.Tag, out IEnumerable<TargetParams> existingTargetParams))
{
food.TargetParams = target;
foreach (var targetParams in existingTargetParams)
{
food.TargetParams = targetParams;
}
}
else if (AIController.AIParams.TryAddNewTarget(food.Tag, AIState.Eat, food.Priority, out TargetParams targetParams))
{
@@ -444,11 +474,15 @@ namespace Barotrauma
}
else
{
WayPoint spawnPoint = null;
//try to find a spawnpoint in the main sub
var spawnPoint = WayPoint.WayPointList.Where(wp => wp.SpawnType == SpawnType.Human && wp.Submarine == Submarine.MainSub).GetRandomUnsynced();
if (Submarine.MainSub != null)
{
spawnPoint = WayPoint.WayPointList.Where(wp => wp.SpawnType == SpawnType.Human && wp.Submarine == Submarine.MainSub).GetRandomUnsynced();
}
//if not found, try any player sub (shuttle/drone etc)
spawnPoint ??= WayPoint.WayPointList.Where(wp => wp.SpawnType == SpawnType.Human && wp.Submarine?.Info.Type == SubmarineType.Player).GetRandomUnsynced();
spawnPos = spawnPoint?.WorldPosition ?? Submarine.MainSub.WorldPosition;
spawnPos = spawnPoint?.WorldPosition ?? Submarine.MainSub?.WorldPosition ?? Vector2.Zero;
}
var characterPrefab = CharacterPrefab.FindBySpeciesName(speciesName.ToIdentifier());