public static ObjectConditional Parse(Mobile from, ref string[] args)
        {
            string[] conditionArgs = null;

            for (int i = 0; i < args.Length; ++i)
            {
                if (InsensitiveStringHelpers.Equals(args[i], "where"))
                {
                    string[] origArgs = args;

                    args = new string[i];

                    for (int j = 0; j < args.Length; ++j)
                    {
                        args[j] = origArgs[j];
                    }

                    conditionArgs = new string[origArgs.Length - i - 1];

                    for (int j = 0; j < conditionArgs.Length; ++j)
                    {
                        conditionArgs[j] = origArgs[i + j + 1];
                    }

                    break;
                }
            }

            return(ParseDirect(from, conditionArgs, 0, conditionArgs?.Length ?? 0));
        }
예제 #2
0
        public override void ExecuteList(CommandEventArgs e, List <object> list)
        {
            if (list.Count > 0)
            {
                List <string> columns = new List <string> {
                    "Object"
                };

                if (e.Length > 0)
                {
                    int offset = 0;

                    if (InsensitiveStringHelpers.Equals(e.GetString(0), "view"))
                    {
                        ++offset;
                    }

                    while (offset < e.Length)
                    {
                        columns.Add(e.GetString(offset++));
                    }
                }

                e.Mobile.SendGump(new InterfaceGump(e.Mobile, columns.ToArray(), list, 0, null));
            }
            else
            {
                AddResponse("No matching objects found.");
            }
        }
예제 #3
0
        public virtual void CapitalizeTitle()
        {
            string title = this.Title;

            if (title == null)
            {
                return;
            }

            string[] split = title.Split(' ');

            for (int i = 0; i < split.Length; ++i)
            {
                if (InsensitiveStringHelpers.Equals(split[i], "the"))
                {
                    continue;
                }

                if (split[i].Length > 1)
                {
                    split[i] = Char.ToUpper(split[i][0]) + split[i].Substring(1);
                }
                else if (split[i].Length > 0)
                {
                    split[i] = Char.ToUpper(split[i][0]).ToString();
                }
            }

            this.Title = String.Join(" ", split);
        }
예제 #4
0
        private static void EventSink_Speech(SpeechEventArgs args)
        {
            if (!args.Handled)
            {
                if (InsensitiveStringHelpers.InsensitiveStartsWith(args.Speech, "set"))
                {
                    Mobile from = args.Mobile;

                    string[] split = args.Speech.Split(' ');

                    if (split.Length == 3)
                    {
                        try
                        {
                            string name  = split[1];
                            double value = Convert.ToDouble(split[2]);

                            if (InsensitiveStringHelpers.Equals(name, "str"))
                            {
                                ChangeStrength(from, (int)value);
                            }
                            else if (InsensitiveStringHelpers.Equals(name, "dex"))
                            {
                                ChangeDexterity(from, (int)value);
                            }
                            else if (InsensitiveStringHelpers.Equals(name, "int"))
                            {
                                ChangeIntelligence(from, (int)value);
                            }
                            else
                            {
                                ChangeSkill(from, name, value);
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                else if (InsensitiveStringHelpers.Equals(args.Speech, "help"))
                {
                    args.Mobile.SendGump(new TCHelpGump());

                    args.Handled = true;
                }
            }
        }
예제 #5
0
            public int Compare(Mobile x, Mobile y)
            {
                if (x == null || y == null)
                {
                    throw new ArgumentException();
                }

                if (x.AccessLevel > y.AccessLevel)
                {
                    return(-1);
                }
                else if (x.AccessLevel < y.AccessLevel)
                {
                    return(1);
                }
                else
                {
                    return(InsensitiveStringHelpers.InsensitiveCompare(x.Name, y.Name));
                }
            }
        public static ObjectConditional ParseDirect(Mobile from, string[] args, int offset, int size)
        {
            if (args == null || size == 0)
            {
                return(Empty);
            }

            int index = 0;

            Type objectType = AssemblyHandler.FindFirstTypeForName(args[offset + index], true);

            if (objectType == null)
            {
                throw new Exception($"No type with that name ({args[offset + index]}) was found.");
            }

            ++index;

            List <ICondition[]> conditions = new List <ICondition[]>();
            List <ICondition>   current    = new List <ICondition>();

            current.Add(TypeCondition.Default);

            while (index < size)
            {
                string cur = args[offset + index];

                bool inverse = false;

                if (InsensitiveStringHelpers.Equals(cur, "not") || cur == "!")
                {
                    inverse = true;
                    ++index;

                    if (index >= size)
                    {
                        throw new Exception("Improperly formatted object conditional.");
                    }
                }
                else if (InsensitiveStringHelpers.Equals(cur, "or") || cur == "||")
                {
                    if (current.Count > 1)
                    {
                        conditions.Add(current.ToArray());

                        current.Clear();
                        current.Add(TypeCondition.Default);
                    }

                    ++index;

                    continue;
                }

                string binding = args[offset + index];
                index++;

                if (index >= size)
                {
                    throw new Exception("Improperly formatted object conditional.");
                }

                string oper = args[offset + index];
                index++;

                if (index >= size)
                {
                    throw new Exception("Improperly formatted object conditional.");
                }

                string val = args[offset + index];
                index++;

                Property prop = new Property(binding);

                prop.BindTo(objectType, PropertyAccess.Read);
                prop.CheckAccess(from);

                var condition = oper switch
                {
                    "=" => (ICondition) new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val),
                    "==" => new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val),
                    "is" => new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val),
                    "!=" => new ComparisonCondition(prop, inverse, ComparisonOperator.NotEqual, val),
                    ">" => new ComparisonCondition(prop, inverse, ComparisonOperator.Greater, val),
                    "<" => new ComparisonCondition(prop, inverse, ComparisonOperator.Lesser, val),
                    ">=" => new ComparisonCondition(prop, inverse, ComparisonOperator.GreaterEqual, val),
                    "<=" => new ComparisonCondition(prop, inverse, ComparisonOperator.LesserEqual, val),
                    "==~" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
                    "~==" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
                    "=~" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
                    "~=" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
                    "is~" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
                    "~is" => new StringCondition(prop, inverse, StringOperator.Equal, val, true),
                    "!=~" => new StringCondition(prop, inverse, StringOperator.NotEqual, val, true),
                    "~!=" => new StringCondition(prop, inverse, StringOperator.NotEqual, val, true),
                    "starts" => new StringCondition(prop, inverse, StringOperator.StartsWith, val, false),
                    "starts~" => new StringCondition(prop, inverse, StringOperator.StartsWith, val, true),
                    "~starts" => new StringCondition(prop, inverse, StringOperator.StartsWith, val, true),
                    "ends" => new StringCondition(prop, inverse, StringOperator.EndsWith, val, false),
                    "ends~" => new StringCondition(prop, inverse, StringOperator.EndsWith, val, true),
                    "~ends" => new StringCondition(prop, inverse, StringOperator.EndsWith, val, true),
                    "contains" => new StringCondition(prop, inverse, StringOperator.Contains, val, false),
                    "contains~" => new StringCondition(prop, inverse, StringOperator.Contains, val, true),
                    "~contains" => new StringCondition(prop, inverse, StringOperator.Contains, val, true),
                    _ => null
                };

                if (condition == null)
                {
                    throw new InvalidOperationException($"Unrecognized operator (\"{oper}\").");
                }

                current.Add(condition);
            }

            conditions.Add(current.ToArray());

            return(new ObjectConditional(objectType, conditions.ToArray()));
        }
    }
예제 #7
0
        public void Acquire(TypeBuilder typeBuilder, ILGenerator il, string fieldName)
        {
            if (!(Value is string toParse))
            {
                return;
            }

            if (!Type.IsValueType && toParse == "null")
            {
                Value = null;
            }
            else if (Type == typeof(string))
            {
                if (toParse == @"@""null""")
                {
                    toParse = "null";
                }

                Value = toParse;
            }
            else if (Type.IsEnum)
            {
                Value = Enum.Parse(Type, toParse, true);
            }
            else
            {
                MethodInfo parseMethod;
                object[]   parseArgs;

                MethodInfo parseNumber = Type.GetMethod(
                    "Parse",
                    BindingFlags.Public | BindingFlags.Static,
                    null,
                    new[] { typeof(string), typeof(NumberStyles) },
                    null);

                if (parseNumber != null)
                {
                    NumberStyles style = NumberStyles.Integer;

                    if (InsensitiveStringHelpers.InsensitiveStartsWith(toParse, "0x"))
                    {
                        style   = NumberStyles.HexNumber;
                        toParse = toParse.Substring(2);
                    }

                    parseMethod = parseNumber;
                    parseArgs   = new object[] { toParse, style };
                }
                else
                {
                    MethodInfo parseGeneral = Type.GetMethod(
                        "Parse",
                        BindingFlags.Public | BindingFlags.Static,
                        null,
                        new[] { typeof(string) },
                        null);

                    parseMethod = parseGeneral;
                    parseArgs   = new object[] { toParse };
                }

                if (parseMethod != null)
                {
                    Value = parseMethod.Invoke(null, parseArgs);

                    if (!Type.IsPrimitive)
                    {
                        Field = typeBuilder.DefineField(
                            fieldName,
                            Type,
                            FieldAttributes.Private | FieldAttributes.InitOnly);

                        // parseMethod.Invoke(null,
                        //              parseArgs.Length == 2 ? new object[] {toParse, (int) parseArgs[1]} : new object[] {toParse});

                        il.Emit(OpCodes.Ldarg_0);

                        il.Emit(OpCodes.Ldstr, toParse);

                        if (parseArgs.Length == 2) // dirty evil hack :-(
                        {
                            il.Emit(OpCodes.Ldc_I4, (int)parseArgs[1]);
                        }

                        il.Emit(OpCodes.Call, parseMethod);
                        il.Emit(OpCodes.Stfld, Field);
                    }
                }
                else
                {
                    throw new InvalidOperationException(
                              $"Unable to convert string \"{Value}\" into type '{Type}'.");
                }
            }
        }
예제 #8
0
        public static void Invoke(Mobile from, Point3D start, Point3D end, string[] args, List <Container> packs = null,
                                  bool outline = false, bool mapAvg = false)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("{0} {1} building ", from.AccessLevel, CommandLogging.Format(from));

            if (start == end)
            {
                sb.AppendFormat("at {0} in {1}", start, from.Map);
            }
            else
            {
                sb.AppendFormat("from {0} to {1} in {2}", start, end, from.Map);
            }

            sb.Append(":");

            for (int i = 0; i < args.Length; ++i)
            {
                sb.AppendFormat(" \"{0}\"", args[i]);
            }

            CommandLogging.WriteLine(from, sb.ToString());

            string name = args[0];

            FixArgs(ref args);

            string[,] props = null;

            for (int i = 0; i < args.Length; ++i)
            {
                if (InsensitiveStringHelpers.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];
                        }

                        FixSetString(ref args, i);
                    }

                    break;
                }
            }

            Type type = AssemblyHandler.FindTypeByName(name);

            if (!IsEntity(type))
            {
                from.SendMessage("No type with that name was found.");
                return;
            }

            DateTime time = DateTime.UtcNow;

            int built = BuildObjects(from, type, start, end, args, props, packs, outline, mapAvg);

            if (built > 0)
            {
                from.SendMessage("{0} object{1} generated in {2:F1} seconds.", built, built != 1 ? "s" : "",
                                 (DateTime.UtcNow - time).TotalSeconds);
            }
            else
            {
                SendUsage(type, from);
            }
        }
예제 #9
0
        public static int BuildObjects(Mobile from, Type type, Point3D start, Point3D end, string[] args, string[,] props,
                                       List <Container> packs, bool outline = false, bool mapAvg = false)
        {
            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 (InsensitiveStringHelpers.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 || attr.ReadOnly)
                        {
                            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 (!IsConstructible(ctor, from.AccessLevel))
                {
                    continue;
                }

                // Handle optional constructors
                ParameterInfo[] paramList   = ctor.GetParameters();
                int             totalParams = paramList.Count(t => !t.HasDefaultValue);

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

                    if (paramValues == null)
                    {
                        continue;
                    }

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

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

            return(0);
        }
예제 #10
0
 private static bool CIEqual(string l, string r) => InsensitiveStringHelpers.Equals(l, r);
        public virtual bool WasNamed(string speech)
        {
            string name = this.Name;

            return(name != null && InsensitiveStringHelpers.InsensitiveStartsWith(speech, name));
        }
예제 #12
0
 public bool WasNamed(string speech)
 {
     return(this.Name != null && InsensitiveStringHelpers.InsensitiveStartsWith(speech, this.Name));
 }
예제 #13
0
        public void Claim(Mobile from, string petName)
        {
            if (Deleted || !from.CheckAlive())
            {
                return;
            }

            bool claimed = false;
            int  stabled = 0;

            bool claimByName = petName != null;

            for (int i = 0; i < from.Stabled.Count; ++i)
            {
                BaseCreature pet = from.Stabled[i] as BaseCreature;

                if (pet == null || pet.Deleted)
                {
                    pet.IsStabled = false;
                    pet.StabledBy = null;
                    from.Stabled.RemoveAt(i);
                    --i;
                    continue;
                }

                ++stabled;

                if (claimByName && !InsensitiveStringHelpers.Equals(pet.Name, petName))
                {
                    continue;
                }

                if (CanClaim(from, pet))
                {
                    DoClaim(from, pet);

                    from.Stabled.RemoveAt(i);

                    --i;

                    claimed = true;
                }
                else
                {
                    SayTo(from, 1049612, pet.Name);                       // ~1_NAME~ remained in the stables because you have too many followers.
                }
            }

            if (claimed)
            {
                SayTo(from, 1042559);                   // Here you go... and good day to you!
            }
            else if (stabled == 0)
            {
                SayTo(from, 502671);                   // But I have no animals stabled with me at the moment!
            }
            else if (claimByName)
            {
                BeginClaimList(from);
            }
        }