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); }
public static object ApplyDamage(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, double multiplier = 1) { 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?.Game, damageType, AttackKind.Magical, (int)Math.Floor(latestDamage[damageType] * multiplier)); } } inGameCreature.FinishTakingDamage(); // TODO: Also get players from the target and work with them. } return(null); }
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); }
/// <summary> /// Returns the player or the in game creature based on the specified creatureId. /// </summary> /// <param name="creatureId">The id of the player (non-negative) or in game creature (negative).</param> public static Creature GetCreatureById(int creatureId) { if (creatureId >= 0) { return(AllPlayers.GetFromId(creatureId)); } else { InGameCreature inGameCreature = AllInGameCreatures.GetByIndex(-creatureId); if (inGameCreature != null) { return(inGameCreature.Creature); } } return(null); }
public static object ApplyDamage(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, double multiplier = 1) { 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); if (inGameCreature != null) { inGameCreature.StartTakingDamage(); if (inGameCreature != null) { foreach (DamageType damageType in latestDamage.Keys) { // TODO: pass in AttackKind with the custom data ReportOnVulnerabilitiesAndResistance(player?.Game, creature, inGameCreature.Name, damageType); inGameCreature.TakeSomeDamage(player?.Game, damageType, AttackKind.Magical, (int)Math.Floor(latestDamage[damageType] * multiplier)); } } inGameCreature.FinishTakingDamage(); } else { if (creature is Character thisPlayer) { foreach (DamageType damageType in latestDamage.Keys) { // TODO: pass in AttackKind with the custom data thisPlayer.TakeDamage(damageType, AttackKind.Any, latestDamage[damageType]); ReportOnVulnerabilitiesAndResistance(thisPlayer.Game, creature, thisPlayer.firstName, damageType); } } } } return(null); }
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); if (inGameCreature != null) { inGameCreature.TakeHalfDamage(player, latestDamage, AttackKind.Magical); } // TODO: Also get players from the target and work with them. } return(null); }