Skip to content

Commit

Permalink
Possible bugfix of issue that broke plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Maartii committed Dec 17, 2020
1 parent d31837e commit 7871b48
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 30 deletions.
63 changes: 51 additions & 12 deletions Jester/GameEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GameEventListener : IEventListener

struct JesterGame
{
public IClientPlayer Jester;
public int JesterClientId;
public bool JesterOn;
public bool Jesterwin;
public bool GameEnded;
Expand Down Expand Up @@ -109,12 +109,12 @@ private async Task AssignJester(IPlayerSetStartCounterEvent e)
int r = rnd.Next(gameplayers.Count);

JesterGame jgame = JesterGames[e.Game.Code];
jgame.Jester = gameplayers[r];
jgame.JesterClientId = gameplayers[r].Client.Id;
jgame.Jestername = gameplayers[r].Character.PlayerInfo.PlayerName;
JesterGames[e.Game.Code] = jgame;

await ServerSendChatToPlayerAsync($"You're the JESTER! (unless you'll be an imposter)", gameplayers[r].Character).ConfigureAwait(false);
_logger.LogInformation($"- {gameplayers[r].Character.PlayerInfo.PlayerName} is probably the jester.");
_logger.LogInformation($"- {JesterGames[e.Game.Code].Jestername} is probably the jester.");
}

private async Task MakePlayerLookAtChat(IClientPlayer player)
Expand All @@ -126,6 +126,39 @@ private async Task MakePlayerLookAtChat(IClientPlayer player)
await player.Character.SetNameAsync(playername).ConfigureAwait(false);
}

[EventListener]
public void OnGamePlayerJoined(IGamePlayerJoinedEvent e)
{
if (JesterGames[e.Game.Code].CountingDown)
{
_logger.LogInformation($"Assigning Jester interrupted. {JesterGames[e.Game.Code].Jestername} is NOT the jester.");
Task.Run(async () => await SorryNotJester(e.Game.GetClientPlayer(JesterGames[e.Game.Code].JesterClientId)).ConfigureAwait(false));

JesterGame jgame = JesterGames[e.Game.Code];
jgame.CountingDown = false;
JesterGames[e.Game.Code] = jgame;
}
}

[EventListener]
public void OnGamePlayerLeft(IGamePlayerLeftEvent e)
{
if (JesterGames[e.Game.Code].CountingDown)
{
_logger.LogInformation($"Assigning Jester interrupted. {JesterGames[e.Game.Code].Jestername} is NOT the jester.");
Task.Run(async () => await SorryNotJester(e.Game.GetClientPlayer(JesterGames[e.Game.Code].JesterClientId)).ConfigureAwait(false));

JesterGame jgame = JesterGames[e.Game.Code];
jgame.CountingDown = false;
JesterGames[e.Game.Code] = jgame;
}
}

private async Task SorryNotJester(IClientPlayer player)
{
await ServerSendChatToPlayerAsync($"Startup interrupted. You're NOT the Jester.", player.Character).ConfigureAwait(false);
}

[EventListener]
public void OnGameStarted(IGameStartedEvent e)
{
Expand Down Expand Up @@ -163,15 +196,15 @@ public void OnGameStarted(IGameStartedEvent e)

private async Task InformJester(IGameStartedEvent e)
{
if (JesterGames[e.Game.Code].Jester.Character.PlayerInfo.IsImpostor)
if (e.Game.GetClientPlayer(JesterGames[e.Game.Code].JesterClientId).Character.PlayerInfo.IsImpostor)
{
_logger.LogInformation($"- {JesterGames[e.Game.Code].Jester.Character.PlayerInfo.PlayerName} isn't jester but impostor.");
await ServerSendChatToPlayerAsync($"You happen to be IMPOSTER! No Jester this game.", JesterGames[e.Game.Code].Jester.Character).ConfigureAwait(false);
_logger.LogInformation($"- {e.Game.GetClientPlayer(JesterGames[e.Game.Code].JesterClientId).Character.PlayerInfo.PlayerName} isn't jester but impostor.");
await ServerSendChatToPlayerAsync($"You happen to be IMPOSTER! No Jester this game.", e.Game.GetClientPlayer(JesterGames[e.Game.Code].JesterClientId).Character).ConfigureAwait(false);
}
else
{
_logger.LogInformation($"- {JesterGames[e.Game.Code].Jester.Character.PlayerInfo.PlayerName} is indeed jester.");
await ServerSendChatToPlayerAsync($"You're indeed the JESTER!", JesterGames[e.Game.Code].Jester.Character).ConfigureAwait(false);
_logger.LogInformation($"- {e.Game.GetClientPlayer(JesterGames[e.Game.Code].JesterClientId).Character.PlayerInfo.PlayerName} is indeed jester.");
await ServerSendChatToPlayerAsync($"You're indeed the JESTER!", e.Game.GetClientPlayer(JesterGames[e.Game.Code].JesterClientId).Character).ConfigureAwait(false);

JesterGame jgame = JesterGames[e.Game.Code];
jgame.JesterInGame = true;
Expand All @@ -187,7 +220,7 @@ private async Task OffWithYourHat(IClientPlayer player)
[EventListener]
public void OnPlayerExiled(IPlayerExileEvent e)
{
if (JesterGames[e.Game.Code].JesterInGame && e.PlayerControl == JesterGames[e.Game.Code].Jester.Character)
if (JesterGames[e.Game.Code].JesterInGame && e.PlayerControl == e.Game.GetClientPlayer(JesterGames[e.Game.Code].JesterClientId).Character)
{
JesterGame jgame = JesterGames[e.Game.Code];
jgame.Jesterwin = true;
Expand All @@ -200,10 +233,10 @@ public void OnPlayerExiled(IPlayerExileEvent e)

private async Task TurnTheTables(IPlayerExileEvent e)
{
await JesterGames[e.Game.Code].Jester.Character.SetHatAsync(HatType.ElfHat).ConfigureAwait(false);
await e.Game.GetClientPlayer(JesterGames[e.Game.Code].JesterClientId).Character.SetHatAsync(HatType.ElfHat).ConfigureAwait(false);
foreach (var player in e.Game.Players)
{
if (player != JesterGames[e.Game.Code].Jester)
if (player.Client.Id != JesterGames[e.Game.Code].JesterClientId)
{
await player.Character.SetHatAsync(HatType.DumSticker).ConfigureAwait(false);
}
Expand All @@ -213,7 +246,7 @@ private async Task TurnTheTables(IPlayerExileEvent e)
if (!player.Character.PlayerInfo.IsDead && player.Character.PlayerInfo.IsImpostor)
{
_logger.LogInformation($"- {player.Character.PlayerInfo.PlayerName} is murdered by plugin.");
await player.Character.SetMurderedAsync().ConfigureAwait(false);
await player.Character.SetMurderedByAsync(player);
}
}

Expand Down Expand Up @@ -252,6 +285,12 @@ private async Task JesterAnnouncement(IPlayerSpawnedEvent e)
}
}

[EventListener]
public void OnGameDestroyed(IGameDestroyedEvent e)
{
JesterGames.Remove(e.Game.Code);
}

[EventListener]
public void OnPlayerChat(IPlayerChatEvent e)
{
Expand Down
2 changes: 1 addition & 1 deletion Jester/Jester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Impostor.Api" Version="1.2.2-ci.116" />
<PackageReference Include="Impostor.Api" Version="1.2.2-ci.121" />
</ItemGroup>

</Project>
12 changes: 6 additions & 6 deletions Jester/bin/Debug/netstandard2.1/Jester.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
".NETStandard,Version=v2.1/": {
"Jester/1.0.0": {
"dependencies": {
"Impostor.Api": "1.2.2-ci.116"
"Impostor.Api": "1.2.2-ci.121"
},
"runtime": {
"Jester.dll": {}
}
},
"Impostor.Api/1.2.2-ci.116": {
"Impostor.Api/1.2.2-ci.121": {
"dependencies": {
"Microsoft.Bcl.HashCode": "1.1.0",
"Microsoft.Extensions.Hosting.Abstractions": "5.0.0",
Expand Down Expand Up @@ -145,12 +145,12 @@
"serviceable": false,
"sha512": ""
},
"Impostor.Api/1.2.2-ci.116": {
"Impostor.Api/1.2.2-ci.121": {
"type": "package",
"serviceable": true,
"sha512": "sha512-L45pnutYrECEfHUfMytw/4DA8xXgUx59H5MqUPQ/fSKvvk8TUITN+julfsit5aQmlJZtq3BH4EWZGRj7f0JzcA==",
"path": "impostor.api/1.2.2-ci.116",
"hashPath": "impostor.api.1.2.2-ci.116.nupkg.sha512"
"sha512": "sha512-umYs6icWxudu5MQEnb4XpSEXKSoznTje/p2YBRGfHAH+eq0KDKTlV9C1eRVyiDJN4q1Rip9RNubYe1W+qvjkeg==",
"path": "impostor.api/1.2.2-ci.121",
"hashPath": "impostor.api.1.2.2-ci.121.nupkg.sha512"
},
"Microsoft.Bcl.HashCode/1.1.0": {
"type": "package",
Expand Down
Binary file modified Jester/bin/Debug/netstandard2.1/Jester.dll
Binary file not shown.
Binary file modified Jester/bin/Debug/netstandard2.1/Jester.pdb
Binary file not shown.
Binary file modified Jester/obj/Debug/netstandard2.1/Jester.assets.cache
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ee585fb3ff86f896801a7112e22852b563f30738
508a8eec638f52d7ae1c0101118c094803b4e1bb
Binary file not shown.
Binary file modified Jester/obj/Debug/netstandard2.1/Jester.dll
Binary file not shown.
Binary file modified Jester/obj/Debug/netstandard2.1/Jester.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion Jester/obj/Jester.csproj.nuget.dgspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"Impostor.Api": {
"target": "Package",
"version": "[1.2.2-ci.116, )"
"version": "[1.2.2-ci.121, )"
}
},
"imports": [
Expand Down
14 changes: 7 additions & 7 deletions Jester/obj/project.assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": 3,
"targets": {
".NETStandard,Version=v2.1": {
"Impostor.Api/1.2.2-ci.116": {
"Impostor.Api/1.2.2-ci.121": {
"type": "package",
"dependencies": {
"Microsoft.Bcl.HashCode": "1.1.0",
Expand Down Expand Up @@ -139,14 +139,14 @@
}
},
"libraries": {
"Impostor.Api/1.2.2-ci.116": {
"sha512": "L45pnutYrECEfHUfMytw/4DA8xXgUx59H5MqUPQ/fSKvvk8TUITN+julfsit5aQmlJZtq3BH4EWZGRj7f0JzcA==",
"Impostor.Api/1.2.2-ci.121": {
"sha512": "umYs6icWxudu5MQEnb4XpSEXKSoznTje/p2YBRGfHAH+eq0KDKTlV9C1eRVyiDJN4q1Rip9RNubYe1W+qvjkeg==",
"type": "package",
"path": "impostor.api/1.2.2-ci.116",
"path": "impostor.api/1.2.2-ci.121",
"files": [
".nupkg.metadata",
".signature.p7s",
"impostor.api.1.2.2-ci.116.nupkg.sha512",
"impostor.api.1.2.2-ci.121.nupkg.sha512",
"impostor.api.nuspec",
"lib/netstandard2.0/Impostor.Api.dll"
]
Expand Down Expand Up @@ -434,7 +434,7 @@
},
"projectFileDependencyGroups": {
".NETStandard,Version=v2.1": [
"Impostor.Api >= 1.2.2-ci.116"
"Impostor.Api >= 1.2.2-ci.121"
]
},
"packageFolders": {
Expand Down Expand Up @@ -474,7 +474,7 @@
"dependencies": {
"Impostor.Api": {
"target": "Package",
"version": "[1.2.2-ci.116, )"
"version": "[1.2.2-ci.121, )"
}
},
"imports": [
Expand Down
4 changes: 2 additions & 2 deletions Jester/obj/project.nuget.cache
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"version": 2,
"dgSpecHash": "CWO6nJjcGR6Oe12TK/ZPlBN7k46ut/gG8bWiYSuw1epo6pxM+KEWQzZiZSdeQ3C7gsbdZCeG697wZrlhy6W7Kg==",
"dgSpecHash": "Fixk9cgrNFmusCrRI7xITHcZceJLmzudVOjq39V6msNPewtOfRV4LSaWceNmNkm6QF6+6Z2MmsBi4sm4mQvdZA==",
"success": true,
"projectFilePath": "C:\\Users\\Tijs\\Documents\\AmongUsProject\\Jester\\Jester\\Jester.csproj",
"expectedPackageFiles": [
"C:\\Users\\Tijs\\.nuget\\packages\\impostor.api\\1.2.2-ci.116\\impostor.api.1.2.2-ci.116.nupkg.sha512",
"C:\\Users\\Tijs\\.nuget\\packages\\impostor.api\\1.2.2-ci.121\\impostor.api.1.2.2-ci.121.nupkg.sha512",
"C:\\Users\\Tijs\\.nuget\\packages\\microsoft.bcl.hashcode\\1.1.0\\microsoft.bcl.hashcode.1.1.0.nupkg.sha512",
"C:\\Users\\Tijs\\.nuget\\packages\\microsoft.extensions.configuration.abstractions\\5.0.0\\microsoft.extensions.configuration.abstractions.5.0.0.nupkg.sha512",
"C:\\Users\\Tijs\\.nuget\\packages\\microsoft.extensions.dependencyinjection.abstractions\\5.0.0\\microsoft.extensions.dependencyinjection.abstractions.5.0.0.nupkg.sha512",
Expand Down

0 comments on commit 7871b48

Please sign in to comment.