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);
|
PurchaseStoreItemRequest request = XmlUtil.DeserializeXml<PurchaseStoreItemRequest>(purchaseItemRequest);
|
||||||
List<CommonInventoryResponseItem> items = new List<CommonInventoryResponseItem>();
|
List<CommonInventoryResponseItem> items = new List<CommonInventoryResponseItem>();
|
||||||
Gender gender = XmlUtil.DeserializeXml<AvatarData>(viking.AvatarSerialized).GenderType;
|
Gender gender = XmlUtil.DeserializeXml<AvatarData>(viking.AvatarSerialized).GenderType;
|
||||||
|
bool success = true;
|
||||||
for (int i = 0; i < request.Items.Length; i++) {
|
for (int i = 0; i < request.Items.Length; i++) {
|
||||||
int itemId = request.Items[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) {
|
if (request.AddMysteryBoxToInventory) {
|
||||||
// force add boxes as item (without "opening")
|
// force add boxes as item (without "opening")
|
||||||
items.Add(inventoryService.AddItemToInventoryAndGetResponse(viking, itemId, 1));
|
items.Add(inventoryService.AddItemToInventoryAndGetResponse(viking, itemId, 1));
|
||||||
@ -762,7 +773,22 @@ public class ContentController : Controller {
|
|||||||
for (int j=0; j<quantity; ++j)
|
for (int j=0; j<quantity; ++j)
|
||||||
items.Add(inventoryService.AddItemToInventoryAndGetResponse(viking, reward.ItemId, 1));
|
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
|
// check for mystery box ... open if need
|
||||||
itemService.CheckAndOpenBox(itemId, gender, out itemId, out int quantity);
|
itemService.CheckAndOpenBox(itemId, gender, out itemId, out int quantity);
|
||||||
for (int j=0; j<quantity; ++j) {
|
for (int j=0; j<quantity; ++j) {
|
||||||
@ -774,7 +800,7 @@ public class ContentController : Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CommonInventoryResponse response = new CommonInventoryResponse {
|
CommonInventoryResponse response = new CommonInventoryResponse {
|
||||||
Success = true,
|
Success = success,
|
||||||
CommonInventoryIDs = items.ToArray(),
|
CommonInventoryIDs = items.ToArray(),
|
||||||
UserGameCurrency = achievementService.GetUserCurrency(viking)
|
UserGameCurrency = achievementService.GetUserCurrency(viking)
|
||||||
};
|
};
|
||||||
@ -789,7 +815,16 @@ public class ContentController : Controller {
|
|||||||
int[] itemIdArr = XmlUtil.DeserializeXml<int[]>(itemIDArrayXml);
|
int[] itemIdArr = XmlUtil.DeserializeXml<int[]>(itemIDArrayXml);
|
||||||
List<CommonInventoryResponseItem> items = new List<CommonInventoryResponseItem>();
|
List<CommonInventoryResponseItem> items = new List<CommonInventoryResponseItem>();
|
||||||
Gender gender = XmlUtil.DeserializeXml<AvatarData>(viking.AvatarSerialized).GenderType;
|
Gender gender = XmlUtil.DeserializeXml<AvatarData>(viking.AvatarSerialized).GenderType;
|
||||||
|
bool success = true;
|
||||||
for (int i = 0; i < itemIdArr.Length; i++) {
|
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);
|
itemService.CheckAndOpenBox(itemIdArr[i], gender, out int itemId, out int quantity);
|
||||||
for (int j=0; j<quantity; ++j) {
|
for (int j=0; j<quantity; ++j) {
|
||||||
items.Add(inventoryService.AddItemToInventoryAndGetResponse(viking, itemId, 1));
|
items.Add(inventoryService.AddItemToInventoryAndGetResponse(viking, itemId, 1));
|
||||||
@ -799,7 +834,7 @@ public class ContentController : Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CommonInventoryResponse response = new CommonInventoryResponse {
|
CommonInventoryResponse response = new CommonInventoryResponse {
|
||||||
Success = true,
|
Success = success,
|
||||||
CommonInventoryIDs = items.ToArray(),
|
CommonInventoryIDs = items.ToArray(),
|
||||||
UserGameCurrency = achievementService.GetUserCurrency(viking)
|
UserGameCurrency = achievementService.GetUserCurrency(viking)
|
||||||
};
|
};
|
||||||
|
@ -167,14 +167,16 @@ public class ProfileController : Controller {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserGameCurrency currency = achievementService.GetUserCurrency(viking);
|
||||||
|
|
||||||
return new UserProfileData {
|
return new UserProfileData {
|
||||||
ID = viking.Uid.ToString(),
|
ID = viking.Uid.ToString(),
|
||||||
AvatarInfo = avatar,
|
AvatarInfo = avatar,
|
||||||
AchievementCount = 0,
|
AchievementCount = 0,
|
||||||
MythieCount = 0,
|
MythieCount = 0,
|
||||||
AnswerData = new UserAnswerData { UserID = viking.Uid.ToString() },
|
AnswerData = new UserAnswerData { UserID = viking.Uid.ToString() },
|
||||||
GameCurrency = 65536,
|
GameCurrency = currency.GameCurrency,
|
||||||
CashCurrency = 65536,
|
CashCurrency = currency.CashCurrency,
|
||||||
ActivityCount = 0,
|
ActivityCount = 0,
|
||||||
BuddyCount = 0,
|
BuddyCount = 0,
|
||||||
UserGradeData = new UserGrade { UserGradeID = 0 }
|
UserGradeData = new UserGrade { UserGradeID = 0 }
|
||||||
|
@ -626930,8 +626930,8 @@ Contains 5x Perfect Aim power-ups.</d>
|
|||||||
<id>12732</id>
|
<id>12732</id>
|
||||||
</at>
|
</at>
|
||||||
<c>
|
<c>
|
||||||
<cid>436</cid>
|
<cid>425</cid>
|
||||||
<cn>Dragons Bundle</cn>
|
<cn>Dragons Treasure</cn>
|
||||||
<i xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
|
<i xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
|
||||||
<id>12732</id>
|
<id>12732</id>
|
||||||
</c>
|
</c>
|
||||||
@ -909766,8 +909766,8 @@ This bundle contains 10 Frostbite Powerups.</d>
|
|||||||
<id>12721</id>
|
<id>12721</id>
|
||||||
</at>
|
</at>
|
||||||
<c>
|
<c>
|
||||||
<cid>436</cid>
|
<cid>425</cid>
|
||||||
<cn>Dragons Bundle</cn>
|
<cn>Dragons Treasure</cn>
|
||||||
<i xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
|
<i xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
|
||||||
<id>12721</id>
|
<id>12721</id>
|
||||||
</c>
|
</c>
|
||||||
|
@ -88,6 +88,8 @@ namespace sodoff.Services {
|
|||||||
value = 0;
|
value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.SaveChanges();
|
||||||
|
|
||||||
return new AchievementReward{
|
return new AchievementReward{
|
||||||
EntityID = viking.Uid,
|
EntityID = viking.Uid,
|
||||||
PointTypeID = type,
|
PointTypeID = type,
|
||||||
@ -157,10 +159,20 @@ namespace sodoff.Services {
|
|||||||
|
|
||||||
public UserGameCurrency GetUserCurrency(Viking viking) {
|
public UserGameCurrency GetUserCurrency(Viking viking) {
|
||||||
// TODO: return real values (after implement currency collecting methods)
|
// 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 {
|
return new UserGameCurrency {
|
||||||
CashCurrency = 65536,
|
CashCurrency = gems,
|
||||||
GameCurrency = 65536,
|
GameCurrency = coins,
|
||||||
UserGameCurrencyID = 1, // TODO: user's wallet ID?
|
UserGameCurrencyID = viking.Id,
|
||||||
UserID = viking.Uid
|
UserID = viking.Uid
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,22 @@ namespace sodoff.Services {
|
|||||||
return items[itemId].Relationship?.FirstOrDefault(e => e.Type == "Bundle") != null;
|
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) {
|
public bool CheckItemGender(ItemData itemData, Gender gender) {
|
||||||
string? itemGender = itemData.Attribute?.FirstOrDefault(e => e.Key == "Gender")?.Value;
|
string? itemGender = itemData.Attribute?.FirstOrDefault(e => e.Key == "Gender")?.Value;
|
||||||
if (itemGender != null) {
|
if (itemGender != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user