public Truck()
 {
     if (AvailableColors.Count > 0)
     {
         Color = AvailableColors[0];
         AvailableColors.Remove(Color);
     }
     else
     {
         Color = "blue";
     }
 }
Beispiel #2
0
 //adds the color specified, switches to it, special case for first color added
 public static void AddColor(ColorIDs.Colors c)
 {
     if (!AvailableColors.Contains(c))
     {
         AvailableColors.Add(c);
         SwitchColor();
     }
     if (AvailableColors.Contains(ColorIDs.Colors.NONE))
     {
         //special case: for the first color added, remove NONE from the available colors
         //list and force the index back down to the first element (which is now our color)
         AvailableColors.Remove(ColorIDs.Colors.NONE);
         index = 0;
     }
 }
        public override void OnStart()
        {
            base.OnStart();

            if (CheepsAmongUsMod.CheepsAmongUsMod.IsDecidingClient)
            {
                Task.Run(async() =>
                {
                    await Task.Delay(1500); // Wait a bit

                    Random random = new Random();

                    List <ColorType> AvailableColors = new List <ColorType>((IEnumerable <ColorType>)Enum.GetValues(typeof(ColorType)));
                    List <ColorType> AvailableNames  = new List <ColorType>(AvailableColors);

                    foreach (var player in PlayerController.AllPlayerControls)
                    {
                        #region ---------- This is required, if more than 12 players are online, as the game only offers 12 colors ----------
                        if (AvailableColors.Count == 0 || AvailableNames.Count == 0)
                        {
                            AvailableColors = new List <ColorType>((IEnumerable <ColorType>)Enum.GetValues(typeof(ColorType)));
                            AvailableNames  = new List <ColorType>(AvailableColors);
                        }
                        #endregion

                        #region ---------- Select random color and name ----------
                        var color = AvailableColors[random.Next(AvailableColors.Count)];
                        var name  = AvailableNames[random.Next(AvailableNames.Count)];

                        AvailableColors.Remove(color);
                        AvailableNames.Remove(name);
                        #endregion

                        #region ---------- As long as the name matches the color, change it ----------
                        while (color == name)
                        {
                            name = AvailableNames[random.Next(AvailableNames.Count)];
                        }
                        #endregion

                        if (player.IsLocalPlayer)
                        {
                            player.RpcSetColor(color);
                            player.RpcSetHat(HatType.NoHat);
                            player.RpcSetName(name.ToString());
                            player.RpcSetSkin(SkinType.None);
                            player.RpcSetPet(PetType.NoPet);
                        }
                        else
                        {
                            var writer = RpcManager.StartRpc(Confusion.ConfusionRpc);
                            writer.Write((byte)0);
                            writer.Write(player.PlayerId);
                            writer.Write((byte)color);
                            writer.Write(name.ToString());
                            writer.EndMessage();
                        }
                    }
                });
            }
        }
Beispiel #4
0
        public override void Loop()
        {
            base.Loop();

            GameModeSettingsAddition = $"\nColor Swap Delay: {Functions.ColorPurple}{SwapDelay}s";

            if (!IsInGame)
            {
                return;
            }

            string toDisplay = $"----- {Functions.ColorYellow}Color Swap []-----\n";

            if (SwapDelay - (Functions.GetUnixTime() - LastSwapped) <= 0 && LastSwapped != 0)
            {
                LastSwapped = Functions.GetUnixTime();

                Random random = new Random();

                if (CheepsAmongUsMod.CheepsAmongUsMod.IsDecidingClient)
                {
                    List <ColorType> AvailableColors = new List <ColorType>((IEnumerable <ColorType>)Enum.GetValues(typeof(ColorType)));

                    foreach (var player in PlayerController.AllPlayerControls)
                    {
                        #region ---------- This is required, if more than 12 players are online, as the game only offers 12 colors ----------
                        if (AvailableColors.Count == 0)
                        {
                            AvailableColors = new List <ColorType>((IEnumerable <ColorType>)Enum.GetValues(typeof(ColorType)));
                        }
                        #endregion

                        #region ---------- Select random color ----------
                        var toSwitchTo = AvailableColors[random.Next(AvailableColors.Count)];
                        AvailableColors.Remove(toSwitchTo);
                        #endregion

                        if (player.IsLocalPlayer)
                        {
                            player.RpcSetColor(toSwitchTo);
                            player.RpcSetHat(HatType.NoHat);
                            player.RpcSetName("");
                            player.RpcSetSkin(SkinType.None);
                            player.RpcSetPet(PetType.NoPet);
                        }
                        else
                        {
                            RpcManager.SendRpc(ColorSwap.ColorSwapRpc, new byte[] { 1, player.PlayerId, (byte)toSwitchTo });
                        }
                    }
                }
            }

            toDisplay += $"Color Swap in [11c5edff]{ SwapDelay - (Functions.GetUnixTime() - LastSwapped) }s[]";

            string curText = PlayerHudManager.TaskText;

            if (!curText.Contains(Delimiter))
            {
                PlayerHudManager.TaskText = toDisplay + Delimiter + PlayerHudManager.TaskText;
            }
            else if (!curText.Contains(toDisplay))
            {
                string toReplace = curText.Split(new string[] { Delimiter }, StringSplitOptions.None)[0];

                PlayerHudManager.TaskText = curText.Replace(toReplace, toDisplay);
            }
        }