From 7ad498f74d80a53f433d16f9cc8a107de6525822 Mon Sep 17 00:00:00 2001 From: iRebbok Date: Sun, 6 Oct 2019 11:03:04 +0300 Subject: [PATCH] adding tag in lang key & cleanup --- scp035/EventHandler.cs | 522 ++++++++++++++++++++--------------------- scp035/Logic.cs | 334 +++++++++++++------------- scp035/Plugin.cs | 86 +++---- 3 files changed, 469 insertions(+), 473 deletions(-) diff --git a/scp035/EventHandler.cs b/scp035/EventHandler.cs index a39aef5..a0d4284 100644 --- a/scp035/EventHandler.cs +++ b/scp035/EventHandler.cs @@ -1,45 +1,45 @@ -using Smod2.API; +using MEC; +using Smod2.API; using Smod2.EventHandlers; using Smod2.Events; -using System.Linq; +using System; using System.Collections.Generic; +using System.Linq; using UnityEngine; -using MEC; -using System; namespace scp035 { - partial class EventHandler : IEventHandlerWaitingForPlayers, IEventHandlerRoundStart, IEventHandlerPlayerPickupItemLate, - IEventHandlerRoundEnd, IEventHandlerPlayerDie, IEventHandlerPlayerHurt, IEventHandlerPocketDimensionEnter, - IEventHandlerCheckRoundEnd, IEventHandlerCheckEscape, IEventHandlerSetRole, IEventHandlerDisconnect, - IEventHandlerContain106, IEventHandlerGeneratorInsertTablet, IEventHandlerUpdate, IEventHandlerPocketDimensionDie - { - private Plugin instance; - private Dictionary scpPickups = new Dictionary(); - internal static Player scpPlayer; - DateTime updateTimer; - private bool isRoundStarted; - private bool isRotating; - private const float dur = 327; - private System.Random rand = new System.Random(); - - // Configs - private List possibleItems; - private int scpHealth; - private float scpInterval; - private bool is035FriendlyFire; - private int possessedItemCount; - private bool spawnNewItems; - private bool useDamageOverride; - private bool winWithTutorials; - private bool changeToZombie; - private bool isTutorialFriendlyFire; - private bool isCorroding; - private float corrodeRange; - private int corrodeDamage; - private float corrodeInterval; - private bool corrodeLifeSteal; - private bool isEnabled; + partial class EventHandler : IEventHandlerWaitingForPlayers, IEventHandlerRoundStart, IEventHandlerPlayerPickupItemLate, + IEventHandlerRoundEnd, IEventHandlerPlayerDie, IEventHandlerPlayerHurt, IEventHandlerPocketDimensionEnter, + IEventHandlerCheckRoundEnd, IEventHandlerCheckEscape, IEventHandlerSetRole, IEventHandlerDisconnect, + IEventHandlerContain106, IEventHandlerGeneratorInsertTablet, IEventHandlerUpdate, IEventHandlerPocketDimensionDie + { + private Plugin instance; + private Dictionary scpPickups = new Dictionary(); + internal static Player scpPlayer; + DateTime updateTimer; + private bool isRoundStarted; + private bool isRotating; + private const float dur = 327; + private System.Random rand = new System.Random(); + + // Configs + private List possibleItems; + private int scpHealth; + private float scpInterval; + private bool is035FriendlyFire; + private int possessedItemCount; + private bool spawnNewItems; + private bool useDamageOverride; + private bool winWithTutorials; + private bool changeToZombie; + private bool isTutorialFriendlyFire; + private bool isCorroding; + private float corrodeRange; + private int corrodeDamage; + private float corrodeInterval; + private bool corrodeLifeSteal; + private bool isEnabled; // Translate private uint bctime; @@ -48,230 +48,230 @@ partial class EventHandler : IEventHandlerWaitingForPlayers, IEventHandlerRoundS private string hiding; public EventHandler(Plugin plugin) - { - instance = plugin; - hInstance = this; - } - - public void OnWaitingForPlayers(WaitingForPlayersEvent ev) - { - LoadConfigs(); - } - - public void OnRoundStart(RoundStartEvent ev) - { - if (!isEnabled) return; - - isRoundStarted = true; - isRotating = true; - scpPickups.Clear(); - scpPlayer = null; - - updateTimer = DateTime.Now; - - Timing.RunCoroutine(RotatePickup()); - } - - public void OnRoundEnd(RoundEndEvent ev) - { - if (!isEnabled) return; - - isRoundStarted = false; - } - - public void OnPlayerPickupItemLate(PlayerPickupItemLateEvent ev) - { - if (!isEnabled) return; - - Inventory.SyncItemInfo? item = ((GameObject)ev.Player.GetGameObject()).GetComponent().items.Last(); - - if (item.Value.durability == dur) - { - InfectPlayer(ev.Player, ev.Item); - } - } - - public void OnPlayerHurt(PlayerHurtEvent ev) - { - if (!isEnabled) return; - - if (scpPlayer != null) - { - if (!is035FriendlyFire && - ((ev.Attacker.PlayerId == scpPlayer.PlayerId && - ev.Player.TeamRole.Team == Smod2.API.Team.SCP) || - (ev.Player.PlayerId == scpPlayer.PlayerId && - ev.Attacker.TeamRole.Team == Smod2.API.Team.SCP))) - { - ev.Damage = 0; - } - if (!isTutorialFriendlyFire && - ev.Attacker.PlayerId != ev.Player.PlayerId && - ((ev.Attacker.PlayerId == scpPlayer.PlayerId && - ev.Player.TeamRole.Team == Smod2.API.Team.TUTORIAL) || - (ev.Player.PlayerId == scpPlayer.PlayerId && - ev.Attacker.TeamRole.Team == Smod2.API.Team.TUTORIAL))) - { - ev.Damage = 0; - } - if (useDamageOverride && ev.Damage > 0) - { - if ((ev.Attacker.PlayerId == scpPlayer.PlayerId || - ev.Player.PlayerId == scpPlayer.PlayerId) && - ev.Attacker.PlayerId != ev.Player.PlayerId && - ev.DamageType != DamageType.FALLDOWN && - ev.DamageType != DamageType.NUKE && - ev.DamageType != DamageType.TESLA && - ev.DamageType != DamageType.WALL && - ev.DamageType != DamageType.DECONT && - ev.DamageType != DamageType.FALLDOWN) - { - ev.Player.SetHealth(ev.Player.GetHealth() - (int)ev.Damage); - } - } - } - } - - public void OnPlayerDie(PlayerDeathEvent ev) - { - if (!isEnabled) return; - - if (ev.Player.PlayerId == scpPlayer?.PlayerId) - { - KillScp035(); - } - } - - public void OnSetRole(PlayerSetRoleEvent ev) - { - if (!isEnabled) return; - - // Counter admins changing roles through RA - if (ev.Player.PlayerId == scpPlayer?.PlayerId) - { - KillScp035(); - } - } - - public void OnPocketDimensionEnter(PlayerPocketDimensionEnterEvent ev) - { - if (!isEnabled) return; - - if (ev.Player.PlayerId == scpPlayer?.PlayerId && !is035FriendlyFire) - { - ev.Damage = 0; - ev.TargetPosition = ev.LastPosition; - } - } - - public void OnCheckRoundEnd(CheckRoundEndEvent ev) - { - if (!isEnabled) return; - - List< Smod2.API.Team> pList = ev.Server.GetPlayers().Select(x => x.TeamRole.Team).ToList(); - pList.Remove(pList.FirstOrDefault(x => x == scpPlayer?.TeamRole.Team)); - - // If everyone but SCPs and 035 or just 035 is alive, end the round - if ((!pList.Contains(Smod2.API.Team.CHAOS_INSURGENCY) && - !pList.Contains(Smod2.API.Team.CLASSD) && - !pList.Contains(Smod2.API.Team.NINETAILFOX) && - !pList.Contains(Smod2.API.Team.SCIENTIST) && - ((pList.Contains(Smod2.API.Team.SCP) && - scpPlayer != null) || - !pList.Contains(Smod2.API.Team.SCP) && - scpPlayer != null)) || - (winWithTutorials && - !pList.Contains(Smod2.API.Team.CHAOS_INSURGENCY) && - !pList.Contains(Smod2.API.Team.CLASSD) && - !pList.Contains(Smod2.API.Team.NINETAILFOX) && - !pList.Contains(Smod2.API.Team.SCIENTIST) && - pList.Contains(Smod2.API.Team.TUTORIAL) && - scpPlayer != null)) - { - if (changeToZombie) - { - scpPlayer.ChangeRole(Role.SCP_049_2, true, false); - } - else - { - ev.Status = ROUND_END_STATUS.SCP_VICTORY; - } - } - // If 035 is the only scp alive keep the round going - else if (scpPlayer != null && !pList.Contains(Smod2.API.Team.SCP)) - { - ev.Status = ROUND_END_STATUS.ON_GOING; - } - } - - public void OnCheckEscape(PlayerCheckEscapeEvent ev) - { - if (!isEnabled) return; - - if (ev.Player.PlayerId == scpPlayer?.PlayerId) ev.AllowEscape = false; - } - - public void OnDisconnect(DisconnectEvent ev) - { - if (!isEnabled) return; - - if (instance.Server.GetPlayers().FirstOrDefault(x => x.PlayerId == scpPlayer?.PlayerId) == null) - { - KillScp035(false); - } - } - - public void OnContain106(PlayerContain106Event ev) - { - if (!isEnabled) return; - - if (ev.Player.PlayerId == scpPlayer?.PlayerId && !is035FriendlyFire) - { - ev.ActivateContainment = false; - } - } - - public void OnGeneratorInsertTablet(PlayerGeneratorInsertTabletEvent ev) - { - if (!isEnabled) return; - - if (ev.Player.PlayerId == scpPlayer?.PlayerId && !is035FriendlyFire) - { - ev.Allow = false; - } - } - - public void OnPocketDimensionDie(PlayerPocketDimensionDieEvent ev) - { - if (!isEnabled) return; - - if (ev.Player.PlayerId == scpPlayer?.PlayerId) - { - ev.Die = false; - ev.Player.Teleport(instance.Server.Map.GetRandomSpawnPoint(Role.SCP_096)); - } - } - - public void OnUpdate(UpdateEvent ev) - { - if (!isEnabled) return; - - if (isRoundStarted && scpPlayer != null && updateTimer != null && updateTimer < DateTime.Now && isCorroding) - { - updateTimer = DateTime.Now.AddSeconds(corrodeInterval); - GameObject scp035 = (GameObject)scpPlayer.GetGameObject(); - - IEnumerable pList = instance.Server.GetPlayers().Where(x => x.PlayerId != scpPlayer.PlayerId); - if (!is035FriendlyFire) pList = pList.Where(x => x.TeamRole.Team != Smod2.API.Team.SCP); - if (!isTutorialFriendlyFire) pList = pList.Where(x => x.TeamRole.Team != Smod2.API.Team.TUTORIAL); - foreach (Player player in pList) - { - if (Vector3.Distance(scp035.transform.position, ((GameObject)player.GetGameObject()).transform.position) <= corrodeRange) - { - CorrodePlayer(player); - } - } - } - } - } + { + instance = plugin; + hInstance = this; + } + + public void OnWaitingForPlayers(WaitingForPlayersEvent ev) + { + LoadConfigs(); + } + + public void OnRoundStart(RoundStartEvent ev) + { + if (!isEnabled) return; + + isRoundStarted = true; + isRotating = true; + scpPickups.Clear(); + scpPlayer = null; + + updateTimer = DateTime.Now; + + Timing.RunCoroutine(RotatePickup()); + } + + public void OnRoundEnd(RoundEndEvent ev) + { + if (!isEnabled) return; + + isRoundStarted = false; + } + + public void OnPlayerPickupItemLate(PlayerPickupItemLateEvent ev) + { + if (!isEnabled) return; + + Inventory.SyncItemInfo? item = ((GameObject)ev.Player.GetGameObject()).GetComponent().items.Last(); + + if (item.Value.durability == dur) + { + InfectPlayer(ev.Player, ev.Item); + } + } + + public void OnPlayerHurt(PlayerHurtEvent ev) + { + if (!isEnabled) return; + + if (scpPlayer != null) + { + if (!is035FriendlyFire && + ((ev.Attacker.PlayerId == scpPlayer.PlayerId && + ev.Player.TeamRole.Team == Smod2.API.Team.SCP) || + (ev.Player.PlayerId == scpPlayer.PlayerId && + ev.Attacker.TeamRole.Team == Smod2.API.Team.SCP))) + { + ev.Damage = 0; + } + if (!isTutorialFriendlyFire && + ev.Attacker.PlayerId != ev.Player.PlayerId && + ((ev.Attacker.PlayerId == scpPlayer.PlayerId && + ev.Player.TeamRole.Team == Smod2.API.Team.TUTORIAL) || + (ev.Player.PlayerId == scpPlayer.PlayerId && + ev.Attacker.TeamRole.Team == Smod2.API.Team.TUTORIAL))) + { + ev.Damage = 0; + } + if (useDamageOverride && ev.Damage > 0) + { + if ((ev.Attacker.PlayerId == scpPlayer.PlayerId || + ev.Player.PlayerId == scpPlayer.PlayerId) && + ev.Attacker.PlayerId != ev.Player.PlayerId && + ev.DamageType != DamageType.FALLDOWN && + ev.DamageType != DamageType.NUKE && + ev.DamageType != DamageType.TESLA && + ev.DamageType != DamageType.WALL && + ev.DamageType != DamageType.DECONT && + ev.DamageType != DamageType.FALLDOWN) + { + ev.Player.SetHealth(ev.Player.GetHealth() - (int)ev.Damage); + } + } + } + } + + public void OnPlayerDie(PlayerDeathEvent ev) + { + if (!isEnabled) return; + + if (ev.Player.PlayerId == scpPlayer?.PlayerId) + { + KillScp035(); + } + } + + public void OnSetRole(PlayerSetRoleEvent ev) + { + if (!isEnabled) return; + + // Counter admins changing roles through RA + if (ev.Player.PlayerId == scpPlayer?.PlayerId) + { + KillScp035(); + } + } + + public void OnPocketDimensionEnter(PlayerPocketDimensionEnterEvent ev) + { + if (!isEnabled) return; + + if (ev.Player.PlayerId == scpPlayer?.PlayerId && !is035FriendlyFire) + { + ev.Damage = 0; + ev.TargetPosition = ev.LastPosition; + } + } + + public void OnCheckRoundEnd(CheckRoundEndEvent ev) + { + if (!isEnabled) return; + + List pList = ev.Server.GetPlayers().Select(x => x.TeamRole.Team).ToList(); + pList.Remove(pList.FirstOrDefault(x => x == scpPlayer?.TeamRole.Team)); + + // If everyone but SCPs and 035 or just 035 is alive, end the round + if ((!pList.Contains(Smod2.API.Team.CHAOS_INSURGENCY) && + !pList.Contains(Smod2.API.Team.CLASSD) && + !pList.Contains(Smod2.API.Team.NINETAILFOX) && + !pList.Contains(Smod2.API.Team.SCIENTIST) && + ((pList.Contains(Smod2.API.Team.SCP) && + scpPlayer != null) || + !pList.Contains(Smod2.API.Team.SCP) && + scpPlayer != null)) || + (winWithTutorials && + !pList.Contains(Smod2.API.Team.CHAOS_INSURGENCY) && + !pList.Contains(Smod2.API.Team.CLASSD) && + !pList.Contains(Smod2.API.Team.NINETAILFOX) && + !pList.Contains(Smod2.API.Team.SCIENTIST) && + pList.Contains(Smod2.API.Team.TUTORIAL) && + scpPlayer != null)) + { + if (changeToZombie) + { + scpPlayer.ChangeRole(Role.SCP_049_2, true, false); + } + else + { + ev.Status = ROUND_END_STATUS.SCP_VICTORY; + } + } + // If 035 is the only scp alive keep the round going + else if (scpPlayer != null && !pList.Contains(Smod2.API.Team.SCP)) + { + ev.Status = ROUND_END_STATUS.ON_GOING; + } + } + + public void OnCheckEscape(PlayerCheckEscapeEvent ev) + { + if (!isEnabled) return; + + if (ev.Player.PlayerId == scpPlayer?.PlayerId) ev.AllowEscape = false; + } + + public void OnDisconnect(DisconnectEvent ev) + { + if (!isEnabled) return; + + if (instance.Server.GetPlayers().FirstOrDefault(x => x.PlayerId == scpPlayer?.PlayerId) == null) + { + KillScp035(false); + } + } + + public void OnContain106(PlayerContain106Event ev) + { + if (!isEnabled) return; + + if (ev.Player.PlayerId == scpPlayer?.PlayerId && !is035FriendlyFire) + { + ev.ActivateContainment = false; + } + } + + public void OnGeneratorInsertTablet(PlayerGeneratorInsertTabletEvent ev) + { + if (!isEnabled) return; + + if (ev.Player.PlayerId == scpPlayer?.PlayerId && !is035FriendlyFire) + { + ev.Allow = false; + } + } + + public void OnPocketDimensionDie(PlayerPocketDimensionDieEvent ev) + { + if (!isEnabled) return; + + if (ev.Player.PlayerId == scpPlayer?.PlayerId) + { + ev.Die = false; + ev.Player.Teleport(instance.Server.Map.GetRandomSpawnPoint(Role.SCP_096)); + } + } + + public void OnUpdate(UpdateEvent ev) + { + if (!isEnabled) return; + + if (isRoundStarted && scpPlayer != null && updateTimer != null && updateTimer < DateTime.Now && isCorroding) + { + updateTimer = DateTime.Now.AddSeconds(corrodeInterval); + GameObject scp035 = (GameObject)scpPlayer.GetGameObject(); + + IEnumerable pList = instance.Server.GetPlayers().Where(x => x.PlayerId != scpPlayer.PlayerId); + if (!is035FriendlyFire) pList = pList.Where(x => x.TeamRole.Team != Smod2.API.Team.SCP); + if (!isTutorialFriendlyFire) pList = pList.Where(x => x.TeamRole.Team != Smod2.API.Team.TUTORIAL); + foreach (Player player in pList) + { + if (Vector3.Distance(scp035.transform.position, ((GameObject)player.GetGameObject()).transform.position) <= corrodeRange) + { + CorrodePlayer(player); + } + } + } + } + } } diff --git a/scp035/Logic.cs b/scp035/Logic.cs index 7faf5cd..6c97126 100644 --- a/scp035/Logic.cs +++ b/scp035/Logic.cs @@ -1,182 +1,178 @@ -using Smod2.API; -using Smod2.EventHandlers; -using Smod2.Events; -using System.Linq; +using MEC; +using Smod2.API; using System.Collections.Generic; +using System.Linq; using UnityEngine; -using MEC; -using ServerMod2.API; -using UnityEngine.Networking; namespace scp035 { - partial class EventHandler - { - public static EventHandler hInstance { get; private set; } - - private void LoadConfigs() - { - possibleItems = instance.GetConfigIntList("035_possible_items").ToList(); - scpHealth = instance.GetConfigInt("035_health"); - scpInterval = instance.GetConfigFloat("035_rotate_interval"); - is035FriendlyFire = instance.GetConfigBool("035_scp_friendly_fire"); - possessedItemCount = instance.GetConfigInt("035_infected_item_count"); - spawnNewItems = instance.GetConfigBool("035_spawn_new_items"); - useDamageOverride = instance.GetConfigBool("035_use_damage_override"); - winWithTutorials = instance.GetConfigBool("035_win_with_tutorial"); - changeToZombie = instance.GetConfigBool("035_change_to_zombie"); - isTutorialFriendlyFire = instance.GetConfigBool("035_tutorial_friendly_fire"); - isCorroding = instance.GetConfigBool("035_corrode_players"); - corrodeRange = instance.GetConfigFloat("035_corrode_distance"); - corrodeDamage = instance.GetConfigInt("035_corrode_damage"); - corrodeInterval = instance.GetConfigFloat("035_corrode_interval"); - corrodeLifeSteal = instance.GetConfigBool("035_corrode_life_steal"); - isEnabled = instance.GetConfigBool("035_enabled"); + partial class EventHandler + { + public static EventHandler hInstance { get; private set; } + + private void LoadConfigs() + { + possibleItems = instance.GetConfigIntList("035_possible_items").ToList(); + scpHealth = instance.GetConfigInt("035_health"); + scpInterval = instance.GetConfigFloat("035_rotate_interval"); + is035FriendlyFire = instance.GetConfigBool("035_scp_friendly_fire"); + possessedItemCount = instance.GetConfigInt("035_infected_item_count"); + spawnNewItems = instance.GetConfigBool("035_spawn_new_items"); + useDamageOverride = instance.GetConfigBool("035_use_damage_override"); + winWithTutorials = instance.GetConfigBool("035_win_with_tutorial"); + changeToZombie = instance.GetConfigBool("035_change_to_zombie"); + isTutorialFriendlyFire = instance.GetConfigBool("035_tutorial_friendly_fire"); + isCorroding = instance.GetConfigBool("035_corrode_players"); + corrodeRange = instance.GetConfigFloat("035_corrode_distance"); + corrodeDamage = instance.GetConfigInt("035_corrode_damage"); + corrodeInterval = instance.GetConfigFloat("035_corrode_interval"); + corrodeLifeSteal = instance.GetConfigBool("035_corrode_life_steal"); + isEnabled = instance.GetConfigBool("035_enabled"); int ConfigBCTime = instance.GetConfigInt("035_bc_time"); if (ConfigBCTime > -1) bctime = (uint)ConfigBCTime; else bctime = 10; - hiding = instance.GetTranslation("hiding"); - picked = instance.GetTranslation("picked"); - infection = instance.GetTranslation("infection"); + hiding = instance.GetTranslation("035_hiding"); + picked = instance.GetTranslation("035_picked"); + infection = instance.GetTranslation("035_infection"); + } + + private void ResetItemDurability() + { + for (int i = 0; i < scpPickups.Count; i++) + { + Pickup p = scpPickups.ElementAt(i).Key; + if (p != null) p.info.durability = scpPickups[p]; + } + scpPickups.Clear(); + } + + private void RemovePossessedItems() + { + for (int i = 0; i < scpPickups.Count; i++) + { + Pickup p = scpPickups.ElementAt(i).Key; + if (p != null) p.Delete(); + } + scpPickups.Clear(); } - private void ResetItemDurability() - { - for (int i = 0; i < scpPickups.Count; i++) - { - Pickup p = scpPickups.ElementAt(i).Key; - if (p != null) p.info.durability = scpPickups[p]; - } - scpPickups.Clear(); - } - - private void RemovePossessedItems() - { - for (int i = 0; i < scpPickups.Count; i++) - { - Pickup p = scpPickups.ElementAt(i).Key; - if (p != null) p.Delete(); - } - scpPickups.Clear(); - } - - private Pickup GetRandomValidItem() - { - List pickups = Object.FindObjectsOfType().Where(x => possibleItems.Contains(x.info.itemId) && !scpPickups.ContainsKey(x)).ToList(); - return pickups[rand.Next(pickups.Count)]; - } - - private Pickup GetRandomItem() - { - List pickups = Object.FindObjectsOfType().Where(x => !scpPickups.ContainsKey(x)).ToList(); - return pickups[rand.Next(pickups.Count)]; - } - - private void RefreshItems() - { - if (instance.Server.GetPlayers().Where(x => x.TeamRole.Team == Smod2.API.Team.SPECTATOR && !x.OverwatchMode).ToList().Count > 0) - { - if (spawnNewItems) - { - RemovePossessedItems(); - for (int i = 0; i < possessedItemCount; i++) - { - Pickup p = GetRandomItem(); - Pickup a = PlayerManager.singleton.players[0] - .GetComponent().SetPickup(possibleItems[rand.Next(possibleItems.Count)], - -4.65664672E+11f, - new Vector3(p.transform.position.x, p.transform.position.y, p.transform.position.z), - new Quaternion(p.transform.rotation.x, p.transform.rotation.y, p.transform.rotation.z, p.transform.rotation.w), - 0, 0, 0).GetComponent(); - scpPickups.Add(a, a.info.durability); - a.info.durability = dur; - //new SmodItem(a.info.itemId, a).SetPosition(instance.Server.GetPlayers().FirstOrDefault(x => x.Name.Contains("cyan")).GetPosition()); - } - } - else - { - ResetItemDurability(); - for (int i = 0; i < possessedItemCount; i++) - { - Pickup p = GetRandomValidItem(); - scpPickups.Add(p, p.info.durability); - p.info.durability = dur; - } - } - } - } - - private void KillScp035(bool setRank = true) - { - if (setRank) scpPlayer.SetRank("default", " "); - scpPlayer = null; - isRotating = true; - RefreshItems(); - } - - private void InfectPlayer(Player player, Smod2.API.Item pItem) - { - List pList = instance.Server.GetPlayers().Where(x => x.TeamRole.Team == Smod2.API.Team.SPECTATOR && !x.OverwatchMode).ToList(); - if (pList.Count > 0 && scpPlayer == null) - { - pItem.Remove(); - Player p035 = pList[rand.Next(pList.Count)]; - p035.ChangeRole(player.TeamRole.Role); - p035.Teleport(player.GetPosition()); - foreach (Smod2.API.Item item in player.GetInventory()) p035.GiveItem(item.ItemType); - p035.SetHealth(scpHealth); - p035.SetAmmo(AmmoType.DROPPED_5, player.GetAmmo(AmmoType.DROPPED_5)); - p035.SetAmmo(AmmoType.DROPPED_7, player.GetAmmo(AmmoType.DROPPED_7)); - p035.SetAmmo(AmmoType.DROPPED_9, player.GetAmmo(AmmoType.DROPPED_9)); - p035.SetRank("red", "SCP-035"); - p035.PersonalBroadcast(bctime, infection, false); - scpPlayer = p035; - isRotating = false; - - player.ChangeRole(Role.SPECTATOR); - player.PersonalBroadcast(bctime, picked, false); - - if (spawnNewItems) RemovePossessedItems(); else ResetItemDurability(); - } - } - - private IEnumerator RotatePickup() - { - while (isRoundStarted) - { - if (isRotating) - { - RefreshItems(); - } - yield return Timing.WaitForSeconds(scpInterval); - } - } - - private void CorrodePlayer(Player player) - { - if (useDamageOverride) - { - player.SetHealth(player.GetHealth() - corrodeDamage, DamageType.NONE); - } - else - { - player.Damage(corrodeDamage, DamageType.NONE); - } - - if (corrodeLifeSteal && scpPlayer != null) - { - int currHP = scpPlayer.GetHealth(); - scpPlayer.SetHealth(currHP + corrodeDamage > scpHealth ? scpHealth : currHP + corrodeDamage); - } - } - - public bool HandleHideTagHook(CharacterClassManager __instance) - { - bool a = __instance.SteamId == scpPlayer?.SteamId; - if (a) __instance.TargetConsolePrint(__instance.connectionToClient, hiding, "green"); - return !a; - } - } + private Pickup GetRandomValidItem() + { + List pickups = Object.FindObjectsOfType().Where(x => possibleItems.Contains(x.info.itemId) && !scpPickups.ContainsKey(x)).ToList(); + return pickups[rand.Next(pickups.Count)]; + } + + private Pickup GetRandomItem() + { + List pickups = Object.FindObjectsOfType().Where(x => !scpPickups.ContainsKey(x)).ToList(); + return pickups[rand.Next(pickups.Count)]; + } + + private void RefreshItems() + { + if (instance.Server.GetPlayers().Where(x => x.TeamRole.Team == Smod2.API.Team.SPECTATOR && !x.OverwatchMode).ToList().Count > 0) + { + if (spawnNewItems) + { + RemovePossessedItems(); + for (int i = 0; i < possessedItemCount; i++) + { + Pickup p = GetRandomItem(); + Pickup a = PlayerManager.singleton.players[0] + .GetComponent().SetPickup(possibleItems[rand.Next(possibleItems.Count)], + -4.65664672E+11f, + new Vector3(p.transform.position.x, p.transform.position.y, p.transform.position.z), + new Quaternion(p.transform.rotation.x, p.transform.rotation.y, p.transform.rotation.z, p.transform.rotation.w), + 0, 0, 0).GetComponent(); + scpPickups.Add(a, a.info.durability); + a.info.durability = dur; + //new SmodItem(a.info.itemId, a).SetPosition(instance.Server.GetPlayers().FirstOrDefault(x => x.Name.Contains("cyan")).GetPosition()); + } + } + else + { + ResetItemDurability(); + for (int i = 0; i < possessedItemCount; i++) + { + Pickup p = GetRandomValidItem(); + scpPickups.Add(p, p.info.durability); + p.info.durability = dur; + } + } + } + } + + private void KillScp035(bool setRank = true) + { + if (setRank) scpPlayer.SetRank("default", " "); + scpPlayer = null; + isRotating = true; + RefreshItems(); + } + + private void InfectPlayer(Player player, Smod2.API.Item pItem) + { + List pList = instance.Server.GetPlayers().Where(x => x.TeamRole.Team == Smod2.API.Team.SPECTATOR && !x.OverwatchMode).ToList(); + if (pList.Count > 0 && scpPlayer == null) + { + pItem.Remove(); + Player p035 = pList[rand.Next(pList.Count)]; + p035.ChangeRole(player.TeamRole.Role); + p035.Teleport(player.GetPosition()); + foreach (Smod2.API.Item item in player.GetInventory()) p035.GiveItem(item.ItemType); + p035.SetHealth(scpHealth); + p035.SetAmmo(AmmoType.DROPPED_5, player.GetAmmo(AmmoType.DROPPED_5)); + p035.SetAmmo(AmmoType.DROPPED_7, player.GetAmmo(AmmoType.DROPPED_7)); + p035.SetAmmo(AmmoType.DROPPED_9, player.GetAmmo(AmmoType.DROPPED_9)); + p035.SetRank("red", "SCP-035"); + p035.PersonalBroadcast(bctime, infection, false); + scpPlayer = p035; + isRotating = false; + + player.ChangeRole(Role.SPECTATOR); + player.PersonalBroadcast(bctime, picked, false); + + if (spawnNewItems) RemovePossessedItems(); else ResetItemDurability(); + } + } + + private IEnumerator RotatePickup() + { + while (isRoundStarted) + { + if (isRotating) + { + RefreshItems(); + } + yield return Timing.WaitForSeconds(scpInterval); + } + } + + private void CorrodePlayer(Player player) + { + if (useDamageOverride) + { + player.SetHealth(player.GetHealth() - corrodeDamage, DamageType.NONE); + } + else + { + player.Damage(corrodeDamage, DamageType.NONE); + } + + if (corrodeLifeSteal && scpPlayer != null) + { + int currHP = scpPlayer.GetHealth(); + scpPlayer.SetHealth(currHP + corrodeDamage > scpHealth ? scpHealth : currHP + corrodeDamage); + } + } + + public bool HandleHideTagHook(CharacterClassManager __instance) + { + bool a = __instance.SteamId == scpPlayer?.SteamId; + if (a) __instance.TargetConsolePrint(__instance.connectionToClient, hiding, "green"); + return !a; + } + } } diff --git a/scp035/Plugin.cs b/scp035/Plugin.cs index 1401903..6676d67 100644 --- a/scp035/Plugin.cs +++ b/scp035/Plugin.cs @@ -1,54 +1,54 @@ -using Smod2.Attributes; -using Harmony; +using Harmony; +using Smod2.Attributes; namespace scp035 { - [PluginDetails( - author = "Cyanox", - name = "SCP-035", - description = "Adds SCP-035 to the game.", - id = "cyan.scp035", - version = "1.5.4", - SmodMajor = 3, - SmodMinor = 0, - SmodRevision = 0 - )] - public class Plugin : Smod2.Plugin - { - public override void OnDisable() { } + [PluginDetails( + author = "Cyanox", + name = "SCP-035", + description = "Adds SCP-035 to the game.", + id = "cyan.scp035", + version = "1.5.4", + SmodMajor = 3, + SmodMinor = 0, + SmodRevision = 0 + )] + public class Plugin : Smod2.Plugin + { + public override void OnDisable() { } - public override void OnEnable() { } + public override void OnEnable() { } - public override void Register() - { - HarmonyInstance.Create(Details.id).PatchAll(); + public override void Register() + { + HarmonyInstance.Create(Details.id).PatchAll(); - // This is for the damage override, don't AngryLaserBoi me - AddEventHandlers(new EventHandler(this), Smod2.Events.Priority.High); + // This is for the damage override, don't AngryLaserBoi me + AddEventHandlers(new EventHandler(this), Smod2.Events.Priority.High); - AddConfig(new Smod2.Config.ConfigSetting("035_possible_items", new[] { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 23, 24, 25, 26, 30 - }, false, true, "The possible item IDs SCP-035 can disguise as.")); - AddConfig(new Smod2.Config.ConfigSetting("035_health", 300, false, true, "The amount of health SCP-035 should have.")); - AddConfig(new Smod2.Config.ConfigSetting("035_rotate_interval", 120f, false, true, "The time in seconds before the item representing SCP-035 will refresh.")); - AddConfig(new Smod2.Config.ConfigSetting("035_scp_friendly_fire", false, false, true, "If SCP-035 is allowed to damage other SCPs.")); - AddConfig(new Smod2.Config.ConfigSetting("035_infected_item_count", 1, false, true, "The number of items at a time that are possessed by SCP-035.")); - AddConfig(new Smod2.Config.ConfigSetting("035_spawn_new_items", false, false, true, "If the plugin should spawn a new item on top of a randomly selected item rather than possessing already existing items.")); - AddConfig(new Smod2.Config.ConfigSetting("035_use_damage_override", false, false, true, "If the plugin should override AdmintoolBox's damage blockers.")); - AddConfig(new Smod2.Config.ConfigSetting("035_win_with_tutorial", false, false, true, "If SCP-035 should win with tutorials.")); - AddConfig(new Smod2.Config.ConfigSetting("035_change_to_zombie", false, false, true, "If SCP-035 should change to a zombie when the SCP team should win. This may fix round lingering issues due to conflicting end conditions.")); - AddConfig(new Smod2.Config.ConfigSetting("035_tutorial_friendly_fire", false, false, true, "If friendly fire between SCP-035 and tutorials is enabled.")); - AddConfig(new Smod2.Config.ConfigSetting("035_corrode_players", true, false, true, "If SCP-035 should do passive damage to players within a range of him.")); - AddConfig(new Smod2.Config.ConfigSetting("035_corrode_distance", 1.5f, false, true, "The distance in which a player will take corrosion damage from SCP-035.")); - AddConfig(new Smod2.Config.ConfigSetting("035_corrode_damage", 5, false, true, "The amount of damage to do to a player within range of corrosion.")); - AddConfig(new Smod2.Config.ConfigSetting("035_corrode_interval", 1f, false, true, "The interval in seconds for corrosion damage.")); - AddConfig(new Smod2.Config.ConfigSetting("035_corrode_life_steal", true, false, true, "If SCP-035 should steal any health taken from other players by corrosion.")); - AddConfig(new Smod2.Config.ConfigSetting("035_enabled", true, false, true, "If SCP-035 is enabled.")); + AddConfig(new Smod2.Config.ConfigSetting("035_possible_items", new[] { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 23, 24, 25, 26, 30 + }, false, true, "The possible item IDs SCP-035 can disguise as.")); + AddConfig(new Smod2.Config.ConfigSetting("035_health", 300, false, true, "The amount of health SCP-035 should have.")); + AddConfig(new Smod2.Config.ConfigSetting("035_rotate_interval", 120f, false, true, "The time in seconds before the item representing SCP-035 will refresh.")); + AddConfig(new Smod2.Config.ConfigSetting("035_scp_friendly_fire", false, false, true, "If SCP-035 is allowed to damage other SCPs.")); + AddConfig(new Smod2.Config.ConfigSetting("035_infected_item_count", 1, false, true, "The number of items at a time that are possessed by SCP-035.")); + AddConfig(new Smod2.Config.ConfigSetting("035_spawn_new_items", false, false, true, "If the plugin should spawn a new item on top of a randomly selected item rather than possessing already existing items.")); + AddConfig(new Smod2.Config.ConfigSetting("035_use_damage_override", false, false, true, "If the plugin should override AdmintoolBox's damage blockers.")); + AddConfig(new Smod2.Config.ConfigSetting("035_win_with_tutorial", false, false, true, "If SCP-035 should win with tutorials.")); + AddConfig(new Smod2.Config.ConfigSetting("035_change_to_zombie", false, false, true, "If SCP-035 should change to a zombie when the SCP team should win. This may fix round lingering issues due to conflicting end conditions.")); + AddConfig(new Smod2.Config.ConfigSetting("035_tutorial_friendly_fire", false, false, true, "If friendly fire between SCP-035 and tutorials is enabled.")); + AddConfig(new Smod2.Config.ConfigSetting("035_corrode_players", true, false, true, "If SCP-035 should do passive damage to players within a range of him.")); + AddConfig(new Smod2.Config.ConfigSetting("035_corrode_distance", 1.5f, false, true, "The distance in which a player will take corrosion damage from SCP-035.")); + AddConfig(new Smod2.Config.ConfigSetting("035_corrode_damage", 5, false, true, "The amount of damage to do to a player within range of corrosion.")); + AddConfig(new Smod2.Config.ConfigSetting("035_corrode_interval", 1f, false, true, "The interval in seconds for corrosion damage.")); + AddConfig(new Smod2.Config.ConfigSetting("035_corrode_life_steal", true, false, true, "If SCP-035 should steal any health taken from other players by corrosion.")); + AddConfig(new Smod2.Config.ConfigSetting("035_enabled", true, false, true, "If SCP-035 is enabled.")); AddConfig(new Smod2.Config.ConfigSetting("035_bc_time", 10, true, "Broadcast time")); - AddTranslation(new Smod2.Lang.LangSetting("infection", "You are SCP-035! You have infected a body and have gained control over it, use it to help the other SCPs!", "SCP035")); - AddTranslation(new Smod2.Lang.LangSetting("picked", "You have picked up SCP-035. He has infected your body and is now in control of you.", "SCP035")); - AddTranslation(new Smod2.Lang.LangSetting("hiding", "You're not trying to exploit the system by hiding your tag as SCP-035 now, are you?", "SCP035)")); + AddTranslation(new Smod2.Lang.LangSetting("035_infection", "You are SCP-035! You have infected a body and have gained control over it, use it to help the other SCPs!", "SCP035")); + AddTranslation(new Smod2.Lang.LangSetting("035_picked", "You have picked up SCP-035. He has infected your body and is now in control of you.", "SCP035")); + AddTranslation(new Smod2.Lang.LangSetting("035_hiding", "You're not trying to exploit the system by hiding your tag as SCP-035 now, are you?", "SCP035)")); } - } + } }