Ejemplo n.º 1
0
        public static void DoSync()
        {
            lock (Server.ClientsLock) {
                for (int i = 0; i < Server.ClientControllers.Count; i++)
                {
                    if (Server.ClientControllers[i].MissionController == null)
                    {
                        continue;
                    }

                    BaseMission mission = Server.ClientControllers[i].MissionController.Mission;

                    if (Server.ClientControllers[i] != null && Server.ClientControllers[i].Actualy)
                    {
                        NetDataEvent allResponse = new NetDataEvent(EventTypes.SyncMission, new Dictionary <string, ObjectWrapper>()
                        {
                            { "mission", new ObjectWrapper <BaseMission>(mission) }
                        });

                        lock (Server.ClientControllers[i].MissionController.Locker) {
                            Server.SendEvent(Server.ClientControllers[i], Utils.ToBytesJSON(allResponse), "EventGameManagerHandleSyncMission");
                        }

                        Server.ClientControllers[i].MissionFirstInited = true;
                    }
                }
            }
        }
Ejemplo n.º 2
0
    //начали миссию
    private void OnStartedMission(byte[] data)
    {
        NetDataEvent netData = Utils.FromBytesJSON <NetDataEvent>(data);

        TransitionManager.I.LoadGame();

        NetManager.I.Client.UnityEventReceiver.RemoveEventObserver(startMissionID);
    }
Ejemplo n.º 3
0
        public static void DoHandle()
        {
            NetDataEvent allResponse = new NetDataEvent(EventTypes.SendRooms, new Dictionary <string, ObjectWrapper>()
            {
                { "rooms", new ObjectWrapper <List <Room> >(Server.GetRooms()) }
            });

            Server.SendEvent(Server.ClientControllers, Utils.ToBytesJSON(allResponse), "EventLobbyHolderOnGetRooms");
        }
Ejemplo n.º 4
0
    private void HandleLeaveMission(byte[] data)
    {
        NetDataEvent ndata = Utils.FromBytesJSON <NetDataEvent>(data);

        Player pl = players.First(x => x.ID.Equals((string)ndata.Values["id"].ObjectValue));

        players.Remove(pl);
        Destroy(pl.gameObject);
    }
Ejemplo n.º 5
0
    private void HandleNewWawe(byte[] data)
    {
        NetDataEvent netData = Utils.FromBytesJSON <NetDataEvent>(data);

        int waveNumber = (int)netData.Values["wave_number"].ObjectValue;

        waveNumberText.text = string.Format("Wave {0}", waveNumber);

        waveNumberText.GetComponent <TweenScale>().ResetToBeginning();
        waveNumberText.GetComponent <TweenScale>().PlayForward();
    }
Ejemplo n.º 6
0
        public static void DoHandle(string roomID)
        {
            RoomController room = Server.RoomControllers.Find(x => x.Room.ID.Equals(roomID));

            NetDataEvent allResponse = new NetDataEvent(EventTypes.SyncRoom, new Dictionary <string, ObjectWrapper>()
            {
                { "room", new ObjectWrapper <Room>(room.Room) }
            });

            Server.SendEvent(room.Clients, Utils.ToBytesJSON(allResponse), "EventRoomHolderOnSyncRoom");
        }
Ejemplo n.º 7
0
        public static void DoHandle(NetDataRequest data, ClientController client, string networkID)
        {
            Room room = Server.GetRooms().Find(x => x.ID.Equals(data.Values["id"].ObjectValue as string));

            NetDataEvent allResponse = new NetDataEvent(EventTypes.SyncRoom, new Dictionary <string, ObjectWrapper>()
            {
                { "room", new ObjectWrapper <Room>(room) }
            });

            Server.SendResponse(client, Utils.ToBytesJSON(allResponse), networkID);
        }
Ejemplo n.º 8
0
        public static void DoHandle(ClientController client)
        {
            List <ClientController> clients = new List <ClientController>(Server.ClientControllers);

            clients.RemoveAll(x => x.Client == client.Client);
            clients.RemoveAll(x => !x.Actualy);

            NetDataEvent allResponse = new NetDataEvent(EventTypes.LeaveMission, new Dictionary <string, ObjectWrapper>()
            {
                { "id", new ObjectWrapper <string>(client.Client.ID) }
            });

            Server.SendEvent(clients, Utils.ToBytesJSON(allResponse), "EventGameManagerHandleLeaveMission");
        }
Ejemplo n.º 9
0
    private void HandleSyncMission(byte[] data)
    {
        NetDataEvent ndata = Utils.FromBytesJSON <NetDataEvent>(data);

        BaseMission mission = (BaseMission)ndata.Values["mission"].ObjectValue;

        if (mission.Objects == null)
        {
            mission.Objects = new Dictionary <string, BaseMissionObject>();
        }
        if (mission.DynamicObjects == null)
        {
            mission.DynamicObjects = new Dictionary <string, BaseMissionObject>();
        }

        Dictionary <string, BaseMissionObject> objects = mission.Objects;

        MergeDictionary(objects, mission.DynamicObjects);

        //instantiate objects on client created on server
        foreach (var o in objects.ToList())
        {
            if (o.Value.Destroyed)
            {
                continue;
            }

            bool isOwn = o.Value.OwnerID.Equals(NetManager.I.ID);

            if (!NetworkObjectDispenser.I.Objects.ContainsKey(o.Value.ID))
            {
                GameObject go = SpawnObject(o.Value.ID, o.Value.NameID, o.Value.Position.FromServerVector3(), o.Value.Center.FromServerVector3(), o.Value.Size.FromServerVector3(), o.Value.EulerAngles.FromServerVector3(), isOwn);

                if (o.Value is PlayerObject)
                {
                    players.Add(go.GetComponent <Player>());

                    if (isOwn)
                    {
                        CameraController.I.Target = go;
                    }
                }
            }
        }

        //sync exist objects
        foreach (var o in objects.ToList())
        {
            if (NetworkObjectDispenser.I.Objects.ContainsKey(o.Value.ID))
            {
                NetworkMissionObject obj = NetworkObjectDispenser.I.Objects[o.Value.ID];
                obj.SyncTransform(o.Value.Position.FromServerVector3(), o.Value.EulerAngles.FromServerVector3());

                if (o.Value is IHuman)
                {
                    (obj as IHumanObject).SyncHealth((o.Value as IHuman).Health, (o.Value as IHuman).MaxHealth);

                    if (o.Value is PlayerObject && o.Value.OwnerID.Equals(NetManager.I.ID))
                    {
                        GameGUIManager.I.UpdateHealthBar((o.Value as IHuman).Health, (o.Value as IHuman).MaxHealth);
                    }
                }

                if (o.Value.Destroyed)
                {
                    NetworkObjectDispenser.I.DestroyObject(o.Value.ID);
                }
            }
        }
    }