51 lines
2.0 KiB
C#
51 lines
2.0 KiB
C#
using Barotrauma.Items.Components;
|
|
using Barotrauma.Extensions;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Barotrauma
|
|
{
|
|
class AIObjectiveChargeBatteries : AIObjectiveLoop<PowerContainer>
|
|
{
|
|
public override string DebugTag => "charge batteries";
|
|
private readonly IEnumerable<PowerContainer> batteryList;
|
|
|
|
public AIObjectiveChargeBatteries(Character character, string option) : base(character, option)
|
|
{
|
|
batteryList = Item.ItemList.Select(i => i.GetComponent<PowerContainer>()).Where(b => b != null);
|
|
}
|
|
|
|
public override bool IsDuplicate(AIObjective otherObjective)
|
|
{
|
|
return otherObjective is AIObjectiveChargeBatteries other && other.Option == Option;
|
|
}
|
|
|
|
protected override void FindTargets()
|
|
{
|
|
base.FindTargets();
|
|
if (targets.None())
|
|
{
|
|
character.Speak(TextManager.Get("DialogNoBatteries"), null, 4.0f, "nobatteries", 10.0f);
|
|
}
|
|
else
|
|
{
|
|
// Sorting should be handled by the objective manager, because the targets should be subobjectives.
|
|
//targets.Sort((x, y) => x.ChargePercentage.CompareTo(y.ChargePercentage));
|
|
}
|
|
}
|
|
|
|
protected override bool Filter(PowerContainer battery)
|
|
{
|
|
var item = battery.Item;
|
|
if (item.Submarine == null) { return false; }
|
|
if (item.Submarine.TeamID != character.TeamID) { return false; }
|
|
if (character.Submarine != null && !character.Submarine.IsEntityFoundOnThisSub(item, true)) { return false; }
|
|
return true;
|
|
}
|
|
|
|
protected override float TargetEvaluation() => targets.Max(t => 100 - t.ChargePercentage);
|
|
protected override IEnumerable<PowerContainer> GetList() => batteryList;
|
|
protected override AIObjective ObjectiveConstructor(PowerContainer battery) => new AIObjectiveOperateItem(battery, character, Option, false, priorityModifier: PriorityModifier) { IsLoop = true };
|
|
}
|
|
}
|