v1.2.2.b1
This commit is contained in:
parent
0fb3d63cd8
commit
46195c2663
147 changed files with 3470 additions and 2161 deletions
|
|
@ -1,122 +1,60 @@
|
|||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Timers;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using src.utils;
|
||||
using System.Collections.Concurrent;
|
||||
using static src.jRandomSkills;
|
||||
using Timer = CounterStrikeSharp.API.Modules.Timers.Timer;
|
||||
|
||||
namespace src.player.skills
|
||||
{
|
||||
public class Phoenix : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.Phoenix;
|
||||
private static readonly object setLock = new();
|
||||
private static readonly ConcurrentDictionary<ulong, Timer> timers = [];
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"), false);
|
||||
}
|
||||
|
||||
public static void PlayerDeath(EventPlayerDeath @event)
|
||||
public static void PlayerHurt(EventPlayerHurt @event)
|
||||
{
|
||||
var player = @event.Userid;
|
||||
if (player == null || !player.IsValid || player.PlayerPawn.Value == null || !player.PlayerPawn.Value.IsValid) return;
|
||||
var user = @event.Userid;
|
||||
if (user == null || !user.IsValid) return;
|
||||
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
if (playerInfo?.Skill == skillName)
|
||||
var victim = PlayerManager.GetPlayerEvent(@event.Userid);
|
||||
if (victim == null || !victim.IsValid) return;
|
||||
|
||||
var pawn = victim.PlayerPawn.Value;
|
||||
if (pawn == null || !pawn.IsValid) return;
|
||||
|
||||
var playerInfo = PlayerManager.GetPlayerByIndex(victim.Index);
|
||||
if (playerInfo?.Skill != skillName || pawn.Health > 0) return;
|
||||
|
||||
if (Instance.Random.NextDouble() > playerInfo.SkillChance) return;
|
||||
if (victim.TeamChanged) return;
|
||||
|
||||
SkillUtils.AddHealth(pawn, 100 - pawn.Health);
|
||||
SkillUtils.PrintToChat(user, user.GetTranslation("phoenix_respawn"));
|
||||
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
if (Instance.Random.NextDouble() <= playerInfo.SkillChance)
|
||||
{
|
||||
lock (setLock)
|
||||
{
|
||||
ulong steamID = player.SteamID;
|
||||
int team = player.TeamNum;
|
||||
if (victim == null || !victim.IsValid) return;
|
||||
if (pawn == null || !pawn.IsValid) return;
|
||||
|
||||
if (team != 2 && team != 3) return;
|
||||
var spawnpoint = SkillUtils.GetSpawnPointVector(victim);
|
||||
if (spawnpoint == null) return;
|
||||
|
||||
player.Respawn();
|
||||
|
||||
Server.NextFrame(() => {
|
||||
lock (setLock)
|
||||
{
|
||||
var player = Utilities.GetPlayerFromSteamId(steamID);
|
||||
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid) return;
|
||||
|
||||
var pawn = player.PlayerPawn.Value;
|
||||
if (pawn == null || !pawn.IsValid) return;
|
||||
|
||||
bool isBlock = team != player.TeamNum || player.TeamChanged;
|
||||
|
||||
player.Respawn();
|
||||
|
||||
if (isBlock)
|
||||
{
|
||||
pawn.Flags |= (uint)Flags_t.FL_FROZEN;
|
||||
pawn.Teleport(new Vector(0, 0, -1000), new QAngle(90, 0, 0));
|
||||
|
||||
bool isFreezeTime = Instance.GameRules != null && Instance.GameRules.FreezePeriod == true;
|
||||
|
||||
if (!isFreezeTime)
|
||||
{
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
if (pawn == null || !pawn.IsValid) return;
|
||||
pawn.CommitSuicide(false, true);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
ulong steamId = player.SteamID;
|
||||
|
||||
if (!timers.ContainsKey(player.SteamID))
|
||||
{
|
||||
var timer = Instance.AddTimer(1f, () =>
|
||||
{
|
||||
if (player == null || !player.IsValid || pawn == null || !pawn.IsValid)
|
||||
{
|
||||
if (timers.TryRemove(steamId, out var t))
|
||||
t.Kill();
|
||||
return;
|
||||
}
|
||||
|
||||
bool isFreezeTime = Instance.GameRules != null && Instance.GameRules.FreezePeriod == true;
|
||||
|
||||
if (!isFreezeTime)
|
||||
{
|
||||
if (timers.TryRemove(steamId, out var t))
|
||||
t.Kill();
|
||||
|
||||
pawn.CommitSuicide(false, true);
|
||||
return;
|
||||
}
|
||||
|
||||
}, TimerFlags.STOP_ON_MAPCHANGE | TimerFlags.REPEAT);
|
||||
|
||||
timers.TryAdd(player.SteamID, timer);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
SkillUtils.PrintToChat(player, player.GetTranslation("phoenix_respawn"));
|
||||
}
|
||||
}
|
||||
}
|
||||
pawn.Teleport(spawnpoint);
|
||||
});
|
||||
}
|
||||
|
||||
public static void EnableSkill(CCSPlayerController player)
|
||||
{
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
|
||||
if (playerInfo == null) return;
|
||||
float newChance = (float)Instance.Random.NextDouble() * (SkillsInfo.GetValue<float>(skillName, "ChanceTo") - SkillsInfo.GetValue<float>(skillName, "ChanceFrom")) + SkillsInfo.GetValue<float>(skillName, "ChanceFrom");
|
||||
playerInfo.SkillChance = newChance;
|
||||
SkillUtils.PrintToChat(player, $"{ChatColors.DarkRed}{player.GetSkillName(skillName)}{ChatColors.Lime}: {player.GetSkillDescription(skillName, newChance)}",
|
||||
border: !Utilities.GetPlayers().Any(p => p.Team == player.Team && !p.IsBot && p != player) ? "tb" : "t");
|
||||
border: !Utilities.GetPlayers().Any(p => p.Team == player.Team && p != player) ? "tb" : "t");
|
||||
}
|
||||
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#ff5C0A", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "", int maxPerServer = -1, Rarity rarity = Rarity.Common, float chanceFrom = .2f, float chanceTo = .4f) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission, maxPerServer, rarity)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue