/// <summary> /// Эту процедуру вызываем когда нужно зарегистрировать прогресс игрока (что он прошёл текущую сцену или что-то ещё) /// </summary> /// <param name="playerId"></param> public static PlayerProgressElement RegisterPlayerProgress(int playerId) { PlayerProgressElement currentElement = CurrentProgressElementForPlayer(playerId); currentElement.SaveData(); PlayerProgressElement tElement = new PlayerProgressElement(playerId, NextStoryObject(currentElement)); playerProgressElementDictionary[playerId] = new PlayerProgressElement(playerId, NextStoryObject(currentElement)); if (!CheckAutomaticallyExecutionedEvent(playerId)) { return(playerProgressElementDictionary[playerId]); } else { return(RegisterPlayerProgress(playerId)); } }
private static StoryObjectFlowElement NextStoryObject(PlayerProgressElement curObject) { CreateStoryObjectDictionary(); if (curObject == null) { curObject = new PlayerProgressElement(); } if (NextStoryObjectDictionary.ContainsKey(curObject.ObjectKey)) { return(NextStoryObjectDictionary[curObject.ObjectKey]); } else { return(null); } }
/// <summary> /// Эту процедуру следует вызывать когда нужно получить текущий элемент истории, на котором /// находится игрок /// </summary> /// <param name="playerId"></param> /// <returns></returns> public static PlayerProgressElement CurrentProgressElementForPlayer(int playerId) { StoryObjectFlowElement tElement; PlayerProgressElement curElement; if (playerProgressElementDictionary == null) { playerProgressElementDictionary = new Dictionary <int, PlayerProgressElement>(); } if (playerProgressElementDictionary.ContainsKey(playerId)) { /*var currentProgress = playerProgressElementDictionary[playerId]; * tElement = NextStoryObject(currentProgress); * curElement = new PlayerProgressElement(playerId, tElement); * playerProgressElementDictionary[playerId] = curElement;*/ return(playerProgressElementDictionary[playerId]); } string q = $@" SELECT id, player, object_type, object_id, date_completed FROM players_progress INNER JOIN ( SELECT MAX(date_completed) AS max_date_completed FROM players_progress WHERE player = {playerId} ) AS max_players_progress ON max_players_progress.max_date_completed = players_progress.date_completed WHERE player = {playerId}"; SqlDataReader r = DataConnection.GetReader(q); if (r.HasRows) { r.Read(); curElement = new PlayerProgressElement(r); } else { curElement = new PlayerProgressElement(); } r.Close(); tElement = NextStoryObject(curElement); curElement = new PlayerProgressElement(playerId, tElement); playerProgressElementDictionary.Add(playerId, curElement); if (CheckAutomaticallyExecutionedEvent(playerId)) { return(CurrentProgressElementForPlayer(playerId)); } else { return(curElement); } }