/// <summary> /// A simple function that takes a string and does a ToUpper /// </summary> /// <param name="input"></param> /// <param name="context"></param> /// <returns></returns> public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context) { var skillResponse = new SkillResponse2(); switch (input.Request) { case LaunchRequest lr: skillResponse.Response.OutputSpeech = new PlainTextOutputSpeech() { Text = "スキルを起動しました。" }; break; case IntentRequest ir: skillResponse = MakeResponse(input, context, input.Session.User.UserId); break; default: skillResponse.Response.OutputSpeech = new PlainTextOutputSpeech() { Text = "不明な呼び出しがされました。" }; break; } return(skillResponse); }
public SkillResponse2 showLastResult(ILambdaContext context, string uid) { // ***** データ読み込み ***** this.loadPracticeData(out Practices practice, out List <Results> resultList, out List <Users> userList); this.loadAllUser(out List <Users> loadAllUser); var repeatResult = resultList.Where(result => result.match_id == resultList.Max(obj => obj.match_id)).OrderBy(obj => obj.id).ToList(); (string msg, SimpleCard card)msgCard = prepareResponse(repeatResult, loadAllUser); SkillResponse2 skillResponse = new SkillResponse2(); skillResponse.Response.OutputSpeech = new PlainTextOutputSpeech() { Text = msgCard.msg }; skillResponse.Response.Card = msgCard.card; skillResponse.Response.ShouldEndSession = false; return(skillResponse); }
private SkillResponse2 MakeResponse(SkillRequest input, ILambdaContext context, string uid) { var skillResponse = new SkillResponse2(); IntentRequest ir = (IntentRequest)input.Request; (string msg, SimpleCard card)msgCard; switch (ir.Intent.Name) { case "dummy": msgCard = ("dummy", new SimpleCard() { Title = "dummy", Content = "dummy" }); skillResponse.Response.OutputSpeech = new PlainTextOutputSpeech() { Text = msgCard.msg }; skillResponse.Response.Card = msgCard.card; skillResponse.Response.ShouldEndSession = false; break; case "NextIntent": skillResponse = new CallNextGameLogic().callNextGame(context, uid, SelectionPatternEnum.DefaultCall); break; case "MixIntent": skillResponse = new CallNextGameLogic().callNextGame(context, uid, SelectionPatternEnum.MixCall); break; case "RepeatIntent": skillResponse = new CallNextGameLogic().callRepeat(context, uid); break; case "ResultUpdatePrepareIntent": skillResponse = new UpdateResultLogic().showLastResult(context, uid); break; case "ResultUpdateExecuteIntent": skillResponse = new UpdateResultLogic().saveResult(context, input, uid); break; } return(skillResponse); }
public SkillResponse2 saveResult(ILambdaContext context, SkillRequest input, string uid) { IntentRequest ir = (IntentRequest)input.Request; // ***** データ読み込み ***** this.loadPracticeData(out Practices practice, out List <Results> resultList, out List <Users> userList); this.loadAllUser(out List <Users> loadAllUser); var results = resultList.Where(result => result.match_id == resultList.Max(obj => obj.match_id)).OrderBy(obj => obj.id).ToList(); //int coat = int.Parse(ir.Intent.Slots[Static.INTENT_SLOT_COAT_NUMBER].Value); //int point1 = int.Parse(ir.Intent.Slots[Static.INTENT_SLOT_POINT_ONE].Value); //int point2 = int.Parse(ir.Intent.Slots[Static.INTENT_SLOT_POINT_TWO].Value); List <string> slotList = new List <string>() { "第一コート", "第二コート", "第三コート", "第四コート", "第五コート", "第六コート", "第七コート", "第八コート" }; int coat = 0, point1 = 0, point2 = 0; bool b1, b2, b3; b1 = int.TryParse(ir.Intent.Slots[Static.INTENT_SLOT_COAT_NUMBER].Value, out coat); b2 = int.TryParse(ir.Intent.Slots[Static.INTENT_SLOT_POINT_ONE].Value, out point1); b3 = int.TryParse(ir.Intent.Slots[Static.INTENT_SLOT_POINT_TWO].Value, out point2); try { if (!b1 || !b2 || !b3) { throw new Exception(); } //if(!results.Any(result => result.count == coat)) //{ // SkillResponse2 errorResponse = new SkillResponse2(); // errorResponse.Response.OutputSpeech = new PlainTextOutputSpeech() { Text = "エラー" }; // errorResponse.Response.Card = new SimpleCard() { Content="指定したコート番号が存在しません。", Title= "第" + coat + "コート" }; // errorResponse.Response.ShouldEndSession = true; // return errorResponse; //} updResults(results[0].match_id, coat, point1, point2); // ***** データ再読み込み ***** this.loadPracticeData(out Practices practice2, out List <Results> resultList2, out List <Users> userList2); var results2 = resultList2.Where(result => result.match_id == resultList.Max(obj => obj.match_id)).OrderBy(obj => obj.id).ToList(); (string msg, SimpleCard card)msgCard = executeResponse(results2, loadAllUser); SkillResponse2 skillResponse = new SkillResponse2(); skillResponse.Response.OutputSpeech = new PlainTextOutputSpeech() { Text = msgCard.msg }; skillResponse.Response.Card = msgCard.card; skillResponse.Response.ShouldEndSession = true; return(skillResponse); } catch (Exception e) { SkillResponse2 errorResponse = new SkillResponse2(); errorResponse.Response.OutputSpeech = new PlainTextOutputSpeech() { Text = "Error" }; errorResponse.Response.Card = new SimpleCard() { Content = "coat = " + coat + "\r\n point1 = " + point1 + "\r\npoint2 = " + point2, Title = "Error" }; errorResponse.Response.ShouldEndSession = true; return(errorResponse); } }
public SkillResponse2 callNextGame(ILambdaContext context, string uid, SelectionPatternEnum pattern) { Random rnd = new Random(DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second); // ***** データ読み込み ***** this.loadPracticeData(out Practices practice, out List <Results> resultList, out List <Users> userList); // 全ゲームに参加したユーザー情報(回数カウント用) List <int> gamePlayerLog = new List <int>(); List <int> lastGameUser = new List <int>(); List <Results> lastGames = new List <Results>(); if (resultList.Any()) { int maxMatchId = resultList.Select(r => r.match_id).Max(); foreach (var r in resultList.OrderByDescending(r => r.match_id)) { gamePlayerLog.Add(r.user1); gamePlayerLog.Add(r.user2); if (r.match_id == maxMatchId) { lastGameUser.Add(r.user1); lastGameUser.Add(r.user2); lastGames.Add(r); } } ; } // 各ユーザーにランダム値と試合率、直前の試合有無を設定 userList.ForEach(user => { user.randomInt = rnd.Next(9999999); user.playPercentage = (user.count ?? 0) == 0 ? 1 : gamePlayerLog.Count(obj => obj == user.id) / (decimal)user.count; user.ContinuousCount = lastGameUser.Count(obj => obj == user.id); }); // コート数取得。最大3コート int coatCount = getCoat(userList); // 次ゲームの参加者決め List <Users> gamePlayers = pattern.getPicker().playerSelect(userList, resultList, coatCount); List <Results> addMatchesAndResults; bool decision; do { decision = false; // 各ユーザーのランダム値更新 gamePlayers.ForEach(user => { user.randomInt = rnd.Next(9999999); }); // ペア決め addMatchesAndResults = pattern.getSelecter().getPairList(gamePlayers, resultList, coatCount); addMatchesAndResults.ForEach(r => decision = decision || lastGames.Select(l => l.pairCheckStr).Contains(r.pairCheckStr)); } while (decision); // DB更新 this.saveData(addMatchesAndResults, gamePlayers, practice, userList); (string msg, SimpleCard card)msgCard = createAlexaResponse(addMatchesAndResults, gamePlayers); SkillResponse2 skillResponse = new SkillResponse2(); skillResponse.Response.OutputSpeech = new PlainTextOutputSpeech() { Text = msgCard.msg }; skillResponse.Response.Card = msgCard.card; skillResponse.Response.ShouldEndSession = null; return(skillResponse); }