Beispiel #1
0
 private void TriggerEvent(Magic magic, string eventCode, DiceStoppedRollingData dice = null)
 {
     if (string.IsNullOrWhiteSpace(eventCode))
     {
         return;
     }
     Expressions.Do(eventCode, magic.Caster as Character, Target.FromMagic(magic), magic.CastedSpell, dice, magic);
 }
Beispiel #2
0
        private static void ExpressionEvaluator_EvaluateFunction(object sender, FunctionEvaluationEventArg e)
        {
            Character              player      = GetPlayer(e.Evaluator.Variables);
            CastedSpell            castedSpell = GetCastedSpell(e.Evaluator.Variables);
            Target                 target      = GetTargetCreature(e.Evaluator.Variables);
            DiceStoppedRollingData dice        = GetDiceStoppedRollingData(e.Evaluator.Variables);
            DndFunction            function    = functions.FirstOrDefault(x => x.Handles(e.Name, player, castedSpell));

            if (function != null)
            {
                try
                {
                    e.Value = function.Evaluate(e.Args, e.Evaluator, player, target, castedSpell, null);
                    Log($"  {e.Name}({GetArgsStr(e.Args)}) => {GetValueStr(e.Value)}");
                }
                catch (Exception ex)
                {
                    e.Value = null;
                    Log($"  Exception thrown trying to evaluate {e.Name}({GetArgsStr(e.Args)})");
                }
            }
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1);

            Ability ability = (Ability)Expressions.GetInt(args[0], player, target, spell);

            return(player.GetAbilityModifier(ability));
        }
Beispiel #4
0
 public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target = null, CastedSpell spell = null, DiceStoppedRollingData dice = null)
 {
     ExpectingArguments(args, 0);
     if (player != null)
     {
         OnRequestClearWindup(player, new NameEventArgs(AddWindupFunction.GetWindupName(player, spell)));
     }
     return(null);
 }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target = null, CastedSpell spell = null, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 2);
            string reminder         = Expressions.GetStr(args[0], player, target, spell);
            string fromNowDuration  = Expressions.GetStr(args[1], player, target, spell);
            AddReminderEventArgs ea = new AddReminderEventArgs(reminder, fromNowDuration);

            AddReminder(player, ea);
            return(null);
        }
Beispiel #6
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1);

            string dieRollMessage = evaluator.Evaluate <string>(args[0]);

            player.AddDieRollMessage(dieRollMessage);

            return(null);
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 4);

            string rechargeableName = Expressions.GetStr(args[0], player, target, spell);
            string variableName     = Expressions.GetStr(args[1], player, target, spell);
            int    maxValue         = Expressions.GetInt(args[2], player, target, spell);
            string cycle            = Expressions.GetStr(args[3], player, target, spell);

            player.AddRechargeable(rechargeableName, variableName, maxValue, cycle);

            return(null);
        }
Beispiel #8
0
 public void TriggerDieRollStopped(Character player, Target target, CastedSpell castedSpell, DiceStoppedRollingData dice)
 {
     if (player.NeedToBreakBeforeFiringEvent(EventType.SpellEvents, Name))
     {
         Debugger.Break();
     }
     Expressions.Do(OnDieRollStopped, player, target, castedSpell, dice);
 }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target = null, CastedSpell spell = null, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1);
            // TODO: Get the condition to set.
            // TODO: Set the target's condition.

            return(null);
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target = null, CastedSpell spell = null, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 0, 1);

            string weaponFilter = null;

            if (args.Count > 0)
            {
                weaponFilter = Expressions.GetStr(args[0], player, target, spell);
            }
            if (player != null)
            {
                return(player.ChooseWeapon(weaponFilter));
            }

            return(null);
        }
        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);
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target = null, CastedSpell spell = null, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1);
            if (player != null)
            {
                string languageStr = Expressions.GetStr(args[0], player, target, spell);
                player.AddLanguages(languageStr);
            }

            return(null);
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            if (player == null)
            {
                return(null);
            }

            ExpectingArguments(args, 2);

            string variableName = args[0];
            object rawValue     = Expressions.Get <object>(args[1], player, target, spell);
            double valueDouble;

            if (rawValue == null)
            {
                valueDouble = 0;
            }
            else
            {
                valueDouble = MathUtils.GetDouble(rawValue.ToString());
            }
            int valueInt = (int)Math.Round(valueDouble);

            // TODO: Wil says Convert.ConvertTo() can simplify this.

            FieldInfo field = typeof(Character).GetField(variableName);

            if (field != null)
            {
                if (field.FieldType.FullName == "System.Int32")
                {
                    field.SetValue(player, MathUtils.GetInt(field.GetValue(player).ToString()) + valueInt);
                }
                else
                {
                    field.SetValue(player, MathUtils.GetDouble(field.GetValue(player).ToString()) + valueDouble);
                }
                return(null);
            }

            PropertyInfo property = typeof(Character).GetProperty(variableName);

            if (property != null)
            {
                if (property.PropertyType.FullName == "System.Int32")
                {
                    property.SetValue(player, MathUtils.GetInt(property.GetValue(player).ToString()) + valueInt);
                }
                else
                {
                    property.SetValue(player, MathUtils.GetDouble(property.GetValue(player).ToString()) + valueDouble);
                }
                return(null);
            }

            object existingValueRaw = player.GetState(variableName);

            if (existingValueRaw != null)
            {
                if (existingValueRaw is int)
                {
                    player.SetState(variableName, MathUtils.GetInt(existingValueRaw.ToString()) + valueInt);
                }
                else
                {
                    player.SetState(variableName, MathUtils.GetDouble(existingValueRaw.ToString()) + valueDouble);
                }
                return(null);
            }

            throw new Exception($"Variable \"{variableName}\" not found.");
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 2);

            string variableName = args[0];
            // TODO: incorrectValue:
            //object incorrectValue = evaluator.Evaluate(Expressions.Clean(args[1]));
            object value = Expressions.Get(Expressions.Clean(args[1]), player, target, spell);

            object instance     = player;
            Type   instanceType = typeof(Character);

            if (KnownQualifiers.IsSpellQualifier(variableName))
            {
                if (evaluator.Variables.ContainsKey(Expressions.STR_CastedSpell))
                {
                    instance     = evaluator.Variables[Expressions.STR_CastedSpell];
                    instanceType = typeof(CastedSpell);
                    variableName = variableName.EverythingAfter(KnownQualifiers.Spell);
                }
            }

            FieldInfo field = instanceType.GetField(variableName);

            if (field != null)
            {
                if (instance != null)
                {
                    field.SetValue(instance, value);
                }
                return(null);
            }

            PropertyInfo property = instanceType.GetProperty(variableName);

            if (property != null)
            {
                if (instance != null)
                {
                    property.SetValue(instance, value);
                }
                return(null);
            }

            player.SetState(variableName, value);

            return(null);
        }
Beispiel #15
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            if (target == null)
            {
                return(null);
            }
            ExpectingArguments(args, 1, 8);              // up to seven optional parameters of any data type.

            string spellName = Expressions.GetStr(args[0], player, target, spell);
            object data1     = null;
            object data2     = null;
            object data3     = null;
            object data4     = null;
            object data5     = null;
            object data6     = null;
            object data7     = null;

            if (args.Count > 1)
            {
                data1 = Expressions.Get(args[1], player, target, spell);
            }
            if (args.Count > 2)
            {
                data2 = Expressions.Get(args[2], player, target, spell);
            }
            if (args.Count > 3)
            {
                data3 = Expressions.Get(args[3], player, target, spell);
            }
            if (args.Count > 4)
            {
                data4 = Expressions.Get(args[4], player, target, spell);
            }
            if (args.Count > 5)
            {
                data5 = Expressions.Get(args[5], player, target, spell);
            }
            if (args.Count > 6)
            {
                data6 = Expressions.Get(args[6], player, target, spell);
            }
            if (args.Count > 7)
            {
                data7 = Expressions.Get(args[7], player, target, spell);
            }

            if (target == null || player.Game == null)
            {
                return(null);
            }

            foreach (int playerId in target.PlayerIds)
            {
                Character recipient = player.Game.GetPlayerFromId(playerId);
                if (recipient == null)
                {
                    break;
                }
                KnownSpell knownSpell = new KnownSpell();
                knownSpell.SpellName = spellName;
                knownSpell.Player    = recipient;
                recipient.GiveSpell(knownSpell, data1, data2, data3, data4, data5, data6, data7);
            }

            return(null);
        }
Beispiel #16
0
        // TODO: Add customData parameter?
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1, 2);

            string shortcutName    = evaluator.Evaluate <string>(args[0]);
            bool   rollImmediately = false;

            if (args.Count > 1)
            {
                rollImmediately = Expressions.GetBool(args[1], player, target, spell, dice);
            }

            player.AddShortcutToQueue(shortcutName, rollImmediately);

            return(null);
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 4);

            string tableName   = evaluator.Evaluate <string>(args[0]);
            string fieldLookup = evaluator.Evaluate <string>(args[1]);
            string matchColumn = evaluator.Evaluate <string>(args[2]);
            object matchValue  = evaluator.Evaluate(Expressions.Clean(args[3]));

            return(AllTables.GetData(tableName, fieldLookup, matchColumn, matchValue));
        }
Beispiel #18
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target = null, CastedSpell spell = null, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 0);
            Dictionary <DamageType, int> latestDamage = Expressions.GetCustomData <Dictionary <DamageType, int> >(evaluator.Variables);

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

            foreach (Creature creature in target.Creatures)
            {
                InGameCreature inGameCreature = AllInGameCreatures.GetByCreature(creature);
                inGameCreature.StartTakingDamage();
                if (inGameCreature != null)
                {
                    foreach (DamageType damageType in latestDamage.Keys)
                    {
                        // TODO: pass in AttackKind with the custom data
                        if (creature.IsVulnerableTo(damageType, AttackKind.Magical))
                        {
                            player.Game.TellDungeonMaster($"{inGameCreature.Name} is vulnerable to {damageType} damage.");
                        }
                        else if (creature.IsResistantTo(damageType, AttackKind.Magical))
                        {
                            player.Game.TellDungeonMaster($"{inGameCreature.Name} is resistant to {damageType} damage.");
                        }
                        inGameCreature.TakeSomeDamage(player, damageType, AttackKind.Magical, latestDamage[damageType]);
                    }
                }
                inGameCreature.FinishTakingDamage();
                // TODO: Also get players from the target and work with them.
            }
            return(null);
        }
Beispiel #19
0
 public abstract object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target, CastedSpell spell, DiceStoppedRollingData dice);
Beispiel #20
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 3);
            string           dungeonMasterMessage = Expressions.GetStr(args[0], player, target, spell, dice);
            string           floatText            = Expressions.GetStr(args[1], player, target, spell, dice);
            ValidationAction validationAction     = Expressions.Get <ValidationAction>(args[2].Trim(), player, target, spell, dice);

            Validation.OnValidationFailed(dungeonMasterMessage, floatText, validationAction);
            return(null);
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 3);
            string timerName       = Expressions.GetStr(args[0], player, target, spell);
            int    durationSeconds = Expressions.GetInt(args[1], player, target, spell);
            string functionToCall  = Expressions.GetStr(args[2], player, target, spell);

            if (player == null)
            {
                return(null);
            }
            if (player.Game == null)
            {
                return(null);
            }
            DndAlarm dndAlarm = player.Game.Clock.CreateAlarm(TimeSpan.FromSeconds(durationSeconds), timerName, player, functionToCall);

            dndAlarm.AlarmFired += DndAlarm_AlarmFired;
            return(null);
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1);

            string varName = args[0];

            player.RemoveStateVar(varName);
            return(null);
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1);
            double value = Expressions.GetDouble(args[0], player, target, spell);

            return(Math.Floor(value / 2.0));
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1, 3);

            string sceneName = evaluator.Evaluate <string>(args[0]);

            sceneName = DndUtils.GetRandomSceneIfNecessary(sceneName);

            double delaySec  = 0;
            double returnSec = 0;

            if (args.Count > 1)
            {
                delaySec = Expressions.GetDouble(args[1]);
                if (args.Count > 2)
                {
                    returnSec = Expressions.GetDouble(args[2]);
                }
            }

            OnRequestPlayScene(sceneName, delaySec, returnSec);

            return(null);
        }
Beispiel #25
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            CreaturePlusModId recipient = Expressions.GetCustomData <CreaturePlusModId>(evaluator.Variables);

            if (recipient == null)
            {
                throw new Exception($"CreaturePlusModId recipient must be specified before evaluating expressions containing AddPropertyMod.");
            }

            ExpectingArguments(args, 4);
            DiceRollType rollType = Expressions.Get <DiceRollType>(args[0], player, target, spell);
            Skills       skills   = Expressions.Get <Skills>(args[1].Trim(), player, target, spell);
            string       dieLabel = args[2].Trim();

            if (dieLabel.StartsWith("\""))
            {
                dieLabel = Expressions.GetStr(dieLabel, player, target, spell);
            }
            int vantageOffset = Expressions.GetInt(args[3], player, target, spell);

            recipient.Creature.AddVantageMod(recipient.ID, rollType, skills, dieLabel, vantageOffset);
            return(null);
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1);
            string featureName = args[0];

            if (featureName.StartsWith("\""))
            {
                featureName = Expressions.GetStr(featureName);
            }
            Feature feature = AllFeatures.Get(featureName);

            if (feature != null)
            {
                feature.Deactivate("", player);
            }

            return(null);
        }
Beispiel #27
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target = null, CastedSpell spell = null, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1, 4);
            string fillColor    = "player";
            string outlineColor = "player";
            int    delayMs      = 0;

            if (args.Count > 1)
            {
                fillColor = args[1].Trim();
                if (args.Count > 2)
                {
                    outlineColor = args[2].Trim();
                    if (args.Count > 3)
                    {
                        delayMs = Expressions.GetInt(args[3], player, target, spell, dice);
                    }
                }
            }

            CreaturePlusModId recipient = Expressions.GetCustomData <CreaturePlusModId>(evaluator.Variables);

            if (recipient != null && recipient.Creature is Character recipientPlayer)
            {
                recipientPlayer.ShowState(Expressions.GetStr(args[0], player, target, spell), fillColor, outlineColor, delayMs);
            }
            else if (player != null)
            {
                player.ShowState(Expressions.GetStr(args[0], player, target, spell), fillColor, outlineColor, delayMs);
            }
            else if (recipient.Creature != null)
            {
                recipient.Creature.ShowState(Expressions.GetStr(args[0], player, target, spell), fillColor, outlineColor, delayMs);
                // TODO: Implement FloatCreatureText
                //FloatCreatureText(recipient.Creature, args[0]);
            }
            return(null);
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target = null, CastedSpell spell = null, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1, 2);
            if (player != null)
            {
                string fileName = Expressions.GetStr(args[0], player, target, spell);

                int timeOffsetMs = 0;
                if (args.Count > 1)
                {
                    timeOffsetMs = Expressions.GetInt(args[1], player, target, spell);
                }

                player.AddSpellCastSoundEffect(fileName, timeOffsetMs);
            }

            return(null);
        }
Beispiel #29
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1);

            string diceStr = evaluator.Evaluate <string>(args[0]);

            player.ReplaceDamageDice(diceStr);

            return(null);
        }
Beispiel #30
0
 public void TriggerDieRollStopped(Magic magic, DiceStoppedRollingData dice)
 {
     TriggerEvent(magic, onDieRollStopped, dice);
 }