forked from SoDOff-Project/sodoff
wallets
This commit is contained in:
parent
6bc5a0b140
commit
8b3ed124c6
@ -749,8 +749,19 @@ public class ContentController : Controller {
|
||||
PurchaseStoreItemRequest request = XmlUtil.DeserializeXml<PurchaseStoreItemRequest>(purchaseItemRequest);
|
||||
List<CommonInventoryResponseItem> items = new List<CommonInventoryResponseItem>();
|
||||
Gender gender = XmlUtil.DeserializeXml<AvatarData>(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<quantity; ++j)
|
||||
items.Add(inventoryService.AddItemToInventoryAndGetResponse(viking, reward.ItemId, 1));
|
||||
}
|
||||
} else {
|
||||
} else if (itemService.IsGemBundle(itemId, out int gems)) {
|
||||
achievementService.AddAchievementPoints(viking, AchievementPointTypes.CashCurrency, gems);
|
||||
items.Add(new CommonInventoryResponseItem {
|
||||
CommonInventoryID = 0,
|
||||
ItemID = itemId,
|
||||
Quantity = 0
|
||||
});
|
||||
} else if (itemService.IsCoinBundle(itemId, out int coins)) {
|
||||
achievementService.AddAchievementPoints(viking, AchievementPointTypes.GameCurrency, coins);
|
||||
items.Add(new CommonInventoryResponseItem {
|
||||
CommonInventoryID = 0,
|
||||
ItemID = itemId,
|
||||
Quantity = 0
|
||||
});
|
||||
}
|
||||
else {
|
||||
// check for mystery box ... open if need
|
||||
itemService.CheckAndOpenBox(itemId, gender, out itemId, out int quantity);
|
||||
for (int j=0; j<quantity; ++j) {
|
||||
@ -774,7 +800,7 @@ public class ContentController : Controller {
|
||||
}
|
||||
|
||||
CommonInventoryResponse response = new CommonInventoryResponse {
|
||||
Success = true,
|
||||
Success = success,
|
||||
CommonInventoryIDs = items.ToArray(),
|
||||
UserGameCurrency = achievementService.GetUserCurrency(viking)
|
||||
};
|
||||
@ -789,7 +815,16 @@ public class ContentController : Controller {
|
||||
int[] itemIdArr = XmlUtil.DeserializeXml<int[]>(itemIDArrayXml);
|
||||
List<CommonInventoryResponseItem> items = new List<CommonInventoryResponseItem>();
|
||||
Gender gender = XmlUtil.DeserializeXml<AvatarData>(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<quantity; ++j) {
|
||||
items.Add(inventoryService.AddItemToInventoryAndGetResponse(viking, itemId, 1));
|
||||
@ -799,7 +834,7 @@ public class ContentController : Controller {
|
||||
}
|
||||
|
||||
CommonInventoryResponse response = new CommonInventoryResponse {
|
||||
Success = true,
|
||||
Success = success,
|
||||
CommonInventoryIDs = items.ToArray(),
|
||||
UserGameCurrency = achievementService.GetUserCurrency(viking)
|
||||
};
|
||||
|
@ -167,14 +167,16 @@ public class ProfileController : Controller {
|
||||
}
|
||||
};
|
||||
|
||||
UserGameCurrency currency = achievementService.GetUserCurrency(viking);
|
||||
|
||||
return new UserProfileData {
|
||||
ID = viking.Uid.ToString(),
|
||||
AvatarInfo = avatar,
|
||||
AchievementCount = 0,
|
||||
MythieCount = 0,
|
||||
AnswerData = new UserAnswerData { UserID = viking.Uid.ToString() },
|
||||
GameCurrency = 65536,
|
||||
CashCurrency = 65536,
|
||||
GameCurrency = currency.GameCurrency,
|
||||
CashCurrency = currency.CashCurrency,
|
||||
ActivityCount = 0,
|
||||
BuddyCount = 0,
|
||||
UserGradeData = new UserGrade { UserGradeID = 0 }
|
||||
|
@ -626930,8 +626930,8 @@ Contains 5x Perfect Aim power-ups.</d>
|
||||
<id>12732</id>
|
||||
</at>
|
||||
<c>
|
||||
<cid>436</cid>
|
||||
<cn>Dragons Bundle</cn>
|
||||
<cid>425</cid>
|
||||
<cn>Dragons Treasure</cn>
|
||||
<i xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
|
||||
<id>12732</id>
|
||||
</c>
|
||||
@ -909766,8 +909766,8 @@ This bundle contains 10 Frostbite Powerups.</d>
|
||||
<id>12721</id>
|
||||
</at>
|
||||
<c>
|
||||
<cid>436</cid>
|
||||
<cn>Dragons Bundle</cn>
|
||||
<cid>425</cid>
|
||||
<cn>Dragons Treasure</cn>
|
||||
<i xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
|
||||
<id>12721</id>
|
||||
</c>
|
||||
|
@ -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
|
||||
};
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user