public RewardItem AcquireItem() { if (m_Items.Length == 0) { return(null); } else if (m_Items.Length == 1) { return(m_Items[0]); } int totalWeight = 0; for (int i = 0; i < m_Items.Length; ++i) { totalWeight += m_Items[i].Weight; } int randomWeight = Utility.Random(totalWeight); for (int i = 0; i < m_Items.Length; ++i) { RewardItem item = m_Items[i]; if (randomWeight < item.Weight) { return(item); } randomWeight -= item.Weight; } return(null); }
public override List <Item> ComputeRewards(bool full) { List <Item> list = new List <Item>(); RewardGroup rewardGroup = SmithRewardCalculator.Instance.LookupRewards(SmithRewardCalculator.Instance.ComputePoints(this)); if (rewardGroup != null) { if (full) { for (int i = 0; i < rewardGroup.Items.Length; ++i) { Item item = rewardGroup.Items[i].Construct(); if (item != null) { list.Add(item); } } } else { RewardItem rewardItem = rewardGroup.AcquireItem(); if (rewardItem != null) { Item item = rewardItem.Construct(); if (item != null) { list.Add(item); } } } } return(list); }