first commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using FunGame.Core.Entity;
|
||||
using FunGame.Core.Library.Constant;
|
||||
|
||||
namespace FunGame.Server.Modules.Example;
|
||||
|
||||
/// <summary>示例角色:战士(力量型近战)</summary>
|
||||
public class ExampleWarrior : Character
|
||||
{
|
||||
public ExampleWarrior() : base()
|
||||
{
|
||||
Id = 90001;
|
||||
Name = "Example";
|
||||
FirstName = "Warrior";
|
||||
NickName = "示例战士";
|
||||
PrimaryAttribute = PrimaryAttribute.STR;
|
||||
InitialATK = 30;
|
||||
InitialHP = 100;
|
||||
InitialMP = 10;
|
||||
InitialSTR = 32;
|
||||
STRGrowth = 3;
|
||||
InitialAGI = 0;
|
||||
AGIGrowth = 0;
|
||||
InitialINT = 0;
|
||||
INTGrowth = 0;
|
||||
InitialSPD = 300;
|
||||
InitialHR = 4;
|
||||
InitialMR = 2;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>示例角色:法师(智力型远程)</summary>
|
||||
public class ExampleMage : Character
|
||||
{
|
||||
public ExampleMage() : base()
|
||||
{
|
||||
Id = 90002;
|
||||
Name = "Example";
|
||||
FirstName = "Mage";
|
||||
NickName = "示例法师";
|
||||
PrimaryAttribute = PrimaryAttribute.INT;
|
||||
InitialATK = 18;
|
||||
InitialHP = 75;
|
||||
InitialMP = 50;
|
||||
InitialSTR = 0;
|
||||
STRGrowth = 0;
|
||||
InitialAGI = 0;
|
||||
AGIGrowth = 0;
|
||||
InitialINT = 35;
|
||||
INTGrowth = 3;
|
||||
InitialSPD = 280;
|
||||
InitialHR = 3;
|
||||
InitialMR = 5;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
using FunGame.Core.Api;
|
||||
using FunGame.Core.Entity;
|
||||
using FunGame.Server.Contracts.Plugins;
|
||||
|
||||
namespace FunGame.Server.Modules.Example;
|
||||
|
||||
/// <summary>
|
||||
/// 示例角色模组:注册工厂(工厂注册保持模块化)+ 提供实体集合<para/>
|
||||
/// 通过工厂注册后,实体 JSON 配置(EntityModuleConfig)通道也能实例化本模组的角色
|
||||
/// </summary>
|
||||
public class ExampleCharacterModule : ICharacterModule
|
||||
{
|
||||
public string Name => "example.characters";
|
||||
public string Version => "1.0.0";
|
||||
public string Author => "FunGame.Server";
|
||||
public string Description => "示例角色模组:战士 / 法师";
|
||||
|
||||
private IReadOnlyDictionary<string, Character>? _entities;
|
||||
|
||||
public IReadOnlyDictionary<string, Character> Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
_entities ??= new Dictionary<string, Character>
|
||||
{
|
||||
["example_warrior"] = new ExampleWarrior(),
|
||||
["example_mage"] = new ExampleMage()
|
||||
};
|
||||
return _entities;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnLoad(IServiceProvider services)
|
||||
{
|
||||
// 工厂注册:id -> 构造函数,供 Factory.GetInstance / GetGameModuleInstances 使用
|
||||
Factory.OpenFactory.RegisterFactory<Character>((id, name, args) => id switch
|
||||
{
|
||||
90001 => new ExampleWarrior(),
|
||||
90002 => new ExampleMage(),
|
||||
_ => null
|
||||
});
|
||||
}
|
||||
|
||||
public void OnUnload()
|
||||
{
|
||||
// 从工厂注销(保持工厂可被热重载模组替换)
|
||||
Factory.OpenFactory.UnRegisterFactory<Character>((id, name, args) => id switch
|
||||
{
|
||||
90001 => new ExampleWarrior(),
|
||||
90002 => new ExampleMage(),
|
||||
_ => null
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>示例技能模组</summary>
|
||||
public class ExampleSkillModule : ISkillModule
|
||||
{
|
||||
public string Name => "example.skills";
|
||||
public string Version => "1.0.0";
|
||||
public string Author => "FunGame.Server";
|
||||
public string Description => "示例技能模组:示例打击";
|
||||
|
||||
private IReadOnlyDictionary<string, Skill>? _entities;
|
||||
|
||||
public IReadOnlyDictionary<string, Skill> Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
_entities ??= new Dictionary<string, Skill>
|
||||
{
|
||||
["example_strike"] = new ExampleStrike()
|
||||
};
|
||||
return _entities;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnLoad(IServiceProvider services)
|
||||
{
|
||||
Factory.OpenFactory.RegisterFactory<Skill>((id, name, args) => id switch
|
||||
{
|
||||
91001 => new ExampleStrike(),
|
||||
_ => null
|
||||
});
|
||||
}
|
||||
|
||||
public void OnUnload()
|
||||
{
|
||||
Factory.OpenFactory.UnRegisterFactory<Skill>((id, name, args) => id switch
|
||||
{
|
||||
91001 => new ExampleStrike(),
|
||||
_ => null
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>示例物品模组</summary>
|
||||
public class ExampleItemModule : IItemModule
|
||||
{
|
||||
public string Name => "example.items";
|
||||
public string Version => "1.0.0";
|
||||
public string Author => "FunGame.Server";
|
||||
public string Description => "示例物品模组:回复药剂";
|
||||
|
||||
private IReadOnlyDictionary<string, Item>? _entities;
|
||||
|
||||
public IReadOnlyDictionary<string, Item> Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
_entities ??= new Dictionary<string, Item>
|
||||
{
|
||||
["example_potion"] = new ExamplePotion()
|
||||
};
|
||||
return _entities;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnLoad(IServiceProvider services)
|
||||
{
|
||||
Factory.OpenFactory.RegisterFactory<Item>((id, name, args) => id switch
|
||||
{
|
||||
92001 => new ExamplePotion(),
|
||||
_ => null
|
||||
});
|
||||
}
|
||||
|
||||
public void OnUnload()
|
||||
{
|
||||
Factory.OpenFactory.UnRegisterFactory<Item>((id, name, args) => id switch
|
||||
{
|
||||
92001 => new ExamplePotion(),
|
||||
_ => null
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>FunGame.Server.Modules.Example</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\FunGame.Server.Contracts\FunGame.Server.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- 构建后复制到宿主的三个实体模组暂存区(热重载:由宿主原子替换到正式目录) -->
|
||||
<Target Name="CopyModulesToHost" AfterTargets="Build">
|
||||
<ItemGroup>
|
||||
<ModuleFiles Include="$(TargetDir)$(AssemblyName).dll;$(TargetDir)$(AssemblyName).pdb" />
|
||||
</ItemGroup>
|
||||
<MakeDir Directories="$(MSBuildThisFileDirectory)..\..\src\FunGame.Server.Host\modules\characters\_staging;$(MSBuildThisFileDirectory)..\..\src\FunGame.Server.Host\modules\skills\_staging;$(MSBuildThisFileDirectory)..\..\src\FunGame.Server.Host\modules\items\_staging" />
|
||||
<Copy SourceFiles="@(ModuleFiles)" DestinationFolder="$(MSBuildThisFileDirectory)..\..\src\FunGame.Server.Host\modules\characters\_staging\" SkipUnchangedFiles="false" />
|
||||
<Copy SourceFiles="@(ModuleFiles)" DestinationFolder="$(MSBuildThisFileDirectory)..\..\src\FunGame.Server.Host\modules\skills\_staging\" SkipUnchangedFiles="false" />
|
||||
<Copy SourceFiles="@(ModuleFiles)" DestinationFolder="$(MSBuildThisFileDirectory)..\..\src\FunGame.Server.Host\modules\items\_staging\" SkipUnchangedFiles="false" />
|
||||
<Message Text="实体模组已复制到 Host/modules/*/_staging:$(AssemblyName).dll(等待宿主热替换)" Importance="high" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,20 @@
|
||||
using FunGame.Core.Entity;
|
||||
using FunGame.Core.Library.Constant;
|
||||
|
||||
namespace FunGame.Server.Modules.Example;
|
||||
|
||||
/// <summary>示例物品:回复药剂(使用后回复生命值)</summary>
|
||||
public class ExamplePotion : Item
|
||||
{
|
||||
public ExamplePotion() : base(ItemType.Consumable)
|
||||
{
|
||||
Id = 92001;
|
||||
Name = "示例回复药剂";
|
||||
QualityType = QualityType.Blue;
|
||||
RemainUseTimes = 1;
|
||||
IsSellable = true;
|
||||
IsTradable = true;
|
||||
Price = 50;
|
||||
Description = "使用后立即回复 100 点生命值。";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using FunGame.Core.Entity;
|
||||
using FunGame.Core.Library.Constant;
|
||||
using FunGame.Core.Model.EffectContext;
|
||||
using FunGame.Core.Model.Framework;
|
||||
|
||||
namespace FunGame.Server.Modules.Example;
|
||||
|
||||
/// <summary>示例技能:强力打击(物理伤害 + 小幅度生命回复)</summary>
|
||||
public class ExampleStrike : Skill
|
||||
{
|
||||
public override long Id => 91001;
|
||||
public override string Name => "示例打击";
|
||||
public override string Description => Effects.Count > 0 ? Effects.First().Description : "";
|
||||
public override double EPCost => 40;
|
||||
public override double CD => 15;
|
||||
public override double HardnessTime { get; set; } = 8;
|
||||
public override int CanSelectTargetRange => 1;
|
||||
|
||||
public ExampleStrike(Character? character = null) : base(SkillType.Skill, character)
|
||||
{
|
||||
Effects.Add(new ExampleDamage(this, 90, 30, DamageType.Physical));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>示例特效:基于攻击力的物理伤害</summary>
|
||||
public class ExampleDamage : Effect
|
||||
{
|
||||
public override long Id => Skill.Id;
|
||||
public override string Name => Skill.Name;
|
||||
public override string Description => $"对目标造成 {Damage:0.##} 点{CharacterSet.GetDamageTypeName(DamageType)}伤害。";
|
||||
|
||||
private double Damage => Skill.Level > 0 ? 基础伤害 + 等级成长 * (Skill.Level - 1) : 基础伤害;
|
||||
private double 基础伤害 { get; set; } = 90;
|
||||
private double 等级成长 { get; set; } = 30;
|
||||
private DamageType DamageType { get; set; } = DamageType.Physical;
|
||||
|
||||
public ExampleDamage(Skill skill, double 基础伤害, double 等级成长, DamageType damageType) : base(skill)
|
||||
{
|
||||
GamingQueue = skill.GamingQueue;
|
||||
this.基础伤害 = 基础伤害;
|
||||
this.等级成长 = 等级成长;
|
||||
DamageType = damageType;
|
||||
}
|
||||
|
||||
public override void OnSkillCasted(SkillCastContext ctx)
|
||||
{
|
||||
Character? caster = ctx.Actor;
|
||||
foreach (Character enemy in ctx.Targets)
|
||||
{
|
||||
if (caster != null)
|
||||
{
|
||||
DamageToEnemy(caster, enemy, DamageType, MagicType.None, Damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user