Exemplo n.º 1
0
    public void Set(Player p, T value)
    {
        var h = new Hashtable();

        h.Add(id, value);
        p.SetCustomProperties(h);
    }
Exemplo n.º 2
0
    private void OnEventActionHandler(ExitGames.Client.Photon.EventData eventData)
    {
        string eventCode = eventData.Code.ToString();
        var    evParams  = eventData.Parameters;
        int    actorNr   = 0;

        ExitGames.Client.Photon.LoadBalancing.Player originatingPlayer = null;
        if (eventData.Parameters.ContainsKey(ParameterCode.ActorNr))
        {
            actorNr = (int)eventData[ParameterCode.ActorNr];
            if (_loadBalancingClient.CurrentRoom != null)
            {
                originatingPlayer = _loadBalancingClient.CurrentRoom.GetPlayer(actorNr);
            }
        }

        switch (eventData.Code)
        {
        case EventCode.Join:
        {
            string name = "";
            // we only want to deal with events from the game server
            if (_loadBalancingClient.Server == ServerConnection.GameServer)
            {
                var playerProps = (ExitGames.Client.Photon.Hashtable)eventData[ParameterCode.PlayerProperties];

                var userId   = (string)playerProps[ActorProperties.UserId];
                var userName = (string)playerProps[ActorProperties.PlayerName];


                if (userId == _loadBalancingClient.UserId)
                {
                    // local user
                    _playerLocal = Player.Create(_userName, _userToken, true, actorNr);
                    if (OnGameEntered != null)
                    {
                        OnGameEntered(actorNr);
                    }
                    eventCode = "EventCode: Join, Local, " + userName + " ID: " + userId;
                }
                //else
                {
                    // other players
                    _playerRemote = Player.Create(_userName, _userToken, false, actorNr);
                    if (OnPlayerJoined != null)
                    {
                        OnPlayerJoined(actorNr);
                    }
                    eventCode = "EventCode: Join, Other, " + userName + " ID: " + userId;
                }
            }

            break;
        }

        case EventCode.Leave:
        {
            // we only want to deal with events from the game server
            if (_loadBalancingClient.Server == ServerConnection.GameServer)
            {
                // check if we have props
                if (evParams.ContainsKey(ParameterCode.PlayerProperties))
                {
                    var playerProps = (Hashtable)eventData[ParameterCode.PlayerProperties];
                    var userId      = (string)playerProps[ActorProperties.UserId];
                    if (userId == _loadBalancingClient.UserId)
                    {
                        // local user
                        if (OnGameLeft != null)
                        {
                            OnGameLeft(actorNr);
                        }
                    }
                    else
                    {
                        // other players
                        if (OnPlayerLeft != null)
                        {
                            OnPlayerLeft(actorNr);
                        }
                    }
                }
                else
                {
                    // all other players - just call default listener
                    if (OnPlayerLeft != null)
                    {
                        OnPlayerLeft(actorNr);
                    }
                }
            }
            eventCode = "EventCode: Leave, " + actorNr;
            break;
        }

        case EventCode.AppStats:
        {
            // get the parameters
            string text = "AppStats: paramCount";

            foreach (var param in evParams)
            {
                text += "param Key:" + param.Key + " param Val:" + param.Value.ToString() + "\n";
            }

            eventCode = text;
            var masterServerAdress = _loadBalancingClient.MasterServerAddress;
            Debug.Log(masterServerAdress);
            if (OnServerIpChangedAction != null)
            {
                OnServerIpChangedAction(masterServerAdress);
            }
            //eventCode += evParams != null ? evParams.Count.ToString() : "AppStats without Parameters";

            break;
        }

        default:
        {
            // all custom events are sent out
            if (eventData.Code <= 200)
            {
                //if (OnGameEvent != null) OnGameEvent(aEvent);
            }
            break;
        }
        }

        if (OnEventAction != null)
        {
            OnEventAction(eventCode);
        }
        //_roomInfo.text = eventCode;
    }
Exemplo n.º 3
0
 public void SaveMyPlayer(Player player)
 {
     string playerJson = JsonConvert.SerializeObject(player);
     this.OpWebRpc(RPC_POST_PLAYER, new Dictionary<string, object>() { { "LocalPlayer", playerJson }, { "GameId", "two" } });
 }
Exemplo n.º 4
0
 public Player GetNextFor(Player currentPlayer)
 {
     if (currentPlayer == null)
     {
         return null;
     }
     return GetNextFor(currentPlayer.ID);
 }
 /// <summary>
 /// Factory method to create a player instance - override to get your own player-type with custom features.
 /// </summary>
 /// <param name="actorName">The name of the player to be created. </param>
 /// <param name="actorNumber">The player ID (a.k.a. actorNumber) of the player to be created.</param>
 /// <param name="isLocal">Sets the distinction if the player to be created is your player or if its assigned to someone else.</param>
 /// <param name="actorProperties">The custom properties for this new player</param>
 /// <returns>The newly created player</returns>
 protected internal virtual Player CreatePlayer(string actorName, int actorNumber, bool isLocal, Hashtable actorProperties)
 {
     Player newPlayer = new Player(actorName, actorNumber, isLocal, actorProperties);
     return newPlayer;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Removes a player from this room's Players Dictionary.
        /// This is internally used by the LoadBalancing API. There is usually no need to remove players yourself.
        /// This is not a way to "kick" players.
        /// </summary>
        protected internal virtual void RemovePlayer(Player player)
        {
            this.Players.Remove(player.ID);
            player.RoomReference = null;

            if (player.ID == this.MasterClientId)
            {
                this.UpdateMasterClientId();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Updates a player reference in the Players dictionary (no matter if it existed before or not).
        /// </summary>
        /// <param name="player">The Player instance to insert into the room.</param>
        public virtual Player StorePlayer(Player player)
        {
            this.Players[player.ID] = player;
            player.RoomReference = this;

            // while initializing the room, the players are not guaranteed to be added in-order
            if (this.MasterClientId == 0 || player.ID < this.MasterClientId)
            {
                this.UpdateMasterClientId();
            }

            return player;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Checks if the player is in the room's list already and calls StorePlayer() if not.
        /// </summary>
        /// <param name="player">The new player - identified by ID.</param>
        /// <returns>False if the player could not be added (cause it was in the list already).</returns>
        public virtual bool AddPlayer(Player player)
        {
            if (!this.Players.ContainsKey(player.ID))
            {
                this.StorePlayer(player);
                return true;
            }

            return false;
        }
Exemplo n.º 9
0
 public T Get(Player p)
 {
     return((T)p.CustomProperties[id]);
 }