Example #1
0
        public Blood(int itemID)
            : base(itemID)
        {
            Movable = false;

            TimerRegistry.Register(_TimerID, this, DecayTime, blood => blood.Delete());
        }
Example #2
0
        public void TurnToBones()
        {
            if (Deleted)
            {
                return;
            }

            ProcessDelta();
            SendRemovePacket();
            ItemID = Utility.Random(0xECA, 9); // bone graphic
            Hue    = 0;
            ProcessDelta();

            SetFlag(CorpseFlag.NoBones, true);
            SetFlag(CorpseFlag.IsBones, true);

            var delay = Owner?.CorpseDecayTime ?? Mobile.DefaultCorpseDecay;

            m_DecayTime = DateTime.UtcNow + delay;

            if (!TimerRegistry.UpdateRegistry(m_TimerID, this, delay))
            {
                TimerRegistry.Register(m_TimerID, this, delay, TimerPriority.FiveSeconds, c => c.DoDecay());
            }
        }
Example #3
0
        public override void UpdateBeforeSimulation()
        {
            Instance = this;
            // This needs to wait until the MyAPIGateway.Session.Player is created, as running on a Dedicated server can cause issues.
            // It would be nicer to just read a property that indicates this is a dedicated server, and simply return.
            if (!_isInitialized && MyAPIGateway.Session != null && MyAPIGateway.Session.Player != null)
            {
                Debug = MyAPIGateway.Session.Player.IsExperimentalCreator();

                if (!MyAPIGateway.Session.OnlineMode.Equals(MyOnlineModeEnum.OFFLINE) && MyAPIGateway.Multiplayer.IsServer && !MyAPIGateway.Utilities.IsDedicated)
                {
                    InitServer();
                }
                Init();
            }
            if (!_isInitialized && MyAPIGateway.Utilities != null && MyAPIGateway.Multiplayer != null &&
                MyAPIGateway.Session != null && MyAPIGateway.Utilities.IsDedicated && MyAPIGateway.Multiplayer.IsServer)
            {
                InitServer();
                return;
            }

            base.UpdateBeforeSimulation();

            ChatCommandService.UpdateBeforeSimulation();
            ProtectionHandler.UpdateBeforeSimulation();
            TimerRegistry.Update();
        }
Example #4
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
            case 4:
                FailedLockpick   = reader.ReadBool();
                _Quality         = (ChestQuality)reader.ReadInt();
                DigTime          = reader.ReadDateTime();
                AncientGuardians = reader.ReadStrongMobileList();
                goto case 3;

            case 3:
                FirstOpenedByOwner = reader.ReadBool();
                TreasureMap        = reader.ReadItem() as TreasureMap;
                goto case 2;

            case 2:
            {
                Guardians = reader.ReadStrongMobileList();
                Temporary = reader.ReadBool();

                goto case 1;
            }

            case 1:
            {
                Owner = reader.ReadMobile();

                goto case 0;
            }

            case 0:
            {
                Level      = reader.ReadInt();
                DeleteTime = reader.ReadDeltaTime();
                m_Lifted   = reader.ReadStrongItemList();

                if (version < 2)
                {
                    Guardians = new List <Mobile>();
                }

                break;
            }
            }

            if (!Temporary && DeleteTime > DateTime.UtcNow)
            {
                TimerRegistry.Register("TreasureMapChest", this, DeleteTime - DateTime.UtcNow, chest => chest.Delete());
            }
            else
            {
                Delete();
            }
        }
Example #5
0
        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);

            writer.Write(1);

            writer.Write(TimerRegistry.HasTimer(m_DeleteTimerID, this));
        }
Example #6
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadEncodedInt();

            TimerRegistry.Register("UnsettlingPortrait", this, TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(3), false, p => p.ChangeDirection());
        }
Example #7
0
        public virtual void BeginDelete(Mobile m)
        {
            StopFollow();

            if (m != null)
            {
                m_EscortTable.Remove(m);
            }

            TimerRegistry.Register(m_TimerID, this, TimeSpan.FromSeconds(45), escort => escort.Delete());
        }
Example #8
0
        public void AddEntry(TownCrierEntry entry)
        {
            if (m_Entries == null)
            {
                m_Entries = new List <TownCrierEntry>();
            }

            m_Entries.Add(entry);

            TimerRegistry.Register(_AutoShoutTimerID, this, TimeSpan.FromMinutes(5.0), TimeSpan.FromMinutes(1.0), false, tc => tc.AutoShout_Callback());
        }
Example #9
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            reader.ReadEncodedInt();

            if (UsesRemaining < 20)
            {
                TimerRegistry.Register(TimerID, this, RechargDuration, false, hammer => Tick_Callback(hammer));
            }
        }
Example #10
0
 protected void PlaySound()
 {
     if (Active)
     {
         Effects.PlaySound(Location, Map, Utility.RandomList(0x1DC, 0x210, 0x2F4));
         TimerRegistry.UpdateRegistry(_TimerID, this, TimeSpan.FromSeconds(Utility.RandomMinMax(5, 25)));
     }
     else
     {
         TimerRegistry.RemoveFromRegistry(_TimerID, this);
     }
 }
        public static void OnTick(FelineBlessedStatue statue)
        {
            if (statue.Movable)
            {
                statue.StopTimer();
                return;
            }

            statue.DropResource();

            TimerRegistry.UpdateRegistry(TimerID, statue, RespawnDuration);
            statue.NextReagentTime = DateTime.UtcNow + RespawnDuration;
        }
Example #12
0
        public TreasureMapChest(Mobile owner, int level, bool temporary)
            : base(0xE40)
        {
            Owner      = owner;
            Level      = level;
            DeleteTime = DateTime.UtcNow + _DeleteTime;

            Temporary        = temporary;
            Guardians        = new List <Mobile>();
            AncientGuardians = new List <Mobile>();

            TimerRegistry.Register("TreasureMapChest", this, _DeleteTime, chest => chest.Delete());
        }
        public void StartTimer()
        {
            if (NextReagentTime == DateTime.MinValue)
            {
                NextReagentTime = DateTime.UtcNow + RespawnDuration;
            }
            else if (NextReagentTime < DateTime.UtcNow)
            {
                NextReagentTime = DateTime.UtcNow + TimeSpan.FromSeconds(10);
            }

            TimerRegistry.Register(TimerID, this, NextReagentTime - DateTime.UtcNow, false, OnTick);
        }
Example #14
0
        public Clone(Mobile caster)
            : base(AIType.AI_Melee, FightMode.None, 10, 1, 0.2, 0.4)
        {
            m_Caster = caster;

            Body = caster.Body;

            Hue    = caster.Hue;
            Female = caster.Female;

            Name    = caster.Name;
            NameHue = caster.NameHue;

            Title = caster.Title;
            Kills = caster.Kills;

            HairItemID = caster.HairItemID;
            HairHue    = caster.HairHue;

            FacialHairItemID = caster.FacialHairItemID;
            FacialHairHue    = caster.FacialHairHue;

            for (int i = 0; i < caster.Skills.Length; ++i)
            {
                Skills[i].Base = caster.Skills[i].Base;
                Skills[i].Cap  = caster.Skills[i].Cap;
            }

            for (int i = 0; i < caster.Items.Count; i++)
            {
                AddItem(CloneItem(caster.Items[i]));
            }

            Warmode = true;

            Summoned     = true;
            SummonMaster = caster;

            ControlOrder  = OrderType.Follow;
            ControlTarget = caster;

            TimeSpan duration = TimeSpan.FromSeconds(30 + caster.Skills.Ninjitsu.Fixed / 40);

            SummonEnd = DateTime.UtcNow + duration;
            TimerRegistry.Register <BaseCreature>("UnsummonTimer", this, duration, c => c.Delete());

            MirrorImage.AddClone(m_Caster);

            IgnoreMobiles = true;
        }
Example #15
0
        public virtual Mobile GetEscorter()
        {
            Mobile master = ControlMaster;

            if (master == null || !Controlled)
            {
                return(master);
            }
            else if (master.Map != Map || !master.InRange(Location, 30) || !master.Alive)
            {
                TimeSpan lastSeenDelay = DateTime.UtcNow - LastSeenEscorter;

                if (lastSeenDelay >= TimeSpan.FromMinutes(2.0))
                {
                    EscortObjective escort = GetObjective();

                    if (escort != null)
                    {
                        master.SendLocalizedMessage(1071194); // You have failed your escort quest…
                        master.PlaySound(0x5B3);
                        escort.Fail();
                    }

                    master.SendLocalizedMessage(1042473); // You have lost the person you were escorting.
                    Say(1005653);                         // Hmmm.  I seem to have lost my master.

                    StopFollow();
                    m_EscortTable.Remove(master);

                    TimerRegistry.Register(m_TimerID, this, TimeSpan.FromSeconds(5.0), e => e.Delete());

                    return(null);
                }
                else
                {
                    ControlOrder = OrderType.Stay;
                }
            }
            else
            {
                if (ControlOrder != OrderType.Follow)
                {
                    StartFollow(master);
                }

                LastSeenEscorter = DateTime.UtcNow;
            }

            return(master);
        }
Example #16
0
        private void AutoShout_Callback()
        {
            TownCrierEntry tce = GetRandomEntry();

            if (tce == null)
            {
                TimerRegistry.RemoveFromRegistry(_AutoShoutTimerID, this);
            }
            else if (m_NewsTimer == null)
            {
                m_NewsTimer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(3.0), new TimerStateCallback(ShoutNews_Callback), new object[] { tce, 0 });

                PublicOverheadMessage(MessageType.Regular, 0x3B2, 502976); // Hear ye! Hear ye!
            }
        }
Example #17
0
        public TownCrierEntry AddEntry(TextDefinition[] lines, TimeSpan duration)
        {
            if (m_Entries == null)
            {
                m_Entries = new List <TownCrierEntry>();
            }

            TownCrierEntry tce = new TownCrierEntry(lines, duration);

            m_Entries.Add(tce);

            TimerRegistry.Register(_AutoShoutTimerID, this, TimeSpan.FromMinutes(5.0), TimeSpan.FromMinutes(1.0), false, tc => tc.AutoShout_Callback());

            return(tce);
        }
Example #18
0
        public Weather(Map facet, Rectangle2D[] area, int temperature, int chanceOfPercipitation, int chanceOfExtremeTemperature, TimeSpan interval)
        {
            m_Facet                      = facet;
            m_Area                       = area;
            m_Temperature                = temperature;
            m_ChanceOfPercipitation      = chanceOfPercipitation;
            m_ChanceOfExtremeTemperature = chanceOfExtremeTemperature;

            List <Weather> list = GetWeatherList(facet);

            if (list != null)
            {
                list.Add(this);
            }

            TimerRegistry.Register(m_TimerID, this, interval, TimeSpan.FromSeconds((0.2 + (Utility.RandomDouble() * 0.8)) * interval.TotalSeconds), false, weather => weather.OnTick());
        }
        private void DetachEvents()
        {
            TimerRegistry.Close();

            Sandbox.Game.MyVisualScriptLogicProvider.PlayerConnected    = null;
            Sandbox.Game.MyVisualScriptLogicProvider.PlayerDropped      = null;
            Sandbox.Game.MyVisualScriptLogicProvider.PlayerDisconnected = null;

            // servers: listen and dedicated, MP
            if (ServerCfg != null)
            {
                MyAPIGateway.Multiplayer.UnregisterMessageHandler(ConnectionHelper.ConnectionId, MessageHandler);
                ProtectionHandler.Close();
                Logger.Debug("Unregistered MessageHandler");
            }

            if (MyAPIGateway.Utilities != null && MyAPIGateway.Multiplayer != null && MyAPIGateway.Multiplayer.IsServer && MyAPIGateway.Utilities.IsDedicated)
            {
                return;
            }

            if (MyAPIGateway.Multiplayer != null && MyAPIGateway.Multiplayer.MultiplayerActive || (ServerCfg != null && ServerConfig.ServerIsClient))
            {
                // all clients, including hosts, MP
                if (PermissionRequestTimer != null)
                {
                    PermissionRequestTimer.Stop();
                    PermissionRequestTimer.Close();
                }
                MyAPIGateway.Session.OnSessionReady -= Session_OnSessionReady;
                Logger.Debug("Detached Session_OnSessionReady");

                // only clients, not the host
                if (ServerCfg == null)
                {
                    MyAPIGateway.Multiplayer.UnregisterMessageHandler(ConnectionHelper.ConnectionId, MessageHandler);
                    Logger.Debug("Unregistered MessageHandler");
                }
            }

            if (MyAPIGateway.Utilities != null)
            {
                MyAPIGateway.Utilities.MessageEntered -= Utilities_MessageEntered;
                Logger.Debug("Detached MessageEntered");
            }
        }
Example #20
0
        public void Stop()
        {
            if (!m_Active || Deleted)
            {
                return;
            }

            m_Active = false;
            m_Level  = 0;

            ClearSpawn();
            Despawn();

            TimerRegistry.RemoveFromRegistry(m_TimerID, this);
            TimerRegistry.RemoveFromRegistry(m_RestartTimerID, this);

            InvalidateProperties();
        }
Example #21
0
        public void RemoveEntry(TownCrierEntry tce)
        {
            if (m_Entries == null)
            {
                return;
            }

            m_Entries.Remove(tce);

            if (m_Entries.Count == 0)
            {
                m_Entries = null;
            }

            if (m_Entries == null && GlobalTownCrierEntryList.Instance.IsEmpty)
            {
                TimerRegistry.RemoveFromRegistry(_AutoShoutTimerID, this);
            }
        }
Example #22
0
        public Game(IEntityFactory entityFactory, IOutputFormatter formatter)
        {
            Instance       = this;
            _formatter     = formatter;
            _timerRegistry = new TimerRegistry();

            _entities      = new Dictionary <int, MudEntity>();
            _rooms         = new Dictionary <int, MudRoom>();
            _zones         = new Dictionary <int, MudZone>();
            _portals       = new Dictionary <int, MudPortal>();
            _portalEntries = new Dictionary <int, MudPortalEntry>();

            _entityFactory = entityFactory;

            ScriptManager.Instance.RefreshScripts(ScriptType.Game);
            ScriptManager.Instance.RefreshScripts(ScriptType.MudComponent);
            ScriptManager.Instance.RefreshScripts(ScriptType.MudCommand);
            ComponentManager.Instance.RefreshAllComponents();
            Commands = new CommandManager();
            Commands.LoadAllCommands();
        }
Example #23
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            reader.ReadInt();

            m_KeyValue    = reader.ReadUInt();
            m_Open        = reader.ReadBool();
            m_Locked      = reader.ReadBool();
            m_OpenedID    = reader.ReadInt();
            m_ClosedID    = reader.ReadInt();
            m_OpenedSound = reader.ReadInt();
            m_ClosedSound = reader.ReadInt();
            m_Offset      = reader.ReadPoint3D();
            m_Link        = reader.ReadItem() as BaseDoor;

            if (m_Open)
            {
                TimerRegistry.Register(m_TimerID, this, TimeSpan.FromSeconds(20), TimeSpan.FromSeconds(10), false, TimerPriority.OneSecond, door => door.InternalClose());
            }
        }
 public override void OnSectorDeactivate()
 {
     TimerRegistry.RemoveFromRegistry(_TimerID, this);
 }
Example #25
0
        public void BeginDecay(TimeSpan delay)
        {
            m_DecayTime = DateTime.UtcNow + delay;

            TimerRegistry.Register(m_TimerID, this, delay, TimerPriority.FiveSeconds, c => c.DoDecay());
        }
Example #26
0
 private void StartTimer()
 {
     TimerRegistry.Register(_TimerID, this, TimeSpan.FromMinutes(15.0), TimeSpan.FromMinutes(15.0), false, spawner => spawner.CheckSpawn());
 }
Example #27
0
 private void StartRestartTimer()
 {
     TimerRegistry.Register(m_RestartTimerID, this, m_RestartDelay, spawner => spawner.Start());
 }
Example #28
0
 private void StartTimer()
 {
     TimerRegistry.Register(m_TimerID, this, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), false, spawner => spawner.OnSlice());
 }
Example #29
0
        public virtual bool CheckAtDestination()
        {
            if (Quest != null)
            {
                EscortObjective escort = GetObjective();

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

                Mobile escorter = GetEscorter();

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

                if (escort.Region != null && Region.IsPartOf(escort.Region))
                {
                    Say(1042809, escorter.Name); // We have arrived! I thank thee, ~1_PLAYER_NAME~! I have no further need of thy services. Here is thy pay.

                    escort.Complete();

                    if (Quest.Completed)
                    {
                        escorter.SendLocalizedMessage(1046258, null, 0x23); // Your quest is complete.

                        if (QuestHelper.AnyRewards(Quest))
                        {
                            escorter.SendGump(new MondainQuestGump(Quest, MondainQuestGump.Section.Rewards, false, true));
                        }
                        else
                        {
                            Quest.GiveRewards();
                        }

                        escorter.PlaySound(Quest.CompleteSound);

                        StopFollow();
                        m_EscortTable.Remove(escorter);

                        TimerRegistry.Register(m_TimerID, this, TimeSpan.FromSeconds(5), e => e.Delete());

                        // fame
                        Misc.Titles.AwardFame(escorter, escort.Fame, true);

                        // compassion
                        bool gainedPath = false;

                        PlayerMobile pm = escorter as PlayerMobile;

                        if (pm != null)
                        {
                            if (pm.CompassionGains > 0 && DateTime.UtcNow > pm.NextCompassionDay)
                            {
                                pm.NextCompassionDay = DateTime.MinValue;
                                pm.CompassionGains   = 0;
                            }

                            if (pm.CompassionGains >= 5)          // have already gained 5 times in one day, can gain no more
                            {
                                pm.SendLocalizedMessage(1053004); // You must wait about a day before you can gain in compassion again.
                            }
                            else if (VirtueHelper.Award(pm, VirtueName.Compassion, escort.Compassion, ref gainedPath))
                            {
                                pm.SendLocalizedMessage(1074949, null, 0x2A);  // You have demonstrated your compassion!  Your kind actions have been noted.

                                if (gainedPath)
                                {
                                    pm.SendLocalizedMessage(1053005); // You have achieved a path in compassion!
                                }
                                else
                                {
                                    pm.SendLocalizedMessage(1053002);                            // You have gained in compassion.
                                }
                                pm.NextCompassionDay = DateTime.UtcNow + TimeSpan.FromDays(1.0); // in one day CompassionGains gets reset to 0
                                ++pm.CompassionGains;
                            }
                            else
                            {
                                pm.SendLocalizedMessage(1053003); // You have achieved the highest path of compassion and can no longer gain any further.
                            }
                        }
                    }
                    else
                    {
                        escorter.PlaySound(Quest.UpdateSound);
                    }

                    return(true);
                }
            }
            else if (!m_Checked)
            {
                string region = GetDestination();

                if (region != null && Region.IsPartOf(region))
                {
                    TimerRegistry.Register(m_TimerID, this, TimeSpan.FromSeconds(5), escort => escort.Delete());
                    m_Checked = true;
                }
            }

            return(false);
        }
 public override void OnSectorActivate()
 {
     TimerRegistry.Register(_TimerID, this, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), false, addon => addon.OnTick());
 }