|
|
@@ -89,9 +89,6 @@ namespace Kitty_Fall.Apis.Business.Game
|
|
|
.Include(x => x.GameRewardLog)
|
|
|
.Where(x => x.Msisdn == msisdn
|
|
|
&& x.Status == 2
|
|
|
- && x.RewardType != null
|
|
|
- && x.RewardType != ""
|
|
|
- && (x.RewardValue ?? 0) > 0
|
|
|
&& ((x.SubmitTime ?? x.StartTime) >= fromDate)
|
|
|
&& ((x.SubmitTime ?? x.StartTime) < toExclusive))
|
|
|
.OrderByDescending(x => x.SubmitTime ?? x.StartTime)
|
|
|
@@ -130,6 +127,13 @@ namespace Kitty_Fall.Apis.Business.Game
|
|
|
var rewardType = rewardLog?.RewardType ?? attempt.RewardType ?? "";
|
|
|
var rewardValue = rewardLog?.RewardValue ?? attempt.RewardValue ?? 0;
|
|
|
var rewardUnit = rewardLog?.RewardUnit ?? attempt.RewardUnit ?? "";
|
|
|
+ if (string.IsNullOrWhiteSpace(rewardType) && attempt.AwardedScore > 0)
|
|
|
+ {
|
|
|
+ // Level thuong khong co reward option van phai hien thi diem base da cong.
|
|
|
+ rewardType = "SCORE";
|
|
|
+ rewardValue = attempt.AwardedScore;
|
|
|
+ rewardUnit = "POINT";
|
|
|
+ }
|
|
|
|
|
|
return new UserGameActivityHistoryItem
|
|
|
{
|
|
|
@@ -756,18 +760,14 @@ namespace Kitty_Fall.Apis.Business.Game
|
|
|
if (awardedScore <= 0) awardedScore = levelConfig.BaseScore;
|
|
|
awardedScore = Math.Min(awardedScore, MaxAttemptScore);
|
|
|
|
|
|
- // Chon cau hinh thuong cho mode/level, uu tien default roi den weight cao.
|
|
|
- var rewardOption = await dbContext.GameLevelRewardOptions.AsNoTracking()
|
|
|
+ // Level moc random 1 option thuong theo weight; level thuong se khong co option.
|
|
|
+ var rewardOptions = await dbContext.GameLevelRewardOptions.AsNoTracking()
|
|
|
.Where(x => x.ModeId == mode.ModeId && x.LevelNo == levelNo.Value && x.Status != false)
|
|
|
.OrderByDescending(x => x.IsDefault == true)
|
|
|
.ThenByDescending(x => x.Weight)
|
|
|
.ThenBy(x => x.RewardOptionId)
|
|
|
- .FirstOrDefaultAsync();
|
|
|
- if (rewardOption == null)
|
|
|
- {
|
|
|
- // Level da cau hinh de choi nhung chua co giai, khong ghi history bi trong prize.
|
|
|
- return CommonLogic.BuildResponse(url, json, CommonErrorCode.Error, "Game reward is not configured", new { });
|
|
|
- }
|
|
|
+ .ToListAsync();
|
|
|
+ var rewardOption = SelectRewardOption(rewardOptions);
|
|
|
|
|
|
var attemptNo = ((await dbContext.GameLevelAttempts.AsNoTracking()
|
|
|
.Where(x => x.SessionId == session.SessionId && x.LevelNo == levelNo.Value)
|
|
|
@@ -826,10 +826,17 @@ namespace Kitty_Fall.Apis.Business.Game
|
|
|
});
|
|
|
|
|
|
var responseData = "";
|
|
|
- var responsePoint = "0";
|
|
|
+ var responsePoint = awardedScore > 0 ? FormatPrizeValue(awardedScore) : "0";
|
|
|
+ var responseRewardType = awardedScore > 0 ? "SCORE" : "";
|
|
|
+ var responseRewardValue = awardedScore > 0 ? (decimal)awardedScore : 0;
|
|
|
+ var responseRewardUnit = awardedScore > 0 ? "POINT" : "";
|
|
|
long rewardScoreDelta = 0;
|
|
|
if (rewardOption != null)
|
|
|
{
|
|
|
+ responseRewardType = rewardOption.RewardType;
|
|
|
+ responseRewardValue = rewardOption.RewardValue;
|
|
|
+ responseRewardUnit = rewardOption.RewardUnit;
|
|
|
+
|
|
|
if (string.Equals(rewardOption.RewardType, "SCORE", StringComparison.OrdinalIgnoreCase))
|
|
|
{
|
|
|
rewardScoreDelta = (long)rewardOption.RewardValue;
|
|
|
@@ -905,9 +912,9 @@ namespace Kitty_Fall.Apis.Business.Game
|
|
|
data = responseData,
|
|
|
score = session.TotalScore.ToString(CultureInfo.InvariantCulture),
|
|
|
transId = request.transId,
|
|
|
- rewardType = rewardOption?.RewardType ?? "",
|
|
|
- rewardValue = rewardOption?.RewardValue ?? 0,
|
|
|
- rewardUnit = rewardOption?.RewardUnit ?? ""
|
|
|
+ rewardType = responseRewardType,
|
|
|
+ rewardValue = responseRewardValue,
|
|
|
+ rewardUnit = responseRewardUnit
|
|
|
});
|
|
|
}
|
|
|
catch (Exception exception)
|
|
|
@@ -949,6 +956,28 @@ namespace Kitty_Fall.Apis.Business.Game
|
|
|
return score > maxScore ? maxScore : score;
|
|
|
}
|
|
|
|
|
|
+ private static GameLevelRewardOption? SelectRewardOption(List<GameLevelRewardOption> rewardOptions)
|
|
|
+ {
|
|
|
+ // Level moc random mot option theo weight, khong tra dong thoi ca DATA/LOYALTY/SCORE.
|
|
|
+ if (rewardOptions.Count == 0) return null;
|
|
|
+
|
|
|
+ var positiveWeightOptions = rewardOptions.Where(x => x.Weight > 0).ToList();
|
|
|
+ if (positiveWeightOptions.Count == 0)
|
|
|
+ {
|
|
|
+ return rewardOptions[Random.Shared.Next(rewardOptions.Count)];
|
|
|
+ }
|
|
|
+
|
|
|
+ var totalWeight = positiveWeightOptions.Sum(x => x.Weight);
|
|
|
+ var cursor = Random.Shared.Next(1, totalWeight + 1);
|
|
|
+ foreach (var option in positiveWeightOptions)
|
|
|
+ {
|
|
|
+ cursor -= option.Weight;
|
|
|
+ if (cursor <= 0) return option;
|
|
|
+ }
|
|
|
+
|
|
|
+ return positiveWeightOptions.FirstOrDefault(x => x.IsDefault == true) ?? positiveWeightOptions[0];
|
|
|
+ }
|
|
|
+
|
|
|
private async Task<GameMode?> GetGameModeAsync(string? gameType)
|
|
|
{
|
|
|
var modeCode = (gameType ?? "EASY").Trim().ToUpperInvariant();
|