Exemplo n.º 1
0
    public void CheckReceived()
    {
        if (received.Length >= length)
        {
            var command = ITell.FromStream(received, length);
            switch (command)
            {
            case TellClient.SetWorld c:
                var sys = c.sys;

                AIShip ai       = null;
                var    playerId = client.playerMain?.playerShip?.id;
                if (playerId.HasValue && client.entityLookup.TryGetValue(playerId.Value, out var en))
                {
                    ai = en as AIShip;
                }
                ai ??= sys.entities.all.OfType <AIShip>().FirstOrDefault();
                if (ai != null)
                {
                    lock (client.World) {
                        client.World = sys;
                    }
                    client.removed = ai;
                    sys.RemoveEntity(ai);
                    var playerShip = new PlayerShip(new Player(client.prev.settings), ai.ship, ai.sovereign);
                    playerShip.mortalChances = 0;
                    sys.AddEntity(playerShip);
                    sys.UpdatePresent();
                    client.SetPlayerMain(new PlayerMain(client.Width, client.Height,
                                                        new Profile(), playerShip));
                    TellServer(new TellServer.AssumePlayerShip()
                    {
                        shipId = ai.id
                    });
                }
                break;

            case TellClient.SetCamera c:
                client.camera = c.pos;
                break;

            case TellClient.SyncSharedState c:
                foreach (var state in c.entities)
                {
                    if (client.entityLookup.TryGetValue(state.id, out Entity e))
                    {
                        e.SetSharedState(state);
                    }
                }
                break;
            }

            received.Close();
        }
    }
Exemplo n.º 2
0
    public void CheckReceived()
    {
        if (received.Length >= length)
        {
            var command = ITell.FromStream(received, length);
            switch (command)
            {
            case TellServer.AssumePlayerShip c:
                Handle(c);
                break;

            case TellServer.LeavePlayerShip:
                RemovePlayer();
                break;

            case TellServer.ControlPlayerShip c:
                Handle(c);
                break;
            }

            received.Close();
        }
    }