Files
2025-05-01 07:20:41 +09:00

94 lines
3.0 KiB
C#

using Amazon.S3.Model;
using ServerCommon;
using ServerCore; using ServerBase;
using META_ID = System.UInt32;
namespace GameServer
{
public class CraftRecipe : EntityBase
{
public CraftRecipe(EntityBase parent)
: base(EntityType.Recipe, parent)
{
}
public override async Task<Result> onInit()
{
var parent = getDirectParent();
NullReferenceCheckHelper.throwIfNull(parent, () => $"parent is null !!!");
addEntityAttribute(new CraftRecipeAttribute(this, parent));
return await base.onInit();
}
public override string toBasicString()
{
return $"{this.getTypeName()} - {getRootParent().toBasicString()}";
}
public override string toSummaryString()
{
return $"{this.getTypeName()} - {getRootParent().toBasicString()}";
}
public static async Task<(Result, CraftRecipe?)> createRecipeFromDoc(EntityBase parent, CraftRecipeDoc doc)
{
var recipe = new CraftRecipe(parent);
var result = await recipe.onInit();
if (result.isFail())
{
return (result, null);
}
var err_msg = string.Empty;
var recipe_attribute = recipe.getEntityAttribute<CraftRecipeAttribute>();
if (recipe_attribute == null)
{
err_msg = $"Failed to get recipe attribute : {nameof(CraftRecipeAttribute)}";
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
Log.getLogger().error(err_msg);
return (result, null);
}
if (recipe_attribute.copyEntityAttributeFromDoc(doc) == false)
{
err_msg = $"Failed to copyEntityAttributeFromDoc !!! : doc_type {doc.GetType()} - {recipe.getRootParent().toBasicString()}";
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
Log.getLogger().error(err_msg);
return (result, null);
}
return (result, recipe);
}
public static async Task<(Result, CraftRecipe?)> createRecipe(EntityBase parent, META_ID craft_meta_id)
{
var recipe = new CraftRecipe(parent);
var result = await recipe.onInit();
if (result.isFail())
{
return (result, null);
}
var err_msg = string.Empty;
var recipe_attribute = recipe.getEntityAttribute<CraftRecipeAttribute>();
if (recipe_attribute == null)
{
err_msg = $"Failed to get recipe attribute : {nameof(CraftRecipeAttribute)}";
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
Log.getLogger().error(err_msg);
return (result, null);
}
recipe_attribute.CraftMetaId = craft_meta_id;
recipe_attribute.newEntityAttribute();
return (result, recipe);
}
}
}