123 lines
3.3 KiB
C#
123 lines
3.3 KiB
C#
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using ServerCore; using ServerBase;
|
|
using ServerCommon;
|
|
|
|
|
|
using SESSION_ID = System.Int32;
|
|
using WORLD_META_ID = System.UInt32;
|
|
using META_ID = System.UInt32;
|
|
using ENTITY_GUID = System.String;
|
|
using ACCOUNT_ID = System.String;
|
|
using OWNER_GUID = System.String;
|
|
using USER_GUID = System.String;
|
|
using CHARACTER_GUID = System.String;
|
|
using ITEM_GUID = System.String;
|
|
|
|
|
|
namespace GameServer
|
|
{
|
|
public abstract class EntityCreatorBase : SimpleEventTriggerBase
|
|
{
|
|
private readonly Player m_owner;
|
|
|
|
private List<DynamoDbDocBase> m_to_write_docs = new();
|
|
|
|
private bool m_is_completed_prepare_create = false;
|
|
|
|
public EntityCreatorBase(Player owner)
|
|
{
|
|
m_owner = owner;
|
|
}
|
|
|
|
public abstract Task<Result> onPrepareCreate();
|
|
|
|
protected Result addWriteDocBases(List<DynamoDbDocBase> docBases)
|
|
{
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
foreach (var doc_base in docBases)
|
|
{
|
|
result = addWriteDocBase(doc_base);
|
|
if(result.isFail())
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
protected Result addWriteDocBase(DynamoDbDocBase docBase)
|
|
{
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
if (true == m_to_write_docs.Exists(x => x.GetType() == docBase.GetType()))
|
|
{
|
|
err_msg = $"Already added DynamoDbDocBase by Exists() !!!, duplicated Doc : {docBase.getTypeName()} - {toBasicString()}";
|
|
result.setFail(ServerErrorCode.UserCreationForDynamoDbDocDuplicated, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
return result;
|
|
}
|
|
|
|
m_to_write_docs.Add(docBase);
|
|
|
|
return result;
|
|
}
|
|
|
|
protected void pushWriteDocBase(DynamoDbDocBase docBase)
|
|
{
|
|
m_to_write_docs.Add(docBase);
|
|
}
|
|
|
|
protected void pushWriteDocBases(List<DynamoDbDocBase> docBases)
|
|
{
|
|
m_to_write_docs.AddRange(docBases);
|
|
}
|
|
|
|
public void deleteWriteDoc<TDoc>()
|
|
where TDoc : DynamoDbDocBase
|
|
{
|
|
var found_doc = getToWriteDocBase<TDoc>();
|
|
if (found_doc == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_to_write_docs.Remove(found_doc);
|
|
}
|
|
|
|
public TDoc? getToWriteDocBase<TDoc>()
|
|
where TDoc : DynamoDbDocBase
|
|
{
|
|
return m_to_write_docs.Find(x => x is TDoc == true) as TDoc;
|
|
}
|
|
|
|
public List<TDoc> getToWriteDocBases<TDoc>()
|
|
where TDoc : DynamoDbDocBase
|
|
{
|
|
return m_to_write_docs.FindAll(doc => doc is TDoc == true).ConvertAll(doc => (TDoc)doc);
|
|
}
|
|
|
|
public List<DynamoDbDocBase> getToWriteDocBases()
|
|
{
|
|
return m_to_write_docs;
|
|
}
|
|
|
|
public bool isCompletedPrepareCreate() => m_is_completed_prepare_create;
|
|
|
|
public void setCompetedPrepareCreate(bool isTrue) => m_is_completed_prepare_create = isTrue;
|
|
|
|
|
|
public Player getOwner() => m_owner;
|
|
}
|
|
}
|