public override async Task <CardResult> MessageReceived(IMessage message, CardResult lastCardResult = CardResult.None) { var result = CardResult.Continue; if (!Asked) { Asked = true; await ReplyAsync(Message); } else { if (string.IsNullOrWhiteSpace(message.Content)) { await ReplyAsync($"Sorry, I didn't see a response. {RetryMessage}"); } else { if (message.MentionedRoleIds.Count == 0) { await ReplyAsync($"You need to mention the role, not just type its name. {RetryMessage}"); } else if (message.MentionedRoleIds.Count > 1) { await ReplyAsync($"Please only mention one role. {RetryMessage}"); } else { var roleId = message.MentionedRoleIds.First(); Result = Context.Guild.GetRole(roleId); result = CardResult.CloseAndContinue; } } } return(result); }
public static void Send(CardResolvePhase phase, CardResult result, CardConfigData configData) { e.ResolvePhase = phase; e.Result = result; e.ConfigData = configData; EventManager.TriggerEvent(e); }
public override async Task <CardResult> MessageReceived(IMessage message, CardResult lastCardResult = CardResult.None) { var result = CardResult.Continue; if (!Asked) { Asked = true; await ReplyAsync(Message); } else { if (TrueOptions.Contains(message.Content.ToLower().Trim(), StringComparer.OrdinalIgnoreCase)) { Result = true; result = CardResult.CloseAndContinue; } else if (FalseOptions.Contains(message.Content.ToLower().Trim(), StringComparer.OrdinalIgnoreCase)) { Result = true; result = CardResult.CloseAndContinue; } else { var options = TrueOptions.Union(FalseOptions).ToArray(); string optionString = options.ToSentence(); await ReplyAsync($"I was expecting an answer of ${optionString}. ${RetryMessage}"); } } return(result); }
private void PlayPreviewAnim(CardResult result, float a, float my, float speed) { var g = result == CardResult.Yes ? YesGroup : NoGroup; var duration = Mathf.Abs(g.alpha - a) / speed; if (result == CardResult.Yes) { _yesTween?.Kill(); } else if (result == CardResult.No) { _noTween?.Kill(); } var tween = DOTween.Sequence() .Join(g.transform.DOLocalMoveY(my, duration)) .Join(g.DOFade(a, duration)) .SetEase(Ease.OutSine); if (result == CardResult.Yes) { _yesTween = tween; } else if (result == CardResult.No) { _noTween = tween; } }
public void Confirm(CardResult result) { if (IsConfirmed) { return; } var clip = result == CardResult.Yes ? YesClip : NoClip; if (clip != null) { AudioSource.PlayClipAtPoint(clip, Vector3.zero); } CardEvent.Send(CardResolvePhase.Preview, result, null); Debug.Log($"Confirmed {result} {ConfigData.Id} {ConfigData.Destext}"); IsConfirmed = true; CardEvent.Send(CardResolvePhase.Resolving, result, ConfigData); DOTween.Kill(transform); var dir = ResultToDir(result); var endPos = dir * ResolvedDist * SlideDiret; var time = Vector2.Distance(transform.localPosition, endPos) / 500; transform.DOLocalMove(endPos, time) .OnComplete(() => { CardEvent.Send(CardResolvePhase.Resolved, result, ConfigData); }) .SetEase(Ease.OutQuad); _cardGroup.DOFade(0, time) .SetEase(Ease.OutQuad); }
public override void ResolvedCard(CardConfigData configData, CardResult result) { base.ResolvedCard(configData, result); if (Value == 0) { GameMgr.Instance.GameOver(true, "你的钱耗尽了"); } }
public override void ResolvingCard(CardConfigData configData, CardResult result) { base.ResolvingCard(configData, result); if (Value <= BadMoodRange.x || Value >= BadMoodRange.y) { GameMgr.Instance.Mood.DailyExtraExpend += ExtraMoodExpend; } }
public virtual void ResolvingCard(CardConfigData configData, CardResult result) { var val = GetPropertyVal(configData, result); if (val != 0) { Value += val; } }
private static Penalization ExtractPenalization(PenalizationDto dto) { return(new Penalization { IsShortPerformance = dto.IsShortPerformance, PenalizationId = dto.PenalizationId, Performance = ExtractPerformance(dto.Performance), Reason = dto.Reason, RuleInput = dto.RuleInput, ShortReason = dto.ShortReason, CardResult = CardResult.Parse(dto.CardResult) }); }
public override async Task <CardResult> MessageReceived(IMessage message, CardResult lastCardResult = CardResult.None) { switch (ActiveSetupStep) { case SetupStep.Welcome: await SendWelcomeMessage(); return(await RequestGuildCommandPrefix(message)); case SetupStep.GuildCommandPrefix: SaveGuildCommandPrefix(); return(await RequestGuildRole( SetupStep.BotGuildAdministratorRole, "What role would you like to use for the Server Administrator?", "What role would you like to use?", message)); case SetupStep.BotGuildAdministratorRole: SaveGuildRole(RoleLevel.GuildAdministrator); return(await RequestGuildRole( SetupStep.BotGuildSuperMemberRole, "What role would you like to use for Super Members?", "What role would you like to use?", message)); case SetupStep.BotGuildSuperMemberRole: SaveGuildRole(RoleLevel.SuperMember); return(await RequestGuildRole( SetupStep.BotGuildMemberRole, "What role would you like to use for Members?", "What role would you like to use?", message)); case SetupStep.BotGuildMemberRole: SaveGuildRole(RoleLevel.Member); return(await RequestGuildRole( SetupStep.BotGuildGuestRole, "What role would you like to use for Guests?", "What role would you like to use?", message)); case SetupStep.BotGuildGuestRole: SaveGuildRole(RoleLevel.Guest); return(await RequestAssignGuestRoleOnJoin(message)); case SetupStep.AssignGuestRoleOnJoin: SaveAssignGuestRoleOnJoin(); return(await SetupComplete()); } return(CardResult.Continue); }
public virtual void Preview(CardConfigData configData, CardResult result) { var val = GetPropertyVal(configData, result); val = Mathf.Abs(val); if (val >= MinBigPreview) { PlayPreviewAnim(PreviewImg, 1.25f, 1); } else if (val > 0) { PlayPreviewAnim(PreviewImg, 0.9f, 1); } }
private async Task CloseCard(ICard card, CardResult lastCardResult) { bool closeActiveCard = true; while (closeActiveCard) { // make sure we are closing cards in order if (Stack.Peek() != card) { break; } //pull the card off the stack if (Stack.Count > 0) { // pull the active card off the stack Stack.Pop(); } // if there are still cards left on the stack if (Stack.Count > 0) { var lastCard = Stack.Peek(); // set the context before we activate the card lastCard.Context = card.Context; // let the parent dialog know the child closed var result = await lastCard.MessageReceived(card.Context.UserMessage, lastCardResult); card = lastCard; // if the card indicated it wanted to close if (result == CardResult.CloseAndContinue) { // loop around again to close the active card closeActiveCard = true; } } // the card was not the topmost card on the stack else { // don't loop around again, bail closeActiveCard = false; } } }
public override async Task <CardResult> MessageReceived(IMessage message, CardResult lastCardResult = CardResult.None) { if (ConfirmLeave == null) { ConfirmLeave = new InputBooleanCard("Are you sure you want the bot to leave the guild? All guild configuration will be lost.", true, new string[] { "cancel" }, "Are you sure?", new string[] { "yes" }, new string[] { "no" }); await this.CardStack.ShowCard(ConfirmLeave, message, this.LlectroBotContext); return(CardResult.Continue); } else { // if they didn't cancel out of the card, and they answered true (yes) if (lastCardResult != CardResult.Cancel && ConfirmLeave.Result) { // adios, buck-o. Time to boogie! var builder = new EmbedBuilder() .WithTitle("So long, and thanks for all the fish! 👋") .WithDescription( "They asked me here and gave me trust.\n" + "Then go they said, so go I must.\n" + "But if by chance you didn't think,\n" + "Just go ahead, and click this link!\n" ) .WithUrl($"https://discordapp.com/oauth2/authorize?client_id={Context.DiscordClient.CurrentUser.Id}&scope=bot&permissions=2146958847"); var botUser = await Context.Guild.GetCurrentUserAsync(); if (botUser.HasPermission(Context.Channel as IGuildChannel, ChannelPermission.SendMessages)) { await ReplyAsync(embed : builder.Build()); } else { ulong guildOwnerId = Context.Guild.OwnerId; var channel = Context.DiscordClient.GetDMChannelAsync(guildOwnerId) as ITextChannel; await channel.SendMessageAsync(embed : builder.Build()); } } return(CardResult.CloseAndContinue); } }
public void ShowPreview(CardConfigData configData, CardResult result) { if (_previewResult == result) { return; } _previewResult = result; if (result == CardResult.Yes) { PlayPreviewAnim(CardResult.Yes, 1, _yesPosY + 30, 3); PlayPreviewAnim(CardResult.No, 0, _noPosY, 6); } else { PlayPreviewAnim(CardResult.No, 1, _noPosY - 30, 3); PlayPreviewAnim(CardResult.Yes, 0, _yesPosY, 6); } }
void newRound() { if (selfState.health <= 0 && opponentState.health <= 0) { gameResult = CardResult.Tie; return; } if (selfState.health <= 0) { gameResult = CardResult.Lose; } if (opponentState.health <= 0) { gameResult = CardResult.Win; } currentRound++; selfIdx = -1; opponentIdx = -1; }
private static CardResult CombineCards(CardResult a, CardResult b) { if (a == CardResult.Red || b == CardResult.Red) { return(CardResult.Red); } if (a == CardResult.Yellow || b == CardResult.Yellow) { return(CardResult.Yellow); } if (a == CardResult.DidNotStart || b == CardResult.DidNotStart) { return(CardResult.DidNotStart); } if (a == CardResult.White || b == CardResult.White) { return(CardResult.White); } return(CardResult.None); }
public void Execute(object o) { var result = (GridReader)o; var adResult = result.Read <AdResult>(); var addressResult = result.Read <AddressResult>(); var ownerResult = result.Read <OwnerResult>(); var imageResult = result.Read <AdImageResult>(); foreach (var ad in adResult) { var card = new CardResult(); card.Ad = ad; card.Address = addressResult.FirstOrDefault(f => f.id.Equals(ad.idAddress)); card.Owner = ownerResult.FirstOrDefault(f => f.id.Equals(ad.idOwner)); card.Owner = ownerResult.FirstOrDefault(f => f.id.Equals(ad.idOwner)); card.Images = imageResult.Where(f => f.GuidProduct.Equals(ad.Guid)).ToList(); this.cards.Add(card); } }
public override async Task <CardResult> MessageReceived(IMessage message, CardResult lastCardResult = CardResult.None) { CardResult result = CardResult.Continue; if (!Asked) { Asked = true; await ReplyAsync(Message); } else if (CountByCard != null) { StringBuilder builder = new StringBuilder(); builder.Append("0, "); int i = 0; while (i < Result) { i += CountByCard.Result; builder.Append($"{i}, "); } await ReplyAsync($"OK, counting to {Result} by {CountByCard.Result}: {builder.ToString()[0..^2]}"); // builder.ToString().Substring(0, builder.ToString().Length - 2)
private static CardUrlResult BuildResult(Employer employer, List <dynamic> cardResults) { var result = new CardUrlResult(); result.Results = new List <CardResult>(); var cardBaseAddress = "CardBaseAddress".GetConfigurationValue(); cardResults.ForEach(cr => { var cardMemberData = new CardDetail(); try { cardMemberData = JsonConvert.DeserializeObject <CardDetail>(cr.MemberCard.CardMemberDataText); } catch { } var cardToken = new CardToken() { EmployerId = employer.Id, CardDetail = cardMemberData, Expires = DateTime.UtcNow.AddMinutes(Convert.ToInt16("TimeoutInMinutes".GetConfigurationValue())) }; cardToken.CardDetail.CardTypeFileName = cr.CardType.FileName; cardToken.CardDetail.CardTypeId = cr.MemberCard.CardTypeId; cardToken.CardDetail.CardViewModeId = cr.CardViewMode.Id; var jwt = ClearCost.Security.JwtService.EncryptPayload(JsonConvert.SerializeObject(cardToken)); var cardResult = new CardResult() { CardName = cr.CardTypeTranslation.CardTypeName, ViewMode = cr.CardViewMode.Name, CardUrl = string.Format("{0}/?tkn={1}|{2}", cardBaseAddress, employer.Id, jwt), SecurityToken = jwt }; result.Results.Add(cardResult); }); return(result); }
public override async Task <CardResult> MessageReceived(IMessage message, CardResult lastCardResult = CardResult.None) { var result = CardResult.Continue; if (!Asked) { Asked = true; await ReplyAsync(Message); } else { if (message.Content.Trim().Length > MaximumLength && MaximumLength > 0) { await ReplyAsync($"Sorry, that was too many characters. I need at most {MaximumLength} character{(MaximumLength > 1 ? "s" : string.Empty)}. {RetryMessage}"); } else { Result = message.Content.Trim(); result = CardResult.CloseAndContinue; } } return(result); }
public override async Task <CardResult> MessageReceived(IMessage message, CardResult lastCardResult = CardResult.None) { CardResult result = CardResult.Continue; if (!Asked) { Asked = true; await ReplyAsync("What number should i increment by?"); } else { if (!int.TryParse(message.Content, out int number)) { await ReplyAsync("That wasn't a number I understood. Please only use digits."); } else { Result = number; result = CardResult.CloseAndContinue; } } return(result); }
protected override int GetPropertyVal(CardConfigData configData, CardResult result) { return(result == CardResult.Yes ? configData.Yesenddays : configData.Noenddays); }
protected override int GetPropertyVal(CardConfigData configData, CardResult result) { return(result == CardResult.Yes ? configData.Yesmood : configData.Nomood); }
public override void ResolvedCard(CardConfigData configData, CardResult result) { CheckGameOver(); }
public void PostAthleteResult(string raceId, string athleteId, Judge authenticatedJudge, ActualResultDto incomingResult) { if (string.IsNullOrEmpty(raceId)) { throw new ArgumentNullException("Missing RaceId"); } if (string.IsNullOrEmpty(athleteId)) { throw new ArgumentNullException("Missing AthleteId"); } if (authenticatedJudge == null) { throw new ArgumentNullException("Missing AuthenticationToken"); } if (string.IsNullOrEmpty(incomingResult.DisciplineId)) { throw new ArgumentNullException("Missing DisciplineId"); } var repositorySet = repositorySetProvider.GetRepositorySet(raceId); var athlete = repositorySet.Athletes.FindAthlete(athleteId); if (athlete == null) { throw new ArgumentOutOfRangeException("Unknown AthleteId " + athleteId); } var discipline = repositorySet.Disciplines.FindDiscipline(incomingResult.DisciplineId); if (discipline == null) { throw new ArgumentOutOfRangeException("Wrong DisciplineId " + incomingResult.DisciplineId); } var rules = rulesRepository.Get(discipline.Rules); if (discipline.ResultsClosed) { throw new ArgumentOutOfRangeException("Discipline " + incomingResult.DisciplineId + " already closed results"); } ActualResult finalResult = new ActualResult(); finalResult.DisciplineId = discipline.DisciplineId; finalResult.JudgeId = authenticatedJudge.JudgeId; finalResult.Penalizations = new List <Penalization>(); finalResult.CardResult = CardResult.Parse(incomingResult.CardResult); finalResult.AddedDate = DateTimeOffset.UtcNow; if (incomingResult.JudgeOverride) { finalResult.Performance = ExtractPerformance(incomingResult.Performance); finalResult.FinalPerformance = ExtractPerformance(incomingResult.FinalPerformance); finalResult.JudgeComment = incomingResult.JudgeComment; } else { var announcement = athlete.Announcements.FirstOrDefault(a => a.DisciplineId == incomingResult.DisciplineId); if (announcement == null) { throw new ArgumentOutOfRangeException("No announcement for " + incomingResult.DisciplineId); } foreach (var incomingPenalization in incomingResult.Penalizations) { if (incomingPenalization.IsShortPerformance) { continue; // we will calculate this ourselves } if (incomingPenalization.PenalizationId == null || incomingPenalization.PenalizationId == "Custom") // custom penalization { VerifyResult(rules.HasDepth, false, incomingPenalization.Performance.Depth, "Penalization.Depth"); VerifyResult(rules.HasDuration, false, incomingPenalization.Performance.DurationSeconds(), "Penalization.Duration"); VerifyResult(rules.HasDistance, false, incomingPenalization.Performance.Distance, "Penalization.Distance"); VerifyResult(rules.HasPoints, false, incomingPenalization.Performance.Points, "Penalization.Points"); finalResult.Penalizations.Add(ExtractPenalization(incomingPenalization)); } else { var rulesPenalization = rules.Penalizations.FirstOrDefault(p => p.Id == incomingPenalization.PenalizationId); if (rulesPenalization == null) { throw new ArgumentOutOfRangeException("Unknown Penalization.Id " + incomingPenalization.PenalizationId); } var finalPenalization = rulesPenalization.BuildPenalization(incomingPenalization.RuleInput ?? 0, finalResult.Performance); if (finalPenalization != null) { finalResult.Penalizations.Add(finalPenalization); finalResult.CardResult = CombineCards(finalResult.CardResult, finalPenalization.CardResult); } } } bool didFinish = finalResult.CardResult == CardResult.White || finalResult.CardResult == CardResult.Yellow; VerifyResult(rules.HasDepth, rules.HasDepth && didFinish, incomingResult.Performance.Depth, "Performance.Depth"); VerifyResult(rules.HasDuration, rules.HasDuration && didFinish, incomingResult.Performance.DurationSeconds(), "Performance.Duration"); VerifyResult(rules.HasDistance, rules.HasDistance && didFinish, incomingResult.Performance.Distance, "Performance.Distance"); finalResult.Performance = ExtractPerformance(incomingResult.Performance); if (!rules.HasPoints) { finalResult.Performance.Points = null; } else { finalResult.Performance.Points = rules.GetPoints(incomingResult.Performance); } bool skipShortCalculation = finalResult.CardResult == CardResult.Red || finalResult.CardResult == CardResult.DidNotStart; if (!skipShortCalculation) { var shortPenalization = rules.BuildShortPenalization(announcement.Performance, finalResult.Performance); if (shortPenalization != null) { finalResult.Penalizations.Insert(0, shortPenalization); finalResult.CardResult = CombineCards(finalResult.CardResult, CardResult.Yellow); } } finalResult.FinalPerformance = new Performance(); CalculateFinalPerformance(finalResult, PerformanceComponent.Duration, rules.PenalizationsTarget); CalculateFinalPerformance(finalResult, PerformanceComponent.Depth, rules.PenalizationsTarget); CalculateFinalPerformance(finalResult, PerformanceComponent.Distance, rules.PenalizationsTarget); CalculateFinalPerformance(finalResult, PerformanceComponent.Points, rules.PenalizationsTarget); } athlete.ActualResults.Add(finalResult); repositorySet.Athletes.SaveAthlete(athlete); }
private float ResultToDir(CardResult result) { return(result == CardResult.Yes && !YesIsNegativeDir || result == CardResult.No && YesIsNegativeDir ? 1 : -1); }
public virtual void RedPenalizationListed(string id, string reason, string shortReason, string cardResult) { RedPenalizationListed(id, reason, shortReason, CardResult.Parse(cardResult)); }
public void RedPenalizationListed(string id, string reason, string shortReason, CardResult cardResult) { Assert.That(Rule.Penalizations, Has.One.Property("Id").EqualTo(id)); var rulePenalization = Rule.Penalizations.Single(p => p.Id == id); Assert.That(rulePenalization.Reason, Is.EqualTo(reason)); Assert.That(rulePenalization.ShortReason, Is.EqualTo(shortReason)); Assert.That(rulePenalization.HasInput, Is.False); Assert.That(rulePenalization.CardResult, Is.EqualTo(cardResult)); Assert.That(rulePenalization.PenaltyCalculation, Is.Null); }
public async Task <CardResult> GetNextCardText(IDialogContext context, Activity activity) { var botdata = context.PrivateConversationData; var userInput = activity.Text; UserProfile userProfileData = null; if (botdata.ContainsKey(UserDataKey)) { userProfileData = botdata.GetValue <UserProfile>(UserDataKey); } var jObjectValue = activity.Value as JObject; var cardProvider = Convert.ToString(jObjectValue["nextcard"]); if (userProfileData == null) { userProfileData = new UserProfile(); } if (cardProvider == "ShowInterviewDate") { userProfileData.InterviewDate = CommonDAL.getInterviewDate(); } if (cardProvider != "") { Type cardProviderType = Type.GetType("RecruitmentQnA.Bot.CardProviders." + cardProvider); if (cardProviderType != null) { object classInstance = Activator.CreateInstance(cardProviderType, null); MethodInfo methodInfo = cardProviderType.GetMethod("GetCardResult"); object[] parametersArray = new object[] { userProfileData, jObjectValue, activity.Text, context }; dynamic cardResult = methodInfo.Invoke(classInstance, parametersArray); CardResult r = cardResult.Result; if (string.IsNullOrEmpty(r.ErrorMessage)) { var action = Convert.ToString(jObjectValue["action"]); if (!string.IsNullOrEmpty(action)) { string validationErr = ValidateInfo(jObjectValue); if (string.IsNullOrEmpty(validationErr)) { userProfileData = AssignValuesToUser(userProfileData, jObjectValue); } else { r.ErrorMessage = validationErr; } if (action.ToLower() == "saveindb" && string.IsNullOrEmpty(r.ErrorMessage)) { int result = UserProfileDAL.SaveUserProfile(userProfileData); if (result == 0) { r.ErrorMessage = "I'm sorry, I couldn't save your record. Please contact helpdesk/support for more information."; } } botdata.SetValue(UserDataKey, userProfileData); } } return(r); } else { new CardResult() { ErrorMessage = "I'm sorry, I don't understand. Please rephrase, or use the Card to respond." } }; } return(new CardResult() { ErrorMessage = "I'm sorry, I don't understand. Please rephrase, or use the Card to respond." }); }
public CardResult Use() { var cardResult = new CardResult(true); return(cardResult); }