/// <summary> /// Ends the turn for the <see cref="WorldState.ActiveFaction"/>, which must be controlled /// by a local human player, and activates subsequent factions.</summary> /// <exception cref="PropertyValueException"> /// The current session <see cref="Session.State"/> is not <see cref="SessionState.Human"/>. /// </exception> /// <remarks><para> /// <b>EndTurn</b> should be called whenever a local human player wishes to end his turn. /// This method performs the following actions: /// </para><list type="number"><item> /// Save the current <see cref="Session.WorldState"/> to the predefined <see /// cref="SessionFileType.Auto"/> session file. /// </item><item> /// Issue an <see cref="EndTurnCommand"/> for the <see cref="WorldState.ActiveFaction"/>. /// </item><item> /// Call <see cref="Session.Dispatch"/> on the current <see cref="Session"/> to dispatch the /// game to the player controlling the faction that was activated in the previous step. /// </item></list><para> /// <b>EndTurn</b> calls <see cref="Session.Close"/> without confirmation if an error /// occurred, or if a faction controlled by a remote human player was activated. /// </para></remarks> public static void EndTurn() { CheckSessionState(); Session session = Session.Instance; // autosave game before executing command string path = FilePaths.GetSessionFile(SessionFileType.Auto).AbsolutePath; session.Save(ref path, false); AsyncAction.BeginRun(delegate { Action postAction; // issue EndTurn command and dispatch game to next player if (session.Executor.ExecuteEndTurn(session.WorldState)) { postAction = session.Dispatch; } else { postAction = () => Session.Close(false); } AsyncAction.BeginInvoke(delegate { postAction(); AsyncAction.EndRun(); }); }); }