Skip to content

Commit

Permalink
support export and import of zzz gacha (not uigf)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jan 26, 2025
1 parent 152c554 commit cdb2679
Show file tree
Hide file tree
Showing 14 changed files with 543 additions and 24 deletions.
19 changes: 18 additions & 1 deletion src/Starward.Core/Gacha/ZZZ/ZZZGachaInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
namespace Starward.Core.Gacha.ZZZ;
using System.Text.Json.Serialization;

namespace Starward.Core.Gacha.ZZZ;

public class ZZZGachaInfo
{

[JsonPropertyName("id")]
public int Id { get; set; }


[JsonPropertyName("name")]
public string Name { get; set; }


[JsonPropertyName("rarity")]
public string Rarity { get; set; }


[JsonPropertyName("icon")]
public string Icon { get; set; }

}
12 changes: 11 additions & 1 deletion src/Starward.Core/Gacha/ZZZ/ZZZGachaWiki.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
namespace Starward.Core.Gacha.ZZZ;
using System.Text.Json.Serialization;

namespace Starward.Core.Gacha.ZZZ;

public class ZZZGachaWiki
{

[JsonPropertyName("avatar")]
public List<ZZZGachaInfo> Avatar { get; set; }


[JsonPropertyName("weapon")]
public List<ZZZGachaInfo> Weapon { get; set; }


[JsonPropertyName("buddy")]
public List<ZZZGachaInfo> Buddy { get; set; }

}
61 changes: 59 additions & 2 deletions src/Starward.Core/GameRecord/GameRecordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using System.Text;
using Starward.Core.GameRecord.Genshin.ImaginariumTheater;
using Starward.Core.GameRecord.ZZZ.InterKnotReport;


using Starward.Core.Gacha.ZZZ;
using Starward.Core.GameRecord.ZZZ.UpgradeGuide;
#if !DEBUG
using System.Net.Http.Json;
#endif
Expand Down Expand Up @@ -458,6 +458,63 @@ protected virtual async Task CommonSendAsync(HttpRequestMessage request, Cancell



/// <summary>
/// 通过养成指南获取抽卡物品信息,不可用,返回未登录错误
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<ZZZGachaWiki> GetZZZGachaWikiAsync(GameRecordRole role, CancellationToken cancellationToken = default)
{
var items = await GetZZZUpgradeGuideItemListAsync(role, cancellationToken: cancellationToken);
var icons = await GetZZZUpgradeGuideIconInfoAsync(role, cancellationToken);
var wiki = new ZZZGachaWiki
{
Avatar = items.AvatarList.Select(x => new ZZZGachaInfo { Id = x.Id, Name = x.Name, Rarity = x.Rarity }).ToList(),
Weapon = items.Weapon.Select(x => new ZZZGachaInfo { Id = x.Id, Name = x.Name, Rarity = x.Rarity, Icon = x.Icon }).ToList(),
Buddy = items.BuddyList.Select(x => new ZZZGachaInfo { Id = x.Id, Name = x.Name, Rarity = x.Rarity }).ToList()
};
foreach (var item in wiki.Avatar)
{
if (icons.AvatarIcon.TryGetValue(item.Id, out UpgradeGuidIconInfoItem? info))
{
item.Icon = info.SquareAvatar;
}
}
foreach (var item in wiki.Buddy)
{
if (icons.BuddyIcon.TryGetValue(item.Id, out UpgradeGuidIconInfoItem? value))
{
item.Icon = value.SquareAvatar;
}
}
return wiki;
}



/// <summary>
/// 养成指南,不可用,返回未登录错误
/// </summary>
/// <param name="role"></param>
/// <param name="avatar_id"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public abstract Task<UpgradeGuideItemList> GetZZZUpgradeGuideItemListAsync(GameRecordRole role, int avatar_id = 1011, CancellationToken cancellationToken = default);



/// <summary>
/// 养成指南,不可用,返回未登录错误
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public abstract Task<UpgradeGuidIconInfo> GetZZZUpgradeGuideIconInfoAsync(GameRecordRole role, CancellationToken cancellationToken = default);




#endregion


Expand Down
3 changes: 3 additions & 0 deletions src/Starward.Core/GameRecord/GameRecordJsonContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Starward.Core.GameRecord.StarRail.SimulatedUniverse;
using Starward.Core.GameRecord.StarRail.TrailblazeCalendar;
using Starward.Core.GameRecord.ZZZ.InterKnotReport;
using Starward.Core.GameRecord.ZZZ.UpgradeGuide;
using Starward.Core.JsonConverter;
using System.Text.Json.Serialization;

Expand All @@ -29,6 +30,8 @@ namespace Starward.Core.GameRecord;
[JsonSerializable(typeof(miHoYoApiWrapper<ImaginariumTheaterWarpper>))]
[JsonSerializable(typeof(miHoYoApiWrapper<InterKnotReportSummary>))]
[JsonSerializable(typeof(miHoYoApiWrapper<InterKnotReportDetail>))]
[JsonSerializable(typeof(miHoYoApiWrapper<UpgradeGuideItemList>))]
[JsonSerializable(typeof(miHoYoApiWrapper<UpgradeGuidIconInfo>))]
[JsonSerializable(typeof(DateTimeObjectJsonConverter.DateTimeObject))]
internal partial class GameRecordJsonContext : JsonSerializerContext
{
Expand Down
42 changes: 42 additions & 0 deletions src/Starward.Core/GameRecord/HoyolabClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Starward.Core.GameRecord.StarRail.SimulatedUniverse;
using Starward.Core.GameRecord.StarRail.TrailblazeCalendar;
using Starward.Core.GameRecord.ZZZ.InterKnotReport;
using Starward.Core.GameRecord.ZZZ.UpgradeGuide;

namespace Starward.Core.GameRecord;

Expand Down Expand Up @@ -659,6 +660,47 @@ public override async Task<InterKnotReportDetail> GetInterKnotReportDetailAsync(



/// <summary>
/// 养成指南,不可用,返回未登录错误
/// </summary>
/// <param name="role"></param>
/// <param name="avatar_id"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<UpgradeGuideItemList> GetZZZUpgradeGuideItemListAsync(GameRecordRole role, int avatar_id = 1011, CancellationToken cancellationToken = default)
{
var url = $"https://sg-public-api.hoyolab.com/event/nap_cultivate_tool/user/item_list?uid={role.Uid}&region={role.Region}&avatar_id={avatar_id}";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, role.Cookie);
request.Headers.Add(Referer, "https://act.mihoyo.com/");
request.Headers.Add(x_rpc_app_version, AppVersion);
request.Headers.Add(x_rpc_device_id, DeviceId);
request.Headers.Add(x_rpc_device_fp, DeviceFp);
return await CommonSendAsync<UpgradeGuideItemList>(request, cancellationToken);
}



/// <summary>
/// 养成指南,不可用,返回未登录错误
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<UpgradeGuidIconInfo> GetZZZUpgradeGuideIconInfoAsync(GameRecordRole role, CancellationToken cancellationToken = default)
{
var url = $"https://sg-public-api.hoyolab.com/event/nap_cultivate_tool/user/icon_info?uid={role.Uid}&region={role.Region}";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, role.Cookie);
request.Headers.Add(Referer, "https://act.mihoyo.com/");
request.Headers.Add(x_rpc_app_version, AppVersion);
request.Headers.Add(x_rpc_device_id, DeviceId);
request.Headers.Add(x_rpc_device_fp, DeviceFp);
return await CommonSendAsync<UpgradeGuidIconInfo>(request, cancellationToken);
}



#endregion


Expand Down
43 changes: 43 additions & 0 deletions src/Starward.Core/GameRecord/HyperionClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Starward.Core.GameRecord.StarRail.SimulatedUniverse;
using Starward.Core.GameRecord.StarRail.TrailblazeCalendar;
using Starward.Core.GameRecord.ZZZ.InterKnotReport;
using Starward.Core.GameRecord.ZZZ.UpgradeGuide;

namespace Starward.Core.GameRecord;

Expand Down Expand Up @@ -728,6 +729,48 @@ public override async Task<InterKnotReportDetail> GetInterKnotReportDetailAsync(



/// <summary>
/// 养成指南,不可用,返回未登录错误
/// </summary>
/// <param name="role"></param>
/// <param name="avatar_id"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<UpgradeGuideItemList> GetZZZUpgradeGuideItemListAsync(GameRecordRole role, int avatar_id = 1011, CancellationToken cancellationToken = default)
{
var url = $"https://api-takumi.mihoyo.com/event/nap_cultivate_tool/user/item_list?uid={role.Uid}&region={role.Region}&avatar_id={avatar_id}";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, role.Cookie);
request.Headers.Add(Referer, "https://act.mihoyo.com/");
request.Headers.Add(x_rpc_app_version, AppVersion);
request.Headers.Add(x_rpc_device_id, DeviceId);
request.Headers.Add(x_rpc_device_fp, DeviceFp);
return await CommonSendAsync<UpgradeGuideItemList>(request, cancellationToken);
}



/// <summary>
/// 养成指南,不可用,返回未登录错误
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<UpgradeGuidIconInfo> GetZZZUpgradeGuideIconInfoAsync(GameRecordRole role, CancellationToken cancellationToken = default)
{
var url = $"https://api-takumi.mihoyo.com/event/nap_cultivate_tool/user/icon_info?uid={role.Uid}&region={role.Region}";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, role.Cookie);
request.Headers.Add(Referer, "https://act.mihoyo.com/");
request.Headers.Add(x_rpc_app_version, AppVersion);
request.Headers.Add(x_rpc_device_id, DeviceId);
request.Headers.Add(x_rpc_device_fp, DeviceFp);
return await CommonSendAsync<UpgradeGuidIconInfo>(request, cancellationToken);
}





#endregion

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Text.Json.Serialization;

namespace Starward.Core.GameRecord.ZZZ.UpgradeGuide;

public class UpgradeGuidIconInfo
{

[JsonPropertyName("avatar_icon")]
public Dictionary<int, UpgradeGuidIconInfoItem> AvatarIcon { get; set; }


[JsonPropertyName("buddy_icon")]
public Dictionary<int, UpgradeGuidIconInfoItem> BuddyIcon { get; set; }

}



public class UpgradeGuidIconInfoItem
{

[JsonPropertyName("square_avatar")]
public string SquareAvatar { get; set; }


[JsonPropertyName("rectangle_avatar")]
public string RectangleAvatar { get; set; }


[JsonPropertyName("vertical_painting")]
public string? VerticalPainting { get; set; }


[JsonPropertyName("vertical_painting_color")]
public string? VerticalPaintingColor { get; set; }


[JsonPropertyName("avatar_us_full_name")]
public string? AvatarUsFullName { get; set; }

}
Loading

2 comments on commit cdb2679

@Eric-Joker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也许可以把米游社账号登录的层级提高一点?毕竟抽卡记录也可以通过cookie拿到,好像游戏所登录的账号也可以?

@Scighost
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

抽卡记录用的是通行证的stoken,只有原神支持

Please sign in to comment.