Exemplo n.º 1
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Send the attack event.
            IController     sender          = actionInput.Controller;
            UnbalanceEffect unbalanceEffect = new UnbalanceEffect()
            {
                Duration = new TimeSpan(0, 0, 0, 0, 5000),
            };

            sender.Thing.Behaviors.Add(unbalanceEffect);

            // Set up the dice for attack and defense rolls.
            // Currently does not consider equipment, skills or stats.
            DiceService dice       = DiceService.Instance;
            Die         attackDie  = dice.GetDie(20);
            Die         defenseDie = dice.GetDie(20);

            // Roll the dice to determine if the attacker hits.
            int attackRoll  = attackDie.Roll();
            int defenseRoll = defenseDie.Roll();

            // Determine amount of damage, if any. Cannot exceed the target's current health.
            int targetHealth = this.target.Stats["HP"].Value;
            int damage       = Math.Max(attackRoll - defenseRoll, 0);

            damage = Math.Min(damage, targetHealth);

            // Choose sensory messaging based on whether or not the hit landed.
            SensoryMessage message = this.CreateResultMessage(sender.Thing, this.target, attackRoll, defenseRoll, damage);

            var attackEvent = new AttackEvent(this.target, message, sender.Thing);

            // Broadcast combat requests/events to the room they're happening in.
            sender.Thing.Eventing.OnCombatRequest(attackEvent, EventScope.ParentsDown);
            if (!attackEvent.IsCancelled)
            {
                this.target.Stats["HP"].Decrease(damage, sender.Thing);
                sender.Thing.Eventing.OnCombatEvent(attackEvent, EventScope.ParentsDown);
            }
        }