Exemple #1
0
        private void Initialize()
        {
            foreach (var project in _context.Projects.Values)
            {
                if (project.InitializeSent)
                {
                    continue;
                }

                WatchProject(project.Path);

                var projectDirectory = Path.GetDirectoryName(project.Path).TrimEnd(Path.DirectorySeparatorChar);

                // Send an InitializeMessage for each project
                var initializeMessage = new InitializeMessage
                {
                    ProjectFolder = projectDirectory,
                };

                // Initialize this project
                _context.Connection.Post(new Message
                {
                    ContextId   = project.ContextId,
                    MessageType = "Initialize",
                    Payload     = JToken.FromObject(initializeMessage),
                    HostId      = _context.HostId
                });

                project.InitializeSent = true;
            }
        }
Exemple #2
0
        private int AddProject(string projectFile)
        {
            Project project;

            if (!_context.TryAddProject(projectFile, out project))
            {
                return(project.ContextId);
            }

            WatchProject(projectFile);

            // Send an InitializeMessage for each project
            var initializeMessage = new InitializeMessage
            {
                ProjectFolder = Path.GetDirectoryName(projectFile),
            };

            // Initialize this project
            _context.Connection.Post(new Message
            {
                ContextId   = project.ContextId,
                MessageType = "Initialize",
                Payload     = JToken.FromObject(initializeMessage),
                HostId      = _context.HostId
            });

            project.InitializeSent = true;
            return(project.ContextId);
        }
        static void InitializeProjects()
        {
            int projectContextId = 0;

            foreach (string projectFile in Directory.EnumerateFiles(solutionPath, "project.json", SearchOption.AllDirectories))
            {
                projectContextId++;

                string projectFolder = Path.GetDirectoryName(projectFile);

                var initializeMessage = new InitializeMessage
                {
                    ProjectFolder = projectFolder
                };

                queue.Post(Message.FromPayload(
                               "Initialize",
                               projectContextId,
                               JToken.FromObject(initializeMessage)));

                var changeConfigMessage = new ChangeConfigurationMessage
                {
                    Configuration = "Release"
                };

                queue.Post(Message.FromPayload(
                               "ChangeConfiguration",
                               projectContextId,
                               JToken.FromObject(changeConfigMessage)));
            }
        }
Exemple #4
0
 public async Task ListenTo(InitializeMessage message)
 {
     Accounts.Clear();
     try
     {
         (await _searchHisoryDataAdapter.LoadAccountsHistory().ConfigureAwait(false))
         ?.ForEach(a => Accounts.Add(a));
     }
     catch (Exception e)
     {
         _applicationMessagesDispatcher.Publish(new ApplicationErrorMessage("Could not load accounts history from local storage", e));
     }
 }
Exemple #5
0
        private bool ProcessMessage()
        {
            Message message;

            lock (_inbox)
            {
                if (!_inbox.Any())
                {
                    return(false);
                }

                message = _inbox.Dequeue();

                // REVIEW: Can this ever happen?
                if (message == null)
                {
                    return(false);
                }
            }

            Logger.TraceInformation("[ApplicationContext]: Received {0}", message.MessageType);

            switch (message.MessageType)
            {
            case "Initialize":
            {
                // This should only be sent once
                if (_initializedContext == null)
                {
                    _initializedContext = message.Sender;

                    var data = new InitializeMessage
                    {
                        Version       = GetValue <int>(message.Payload, "Version"),
                        Configuration = GetValue(message.Payload, "Configuration"),
                        ProjectFolder = GetValue(message.Payload, "ProjectFolder")
                    };

                    _appPath.Value       = data.ProjectFolder;
                    _configuration.Value = data.Configuration ?? "Debug";

                    // Therefore context protocol version is set only when the version is not 0 (meaning 'Version'
                    // protocol is not missing) and protocol version is not overridden by environment variable.
                    if (data.Version != 0 && !_protocolManager.EnvironmentOverridden)
                    {
                        _contextProtocolVersion = Math.Min(data.Version, _protocolManager.MaxVersion);
                        Logger.TraceInformation($"[{nameof(ApplicationContext)}]: Set context protocol version to {_contextProtocolVersion.Value}");
                    }
                }
                else
                {
                    Logger.TraceInformation("[ApplicationContext]: Received Initialize message more than once for {0}", _appPath.Value);
                }
            }
            break;

            case "Teardown":
            {
                // TODO: Implement
            }
            break;

            case "ChangeConfiguration":
            {
                var data = new ChangeConfigurationMessage
                {
                    Configuration = GetValue(message.Payload, "Configuration")
                };
                _configuration.Value = data.Configuration;
            }
            break;

            case "RefreshDependencies":
            case "RestoreComplete":
            {
                _refreshDependencies.Value = default(Void);
            }
            break;

            case "Rebuild":
            {
                _rebuild.Value = default(Void);
            }
            break;

            case "FilesChanged":
            {
                _filesChanged.Value = default(Void);
            }
            break;

            case "GetCompiledAssembly":
            {
                var libraryKey = new RemoteLibraryKey
                {
                    Name            = GetValue(message.Payload, "Name"),
                    TargetFramework = GetValue(message.Payload, "TargetFramework"),
                    Configuration   = GetValue(message.Payload, "Configuration"),
                    Aspect          = GetValue(message.Payload, "Aspect"),
                    Version         = GetValue <int>(message.Payload, nameof(RemoteLibraryKey.Version)),
                };

                var targetFramework = new FrameworkName(libraryKey.TargetFramework);

                // Only set this the first time for the project
                if (!_requiresAssemblies.ContainsKey(targetFramework))
                {
                    _requiresAssemblies[targetFramework] = new Trigger <Void>();
                }

                _requiresAssemblies[targetFramework].Value = default(Void);

                List <CompiledAssemblyState> waitingForCompiledAssemblies;
                if (!_waitingForCompiledAssemblies.TryGetValue(targetFramework, out waitingForCompiledAssemblies))
                {
                    waitingForCompiledAssemblies = new List <CompiledAssemblyState>();
                    _waitingForCompiledAssemblies[targetFramework] = waitingForCompiledAssemblies;
                }

                waitingForCompiledAssemblies.Add(new CompiledAssemblyState
                    {
                        Connection = message.Sender,
                        Version    = libraryKey.Version
                    });
            }
            break;

            case "GetDiagnostics":
            {
                _requiresCompilation.Value = default(Void);

                _waitingForDiagnostics.Add(message.Sender);
            }
            break;

            case "Plugin":
            {
                var pluginMessage = message.Payload.ToObject <PluginMessage>();
                var result        = _pluginHandler.OnReceive(pluginMessage);

                _refreshDependencies.Value = default(Void);
                _pluginWorkNeeded.Value    = default(Void);

                if (result == PluginHandlerOnReceiveResult.RefreshDependencies)
                {
                    _refreshDependencies.Value = default(Void);
                }
            }
            break;
            }

            return(true);
        }
        private static void Go(string runtimePath, string applicationRoot)
        {
            var hostId = Guid.NewGuid().ToString();
            var port   = 1334;

            // Show runtime output
            var showRuntimeOutput = true;

            StartRuntime(runtimePath, hostId, port, showRuntimeOutput, () =>
            {
                var socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
                socket.Connect(new IPEndPoint(IPAddress.Loopback, port));

                var networkStream = new NetworkStream(socket);

                Console.WriteLine("Connected");

                var mapping  = new Dictionary <int, string>();
                var messages = new ConcurrentDictionary <int, List <Message> >();
                var queue    = new ProcessingQueue(networkStream);

                queue.OnReceive += m =>
                {
                    // Get the project associated with this message
                    var projectPath = mapping[m.ContextId];

                    // This is where we can handle messages and update the
                    // language service
                    if (m.MessageType == "References")
                    {
                        // References as well as the dependency graph information
                        // var val = m.Payload.ToObject<ReferencesMessage>();
                    }
                    else if (m.MessageType == "Diagnostics")
                    {
                        // Errors and warnings
                        // var val = m.Payload.ToObject<DiagnosticsMessage>();
                    }
                    else if (m.MessageType == "Configurations")
                    {
                        // Configuration and compiler options
                        // var val = m.Payload.ToObject<ConfigurationsMessage>();
                    }
                    else if (m.MessageType == "Sources")
                    {
                        // The sources to feed to the language service
                        // var val = m.Payload.ToObject<SourcesMessage>();
                    }
                };

                // Start the message channel
                queue.Start();

                var solutionPath = applicationRoot;
                var watcher      = new FileWatcher(solutionPath);
                var projects     = new Dictionary <string, int>();
                int contextId    = 0;

                foreach (var projectFile in Directory.EnumerateFiles(solutionPath, "project.json", SearchOption.AllDirectories))
                {
                    string projectPath = Path.GetDirectoryName(projectFile).TrimEnd(Path.DirectorySeparatorChar);

                    // Send an InitializeMessage for each project
                    var initializeMessage = new InitializeMessage
                    {
                        ProjectFolder = projectPath,
                    };

                    // Create a unique id for this project
                    int projectContextId = contextId++;

                    // Create a mapping from path to contextid and back
                    projects[projectPath]     = projectContextId;
                    mapping[projectContextId] = projectPath;

                    // Initialize this project
                    queue.Post(new Message
                    {
                        ContextId   = projectContextId,
                        MessageType = "Initialize",
                        Payload     = JToken.FromObject(initializeMessage),
                        HostId      = hostId
                    });

                    // Watch the project.json file
                    watcher.WatchFile(Path.Combine(projectPath, "project.json"));
                    watcher.WatchDirectory(projectPath, ".cs");

                    // Watch all directories for cs files
                    foreach (var cs in Directory.GetFiles(projectPath, "*.cs", SearchOption.AllDirectories))
                    {
                        watcher.WatchFile(cs);
                    }

                    foreach (var d in Directory.GetDirectories(projectPath, "*.*", SearchOption.AllDirectories))
                    {
                        watcher.WatchDirectory(d, ".cs");
                    }
                }

                // When there's a file change
                watcher.OnChanged += changedPath =>
                {
                    foreach (var project in projects)
                    {
                        // If the project changed
                        if (changedPath.StartsWith(project.Key, StringComparison.OrdinalIgnoreCase))
                        {
                            queue.Post(new Message
                            {
                                ContextId   = project.Value,
                                MessageType = "FilesChanged",
                                HostId      = hostId
                            });
                        }
                    }
                };
            });

            Console.WriteLine("Process Q to exit");

            while (true)
            {
                var ki = Console.ReadKey(true);

                if (ki.Key == ConsoleKey.Q)
                {
                    break;
                }
            }
        }
Exemple #7
0
        void OnInitialise(InitializeMessage msg)
        {
            RegisterResources();

            //add the camera to view the scene
            Entity camera = Owner.CreateEntity();
            camera.AddComponent(new Camera());

            camera.Transform = Matrix.CreateWorld(new Vector3(0, -1, 1), -Vector3.UnitZ, Vector3.UnitY);

            //create carré rouge
            Entity eleve = Owner.CreateEntity();
            camera.AddComponent(new FollowEntity(eleve, 0.5f * Vector3.UnitY, false, true));
            Vector2 bodySize = IMAGE_SCALE * new Vector2(50, 50);
            m_EZBakeOven.MakeSprite(eleve, bodySize, "Eleve", 4, 10);
            eleve.AddComponent(m_Physics.CreateRectangle(0.5f * bodySize, 1.0f, FarseerPhysics.Dynamics.BodyType.Dynamic));
            m_Physics.ConstrainAngle(0, float.MaxValue, 0, eleve);
            eleve.AddComponent(new Eleve(2, .1f));

            //create policier
               Entity policier = Owner.CreateEntity();
               policier.Transform = Matrix.CreateTranslation(Vector3.UnitY);
            m_EZBakeOven.MakeSprite(policier, IMAGE_SCALE * new Vector2(122, 48), "PoliceDos", 4, 10);
            //policier.GetComponent<RenderSettings>().BlendState = BlendState.Additive;

            Vector3 background_translation = -0.5f * Vector3.UnitY;
            CreateBackground(camera, background_translation);

            //add grass in front of everything
            Entity grass = Owner.CreateEntity();
            grass.Transform = Matrix.CreateTranslation(background_translation);
            grass.AddComponent(new FollowEntity(camera, Vector3.Zero, false, true));
            m_EZBakeOven.MakeParallaxSprite(grass, IMAGE_SCALE * new Vector2(800, 600), "grass", 1.0f);

            ResourceLoader loader = Owner.GetComponent<ResourceLoader>();
            loader.ForceLoadAll(); // so as to not have glitches in the first couple seconds while all the items are loaded as they are accessed

            // enter: The Queen!
            loader.GetResource("fanfare").Get<SoundEffect>().Play();
        }
Exemple #8
0
        void OnInitialise(InitializeMessage msg)
        {
            RegisterResources();

            //add the camera to view the scene
            Entity camera = Owner.CreateEntity();
            camera.AddComponent(new Camera());

            camera.Transform = Matrix.CreateWorld(new Vector3(0, -1, 1), -Vector3.UnitZ, Vector3.UnitY);

            Entity background = Owner.CreateEntity();
            Vector2 backsize = IMAGE_SCALE * DESIRED_SCREEN_SIZE;
            m_EZBakeOven.MakeParallaxSprite(background, backsize, "Background", 0.9f);

            //create carré rouge
            Entity eleve = Owner.CreateEntity();
            camera.AddComponent(new FollowEntity(eleve, 0.5f * Vector3.UnitY, false, false));
            eleve.AddComponent(new GamepadComponent());
            Vector2 bodySize = IMAGE_SCALE * new Vector2(50, 50);
            m_EZBakeOven.MakeSprite(eleve, bodySize, "Eleve", 4, 10);
            eleve.AddComponent(m_Physics.CreateRectangle(0.5f * bodySize, 1.0f, FarseerPhysics.Dynamics.BodyType.Dynamic));
            eleve.AddComponent(new Eleve(1f));
            eleve.Name = "Eleve";

            //CARRÉ ROUGE TEST
            Entity eleve2 = Owner.CreateEntity();
            ////eleve2.Transform = Matrix.CreateTranslation(-1.0f, -1.0f, 0.0f);
            Vector2 bodySize2 = IMAGE_SCALE * new Vector2(50, 50);
            m_EZBakeOven.MakeSprite(eleve2, bodySize2, "Eleve", 4, 10);
            eleve2.AddComponent(m_Physics.CreateRectangle(0.5f * bodySize2, 1.0f, FarseerPhysics.Dynamics.BodyType.Dynamic));
            //eleve2.AddComponent(new Eleve(1f));

            ResourceLoader loader = Owner.GetComponent<ResourceLoader>();
            loader.ForceLoadAll();

            // enter: The Queen!
            loader.GetResource("fanfare").Get<SoundEffect>().Play();
        }
Exemple #9
0
        void OnInitialise(InitializeMessage msg)
        {
            RegisterResources();

            //add the camera to view the scene
            Entity camera = Owner.CreateEntity();
            camera.AddComponent(new Camera());

            camera.Transform = Matrix.CreateWorld(new Vector3(0, -1, 1), -Vector3.UnitZ, Vector3.UnitY);

            Entity queen = Owner.CreateEntity();

            //make camera follow queen
            camera.AddComponent(new FollowEntity(queen, 0.5f * Vector3.UnitY, false, true));

            Vector3 background_translation = -0.5f * Vector3.UnitY;
            CreateBackground(camera, background_translation);

            //create fanboys
            CreateBeefeater(new Vector3(4, -2, 0));
            CreateBeefeater(new Vector3(3, -2, 0));
            CreateBeefeater(new Vector3(2, -2, 0));
            CreateBeefeater(new Vector3(-2, -2, 0));
            CreateBeefeater(new Vector3(-3, -2, 0));
            CreateBeefeater(new Vector3(-4, -2, 0));

            //create body
            queen.Transform = Matrix.CreateTranslation(-1.5f * Vector3.UnitY);
            Vector2 bodySize = IMAGE_SCALE * new Vector2(300, 198);

            queen.AddComponent(m_Physics.CreateRectangle(0.5f * bodySize, 1.0f, FarseerPhysics.Dynamics.BodyType.Dynamic));
            m_Physics.ConstrainAngle(0, 0.01f, 0.4f, queen); //make body stay upright

            queen.AddComponent(new Selectable(new BoundingBox(new Vector3(-0.5f * bodySize, -2), new Vector3(0.5f * bodySize, 2))));
            queen.AddComponent(new FollowFinger());
            queen.AddComponent(new Queen(2, 10));
            m_EZBakeOven.MakeSprite(queen, bodySize, "body");

            //create neck
            Entity neck = queen.CreateChild();
            neck.Transform = Matrix.CreateTranslation(1.5f * Vector3.UnitY);

            //create head
            Entity head = neck.CreateChild();
            head.AddComponent(new LeftRightComponent(-30, 30, 0.75f, -0.5f * 1.7f * Vector3.UnitY));
            head.AddComponent(m_Physics.CreateCapsule(0.25f, 0.5f, 1.0f, FarseerPhysics.Dynamics.BodyType.Static));
            head.AddComponent(new SoundOnCollision());
            head.AddComponent(new Handle<SoundEffect>("laugh"));
            m_EZBakeOven.MakeSprite(head, IMAGE_SCALE * new Vector2(152, 175), "head");

            //create mouth hinge
            Entity mouthHinge = head.CreateChild();
            mouthHinge.Transform = Matrix.CreateTranslation(-0.85f * Vector3.UnitY);

            //create mouth
            Entity mouth = mouthHinge.CreateChild();
            mouth.AddComponent(new UpDownComponent(-0.2f, 0, 0.3f, Vector3.UnitY));
            m_EZBakeOven.MakeSprite(mouth, IMAGE_SCALE * new Vector2(79, 30), "mouth");

            //create flowers
            foreach(int i in Enumerable.Range(1, 10))
            {
                Entity flowers = Owner.CreateEntity();
                flowers.Transform = Matrix.CreateTranslation((2 + i * 1) * Vector3.UnitY + ((float)m_Rand.NextDouble() - 0.5f) * Vector3.UnitX);
                flowers.AddComponent(m_Physics.CreateTriangle(0.25f, 0.5f, 1, FarseerPhysics.Dynamics.BodyType.Dynamic));

                m_EZBakeOven.MakeSprite(flowers, IMAGE_SCALE * new Vector2(100, 100), "flowers");
            }

            //create cake
            Entity cake = Owner.CreateEntity();
            cake.Transform = Matrix.CreateTranslation(-2 * Vector3.UnitY);
            m_EZBakeOven.MakeSprite(cake, IMAGE_SCALE * new Vector2(200, 200), "cake");

            //create flame
            Entity flame = cake.CreateChild();
            flame.Transform = Matrix.CreateTranslation(Vector3.UnitY);
            m_EZBakeOven.MakeSprite(flame, IMAGE_SCALE * new Vector2(100, 100), "flame", 4, 10);
            flame.GetComponent<RenderSettings>().BlendState = BlendState.Additive;

            //add grass in front of everything
            Entity grass = Owner.CreateEntity();
            grass.Transform = Matrix.CreateTranslation(background_translation);
            grass.AddComponent(new FollowEntity(camera, Vector3.Zero, false, true));
            m_EZBakeOven.MakeParallaxSprite(grass, IMAGE_SCALE * new Vector2(800, 600), "grass", 1.0f);

            ResourceLoader loader = Owner.GetComponent<ResourceLoader>();
            loader.ForceLoadAll(); // so as to not have glitches in the first couple seconds while all the items are loaded as they are accessed

            // enter: The Queen!
            loader.GetResource("fanfare").Get<SoundEffect>().Play();
        }
Exemple #10
0
 private void HandleInitMessage(InitializeMessage message)
 {
     CurrentPlayer.Id = message.Id;
 }
Exemple #11
0
        void OnInitialise(InitializeMessage msg)
        {
            RegisterResources();

            //add the camera to view the scene
            Entity camera = Owner.CreateEntity();
            camera.AddComponent(new Camera());

            camera.Transform = Matrix.CreateWorld(new Vector3(0, -1, 1), -Vector3.UnitZ, Vector3.UnitY);

            Entity background = Owner.CreateEntity();
            background.Transform = Matrix.CreateRotationZ(MathHelper.ToRadians(34f));
            m_EZBakeOven.MakeSprite(background, IMAGE_SCALE * WORLD_SIZE, "emily_gamelin");

            Entity character = Owner.CreateEntity();
            m_EZBakeOven.MakeSprite(character, 0.002f * new Vector2(300, 289), "player");
            character.AddComponent(m_Physics.CreateCircle(0.1f, 1, FarseerPhysics.Dynamics.BodyType.Dynamic));
            character.GetComponent<PhysicsComponent>().LinearDamping = 3;
            character.GetComponent<PhysicsComponent>().AngularDamping = 1000;
            character.AddComponent(new MainCharacter(1));

            Entity characterJoint = character.CreateChild();
            characterJoint.AddComponent(m_Physics.CreateCircle(0.8f, 1, FarseerPhysics.Dynamics.BodyType.Static));
            characterJoint.GetComponent<PhysicsComponent>().IsSensor = true;
            characterJoint.AddComponent(new Recruter());

            m_Physics.ConstrainAngle(0, 0.0003f, 0.2f, character);

            camera.AddComponent(new FollowEntity(character, Vector3.Zero));

            Entity building = Owner.CreateEntity();
            building.Transform = Matrix.CreateTranslation( new Vector3(1, 1, 0) );
            building.AddComponent(m_Physics.CreateRectangle(new Vector2(2, 4), 1, FarseerPhysics.Dynamics.BodyType.Static));

            for (int i = 0; i < 10; i++)
            {
                Entity manifestant = Owner.CreateEntity();
                manifestant.Transform = Matrix.CreateTranslation(new Vector3(-0.3f * i, -0.3f * i, 0));
                m_EZBakeOven.MakeSprite(manifestant, 0.002f * new Vector2(300, 289), "manifestant");
                manifestant.AddComponent(m_Physics.CreateCircle(0.1f, 1, FarseerPhysics.Dynamics.BodyType.Dynamic));
                manifestant.GetComponent<PhysicsComponent>().LinearDamping = 2;
                manifestant.AddComponent(new Manifestant(0.15f));
                manifestant.AddComponent(new Recrutable());
            }

            Entity police = Owner.CreateEntity();
            police.Transform = Matrix.CreateTranslation(new Vector3(-2, -2, 0));
            m_EZBakeOven.MakeSprite(police, 0.005f * new Vector2(300, 289), "police");
            police.AddComponent(m_Physics.CreateCircle(0.25f, 1, FarseerPhysics.Dynamics.BodyType.Dynamic));
            police.GetComponent<PhysicsComponent>().LinearDamping = 2;
            police.AddComponent(new Police(0.25f));

            ResourceLoader loader = Owner.GetComponent<ResourceLoader>();
            loader.ForceLoadAll(); // so as to not have glitches in the first couple seconds while all the items are loaded as they are accessed
        }
Exemple #12
0
        void OnInitialise(InitializeMessage msg)
        {
            RegisterResources();

            //add the camera to view the scene
            Entity camera = Owner.CreateEntity();
            camera.AddComponent(new Camera());

            camera.Transform = Matrix.CreateWorld(new Vector3(0, -1, 1), -Vector3.UnitZ, Vector3.UnitY);

            CreateBackground();

            Entity character = Owner.CreateEntity();
            m_EZBakeOven.MakeSprite(character, 0.007f * new Vector2(24, 27), "panda_dos",4,5);
            character.AddComponent(m_Physics.CreateCircle(0.1f, 1, FarseerPhysics.Dynamics.BodyType.Dynamic));
            character.GetComponent<PhysicsComponent>().LinearDamping = 3;
            character.GetComponent<PhysicsComponent>().AngularDamping = 1000;
            character.AddComponent(new MainCharacter(1));
            character.AddComponent(new Recruter());

            Entity radiusBillboard = character.CreateChild();
            m_EZBakeOven.MakeSprite(radiusBillboard, new Vector2(2, 2), "radius");
            radiusBillboard.AddComponent(new InfluenceComponent());

            Entity zone = Owner.CreateEntity();
            zone.Transform = Matrix.CreateTranslation(new Vector3(-5, -9, 0));
            m_EZBakeOven.MakeSprite(zone, 0.005f * new Vector2(600, 303), "finish");
            zone.AddComponent(m_Physics.CreateRectangle(new Vector2(2, 1), 1, FarseerPhysics.Dynamics.BodyType.Static));
            zone.GetComponent<PhysicsComponent>().IsSensor = true;
            zone.AddComponent(new EndZone());

            Entity characterJoint = character.CreateChild();
            characterJoint.AddComponent(m_Physics.CreateCircle(0.8f, 1, FarseerPhysics.Dynamics.BodyType.Static));
            characterJoint.GetComponent<PhysicsComponent>().IsSensor = true;
            characterJoint.AddComponent(new Recruter());

            m_Physics.ConstrainAngle(0, 0.0003f, 0.2f, character);

            camera.AddComponent(new FollowEntity(character, Vector3.Zero));

            CreateManifestants(Vector3.Zero);

            CreateManifestants(new Vector3(8, 5, 0));

            CreateManifestants(new Vector3(-5, 7, 0));

            CreateManifestants(new Vector3(-6, -7, 0));

               for(int i=0;i < 10;i++)
            {

               Entity carreVert = Owner.CreateEntity();
            carreVert.Transform = Matrix.CreateTranslation(new Vector3(-1.1f*i, -0.9f*i, 0));

            m_EZBakeOven.MakeSprite(carreVert, 0.006f * new Vector2(21, 25), "vert_face");
            carreVert.AddComponent(m_Physics.CreateCircle(0.1f, 1, FarseerPhysics.Dynamics.BodyType.Dynamic));
            carreVert.GetComponent<PhysicsComponent>().LinearDamping = 2;
            carreVert.AddComponent(new CarreVert());
            carreVert.AddComponent(new Recrutable());
            }
            int policecount = 10;
            Matrix pos = Matrix.CreateTranslation(new Vector3(0, 5, 0));
            Matrix rot = Matrix.CreateRotationZ(MathHelper.TwoPi / policecount);

            for (int i = 0; i < policecount; i++)
            {
                Entity police = Owner.CreateEntity();
                police.Transform = pos;
                m_EZBakeOven.MakeSprite(police, 0.001f * new Vector2(300, 289), "police_bas", 3, 2);
                police.AddComponent(m_Physics.CreateCircle(0.1f, 1, FarseerPhysics.Dynamics.BodyType.Dynamic));
                police.GetComponent<PhysicsComponent>().LinearDamping = 4;
                police.AddComponent(new Police(0.1f, 4));
                police.AddComponent(new Recrutable());

                m_Physics.ConstrainAngle(0, float.MaxValue, 0, police);

                pos *= rot;
            }

            ResourceLoader loader = Owner.GetComponent<ResourceLoader>();
            loader.ForceLoadAll(); // so as to not have glitches in the first couple seconds while all the items are loaded as they are accessed

            m_MusicInstance = loader.GetResource("theme").Get<SoundEffect>().CreateInstance();
            m_MusicInstance.IsLooped = true;
            m_MusicInstance.Play();
        }
Exemple #13
0
    void OnEvent(byte eventCode, object content, int senderId)
    {
        int i;
        BaseObjectMessage baseObjectMessage;
        PlayerObject      playerObject     = null;
        PlayerController  playerController = null;

        //Debug.Log("RECEIVE EVENT[" + eventCode + "] from [" + senderId + "]");
        switch (eventCode)
        {
        case 1:
            baseObjectMessage = new BaseObjectMessage();
            baseObjectMessage.Unpack((byte[])content);
            remoteTimestamp = baseObjectMessage.timemark;
            gameNetwork.ClientInit();
            gameNetwork.playerId = baseObjectMessage.id;
            Debug.Log("INITIALIZE PLAYER ID: " + gameNetwork.playerId);
            /* duplicate for GameNetwork RpcSpawnObject case PLAYER */
            playerObject = (PlayerObject)gameNetwork.location.GetObject(gameNetwork.playerId);
            if (playerObject != null)
            {
                camera.transform.position = playerObject.position * 100.0f + Vector3.up * 20.0f;
                if (gameNetwork.playerId == 1)
                {
                    camera.transform.eulerAngles = new Vector3(camera.transform.eulerAngles.x, 180.0f, camera.transform.eulerAngles.z);
                }
            }
            playerObject = (PlayerObject)gameNetwork.location.GetObject(gameNetwork.playerId == 1 ? 0 : 1);
            if (playerObject != null && playerObject.visualObject == null)
            {
                playerController                    = (Instantiate(gameNetwork.bodyPrefabs[0])).GetComponent <PlayerController>();
                playerController.gameNetwork        = gameNetwork;
                playerController.obj                = playerObject;
                playerObject.visualObject           = playerController;
                playerController.transform.position = playerObject.position * 100.0f;
                //playerController.transform.localScale *= 10.0f;
                if (playerObject.position.z < 0.0f)
                {
                    playerObject.visualObject.transform.Rotate(0.0f, 180.0f, 0.0f);
                }
            }
            /* */
            canvasPlay.enabled = true;

            InitializeMessage initializeMessage = new InitializeMessage();
            for (i = 1; i < AbilityButtons.Length; i++)
            {
                if (AbilityButtons[i].image.color == Color.green)
                {
                    if (initializeMessage.abilityFirstId <= -1)
                    {
                        initializeMessage.abilityFirstId = i;
                    }
                    else
                    {
                        initializeMessage.abilitySecondId = i;
                    }
                }
            }
            gameNetwork.myMissileId     = armedMissile.GetCurrentMissile();
            initializeMessage.missileId = gameNetwork.myMissileId;
            for (i = 1; i < VenomButtons.Length; i++)
            {
                if (VenomButtons[i].image.color == Color.green)
                {
                    initializeMessage.venomId = i;
                }
            }
            PhotonNetwork.networkingPeer.OpCustom((byte)1, new Dictionary <byte, object> {
                { 245, initializeMessage.Pack() }
            }, true);

            break;

        case 2:
            SpawnObjectMessage spawnObjectMessage = new SpawnObjectMessage();
            spawnObjectMessage.Unpack((byte[])content);
            //Debug.Log(Time.fixedTime + " Spawn." + spawnObjectMessage.objectType + " [" + spawnObjectMessage.id + "]");
            spawnObjectMessage.eventCode = eventCode;
            delayedMessages.AddLast(spawnObjectMessage);
            //gameNetwork.RpcSpawnObject(spawnObjectMessage.id, spawnObjectMessage.objectType, spawnObjectMessage.newPosition, spawnObjectMessage.newFloat, spawnObjectMessage.visualId);
            break;

        case 3:
            DestroyObjectMessage destroyObjectMessage = new DestroyObjectMessage();
            destroyObjectMessage.Unpack((byte[])content);
            //Debug.Log(Time.fixedTime + " Destroy [" + destroyObjectMessage.id + "]: " + destroyObjectMessage.objectId);
            destroyObjectMessage.eventCode = eventCode;
            delayedMessages.AddLast(destroyObjectMessage);
            //gameNetwork.RpcDestroyObject(destroyObjectMessage.id);
            break;

        case 4:
            MoveObjectMessage moveObjectMessage = new MoveObjectMessage();
            moveObjectMessage.Unpack((byte[])content);
            //Debug.Log(Time.fixedTime + " Move [" + moveObjectMessage.id + "]");
            moveObjectMessage.eventCode = eventCode;
            delayedMessages.AddLast(moveObjectMessage);
            //gameNetwork.RpcMoveObject(moveObjectMessage.id, moveObjectMessage.newPosition, moveObjectMessage.newFloat, moveObjectMessage.timestamp);
            break;

        case 5:
            UpdatePlayerMessage updatePlayerMessage = new UpdatePlayerMessage();
            updatePlayerMessage.Unpack((byte[])content);
            //Debug.Log("Player[" + updatePlayerMessage.id + "] health: " + updatePlayerMessage.newHealth + " ; stamina: " + updatePlayerMessage.newStamina);
            gameNetwork.RpcUpdatePlayer(updatePlayerMessage.id, updatePlayerMessage.newHealth, updatePlayerMessage.newStamina, updatePlayerMessage.newStaminaConsumption);
            break;

        case 6:
            gameNetwork.RpcRearmMissile();
            break;

        case 7:
            baseObjectMessage = new BaseObjectMessage();
            baseObjectMessage.Unpack((byte[])content);
            gameNetwork.RpcFlashPlayer(baseObjectMessage.id);
            break;

        case 8:
            GameOverMessage gameOverMessage = new GameOverMessage();
            gameOverMessage.Unpack((byte[])content);
            gameNetwork.RpcGameOver(gameOverMessage.winner, gameOverMessage.time, gameOverMessage.damage, gameOverMessage.wound);

            gameNetwork                = GameObject.Instantiate(gameNetworkPrefab).GetComponent <GameNetwork>();
            gameNetwork.camera         = camera;
            gameNetwork.gameMatchMaker = this;
            gameNetwork.isServer       = false;
            gameNetwork.isLocal        = false;

            break;

        case 9:
            SetAbilityMessage setAbilityMessage = new SetAbilityMessage();
            setAbilityMessage.Unpack((byte[])content);
            gameNetwork.RpcSetAbility(setAbilityMessage.id, setAbilityMessage.value);
            break;

        case 10:
            NoticeMessage noticeMessage = new NoticeMessage();
            noticeMessage.Unpack((byte[])content);
            //Debug.Log("GET NOTICE MESSAGE. timemark: " + noticeMessage.timemark + " ; numericValue: " + noticeMessage.numericValue);
            noticeMessage.eventCode = eventCode;
            delayedMessages.AddLast(noticeMessage);
            break;

        case 11:
            baseObjectMessage = new BaseObjectMessage();
            baseObjectMessage.Unpack((byte[])content);
            Debug.Log("RECEIVE FLASH PASSIVE ABILITY. timemark: " + baseObjectMessage.timemark);
            baseObjectMessage.eventCode = eventCode;
            delayedMessages.AddLast(baseObjectMessage);
            break;

        case 12:
            baseObjectMessage = new BaseObjectMessage();
            baseObjectMessage.Unpack((byte[])content);
            //Debug.Log("FLASH OBSTRUCTION[" + baseObjectMessage.id + "]. timemark: " + baseObjectMessage.timemark);
            gameNetwork.RpcFlashObstruction(baseObjectMessage.id);
            break;

        case 13:
            VisualEffectMessage visualEffectMessage = new VisualEffectMessage();
            visualEffectMessage.Unpack((byte[])content);
            Debug.Log("VISUAL EFFECT [" + visualEffectMessage.id + "]. targetId: " + visualEffectMessage.targetId);
            visualEffectMessage.eventCode = eventCode;
            delayedMessages.AddLast(visualEffectMessage);
            break;

        case 14:
            PingMessage pingMessage = new PingMessage();
            PingMessage newPingMessage;
            pingMessage.Unpack((byte[])content);
            if (pingMessage.time == 0.0f)
            {
                newPingMessage = new PingMessage(remoteTimestamp, pingMessage.timemark);
                PhotonNetwork.networkingPeer.OpCustom((byte)4, new Dictionary <byte, object> {
                    { 245, newPingMessage.Pack() }
                }, true);
            }
            else
            {
                remoteTimestamp = pingMessage.timemark + pingMessage.time / 2.0f;
            }
            break;
        }
    }