コード例 #1
0
ファイル: Player.cs プロジェクト: hach-que/Substrate
        /// <summary>
        /// Creates a copy of a <see cref="Player"/> object.
        /// </summary>
        /// <param name="p">The <see cref="Player"/> to copy fields from.</param>
        protected Player(Player p)
            : base(p)
        {
            _attackTime = p._attackTime;
            _deathTime  = p._deathTime;
            _health     = p._health;
            _hurtTime   = p._hurtTime;

            _dimension  = p._dimension;
            _gameType   = p._gameType;
            _sleeping   = p._sleeping;
            _sleepTimer = p._sleepTimer;
            _spawnX     = p._spawnX;
            _spawnY     = p._spawnY;
            _spawnZ     = p._spawnZ;
            _world      = p._world;
            _inventory  = p._inventory.Copy();
            _enderItems = p._inventory.Copy();

            _foodLevel      = p._foodLevel;
            _foodTickTimer  = p._foodTickTimer;
            _foodSaturation = p._foodSaturation;
            _foodExhaustion = p._foodExhaustion;
            _xpP            = p._xpP;
            _xpLevel        = p._xpLevel;
            _xpTotal        = p._xpTotal;
            _abilities      = p._abilities.Copy();
        }
コード例 #2
0
        /// <summary>
        /// Creates a new <see cref="Player"/> object with reasonable default values.
        /// </summary>
        public Player()
            : base()
        {
            _inventory = new ItemCollection(_CAPACITY);
            _abilities = new PlayerAbilities();

            // Sane defaults
            _dimension  = 0;
            _sleeping   = 0;
            _sleepTimer = 0;

            Air    = 300;
            Health = 20;
            Fire   = -20;
        }
コード例 #3
0
ファイル: Player.cs プロジェクト: hach-que/Substrate
        /// <summary>
        /// Attempt to load a Player subtree into the <see cref="Player"/> without validation.
        /// </summary>
        /// <param name="tree">The root node of a Player subtree.</param>
        /// <returns>The <see cref="Player"/> returns itself on success, or null if the tree was unparsable.</returns>
        public virtual new Player LoadTree(TagNode tree)
        {
            TagNodeCompound ctree = tree as TagNodeCompound;

            if (ctree == null || base.LoadTree(tree) == null)
            {
                return(null);
            }

            _attackTime = ctree["AttackTime"].ToTagShort();
            _deathTime  = ctree["DeathTime"].ToTagShort();
            _health     = ctree["Health"].ToTagShort();
            _hurtTime   = ctree["HurtTime"].ToTagShort();

            _dimension  = ctree["Dimension"].ToTagInt();
            _sleeping   = ctree["Sleeping"].ToTagByte();
            _sleepTimer = ctree["SleepTimer"].ToTagShort();

            if (ctree.ContainsKey("SpawnX"))
            {
                _spawnX = ctree["SpawnX"].ToTagInt();
            }
            if (ctree.ContainsKey("SpawnY"))
            {
                _spawnY = ctree["SpawnY"].ToTagInt();
            }
            if (ctree.ContainsKey("SpawnZ"))
            {
                _spawnZ = ctree["SpawnZ"].ToTagInt();
            }

            if (ctree.ContainsKey("World"))
            {
                _world = ctree["World"].ToTagString();
            }

            if (ctree.ContainsKey("foodLevel"))
            {
                _foodLevel = ctree["foodLevel"].ToTagInt();
            }
            if (ctree.ContainsKey("foodTickTimer"))
            {
                _foodTickTimer = ctree["foodTickTimer"].ToTagInt();
            }
            if (ctree.ContainsKey("foodExhaustionLevel"))
            {
                _foodExhaustion = ctree["foodExhaustionLevel"].ToTagFloat();
            }
            if (ctree.ContainsKey("foodSaturationLevel"))
            {
                _foodSaturation = ctree["foodSaturationLevel"].ToTagFloat();
            }
            if (ctree.ContainsKey("XpP"))
            {
                _xpP = ctree["XpP"].ToTagFloat();
            }
            if (ctree.ContainsKey("XpLevel"))
            {
                _xpLevel = ctree["XpLevel"].ToTagInt();
            }
            if (ctree.ContainsKey("XpTotal"))
            {
                _xpTotal = ctree["XpTotal"].ToTagInt();
            }
            if (ctree.ContainsKey("Score"))
            {
                _score = ctree["Score"].ToTagInt();
            }

            if (ctree.ContainsKey("abilities"))
            {
                TagNodeCompound pb = ctree["abilities"].ToTagCompound();

                _abilities              = new PlayerAbilities();
                _abilities.Flying       = pb["flying"].ToTagByte().Data == 1;
                _abilities.InstantBuild = pb["instabuild"].ToTagByte().Data == 1;
                _abilities.MayFly       = pb["mayfly"].ToTagByte().Data == 1;
                _abilities.Invulnerable = pb["invulnerable"].ToTagByte().Data == 1;

                if (pb.ContainsKey("mayBuild"))
                {
                    _abilities.MayBuild = pb["mayBuild"].ToTagByte().Data == 1;
                }
                if (pb.ContainsKey("walkSpeed"))
                {
                    _abilities.WalkSpeed = pb["walkSpeed"].ToTagFloat();
                }
                if (pb.ContainsKey("flySpeed"))
                {
                    _abilities.FlySpeed = pb["flySpeed"].ToTagFloat();
                }
            }

            if (ctree.ContainsKey("PlayerGameType"))
            {
                _gameType = (PlayerGameType)ctree["PlayerGameType"].ToTagInt().Data;
            }

            _inventory.LoadTree(ctree["Inventory"].ToTagList());

            if (ctree.ContainsKey("EnderItems"))
            {
                if (ctree["EnderItems"].ToTagList().Count > 0)
                {
                    _enderItems.LoadTree(ctree["EnderItems"].ToTagList());
                }
            }

            return(this);
        }