Beispiel #1
0
        public override Handler DoSearch(ParsedInput input)
        {
            if (input.Words.Length == 1)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, "Search".ToParagraph()));
            }

            int    nOrdinal = 0;
            string strNPC   = "";

            switch (input.Words.Length)
            {
            case 2:
                strNPC = input.Words[1];
                break;

            case 3:
                if (!Statics.OrdinalStringToInt.ContainsKey(input.Words[1]))
                {
                    return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
                }
                nOrdinal = Statics.OrdinalStringToInt[input.Words[1]];
                strNPC   = input.Words[2];
                break;

            default:
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }

            EntityNPCBase npc = CurrentRoom.NPCs.FindDead(strNPC, nOrdinal);

            if (npc == null)
            {
                npc = CurrentRoom.NPCs.Find(strNPC, nOrdinal);
            }
            if (npc == null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }
            if (!npc.IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_NPC_NOT_DEAD, npc.NameAsParagraph));
            }

            // add npc inventory to room
            // TODO: messaging?
            // You search the goblin and remove its equipment. You find <x> gold.
            Gold += npc.Gold;
            npc.BeSearched();

            if (npc.Gold > 0)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.NPC_SEARCH_WITH_GOLD, npc.NameAsParagraph, npc.Gold.ToString().ToParagraph()));
            }
            else
            {
                return(Handler.HANDLED(MESSAGE_ENUM.NPC_SEARCH_NO_GOLD, npc.NameAsParagraph));
            }
        }
Beispiel #2
0
        public EntityNPCBase GetRandomHostile(EntityNPCBase source, bool bMustBeAlive = false)
        {
            List <EntityNPCBase> hostiles = GetListOfHostiles(source, bMustBeAlive);

            if (hostiles.Count == 0)
            {
                return(null);
            }
            return(hostiles.RandomListItem());
        }
Beispiel #3
0
        protected override Handler DoLook(string strWord1, string strWord2)
        {
            if (strWord1 == "at")
            {
                return(DoLook(strWord2));
            }
            if (strWord1 == "in")
            {
                return(DoLookInContainer(strWord2));
            }

            // TODO: handle "my"
            // - look [at] my backpack, "at" is implied--not "in"
            // can't simply call strWord1 version; needs to be specific for "my"
            if (strWord1 == "my")
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_NEED_TO_IMPLEMENT));
            }

            // if we make it here, we expect "look <ordinal> <item||npc>"
            // TODO: support "look at (the?) second goblin"

            int ordinal;

            if (!Statics.OrdinalStringToInt.TryGetValue(strWord1, out ordinal))
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }

            Item item = CurrentRoom.Items.Find(strWord2, ITEM_TYPE.ANY, ordinal);

            if (item != null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, (item.Description).ToParagraph()));
            }

            EntityNPCBase npc = CurrentRoom.NPCs.Find(strWord2, ordinal);

            if (npc != null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, npc.LookParagraph));
            }

            return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
        }
Beispiel #4
0
        protected override Handler DoLook(string strWord)
        {
            // look hands - special case
            if (strWord == "hands")
            {
                return(DoLookHands(null));
            }

            // TODO: consider more specific strings for held or equipped items
            Item item = CurrentRoom.Items.Find(strWord);

            if (item != null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, (item.Description).ToParagraph()));
            }

            item = Hands.GetItem(strWord, false);
            if (item != null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, (item.Description).ToParagraph()));
            }

            item = Body.GetItem(strWord, false);
            if (item != null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, (item.Description).ToParagraph()));
            }

            item = ContainerSlots.GetContainer(strWord); //GetItem(strWord, false);
            if (item != null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, (item.Description).ToParagraph()));
            }

            EntityNPCBase npc = CurrentRoom.NPCs.Find(strWord);

            if (npc != null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, npc.LookParagraph));
            }

            return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
        }
Beispiel #5
0
        public Paragraph ProcessExperience(EntityNPCBase npc)
        {
            int experience = Statics.LevelDeltaToExperience(npc.Level);

            Game.Player.Experience += experience;

            Paragraph p = new Paragraph();

            string strExperience = "You have gained " + experience.ToString() + " experience.";

            p.Inlines.Add(strExperience.ToRun());

            // TODO: replace hard-coded 1000?
            if (Game.Player.Experience > Game.Player.Level * 1000)
            {
                Game.Player.GainLevel();
                string strLevelUp = "You have gained a level! You are now level " + Game.Player.Level.ToString();
                p.Inlines.Add(strLevelUp.ToRun());
            }

            return(p);
        }
Beispiel #6
0
        private List <EntityNPCBase> GetListOfHostiles(EntityNPCBase source, bool bMustBeAlive = false)
        {
            List <EntityNPCBase> hostiles = new List <EntityNPCBase>();

            foreach (EntityNPCBase npc in Entities)
            {
                // ignore entities of same type
                if (npc.Faction.Equals(source.Faction))
                {
                    continue;
                }

                int relationship = EntityRelationshipTable.GetRelationship(source.Faction, npc.Faction);
                if (relationship < 0)
                {
                    if (!bMustBeAlive || !npc.IsDead)
                    {
                        hostiles.Add(npc);
                    }
                }
            }

            return(hostiles);
        }
        // with dependency on entity, might make sense to move up, since entity already has hands (circular?)
        // otherwise, remove dependency
        public Paragraph NPCDisplayParagraph(EntityNPCBase entity)
        {
            // if the NPC has hands, assume two hands for now
            if (Hands.Count == 0)
            {
                return(null);
            }

            Paragraph p = new Paragraph();

            EntityHand RightHand = Hands[0];
            EntityHand LeftHand  = Hands[1];

            if (LeftHand.Item == null && RightHand.Item == null)
            {
                p.Inlines.Add("The ".ToRun());
                p.Merge(entity.NameAsParagraph);
                p.Inlines.Add(" isn't holding anything.".ToRun());
                return(p);
            }

            if (RightHand.Item == null)
            {
                // RightHand IS empty
                // LeftHand IS NOT empty
                p.Inlines.Add("The ".ToRun());
                p.Merge(entity.NameAsParagraph);
                p.Inlines.Add(" is holding ".ToRun());
                p.Merge(LeftHand.Item.NameWithIndefiniteArticle);
                p.Inlines.Add(" in its left hand.".ToRun());
                return(p);
            }
            else
            {
                // RightHand IS NOT empty
                // LeftHand MAY OR MAY NOT BE empty
                p.Inlines.Add("The ".ToRun());
                p.Merge(entity.NameAsParagraph);
                p.Inlines.Add(" is holding ".ToRun());
                p.Merge(RightHand.Item.NameWithIndefiniteArticle);
                p.Inlines.Add(" in its right hand".ToRun());

                // TODO: LeftHand switch here
                if (LeftHand.Item == null)
                {
                    // RightHand IS NOT empty
                    // LeftHand IS empty
                    p.Inlines.Add(".".ToRun());
                    return(p);
                }
                else
                {
                    // RightHand IS NOT empty
                    // LeftHand IS NOT empty
                    // append ...and a blah in its left hand.
                    p.Inlines.Add(" and ".ToRun());
                    p.Merge(LeftHand.Item.NameWithIndefiniteArticle);
                    p.Inlines.Add(" in its left hand.".ToRun());
                    return(p);
                }
            }
        }
Beispiel #8
0
 public void Remove(EntityNPCBase npc)
 {
     Entities.Remove(npc);
 }
Beispiel #9
0
 public void Add(EntityNPCBase npc)
 {
     Entities.Add(npc);
 }
Beispiel #10
0
 public EntityNPCBase GetRandomHostile(EntityNPCBase source, bool bMustBeAlive = false)
 {
     return(NPCs.GetRandomHostile(source, bMustBeAlive));
 }
Beispiel #11
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()));
        }