초기커밋
This commit is contained in:
75
ServerBase/Entity/State/EntityHFSMBase.cs
Normal file
75
ServerBase/Entity/State/EntityHFSMBase.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using AsyncStateMachine;
|
||||
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
|
||||
using SESSION_ID = System.Int32;
|
||||
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 ServerBase;
|
||||
|
||||
|
||||
public abstract partial class EntityHFSMBase : HFSMBase<EntityStateTriggerType, EntityStateType>, IWithEntityOwner
|
||||
{
|
||||
private readonly EntityBase m_owner;
|
||||
|
||||
public EntityHFSMBase(EntityBase owner)
|
||||
: base()
|
||||
{
|
||||
m_owner = owner;
|
||||
}
|
||||
|
||||
|
||||
public async Task<Result> loadHfsm()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
if (false == await initHfsm(EntityStateType.Created, setupHfsm))
|
||||
{
|
||||
err_msg = $"\"Failed to create Entity HFSM !!!";
|
||||
result.setFail(ServerErrorCode.EntityBaseHfsmInitFailed, err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected abstract bool setupHfsm(HFSMBase<EntityStateTriggerType, EntityStateType> initHFSM);
|
||||
|
||||
public override void onSubscribeStateChangeNotify()
|
||||
{
|
||||
var sm = getStateMachine();
|
||||
NullReferenceCheckHelper.throwIfNull(sm, () => $"sm is null !!!");
|
||||
|
||||
sm.Observable.Subscribe(onTransitionedState);
|
||||
}
|
||||
|
||||
protected virtual void onTransitionedState(AsyncStateMachine.Transition<EntityStateTriggerType, EntityStateType> transition)
|
||||
{
|
||||
if (false == transition.isChangedState())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var owner = getOwner();
|
||||
|
||||
var debug_msg = $"EntityHFSM transited State !!! : {transition.toBasicString()} - {owner.toBasicString()}";
|
||||
Log.getLogger().debug(debug_msg);
|
||||
}
|
||||
}
|
||||
61
ServerBase/Entity/State/EntityStateBase.cs
Normal file
61
ServerBase/Entity/State/EntityStateBase.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
|
||||
using SESSION_ID = System.Int32;
|
||||
using WORLD_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 ServerBase;
|
||||
|
||||
public abstract partial class EntityStateBase
|
||||
{
|
||||
private readonly EntityBase m_owner;
|
||||
|
||||
private DateTime m_start_time = DateTime.MinValue;
|
||||
private DateTime m_end_time = DateTime.MinValue;
|
||||
|
||||
public EntityStateBase(EntityBase owner)
|
||||
{
|
||||
m_owner = owner;
|
||||
}
|
||||
|
||||
public virtual async Task onEnter()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
m_start_time = DateTimeHelper.Current;
|
||||
}
|
||||
|
||||
public virtual async Task onTick()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual async Task onExit()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
m_end_time = DateTimeHelper.Current;
|
||||
}
|
||||
|
||||
public DateTime getStartTime() { return m_start_time; }
|
||||
|
||||
public DateTime getEndTime() { return m_end_time; }
|
||||
|
||||
public UInt64 getElapsedMilliSeconds()
|
||||
{
|
||||
return (UInt64)(m_end_time - m_start_time).TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user