public async Task <JsonResult> Data() { var user = await _udb.Users.Include(u => u.quest).SingleOrDefaultAsync(u => u.UserName == User.Identity.Name); if (user.quest == null) { user.quest = new UserQuest(); await _udb.SaveChangesAsync(); } var desc = new GameChoiceDescriptor(user.quest); return(Json(new { nickname = user.NickName, progress = user.quest.Progress, profession = UserQuest.ProfessionName(user.quest.Profession), stats = user.quest.Progress == UserQuest.GameProgress.Act1AfterChoose ? await GetProfessionStatsAsync() : null, isdead = user.quest.IsDead, deathcount = user.quest.DeathCount, act2choice = desc.GetAct2Choice(), act3choice = desc.GetAct3Choice(), act4choice = desc.GetAct4Choice(), act5choice = desc.GetAct5Choice(), act5bchoice = desc.GetAct5bChoice(), act6choice = desc.GetAct6Choice() == "true", question = desc.GetCurrentQuestion(), })); }
public string GetProgressString(IEnumerable <UserItemCount> userItems) { if (Hidden && !Satisfy(userItems)) { return(""); } if (userItems.All(uic => !Related(uic))) { return(""); } StringBuilder sb = new StringBuilder(); sb.AppendFormat("称号【{0}】:", UserQuest.ProfessionName(Title)); foreach (var cond in NameCountMap) { var item = userItems.FirstOrDefault(uic => uic.ItemName == cond.Key); if (item != null) { int progress = item.ItemCount; int threshold = cond.Value; if (progress > threshold) { progress = threshold; } sb.AppendFormat($"{cond.Key} {progress}/{threshold};"); } else { sb.AppendFormat($"??? 0/{cond.Value};"); } } return(sb.ToString()); }
public string GetProgressString(IEnumerable <UserItemCount> userItems) { var progress = userItems.Where(uic => this.Name.Contains(uic.ItemName)).Sum(uic => uic.ItemCount); if (progress == 0) { return(""); } if (progress > Count) { progress = Count; } return($"称号【{UserQuest.ProfessionName(Title)}】: {progress}/{Count}"); }
public string GetProgressString(IEnumerable <UserItemCount> userItems) { var progress = userItems.Where(i => i.ItemPool.ContainsKey(PoolName)).Sum(i => i.ItemPool[PoolName]); if (progress == 0) { return(""); } if (progress > Count) { progress = Count; } var tmp = (Count > 1) ? "抽取卡池次数" : ""; return($"称号【{UserQuest.ProfessionName(Title)}】:{tmp} {progress}/{Count}"); }
public string GetProgressString(IEnumerable <UserItemCount> userItems) { var item = userItems.FirstOrDefault(uic => uic.ItemName == Name); if (item == null) { return(""); } int progress = item.ItemCount; if (progress > Count) { progress = Count; } return($"称号【{UserQuest.ProfessionName(Title)}】: {progress}/{Count}"); }
private string BuildNickName(UserQuest.UserProfession title, string nickname, string username) { if (string.IsNullOrEmpty(username)) { return(string.Empty); } StringBuilder sb = new StringBuilder(); if (title != UserQuest.UserProfession.None) { sb.AppendFormat("[{0}] ", UserQuest.ProfessionName(title)); } if (string.IsNullOrEmpty(nickname)) { nickname = username; } sb.Append(nickname); return(sb.ToString()); }
public async Task <List <string> > HandleForItemsAsync(IEnumerable <GachaItem> items) { var user = await db_.Users.Include("quest").SingleOrDefaultAsync(u => u.UserName == context_.User.Identity.Name); if (user.quest == null) { user.quest = new UserQuest { UserId = user.Id }; } var quest = user.quest; var itemCounts = items.GroupBy(i => i.Id).ToDictionary(g => g.Key, g => new { Item = g.FirstOrDefault(), Count = g.Count() }); var itemIds = itemCounts.Keys; var allUserRareItems = await GetUserMissionItemsAsync(user); var bonus = new GachaBonus(); bonus.AddExp(items.Count()); var result = new List <string>(); foreach (var item in itemCounts.Values) { var userItem = allUserRareItems.FirstOrDefault(i => i.ItemName == item.Item.Name); var conds = userItem == null?Enumerable.Empty <IGachaTitleCondition>() : titleConditions.Where(c => c.Related(userItem)).ToList(); if (conds.Count() > 0) { int minBonusTimes = -1; foreach (var cond in conds) { if (cond.Satisfy(allUserRareItems)) { if (!quest.HasTitle(cond.Title)) { quest.AddTitle(cond.Title); result.Add(string.Format("获得称号【{0}】", UserQuest.ProfessionName(cond.Title))); } int bonusTimes = item.Count; int threshold = cond.GetThresholdForItem(item.Item.Name); if (userItem.ItemCount - item.Count < threshold) { bonusTimes = userItem.ItemCount - threshold; } if (minBonusTimes < 0 || bonusTimes < minBonusTimes) { minBonusTimes = bonusTimes; } } } if (item.Item.Rarity > 1 && item.Item.Rarity < 5 && conds.All(c => c.Satisfy(allUserRareItems))) { bonus.IncreaseMultiple((item.Item.Rarity - 1) * 4, minBonusTimes); // r2: 4, r3: 8, r4: 12 } } else if (item.Item.Rarity > 1 && item.Item.Rarity < 5) { bonus.IncreaseMultiple((item.Item.Rarity - 1) * 4, item.Count); // r2: 4, r3: 8, r4: 12 } if (item.Item.Rarity >= 5) { for (int i = 0; i < item.Count; ++i) { bonus.AddPointRandom(30, 50); } } } bonus.ApplyBonus(user, expUtil_); await db_.SaveChangesAsync(); result.Add(bonus.GetResult()); return(result); }