public override bool TakeAction() { UserGuild guild = new ShareCacheStruct <UserGuild>().FindKey(ContextUser.MercenariesID); if (guild == null) { ErrorCode = LanguageManager.GetLang().ErrorCode; ErrorInfo = LanguageManager.GetLang().St6301_GuildExerciseIsOpen; return(false); } GameActive gameactive = new ShareCacheStruct <GameActive>().FindKey(11); if (gameactive == null || !gameactive.State) { ErrorCode = LanguageManager.GetLang().ErrorCode; ErrorInfo = LanguageManager.GetLang().St6301_GuildExerciseIsOpen; return(false); } gameactive.BeginTime = gameactive.EnablePeriod.ToDateTime(DateTime.MinValue); gameactive.EndTime = gameactive.BeginTime.AddMinutes(gameactive.Minutes); DateTime readytime = gameactive.BeginTime.AddMinutes(0 - gameactive.WaitMinutes); if (gameactive.BeginTime > DateTime.Now) { ErrorCode = LanguageManager.GetLang().ErrorCode; ErrorInfo = LanguageManager.GetLang().St6301_GuildExerciseIsOpen; return(false); } if (gameactive.EndTime < DateTime.Now.AddSeconds(2)) { ContextUser.UserLocation = Location.City; Status = 3; ColdTime = 10; ErrorInfo = LanguageManager.GetLang().St6301_GuildExerciseClose; return(true); } if (guild.GuildExercise == null) { ContextUser.UserLocation = Location.City; Status = 3; ColdTime = 10; ErrorInfo = LanguageManager.GetLang().St6301_GuildExerciseClose; return(true); } if (guild.GuildExercise.UserList.Count == 0) { ContextUser.UserLocation = Location.City; Status = 3; ColdTime = 10; ErrorInfo = LanguageManager.GetLang().St6301_GuildExerciseClose; return(true); } ExerciseUser exUser = guild.GuildExercise.UserList.Find(u => u.UserID == ContextUser.UserID); if (exUser == null) { ContextUser.UserLocation = Location.City; Status = 3; ColdTime = 10; ErrorInfo = LanguageManager.GetLang().St6301_GuildExerciseClose; return(true); } Question = GuildExerciseHelper.GetQuestion(guild, gameactive, exUser, ref ColdTime); if (Question == null) { Question = null; } if (Question != null) { Level = guild.GuildExercise.Level; QuestionNo = guild.GuildExercise.QuestionNo; } if (guild.GuildExercise.QuestionNo - exUser.QuestionNo > 5) { ContextUser.UserLocation = Location.City; Status = 3; ColdTime = 10; ErrorInfo = LanguageManager.GetLang().St6301_GuildExerciseTimeOut; return(true); } if (guild.GuildExercise.CheckAllAnswer == 0) { if (guild.GuildExercise.QuestionNo != exUser.QuestionNo) { exUser.QuestionStatus = GuildQuestionStatus.ToAnswer; } } else { exUser.QuestionStatus = GuildQuestionStatus.ToNext; } Status = guild.GuildExercise.Status; QueueStatus = (int)exUser.QuestionStatus; IsAuto = exUser.Status == GuildExerciseStatus.All ? 1 : 0; return(true); }
public static GuildQuestion GetQuestion(UserGuild userGuild, GameActive gameActive, ExerciseUser exUser, ref int ColdTime) { DateTime dt = DateTime.Now; DateTime beginTime = gameActive.BeginTime.AddMinutes(gameActive.WaitMinutes); if (dt < gameActive.BeginTime.AddMinutes(gameActive.WaitMinutes)) { ColdTime = (int)(beginTime - dt).TotalSeconds; userGuild.GuildExercise.UpdateNotify(obj => { userGuild.GuildExercise.Status = 1; return(true); }); return(null); } GuildQuestion Question = new GuildQuestion(); if (userGuild.GuildExercise.QuesTime != null && dt < userGuild.GuildExercise.QuesTime.AddSeconds(QuestionWaitTime) && userGuild.GuildExercise.QuestionID != 0) { Question = new ConfigCacheSet <GuildQuestion>().FindKey(userGuild.GuildExercise.QuestionID); } else { int questionid = GetID(userGuild.GuildExercise.QuestionIDList.ToList()); userGuild.GuildExercise.QuestionID = questionid; Question = new ConfigCacheSet <GuildQuestion>().FindKey(userGuild.GuildExercise.QuestionID); userGuild.GuildExercise.UpdateNotify(obj => { if (userGuild.GuildExercise.QuesTime < beginTime) { userGuild.GuildExercise.QuesTime = beginTime; } int count = ((int)(dt - userGuild.GuildExercise.QuesTime).TotalSeconds) / QuestionWaitTime; if (count <= 0) { count = 0; } userGuild.GuildExercise.QuestionNo = MathUtils.Addition(userGuild.GuildExercise.QuestionNo, (count <= 1 ? 1 : count), int.MaxValue); userGuild.GuildExercise.QuesTime = beginTime.AddSeconds((userGuild.GuildExercise.QuestionNo - 1) * QuestionWaitTime); userGuild.GuildExercise.Status = 2; //已开始活动 userGuild.GuildExercise.CheckAllAnswer = 0; return(true); });//userGuild.Update(); exUser.QuestionStatus = GuildQuestionStatus.ToAnswer; } ColdTime = QuestionWaitTime - (int)(dt - userGuild.GuildExercise.QuesTime).TotalSeconds; if (userGuild.GuildExercise.CheckAllAnswer == 0) { ColdTime -= 10; } if (ColdTime <= 0) { ColdTime = 0; return(null); } return(Question); }