当前位置: 首页>>代码示例>>C#>>正文


C# Sandbox.NextAttribs方法代码示例

本文整理汇总了C#中Sandbox.NextAttribs方法的典型用法代码示例。如果您正苦于以下问题:C# Sandbox.NextAttribs方法的具体用法?C# Sandbox.NextAttribs怎么用?C# Sandbox.NextAttribs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sandbox的用法示例。


在下文中一共展示了Sandbox.NextAttribs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public override IEnumerator<RantAction> Run(Sandbox sb)
		{
			var attribs = sb.NextAttribs(this);
			int next = -1;
			int reps = attribs.RepEach ? _items.Count : attribs.Repetitions;
			var block = new BlockState(attribs.Repetitions);
			double weightSum = _constantWeightSum;

			if (attribs.Start != null) yield return attribs.Start;

			if (_weighted && attribs.Sync == null)
			{
				foreach (var dw in _dynamicWeights)
				{
					sb.AddOutputWriter();
					yield return dw.Item2;
					var strWeight = sb.Return().Main;
					if (!Double.TryParse(strWeight, out _weights[dw.Item1]))
						throw new RantRuntimeException(sb.Pattern, dw.Item2.Range,
							$"Dynamic weight returned invalid weight value: '{strWeight}'");
					weightSum += _weights[dw.Item1];
				}
			}

			sb.Blocks.Push(block);
			for (int i = 0; i < reps; i++)
			{
				if (_weighted)
				{
					double choice = sb.RNG.NextDouble(weightSum);
					for (int j = 0; j < _count; j++)
					{
						if (choice < _weights[j])
						{
							next = j;
							break;
						}
						choice -= _weights[j];
					}
				}
				else
				{
					next = attribs.NextIndex(_count, sb.RNG);
				}

				if (next == -1) break;
				block.Next(next);

				sb.Blocks.Pop(); // Don't allow separator to access block state
				// Separator
				if (i > 0 && attribs.Separator != null) yield return attribs.Separator;
				sb.Blocks.Push(block); // Now put it back

				// Prefix
				if (attribs.Before != null) yield return attribs.Before;

				// Content
				sb.Objects.EnterScope();
				yield return _items[next];
				sb.Objects.ExitScope();

				// Affix
				if (attribs.After != null) yield return attribs.After;
			}
			sb.Blocks.Pop();

			if (attribs.End != null) yield return attribs.End;
		}
开发者ID:katnapper323,项目名称:Rant,代码行数:68,代码来源:RABlock.cs

示例2: Run

        public override IEnumerator<RantAction> Run(Sandbox sb)
		{
			var attribs = sb.NextAttribs(this);

			// Skip if chance doesn't fall within range
			if (attribs.Chance < 100 && sb.RNG.NextDouble(0, 100) > attribs.Chance)
			{
				yield break;
			}

			int next = -1;
			int reps = attribs.RepEach ? _items.Count : attribs.Repetitions;
			var block = new BlockState(attribs.Repetitions);
			double weightSum = _constantWeightSum;

			if (attribs.Start != null) yield return attribs.Start;

			if (_weighted && attribs.Sync == null)
			{
				foreach (var dw in _dynamicWeights)
				{
					sb.AddOutputWriter();
					yield return dw.Item2;
					var strWeight = sb.Return().Main;
					if (!Double.TryParse(strWeight, out _weights[dw.Item1]))
						throw new RantRuntimeException(sb.Pattern, dw.Item2.Range,
							$"Dynamic weight returned invalid weight value: '{strWeight}'");
					weightSum += _weights[dw.Item1];
				}
			}
	        
			sb.Blocks.Push(block);
			for (int i = 0; i < reps; i++)
			{
				if (_weighted)
				{
					double choice = sb.RNG.NextDouble(weightSum);
					for (int j = 0; j < _count; j++)
					{
						if (choice < _weights[j])
						{
							next = j;
							break;
						}
						choice -= _weights[j];
					}
				}
				else
				{
					next = attribs.NextIndex(_count, sb.RNG);
				}

				if (next == -1) break;
				block.Next(next);

				sb.Blocks.Pop(); // Don't allow separator to access block state
				// Separator
				if (i > 0 && attribs.Separator != null)
				{
					if (attribs.IsSeries)
					{
						// Check if we're on the last separator in a series
						if (i == reps - 1)
						{
							// Add the oxford comma if specified
							if (attribs.EndSeparator != null)
							{
								// If there are more than two items, print it!
								if (reps > 2) yield return attribs.EndSeparator;
							}

							sb.Print(sb.Format.StandardSpace);

							// Add conjunction if specified (it normally should be, if it's a series)
							if (attribs.EndConjunction != null)
							{
								yield return attribs.EndConjunction;
								sb.Print(sb.Format.StandardSpace);
							}
						}
						else if (reps > 2)
						{
							yield return attribs.Separator;
							sb.Print(sb.Format.StandardSpace);
						}
					}
					else
					{
						yield return attribs.Separator;
					}
				}
				sb.Blocks.Push(block); // Now put it back

				// Prefix
				if (attribs.Before != null) yield return attribs.Before;

				// Content
				sb.Objects.EnterScope();
				yield return _items[next];
				sb.Objects.ExitScope();
//.........这里部分代码省略.........
开发者ID:W-h-a-t-s,项目名称:Rant,代码行数:101,代码来源:RABlock.cs


注:本文中的Sandbox.NextAttribs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。