Beispiel #1
0
        private void OnAddSite(Type t)
        {
            IVoteSite site = VitaNexCore.TryCatchGet(() => t.CreateInstance <IVoteSite>());

            if (site != null && !Voting.VoteSites.ContainsKey(site.UID))
            {
                Voting.VoteSites.Add(site.UID, site);
            }

            Refresh(true);
        }
Beispiel #2
0
        public MySQLRow[] Query(string query, params object[] args)
        {
            if (IsDisposed || !Connected || String.IsNullOrWhiteSpace(query))
            {
                return(new MySQLRow[0]);
            }

            return(VitaNexCore.TryCatchGet(
                       () =>
            {
                var rows = new List <MySQLRow>();

                var cmd = Instance.CreateCommand();

                if (_Transaction != null)
                {
                    cmd.Transaction = _Transaction;
                }

                if (args == null || args.Length == 0)
                {
                    cmd.CommandText = query;
                }
                else
                {
                    cmd.CommandText = String.Format(query, args);
                }

                var reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    var rowID = 0;

                    while (reader.Read())
                    {
                        var count = reader.FieldCount;
                        var results = new MySQLData[count];

                        for (var x = 0; x < count; x++)
                        {
                            results[x] = new MySQLData(reader.GetName(x), reader.GetValue(x));
                        }

                        rows.Add(new MySQLRow(rowID, results));
                        rowID++;
                    }
                }

                return rows.ToArray();
            },
                       MySQL.CSOptions.ToConsole) ?? new MySQLRow[0]);
        }
Beispiel #3
0
        public string Generate(string seed)
        {
            Buffer =
                VitaNexCore.TryCatchGet(
                    () =>
                    Provider == null
                                                ? Encoding.UTF8.GetBytes(Transform(seed))
                                                : Provider.ComputeHash(Encoding.UTF8.GetBytes(Transform(seed))),
                    VitaNexCore.ToConsole) ?? new byte[0];

            return(Mutate(BitConverter.ToString(Buffer)));
        }
Beispiel #4
0
        private static void CMSave()
        {
            var result = VitaNexCore.TryCatchGet(VoteSites.Export, CMOptions.ToConsole);

            CMOptions.ToConsole("{0:#,0} site{1} saved, {2}", VoteSites.Count, VoteSites.Count != 1 ? "s" : String.Empty, result);

            result = VitaNexCore.TryCatchGet(Profiles.Export, CMOptions.ToConsole);
            CMOptions.ToConsole(
                "{0:#,0} profile{1} saved, {2}",
                Profiles.Count,
                Profiles.Count != 1 ? "s" : String.Empty,
                result);
        }
Beispiel #5
0
        public static TSchedule CreateSchedule <TSchedule>(
            string name, bool enabled = true, bool register = true, ScheduleInfo info = null, Action <Schedule> handler = null)
            where TSchedule : Schedule
        {
            var st = VitaNexCore.TryCatchGet(() => typeof(TSchedule).CreateInstance <TSchedule>(name, enabled, info, handler));

            if (st != null && register)
            {
                st.Register();
            }

            return(st);
        }
Beispiel #6
0
        public void RewriteID(NetState state, bool multi, ref byte[] buffer, int offset)
        {
            if (state == null || buffer == null || offset >= buffer.Length || state.Version >= Version)
            {
                return;
            }

            byte[] b = buffer;

            buffer = VitaNexCore.TryCatchGet(
                () =>
            {
                int v  = b.Length == 23 ? 0 : b.Length == 24 ? 1 : b.Length == 26 ? 2 : -1;
                int id = ItemID.Right;

                switch (v)
                {
                case 0:                                 //Old
                    {
                        id &= 0x3FFF;

                        if (multi)
                        {
                            id |= 0x4000;
                        }
                    }
                    break;

                case 1:                                 //SA
                    {
                        id &= multi ? 0x3FFF : 0x7FFF;
                    }
                    break;

                case 2:                                 //HS
                    {
                        id &= multi ? 0x3FFF : 0xFFFF;
                    }
                    break;

                default:
                    return(b);
                }

                BitConverter.GetBytes((short)id).CopyTo(b, offset);

                return(b);
            },
                ArtworkSupport.CSOptions.ToConsole);
        }
Beispiel #7
0
        private static bool Restart()
        {
            return(VitaNexCore.TryCatchGet(
                       () =>
            {
                Process.Start(
                    Core.ExePath,
                    !CSOptions.RestartDebug || Insensitive.Contains(Core.Arguments, "-debug")
                                                        ? Core.Arguments
                                                        : Core.Arguments + " -debug");

                return true;
            },
                       CSOptions.ToConsole));
        }
Beispiel #8
0
            public static void Resolve(string addr, out IPAddress outValue)
            {
                if (IPAddress.TryParse(addr.Trim(), out outValue))
                {
                    return;
                }

                outValue = VitaNexCore.TryCatchGet(
                    () =>
                {
                    var iphe = Dns.GetHostEntry(addr);

                    return(iphe.AddressList.LastOrDefault());
                });
            }
Beispiel #9
0
        public long GetStatistic(PvPTeam t, PlayerMobile pm, Func <PvPProfileHistoryEntry, long> fetch)
        {
            if (t == null || t.Deleted || pm == null || fetch == null)
            {
                return(0);
            }

            var s = t.GetStatistics(pm);

            if (s != null)
            {
                return(VitaNexCore.TryCatchGet(fetch, s, AutoPvP.CMOptions.ToConsole));
            }

            return(0);
        }
Beispiel #10
0
        protected override void OnThrownAt(Mobile from, TMobile target)
        {
            if (from == null || from.Deleted || target == null || target.Deleted)
            {
                return;
            }

            if (target.Alive && Damages)
            {
                target.Damage(Utility.RandomMinMax(DamageMin, DamageMax), from);
            }

            if (target.Alive && Heals)
            {
                target.Heal(Utility.RandomMinMax(HealMin, HealMax), from);
            }

            if (Delivery != ThrowableAtMobileDelivery.None)
            {
                var instance = VitaNexCore.TryCatchGet(() => GetType().CreateInstance <BaseThrowableAtMobile <TMobile> >());

                if (instance != null)
                {
                    switch (Delivery)
                    {
                    case ThrowableAtMobileDelivery.MoveToWorld:
                        instance.MoveToWorld(target.Location, target.Map);
                        break;

                    case ThrowableAtMobileDelivery.AddToPack:
                    {
                        if (!target.AddToBackpack(instance))
                        {
                            instance.MoveToWorld(target.Location, target.Map);
                        }
                    }
                    break;

                    default:
                        instance.Delete();
                        break;
                    }
                }
            }

            base.OnThrownAt(from, target);
        }
Beispiel #11
0
        private static bool Email()
        {
            return(CSOptions.EmailOptions.Valid && VitaNexCore.TryCatchGet(
                       () =>
            {
                using (SmtpClient smtp = CSOptions.EmailOptions)
                {
                    string sub = String.Format("{0} Crash Report", ServerList.ServerName);
                    string body = String.Format(
                        "{0} has crashed! {1}Crash Report: {2}",
                        ServerList.ServerName,
                        CSOptions.ReportAttach ? "Attached " : String.Empty,
                        _Report == null || !_Report.Exists ? "N/A" : _Report.Name);

                    if (!CSOptions.ReportAttach && _Report != null && _Report.Exists)
                    {
                        using (StreamReader sr = _Report.OpenText())
                        {
                            body += VitaNexCore.TryCatchGet(sr.ReadToEnd, CSOptions.ToConsole);
                        }
                    }

                    using (MailMessage message = CSOptions.EmailOptions)
                    {
                        return VitaNexCore.TryCatchGet(
                            () =>
                        {
                            message.Subject = sub;
                            message.Body = body;

                            if (CSOptions.ReportAttach && _Report != null && _Report.Exists)
                            {
                                message.Attachments.Add(new Attachment(_Report.FullName, "text/plain; charset=utf-8"));
                            }

                            smtp.Send(message);
                            return true;
                        },
                            CSOptions.ToConsole);
                    }
                }
            },
                       CSOptions.ToConsole));
        }
Beispiel #12
0
        public bool TryInvoke(BaseAspect aspect)
        {
            if (CanInvoke(aspect))
            {
                return(VitaNexCore.TryCatchGet(
                           () =>
                {
                    OnInvoke(aspect);

                    SetLock(aspect, true);

                    Timer.DelayCall(Lockdown, () => SetLock(aspect, false));

                    return true;
                },
                           x => x.ToConsole(true)));
            }

            return(false);
        }
Beispiel #13
0
        public static string GetContent(this HttpWebResponse response)
        {
            return(VitaNexCore.TryCatchGet(
                       () =>
            {
                var content = new StringBuilder();

                var s = response.GetResponseStream();

                if (s != null)
                {
                    var enc = Encoding.UTF8;

                    if (!String.IsNullOrWhiteSpace(response.ContentEncoding))
                    {
                        enc = Encoding.GetEncoding(response.ContentEncoding);
                    }

                    var r = new StreamReader(s, enc);
                    var b = new char[256];

                    int len;

                    while ((len = r.Read(b, 0, b.Length)) > 0)
                    {
                        content.Append(b, 0, len);
                    }

                    r.Close();
                    s.Close();
                }

                return content.ToString();
            },
                       CSOptions.ToConsole));
        }
        public override void Ignite()
        {
            var points = new List <Point3D>();

            Location.ScanRange(
                Map,
                5,
                r =>
            {
                if (!Map.CanSpawnMobile(r.Current))
                {
                    r.Exclude();
                }

                if (!r.Excluded)
                {
                    points.Add(r.Current);
                }

                return(false);
            });

            if (points.Count == 0)
            {
                return;
            }

            var t = this.GetRandomSpawn();

            if (t == null)
            {
                return;
            }

            var m = VitaNexCore.TryCatchGet(() => t.CreateInstance <Mobile>(), DeceitBraziers.CMOptions.ToConsole);

            if (m == null)
            {
                return;
            }

            VitaNexCore.TryCatch(
                () =>
            {
                Duration  = CoolDown;
                Protected = true;
                base.Ignite();

                var fx = new FireExplodeEffect(this, Map, 5, 2)
                {
                    Reversed      = true,
                    EffectHandler = e =>
                                    e.Source.GetMobilesInRange(e.Map, 0)
                                    .Where(v => v != null && v.CanBeDamaged())
                                    .ForEach(v => AOS.Damage(v, Utility.RandomMinMax(10, 20), 10, 80, 0, 0, 10))
                };

                fx.Callback = () =>
                {
                    if (fx.CurrentProcess < fx.Repeat)
                    {
                        return;
                    }

                    new SmokeExplodeEffect(Location, Map, 1).Send();
                    m.MoveToWorld(points.GetRandom(), Map);
                };

                fx.Send();
            },
                ex => m.Delete());
        }
Beispiel #15
0
        private static ConquestRewardInfo CreateInstance(Type t)
        {
            if (t == null)
            {
                return(null);
            }

            return(VitaNexCore.TryCatchGet(
                       () =>
            {
                ConquestRewardInfo info;

                if (t.IsEqualOrChildOf <TitleScroll>())
                {
                    var scroll = t.CreateInstanceSafe <TitleScroll>();

                    if (scroll != null)
                    {
                        string name = scroll.ResolveName();

                        if (scroll.Title != null)
                        {
                            name += " - " +
                                    (scroll.Title.MaleTitle == scroll.Title.FemaleTitle
                                            ? scroll.Title.MaleTitle
                                            : (scroll.Title.MaleTitle + ":" + scroll.Title.FemaleTitle));
                        }

                        info = new ConquestRewardInfo(
                            t, scroll.LabelNumber, name, scroll.Amount, scroll.Stackable, scroll.Hue, scroll.ItemID);

                        scroll.Delete();
                        return info;
                    }
                }
                else if (t.IsEqualOrChildOf <HueScroll>())
                {
                    var scroll = t.CreateInstanceSafe <HueScroll>();

                    if (scroll != null)
                    {
                        string name = scroll.ResolveName();

                        if (scroll.TitleHue != null)
                        {
                            name += ": #" + scroll.TitleHue;
                        }

                        info = new ConquestRewardInfo(
                            t, scroll.LabelNumber, name, scroll.Amount, scroll.Stackable, scroll.Hue, scroll.ItemID);

                        scroll.Delete();
                        return info;
                    }
                }
                else if (t.IsEqualOrChildOf <Item>())
                {
                    var item = t.CreateInstanceSafe <Item>();

                    if (item != null)
                    {
                        info = new ConquestRewardInfo(
                            t, item.LabelNumber, item.ResolveName().ToUpperWords(), item.Amount, item.Stackable,
                            item.Hue, item.ItemID);

                        item.Delete();
                        return info;
                    }
                }
                else if (t.IsEqualOrChildOf <Mobile>())
                {
                    var mob = t.CreateInstanceSafe <Mobile>();

                    if (mob != null)
                    {
                        info = new ConquestRewardInfo(t, 0, mob.RawName.ToUpperWords(), 1, false, mob.Hue,
                                                      ShrinkTable.Lookup(mob));

                        mob.Delete();

                        return info;
                    }
                }
                else if (t.IsEqualOrChildOf <IEntity>())
                {
                    var ent = t.CreateInstanceSafe <IEntity>();

                    if (ent != null)
                    {
                        info = new ConquestRewardInfo(t, 0, t.Name.SpaceWords());

                        ent.Delete();
                        return info;
                    }
                }
                else if (t.IsEqualOrChildOf <XmlAttachment>())
                {
                    var xml = t.CreateInstanceSafe <XmlAttachment>();

                    if (xml != null)
                    {
                        info = new ConquestRewardInfo(t, 0, xml.Name.ToUpperWords());

                        xml.Delete();
                        return info;
                    }
                }

                info = new ConquestRewardInfo(t, 0, t.Name.SpaceWords());

                return info;
            },
                       Conquests.CMOptions.ToConsole));
        }
Beispiel #16
0
 public static TObj ReadTypeCreate <TObj>(this GenericReader reader, params object[] args)
     where TObj : class
 {
     return(VitaNexCore.TryCatchGet(t => t.CreateInstanceSafe <TObj>(args), ReadType(reader), VitaNexCore.ToConsole));
 }
Beispiel #17
0
 public static HttpInfo Create(string url, int?timeout = null)
 {
     return(VitaNexCore.TryCatchGet(
                () => new HttpInfo(new Uri(url), timeout ?? (int)DefaultTimeout.TotalMilliseconds), e => e.ToConsole(true, true)));
 }
Beispiel #18
0
 private static void CSLoad()
 {
     VitaNexCore.TryCatchGet(PlayerProfiles.Import, x => x.ToConsole());
     VitaNexCore.TryCatchGet(PortalList.Import, x => x.ToConsole());
 }
Beispiel #19
0
        public static GiveFlags GiveTo(
            this Item item, Mobile m, GiveFlags flags = GiveFlags.PackBankFeet, bool message = true)
        {
            if (item == null || item.Deleted || m == null || m.Deleted || flags == GiveFlags.None)
            {
                return(GiveFlags.None);
            }

            bool pack   = flags.HasFlag(GiveFlags.Pack);
            bool bank   = flags.HasFlag(GiveFlags.Bank);
            bool feet   = flags.HasFlag(GiveFlags.Feet);
            bool delete = flags.HasFlag(GiveFlags.Delete);

            GiveFlags result = VitaNexCore.TryCatchGet(
                () =>
            {
                if (pack && m.PlaceInBackpack(item))
                {
                    return(GiveFlags.Pack);
                }

                if (bank && m.BankBox.TryDropItem(m, item, false))
                {
                    return(GiveFlags.Bank);
                }

                if (feet)
                {
                    MapPoint mp = m.ToMapPoint();

                    if (!mp.Internal)
                    {
                        item.MoveToWorld(mp.Location, mp.Map);
                        return(GiveFlags.Feet);
                    }
                }

                if (delete)
                {
                    item.Delete();
                    return(GiveFlags.Delete);
                }

                return(GiveFlags.None);
            });

            if (message)
            {
                switch (result)
                {
                case GiveFlags.Pack:
                    m.SendMessage("{0} has been placed in your pack.", item.ResolveName(m));
                    break;

                case GiveFlags.Bank:
                    m.SendMessage("{0} has been placed in your bank.", item.ResolveName(m));
                    break;

                case GiveFlags.Feet:
                    m.SendMessage("{0} has been placed at your feet.", item.ResolveName(m));
                    break;
                }
            }

            return(result);
        }
Beispiel #20
0
        /// <summary>
        ///     Attempts to connect to the specified MySQL Server with the given settings.
        /// </summary>
        /// <param name="retries">Retry connection attempts this many times if the initial connection fails.</param>
        /// <param name="createDB">If a database name is specified, should it try to create it if it doesn't exist?</param>
        /// <returns>True if connection successful</returns>
        public bool Connect(int retries = 0, bool createDB = false)
        {
            if (IsDisposed)
            {
                return(false);
            }

            if (Connected)
            {
                return(true);
            }

            if (Connecting)
            {
                return(false);
            }

            if (!CanConnect())
            {
                return(false);
            }

            var conStr = Credentials.GetConnectionString();

            //MySQL.CSOptions.ToConsole("{0}", conStr);

            var connected = VitaNexCore.TryCatchGet(
                () =>
            {
                if (Instance == null)
                {
                    MySQL.CSOptions.ToConsole("Connection Attempt.");

                    Instance              = new OdbcConnection(conStr);
                    Instance.InfoMessage += OnMessage;

                    Instance.Open();

                    VitaNexCore.WaitWhile(() => Instance.State == ConnectionState.Connecting, TimeSpan.FromSeconds(3));

                    if (Instance.State == ConnectionState.Broken)
                    {
                        Instance.Close();
                    }

                    if (Instance.State == ConnectionState.Open)
                    {
                        MySQL.CSOptions.ToConsole("Connection Successful.");
                        MySQL.Connected(this);

                        if (!String.IsNullOrWhiteSpace(Credentials.Database))
                        {
                            if (createDB)
                            {
                                NonQuery(
                                    @"CREATE DATABASE IF NOT EXISTS `{0}` DEFAULT CHARSET `utf8` DEFAULT COLLATE `utf8_bin`",
                                    Credentials.Database);
                            }

                            Instance.ChangeDatabase(Credentials.Database);
                        }

                        return(true);
                    }
                }

                if (Instance == null)
                {
                    return(false);
                }

                if (Instance.State != ConnectionState.Open)
                {
                    Instance.Close();

                    for (var i = 1; i <= retries; i++)
                    {
                        MySQL.CSOptions.ToConsole("Connection Attempt {0}.", i);

                        Instance.Open();

                        VitaNexCore.WaitWhile(() => Instance.State == ConnectionState.Connecting, TimeSpan.FromSeconds(3));

                        if (Instance.State != ConnectionState.Open)
                        {
                            Instance.Close();
                            continue;
                        }

                        MySQL.CSOptions.ToConsole("Connection Successful.");

                        OnConnected();

                        if (!String.IsNullOrWhiteSpace(Credentials.Database))
                        {
                            if (createDB)
                            {
                                NonQuery(
                                    @"CREATE DATABASE IF NOT EXISTS `{0}` DEFAULT CHARSET `utf8` DEFAULT COLLATE `utf8_bin` DEFAULT ENGINE `INNODB`",
                                    Credentials.Database);
                            }

                            Instance.ChangeDatabase(Credentials.Database);
                        }

                        return(true);
                    }
                }

                if (Instance.State != ConnectionState.Open)
                {
                    Instance.Close();
                }

                return(false);
            },
                MySQL.CSOptions.ToConsole);

            if (!connected)
            {
                MySQL.CSOptions.ToConsole("Connection Failed.");
                Close();
            }

            return(connected);
        }
 private static void CSSave()
 {
     VitaNexCore.TryCatchGet(PlayerProfiles.Export, x => x.ToConsole());
     VitaNexCore.TryCatchGet(Messages.Export, x => x.ToConsole());
 }
Beispiel #22
0
 private static void CSLoad()
 {
     VitaNexCore.TryCatchGet(DonationProfiles.Import, x => x.ToConsole());
 }
Beispiel #23
0
        public virtual SuperGump Send()
        {
            if (IsDisposed || _Sending)
            {
                return(this);
            }

            _Sending = true;

            return(VitaNexCore.TryCatchGet(
                       () =>
            {
                if (IsOpen)
                {
                    InternalClose(this);
                }

                Compile();
                Clear();

                AddPage();

                CompileLayout(Layout);
                Layout.ApplyTo(this);

                InvalidateOffsets();
                InvalidateSize();

                Compiled = true;

                if (Modal && ModalSafety && Buttons.Count == 0 && TileButtons.Count == 0)
                {
                    CanDispose = true;
                    CanClose = true;
                }

                OnBeforeSend();

                Initialized = true;
                IsOpen = User.SendGump(this, false);
                Hidden = false;

                if (IsOpen)
                {
                    OnSend();
                }
                else
                {
                    OnSendFail();
                }

                _Sending = false;

                return this;
            },
                       e =>
            {
                Console.WriteLine("SuperGump '{0}' could not be sent, an exception was caught:", GetType().FullName);
                VitaNexCore.ToConsole(e);
                IsOpen = false;
                Hidden = false;
                OnSendFail();

                _Sending = false;
            }) ?? this);
        }
Beispiel #24
0
        public static GiveFlags GiveTo(this Item item, Mobile m, GiveFlags flags = GiveFlags.All, bool message = true)
        {
            if (item == null || item.Deleted || m == null || m.Deleted || flags == GiveFlags.None)
            {
                return(GiveFlags.None);
            }

            var pack   = flags.HasFlag(GiveFlags.Pack);
            var bank   = flags.HasFlag(GiveFlags.Bank);
            var feet   = flags.HasFlag(GiveFlags.Feet);
            var corpse = flags.HasFlag(GiveFlags.Corpse);
            var delete = flags.HasFlag(GiveFlags.Delete);

            if (pack && (m.Backpack == null || m.Backpack.Deleted || !m.Backpack.CheckHold(m, item, false)))
            {
                pack   = false;
                flags &= ~GiveFlags.Pack;
            }

            if (bank && (!m.Player || !m.BankBox.CheckHold(m, item, false)))
            {
                bank   = false;
                flags &= ~GiveFlags.Bank;
            }

            if (corpse && (m.Alive || m.Corpse == null || m.Corpse.Deleted))
            {
                corpse = false;
                flags &= ~GiveFlags.Corpse;
            }

            if (feet && (m.Map == null || m.Map == Map.Internal) && (m.LogoutMap == null || m.LogoutMap == Map.Internal))
            {
                feet   = false;
                flags &= ~GiveFlags.Feet;
            }

            var result = VitaNexCore.TryCatchGet(
                f =>
            {
                if (pack && m.Backpack.DropItemStack(m, item))
                {
                    return(GiveFlags.Pack);
                }

                if (bank && m.BankBox.DropItemStack(m, item))
                {
                    return(GiveFlags.Bank);
                }

                if (corpse && m.Corpse.DropItemStack(m, item))
                {
                    return(GiveFlags.Corpse);
                }

                if (feet)
                {
                    if (m.Map != null && m.Map != Map.Internal)
                    {
                        item.MoveToWorld(m.Location, m.Map);

                        if (m.Player)
                        {
                            item.SendInfoTo(m.NetState);
                        }

                        return(GiveFlags.Feet);
                    }

                    if (m.LogoutMap != null && m.LogoutMap != Map.Internal)
                    {
                        item.MoveToWorld(m.LogoutLocation, m.LogoutMap);

                        return(GiveFlags.Feet);
                    }
                }

                if (delete)
                {
                    item.Delete();

                    return(GiveFlags.Delete);
                }

                return(GiveFlags.None);
            },
                flags);

            if (!message || result == GiveFlags.None || result == GiveFlags.Delete)
            {
                return(result);
            }

            var amount = String.Empty;
            var name   = ResolveName(item, m);

            var p = item.Stackable && item.Amount > 1;

            if (p)
            {
                amount = item.Amount.ToString("#,0") + " ";

                if (!Insensitive.EndsWith(name, "s") && !Insensitive.EndsWith(name, "z"))
                {
                    name += "s";
                }
            }

            switch (result)
            {
            case GiveFlags.Pack:
                m.SendMessage("{0}{1} {2} been placed in your pack.", amount, name, p ? "have" : "has");
                break;

            case GiveFlags.Bank:
                m.SendMessage("{0}{1} {2} been placed in your bank.", amount, name, p ? "have" : "has");
                break;

            case GiveFlags.Corpse:
                m.SendMessage("{0}{1} {2} been placed in your corpse.", amount, name, p ? "have" : "has");
                break;

            case GiveFlags.Feet:
                m.SendMessage("{0}{1} {2} been placed at your feet.", amount, name, p ? "have" : "has");
                break;
            }

            return(result);
        }
Beispiel #25
0
 private static void CSLoad()
 {
     VitaNexCore.TryCatchGet(PlayerProfiles.Import, x => x.ToConsole());
     VitaNexCore.TryCatchGet(ZombieEvents.Import, x => x.ToConsole());
 }
Beispiel #26
0
        public static SuperGumpAsset CreateInstance(FileInfo file, bool cache, bool reload)
        {
            if (file == null || !file.Exists)
            {
                return(Empty);
            }

            return(VitaNexCore.TryCatchGet(
                       () =>
            {
                var hash = CryptoGenerator.GenString(CryptoHashType.MD5, file.FullName);

                SuperGumpAsset a;

                lock (_CacheLock)
                {
                    a = AssetCache.FirstOrDefault(ca => ca.Hash == hash);
                }

                if (a == null || reload)
                {
                    using (var img = new Bitmap(file.FullName, true))
                    {
                        a = new SuperGumpAsset(file, img);

                        if (cache)
                        {
                            lock (_CacheLock)
                            {
                                AssetCache.AddOrReplace(a);
                            }
                        }
                    }
                }

                if (IsNullOrEmpty(a))
                {
                    return Empty;
                }

                if (!cache || a.Capacity > 0x1000)
                {
                    lock (_CacheLock)
                    {
                        AssetCache.Remove(a);
                        AssetCache.Free(false);
                    }
                }

                lock (_CacheLock)
                {
                    if (AssetCache.Count > 100)
                    {
                        AssetCache.RemoveAt(0);
                    }

                    AssetCache.Free(false);
                }

                return a;
            },
                       VitaNexCore.ToConsole));
        }
Beispiel #27
0
        public virtual SuperGump Send()
        {
            if (IsDisposed || _Sending)
            {
                return(this);
            }

            if (User == null || !User.IsOnline())
            {
                return(this);
            }

            _Sending = true;

            return(VitaNexCore.TryCatchGet(
                       () =>
            {
                if (IsOpen)
                {
                    InternalClose(this);
                }

                Compile();

                Clear();

                AddPage();

                CompileLayout(Layout);

                Layout.ApplyTo(this);

                OnLayoutApplied();

                InvalidateAnimations();
                InvalidateOffsets();
                InvalidateSize();

                Compiled = true;

                if (!CanDispose && CanClose)
                {
                    CanClose = false;
                }

                var wasHolding = false;

                if (Modal)
                {
                    if (ModalSafety && Buttons.Count == 0 && TileButtons.Count == 0)
                    {
                        CanDispose = true;
                        CanClose = true;
                    }

                    if (User != null && User.Holding != null)
                    {
                        var held = User.Holding;

                        if (held.GetBounce() != null)
                        {
                            held.Bounce(User);
                        }
                        else
                        {
                            User.GiveItem(held, GiveFlags.PackFeet, false);
                            User.Holding = null;
                            held.ClearBounce();
                        }

                        wasHolding = held != null;
                    }
                }

                if (OnBeforeSend())
                {
                    InternalCloseDupes(this);

                    Initialized = true;
                    IsOpen = User.SendGump(this, false);
                    Hidden = !IsOpen;

                    if (IsOpen)
                    {
                        OnSend();

                        InternalSend(this);
                    }
                    else
                    {
                        OnSendFail();
                    }
                }
                else
                {
                    Close();
                }

                _Sending = false;

                if (wasHolding)
                {
                    Timer.DelayCall(TimeSpan.FromSeconds(0.5), () => Refresh(true));
                }

                return this;
            },
                       e =>
            {
                _Sending = false;

                Console.WriteLine("SuperGump '{0}' could not be sent, an exception was caught:", GetType().FullName);

                e.ToConsole();

                IsOpen = Hidden = false;

                OnSendFail();
            }) ?? this);
        }
Beispiel #28
0
        public static GiveFlags GiveTo(
            this Item item, Mobile m, GiveFlags flags = GiveFlags.PackBankFeet, bool message = true)
        {
            if (item == null || item.Deleted || m == null || m.Deleted || flags == GiveFlags.None)
            {
                return(GiveFlags.None);
            }

            bool pack   = flags.HasFlag(GiveFlags.Pack);
            bool bank   = flags.HasFlag(GiveFlags.Bank);
            bool feet   = flags.HasFlag(GiveFlags.Feet);
            bool delete = flags.HasFlag(GiveFlags.Delete);

            GiveFlags result = VitaNexCore.TryCatchGet(
                () =>
            {
                if (pack && m.PlaceInBackpack(item))
                {
                    return(GiveFlags.Pack);
                }

                if (bank && m.BankBox.TryDropItem(m, item, false))
                {
                    return(GiveFlags.Bank);
                }

                if (feet)
                {
                    MapPoint mp = m.ToMapPoint();

                    if (!mp.Internal)
                    {
                        item.MoveToWorld(mp.Location, mp.Map);
                        return(GiveFlags.Feet);
                    }
                }

                if (delete)
                {
                    item.Delete();
                    return(GiveFlags.Delete);
                }

                return(GiveFlags.None);
            });

            if (message)
            {
                string amount = String.Empty;
                string name   = ResolveName(item, m);

                bool p = false;

                if (item.Stackable && item.Amount > 1)
                {
                    amount = item.Amount.ToString("#,0") + " ";
                    p      = true;

                    if (!Insensitive.EndsWith(name, "s") && !Insensitive.EndsWith(name, "z"))
                    {
                        name += "s";
                    }
                }

                switch (result)
                {
                case GiveFlags.Pack:
                    m.SendMessage("{0}{1} {2} been placed in your pack.", amount, name, p ? "have" : "has");
                    break;

                case GiveFlags.Bank:
                    m.SendMessage("{0}{1} {2} been placed in your bank.", amount, name, p ? "have" : "has");
                    break;

                case GiveFlags.Feet:
                    m.SendMessage("{0}{1} {2} been placed at your feet.", amount, name, p ? "have" : "has");
                    break;
                }
            }

            return(result);
        }
 private static void CSSave()
 {
     //DefragmentPlayerScores();
     VitaNexCore.TryCatchGet(Registry.Export, x => x.ToConsole());
 }