Beispiel #1
0
        public void AssignToLayer(Scene scene, LoginManagerServer login, PlayerComponent pc = null)
        {
            MapLayer assignedLayer = null;

            if (MapType == MapType.Multi)
            {
                //find first that isn't full
                assignedLayer = MapLayers.Find(l =>
                {
                    if (l != null)
                    {
                        return(l.LayerLogins.Count < ConstantValues.MaxConnectionsToLayer);
                    }
                    return(false);
                });
                //if none found then make new layer
                if (assignedLayer == null)
                {
                    assignedLayer = CreateNewLayer(-1);
                }
                login.GetCharacter().LastMultiLocation = MapName;
            }
            else if (MapType == MapType.Single)
            {
                assignedLayer = CreateNewLayer(login.GetUniqueID());
            }

            assignedLayer.AddLoginToLayer(login);

            Entity e = Core.Scene.FindEntity(login.GetCharacter()._name);

            if (e == null)
            {
                FSRigidBody fbody = new FSRigidBody().SetBodyType(BodyType.Dynamic).SetIgnoreGravity(true).SetLinearDamping(15f);

                e = scene.CreateEntity(login.GetCharacter()._name).SetPosition(login.GetCharacter().physicalPosition);
                e.AddComponent(fbody)
                .AddComponent(new FSCollisionCircle(25))
                .AddComponent(new PlayerComponent(login)
                {
                    CurrentLayer = assignedLayer
                })
                .AddComponent(new Mover())
                .AddComponent(new CircleCollider(25))
                .AddComponent(new StatsComponent())
                .AddComponent(new DamageComponent());
                fbody.Body.FixedRotation = true;
                login.SetEntity(e);
            }
            if (pc != null)
            {
                pc.CurrentLayer = assignedLayer;
            }
        }