Ejemplo n.º 1
0
        /// <summary>
        /// Gets a code to uniquely identify a given player. These are synced to the server in multiplayer.
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public static string GetUniqueId(Player player)
        {
            var    mymod = ModHelpersMod.Instance;
            string id;

            if (!mymod.PlayerIdentityHelpers.PlayerIds.TryGetValue(player.whoAmI, out id))
            {
                if (Main.netMode != 2 && player.whoAmI == Main.myPlayer)
                {
                    id = PlayerIdentityHelpers.GetUniqueId();
                    mymod.PlayerIdentityHelpers.PlayerIds[player.whoAmI] = id;
                }
                else
                {
                    //throw new HamstarException( "!ModHelpers.PlayerIdentityHelpers.GetProperUniqueId - Could not find player " + player.name + "'s id." );
                    return(null);
                }
            }
            return(id);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets an active player by a given unique id (if present).
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public static Player GetPlayerByUniqueId(string uid)
        {
            int len = Main.player.Length;

            for (int i = 0; i < len; i++)
            {
                Player plr = Main.player[i];
//LogHelpers.Log( "GetPlayerByProperId: "+PlayerIdentityHelpers.GetProperUniqueId( plr )+" == "+uid+": "+plr.name+" ("+plr.whoAmI+")" );
                if (plr == null /*|| !plr.active*/)
                {
                    continue;
                }                                                                       // <- This is WEIRD!

                if (PlayerIdentityHelpers.GetUniqueId(plr) == uid)
                {
                    return(plr);
                }
            }

            return(null);
        }