초기커밋
This commit is contained in:
320
UGQApiServer/Controllers/Common/MetaDataApi.cs
Normal file
320
UGQApiServer/Controllers/Common/MetaDataApi.cs
Normal file
@@ -0,0 +1,320 @@
|
||||
using System.Globalization;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MetaAssets;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using UGQApiServer.Converter;
|
||||
using UGQApiServer.Models;
|
||||
using UGQApiServer.UGQData;
|
||||
using UGQDataAccess;
|
||||
|
||||
|
||||
|
||||
namespace UGQApiServer.Controllers.Common;
|
||||
|
||||
public class MetaDataApi
|
||||
{
|
||||
UGQMetaData _ugqMetaData;
|
||||
DynamoDbClient _dynamoDbClient;
|
||||
|
||||
public MetaDataApi(UGQMetaData ugqMetaData, DynamoDbClient dynamoDbClient)
|
||||
{
|
||||
_ugqMetaData = ugqMetaData;
|
||||
_dynamoDbClient = dynamoDbClient;
|
||||
}
|
||||
|
||||
public async Task<IResult> getAssignableNpcs(string userGuid, int pageNumber, int pageSize)
|
||||
{
|
||||
if (pageNumber < 1)
|
||||
pageNumber = 1;
|
||||
|
||||
pageSize = Math.Clamp(pageSize, 1, UGQConstants.MAX_INPUT_PAGE_SIZE);
|
||||
|
||||
(Result result, List<UgcNpcAttrib>? ugcNpcs) =
|
||||
await EntitySearchHelper.findUgcNpcAttribAllByUserGuid(_dynamoDbClient, userGuid, "");
|
||||
if (result.isFail())
|
||||
return Results.BadRequest(ApiResponseFactory.error(result.ErrorCode));
|
||||
|
||||
var UserNpcPos = MetaHelper.GameConfigMeta.UGQNormalBeaconQuestMarkerPos;
|
||||
|
||||
List<UGQNpcMetaData> value = new List<UGQNpcMetaData>();
|
||||
if (ugcNpcs != null)
|
||||
{
|
||||
value.AddRange(ugcNpcs.Select(x => new UGQNpcMetaData
|
||||
{
|
||||
UgcNpcGuid = x.UgcNpcMetaGuid,
|
||||
NpcName = x.Nickname,
|
||||
NpcTitle = x.Title,
|
||||
NpcGender = convertGenderTypeFromItem((int)x.BodyItemMetaId),
|
||||
Location = new Locaion() { x = (int)UserNpcPos.X, y = (int)UserNpcPos.Y },
|
||||
}));
|
||||
}
|
||||
|
||||
value.AddRange(_ugqMetaData.getAssignableNpcs().Select(x => new UGQNpcMetaData
|
||||
{
|
||||
NpcId = x.npc_id,
|
||||
NpcName = x.name,
|
||||
NpcTitle = x.NpcTitle,
|
||||
NpcGender = x.Gender,
|
||||
Location = new Locaion() { x = x.UGQmap_x, y = x.UGQmap_y },
|
||||
}));
|
||||
|
||||
var paging = value.Skip((pageNumber - 1) * pageSize).Take(pageSize + 1).ToList();
|
||||
|
||||
bool hasNextPage = false;
|
||||
if (paging.Count > pageSize)
|
||||
hasNextPage = true;
|
||||
|
||||
LangEnum langEnum = Culture.ToLangEnum(CultureInfo.CurrentCulture.Name);
|
||||
return Results.Ok(new UGQNpcMetaDataList
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize,
|
||||
HasNextPage = hasNextPage,
|
||||
Npcs = paging.Take(pageSize).Select(x => x.ToNpcLocale(langEnum)).ToList(),
|
||||
});
|
||||
}
|
||||
|
||||
private EGenderType convertGenderTypeFromItem(int itemId)
|
||||
{
|
||||
MetaData.Instance._ItemTable.TryGetValue(itemId, out var item);
|
||||
if(item == null)
|
||||
return EGenderType.ALL;
|
||||
|
||||
return item.Gender;
|
||||
}
|
||||
|
||||
public async Task<IResult> getAvailableTaskActions(int pageNumber, int pageSize)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
pageSize = Math.Clamp(pageSize, 1, UGQConstants.MAX_INPUT_PAGE_SIZE);
|
||||
|
||||
var paging = _ugqMetaData.TackActions.Skip((pageNumber - 1) * pageSize).Take(pageSize + 1).ToList();
|
||||
|
||||
bool hasNextPage = false;
|
||||
if (paging.Count > pageSize)
|
||||
hasNextPage = true;
|
||||
|
||||
LangEnum langEnum = Culture.ToLangEnum(CultureInfo.CurrentCulture.Name);
|
||||
return Results.Ok(new TaskActionList
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize,
|
||||
HasNextPage = hasNextPage,
|
||||
TaskActions = paging.Take(pageSize).Select(x => x.Value.ToTaskAction(langEnum)).ToList(),
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IResult> getActionValues(string userGuid, int taskActionId, int pageNumber, int pageSize)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
if (pageNumber < 1)
|
||||
pageNumber = 1;
|
||||
|
||||
pageSize = Math.Clamp(pageSize, 1, UGQConstants.MAX_INPUT_PAGE_SIZE);
|
||||
|
||||
List<UGQActionValue> taskActions = [];
|
||||
{
|
||||
_ugqMetaData.TackActions.TryGetValue(taskActionId, out var value);
|
||||
if (value == null)
|
||||
return Results.BadRequest(ApiResponseFactory.error(ServerErrorCode.UgqInvalidTaskAction));
|
||||
|
||||
if (value.Disabled == true)
|
||||
return Results.BadRequest(ApiResponseFactory.error(ServerErrorCode.UgqTaskActionDisabled));
|
||||
|
||||
taskActions = value.TaskActions;
|
||||
}
|
||||
|
||||
// taskActionId<49><64> talk<6C><6B> <20><><EFBFBD><EFBFBD> dynamodb<64><62><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> npc <20><><EFBFBD><EFBFBD><EFBFBD>;<EFBFBD> <20>Ѵ<EFBFBD>
|
||||
if (taskActionId == UGQMetaData.TALK_ACTION_ID)
|
||||
{
|
||||
(Result result, List<UgcNpcAttrib>? ugcNpcs) =
|
||||
await EntitySearchHelper.findUgcNpcAttribAllByUserGuid(_dynamoDbClient, userGuid, "");
|
||||
if (result.isFail())
|
||||
return Results.BadRequest(ApiResponseFactory.error(result.ErrorCode));
|
||||
|
||||
if (ugcNpcs != null)
|
||||
{
|
||||
List<UGQActionValue> npcValues = new List<UGQActionValue>();
|
||||
npcValues.AddRange(ugcNpcs.Select(x => new UGQActionValue
|
||||
{
|
||||
UgcValueGuid = x.UgcNpcMetaGuid,
|
||||
ValueName = x.Nickname,
|
||||
}));
|
||||
|
||||
npcValues.AddRange(taskActions);
|
||||
taskActions = npcValues;
|
||||
}
|
||||
}
|
||||
|
||||
var paging = taskActions.Skip((pageNumber - 1) * pageSize).Take(pageSize + 1).ToList();
|
||||
|
||||
bool hasNextPage = false;
|
||||
if (paging.Count > pageSize)
|
||||
hasNextPage = true;
|
||||
|
||||
LangEnum langEnum = Culture.ToLangEnum(CultureInfo.CurrentCulture.Name);
|
||||
return Results.Ok(new TaskActionValueList
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize,
|
||||
HasNextPage = hasNextPage,
|
||||
Values = paging.Take(pageSize).Select(x => x.ToTaskActionValue(langEnum)).ToList(),
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IResult> getDialogTypes(int pageNumber, int pageSize)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
pageSize = Math.Clamp(pageSize, 1, UGQConstants.MAX_INPUT_PAGE_SIZE);
|
||||
|
||||
var paging = _ugqMetaData.DialogActions.Skip((pageNumber - 1) * pageSize).Take(pageSize + 1).ToList();
|
||||
|
||||
bool hasNextPage = false;
|
||||
if (paging.Count > pageSize)
|
||||
hasNextPage = true;
|
||||
|
||||
LangEnum langEnum = Culture.ToLangEnum(CultureInfo.CurrentCulture.Name);
|
||||
|
||||
return Results.Ok(new DialogTypeList
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize,
|
||||
HasNextPage = hasNextPage,
|
||||
DialogTypes = _ugqMetaData.DialogActions.Select(x => x.Value.ToDialogType(langEnum)).ToList(),
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IResult> getDialogActions(int dialogType, int pageNumber, int pageSize)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
if (pageNumber < 1)
|
||||
pageNumber = 1;
|
||||
|
||||
pageSize = Math.Clamp(pageSize, 1, UGQConstants.MAX_INPUT_PAGE_SIZE);
|
||||
|
||||
_ugqMetaData.DialogActions.TryGetValue(dialogType, out var value);
|
||||
if (value == null)
|
||||
return Results.BadRequest(ApiResponseFactory.error(ServerErrorCode.UgqInvalidDialogType));
|
||||
|
||||
var paging = value.DialogConditions.Skip((pageNumber - 1) * pageSize).Take(pageSize + 1).ToList();
|
||||
|
||||
bool hasNextPage = false;
|
||||
if (paging.Count > pageSize)
|
||||
hasNextPage = true;
|
||||
|
||||
LangEnum langEnum = Culture.ToLangEnum(CultureInfo.CurrentCulture.Name);
|
||||
return Results.Ok(new DialogActionList
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize,
|
||||
HasNextPage = hasNextPage,
|
||||
DialogActions = paging.Take(pageSize).Select(x => x.ToDialogAction(langEnum)).ToList(),
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IResult> getDialogConditionValues(int dialogType, int dialogActionId, int pageNumber, int pageSize)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
if (pageNumber < 1)
|
||||
pageNumber = 1;
|
||||
|
||||
pageSize = Math.Clamp(pageSize, 1, UGQConstants.MAX_INPUT_PAGE_SIZE);
|
||||
|
||||
_ugqMetaData.DialogActions.TryGetValue(dialogType, out var value);
|
||||
if (value == null)
|
||||
return Results.BadRequest(ApiResponseFactory.error(ServerErrorCode.UgqInvalidDialogType));
|
||||
|
||||
var dialogAction = value.DialogConditions.Find(x => x.ConditionId == dialogActionId);
|
||||
if (dialogAction == null)
|
||||
return Results.BadRequest(ApiResponseFactory.error(ServerErrorCode.UgqInvalidDialogCondition));
|
||||
|
||||
var paging = dialogAction.DialogConditionValues.Skip((pageNumber - 1) * pageSize).Take(pageSize + 1).ToList();
|
||||
|
||||
bool hasNextPage = false;
|
||||
if (paging.Count > pageSize)
|
||||
hasNextPage = true;
|
||||
|
||||
LangEnum langEnum = Culture.ToLangEnum(CultureInfo.CurrentCulture.Name);
|
||||
return Results.Ok(new DialogActionValueList
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize,
|
||||
HasNextPage = hasNextPage,
|
||||
Values = paging.Take(pageSize).Select(x => x.ToDialogActionValue(langEnum)).ToList(),
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IResult> getNpcActionValues(int pageNumber, int pageSize, EGenderType gender)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
if (pageNumber < 1)
|
||||
pageNumber = 1;
|
||||
|
||||
pageSize = Math.Clamp(pageSize, 1, UGQConstants.MAX_INPUT_PAGE_SIZE);
|
||||
|
||||
var npcActionMetaDatas = MetaData.Instance.UGQBeaconActionDataListbyId;
|
||||
if(gender != EGenderType.ALL)
|
||||
{
|
||||
npcActionMetaDatas = npcActionMetaDatas.Where(x => x.Value.Gender == gender || x.Value.Gender == EGenderType.ALL).ToDictionary(x => x.Key, x => x.Value);
|
||||
}
|
||||
var paging = npcActionMetaDatas.Skip((pageNumber - 1) * pageSize).Take(pageSize + 1).ToList();
|
||||
|
||||
bool hasNextPage = false;
|
||||
if (paging.Count > pageSize)
|
||||
hasNextPage = true;
|
||||
|
||||
LangEnum langEnum = Culture.ToLangEnum(CultureInfo.CurrentCulture.Name);
|
||||
return Results.Ok(new NpcActionValueList
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize,
|
||||
HasNextPage = hasNextPage,
|
||||
Values = paging.Take(pageSize).Select(x => x.Value.ToNpcActionValue(langEnum)).ToList(),
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IResult> getMapDataValues(int pageNumber, int pageSize)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
if (pageNumber < 1)
|
||||
pageNumber = 1;
|
||||
|
||||
pageSize = Math.Clamp(pageSize, 1, UGQConstants.MAX_INPUT_PAGE_SIZE);
|
||||
|
||||
var zoneMetaDatas = MetaData.Instance.ZoneMetaDataListbyId;
|
||||
var paging = zoneMetaDatas.Skip((pageNumber - 1) * pageSize).Take(pageSize + 1).ToList();
|
||||
|
||||
bool hasNextPage = false;
|
||||
if (paging.Count > pageSize)
|
||||
hasNextPage = true;
|
||||
|
||||
LangEnum langEnum = Culture.ToLangEnum(CultureInfo.CurrentCulture.Name);
|
||||
return Results.Ok(new MapDataValueList
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize,
|
||||
HasNextPage = hasNextPage,
|
||||
Values = paging.Take(pageSize).Select(x => x.Value.ToMapDataValue(langEnum)).ToList(),
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IResult> getPresetImages(PresetKind kind, PresetCategory category)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
if (_ugqMetaData.PresetImages.TryGetValue((kind, category), out var presetImages) == false)
|
||||
return Results.BadRequest();
|
||||
|
||||
return Results.Ok(presetImages.Select(x => x.ToDTO()).ToList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user