2/01/2014

Project RPG BÀI 10A. DỌN DẸP FILE BASESTAT



Chuỗi bài viết dọn dẹp nhà cửa vì lo ăn tết nên post muộn :D



B1. Double click vào file C# BaseStat và xóa tất cả đi, chèn lại đoạn code sau vào:

public class BaseStat {
    public const int STARTING_EXP_COST = 100;    //value of all stats to start

    private int _baseValue;                        //the base value of this stat
    private int _buffValue;                        //the amount of the buff to this stat
    private int _expToLevel;                    //the total amount of exp needed to raise this skill
    private float _levelModifier;                //the modifier applied to the exp needed to raise this skill


    /// <summary>
    /// Initializes a new instance of the <see cref="BaseStat"/> class.
    /// </summary>
    public BaseStat(){
        _baseValue = 0;
        _buffValue = 0;
        _levelModifier = 1.1f;
        _expToLevel = STARTING_EXP_COST;
    }

#region Basic Setters and Getters
    //Basic Setters and Getters
    /// <summary>
    /// Gets or sets the _baseValue.
    /// </summary>
    /// <value>The _baseValue.</value>
    public int BaseValue{
        get{ return _baseValue;}
        set{ _baseValue = value;}

    }

    /// <summary>
    /// Gets or sets the _buffValue.
    /// </summary>
    /// <value>The _buffValue.</value>
    public int BuffValue{
        get{ return _buffValue;}
        set{ _buffValue = value;}
       
    }

    /// <summary>
    /// Gets or sets the _expToLevel.
    /// </summary>
    /// <value>The _expToLevel.</value>
    public int ExpToLevel{
        get{ return _expToLevel;}
        set{ _expToLevel = value;}
       
    }

    /// <summary>
    /// Gets or sets the _levelModifier.
    /// </summary>
    /// <value>The _levelModifier.</value>
    public float LevelModifier{
        get{ return _levelModifier;}
        set{ _levelModifier = value;}
       
    }
#endregion
    /// <summary>
    /// Calculates the exp to level.
    /// </summary>
    /// <returns>The exp to level.</returns>
    private int CalculateExpToLevel(){
        return (int)(_expToLevel * _levelModifier);
    }

    /// <summary>
    /// Assign the new level to _expToLevel and then increase the _baseValue by one.
    /// </summary>
    public void LevelUp(){
        _expToLevel = CalculateExpToLevel();
        _baseValue++;
    }

    /// <summary>
    /// Recalculate the adjust base value ans return it
    /// </summary>
    /// <value>The adjusted base value.</value>
    public int AdjustedBaseValue{
        get{ return _baseValue + _buffValue; }
    }
}


B2. Double click vào file C# GameSettings và sửa lại dòng code tô đỏ dưới đây:

public void LoadCharacterData(){
        GameObject pc = GameObject.Find("pc");
      
        PlayerCharacter pcClass = pc.GetComponent<PlayerCharacter>();

        pcClass.Name = PlayerPrefs.GetString("Player Name", "Name me");

        for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++){
            pcClass.GetPrimaryAttribute(cnt).BaseValue = PlayerPrefs.GetInt (((AttributeName)cnt).ToString() + " - Base Value", 0);
            pcClass.GetPrimaryAttribute(cnt).ExpToLevel = PlayerPrefs.GetInt (((AttributeName)cnt).ToString() + " - EXP To Level", 1);
        }



Sửa thành như đã tô đỏ dưới đây:

            pcClass.GetPrimaryAttribute(cnt).ExpToLevel = PlayerPrefs.GetInt (((AttributeName)cnt).ToString() + " - EXP To Level", Attribute.STARTING_EXP_COST);

No comments:

Post a Comment