485 lines
16 KiB
C#
485 lines
16 KiB
C#
using System.Runtime.CompilerServices;
|
||
using System.Xml.Linq;
|
||
|
||
|
||
using Amazon.DynamoDBv2.Model;
|
||
|
||
|
||
using ServerCommon;
|
||
|
||
|
||
using MetaAssets;
|
||
|
||
|
||
using UGQApiServer.Validation;
|
||
using UGQDataAccess.Service;
|
||
using UGQDatabase.Models;
|
||
|
||
|
||
namespace UGQApiServer.UGQData;
|
||
|
||
public enum PresetKind
|
||
{
|
||
None = 0,
|
||
Title = 1,
|
||
Banner = 2,
|
||
}
|
||
|
||
public enum PresetCategory
|
||
{
|
||
None = 0,
|
||
Comedy = 1,
|
||
Drama = 2,
|
||
Horror = 3,
|
||
Mystery = 4,
|
||
Romance = 5,
|
||
Thriller = 6,
|
||
All = 7,
|
||
}
|
||
|
||
|
||
#pragma warning disable CS8618
|
||
|
||
public class UGQActionValue
|
||
{
|
||
public int? ValueId { get; set; }
|
||
public string? UgcValueGuid { get; set; }
|
||
public string ValueName { get; set; } = string.Empty;
|
||
public string TextId { get; set; } = string.Empty;
|
||
}
|
||
|
||
public class UGQTaskAction
|
||
{
|
||
public int ActionId { get; set; }
|
||
public string ActionName { get; set; } = string.Empty;
|
||
public string TextId { get; set; } = string.Empty;
|
||
public bool Disabled { get; set; }
|
||
|
||
public List<UGQActionValue> TaskActions { get; set; }
|
||
}
|
||
|
||
|
||
public class UGQDialogCondition
|
||
{
|
||
public int? ConditionId { get; set; }
|
||
public string ConditionName { get; set; } = string.Empty;
|
||
public string TextId { get; set; } = string.Empty;
|
||
public List<UGQActionValue> DialogConditionValues { get; set; }
|
||
}
|
||
|
||
public class UGQDialogType
|
||
{
|
||
public int TypeId { get; set; }
|
||
public string TypeName { get; set; } = string.Empty;
|
||
public string TextId { get; set; } = string.Empty;
|
||
public List<UGQDialogCondition> DialogConditions { get; set; }
|
||
}
|
||
|
||
#pragma warning restore CS8618
|
||
|
||
public class UGQMetaData
|
||
{
|
||
public const int TALK_ACTION_ID = 1;
|
||
|
||
public Dictionary<int, UGQTaskAction> TackActions = new(); // key: TackActionType
|
||
public Dictionary<int, UGQDialogType> DialogActions = new(); // key: DialogType
|
||
|
||
public IReadOnlyDictionary<int, MetaAssets.UGQPresetImageMetaData> UGQPresetImageMetaDataListbyId =>
|
||
MetaData.Instance.UGQPresetImageMetaDataListbyId;
|
||
|
||
public Dictionary<(PresetKind, PresetCategory), List<MetaAssets.UGQPresetImageMetaData>> PresetImages = new();
|
||
|
||
InGameService _inGameService;
|
||
|
||
public UGQMetaData(InGameService inGameService)
|
||
{
|
||
_inGameService = inGameService;
|
||
}
|
||
|
||
List<UGQActionValue> getInputValues(MetaAssets.EUGQValueSource source)
|
||
{
|
||
List<UGQActionValue> values = new();
|
||
|
||
switch(source)
|
||
{
|
||
case MetaAssets.EUGQValueSource.UGQ_NPC:
|
||
values = MetaData.Instance._npcTable
|
||
.Where(x => x.Value.UGQ == true)
|
||
.Select(x => new UGQActionValue
|
||
{
|
||
ValueId = x.Value.npc_id,
|
||
TextId = x.Value.name,
|
||
}).ToList();
|
||
break;
|
||
case MetaAssets.EUGQValueSource.CLOTH_ITEM:
|
||
values = MetaData.Instance._ItemTable
|
||
.Where(x => x.Value.UGQAction == MetaAssets.EUGQAction.CLOTH)
|
||
.Select(x => new UGQActionValue
|
||
{
|
||
ValueId = x.Value.ItemId,
|
||
TextId = x.Value.Name,
|
||
}).ToList();
|
||
break;
|
||
case MetaAssets.EUGQValueSource.UGQ_ITEM:
|
||
values = MetaData.Instance._ItemTable
|
||
.Where(x => x.Value.UGQAction != MetaAssets.EUGQAction.NOTUSE)
|
||
.Select(x => new UGQActionValue
|
||
{
|
||
ValueId = x.Value.ItemId,
|
||
TextId = x.Value.Name,
|
||
}).ToList();
|
||
break;
|
||
case MetaAssets.EUGQValueSource.UGQ_ATTRIBUTE_DEFINITION:
|
||
values = MetaData.Instance._AttributeDefinitionMetaTable
|
||
.Where(x => x.Value.UGQ == true)
|
||
.Select(x => new UGQActionValue
|
||
{
|
||
ValueId = x.Value.ID,
|
||
TextId = x.Value.Name,
|
||
}).ToList();
|
||
break;
|
||
case MetaAssets.EUGQValueSource.RANGE_1_30:
|
||
for (int i = 1; i <= 30; i++)
|
||
{
|
||
values.Add(new UGQActionValue
|
||
{
|
||
ValueId = i,
|
||
ValueName = i.ToString(),
|
||
});
|
||
}
|
||
break;
|
||
case MetaAssets.EUGQValueSource.UGQ_SOCIAL_ACTION:
|
||
values = MetaData.Instance._SocialActionTable
|
||
.Where(x => x.Value.UGQ == true)
|
||
.Select(x => new UGQActionValue
|
||
{
|
||
ValueId = x.Value.SocialActionId,
|
||
TextId = x.Value.Content,
|
||
}).ToList();
|
||
break;
|
||
}
|
||
|
||
return values;
|
||
}
|
||
|
||
void initTaskActions()
|
||
{
|
||
foreach(var taskInput in MetaData.Instance.UGQInputTaskMetaDataList)
|
||
{
|
||
var action = new UGQTaskAction
|
||
{
|
||
ActionId = taskInput.Id,
|
||
ActionName = taskInput.Name,
|
||
TextId = taskInput.Name,
|
||
Disabled = !taskInput.Enabled,
|
||
TaskActions = getInputValues(taskInput.ValueSource),
|
||
};
|
||
|
||
TackActions.Add(taskInput.Id, action);
|
||
}
|
||
}
|
||
|
||
void initDialogTypes()
|
||
{
|
||
foreach (var dialogInput in MetaData.Instance.UGQInputDialogMetaDataList)
|
||
{
|
||
var conditionValues = getInputValues(dialogInput.ConditionValueSource);
|
||
|
||
List<UGQDialogCondition> conditions = new();
|
||
switch (dialogInput.ConditionSelection)
|
||
{
|
||
case MetaAssets.EConditionSelection.USE_STATIC:
|
||
|
||
MetaData.Instance.UGQInputDialogConditionMetaDataListbyName.TryGetValue(dialogInput.ConditionName, out var dialogCondition);
|
||
if(dialogCondition == null)
|
||
{
|
||
conditions.Add(new UGQDialogCondition
|
||
{
|
||
ConditionId = 0,
|
||
ConditionName = "UGQInput_Dialog_None",
|
||
TextId = "UGQInput_Dialog_None",
|
||
DialogConditionValues = conditionValues
|
||
});
|
||
}
|
||
else
|
||
{
|
||
conditions.Add(new UGQDialogCondition
|
||
{
|
||
ConditionId = dialogCondition.Id,
|
||
ConditionName = dialogCondition.Text,
|
||
TextId = dialogCondition.Text,
|
||
DialogConditionValues = conditionValues
|
||
});
|
||
}
|
||
break;
|
||
case MetaAssets.EConditionSelection.USE_SOURCE:
|
||
|
||
var source = getInputValues(dialogInput.ConditionSource);
|
||
conditions = source.Select(x => new UGQDialogCondition
|
||
{
|
||
ConditionId = x.ValueId,
|
||
ConditionName = x.ValueName,
|
||
TextId = x.TextId,
|
||
DialogConditionValues = conditionValues
|
||
}).ToList();
|
||
break;
|
||
}
|
||
|
||
var dialogType = new UGQDialogType
|
||
{
|
||
TypeId = dialogInput.TypeId,
|
||
TypeName = dialogInput.TypeName,
|
||
TextId = dialogInput.TypeName,
|
||
DialogConditions = conditions,
|
||
};
|
||
|
||
DialogActions.Add(dialogInput.TypeId, dialogType);
|
||
}
|
||
}
|
||
|
||
public TextEntity getNpcName(int npcId)
|
||
{
|
||
TextEntity getNpcNameEntity(string textId)
|
||
{
|
||
MetaData.Instance._textTable.TryGetValue(textId, out var textData);
|
||
if (textData == null)
|
||
return new TextEntity();
|
||
|
||
return new TextEntity
|
||
{
|
||
Kr = textData.SourceString,
|
||
En = textData.en,
|
||
Jp = textData.ja,
|
||
};
|
||
}
|
||
|
||
MetaData.Instance._npcTable.TryGetValue(npcId, out var data);
|
||
if(data != null)
|
||
{
|
||
return getNpcNameEntity(data.name);
|
||
}
|
||
|
||
return new TextEntity
|
||
{
|
||
Kr = "",
|
||
En = "",
|
||
Jp = "",
|
||
};
|
||
}
|
||
|
||
|
||
|
||
public void init()
|
||
{
|
||
initTaskActions();
|
||
initDialogTypes();
|
||
|
||
foreach (var preset in MetaData.Instance.UGQPresetImageMetaDataListbyId.Values)
|
||
{
|
||
var pathSplit = preset.FileName.Split('/');
|
||
|
||
if (Enum.TryParse(pathSplit[1], true, out PresetCategory category) == false)
|
||
continue;
|
||
|
||
PresetKind kind = PresetKind.None;
|
||
if (preset.FileName.EndsWith("normal.png") == true)
|
||
kind = PresetKind.Banner;
|
||
else if (preset.FileName.EndsWith("hot.png") == true)
|
||
kind = PresetKind.Title;
|
||
|
||
if (kind == PresetKind.None)
|
||
continue;
|
||
|
||
if (PresetImages.TryGetValue((kind, category), out var list) == false)
|
||
{
|
||
list = new();
|
||
PresetImages.Add((kind, category), list);
|
||
}
|
||
list.Add(preset);
|
||
|
||
if (PresetImages.TryGetValue((kind, PresetCategory.All), out var allList) == false)
|
||
{
|
||
allList = new();
|
||
PresetImages.Add((kind, PresetCategory.All), allList);
|
||
}
|
||
allList.Add(preset);
|
||
}
|
||
}
|
||
|
||
public List<MetaAssets.NpcMetaData> getAssignableNpcs()
|
||
{
|
||
return MetaData.Instance._npcTable
|
||
.Where(x => x.Value.UGQ == true)
|
||
.Select(x => x.Value).ToList();
|
||
}
|
||
|
||
public string getBeaconName(int beaconId, LangEnum langEnum)
|
||
{
|
||
MetaData.Instance._npcTable.TryGetValue(beaconId, out var npcData);
|
||
if (npcData == null)
|
||
return string.Empty;
|
||
|
||
return UGQDataHelper.getText(langEnum, npcData.name) ?? string.Empty;
|
||
}
|
||
|
||
public string getTaskActionName(int actionId, LangEnum langEnum)
|
||
{
|
||
TackActions.TryGetValue(actionId, out var taskAction);
|
||
if (taskAction == null)
|
||
return string.Empty;
|
||
|
||
return UGQDataHelper.getText(langEnum, taskAction.TextId) ?? string.Empty;
|
||
}
|
||
|
||
public string getTaskActionValueName(int actionId, int actionValueId, LangEnum langEnum)
|
||
{
|
||
TackActions.TryGetValue(actionId, out var taskAction);
|
||
if (taskAction == null)
|
||
return "";
|
||
|
||
var actionValue = taskAction.TaskActions.Where(x => x.ValueId == actionValueId).FirstOrDefault();
|
||
if (actionValue == null)
|
||
return "";
|
||
|
||
return UGQDataHelper.getText(langEnum, actionValue.TextId) ?? string.Empty;
|
||
}
|
||
|
||
public string getDialogTypeName(int typeId, LangEnum langEnum)
|
||
{
|
||
DialogActions.TryGetValue(typeId, out var dialogType);
|
||
if (dialogType == null)
|
||
return "";
|
||
|
||
return UGQDataHelper.getText(langEnum, dialogType.TextId) ?? string.Empty;
|
||
}
|
||
|
||
public string getDialogConditionName(int typeId, int conditionId, LangEnum langEnum)
|
||
{
|
||
DialogActions.TryGetValue(typeId, out var dialogType);
|
||
if (dialogType == null)
|
||
return "";
|
||
|
||
var dialogCondition = dialogType.DialogConditions.Where(x => x.ConditionId == conditionId).FirstOrDefault();
|
||
if (dialogCondition == null)
|
||
return "";
|
||
|
||
return UGQDataHelper.getText(langEnum, dialogCondition.TextId) ?? string.Empty;
|
||
}
|
||
|
||
public string getDialogConditionValueName(int typeId, int conditionId, int conditionValue, LangEnum langEnum)
|
||
{
|
||
DialogActions.TryGetValue(typeId, out var dialogType);
|
||
if (dialogType == null)
|
||
return "";
|
||
|
||
var dialogCondition = dialogType.DialogConditions.Where(x => x.ConditionId == conditionId).FirstOrDefault();
|
||
if (dialogCondition == null)
|
||
return "";
|
||
|
||
var dialogConditionValue = dialogCondition.DialogConditionValues.Where(x => x.ValueId == conditionValue).FirstOrDefault();
|
||
if (dialogConditionValue == null)
|
||
return "";
|
||
|
||
return UGQDataHelper.getText(langEnum, dialogConditionValue.TextId) ?? string.Empty;
|
||
}
|
||
|
||
public ValidationErrorKind isValidNpcId(int npcId)
|
||
{
|
||
if (MetaData.Instance._npcTable.TryGetValue(npcId, out var result) == false)
|
||
return ValidationErrorKind.NotFoundBeaconId;
|
||
|
||
return ValidationErrorKind.Success;
|
||
}
|
||
|
||
public ValidationErrorKind isValidDialogTypeId(int dialogTypeId)
|
||
{
|
||
DialogActions.TryGetValue((int)dialogTypeId, out var dialogType);
|
||
if (dialogType == null)
|
||
return ValidationErrorKind.InvalidDialogType;
|
||
|
||
return ValidationErrorKind.Success;
|
||
}
|
||
|
||
public ValidationErrorKind isValidDialogConditionId(int dialogTypeId, int conditionId)
|
||
{
|
||
// DialogActions<6E><73><EFBFBD><EFBFBD> dialogType <20>˻<EFBFBD>
|
||
DialogActions.TryGetValue((int)dialogTypeId, out var dialogType);
|
||
if (dialogType == null)
|
||
return ValidationErrorKind.InvalidDialogType;
|
||
|
||
var dialogCondition = dialogType.DialogConditions.Where(x => x.ConditionId == conditionId).FirstOrDefault();
|
||
if (dialogCondition == null)
|
||
return ValidationErrorKind.InvalidDialogConditionId;
|
||
|
||
return ValidationErrorKind.Success;
|
||
}
|
||
|
||
public ValidationErrorKind isValidDialogActionValue(int dialogTypeId, int conditionId, int conditionValue)
|
||
{
|
||
// DialogActions<6E><73><EFBFBD><EFBFBD> dialogType, dialogActionType <20>˻<EFBFBD>
|
||
// dialogActionId<49><64> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> üũ
|
||
DialogActions.TryGetValue((int)dialogTypeId, out var dialogType);
|
||
if (dialogType == null)
|
||
return ValidationErrorKind.InvalidDialogType;
|
||
|
||
var dialogCondition = dialogType.DialogConditions.Where(x => x.ConditionId == conditionId).FirstOrDefault();
|
||
if (dialogCondition == null)
|
||
return ValidationErrorKind.InvalidDialogConditionId;
|
||
|
||
// DialogConditionValues<65><73> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> üũ
|
||
if (dialogCondition.DialogConditionValues.Count > 0)
|
||
{
|
||
var dialogConditionValue = dialogCondition.DialogConditionValues.Where(x => x.ValueId == conditionValue).FirstOrDefault();
|
||
if (dialogConditionValue == null)
|
||
return ValidationErrorKind.InvalidDialogConditionValue;
|
||
}
|
||
|
||
return ValidationErrorKind.Success;
|
||
}
|
||
|
||
public ValidationErrorKind isValidNpcActionId(int actionId)
|
||
{
|
||
// TackActionType
|
||
MetaData.Instance.UGQBeaconActionDataListbyId.TryGetValue(actionId, out var npcAction);
|
||
if (npcAction == null)
|
||
return ValidationErrorKind.InvalidNpcActionId;
|
||
|
||
return ValidationErrorKind.Success;
|
||
}
|
||
|
||
public ValidationErrorKind isValidTackActionId(int actionId)
|
||
{
|
||
// TackActionType
|
||
TackActions.TryGetValue(actionId, out var tackAction);
|
||
if (tackAction == null)
|
||
return ValidationErrorKind.InvalidTaskActionId;
|
||
|
||
if (tackAction.Disabled == true)
|
||
return ValidationErrorKind.InvalidTaskActionValue;
|
||
|
||
return ValidationErrorKind.Success;
|
||
}
|
||
|
||
public ValidationErrorKind isValidTackActionValue(int actionId, int actionValue)
|
||
{
|
||
// TackActions<6E><73><EFBFBD><EFBFBD> TackActionType <20>˻<EFBFBD>
|
||
TackActions.TryGetValue(actionId, out var tackAction);
|
||
if (tackAction == null)
|
||
return ValidationErrorKind.InvalidTaskActionId;
|
||
|
||
// actionValue<75><65> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> üũ
|
||
var taskActionValue = tackAction.TaskActions.Where(x => x.ValueId == actionValue).FirstOrDefault();
|
||
if (taskActionValue == null)
|
||
return ValidationErrorKind.InvalidTaskActionValue;
|
||
|
||
return ValidationErrorKind.Success;
|
||
}
|
||
|
||
public MetaAssets.UGQPresetImageMetaData? getPresetImage(int id)
|
||
{
|
||
UGQPresetImageMetaDataListbyId.TryGetValue(id, out var presetImage);
|
||
return presetImage;
|
||
}
|
||
}
|
||
|