public bool Process(IEvent e)
        {
            if (e is PlayerInputEvent)
            {
                PlayerInputEvent inputEvent = e as PlayerInputEvent;
                Vector2          pos;

                if (!PlayerPositionsByUID.TryGetValue(inputEvent.PlayerUID, out pos))
                {
                    throw new Exception("Player moved that was not yet created: " + inputEvent.PlayerUID);
                }

                PlayerPositionsByUID[inputEvent.PlayerUID] = pos + NetworkGameMaster.DirectionToMovement(inputEvent.Direction);
            }
            else if (e is PlayerCreatedEvent)
            {
                PlayerCreatedEvent createdEvent = e as PlayerCreatedEvent;

                if (PlayerPositionsByUID.ContainsKey(createdEvent.PlayerUID))
                {
                    throw new Exception("Player was created for a second time: " + createdEvent.PlayerUID);
                }

                PlayerPositionsByUID[createdEvent.PlayerUID] = Vector2.zero;
            }

            return(true);
        }
Exemple #2
0
        public static IEvent ApplyMod(EntityManager EM, CreatePlayerMod c)
        {
            NetworkGameMaster  NetworkTester = GameObject.FindObjectOfType <NetworkGameMaster>();
            PlayerEntity       player;
            PlayerCreatedEvent e = new PlayerCreatedEvent();

            // Apply command
            player = EM.GetRegistry <PlayerRegistry>().NewEntity();
            player.PlayerComponent     = GameObject.Instantiate(NetworkTester.PlayerTemplate.gameObject).GetComponent <PlayerComponent>();
            player.PlayerComponent.UID = player.UID;
            e.PlayerUID      = player.uid;
            e.PlayerPhotonID = c.PlayerPhotonID;

            if (NetworkTester.CurrentPlayer == null && PhotonNetwork.player.ID == c.PlayerPhotonID)
            {
                NetworkTester.CurrentPlayer = player;
            }

            return(e);
        }