Unstable 0.17.4.0
This commit is contained in:
@@ -30,23 +30,21 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
#if CLIENT
|
||||
public PurchasedItem(ItemPrefab itemPrefab, int quantity, Client buyer = null)
|
||||
public PurchasedItem(ItemPrefab itemPrefab, int quantity)
|
||||
: this(itemPrefab, quantity, buyer: null) { }
|
||||
#endif
|
||||
public PurchasedItem(ItemPrefab itemPrefab, int quantity, Client buyer)
|
||||
{
|
||||
ItemPrefab = itemPrefab;
|
||||
Quantity = quantity;
|
||||
IsStoreComponentEnabled = null;
|
||||
BuyerCharacterInfoId = buyer?.Character?.Info?.ID ?? Character.Controlled?.Info?.ID ?? 0;
|
||||
}
|
||||
#elif SERVER
|
||||
public PurchasedItem(ItemPrefab itemPrefab, int quantity, Client buyer)
|
||||
{
|
||||
ItemPrefab = itemPrefab;
|
||||
Quantity = quantity;
|
||||
IsStoreComponentEnabled = null;
|
||||
BuyerCharacterInfoId = buyer?.Character?.Info?.ID ?? 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{ItemPrefab.Name} ({Quantity})";
|
||||
}
|
||||
}
|
||||
|
||||
class SoldItem
|
||||
@@ -133,11 +131,11 @@ namespace Barotrauma
|
||||
|
||||
public const int MaxQuantity = 100;
|
||||
|
||||
public List<PurchasedItem> ItemsInBuyCrate { get; } = new List<PurchasedItem>();
|
||||
public List<PurchasedItem> ItemsInSellCrate { get; } = new List<PurchasedItem>();
|
||||
public List<PurchasedItem> ItemsInSellFromSubCrate { get; } = new List<PurchasedItem>();
|
||||
public List<PurchasedItem> PurchasedItems { get; } = new List<PurchasedItem>();
|
||||
public List<SoldItem> SoldItems { get; } = new List<SoldItem>();
|
||||
public Dictionary<Identifier, List<PurchasedItem>> ItemsInBuyCrate { get; } = new Dictionary<Identifier, List<PurchasedItem>>();
|
||||
public Dictionary<Identifier, List<PurchasedItem>> ItemsInSellCrate { get; } = new Dictionary<Identifier, List<PurchasedItem>>();
|
||||
public Dictionary<Identifier, List<PurchasedItem>> ItemsInSellFromSubCrate { get; } = new Dictionary<Identifier, List<PurchasedItem>>();
|
||||
public Dictionary<Identifier, List<PurchasedItem>> PurchasedItems { get; } = new Dictionary<Identifier, List<PurchasedItem>>();
|
||||
public Dictionary<Identifier, List<SoldItem>> SoldItems { get; } = new Dictionary<Identifier, List<SoldItem>>();
|
||||
|
||||
private readonly CampaignMode campaign;
|
||||
|
||||
@@ -154,6 +152,60 @@ namespace Barotrauma
|
||||
this.campaign = campaign;
|
||||
}
|
||||
|
||||
private List<T> GetItems<T>(Identifier identifier, Dictionary<Identifier, List<T>> items, bool create = false)
|
||||
{
|
||||
if (items.TryGetValue(identifier, out var storeSpecificItems) && storeSpecificItems != null)
|
||||
{
|
||||
return storeSpecificItems;
|
||||
}
|
||||
else if (create)
|
||||
{
|
||||
storeSpecificItems = new List<T>();
|
||||
items.Add(identifier, storeSpecificItems);
|
||||
return storeSpecificItems;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<T>();
|
||||
}
|
||||
}
|
||||
|
||||
public List<PurchasedItem> GetBuyCrateItems(Identifier identifier, bool create = false) => GetItems(identifier, ItemsInBuyCrate, create);
|
||||
|
||||
public List<PurchasedItem> GetBuyCrateItems(Location.StoreInfo store, bool create = false) => GetBuyCrateItems(store?.Identifier ?? Identifier.Empty, create);
|
||||
|
||||
public PurchasedItem GetBuyCrateItem(Identifier identifier, ItemPrefab prefab) => GetBuyCrateItems(identifier)?.FirstOrDefault(i => i.ItemPrefab == prefab);
|
||||
|
||||
public PurchasedItem GetBuyCrateItem(Location.StoreInfo store, ItemPrefab prefab) => GetBuyCrateItem(store?.Identifier ?? Identifier.Empty, prefab);
|
||||
|
||||
public List<PurchasedItem> GetSellCrateItems(Identifier identifier, bool create = false) => GetItems(identifier, ItemsInSellCrate, create);
|
||||
|
||||
public List<PurchasedItem> GetSellCrateItems(Location.StoreInfo store, bool create = false) => GetSellCrateItems(store?.Identifier ?? Identifier.Empty, create);
|
||||
|
||||
public PurchasedItem GetSellCrateItem(Identifier identifier, ItemPrefab prefab) => GetSellCrateItems(identifier)?.FirstOrDefault(i => i.ItemPrefab == prefab);
|
||||
|
||||
public PurchasedItem GetSellCrateItem(Location.StoreInfo store, ItemPrefab prefab) => GetSellCrateItem(store?.Identifier ?? Identifier.Empty, prefab);
|
||||
|
||||
public List<PurchasedItem> GetSubCrateItems(Identifier identifier, bool create = false) => GetItems(identifier, ItemsInSellFromSubCrate, create);
|
||||
|
||||
public List<PurchasedItem> GetSubCrateItems(Location.StoreInfo store, bool create = false) => GetSubCrateItems(store?.Identifier ?? Identifier.Empty, create);
|
||||
|
||||
public PurchasedItem GetSubCrateItem(Identifier identifier, ItemPrefab prefab) => GetSubCrateItems(identifier)?.FirstOrDefault(i => i.ItemPrefab == prefab);
|
||||
|
||||
public PurchasedItem GetSubCrateItem(Location.StoreInfo store, ItemPrefab prefab) => GetSubCrateItem(store?.Identifier ?? Identifier.Empty, prefab);
|
||||
|
||||
public List<PurchasedItem> GetPurchasedItems(Identifier identifier, bool create = false) => GetItems(identifier, PurchasedItems, create);
|
||||
|
||||
public List<PurchasedItem> GetPurchasedItems(Location.StoreInfo store, bool create = false) => GetPurchasedItems(store?.Identifier ?? Identifier.Empty, create);
|
||||
|
||||
public PurchasedItem GetPurchasedItem(Identifier identifier, ItemPrefab prefab) => GetPurchasedItems(identifier)?.FirstOrDefault(i => i.ItemPrefab == prefab);
|
||||
|
||||
public PurchasedItem GetPurchasedItem(Location.StoreInfo store, ItemPrefab prefab) => GetPurchasedItem(store?.Identifier ?? Identifier.Empty, prefab);
|
||||
|
||||
public List<SoldItem> GetSoldItems(Identifier identifier, bool create = false) => GetItems(identifier, SoldItems, create);
|
||||
|
||||
public List<SoldItem> GetSoldItems(Location.StoreInfo store, bool create = false) => GetSoldItems(store?.Identifier ?? Identifier.Empty, create);
|
||||
|
||||
public void ClearItemsInBuyCrate()
|
||||
{
|
||||
ItemsInBuyCrate.Clear();
|
||||
@@ -172,61 +224,62 @@ namespace Barotrauma
|
||||
OnItemsInSellFromSubCrateChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void SetPurchasedItems(List<PurchasedItem> items)
|
||||
public void SetPurchasedItems(Dictionary<Identifier, List<PurchasedItem>> purchasedItems)
|
||||
{
|
||||
PurchasedItems.Clear();
|
||||
PurchasedItems.AddRange(items);
|
||||
foreach (var entry in purchasedItems)
|
||||
{
|
||||
PurchasedItems.Add(entry.Key, entry.Value);
|
||||
}
|
||||
OnPurchasedItemsChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void ModifyItemQuantityInBuyCrate(ItemPrefab itemPrefab, int changeInQuantity, Client client = null)
|
||||
public void ModifyItemQuantityInBuyCrate(Identifier storeIdentifier, ItemPrefab itemPrefab, int changeInQuantity, Client client = null)
|
||||
{
|
||||
var itemInCrate = ItemsInBuyCrate.Find(i => i.ItemPrefab == itemPrefab);
|
||||
if (itemInCrate != null)
|
||||
if (GetBuyCrateItem(storeIdentifier, itemPrefab) is { } item)
|
||||
{
|
||||
itemInCrate.Quantity += changeInQuantity;
|
||||
if (itemInCrate.Quantity < 1)
|
||||
item.Quantity += changeInQuantity;
|
||||
if (item.Quantity < 1)
|
||||
{
|
||||
ItemsInBuyCrate.Remove(itemInCrate);
|
||||
GetBuyCrateItems(storeIdentifier, create: true).Remove(item);
|
||||
}
|
||||
}
|
||||
else if (changeInQuantity > 0)
|
||||
{
|
||||
itemInCrate = new PurchasedItem(itemPrefab, changeInQuantity, client);
|
||||
ItemsInBuyCrate.Add(itemInCrate);
|
||||
GetBuyCrateItems(storeIdentifier, create: true).Add(new PurchasedItem(itemPrefab, changeInQuantity, client));
|
||||
}
|
||||
OnItemsInBuyCrateChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void ModifyItemQuantityInSubSellCrate(ItemPrefab itemPrefab, int changeInQuantity, Client client = null)
|
||||
public void ModifyItemQuantityInSubSellCrate(Identifier storeIdentifier, ItemPrefab itemPrefab, int changeInQuantity, Client client = null)
|
||||
{
|
||||
var itemInCrate = ItemsInSellFromSubCrate.Find(i => i.ItemPrefab == itemPrefab);
|
||||
if (itemInCrate != null)
|
||||
if (GetSubCrateItem(storeIdentifier, itemPrefab) is { } item)
|
||||
{
|
||||
itemInCrate.Quantity += changeInQuantity;
|
||||
if (itemInCrate.Quantity < 1)
|
||||
item.Quantity += changeInQuantity;
|
||||
if (item.Quantity < 1)
|
||||
{
|
||||
ItemsInSellFromSubCrate.Remove(itemInCrate);
|
||||
GetSubCrateItems(storeIdentifier)?.Remove(item);
|
||||
}
|
||||
}
|
||||
else if (changeInQuantity > 0)
|
||||
{
|
||||
itemInCrate = new PurchasedItem(itemPrefab, changeInQuantity, client);
|
||||
ItemsInSellFromSubCrate.Add(itemInCrate);
|
||||
GetSubCrateItems(storeIdentifier, create: true).Add(new PurchasedItem(itemPrefab, changeInQuantity, client));
|
||||
}
|
||||
OnItemsInSellFromSubCrateChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void PurchaseItems(List<PurchasedItem> itemsToPurchase, bool removeFromCrate, Client client = null)
|
||||
public void PurchaseItems(Identifier storeIdentifier, List<PurchasedItem> itemsToPurchase, bool removeFromCrate, Client client = null)
|
||||
{
|
||||
// Check all the prices before starting the transaction
|
||||
// to make sure the modifiers stay the same for the whole transaction
|
||||
Dictionary<ItemPrefab, int> buyValues = GetBuyValuesAtCurrentLocation(itemsToPurchase.Select(i => i.ItemPrefab));
|
||||
|
||||
var store = Location.GetStore(storeIdentifier);
|
||||
if (store == null) { return; }
|
||||
var itemsPurchasedFromStore = GetPurchasedItems(storeIdentifier, create: true);
|
||||
// Check all the prices before starting the transaction to make sure the modifiers stay the same for the whole transaction
|
||||
var buyValues = GetBuyValuesAtCurrentLocation(storeIdentifier, itemsToPurchase.Select(i => i.ItemPrefab));
|
||||
var itemsInStoreCrate = GetBuyCrateItems(storeIdentifier, create: true);
|
||||
foreach (PurchasedItem item in itemsToPurchase)
|
||||
{
|
||||
// Add to the purchased items
|
||||
var purchasedItem = PurchasedItems.Find(pi => pi.ItemPrefab == item.ItemPrefab);
|
||||
var purchasedItem = itemsPurchasedFromStore.Find(pi => pi.ItemPrefab == item.ItemPrefab);
|
||||
if (purchasedItem != null)
|
||||
{
|
||||
purchasedItem.Quantity += item.Quantity;
|
||||
@@ -234,53 +287,54 @@ namespace Barotrauma
|
||||
else
|
||||
{
|
||||
purchasedItem = new PurchasedItem(item.ItemPrefab, item.Quantity, client);
|
||||
PurchasedItems.Add(purchasedItem);
|
||||
itemsPurchasedFromStore.Add(purchasedItem);
|
||||
}
|
||||
|
||||
// Exchange money
|
||||
var itemValue = item.Quantity * buyValues[item.ItemPrefab];
|
||||
int itemValue = item.Quantity * buyValues[item.ItemPrefab];
|
||||
campaign.GetWallet(client).TryDeduct(itemValue);
|
||||
GameAnalyticsManager.AddMoneySpentEvent(itemValue, GameAnalyticsManager.MoneySink.Store, item.ItemPrefab.Identifier.Value);
|
||||
Location.StoreCurrentBalance += itemValue;
|
||||
|
||||
store.Balance += itemValue;
|
||||
if (removeFromCrate)
|
||||
{
|
||||
// Remove from the shopping crate
|
||||
var crateItem = ItemsInBuyCrate.Find(pi => pi.ItemPrefab == item.ItemPrefab);
|
||||
if (crateItem != null)
|
||||
if (itemsInStoreCrate.Find(pi => pi.ItemPrefab == item.ItemPrefab) is { } crateItem)
|
||||
{
|
||||
crateItem.Quantity -= item.Quantity;
|
||||
if (crateItem.Quantity < 1) { ItemsInBuyCrate.Remove(crateItem); }
|
||||
if (crateItem.Quantity < 1) { itemsInStoreCrate.Remove(crateItem); }
|
||||
}
|
||||
}
|
||||
}
|
||||
OnPurchasedItemsChanged?.Invoke();
|
||||
}
|
||||
|
||||
public Dictionary<ItemPrefab, int> GetBuyValuesAtCurrentLocation(IEnumerable<ItemPrefab> items)
|
||||
public Dictionary<ItemPrefab, int> GetBuyValuesAtCurrentLocation(Identifier storeIdentifier, IEnumerable<ItemPrefab> items)
|
||||
{
|
||||
var buyValues = new Dictionary<ItemPrefab, int>();
|
||||
var store = Location?.GetStore(storeIdentifier);
|
||||
if (store == null) { return buyValues; }
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item == null) { continue; }
|
||||
if (!buyValues.ContainsKey(item))
|
||||
{
|
||||
var buyValue = Location?.GetAdjustedItemBuyPrice(item) ?? 0;
|
||||
int buyValue = store?.GetAdjustedItemBuyPrice(item) ?? 0;
|
||||
buyValues.Add(item, buyValue);
|
||||
}
|
||||
}
|
||||
return buyValues;
|
||||
}
|
||||
|
||||
public Dictionary<ItemPrefab, int> GetSellValuesAtCurrentLocation(IEnumerable<ItemPrefab> items)
|
||||
public Dictionary<ItemPrefab, int> GetSellValuesAtCurrentLocation(Identifier storeIdentifier, IEnumerable<ItemPrefab> items)
|
||||
{
|
||||
var sellValues = new Dictionary<ItemPrefab, int>();
|
||||
var store = Location?.GetStore(storeIdentifier);
|
||||
if (store == null) { return sellValues; }
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item == null) { continue; }
|
||||
if (!sellValues.ContainsKey(item))
|
||||
{
|
||||
var sellValue = Location?.GetAdjustedItemSellPrice(item) ?? 0;
|
||||
int sellValue = store?.GetAdjustedItemSellPrice(item) ?? 0;
|
||||
sellValues.Add(item, sellValue);
|
||||
}
|
||||
}
|
||||
@@ -289,7 +343,13 @@ namespace Barotrauma
|
||||
|
||||
public void CreatePurchasedItems()
|
||||
{
|
||||
CreateItems(PurchasedItems, Submarine.MainSub);
|
||||
var items = new List<PurchasedItem>();
|
||||
foreach (var storeSpecificItems in PurchasedItems)
|
||||
{
|
||||
items.AddRange(storeSpecificItems.Value);
|
||||
}
|
||||
CreateItems(items, Submarine.MainSub);
|
||||
PurchasedItems.Clear();
|
||||
OnPurchasedItemsChanged?.Invoke();
|
||||
}
|
||||
|
||||
@@ -509,33 +569,41 @@ namespace Barotrauma
|
||||
public void SavePurchasedItems(XElement parentElement)
|
||||
{
|
||||
var itemsElement = new XElement("cargo");
|
||||
foreach (PurchasedItem item in PurchasedItems)
|
||||
foreach (var storeSpecificItems in PurchasedItems)
|
||||
{
|
||||
if (item?.ItemPrefab == null) { continue; }
|
||||
itemsElement.Add(new XElement("item",
|
||||
new XAttribute("id", item.ItemPrefab.Identifier),
|
||||
new XAttribute("qty", item.Quantity),
|
||||
new XAttribute("buyer", item.BuyerCharacterInfoId)));
|
||||
foreach (var item in storeSpecificItems.Value)
|
||||
{
|
||||
if (item?.ItemPrefab == null) { continue; }
|
||||
itemsElement.Add(new XElement("item",
|
||||
new XAttribute("id", item.ItemPrefab.Identifier),
|
||||
new XAttribute("qty", item.Quantity),
|
||||
new XAttribute("storeid", storeSpecificItems.Key),
|
||||
new XAttribute("buyer", item.BuyerCharacterInfoId)));
|
||||
}
|
||||
}
|
||||
parentElement.Add(itemsElement);
|
||||
}
|
||||
|
||||
public void LoadPurchasedItems(XElement element)
|
||||
{
|
||||
var purchasedItems = new List<PurchasedItem>();
|
||||
var purchasedItems = new Dictionary<Identifier, List<PurchasedItem>>();
|
||||
if (element != null)
|
||||
{
|
||||
foreach (XElement itemElement in element.GetChildElements("item"))
|
||||
{
|
||||
string id = itemElement.GetAttributeString("id", null);
|
||||
if (string.IsNullOrWhiteSpace(id)) { continue; }
|
||||
var prefab = ItemPrefab.Prefabs.Find(p => p.Identifier == id);
|
||||
string prefabId = itemElement.GetAttributeString("id", null);
|
||||
if (string.IsNullOrWhiteSpace(prefabId)) { continue; }
|
||||
var prefab = ItemPrefab.Prefabs.Find(p => p.Identifier == prefabId);
|
||||
if (prefab == null) { continue; }
|
||||
int qty = itemElement.GetAttributeInt("qty", 0);
|
||||
Identifier storeId = itemElement.GetAttributeIdentifier("storeid", "merchant");
|
||||
int buyerId = itemElement.GetAttributeInt("buyer", 0);
|
||||
|
||||
purchasedItems.Add(new PurchasedItem(prefab, qty, buyerId));
|
||||
|
||||
if (!purchasedItems.TryGetValue(storeId, out var storeItems))
|
||||
{
|
||||
storeItems = new List<PurchasedItem>();
|
||||
purchasedItems.Add(storeId, storeItems);
|
||||
}
|
||||
storeItems.Add(new PurchasedItem(prefab, qty, buyerId));
|
||||
}
|
||||
}
|
||||
SetPurchasedItems(purchasedItems);
|
||||
|
||||
@@ -25,12 +25,18 @@ namespace Barotrauma
|
||||
public int Balance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Network message for the server to update wallet values to clients
|
||||
/// </summary>
|
||||
internal struct NetWalletUpdate : INetSerializableStruct
|
||||
{
|
||||
[NetworkSerialize(ArrayMaxSize = NetConfig.MaxPlayers + 1)]
|
||||
public NetWalletTransaction[] Transactions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Network message for the client to transfer money between wallets
|
||||
/// </summary>
|
||||
[NetworkSerialize]
|
||||
internal struct NetWalletTransfer : INetSerializableStruct
|
||||
{
|
||||
@@ -39,7 +45,10 @@ namespace Barotrauma
|
||||
public int Amount;
|
||||
}
|
||||
|
||||
internal struct NetWalletSalaryUpdate : INetSerializableStruct
|
||||
/// <summary>
|
||||
/// Network message for the client to set the salary of someone
|
||||
/// </summary>
|
||||
internal struct NetWalletSetSalaryUpdate : INetSerializableStruct
|
||||
{
|
||||
[NetworkSerialize]
|
||||
public ushort Target;
|
||||
@@ -48,6 +57,10 @@ namespace Barotrauma
|
||||
public int NewRewardDistribution;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the difference in balance and salary when a wallet gets updated
|
||||
/// Not really used right now but could be used for notifications when receiving funds similar to how talents do it
|
||||
/// </summary>
|
||||
[NetworkSerialize]
|
||||
internal struct WalletChangedData : INetSerializableStruct
|
||||
{
|
||||
@@ -82,6 +95,9 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents an update that changed the amount of money or salary of the wallet
|
||||
/// </summary>
|
||||
[NetworkSerialize]
|
||||
internal struct NetWalletTransaction : INetSerializableStruct
|
||||
{
|
||||
|
||||
@@ -321,15 +321,32 @@ namespace Barotrauma
|
||||
}
|
||||
if (levelData.HasHuntingGrounds)
|
||||
{
|
||||
var huntingGroundsMissionPrefabs = MissionPrefab.Prefabs.Where(m => m.Tags.Any(t => t.Equals("huntinggroundsnoreward", StringComparison.OrdinalIgnoreCase)));
|
||||
var huntingGroundsMissionPrefabs = MissionPrefab.Prefabs.Where(m => m.Tags.Any(t => t.Equals("huntinggrounds", StringComparison.OrdinalIgnoreCase)));
|
||||
if (!huntingGroundsMissionPrefabs.Any())
|
||||
{
|
||||
DebugConsole.AddWarning("Could not find a hunting grounds mission for the level. No mission with the tag \"huntinggroundsnoreward\" found.");
|
||||
DebugConsole.AddWarning("Could not find a hunting grounds mission for the level. No mission with the tag \"huntinggrounds\" found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Random rand = new MTRandom(ToolBox.StringToInt(levelData.Seed));
|
||||
var huntingGroundsMissionPrefab = ToolBox.SelectWeightedRandom(huntingGroundsMissionPrefabs, p => (float)Math.Max(p.Commonness, 0.1f), rand);
|
||||
// Adjust the prefab commonness based on the difficulty tag
|
||||
var prefabs = huntingGroundsMissionPrefabs.ToList();
|
||||
var weights = prefabs.Select(p => (float)Math.Max(p.Commonness, 1)).ToList();
|
||||
for (int i = 0; i < prefabs.Count; i++)
|
||||
{
|
||||
var prefab = prefabs[i];
|
||||
var weight = weights[i];
|
||||
if (prefab.Tags.Contains("easy"))
|
||||
{
|
||||
weight *= MathHelper.Lerp(0.2f, 2f, MathUtils.InverseLerp(80, LevelData.HuntingGroundsDifficultyThreshold, levelData.Difficulty));
|
||||
}
|
||||
else if (prefab.Tags.Contains("hard"))
|
||||
{
|
||||
weight *= MathHelper.Lerp(0.5f, 1.5f, MathUtils.InverseLerp(LevelData.HuntingGroundsDifficultyThreshold + 10, 80, levelData.Difficulty));
|
||||
}
|
||||
weights[i] = weight;
|
||||
}
|
||||
var huntingGroundsMissionPrefab = ToolBox.SelectWeightedRandom(prefabs, weights, rand);
|
||||
if (!Missions.Any(m => m.Prefab.Tags.Any(t => t.Equals("huntinggrounds", StringComparison.OrdinalIgnoreCase))))
|
||||
{
|
||||
extraMissions.Add(huntingGroundsMissionPrefab.Instantiate(Map.SelectedConnection.Locations, Submarine.MainSub));
|
||||
@@ -596,22 +613,22 @@ namespace Barotrauma
|
||||
if (map != null && CargoManager != null)
|
||||
{
|
||||
map.CurrentLocation.RegisterTakenItems(takenItems);
|
||||
map.CurrentLocation.AddToStock(CargoManager.SoldItems);
|
||||
map.CurrentLocation.AddStock(CargoManager.SoldItems);
|
||||
CargoManager.ClearSoldItemsProjSpecific();
|
||||
map.CurrentLocation.RemoveFromStock(CargoManager.PurchasedItems);
|
||||
map.CurrentLocation.RemoveStock(CargoManager.PurchasedItems);
|
||||
}
|
||||
if (GameMain.NetworkMember == null)
|
||||
{
|
||||
CargoManager.ClearItemsInBuyCrate();
|
||||
CargoManager.ClearItemsInSellCrate();
|
||||
CargoManager.ClearItemsInSellFromSubCrate();
|
||||
CargoManager?.ClearItemsInBuyCrate();
|
||||
CargoManager?.ClearItemsInSellCrate();
|
||||
CargoManager?.ClearItemsInSellFromSubCrate();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GameMain.NetworkMember.IsServer)
|
||||
{
|
||||
CargoManager?.ClearItemsInBuyCrate();
|
||||
// TODO: CargoManager?.ClearItemsInSellFromSubCrate();
|
||||
CargoManager?.ClearItemsInSellFromSubCrate();
|
||||
}
|
||||
else if (GameMain.NetworkMember.IsClient)
|
||||
{
|
||||
@@ -772,6 +789,11 @@ namespace Barotrauma
|
||||
public void AssignNPCMenuInteraction(Character character, InteractionType interactionType)
|
||||
{
|
||||
character.CampaignInteractionType = interactionType;
|
||||
if (character.CampaignInteractionType == InteractionType.Store &&
|
||||
character.HumanPrefab is { Identifier: var merchantId })
|
||||
{
|
||||
character.MerchantIdentifier = merchantId;
|
||||
}
|
||||
character.DisableHealthWindow =
|
||||
interactionType != InteractionType.None &&
|
||||
interactionType != InteractionType.Examine &&
|
||||
|
||||
+74
-1
@@ -1,4 +1,5 @@
|
||||
using Barotrauma.IO;
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -211,7 +212,6 @@ namespace Barotrauma
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
public static List<SubmarineInfo> GetCampaignSubs()
|
||||
{
|
||||
bool isSubmarineVisible(SubmarineInfo s)
|
||||
@@ -242,5 +242,78 @@ namespace Barotrauma
|
||||
return availableSubs;
|
||||
}
|
||||
|
||||
private static void WriteItems(IWriteMessage msg, Dictionary<Identifier, List<PurchasedItem>> purchasedItems)
|
||||
{
|
||||
msg.Write((byte)purchasedItems.Count);
|
||||
foreach (var storeItems in purchasedItems)
|
||||
{
|
||||
msg.Write(storeItems.Key);
|
||||
msg.Write((UInt16)storeItems.Value.Count);
|
||||
foreach (var item in storeItems.Value)
|
||||
{
|
||||
msg.Write(item.ItemPrefab.Identifier);
|
||||
msg.WriteRangedInteger(item.Quantity, 0, CargoManager.MaxQuantity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<Identifier, List<PurchasedItem>> ReadPurchasedItems(IReadMessage msg, Client sender)
|
||||
{
|
||||
var items = new Dictionary<Identifier, List<PurchasedItem>>();
|
||||
byte storeCount = msg.ReadByte();
|
||||
for (int i = 0; i < storeCount; i++)
|
||||
{
|
||||
Identifier storeId = msg.ReadIdentifier();
|
||||
items.Add(storeId, new List<PurchasedItem>());
|
||||
UInt16 itemCount = msg.ReadUInt16();
|
||||
for (int j = 0; j < itemCount; j++)
|
||||
{
|
||||
Identifier itemId = msg.ReadIdentifier();
|
||||
int quantity = msg.ReadRangedInteger(0, CargoManager.MaxQuantity);
|
||||
items[storeId].Add(new PurchasedItem(ItemPrefab.Prefabs[itemId], quantity, sender));
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private static void WriteItems(IWriteMessage msg, Dictionary<Identifier, List<SoldItem>> soldItems)
|
||||
{
|
||||
msg.Write((byte)soldItems.Count);
|
||||
foreach (var storeItems in soldItems)
|
||||
{
|
||||
msg.Write(storeItems.Key);
|
||||
msg.Write((UInt16)storeItems.Value.Count);
|
||||
foreach (var item in storeItems.Value)
|
||||
{
|
||||
msg.Write(item.ItemPrefab.Identifier);
|
||||
msg.Write((UInt16)item.ID);
|
||||
msg.Write(item.Removed);
|
||||
msg.Write(item.SellerID);
|
||||
msg.Write((byte)item.Origin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<Identifier, List<SoldItem>> ReadSoldItems(IReadMessage msg)
|
||||
{
|
||||
var soldItems = new Dictionary<Identifier, List<SoldItem>>();
|
||||
byte storeCount = msg.ReadByte();
|
||||
for (int i = 0; i < storeCount; i++)
|
||||
{
|
||||
Identifier storeId = msg.ReadIdentifier();
|
||||
soldItems.Add(storeId, new List<SoldItem>());
|
||||
UInt16 itemCount = msg.ReadUInt16();
|
||||
for (int j = 0; j < storeCount; j++)
|
||||
{
|
||||
Identifier prefabId = msg.ReadIdentifier();
|
||||
UInt16 itemId = msg.ReadUInt16();
|
||||
bool removed = msg.ReadBoolean();
|
||||
byte sellerId = msg.ReadByte();
|
||||
byte origin = msg.ReadByte();
|
||||
soldItems[storeId].Add(new SoldItem(ItemPrefab.Prefabs[prefabId], itemId, removed, sellerId, (SoldItem.SellOrigin)origin));
|
||||
}
|
||||
}
|
||||
return soldItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -754,9 +754,9 @@ namespace Barotrauma
|
||||
|
||||
try
|
||||
{
|
||||
IEnumerable<Character> crewCharacters = GetSessionCrewCharacters();
|
||||
ImmutableArray<Character> crewCharacters = GetSessionCrewCharacters().ToImmutableArray();
|
||||
|
||||
int prevMoney = (GameMode as CampaignMode)?.Bank.Balance ?? 0; // FIXME personal wallets - reward distribution
|
||||
int prevMoney = GetAmountOfMoney(crewCharacters);
|
||||
|
||||
foreach (Mission mission in missions)
|
||||
{
|
||||
@@ -828,7 +828,7 @@ namespace Barotrauma
|
||||
LogEndRoundStats(eventId);
|
||||
if (GameMode is CampaignMode campaignMode)
|
||||
{
|
||||
GameAnalyticsManager.AddDesignEvent(eventId + "MoneyEarned", campaignMode.Bank.Balance - prevMoney); // FIXME personal wallets - reward distrubiton
|
||||
GameAnalyticsManager.AddDesignEvent(eventId + "MoneyEarned", GetAmountOfMoney(crewCharacters) - prevMoney);
|
||||
campaignMode.TotalPlayTime += roundDuration;
|
||||
}
|
||||
#if CLIENT
|
||||
@@ -840,6 +840,17 @@ namespace Barotrauma
|
||||
{
|
||||
RoundEnding = false;
|
||||
}
|
||||
|
||||
int GetAmountOfMoney(IEnumerable<Character> crew)
|
||||
{
|
||||
if (!(GameMode is CampaignMode campaign)) { return 0; }
|
||||
|
||||
return GameMain.NetworkMember switch
|
||||
{
|
||||
null => campaign.Bank.Balance,
|
||||
_ => crew.Sum(c => c.Wallet.Balance) + campaign.Bank.Balance
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void LogEndRoundStats(string eventId)
|
||||
|
||||
@@ -216,7 +216,7 @@ namespace Barotrauma
|
||||
price = 0;
|
||||
}
|
||||
|
||||
if (Campaign.GetWallet(client).TryDeduct(price)) // FIXME personal wallets
|
||||
if (Campaign.GetWallet(client).TryDeduct(price))
|
||||
{
|
||||
if (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user