Skip to content

Commit

Permalink
Publish
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ryuu committed Nov 1, 2023
1 parent d1d5cd5 commit c3b907c
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ $RECYCLE.BIN/

# Windows shortcuts
*.lnk

# macOS-specific files and directories to ignore
.DS_Store
.AppleDouble/
__MACOSX/

# Remove dotnet normal build
bin/
obj/
Binary file not shown.
39 changes: 39 additions & 0 deletions build/K4ryuuDamageInfo/K4ryuuDamageInfo.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v7.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v7.0": {
"K4ryuuDamageInfo/1.0.0": {
"dependencies": {
"CounterStrikeSharp.API": "1.0.0.0"
},
"runtime": {
"K4ryuuDamageInfo.dll": {}
}
},
"CounterStrikeSharp.API/1.0.0.0": {
"runtime": {
"CounterStrikeSharp.API.dll": {
"assemblyVersion": "1.0.0.0",
"fileVersion": "1.0.0.0"
}
}
}
}
},
"libraries": {
"K4ryuuDamageInfo/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"CounterStrikeSharp.API/1.0.0.0": {
"type": "reference",
"serviceable": false,
"sha512": ""
}
}
}
Binary file added build/K4ryuuDamageInfo/K4ryuuDamageInfo.dll
Binary file not shown.
Binary file added build/K4ryuuDamageInfo/K4ryuuDamageInfo.pdb
Binary file not shown.
Binary file added src/CounterStrikeSharp.API.dll
Binary file not shown.
109 changes: 109 additions & 0 deletions src/K4ryuuDamageInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;

namespace K4ryuuDamageInfo
{
public class DamageInfoPlugin : BasePlugin
{
public override string ModuleName => "Damage Info";
public override string ModuleVersion => "0.0.1";

private Dictionary<CCSPlayerController, DamageData> playerDamageData = new Dictionary<CCSPlayerController, DamageData>();

public override void Load(bool hotReload)
{
RegisterEventHandler<EventPlayerHurt>((@event, info) =>
{
CCSPlayerController attackerController = @event.Attacker;
int targetId = @event.Userid.UserId ?? -1;

if (attackerController.IsValid && !attackerController.IsBot)
{
if (!playerDamageData.ContainsKey(attackerController))
{
playerDamageData[attackerController] = new DamageData();
}

playerDamageData[attackerController].UpdateDamage(attackerController, targetId, @event.DmgHealth, @event.DmgArmor, @event.Hitgroup);
}

return HookResult.Continue;
});
}
}

public class DamageData
{
private Dictionary<int, DamageInfo> damageInfo = new Dictionary<int, DamageInfo>();
private Dictionary<int, DateTime> lastUpdateTime = new Dictionary<int, DateTime>();

public void UpdateDamage(CCSPlayerController attackerController, int targetId, int damageHP, int damageArmor, int Hitgroup)
{
if (!damageInfo.ContainsKey(targetId))
{
damageInfo[targetId] = new DamageInfo();
lastUpdateTime[targetId] = DateTime.Now;
}

ClearOutdatedDamageInfo(targetId);

damageInfo[targetId].DamageHP += damageHP;
damageInfo[targetId].DamageArmor += damageArmor;

if (damageHP > 350)
{
attackerController.PrintToCenter($"Damage Given:\nHP {damageInfo[targetId].DamageHP} | HitGroup: {HitGroupToString(Hitgroup)}");
}
else
attackerController.PrintToCenter($"Damage Given:\nHP {damageInfo[targetId].DamageHP} | Armor {damageInfo[targetId].DamageArmor} | HitGroup: {HitGroupToString(Hitgroup)}");

lastUpdateTime[targetId] = DateTime.Now;
}

private void ClearOutdatedDamageInfo(int targetId)
{
if (lastUpdateTime.ContainsKey(targetId))
{
TimeSpan elapsed = DateTime.Now - lastUpdateTime[targetId];
if (elapsed.TotalSeconds > 5)
{
damageInfo.Remove(targetId);
lastUpdateTime.Remove(targetId);
}
}
}

public string HitGroupToString(int hitGroup)
{
switch (hitGroup)
{
case 0:
return "Body";
case 1:
return "Head";
case 2:
return "Chest";
case 3:
return "Stomach";
case 4:
return "Left Arm";
case 5:
return "Right Arm";
case 6:
return "Left Leg";
case 7:
return "Right Leg";
case 10:
return "Gear";
default:
return "Unknown";
}
}
}

public class DamageInfo
{
public int DamageHP { get; set; }
public int DamageArmor { get; set; }
}
}
11 changes: 11 additions & 0 deletions src/K4ryuuDamageInfo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Reference Include="CounterStrikeSharp.API" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions src/K4ryuuDamageInfo.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "K4ryuuDamageInfo", "K4ryuuDamageInfo.csproj", "{3C041C13-9D82-4182-B13E-C72A23029731}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3C041C13-9D82-4182-B13E-C72A23029731}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C041C13-9D82-4182-B13E-C72A23029731}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C041C13-9D82-4182-B13E-C72A23029731}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C041C13-9D82-4182-B13E-C72A23029731}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {477EB2E4-F28D-4ABA-A360-C4F8CC1F3594}
EndGlobalSection
EndGlobal

0 comments on commit c3b907c

Please sign in to comment.