using Milimoe.FunGame.Core.Api.Utility;
using Milimoe.FunGame.Core.Entity;
using Milimoe.FunGame.Core.Interface.Addons;
namespace Milimoe.FunGame.Core.Library.Common.Addon
{
public abstract class CharacterModule : IAddon
{
///
/// 模组名称
///
public abstract string Name { get; }
///
/// 模组描述
///
public abstract string Description { get; }
///
/// 模组版本
///
public abstract string Version { get; }
///
/// 模组作者
///
public abstract string Author { get; }
///
/// 此模组中包含的角色
///
public abstract Dictionary Characters { get; }
///
/// 加载标记
///
private bool IsLoaded = false;
///
/// 加载模组
///
public bool Load(params object[] objs)
{
if (IsLoaded)
{
return false;
}
// BeforeLoad可以阻止加载此模组
if (BeforeLoad())
{
// 模组加载后,不允许再次加载此模组
IsLoaded = true;
// 注册工厂
Factory.OpenFactory.RegisterFactory(EntityFactory());
// 如果加载后需要执行代码,请重写AfterLoad方法
AfterLoad();
}
return IsLoaded;
}
///
/// 注册工厂
///
protected virtual Factory.EntityFactoryDelegate EntityFactory()
{
return (id, name, args) =>
{
Character c = Factory.GetCharacter();
c.Id = id;
c.Name = name;
return c;
};
}
///
/// 模组加载后需要做的事
///
protected virtual void AfterLoad()
{
// override
}
///
/// 允许返回false来阻止加载此模组
///
///
protected virtual bool BeforeLoad()
{
return true;
}
}
}