Skip to content

Commit

Permalink
Merge pull request #76 from jonathan-robertson/dev
Browse files Browse the repository at this point in the history
Fix Minor Bugs, Improve Text, Add/Update Admin Commands
  • Loading branch information
jonathan-robertson authored May 31, 2023
2 parents 61741ec + 0d83bf7 commit a1bb9d5
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 104 deletions.
Binary file modified Amnesia.dll
Binary file not shown.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ 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.2.0] - 2023-05-31

- add clarification for blood moon protection buff
- add clarifying text to amnesia buffs
- add debug toggle console command
- fix positive outlook bonus xp color
- improve performance of blood moon triggers
- move default console command to players param
- update badge for 20.7-b1

## [1.1.1] - 2023-02-19

- update xp debt prevention text
Expand Down
6 changes: 3 additions & 3 deletions Config/Localization.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ buffAmnesiaMemoryLossDesc,buffs,Buffs,"You feel a sense that mistakes were made,
buffAmnesiaMemoryLossTooltip,buffs,Buffs,"You experienced [ff007f]Memory Loss[-] due to being incapacitated"

buffAmnesiaPositiveOutlookName,buffs,Buffs,"Positive Outlook"
buffAmnesiaPositiveOutlookDesc,buffs,Buffs,"You're feeling especially positive about your situation and the future.\n\nSure, the world has gone to hell, but that doesn't mean your attitude needs to!\n\n[00FF00]XP Gain is Doubled!"
buffAmnesiaPositiveOutlookTooltip,buffs,Buffs,"Positive Outlook: [00FF00]XP Gain Doubled!"
buffAmnesiaPositiveOutlookDesc,buffs,Buffs,"You're feeling especially positive about your situation and the future.\n\nSure, the world has gone to hell, but that doesn't mean your attitude needs to!\n\n[00ff80]XP Gain is Doubled!"
buffAmnesiaPositiveOutlookTooltip,buffs,Buffs,"Positive Outlook: [00ff80]XP Gain Doubled!"

buffAmnesiaBloodmoonLifeProtectionName,buffs,Buffs,"Blood Moon Life Protection"
buffAmnesiaBloodmoonLifeProtectionDesc,buffs,Buffs,"You feel something in the air that seems to provide you with a sense of peace and clarity of thought... perhaps this is the same 'something' causing the zombies to go wild.\n\n[00ff80]You [00ff80]CANNOT[-] lose memory during or otherwise experience harm to your memory if you die during this event[-].\n\n... but still, try to play it safe."
buffAmnesiaBloodmoonLifeProtectionDesc,buffs,Buffs,"You feel something in the air that seems to provide you with a sense of peace and clarity of thought... perhaps this is the same 'something' causing the zombies to go wild.\n\n[00ff80]You [00ff80]CANNOT[-] lose memory or otherwise experience harm to your memory if you die during this event[-].\n\n... but still, try to play it safe.\n\nBefore level [007fff]{cvar(amnesiaLongTermMemoryLevel)}[-], this buff has no practical effect since your young, healthy brain wards off the mental impact of the apocalypse."
buffAmnesiaBloodmoonLifeProtectionTooltip,buffs,Buffs,"You [00ff80]CANNOT[-] lose memory if you die during this event"
buffAmnesiaBloodmoonLifeProtectionEndTooltip,buffs,Buffs,"Blood Moon Memory Protection [ff007f]HAS ENDED[-]"

Expand Down
11 changes: 10 additions & 1 deletion Config/buffs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<set xpath="/buffs/buff[@name='buffNewbieCoat']/effect_group/triggered_effect/requirement[@name='PlayerLevel']/@value">@amnesiaLongTermMemoryLevel</set>

<append xpath="/buffs">
<!-- deprecated: keeping around for a while for backwards compatibility -->
<!-- TODO: remove for 2.0.0 - deprecated: keeping around until then for backwards compatibility -->
<buff name="buffAmnesiaHardenedMemory" remove_on_death="false" hidden="true">
<duration value="0" />
<stack_type value="ignore" />
Expand All @@ -22,6 +22,8 @@
<buff name="buffAmnesiaFragileMemory" name_key="buffAmnesiaFragileMemoryName" description_key="buffAmnesiaFragileMemoryDesc" icon="ui_game_symbol_intellect" icon_color="255,128,0" remove_on_death="false">
<duration value="0" />
<stack_type value="ignore" />
<display_value value="xxx" />
<display_value_key value="[[ff8000]Fragile[-]]" />

<effect_group>
<triggered_effect trigger="onSelfBuffStart" action="ShowToolbeltMessage" message_key="buffAmnesiaFragileMemoryStartTooltip" />
Expand All @@ -33,6 +35,9 @@
<buff name="buffAmnesiaMemoryLoss" name_key="buffAmnesiaMemoryLossName" description_key="buffAmnesiaMemoryLossDesc" icon="ui_game_symbol_skull_crusher" icon_color="255,0,127" remove_on_death="false">
<duration value="30" />
<stack_type value="ignore" />
<display_value value="xxx" />
<display_value_key value="[[ff007f]LOST[-]]" />

<effect_group name="display-effects">
<!-- TODO: add bad/sad sound (you lost your memory :[ ) -->
<triggered_effect trigger="onSelfBuffStart" action="ShowToolbeltMessage" message_key="buffAmnesiaMemoryLossTooltip" />
Expand Down Expand Up @@ -69,6 +74,9 @@
<buff name="buffAmnesiaBloodmoonLifeProtection" name_key="buffAmnesiaBloodmoonLifeProtectionName" description_key="buffAmnesiaBloodmoonLifeProtectionDesc" icon="ui_game_symbol_intellect" icon_color="0,255,128" remove_on_death="false">
<duration value="0" />
<stack_type value="ignore" />
<display_value value="xxx" />
<display_value_key value="[[00FF80]Safe[-]]" />

<effect_group>
<passive_effect name="BuffBlink" operation="base_set" value="2" duration="0,3" tags="buffAmnesiaBloodmoonLifeProtection" />
<triggered_effect trigger="onSelfBuffStart" action="ShowToolbeltMessage" message_key="buffAmnesiaBloodmoonLifeProtectionTooltip" />
Expand All @@ -80,6 +88,7 @@
<stack_type value="ignore" />
<display_value value="$postBloodmoonProtectionTime" />
<display_value_format value="time" />

<effect_group name="setup">
<passive_effect name="BuffBlink" operation="base_set" value="2" duration="0,3" tags="buffAmnesiaPostBloodmoonLifeProtection" />
<!-- 300s == 5m -->
Expand Down
4 changes: 2 additions & 2 deletions ModInfo.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<xml>
<ModInfo>
<Name value="Amnesia" />
<Description value="Reset player progress after a configurable number of deaths" />
<Description value="Reset player progress after dying under a configurable set of circumstances" />
<Author value="Jonathan Robertson (Kanaverum)" />
<Version value="1.1.1" />
<Version value="1.2.0" />
<Website value="https://github.com/jonathan-robertson/amnesia" />
</ModInfo>
</xml>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Amnesia

[![🧪 Tested On](https://img.shields.io/badge/🧪%20Tested%20On-A20.6%20b9-blue.svg)](https://7daystodie.com/) [![📦 Automated Release](https://github.com/jonathan-robertson/amnesia/actions/workflows/release.yml/badge.svg)](https://github.com/jonathan-robertson/amnesia/actions/workflows/release.yml)
[![🧪 Tested On](https://img.shields.io/badge/🧪%20Tested%20On-A20.7%20b1-blue.svg)](https://7daystodie.com/) [![📦 Automated Release](https://github.com/jonathan-robertson/amnesia/actions/workflows/release.yml/badge.svg)](https://github.com/jonathan-robertson/amnesia/actions/workflows/release.yml)

![amnesia social image](https://github.com/jonathan-robertson/amnesia/raw/media/amnesia-logo-social.jpg)

Expand Down
Binary file added References/0Harmony.dll
Binary file not shown.
6 changes: 5 additions & 1 deletion src/Amnesia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\References\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\References\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -58,13 +62,13 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Patches\AIDirectorBloodMoonComponent.cs" />
<Compile Include="ModApi.cs" />
<Compile Include="Commands\ConsoleCmdAmnesia.cs" />
<Compile Include="Data\Config.cs" />
<Compile Include="Data\Values.cs" />
<Compile Include="Handlers\EntityKilled.cs" />
<Compile Include="Handlers\GameMessage.cs" />
<Compile Include="Handlers\GameUpdate.cs" />
<Compile Include="Handlers\PlayerSpawnedInWorld.cs" />
<Compile Include="Handlers\SavePlayerData.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
18 changes: 14 additions & 4 deletions src/Commands/ConsoleCmdAmnesia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ namespace Amnesia.Commands
{
internal class ConsoleCmdAmnesia : ConsoleCmdAbstract
{
private static readonly string[] Commands = new string[] {
private static readonly string[] Commands = new string[]
{
"amnesia",
"amn"
};
private readonly string help;

public ConsoleCmdAmnesia()
{
var dict = new Dictionary<string, string>() {
{ "", "show players and their amnesia-related info" },
var dict = new Dictionary<string, string>()
{
{ "debug", "toggle debug logging mode" },
{ "players", "show players and their amnesia-related info" },
{ "grant <user id / player name / entity id> <timeInSeconds>", "grant player some bonus xp time" },
{ "config", "show current amnesia configuration" },
{ "set", "show the single-value fields you can adjust" },
Expand Down Expand Up @@ -56,11 +59,18 @@ public override void Execute(List<string> _params, CommandSenderInfo _senderInfo
{
if (_params.Count == 0)
{
HandleShowPlayers();
SdtdConsole.Instance.Output($"A parameter is required; run 'help {Commands[0]}' for more info");
return;
}
switch (_params[0].ToLower())
{
case "debug":
ModApi.DebugMode = !ModApi.DebugMode;
SdtdConsole.Instance.Output($"Debug Mode has successfully been {(ModApi.DebugMode ? "enabled" : "disabled")}.");
return;
case "players":
HandleShowPlayers();
return;
case "test":
HandleTest(_params, _senderInfo);
return;
Expand Down
21 changes: 13 additions & 8 deletions src/Handlers/GameMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,34 @@ public static bool Handle(ClientInfo clientInfo, EnumGameMessages messageType, s
return true; // player not present; skip
}

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

if (Config.ProtectMemoryDuringPvp && mainName != secondaryName)
if (Config.ProtectMemoryDuringPvp && !mainName.Equals(secondaryName))
{
var killerClient = ConnectionManager.Instance.Clients.GetForNameOrId(secondaryName);
if (killerClient != null)
// TODO: this is nice, but damage/kill handling needs to also be redone to include the killing player in game message even if that player is offline
// and probably also to give that player offline credit for the kill(s).
foreach (var kvp in GameManager.Instance.persistentPlayers.Players)
{
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 (secondaryName.Equals(kvp.Value.PlayerName))
{
log.Trace($"{clientIdentifier} 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)
{
log.Trace($"{clientInfo.InternalId.CombinedString} ({player.GetDebugName()}) died but had not yet reached the configured LongTermMemoryLevel of {Config.LongTermMemoryLevel}");
log.Trace($"{clientIdentifier} died but had not yet reached the configured LongTermMemoryLevel of {Config.LongTermMemoryLevel}");
return true;
}

Expand Down
66 changes: 0 additions & 66 deletions src/Handlers/GameUpdate.cs

This file was deleted.

7 changes: 6 additions & 1 deletion src/ModApi.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
using Amnesia.Data;
using Amnesia.Handlers;
using HarmonyLib;
using System.Collections.Generic;
using System.Reflection;

namespace Amnesia
{
internal class ModApi : IModApi
{
public static bool DebugMode { get; set; } = false;
public static Dictionary<int, bool> Obituary { get; private set; } = new Dictionary<int, bool>();

public void InitMod(Mod _modInstance)
{
var harmony = new Harmony(GetType().ToString());
harmony.PatchAll(Assembly.GetExecutingAssembly());

ModEvents.GameStartDone.RegisterHandler(Config.Load);
ModEvents.GameUpdate.RegisterHandler(GameUpdate.Handle);
ModEvents.PlayerSpawnedInWorld.RegisterHandler(PlayerSpawnedInWorld.Handle);
ModEvents.GameMessage.RegisterHandler(GameMessage.Handle);
ModEvents.SavePlayerData.RegisterHandler(SavePlayerData.Handle);
Expand Down
54 changes: 54 additions & 0 deletions src/Patches/AIDirectorBloodMoonComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Amnesia.Data;
using Amnesia.Utilities;
using HarmonyLib;
using System;

namespace Amnesia.Patches
{
[HarmonyPatch(typeof(AIDirectorBloodMoonComponent), "StartBloodMoon")]
internal class AIDirectorBloodMoonComponent_StartBloodMoon_Patches
{
private static readonly ModLog<AIDirectorBloodMoonComponent_StartBloodMoon_Patches> _log = new ModLog<AIDirectorBloodMoonComponent_StartBloodMoon_Patches>();

public static void Postfix()
{
try
{
_log.Trace("Prefix: StartBloodMoon triggered");
var players = GameManager.Instance.World.Players.list;
for (var i = 0; i < players.Count; i++)
{
_ = players[i].Buffs.AddBuff(Values.BuffBloodmoonLifeProtection);
}
}
catch (Exception e)
{
_log.Error("Postfix", e);
}
}
}

[HarmonyPatch(typeof(AIDirectorBloodMoonComponent), "EndBloodMoon")]
internal class AIDirectorBloodMoonComponent_EndBloodMoon_Patches
{
private static readonly ModLog<AIDirectorBloodMoonComponent_EndBloodMoon_Patches> _log = new ModLog<AIDirectorBloodMoonComponent_EndBloodMoon_Patches>();

public static void Postfix()
{
try
{
_log.Trace("Prefix: EndBloodMoon triggered");
var players = GameManager.Instance.World.Players.list;
for (var i = 0; i < players.Count; i++)
{
_ = players[i].Buffs.AddBuff(Values.BuffPostBloodmoonLifeProtection);
players[i].Buffs.RemoveBuff(Values.BuffBloodmoonLifeProtection);
}
}
catch (Exception e)
{
_log.Error("Postfix", e);
}
}
}
}
Loading

0 comments on commit a1bb9d5

Please sign in to comment.