Пример #1
0
        public void Activate(string arguments, Character player, bool forceActivation = false)
        {
            if (IsActive && !forceActivation)
            {
                return;
            }

            string activationMessage;

            if (!string.IsNullOrWhiteSpace(ActivationMessage))
            {
                activationMessage = Expressions.GetStr(DndUtils.InjectParameters(ActivationMessage, Parameters, arguments), player);
            }
            else if (player != null)
            {
                activationMessage = $"Activating {player.name}'s {Name}.";
            }
            else
            {
                activationMessage = $"Activating {Name}.";
            }

            IsActive = true;
            if (Duration.HasValue())
            {
                string alarmName = $"{player.name}.{Name}";
                History.TimeClock.CreateAlarm(Duration.GetTimeSpan(), alarmName, player).AlarmFired += Feature_Expired;
            }
            if (!string.IsNullOrWhiteSpace(OnActivate))
            {
                Expressions.Do(DndUtils.InjectParameters(OnActivate, Parameters, arguments), player);
            }
            OnRequestMessageToDungeonMaster(this, activationMessage);
            OnFeatureActivated(player, new FeatureEventArgs(this));
        }
Пример #2
0
        void SetSkillCheckBonus(string skillStr)
        {
            skillStr = skillStr.Trim();
            if (string.IsNullOrEmpty(skillStr))
            {
                return;
            }
            int lastSpacePos = skillStr.LastIndexOf(' ');

            if (lastSpacePos < 0)
            {
                return;
            }

            string skillName = skillStr.Substring(0, lastSpacePos).Trim();
            string bonusStr  = skillStr.Substring(lastSpacePos).Trim();


            if (!int.TryParse(bonusStr, out int bonus))
            {
                return;
            }

            Skills skill = DndUtils.ToSkill(skillName);

            AddSkillCheckOverride(skill, bonus);
        }
Пример #3
0
        public void Deactivate(string arguments, Character player, bool forceDeactivation = false)
        {
            if (!IsActive && !forceDeactivation)
            {
                return;
            }
            string deactivationMessage;

            if (!string.IsNullOrWhiteSpace(DeactivationMessage))
            {
                deactivationMessage = Expressions.GetStr(DndUtils.InjectParameters(DeactivationMessage, Parameters, arguments), player);
            }
            else if (player != null)
            {
                deactivationMessage = $"Deactivating {player.name}'s {Name}.";
            }
            else
            {
                deactivationMessage = $"Deactivating {Name}.";
            }

            IsActive = false;
            if (!string.IsNullOrWhiteSpace(OnDeactivate))
            {
                Expressions.Do(DndUtils.InjectParameters(OnDeactivate, Parameters, arguments), player);
            }
            OnRequestMessageToDungeonMaster(this, deactivationMessage);
            OnFeatureDeactivated(player, new FeatureEventArgs(this));
        }
        public override object Evaluate(
            List <string> args,
            ExpressionEvaluator evaluator,
            Creature player,
            Target target,
            CastedSpell spell,
            RollResults dice = null)
        {
            ExpectingArguments(args, 0, 1);

            WhatSide whatSide = WhatSide.All;

            if (args.Count > 0)
            {
                string   whatSideStr = args[0].Trim();
                string[] parts       = whatSideStr.Split('|');            // Union enum elements, e.g., "Friendly | Neutral"
                whatSide = WhatSide.None;
                foreach (string part in parts)
                {
                    whatSide |= DndUtils.ToWhatSide(part);
                }
            }

            OnTargetCreaturesInVolumeRequest(player, new WhatSideEventArgs(whatSide));

            return(null);
        }
Пример #5
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.Description              = featureDto.Description;
            result.OnActivate               = featureDto.OnActivate;
            result.ActivationMessage        = featureDto.ActivationMessage;
            result.OnDeactivate             = featureDto.OnDeactivate;
            result.DeactivationMessage      = featureDto.DeactivationMessage;
            result.OnPlayerCastsSpell       = featureDto.OnPlayerCastsSpell;
            result.OnPlayerSwingsWeapon     = featureDto.OnPlayerSwingsWeapon;
            result.OnPlayerStartsTurn       = featureDto.OnPlayerStartsTurn;
            result.OnPlayerSaves            = featureDto.OnPlayerSaves;
            result.OnRollComplete           = featureDto.OnRollComplete;
            result.ShortcutName             = featureDto.ShortcutName;
            result.ShortcutAvailableWhen    = featureDto.ShortcutAvailableWhen;
            result.Magic                    = MathUtils.IsChecked(featureDto.Magic);
            result.ActivationTime           = PlayerActionShortcut.GetTurnPart(featureDto.ActivationTime);
            result.RequiresPlayerActivation = MathUtils.IsChecked(featureDto.RequiresActivation);
            result.Duration                 = DndTimeSpan.FromDurationStr(featureDto.Duration);
            result.Per   = DndTimeSpan.FromDurationStr(featureDto.Per);
            result.Limit = featureDto.Limit;
            return(result);
        }
Пример #6
0
        /// <summary>
        /// Triggers the specified event, ensuring a CreaturePlusModId is passed in as custom data to the expressions engine.
        /// </summary>
        void TriggerEvent(Creature magicOwner, string eventCode)
        {
            if (string.IsNullOrWhiteSpace(eventCode))
            {
                return;
            }

            SystemVariables.Creature = magicOwner;

            CreaturePlusModId creaturePlusModId = new CreaturePlusModId(GetModId(), magicOwner, Id);

            creaturePlusModId.Magic = this;
            List <string> args = GetArgumentList();

            //if (MagicItem != null)
            //{
            //	SystemVariables.CardId = GetParameter<string>("CardId");
            //	SystemVariables.CardGuid = GetParameter<string>("CardGuid");
            //	SystemVariables.CardUserName = GetParameter<string>("UserName");
            //}

            //if (Args.Length > 0 && Args[0] is IGetUserName iGetUserName)  // It's a Card.
            //{
            //	SystemVariables.ThisCard = iGetUserName;
            //}
            string expressionToEvaluate = DndUtils.InjectParameters(eventCode, MagicItem.Parameters, args);

            Expressions.Do(expressionToEvaluate, magicOwner, null, null, null, creaturePlusModId);
        }
Пример #7
0
 public static string GetDiceRollTypeStr(Spell spell)
 {
     if (spell.SpellType == SpellType.RangedSpell || spell.SpellType == SpellType.MeleeSpell)
     {
         if (spell.Name == "Chaos Bolt")
         {
             return(DndUtils.DiceRollTypeToStr(DiceRollType.ChaosBolt));
         }
         else
         {
             return(DndUtils.DiceRollTypeToStr(DiceRollType.Attack));
         }
     }
     else if (spell.SpellType == SpellType.SavingThrowSpell || spell.SpellType == SpellType.DamageSpell)
     {
         return(DndUtils.DiceRollTypeToStr(DiceRollType.DamageOnly));
     }
     else if (spell.SpellType == SpellType.OtherSpell)
     {
         return(DndUtils.DiceRollTypeToStr(DiceRollType.None));
     }
     else if (spell.SpellType == SpellType.HealingSpell)
     {
         return(DndUtils.DiceRollTypeToStr(DiceRollType.HealthOnly));
     }
     else if (spell.SpellType == SpellType.HpCapacitySpell)
     {
         return(DndUtils.DiceRollTypeToStr(DiceRollType.ExtraOnly));
     }
     else
     {
         return(DndUtils.DiceRollTypeToStr(DiceRollType.None));
     }
 }
Пример #8
0
        public static DiceDto FromCreatureId(int creatureId, double mod)
        {
            DiceDto diceDto = new DiceDto();

            if (creatureId < 0)
            {
                InGameCreature inGameCreature = AllInGameCreatures.GetByIndex(-creatureId);
                if (inGameCreature != null)
                {
                    diceDto.BackColor = inGameCreature.BackgroundHex;
                    diceDto.FontColor = inGameCreature.ForegroundHex;
                    diceDto.Label     = DndUtils.GetFirstName(inGameCreature.Name);
                }
            }
            else
            {
                Character player = AllPlayers.GetFromId(creatureId);
                if (player != null)
                {
                    diceDto.BackColor = player.dieBackColor;
                    diceDto.FontColor = player.dieFontColor;
                    diceDto.Label     = player.firstName;
                }
            }
            diceDto.IsMagic = false;

            diceDto.CreatureId  = creatureId;
            diceDto.Sides       = 20;
            diceDto.DieCountsAs = DieCountsAs.totalScore;
            diceDto.DamageType  = DamageType.None;
            diceDto.Modifier    = mod;
            return(diceDto);
        }
Пример #9
0
 public void SetRollDetails(DiceRollType type, string descriptor)
 {
     descriptor = descriptor.ToLower();
     DamageType = DndUtils.ToDamage(descriptor);
     if (DamageType != DamageType.None)
     {
         DieCountsAs = DieCountsAs.damage;
     }
     else if (descriptor.Contains("health") || type == DiceRollType.HealthOnly)
     {
         DieCountsAs = DieCountsAs.health;
     }
     else if (descriptor.Contains("inspiration") || type == DiceRollType.InspirationOnly)
     {
         DieCountsAs = DieCountsAs.inspiration;
     }
     else if (descriptor.Contains("extra") || type == DiceRollType.ExtraOnly)
     {
         DieCountsAs = DieCountsAs.extra;
     }
     else if (descriptor.Contains("bent luck") || type == DiceRollType.BendLuckAdd || type == DiceRollType.BendLuckSubtract)
     {
         DieCountsAs = DieCountsAs.bentLuck;
     }
     else if (descriptor.Contains("bonus"))
     {
         DieCountsAs = DieCountsAs.bonus;
     }
     else
     {
         DieCountsAs = DieCountsAs.totalScore;
     }
 }
Пример #10
0
 public CharacterClass(string name, int level, string hitDice = "")
 {
     Name    = name;
     Class   = DndUtils.ToClass(name);
     Level   = level;
     HitDice = hitDice;
 }
Пример #11
0
 public void StartGame(string arguments, Character player)
 {
     if (string.IsNullOrWhiteSpace(OnStartGame))
     {
         return;
     }
     Expressions.Do(DndUtils.InjectParameters(OnStartGame, Parameters, arguments), player);
 }
 public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, RollResults dice = null)
 {
     if (function == null)
     {
         return(null);
     }
     return(evaluator.Evaluate(DndUtils.InjectParameters(function.Expression, function.Parameters, args)));
 }
Пример #13
0
 public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
 {
     if (function == null)
     {
         return(null);
     }
     return(evaluator.Evaluate(DndUtils.InjectParameters(function.Expression, function.Parameters, args)));
 }
Пример #14
0
        public bool ShouldActivateNow(List <string> args, Character player)
        {
            if (string.IsNullOrWhiteSpace(ActivateWhen))
            {
                return(true);
            }

            return(Expressions.GetBool(DndUtils.InjectParameters(ActivateWhen, Parameters, args), player));
        }
Пример #15
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            if (proc == null)
            {
                return(null);
            }

            Expressions.Do(DndUtils.InjectParameters(proc.Script, proc.Parameters, args), player, target, spell);
            return(null);
        }
Пример #16
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target = null, CastedSpell spell = null, RollResults dice = null)
        {
            ExpectingArguments(args, 1);
            WhatSide             whatSide = DndUtils.GetSide(args[0]);
            TargetCountEventArgs ea       = new TargetCountEventArgs();

            ea.WhatSide = whatSide;
            OnRequestTargetCount(player, ea);
            return(ea.Count);
        }
Пример #17
0
 public void TakeHalfDamage(Character player, Dictionary <DamageType, int> latestDamage, AttackKind attackKind)
 {
     StartTakingDamage();
     foreach (DamageType damageType in latestDamage.Keys)
     {
         int damageTaken = DndUtils.HalveValue(latestDamage[damageType]);
         TakeSomeDamage(player, damageType, attackKind, damageTaken);
     }
     FinishTakingDamage();
 }
Пример #18
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target = null, CastedSpell spell = null, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1);
            TargetStatus         targetStatus = DndUtils.GetTargetStatus(args[0]);
            TargetCountEventArgs ea           = new TargetCountEventArgs();

            ea.TargetStatus = targetStatus;
            OnRequestTargetCount(player, ea);
            return(ea.Count);
        }
Пример #19
0
 public void WeaponJustSwung(string arguments, Character player)
 {
     if (!IsActive)
     {
         return;
     }
     if (!string.IsNullOrWhiteSpace(OnPlayerSwingsWeapon))
     {
         Expressions.Do(DndUtils.InjectParameters(OnPlayerSwingsWeapon, Parameters, arguments), player);
     }
 }
Пример #20
0
 private void TriggerPlayerCastsSpell(string arguments, Character player, CastedSpell spell)
 {
     if (player.NeedToBreakBeforeFiringEvent(EventType.FeatureEvents, Name))
     {
         Debugger.Break();
     }
     if (!string.IsNullOrWhiteSpace(OnPlayerCastsSpell))
     {
         Expressions.Do(DndUtils.InjectParameters(OnPlayerCastsSpell, Parameters, arguments), player, null, spell);
     }
 }
Пример #21
0
 public void SpellJustCast(string arguments, Character player, CastedSpell spell)
 {
     if (!IsActive)
     {
         return;
     }
     if (!string.IsNullOrWhiteSpace(OnPlayerCastsSpell))
     {
         Expressions.Do(DndUtils.InjectParameters(OnPlayerCastsSpell, Parameters, arguments), player, null, spell);
     }
 }
Пример #22
0
 public void RollIsComplete(string arguments, Character player)
 {
     if (!IsActive)
     {
         return;
     }
     if (!string.IsNullOrWhiteSpace(OnRollComplete))
     {
         Expressions.Do(DndUtils.InjectParameters(OnRollComplete, Parameters, arguments), player);
     }
 }
Пример #23
0
 private void TriggerPlayerSaves(string arguments, Creature player)
 {
     if (player.NeedToBreakBeforeFiringEvent(EventType.FeatureEvents, Name))
     {
         Debugger.Break();
     }
     if (!string.IsNullOrWhiteSpace(OnPlayerSaves))
     {
         Expressions.Do(DndUtils.InjectParameters(OnPlayerSaves, Parameters, arguments), player);
     }
 }
Пример #24
0
 // TODO: Call when a player rolls a saving throw (to implement DangerSense).
 public void PlayerSaves(string arguments, Character player)
 {
     if (!IsActive)
     {
         return;
     }
     if (!string.IsNullOrWhiteSpace(OnPlayerSaves))
     {
         Expressions.Do(DndUtils.InjectParameters(OnPlayerSaves, Parameters, arguments), player);
     }
 }
Пример #25
0
 private void TriggerRollComplete(string arguments, Character player)
 {
     if (player.NeedToBreakBeforeFiringEvent(EventType.FeatureEvents, Name))
     {
         Debugger.Break();
     }
     if (!string.IsNullOrWhiteSpace(OnRollComplete))
     {
         Expressions.Do(DndUtils.InjectParameters(OnRollComplete, Parameters, arguments), player);
     }
 }
Пример #26
0
 private void TriggerAfterPlayerSwingsWeapon(string arguments, Character player)
 {
     if (player.NeedToBreakBeforeFiringEvent(EventType.FeatureEvents, Name))
     {
         Debugger.Break();
     }
     if (!string.IsNullOrWhiteSpace(AfterPlayerSwingsWeapon))
     {
         Expressions.Do(DndUtils.InjectParameters(AfterPlayerSwingsWeapon, Parameters, arguments), player);
     }
 }
Пример #27
0
        public static List <PlayerActionShortcut> FromItemSpellEffect(string spellName, ItemEffect spellEffect, Character player)
        {
            List <PlayerActionShortcut> results = new List <PlayerActionShortcut>();

            List <Spell> spells = AllSpells.GetAll(spellName);

            foreach (Spell spell in spells)
            {
                PlayerActionShortcutDto dto = new PlayerActionShortcutDto();
                dto.name   = spell.Name;
                dto.player = player.name;

                //dto.effectAvailableWhen = weaponEffect.effectAvailableWhen;

                SetDtoFromEffect(dto, spellEffect);
                if (spell.SpellType == SpellType.RangedSpell || spell.SpellType == SpellType.MeleeSpell)
                {
                    if (spell.Name == "Chaos Bolt")
                    {
                        dto.type = DndUtils.DiceRollTypeToStr(DiceRollType.ChaosBolt);
                    }
                    else
                    {
                        dto.type = DndUtils.DiceRollTypeToStr(DiceRollType.Attack);
                    }
                }
                else if (spell.SpellType == SpellType.SavingThrowSpell)
                {
                    dto.type = DndUtils.DiceRollTypeToStr(DiceRollType.DamageOnly);
                }
                else if (spell.SpellType == SpellType.OtherSpell)
                {
                    dto.type = DndUtils.DiceRollTypeToStr(DiceRollType.None);
                }
                else if (spell.SpellType == SpellType.HpCapacitySpell)
                {
                    dto.type = DndUtils.DiceRollTypeToStr(DiceRollType.ExtraOnly);
                }
                else
                {
                    dto.type = DndUtils.DiceRollTypeToStr(DiceRollType.None);
                }

                SetSpellCastingTime(dto, spell);
                List <Spell> oneSpell = new List <Spell>();
                oneSpell.Add(spell);
                AddSpellShortcuts(dto, results, player, oneSpell);
            }

            AddItemEffect(results, spellEffect);

            return(results);
        }
Пример #28
0
        /// <summary>
        /// Triggers the specified event, ensuring a CreaturePlusModId is passed in as custom data to the expressions engine.
        /// </summary>
        void TriggerEvent(Creature magicOwner, string eventCode)
        {
            if (string.IsNullOrWhiteSpace(eventCode))
            {
                return;
            }

            CreaturePlusModId creaturePlusModId = new CreaturePlusModId(GetModId(), magicOwner);
            List <string>     args = GetArgumentList();
            string            expressionToEvaluate = DndUtils.InjectParameters(eventCode, MagicItem.Parameters, args);

            Expressions.Do(expressionToEvaluate, magicOwner, null, null, null, creaturePlusModId);
        }
Пример #29
0
        public static Weapon From(WeaponDto weaponDto)
        {
            Weapon weapon = new Weapon();

            weapon.normalRange       = MathUtils.GetInt(weaponDto.Range);
            weapon.disadvantageRange = MathUtils.GetInt(weaponDto.DisadvantageRange);
            weapon.weaponProperties  = GetWeaponProperties(weaponDto);
            weapon.costValue         = DndUtils.GetGoldPieces(weaponDto.Cost);
            weapon.damageOneHanded   = weaponDto.DamageOneHanded;
            weapon.damageTwoHanded   = weaponDto.DamageTwoHanded;
            weapon.Name = weaponDto.Name;
            return(weapon);
        }
Пример #30
0
 private void TriggerPlayerCastsSpell(string arguments, Creature player, CastedSpell spell)
 {
     if (Name == "WildMagicSurge")
     {
         //System.Diagnostics.Debugger.Break();
     }
     if (player.NeedToBreakBeforeFiringEvent(EventType.FeatureEvents, Name))
     {
         Debugger.Break();
     }
     if (!string.IsNullOrWhiteSpace(OnPlayerCastsSpell))
     {
         Expressions.Do(DndUtils.InjectParameters(OnPlayerCastsSpell, Parameters, arguments), player, null, spell);
     }
 }