private void OnShipRemoved(Packet<IScenePeer> obj)
 {
     if (_simulation != null)
     {
         var id = obj.ReadObject<ushort>();
         //Console.WriteLine("[" + _name + "] Ship {0} removed ", id);
         lock (_simulation.Environment)
         {
             _simulation.Environment.RemoveShip(id);
         }
     }
 }
 private void OnShipAdded(Packet<IScenePeer> obj)
 {
     //Console.WriteLine("ship.add received");
     if (_simulation != null && _isReady)
     {
         var shipsToAdd = obj.ReadObject<ShipCreatedDto[]>();
         //while (obj.Stream.Position != obj.Stream.Length)
         for (var i = 0; i < shipsToAdd.Length; i++)
         {
             var shipInfos = shipsToAdd[i];
             if (shipInfos.id != this.id && !_simulation.Environment.VisibleShips.ContainsKey(shipInfos.id))
             {
                 var ship = new Ship { Id = shipInfos.id, Team = shipInfos.team, X = shipInfos.x, Status = shipInfos.status, Y = shipInfos.y, Rot = shipInfos.rot, Weapons = shipInfos.weapons };
                 //Console.WriteLine("[" + _name + "] Ship {0} added ", shipInfos.id);
                 lock (_simulation.Environment)
                 {
                     _simulation.Environment.AddShip(ship);
                 }
             }
         }
     }
 }
        private void OnShipStatusChanged(Packet<IScenePeer> obj)
        {
            if (!_isReady)
            {
                return;
            }
            var statusChangedArgs = obj.ReadObject<StatusChangedMsg>();
            if (statusChangedArgs.shipId != this.id)
            {
                if (_simulation.Environment.VisibleShips.ContainsKey(statusChangedArgs.shipId))
                {


                    _simulation.Environment.VisibleShips[statusChangedArgs.shipId].Status = (ShipStatus)statusChangedArgs.status;
                }
            }
            else
            {
                if (_simulation.Boid.Status != ShipStatus.InGame && statusChangedArgs.status == ShipStatus.InGame)
                {
                    _simulation.Reset();
                }
                _simulation.Boid.Status = statusChangedArgs.status;


            }

        }
        private void OnGetMyShipInfos(Packet<IScenePeer> obj)
        {
            var dtos = obj.ReadObject<ShipCreatedDto[]>();
            if (dtos.Length != 1)
            {
                throw new InvalidDataException("Invalid number of dtos");
            }

            var dto = dtos[0];
            Console.WriteLine("[" + _name + "] Ship infos received : {0}", dto.id);
            id = dto.id;
            _simulation.Boid.Id = id;
            _simulation.Boid.X = dto.x;
            _simulation.Boid.Y = dto.y;
            _simulation.Boid.Rot = dto.rot;//= new Simulation(dto.x, dto.y, dto.rot);
            _simulation.Boid.Weapons = dto.weapons.Select(w => new WeaponViewModel { Weapon = w }).ToList();
            _isReady = true;
        }
Exemple #5
0
        public static void HandlePlayerInput(int fromClient, Packet p)
        {
            InputData data = p.ReadObject <InputData>();

            Server.clients[fromClient].player.SetInput(data);
        }