Skip to content

Commit 60d366f

Browse files
authored
源代码
1 parent bfa03a6 commit 60d366f

File tree

5 files changed

+284
-0
lines changed

5 files changed

+284
-0
lines changed

MusicDummy/Dummy.cs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using Exiled.API.Features;
2+
using Mirror;
3+
using SCPSLAudioApi.AudioCore;
4+
using System.Collections.Generic;
5+
using UnityEngine;
6+
using VoiceChat;
7+
8+
namespace MusicDummy
9+
{
10+
public static class Dummy
11+
{
12+
/// <summary>
13+
/// 假人列表
14+
/// </summary>
15+
public static Dictionary<int, Player> List = new Dictionary<int, Player>();
16+
/// <summary>
17+
/// 清除所以假人
18+
/// </summary>
19+
public static void Clear()
20+
{
21+
foreach (int Id in List.Keys)
22+
{
23+
AudioPlayerBase audioPlayerBase = AudioPlayerBase.Get(List[Id].ReferenceHub);
24+
if (audioPlayerBase.CurrentPlay != null)
25+
{
26+
audioPlayerBase.Stoptrack(true);
27+
audioPlayerBase.OnDestroy();
28+
}
29+
try
30+
{
31+
NetworkServer.RemovePlayerForConnection(List[Id].Connection, true);
32+
}
33+
catch
34+
{
35+
36+
}
37+
}
38+
Log.Info($"删除了所有的假人");
39+
List.Clear();
40+
}
41+
/// <summary>
42+
/// 删除假人
43+
/// </summary>
44+
/// <param name="Id">假人Id</param>
45+
public static void Remove(int Id)
46+
{
47+
AudioPlayerBase audioPlayerBase = AudioPlayerBase.Get(List[Id].ReferenceHub);
48+
if (audioPlayerBase.CurrentPlay != null)
49+
{
50+
audioPlayerBase.Stoptrack(true);
51+
audioPlayerBase.OnDestroy();
52+
}
53+
try
54+
{
55+
NetworkServer.RemovePlayerForConnection(List[Id].Connection,true);
56+
}
57+
catch
58+
{
59+
60+
}
61+
Log.Info($"删除了所有的假人");
62+
List.Clear();
63+
}
64+
/// <summary>
65+
/// 播放音乐
66+
/// 当没有假人Id不存在时会创建假人
67+
/// </summary>
68+
/// <param name="Id">假人Id</param>
69+
/// <param name="Paths">路径[完整文件路径+扩展名]</param>
70+
/// <returns></returns>
71+
public static AudioPlayerBase PlayAudio(int Id, string Paths)
72+
{
73+
if (!List.ContainsKey(Id))
74+
Add(Id, "Bot");
75+
Log.Info($"播放音乐[{Paths}]");
76+
ReferenceHub component = List[Id].ReferenceHub;
77+
AudioPlayerBase audioPlayerBase = AudioPlayerBase.Get(component);
78+
string str = Paths;
79+
audioPlayerBase.Enqueue(str, -1);
80+
audioPlayerBase.LogDebug = false;
81+
audioPlayerBase.BroadcastChannel = VoiceChatChannel.Intercom;
82+
audioPlayerBase.Volume = 50f;
83+
audioPlayerBase.Loop = false;
84+
audioPlayerBase.Play(0);
85+
return audioPlayerBase;
86+
}
87+
/// <summary>
88+
/// 停止播放音乐
89+
/// </summary>
90+
/// <param name="Id">假人Id</param>
91+
/// <returns></returns>
92+
public static void StopAudio(int Id)
93+
{
94+
AudioPlayerBase audioPlayerBase = AudioPlayerBase.Get(List[Id].ReferenceHub);
95+
if (audioPlayerBase.CurrentPlay != null)
96+
{
97+
audioPlayerBase.Stoptrack(true);
98+
audioPlayerBase.OnDestroy();
99+
}
100+
}
101+
/// <summary>
102+
/// 添加假人
103+
/// </summary>
104+
/// <param name="Id">假人Id</param>
105+
/// <param name="Name">假人名</param>
106+
/// <returns></returns>
107+
public static void Add(int Id, string Name = "Bot")
108+
{
109+
if (List.ContainsKey(Id))
110+
return;
111+
Log.Info($"添加了Id为{Id},名称为{Name}的假人");
112+
GameObject player1 = Object.Instantiate(NetworkManager.singleton.playerPrefab);
113+
NetworkServer.AddPlayerForConnection(new FakeConnection(Id), player1);
114+
ReferenceHub component = player1.GetComponent<ReferenceHub>();
115+
Player player = Player.Get(component);
116+
player.DisplayNickname = Name;
117+
List.Add(Id, player);
118+
}
119+
}
120+
}

MusicDummy/Extensions.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Exiled.API.Features;
2+
using SCPSLAudioApi.AudioCore;
3+
4+
namespace MusicDummy
5+
{
6+
public static class Extensions
7+
{
8+
/// <summary>
9+
/// 向玩家播放音乐
10+
/// </summary>
11+
/// <param name="player"></param>
12+
/// <param name="Id">假人Id</param>
13+
/// <param name="Paths">路径[完整文件路径+扩展名]</param>
14+
/// <returns></returns>
15+
public static AudioPlayerBase PlayAudio(this Player player, int Id, string Paths)
16+
{
17+
if (!Dummy.List.ContainsKey(Id))
18+
Dummy.Add(Id, "Bot");
19+
Log.Info($"向玩家{player.Nickname}播放音乐[{Paths}]");
20+
ReferenceHub component = Dummy.List[Id].ReferenceHub;
21+
AudioPlayerBase audioPlayerBase = AudioPlayerBase.Get(component);
22+
string str = Paths;
23+
audioPlayerBase.Enqueue(str, -1);
24+
audioPlayerBase.LogDebug = false;
25+
audioPlayerBase.BroadcastTo.Add(player.Id);
26+
audioPlayerBase.Volume = 50f;
27+
audioPlayerBase.Loop = false;
28+
audioPlayerBase.Play(0);
29+
return audioPlayerBase;
30+
}
31+
}
32+
}

MusicDummy/FakeConnection.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Mirror;
2+
using System;
3+
4+
namespace MusicDummy
5+
{
6+
public class FakeConnection : NetworkConnectionToClient
7+
{
8+
public FakeConnection(int networkConnectionId) : base(networkConnectionId)
9+
{
10+
11+
}
12+
public override string address => "localhost";
13+
public override void Send(ArraySegment<byte> segment, int channelId = 0)
14+
{
15+
16+
}
17+
public override void Disconnect()
18+
{
19+
}
20+
}
21+
}

MusicDummy/MusicDummy.csproj

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{95B81880-7F1D-46B0-B12D-F1EFF4B320C5}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>MusicDummy</RootNamespace>
11+
<AssemblyName>MusicDummy</AssemblyName>
12+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
<PlatformTarget>x64</PlatformTarget>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="Assembly-CSharp">
36+
<HintPath>..\..\..\..\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Assembly-CSharp.dll</HintPath>
37+
</Reference>
38+
<Reference Include="CommandSystem.Core">
39+
<HintPath>..\..\..\..\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\CommandSystem.Core.dll</HintPath>
40+
</Reference>
41+
<Reference Include="Exiled.API">
42+
<HintPath>C:\Users\Administrator\AppData\Roaming\EXILED\Plugins\dependencies\Exiled.API.dll</HintPath>
43+
</Reference>
44+
<Reference Include="Mirror">
45+
<HintPath>..\..\..\..\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Mirror.dll</HintPath>
46+
</Reference>
47+
<Reference Include="PluginAPI">
48+
<HintPath>..\..\..\..\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\PluginAPI.dll</HintPath>
49+
</Reference>
50+
<Reference Include="SCPSLAudioApi">
51+
<HintPath>C:\Users\Administrator\Desktop\SCPSLAudioApi.dll</HintPath>
52+
</Reference>
53+
<Reference Include="System" />
54+
<Reference Include="System.Core" />
55+
<Reference Include="System.Xml.Linq" />
56+
<Reference Include="System.Data.DataSetExtensions" />
57+
<Reference Include="Microsoft.CSharp" />
58+
<Reference Include="System.Data" />
59+
<Reference Include="System.Net.Http" />
60+
<Reference Include="System.Xml" />
61+
<Reference Include="UnityEngine">
62+
<HintPath>..\..\..\..\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\UnityEngine.dll</HintPath>
63+
</Reference>
64+
<Reference Include="UnityEngine.CoreModule">
65+
<HintPath>..\..\..\..\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
66+
</Reference>
67+
<Reference Include="UnityEngine.PhysicsModule">
68+
<HintPath>..\..\..\..\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
69+
</Reference>
70+
</ItemGroup>
71+
<ItemGroup>
72+
<Compile Include="Dummy.cs" />
73+
<Compile Include="Extensions.cs" />
74+
<Compile Include="FakeConnection.cs" />
75+
<Compile Include="Properties\AssemblyInfo.cs" />
76+
</ItemGroup>
77+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
78+
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// 有关程序集的一般信息由以下
6+
// 控制。更改这些特性值可修改
7+
// 与程序集关联的信息。
8+
[assembly: AssemblyTitle("MusicDummy")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("史蒂夫")]
12+
[assembly: AssemblyProduct("音乐假人")]
13+
[assembly: AssemblyCopyright("Copyright © 史蒂夫 2024")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// 将 ComVisible 设置为 false 会使此程序集中的类型
18+
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19+
//请将此类型的 ComVisible 特性设置为 true。
20+
[assembly: ComVisible(false)]
21+
22+
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23+
[assembly: Guid("95b81880-7f1d-46b0-b12d-f1eff4b320c5")]
24+
25+
// 程序集的版本信息由下列四个值组成:
26+
//
27+
// 主版本
28+
// 次版本
29+
// 生成号
30+
// 修订号
31+
//
32+
[assembly: AssemblyVersion("1.1.4.5")]
33+
[assembly: AssemblyFileVersion("0.0.0.1")]

0 commit comments

Comments
 (0)