Implement money utility APIs

Part of #6
This commit is contained in:
zontreck 2025-06-05 16:44:48 -07:00
parent ac8ac62d27
commit a88807045e
4 changed files with 164 additions and 43 deletions

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.ConstrainedExecution;
using Vintagestory.API.Common;
using Vintagestory.API.Server;
namespace AriasServerUtils
@ -114,10 +115,39 @@ namespace AriasServerUtils
public Dictionary<string, Warp> warps = new Dictionary<string, Warp>();
}
/// <summary>
/// This contains per command costs, as well as helper functions that can refund a player, or check if the player has the required balance, or payment
///
/// </summary>
[Serializable]
public class Costs
{
public Dictionary<string, int> costs = new Dictionary<string, int>();
/// <summary>
/// Checks if the player has the balance required to use the command
/// </summary>
/// <param name="cmd">The command the player is trying to use</param>
/// <param name="player">The player</param>
/// <returns>True if the player has the required balance</returns>
public bool PlayerHasBalance(string cmd, EntityPlayer player)
{
int gears = 0;
int required = 0;
if (costs.ContainsKey(cmd))
{
// Get the cost for that command
required = costs[cmd];
}
// Scan the player inventory, check gears
if (gears >= required) return true;
return false;
}
}