Skip to content

Commit 10a1094

Browse files
committed
更新API,更新远程管理员记录
1 parent a65a025 commit 10a1094

File tree

10 files changed

+293
-3
lines changed

10 files changed

+293
-3
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using GameCore;
2+
using LabMorePlugins.Interfaces;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Log = LabApi.Features.Console.Logger;
10+
11+
namespace LabMorePlugins.API
12+
{
13+
public static class AbilityManager
14+
{
15+
public static void RegisterAbilities()
16+
{
17+
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
18+
{
19+
try
20+
{
21+
if (!type.IsInterface && !type.IsAbstract && type.GetInterfaces().Contains(typeof(IAbility)))
22+
{
23+
IAbility ability = Activator.CreateInstance(type) as IAbility;
24+
if (ability != null)
25+
{
26+
AbilityManager._abilityList.Add(ability);
27+
Log.Debug("Register the " + ability.Name + " ability.");
28+
ability.Register();
29+
}
30+
}
31+
}
32+
catch (Exception ex)
33+
{
34+
Log.Error("Error in RegisterAbilities:" + ex.Message);
35+
}
36+
}
37+
}
38+
39+
public static void UnregisterAbilities()
40+
{
41+
foreach (IAbility ability in AbilityManager._abilityList)
42+
{
43+
try
44+
{
45+
ability.Unregister();
46+
}
47+
catch (Exception ex)
48+
{
49+
Log.Error("Error in UnregisterAbilities:" + ex.Message);
50+
}
51+
}
52+
}
53+
54+
public static List<IAbility> GetAbilities
55+
{
56+
get
57+
{
58+
return AbilityManager._abilityList;
59+
}
60+
}
61+
62+
private static List<IAbility> _abilityList = new List<IAbility>();
63+
}
64+
}

LabMorePlugins/API/Events.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using HintServiceMeow.Core.Extension;
33
using HintServiceMeow.Core.Models.Hints;
44
using HintServiceMeow.UI.Extension;
5+
using InventorySystem.Items.Firearms;
6+
using InventorySystem.Items.Firearms.Modules;
57
using InventorySystem.Items.Keycards;
68
using InventorySystem.Items.MicroHID;
79
using InventorySystem.Items.MicroHID.Modules;
@@ -12,15 +14,18 @@
1214
using LabApi.Events.CustomHandlers;
1315
using LabApi.Features.Wrappers;
1416
using LabMorePlugins.Enums;
17+
using LabMorePlugins.Interfaces;
1518
using LabMorePlugins.Patchs;
1619
using MapGeneration.Distributors;
1720
using MEC;
1821
using PlayerRoles;
1922
using PlayerRoles.PlayableScps.Scp079;
2023
using PlayerRoles.Spectating;
2124
using PlayerRoles.Subroutines;
25+
using RemoteAdmin;
2226
using System;
2327
using System.Collections.Generic;
28+
using System.IO;
2429
using System.Linq;
2530
using System.Text;
2631
using System.Text.RegularExpressions;
@@ -336,6 +341,16 @@ public override void OnPlayerHurting(PlayerHurtingEventArgs ev)
336341
}
337342

338343
}
344+
public override void OnServerCommandExecuted(CommandExecutedEventArgs ev)
345+
{
346+
if (ev.CommandType == LabApi.Features.Enums.CommandType.RemoteAdmin)
347+
{
348+
Player player = Player.Get(ev.Sender.SenderId);
349+
var Time = DateTime.Now.ToString();
350+
string AdminLog = $"[{Time}|{ev.Sender.SenderId}|{ev.Sender.Nickname}|{player.IpAddress}|{ev.CommandName}]";
351+
File.AppendAllText(Plugin.AdminLogs, AdminLog);
352+
}
353+
}
339354
public override void OnPlayerDeath(PlayerDeathEventArgs ev)
340355
{
341356
if (ev.Player != null&&ev.Attacker!=null)
@@ -426,6 +441,18 @@ public override void OnServerWaveRespawned(WaveRespawnedEventArgs ev)
426441

427442
}
428443
}
444+
public override void OnPlayerReloadingWeapon(PlayerReloadingWeaponEventArgs ev)
445+
{
446+
if(ev.FirearmItem.Base.TryGetSubcomponent(out Firearm firearm))
447+
{
448+
var Max = firearm.GetTotalMaxAmmo();
449+
var Total = firearm.GetTotalStoredAmmo();
450+
if (Max > Total)
451+
{
452+
ev.Player.AddAmmo(ev.FirearmItem.Type, 55);
453+
}
454+
}
455+
}
429456
public override void OnPlayerUsedItem(PlayerUsedItemEventArgs ev)
430457
{
431458
if (ev.Player == null)
@@ -449,11 +476,12 @@ public override void OnPlayerInteractingDoor(PlayerInteractingDoorEventArgs ev)
449476
}
450477
}
451478
}
452-
if (SRoleSystem.IsRole(ev.Player.PlayerId, RoleName.SCP181) && Random.Next(1, 5) >= 2 && !ev.Door.IsLocked && !ev.Door.IsOpened)
479+
if (SRoleSystem.IsRole(ev.Player.PlayerId, RoleName.SCP181) && Random.Next(1, 5) >= 2 && !ev.Door.IsLocked)
453480
{
454481
ev.Door.IsOpened = true;
455482
ev.Player.GetPlayerUi().CommonHint.ShowOtherHint("你打开了这道权限门", 6);
456483
}
457484
}
485+
458486
}
459487
}

LabMorePlugins/API/SSSS.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using LabApi.Features.Wrappers;
1+
using Interactables.Interobjects.DoorUtils;
2+
using LabApi.Features.Wrappers;
23
using PlayerRoles;
34
using PlayerRoles.FirstPersonControl;
45
using PlayerRoles.FirstPersonControl.Spawnpoints;
@@ -110,6 +111,5 @@ public static void SetExp(this Player player, int 数值)
110111
{
111112
player.GetPlayerData().Exp = 数值;
112113
}
113-
114114
}
115115
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using LabApi.Features.Wrappers;
2+
using LabMorePlugins.Interfaces;
3+
using MEC;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using UnityEngine;
10+
11+
namespace LabMorePlugins.Ability
12+
{
13+
public class S106Black : Interfaces.Ability
14+
{
15+
public override string Name => "老头回口袋";
16+
17+
public override string Description => "老头回口袋";
18+
19+
public override int KeyId => 106;
20+
21+
public override KeyCode KeyCode => KeyCode.Y;
22+
23+
public override float Cooldown => 90;
24+
25+
public override void Register()
26+
{
27+
throw new NotImplementedException();
28+
}
29+
30+
public override void Unregister()
31+
{
32+
throw new NotImplementedException();
33+
}
34+
35+
protected override void ActivateAbility(Player player)
36+
{
37+
if (player.Role == PlayerRoles.RoleTypeId.Scp106)
38+
{
39+
Timing.RunCoroutine(Check106(player));
40+
player.Position = Room.Get(MapGeneration.RoomName.Pocket).FirstOrDefault().Position + Vector3.up;
41+
for (int i = 20; i >= 0; i--)
42+
{
43+
player.SendHint($"回血中,还剩{i}", 20);
44+
}
45+
Timing.CallDelayed(20f, () =>
46+
{
47+
player.Position = Room.Get(MapGeneration.FacilityZone.HeavyContainment).FirstOrDefault().Position + Vector3.up;
48+
49+
});
50+
}
51+
}
52+
public IEnumerator<float> Check106(Player player)
53+
{
54+
while(player.Role == PlayerRoles.RoleTypeId.Scp106)
55+
{
56+
if (player.Room.Name == MapGeneration.RoomName.Pocket)
57+
{
58+
player.Heal(25);
59+
}
60+
yield return Timing.WaitForSeconds(1f);
61+
}
62+
}
63+
}
64+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using LabApi.Features.Wrappers;
2+
using LabMorePlugins.MonoBehaviours;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using UnityEngine;
9+
10+
namespace LabMorePlugins.Interfaces
11+
{
12+
public abstract class Ability : IAbility
13+
{
14+
public abstract string Name { get; }
15+
public abstract string Description { get; }
16+
public abstract int KeyId { get; }
17+
public abstract KeyCode KeyCode { get; }
18+
public abstract float Cooldown { get; }
19+
20+
public abstract void Register();
21+
public abstract void Unregister();
22+
public void OnKeyPressed(Player player)
23+
{
24+
if (player == null)
25+
{
26+
return;
27+
}
28+
CooldownController component = player.GameObject.GetComponent<CooldownController>();
29+
if (!component.IsAbilityAvailable(this.Name))
30+
{
31+
return;
32+
}
33+
component.SetCooldownForAbility(this.Name, this.Cooldown);
34+
}
35+
protected abstract void ActivateAbility(Player player);
36+
}
37+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using UnityEngine;
7+
8+
namespace LabMorePlugins.Interfaces
9+
{
10+
public interface IAbility
11+
{
12+
string Name { get; }
13+
14+
string Description { get; }
15+
16+
int KeyId { get; }
17+
18+
KeyCode KeyCode { get; }
19+
20+
float Cooldown { get; }
21+
22+
void Register();
23+
24+
void Unregister();
25+
}
26+
}

LabMorePlugins/LabMorePlugins.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
</Reference>
103103
</ItemGroup>
104104
<ItemGroup>
105+
<Compile Include="Ability\S106Black.cs" />
106+
<Compile Include="API\AbilityManager.cs" />
105107
<Compile Include="API\Events.cs" />
106108
<Compile Include="API\SAPI.cs" />
107109
<Compile Include="API\SRoleSystem.cs" />
@@ -115,6 +117,9 @@
115117
<Compile Include="Enums\RoleName.cs" />
116118
<Compile Include="Enums\SCP914Enum.cs" />
117119
<Compile Include="Enums\ZoneNum.cs" />
120+
<Compile Include="Interfaces\Ability.cs" />
121+
<Compile Include="Interfaces\IAbility.cs" />
122+
<Compile Include="MonoBehaviours\CooldownController.cs" />
118123
<Compile Include="Patchs\SCPChannelFixSecond.cs" />
119124
<Compile Include="PlayerData.cs" />
120125
<Compile Include="Plugin.cs" />
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using GameCore;
2+
using LabMorePlugins.API;
3+
using LabMorePlugins.Interfaces;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using UnityEngine;
10+
using Log = LabApi.Features.Console.Logger;
11+
12+
namespace LabMorePlugins.MonoBehaviours
13+
{
14+
public class CooldownController : MonoBehaviour
15+
{
16+
public void Awake()
17+
{
18+
this._abilityCooldown = AbilityManager.GetAbilities.ToDictionary((IAbility a) => a.Name, (IAbility _) => 0f);
19+
base.InvokeRepeating("CheckCooldown", 0f, 1f);
20+
LabApi.Features.Console.Logger.Debug("[CooldownController] Invoke the cooldown cycle");
21+
}
22+
23+
private void CheckCooldown()
24+
{
25+
foreach (string text in this._abilityCooldown.Keys.ToList<string>())
26+
{
27+
if (this._abilityCooldown[text] > 0f)
28+
{
29+
Dictionary<string, float> abilityCooldown = this._abilityCooldown;
30+
string key = text;
31+
float num = abilityCooldown[key];
32+
abilityCooldown[key] = num - 1f;
33+
}
34+
else
35+
{
36+
this._abilityCooldown[text] = 0f;
37+
}
38+
}
39+
}
40+
41+
private void OnDestroy()
42+
{
43+
base.CancelInvoke("CheckCooldown");
44+
Log.Debug("[CooldownController] Cancel the cooldown cycle");
45+
}
46+
47+
public bool IsAbilityAvailable(string ability)
48+
{
49+
return this._abilityCooldown[ability] <= 0f;
50+
}
51+
52+
public void SetCooldownForAbility(string ability, float time)
53+
{
54+
this._abilityCooldown[ability] = time;
55+
}
56+
57+
private Dictionary<string, float> _abilityCooldown;
58+
}
59+
}

LabMorePlugins/Patchs/SCPChannelFixSecond.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using HarmonyLib;
22
using LabApi.Features.Wrappers;
3+
using LabMorePlugins.Interfaces;
34
using Mirror;
45
using PlayerRoles;
56
using PlayerRoles.Voice;

LabMorePlugins/Plugin.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class Plugin : Plugin<Class1>
3535
public override Version RequiredApiVersion => new Version(LabApi.Features.LabApiProperties.CompiledVersion);
3636
public static Dictionary<string, PlayerData> playerData = new Dictionary<string, PlayerData>();
3737
private string dataFilePath;
38+
public static string AdminLogs;
3839
public static readonly object KillCountsLock = new object();
3940
public static Dictionary<Player, int> killCounts = new Dictionary<Player, int>();
4041
public API.Events Events { get; set; } = new Events();
@@ -52,6 +53,11 @@ public override void Enable()
5253
{
5354
File.Create(dataFilePath);
5455
}
56+
AdminLogs = Path.Combine(LabApi.Loader.Features.Paths.PathManager.LabApi.ToString(), "AdminLogs", Server.Port.ToString(), "Log.txt");
57+
if (!File.Exists(AdminLogs))
58+
{
59+
File.Create (AdminLogs);
60+
}
5561
LoadPlayerData();
5662
var harmony = new Harmony("hui.sl.moreplugin");
5763
harmony.PatchAll();

0 commit comments

Comments
 (0)