Ejemplo n.º 1
0
        /// <summary>
        /// Called when a player gets the crown. Only one player can have the crown at one time.
        /// </summary>
        /// <param name="m">The message.</param>
        public void OnCrown(Message m)
        {
            // Extract data.
            int id = m.GetInteger(0);

            if (id == -1)
            {
                return;
            }

            // Update relevant objects.
            Player subject = Tools.GetPlayer(id, _in.Source);

            // Take the crown from the current holder (if one exists)
            Player crownHolder = Tools.GetCrownHolder(_in.Source);

            if (crownHolder != null)
                crownHolder.HasCrown = false;

            // Give it to the subject.
            if (subject != null)
                subject.HasCrown = true;

            // Fire the event.
            var e = new PlayerEventArgs(subject, _in.Source, m);

            _in.Source.Pull.Crown.CrownEvent(e);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called when the bot received elevated permission access (god mode, changing blocks) to the room.
        /// </summary>
        /// <param name="m">
        /// The message.
        /// </param>
        public void OnAccess(Message m)
        {
            // Nothing to extract from message.
            // Update relevant objects.
            this._in.Bot.HasAccess = true;

            // Fire the event.
            var e = new PlayerEventArgs(this._in.Bot, this._in.Source, m);

            this._in.Source.Pull.Access.GainAccessEvent(e);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called when the server gives a different wizard smiley to a player.
        /// </summary>
        /// <param name="m">
        /// The message.
        /// </param>
        public void OnGiveWizard2(Message m)
        {
            // Extract data
            int id = m.GetInteger(0);

            // Update relevant objects.
            Player subject = Tools.GetPlayer(id, this._in.Source);

            // Fire the event.
            var e = new PlayerEventArgs(subject, this._in.Source, m);

            this._in.Source.Pull.GiveWizard2.RedWizardEvent(e);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Called when a player levels up.
        /// </summary>
        /// <param name="m">
        /// The message.
        /// </param>
        public void OnLevelUp(Message m)
        {
            // Extract data.
            int id = m.GetInteger(0), level = m.GetInteger(1);

            // Update relevant objects.
            Player subject = Tools.GetPlayer(id, this._in.Source);
            subject.Level = level;

            // Fire the event.
            var e = new PlayerEventArgs(subject, this._in.Source, m);

            this._in.Source.Pull.LevelChange.LevelUpEvent(e);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called when a player touches the trophy (silver crown).
        /// </summary>
        /// <param name="m">
        /// The message.
        /// </param>
        public void OnTrophy(Message m)
        {
            // Extract data.
            int id = m.GetInteger(0);

            // Update relevant objects.
            Player subject = Tools.GetPlayer(id, this._in.Source);

            subject.HasSilverCrown = true;

            // Fire the event.
            var e = new PlayerEventArgs(subject, this._in.Source, m);

            this._in.Source.Pull.Trophy.TrophyEvent(e);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Called when a player teleports to a location.
        /// </summary>
        /// <param name="m">
        /// The message.
        /// </param>
        public void OnTeleport(Message m)
        {
            // Extract data.
            int id = m.GetInteger(0), x = m.GetInteger(1), y = m.GetInteger(2);

            // Update relevant objects.
            Player subject = Tools.GetPlayer(id, this._in.Source);

            subject.X = x;
            subject.Y = y;

            // Fire the event.
            var e = new PlayerEventArgs(subject, this._in.Source, m);

            this._in.Source.Pull.Teleport.TeleportEvent(e);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Called when a player toggles god mode.
        /// </summary>
        /// <param name="m">
        /// The message.
        /// </param>
        public void OnGod(Message m)
        {
            // Extract data.
            bool isGod = m.GetBoolean(1);

            int id = m.GetInteger(0);

            // Update relevant objects.
            Player subject = Tools.GetPlayer(id, this._in.Source);

            subject.IsGod = isGod;

            // Fire the event.
            var e = new PlayerEventArgs(subject, this._in.Source, m);

            this._in.Source.Pull.GodMode.GodEvent(e);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Called when a player left the world.
        /// </summary>
        /// <param name="m">
        /// The m.
        /// </param>
        public void OnLeft(Message m)
        {
            // Extract data.
            int id = m.GetInteger(0);

            // Update relevant objects.
            Player subject = Tools.GetPlayer(id, this._in.Source);
            for (int i = 0; i < this._in.Source.OnlinePlayers.Count; i++)
            {
                if (this._in.Source.OnlinePlayers[i] != subject)
                {
                    continue;
                }

                this._in.Source.OnlinePlayers.RemoveAt(i);
                break;
            }

            // Fire the event.
            var e = new PlayerEventArgs(subject, this._in.Source, m);

            this._in.Source.Pull.LeftWorld.LeaveEvent(e);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     Updates the physics.
        /// </summary>
        private void UpdatePhysics()
        {
            this._playerPhysicsStopwatch.Start();

            long accumulator = 0;

            while (true) // Player shouldtick boolean throws a nullReferenceException
            {
                if (!Source.ShouldTick)
                    continue;

                try
                {
                    if (this._playerPhysicsStopwatch.ElapsedMilliseconds >= accumulator + Config.physics_ms_per_tick)
                    {
                        accumulator += Config.physics_ms_per_tick;
                        int iCount = this.Source.OnlinePlayers.Count();
                        for (int iPlayer = 0; iPlayer <= iCount; iPlayer++)
                        {
                            Player player = this.Source.OnlinePlayers[iPlayer];
                            if (player.ShouldTick)
                            {
                                player.Tick();

                                var e = new PlayerEventArgs(player, this.Source, null);
                                this.Source.Pull.TickEvent(e);
                            }
                        }
                    }
                    else
                    {
                        // Since the timescales dealt with here should be subsecond, explicit unchecked casts
                        // to int should never overflow.
                        var difference = (int)(this._playerPhysicsStopwatch.ElapsedMilliseconds - accumulator);
                        Thread.Sleep(difference);
                    }
                }
                catch (Exception e)
                {
                    Tools.SkylightMessage(e.ToString());
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Called when [lost access].
        /// </summary>
        /// <param name="m">
        /// The m.
        /// </param>
        private void OnLostAccess(Message m)
        {
            // Nothing to extract from message.
            // Update relevant objects.
            this.Bot.HasAccess = false;

            // Fire the event.
            var e = new PlayerEventArgs(this.Bot, this.Source, m);

            this.Source.Pull.LoseAccessEvent(e);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Called when [guardian mode].
        /// </summary>
        /// <param name="m">
        /// The m.
        /// </param>
        private void OnGuardianMode(Message m)
        {
            int id = m.GetInteger(0);

            Player player = Tools.GetPlayer(id, this.Source);

            var e = new PlayerEventArgs(player, this.Source, null);
            this.Source.Pull.GuardianEvent(e);
        }