Exemple #1
0
        private static void EventSink_Speech(SpeechEventArgs args)
        {
            if (!args.Handled)
            {
                if (Insensitive.StartsWith(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 (Insensitive.Equals(name, "str"))
                            {
                                ChangeStrength(@from, (int)value);
                            }
                            else if (Insensitive.Equals(name, "dex"))
                            {
                                ChangeDexterity(@from, (int)value);
                            }
                            else if (Insensitive.Equals(name, "int"))
                            {
                                ChangeIntelligence(@from, (int)value);
                            }
                            else
                            {
                                ChangeSkill(@from, name, value);
                            }
                        }
                        catch (Exception e)
                        {
                            Server.Diagnostics.ExceptionLogging.LogException(e);
                        }
                    }
                }
                else if (Insensitive.StartsWith(args.Speech, "give"))
                {
                    Mobile from = args.Mobile;

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

                    if (split.Length == 2)
                    {
                        string name = split[1];

                        if (Insensitive.Equals(name, "resources"))
                        {
                            if (CanGive(from, "Resources"))
                            {
                                GiveResources(from);
                                from.SendMessage("Resources have been added to your bank");
                            }
                        }
                        else if (Insensitive.Equals(name, "arties"))
                        {
                            if (CanGive(from, "Artifacts"))
                            {
                                GiveArtifacts(from);
                                from.SendMessage("Artifacts have been added to your bank");
                            }
                        }
                        else if (Insensitive.Equals(name, "air"))
                        {
                            if (CanGive(from, "Air"))
                            {
                                GiveAirFreshner(from);
                                from.SendMessage("Air Freshner has been added to your bank.");
                            }
                        }
                        else if (Insensitive.Equals(name, "seeds"))
                        {
                            if (CanGive(from, "Seeds"))
                            {
                                GiveSeeds(from);
                                from.SendMessage("Seeds have been added to your bank.");
                            }
                        }
                        else if (Insensitive.Equals(name, "tokens"))
                        {
                            if (CanGive(from, "Tokens"))
                            {
                                GiveTokens(from);
                            }
                        }
                        else if (Insensitive.Equals(name, "masteries"))
                        {
                            if (CanGive(from, "Masteries"))
                            {
                                GiveMasteries(from);
                                from.SendMessage("Masteries have been added to your bank.");
                            }
                        }
                    }
                }
                else if (Insensitive.Equals(args.Speech, "help"))
                {
                    args.Mobile.SendGump(new TCHelpGump());

                    args.Handled = true;
                }
            }
        }
Exemple #2
0
 private static bool CIEqual(string l, string r) => Insensitive.Equals(l, r);
        private static bool Check(
            Map map,
            IPoint3D p,
            List <Item> items,
            int x,
            int y,
            int startTop,
            int startZ,
            bool canSwim,
            bool cantWalk,
            out int newZ)
        {
            newZ = 0;

            StaticTile[] tiles        = map.Tiles.GetStaticTiles(x, y, true);
            LandTile     landTile     = map.Tiles.GetLandTile(x, y);
            LandData     landData     = TileData.LandTable[landTile.ID & TileData.MaxLandValue];
            bool         landBlocks   = (landData.Flags & TileFlag.Impassable) != 0;
            bool         considerLand = !landTile.Ignored;

            if (landBlocks && canSwim && (landData.Flags & TileFlag.Wet) != 0)
            {
                //Impassable, Can Swim, and Is water.  Don't block it.
                landBlocks = false;
            }
            else if (cantWalk && (landData.Flags & TileFlag.Wet) == 0)
            {
                //Can't walk and it's not water
                landBlocks = true;
            }

            int landZ = 0, landCenter = 0, landTop = 0;

            map.GetAverageZ(x, y, ref landZ, ref landCenter, ref landTop);

            bool moveIsOk = false;

            int stepTop  = startTop + StepHeight;
            int checkTop = startZ + PersonHeight;

            Mobile m = p as Mobile;

            bool ignoreDoors = MovementImpl.AlwaysIgnoreDoors || m == null || !m.Alive || m.IsDeadBondedPet || m.Body.IsGhost ||
                               m.Body.BodyID == 987;
            bool ignoreSpellFields = m is PlayerMobile && map.MapID != 0;

            int      itemZ, itemTop, ourZ, ourTop, testTop;
            ItemData itemData;
            TileFlag flags;

            #region Tiles
            foreach (StaticTile tile in tiles)
            {
                itemData = TileData.ItemTable[tile.ID & TileData.MaxItemValue];
                flags    = itemData.Flags;

                #region SA
                if (m != null && m.Flying && (Insensitive.Equals(itemData.Name, "hover over") || (flags & TileFlag.HoverOver) != 0))
                {
                    newZ = tile.Z;
                    return(true);
                }

                // Stygian Dragon
                if (m != null && m.Body == 826 && map != null && map.MapID == 5)
                {
                    if (x >= 307 && x <= 354 && y >= 126 && y <= 192)
                    {
                        if (tile.Z > newZ)
                        {
                            newZ = tile.Z;
                        }

                        moveIsOk = true;
                    }
                    else if (x >= 42 && x <= 89)
                    {
                        if ((y >= 333 && y <= 399) || (y >= 531 && y <= 597) || (y >= 739 && y <= 805))
                        {
                            if (tile.Z > newZ)
                            {
                                newZ = tile.Z;
                            }

                            moveIsOk = true;
                        }
                    }
                }
                #endregion

                if ((flags & ImpassableSurface) != TileFlag.Surface && (!canSwim || (flags & TileFlag.Wet) == 0))
                {
                    continue;
                }

                if (cantWalk && (flags & TileFlag.Wet) == 0)
                {
                    continue;
                }

                itemZ   = tile.Z;
                itemTop = itemZ;
                ourZ    = itemZ + itemData.CalcHeight;
                ourTop  = ourZ + PersonHeight;
                testTop = checkTop;

                if (moveIsOk)
                {
                    int cmp = Math.Abs(ourZ - p.Z) - Math.Abs(newZ - p.Z);

                    if (cmp > 0 || (cmp == 0 && ourZ > newZ))
                    {
                        continue;
                    }
                }

                if (ourTop > testTop)
                {
                    testTop = ourTop;
                }

                if (!itemData.Bridge)
                {
                    itemTop += itemData.Height;
                }

                if (stepTop < itemTop)
                {
                    continue;
                }

                int landCheck = itemZ;

                if (itemData.Height >= StepHeight)
                {
                    landCheck += StepHeight;
                }
                else
                {
                    landCheck += itemData.Height;
                }

                if (considerLand && landCheck < landCenter && landCenter > ourZ && testTop > landZ)
                {
                    continue;
                }

                if (!IsOk(m, ignoreDoors, ignoreSpellFields, ourZ, testTop, tiles, items))
                {
                    continue;
                }

                newZ     = ourZ;
                moveIsOk = true;
            }
            #endregion

            #region Items
            foreach (Item item in items)
            {
                itemData = item.ItemData;
                flags    = itemData.Flags;

                #region SA
                if (m != null && m.Flying && (Insensitive.Equals(itemData.Name, "hover over") || (flags & TileFlag.HoverOver) != 0))
                {
                    newZ = item.Z;
                    return(true);
                }
                #endregion

                if (item.Movable)
                {
                    continue;
                }

                if ((flags & ImpassableSurface) != TileFlag.Surface && ((m != null && !m.CanSwim) || (flags & TileFlag.Wet) == 0))
                {
                    continue;
                }

                if (cantWalk && (flags & TileFlag.Wet) == 0)
                {
                    continue;
                }

                itemZ   = item.Z;
                itemTop = itemZ;
                ourZ    = itemZ + itemData.CalcHeight;
                ourTop  = ourZ + PersonHeight;
                testTop = checkTop;

                if (moveIsOk)
                {
                    int cmp = Math.Abs(ourZ - p.Z) - Math.Abs(newZ - p.Z);

                    if (cmp > 0 || (cmp == 0 && ourZ > newZ))
                    {
                        continue;
                    }
                }

                if (ourTop > testTop)
                {
                    testTop = ourTop;
                }

                if (!itemData.Bridge)
                {
                    itemTop += itemData.Height;
                }

                if (stepTop < itemTop)
                {
                    continue;
                }

                int landCheck = itemZ;

                if (itemData.Height >= StepHeight)
                {
                    landCheck += StepHeight;
                }
                else
                {
                    landCheck += itemData.Height;
                }

                if (considerLand && landCheck < landCenter && landCenter > ourZ && testTop > landZ)
                {
                    continue;
                }

                if (!IsOk(m, ignoreDoors, ignoreSpellFields, ourZ, testTop, tiles, items))
                {
                    continue;
                }

                newZ     = ourZ;
                moveIsOk = true;
            }
            #endregion

            if (!considerLand || landBlocks || stepTop < landZ)
            {
                return(moveIsOk);
            }

            ourZ    = landCenter;
            ourTop  = ourZ + PersonHeight;
            testTop = checkTop;

            if (ourTop > testTop)
            {
                testTop = ourTop;
            }

            bool shouldCheck = true;

            if (moveIsOk)
            {
                int cmp = Math.Abs(ourZ - p.Z) - Math.Abs(newZ - p.Z);

                if (cmp > 0 || (cmp == 0 && ourZ > newZ))
                {
                    shouldCheck = false;
                }
            }

            if (!shouldCheck || !IsOk(m, ignoreDoors, ignoreSpellFields, ourZ, testTop, tiles, items))
            {
                return(moveIsOk);
            }

            newZ     = ourZ;
            moveIsOk = true;

            return(moveIsOk);
        }
Exemple #4
0
        public static void EventSink_Speech(SpeechEventArgs e)
        {
            if (e.Blocked || e.Handled)
            {
                return;
            }

            Player pl = Player.Find(e.Mobile);

            if (pl == null)
            {
                for (int i = 0; i < Ethics.Length; ++i)
                {
                    Ethic ethic = Ethics[i];

                    if (!ethic.IsEligible(e.Mobile))
                    {
                        continue;
                    }

                    if (!Insensitive.Equals(ethic.Definition.JoinPhrase.String, e.Speech))
                    {
                        continue;
                    }

                    bool isNearAnkh = false;

                    foreach (Item item in e.Mobile.GetItemsInRange(2))
                    {
                        if (item is Items.AnkhNorth || item is Items.AnkhWest)
                        {
                            isNearAnkh = true;
                            break;
                        }
                    }

                    if (!isNearAnkh)
                    {
                        continue;
                    }

                    pl = new Player(ethic, e.Mobile);

                    pl.Attach();

                    e.Mobile.FixedEffect(0x373A, 10, 30);
                    e.Mobile.PlaySound(0x209);

                    e.Handled = true;
                    break;
                }
            }
            else
            {
                if (e.Mobile is PlayerMobile && (e.Mobile as PlayerMobile).DuelContext != null)
                {
                    return;
                }

                Ethic ethic = pl.Ethic;

                for (int i = 0; i < ethic.Definition.Powers.Length; ++i)
                {
                    Power power = ethic.Definition.Powers[i];

                    if (!Insensitive.Equals(power.Definition.Phrase.String, e.Speech))
                    {
                        continue;
                    }

                    if (!power.CheckInvoke(pl))
                    {
                        continue;
                    }

                    power.BeginInvoke(pl);
                    e.Handled = true;

                    break;
                }
            }
        }
Exemple #5
0
 private static bool CIEqual(string l, string r)
 {
     return(Insensitive.Equals(l, r));
 }
Exemple #6
0
 public static int InsensitiveCompare(string first, string second)
 {
     return(Insensitive.Compare(first, second));
 }
Exemple #7
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.Spawner >= 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.Spawner))
                {
                    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;
                            }

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

                    return((ISpawnable)built);
                }
            }

            return(null);
        }
        public void Acquire(TypeBuilder typeBuilder, ILGenerator il, string fieldName)
        {
            if (m_Value is string)
            {
                string toParse = (string)m_Value;

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

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

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

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

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

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

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

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

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

                            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, m_Field);
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException(
                                  string.Format(
                                      "Unable to convert string \"{0}\" into type '{1}'.",
                                      m_Value,
                                      m_Type));
                    }
                }
            }
        }
Exemple #9
0
 private static int FindSkill(string name, bool ignoreCase = true)
 {
     return
         (_SkillNames.IndexOf(
              _SkillNames.FirstOrDefault(s => ignoreCase ? Insensitive.Equals(s, name) : String.Equals(s, name))));
 }
Exemple #10
0
        public bool Add(Mobile m, Item item, RuneCodexCategory cat, bool message)
        {
            if (m == null || m.Deleted || item == null || item.Deleted || !item.IsAccessibleTo(m))
            {
                return(false);
            }

            if (item is RecallRune)
            {
                return(AddRune(m, (RecallRune)item, cat, message));
            }

            if (item is Runebook)
            {
                return(AddRunebook(m, (Runebook)item, cat, message));
            }

            #region Master Runebook Support
            //Using Reflection for shards that don't have it installed.
            Type t = item.GetType();

            if (Insensitive.Equals(t.Name, "MasterRunebook"))
            {
                var pi = t.GetProperty("Books");

                if (pi != null && pi.CanRead)
                {
                    var obj = pi.GetValue(item, null);

                    if (obj is ICollection)
                    {
                        var ex = new Queue <Runebook>(((ICollection)obj).OfType <Runebook>().Where(r => r.Entries.Count > 0));

                        if (ex.Count == 0)
                        {
                            if (message)
                            {
                                m.SendMessage("That master rune book is empty.");
                            }

                            return(false);
                        }

                        if (Categories.Count + ex.Count > Categories.Capacity)
                        {
                            if (message)
                            {
                                m.SendMessage("That master rune book won't fit in this rune codex.");
                            }

                            return(false);
                        }

                        int extracted = 0;

                        while (ex.Count > 0)
                        {
                            var b = ex.Dequeue();

                            if (AddRunebook(m, b, cat, message))
                            {
                                ++extracted;
                            }
                        }

                        if (extracted > 0)
                        {
                            if (message)
                            {
                                m.SendMessage(
                                    "You extract {0:#,0} book{1} from the master rune book and add them to the codex.",
                                    extracted,
                                    extracted != 1 ? "s" : String.Empty);
                            }

                            return(true);
                        }

                        if (message)
                        {
                            m.SendMessage("There was nothing in the master rune book to extract.");
                        }
                    }
                }

                return(false);
            }
            #endregion Master Runebook Support

            if (AddCharges(m, item, message))
            {
                return(item.Deleted);
            }

            if (message)
            {
                m.SendMessage("Drop a rune book or recall rune on the codex to add them.");
            }

            return(false);
        }
Exemple #11
0
		public bool Equals(string other)
		{
			return Insensitive.Equals(FullName, other);
		}
Exemple #12
0
        public static ObjectConditional ParseDirect(Mobile from, string[] args, int offset, int size)
        {
            if (args == null || size == 0)
            {
                return(ObjectConditional.Empty);
            }

            int index = 0;

            Type objectType = Assembler.FindTypeByName(args[offset + index], true);

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

            ++index;

            List <ICondition[]> conditions = new List <ICondition[]>();
            List <ICondition>   current    = new List <ICondition>
            {
                TypeCondition.Default
            };

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

                bool inverse = false;

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

                    if (index >= size)
                    {
                        throw new Exception("Improperly formatted object conditional.");
                    }
                }
                else if (Insensitive.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);

                ICondition condition = null;

                switch (oper)
                {
                    #region Equality
                case "=":
                case "==":
                case "is":
                    condition = new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val);
                    break;

                case "!=":
                    condition = new ComparisonCondition(prop, inverse, ComparisonOperator.NotEqual, val);
                    break;
                    #endregion

                    #region Relational
                case ">":
                    condition = new ComparisonCondition(prop, inverse, ComparisonOperator.Greater, val);
                    break;

                case "<":
                    condition = new ComparisonCondition(prop, inverse, ComparisonOperator.Lesser, val);
                    break;

                case ">=":
                    condition = new ComparisonCondition(prop, inverse, ComparisonOperator.GreaterEqual, val);
                    break;

                case "<=":
                    condition = new ComparisonCondition(prop, inverse, ComparisonOperator.LesserEqual, val);
                    break;
                    #endregion

                    #region Strings
                case "==~":
                case "~==":
                case "=~":
                case "~=":
                case "is~":
                case "~is":
                    condition = new StringCondition(prop, inverse, StringOperator.Equal, val, true);
                    break;

                case "!=~":
                case "~!=":
                    condition = new StringCondition(prop, inverse, StringOperator.NotEqual, val, true);
                    break;

                case "starts":
                    condition = new StringCondition(prop, inverse, StringOperator.StartsWith, val, false);
                    break;

                case "starts~":
                case "~starts":
                    condition = new StringCondition(prop, inverse, StringOperator.StartsWith, val, true);
                    break;

                case "ends":
                    condition = new StringCondition(prop, inverse, StringOperator.EndsWith, val, false);
                    break;

                case "ends~":
                case "~ends":
                    condition = new StringCondition(prop, inverse, StringOperator.EndsWith, val, true);
                    break;

                case "contains":
                    condition = new StringCondition(prop, inverse, StringOperator.Contains, val, false);
                    break;

                case "contains~":
                case "~contains":
                    condition = new StringCondition(prop, inverse, StringOperator.Contains, val, true);
                    break;
                    #endregion
                }

                if (condition == null)
                {
                    throw new InvalidOperationException(string.Format("Unrecognized operator (\"{0}\").", oper));
                }

                current.Add(condition);
            }

            conditions.Add(current.ToArray());

            return(new ObjectConditional(objectType, conditions.ToArray()));
        }
Exemple #13
0
 public virtual bool Equals(string other)
 {
     return(Insensitive.Equals(FullName, other));
 }
Exemple #14
0
        public static void EventSink_Speech(SpeechEventArgs e)
        {
            if (e.Blocked || e.Handled)
            {
                return;
            }

            Player pl = Player.Find(e.Mobile);

            if (pl == null)
            {
                for (int i = 0; i < Ethics.Length; ++i)
                {
                    Ethic ethic = Ethics[i];

                    if (!ethic.IsEligible(e.Mobile))
                    {
                        continue;
                    }

                    if (!Insensitive.Equals(ethic.Definition.JoinPhrase.String, e.Speech))
                    {
                        continue;
                    }

                    bool isNearAnkh = false;

                    foreach (Item item in e.Mobile.GetItemsInRange(2))
                    {
                        if (item is Items.AnkhNorth || item is Items.AnkhWest)
                        {
                            isNearAnkh = true;
                            break;
                        }
                    }

                    if (isNearAnkh)
                    {
                        pl = new Player(ethic, e.Mobile);

                        pl.Attach();

                        if (ethic is EvilEthic)
                        {
                            e.Mobile.FixedParticles(0x375A, 1, 17, 9919, 33, 7, EffectLayer.Waist);
                            e.Mobile.FixedParticles(0x3728, 1, 13, 9502, 33, 7, (EffectLayer)255);
                            e.Mobile.PlaySound(0x457);
                        }
                        else
                        {
                            e.Mobile.FixedEffect(0x373A, 10, 30);
                            e.Mobile.PlaySound(0x209);
                        }

                        e.Handled = true;
                        break;
                    }
                }
            }
            else
            {
                Ethic ethic = pl.Ethic;

                for (int i = 0; i < ethic.Definition.Powers.Length; ++i)
                {
                    Power power = ethic.Definition.Powers[i];

                    if (!Insensitive.Equals(power.Definition.Phrase.String, e.Speech))
                    {
                        continue;
                    }

                    if (!power.CheckInvoke(pl))
                    {
                        continue;
                    }

                    power.BeginInvoke(pl);
                    e.Handled = true;

                    break;
                }
            }
        }
Exemple #15
0
        public override void OnSpeech(SpeechEventArgs e)
        {
            base.OnSpeech(e);

            Mobile from = e.Mobile;

            if (!e.Handled && InRange(from, ListenRange) && from.Alive)
            {
                if (e.HasKeyword(0xE6) && (Insensitive.Equals(e.Speech, "orders") || WasNamed(e.Speech)))                         // *orders*
                {
                    if (m_Town == null || !m_Town.IsSheriff(from))
                    {
                        this.Say(1042189);                           // I don't work for you!
                    }
                    else if (Town.FromRegion(this.Region) == m_Town)
                    {
                        this.Say(1042180);                           // Your orders, sire?
                        m_OrdersEnd = DateTime.Now + TimeSpan.FromSeconds(10.0);
                    }
                }
                else if (DateTime.Now < m_OrdersEnd)
                {
                    if (m_Town != null && m_Town.IsSheriff(from) && Town.FromRegion(this.Region) == m_Town)
                    {
                        m_OrdersEnd = DateTime.Now + TimeSpan.FromSeconds(10.0);

                        bool         understood = true;
                        ReactionType newType    = 0;

                        if (Insensitive.Contains(e.Speech, "attack"))
                        {
                            newType = ReactionType.Attack;
                        }
                        else if (Insensitive.Contains(e.Speech, "warn"))
                        {
                            newType = ReactionType.Warn;
                        }
                        else if (Insensitive.Contains(e.Speech, "ignore"))
                        {
                            newType = ReactionType.Ignore;
                        }
                        else
                        {
                            understood = false;
                        }

                        if (understood)
                        {
                            understood = false;

                            if (Insensitive.Contains(e.Speech, "civil"))
                            {
                                ChangeReaction(null, newType);
                                understood = true;
                            }

                            FactionCollection factions = Faction.Factions;

                            for (int i = 0; i < factions.Count; ++i)
                            {
                                Faction faction = factions[i];

                                if (faction != m_Faction && Insensitive.Contains(e.Speech, faction.Definition.Keyword))
                                {
                                    ChangeReaction(faction, newType);
                                    understood = true;
                                }
                            }
                        }
                        else if (Insensitive.Contains(e.Speech, "patrol"))
                        {
                            Home              = Location;
                            RangeHome         = 6;
                            Combatant         = null;
                            m_Orders.Movement = MovementType.Patrol;
                            Say(1005146);                               // This spot looks like it needs protection!  I shall guard it with my life.
                            understood = true;
                        }
                        else if (Insensitive.Contains(e.Speech, "follow"))
                        {
                            Home              = Location;
                            RangeHome         = 6;
                            Combatant         = null;
                            m_Orders.Follow   = from;
                            m_Orders.Movement = MovementType.Follow;
                            Say(1005144);                               // Yes, Sire.
                            understood = true;
                        }

                        if (!understood)
                        {
                            Say(1042183);                               // I'm sorry, I don't understand your orders...
                        }
                    }
                }
            }
        }
Exemple #16
0
        public static int BuildObjects(Mobile from, Type type, Point3D start, Point3D end, string[] args, string[,] props, List <Container> packs, bool outline, bool mapAvg)
        {
            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 || 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 (!IsConstructable(ctor, from.AccessLevel))
                {
                    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, outline, mapAvg);

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

            return(0);
        }
        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 (Insensitive.Equals(cur, "not") || cur == "!")
                {
                    inverse = true;
                    ++index;

                    if (index >= size)
                    {
                        throw new Exception("Improperly formatted object conditional.");
                    }
                }
                else if (Insensitive.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()));
        }
    }
Exemple #18
0
        public static void Invoke(Mobile from, Point3D start, Point3D end, string[] args, List <Container> packs, bool outline, bool mapAvg)
        {
            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 (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];
                        }

                        FixSetString(ref args, i);
                    }

                    break;
                }
            }

            Type type = ScriptCompiler.FindTypeByName(name);

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

            DateTime time = DateTime.Now;

            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.Now - time).TotalSeconds);
            }
            else
            {
                SendUsage(type, from);
            }
        }
Exemple #19
0
 public static bool InsensitiveStartsWith(string first, string second)
 {
     return(Insensitive.StartsWith(first, second));
 }
Exemple #20
0
        private static void Go_OnCommand(CommandEventArgs e)
        {
            Mobile from = e.Mobile;

            if (e.Length == 0)
            {
                GoGump.DisplayTo(from);
                return;
            }

            if (e.Length == 1)
            {
                try
                {
                    int ser = e.GetInt32(0);

                    IEntity ent = World.FindEntity(ser);

                    if (ent is Item)
                    {
                        Item item = (Item)ent;

                        Map     map = item.Map;
                        Point3D loc = item.GetWorldLocation();

                        Mobile owner = item.RootParent as Mobile;

                        if (owner != null && (owner.Map != null && owner.Map != Map.Internal) && !BaseCommand.IsAccessible(from, owner) /* !from.CanSee( owner )*/)
                        {
                            from.SendMessage("You can not go to what you can not see.");
                            return;
                        }
                        else if (owner != null && (owner.Map == null || owner.Map == Map.Internal) && owner.Hidden && owner.AccessLevel >= from.AccessLevel)
                        {
                            from.SendMessage("You can not go to what you can not see.");
                            return;
                        }
                        else if (!FixMap(ref map, ref loc, item))
                        {
                            from.SendMessage("That is an internal item and you cannot go to it.");
                            return;
                        }

                        from.MoveToWorld(loc, map);

                        return;
                    }
                    else if (ent is Mobile)
                    {
                        Mobile m = (Mobile)ent;

                        Map     map = m.Map;
                        Point3D loc = m.Location;

                        Mobile owner = m;

                        if (owner != null && (owner.Map != null && owner.Map != Map.Internal) && !BaseCommand.IsAccessible(from, owner) /* !from.CanSee( owner )*/)
                        {
                            from.SendMessage("You can not go to what you can not see.");
                            return;
                        }
                        else if (owner != null && (owner.Map == null || owner.Map == Map.Internal) && owner.Hidden && owner.AccessLevel >= from.AccessLevel)
                        {
                            from.SendMessage("You can not go to what you can not see.");
                            return;
                        }
                        else if (!FixMap(ref map, ref loc, m))
                        {
                            from.SendMessage("That is an internal mobile and you cannot go to it.");
                            return;
                        }

                        from.MoveToWorld(loc, map);

                        return;
                    }
                    else
                    {
                        string name = e.GetString(0);
                        Map    map;

                        for (int i = 0; i < Map.AllMaps.Count; ++i)
                        {
                            map = Map.AllMaps[i];

                            if (map.MapIndex == 0x7F || map.MapIndex == 0xFF)
                            {
                                continue;
                            }

                            if (Insensitive.Equals(name, map.Name))
                            {
                                from.Map = map;
                                return;
                            }
                        }

                        Dictionary <string, Region> list = from.Map.Regions;

                        foreach (KeyValuePair <string, Region> kvp in list)
                        {
                            Region r = kvp.Value;

                            if (Insensitive.Equals(r.Name, name))
                            {
                                from.Location = new Point3D(r.GoLocation);
                                return;
                            }
                        }

                        for (int i = 0; i < Map.AllMaps.Count; ++i)
                        {
                            Map m = Map.AllMaps[i];

                            if (m.MapIndex == 0x7F || m.MapIndex == 0xFF || from.Map == m)
                            {
                                continue;
                            }

                            foreach (Region r in m.Regions.Values)
                            {
                                if (Insensitive.Equals(r.Name, name))
                                {
                                    from.MoveToWorld(r.GoLocation, m);
                                    return;
                                }
                            }
                        }

                        if (ser != 0)
                        {
                            from.SendMessage("No object with that serial was found.");
                        }
                        else
                        {
                            from.SendMessage("No region with that name was found.");
                        }

                        return;
                    }
                }
                catch
                {
                }

                from.SendMessage("Region name not found");
            }
            else if (e.Length == 2 || e.Length == 3)
            {
                Map map = from.Map;

                if (map != null)
                {
                    try
                    {
                        /*
                         * This to avoid being teleported to (0,0) if trying to teleport
                         * to a region with spaces in its name.
                         */
                        int x = int.Parse(e.GetString(0));
                        int y = int.Parse(e.GetString(1));
                        int z = (e.Length == 3) ? int.Parse(e.GetString(2)) : map.GetAverageZ(x, y);

                        from.Location = new Point3D(x, y, z);
                    }
                    catch
                    {
                        from.SendMessage("Region name not found.");
                    }
                }
            }
            else if (e.Length == 6)
            {
                Map map = from.Map;

                if (map != null)
                {
                    Point3D p = Sextant.ReverseLookup(map, e.GetInt32(3), e.GetInt32(0), e.GetInt32(4), e.GetInt32(1), Insensitive.Equals(e.GetString(5), "E"), Insensitive.Equals(e.GetString(2), "S"));

                    if (p != Point3D.Zero)
                    {
                        from.Location = p;
                    }
                    else
                    {
                        from.SendMessage("Sextant reverse lookup failed.");
                    }
                }
            }
            else
            {
                from.SendMessage("Format: Go [name | serial | (x y [z]) | (deg min (N | S) deg min (E | W)]");
            }
        }
Exemple #21
0
        public static void OpenChatWindowRequest(NetState state, PacketReader pvSrc)
        {
            Mobile from = state.Mobile;

            if (!m_Enabled)
            {
                from.SendMessage("The chat system has been disabled.");
                return;
            }

            pvSrc.Seek(2, SeekOrigin.Begin);
            string chatName = pvSrc.ReadUnicodeStringSafe((0x40 - 2) >> 1).Trim();

            Account acct = state.Account as Account;

            string accountChatName = null;

            if (acct != null)
            {
                accountChatName = acct.GetTag("ChatName");
            }

            if (accountChatName != null)
            {
                accountChatName = accountChatName.Trim();
            }

            if (accountChatName != null && accountChatName.Length > 0)
            {
                if (chatName.Length > 0 && chatName != accountChatName)
                {
                    from.SendMessage("You cannot change chat nickname once it has been set.");
                }
            }
            else
            {
                if (chatName == null || chatName.Length == 0)
                {
                    SendCommandTo(from, ChatCommand.AskNewNickname);
                    return;
                }

                if (NameVerification.Validate(chatName, 2, 31, true, true, true, 0, NameVerification.SpaceDashPeriodQuote) && chatName.ToLower().IndexOf("system") == -1)
                {
                    // TODO: Optimize this search

                    foreach (Account checkAccount in Accounts.GetAccounts())
                    {
                        string existingName = checkAccount.GetTag("ChatName");

                        if (existingName != null)
                        {
                            existingName = existingName.Trim();

                            if (Insensitive.Equals(existingName, chatName))
                            {
                                from.SendMessage("Nickname already in use.");
                                SendCommandTo(from, ChatCommand.AskNewNickname);
                                return;
                            }
                        }
                    }

                    accountChatName = chatName;

                    if (acct != null)
                    {
                        acct.AddTag("ChatName", chatName);
                    }
                }
                else
                {
                    from.SendLocalizedMessage(501173);                       // That name is disallowed.
                    SendCommandTo(from, ChatCommand.AskNewNickname);
                    return;
                }
            }

            SendCommandTo(from, ChatCommand.OpenChatWindow, accountChatName);
            ChatUser.AddChatUser(from);
        }
Exemple #22
0
        public static object GetObjectFromString(Type t, string s)
        {
            if (t == typeof(string))
            {
                return(s);
            }

            if (t == typeof(byte) || t == typeof(sbyte) || t == typeof(short) || t == typeof(ushort) || t == typeof(int) ||
                t == typeof(uint) || t == typeof(long) || t == typeof(ulong))
            {
                if (s.StartsWith("0x"))
                {
                    if (t == typeof(ulong) || t == typeof(uint) || t == typeof(ushort) || t == typeof(byte))
                    {
                        return(Convert.ChangeType(Convert.ToUInt64(s.Substring(2), 16), t));
                    }

                    return(Convert.ChangeType(Convert.ToInt64(s.Substring(2), 16), t));
                }

                return(Convert.ChangeType(s, t));
            }

            if (t == typeof(double) || t == typeof(float))
            {
                return(Convert.ChangeType(s, t));
            }

            if (t == typeof(IAccount) || t == typeof(Account))
            {
                return(Accounts.GetAccount(s));
            }

            if (t == typeof(Color))
            {
                if (Insensitive.StartsWith(s, "0x"))
                {
                    return(Color.FromArgb(Convert.ToInt32(s.Substring(2), 16)));
                }

                if (Insensitive.StartsWith(s, "#"))
                {
                    return(Color.FromArgb(Convert.ToInt32(s.Substring(1), 16)));
                }

                int val;

                if (Int32.TryParse(s, out val))
                {
                    return(Color.FromArgb(val));
                }

                var rgb = s.Split(',');

                if (rgb.Length >= 3)
                {
                    int r, g, b;

                    if (Int32.TryParse(rgb[0], out r) && Int32.TryParse(rgb[1], out g) && Int32.TryParse(rgb[2], out b))
                    {
                        return(Color.FromArgb(r, g, b));
                    }
                }

                return(Color.FromName(s));
            }

            if (t.IsDefined(typeof(ParsableAttribute), false))
            {
                var parseMethod = t.GetMethod("Parse", new[] { typeof(string) });

                return(parseMethod.Invoke(null, new object[] { s }));
            }

            throw new Exception("bad");
        }
Exemple #23
0
        public void Claim(Mobile from, string petName)
        {
            if (Deleted || !from.CheckAlive())
            {
                return;
            }

            var claimed = false;
            var stabled = 0;

            var claimByName = (petName != null);

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

                if (pet == null || pet.Deleted)
                {
                    if (pet != null)
                    {
                        pet.IsStabled = false;
                        pet.StabledBy = null;
                    }

                    from.Stabled.RemoveAt(i--);
                    continue;
                }

                ++stabled;

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

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

                    from.Stabled.RemoveAt(i);

                    if (from is PlayerMobile)
                    {
                        ((PlayerMobile)from).AutoStabled.Remove(pet);
                    }

                    --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);
            }
        }
Exemple #24
0
        private static bool Check(
            Map map,
            Mobile m,
            List <Item> items,
            int x,
            int y,
            int startTop,
            int startZ,
            bool canSwim,
            bool cantWalk,
            out int newZ
            )
        {
            newZ = 0;

            var tiles        = map.Tiles.GetStaticTiles(x, y, true);
            var landTile     = map.Tiles.GetLandTile(x, y);
            var landData     = TileData.LandTable[landTile.ID & TileData.MaxLandValue];
            var landBlocks   = (landData.Flags & TileFlag.Impassable) != 0;
            var considerLand = !landTile.Ignored;

            if (landBlocks && canSwim && (landData.Flags & TileFlag.Wet) != 0)
            {
                landBlocks = false;
            }
            else if (cantWalk && (landData.Flags & TileFlag.Wet) == 0)
            {
                landBlocks = true;
            }

            int landZ = 0, landCenter = 0, landTop = 0;

            map.GetAverageZ(x, y, ref landZ, ref landCenter, ref landTop);

            var moveIsOk = false;

            var stepTop  = startTop + StepHeight;
            var checkTop = startZ + PersonHeight;

            var ignoreDoors = MovementImpl.AlwaysIgnoreDoors || !m.Alive || m.IsDeadBondedPet || m.Body.IsGhost ||
                              m.Body.BodyID == 987;
            var ignoreSpellFields = m is PlayerMobile && map.MapID != 0;

            int      itemZ, itemTop, ourZ, ourTop, testTop;
            ItemData itemData;
            TileFlag flags;

            foreach (var tile in tiles)
            {
                itemData = TileData.ItemTable[tile.ID & TileData.MaxItemValue];

                if (m.Flying && Insensitive.Equals(itemData.Name, "hover over"))
                {
                    newZ = tile.Z;
                    return(true);
                }

                // Stygian Dragon
                if (m.Body == 826 && map?.MapID == 5)
                {
                    if (x >= 307 && x <= 354 && y >= 126 && y <= 192)
                    {
                        if (tile.Z > newZ)
                        {
                            newZ = tile.Z;
                        }

                        moveIsOk = true;
                    }
                    else if (x >= 42 && x <= 89)
                    {
                        if (y >= 333 && y <= 399 || y >= 531 && y <= 597 || y >= 739 && y <= 805)
                        {
                            if (tile.Z > newZ)
                            {
                                newZ = tile.Z;
                            }

                            moveIsOk = true;
                        }
                    }
                }

                flags = itemData.Flags;

                if ((flags & ImpassableSurface) != TileFlag.Surface && (!canSwim || (flags & TileFlag.Wet) == 0))
                {
                    continue;
                }

                if (cantWalk && (flags & TileFlag.Wet) == 0)
                {
                    continue;
                }

                itemZ   = tile.Z;
                itemTop = itemZ;
                ourZ    = itemZ + itemData.CalcHeight;
                ourTop  = ourZ + PersonHeight;
                testTop = checkTop;

                if (moveIsOk)
                {
                    var cmp = Math.Abs(ourZ - m.Z) - Math.Abs(newZ - m.Z);

                    if (cmp > 0 || cmp == 0 && ourZ > newZ)
                    {
                        continue;
                    }
                }

                if (ourTop > testTop)
                {
                    testTop = ourTop;
                }

                if (!itemData.Bridge)
                {
                    itemTop += itemData.Height;
                }

                if (stepTop < itemTop)
                {
                    continue;
                }

                var landCheck = itemZ;

                if (itemData.Height >= StepHeight)
                {
                    landCheck += StepHeight;
                }
                else
                {
                    landCheck += itemData.Height;
                }

                if (considerLand && landCheck < landCenter && landCenter > ourZ && testTop > landZ)
                {
                    continue;
                }

                if (!IsOk(ignoreDoors, ignoreSpellFields, ourZ, testTop, tiles, items))
                {
                    continue;
                }

                newZ     = ourZ;
                moveIsOk = true;
            }

            foreach (var item in items)
            {
                itemData = item.ItemData;
                flags    = itemData.Flags;

                if (m.Flying && Insensitive.Equals(itemData.Name, "hover over"))
                {
                    newZ = item.Z;
                    return(true);
                }

                if (item.Movable)
                {
                    continue;
                }

                if ((flags & ImpassableSurface) != TileFlag.Surface && (!m.CanSwim || (flags & TileFlag.Wet) == 0))
                {
                    continue;
                }

                if (cantWalk && (flags & TileFlag.Wet) == 0)
                {
                    continue;
                }

                itemZ   = item.Z;
                itemTop = itemZ;
                ourZ    = itemZ + itemData.CalcHeight;
                ourTop  = ourZ + PersonHeight;
                testTop = checkTop;

                if (moveIsOk)
                {
                    var cmp = Math.Abs(ourZ - m.Z) - Math.Abs(newZ - m.Z);

                    if (cmp > 0 || cmp == 0 && ourZ > newZ)
                    {
                        continue;
                    }
                }

                if (ourTop > testTop)
                {
                    testTop = ourTop;
                }

                if (!itemData.Bridge)
                {
                    itemTop += itemData.Height;
                }

                if (stepTop < itemTop)
                {
                    continue;
                }

                var landCheck = itemZ;

                if (itemData.Height >= StepHeight)
                {
                    landCheck += StepHeight;
                }
                else
                {
                    landCheck += itemData.Height;
                }

                if (considerLand && landCheck < landCenter && landCenter > ourZ && testTop > landZ)
                {
                    continue;
                }

                if (!IsOk(ignoreDoors, ignoreSpellFields, ourZ, testTop, tiles, items))
                {
                    continue;
                }

                newZ     = ourZ;
                moveIsOk = true;
            }

            if (!considerLand || landBlocks || stepTop < landZ)
            {
                return(moveIsOk);
            }

            ourZ    = landCenter;
            ourTop  = ourZ + PersonHeight;
            testTop = checkTop;

            if (ourTop > testTop)
            {
                testTop = ourTop;
            }

            var shouldCheck = true;

            if (moveIsOk)
            {
                var cmp = Math.Abs(ourZ - m.Z) - Math.Abs(newZ - m.Z);

                if (cmp > 0 || cmp == 0 && ourZ > newZ)
                {
                    shouldCheck = false;
                }
            }

            if (!shouldCheck || !IsOk(ignoreDoors, ignoreSpellFields, ourZ, testTop, tiles, items))
            {
                return(moveIsOk);
            }

            newZ     = ourZ;
            moveIsOk = true;

            return(moveIsOk);
        }
Exemple #25
0
        public virtual bool WasNamed(string speech)
        {
            string name = this.Name;

            return(name != null && Insensitive.StartsWith(speech, name));
        }
        public override int SortCompare(ConquestState a, ConquestState b)
        {
            int result = 0;

            if (a.CompareNull(b, ref result))
            {
                return(result);
            }

            if (a.Completed && b.Completed)
            {
                if (a.CompletedDate.Year > b.CompletedDate.Year)
                {
                    return(-1);
                }

                if (a.CompletedDate.Year < b.CompletedDate.Year)
                {
                    return(1);
                }

                if (a.CompletedDate.Month > b.CompletedDate.Month)
                {
                    return(-1);
                }

                if (a.CompletedDate.Month < b.CompletedDate.Month)
                {
                    return(1);
                }

                if (a.CompletedDate.Day > b.CompletedDate.Day)
                {
                    return(-1);
                }

                if (a.CompletedDate.Day < b.CompletedDate.Day)
                {
                    return(1);
                }

                return(Insensitive.Compare(a.Name, b.Name));
            }

            if (a.Completed)
            {
                return(-1);
            }

            if (b.Completed)
            {
                return(1);
            }

            double aT = a.Tier / (double)a.TierMax;
            double bT = b.Tier / (double)b.TierMax;

            if (aT > bT)
            {
                return(-1);
            }

            if (aT < bT)
            {
                return(1);
            }

            double aP = a.Progress / (double)a.ProgressMax;
            double bP = b.Progress / (double)b.ProgressMax;

            if (aP > bP)
            {
                return(-1);
            }

            if (aP < bP)
            {
                return(1);
            }

            return(Insensitive.Compare(a.Name, b.Name));
        }
        private static void ProcessCommand(string input)
        {
            input = input.Trim();

            if (_Pages != null)
            {
                HandlePaging(input);
                return;
            }

            if (input.StartsWith("pages", StringComparison.OrdinalIgnoreCase))
            {
                HandlePaging(input.Substring(5).Trim());
                return;
            }

            if (input.StartsWith("bc", StringComparison.OrdinalIgnoreCase))
            {
                string sub = input.Substring(2).Trim();

                BroadcastMessage(AccessLevel.Player, 0x35, string.Format("[Admin] {0}", sub));

                Console.WriteLine("[World]: {0}", sub);
                return;
            }

            if (input.StartsWith("sc", StringComparison.OrdinalIgnoreCase))
            {
                string sub = input.Substring(2).Trim();

                BroadcastMessage(AccessLevel.Counselor, 0x32, string.Format("[Admin] {0}", sub));

                Console.WriteLine("[Staff]: {0}", sub);
                return;
            }

            if (input.StartsWith("ban", StringComparison.OrdinalIgnoreCase))
            {
                string sub = input.Substring(3).Trim();

                System.Collections.Generic.List <NetState> states = NetState.Instances;

                if (states.Count == 0)
                {
                    Console.WriteLine("There are no players online.");
                    return;
                }

                NetState ns = states.Find(o => o.Account != null && o.Mobile != null && Insensitive.StartsWith(sub, o.Mobile.RawName));

                if (ns != null)
                {
                    Console.WriteLine("[Ban]: {0}: Mobile: '{1}' Account: '{2}'", ns, ns.Mobile.RawName, ns.Account.Username);

                    ns.Dispose();
                }

                return;
            }

            if (input.StartsWith("kick", StringComparison.OrdinalIgnoreCase))
            {
                string sub = input.Substring(4).Trim();

                System.Collections.Generic.List <NetState> states = NetState.Instances;

                if (states.Count == 0)
                {
                    Console.WriteLine("There are no players online.");
                    return;
                }

                NetState ns = states.Find(o => o.Account != null && o.Mobile != null && Insensitive.StartsWith(sub, o.Mobile.RawName));

                if (ns != null)
                {
                    Console.WriteLine("[Kick]: {0}: Mobile: '{1}' Account: '{2}'", ns, ns.Mobile.RawName, ns.Account.Username);

                    ns.Dispose();
                }

                return;
            }

            switch (input.Trim())
            {
            case "crash":
            {
                Timer.DelayCall(() => { throw new Exception("Forced Crash"); });
            }
            break;

            case "shutdown":
            {
                AutoSave.Save();
                Core.Kill(false);
            }
            break;

            case "shutdown nosave":
            {
                Core.Kill(false);
            }
            break;

            case "restart":
            {
                AutoSave.Save();
                Core.Kill(true);
            }
            break;

            case "save recompile":
            {
                var path = AutoRestart.RecompilePath;

                if (!File.Exists(path))
                {
                    Console.WriteLine("Unable to Re-Compile due to missing file: {0}", AutoRestart.RecompilePath);
                }
                else
                {
                    AutoSave.Save();

                    System.Diagnostics.Process.Start(path);
                    Core.Kill();
                }
            }
            break;

            case "nosave recompile":
            {
                var path = AutoRestart.RecompilePath;

                if (!File.Exists(path))
                {
                    Console.WriteLine("Unable to Re-Compile due to missing file: {0}", AutoRestart.RecompilePath);
                }
                else
                {
                    System.Diagnostics.Process.Start(path);
                    Core.Kill();
                }
            }
            break;

            case "restart nosave":
            {
                Core.Kill(true);
            }
            break;

            case "online":
            {
                System.Collections.Generic.List <NetState> states = NetState.Instances;

                if (states.Count == 0)
                {
                    Console.WriteLine("There are no users online at this time.");
                }

                foreach (NetState t in states)
                {
                    Account a = t.Account as Account;

                    if (a == null)
                    {
                        continue;
                    }

                    Mobile m = t.Mobile;

                    if (m != null)
                    {
                        Console.WriteLine("- Account: {0}, Name: {1}, IP: {2}", a.Username, m.Name, t);
                    }
                }
            }
            break;

            case "save":
                AutoSave.Save();
                break;

            case "hear":     // Credit to Zippy for the HearAll script!
            {
                _HearConsole = !_HearConsole;

                Console.WriteLine("{0} sending speech to the console.", _HearConsole ? "Now" : "No longer");
            }
            break;

            default:
                DisplayHelp();
                break;
            }
        }
Exemple #28
0
        public static bool TryConvert(string data, DataType flag, out object val)
        {
            val = null;

            if (flag == DataType.Null)
            {
                return(false);
            }

            try
            {
                var numStyle = Insensitive.StartsWith(data.Trim(), "0x") ? NumberStyles.HexNumber : NumberStyles.Any;

                if (numStyle == NumberStyles.HexNumber)
                {
                    data = data.Substring(data.IndexOf("0x", StringComparison.OrdinalIgnoreCase) + 2);
                }

                switch (flag)
                {
                case DataType.Bool:
                    val = Boolean.Parse(data);
                    return(true);

                case DataType.Char:
                    val = Char.Parse(data);
                    return(true);

                case DataType.Byte:
                    val = Byte.Parse(data, numStyle);
                    return(true);

                case DataType.SByte:
                    val = SByte.Parse(data, numStyle);
                    return(true);

                case DataType.Short:
                    val = Int16.Parse(data, numStyle);
                    return(true);

                case DataType.UShort:
                    val = UInt16.Parse(data, numStyle);
                    return(true);

                case DataType.Int:
                    val = Int32.Parse(data, numStyle);
                    return(true);

                case DataType.UInt:
                    val = UInt32.Parse(data, numStyle);
                    return(true);

                case DataType.Long:
                    val = Int64.Parse(data, numStyle);
                    return(true);

                case DataType.ULong:
                    val = UInt64.Parse(data, numStyle);
                    return(true);

                case DataType.Float:
                    val = Single.Parse(data, numStyle);
                    return(true);

                case DataType.Decimal:
                    val = Decimal.Parse(data, numStyle);
                    return(true);

                case DataType.Double:
                    val = Double.Parse(data, numStyle);
                    return(true);

                case DataType.String:
                    val = data;
                    return(true);

                case DataType.DateTime:
                    val = DateTime.Parse(data, CultureInfo.CurrentCulture, DateTimeStyles.AllowWhiteSpaces);
                    return(true);

                case DataType.TimeSpan:
                    val = TimeSpan.Parse(data);
                    return(true);

                default:
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
Exemple #29
0
        public override void OnSpeech(SpeechEventArgs e)
        {
            base.OnSpeech(e);

            Mobile from = e.Mobile;
            Item   sign = m_House.Sign;

            bool isOwner   = m_House.IsOwner(from);
            bool isCoOwner = isOwner || m_House.IsCoOwner(from);
            bool isFriend  = isCoOwner || m_House.IsFriend(from);

            if (!isFriend)
            {
                return;
            }

            if (!from.Alive)
            {
                return;
            }

            if (Core.ML && Insensitive.Equals(e.Speech, "I wish to resize my house"))
            {
                if (from.Map != sign.Map || !from.InRange(sign, 0))
                {
                    from.SendLocalizedMessage(500295); // you are too far away to do that.
                }
                else if (DateTime.UtcNow <= m_House.BuiltOn.AddHours(1))
                {
                    from.SendLocalizedMessage(1080178); // You must wait one hour between each house demolition.
                }
                else if (isOwner)
                {
                    from.CloseGump(typeof(ConfirmHouseResize));
                    from.CloseGump(typeof(HouseGumpAOS));
                    from.SendGump(new ConfirmHouseResize(from, m_House));
                }
                else
                {
                    from.SendLocalizedMessage(501320); // Only the house owner may do
                }
            }

            if (!m_House.IsInside(from) || !m_House.IsActive)
            {
                return;
            }

            else if (e.HasKeyword(0x33)) // remove thyself
            {
                if (isFriend)
                {
                    from.SendLocalizedMessage(501326); // Target the individual to eject from this house.
                    from.Target = new HouseKickTarget(m_House);
                }
                else
                {
                    from.SendLocalizedMessage(502094); // You must be in your house to do this.
                }
            }
            else if (e.HasKeyword(0x34)) // I ban thee
            {
                if (!isFriend)
                {
                    from.SendLocalizedMessage(502094); // You must be in your house to do this.
                }
                else if (!m_House.Public && m_House.IsAosRules)
                {
                    from.SendLocalizedMessage(1062521); // You cannot ban someone from a private house.  Revoke their access instead.
                }
                else
                {
                    from.SendLocalizedMessage(501325); // Target the individual to ban from this house.
                    from.Target = new HouseBanTarget(true, m_House);
                }
            }
            else if (e.HasKeyword(0x23)) // I wish to lock this down
            {
                if (isFriend)
                {
                    from.SendLocalizedMessage(502097); // Lock what down?
                    from.Target = new LockdownTarget(false, m_House);
                }
                else
                {
                    from.SendLocalizedMessage(502094); // You must be in your house to do this.
                }
            }
            else if (e.HasKeyword(0x24)) // I wish to release this
            {
                if (isFriend)
                {
                    from.SendLocalizedMessage(502100); // Choose the item you wish to release
                    from.Target = new LockdownTarget(true, m_House);
                }
                else
                {
                    from.SendLocalizedMessage(502094); // You must be in your house to do this.
                }
            }
            else if (e.HasKeyword(0x25)) // I wish to secure this
            {
                if (isOwner)
                {
                    from.SendLocalizedMessage(502103); // Choose the item you wish to secure
                    from.Target = new SecureTarget(false, m_House);
                }
                else
                {
                    from.SendLocalizedMessage(502094); // You must be in your house to do this.
                }
            }
            else if (e.HasKeyword(0x26)) // I wish to unsecure this
            {
                if (isOwner)
                {
                    from.SendLocalizedMessage(502106); // Choose the item you wish to unsecure
                    from.Target = new SecureTarget(true, m_House);
                }
                else
                {
                    from.SendLocalizedMessage(502094); // You must be in your house to do this.
                }
            }
            else if (e.HasKeyword(0x27)) // I wish to place a strongbox
            {
                if (isOwner)
                {
                    from.SendLocalizedMessage(502109); // Owners do not get a strongbox of their own.
                }
                else if (isCoOwner)
                {
                    m_House.AddStrongBox(from);
                }
                else if (isFriend)
                {
                    from.SendLocalizedMessage(1010587); // You are not a co-owner of this house.
                }
                else
                {
                    from.SendLocalizedMessage(502094); // You must be in your house to do this.
                }
            }
            else if (e.HasKeyword(0x28)) // trash barrel
            {
                if (isCoOwner)
                {
                    m_House.AddTrashBarrel(from);
                }
                else if (isFriend)
                {
                    from.SendLocalizedMessage(1010587); // You are not a co-owner of this house.
                }
                else
                {
                    from.SendLocalizedMessage(502094); // You must be in your house to do this.
                }
            }
        }
Exemple #30
0
 public virtual int CompareTo(CryptoHashCode code)
 {
     return(!ReferenceEquals(code, null) ? Insensitive.Compare(Value, code.Value) : -1);
 }