Beispiel #1
0
    /// <summary>
    /// If someone depends on a char and that char is removed, remove that someone.
    /// </summary>
    /// <param name="ID"></param>
    /// <param name="CurrentState"></param>
    /// <param name="NextState"></param>
    /// <returns></returns>
    public void removeDependencies(int ID, CharController.State CurrentState, CharController.State NextState)
    {
        //If we're alreasdy "WaitingOut"side of Selection, or needed by no one, nothing to do here.
        if (NeededBy[ID].Length == 0 || NextState == CharController.State.WaitingOut)
        {
            return;
        }

        //Tell friends we're leaving.
        CBUG.Log(ID_to_Name[ID] + " has " + NeededBy[ID].Length + " references on to remove");
        for (int i = 0; i < NeededBy[ID].Length; i++)
        {
            //To prevent multiple calls to a Character within a single frame, we check action buffer.
            if (!ActionBufferRemove.ContainsKey(NeededBy[ID][i]))
            {
                //Fixing circular dependency with this:
                //Don't call the one who called me.
                //if Caller of Past == Character I want to Call, don't call
                if ((!ActionBufferRemove.ContainsKey(ID)) || ActionBufferRemove[ID] != NeededBy[ID][i])
                {
                    if (Characters[NeededBy[ID][i]].GetComponent <CharController>().NextState != CharController.State.WaitingOut)
                    {
                        ActionBufferRemove.Add(NeededBy[ID][i], ID);
                        Characters[NeededBy[ID][i]].GetComponent <CharController>().OnPointerClick(null);
                    }
                }
            }
        }
    }
Beispiel #2
0
 private void ShowNewChar(int playerID, int newChar)
 {
     //Update local player's chosen character locally.
     ID_to_CharNum[playerID] = newChar;
     charStateChange         = true;
     CBUG.Log(string.Format("Received PlayerID: {0} to Char: {1}", playerID, newChar));
 }
Beispiel #3
0
    private void setServerStats()
    {
        totalOnline = PhotonNetwork.countOfPlayers;
        latestRooms = PhotonNetwork.GetRoomList();

        //empty out old rooms list
        for (int x = 0; x < M.TotalUniqueStages; x++)
        {
            Rooms[x].Clear();
        }

        string   roomNameTemp;
        RoomInfo roomInfoTemp;
        int      roomSizeTemp;

        for (int x = 0; x < latestRooms.Length; x++)
        {
            roomInfoTemp = latestRooms[x];
            roomNameTemp = roomInfoTemp.Name;
            roomSizeTemp = roomInfoTemp.PlayerCount;

            CBUG.Log("Room " + roomNameTemp + " has " + roomSizeTemp + " players.");
            for (int i = 0; i < M.TotalUniqueStages; i++)
            {
                if (roomNameTemp.Contains(M.StageNames[i]))
                {
                    Rooms[i].Add(new room(roomSizeTemp, roomNameTemp));
                }
            }
        }
        //CBUG.Log("There are a total of " + totalOnline + " online.");
    }
Beispiel #4
0
    public void OnJoinedLobby()
    {
        CBUG.Log("OnJoinedLobby() was a success.");
        //PhotonNetwork.JoinOrCreateRoom("Waiting", new RoomOptions() { MaxPlayers = Convert.ToByte(serverPlayerMax) }, null);

        inLobby = true;
    }
Beispiel #5
0
    /// <summary>
    /// Helper function called when a new player joins after you.
    /// </summary>
    /// <param name="player">New player that connected.</param>
    private void storeRemoteData(PhotonPlayer player)
    {
        int playerChar;
        int playerID = player.ID;

        if (player.CustomProperties.ContainsKey("characterNum"))
        {
            playerChar = (int)player.CustomProperties["characterNum"];
        }
        else
        {
            playerChar = 0;
        }

        //Add player to info tracking.
        if (!ID_to_CharNum.ContainsKey(playerID))
        {
            ID_to_CharNum.Add(playerID, playerChar);
        }
        else
        {
            ID_to_CharNum[playerID] = playerChar;
        }

        if (!ID_to_IsRdy.ContainsKey(playerID))
        {
            ID_to_IsRdy.Add(playerID, false);
        }
        else
        {
            ID_to_IsRdy[playerID] = false;
        }
        CBUG.Log(string.Format("New Player Connected! ID: {0} Char: {1}", playerID, playerChar));
    }
Beispiel #6
0
    private IEnumerator goToHelper()
    {
        float startTime = Time.time;
        float startPos  = transform.position.sqrMagnitude;

        CBUG.Log("MOVING!");
        bool idling = false;

        while ((toPos - transform.position).sqrMagnitude > NearbyBuffer)
        {
            if ((toPos - transform.position).sqrMagnitude < NearbyBuffer * 2f &&
                !idling)
            {
                idling = true;
                Anim.SetTrigger("Idle0");
                //Too much hopping. So let's idle a little bit before the buffer
                // cuts us off.
                CBUG.Log("Idling!");
            }
            transform.Translate((toPos - transform.position) * GoToSpeed *
                                Smooth(transform.position.sqrMagnitude, startPos, toPos.sqrMagnitude, true));
            yield return(null);
        }
        CurrentState = NextState;
        StartCoroutine(DesyncAnim("Idle" + Random.Range(1, 3)));
    }
Beispiel #7
0
    void Start()
    {
        minPlayersAllowed = SettingsManager._MinimumPlayers;
        maxPlayersAllowed = SettingsManager._MaximumPlayers;

        ID_to_CharNum = new Dictionary <int, int>();
        ID_to_IsRdy   = new Dictionary <int, bool>();

        CBUG.Log("Setting Send Rate to: " + SendRate);
        PhotonNetwork.sendRate = SendRate;

        PhotonNetwork.sendRateOnSerialize = SendRate;


        version      = M.Version; //Debug.isDebugBuild ? "test" :
        isEastServer = PlayerPrefs.GetInt("Server", 0) == 1 ? true : false;
        //"Server" returns either 0=none, 1 = east, 2 = West
        //isEastServer won't be used if 0, and instead 'best' region is used.

        previousUpdateTime = Time.time;

        serverPlayerMax  = 100;
        isConnectAllowed = false; //Enabled when server region given.

        Rooms = new List <List <room> > ();
        for (int x = 0; x < M.TotalUniqueStages; x++)
        {
            Rooms.Add(new List <room>());
            Rooms[x].Clear();
        }
    }
Beispiel #8
0
    /// <summary>
    /// Note: NEED GUI FOR IF ROOM IS FULL.
    /// </summary>
    public void JoinRoom()
    {
        string roomNameTemp = Rooms[MapUI.getTargetStage()][MapUI.getTargetRoom()].name;

        CBUG.Log("Joining room named: " + roomNameTemp);
        PhotonNetwork.JoinRoom(roomNameTemp);
    }
 public override void OnJoinRandomFailed(short returnCode, string message)
 {
     CBUG.Log("Room Join failed. Creating a room ...");
     PhotonNetwork.CreateRoom(null, new RoomOptions()
     {
         MaxPlayers = 2, CleanupCacheOnLeave = false
     }, null);
 }
Beispiel #10
0
 public void SetNotify(bool isOn)
 {
     notifyOn = isOn;
     NotifyObj.SetActive(notifyOn);
     if (notifyOn)
     {
         CBUG.Log("NOTICE ME!");
     }
 }
Beispiel #11
0
 void OnPhotonPlayerDisconnected(PhotonPlayer player)
 {
     CBUG.Log("OnPhotonPlayerDisconnected: " + player);
     //Tell everyone to reset their ready status.
     ResetReadyStatus();
     unassignPlayerTracking(player);
     plrStateChange = true;
     rdyStateChange = true;
 }
Beispiel #12
0
    public void Update()
    {
        if (isConnectAllowed && !PhotonNetwork.connected)
        {
            CBUG.Log("Beginning Connection . . .");

            isConnectAllowed = false;
            if (PlayerPrefs.GetInt("Server", 0) == 0)
            {
                PhotonNetwork.ConnectToBestCloudServer(version);
                CBUG.Log("Connecting to Best Region.");
            }
            else
            {
                PhotonNetwork.ConnectToRegion(isEastServer ? CloudRegionCode.us : CloudRegionCode.usw, version);
                CBUG.Log("Connecting to Chosen Region.");
            }

            CBUG.Log("Version Number is: " + version);
            PhotonNetwork.sendRate            = SendRate;
            PhotonNetwork.sendRateOnSerialize = SendRate;
        }

        if (!PhotonNetwork.connectedAndReady && PhotonNetwork.connecting)
        {
            printStatus();
        }

        if (!PhotonNetwork.connected)
        {
            return;
        }
        //if(PhotonNetwork.room != null)
        //    CBUG.Do("TotalRoomPlayersIs: " + PhotonNetwork.room.playerCount);

        if (Time.time - previousUpdateTime > ServerUpdateLoopTime)
        {
            previousUpdateTime = Time.time;
            setServerStats();
        }

        //CBUG.Log("CHAR NUM: " + ID_to_CharNum[1]);

        #region Match Tracking
        if (readyTotal >= PhotonNetwork.playerList.Length && !startTheMatch && !startCountdown)
        {
            startTimer     = CountdownLength;
            startCountdown = true;
            StartCoroutine(GameCountdown());
        }
        if (startCountdown == true && readyTotal < PhotonNetwork.playerList.Length)
        {
            startCountdown = false;
        }
        #endregion
    }
Beispiel #13
0
 public void SetMSXVolume(float amt)
 {
     if (amt < 0f || amt > 1f)
     {
         CBUG.Error("Volume amount must be betweeen 0 and 1.");
     }
     myMusicAudio.volume = amt;
     PlayerPrefs.SetFloat("MSXVol", amt);
     PlayerPrefs.Save();
     CBUG.Log("MSXVolume Set");
 }
Beispiel #14
0
    void OnPhotonPlayerConnected(PhotonPlayer player)
    {
        //Add new player info tracking.
        storeRemoteData(player);
        CBUG.Log("OnPhotonPlayerConnected: " + player);
        //Tell everyone to reset their ready status.
        ResetReadyStatus();

        plrStateChange = true;
        rdyStateChange = true;
        startCountdown = false;
        startTimer     = CountdownLength;
    }
Beispiel #15
0
    private void updatePlayerCharDisplay()
    {
        int slotNum;
        int charNum;

        for (int x = 0; x < PhotonNetwork.room.PlayerCount; x++)
        {
            slotNum = NetIDs.PlayerNumber(PhotonNetwork.playerList[x].ID);
            charNum = N.GetCharNum(PhotonNetwork.playerList[x].ID);
            RoomSlotImages[slotNum].sprite = UIHeads[charNum];
            CBUG.Log(string.Format("UpdateHUDCharDisplay playerID/slotNum: {0} charNum: {1}", slotNum, charNum));
        }
    }
Beispiel #16
0
    public void Save()
    {
        int i = 0;

        CBUG.Log("Saving PlayerPrefs!");
        foreach (InputField obj in SaveObjs)
        {
            CBUG.Log("Key: " + i + " String: " + SaveObjs[i].text);
            PlayerPrefs.SetString("" + i, SaveObjs[i].text);
            i++;
        }
        PlayerPrefs.Save();
    }
Beispiel #17
0
    public void Load()
    {
        int    i = 0;
        string temp;

        CBUG.Log("Loading PlayerPrefs");
        foreach (InputField obj in SaveObjs)
        {
            temp = PlayerPrefs.GetString("" + i, "");
            CBUG.Log("Key: " + i + " String: " + temp);
            SaveObjs[i].text = temp;
            i++;
        }
    }
Beispiel #18
0
 void OnPhotonPlayerDisconnected(PhotonPlayer player)
 {
     CBUG.Log("OnPhotonPlayerDisconnected: " + player);
     //Tell everyone to reset their ready status.
     ResetReadyStatus();
     unassignPlayerTracking(player);
     plrStateChange = true;
     rdyStateChange = true;
     if (gameStarted)
     {
         GameManager.RecordDeath(-1, NetIDs.PlayerNumber(player.ID), true);
         GameManager.HandleDeath(NetIDs.PlayerNumber(player.ID), true);
     }
 }
    void Awake()
    {
        isFrozen = false;
        //DontDestroyOnLoad(gameObject);
        anim            = GetComponentInChildren <Animator>();
        moveRight       = 0;
        moveLeft        = 0;
        controlsPaused  = false;
        myAudioSrc      = GetComponent <AudioSource>();
        myAudioSrc.clip = DeathNoise;
        punching        = false;

        isDead        = false;
        StrengthsList = GameObject.FindGameObjectWithTag("Master").
                        GetComponent <Master>().GetStrengthList();

        CBUG.Log("Str List: " + StrengthsList.ToStringFull());
        jumpForceTemp      = 0f;
        SpeedTemp          = 0f;
        attackDisableDelay = new WaitForSeconds(AttackLife);
        facingRight        = true;
        position           = new Vector2();
        _Rigibody2D        = GetComponent <Rigidbody2D>();
        jumpsRemaining     = TotalJumpsAllowed;
        _PhotonView        = GetComponent <PhotonView>();
        _PhotonTransform   = GetComponent <PhotonTransformView>();

        AttackObjs    = new GameObject[3];
        AttackObjs[0] = transform.GetChild(3).gameObject;
        AttackObjs[1] = transform.GetChild(1).gameObject;
        AttackObjs[2] = transform.GetChild(2).gameObject;

        _MobileInput = GameObject.FindGameObjectWithTag("MobileController").GetComponent <MobileController>();

        spawnPause     = 0.5f;
        spawnPauseWait = new WaitForSeconds(spawnPause);

        lastHitBy           = -1;
        lastHitTime         = Time.time;
        lastHitForgetLength = 5;//Seconds

        if (_PhotonView.isMine)
        {
            tag = "PlayerSelf";
            _PhotonView.RPC("SetSlotNum", PhotonTargets.All, NetIDs.PlayerNumber(PhotonNetwork.player.ID));
            CamManager.SetTarget(transform);
        }
    }
Beispiel #20
0
    // Update is called once per frame
    void Update()
    {
        if (ClearAll)
        {
            PlayerPrefs.DeleteAll();
            ClearAll = false;
            CBUG.Log("Clearing All PlayerPrefs!");
        }

        if (Clear)
        {
            Clear = false;
            PlayerPrefs.DeleteKey(ClearKey);
            CBUG.Log("Clearing Key: " + ClearKey);
        }
    }
Beispiel #21
0
    /// <summary>
    /// Makes sure there is space available for Char N Friends.
    /// If so, also tell friend to go as well.
    /// </summary>
    /// <param name="ID"></param>
    /// <param name="CurrentState"></param>
    /// <param name="NextState"></param>
    /// <returns></returns>
    public bool includeDependencies(int ID, CharController.State CurrentState, CharController.State NextState)
    {
        //If we're already "WaitingIn" Selection, or have no friends, nothing to do here.
        if (DependenciesOf[ID].Length == 0 || NextState == CharController.State.WaitingIn)
        {
            return(true);
        }

        //Is there space for us and our friends? If not, don't act!
        int totalDependenciesNotSelected = 0;

        for (int x = 0; x < DependenciesOf[ID].Length; x++)
        {
            if (Characters[DependenciesOf[ID][x]].GetComponent <CharController>().NextState == CharController.State.WaitingOut)
            {
                totalDependenciesNotSelected++;
            }
        }
        if (!IsPositionAvailable(totalDependenciesNotSelected + 1))
        {
            return(false);
        }

        //Tell friends they got "clicked".
        CBUG.Log(ID_to_Name[ID] + " has " + DependenciesOf[ID].Length + " friends to add");
        for (int i = 0; i < DependenciesOf[ID].Length; i++)
        {
            //To prevent multiple calls to a Character within a single frame, we check action buffer.
            if (!ActionBufferAdd.ContainsKey(DependenciesOf[ID][i]))
            {
                //Fixing circular dependency with this:
                //Don't call the one who called me.
                //if Caller of Past == Character I want to Call, don't call
                if ((!ActionBufferAdd.ContainsKey(ID)) || ActionBufferAdd[ID] != DependenciesOf[ID][i])
                {
                    //Don't call anyone already settled in.
                    if (Characters[DependenciesOf[ID][i]].GetComponent <CharController>().NextState != CharController.State.WaitingIn)
                    {
                        ActionBufferAdd.Add(DependenciesOf[ID][i], ID);
                        Characters[DependenciesOf[ID][i]].GetComponent <CharController>().OnPointerClick(null);
                    }
                }
            }
        }
        return(true);
    }
Beispiel #22
0
    /// <summary>
    /// Shows character a player is hovering over.
    /// </summary>
    public void SetCharacter()
    {
        CBUG.Log("Adding player property");
        ExitGames.Client.Photon.Hashtable playerProperties = PhotonNetwork.player.CustomProperties;
        //Update local player's chosen character online.
        if (playerProperties.ContainsKey("characterNum"))
        {
            playerProperties["characterNum"] = M.PlayerCharNum;
        }
        else
        {
            playerProperties.Add("characterNum", M.PlayerCharNum);
        }

        PhotonNetwork.player.SetCustomProperties(playerProperties);
        SetCharDisplay(PhotonTargets.All, M.PlayerCharNum);
    }
 public override void OnJoinedLobby()
 {
     CBUG.Log("Lobby Joined!");
     CBUG.Log("Joining Random Room ...");
     if (needsNewRoom)
     {
         PhotonNetwork.CreateRoom(null, new RoomOptions()
         {
             MaxPlayers = 2, CleanupCacheOnLeave = false
         }, null);
     }
     else
     {
         //string sqlLobbyFilter = "GameStartTime = -1"; //todo ??? implement sql lobbying
         PhotonNetwork.JoinRandomRoom();
     }
     currentServerUserDepth = ServerDepthLevel.InLobby;
 }
    //public override void On

    public override void OnJoinedRoom()
    {
        CBUG.Log("Joined Room! Total Players: " + PhotonNetwork.CurrentRoom.PlayerCount);

        currentServerUserDepth = ServerDepthLevel.InRoom;

        SaveData("FirstTimeSetupDone", false);

        if (PhotonNetwork.IsMasterClient)
        {
            //spawn singletons
            foreach (var singleton in singletonNames)
            {
                SpawnObject(singleton);
            }
        }
        SaveData("FirstTimeSetupDone", true);
    }
Beispiel #25
0
    void Awake()
    {
        anim            = GetComponentInChildren <Animator>();
        moveRight       = 0;
        moveLeft        = 0;
        controlsPaused  = false;
        myAudioSrc      = GetComponent <AudioSource>();
        myAudioSrc.clip = DeathNoise;
        punching        = false;

        deathColor    = Color.clear;
        lifeColor     = Color.white;
        isDead        = false;
        StrengthsList = GameObject.FindGameObjectWithTag("Master").
                        GetComponent <Master>().GetStrengthList();


        CBUG.Log("" + (StrengthsList == null ? "True" : "False"));

        jumpForceTemp      = 0f;
        SpeedTemp          = 0f;
        attackDisableDelay = new WaitForSeconds(AttackLife);
        facingRight        = true;
        position           = new Vector2();
        _Rigibody2D        = GetComponent <Rigidbody2D>();
        jumpsRemaining     = TotalJumpsAllowed;

        AttackObjs    = new GameObject[3];
        AttackObjs[0] = transform.GetChild(3).gameObject;
        AttackObjs[1] = transform.GetChild(1).gameObject;
        AttackObjs[2] = transform.GetChild(2).gameObject;

        _MobileInput = GameObject.FindGameObjectWithTag("MobileController").GetComponent <MobileController>();

        spawnPause     = 0.5f;
        spawnPauseWait = new WaitForSeconds(spawnPause);

        lastHitBy           = -1;
        lastHitTime         = Time.time;
        lastHitForgetLength = 5;//Seconds
    }
    public void ConnectAndJoinRoom(string username, string[] singletons)
    {
        if (CurrentServerUserDepth != ServerDepthLevel.Offline)
        {
            CBUG.Do("Redundant connect call! Already at " + CurrentServerUserDepth.ToString());
            return;
        }

        CBUG.Do("Connecting!");
        PhotonNetwork.GameVersion = "HotelGame";

        PhotonNetwork.NetworkingClient.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;

        PhotonNetwork.AuthValues        = new AuthenticationValues();
        PhotonNetwork.AuthValues.UserId = username + "_" + UnityEngine.Random.Range(0, 9999);

        string region  = "us";
        bool   _result = PhotonNetwork.ConnectToRegion(region);

        CBUG.Log("PunCockpit:ConnectToRegion(" + region + ") -> " + _result);
    }
Beispiel #27
0
    /// <summary>
    /// Helper function for OnJoinedRoom. Called while iterating through current list of players
    /// in the room.
    /// </summary>
    /// <param name="playerID">Unique Player ID</param>
    /// <param name="playerNum">i'th player in room</param>
    private void storeLocalData(int playerID, int playerNum)
    {
        int playerChar;

        if (PhotonNetwork.playerList[playerNum].CustomProperties.ContainsKey("characterNum"))
        {
            playerChar = (int)PhotonNetwork.playerList[playerNum].CustomProperties["characterNum"];
        }
        else
        {
            playerChar = 0;
        }

        //Add other players to info tracking.
        if (!ID_to_CharNum.ContainsKey(playerID))
        {
            ID_to_CharNum.Add(playerID, playerChar);
        }
        else
        {
            ID_to_CharNum[playerID] = playerChar;
        }

        if (!ID_to_IsRdy.ContainsKey(playerID))
        {
            ID_to_IsRdy.Add(playerID, false);
        }
        else
        {
            ID_to_IsRdy[playerID] = false;
        }

        plrStateChange  = true;
        rdyStateChange  = true;
        charStateChange = true;
        CBUG.Log(string.Format("Assigning Local Data. ID: {0} Slot: {1}", playerID, playerNum));
        //TODO: playerID is just playerNum - 1. Merge the two.
    }
Beispiel #28
0
    public void OnPointerClick(PointerEventData eventData)
    {
        CBUG.Log(MyStats.Name + " was clicked!");
        if (!charMan.includeDependencies(MyStats.ID, CurrentState, NextState))
        {
            return;
        }

        charMan.removeDependencies(MyStats.ID, CurrentState, NextState);


        if (CurrentState == State.Moving)
        {
            if (NextState == State.WaitingIn)
            {
                toPos     = charMan.GetHomePos(MyStats.ID);
                NextState = State.WaitingOut;
            }
            else if (NextState == State.WaitingOut && charMan.IsPositionAvailable(1))
            {
                toPos     = charMan.GetNextSelectPos(MyStats.ID);
                NextState = State.WaitingIn;
            }
        }
        else
        {
            if (CurrentState == State.WaitingOut && charMan.IsPositionAvailable(1))
            {
                GoTo(charMan.GetNextSelectPos(MyStats.ID), State.WaitingIn);
            }
            else if (CurrentState == State.WaitingIn)
            {
                GoTo(charMan.GetHomePos(MyStats.ID), State.WaitingOut);
            }
        }
        charMan.SetNotifications();
    }
Beispiel #29
0
 private void printStatus()
 {
     CBUG.Log("Connection Status: " + PhotonNetwork.connectionStateDetailed);
 }
Beispiel #30
0
 public void LeaveRoom()
 {
     CBUG.Log("Leaving Room.");
     //unassignPlayerTracking(PhotonNetwork.player);
     PhotonNetwork.LeaveRoom();
 }