/// <summary>Remove gold from an RpgAccount.</summary> /// <exception cref="NotEnoughGoldException"></exception> public static void RemoveGold(this RpgAccount account, uint amount) { if (!account.HasEnoughGold(amount)) { throw new NotEnoughGoldException(); } account.RemoveItemCount(GoldId, amount); }
/// <summary>Transfers gold from one RpgAccount to another.</summary> /// <exception cref="NotEnoughGoldException"></exception> public static void TransferGold(this RpgAccount source, RpgAccount target, uint amount) { if (!source.HasEnoughGold(amount)) { throw new NotEnoughGoldException(); } source.RemoveGold(amount); target.AddGold(amount); }
/// <summary> /// Adds an item based on item ID. /// </summary> public static void AddItemById(this RpgAccount account, uint itemId, uint amount) { var targetSlot = account.InventorySlots.FirstOrDefault(s => s.Item.Id == itemId); if (targetSlot is null) { account.ForceAddItemById(itemId, amount); return; } targetSlot.Amount += amount; }
public void ForceAddItem_ValidTest() { var acc = new RpgAccount(); Assert.True(acc.InventorySlots.Count == 0); acc.ForceAddItemById(itemId: 1, amount: 5); Assert.True(acc.InventorySlots.Count == 1); Assert.True(acc.InventorySlots.First().Amount == 5); Assert.True(acc.InventorySlots.First().Item.Id == 1); }
public static StatUpgradeResult UpgradeEndurance(this RpgAccount account) { var cost = JustineCore.Utilities.GetGeneralCurveCost((int)(account.Endurance + 1)); var gold = account.GetItemCount(1); if (cost > gold) { return(StatUpgradeResult.NotEnoughGold); } account.RemoveItemCount(1, (uint)cost); account.Endurance++; return(StatUpgradeResult.Success); }
public static StatUpgradeResult HealFor50(this RpgAccount account) { var cost = 50; var gold = account.GetItemCount(1); if (50 > gold) { return(StatUpgradeResult.NotEnoughGold); } account.RemoveItemCount(1, (uint)cost); account.Health = Math.Clamp(account.Health + 50, 0, account.MaxHealth); return(StatUpgradeResult.Success); }
public static string GetStringReport(this RpgAccount account) { var gold = account.GetGoldAmount(); return($@"``` Gold: {gold} [N/A] Health: ..... {account.Health} / {account.MaxHealth} [STR] Strength: ... {account.Strength} | {JustineCore.Utilities.GetGeneralCurveCost(account.Strength + 1)} gold to upgrade. [SPD] Speed: ...... {account.Speed} | {JustineCore.Utilities.GetGeneralCurveCost(account.Speed + 1)} gold to upgrade. [INT] Intelligence: {account.Intelligence} | {JustineCore.Utilities.GetGeneralCurveCost(account.Intelligence + 1)} gold to upgrade. [END] Endurance: .. {account.Endurance} | {JustineCore.Utilities.GetGeneralCurveCost(account.Endurance + 1)} gold to upgrade. [LCK] Luck: ....... {account.Luck} | {JustineCore.Utilities.GetGeneralCurveCost(account.Luck + 1)} gold to upgrade. ```"); }
public static void RemoveItemCount(this RpgAccount account, uint itemId, uint amount) { var targetSlot = account.InventorySlots.FirstOrDefault(s => s.Item.Id == itemId); if (targetSlot is null) { return; } if (targetSlot.Amount <= amount) { account.InventorySlots.Remove(targetSlot); } else { targetSlot.Amount -= amount; } }
/// <summary> /// Force adds an item. This will bypass any slot capacity limitations, and not enough slots limitations. /// </summary> /// <param name="account">Target RPG account</param> /// <param name="itemId">ID of the desired item</param> /// <param name="amount">Amount of the item to be added</param> public static void ForceAddItemById(this RpgAccount account, uint itemId, uint amount) { if (account.HasItem(itemId)) { var targetSlot = account.InventorySlots.FirstOrDefault(s => s.Amount != 0 && s.Item.Id == itemId); if (targetSlot is null) { return; } targetSlot.Amount += amount; } else { account.InventorySlots.Add(new InventorySlot { Amount = amount, Item = new InventoryItem(itemId) }); } }
public static void AddHealth(this RpgAccount account, int amount) { account.Health = Math.Clamp(account.Health + amount, 0, account.MaxHealth); }
public static void AddGold(this RpgAccount account, uint amount) { account.AddItemById(GoldId, amount); }
public static bool HasEnoughGold(this RpgAccount account, uint minimum) { return(account.GetGoldAmount() >= minimum); }
public static uint GetGoldAmount(this RpgAccount account) { return(account.GetItemCount(GoldId)); }
/// <summary> /// Gets a number of items of a certain type owned. (0 if not found) /// </summary> public static uint GetItemCount(this RpgAccount accout, uint itemId) { return((uint)accout.InventorySlots.Where(s => s.Item.Id == itemId).Sum(s => s.Amount)); }
/// <summary> /// Determines if the account has an item with a particular ID. /// </summary> /// <param name="account">target account</param> /// <param name="itemId">item ID</param> /// <returns>true if the the account has an item with that ID.</returns> public static bool HasItem(this RpgAccount account, uint itemId) { return(account.InventorySlots.Any(s => s.Amount != 0 && s.Item.Id == itemId)); }
public static void GiveDamage(this RpgAccount account, int damage) { account.Health = Math.Clamp(account.Health - damage, 0, account.MaxHealth); }