(98ad00fa2) v0.9.1.0

This commit is contained in:
Joonas Rikkonen
2019-07-10 13:52:12 +03:00
parent 2a791887ed
commit afa2137bd2
104 changed files with 3041 additions and 3134 deletions
@@ -178,29 +178,35 @@ namespace Barotrauma.Items.Components
private void SetUser(Character character)
{
if (user == character) return;
if (user != null && user.Removed) user = null;
if (user == character) { return; }
if (user != null && user.Removed) { user = null; }
user = character;
if (item.body?.FarseerBody == null || item.Removed ||
!GameMain.World.BodyList.Contains(item.body.FarseerBody))
{
return;
}
if (user != null)
{
foreach (Limb limb in user.AnimController.Limbs)
{
if (limb.body.FarseerBody != null)
if (limb.body.FarseerBody != null && GameMain.World.BodyList.Contains(limb.body.FarseerBody))
{
if (GameMain.World.BodyList.Contains(limb.body.FarseerBody))
{
item.body.FarseerBody.RestoreCollisionWith(limb.body.FarseerBody);
}
item.body.FarseerBody.RestoreCollisionWith(limb.body.FarseerBody);
}
}
}
foreach (Limb limb in character.AnimController.Limbs)
{
item.body.FarseerBody.IgnoreCollisionWith(limb.body.FarseerBody);
if (limb.body.FarseerBody != null && GameMain.World.BodyList.Contains(limb.body.FarseerBody))
{
item.body.FarseerBody.IgnoreCollisionWith(limb.body.FarseerBody);
}
}
user = character;
}
private void RestoreCollision()
@@ -21,7 +21,7 @@ namespace Barotrauma.Items.Components
private UsableIn usableIn;
[Serialize(0.0f, false), Editable(MinValueFloat = 0.0f, MaxValueFloat = 1000.0f)]
[Serialize(0.0f, false), Editable(MinValueFloat = -1000.0f, MaxValueFloat = 1000.0f)]
public float Force
{
get { return force; }
@@ -11,6 +11,8 @@ namespace Barotrauma.Items.Components
private float progressTimer;
private float progressState;
private bool hasPower;
private ItemContainer inputContainer, outputContainer;
public ItemContainer InputContainer
@@ -58,7 +60,8 @@ namespace Barotrauma.Items.Components
return;
}
if (voltage < minVoltage) { return; }
hasPower = voltage >= minVoltage;
if (!hasPower) { return; }
var repairable = item.GetComponent<Repairable>();
if (repairable != null)
@@ -68,7 +71,7 @@ namespace Barotrauma.Items.Components
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
if (powerConsumption == 0.0f) voltage = 1.0f;
if (powerConsumption == 0.0f) { voltage = 1.0f; }
progressTimer += deltaTime * voltage;
Voltage -= deltaTime * 10.0f;
@@ -107,28 +110,41 @@ namespace Barotrauma.Items.Components
}
}
if (targetItem.Prefab.DeconstructItems.Any())
if (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer)
{
inputContainer.Inventory.RemoveItem(targetItem);
Entity.Spawner.AddToRemoveQueue(targetItem);
MoveInputQueue();
PutItemsToLinkedContainer();
}
else
{
if (outputContainer.Inventory.Items.All(i => i != null))
if (targetItem.Prefab.DeconstructItems.Any())
{
targetItem.Drop(dropper: null);
//drop all items that are inside the deconstructed item
foreach (ItemContainer ic in targetItem.GetComponents<ItemContainer>())
{
if (ic?.Inventory?.Items == null) { continue; }
foreach (Item containedItem in ic.Inventory.Items)
{
containedItem?.Drop(dropper: null, createNetworkEvent: true);
}
}
inputContainer.Inventory.RemoveItem(targetItem);
Entity.Spawner.AddToRemoveQueue(targetItem);
MoveInputQueue();
PutItemsToLinkedContainer();
}
else
{
outputContainer.Inventory.TryPutItem(targetItem, user: null, createNetworkEvent: true);
if (outputContainer.Inventory.Items.All(i => i != null))
{
targetItem.Drop(dropper: null);
}
else
{
outputContainer.Inventory.TryPutItem(targetItem, user: null, createNetworkEvent: true);
}
}
}
if (inputContainer.Inventory.Items.Any(i => i != null))
{
#if SERVER
item.CreateServerEvent(this);
#endif
progressTimer = 0.0f;
progressState = 0.0f;
}
}
@@ -188,21 +204,17 @@ namespace Barotrauma.Items.Components
}
#endif
if (!IsActive) { progressState = 0.0f; }
#if CLIENT
if (!IsActive)
{
progressTimer = 0.0f;
activateButton.Text = TextManager.Get("DeconstructorDeconstruct");
}
else
{
activateButton.Text = TextManager.Get("DeconstructorCancel");
progressState = 0.0f;
}
#if CLIENT
activateButton.Text = TextManager.Get(IsActive ? "DeconstructorCancel" : "DeconstructorDeconstruct");
#endif
inputContainer.Inventory.Locked = IsActive;
inputContainer.Inventory.Locked = IsActive;
}
}
}
@@ -19,6 +19,8 @@ namespace Barotrauma.Items.Components
private float timeUntilReady;
private float requiredTime;
private bool hasPower;
private Character user;
private ItemContainer inputContainer, outputContainer;
@@ -198,8 +200,9 @@ namespace Barotrauma.Items.Components
progressState = fabricatedItem == null ? 0.0f : (requiredTime - timeUntilReady) / requiredTime;
if (voltage < minVoltage) { return; }
hasPower = voltage >= minVoltage;
if (!hasPower) { return; }
var repairable = item.GetComponent<Repairable>();
if (repairable != null)
{
@@ -215,43 +218,50 @@ namespace Barotrauma.Items.Components
if (timeUntilReady > 0.0f) { return; }
var availableIngredients = GetAvailableIngredients();
foreach (FabricationRecipe.RequiredItem ingredient in fabricatedItem.RequiredItems)
if (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer)
{
for (int i = 0; i < ingredient.Amount; i++)
var availableIngredients = GetAvailableIngredients();
foreach (FabricationRecipe.RequiredItem ingredient in fabricatedItem.RequiredItems)
{
var requiredItem = inputContainer.Inventory.Items.FirstOrDefault(it => it != null && it.Prefab == ingredient.ItemPrefab && it.Condition >= ingredient.ItemPrefab.Health * ingredient.MinCondition);
if (requiredItem == null) continue;
//Item4 = use condition bool
if (ingredient.UseCondition && requiredItem.Condition - ingredient.ItemPrefab.Health * ingredient.MinCondition > 0.0f) //Leave it behind with reduced condition if it has enough to stay above 0
for (int i = 0; i < ingredient.Amount; i++)
{
requiredItem.Condition -= ingredient.ItemPrefab.Health * ingredient.MinCondition;
continue;
var availableItem = availableIngredients.FirstOrDefault(it => it != null && it.Prefab == ingredient.ItemPrefab && it.Condition >= ingredient.ItemPrefab.Health * ingredient.MinCondition);
if (availableItem == null) { continue; }
//Item4 = use condition bool
if (ingredient.UseCondition && availableItem.Condition - ingredient.ItemPrefab.Health * ingredient.MinCondition > 0.0f) //Leave it behind with reduced condition if it has enough to stay above 0
{
availableItem.Condition -= ingredient.ItemPrefab.Health * ingredient.MinCondition;
continue;
}
availableIngredients.Remove(availableItem);
Entity.Spawner.AddToRemoveQueue(availableItem);
inputContainer.Inventory.RemoveItem(availableItem);
}
Entity.Spawner.AddToRemoveQueue(requiredItem);
inputContainer.Inventory.RemoveItem(requiredItem);
}
}
if (outputContainer.Inventory.Items.All(i => i != null))
{
Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, item.Position, item.Submarine, fabricatedItem.TargetItem.Health * fabricatedItem.OutCondition);
}
else
{
Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, outputContainer.Inventory, fabricatedItem.TargetItem.Health * fabricatedItem.OutCondition);
}
if ((GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer) && user != null && !user.Removed)
{
foreach (Skill skill in fabricatedItem.RequiredSkills)
if (outputContainer.Inventory.Items.All(i => i != null))
{
user.Info.IncreaseSkillLevel(skill.Identifier, skill.Level / 100.0f * SkillIncreaseMultiplier, user.WorldPosition + Vector2.UnitY * 150.0f);
Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, item.Position, item.Submarine, fabricatedItem.TargetItem.Health * fabricatedItem.OutCondition);
}
else
{
Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, outputContainer.Inventory, fabricatedItem.TargetItem.Health * fabricatedItem.OutCondition);
}
if (user != null && !user.Removed)
{
foreach (Skill skill in fabricatedItem.RequiredSkills)
{
user.Info.IncreaseSkillLevel(skill.Identifier, skill.Level / 100.0f * SkillIncreaseMultiplier, user.WorldPosition + Vector2.UnitY * 150.0f);
}
}
}
CancelFabricating(null);
CancelFabricating(null);
#if SERVER
item.CreateServerEvent(this);
#endif
}
}
private bool CanBeFabricated(FabricationRecipe fabricableItem)
@@ -328,6 +338,8 @@ namespace Barotrauma.Items.Components
{
var matchingItem = availableIngredients.Find(it => !usedItems.Contains(it) && IsItemValidIngredient(it, requiredItem));
if (matchingItem == null) { continue; }
availableIngredients.Remove(matchingItem);
if (matchingItem.ParentInventory == inputContainer.Inventory)
{
@@ -254,15 +254,19 @@ namespace Barotrauma.Items.Components
{
foreach (Connection connection in connections)
{
if (!connection.IsPower) continue;
if (!connection.IsPower) { continue; }
foreach (Connection recipient in connection.Recipients)
{
if (!(recipient.Item is Item it)) continue;
if (!(recipient.Item is Item it)) { continue; }
PowerTransfer pt = it.GetComponent<PowerTransfer>();
if (pt == null) continue;
if (pt == null) { continue; }
load = Math.Max(load, pt.PowerLoad);
//calculate how much external power there is in the grid
//(power coming from somewhere else than this reactor, e.g. batteries)
float externalPower = CurrPowerConsumption - pt.CurrPowerConsumption;
//reduce the external power from the load to prevent overloading the grid
load = Math.Max(load, pt.PowerLoad - externalPower);
}
}
}
@@ -176,7 +176,7 @@ namespace Barotrauma.Items.Components
float successFactor = requiredSkills.Count == 0 ? 1.0f : 0.0f;
//item must have been below 50% condition for the player to get an achievement or XP for repairing it
//item must have been below the repair threshold for the player to get an achievement or XP for repairing it
if (item.Condition < ShowRepairUIThreshold)
{
wasBroken = true;
@@ -61,6 +61,7 @@ namespace Barotrauma.Items.Components
{
get
{
if (GameMain.NetworkMember?.ServerSettings != null && !GameMain.NetworkMember.ServerSettings.AllowRewiring) { return false; }
return locked || connections.Any(c => c != null && c.ConnectionPanel.Locked);
}
set { locked = value; }
@@ -152,13 +152,12 @@ namespace Barotrauma
get { return description ?? prefab.Description; }
set { description = value; }
}
private bool hiddenInGame;
[Editable, Serialize(false, true)]
public bool HiddenInGame
{
get { return hiddenInGame; }
set { hiddenInGame = value; }
get;
set;
}
public float ImpactTolerance
@@ -262,7 +261,26 @@ namespace Barotrauma
/// </summary>
public string ContainerIdentifier
{
get { return Container?.prefab.Identifier ?? ""; }
get
{
return
Container?.prefab.Identifier ??
ParentInventory?.Owner?.ToString() ??
"";
}
set { /*do nothing*/ }
}
[Serialize(false, false)]
/// <summary>
/// Can be used by status effects or conditionals to check if the physics body of the item is active
/// </summary>
public bool PhysicsBodyActive
{
get
{
return body != null && body.Enabled;
}
set { /*do nothing*/ }
}
@@ -315,7 +333,7 @@ namespace Barotrauma
get { return spriteColor; }
}
public bool IsFullCondition => Condition >= MaxCondition;
public bool IsFullCondition => MathUtils.NearlyEqual(Condition, MaxCondition);
public float MaxCondition => Prefab.Health;
public float ConditionPercentage => MathUtils.Percentage(Condition, MaxCondition);
@@ -334,6 +352,8 @@ namespace Barotrauma
if (Indestructible) return;
float prev = condition;
bool wasInFullCondition = IsFullCondition;
condition = MathHelper.Clamp(value, 0.0f, Prefab.Health);
if (condition == 0.0f && prev > 0.0f)
{
@@ -349,9 +369,17 @@ namespace Barotrauma
SetActiveSprite();
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer && !MathUtils.NearlyEqual(lastSentCondition, condition))
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
{
if (Math.Abs(lastSentCondition - condition) > 1.0f || condition == 0.0f || condition == Prefab.Health)
if (Math.Abs(lastSentCondition - condition) > 1.0f)
{
conditionUpdatePending = true;
}
else if (wasInFullCondition != IsFullCondition)
{
conditionUpdatePending = true;
}
else if (!MathUtils.NearlyEqual(lastSentCondition, condition) && (condition <= 0.0f || condition >= Prefab.Health))
{
conditionUpdatePending = true;
}
@@ -2086,11 +2114,13 @@ namespace Barotrauma
System.Diagnostics.Debug.Assert(Submarine != null || rootContainer.ParentInventory?.Owner is Character);
Vector2 subPosition = Submarine == null ? Vector2.Zero : Submarine.HiddenSubPosition;
int width = ResizeHorizontal ? rect.Width : defaultRect.Width;
int height = ResizeVertical ? rect.Height : defaultRect.Height;
element.Add(new XAttribute("rect",
(int)(rect.X - subPosition.X) + "," +
(int)(rect.Y - subPosition.Y) + "," +
defaultRect.Width + "," + defaultRect.Height));
width + "," + height));
if (linkedTo != null && linkedTo.Count > 0)
{
@@ -17,7 +17,8 @@ namespace Barotrauma
}
public bool IsOptional { get; set; }
public bool MatchOnEmpty { get; set; }
public bool IgnoreInEditor { get; set; }
private string[] excludedIdentifiers;
@@ -99,6 +100,11 @@ namespace Barotrauma
var containedItems = parentItem.ContainedItems;
if (containedItems == null) return false;
if (MatchOnEmpty && !containedItems.Any(ci => ci != null))
{
return true;
}
foreach (Item contained in containedItems)
{
if (contained.Condition > 0.0f && MatchesItem(contained)) return true;
@@ -222,6 +228,7 @@ namespace Barotrauma
ri.IsOptional = element.GetAttributeBool("optional", false);
ri.IgnoreInEditor = element.GetAttributeBool("ignoreineditor", false);
ri.MatchOnEmpty = element.GetAttributeBool("matchonempty", false);
return ri;
}
}