Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Commit

Permalink
add support for battle items import
Browse files Browse the repository at this point in the history
  • Loading branch information
rpaciorek committed Sep 8, 2023
1 parent 34062a1 commit f63b22c
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Use import with caution – in case of bug can broke your current account / viki
* **Note:** import hideout from original dragonrescue dumps doesn't work and won't work, due to the lack of hideout in original data
* farm
* **Note:** due to the lack some data in original dragonrescue dumps, import farm (in some cases) can be limited only to main (default) farm
* inventory (**experimental** - can broke your account; blueprint not working, battle backpack not working correctly)
* inventory
* **Warning:** inventory contains many invisible items (for example affecting quests); inventory import can broke your account

### What doesn't work – TODO

Expand Down
2 changes: 1 addition & 1 deletion dragonrescue-import.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>

<SourceControlInformationFeatureSupported>true</SourceControlInformationFeatureSupported>
<Version>0.2.1</Version>
<Version>0.3.0</Version>
<InformationalVersion>$(SourceRevisionId)</InformationalVersion>

<OutputPath>$(MSBuildThisFileDirectory)bin</OutputPath>
Expand Down
16 changes: 16 additions & 0 deletions src/Api/InventoryApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ public static async Task<string> AddItems(HttpClient client, string apiToken, Di
return bodyRaw;
}

public static async Task<string> AddBattleItems(HttpClient client, string apiToken, List<BattleItemTierMap> itemsList) {
var request = new AddBattleItemsRequest {
BattleItemTierMaps = itemsList
};

var formContent = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("apiKey", Config.APIKEY),
new KeyValuePair<string, string>("apiToken", apiToken),
new KeyValuePair<string, string>("request", XmlUtil.SerializeXml(request)),
});

var bodyRaw = await client.PostAndGetReplayOrThrow(Config.URL_CONT_API + "/V2/ContentWebService.asmx/AddBattleItems", formContent);

return bodyRaw;
}

public static async Task<string> GetCommonInventory(HttpClient client, string apiToken) {
GetCommonInventoryRequest request = new GetCommonInventoryRequest {
ContainerId = 1,
Expand Down
33 changes: 25 additions & 8 deletions src/Importers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,23 @@ public static async System.Threading.Tasks.Task ImportInventory(LoginApi.Data lo
CommonInventoryData inventory = XmlUtil.DeserializeXml<CommonInventoryData>(System.IO.File.ReadAllText(path));

var inventoryChanges = new Dictionary<int, int>();
var battleInventoryChanges = new List<BattleItemTierMap>();
foreach (UserItemData userItem in inventory.Item) {
if (skipStables && userItem.Item.AssetName.Length >= 12 && userItem.Item.AssetName.Substring(0,12) == "DragonStable")
continue;

//Console.WriteLine($"{userItem.ItemID} {userItem.Quantity} {userItem.ItemTier} {userItem.ItemStats}");
// TODO support for DT items (items with non empty userItem.ItemTier and userItem.ItemStats)

if (userItem.Item.BluePrint != null) continue;

inventoryChanges[userItem.ItemID] = userItem.Quantity;
if (userItem.ItemTier != null && userItem.ItemStats != null) {
battleInventoryChanges.Add(
new BattleItemTierMap{
ItemID = userItem.ItemID,
Quantity = userItem.Quantity,
Tier = userItem.ItemTier,
ItemStats = userItem.ItemStats
}
);
} else {
inventoryChanges[userItem.ItemID] = userItem.Quantity;
}
}

// connect to server and login as viking
Expand All @@ -139,8 +146,18 @@ public static async System.Threading.Tasks.Task ImportInventory(LoginApi.Data lo

// send inventory to server
Console.WriteLine("Importing inventory ... please be patient ... it may take a while ...");
var res = await InventoryApi.AddItems(client2, apiToken, inventoryChanges);
Console.WriteLine(res);
var res1 = await InventoryApi.AddItems(client2, apiToken, inventoryChanges);

XmlDocument res1Xml = new XmlDocument();
res1Xml.LoadXml(res1);
Console.WriteLine(res1Xml["CIRS"]["s"].InnerText);

Console.WriteLine("Importing battle inventory ... please be patient ... it may take a while ...");
var res2 = await InventoryApi.AddBattleItems(client2, apiToken, battleInventoryChanges);

XmlDocument res2Xml = new XmlDocument();
res2Xml.LoadXml(res2);
Console.WriteLine(res2Xml["ABIRES"]["ST"].InnerText);
}

public static async System.Threading.Tasks.Task ImportHideout(LoginApi.Data loginData, string path, bool addToInventory = true) {
Expand Down
10 changes: 10 additions & 0 deletions src/Schema/AddBattleItemsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Xml.Serialization;

namespace dragonrescue.Schema;

[XmlRoot(ElementName = "ABIR", Namespace = "")]
[Serializable]
public class AddBattleItemsRequest {
[XmlElement(ElementName = "BITM", IsNullable = false)]
public List<BattleItemTierMap> BattleItemTierMaps { get; set; }
}
19 changes: 19 additions & 0 deletions src/Schema/BattleItemTierMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Xml.Serialization;

namespace dragonrescue.Schema;

[XmlRoot(ElementName = "BITM", Namespace = "")]
[Serializable]
public class BattleItemTierMap {
[XmlElement(ElementName = "IID", IsNullable = false)]
public int ItemID { get; set; }

[XmlElement(ElementName = "T", IsNullable = true)]
public ItemTier? Tier { get; set; }

[XmlElement(ElementName = "QTY", IsNullable = true)]
public int? Quantity { get; set; }

[XmlElement(ElementName = "iss", IsNullable = true)]
public ItemStat[] ItemStats { get; set; }
}

0 comments on commit f63b22c

Please sign in to comment.