예제 #1
0
        public override void ReadPacketData(Stream stream)
        {
            var numBlackHoles = ReadInt(stream);

            for (int i = 0; i < numBlackHoles; i++)
            {
                var id        = ReadInt(stream);
                var owner     = stream.ReadByte();
                var position  = ReadVector3(stream);
                var mass      = ReadDouble(stream);
                var blackHole = new Blackhole(owner == 1, mass, position);
                blackHole._id = id;
                Blackholes.Add(blackHole);
            }
            var numPlanets = ReadInt(stream);

            for (int i = 0; i < numPlanets; i++)
            {
                var id     = ReadInt(stream);
                var pos    = ReadVector3(stream);
                var mass   = ReadDouble(stream);
                var size   = ReadDouble(stream);
                var randy  = randall.Next(1, 8);
                var planet = new Spheroid(pos, Vector3.Zero, mass, size, randall.Next(2, 40), randy == 1 ? "earth" : randy == 2 ? "mars" : randy == 3 ? "moon" : randy == 4 ? "neptune" : randy == 5 ? "uranus" : randy == 6 ? "venus" : "ganymede", null);
                planet._id = id;
                Planets.Add(planet);
            }
        }
        void CreateBlackHole(bool id)
        {
            //Send command from client instead.
            Blackhole b = new Blackhole(id, 200, id ? new Vector3(-1000, 250, 0) : new Vector3(1000, 250, 0));

            gravityObjects.Add(b);
            units.Add(b);
        }
        private void UpdateToState(GameStatePacket packet)
        {
            var usedIds = new HashSet <long>();

            foreach (var blackHole in packet.Blackholes)
            {
                var b = gravityObjects.FirstOrDefault(a => a.ID() == blackHole.ID());
                if (b != default(GravitationalField))
                {
                    b.state = new State {
                        v = b.state.v, x = blackHole.Position
                    };
                    b.mass = blackHole.Mass();
                }
                else
                {
                    b = new Blackhole(blackHole.Owner(), blackHole.Mass(), blackHole.Position);
                    gravityObjects.Add(b);
                    units.Add(b);
                }
                usedIds.Add(b.ID());
            }
            foreach (var planet in packet.Planets)
            {
                var p = gravityObjects.FirstOrDefault(a => a.ID() == planet.ID());
                if (p != default(GravitationalField))
                {
                    p.state = new State {
                        v = p.state.v, x = planet.Position()
                    };
                    p.bounds.Center = p.state.x;
                    p.mass          = planet.Mass();
                }
                else
                {
                    var randy = randall.Next(1, 8);
                    p = new Spheroid(planet.Position(), Vector3.Zero, planet.mass, planet.size, randall.Next(2, 40), randy == 1 ? "earth" : randy == 2 ? "mars" : randy == 3 ? "moon" : randy == 4 ? "neptune" : randy == 5 ? "uranus" : randy == 6 ? "venus" : "ganymede", null);
                    gravityObjects.Add(p);
                    units.Add(p);
                }
                usedIds.Add(p.ID());
            }
            gravityObjects = gravityObjects.Where(a => usedIds.Contains(a.ID())).ToList();
            units          = units.Where(a => usedIds.Contains(a.ID())).ToList();
            selectedUnits  = new HashSet <IUnit>(selectedUnits.Where(a => usedIds.Contains(a.ID())));
            if (!selectedUnits.Any())
            {
                selectedUnits.Add(units.First(a => a is Blackhole && ((Blackhole)a).Owner() == IsServer));
            }
        }