diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index eb66216..9637c40 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -749,8 +749,19 @@ public class ContentController : Controller { PurchaseStoreItemRequest request = XmlUtil.DeserializeXml(purchaseItemRequest); List items = new List(); Gender gender = XmlUtil.DeserializeXml(viking.AvatarSerialized).GenderType; + bool success = true; for (int i = 0; i < request.Items.Length; i++) { int itemId = request.Items[i]; + ItemData item = itemService.GetItem(itemId); + UserGameCurrency currency = achievementService.GetUserCurrency(viking); + int coinCost = (int)Math.Round(0.8 * item.Cost); // 20% discount for members + int gemCost = (int)Math.Round(0.8 * item.CashCost); + if (currency.GameCurrency - coinCost < 0 && currency.CashCurrency - gemCost < 0) { + success = false; + break; + } + achievementService.AddAchievementPoints(viking, AchievementPointTypes.GameCurrency, -coinCost); + achievementService.AddAchievementPoints(viking, AchievementPointTypes.CashCurrency, -gemCost); if (request.AddMysteryBoxToInventory) { // force add boxes as item (without "opening") items.Add(inventoryService.AddItemToInventoryAndGetResponse(viking, itemId, 1)); @@ -762,7 +773,22 @@ public class ContentController : Controller { for (int j=0; j(itemIDArrayXml); List items = new List(); Gender gender = XmlUtil.DeserializeXml(viking.AvatarSerialized).GenderType; + bool success = true; for (int i = 0; i < itemIdArr.Length; i++) { + ItemData item = itemService.GetItem(itemIdArr[i]); + UserGameCurrency currency = achievementService.GetUserCurrency(viking); + if (currency.GameCurrency - item.Cost < 0 && currency.CashCurrency - item.CashCost < 0) { + success = false; + break; + } + achievementService.AddAchievementPoints(viking, AchievementPointTypes.GameCurrency, -item.Cost); + achievementService.AddAchievementPoints(viking, AchievementPointTypes.CashCurrency, -item.CashCost); itemService.CheckAndOpenBox(itemIdArr[i], gender, out int itemId, out int quantity); for (int j=0; j 12732 - 436 - Dragons Bundle + 425 + Dragons Treasure 12732 @@ -909766,8 +909766,8 @@ This bundle contains 10 Frostbite Powerups. 12721 - 436 - Dragons Bundle + 425 + Dragons Treasure 12721 diff --git a/src/Services/AchievementService.cs b/src/Services/AchievementService.cs index 87e8ad6..9396dfa 100644 --- a/src/Services/AchievementService.cs +++ b/src/Services/AchievementService.cs @@ -88,6 +88,8 @@ namespace sodoff.Services { value = 0; } + ctx.SaveChanges(); + return new AchievementReward{ EntityID = viking.Uid, PointTypeID = type, @@ -157,10 +159,20 @@ namespace sodoff.Services { public UserGameCurrency GetUserCurrency(Viking viking) { // TODO: return real values (after implement currency collecting methods) + int? coins = viking.AchievementPoints.FirstOrDefault(x => x.Type == (int)AchievementPointTypes.GameCurrency)?.Value; + int? gems = viking.AchievementPoints.FirstOrDefault(x => x.Type == (int)AchievementPointTypes.CashCurrency)?.Value; + if (coins is null) { + coins = 300; + AddAchievementPoints(viking, AchievementPointTypes.GameCurrency, coins); + } + if (gems is null) { + gems = 75; + AddAchievementPoints(viking, AchievementPointTypes.CashCurrency, gems); + } return new UserGameCurrency { - CashCurrency = 65536, - GameCurrency = 65536, - UserGameCurrencyID = 1, // TODO: user's wallet ID? + CashCurrency = gems, + GameCurrency = coins, + UserGameCurrencyID = viking.Id, UserID = viking.Uid }; } diff --git a/src/Services/ItemService.cs b/src/Services/ItemService.cs index 13c1ae5..38c0e94 100644 --- a/src/Services/ItemService.cs +++ b/src/Services/ItemService.cs @@ -90,6 +90,22 @@ namespace sodoff.Services { return items[itemId].Relationship?.FirstOrDefault(e => e.Type == "Bundle") != null; } + public bool IsGemBundle(int itemId, out int value) { + value = 0; + ItemAttribute? attribute = items[itemId].Attribute?.FirstOrDefault(e => e.Key == "VCashRedemptionValue"); + if (attribute != null && int.TryParse(attribute.Value, out int result)) + value = result; + return attribute != null; + } + + public bool IsCoinBundle(int itemId, out int value) { + value = 0; + ItemAttribute? attribute = items[itemId].Attribute?.FirstOrDefault(e => e.Key == "CoinRedemptionValue"); + if (attribute != null && int.TryParse(attribute.Value, out int result)) + value = result; + return attribute != null; + } + public bool CheckItemGender(ItemData itemData, Gender gender) { string? itemGender = itemData.Attribute?.FirstOrDefault(e => e.Key == "Gender")?.Value; if (itemGender != null) {