自己捣鼓的,功能已实现,不知道有没有缺陷,希望大佬们指正。
具体步骤:
1、添加D键设置选项
Client\UserModels\KeyBindInfo.cs
public enum KeyBindAction中添加
[Description("D键菜单")]
DWindow,
2、设置默认按键设置
Client\Envir\CEnvir.cs
public static void ResetKeyBind(KeyBindAction action)添加修改
case KeyBindAction.DWindow://D键
bind.Category = "Functions";
bind.Key1 = Keys.D;
break;
case KeyBindAction.AutoRunToggle://自动跑
bind.Category = "Functions";
bind.Key1 = Keys.D;
bind.Control1 = true;
break;
3、在数据库中新建D键NPC
NPC对话中新建D键目录及需要的功能
NPC设置中新建NPC,地图不选,Page选择D键主菜单
从任务等设置中看看刚才NPC的index,记下来
4、声明一个NPCObject
Server\Models\NPCObject.cs添加
public static NPCObject Dnpc;//D键随身NPC
5、服务器启动这个NPC并保存进Dnpc
Server\Envir\SEnvir.cs修改
private static void CreateNPCs()
{
NPCObject ob;
foreach (NPCInfo info in NPCInfoList.Binding)
{
if (info.Index == 140)
{
ob = new NPCObject { NPCInfo = info, };
NPCObject.Dnpc = ob;//储存刚才的NPC
}
else
{
if (info.Region == null) continue;
Map map = GetMap(info.Region.Map);
if (map == null)
{
Log(string.Format("[NPC错误] 错误地图, NPC: {0}, Map: {1}", info.NPCName, info.Region.ServerDescription));
continue;
}
ob = new NPCObject
{
NPCInfo = info,
};
if (!ob.Spawn(info.Region))
Log($"[NPC错误] 无法生成NPC, 区域: {info.Region.ServerDescription}, NPC: {info.NPCName}");
}
}
}
6、客户端D键按下触发
Client\Scenes\GameScene.cs
public override void OnKeyDown(KeyEventArgs e)
foreach (KeyBindAction action in CEnvir.GetKeyAction(e.KeyCode))添加
case KeyBindAction.DWindow:
//D键
if (CEnvir.Now <= GameScene.Game.NPCTime) return;
GameScene.Game.NPCTime = CEnvir.Now.AddSeconds(1);
CEnvir.Enqueue(new C.NPCCall { ObjectID = 1 });//随便用了一个id
break;
7、服务端判断并传回
Server\Models\PlayerObject.cs修改
public void NPCCall(uint objectID)
{
if (Dead) return;
NPC = null;
NPCPage = null;
//D键随身NPC载入,ID对应客户端传入的id
if (objectID == 1)
{
NPCObject ob = NPCObject.Dnpc;
ob.NPCCall(this, ob.NPCInfo.EntryPage);
return;
}
else
{
foreach (NPCObject ob in CurrentMap.NPCs)
{
if (ob.ObjectID != objectID) continue;
if (!Functions.InRange(ob.CurrentLocation, CurrentLocation, Config.MaxViewRange)) return;
ob.NPCCall(this, ob.NPCInfo.EntryPage);
return;
}
}
}
D键随身NPC功能,不需要外挂脚本,使用原版数据库设置。
摘要:
...
您需要 登录账户 后才能发表评论
还没有评论,来说两句吧...