[Fix] Code visual
This commit is contained in:
@@ -6,80 +6,79 @@ using YachtDice.Modifiers;
|
||||
|
||||
namespace YachtDice.Shop
|
||||
{
|
||||
|
||||
public sealed class ShopModel
|
||||
{
|
||||
private readonly CurrencyBank currencyBank;
|
||||
private readonly InventoryModel inventoryModel;
|
||||
private readonly HashSet<string> purchasedPermanentIds = new();
|
||||
|
||||
public event Action<ModifierData> OnItemPurchased;
|
||||
|
||||
public ShopModel(CurrencyBank currencyBank, InventoryModel inventoryModel)
|
||||
public class ShopModel
|
||||
{
|
||||
this.currencyBank = currencyBank;
|
||||
this.inventoryModel = inventoryModel;
|
||||
private readonly CurrencyBank currencyBank;
|
||||
private readonly InventoryModel inventoryModel;
|
||||
private readonly HashSet<string> purchasedPermanentIds = new();
|
||||
|
||||
public event Action<ModifierData> OnItemPurchased;
|
||||
|
||||
public ShopModel(CurrencyBank currencyBank, InventoryModel inventoryModel)
|
||||
{
|
||||
this.currencyBank = currencyBank;
|
||||
this.inventoryModel = inventoryModel;
|
||||
}
|
||||
|
||||
public bool CanPurchase(ModifierData modifier)
|
||||
{
|
||||
if (modifier == null) return false;
|
||||
if (!currencyBank.CanAfford(modifier.ShopPrice)) return false;
|
||||
|
||||
if (modifier.Durability == ModifierDurability.Permanent &&
|
||||
purchasedPermanentIds.Contains(modifier.Id))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryPurchase(ModifierData modifier)
|
||||
{
|
||||
if (!CanPurchase(modifier)) return false;
|
||||
|
||||
if (!currencyBank.Spend(modifier.ShopPrice)) return false;
|
||||
|
||||
if (modifier.Durability == ModifierDurability.Permanent)
|
||||
purchasedPermanentIds.Add(modifier.Id);
|
||||
|
||||
inventoryModel.AddModifier(modifier);
|
||||
OnItemPurchased?.Invoke(modifier);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsPermanentOwned(string modifierId) => purchasedPermanentIds.Contains(modifierId);
|
||||
|
||||
public ShopItemState GetItemState(ModifierData modifier)
|
||||
{
|
||||
if (modifier == null) return ShopItemState.TooExpensive;
|
||||
|
||||
if (modifier.Durability == ModifierDurability.Permanent &&
|
||||
purchasedPermanentIds.Contains(modifier.Id))
|
||||
return ShopItemState.Owned;
|
||||
|
||||
if (!currencyBank.CanAfford(modifier.ShopPrice))
|
||||
return ShopItemState.TooExpensive;
|
||||
|
||||
return modifier.Durability == ModifierDurability.LimitedUses
|
||||
? ShopItemState.RepurchaseAvailable
|
||||
: ShopItemState.Available;
|
||||
}
|
||||
|
||||
public void LoadPurchasedPermanentIds(IEnumerable<string> ids)
|
||||
{
|
||||
purchasedPermanentIds.Clear();
|
||||
if (ids != null)
|
||||
foreach (var id in ids) purchasedPermanentIds.Add(id);
|
||||
}
|
||||
|
||||
public HashSet<string> GetPurchasedPermanentIds() => new(purchasedPermanentIds);
|
||||
}
|
||||
|
||||
public bool CanPurchase(ModifierData modifier)
|
||||
public enum ShopItemState
|
||||
{
|
||||
if (modifier == null) return false;
|
||||
if (!currencyBank.CanAfford(modifier.ShopPrice)) return false;
|
||||
|
||||
if (modifier.Durability == ModifierDurability.Permanent &&
|
||||
purchasedPermanentIds.Contains(modifier.Id))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
Available,
|
||||
TooExpensive,
|
||||
Owned,
|
||||
RepurchaseAvailable
|
||||
}
|
||||
|
||||
public bool TryPurchase(ModifierData modifier)
|
||||
{
|
||||
if (!CanPurchase(modifier)) return false;
|
||||
|
||||
if (!currencyBank.Spend(modifier.ShopPrice)) return false;
|
||||
|
||||
if (modifier.Durability == ModifierDurability.Permanent)
|
||||
purchasedPermanentIds.Add(modifier.Id);
|
||||
|
||||
inventoryModel.AddModifier(modifier);
|
||||
OnItemPurchased?.Invoke(modifier);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsPermanentOwned(string modifierId) => purchasedPermanentIds.Contains(modifierId);
|
||||
|
||||
public ShopItemState GetItemState(ModifierData modifier)
|
||||
{
|
||||
if (modifier == null) return ShopItemState.TooExpensive;
|
||||
|
||||
if (modifier.Durability == ModifierDurability.Permanent &&
|
||||
purchasedPermanentIds.Contains(modifier.Id))
|
||||
return ShopItemState.Owned;
|
||||
|
||||
if (!currencyBank.CanAfford(modifier.ShopPrice))
|
||||
return ShopItemState.TooExpensive;
|
||||
|
||||
return modifier.Durability == ModifierDurability.LimitedUses
|
||||
? ShopItemState.RepurchaseAvailable
|
||||
: ShopItemState.Available;
|
||||
}
|
||||
|
||||
public void LoadPurchasedPermanentIds(IEnumerable<string> ids)
|
||||
{
|
||||
purchasedPermanentIds.Clear();
|
||||
if (ids != null)
|
||||
foreach (var id in ids) purchasedPermanentIds.Add(id);
|
||||
}
|
||||
|
||||
public HashSet<string> GetPurchasedPermanentIds() => new(purchasedPermanentIds);
|
||||
}
|
||||
|
||||
public enum ShopItemState
|
||||
{
|
||||
Available,
|
||||
TooExpensive,
|
||||
Owned,
|
||||
RepurchaseAvailable
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user