Exemple #1
0
        /// <summary>
        /// Looks at a given object
        /// </summary>
        /// <param name="oUser"></param>
        /// <param name="location"></param>
        /// <param name="obj"></param>
        private void LookObject(Character oUser, Entity location, string obj)
        {
            if (!oUser.canSee(null))
            {
                CommandManager.instance.report(MessageScope.CHAR, "#look_dark#", oUser);
                return;
            }

            // Find the target somewhere
            int validLocs =
                (int)EntityLocationType.LOC_ROOM |
                (int)EntityLocationType.LOC_INVENTORY |
                (int)EntityLocationType.LOC_EQUIPMENT |
                (int)EntityLocationType.LOC_CONTAINER |
                (int)EntityLocationType.LOC_SHOP |
                (int)EntityLocationType.LOC_NPC_INVENTORY |
                (int)EntityLocationType.LOC_NPC_EQUIPMENT |
                (int)EntityLocationType.LOC_RECIPES;
            TargetResult result = TargetLocation.findTargetEntity(oUser, obj, validLocs);

            if (null == result._foundEntity)
            {
                CommandManager.instance.report(MessageScope.CHAR, "#nothing_here#", oUser);
                return;
            }
            Entity entity = result._foundEntity;

            if (entity == oUser)
            {
                CommandManager.instance.report(MessageScope.CHAR, "#cant_do_that#", oUser);
                return;
            }

            #region Looking at a Player/Mob
            if (entity.Is(EntityType.BIOTA))
            {
                if (entity.Is(EntityType.PLAYER))
                {
                    CommandManager.instance.report(MessageScope.CHAR, "#looks_at_you#", oUser, entity);
                }

                Biota         biote = null;
                StringBuilder sb    = new StringBuilder();
                if (entity.Is(EntityType.PLAYER))
                {
                    Character user = entity as Character;
                    sb.Append("#you_look_at#");
                    sb.Append(Environment.NewLine);
                    sb.Append(user.description);
                    sb.Append(Environment.NewLine);
                    biote = user;
                }
                else
                {
                    MobInstance mob = entity as MobInstance;
                    sb.Append("#you_look_at#");
                    sb.Append(Environment.NewLine);
                    sb.Append(mob.description);
                    sb.Append(Environment.NewLine);
                    biote = (MobInstance)entity;
                }

                if (biote.isNaked)
                {
                    sb.Append(Environment.NewLine);
                    sb.Append(" #nothing#");
                    CommandManager.instance.report(MessageScope.CHAR, sb.ToString(), oUser, biote);
                }
                else
                {
                    IEnumerable equipment = biote.getEquipment();
                    foreach (DictionaryEntry entry in equipment)
                    {
                        ItemInstance instance = (ItemInstance)entry.Value;
                        WearLocation loc      = instance.getWearLocation(1);

                        sb.Append(Environment.NewLine);
                        sb.AppendFormat(" {0}", loc.longName.PadRight(30, '.'));

                        if (oUser.HasFlag("Admin") || oUser.HasFlag("Builder") || oUser.HasFlag("Wizard"))
                        {
                            sb.Append(Server.Client.MXP_TAG("Item"));
                            sb.Append(instance.Name);
                            sb.Append(Server.Client.MXP_TAG("/Item"));
                            sb.Append(Server.Client.MXP_TAG("Id"));
                            sb.Append(" (#");
                            sb.Append(Server.Client.MXP_TAG("WizItem '" + instance.ID + "'"));
                            sb.Append(instance.ID);
                            sb.Append(instance.GetFlags());
                            sb.Append(Server.Client.MXP_TAG("/WizItem"));
                            sb.Append(")");
                            sb.Append(Server.Client.MXP_TAG("/Id"));
                        }
                        else
                        {
                            sb.Append(Server.Client.MXP_TAG("Item"));
                            sb.Append(instance.Name);
                            sb.Append(Server.Client.MXP_TAG("/Item"));
                        }
                    }

                    CommandManager.instance.report(MessageScope.CHAR, sb.ToString(), oUser, biote);
                }
            }
            #endregion

            #region Looking at an Item
            else if (entity.Is(EntityType.ITEM))
            {
                StringBuilder sb = new StringBuilder();
                if (result._foundEntityLocationType == EntityLocationType.LOC_NPC_INVENTORY ||
                    result._foundEntityLocationType == EntityLocationType.LOC_NPC_EQUIPMENT)
                {
                    // Item is on a NPC's Inventory/Equipment
                    ItemInstance instance = entity as ItemInstance;
                    MobInstance  mob      = result._foundEntityLocation as MobInstance;

                    sb.Append("#look_npc_item_self#");
                    sb.Append(Environment.NewLine);
                    sb.Append(this.LookItem(oUser, instance));
                    sb.Append(Environment.NewLine);

                    CommandManager.instance.report(MessageScope.CHAR, sb.ToString(), oUser, mob, instance);
                    CommandManager.instance.report(MessageScope.ROOM_LIMITED, "#look_npc_item_other#", oUser, mob, instance);
                }
                else if (result._foundEntityLocationType == EntityLocationType.LOC_SHOP)
                {
                    // Item is in a Shop
                    ShopkeeperMobInstance mob = result._foundEntityLocation as ShopkeeperMobInstance;

                    sb.Append("#look_item_shop#");
                    sb.Append(Environment.NewLine);
                    // @TODO: Finish looking at items in shops
                }

                else if (result._foundEntityLocationType == EntityLocationType.LOC_RECIPES)
                {
                    // Item is memorized as a recipe
                    FormulaItemTemplate formula = result._foundEntity as FormulaItemTemplate;

                    string msg = "#look_item_formula#";

                    ItemTemplate product = EntityManager.instance.getTemplateByID(formula.product) as ItemTemplate;
                    msg += Environment.NewLine + "  Product: " + product.Name;
                    if (oUser.HasFlag("Admin") || oUser.HasFlag("Builder") || oUser.HasFlag("Wizard"))
                    {
                        msg += Server.Client.MXP_TAG("Id") + " (#" + Server.Client.MXP_TAG("WizItem '" + product.ID + "'");
                        msg += product.ID + product.GetFlags() + Server.Client.MXP_TAG("/WizItem") + ")" + Server.Client.MXP_TAG("/Id");
                    }

                    msg += Environment.NewLine + "  Skill: " + formula.skill.Name + " (" + formula.skillValue + ")";
                    if (oUser.HasFlag("Admin") || oUser.HasFlag("Builder") || oUser.HasFlag("Wizard"))
                    {
                        msg += Server.Client.MXP_TAG("Id") + " (#" + formula.skill.ID + ")" + Server.Client.MXP_TAG("/Id");
                    }

                    ItemTemplate machine = EntityManager.instance.getTemplateByID(formula.machine) as ItemTemplate;
                    msg += Environment.NewLine + "  Machine: " + EntityManager.instance.getTemplateByID(formula.machine).Name;
                    if (oUser.HasFlag("Admin") || oUser.HasFlag("Builder") || oUser.HasFlag("Wizard"))
                    {
                        msg += Server.Client.MXP_TAG("Id") + " (#" + Server.Client.MXP_TAG("WizItem '" + machine.ID + "'");
                        msg += machine.ID + machine.GetFlags() + Server.Client.MXP_TAG("/WizItem") + ")" + Server.Client.MXP_TAG("/Id");
                    }

                    ItemTemplate tool = EntityManager.instance.getTemplateByID(formula.tool) as ItemTemplate;
                    msg += Environment.NewLine + "  Tool: " + EntityManager.instance.getTemplateByID(formula.tool).Name;
                    if (oUser.HasFlag("Admin") || oUser.HasFlag("Builder") || oUser.HasFlag("Wizard"))
                    {
                        msg += Server.Client.MXP_TAG("Id") + " (#" + Server.Client.MXP_TAG("WizItem '" + tool.ID + "'");
                        msg += tool.ID + tool.GetFlags() + Server.Client.MXP_TAG("/WizItem") + ")" + Server.Client.MXP_TAG("/Id");
                    }

                    msg += Environment.NewLine + "  Resources:";
                    foreach (int resourceId in formula.resourceKeys)
                    {
                        ResourceItemTemplate resource = EntityManager.instance.getTemplateByID(resourceId) as ResourceItemTemplate;
                        msg += Environment.NewLine + "   " + resource.Name + " (x" + formula.getResource(resourceId) + ")";
                        if (oUser.HasFlag("Admin") || oUser.HasFlag("Builder") || oUser.HasFlag("Wizard"))
                        {
                            msg += Server.Client.MXP_TAG("Id") + " (#" + Server.Client.MXP_TAG("WizItem '" + resource.ID + "'");
                            msg += resource.ID + resource.GetFlags() + Server.Client.MXP_TAG("/WizItem") + ")" + Server.Client.MXP_TAG("/Id");
                        }
                    }

                    CommandManager.instance.report(MessageScope.CHAR, msg, oUser, null, formula);
                }

                else
                {
                    ItemInstance instance = entity as ItemInstance;
                    sb.Append("#look_item_self#");
                    sb.Append(Environment.NewLine);
                    sb.Append(this.LookItem(oUser, instance));
                    sb.Append(Environment.NewLine);

                    CommandManager.instance.report(MessageScope.CHAR, sb.ToString(), oUser, null, instance);
                    CommandManager.instance.report(MessageScope.ROOM_LIMITED, "#look_item_other#", oUser, null, instance);
                }
            }
            #endregion

            else
            {
                this.LogError("LookObject", "User[" + oUser.ID + "], Object[" + entity.ID + "] had no known type.");
            }
        }