Example #1
0
        public void UserChats(string username)
        {
            if (username == "dragonhumpersdm" || username == "dragonhumpers")
            {
                return;
            }

            DndViewer viewer = AllViewers.Get(username);

            viewer.LastChatMessage = DateTime.Now;

            if (viewer.AlreadySeen)
            {
                return;
            }

            viewer.AlreadySeen = true;

            if (viewer.CardsPlayed > 0)
            {
                VipGreeting(viewer.UserName);
                if (viewer.HasAnyCharges())
                {
                    TellViewerAboutRemainingCharges(viewer);
                }
            }
            else
            {
                NormalGreeting(viewer.UserName);
            }
        }
        private static DiceDto AddDieStr(DiceRoll diceRoll, CardDto cardDto, DndViewer viewer, string dieStr, string dieLabelOverride = null, int targetCharacterId = int.MinValue)
        {
            string      dieBackColorOverride = viewer.DieBackColor;
            string      dieTextColorOverride = viewer.DieTextColor;
            int         parenIndex           = dieStr.IndexOf("(");
            DamageType  damageType           = DamageType.None;
            DieCountsAs dieCountsAs          = DieCountsAs.totalScore;
            string      diePlayerName        = cardDto.Card.UserName;
            double      modifier             = 0;
            double      scaleOverride        = viewer.Reputation + 0.30;
            int         dieOwnerOverride     = int.MinValue;

            if (parenIndex >= 0)
            {
                ProcessDieDetails(diceRoll, targetCharacterId, ref dieStr, ref dieBackColorOverride, ref dieTextColorOverride, parenIndex, ref damageType, ref dieCountsAs, ref modifier, ref diePlayerName, ref scaleOverride, ref dieOwnerOverride);
            }

            string[] dieParts = dieStr.Split('d');
            if (dieParts.Length != 2)
            {
                return(null);
            }

            string dieLabel;

            if (string.IsNullOrWhiteSpace(dieLabelOverride) || dieLabelOverride.Trim() == "\"\"")
            {
                dieLabel = $"{cardDto.Card.UserName}";
            }
            else
            {
                dieLabel = dieLabelOverride.Trim().TrimStart('"').TrimEnd('"');
            }

            int quantity;
            int sides;

            if (!int.TryParse(dieParts[0], out quantity) || !int.TryParse(dieParts[1], out sides))
            {
                return(null);
            }
            DiceDto diceDto = new DiceDto()
            {
                PlayerName  = diePlayerName,
                CreatureId  = dieOwnerOverride,
                Sides       = sides,
                Quantity    = quantity,
                Label       = dieLabel.Replace("target_name", DndUtils.GetFirstName(diePlayerName)),
                Scale       = scaleOverride,
                Modifier    = modifier,
                DamageType  = damageType,
                BackColor   = dieBackColorOverride,
                FontColor   = dieTextColorOverride,
                DieCountsAs = dieCountsAs,
                Data        = cardDto.Card.Guid
            };

            diceRoll.DiceDtos.Add(diceDto);
            return(diceDto);
        }
Example #3
0
        /// <summary>
        /// Adds the specified charge to the specified viewer and returns the total charge count for the specified chargeName.
        /// </summary>
        /// <param name="viewerName">The name of the viewer to add the charges to.</param>
        /// <param name="chargeName">The name of the charge to add.</param>
        /// <param name="chargeCount">The number of charges to add.</param>
        /// <returns>The total charge count for the specified chargeName.</returns>
        public static int AddCharge(string viewerName, string chargeName, int chargeCount)
        {
            if (DndViewer.TestingSayAnything)
#pragma warning disable CS0162 // Used for testing.
            {
                viewerName = "SayAnythingTester";
            }

            DndViewer viewer = Get(viewerName);
            return(viewer.AddCharge(chargeName, chargeCount));
        }
 public static void Execute(string command, CardDto cardDto, DndViewer viewer)
 {
     if (command.StartsWith(CardDto.CMD_RollDie))
     {
         RollViewerDie(command, cardDto, viewer);
     }
     else
     {
         Expressions.Do(command);
     }
 }
Example #5
0
        public static DndViewer Get(string userName)
        {
            DndViewer foundUser = KnownViewers.FirstOrDefault(x => x.UserName == userName);

            if (foundUser == null)
            {
                foundUser = new DndViewer(userName);
                KnownViewers.Add(foundUser);
            }
            return(foundUser);
        }
        static string GetDieTextColor(Creature targetCreature, string dieBackColor)
        {
            if (targetCreature is Character player)
            {
                return(player.dieFontColor);
            }
            InGameCreature inGameCreature = AllInGameCreatures.GetByCreature(targetCreature);

            if (inGameCreature != null)
            {
                return(inGameCreature.ForegroundHex);
            }
            return(DndViewer.GetDieTextColor(dieBackColor));
        }
        static DiceRoll CreateRoll(string command, CardDto cardDto, DndViewer viewer)
        {
            string parameterStr = command.EverythingAfter("(").EverythingBeforeLast(")");

            string[] parameters = parameterStr.Split(',');
            if (parameters.Length < 2)
            {
                return(null);
            }

            DiceRoll diceRoll = new DiceRoll(DiceRollType.ViewerRoll);

            diceRoll.AddTrailingEffects(viewer.TrailingEffects);

            HueSatLight hueSatLight = new HueSatLight(viewer.DieBackColor);

            CorrectHueShifts(diceRoll, hueSatLight);
            diceRoll.DieTotalMessage  = $"{cardDto.Card.UserName}'s {cardDto.Card.CardName}";
            diceRoll.TextOutlineColor = viewer.DieTextColor;
            diceRoll.TextFillColor    = viewer.DieBackColor;
            diceRoll.DiceGroup        = DiceGroup.Viewers;
            diceRoll.RollScope        = RollScope.Viewer;
            diceRoll.RollID           = cardDto.InstanceID;
            diceRoll.Viewer           = cardDto.Card.UserName;

            for (int i = 0; i < parameters.Length; i += 2)
            {
                string dieLabel = parameters[i + 1].Trim();
                string dieStr   = parameters[i].Trim();
                if (dieStr.Contains("save:"))
                {
                    foreach (int targetCharacterId in cardDto.TargetCharacterIds)
                    {
                        DiceDto diceDto = AddDieStr(diceRoll, cardDto, viewer, dieStr, dieLabel, targetCharacterId);
                        diceDto.DieCountsAs = DieCountsAs.savingThrow;
                    }
                }
                else
                {
                    AddDieStr(diceRoll, cardDto, viewer, dieStr, dieLabel);
                }
            }

            savedCardsForViewerDieRolls.Add(cardDto);

            return(diceRoll);
        }
Example #8
0
        public static DndViewer Get(string userName)
        {
            DndViewer foundUser;

            if (RandomlyReplaceDragonHumpersViewerWithOthers && userName == "dragonhumpers")
            {
                foundUser = KnownViewers[new Random().Next(KnownViewers.Count)];                  // Select a random user.
            }
            else
            {
                foundUser = KnownViewers.FirstOrDefault(x => x.UserName == userName);
            }

            if (foundUser == null)
            {
                foundUser = new DndViewer(userName);
                KnownViewers.Add(foundUser);
            }
            return(foundUser);
        }
Example #9
0
        void TellViewerAboutRemainingCharges(DndViewer viewer)
        {
            string result      = string.Empty;
            int    chargeCount = 0;

            foreach (string key in viewer.charges.Keys)
            {
                if (viewer.charges[key] > 0)
                {
                    chargeCount += viewer.charges[key];
                    result      += $"{key} ({viewer.charges[key]}), ";
                }
            }
            result = result.TrimEnd(' ', ',');

            if (chargeCount > 0)
            {
                dungeonMasterApp.TellViewers(GetRemainingChargeMessage(viewer.UserName, result, chargeCount > 1));
            }
        }
Example #10
0
        private static void RollViewerDie(string command, CardDto cardDto, DndViewer viewer)
        {
            DiceRoll diceRoll = CreateRoll(command, cardDto, viewer);

            if (diceRoll == null)
            {
                return;
            }

            if (waitingForDiceToBeDestroyed)
            {
                if (!forceDieRollTimer.Enabled)
                {
                    forceDieRollTimer.Start();
                }
                WaitForRoll(diceRoll);
                return;
            }

            RollViewerDice(diceRoll);
        }