Example #1
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;
                }
            }
        }
Example #2
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}'.");
                }
            }
        }
        public virtual bool WasNamed(string speech)
        {
            string name = this.Name;

            return(name != null && InsensitiveStringHelpers.InsensitiveStartsWith(speech, name));
        }
Example #4
0
 public bool WasNamed(string speech)
 {
     return(this.Name != null && InsensitiveStringHelpers.InsensitiveStartsWith(speech, this.Name));
 }