mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
batch compute api endpoint
This commit is contained in:
@@ -153,31 +153,14 @@ internal static class ApiEndpoints
|
||||
|
||||
#region ApiTakumiEventCalculate
|
||||
|
||||
/// <summary>
|
||||
/// 计算器角色列表 size 20
|
||||
/// </summary>
|
||||
#region V1
|
||||
public const string CalculateAvatarList = $"{ApiTakumiEventCalculate}/v1/avatar/list";
|
||||
|
||||
/// <summary>
|
||||
/// 计算器角色技能列表
|
||||
/// </summary>
|
||||
/// <param name="avatar">元素类型</param>
|
||||
/// <returns>技能列表</returns>
|
||||
public static string CalculateAvatarSkillList(Hoyolab.Takumi.Event.Calculate.Avatar avatar)
|
||||
{
|
||||
return $"{ApiTakumiEventCalculate}/v1/avatarSkill/list?avatar_id={avatar.Id}&element_attr_id={(int)avatar.ElementAttrId}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算器结果
|
||||
/// </summary>
|
||||
public const string CalculateCompute = $"{ApiTakumiEventCalculate}/v2/compute";
|
||||
|
||||
/// <summary>
|
||||
/// 计算器洞天摹本
|
||||
/// </summary>
|
||||
/// <param name="shareCode">分享码</param>
|
||||
/// <returns>洞天摹本</returns>
|
||||
public static string CalculateFurnitureBlueprint(string shareCode)
|
||||
{
|
||||
// ®ion=cn_gf01
|
||||
@@ -185,38 +168,30 @@ internal static class ApiEndpoints
|
||||
return $"{ApiTakumiEventCalculate}/v1/furniture/blueprint?share_code={shareCode}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算器家具计算
|
||||
/// </summary>
|
||||
public const string CalculateFurnitureCompute = $"{ApiTakumiEventCalculate}/v1/furniture/compute";
|
||||
|
||||
/// <summary>
|
||||
/// 计算器家具列表 size 32
|
||||
/// </summary>
|
||||
public const string CalculateFurnitureList = $"{ApiTakumiEventCalculate}/v1/furniture/list";
|
||||
|
||||
/// <summary>
|
||||
/// 计算器同步角色详情 size 20
|
||||
/// </summary>
|
||||
/// <param name="avatarId">角色Id</param>
|
||||
/// <param name="uid">uid</param>
|
||||
/// <returns>角色详情</returns>
|
||||
public static string CalculateSyncAvatarDetail(in AvatarId avatarId, in PlayerUid uid)
|
||||
{
|
||||
return $"{ApiTakumiEventCalculate}/v1/sync/avatar/detail?avatar_id={avatarId.Value}&uid={uid.Value}®ion={uid.Region}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算器同步角色列表 size 20
|
||||
/// </summary>
|
||||
public const string CalculateSyncAvatarList = $"{ApiTakumiEventCalculate}/v1/sync/avatar/list";
|
||||
|
||||
/// <summary>
|
||||
/// 计算器武器列表 size 20
|
||||
/// </summary>
|
||||
public const string CalculateWeaponList = $"{ApiTakumiEventCalculate}/v1/weapon/list";
|
||||
#endregion
|
||||
|
||||
#region V2
|
||||
public const string CalculateCompute = $"{ApiTakumiEventCalculate}/v2/compute";
|
||||
#endregion
|
||||
|
||||
#region V3
|
||||
public const string CalculateBatchCompute = $"{ApiTakumiEventCalculate}/v3/batch_compute";
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region ApiTakumiEventLuna
|
||||
public const string LunaActivityId = "e202311201442471";
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
|
||||
|
||||
internal sealed class BatchConsumption
|
||||
{
|
||||
[JsonPropertyName("items")]
|
||||
public List<Consumption>? Items { get; set; }
|
||||
|
||||
[JsonPropertyName("available_material")]
|
||||
public List<Item>? AvailableMaterial { get; set; }
|
||||
|
||||
[JsonPropertyName("overall_consume")]
|
||||
public List<Item>? OverallConsume { get; set; }
|
||||
|
||||
[JsonPropertyName("has_user_info")]
|
||||
public bool HasUserInfo { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
|
||||
|
||||
internal sealed class BatchSkillCosumption
|
||||
{
|
||||
[JsonPropertyName("consume_list")]
|
||||
public List<Item> ConsumeList { get; set; } = default!;
|
||||
|
||||
[JsonPropertyName("skill_info")]
|
||||
public PromotionDelta SkillInfo { get; set; } = default!;
|
||||
}
|
||||
@@ -7,14 +7,8 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
|
||||
/// 可计算的物品
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal class Calculable
|
||||
internal class Calculable : PromotionDelta
|
||||
{
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
[JsonPropertyName("id")]
|
||||
public uint Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
@@ -27,24 +21,12 @@ internal class Calculable
|
||||
[JsonPropertyName("icon_url")]
|
||||
public Uri Icon { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 默认值设为1,因为部分API不返回该字段
|
||||
/// </summary>
|
||||
[JsonPropertyName("level_current")]
|
||||
public uint LevelCurrent { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 最大等级
|
||||
/// </summary>
|
||||
[JsonPropertyName("max_level")]
|
||||
public int MaxLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 目标等级
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public uint LevelTarget { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 转化到提升差异
|
||||
/// </summary>
|
||||
@@ -58,4 +40,4 @@ internal class Calculable
|
||||
Id = Id,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,30 @@ internal sealed partial class CalculateClient
|
||||
return Response.Response.DefaultIfNull(resp);
|
||||
}
|
||||
|
||||
public async ValueTask<Response<BatchConsumption>> BatchComputeAsync(UserAndUid userAndUid, List<AvatarPromotionDelta> deltas, CancellationToken token = default)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(deltas.Count, 8);
|
||||
|
||||
BatchConsumptionData data = new()
|
||||
{
|
||||
Items = deltas,
|
||||
Region = userAndUid.Uid.Region,
|
||||
Uid = userAndUid.Uid.ToString(),
|
||||
};
|
||||
|
||||
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
|
||||
.SetRequestUri(ApiEndpoints.CalculateBatchCompute)
|
||||
.SetUserCookieAndFpHeader(userAndUid.User, CookieType.Cookie)
|
||||
.SetReferer(userAndUid.IsOversea ? ApiOsEndpoints.ActHoyolabReferer : ApiEndpoints.WebStaticMihoyoReferer)
|
||||
.PostJson(data);
|
||||
|
||||
Response<BatchConsumption>? resp = await builder
|
||||
.TryCatchSendAsync<Response<BatchConsumption>>(httpClient, logger, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return Response.Response.DefaultIfNull(resp);
|
||||
}
|
||||
|
||||
public async ValueTask<List<Avatar>> GetAvatarsAsync(UserAndUid userAndUid, CancellationToken token = default)
|
||||
{
|
||||
int currentPage = 1;
|
||||
@@ -153,4 +177,16 @@ internal sealed partial class CalculateClient
|
||||
[JsonPropertyName("id")]
|
||||
public uint Id { get; set; }
|
||||
}
|
||||
|
||||
private class BatchConsumptionData
|
||||
{
|
||||
[JsonPropertyName("items")]
|
||||
public List<AvatarPromotionDelta> Items { get; set; } = default!;
|
||||
|
||||
[JsonPropertyName("region")]
|
||||
public Region Region { get; set; } = default!;
|
||||
|
||||
[JsonPropertyName("uid")]
|
||||
public string Uid { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
|
||||
/// 消耗
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal sealed class Consumption
|
||||
internal class Consumption
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色等级消耗
|
||||
@@ -26,4 +26,7 @@ internal sealed class Consumption
|
||||
/// </summary>
|
||||
[JsonPropertyName("weapon_consume")]
|
||||
public List<Item>? WeaponConsume { get; set; }
|
||||
|
||||
[JsonPropertyName("skills_consume")]
|
||||
public List<BatchSkillCosumption>? SkillsComsume { get; set; }
|
||||
}
|
||||
@@ -40,4 +40,7 @@ internal sealed class Item
|
||||
/// </summary>
|
||||
[JsonPropertyName("level")]
|
||||
public QualityType Level { get; set; }
|
||||
|
||||
[JsonPropertyName("lack_num")]
|
||||
public uint LackNum { get; set; }
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
|
||||
/// 计算信息
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal sealed class PromotionDelta
|
||||
internal class PromotionDelta
|
||||
{
|
||||
/// <summary>
|
||||
/// 物品Id
|
||||
|
||||
Reference in New Issue
Block a user