Beispiel #1
0
 public static bool RemoveClass(Player p)
 {
     if (!PlayerHasSubclass(p))
     {
         return(false);
     }
     TrackingAndMethods.RemoveAndAddRoles(p, true);
     return(true);
 }
Beispiel #2
0
 public override void OnDisabled()
 {
     base.OnDisabled();
     Log.Info("Subclass disabled.");
     UnregisterEvents();
     HarmonyInstance.UnpatchAll();
     foreach (Exiled.API.Features.Player player in Exiled.API.Features.Player.List)
     {
         TrackingAndMethods.RemoveAndAddRoles(player, true);
     }
     Instance = null;
 }
Beispiel #3
0
 public void OnSpawning(SpawningEventArgs ev)
 {
     Timing.CallDelayed(Subclass.Instance.CommonUtilsEnabled ? 2f : 0.1f, () =>
     {
         if (!Subclass.Instance.RealisticSizesEnabled)
         {
             ev.Player.Scale = new Vector3(1, 1, 1);
         }
         try
         {
             TrackingAndMethods.RemoveZombie(ev.Player);
             TrackingAndMethods.QueuedCassieMessages.Clear();
             if (TrackingAndMethods.NextSpawnWave.Contains(ev.Player) && TrackingAndMethods.NextSpawnWaveGetsRole.ContainsKey(ev.Player.Role))
             {
                 TrackingAndMethods.AddClass(ev.Player, TrackingAndMethods.NextSpawnWaveGetsRole[ev.Player.Role]);
             }
             else
             {
                 if (!TrackingAndMethods.PlayersWithSubclasses.ContainsKey(ev.Player))
                 {
                     if (Subclass.Instance.Scp035Enabled)
                     {
                         EPlayer scp035 = (EPlayer)Loader.Plugins.First(pl => pl.Name == "scp035").Assembly.GetType("scp035.API.Scp035Data").GetMethod("GetScp035", BindingFlags.Public | BindingFlags.Static).Invoke(null, null);
                         TrackingAndMethods.RemoveAndAddRoles(ev.Player, false, scp035?.Id == ev.Player.Id);
                     }
                     else
                     {
                         TrackingAndMethods.RemoveAndAddRoles(ev.Player, false, false);
                     }
                 }
             }
             foreach (string message in TrackingAndMethods.QueuedCassieMessages)
             {
                 Cassie.Message(message, true, false);
                 Log.Debug($"Sending message via cassie: {message}", Subclass.Instance.Config.Debug);
             }
             Timing.RunCoroutine(TrackingAndMethods.CheckRoundEnd());
         }
         catch (Exception e)
         {
             Log.Error(e);
         }
     });
 }
Beispiel #4
0
        public void OnChangingRole(ChangingRoleEventArgs ev)
        {
            Timing.CallDelayed(Subclass.Instance.CommonUtilsEnabled ? 2f : 0.1f, () =>
            {
                if (!ev.IsEscaped)
                {
                    TrackingAndMethods.RemoveAndAddRoles(ev.Player);
                }
            });
            object afkComp = ev.Player.GameObject.GetComponent("AFKComponent");

            if (afkComp != null)
            {
                if (afkComp.GetType().GetMember("PlayerToReplace").Length > 0)
                {
                    EPlayer p = (EPlayer)((FieldInfo)afkComp.GetType().GetMember("PlayerToReplace")[0]).GetValue(afkComp);
                    if (p != null)
                    {
                        if (API.PlayerHasSubclass(ev.Player))
                        {
                            SubClass subClass = API.GetPlayersSubclass(ev.Player);
                            if (!TrackingAndMethods.PlayersThatJustGotAClass.ContainsKey(p))
                            {
                                TrackingAndMethods.PlayersThatJustGotAClass.Add(p, Time.time + 5f);
                            }
                            else
                            {
                                TrackingAndMethods.PlayersThatJustGotAClass[p] = Time.time + 5f;
                            }
                            Timing.CallDelayed(1f, () =>
                            {
                                API.GiveClass(p, subClass, true);
                            });
                        }
                    }
                }
            }
        }
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            if (sender is PlayerCommandSender player)
            {
                Player p = Player.Get(player.SenderId);
                if (!p.CheckPermission("sc.giveclass"))
                {
                    response = "You do not have the necessary permissions to run this command. Requires: sc.giveclass";
                    return(false);
                }

                if (arguments.Count == 0)
                {
                    response = "Command syntax should be subclass (player id/all) [class].";
                    return(false);
                }

                try
                {
                    if (Player.Get(int.Parse(arguments.Array[arguments.Offset])) != null)
                    {
                        Player player1 = Player.Get(int.Parse(arguments.Array[arguments.Offset]));
                        if (!Subclass.Instance.Classes.ContainsKey(string.Join(" ", arguments.Array.Segment(arguments.Offset + 1))))
                        {
                            response = "Class not found.";
                            return(false);
                        }
                        else
                        {
                            SubClass sc = Subclass.Instance.Classes[string.Join(" ", arguments.Array.Segment(arguments.Offset + 1))];
                            if (!sc.AffectsRoles.Contains(player1.Role))
                            {
                                player1.SetRole(sc.AffectsRoles[rnd.Next(sc.AffectsRoles.Count)], true);
                            }
                            TrackingAndMethods.RemoveAndAddRoles(player1, true);
                            TrackingAndMethods.AddClass(player1, sc);
                            response = "Success.";
                            return(true);
                        }
                    }
                    else
                    {
                        if (Subclass.Instance.Classes.ContainsKey(string.Join(" ", arguments.Array.Segment(arguments.Offset))))
                        {
                            SubClass sc = Subclass.Instance.Classes[string.Join(" ", arguments.Array.Segment(arguments.Offset))];
                            if (!sc.AffectsRoles.Contains(p.Role))
                            {
                                p.SetRole(sc.AffectsRoles[rnd.Next(sc.AffectsRoles.Count)], true);
                            }
                            TrackingAndMethods.RemoveAndAddRoles(p, true);
                            TrackingAndMethods.AddClass(p, sc);
                            response = "Success.";
                            return(true);
                        }
                        response = "Player not found.";
                        return(false);
                    }
                }
                catch
                {
                    if (arguments.Array[arguments.Offset].ToLower() != "all")
                    {
                        if (!Subclass.Instance.Classes.ContainsKey(string.Join(" ", arguments.Array.Segment(arguments.Offset))))
                        {
                            response = "Class not found.";
                            return(false);
                        }
                        else
                        {
                            SubClass sc = Subclass.Instance.Classes[string.Join(" ", arguments.Array.Segment(arguments.Offset))];
                            if (!sc.AffectsRoles.Contains(p.Role))
                            {
                                p.SetRole(sc.AffectsRoles[rnd.Next(sc.AffectsRoles.Count)], true);
                            }
                            TrackingAndMethods.RemoveAndAddRoles(p, true);
                            TrackingAndMethods.AddClass(p, sc);
                            response = "Success.";
                            return(true);
                        }
                    }
                    else
                    {
                        if (!Subclass.Instance.Classes.ContainsKey(string.Join(" ", arguments.Array.Segment(arguments.Offset + 1))))
                        {
                            response = "Class not found.";
                            return(false);
                        }
                        else
                        {
                            SubClass sc = Subclass.Instance.Classes[string.Join(" ", arguments.Array.Segment(arguments.Offset + 1))];
                            foreach (Player p1 in Player.List)
                            {
                                if (p1.Role == RoleType.Spectator)
                                {
                                    continue;
                                }
                                if (!sc.AffectsRoles.Contains(p1.Role))
                                {
                                    p1.SetRole(sc.AffectsRoles[rnd.Next(sc.AffectsRoles.Count)], true);
                                }
                                TrackingAndMethods.RemoveAndAddRoles(p1, true);
                                TrackingAndMethods.AddClass(p1, sc);
                            }
                            response = "Success.";
                            return(true);
                        }
                    }
                }
            }
            response = "";
            return(false);
        }
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            Player player = Player.Get(((PlayerCommandSender)sender).SenderId);

            if (!TrackingAndMethods.PlayersWithSubclasses.ContainsKey(player) || !TrackingAndMethods.PlayersWithSubclasses[player].Abilities.Contains(AbilityType.Disguise))
            {
                Log.Debug($"Player {player.Nickname} could not disguise", Subclass.Instance.Config.Debug);
                response = "";
                return(true);
            }
            SubClass subClass = TrackingAndMethods.PlayersWithSubclasses[player];

            if (TrackingAndMethods.OnCooldown(player, AbilityType.Disguise, subClass))
            {
                Log.Debug($"Player {player.Nickname} failed to disguise", Subclass.Instance.Config.Debug);
                TrackingAndMethods.DisplayCooldown(player, AbilityType.Disguise, subClass, "disguise", Time.time);
                response = "";
                return(true);
            }

            if (!TrackingAndMethods.CanUseAbility(player, AbilityType.Disguise, subClass))
            {
                TrackingAndMethods.DisplayCantUseAbility(player, AbilityType.Disguise, subClass, "disguise");
                response = "";
                return(true);
            }

            Team mostTeam = Team.RIP;
            Dictionary <Team, int> occurrences = new Dictionary <Team, int>();

            Collider[] dcolliders = Physics.OverlapSphere(player.Position, 50);
            foreach (Collider c in dcolliders.Where(c => c.enabled && Player.Get(c.gameObject) != null))
            {
                Team t = Player.Get(c.gameObject).Team;
                if (t == Team.CDP)
                {
                    t = Team.CHI;
                }
                if (t == Team.RSC)
                {
                    t = Team.MTF;
                }
                if (!occurrences.ContainsKey(t))
                {
                    occurrences.Add(t, 0);
                }
                occurrences[t]++;
            }
            var copy = occurrences.ToList();

            copy.Sort((x, y) => y.Value.CompareTo(x.Value));
            mostTeam = copy[0].Key;
            if (mostTeam == player.Team || mostTeam == Team.RIP || mostTeam == Team.SCP)
            {
                Log.Debug($"Player {player.Nickname} failed to disguise", Subclass.Instance.Config.Debug);
                player.Broadcast(3, Subclass.Instance.Config.DisguiseFailedMessage);
                response = "";
                return(true);
            }
            RoleType role = RoleType.None;

            switch (mostTeam)
            {
            case Team.CDP:
                role = RoleType.ClassD;
                break;

            case Team.CHI:
                role = RoleType.ChaosInsurgency;
                break;

            case Team.MTF:
                role = RoleType.NtfCadet;
                break;

            case Team.RSC:
                role = RoleType.Scientist;
                break;

            case Team.TUT:
                role = RoleType.Tutorial;
                break;
            }

            bool wasLockedBefore = Round.IsLocked;

            Round.IsLocked = true;

            TrackingAndMethods.AddCooldown(player, AbilityType.Disguise);
            TrackingAndMethods.UseAbility(player, AbilityType.Disguise, subClass);

            TrackingAndMethods.PlayersThatJustGotAClass[player] = Time.time + 5f;
            TrackingAndMethods.RemoveAndAddRoles(player, true, false, false, true);

            float health    = player.Health;
            float armor     = player.ArtificialHealth;
            int   maxHealth = player.MaxHealth;
            int   maxArmor  = player.MaxArtificialHealth;

            RoleType trueRole = player.Role;

            SubClass cloneClass = new SubClass(subClass);

            cloneClass.BoolOptions["TakesFriendlyFire"] = true;

            player.SetRole(role, true);

            Timing.CallDelayed(0.1f, () =>
            {
                player.Health                = health;
                player.ArtificialHealth      = armor;
                player.IsFriendlyFireEnabled = true;
                Player scp035                = null;
                if (Subclass.Instance.Scp035Enabled)
                {
                    scp035 = (Player)Loader.Plugins.FirstOrDefault(pl => pl.Name == "scp035")?.Assembly?.GetType("scp035.API.Scp035Data")
                             ?.GetMethod("GetScp035", BindingFlags.Public | BindingFlags.Static)?.Invoke(null, null);
                }
                TrackingAndMethods.AddClass(player, cloneClass, scp035?.Id == player.Id, true, false, true);
            });

            if (subClass.StringOptions.ContainsKey("Badge") && player.RankName == subClass.StringOptions["Badge"])
            {
                player.RankName = null;
            }
            if (subClass.StringOptions.ContainsKey("BadgeColor") && player.RankColor == subClass.StringOptions["BadgeColor"])
            {
                player.RankColor = null;
            }
            Timing.CallDelayed(subClass.FloatOptions["DisguiseDuration"], () =>
            {
                if (!player.IsAlive)
                {
                    return;
                }
                TrackingAndMethods.PlayersThatJustGotAClass[player] = Time.time + 5f;
                TrackingAndMethods.RemoveAndAddRoles(player, true, false, false, true);

                float curHealth = player.Health;
                float curArmor  = player.ArtificialHealth;

                player.SetRole(trueRole, true);

                Timing.CallDelayed(Subclass.Instance.CommonUtilsEnabled ? 2f : 0.1f, () =>
                {
                    Player scp035 = null;
                    if (Subclass.Instance.Scp035Enabled)
                    {
                        scp035 = (Player)Loader.Plugins.FirstOrDefault(pl => pl.Name == "scp035")?.Assembly?.GetType("scp035.API.Scp035Data")
                                 ?.GetMethod("GetScp035", BindingFlags.Public | BindingFlags.Static)?.Invoke(null, null);
                    }

                    TrackingAndMethods.AddClass(player, subClass, scp035?.Id == player.Id, true, false, true);

                    player.MaxHealth           = maxHealth;
                    player.MaxArtificialHealth = maxArmor;
                    player.Health                = curHealth;
                    player.ArtificialHealth      = curArmor;
                    player.IsFriendlyFireEnabled = !subClass.BoolOptions["DisregardHasFF"] && subClass.BoolOptions["HasFriendlyFire"];
                });

                if (subClass.StringOptions.ContainsKey("Badge") && player.RankName == null)
                {
                    player.RankName = subClass.StringOptions["Badge"];
                }
                if (subClass.StringOptions.ContainsKey("BadgeColor") && player.RankColor == null)
                {
                    player.RankColor = subClass.StringOptions["BadgeColor"];
                }

                Round.IsLocked = wasLockedBefore;
            });
            response = "";
            return(true);
        }