jRandomSkills/jRandomSkills - SRC Files/src/player/skills/RichBoy.cs
2026-05-24 23:13:56 +02:00

61 lines
No EOL
2.6 KiB
C#

using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using src.utils;
using static src.jRandomSkills;
namespace src.player.skills
{
public class RichBoy : ISkill
{
private const Skills skillName = Skills.RichBoy;
public static void LoadSkill()
{
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
}
public static void EnableSkill(CCSPlayerController player)
{
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
if (playerInfo == null) return;
int moneyBonus = Instance.Random.Next(SkillsInfo.GetValue<int>(skillName, "minMoney"), SkillsInfo.GetValue<int>(skillName, "maxMoney"));
var moneyServices = player.InGameMoneyServices;
if (moneyServices == null) return;
moneyBonus = Math.Min(moneyBonus, 16000 - moneyServices.Account);
playerInfo.SkillChance = moneyBonus;
AddMoney(player, moneyBonus);
}
public static void DisableSkill(CCSPlayerController player)
{
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
if (playerInfo == null) return;
var moneyServices = player.InGameMoneyServices;
if (moneyServices == null) return;
int money = Math.Abs((int)playerInfo.SkillChance! - moneyServices.CashSpentThisRound);
AddMoney(player, -money, 3000);
}
private static void AddMoney(CCSPlayerController player, int money, int minimum = 0)
{
if (player == null || !player.IsValid) return;
var moneyServices = player.InGameMoneyServices;
if (moneyServices == null) return;
moneyServices.Account = Math.Clamp(moneyServices.Account + money, minimum, 16000);
Utilities.SetStateChanged(player, "CCSPlayerController", "m_pInGameMoneyServices");
}
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#D4AF37", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "", int maxPerServer = -1, Rarity rarity = Rarity.Common, int minMoney = 5000, int maxMoney = 15000) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission, maxPerServer, rarity)
{
public int MinMoney { get; set; } = minMoney;
public int MaxMoney { get; set; } = maxMoney;
}
}
}