Beispiel #1
0
        /// <summary>
        /// Find the player owner of the pets at the top of the tree
        /// </summary>
        /// <returns>Player owner at the top of the tree.  If there was no player, then return null.</returns>
        public virtual GamePlayer GetPlayerOwner()
        {
            GameLiving owner = Owner;
            int        i     = 0;

            while (owner is GameNPC && owner != null)
            {
                i++;
                if (i > 50)
                {
                    throw new Exception("GetPlayerOwner() from " + Owner.Name + "caused a cyclical loop.");
                }

                // If this is a pet, get its owner
                if (((GameNPC)owner).Brain is IControlledBrain)
                {
                    owner = ((IControlledBrain)((GameNPC)owner).Brain).Owner;
                }

                // This isn't a pet, that means it's at the top of the tree.  This case will only happen if
                // owner is not a GamePlayer
                else
                {
                    break;
                }
            }

            // Return if we found the gameplayer
            if (owner is GamePlayer)
            {
                return((GamePlayer)owner);
            }

            // If the root owner was not a player or npc then make sure we know that something went wrong!
            if (!(owner is GameNPC))
            {
                throw new Exception("Unrecognized owner: " + owner.GetType().FullName);
            }

            // No GamePlayer at the top of the tree
            return(null);
        }