예제 #1
0
        private ArrayList GetGroups(Type objectType, PropertyInfo[] props)
        {
            Hashtable groups = new Hashtable();

            for (int i = 0; i < props.Length; ++i)
            {
                PropertyInfo prop = props[i];

                if (prop.CanRead)
                {
                    CPA attr = GetCPA(prop);

                    if (attr != null && m_Mobile.AccessLevel >= attr.ReadLevel)
                    {
                        Type type = prop.DeclaringType;

                        while (true)
                        {
                            Type baseType = type.BaseType;

                            if (baseType == null || baseType == typeofObject)
                            {
                                break;
                            }

                            if (baseType.GetProperty(prop.Name, prop.PropertyType) != null)
                            {
                                type = baseType;
                            }
                            else
                            {
                                break;
                            }
                        }

                        ArrayList list = (ArrayList)groups[type];

                        if (list == null)
                        {
                            groups[type] = list = new ArrayList();
                        }

                        list.Add(prop);
                    }
                }
            }

            ArrayList sorted = new ArrayList(groups);

            sorted.Sort(new GroupComparer(objectType));

            return(sorted);
        }
예제 #2
0
        private static PropertyInfo[] GetTypeProperties(Type type, string[,] props)
        {
            PropertyInfo[] realProps = null;

            if (props != null)
            {
                realProps = new PropertyInfo[props.GetLength(0)];

                PropertyInfo[] allProps = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

                for (int i = 0; i < realProps.Length; ++i)
                {
                    PropertyInfo thisProp = null;

                    string propName = props[i, 0];

                    for (int j = 0; thisProp == null && j < allProps.Length; ++j)
                    {
                        if (Insensitive.Equals(propName, allProps[j].Name))
                        {
                            thisProp = allProps[j];
                        }
                    }

                    if (thisProp == null)
                    {
                        return(null);
                    }
                    else
                    {
                        CPA attr = Properties.GetCPA(thisProp);

                        if (attr == null || AccessLevel.GameMaster < attr.WriteLevel || !thisProp.CanWrite || attr.ReadOnly)
                        {
                            return(null);
                        }
                        else
                        {
                            realProps[i] = thisProp;
                        }
                    }
                }
            }

            return(realProps);
        }
예제 #3
0
        public bool CheckAccess(Mobile from)
        {
            if (!IsBound)
            {
                throw new NotYetBoundException(this);
            }

            for (int i = 0; i < m_Chain.Length; ++i)
            {
                PropertyInfo prop = m_Chain[i];

                bool isFinal = (i == (m_Chain.Length - 1));

                PropertyAccess access = m_Access;

                if (!isFinal)
                {
                    access |= PropertyAccess.Read;
                }

                CPA security = Properties.GetCPA(prop);

                if (security == null)
                {
                    throw new InternalAccessException(this);
                }

                if ((access & PropertyAccess.Read) != 0 && from.AccessLevel < security.ReadLevel)
                {
                    throw new ReadAccessException(this, from.AccessLevel, security.ReadLevel);
                }

                if ((access & PropertyAccess.Write) != 0 && (from.AccessLevel < security.WriteLevel || security.ReadOnly))
                {
                    throw new WriteAccessException(this, from.AccessLevel, security.ReadLevel);
                }
            }

            return(true);
        }
예제 #4
0
        public static ISpawnable Build(Type type, string[] args)
        {
            bool isISpawnable = typeof(ISpawnable).IsAssignableFrom(type);

            if (!isISpawnable)
            {
                return(null);
            }

            Add.FixArgs(ref args);

            string[,] props = null;

            for (int i = 0; i < args.Length; ++i)
            {
                if (Insensitive.Equals(args[i], "set"))
                {
                    int remains = args.Length - i - 1;

                    if (remains >= 2)
                    {
                        props = new string[remains / 2, 2];

                        remains /= 2;

                        for (int j = 0; j < remains; ++j)
                        {
                            props[j, 0] = args[i + (j * 2) + 1];
                            props[j, 1] = args[i + (j * 2) + 2];
                        }

                        Add.FixSetString(ref args, i);
                    }

                    break;
                }
            }

            PropertyInfo[] realProps = null;

            if (props != null)
            {
                realProps = new PropertyInfo[props.GetLength(0)];

                PropertyInfo[] allProps = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

                for (int i = 0; i < realProps.Length; ++i)
                {
                    PropertyInfo thisProp = null;

                    string propName = props[i, 0];

                    for (int j = 0; thisProp == null && j < allProps.Length; ++j)
                    {
                        if (Insensitive.Equals(propName, allProps[j].Name))
                        {
                            thisProp = allProps[j];
                        }
                    }

                    if (thisProp != null)
                    {
                        CPA attr = Properties.GetCPA(thisProp);

                        if (attr != null && AccessLevel.GameMaster >= attr.WriteLevel && thisProp.CanWrite && !attr.ReadOnly)
                        {
                            realProps[i] = thisProp;
                        }
                    }
                }
            }

            ConstructorInfo[] ctors = type.GetConstructors();

            for (int i = 0; i < ctors.Length; ++i)
            {
                ConstructorInfo ctor = ctors[i];

                if (!Add.IsConstructable(ctor, AccessLevel.GameMaster))
                {
                    continue;
                }

                ParameterInfo[] paramList = ctor.GetParameters();

                if (args.Length == paramList.Length)
                {
                    object[] paramValues = Add.ParseValues(paramList, args);

                    if (paramValues == null)
                    {
                        continue;
                    }

                    object built = ctor.Invoke(paramValues);

                    if (built != null && realProps != null)
                    {
                        for (int j = 0; j < realProps.Length; ++j)
                        {
                            if (realProps[j] == null)
                            {
                                continue;
                            }

                            string result = Properties.InternalSetValue(built, realProps[j], props[j, 1]);
                        }
                    }

                    return((ISpawnable)built);
                }
            }

            return(null);
        }
예제 #5
0
        public static int BuildObjects(Mobile from, Type type, Point3D start, Point3D end, string[] args, string[,] props, ArrayList packs)
        {
            Utility.FixPoints(ref start, ref end);

            PropertyInfo[] realProps = null;

            if (props != null)
            {
                realProps = new PropertyInfo[props.GetLength(0)];

                PropertyInfo[] allProps = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

                for (int i = 0; i < realProps.Length; ++i)
                {
                    PropertyInfo thisProp = null;

                    string propName = props[i, 0];

                    for (int j = 0; thisProp == null && j < allProps.Length; ++j)
                    {
                        if (Insensitive.Equals(propName, allProps[j].Name))
                        {
                            thisProp = allProps[j];
                        }
                    }

                    if (thisProp == null)
                    {
                        from.SendMessage("Property not found: {0}", propName);
                    }
                    else
                    {
                        CPA attr = Properties.GetCPA(thisProp);

                        if (attr == null)
                        {
                            from.SendMessage("Property ({0}) not found.", propName);
                        }
                        else if (from.AccessLevel < attr.WriteLevel)
                        {
                            from.SendMessage("Setting this property ({0}) requires at least {1} access level.", propName, Mobile.GetAccessLevelName(attr.WriteLevel));
                        }
                        else if (!thisProp.CanWrite)
                        {
                            from.SendMessage("Property ({0}) is read only.", propName);
                        }
                        else
                        {
                            realProps[i] = thisProp;
                        }
                    }
                }
            }

            ConstructorInfo[] ctors = type.GetConstructors();

            for (int i = 0; i < ctors.Length; ++i)
            {
                ConstructorInfo ctor = ctors[i];

                if (!IsConstructable(ctor))
                {
                    continue;
                }

                ParameterInfo[] paramList = ctor.GetParameters();

                if (args.Length == paramList.Length)
                {
                    object[] paramValues = ParseValues(paramList, args);

                    if (paramValues == null)
                    {
                        continue;
                    }

                    int built = Build(from, start, end, ctor, paramValues, props, realProps, packs);

                    if (built > 0)
                    {
                        return(built);
                    }
                }
            }

            return(0);
        }
예제 #6
0
        public override void OnResponse(NetState state, RelayInfo info)
        {
            Mobile from = state.Mobile;

            if (!BaseCommand.IsAccessible(from, m_Object))
            {
                from.SendMessage("You may no longer access their properties.");
                return;
            }

            switch (info.ButtonID)
            {
            case 0:                     // Closed
            {
                if (m_Stack != null && m_Stack.Count > 0)
                {
                    StackEntry entry = m_Stack.Pop();

                    from.SendGump(new PropertiesGump(from, entry.m_Object, m_Stack, null));
                }

                break;
            }

            case 1:                     // Previous
            {
                if (m_Page > 0)
                {
                    from.SendGump(new PropertiesGump(from, m_Object, m_Stack, m_List, m_Page - 1));
                }

                break;
            }

            case 2:                     // Next
            {
                if ((m_Page + 1) * EntryCount < m_List.Count)
                {
                    from.SendGump(new PropertiesGump(from, m_Object, m_Stack, m_List, m_Page + 1));
                }

                break;
            }

            default:
            {
                int index = (m_Page * EntryCount) + (info.ButtonID - 3);

                if (index >= 0 && index < m_List.Count)
                {
                    PropertyInfo prop = m_List[index] as PropertyInfo;

                    if (prop == null)
                    {
                        return;
                    }

                    CPA attr = GetCPA(prop);

                    if (!prop.CanWrite || attr == null || from.AccessLevel < attr.WriteLevel || attr.ReadOnly)
                    {
                        return;
                    }

                    Type type = prop.PropertyType;

                    if (IsType(type, typeofMobile) || IsType(type, typeofItem))
                    {
                        from.SendGump(new SetObjectGump(prop, from, m_Object, m_Stack, type, m_Page, m_List));
                    }
                    else if (IsType(type, typeofType))
                    {
                        from.Target = new SetObjectTarget(prop, from, m_Object, m_Stack, type, m_Page, m_List);
                    }
                    else if (IsType(type, typeofPoint3D))
                    {
                        from.SendGump(new SetPoint3DGump(prop, from, m_Object, m_Stack, m_Page, m_List));
                    }
                    else if (IsType(type, typeofPoint2D))
                    {
                        from.SendGump(new SetPoint2DGump(prop, from, m_Object, m_Stack, m_Page, m_List));
                    }
                    else if (IsType(type, typeofTimeSpan))
                    {
                        from.SendGump(new SetTimeSpanGump(prop, from, m_Object, m_Stack, m_Page, m_List));
                    }
                    else if (IsCustomEnum(type))
                    {
                        from.SendGump(new SetCustomEnumGump(prop, from, m_Object, m_Stack, m_Page, m_List, GetCustomEnumNames(type)));
                    }
                    else if (IsType(type, typeofEnum))
                    {
                        from.SendGump(new SetListOptionGump(prop, from, m_Object, m_Stack, m_Page, m_List, Enum.GetNames(type), GetObjects(Enum.GetValues(type))));
                    }
                    else if (IsType(type, typeofBool))
                    {
                        from.SendGump(new SetListOptionGump(prop, from, m_Object, m_Stack, m_Page, m_List, m_BoolNames, m_BoolValues));
                    }
                    else if (IsType(type, typeofString) || IsType(type, typeofReal) || IsType(type, typeofNumeric) || IsType(type, typeofText))
                    {
                        from.SendGump(new SetGump(prop, from, m_Object, m_Stack, m_Page, m_List));
                    }
                    else if (IsType(type, typeofPoison))
                    {
                        from.SendGump(new SetListOptionGump(prop, from, m_Object, m_Stack, m_Page, m_List, m_PoisonNames, m_PoisonValues));
                    }
                    else if (IsType(type, typeofMap))
                    {
                        from.SendGump(new SetListOptionGump(prop, from, m_Object, m_Stack, m_Page, m_List, Map.GetMapNames(), Map.GetMapValues()));
                    }
                    else if (IsType(type, typeofSkills) && m_Object is Mobile)
                    {
                        from.SendGump(new PropertiesGump(from, m_Object, m_Stack, m_List, m_Page));
                        from.SendGump(new SkillsGump(from, (Mobile)m_Object));
                    }
                    else if (HasAttribute(type, typeofPropertyObject, true))
                    {
                        object obj = prop.GetValue(m_Object, null);

                        if (obj != null)
                        {
                            from.SendGump(new PropertiesGump(from, obj, m_Stack, new StackEntry(m_Object, prop)));
                        }
                        else
                        {
                            from.SendGump(new PropertiesGump(from, m_Object, m_Stack, m_List, m_Page));
                        }
                    }
                }

                break;
            }
            }
        }
예제 #7
0
        private void Initialize(int page)
        {
            m_Page = page;

            int count = m_List.Count - (page * EntryCount);

            if (count < 0)
            {
                count = 0;
            }
            else if (count > EntryCount)
            {
                count = EntryCount;
            }

            int lastIndex = (page * EntryCount) + count - 1;

            if (lastIndex >= 0 && lastIndex < m_List.Count && m_List[lastIndex] == null)
            {
                --count;
            }

            int totalHeight = OffsetSize + ((EntryHeight + OffsetSize) * (count + 1));

            AddPage(0);

            AddBackground(0, 0, BackWidth, BorderSize + totalHeight + BorderSize, BackGumpID);
            AddImageTiled(BorderSize, BorderSize, TotalWidth - (OldStyle ? SetWidth + OffsetSize : 0), totalHeight, OffsetGumpID);

            int x = BorderSize + OffsetSize;
            int y = BorderSize + OffsetSize;

            int emptyWidth = TotalWidth - PrevWidth - NextWidth - (OffsetSize * 4) - (OldStyle ? SetWidth + OffsetSize : 0);

            if (OldStyle)
            {
                AddImageTiled(x, y, TotalWidth - (OffsetSize * 3) - SetWidth, EntryHeight, HeaderGumpID);
            }
            else
            {
                AddImageTiled(x, y, PrevWidth, EntryHeight, HeaderGumpID);
            }

            if (page > 0)
            {
                AddButton(x + PrevOffsetX, y + PrevOffsetY, PrevButtonID1, PrevButtonID2, 1, GumpButtonType.Reply, 0);

                if (PrevLabel)
                {
                    AddLabel(x + PrevLabelOffsetX, y + PrevLabelOffsetY, TextHue, "Previous");
                }
            }

            x += PrevWidth + OffsetSize;

            if (!OldStyle)
            {
                AddImageTiled(x, y, emptyWidth, EntryHeight, HeaderGumpID);
            }

            if (TypeLabel && m_Type != null)
            {
                AddHtml(x, y, emptyWidth, EntryHeight, String.Format("<BASEFONT COLOR=#FAFAFA><CENTER>{0}</CENTER></BASEFONT>", m_Type.Name), false, false);
            }

            x += emptyWidth + OffsetSize;

            if (!OldStyle)
            {
                AddImageTiled(x, y, NextWidth, EntryHeight, HeaderGumpID);
            }

            if ((page + 1) * EntryCount < m_List.Count)
            {
                AddButton(x + NextOffsetX, y + NextOffsetY, NextButtonID1, NextButtonID2, 2, GumpButtonType.Reply, 1);

                if (NextLabel)
                {
                    AddLabel(x + NextLabelOffsetX, y + NextLabelOffsetY, TextHue, "Next");
                }
            }

            for (int i = 0, index = page * EntryCount; i < count && index < m_List.Count; ++i, ++index)
            {
                x  = BorderSize + OffsetSize;
                y += EntryHeight + OffsetSize;

                object o = m_List[index];

                if (o == null)
                {
                    AddImageTiled(x - OffsetSize, y, TotalWidth, EntryHeight, BackGumpID + 4);
                }
                else if (o is Type)
                {
                    Type type = (Type)o;

                    AddImageTiled(x, y, TypeWidth, EntryHeight, EntryGumpID);
                    AddLabelCropped(x + TextOffsetX, y, TypeWidth - TextOffsetX, EntryHeight, TextHue, type.Name);
                    x += TypeWidth + OffsetSize;

                    if (SetGumpID != 0)
                    {
                        AddImageTiled(x, y, SetWidth, EntryHeight, SetGumpID);
                    }
                }
                else if (o is PropertyInfo)
                {
                    PropertyInfo prop = (PropertyInfo)o;

                    AddImageTiled(x, y, NameWidth, EntryHeight, EntryGumpID);
                    AddLabelCropped(x + TextOffsetX, y, NameWidth - TextOffsetX, EntryHeight, TextHue, prop.Name);
                    x += NameWidth + OffsetSize;
                    AddImageTiled(x, y, ValueWidth, EntryHeight, EntryGumpID);
                    AddLabelCropped(x + TextOffsetX, y, ValueWidth - TextOffsetX, EntryHeight, TextHue, ValueToString(prop));
                    x += ValueWidth + OffsetSize;

                    if (SetGumpID != 0)
                    {
                        AddImageTiled(x, y, SetWidth, EntryHeight, SetGumpID);
                    }

                    CPA cpa = GetCPA(prop);

                    if (prop.CanWrite && cpa != null && m_Mobile.AccessLevel >= cpa.WriteLevel && !cpa.ReadOnly)
                    {
                        AddButton(x + SetOffsetX, y + SetOffsetY, SetButtonID1, SetButtonID2, i + 3, GumpButtonType.Reply, 0);
                    }
                }
            }
        }
예제 #8
0
        public static PropertyInfo[] GetPropertyInfoChain(Mobile from, Type type, string propertyString, PropertyAccess endAccess, ref string failReason)
        {
            string[] split = propertyString.Split('.');

            if (split.Length == 0)
            {
                return(null);
            }

            PropertyInfo[] info = new PropertyInfo[split.Length];

            for (int i = 0; i < info.Length; ++i)
            {
                string propertyName = split[i];

                if (CIEqual(propertyName, "current"))
                {
                    continue;
                }

                PropertyInfo[] props = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

                bool isFinal = (i == (info.Length - 1));

                PropertyAccess access = endAccess;

                if (!isFinal)
                {
                    access |= PropertyAccess.Read;
                }

                for (int j = 0; j < props.Length; ++j)
                {
                    PropertyInfo p = props[j];

                    if (CIEqual(p.Name, propertyName))
                    {
                        CPA attr = GetCPA(p);

                        if (attr == null)
                        {
                            failReason = String.Format("Property '{0}' not found.", propertyName);
                            return(null);
                        }
                        else if ((access & PropertyAccess.Read) != 0 && from.AccessLevel < attr.ReadLevel)
                        {
                            failReason = String.Format("You must be at least {0} to get the property '{1}'.",
                                                       Mobile.GetAccessLevelName(attr.ReadLevel), propertyName);

                            return(null);
                        }
                        else if ((access & PropertyAccess.Write) != 0 && from.AccessLevel < attr.WriteLevel)
                        {
                            if ((int)attr.WriteLevel > (Enum.GetValues(typeof(AccessLevel)).Length - 1))
                            {
                                failReason = String.Format("Property '{0}' is read only.", propertyName);
                            }
                            else
                            {
                                failReason = String.Format("You must be at least {0} to set the property '{1}'.",
                                                           Mobile.GetAccessLevelName(attr.WriteLevel), propertyName);
                            }

                            return(null);
                        }
                        else if ((access & PropertyAccess.Read) != 0 && !p.CanRead)
                        {
                            failReason = String.Format("Property '{0}' is write only.", propertyName);
                            return(null);
                        }
                        else if ((access & PropertyAccess.Write) != 0 && (!p.CanWrite || attr.ReadOnly) && isFinal)
                        {
                            failReason = String.Format("Property '{0}' is read only.", propertyName);
                            return(null);
                        }

                        info[i] = p;
                        type    = p.PropertyType;
                        break;
                    }
                }

                if (info[i] == null)
                {
                    failReason = String.Format("Property '{0}' not found.", propertyName);
                    return(null);
                }
            }

            return(info);
        }
예제 #9
0
        private void Initialize(int page)
        {
            m_Page = page;

            int count = m_List.Count - (page * EntryCount);

            if (count < 0)
            {
                count = 0;
            }
            else if (count > EntryCount)
            {
                count = EntryCount;
            }

            int lastIndex = (page * EntryCount) + count - 1;

            if (lastIndex >= 0 && lastIndex < m_List.Count && m_List[lastIndex] == null)
            {
                --count;
            }

            int totalHeight = OffsetSize + ((EntryHeight + OffsetSize) * (ColumnEntryCount + 1));

            AddPage(0);

            AddBackground(0, 0, TotalWidth * 3 + BorderSize * 2, BorderSize + totalHeight + BorderSize, BackGumpID);
            AddImageTiled(BorderSize, BorderSize + EntryHeight, (TotalWidth - (OldStyle ? SetWidth + OffsetSize : 0)) * 3, totalHeight - EntryHeight, OffsetGumpID);

            int x = BorderSize + OffsetSize;
            int y = BorderSize /*+ OffsetSize*/;

            int emptyWidth = TotalWidth - PrevWidth - NextWidth - (OffsetSize * 4) - (OldStyle ? SetWidth + OffsetSize : 0);

            if (m_Object is Item)
            {
                AddLabelCropped(x + TextOffsetX, y, TypeWidth - TextOffsetX, EntryHeight, TextHue, ((Item)m_Object).Name);
            }
            int propcount = 0;

            for (int i = 0, index = page * EntryCount; i < count && index < m_List.Count; ++i, ++index)
            {
                // do the multi column display
                int column = propcount / ColumnEntryCount;
                if (propcount % ColumnEntryCount == 0)
                {
                    y = BorderSize;
                }
                x  = BorderSize + OffsetSize + column * (ValueWidth + NameWidth + OffsetSize * 2 + SetOffsetX + SetWidth);
                y += EntryHeight + OffsetSize;



                object o = m_List[index];

                if (o == null)
                {
                    AddImageTiled(x - OffsetSize, y, TotalWidth, EntryHeight, BackGumpID + 4);
                    propcount++;
                }
                else

                /*if ( o is Type )
                 *              {
                 *                      Type type = (Type)o;
                 *
                 *                      AddImageTiled( x, y, TypeWidth, EntryHeight, EntryGumpID );
                 *                      AddLabelCropped( x + TextOffsetX, y, TypeWidth - TextOffsetX, EntryHeight, TextHue, type.Name );
                 *                      x += TypeWidth + OffsetSize;
                 *
                 *                      if ( SetGumpID != 0 )
                 *                              AddImageTiled( x, y, SetWidth, EntryHeight, SetGumpID );
                 *              }
                 *              else
                 */
                if (o is PropertyInfo)
                {
                    propcount++;

                    PropertyInfo prop = (PropertyInfo)o;

                    // look for the default value of the equivalent property in the XmlSpawnerDefaults.DefaultEntry class

                    int       huemodifier = TextHue;
                    FieldInfo finfo       = null;
                    Server.Mobiles.XmlSpawnerDefaults.DefaultEntry de = new Server.Mobiles.XmlSpawnerDefaults.DefaultEntry();
                    Type ftype = de.GetType();
                    if (ftype != null)
                    {
                        finfo = ftype.GetField(prop.Name);
                    }
                    // is there an equivalent default field?
                    if (finfo != null)
                    {
                        // see if the value is different from the default
                        if (ValueToString(finfo.GetValue(de)) != ValueToString(prop))
                        {
                            huemodifier = 68;
                        }
                    }

                    AddImageTiled(x, y, NameWidth, EntryHeight, EntryGumpID);
                    AddLabelCropped(x + TextOffsetX, y, NameWidth - TextOffsetX, EntryHeight, huemodifier, prop.Name);
                    x += NameWidth + OffsetSize;
                    AddImageTiled(x, y, ValueWidth, EntryHeight, EntryGumpID);
                    AddLabelCropped(x + TextOffsetX, y, ValueWidth - TextOffsetX, EntryHeight, huemodifier, ValueToString(prop));
                    x += ValueWidth + OffsetSize;

                    if (SetGumpID != 0)
                    {
                        AddImageTiled(x, y, SetWidth, EntryHeight, SetGumpID);
                    }

                    CPA cpa = GetCPA(prop);

                    if (prop.CanWrite && cpa != null && m_Mobile.AccessLevel >= cpa.WriteLevel)
                    {
                        AddButton(x + SetOffsetX, y + SetOffsetY, SetButtonID1, SetButtonID2, i + 3, GumpButtonType.Reply, 0);
                    }
                }
            }
        }
예제 #10
0
        public static string IncreaseValue(Mobile from, object o, string[] args)
        {
            Type type = o.GetType();

            PropertyInfo[] props      = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);
            PropertyInfo[] realProps  = new PropertyInfo[args.Length / 2];
            int[]          realValues = new int[args.Length / 2];

            bool positive = false, negative = false;

            for (int i = 0; i < realProps.Length; ++i)
            {
                string name = args[i * 2];

                try
                {
                    string valueString = args[1 + (i * 2)];

                    if (valueString.StartsWith("0x"))
                    {
                        realValues[i] = Convert.ToInt32(valueString.Substring(2), 16);
                    }
                    else
                    {
                        realValues[i] = Convert.ToInt32(valueString);
                    }
                }
                catch
                {
                    return("Offset value could not be parsed.");
                }

                if (realValues[i] > 0)
                {
                    positive = true;
                }
                else if (realValues[i] < 0)
                {
                    negative = true;
                }
                else
                {
                    return("Zero is not a valid value to offset.");
                }

                foreach (PropertyInfo p in props)
                {
                    if (CIEqual(p.Name, name))
                    {
                        CPA attr = GetCPA(p);

                        if (attr == null)
                        {
                            return("Property not found.");
                        }

                        if (from.AccessLevel < attr.ReadLevel)
                        {
                            return(String.Format("Getting this property requires at least {0} access level.", Mobile.GetAccessLevelName(attr.ReadLevel)));
                        }

                        if (!p.CanRead)
                        {
                            return("Property is write only.");
                        }

                        if (from.AccessLevel < attr.WriteLevel)
                        {
                            return(String.Format("Setting this property requires at least {0} access level.", Mobile.GetAccessLevelName(attr.WriteLevel)));
                        }

                        if (!p.CanWrite)
                        {
                            return("Property is read only.");
                        }

                        realProps[i] = p;
                    }
                }

                if (realProps[i] == null)
                {
                    return("Property not found.");
                }
            }

            for (int i = 0; i < realProps.Length; ++i)
            {
                object obj = realProps[i].GetValue(o, null);
                long   v   = (long)Convert.ChangeType(obj, TypeCode.Int64);
                v += realValues[i];

                realProps[i].SetValue(o, Convert.ChangeType(v, realProps[i].PropertyType), null);
            }

            if (realProps.Length == 1)
            {
                if (positive)
                {
                    return("The property has been increased.");
                }

                return("The property has been decreased.");
            }

            if (positive && negative)
            {
                return("The properties have been changed.");
            }

            if (positive)
            {
                return("The properties have been increased.");
            }

            return("The properties have been decreased.");
        }
예제 #11
0
        public static PropertyInfo[] GetPropertyInfoChain(Mobile from, Type type, string propertyString, bool isReading, ref string failReason)
        {
            string[] split = propertyString.Split('.');

            if (split.Length == 0)
            {
                return(null);
            }

            PropertyInfo[] info = new PropertyInfo[split.Length];

            for (int i = 0; i < info.Length; ++i)
            {
                string propertyName = split[i];

                if (CIEqual(propertyName, "current"))
                {
                    continue;
                }

                PropertyInfo[] props = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

                bool reading = true;

                if (i == info.Length - 1)
                {
                    reading = isReading;
                }

                for (int j = 0; j < props.Length; ++j)
                {
                    PropertyInfo p = props[j];

                    if (CIEqual(p.Name, propertyName))
                    {
                        CPA attr = GetCPA(p);

                        if (attr == null)
                        {
                            failReason = String.Format("Property '{0}' not found.", propertyName);
                            return(null);
                        }

                        if (from.AccessLevel < (reading ? attr.ReadLevel : attr.WriteLevel))
                        {
                            failReason = String.Format("You must be at least {0} to {1} the property '{2}'.",
                                                       Mobile.GetAccessLevelName((reading ? attr.ReadLevel : attr.WriteLevel)), reading ? "get" : "set", propertyName);

                            return(null);
                        }

                        if (from.AccessLevel < (reading ? attr.ReadLevel : attr.WriteLevel))
                        {
                            failReason = String.Format("You must be at least {0} to {1} the property '{2}'.",
                                                       Mobile.GetAccessLevelName(attr.ReadLevel), reading ? "get" : "set", propertyName);

                            return(null);
                        }
                        if (reading && !p.CanRead)
                        {
                            failReason = String.Format("Property '{0}' is write only.", propertyName);
                            return(null);
                        }
                        else if (!reading && !p.CanWrite)
                        {
                            failReason = String.Format("Property '{0}' is read only.", propertyName);
                            return(null);
                        }

                        info[i] = p;
                        type    = p.PropertyType;
                        break;
                    }
                }

                if (info[i] == null)
                {
                    failReason = String.Format("Property '{0}' not found.", propertyName);
                    return(null);
                }
            }

            return(info);
        }