예제 #1
0
        /// <summary>
        /// This is raised by Player.HandleActionUseItem.<para />
        /// The item should be in the players possession.
        /// </summary>
        public override void UseItem(Player player)
        {
            bool   success    = true;
            string failReason = "You are unable to read the scroll.";

            switch (Power)
            {
            // research: http://asheron.wikia.com/wiki/Announcements_-_2002/06_-_Castling
            case spellLevel2:     // Level 2
            case spellLevel3:     // Level 3
            case spellLevel4:     // Level 4
            case spellLevel5:     // Level 5
            case spellLevel6:     // Level 6
                if (!player.CanReadScroll(School, Power))
                {
                    success    = false;
                    failReason = "You are not skilled enough in the inscribed spell's school of magic to understand the writing on this scroll.";
                }
                break;
            }

            if (player.SpellIsKnown(SpellId))
            {
                success    = false;
                failReason = "You already know the spell inscribed upon this scroll.";
            }

            var actionChain = new ActionChain();

            actionChain
            .AddAction(player, () => player.EnqueueBroadcastMotion(motionReading))
            .AddDelaySeconds(2);

            if (success)
            {
                actionChain.AddAction(player, () =>
                {
                    player.LearnSpellWithNetworking(SpellId);
                    player.EnqueueBroadcastMotion(motionReady);
                    if (player.TryRemoveFromInventoryWithNetworking(this))
                    {
                        player.Session.Network.EnqueueSend(new GameMessageSystemChat("The scroll is destroyed.", ChatMessageType.Magic));
                    }
                });
            }
            else
            {
                actionChain
                .AddDelaySeconds(2)
                .AddAction(player, () =>
                {
                    player.EnqueueBroadcastMotion(motionReady);
                    player.Session.Network.EnqueueSend(new GameMessageSystemChat($"{failReason}", ChatMessageType.Magic));
                });
            }

            actionChain
            .AddAction(player, () => player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session)));

            actionChain.EnqueueChain();
        }