Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created March 26, 2025 07:00
Show Gist options
  • Select an option

  • Save todorok1/7736109a1dfe106286bc61a09c137e83 to your computer and use it in GitHub Desktop.

Select an option

Save todorok1/7736109a1dfe106286bc61a09c137e83 to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第53回 行動処理の全体を管理するクラス
/// <summary>
/// アクションリストの要素の優先度を設定します。
/// </summary>
public void SetPriorities()
{
// アクションコマンドの素早さの値に20%の乱数を乗じます。
foreach (var action in _actions)
{
action.actorSpeed = (int)(action.actorSpeed * (1 + Random.Range(-0.2f, 0.2f)));
}
// 遅い順に並べ替え、優先度を1から順に設定します。
// 優先度が大きい方を先に処理します。
var query = _actions.OrderBy(a => a.actorSpeed);
int priority = 1;
int runPriority = 100;
foreach (var action in query)
{
if (action.battleCommand == BattleCommand.Run)
{
action.priority = runPriority;
continue;
}
action.priority = priority;
priority++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment