ModifiedStat.cs

/// <summary>
/// ModifiedStat.cs
/// High Sword
/// July 27, 2012
/// 
/// This is the base class for all stats that will be modifiable by attributes 
/// </summary>
using System.Collections.Generic;				// Generic was added so we can use the List<>

public class ModifiedStat : BaseStat {
	private List<ModifyingAttribute> _mods;		// A list of Attributes that modify this stat
	private int _modValue;						// The amount added to the baseValue from the modifiers
	
	/// <summary>
	/// Initializes a new instance of the <see cref="ModifiedStat"/> class.
	/// </summary>
	public ModifiedStat () {
		_mods = new List<ModifyingAttribute>();
		_modValue = 0;	
	}
	
	/// <summary>
	/// add a ModifyingAttribute to our list of mods for this ModifiedStat
	/// </summary>
	/// <param name='mod'>
	/// Mod.
	/// </param>
	public void AddModifier(ModifyingAttribute mod) {
		_mods.Add (mod);
	}
	
	/// <summary>
	/// Reset _modValue to zero.
	/// Check to see if we have at least one ModifyingAttribute in our list of mods.
	/// If we do, then iterate the list and add the AdjustedBaseValue * ratio to our _modValue.
	/// </summary>
	private void CalculateModValue () {
		_modValue = 0;
		
		if (_mods.Count > 0)
			foreach (ModifyingAttribute att in _mods)
				_modValue += (int)(att.attribute.AdjustedBaseValue * att.ratio);
	}
	
	// Override "AdjustedBaseValue" in BaseStat.cs
	/// <summary>
	/// This function is overriding the AdjustedBaseValue in the BaseStat class.
	/// Calculate the AdjustedBaseValue from the BaseValue  + BuffValue + _modValue
	/// </summary>
	/// <value>
	/// The adjusted base value.
	/// </value>
	public new int AdjustedBaseValue {
		get{return BaseValue + BuffValue + _modValue;}
	}
	
	/// <summary>
	/// Update this instance.
	/// </summary>
	public void Update () {
		CalculateModValue();
	
	}
	
	public string GetModifyingAttributeString () {
		string temp = "";
		
//		UnityEngine.Debug.Log(_mods.Count);
		for (int cnt = 0; cnt < _mods.Count; cnt++) {
			temp += _mods[cnt].attribute.Name;
			temp += "_";
			temp += _mods[cnt].ratio;
			
			// Cut entry seperately
			if (cnt < _mods.Count - 1)
				temp += "|";
			
			UnityEngine.Debug.Log(temp);
		}
		
		return temp;
	}
}

/// <summary>
/// A structure that will hold an Attribute and ratio that will be added as a modifying attribute to our ModifiedStats
/// </summary>
public struct ModifyingAttribute {
	public Attribute attribute;			// the attribute to be used as a modifier
	public float ratio;					// the percent of attributes AdjustedBaseValue that will be applied to the modifiedStat
	
	/// <summary>
	/// Initializes a new instance of the <see cref="ModifyingAttribute"/> struct.
	/// </summary>
	/// <param name='att'>
	/// Att. the attribute to be used 
	/// </param>
	/// <param name='rat'>
	/// Rat. the ratio to use
	/// </param>
	public ModifyingAttribute(Attribute att, float rat) {
		attribute = att;
		ratio = rat;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值