예제 #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)
        {
            IController sender = actionInput.Controller;
            var contextMessage = new ContextualString(sender.Thing, this.target)
            {
                ToOriginator = "You cast ThunderClap at $ActiveThing.Name!",
                ToReceiver = "$Aggressor.Name casts ThunderClap at you, you only hear a ringing in your ears now.",
                ToOthers = "You hear $Aggressor.Name cast ThunderClap at $ActiveThing.Name!  It was very loud.",
            };
            var sm = new SensoryMessage(SensoryType.Hearing, 100, contextMessage);

            var attackEvent = new AttackEvent(this.target, sm, sender.Thing);
            sender.Thing.Eventing.OnCombatRequest(attackEvent, EventScope.ParentsDown);
            if (!attackEvent.IsCancelled)
            {
                var deafenEffect = new AlterSenseEffect()
                {
                    SensoryType = SensoryType.Hearing,
                    AlterAmount = -1000,
                    Duration = new TimeSpan(0, 0, 45),
                };

                this.target.Behaviors.Add(deafenEffect);
                sender.Thing.Eventing.OnCombatEvent(attackEvent, EventScope.ParentsDown);
            }
        }
예제 #2
0
파일: Punch.cs 프로젝트: Hobbitron/WheelMUD
        /// <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);
            }
        }