Files
LuaCsForBarotraumaEP/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/OxygenGenerator.cs
T
Joonas Rikkonen 6cf0f966aa Refactored event/task logic:
- Instead of configuring a commonness value and difficulty for an event and creating new random events until the maximum difficulty of the selected level is reached, the number of events per level can be configured directly (and overridden for specific level types).
- Removed task logic. The initial idea was to display the unfinished tasks to the player somehow and to use them as objectives for the AI crew, but those were scrapped and the tasks only ended up controlling which type of music to play. TODO: implement some kind of logic to determine when to play repair/monster music clips.
2017-08-22 21:12:06 +03:00

126 lines
3.1 KiB
C#

using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
class OxygenGenerator : Powered
{
float powerDownTimer;
bool running;
private float generatedAmount;
List<Vent> ventList;
private float totalHullVolume;
public bool IsRunning()
{
return (running && item.Condition>0.0f);
}
public float CurrFlow
{
get;
private set;
}
[Editable, HasDefaultValue(100.0f, true)]
public float GeneratedAmount
{
get { return generatedAmount; }
set { generatedAmount = MathHelper.Clamp(value, -10000.0f, 10000.0f); }
}
public OxygenGenerator(Item item, XElement element)
: base(item, element)
{
IsActive = true;
//item.linkedTo.CollectionChanged += delegate { GetVents(); };
}
public override void Update(float deltaTime, Camera cam)
{
base.Update(deltaTime, cam);
CurrFlow = 0.0f;
currPowerConsumption = powerConsumption;
if (item.CurrentHull == null) return;
if (voltage < minVoltage)
{
powerDownTimer += deltaTime;
running = false;
return;
}
else
{
powerDownTimer = 0.0f;
}
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
running = true;
CurrFlow = Math.Min(voltage, 1.0f) * generatedAmount*100.0f;
//item.CurrentHull.Oxygen += CurrFlow * deltaTime;
UpdateVents(CurrFlow);
voltage -= deltaTime;
}
public override void UpdateBroken(float deltaTime, Camera cam)
{
powerDownTimer += deltaTime;
}
private void GetVents()
{
ventList.Clear();
foreach (MapEntity entity in item.linkedTo)
{
Item linkedItem = entity as Item;
if (linkedItem == null) continue;
Vent vent = linkedItem.GetComponent<Vent>();
if (vent == null) continue;
ventList.Add(vent);
if (linkedItem.CurrentHull!=null) totalHullVolume += linkedItem.CurrentHull.FullVolume;
}
}
//public override void OnMapLoaded()
//{
// GetVents();
//}
private void UpdateVents(float deltaOxygen)
{
if (ventList == null)
{
ventList = new List<Vent>();
GetVents();
}
if (!ventList.Any() || totalHullVolume == 0.0f) return;
foreach (Vent v in ventList)
{
if (v.Item.CurrentHull == null) continue;
v.OxygenFlow = deltaOxygen * (v.Item.CurrentHull.FullVolume / totalHullVolume);
v.IsActive = true;
}
}
}
}