Ejemplo n.º 1
0
        public static string ToWrappedString <T>(this IEnumerable <T> source, string sep, int wrap)
        {
            source = source.Ensure();

            if (sep == null)
            {
                sep = String.Empty;
            }

            if (wrap <= 0)
            {
                return(String.Join(sep, source));
            }

            var strings = ListPool <string> .AcquireObject();

            var values = ObjectPool <StringBuilder> .AcquireObject();

            try
            {
                strings.AddRange(source.Select(o => Convert.ToString(o)));

                if (strings.Count == 0)
                {
                    return(String.Empty);
                }

                var capacity = strings.Sum(s => s.Length + sep.Length) + (strings.Count / wrap);

                values.EnsureCapacity(capacity);

                var i = 0;

                foreach (var t in strings)
                {
                    values.Append(t);

                    if (++i < strings.Count)
                    {
                        values.Append(sep);

                        if (i % wrap == 0)
                        {
                            values.Append('\n');
                        }
                    }
                }

                return(values.ToString());
            }
            catch
            {
                return(String.Empty);
            }
            finally
            {
                ObjectPool.Free(ref strings);
                ObjectPool.Free(ref values);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Create with pre-defined OPL
        /// </summary>
        /// <param name="opl">ObjectPropertyList object to wrap and extend</param>
        public ExtendedOPL(ObjectPropertyList opl)
        {
            _Buffer = ListPool <string> .AcquireObject();

            Opl       = opl;
            LineBreak = ClilocBreak;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Create with pre-defined OPL
        /// </summary>
        /// <param name="opl">ObjectPropertyList object to wrap and extend</param>
        /// <param name="capacity">Capacity of the extension</param>
        public ExtendedOPL(ObjectPropertyList opl, int capacity)
        {
            _Buffer = ListPool <string> .AcquireObject();

            _Buffer.Capacity = capacity;

            Opl       = opl;
            LineBreak = ClilocBreak;
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Create with pre-defined OPL
        /// </summary>
        /// <param name="opl">ObjectPropertyList object to wrap and extend</param>
        /// <param name="list">Pre-defined list to append to the specified OPL</param>
        public ExtendedOPL(ObjectPropertyList opl, IEnumerable <string> list)
        {
            _Buffer = ListPool <string> .AcquireObject();

            _Buffer.AddRange(list);

            Opl       = opl;
            LineBreak = ClilocBreak;
        }
Ejemplo n.º 5
0
        public void Flatten()
        {
            var list = ListPool <Block3D> .AcquireObject();

            list.AddRange(this);

            Clear();

            AddRange(list.Flatten());

            ObjectPool.Free(ref list);
        }
Ejemplo n.º 6
0
        protected override void OnInvoke(BaseAspect aspect)
        {
            if (aspect == null || aspect.Deleted)
            {
                return;
            }

            if (aspect.PlayAttackAnimation())
            {
                aspect.PlayAttackSound();
            }

            var targets = ListPool <Mobile> .AcquireObject();

            targets.AddRange(AcquireTargets <Mobile>(aspect));

            if (targets.Count > 0)
            {
                using (var fx = new EffectInfo(aspect, aspect.Map, 14120, 0, 10, 10, EffectRender.Lighten))
                {
                    fx.SoundID = 510;

                    Mobile t;

                    var i = targets.Count;

                    foreach (var p in targets.Select(o => o.Location))
                    {
                        t = targets[--i];

                        fx.SetSource(t);

                        fx.Send();
                        t.Location = p;
                        fx.Send();
                    }

                    var l = aspect.Location;

                    t = targets.GetRandom();

                    fx.SetSource(aspect);

                    fx.Send();
                    aspect.Location = t.Location;
                    fx.Send();

                    t.Location = l;
                }
            }

            ObjectPool.Free(targets);
        }
Ejemplo n.º 7
0
        public static List <T> Acquire(IEnumerable <T> e = null)
        {
            var o = ListPool <T> .AcquireObject();

            if (e != null)
            {
                o.AddRange(e);
            }
            else if (o.Capacity < 0x40)
            {
                o.Capacity = 0x40;
            }

            return(o);
        }
        public static void Register(IAspectSpawn spawn)
        {
            if (spawn == null || spawn.Aspect == null)
            {
                return;
            }

            List <IAspectSpawn> list;

            if (!Spawn.TryGetValue(spawn.Aspect, out list) || list == null)
            {
                Spawn[spawn.Aspect] = list = ListPool <IAspectSpawn> .AcquireObject();
            }

            list.AddOrReplace(spawn);
        }
Ejemplo n.º 9
0
        public virtual void InsertColumn(int x)
        {
            x = Math.Max(0, x);

            var col = ListPool <T> .AcquireObject();

            col.Capacity = Height;
            col.SetAll(DefaultValue);

            if (x >= Width)
            {
                _InternalGrid.Add(col);
            }
            else
            {
                _InternalGrid.Insert(x, col);
            }

            _Size = new Size(_InternalGrid.Count, _Size.Height);
        }
Ejemplo n.º 10
0
            private void Slice()
            {
                if (Deleted || !Alive)
                {
                    StopTimer();
                    return;
                }

                if (Aspect == null || Aspect.Deleted || !Aspect.Alive || !Aspect.InRange(this, Aspect.RangePerception * 2))
                {
                    Destroy();
                    return;
                }

                if (!Aspect.InCombat())
                {
                    return;
                }

                if (_Spawn == null)
                {
                    _Spawn = ListPool <ISpawnable> .AcquireObject();
                }

                if (_Spawn.Count < 3)
                {
                    var s = new Tinker(Aspect);

                    _Spawn.Add(s);

                    s.Spawner = this;

                    Register(s);

                    var p = this.GetRandomPoint3D(1, 2, Map, true, true);

                    s.OnBeforeSpawn(p, Map);
                    s.MoveToWorld(p, Map);
                    s.OnAfterSpawn();
                }
            }
Ejemplo n.º 11
0
        public override IBuyItemInfo[] GetBuyInfo()
        {
            var info = base.GetBuyInfo();

            if (_DynamicStock.Count > 0)
            {
                var buffer = ListPool <IBuyItemInfo> .AcquireObject();

                buffer.AddRange(_DynamicStock.Values.Where(o => o.Price >= 0));

                buffer.AddRange(info);

                info = buffer.ToArray();

                ObjectPool.Free(ref buffer);
            }

            _VendorBuy = null;

            return(info);
        }
Ejemplo n.º 12
0
        protected override void CompileList(List <TreeGumpNode> list)
        {
            foreach (var n in Nodes.Keys)
            {
                list.AddOrReplace(n);
            }

            var nodes = ListPool <TreeGumpNode> .AcquireObject();

            var selected = ListPool <TreeGumpNode> .AcquireObject();

            var parents = ListPool <TreeGumpNode> .AcquireObject();

            nodes.Capacity = list.Count;

            foreach (var n in list)
            {
                foreach (var p in n.GetParents())
                {
                    nodes.AddOrReplace(p);
                }

                nodes.AddOrReplace(n);
            }

            if (SelectedNode.HasParent)
            {
                nodes.AddOrReplace(SelectedNode.Parent);
            }

            selected.AddRange(SelectedNode.GetParents());

            nodes.RemoveAll(
                c =>
            {
                parents.AddRange(c.GetParents());

                var remove = false;

                if (parents.Count > 0)
                {
                    if (parents.Count <= selected.Count && c != SelectedNode && !parents.Contains(SelectedNode) &&
                        !selected.Any(p => p == c || c.Parent == p))
                    {
                        remove = true;
                    }
                    else if (parents.Count > selected.Count && c.Parent != SelectedNode)
                    {
                        remove = true;
                    }
                }

                parents.Clear();

                return(remove);
            });

            list.Clear();
            list.AddRange(nodes);

            ObjectPool.Free(ref nodes);
            ObjectPool.Free(ref selected);
            ObjectPool.Free(ref parents);

            base.CompileList(list);
        }
Ejemplo n.º 13
0
        public Grid(GenericReader reader)
        {
            _InternalGrid = ListPool <List <T> > .AcquireObject();

            Deserialize(reader);
        }
Ejemplo n.º 14
0
        protected override void OnInvoke(BaseAspect aspect)
        {
            if (aspect == null || aspect.Deleted)
            {
                return;
            }

            var list = ListPool <EffectQueue> .AcquireObject();

            var cw = Utility.RandomBool();

            for (int a = (cw ? 0 : 360), h = 0; (cw ? a <= 360 : a >= 0); a += (cw ? 1 : -1))
            {
                var x = (int)Math.Round(aspect.X + (aspect.RangePerception * Math.Sin(Geometry.DegreesToRadians(a))));
                var y = (int)Math.Round(aspect.Y + (aspect.RangePerception * Math.Cos(Geometry.DegreesToRadians(a))));

                if (((x * 397) ^ y) == h)
                {
                    // This location was just handled, ignore it to avoid small increments
                    continue;
                }

                h = ((x * 397) ^ y);

                var start = aspect.Clone3D(0, 0, 10);
                var end   = new Point3D(x, y, aspect.Z);

                end.Z = end.GetTopZ(aspect.Map);

                var l = start.GetLine3D(end, aspect.Map, false);

                var q = new EffectQueue
                {
                    Deferred = false,
                    Handler  = e => HandleDeathRay(aspect, e)
                };

                for (var i = 0; i < l.Length; i++)
                {
                    var p       = new Block3D(l[i], 5);
                    var blocked = i + 1 >= l.Length;

                    if (!blocked)
                    {
                        var land = aspect.Map.GetLandTile(p);

                        if (p.Intersects(land.Z, land.Height))
                        {
                            var o = TileData.LandTable[land.ID];

                            if (o.Flags.AnyFlags(_BlockingFlags))
                            {
                                blocked = true;
                            }
                        }
                    }

                    if (!blocked)
                    {
                        var tiles = aspect.Map.GetStaticTiles(p);

                        var data = tiles.Where(o => p.Intersects(o.Z, o.Height)).Select(t => TileData.ItemTable[t.ID]);

                        if (data.Any(o => o.Flags.AnyFlags(_BlockingFlags)))
                        {
                            blocked = true;
                        }
                    }

                    if (!blocked)
                    {
                        var items = p.FindItemsAt(aspect.Map);

                        var data = items.Where(p.Intersects).Select(o => TileData.ItemTable[o.ItemID]);

                        if (data.Any(o => o.Flags.AnyFlags(_BlockingFlags)))
                        {
                            blocked = true;
                        }
                    }

                    var effect = blocked ? 14120 : Utility.RandomMinMax(12320, 12324);
                    var hue    = blocked ? 0 : 2075;

                    if (blocked)
                    {
                        p = p.Clone3D(0, 0, -8);
                    }

                    q.Add(
                        new EffectInfo(p, aspect.Map, effect, hue, 10, 10, EffectRender.Darken)
                    {
                        QueueIndex = i
                    });

                    if (blocked)
                    {
                        break;
                    }
                }

                if (q.Queue.Count > 0)
                {
                    list.Add(q);
                }
            }

            if (list.Count == 0)
            {
                ObjectPool.Free(list);

                return;
            }

            for (var i = 0; i < list.Count; i++)
            {
                var cur = list[i];

                if (i + 1 < list.Count)
                {
                    var next = list[i + 1];

                    cur.Callback = () =>
                    {
                        if (aspect.Deleted || !aspect.Alive)
                        {
                            list.ForEach(q => q.Dispose());

                            ObjectPool.Free(list);

                            return;
                        }

                        if (next.Queue.Count > 0)
                        {
                            SpellHelper.Turn(aspect, next.Queue.Last().Source);
                        }

                        Timer.DelayCall(TimeSpan.FromSeconds(0.05), next.Process);
                    };
                }
                else
                {
                    cur.Callback = () =>
                    {
                        list.ForEach(q => q.Dispose());

                        ObjectPool.Free(list);

                        aspect.CantWalk      = false;
                        aspect.LockDirection = false;
                    };
                }
            }

            if (list.Count == 0)
            {
                ObjectPool.Free(list);

                return;
            }

            aspect.CantWalk      = true;
            aspect.LockDirection = true;

            if (list[0].Queue.Count > 0)
            {
                SpellHelper.Turn(aspect, list[0].Queue.Last().Source);
            }

            Timer.DelayCall(TimeSpan.FromSeconds(0.1), list[0].Process);
        }
Ejemplo n.º 15
0
        public static IEnumerable <TextDefinition> EnumerateEntries(this ObjectPropertyList list)
        {
            var msgs = ListPool <TextDefinition> .AcquireObject();

            try
            {
                var data = list.UnderlyingStream.UnderlyingStream.ToArray();

                var index = 15;

                while (index + 4 < data.Length)
                {
                    var id = data[index++] << 24 | data[index++] << 16 | data[index++] << 8 | data[index++];

                    if (index + 2 > data.Length)
                    {
                        break;
                    }

                    var paramLength = data[index++] << 8 | data[index++];

                    var param = String.Empty;

                    if (paramLength > 0)
                    {
                        var terminate = index + paramLength;

                        if (terminate >= data.Length)
                        {
                            terminate = data.Length - 1;
                        }

                        while (index + 2 <= terminate + 1)
                        {
                            var peek = (short)(data[index++] | data[index++] << 8);

                            if (peek == 0)
                            {
                                break;
                            }

                            param += Encoding.Unicode.GetString(BitConverter.GetBytes(peek));
                        }
                    }

                    msgs.Add(new TextDefinition(id, param));
                }
            }
            catch
            { }

            if (!msgs.IsNullOrEmpty())
            {
                foreach (var o in msgs)
                {
                    yield return(o);
                }
            }

            ObjectPool.Free(ref msgs);
        }
Ejemplo n.º 16
0
        public static string[] DecodePropertyList(this ObjectPropertyList list, ClilocLNG lng)
        {
            if (lng == ClilocLNG.NULL)
            {
                lng = DefaultLanguage;
            }

            var msgs = ListPool <string> .AcquireObject();

            try
            {
                var data = list.UnderlyingStream.UnderlyingStream.ToArray();

                var index = 15;

                while (index + 4 < data.Length)
                {
                    var id = data[index++] << 24 | data[index++] << 16 | data[index++] << 8 | data[index++];

                    if (index + 2 > data.Length)
                    {
                        break;
                    }

                    var paramLength = data[index++] << 8 | data[index++];

                    var param = String.Empty;

                    if (paramLength > 0)
                    {
                        var terminate = index + paramLength;

                        if (terminate >= data.Length)
                        {
                            terminate = data.Length - 1;
                        }

                        while (index + 2 <= terminate + 1)
                        {
                            var peek = (short)(data[index++] | data[index++] << 8);

                            if (peek == 0)
                            {
                                break;
                            }

                            param += Encoding.Unicode.GetString(BitConverter.GetBytes(peek));
                        }
                    }

                    msgs.Add(GetString(lng, id, param) ?? String.Empty);
                }

                var join = String.Join("\n", msgs);

                msgs.Clear();
                msgs.AddRange(join.Split('\n'));
                msgs.PruneStart();
            }
            catch
            { }

            var arr = msgs.ToArray();

            ObjectPool.Free(ref msgs);

            return(arr);
        }
Ejemplo n.º 17
0
        public Grid(int width, int height)
        {
            _InternalGrid = ListPool <List <T> > .AcquireObject();

            Resize(width, height);
        }