Skip to content

Commit ab4a697

Browse files
authored
event support
1 parent cdfb5ae commit ab4a697

File tree

9 files changed

+344
-26
lines changed

9 files changed

+344
-26
lines changed

SCP-600V/API/Role.cs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using Exiled.CustomRoles.API.Features;
8-
8+
using SCP_600V.Events;
99

1010
namespace SCP_600V.API.Role
1111
{
@@ -46,36 +46,28 @@ public static bool IsScp600(Player player)
4646
/// Gives the role of SCP-600V to the player
4747
/// </summary>
4848
/// <param name="player">The player who will receive the role of SCP-600V</param>
49-
public static void Spawn(Player player)
50-
{
51-
if (player == null && player.IsDead)
52-
{
53-
return;
54-
}
55-
else
56-
{
57-
CustomRole.Get(typeof(Scp600CotumRoleBase)).AddRole(player);
58-
}
59-
}
60-
/// <summary>
61-
/// Gives the role of SCP-600V to the player
62-
/// </summary>
63-
/// <param name="player">The player who will receive the role of SCP-600V</param>
6449
/// <param name="MaxHealt">Assigning a custom MaxHealt parameter to a player</param>
65-
public static void Spawn(Player player, int MaxHealt = 400)
50+
public static void Spawn(Player player)
6651
{
6752
if (player == null && player.IsDead)
6853
{
6954
return;
7055
}
7156
else
7257
{
73-
CustomRole.Get(typeof(Scp600CotumRoleBase)).AddRole(player);
74-
Timing.CallDelayed(2f, () =>
58+
Events.EventArg.SpawningEventArgs e = new Events.EventArg.SpawningEventArgs(player, true);
59+
Log.Debug($"After Invoke event Player: {e.Player.Nickname} IsAllow: {e.IsAllow}");
60+
new Scp600Handler().InvokeSpawning(e);
61+
Log.Debug($"Before Invoke event Player: {e.Player.Nickname} IsAllow: {e.IsAllow}");
62+
63+
if (e.IsAllow)
64+
{
65+
CustomRole.Get(typeof(Scp600Base)).AddRole(e.Player);
66+
}
67+
if (e.IsAllow == false)
7568
{
76-
player.MaxHealth = MaxHealt;
77-
player.Health = MaxHealt;
78-
});
69+
Log.Debug("Player do not get role called event set IsSpawning to false");
70+
}
7971
}
8072
}
8173
/// <summary>

SCP-600V/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ internal class Config : IConfig
4040
/// SCP-600V Role Configurations
4141
/// </summary>
4242
[Description("SCP-600V Role Configurations")]
43-
public Scp600CotumRoleBase Scp600ConfigRole { get; set; } = new Scp600CotumRoleBase();
43+
public Scp600Base Scp600ConfigRole { get; set; } = new Scp600Base();
4444
}
4545
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Exiled.API.Features;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using UnityEngine;
8+
9+
namespace SCP_600V.Events.EventArg
10+
{
11+
public class SpawnedEventArgs: EventArgs
12+
{
13+
/// <summary>
14+
/// player who is scp 600
15+
/// </summary>
16+
public Player Player { get; private set; }
17+
/// <summary>
18+
/// Position where scp 600 will appear
19+
/// </summary>
20+
public Vector3 Position { get; private set; }
21+
/// <summary>
22+
/// Maximum Health
23+
/// </summary>
24+
public int MaxHealt { get; private set; } = 400;
25+
/// <summary>
26+
/// Health
27+
/// </summary>
28+
public float Healt { get; private set; } = 400f;
29+
30+
public SpawnedEventArgs(Player player, Vector3 position, int maxHealt, float healt)
31+
{
32+
Player = player;
33+
Position = position;
34+
MaxHealt = maxHealt;
35+
Healt = healt;
36+
}
37+
}
38+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Exiled.API.Features;
2+
using Exiled.API.Interfaces;
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 SCP_600V.Events.EventArg
11+
{
12+
public class SpawningEventArgs: EventArgs
13+
{
14+
/// <summary>
15+
/// player who is scp 600
16+
/// </summary>
17+
public Player Player { get; set; }
18+
/// <summary>
19+
/// Will the player appear at all? (default true)
20+
/// </summary>
21+
public bool IsAllow { get; set; } = true;
22+
23+
public SpawningEventArgs(Player player, bool IsAllow)
24+
{
25+
Player = player;
26+
this.IsAllow = IsAllow;
27+
}
28+
}
29+
}

SCP-600V/Events/Scp600Handler.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Exiled.API.Features;
2+
using SCP_600V.Events.EventArg;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace SCP_600V.Events
10+
{
11+
public class Scp600Handler
12+
{
13+
public delegate void Spawning(SpawningEventArgs e);
14+
15+
public delegate void Spawned(SpawnedEventArgs e);
16+
17+
public static event Spawning OnSpawning;
18+
19+
public static event Spawned OnSpawned;
20+
21+
internal void InvokeSpawning(SpawningEventArgs e)
22+
{
23+
if (OnSpawning != null)
24+
{
25+
OnSpawning.Invoke(e);
26+
}
27+
else
28+
{
29+
Log.Debug("No have subscriders to event OnSpawning");
30+
}
31+
}
32+
internal void InvokeSpawned(SpawnedEventArgs e)
33+
{
34+
if (OnSpawned != null)
35+
{
36+
OnSpawned.Invoke(e);
37+
}
38+
else
39+
{
40+
Log.Debug("No have subscriders to event OnSpawned");
41+
}
42+
}
43+
}
44+
}

SCP-600V/Extension/Scp600Base.cs

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
using Exiled.API.Enums;
2+
using Exiled.API.Features;
3+
using Exiled.CustomRoles.API.Features;
4+
using Exiled.API.Features.Attributes;
5+
using System.Collections.Generic;
6+
using PlayerRoles;
7+
using UnityEngine;
8+
using MEC;
9+
using Exiled.API.Extensions;
10+
using Exiled.Events.EventArgs.Player;
11+
using EvHandler = Exiled.Events.Handlers;
12+
using YamlDotNet.Serialization;
13+
using System.ComponentModel;
14+
using Exiled.API.Features.Spawn;
15+
using SCP_600V.Events;
16+
17+
namespace SCP_600V.Extension
18+
{
19+
/// <summary>
20+
/// the main component of the role acting as its basis
21+
/// </summary>
22+
[CustomRole(RoleTypeId.Tutorial)]
23+
internal class Scp600Base : CustomRole
24+
{
25+
public override string CustomInfo { get; set; } = "SCP-600V";
26+
27+
public override string Name { get; set; } = "SCP-600V";
28+
29+
public override int MaxHealth { get; set; } = 400;
30+
31+
[Description("whether it will be shown next to the player's name that he is SCP-600V")]
32+
public bool VisibleScpName { get; set; } = true;
33+
34+
[YamlIgnore]
35+
public override RoleTypeId Role { get; set; } = RoleTypeId.Tutorial;
36+
37+
[Description("the initial appearance of the object during behavior (preferably left as it will follow among class D)")]
38+
public RoleTypeId StartAppearance { get; set; } = RoleTypeId.ClassD;
39+
40+
public override string Description { get; set; } = "<color=\"purple\">Help other scp complete task</color>";
41+
42+
public override uint Id { get; set; } = 96;
43+
44+
public override List<string> Inventory { get; set; } = new List<string>() { ItemType.KeycardScientist.ToString()};
45+
46+
public override string ConsoleMessage { get; set; } = "<color=\"green\">Your are spawned as</color> <color=\"red\">SCP-600V</color>";
47+
[YamlIgnore]
48+
public RoleTypeId VisibledRole { get; set; }
49+
[YamlIgnore]
50+
public override bool KeepPositionOnSpawn { get; set; }
51+
[YamlIgnore]
52+
public override bool KeepRoleOnDeath { get; set; } = false;
53+
[YamlIgnore]
54+
public override bool KeepRoleOnChangingRole { get; set; } = false;
55+
[YamlIgnore]
56+
public override float SpawnChance { get; set; }
57+
[YamlIgnore]
58+
public override SpawnProperties SpawnProperties { get; set; } = new SpawnProperties();
59+
[YamlIgnore]
60+
public override List<CustomAbility> CustomAbilities { get; set; } = new List<CustomAbility>();
61+
[Description("will allow you to change the size of scp but personally I would not change")]
62+
public override Vector3 Scale { get; set; } = new Vector3(1, 1, 1);
63+
64+
public override Dictionary<RoleTypeId, float> CustomRoleFFMultiplier { get; set; } = new Dictionary<RoleTypeId, float>()
65+
{
66+
{ RoleTypeId.Scp049, 0 },
67+
{ RoleTypeId.Scp173, 0 },
68+
{ RoleTypeId.Scp096, 0 },
69+
{ RoleTypeId.Scp939, 0 },
70+
{ RoleTypeId.Scp0492, 0 },
71+
{ RoleTypeId.Scp106, 0 }
72+
};
73+
public override Dictionary<AmmoType, ushort> Ammo { get; set; } = new Dictionary<AmmoType, ushort>()
74+
{
75+
{ AmmoType.Nato9, 30 },
76+
{ AmmoType.Ammo44Cal, 0 },
77+
{ AmmoType.Nato556, 0 },
78+
{ AmmoType.Nato762, 0 },
79+
{ AmmoType.Ammo12Gauge, 0}
80+
};
81+
public List<ItemType> DontUserItems { get; private set; } = new List<ItemType>()
82+
{
83+
ItemType.MicroHID
84+
};
85+
86+
public override void AddRole(Player player)
87+
{
88+
if (this.Role != RoleTypeId.None)
89+
{
90+
Vector3 pos = player.Position;
91+
player.Role.Set(this.Role, RoleSpawnFlags.None);
92+
Timing.CallDelayed(1f, () =>
93+
{
94+
player.Position = pos;
95+
player.ClearInventory();
96+
foreach (string PlyItem in this.Inventory)
97+
{
98+
this.TryAddItem(player, PlyItem);
99+
}
100+
foreach (AmmoType key in this.Ammo.Keys)
101+
{
102+
player.SetAmmo(key, this.Ammo[key]);
103+
}
104+
player.Health = (float)this.MaxHealth;
105+
player.MaxHealth = (float)this.MaxHealth;
106+
if (!player.RemoteAdminAccess | this.VisibleScpName)
107+
{
108+
player.RankName = "SCP-600V";
109+
player.RankColor = Sai.Instance.Config.BadgeColor;
110+
}
111+
this.ShowMessage(player);
112+
this.TrackedPlayers.Add(player);
113+
this.RoleAdded(player);
114+
player.UniqueRole = this.Name;
115+
player.TryAddCustomRoleFriendlyFire(this.Name, this.CustomRoleFFMultiplier);
116+
player.Scale = this.Scale;
117+
if (this.VisibleScpName)
118+
{
119+
player.CustomInfo = $"{player.Nickname}\n{this.CustomInfo}";
120+
player.InfoArea &= ~PlayerInfoArea.Role;
121+
}
122+
if (Sai.Instance.Config.CanBleading)
123+
{
124+
Timing.RunCoroutine(this.Hurting(player), $"{player.Id}-hurt");
125+
}
126+
try
127+
{
128+
player.SessionVariables.Add("IsSCP600", null);
129+
player.SessionVariables.Add("IsScp", null);
130+
}
131+
catch
132+
{
133+
134+
}
135+
});
136+
Events.EventArg.SpawnedEventArgs e = new Events.EventArg.SpawnedEventArgs(player, pos, this.MaxHealth, (float)this.MaxHealth);
137+
new Scp600Handler().InvokeSpawned(e);
138+
}
139+
}
140+
protected override void RoleAdded(Player player)
141+
{
142+
Timing.CallDelayed(1f, () =>
143+
{
144+
player.ChangeAppearance(this.StartAppearance, false, 0);
145+
this.VisibledRole = RoleTypeId.ClassD;
146+
});
147+
base.RoleAdded(player);
148+
}
149+
protected override void RoleRemoved(Player player)
150+
{
151+
Log.Debug($"SCP-600V dead and role romoved to player: {player}");
152+
try
153+
{
154+
player.SessionVariables.Remove("IsSCP600");
155+
player.SessionVariables.Remove("IsScp");
156+
Timing.KillCoroutines($"{player.Id}-hurt");
157+
if (!player.RemoteAdminAccess)
158+
{
159+
player.RankName = string.Empty;
160+
player.RankColor = string.Empty;
161+
}
162+
}
163+
catch
164+
{
165+
166+
}
167+
base.RoleRemoved(player);
168+
}
169+
protected override void SubscribeEvents()
170+
{
171+
EvHandler.Player.Died += this.OnDeath;
172+
EvHandler.Player.PickingUpItem += this.PickUpItems;
173+
base.SubscribeEvents();
174+
}
175+
protected override void UnsubscribeEvents()
176+
{
177+
EvHandler.Player.Died -= this.OnDeath;
178+
EvHandler.Player.PickingUpItem -= this.PickUpItems;
179+
base.UnsubscribeEvents();
180+
}
181+
public void OnDeath(DiedEventArgs e)
182+
{
183+
if (Check(e.Attacker) & e.Attacker != null & e.Player != null & e.Attacker != e.Player)
184+
{
185+
Debug.Log("Attacker is SCP600");
186+
if (e.TargetOldRole != this.VisibledRole & e.TargetOldRole != RoleTypeId.None & e.TargetOldRole != RoleTypeId.Spectator)
187+
{
188+
this.VisibledRole = e.TargetOldRole;
189+
e.Attacker.ChangeAppearance(this.VisibledRole, false, 0);
190+
}
191+
}
192+
}
193+
public void PickUpItems(PickingUpItemEventArgs e)
194+
{
195+
if (e.Player != null & Check(e.Player) & this.DontUserItems.Contains(e.Pickup.Type))
196+
{
197+
e.IsAllowed = false;
198+
}
199+
}
200+
public IEnumerator<float> Hurting(Player player)
201+
{
202+
for (; ; )
203+
{
204+
yield return Timing.WaitForSeconds(5);
205+
player.Hurt(5f, DamageType.Bleeding);
206+
}
207+
}
208+
}
209+
}

SCP-600V/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
// Можно задать все значения или принять номера сборки и редакции по умолчанию
3434
// используя "*", как показано ниже:
3535
// [assembly: AssemblyVersion("1.0.*")]
36-
[assembly: AssemblyVersion("2.3.1.0")]
37-
[assembly: AssemblyFileVersion("2.3.1.0")]
36+
[assembly: AssemblyVersion("2.3.3.0")]
37+
[assembly: AssemblyFileVersion("2.3.3.0")]
3838
[assembly: NeutralResourcesLanguage("ru-RU")]

0 commit comments

Comments
 (0)