Esempio n. 1
0
 private void ReadDetailsCommand()
 {
     if (this.details.Command == DetailCommand.PickEntity)
     {
         EntitySelector.PickEntity(this.details.Entity);
         this.details = null;
     }
     else if (this.details.Command == DetailCommand.GatherResource)
     {
         ((IResourceProvider)this.details.Entity).Gather(5);
     }
     else if (this.details.Command == DetailCommand.Close)
     {
         this.details = null;
     }
 }
Esempio n. 2
0
        private void CleanDead()
        {
            var markedForDestruction = UsersManager.CurrentPlayer.Units.Where(u => u.IsAlive == false).ToArray();

            foreach (var unit in markedForDestruction)
            {
                this.deadUnits.Enqueue(unit);
                UsersManager.CurrentPlayer.Units.Remove(unit);
                UsersManager.CurrentPlayer.AllEntities.Remove(unit);
                if (EntitySelector.EntityPicked == unit || EntitySelector.EntitySelected == unit)
                {
                    EntitySelector.Deselect();
                    EntitySelector.PlaceEntity();
                }

                if (this.details?.Entity == unit)
                {
                    this.details = null;
                }
            }
        }
Esempio n. 3
0
        public override void Update(GameTime gameTime)
        {
            this.CleanDead();

            var allEntities = UsersManager.CurrentPlayer.AllEntities;

            foreach (var entity in allEntities)
            {
                entity.GravityAffect(gameTime, this.terrain);
            }

            foreach (var unit in UsersManager.CurrentPlayer.Units)
            {
                unit.Update(gameTime, this.terrain, allEntities);
            }

            this.details?.Update(gameTime);

            if (Input.KeyPressed(Keys.D1))
            {
                if (EntitySelector.HasPicked())
                {
                    EntitySelector.PlaceEntity();
                }
                else
                {
                    var unit = new Swordsman(Guid.NewGuid(), UsersManager.CurrentPlayer.Id, Vector3.Zero, Quaternion.Identity);
                    Client.Socket.Writer.Send(Message.Create(Service.AddUnit, UnitFactory.ToDto(unit)));
                    UsersManager.CurrentPlayer.Units.Add(unit);
                    UsersManager.CurrentPlayer.AllEntities.Add(unit);
                    EntitySelector.EntityPicked = unit;
                }
            }

            if (Input.LeftMouseClick())
            {
                if (EntitySelector.HasPicked())
                {
                    EntitySelector.PlaceEntity();
                }
                else
                {
                    EntitySelector.SelectEntity(
                        DisplayManager.Instance.GraphicsDevice,
                        this.camera.ProjectionMatrix,
                        this.camera.ViewMatrix,
                        allEntities);

                    if (EntitySelector.HasSelected())
                    {
                        var projectedPosition =
                            DisplayManager.Instance.GraphicsDevice.Viewport.Project(
                                EntitySelector.EntitySelected.Position,
                                this.camera.ProjectionMatrix,
                                this.camera.ViewMatrix,
                                Matrix.Identity);

                        this.details = new EntityDetailsLayout(EntitySelector.EntitySelected, PointTextures.TransparentBlackPoint, projectedPosition);
                    }
                }
            }

            if (EntitySelector.HasSelected())
            {
                if (Input.RightMouseDoubleClick)
                {
                    IEntity selected = EntitySelector.EntitySelected;
                    this.CommandSelectedEntity(selected, allEntities.Where(e => e != selected));
                }
            }

            if (this.details != null)
            {
                this.ProjectClickedEntity();
                this.ReadDetailsCommand();
            }

            EntitySelector.DragEntity(
                DisplayManager.Instance.GraphicsDevice,
                this.camera.ProjectionMatrix,
                this.camera.ViewMatrix,
                this.terrain);

            this.skybox.Update(gameTime);
            this.camera.Update(gameTime, this.terrain);
        }