v1.5.7.0 (Summer Update)
This commit is contained in:
@@ -188,18 +188,7 @@ namespace Barotrauma
|
||||
|
||||
public static PurchasedItem CreateInitialStockItem(ItemPrefab itemPrefab, PriceInfo priceInfo)
|
||||
{
|
||||
int quantity = PriceInfo.DefaultAmount;
|
||||
if (priceInfo.MaxAvailableAmount > 0)
|
||||
{
|
||||
quantity =
|
||||
priceInfo.MaxAvailableAmount > priceInfo.MinAvailableAmount ?
|
||||
Rand.Range(priceInfo.MinAvailableAmount, priceInfo.MaxAvailableAmount + 1) :
|
||||
priceInfo.MaxAvailableAmount;
|
||||
}
|
||||
else if (priceInfo.MinAvailableAmount > 0)
|
||||
{
|
||||
quantity = priceInfo.MinAvailableAmount;
|
||||
}
|
||||
int quantity = Rand.Range(priceInfo.MinAvailableAmount, priceInfo.MaxAvailableAmount + 1);
|
||||
return new PurchasedItem(itemPrefab, quantity, buyer: null);
|
||||
}
|
||||
|
||||
@@ -256,7 +245,7 @@ namespace Barotrauma
|
||||
if (stockItem.ItemPrefab.GetPriceInfo(this) is PriceInfo priceInfo)
|
||||
{
|
||||
if (!priceInfo.CanBeSpecial) { continue; }
|
||||
var baseQuantity = priceInfo.MinAvailableAmount > 0 ? priceInfo.MinAvailableAmount : PriceInfo.DefaultAmount;
|
||||
var baseQuantity = priceInfo.MinAvailableAmount;
|
||||
weight += (float)(stockItem.Quantity - baseQuantity) / baseQuantity;
|
||||
if (weight < 0.0f) { continue; }
|
||||
}
|
||||
@@ -906,8 +895,8 @@ namespace Barotrauma
|
||||
}
|
||||
MissionPrefab missionPrefab =
|
||||
random != null ?
|
||||
ToolBox.SelectWeightedRandom(suitableMissions.OrderBy(m => m.Identifier), m => m.Commonness, random) :
|
||||
ToolBox.SelectWeightedRandom(suitableMissions.OrderBy(m => m.Identifier), m => m.Commonness, Rand.RandSync.Unsynced);
|
||||
ToolBox.SelectWeightedRandom(suitableMissions, m => m.Commonness, random) :
|
||||
ToolBox.SelectWeightedRandom(suitableMissions, m => m.Commonness, Rand.RandSync.Unsynced);
|
||||
|
||||
var mission = InstantiateMission(missionPrefab, out LocationConnection connection);
|
||||
//don't allow duplicate missions in the same connection
|
||||
@@ -1141,6 +1130,12 @@ namespace Barotrauma
|
||||
return HireManager.AvailableCharacters;
|
||||
}
|
||||
|
||||
public void ForceHireableCharacters(IEnumerable<CharacterInfo> hireableCharacters)
|
||||
{
|
||||
HireManager ??= new HireManager();
|
||||
HireManager.AvailableCharacters = hireableCharacters.ToList();
|
||||
}
|
||||
|
||||
private void CreateRandomName(LocationType type, Random rand, IEnumerable<Location> existingLocations)
|
||||
{
|
||||
if (!type.ForceLocationName.IsEmpty)
|
||||
@@ -1402,12 +1397,12 @@ namespace Barotrauma
|
||||
existingStock.Quantity =
|
||||
Math.Min(
|
||||
existingStock.Quantity + 1,
|
||||
priceInfo.MaxAvailableAmount > 0 ? priceInfo.MaxAvailableAmount : CargoManager.MaxQuantity);
|
||||
priceInfo.MaxAvailableAmount);
|
||||
}
|
||||
}
|
||||
else if (existingStock != null)
|
||||
{
|
||||
stockToRemove.Add(existingStock);
|
||||
stockToRemove.Add(existingStock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Barotrauma
|
||||
private readonly ImmutableArray<Sprite> portraits;
|
||||
|
||||
//<name, commonness>
|
||||
private readonly ImmutableArray<(Identifier Name, float Commonness)> hireableJobs;
|
||||
private readonly ImmutableArray<(Identifier Identifier, float Commonness, bool AlwaysAvailableIfMissingFromCrew)> hireableJobs;
|
||||
private readonly float totalHireableWeight;
|
||||
|
||||
public readonly Dictionary<int, float> CommonnessPerZone = new Dictionary<int, float>();
|
||||
@@ -226,7 +226,7 @@ namespace Barotrauma
|
||||
MinCountPerZone[zoneIndex] = minCount;
|
||||
}
|
||||
var portraits = new List<Sprite>();
|
||||
var hireableJobs = new List<(Identifier, float)>();
|
||||
var hireableJobs = new List<(Identifier, float, bool)>();
|
||||
foreach (var subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
@@ -234,8 +234,9 @@ namespace Barotrauma
|
||||
case "hireable":
|
||||
Identifier jobIdentifier = subElement.GetAttributeIdentifier("identifier", Identifier.Empty);
|
||||
float jobCommonness = subElement.GetAttributeFloat("commonness", 1.0f);
|
||||
bool availableIfMissing = subElement.GetAttributeBool("AlwaysAvailableIfMissingFromCrew", false);
|
||||
totalHireableWeight += jobCommonness;
|
||||
hireableJobs.Add((jobIdentifier, jobCommonness));
|
||||
hireableJobs.Add((jobIdentifier, jobCommonness, availableIfMissing));
|
||||
break;
|
||||
case "symbol":
|
||||
Sprite = new Sprite(subElement, lazyLoad: true);
|
||||
@@ -270,16 +271,33 @@ namespace Barotrauma
|
||||
this.hireableJobs = hireableJobs.ToImmutableArray();
|
||||
}
|
||||
|
||||
public IEnumerable<JobPrefab> GetHireablesMissingFromCrew()
|
||||
{
|
||||
if (GameMain.GameSession?.CrewManager != null)
|
||||
{
|
||||
var missingJobs = hireableJobs
|
||||
.Where(j => j.AlwaysAvailableIfMissingFromCrew)
|
||||
.Where(j => GameMain.GameSession.CrewManager.GetCharacterInfos().None(c => c.Job?.Prefab.Identifier == j.Identifier));
|
||||
if (missingJobs.Any())
|
||||
{
|
||||
foreach (var missingJob in missingJobs)
|
||||
{
|
||||
if (JobPrefab.Prefabs.TryGet(missingJob.Identifier, out JobPrefab job))
|
||||
{
|
||||
yield return job;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public JobPrefab GetRandomHireable()
|
||||
{
|
||||
float randFloat = Rand.Range(0.0f, totalHireableWeight, Rand.RandSync.ServerAndClient);
|
||||
|
||||
foreach ((Identifier jobIdentifier, float commonness) in hireableJobs)
|
||||
Identifier selectedJobId = hireableJobs.GetRandomByWeight(j => j.Commonness, Rand.RandSync.ServerAndClient).Identifier;
|
||||
if (JobPrefab.Prefabs.TryGet(selectedJobId, out JobPrefab job))
|
||||
{
|
||||
if (randFloat < commonness) { return JobPrefab.Prefabs[jobIdentifier]; }
|
||||
randFloat -= commonness;
|
||||
return job;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -261,8 +261,7 @@ namespace Barotrauma
|
||||
|
||||
foreach (var endLocation in EndLocations)
|
||||
{
|
||||
if (endLocation.Type?.ForceLocationName != null &&
|
||||
!endLocation.Type.ForceLocationName.IsEmpty)
|
||||
if (endLocation.Type?.ForceLocationName is { IsEmpty: false })
|
||||
{
|
||||
endLocation.ForceName(endLocation.Type.ForceLocationName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user