Esempio n. 1
0
        void AddDice(int quantity, int sides, string label, double modifier, VantageKind vantage, int creatureId, string backColor = null, string fontColor = null, string playerName = null)
        {
            if (vantage != VantageKind.Normal && quantity == 1)
            {
                quantity = 2;
            }

            DiceDto diceDto = new DiceDto();

            if (backColor != null)
            {
                diceDto.BackColor = backColor;
            }
            if (fontColor != null)
            {
                diceDto.FontColor = fontColor;
            }
            diceDto.Label = label;
            if (playerName == null)
            {
                playerName = label;
            }
            diceDto.PlayerName = playerName;
            diceDto.CreatureId = creatureId;
            diceDto.Quantity   = quantity;
            diceDto.Sides      = sides;
            diceDto.Modifier   = modifier;
            diceDto.Vantage    = vantage;
            DiceDtos.Add(diceDto);
        }
Esempio n. 2
0
        public ViewerQueueDto(Queue <DiceRoll> viewerRollQueue)
        {
            Command       = "UpdateViewerRollQueue";
            ViewerRollDto = new List <ViewerRollDto>();

            int queuePosition = 0;

            foreach (DiceRoll diceRoll in viewerRollQueue)
            {
                ViewerRollDto viewerRollDto = new ViewerRollDto();
                if (diceRoll.DiceDtos != null && diceRoll.DiceDtos.Count > 0)
                {
                    DiceDto diceDto = diceRoll.DiceDtos[0];
                    viewerRollDto.Label         = diceDto.Label;
                    viewerRollDto.RollId        = diceRoll.RollID;
                    viewerRollDto.UserName      = diceRoll.Viewer;
                    viewerRollDto.FontColor     = diceDto.BackColor;
                    viewerRollDto.OutlineColor  = diceDto.FontColor;
                    viewerRollDto.RollStr       = GetRollStr(diceRoll.DiceDtos);
                    viewerRollDto.QueuePosition = queuePosition;
                    queuePosition++;
                    ViewerRollDto.Add(viewerRollDto);
                    if (queuePosition >= INT_MaxViewersInQueueToSend)
                    {
                        return;
                    }
                }
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public DiceFront Get()
        {
            var map = new DemoMap("map1");

            var dice = new DiceDto();

            return(new DiceFront(dice.RollDice()));
        }
Esempio n. 5
0
        public void HaveFun(Game room, StringBuilder sb, string preferredMap, bool isSingle, int singleCharId)
        {
            int roomId = room.Id;

            //Create dice
            DiceDto dice = new DiceDto();

            //Add Characters to the room
            var game       = context.Games.FirstOrDefault(g => g.Id == room.Id);
            var characters = new List <Character>();

            foreach (var gc in game.Characters)
            {
                var character = gc.Character;
                characters.Add(character);
            }


            if (preferredMap == "demomap")
            {
                var map         = new DemoMap("map1");
                var playableMap = map.GenerateMap();
                SetOnStart(room, playableMap, roomId);// set all chars on start
                if (!isSingle)
                {
                    ProceedGame(game, sb, playableMap, characters, dice, roomId);
                }
                else
                {
                    var gaChar       = context.GameCharacters.FirstOrDefault(gc => gc.CharacterId == singleCharId && gc.GameId == roomId);
                    var singlePlayer = new SinglePlayer(context, reader, writer, numberGenerator);
                    singlePlayer.StartSinglePlayer(dice, gaChar, playableMap, characters, sb, roomId, game);
                }
            }
            else if (preferredMap == "firstmap")
            {
                var firstMap          = new FirstMapFrontEnd();
                var generatedFirstMap = firstMap.GenerateFirstMap();
                SetOnStart(room, generatedFirstMap, roomId);// set all chars on start
                if (!isSingle)
                {
                    ProceedGame(game, sb, generatedFirstMap, characters, dice, roomId);
                }
                else
                {
                    var gaChar       = context.GameCharacters.FirstOrDefault(gc => gc.CharacterId == singleCharId && gc.GameId == roomId);
                    var singlePlayer = new SinglePlayer(context, reader, writer, numberGenerator);
                    singlePlayer.StartSinglePlayer(dice, gaChar, generatedFirstMap, characters, sb, roomId, game);
                }
            }
        }
        private static void SavingThrowForTargetsRequested(object sender, SavingThrowRollEventArgs ea)
        {
            // TODO: Get all the targets.
            if (Targeting.ActualKind.HasFlag(TargetKind.Volume))
            {
                CharacterPositions allTargetsInVolume = TargetManager.GetAllCreaturesInVolume();
                if (allTargetsInVolume == null)
                {
                    return;
                }

                DiceRoll diceRoll = new DiceRoll(DiceRollType.SavingThrow, VantageKind.Normal, ea.DamageDieStr);
                diceRoll.SavingThrow = ea.Ability;

                diceRoll.SuppressLegacyRoll = true;
                diceRoll.Conditions         = ea.Condition;
                if (ea.CastedSpell?.SpellCaster is Character spellCaster)
                {
                    diceRoll.HiddenThreshold = spellCaster.SpellSaveDC;
                }

                foreach (CharacterPosition characterPosition in allTargetsInVolume.Characters)
                {
                    Creature creature = CreatureManager.GetCreatureFromTaleSpireId(characterPosition.ID);
                    DiceDto  diceDto  = null;
                    if (creature is Character player)
                    {
                        diceDto = DiceDto.AddD20ForCharacter(player, $"{player.Name}'s Save", player.GetSavingThrowModifier(ea.Ability), DieCountsAs.savingThrow);
                    }
                    else
                    {
                        InGameCreature inGameCreature = AllInGameCreatures.GetByCreature(creature);
                        if (inGameCreature != null)
                        {
                            diceDto = DiceDto.D20FromInGameCreature(inGameCreature, DiceRollType.SavingThrow, diceRoll.SavingThrow);
                        }
                    }
                    if (diceDto == null)
                    {
                        continue;
                    }

                    diceRoll.DiceDtos.Add(diceDto);
                    diceRoll.SpellID = ea.CastedSpell.ID;                        // Add ea.SpellGuid so we can undo the effect after the spell dispels.
                }
                SeriouslyRollTheDice(diceRoll);
            }
        }
Esempio n. 7
0
        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);
        }
        private void AddConcentrationSaveForPlayer(DiceRoll diceRoll, int playerId)
        {
            string    backgroundColor, textColor;
            Character player = AllPlayers.GetFromId(playerId);

            GetPlayerDieColor(player, out backgroundColor, out textColor);
            string name = "";

            if (player != null)
            {
                name = player.name;
            }
            DiceDto diceDto = CreateDie(playerId, backgroundColor, textColor, name, 20, STR_ConcentrationSave);

            diceDto.Label = STR_ConcentrationSave;
            diceRoll.DiceDtos.Add(diceDto);
        }
Esempio n. 9
0
        public override void PrepareRoll(DiceRoll diceRoll)
        {
            base.PrepareRoll(diceRoll);
            diceRoll.SavingThrow        = Ability.constitution;
            diceRoll.SuppressLegacyRoll = true;
            string    backgroundColor, textColor;
            Character player = AllPlayers.GetFromId(PlayerId);

            GetPlayerDieColor(player, out backgroundColor, out textColor);
            string name = "";

            if (player != null)
            {
                name = player.name;
            }
            DiceDto diceDto = CreateDie(backgroundColor, textColor, name, 20, STR_ConcentrationSave);

            diceDto.Label = STR_ConcentrationSave;
            diceRoll.DiceDtos.Add(diceDto);
        }
Esempio n. 10
0
        public void StartSinglePlayer(DiceDto dice, GameCharacter singleGaChar, MapSection[][] map, List <Character> characters, StringBuilder sb, int roomId, Game game)
        {
            bool hasReachedFinalSpot = false;

            var playerInTurn = 1;

            while (!hasReachedFinalSpot)
            {
                if (singleGaChar.Character == characters[playerInTurn - 1])
                {
                    Console.WriteLine($"Type R in order to roll the dice!");
                    var input = Console.ReadLine();
                    while (input != "R")
                    {
                        Console.WriteLine("Invalid input, please try again:");
                        input = Console.ReadLine();
                    }
                }

                var diceResult = dice.RollDice();

                var character = characters[playerInTurn - 1];
                var chNum     = context.GameCharacters.FirstOrDefault(c => c.CharacterId == character.Id && c.GameId == roomId)
                                .MapSectionNumber;
                var chNewPos  = chNum + diceResult;
                var charMoved = false;

                for (int i = 0; i < map.Length; i++)
                {
                    for (int j = 0; j < map[i].Length; j++)
                    {
                        if (map[i][j].Number == chNewPos)
                        {
                            if (i == map.Length - 1 && j == map[i].Length - 1)
                            {
                                sb.AppendLine($"{character.Name} wins the game by reaching the final first!");

                                //add money, xp and winrate for winner


                                AddWinnerStats(roomId, character.Id, game);
                                AddGamesPlayedForPlayers(roomId);
                                UpdateCharacterPositionInDb(character, map[i][j].X, map[i][j].Y, map[i][j].Number, roomId);

                                hasReachedFinalSpot = true;
                                charMoved           = true;
                                break;
                            }

                            var positionNumber = map[i][j].Number;
                            UpdateCharacterPositionInDb(character, map[i][j].X, map[i][j].Y, positionNumber, roomId);
                            Console.WriteLine($"{character.Name} successfully moved to square number {chNewPos}");
                            //TODO - add clauses to check if it is a special square and what actions should
                            //be taken in that case
                            try
                            {
                                CheckIfSpecialSquare(map, i, j, positionNumber, character, roomId);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                            if (context.GameCharacters.SingleOrDefault(ch => ch.CharacterId == character.Id && ch.GameId == roomId).SpellsId.Any())
                            {
                                Console.WriteLine("You can make an atack now. If you want to attack press spacebar, if you want to continue without attacking press any key");
                                var keyboardInput = new KeyboardInput();
                                if (singleGaChar.Character != character)
                                {
                                    AttackACharacter characterAttack = new AttackACharacter(context, map, roomId, character.Id);
                                    bool             isInGame        = true;
                                    while (isInGame)
                                    {
                                        try
                                        {
                                            characterAttack.SinglePlayerAttack(numberGenerator);
                                            isInGame = false;
                                        }
                                        catch (Exception ex)
                                        {
                                            if (ex.Message == "Sorry, there ain't any characters in your range...")
                                            {
                                                Console.WriteLine(ex.Message);
                                                break;
                                            }
                                            Console.WriteLine($"Well, you didn't pay much attention, didn't you? Try again now...");
                                        }
                                    }
                                }
                                else
                                {
                                    if (keyboardInput.ReadInput())
                                    {
                                        AttackACharacter characterAttack = new AttackACharacter(context, map, roomId, character.Id);
                                        bool             isInGame        = true;
                                        while (isInGame)
                                        {
                                            try
                                            {
                                                characterAttack.Attack();
                                                isInGame = false;
                                            }
                                            catch (Exception ex)
                                            {
                                                if (ex.Message == "Sorry, there ain't any characters in your range...")
                                                {
                                                    Console.WriteLine(ex.Message);
                                                    break;
                                                }
                                                Console.WriteLine($"Well, you didn't pay much attention, didn't you? Try again now...");
                                            }
                                        }
                                    }
                                }
                            }
                            charMoved = true;
                        }
                        else if (chNewPos > map[map.Length - 1][map[0].Length - 1].Number)
                        {
                            Console.WriteLine("Better luck next time, you can't go further than the final :)");
                            charMoved = true;
                            break;
                        }
                    }

                    if (charMoved)
                    {
                        break;
                    }
                }

                if (playerInTurn != characters.Count)
                {
                    playerInTurn++;
                }
                else
                {
                    playerInTurn = 1;
                }
            }
        }