Skip to content

Commit

Permalink
Merge pull request #64 from jonathan-robertson/dev
Browse files Browse the repository at this point in the history
Update XP Debt Prevention Text
  • Loading branch information
jonathan-robertson authored Feb 20, 2023
2 parents b912e0a + d2007f3 commit 61741ec
Show file tree
Hide file tree
Showing 16 changed files with 682 additions and 312 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.1] - 2023-02-19

- update xp debt prevention text

## [1.1.0] - 2023-01-03

- add fragile memory state
Expand Down
3 changes: 3 additions & 0 deletions Config/Localization.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
amnesiaJournalTip,Journal Tip,,"Survivors are reporting strange occurrences of Amnesia when experiencing severe trauma... At level [007fff]{cvar(amnesiaLongTermMemoryLevel)}[-] and beyond, becoming incapacitated will result in a [ff8000]Fragile Memory[-]. This [ff8000]Fragile Memory[-] will cause full-blown [ff007f]Memory Loss[-] if you were to become incapacitated once more.\n\n[ff8000]This Happens Every Time I Die?[-]\nDying will impact memory, but there are a few exceptions: if [00ff80]another player kills you[-], or if [00ff80]you die during Blood Moon for any reason[-].\n\n[ff8000]What Would I Forget Due to Memory Loss?[-]\nYou will forget your level, learned skills, and unspent skill points (you'll be reset back to level [007fff]{cvar(amnesiaLongTermMemoryLevel)}[-] and can reallocate the skillpoints you would've had at that level).\n\n[ff8000]Will I Remember Anything After Memory Loss?[-]\nYou will never forget schematics, books, items/equipment (backpack is dropped on ground, but not deleted), vehicles, map, waypoints, land claims, bedroll location, quests, trader relationships.\n\n[ff8000]How Can I Recover From a Fragile Memory?[-]\nYou'll find that all traders sell a new item called [007fff]Trader Jen's Memory Boosters[-] in limited quantities, which you can use to recover from a [ff8000]Fragile Memory[-]. This will give you a buffer against memory loss, but the sale price is also quite high; you probably won't be able to afford it right away.\n\n[ff8000]Anything Else I Should Know?[-]\nDefeating certain powerful zombies will lift your spirits, providing a timed boost of double xp for you and everyone else on the server! Try to take these challenging enemies down for the benefit and relief of the entire community."
amnesiaJournalTip_title,Journal Tip,,"Amnesia [ff8000][MOD]"

buffNewbieCoatDesc,buffs,Buff,"There is no XP penalty on death.\n\nThis protection will eventually disappear, so plan ahead."
buffNewbieCoatName,buffs,Buff,"Death XP Penalty Protection"

buffAmnesiaFragileMemoryName,buffs,Buffs,"Fragile Memory"
buffAmnesiaFragileMemoryDesc,buffs,Buffs,"You now have a [ff8000]Fragile Memory[-] due to being incapacitated. \n\nIf you become incapacitated again, you will experience [ff007f]Memory Loss[-].\n\n[007fff]Trader Jen's Memory Boosters[-] can be purchased from any trader to cure your [ff8000]Fragile Memory[-], which will provide a buffer against [ff007f]Memory Loss[-]."
buffAmnesiaFragileMemoryStartTooltip,buffs,Buffs,"You now have a [ff8000]Fragile Memory[-] due to being incapacitated"
Expand Down
2 changes: 1 addition & 1 deletion ModInfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Name value="Amnesia" />
<Description value="Reset player progress after a configurable number of deaths" />
<Author value="Jonathan Robertson (Kanaverum)" />
<Version value="1.1.0" />
<Version value="1.1.1" />
<Website value="https://github.com/jonathan-robertson/amnesia" />
</ModInfo>
</xml>
281 changes: 191 additions & 90 deletions src/Commands/ConsoleCmdAmnesia.cs

Large diffs are not rendered by default.

237 changes: 163 additions & 74 deletions src/Data/Config.cs

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/Data/Values.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Collections.Generic;
using System.Linq;

namespace Amnesia.Data {
internal class Values {
namespace Amnesia.Data
{
internal class Values
{

// cvars
public const string CVarLongTermMemoryLevel = "amnesiaLongTermMemoryLevel";
Expand Down
22 changes: 15 additions & 7 deletions src/Handlers/EntityKilled.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@
using Amnesia.Utilities;
using System;

namespace Amnesia.Handlers {
internal class EntityKilled {
namespace Amnesia.Handlers
{
internal class EntityKilled
{
private static readonly ModLog<EntityKilled> log = new ModLog<EntityKilled>();

internal static void Handle(Entity killedEntity, Entity killerEntity) {
try {
internal static void Handle(Entity killedEntity, Entity killerEntity)
{
try
{
if (killerEntity == null || killerEntity.entityType != EntityType.Player) { return; }
if (!Config.PositiveOutlookTimeOnKill.TryGetValue(killedEntity.GetDebugName(), out var entry)) {
if (!Config.PositiveOutlookTimeOnKill.TryGetValue(killedEntity.GetDebugName(), out var entry))
{
return;
}

var minutes = entry.value / 60f;
MessagingSystem.Broadcast($"[007fff]{killerEntity.GetDebugName()} just took down a {entry.caption}!");
MessagingSystem.Broadcast($"[007fff]Relief washes over each survivor as a newfound confidence takes hold: [00ff80]all online players receive Double XP for {(minutes > 1 ? minutes + " Minutes!" : entry.value + " Seconds!")}");
foreach (var player in GameManager.Instance.World.Players.list) {
foreach (var player in GameManager.Instance.World.Players.list)
{
_ = PlayerHelper.AddPositiveOutlookTime(player, entry.value);
}
} catch (Exception e) {
}
catch (Exception e)
{
log.Error("HandleEntityKilled", e);
}
}
Expand Down
41 changes: 28 additions & 13 deletions src/Handlers/GameMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,60 @@
using Amnesia.Utilities;
using System;

namespace Amnesia.Handlers {
internal class GameMessage {
namespace Amnesia.Handlers
{
internal class GameMessage
{
private static readonly ModLog<GameMessage> log = new ModLog<GameMessage>();

public static bool Handle(ClientInfo clientInfo, EnumGameMessages messageType, string message, string mainName, bool localizeMain, string secondaryName, bool localizeSecondary) {
public static bool Handle(ClientInfo clientInfo, EnumGameMessages messageType, string message, string mainName, bool localizeMain, string secondaryName, bool localizeSecondary)
{
if (!Config.Loaded) { return true; } // do not interrupt other mods from processing event
try {
if (EnumGameMessages.EntityWasKilled != messageType) {
try
{
if (EnumGameMessages.EntityWasKilled != messageType)
{
return true; // only focus on entity killed messages
}

if (!GameManager.Instance.World.Players.dict.TryGetValue(clientInfo.entityId, out var player)) {
if (!GameManager.Instance.World.Players.dict.TryGetValue(clientInfo.entityId, out var player))
{
return true; // player not present; skip
}

if (player.Buffs.HasBuff(Values.BuffBloodmoonLifeProtection) || player.Buffs.HasBuff(Values.BuffPostBloodmoonLifeProtection)) {
if (player.Buffs.HasBuff(Values.BuffBloodmoonLifeProtection) || player.Buffs.HasBuff(Values.BuffPostBloodmoonLifeProtection))
{
log.Trace($"{clientInfo.InternalId.CombinedString} ({player.GetDebugName()}) died but had bloodmoon memory protection.");
return true; // player had protection
} else {
}
else
{
log.Trace($"{clientInfo.InternalId.CombinedString} ({player.GetDebugName()}) died and did not have bloodmoon memory protection.");
}

if (Config.ProtectMemoryDuringPvp && mainName != secondaryName) {
if (Config.ProtectMemoryDuringPvp && mainName != secondaryName)
{
var killerClient = ConnectionManager.Instance.Clients.GetForNameOrId(secondaryName);
if (killerClient != null) {
if (killerClient != null)
{
log.Trace($"{clientInfo.InternalId.CombinedString} ({player.GetDebugName()}) was killed by {secondaryName} but this server has pvp deaths set to not harm memory.");
return true; // being killed in pvp doesn't count against player
}
}

if (player.Progression.Level < Config.LongTermMemoryLevel) {
if (player.Progression.Level < Config.LongTermMemoryLevel)
{
log.Trace($"{clientInfo.InternalId.CombinedString} ({player.GetDebugName()}) died but had not yet reached the configured LongTermMemoryLevel of {Config.LongTermMemoryLevel}");
return true;
}

if (!ModApi.Obituary.ContainsKey(clientInfo.entityId)) {
if (!ModApi.Obituary.ContainsKey(clientInfo.entityId))
{
ModApi.Obituary.Add(clientInfo.entityId, true);
}
} catch (Exception e) {
}
catch (Exception e)
{
log.Error("Failed to handle GameMessage event.", e);
}
return true; // do not interrupt other mods from processing event
Expand Down
45 changes: 31 additions & 14 deletions src/Handlers/GameUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,63 @@
using Amnesia.Utilities;
using System;

namespace Amnesia.Handlers {
internal class GameUpdate {
namespace Amnesia.Handlers
{
internal class GameUpdate
{
private static readonly ModLog<GameUpdate> log = new ModLog<GameUpdate>();
private static readonly uint _ceiling = 100;
private static uint _counter = 0;
private static bool isBloodmoon = false;

internal static void Handle() {
internal static void Handle()
{
if (!Config.Loaded || !Config.ProtectMemoryDuringBloodmoon) { return; }
try {
try
{
_counter++;
if (_counter > _ceiling) {
if (_counter > _ceiling)
{
_counter = 0;
HandleBloodMoon();
}
} catch (Exception e) {
}
catch (Exception e)
{
log.Error("Failed to handle GameUpdate event.", e);
}
}

private static void HandleBloodMoon() {
private static void HandleBloodMoon()
{
// TODO: this should probably be injected into triggers when bloodmoon starts and ends, honestly
try {
if (isBloodmoon == GameManager.Instance.World.aiDirector.BloodMoonComponent.BloodMoonActive) {
try
{
if (isBloodmoon == GameManager.Instance.World.aiDirector.BloodMoonComponent.BloodMoonActive)
{
return;
}
isBloodmoon = !isBloodmoon;

var players = GameManager.Instance.World.Players.list;
if (isBloodmoon) {
for (var i = 0; i < players.Count; i++) {
if (isBloodmoon)
{
for (var i = 0; i < players.Count; i++)
{
_ = players[i].Buffs.AddBuff(Values.BuffBloodmoonLifeProtection);
}
} else {
for (var i = 0; i < players.Count; i++) {
}
else
{
for (var i = 0; i < players.Count; i++)
{
_ = players[i].Buffs.AddBuff(Values.BuffPostBloodmoonLifeProtection);
players[i].Buffs.RemoveBuff(Values.BuffBloodmoonLifeProtection);
}
}
} catch (Exception e) {
}
catch (Exception e)
{
log.Error("Failed to handle bloodmoon.", e);
}
}
Expand Down
51 changes: 35 additions & 16 deletions src/Handlers/PlayerSpawnedInWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using Amnesia.Utilities;
using System;

namespace Amnesia.Handlers {
internal class PlayerSpawnedInWorld {
namespace Amnesia.Handlers
{
internal class PlayerSpawnedInWorld
{
private static readonly ModLog<PlayerSpawnedInWorld> log = new ModLog<PlayerSpawnedInWorld>();

/// <summary>
Expand All @@ -13,13 +15,17 @@ internal class PlayerSpawnedInWorld {
/// <param name="respawnType">The type of respawn.</param>
/// <param name="pos">The position this player is respawning to.</param>
/// <remarks>This mod supports being dropped into an existing game, thanks to how we handle this process.</remarks>
public static void Handle(ClientInfo clientInfo, RespawnType respawnType, Vector3i pos) {
public static void Handle(ClientInfo clientInfo, RespawnType respawnType, Vector3i pos)
{
if (!Config.Loaded) { return; }
try {
if (clientInfo == null || !GameManager.Instance.World.Players.dict.TryGetValue(clientInfo.entityId, out var player) || !player.IsAlive()) {
try
{
if (clientInfo == null || !GameManager.Instance.World.Players.dict.TryGetValue(clientInfo.entityId, out var player) || !player.IsAlive())
{
return; // exit early if player cannot be found in active world or is dead
}
switch (respawnType) {
switch (respawnType)
{
case RespawnType.EnterMultiplayer: // first-time login for new player
_ = PlayerHelper.AddPositiveOutlookTime(player, Config.PositiveOutlookTimeOnFirstJoin);
RefundHardenedMemory(clientInfo, player);
Expand All @@ -36,7 +42,9 @@ public static void Handle(ClientInfo clientInfo, RespawnType respawnType, Vector
HandleStandardRespawnSteps(player);
break;
}
} catch (Exception e) {
}
catch (Exception e)
{
log.Error("Failed to handle PlayerSpawnedInWorld event.", e);
}
}
Expand All @@ -46,27 +54,36 @@ public static void Handle(ClientInfo clientInfo, RespawnType respawnType, Vector
/// </summary>
/// <param name="player">Player to process steps for.</param>
/// <remarks>This method also handles cleanup when player was already dead on Enter/Join (happens if player logged out while dead).</remarks>
private static void HandleStandardRespawnSteps(EntityPlayer player) {
private static void HandleStandardRespawnSteps(EntityPlayer player)
{

// Ensure joining/respawning players have their constants updated
if (player.GetCVar(Values.CVarLongTermMemoryLevel) != Config.LongTermMemoryLevel) {
if (player.GetCVar(Values.CVarLongTermMemoryLevel) != Config.LongTermMemoryLevel)
{
player.SetCVar(Values.CVarLongTermMemoryLevel, Config.LongTermMemoryLevel);
}

// Remove Positive Outlook if admin disabled it since player's last login
if (Config.PositiveOutlookTimeOnMemoryLoss == 0 && player.Buffs.HasBuff(Values.BuffPositiveOutlook)) {
if (Config.PositiveOutlookTimeOnMemoryLoss == 0 && player.Buffs.HasBuff(Values.BuffPositiveOutlook))
{
player.Buffs.RemoveBuff(Values.BuffPositiveOutlook);
}

// Apply/Remove memory protection based on configuration
if (Config.ProtectMemoryDuringBloodmoon) {
if (Config.ProtectMemoryDuringBloodmoon)
{
// add or remove protection based on whether BM is active
if (GameManager.Instance.World.aiDirector.BloodMoonComponent.BloodMoonActive) {
if (GameManager.Instance.World.aiDirector.BloodMoonComponent.BloodMoonActive)
{
_ = player.Buffs.AddBuff(Values.BuffBloodmoonLifeProtection);
} else {
}
else
{
player.Buffs.RemoveBuff(Values.BuffBloodmoonLifeProtection);
}
} else {
}
else
{
// remove/clean up since protection is inactive
player.Buffs.RemoveBuff(Values.BuffBloodmoonLifeProtection);
player.Buffs.RemoveBuff(Values.BuffPostBloodmoonLifeProtection);
Expand All @@ -77,8 +94,10 @@ private static void HandleStandardRespawnSteps(EntityPlayer player) {
/// Temporary method to automatically refund any players with the Hardened Memory buff from version 1.0.0.
/// </summary>
/// <param name="player">EntityPlayer to check buffs for and refund if hardened.</param>
private static void RefundHardenedMemory(ClientInfo clientInfo, EntityPlayer player) {
if (player.Buffs.HasBuff(Values.BuffHardenedMemory)) {
private static void RefundHardenedMemory(ClientInfo clientInfo, EntityPlayer player)
{
if (player.Buffs.HasBuff(Values.BuffHardenedMemory))
{
PlayerHelper.GiveItem(clientInfo, player, Values.NameMemoryBoosters);
player.Buffs.RemoveBuff(Values.BuffHardenedMemory);
}
Expand Down
Loading

0 comments on commit 61741ec

Please sign in to comment.