Example #1
0
        public static List <PlayerActionShortcut> From(PlayerActionShortcutDto shortcutDto)
        {
            List <PlayerActionShortcut> results = new List <PlayerActionShortcut>();
            string cleanName = DndUtils.GetCleanItemName(shortcutDto.name);
            Weapon weapon    = AllWeapons.Get(cleanName);

            if (weapon == null && cleanName.IndexOf(" of ") > 0)
            {
                // Try again with the weapon...
                cleanName = cleanName.EverythingBefore(" of ");
                weapon    = AllWeapons.Get(cleanName);
            }
            Character player = AllPlayers.GetFromId(PlayerID.FromName(shortcutDto.player));

            if (weapon != null)
            {
                AddWeaponShortcuts(shortcutDto, results, weapon, player);
            }
            else
            {
                List <Spell> spells = AllSpells.GetAll(cleanName, player);
                if (spells != null && spells.Count > 0)
                {
                    AddSpellShortcuts(shortcutDto, results, player, spells);
                }
                else                 // Not a weapon or a spell.
                {
                    PlayerActionShortcut shortcut = FromAction(shortcutDto);
                    results.Add(shortcut);
                    shortcut.AddEffect(shortcutDto, "", player);
                }
            }

            return(results);
        }
Example #2
0
        public static Feature FromDto(FeatureDto featureDto)
        {
            Feature result = new Feature();

            result.Name         = DndUtils.GetName(featureDto.Name);
            result.Parameters   = DndUtils.GetParameters(featureDto.Name);
            result.ActivateWhen = featureDto.ActivateWhen;
            result.OnStartGame  = featureDto.OnStartGame;
            result.OnShortcutAvailabilityChange = featureDto.OnShortcutAvailabilityChange;
            result.Description                     = featureDto.Description;
            result.OnActivate                      = featureDto.OnActivate;
            result.ActivationMessage               = featureDto.ActivationMessage;
            result.OnDeactivate                    = featureDto.OnDeactivate;
            result.DeactivationMessage             = featureDto.DeactivationMessage;
            result.OnPlayerCastsSpell              = featureDto.OnPlayerCastsSpell;
            result.AfterPlayerSwingsWeapon         = featureDto.AfterPlayerSwingsWeapon;
            result.BeforePlayerRollsDice           = featureDto.BeforePlayerRollsDice;
            result.OnPlayerRaisesWeapon            = featureDto.OnPlayerRaisesWeapon;
            result.OnPlayerStartsTurn              = featureDto.OnPlayerStartsTurn;
            result.OnPlayerSaves                   = featureDto.OnPlayerSaves;
            result.OnRollComplete                  = featureDto.OnRollComplete;
            result.ActivateShortcutDisplayText     = featureDto.ActivateShortcutDisplayText;
            result.DeactivateShortcutDisplayText   = featureDto.DeactivateShortcutDisplayText;
            result.ActivateShortcutAvailableWhen   = featureDto.ActivateShortcutAvailableWhen;
            result.DeactivateShortcutAvailableWhen = featureDto.DeactivateShortcutAvailableWhen;
            result.ModifiesExistingRoll            = MathUtils.IsChecked(featureDto.rollMod);
            result.Magic                    = MathUtils.IsChecked(featureDto.Magic);
            result.ActivationTime           = PlayerActionShortcut.GetTurnPart(featureDto.ActivationTime);
            result.DeactivationTime         = PlayerActionShortcut.GetTurnPart(featureDto.DeactivationTime);
            result.RequiresPlayerActivation = MathUtils.IsChecked(featureDto.RequiresActivation);
            result.Duration                 = DndTimeSpan.FromDurationStr(featureDto.Duration);
            result.Per   = DndTimeSpan.FromDurationStr(featureDto.Per);
            result.Limit = featureDto.Limit;
            return(result);
        }
        static void AddSpellShortcutsFor(Character player, KnownSpell knownSpell)
        {
            List <PlayerActionShortcut> lastShortcuts = null;
            List <ItemEffect>           spellEffects  = AllSpellEffects.GetAll(knownSpell.SpellName).OrderBy(x => x.index).ToList();

            if (spellEffects.Count == 0)
            {
                lastShortcuts = PlayerActionShortcut.FromItemSpellEffect(knownSpell.SpellName, null, player);
            }
            else
            {
                for (int i = 0; i < spellEffects.Count; i++)
                {
                    ItemEffect itemEffect = spellEffects[i];
                    if (i == 0)
                    {
                        lastShortcuts = PlayerActionShortcut.FromItemSpellEffect(knownSpell.SpellName, itemEffect, player);
                    }
                    else
                    {
                        foreach (PlayerActionShortcut playerActionShortcut in lastShortcuts)
                        {
                            playerActionShortcut.Windups.Add(WindupDto.FromItemEffect(itemEffect, playerActionShortcut.Name));
                        }
                    }
                }
            }
            if (lastShortcuts != null)
            {
                AllShortcuts.AddRange(lastShortcuts);
            }
        }
Example #4
0
        private static PlayerActionShortcut FromAction(PlayerActionShortcutDto shortcutDto, string damageStr = "", string suffix = "", int slotLevel = 0)
        {
            PlayerActionShortcut result = new PlayerActionShortcut();

            result.Description         = shortcutDto.description;
            result.AddDice             = shortcutDto.addDice;
            result.AddDiceOnHit        = shortcutDto.addDiceOnHit;
            result.AddDiceOnHitMessage = shortcutDto.addDiceOnHitMessage;
            result.AdditionalRollTitle = shortcutDto.addDiceTitle;

            result.MinDamage    = MathUtils.GetInt(shortcutDto.minDamage);
            result.PlusModifier = MathUtils.GetInt(shortcutDto.plusModifier);
            result.Name         = shortcutDto.name + suffix;

            result.Part                 = GetTurnPart(shortcutDto.time);
            result.PlayerId             = PlayerID.FromName(shortcutDto.player);
            result.Type                 = GetDiceRollType(shortcutDto.type);
            result.VantageMod           = DndUtils.ToVantage(shortcutDto.vantageMod);
            result.ModifiesExistingRoll = MathUtils.IsChecked(shortcutDto.rollMod);
            result.UsesMagic            = MathUtils.IsChecked(shortcutDto.magic);
            result.Commands             = shortcutDto.commands;
            result.SpellSlotLevel       = slotLevel;
            //player.ResetPlayerTurnBasedState();
            result.ProcessDieStr(shortcutDto, damageStr);
            result.TrailingEffects = shortcutDto.trailingEffects;
            result.DieRollEffects  = shortcutDto.dieRollEffects;

            return(result);
        }
Example #5
0
        public static PlayerActionShortcut FromSpell(PlayerActionShortcutDto shortcutDto, Character player, Spell spell, int slotLevelOverride = 0, string damageStr = null, string suffix = "")
        {
            PlayerActionShortcut result = FromAction(shortcutDto, damageStr, suffix, slotLevelOverride, player);

            result.ProficiencyBonus = (int)Math.Round(player.proficiencyBonus);
            result.ProcessDieStr(shortcutDto, damageStr);
            result.Type      = GetDiceRollType(GetDiceRollTypeStr(spell));
            result.UsesMagic = true;
            int spellSlotLevel = spell.Level;

            if (slotLevelOverride > 0)
            {
                spellSlotLevel = slotLevelOverride;
            }
            result.AddSpell(spellSlotLevel, player, spell);
            result.Description      = spell.Description;
            result.AttackingAbility = player == null ? Ability.none : player.spellCastingAbility;
            result.ProcessDieStr(shortcutDto, damageStr);
            bool mustRollDiceToCast = result.Spell.MustRollDiceToCast();
            bool isWindup           = result.Spell != null && !result.Spell.Duration.HasValue() && mustRollDiceToCast;

            result.AddEffect(shortcutDto, SpellWindupPrefix, player, spellSlotLevel, isWindup);
            if (!mustRollDiceToCast)
            {
                result.Type = DiceRollType.CastSimpleSpell;
            }

            if (player != null)
            {
                result.AttackingAbilityModifier = player.GetSpellcastingAbilityModifier();
            }

            return(result);
        }
        static void AddWeaponShortcutsFor(Character player, CarriedWeapon carriedWeapon)
        {
            List <PlayerActionShortcut> lastShortcuts = null;

            List <ItemEffect> weaponEffects = AllWeaponEffects.GetAll(carriedWeapon.Weapon.Name).OrderBy(x => x.index).ToList();;

            if (weaponEffects.Count == 0)
            {
                lastShortcuts = PlayerActionShortcut.FromWeapon(carriedWeapon, null, player);
            }
            else
            {
                for (int i = 0; i < weaponEffects.Count; i++)
                {
                    ItemEffect itemEffect = weaponEffects[i];
                    if (i == 0)
                    {
                        lastShortcuts = PlayerActionShortcut.FromWeapon(carriedWeapon, itemEffect, player);
                    }
                    else
                    {
                        foreach (PlayerActionShortcut playerActionShortcut in lastShortcuts)
                        {
                            playerActionShortcut.Windups.Add(WindupDto.FromItemEffect(itemEffect, PlayerActionShortcut.WeaponWindupPrefix + playerActionShortcut.Name));
                        }
                    }
                }
            }

            if (lastShortcuts != null)
            {
                AllShortcuts.AddRange(lastShortcuts);
            }
        }
        static void ProcessDtos(List <PlayerActionShortcutDto> playerDtos)
        {
            shortcuts = new List <PlayerActionShortcut>();

            shortcuts.Clear();

            int index = 0;
            List <PlayerActionShortcut> lastShortcuts = null;

            while (index <= playerDtos.Count - 1)
            {
                PlayerActionShortcutDto thisShortcutDto = playerDtos[index];

                if (string.IsNullOrWhiteSpace(thisShortcutDto.player))                 // appending to last entry...
                {
                    foreach (PlayerActionShortcut shortcut in lastShortcuts)
                    {
                        Character player = AllPlayers.GetFromId(shortcut.PlayerId);

                        bool isWindup = shortcut.Spell != null && !shortcut.Spell.Duration.HasValue() && shortcut.Spell.MustRollDiceToCast();
                        shortcut.AddEffect(thisShortcutDto, shortcut.lastPrefix, player, shortcut.SpellSlotLevel, isWindup);
                    }
                }
                else
                {
                    lastShortcuts = PlayerActionShortcut.From(thisShortcutDto);
                    foreach (PlayerActionShortcut shortcut in lastShortcuts)
                    {
                        shortcuts.Add(shortcut);
                    }
                }
                index++;
            }
        }
        static void AddFeatureShortcutsFor(Character player, Feature feature)
        {
            PlayerActionShortcut shortcut = PlayerActionShortcut.FromFeature(feature, player, ActivationShortcutKind.Activate);

            AllShortcuts.Add(shortcut);

            shortcut = PlayerActionShortcut.FromFeature(feature, player, ActivationShortcutKind.Deactivate);
            if (shortcut != null)
            {
                AllShortcuts.Add(shortcut);
            }
        }
Example #9
0
        public static PlayerActionShortcut FromFeature(Feature feature, Character player, ActivationShortcutKind activationShortcutKind)
        {
            if (activationShortcutKind == ActivationShortcutKind.Deactivate)
            {
                if (string.IsNullOrWhiteSpace(feature.DeactivateShortcutDisplayText))
                {
                    return(null);
                }
            }

            string   availableWhen;
            string   displayText;
            TurnPart executionTime;
            string   commands;

            if (activationShortcutKind == ActivationShortcutKind.Deactivate)
            {
                availableWhen = feature.DeactivateShortcutAvailableWhen;
                displayText   = feature.DeactivateShortcutDisplayText;
                executionTime = feature.DeactivationTime;
                commands      = $"DeactivateFeature({feature.Name})";
            }
            else
            {
                availableWhen = feature.ActivateShortcutAvailableWhen;
                displayText   = feature.ActivateShortcutDisplayText;
                executionTime = feature.ActivationTime;
                commands      = $"ActivateFeature({feature.Name})";
            }

            PlayerActionShortcut result = new PlayerActionShortcut();

            result.Description = feature.Description;

            if (string.IsNullOrEmpty(displayText))
            {
                result.DisplayText = feature.Name;
            }
            else
            {
                result.DisplayText = displayText;
            }
            result.AvailableWhen        = availableWhen;
            result.UsesMagic            = feature.Magic;
            result.ModifiesExistingRoll = feature.ModifiesExistingRoll;
            result.Part          = executionTime;
            result.PlayerId      = player.playerID;
            result.Commands      = commands;
            result.SourceFeature = feature;
            return(result);
        }
Example #10
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Creature target, CastedSpell spell)
        {
            ExpectingArguments(args, 1);
            char[] trimChars    = { '"', ' ' };
            string shortcutName = args[0].Trim(trimChars);

            if (player == null)
            {
                return(null);
            }

            PlayerActionShortcut shortcut = AllActionShortcuts.Get(player.playerID, shortcutName).FirstOrDefault();

            if (shortcut == null)
            {
                return(null);
            }
            OnActivateShortcutRequest(player, new ShortcutEventArgs(shortcut));
            return(null);
        }
Example #11
0
        private static PlayerActionShortcut FromSpell(PlayerActionShortcutDto shortcutDto, Character player, Spell spell, int slotLevelOverride = 0, string damageStr = null, string suffix = "")
        {
            PlayerActionShortcut result = FromAction(shortcutDto, damageStr, suffix, slotLevelOverride);

            result.UsesMagic = true;
            int spellSlotLevel = spell.Level;

            if (slotLevelOverride > 0)
            {
                spellSlotLevel = slotLevelOverride;
            }
            result.AddSpell(spellSlotLevel, player, spell);
            result.Description      = spell.Description;
            result.AttackingAbility = player == null ? Ability.none : player.spellCastingAbility;
            result.ProcessDieStr(shortcutDto, damageStr);
            bool isWindup = result.Spell != null && !result.Spell.Duration.HasValue() && result.Spell.MustRollDiceToCast();

            result.AddEffect(shortcutDto, SpellWindupPrefix, player, spellSlotLevel, isWindup);
            return(result);
        }
Example #12
0
        public static PlayerActionShortcut FromFeature(Feature feature, Character player)
        {
            PlayerActionShortcut result = new PlayerActionShortcut();

            result.Description = feature.Description;

            if (string.IsNullOrEmpty(feature.ShortcutName))
            {
                result.Name = feature.Name;
            }
            else
            {
                result.Name = feature.ShortcutName;
            }
            result.AvailableWhen = feature.ShortcutAvailableWhen;
            result.UsesMagic     = feature.Magic;
            result.Part          = feature.ActivationTime;
            result.PlayerId      = player.playerID;
            result.Commands      = $"ActivateFeature({feature.Name})";
            return(result);
        }
Example #13
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 2);
            char[] trimChars    = { '"', ' ' };
            string shortcutName = args[1].Trim(trimChars);

            if (player == null)
            {
                return(null);
            }

            PlayerActionShortcut shortcut = AllActionShortcuts.Get(player.IntId, shortcutName).FirstOrDefault();

            if (shortcut == null)
            {
                return(null);
            }

            int delayMs = MathUtils.GetInt(args[0].Trim());

            OnActivateShortcutRequest(player, new ShortcutEventArgs(shortcut, delayMs));
            return(null);
        }
Example #14
0
        private static PlayerActionShortcut FromWeapon(string weaponName, PlayerActionShortcutDto shortcutDto, Character player, string damageStr = null, string suffix = "", WeaponProperties weaponProperties = WeaponProperties.None, AttackType attackType = AttackType.None)
        {
            PlayerActionShortcut result = FromAction(shortcutDto, damageStr, suffix);

            result.WeaponProperties = weaponProperties;

            if (attackType == AttackType.None && weaponProperties != WeaponProperties.None)
            {
                if ((weaponProperties & WeaponProperties.Melee) == WeaponProperties.Melee)
                {
                    attackType = AttackType.Melee;
                }
                else if ((weaponProperties & WeaponProperties.Ranged) == WeaponProperties.Ranged)
                {
                    attackType = AttackType.Range;
                }
            }
            result.AttackingType = attackType;

            if ((attackType & AttackType.Range) == AttackType.Range ||
                (attackType & AttackType.MartialRange) == AttackType.MartialRange ||
                (attackType & AttackType.Melee) == AttackType.Melee ||
                (attackType & AttackType.MartialMelee) == AttackType.MartialMelee)
            {
                if (player.IsProficientWith(weaponName))
                {
                    result.ProficiencyBonus = (int)Math.Round(player.proficiencyBonus);
                }
            }
            result.UpdatePlayerAttackingAbility(player);

            result.ProcessDieStr(shortcutDto, damageStr);

            result.AddEffect(shortcutDto, WeaponWindupPrefix, player);

            return(result);
        }
Example #15
0
        public static PlayerActionShortcut FromAction(PlayerActionShortcutDto shortcutDto, string weaponDamage = "", string suffix = "", int slotLevel = 0, Character player = null)
        {
            PlayerActionShortcut result = new PlayerActionShortcut();

            result.WeaponDamage        = weaponDamage;
            result.Description         = shortcutDto.description;
            result.AddDice             = shortcutDto.addDice;
            result.AddDiceOnHit        = shortcutDto.addDiceOnHit;
            result.AddDiceOnHitMessage = shortcutDto.addDiceOnHitMessage;
            result.AdditionalRollTitle = shortcutDto.addDiceTitle;

            result.MinDamage    = MathUtils.GetInt(shortcutDto.minDamage);
            result.PlusModifier = MathUtils.GetInt(shortcutDto.plusModifier);
            result.DisplayText  = shortcutDto.name + suffix;

            result.Part = GetTurnPart(shortcutDto.time);
            if (player != null)
            {
                result.PlayerId = player.playerID;
            }
            else
            {
                result.PlayerId = AllPlayers.GetPlayerIdFromName(shortcutDto.player);
            }

            result.Type                 = GetDiceRollType(shortcutDto.type);
            result.VantageMod           = DndUtils.ToVantage(shortcutDto.vantageMod);
            result.ModifiesExistingRoll = MathUtils.IsChecked(shortcutDto.rollMod);
            result.UsesMagic            = MathUtils.IsChecked(shortcutDto.magic);
            result.Commands             = shortcutDto.commands;
            result.SpellSlotLevel       = slotLevel;
            result.TrailingEffects      = shortcutDto.trailingEffects;
            result.DieRollEffects       = shortcutDto.dieRollEffects;

            return(result);
        }
Example #16
0
 public ShortcutEventArgs(PlayerActionShortcut shortcut, int delayMs = 0)
 {
     DelayMs  = delayMs;
     Shortcut = shortcut;
 }
Example #17
0
 public ShortcutEventArgs(PlayerActionShortcut shortcut)
 {
     Shortcut = shortcut;
 }
Example #18
0
        // TODO: Put DiceRollType as a property on actionShortcut
        public static DiceRoll GetFrom(PlayerActionShortcut actionShortcut, Character player = null)
        {
            DieRollDetails bonusDie = DieRollDetails.From("");

            if (actionShortcut.CarriedWeapon != null)
            {
                if (actionShortcut.CarriedWeapon.Weapon.RequiresAmmunition() && player != null && player.ReadiedAmmunition != null)
                {
                    if (!string.IsNullOrEmpty(player.ReadiedAmmunition.DamageBonusStr))
                    {
                        bonusDie.AddRoll(player.ReadiedAmmunition.DamageBonusStr);
                    }
                }
            }

            DiceRoll diceRoll = new DiceRoll(actionShortcut.Type);

            if (player != null)
            {
                diceRoll.SingleOwnerId = player.playerID;
            }
            diceRoll.AdditionalDiceOnHit        = actionShortcut.AddDiceOnHit;
            diceRoll.AdditionalDiceOnHitMessage = actionShortcut.AddDiceOnHitMessage;
            diceRoll.AddCritFailMessages(actionShortcut.Type);
            string dieToRoll;

            if (actionShortcut.HasInstantDice())
            {
                dieToRoll = actionShortcut.InstantDice;
            }
            else
            {
                dieToRoll = actionShortcut.Dice;
            }

            if (bonusDie.DieCount > 0)
            {
                DieRollDetails tempDiceRoll = DieRollDetails.From(dieToRoll);
                tempDiceRoll.AddDetails(bonusDie);
                diceRoll.DamageHealthExtraDice = tempDiceRoll.ToString();
            }
            else
            {
                diceRoll.DamageHealthExtraDice = dieToRoll;
            }

            string overrideReplaceDamageDice = null;

            if (player != null)
            {
                overrideReplaceDamageDice = player.overrideReplaceDamageDice;
            }
            if (!string.IsNullOrEmpty(overrideReplaceDamageDice))
            {
                DieRollDetails originalRoll    = DieRollDetails.From(diceRoll.DamageHealthExtraDice);
                DieRollDetails replacementRoll = DieRollDetails.From(overrideReplaceDamageDice);
                if (replacementRoll.FirstDescriptor == "()")
                {
                    replacementRoll.FirstDescriptor = originalRoll.FirstDescriptor;
                }

                if (replacementRoll.FirstOffset == 0)
                {
                    replacementRoll.FirstOffset = originalRoll.FirstOffset;
                }

                overrideReplaceDamageDice      = replacementRoll.ToString();
                diceRoll.DamageHealthExtraDice = overrideReplaceDamageDice;
            }

            diceRoll.DamageType      = DamageType.None;         // Consider deprecating.
            diceRoll.IsMagic         = actionShortcut.UsesMagic || actionShortcut.Type == DiceRollType.WildMagicD20Check || player.usesMagicThisRoll || player.usesMagicAmmunitionThisRoll;
            diceRoll.MinDamage       = actionShortcut.MinDamage;
            diceRoll.Modifier        = actionShortcut.ToHitModifier;
            diceRoll.SecondRollTitle = actionShortcut.AdditionalRollTitle;
            if (actionShortcut.Spell != null)
            {
                diceRoll.Modifier  = player.SpellAttackBonus;
                diceRoll.SpellName = actionShortcut.Spell.Name;
                if (actionShortcut.Spell.MustRollDiceToCast())
                {
                    diceRoll.DamageHealthExtraDice = actionShortcut.Spell.DieStr;
                }
            }

            return(diceRoll);
        }
Example #19
0
 public void Modify(PlayerActionShortcut actionShortcut)
 {
 }
        static void AddFeatureShortcutsFor(Character player, Feature feature)
        {
            PlayerActionShortcut shortcut = PlayerActionShortcut.FromFeature(feature, player);

            AllShortcuts.Add(shortcut);
        }