public bool TryDeductCost(TSPlayer player, CustomSkillCost cost) { if (!CanAfford(player, cost)) { return(false); } if (cost == null) { return(true); } else { var tPlayer = Player.TPlayer; if (cost.RequiresHp) { tPlayer.statLife = Math.Max(0, tPlayer.statLife - cost.Hp); //send player life packet TSPlayer.All.SendData(PacketTypes.PlayerHp, "", Player.Index); //, tPlayer.statLife, tPlayer.statLifeMax ); } if (cost.RequiresMp) { tPlayer.statMana = Math.Max(0, tPlayer.statMana - cost.Mp); //send player mana packet TSPlayer.All.SendData(PacketTypes.PlayerMana, "", Player.Index); //, tPlayer.statMana, tPlayer.statManaMax); } var bank = BankingPlugin.Instance.Bank; if (bank == null) { return(true); //this probably is an error condition, but for now we just get out of dodge. } if (cost.RequiresExp) { var account = BankingPlugin.Instance.GetBankAccount(player, "Exp"); if (account != null) { var result = account.TryWithdraw(Math.Abs(cost.Exp), WithdrawalMode.RequireFullBalance); if (result == false) //player cant cover balance { return(false); } } else { return(false); } } if (cost.RequiresCurrency) { if (bank.CurrencyManager.TryFindCurrencyFromString(cost.Currency, out var currency)) { var account = bank.GetBankAccount(Player.Name, currency.InternalName); if (account != null) { //check for funds... Debug.Print($"Found bank account for {currency.InternalName}"); //parse currency.GetCurrencyConverter().TryParse(cost.Currency, out var rawValue); if (!account.TryWithdraw(rawValue, WithdrawalMode.RequireFullBalance)) { Debug.Print("Player bank balance is less than skill cost."); return(false); } } else { Debug.Print($"Did not find bank account for {currency.InternalName}"); } } } return(true); } }
public bool CanAfford(TSPlayer player, CustomSkillCost cost) { if (cost == null) { return(true); } else { if (cost.RequiresHp) { if (Player.TPlayer.statLife < cost.Hp) { return(false); } } if (cost.RequiresMp) { if (Player.TPlayer.statMana < cost.Mp) { return(false); } } var bank = BankingPlugin.Instance.Bank; if (bank == null) { return(true); //probably an error condition, but let the admin deal with this. } if (cost.RequiresExp) { var account = BankingPlugin.Instance.GetBankAccount(player, "Exp"); if (account != null) { if (account.Balance < Math.Abs(cost.Exp)) { return(false); //player cant cover balance } } else { return(false); } } if (cost.RequiresCurrency) { if (bank.CurrencyManager.TryFindCurrencyFromString(cost.Currency, out var currency)) { var account = bank.GetBankAccount(Player.Name, currency.InternalName); if (account != null) { //check for funds... Debug.Print($"Found bank account for {currency.InternalName}"); //parse currency.GetCurrencyConverter().TryParse(cost.Currency, out var rawValue); if (account.Balance < rawValue) { Debug.Print("Player bank balance is less than skill cost."); return(false); } //account.TryWithdraw(rawValue) } else { Debug.Print($"Did not find bank account for {currency.InternalName}"); } } } return(true); } }