コード例 #1
0
        public override Handler DoAttack(ParsedInput input)
        {
            if (input.Words.Length == 1)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, input.Words[0].ToSentenceCase().ToParagraph()));
            }
            if (IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_IS_DEAD));
            }

            string strNPCName = "";
            int    ordinal    = 0;

            if (input.Words.Length == 2)
            {
                strNPCName = input.Words[1];
            }
            else if (input.Words.Length == 3)
            {
                if (!Statics.OrdinalStringToInt.TryGetValue(input.Words[1], out ordinal))
                {
                    return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
                }
                strNPCName = input.Words[2];
            }

            EntityNPCBase npc = CurrentRoom.NPCs.FindLiving(strNPCName, ordinal);

            if (npc == null)
            {
                npc = CurrentRoom.NPCs.Find(strNPCName, ordinal);
            }
            if (npc == null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }
            if (npc.IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_NPC_ALREADY_DEAD, npc.NameBaseAsParagraph));
            }

            Item weapon = Hands.GetAnyItem(ITEM_TYPE.WEAPON);

            // TODO: fix this
            if (weapon == null)
            {
                if (Hands.Hands[0].Item != null)
                {
                    return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_ATTACKS_BAD_WEAPON, Hands.Hands[0].Item.NameAsParagraph));
                }
                else if (Hands.Hands[1].Item != null)
                {
                    return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_ATTACKS_BAD_WEAPON, Hands.Hands[1].Item.NameAsParagraph));
                }
            }

            Paragraph pWeapon = weapon == null ? "fist".ToParagraph() : weapon.NameAsParagraph;

            // calculate damage
            MESSAGE_ENUM message = MESSAGE_ENUM.PLAYER_ATTACKS_NPC;
            int          damage  = AttackPower - npc.Body.DefensePower;

            npc.Attributes.CurrentHealth -= damage;
            if (npc.IsDead)
            {
                Paragraph xpPara = Game.Player.ProcessExperience(npc);
                return(Handler.HANDLED(MESSAGE_ENUM.PLAYER_KILLS_NPC, npc.NameBaseAsParagraph, pWeapon, damage.ToString().ToParagraph(), xpPara));
            }

            return(Handler.HANDLED(message, npc.NameBaseAsParagraph, pWeapon, damage.ToString().ToParagraph()));
        }