Skip to content

Commit

Permalink
1.2.2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaltharos committed Aug 24, 2022
1 parent 967ace8 commit 2b840c1
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 29 deletions.
3 changes: 2 additions & 1 deletion Hooks/BuffHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private static void Postfix(BuffSystem_Spawn_Server __instance)
{
if (__instance.__OnUpdate_LambdaJob0_entityQuery == null) return;

if (HunterHuntedSystem.isActive || WeaponMasterSystem.isMasteryEnabled)
if (PvPSystem.isPunishEnabled || HunterHuntedSystem.isActive || WeaponMasterSystem.isMasteryEnabled)
{
NativeArray<Entity> entities = __instance.__OnUpdate_LambdaJob0_entityQuery.ToEntityArray(Allocator.Temp);
foreach (var entity in entities)
Expand All @@ -315,6 +315,7 @@ private static void Postfix(BuffSystem_Spawn_Server __instance)
HunterHuntedSystem.BanditAmbusher(e_User, e_Owner, true);
}
if (WeaponMasterSystem.isMasteryEnabled) WeaponMasterSystem.LoopMastery(e_User, e_Owner);
if (PvPSystem.isPunishEnabled && !ExperienceSystem.isEXPActive) PvPSystem.OnCombatEngaged(entity, e_Owner);
}
}
}
Expand Down
54 changes: 43 additions & 11 deletions Hooks/EquipmentSystemHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using ProjectM;
using RPGMods.Systems;
using RPGMods.Utils;
using System;

namespace RPGMods.Hooks;

Expand All @@ -28,6 +29,23 @@ private static void Prefix(ArmorLevelSystem_Spawn __instance)
}
}
}

private static void Postfix(ArmorLevelSystem_Spawn __instance)
{
if (__instance.__OnUpdate_LambdaJob0_entityQuery == null) return;

if (PvPSystem.isPunishEnabled && !ExperienceSystem.isEXPActive)
{
NativeArray<Entity> entities = __instance.__OnUpdate_LambdaJob0_entityQuery.ToEntityArray(Allocator.Temp);

foreach (var entity in entities)
{
Entity Owner = __instance.EntityManager.GetComponentData<EntityOwner>(entity).Owner;
if (!__instance.EntityManager.HasComponent<PlayerCharacter>(Owner)) return;
if (PvPSystem.isPunishEnabled) PvPSystem.OnEquipChange(Owner);
}
}
}
}

[HarmonyPatch(typeof(WeaponLevelSystem_Spawn), nameof(WeaponLevelSystem_Spawn.OnUpdate))]
Expand All @@ -41,7 +59,8 @@ private static void Prefix(WeaponLevelSystem_Spawn __instance)
{
EntityManager entityManager = __instance.EntityManager;
NativeArray<Entity> entities = __instance.__OnUpdate_LambdaJob0_entityQuery.ToEntityArray(Allocator.Temp);
foreach(var entity in entities)

foreach (var entity in entities)
{
if (ExperienceSystem.isEXPActive)
{
Expand All @@ -61,7 +80,22 @@ private static void Prefix(WeaponLevelSystem_Spawn __instance)
}
}
}
}

private static void Postfix(WeaponLevelSystem_Spawn __instance)
{
if (__instance.__OnUpdate_LambdaJob0_entityQuery == null) return;

if (PvPSystem.isPunishEnabled && !ExperienceSystem.isEXPActive)
{
NativeArray<Entity> entities = __instance.__OnUpdate_LambdaJob0_entityQuery.ToEntityArray(Allocator.Temp);
foreach (var entity in entities)
{
Entity Owner = __instance.EntityManager.GetComponentData<EntityOwner>(entity).Owner;
if (!__instance.EntityManager.HasComponent<PlayerCharacter>(Owner)) return;
if (PvPSystem.isPunishEnabled) PvPSystem.OnEquipChange(Owner);
}
}
}
}

Expand Down Expand Up @@ -89,21 +123,19 @@ private static void Postfix(SpellLevelSystem_Spawn __instance)
{
if (__instance.__OnUpdate_LambdaJob0_entityQuery == null) return;

if (ExperienceSystem.isEXPActive)
if (ExperienceSystem.isEXPActive || PvPSystem.isPunishEnabled)
{
EntityManager entityManager = __instance.EntityManager;
NativeArray<Entity> entities = __instance.__OnUpdate_LambdaJob0_entityQuery.ToEntityArray(Allocator.Temp);
foreach (var entity in entities)
{
if (!entityManager.HasComponent<LastTranslation>(entity))
Entity Owner = __instance.EntityManager.GetComponentData<EntityOwner>(entity).Owner;
if (!__instance.EntityManager.HasComponent<PlayerCharacter>(Owner)) return;
if (PvPSystem.isPunishEnabled && !ExperienceSystem.isEXPActive) PvPSystem.OnEquipChange(Owner);
if (ExperienceSystem.isEXPActive)
{
Entity Owner = entityManager.GetComponentData<EntityOwner>(entity).Owner;
if (entityManager.HasComponent<PlayerCharacter>(Owner))
{
Entity User = entityManager.GetComponentData<PlayerCharacter>(Owner).UserEntity._Entity;
ulong SteamID = entityManager.GetComponentData<User>(User).PlatformId;
ExperienceSystem.SetLevel(Owner, User, SteamID);
}
Entity User = __instance.EntityManager.GetComponentData<PlayerCharacter>(Owner).UserEntity._Entity;
ulong SteamID = __instance.EntityManager.GetComponentData<User>(User).PlatformId;
ExperienceSystem.SetLevel(Owner, User, SteamID);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Hooks/ServerBootstrapHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void Postfix(ServerBootstrapSystem __instance, NetConnectionId net
{
if (PvPSystem.isHonorSystemEnabled)
{
Helper.RenamePlayer(userEntity, userData.LocalCharacter._Entity, userData.CharacterName);
if (PvPSystem.isHonorTitleEnabled) Helper.RenamePlayer(userEntity, userData.LocalCharacter._Entity, userData.CharacterName);

Database.PvPStats.TryGetValue(userData.PlatformId, out var pvpStats);
Database.SiegeState.TryGetValue(userData.PlatformId, out var siegeState);
Expand Down
3 changes: 3 additions & 0 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class Plugin : BasePlugin
private static ConfigEntry<float> PunishOffenseCooldown;

private static ConfigEntry<bool> EnableHonorSystem;
private static ConfigEntry<bool> EnableHonorTitle;
private static ConfigEntry<int> MaxHonorGainPerSpan;
private static ConfigEntry<bool> EnableHonorBenefit;
private static ConfigEntry<int> HonorSiegeDuration;
Expand Down Expand Up @@ -165,6 +166,7 @@ public void InitConfig()

AnnouncePvPKills = Config.Bind("PvP", "Announce PvP Kills", true, "Make a server wide announcement for all PvP kills.");
EnableHonorSystem = Config.Bind("PvP", "Enable Honor System", false, "Enable the honor system.");
EnableHonorTitle = Config.Bind("PvP", "Enable Honor Title", true, "When enabled, the system will append the title to their name.\nHonor system will leave the player name untouched if disabled.");
MaxHonorGainPerSpan = Config.Bind("PvP", "Max Honor Gain/Hour", 250, "Maximum amount of honor points the player can gain per hour.");
EnableHonorBenefit = Config.Bind("PvP", "Enable Honor Benefit & Penalties", true, "If disabled, the hostility state and custom siege system will be disabled.\n" +
"All other bonus is also not applied.");
Expand Down Expand Up @@ -312,6 +314,7 @@ public static void Initialize()
PvPSystem.isAnnounceKills = AnnouncePvPKills.Value;

PvPSystem.isHonorSystemEnabled = EnableHonorSystem.Value;
PvPSystem.isHonorTitleEnabled = EnableHonorTitle.Value;
PvPSystem.MaxHonorGainPerSpan = MaxHonorGainPerSpan.Value;
PvPSystem.SiegeDuration = HonorSiegeDuration.Value;
PvPSystem.isHonorBenefitEnabled = EnableHonorBenefit.Value;
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ players will otherwise never be able to do any pvp damage despite toggling pvp s
PvP toggle will be overridden by Hostility Mode if the honor system is active.
> ### Punishment System
Additionally, there's a punishment system which can be used to punish players who kill lower level players,\
which is configurable in the config.\
which is configurable in the config.

The punishment system also has an anti-cheese built-in in case the server is not using the EXP system.\
Purposefully unequiping gear to appear as lower level to cheese the punishment system will not work.

Punishment will apply a debuff that reduces player combat efficiency.
* -25% Physical & spell power
* -15 Physical, spell, holy, and fire resistance
Expand Down Expand Up @@ -251,6 +255,9 @@ Multiply resource yield (not item drop) when user is out of combat. -1.0 to disa
Make a server wide announcement for all PvP kills.
- `Enable Honor System` [default `false`]\
Enable the honor system.
- `Enable Honor Title` [default `true`]\
When enabled, the system will append the title to their name.\
Honor system will leave the player name untouched if disabled.
- `Max Honor Gain/Hour` [default `250`]\
Maximum amount of honor points the player can gain per hour.
- `Enable Honor Benefit & Penalties` [default `true`]\
Expand Down Expand Up @@ -805,6 +812,10 @@ Notes:
<details>
<summary>Changelog</summary>

`1.2.2`
- Added anti-cheese system for PvP Punishment without EXP System.
- Added a config to disable the honor title only with benefits, etc still active.

`1.2.1`
- Added mob ignore feature for faction buff.
- Added mob ignore command for faction buffs.
Expand Down
2 changes: 1 addition & 1 deletion RPGMods.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>RPGMods</AssemblyName>
<Description>RPG Mods combined with ChatCommands</Description>
<Version>1.2.1</Version>
<Version>1.2.2</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>preview</LangVersion>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
Expand Down
65 changes: 52 additions & 13 deletions Systems/PvPSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class PvPSystem
//Buff_Cultist_BloodFrenzy_Buff - PrefabGuid(-106492795)
public static PrefabGUID HostileBuff = new PrefabGUID(-106492795);
public static bool isHonorSystemEnabled = true;
public static bool isHonorTitleEnabled = true;
public static int HonorGainSpanLimit = 60;
public static int MaxHonorGainPerSpan = 250;
public static bool isHonorBenefitEnabled = true;
Expand Down Expand Up @@ -165,10 +166,13 @@ public static void MobKillMonitor(Entity KillerEntity, Entity VictimEntity)
{
if (KillerStats.Reputation <= -1000) PvPSystem.HostileON(killer_id, KillerEntity, killer_userEntity);
KillerStats.Title = KillerHonorInfo.Title;
var true_name = Helper.GetTrueName(killer_name);
killer_name = "[" + KillerHonorInfo.Title + "]" + true_name;
KillerStats.PlayerName = killer_name;
renamePlayer = true;
if (isHonorTitleEnabled)
{
var true_name = Helper.GetTrueName(killer_name);
killer_name = "[" + KillerHonorInfo.Title + "]" + true_name;
KillerStats.PlayerName = killer_name;
renamePlayer = true;
}
}
}

Expand Down Expand Up @@ -245,10 +249,14 @@ public static void Monitor(Entity KillerEntity, Entity VictimEntity)
if (KillerStats.Reputation <= -20000) PvPSystem.SiegeON(killer_id, KillerEntity, killer_userEntity, true, true);

KillerStats.Title = KillerHonorInfo.Title;
var true_name = Helper.GetTrueName(killer_name);
killer_name = "[" + KillerHonorInfo.Title + "]" + true_name;
KillerStats.PlayerName = killer_name;
renamePlayer = true;

if (isHonorTitleEnabled)
{
var true_name = Helper.GetTrueName(killer_name);
killer_name = "[" + KillerHonorInfo.Title + "]" + true_name;
KillerStats.PlayerName = killer_name;
renamePlayer = true;
}
}
}

Expand Down Expand Up @@ -423,15 +431,46 @@ public static async Task SiegeList(Context ctx)
}, false);
}

public static void OnEquipChange(Entity player)
{
var PlayerLevel = em.GetComponentData<Equipment>(player).GetFullLevel();
Cache.PlayerLevelCache.TryGetValue(player, out var levelData);

if (PlayerLevel > levelData.Level)
{
levelData.Level = PlayerLevel;
levelData.TimeStamp = DateTime.Now;
Cache.PlayerLevelCache[player] = levelData;
}
}

public static void OnCombatEngaged(Entity buffEntity, Entity player)
{
PrefabGUID GUID = em.GetComponentData<PrefabGUID>(buffEntity);
if (GUID.Equals(Database.Buff.InCombat_PvP))
{
Cache.PlayerLevelCache.TryGetValue(player, out var levelData);
if (DateTime.Now.Subtract(levelData.TimeStamp).TotalSeconds > 60)
{
levelData.Level = em.GetComponentData<Equipment>(player).GetFullLevel();
}
levelData.TimeStamp = DateTime.Now;
Cache.PlayerLevelCache[player] = levelData;
}
}

public static void PunishCheck(Entity Killer, Entity Victim)
{
Entity KillerUser = em.GetComponentData<PlayerCharacter>(Killer).UserEntity._Entity;
ulong KillerSteamID = em.GetComponentData<User>(KillerUser).PlatformId;
Equipment KillerGear = em.GetComponentData<Equipment>(Killer);
float KillerLevel = KillerGear.ArmorLevel + KillerGear.WeaponLevel + KillerGear.SpellLevel;

Equipment VictimGear = em.GetComponentData<Equipment>(Victim);
float VictimLevel = VictimGear.ArmorLevel + VictimGear.WeaponLevel + VictimGear.SpellLevel;
float KillerLevel;
if (Cache.PlayerLevelCache.TryGetValue(Killer, out var killerData)) KillerLevel = killerData.Level;
else KillerLevel = em.GetComponentData<Equipment>(Killer).GetFullLevel();

float VictimLevel;
if (Cache.PlayerLevelCache.TryGetValue(Victim, out var victimData)) VictimLevel = victimData.Level;
else VictimLevel = em.GetComponentData<Equipment>(Victim).GetFullLevel();

if (VictimLevel - KillerLevel <= PunishLevelDiff)
{
Expand Down Expand Up @@ -523,7 +562,7 @@ public static void HonorBuffReceiver(Entity BuffEntity, PrefabGUID GUID)

public static void NewPlayerReceiver(Entity userEntity, Entity playerEntity, FixedString64 playerName)
{
Helper.RenamePlayer(userEntity, playerEntity, playerName);
if (isHonorTitleEnabled) Helper.RenamePlayer(userEntity, playerEntity, playerName);

var steamID = Plugin.Server.EntityManager.GetComponentData<User>(userEntity).PlatformId;
Cache.HostilityState[playerEntity] = new StateData(steamID, false);
Expand Down
2 changes: 2 additions & 0 deletions Utils/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Cache
public static Dictionary<ulong, float> player_level = new();

//-- -- PvP System
public static Dictionary<Entity, LevelData> PlayerLevelCache = new();
public static Dictionary<ulong, PvPOffenseLog> OffenseLog = new();
public static Dictionary<ulong, ReputationLog> ReputationLog = new();
public static Dictionary<Entity, StateData> HostilityState = new();
Expand Down Expand Up @@ -377,6 +378,7 @@ public class Database

public static class Buff
{
public static PrefabGUID EquipBuff = new PrefabGUID(343359674);
public static PrefabGUID WolfStygian = new PrefabGUID(-1158884666);
public static PrefabGUID WolfNormal = new PrefabGUID(-351718282);
public static PrefabGUID BatForm = new PrefabGUID(1205505492);
Expand Down
2 changes: 1 addition & 1 deletion Utils/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static bool RenamePlayer(Entity userEntity, Entity charEntity, FixedStrin
//}

var userData = Plugin.Server.EntityManager.GetComponentData<User>(userEntity);
if (PvPSystem.isHonorSystemEnabled)
if (PvPSystem.isHonorSystemEnabled && PvPSystem.isHonorTitleEnabled)
{
var vampire_name = GetTrueName(newName.ToString());

Expand Down
12 changes: 12 additions & 0 deletions Utils/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@

namespace RPGMods.Utils
{
public struct LevelData
{
public float Level;
public DateTime TimeStamp;

public LevelData(float level = 0, DateTime timeStamp = default)
{
Level = level;
TimeStamp = timeStamp;
}
}

public struct PowerUpData
{
public string Name { get; set; }
Expand Down

0 comments on commit 2b840c1

Please sign in to comment.