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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>FunGame.Server.Modules.Melee</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\FunGame.Server.Contracts\FunGame.Server.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- 构建后复制到宿主的游戏模式模组暂存区(热重载:由宿主原子替换到正式目录 modules/games) -->
|
||||
<Target Name="CopyModulesToHost" AfterTargets="Build">
|
||||
<ItemGroup>
|
||||
<ModuleFiles Include="$(TargetDir)$(AssemblyName).dll;$(TargetDir)$(AssemblyName).pdb" />
|
||||
</ItemGroup>
|
||||
<MakeDir Directories="$(MSBuildThisFileDirectory)..\..\src\FunGame.Server.Host\modules\games\_staging" />
|
||||
<Copy SourceFiles="@(ModuleFiles)" DestinationFolder="$(MSBuildThisFileDirectory)..\..\src\FunGame.Server.Host\modules\games\_staging\" SkipUnchangedFiles="false" />
|
||||
<Message Text="GameModule 已复制到 Host/modules/games/_staging:$(AssemblyName).dll(等待宿主热替换)" Importance="high" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,134 @@
|
||||
using System.Collections.Concurrent;
|
||||
using FunGame.Core.Entity;
|
||||
using FunGame.Core.Library.Constant;
|
||||
using FunGame.Core.Model.Framework;
|
||||
using FunGame.Core.Model.Queue;
|
||||
using FunGame.Server.Contracts.Gaming;
|
||||
using FunGame.Server.Contracts.Networking;
|
||||
using FunGame.Server.Contracts.Plugins;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FunGame.Server.Modules.Melee;
|
||||
|
||||
/// <summary>
|
||||
/// 标准近战 GameModule(游戏模式模组):封装网络层在 MixGamingQueue 之上<para/>
|
||||
/// 参考 v2 ExampleGameModuleServer:单例模组、按房间建 Worker(GamingObject 对应物)、
|
||||
/// GamingType switch-case 处理玩家行动;内容层(角色/技能/物品/Effect)经 GameModuleDepend 声明依赖。<para/>
|
||||
/// 当前为 Phase 0:建房(StartGameAsync)+ 连接确认 + 选角;Attack/Skill/Item 等玩家局内决策后续接入。
|
||||
/// </summary>
|
||||
public class MeleeGameModuleServer : IGameModuleServer
|
||||
{
|
||||
public string Name => "melee";
|
||||
public string Version => "0.1.0";
|
||||
public string Author => "FunGame.Server";
|
||||
public string Description => "标准近战游戏模式:淘汰制死亡竞赛(最多复活 1 次),封装网络层在 MixGamingQueue 上";
|
||||
|
||||
public string Id => Name;
|
||||
|
||||
public GameModuleDepend Dependencies { get; } = new(
|
||||
maps: [],
|
||||
characters: ["example", "oshima"],
|
||||
skills: ["example", "oshima"],
|
||||
items: ["example", "oshima"]);
|
||||
|
||||
public string DefaultMap => "";
|
||||
|
||||
public RoomType RoomType => RoomType.Mix;
|
||||
|
||||
public int MaxUsers => 8;
|
||||
|
||||
private ILogger? _logger;
|
||||
|
||||
/// <summary>房间工作区:游戏 Id ->(角色池 / 已连接用户 / 用户角色选择)</summary>
|
||||
private sealed record Worker(List<Character> Characters, HashSet<long> ConnectedUsers, Dictionary<long, Character> UserCharacters);
|
||||
|
||||
private readonly ConcurrentDictionary<Guid, Worker> _workers = new();
|
||||
|
||||
public void OnLoad(IServiceProvider services)
|
||||
{
|
||||
_logger = services.GetService<ILoggerFactory>()?.CreateLogger("GameModule.melee");
|
||||
_logger?.LogInformation("MeleeGameModuleServer v{Version} 已加载", Version);
|
||||
}
|
||||
|
||||
public void OnUnload()
|
||||
{
|
||||
_logger?.LogInformation("MeleeGameModuleServer 即将卸载(活跃对局 {Count})", _workers.Count);
|
||||
_workers.Clear();
|
||||
}
|
||||
|
||||
/// <summary>建房:创建 MixGamingQueue(沿用宿主当前淘汰/复活=1 配置),登记房间工作区</summary>
|
||||
public Task<GamingQueue> StartGameAsync(IGameSession session, params object[] args)
|
||||
{
|
||||
List<Character> characters = args.Length > 0 && args[0] is List<Character> list ? list : [];
|
||||
GameMap? map = args.Length > 1 ? args[1] as GameMap : null;
|
||||
|
||||
MixGamingQueue queue = new(characters, msg => _logger?.LogDebug("[Melee {GameId}] {Msg}", session.Id, msg))
|
||||
{
|
||||
IsDebug = false,
|
||||
MaxRespawnTimes = 1
|
||||
};
|
||||
if (map != null)
|
||||
{
|
||||
queue.LoadGameMap(map);
|
||||
}
|
||||
queue.InitActionQueue();
|
||||
|
||||
_workers[session.Id] = new Worker(characters, [], []);
|
||||
_logger?.LogInformation("Melee 对局 {GameId} 开始({Count} 名角色)", session.Id, characters.Count);
|
||||
return Task.FromResult<GamingQueue>(queue);
|
||||
}
|
||||
|
||||
/// <summary>处理客户端局内消息(switch-case GamingType,参考 v2)</summary>
|
||||
public Task<Dictionary<string, object>?> HandleGamingMessageAsync(IGameSession session, IClientSession client, GamingType type, Dictionary<string, object> data)
|
||||
{
|
||||
if (!_workers.TryGetValue(session.Id, out Worker? worker))
|
||||
{
|
||||
return Task.FromResult<Dictionary<string, object>?>(new Dictionary<string, object> { ["error"] = "对局工作区不存在" });
|
||||
}
|
||||
|
||||
long userId = client.UserId ?? client.SessionId;
|
||||
switch (type)
|
||||
{
|
||||
case GamingType.Connect:
|
||||
worker.ConnectedUsers.Add(userId);
|
||||
return Task.FromResult<Dictionary<string, object>?>(new Dictionary<string, object>
|
||||
{
|
||||
["msg"] = "连接确认成功",
|
||||
["connected"] = worker.ConnectedUsers.Count,
|
||||
["total"] = worker.Characters.Count
|
||||
});
|
||||
|
||||
case GamingType.PickCharacter:
|
||||
{
|
||||
long id = GetLong(data, "id");
|
||||
Character? character = worker.Characters.FirstOrDefault(c => c.Id == id);
|
||||
if (character == null)
|
||||
{
|
||||
return Task.FromResult<Dictionary<string, object>?>(new Dictionary<string, object> { ["error"] = $"角色不存在:{id}" });
|
||||
}
|
||||
worker.UserCharacters[userId] = character;
|
||||
return Task.FromResult<Dictionary<string, object>?>(new Dictionary<string, object>
|
||||
{
|
||||
["msg"] = $"已选择角色:{character.NickName ?? character.Name}",
|
||||
["id"] = character.Id
|
||||
});
|
||||
}
|
||||
|
||||
case GamingType.Surrender:
|
||||
_ = session.EndGameAsync();
|
||||
return Task.FromResult<Dictionary<string, object>?>(new Dictionary<string, object> { ["msg"] = "对局已结束" });
|
||||
|
||||
default:
|
||||
// Attack/Skill/Item/Move/Magic/Buy/... 玩家局内决策接入后续里程碑实现
|
||||
return Task.FromResult<Dictionary<string, object>?>(new Dictionary<string, object>
|
||||
{
|
||||
["msg"] = $"已收到 {type}(玩家局内决策接入后续实现)",
|
||||
["round"] = session.Queue.TotalRound
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static long GetLong(Dictionary<string, object> data, string key)
|
||||
=> data.TryGetValue(key, out object? value) && long.TryParse(value?.ToString(), out long result) ? result : 0;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>FunGame.Server.Modules.Oshima</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\FunGame.Server.Contracts\FunGame.Server.Contracts.csproj" />
|
||||
<ProjectReference Include="..\..\..\FunGame.Core\FunGame.Core.csproj" />
|
||||
<!-- Oshima 内容库:Testing-v3 维护(最先适配 Core v3),Server 只引用不拷贝 -->
|
||||
<ProjectReference Include="..\..\..\FunGame.Testing-v3\OshimaGameModules\OshimaGameModules.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- 构建后复制包装层 + 内容库 DLL 到宿主的三个实体模组暂存区(热重载:由宿主原子替换到正式目录) -->
|
||||
<Target Name="CopyModulesToHost" AfterTargets="Build">
|
||||
<ItemGroup>
|
||||
<ModuleFiles Include="$(TargetDir)$(AssemblyName).dll;$(TargetDir)$(AssemblyName).pdb;$(TargetDir)OshimaGameModules.dll;$(TargetDir)OshimaGameModules.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="Oshima 包装层 + 内容库已复制到 Host/modules/*/_staging(等待宿主热替换)" Importance="high" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Milimoe.FunGameTesting.Others
|
||||
{
|
||||
public class OshimaGameModuleConstant
|
||||
{
|
||||
public const string General = "oshima-studios";
|
||||
public const string WebAPI = "oshima.fungame.webapi";
|
||||
public const string FastAuto = "oshima.fungame.fastauto";
|
||||
public const string Character = "oshima.fungame.characters";
|
||||
public const string Skill = "oshima.fungame.skills";
|
||||
public const string Item = "oshima.fungame.items";
|
||||
public const string Description = "Oshima Studios Presents";
|
||||
public const string Version = "1.0.0";
|
||||
public const string Author = "Oshima Studios";
|
||||
public const string FastAutoMap = "oshima.fungame.fastauto.map";
|
||||
public const string Anonymous = "oshima.fungame.anonymous";
|
||||
public const string AnonymousMap = "oshima.fungame.anonymous.map";
|
||||
public const string Server = "oshima.fungame.server";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
using FunGame.Core.Api;
|
||||
using FunGame.Core.Entity;
|
||||
using FunGame.Server.Contracts.Plugins;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Milimoe.FunGameTesting.Others;
|
||||
using Milimoe.FunGameTesting.OshimaGameModules.Characters;
|
||||
using Milimoe.FunGameTesting.OshimaGameModules.Items;
|
||||
using Milimoe.FunGameTesting.OshimaGameModules.Skills;
|
||||
|
||||
namespace FunGame.Server.Modules.Oshima;
|
||||
|
||||
/// <summary>
|
||||
/// 创建实体新实例:优先无参构造;无无参构造时退化为 (Character? = null) 风格的构造(技能类惯例)<para/>
|
||||
/// 工厂委托必须返回新实例而非 Copy(),避免 Skill.Copy 内部调用 Factory.GetInstance 造成无限递归
|
||||
/// </summary>
|
||||
internal static class ModuleEntityFactory
|
||||
{
|
||||
public static T? Create<T>(Type type) where T : class
|
||||
{
|
||||
try
|
||||
{
|
||||
return (T)Activator.CreateInstance(type)!;
|
||||
}
|
||||
catch (MissingMethodException)
|
||||
{
|
||||
return (T)Activator.CreateInstance(type, (object?[]?)[null])!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Oshima Studios 角色模组:Testing-v3(FunGameSimulation)同源内容,供 Server 加载<para/>
|
||||
/// 18 名角色(大島シヤ / 心音 / 阳 / 南甘雨 …),与 Testing-v3 的 Oshima CharacterModule 工厂(id 1-18)一一对应
|
||||
/// </summary>
|
||||
public class OshimaCharacterModule : ICharacterModule
|
||||
{
|
||||
public string Name => "oshima.characters";
|
||||
public string Version => "1.0.0";
|
||||
public string Author => "Oshima Studios";
|
||||
public string Description => "Oshima 角色模组:18 名角色(移植自 FunGame.Testing-v3 / FunGameSimulation)";
|
||||
|
||||
private IReadOnlyDictionary<string, Character>? _entities;
|
||||
|
||||
public IReadOnlyDictionary<string, Character> Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
_entities ??= new Dictionary<string, Character>
|
||||
{
|
||||
["oshima_shiya"] = new OshimaShiya(),
|
||||
["xin_yin"] = new XinYin(),
|
||||
["yang"] = new Yang(),
|
||||
["nan_ganyu"] = new NanGanYu(),
|
||||
["niu_nan"] = new NiuNan(),
|
||||
["dokyo_mayor"] = new DokyoMayor(),
|
||||
["magical_girl"] = new MagicalGirl(),
|
||||
["qing_xiang"] = new QingXiang(),
|
||||
["qwqaqw"] = new QWQAQW(),
|
||||
["cold_blue"] = new ColdBlue(),
|
||||
["dddovo"] = new Dddovo(),
|
||||
["qu_duoduo"] = new Quduoduo(),
|
||||
["shi_yu"] = new ShiYu(),
|
||||
["xreouni"] = new XReouni(),
|
||||
["neptune"] = new Neptune(),
|
||||
["chaos"] = new CHAOS(),
|
||||
["ryuko"] = new Ryuko(),
|
||||
["the_god_k"] = new TheGodK()
|
||||
};
|
||||
return _entities;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnLoad(IServiceProvider services)
|
||||
{
|
||||
// 注册工厂(与 Oshima CharacterModule 工厂一致:id 1-18)
|
||||
Factory.OpenFactory.RegisterFactory<Character>((id, name, args) => id switch
|
||||
{
|
||||
1 => new OshimaShiya(),
|
||||
2 => new XinYin(),
|
||||
3 => new Yang(),
|
||||
4 => new NanGanYu(),
|
||||
5 => new NiuNan(),
|
||||
6 => new DokyoMayor(),
|
||||
7 => new MagicalGirl(),
|
||||
8 => new QingXiang(),
|
||||
9 => new QWQAQW(),
|
||||
10 => new ColdBlue(),
|
||||
11 => new Dddovo(),
|
||||
12 => new Quduoduo(),
|
||||
13 => new ShiYu(),
|
||||
14 => new XReouni(),
|
||||
15 => new Neptune(),
|
||||
16 => new CHAOS(),
|
||||
17 => new Ryuko(),
|
||||
18 => new TheGodK(),
|
||||
_ => null
|
||||
});
|
||||
}
|
||||
|
||||
public void OnUnload()
|
||||
{
|
||||
Factory.OpenFactory.UnRegisterFactory<Character>((id, name, args) => id switch
|
||||
{
|
||||
1 => new OshimaShiya(),
|
||||
2 => new XinYin(),
|
||||
3 => new Yang(),
|
||||
4 => new NanGanYu(),
|
||||
5 => new NiuNan(),
|
||||
6 => new DokyoMayor(),
|
||||
7 => new MagicalGirl(),
|
||||
8 => new QingXiang(),
|
||||
9 => new QWQAQW(),
|
||||
10 => new ColdBlue(),
|
||||
11 => new Dddovo(),
|
||||
12 => new Quduoduo(),
|
||||
13 => new ShiYu(),
|
||||
14 => new XReouni(),
|
||||
15 => new Neptune(),
|
||||
16 => new CHAOS(),
|
||||
17 => new Ryuko(),
|
||||
18 => new TheGodK(),
|
||||
_ => null
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Oshima 技能模组:基础战技 / 爆发技 / 被动 / 通用被动 / 通用爆发 / 魔法 全量注册
|
||||
/// </summary>
|
||||
public class OshimaSkillModule : ISkillModule
|
||||
{
|
||||
public string Name => "oshima.skills";
|
||||
public string Version => "1.0.0";
|
||||
public string Author => "Oshima Studios";
|
||||
public string Description => "Oshima 技能模组:基础技能 / 爆发技 / 被动 / 魔法(移植自 FunGame.Testing-v3)";
|
||||
|
||||
private IReadOnlyDictionary<string, Skill>? _entities;
|
||||
|
||||
public IReadOnlyDictionary<string, Skill> Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
_entities ??= BuildEntities();
|
||||
return _entities;
|
||||
}
|
||||
}
|
||||
|
||||
private static IReadOnlyDictionary<string, Skill> BuildEntities()
|
||||
{
|
||||
Dictionary<string, Skill> skills = new();
|
||||
int seq = 0;
|
||||
Skill[] all =
|
||||
[
|
||||
// ===== 基础战技 =====
|
||||
new 疾风步(), new 助威(), new 挑拨(), new 绞丝棍(), new 金刚击(), new 旋风轮(), new 双连击(), new 绝影(), new 胧(), new 魔眼(),
|
||||
new 天堂之吻(), new 回复弹(), new 养命功(), new 镜花水月(), new 剑风闪(), new 鲨鱼锚击(), new 疾走(), new 闪现(),
|
||||
// ===== 爆发技 =====
|
||||
new 极寒渴望(), new 身心一境(), new 绝对领域(), new 零式灭杀(), new 三相灵枢(), new 变幻之心(), new 熵灭极诣(), new 残香凋零(), new 饕餮盛宴(),
|
||||
new 宿命时律(), new 千羽瞬华(), new 咒怨洪流(), new 放监(), new 归元环(), new 海王星的野望(), new 全军出击(), new 宿命之潮(), new 神之因果(),
|
||||
// ===== 角色被动 =====
|
||||
new META马(), new 心灵之弦(), new 蚀魂震击(), new 灵能反射(), new 双生流转(), new 零式崩解(), new 少女绮想(), new 暗香疏影(), new 破釜沉舟(),
|
||||
new 累积之压(), new 银隼之赐(), new 弱者猎手(), new 开宫(), new 八卦阵(), new 深海之戟(), new 雇佣兵团(), new 不息之流(), new 概念之骰(),
|
||||
// ===== 通用被动 =====
|
||||
new 征服者(), new 致命节奏(), new 强攻(), new 电刑(), new 黑暗收割(), new 迅捷步法(), new 贪欲猎手(),
|
||||
// ===== 通用爆发 =====
|
||||
new 樱花无双击(), new 漆黑之牙(), new 女王之怒(), new 裁决塔罗(), new 光明之环(), new 圣星光旋(),
|
||||
// ===== 魔法 =====
|
||||
new 冰霜攻击(), new 火之矢(), new 水之矢(), new 风之轮(), new 石之锤(), new 心灵之霞(), new 次元上升(), new 暗物质(),
|
||||
new 回复术(), new 治愈术(), new 复苏术(), new 圣灵术(), new 时间加速(), new 时间减速(), new 反魔法领域(), new 沉默十字(), new 虚弱领域(), new 混沌烙印(), new 凝胶稠絮(),
|
||||
new 大地之墙(), new 盖亚之盾(), new 风之守护(), new 结晶防护(), new 强音之力(), new 神圣祝福(), new 根源屏障(), new 灾难冲击波(), new 银色荆棘(), new 等离子之波(),
|
||||
new 地狱之门(), new 钻石星尘(), new 死亡咆哮(), new 鬼魅之痛(), new 导力停止(), new 冰狱冥嚎(), new 火山咆哮(), new 水蓝轰炸(), new 岩石之息(), new 弧形日珥(), new 苍白地狱(), new 破碎虚空(),
|
||||
new 弧光消耗(), new 回复术改(), new 回复术复(), new 治愈术复(), new 风之守护复(), new 强音之力复(), new 结晶防护复(), new 神圣祝福复(), new 时间加速改(), new 时间减速改(), new 时间加速复(), new 时间减速复()
|
||||
];
|
||||
foreach (Skill skill in all)
|
||||
{
|
||||
skills[$"oshima_skill_{++seq}"] = skill;
|
||||
}
|
||||
return skills;
|
||||
}
|
||||
|
||||
public void OnLoad(IServiceProvider services)
|
||||
{
|
||||
// 注意:工厂委托必须返回“新实例”,不能用 skill.Copy()——Copy 内部会再调 Factory.GetInstance,形成无限递归
|
||||
foreach (Skill skill in Entities.Values)
|
||||
{
|
||||
Factory.OpenFactory.RegisterFactory<Skill>((id, name, args) => skill.Id == id ? ModuleEntityFactory.Create<Skill>(skill.GetType()) : null);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnUnload()
|
||||
{
|
||||
foreach (Skill skill in Entities.Values)
|
||||
{
|
||||
Factory.OpenFactory.UnRegisterFactory<Skill>((id, name, args) => skill.Id == id ? ModuleEntityFactory.Create<Skill>(skill.GetType()) : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Oshima 物品模组:装备(武器/防具/鞋子/饰品)+ 消耗品 + 收藏品 全量注册
|
||||
/// </summary>
|
||||
public class OshimaItemModule : IItemModule
|
||||
{
|
||||
public string Name => "oshima.items";
|
||||
public string Version => "1.0.0";
|
||||
public string Author => "Oshima Studios";
|
||||
public string Description => "Oshima 物品模组:装备 / 消耗品 / JSON 配置物品(移植自 FunGame.Testing-v3)";
|
||||
|
||||
/// <summary>JSON 配置物品数量(modules/oshima-studios/oshima.fungame.items.json)</summary>
|
||||
public static int JsonItemCount { get; private set; }
|
||||
|
||||
private IReadOnlyDictionary<string, Item>? _entities;
|
||||
|
||||
public IReadOnlyDictionary<string, Item> Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
_entities ??= BuildEntities();
|
||||
return _entities;
|
||||
}
|
||||
}
|
||||
|
||||
private static IReadOnlyDictionary<string, Item> BuildEntities()
|
||||
{
|
||||
Dictionary<string, Item> items = new();
|
||||
|
||||
// ===== JSON 配置物品(EntityModuleConfig 通道:modules/oshima-studios/oshima.fungame.items.json)=====
|
||||
try
|
||||
{
|
||||
Dictionary<string, Item> jsonItems = Factory.GetGameModuleInstances<Item>(OshimaGameModuleConstant.General, OshimaGameModuleConstant.Item);
|
||||
foreach ((string key, Item item) in jsonItems)
|
||||
{
|
||||
items[$"oshima_json_{key}"] = item;
|
||||
}
|
||||
JsonItemCount = jsonItems.Count;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
JsonItemCount = -1; // JSON 缺失或解析失败(代码物品仍可用)
|
||||
}
|
||||
|
||||
// ===== 代码注册物品 =====
|
||||
int seq = 0;
|
||||
Item[] all =
|
||||
[
|
||||
// ===== 武器 =====
|
||||
new 攻击之爪10(), new 攻击之爪25(), new 攻击之爪40(), new 攻击之爪55(), new 攻击之爪70(), new 攻击之爪85(), new 糖糖一周年纪念武器(),
|
||||
// ===== 防具 =====
|
||||
new 糖糖一周年纪念防具(),
|
||||
// ===== 鞋子 =====
|
||||
new 糖糖一周年纪念鞋子(),
|
||||
// ===== 饰品 =====
|
||||
new 糖糖一周年纪念饰品1(), new 糖糖一周年纪念饰品2(),
|
||||
// ===== 消耗品 =====
|
||||
new 小经验书(), new 中经验书(), new 大经验书(), new 升华之印(), new 流光之印(), new 永恒之印(), new 技能卷轴(), new 智慧之果(), new 奥术符文(), new 混沌之核(),
|
||||
new 小回复药(), new 中回复药(), new 大回复药(), new 魔力填充剂1(), new 魔力填充剂2(), new 魔力填充剂3(), new 能量饮料1(), new 能量饮料2(), new 能量饮料3(), new 年夜饭(), new 蛇年大吉(), new 新春快乐(), new 毕业礼包(),
|
||||
new 复苏药1(), new 复苏药2(), new 复苏药3(), new 全回复药(), new 魔法卡礼包(), new 奖券(), new 十连奖券(), new 改名卡(), new 原初之印(), new 创生之印(), new 法则精粹(), new 大师锻造券(),
|
||||
new 一周年纪念礼包(), new 一周年纪念套装(), new 冬至快乐(), new 圣诞礼包(), new 元旦快乐()
|
||||
];
|
||||
foreach (Item item in all)
|
||||
{
|
||||
items[$"oshima_item_{++seq}"] = item;
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public void OnLoad(IServiceProvider services)
|
||||
{
|
||||
ILoggerFactory? loggerFactory = services.GetService(typeof(ILoggerFactory)) as ILoggerFactory;
|
||||
ILogger? logger = loggerFactory?.CreateLogger("OshimaItemModule");
|
||||
int total = Entities.Count;
|
||||
int jsonCount = Math.Max(JsonItemCount, 0);
|
||||
logger?.LogInformation("Oshima 物品模组加载:代码物品 {CodeCount} 件 + JSON 配置物品 {JsonCount} 件", total - jsonCount, JsonItemCount);
|
||||
foreach (Item item in Entities.Values)
|
||||
{
|
||||
// 注意:工厂委托必须返回“新实例”,不能用 item.Copy()——Copy 内部会再调 Factory.GetInstance,形成无限递归
|
||||
Factory.OpenFactory.RegisterFactory<Item>((id, name, args) => item.Id == id ? ModuleEntityFactory.Create<Item>(item.GetType()) : null);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnUnload()
|
||||
{
|
||||
foreach (Item item in Entities.Values)
|
||||
{
|
||||
Factory.OpenFactory.UnRegisterFactory<Item>((id, name, args) => item.Id == id ? ModuleEntityFactory.Create<Item>(item.GetType()) : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user