64 lines
No EOL
2.7 KiB
C#
64 lines
No EOL
2.7 KiB
C#
using CounterStrikeSharp.API;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Modules.Cvars;
|
|
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"));
|
|
}
|
|
|
|
private static int GetMaxMoney() => ConVar.Find("mp_maxmoney")?.GetPrimitiveValue<int>() ?? 16000;
|
|
|
|
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, GetMaxMoney() - 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, GetMaxMoney());
|
|
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;
|
|
}
|
|
}
|
|
} |