Example #1
0
        public void CheckExistence()
        {
            if (!router.disconnected)
            {
                return;
            }
            if (currentState != PlayerState.Alive)
            {
                handle.RemovePlayer(id);
                return;
            }
            int disposeDelay = Settings.worldPlayerDisposeDelay;

            if (disposeDelay > 0 && handle.tick - router.disconnectionTick >= disposeDelay)
            {
                handle.RemovePlayer(id);
            }
        }
Example #2
0
        public void LiveUpdate()
        {
            handle.gamemode.OnWorldTick(this);
            var         self = this;
            List <Cell> eat = new List <Cell>(), rigid = new List <Cell>();

            foreach (var _cell in cells)
            {
                _cell.OnTick();
            }
            while (PelletCount < Settings.pelletCount)
            {
                var pos = GetSafeSpawnPos(Settings.pelletMinSize);
                AddCell(new Pellet(this, this, pos.X, pos.Y));
            }
            while (this.virusCount < Settings.virusMinCount)
            {
                var pos = this.GetSafeSpawnPos(Settings.virusSize);
                AddCell(new Virus(this, pos.X, pos.Y));
            }

            /*while (motherCellCount < Settings.motherCellCount)
             * {
             *  var pos = this.GetSafeSpawnPos(Settings.motherCellSize);
             *  AddCell(new MotherCell(this, pos.X, pos.Y));
             * }*/

            for (int i = 0, l = this.boostingCells.Count; i < l;)
            {
                if (!this.BoostCell(this.boostingCells[i]))
                {
                    l--;
                }
                else
                {
                    i++;
                }
            }
            for (int i = 0; i < this.boostingCells.Count; i++)
            {
                var cell = this.boostingCells[i];
                if (cell.Type != 2 && cell.Type != 3)
                {
                    continue;
                }
                finder.Search(cell.range, (other) =>
                {
                    if (cell.id != ((Cell)other).id)
                    {
                        switch (cell.GetEatResult(((Cell)other)))
                        {
                        case CellEatResult.Rigid: rigid.AddRange(new Cell[2] {
                                cell, ((Cell)other)
                            }); break;

                        case CellEatResult.Eat: eat.AddRange(new Cell[2] {
                                cell, ((Cell)other)
                            }); break;

                        case CellEatResult.EatInvd: eat.AddRange(new Cell[2] {
                                ((Cell)other), cell
                            }); break;
                        }
                    }
                });
            }
            for (int i = 0, l = this.playerCells.Count; i < l; i++)
            {
                var cell = this.playerCells[i];
                this.AutoSplitPlayerCell(cell);
                this.MovePlayerCell(cell);
                this.DecayPlayerCell(cell);
                this.BounceCell(cell, false);
                this.UpdateCell(cell);
            }
            object locker = new object();

            for (int i = 0, l = playerCells.Count; i < l; i++)
            {
                var cell = this.playerCells[i];
                this.finder.Search(cell.range, (other) =>
                {
                    if (cell.id != (other).id)
                    {
                        lock (locker)
                            switch (cell.GetEatResult(other))
                            {
                            case CellEatResult.Rigid:
                                rigid.AddRange(new Cell[2] {
                                    cell, other
                                }); break;

                            case CellEatResult.Eat:
                                eat.AddRange(new Cell[2] {
                                    cell, (other)
                                }); break;

                            case CellEatResult.EatInvd:
                                eat.AddRange(new Cell[2] {
                                    (other), cell
                                }); break;
                            }
                    }
                });
            }
            for (int i = 0, l = rigid.Count; i < l;)
            {
                this.ResolveRigidCheck(rigid[i++], rigid[i++]);
            }
            for (int i = 0, l = eat.Count; i < l;)
            {
                this.ResolveEatCheck(eat[i++], eat[i++]);
            }
            largestPlayer = null;
            for (int i = 0, l = this.players.Count; i < l; i++)
            {
                var player = this.players[i];
                if (!float.IsNaN(player.score) && (this.largestPlayer == null || player.score > this.largestPlayer.score))
                {
                    this.largestPlayer = player;
                }
            }
            for (int i = 0, l = this.players.Count; i < l; i++)
            {
                var player = this.players[i];
                player.CheckExistence();
                if (!player.exists)
                {
                    i--; l--;
                    continue;
                }
                if (player.currentState == PlayerState.Spectating && this.largestPlayer == null)
                {
                    player.UpdateState(PlayerState.Roaming);
                }
                var router = player.router;
                for (int j = 0, k = this.Settings.playerSplitCap; j < k && router.splitAttempts > 0; j++)
                {
                    router.AttemptSplit();
                    router.splitAttempts--;
                }
                var nextEjectTick = this.handle.tick - this.Settings.playerEjectDelay;
                if (router.ejectAttempts > 0 && nextEjectTick >= router.ejectTick)
                {
                    router.AttemptEject();
                    router.ejectAttempts = 0;
                    router.ejectTick     = this.handle.tick;
                }
                if (router.isPressingQ)
                {
                    if (!router.hasProcessedQ)
                    {
                        router.OnQPress();
                    }
                    router.hasProcessedQ = true;
                }
                else
                {
                    router.hasProcessedQ = false;
                }
                if (router.requestingSpectate)
                {
                    router.OnSpectateRequest();
                    router.requestingSpectate = false;
                }
                if (router.spawningName != null)
                {
                    router.OnSpawnRequest();
                    router.spawningName = null;
                }
                player.UpdateViewArea();
            }
            CompileStatistics();
            handle.gamemode.CompileLeaderboard(this);
            if (stats.external <= 1 && handle.worlds.Count > Settings.worldMinCount)
            {
                handle.RemovePlayer((short)id);
            }
        }