[Add] Dice & Refactor private names
This commit is contained in:
@@ -10,26 +10,26 @@ namespace YachtDice.Shop
|
||||
{
|
||||
public class ShopModel
|
||||
{
|
||||
private readonly CurrencyBank currencyBank;
|
||||
private readonly InventoryModel inventoryModel;
|
||||
private readonly DiceCollection diceCollection;
|
||||
private readonly HashSet<string> purchasedPermanentIds = new();
|
||||
private readonly CurrencyBank _currencyBank;
|
||||
private readonly InventoryModel _inventoryModel;
|
||||
private readonly DiceCollection _diceCollection;
|
||||
private readonly HashSet<string> _purchasedPermanentIds = new();
|
||||
|
||||
public event Action<IShopItem> OnItemPurchased;
|
||||
|
||||
public ShopModel(CurrencyBank currencyBank, InventoryModel inventoryModel, DiceCollection diceCollection)
|
||||
{
|
||||
this.currencyBank = currencyBank;
|
||||
this.inventoryModel = inventoryModel;
|
||||
this.diceCollection = diceCollection;
|
||||
this._currencyBank = currencyBank;
|
||||
this._inventoryModel = inventoryModel;
|
||||
this._diceCollection = diceCollection;
|
||||
}
|
||||
|
||||
public bool CanPurchase(IShopItem item)
|
||||
{
|
||||
if (item == null) return false;
|
||||
if (!currencyBank.CanAfford(item.ShopPrice)) return false;
|
||||
if (!_currencyBank.CanAfford(item.ShopPrice)) return false;
|
||||
|
||||
if (!item.IsRepurchasable && purchasedPermanentIds.Contains(item.Id))
|
||||
if (!item.IsRepurchasable && _purchasedPermanentIds.Contains(item.Id))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -39,18 +39,18 @@ namespace YachtDice.Shop
|
||||
{
|
||||
if (!CanPurchase(item)) return false;
|
||||
|
||||
if (!currencyBank.Spend(item.ShopPrice)) return false;
|
||||
if (!_currencyBank.Spend(item.ShopPrice)) return false;
|
||||
|
||||
if (!item.IsRepurchasable)
|
||||
purchasedPermanentIds.Add(item.Id);
|
||||
_purchasedPermanentIds.Add(item.Id);
|
||||
|
||||
switch (item)
|
||||
{
|
||||
case ModifierDefinition modifier:
|
||||
inventoryModel.AddModifier(modifier);
|
||||
_inventoryModel.AddModifier(modifier);
|
||||
break;
|
||||
case DiceDefinition dice:
|
||||
diceCollection.Add(dice);
|
||||
_diceCollection.Add(dice);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -58,16 +58,16 @@ namespace YachtDice.Shop
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsPermanentOwned(string itemId) => purchasedPermanentIds.Contains(itemId);
|
||||
public bool IsPermanentOwned(string itemId) => _purchasedPermanentIds.Contains(itemId);
|
||||
|
||||
public ShopItemState GetItemState(IShopItem item)
|
||||
{
|
||||
if (item == null) return ShopItemState.TooExpensive;
|
||||
|
||||
if (!item.IsRepurchasable && purchasedPermanentIds.Contains(item.Id))
|
||||
if (!item.IsRepurchasable && _purchasedPermanentIds.Contains(item.Id))
|
||||
return ShopItemState.Owned;
|
||||
|
||||
if (!currencyBank.CanAfford(item.ShopPrice))
|
||||
if (!_currencyBank.CanAfford(item.ShopPrice))
|
||||
return ShopItemState.TooExpensive;
|
||||
|
||||
return item.IsRepurchasable
|
||||
@@ -77,12 +77,12 @@ namespace YachtDice.Shop
|
||||
|
||||
public void LoadPurchasedPermanentIds(IEnumerable<string> ids)
|
||||
{
|
||||
purchasedPermanentIds.Clear();
|
||||
_purchasedPermanentIds.Clear();
|
||||
if (ids != null)
|
||||
foreach (var id in ids) purchasedPermanentIds.Add(id);
|
||||
foreach (var id in ids) _purchasedPermanentIds.Add(id);
|
||||
}
|
||||
|
||||
public HashSet<string> GetPurchasedPermanentIds() => new(purchasedPermanentIds);
|
||||
public HashSet<string> GetPurchasedPermanentIds() => new(_purchasedPermanentIds);
|
||||
}
|
||||
|
||||
public enum ShopItemState
|
||||
|
||||
Reference in New Issue
Block a user