Skip to content

Commit

Permalink
Merge pull request #50 from jonathan-robertson/add-positive-boost
Browse files Browse the repository at this point in the history
World Impact (Experiment)
  • Loading branch information
jonathan-robertson authored Sep 27, 2022
2 parents 2d4e592 + e8f02f9 commit 09749ff
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 5 deletions.
1 change: 1 addition & 0 deletions Amnesia/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public void InitMod(Mod _modInstance) {
ModEvents.PlayerSpawnedInWorld.RegisterHandler(PlayerSpawnedInWorld.Handle);
ModEvents.GameMessage.RegisterHandler(GameMessage.Handle);
ModEvents.SavePlayerData.RegisterHandler(SavePlayerData.Handle);
ModEvents.EntityKilled.RegisterHandler(EntityKilled.Handle);
}
}
}
2 changes: 2 additions & 0 deletions Amnesia/Amnesia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@
<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" />
<Compile Include="Utilities\MessagingSystem.cs" />
<Compile Include="Utilities\ModLog.cs" />
<Compile Include="Utilities\PlayerHelper.cs" />
<Compile Include="Utilities\QuestHelper.cs" />
Expand Down
38 changes: 36 additions & 2 deletions Amnesia/Config/buffs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,50 @@
</effect_group>
</buff>

<!-- meant for admin testing only -->
<buff name="triggerAmnesiaPositiveOutlookLoss" hidden="true">
<duration value=".1" />
<effect_group>
<triggered_effect trigger="onSelfBuffStart" action="ModifyCVar" cvar="$positiveOutlookTime" operation="subtract" value="900" />
</effect_group>
</buff>

<!-- a reward given by admin... and/or for killing special zombies, perhaps -->
<buff name="triggerAmnesiaPositiveOutlookBoost" hidden="true">
<duration value="0" />
<effect_group>
<triggered_effect trigger="onSelfBuffStart" action="AddBuff" buff="buffAmnesiaPositiveOutlook" />
</effect_group>
</buff>

<buff name="buffAmnesiaPositiveOutlook" name_key="buffAmnesiaPositiveOutlookName" description_key="buffAmnesiaPositiveOutlookDesc" icon="ui_game_symbol_xp" icon_color="0,255,128" remove_on_death="false">
<duration value="0" />
<display_value value="$positiveOutlookTime" />
<display_value_format value="time" />

<effect_group name="startup">
<!-- TODO: consider setting to @amnesiaPositiveOutlookTime value instead and base this value off of... the level the player was able to achieve last? -->
<effect_group name="onStartup">
<requirement name="!HasBuff" buff="triggerAmnesiaPositiveOutlookBoost" />
<triggered_effect trigger="onSelfBuffStart" action="ModifyCVar" cvar="$positiveOutlookTime" operation="set" value="3600" />
</effect_group>
<effect_group name="onStack">
<requirement name="!HasBuff" buff="triggerAmnesiaPositiveOutlookBoost" />
<triggered_effect trigger="onSelfBuffStack" action="ModifyCVar" cvar="$positiveOutlookTime" operation="set" value="3600" />
</effect_group>

<effect_group name="applyBoostOnStartup">
<requirement name="HasBuff" buff="triggerAmnesiaPositiveOutlookBoost" />
<triggered_effect trigger="onSelfBuffStart" action="ModifyCVar" cvar="$positiveOutlookTime" operation="set" value="900" />
<triggered_effect trigger="onSelfBuffStart" action="RemoveBuff" buff="triggerAmnesiaPositiveOutlookBoost" />
</effect_group>
<effect_group name="applyBoostOnStack">
<requirement name="HasBuff" buff="triggerAmnesiaPositiveOutlookBoost" />
<triggered_effect trigger="onSelfBuffStack" action="ModifyCVar" cvar="$positiveOutlookTime" operation="add" value="900" />
<triggered_effect trigger="onSelfBuffStack" action="ModifyCVar" cvar="$positiveOutlookTime" operation="set" value="3600">
<requirement name="CVarCompare" cvar="$positiveOutlookTime" operation="GT" value="3600" />
</triggered_effect>
<triggered_effect trigger="onSelfBuffStack" action="RemoveBuff" buff="triggerAmnesiaPositiveOutlookBoost" />
</effect_group>

<effect_group name="activeEffects">
<!-- TODO: consider setting to @amnesiaPositiveOutlookXpBoost value instead and base this value off of... the level the player was able to achieve last? -->
<!-- 4x multiplier -->
Expand Down
30 changes: 30 additions & 0 deletions Amnesia/Handlers/EntityKilled.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Amnesia.Utilities;
using System;

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

internal static void Handle(Entity killedEntity, Entity killerEntity) {
try {
if (killerEntity.entityType != EntityType.Player) { return; }
switch (killedEntity.GetDebugName()) {
case "ZombieJuggernaut":
TriggerKillAnnouncementAndBonus(killerEntity.GetDebugName(), "[ff8000]Juggernaut");
break;
case "ZombieJuggernautGolden":
TriggerKillAnnouncementAndBonus(killerEntity.GetDebugName(), "[ffff00]Golden Juggernaut");
break;
}
} catch (Exception e) {
log.Error("HandleEntityKilled", e);
}
}

internal static void TriggerKillAnnouncementAndBonus(string playerName, string zombieName) {
MessagingSystem.Broadcast($"[007fff]{playerName} just killed a {zombieName}[007fff]!");
MessagingSystem.Broadcast($"[007fff]Relief washes over each survivor as a newfound confidence takes hold: [00ff80]all online players receive Double XP for 15 Minutes!");
GameManager.Instance.World.Players.list.ForEach(player => player.Buffs.AddBuff("triggerAmnesiaPositiveOutlookBoost"));
}
}
}
57 changes: 57 additions & 0 deletions Amnesia/Utilities/MessagingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace Amnesia.Utilities {
internal class MessagingSystem {

/**
* <summary>Send a private message to a specific player.</summary>
* <param name="message">The message to send.</param>
* <param name="recipients">The player entityId(s) this message is addressed to.</param>
*/
public static void Whisper(string message, params int[] recipients) {
Send(EChatType.Whisper, message, recipients.ToList());
}

/**
* <summary>Send a private message to a specific player.</summary>
* <param name="message">The message to send.</param>
* <param name="recipients">The player entityId(s) this message is addressed to.</param>
*/
public static void Whisper(string message, List<int> recipients) {
Send(EChatType.Whisper, message, recipients);
}

/**
* <summary>Send a message to all players.</summary>
* <param name="message">The message to send.</param>
*/
public static void Broadcast(string message) {
Send(EChatType.Global, message, GameManager.Instance.World.Players.list.Select(p => p.entityId).ToList());
}

/**
* <summary>Send a message to all players who match the given condition.</summary>
* <param name="message">The message to send.</param>
* <param name="condition">The condition determining whether the player will receive the given message.</param>
*/
public static void Broadcast(string message, Func<EntityPlayer, bool> condition) {
Send(EChatType.Global, message, GameManager.Instance.World.Players.list
.Where(condition)
.Select(p => p.entityId)
.ToList());
}

private static void Send(EChatType chatType, string message, List<int> recipients) {
GameManager.Instance.ChatMessageServer(
_cInfo: null,
_chatType: chatType,
_senderEntityId: -1,
_msg: message,
_mainName: "",
_localizeMain: false,
_recipientEntityIds: recipients);
}
}
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ 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).

## [0.9.0] - 2022-09-26

- add new positive outlook trigger buffs for admins
- add special surprise when defeating a tough zombie

## [0.8.1] - 2022-09-03

- fix post-bloodmoon grace period
Expand Down
Binary file modified LatestReleaseBuild/Amnesia.dll
Binary file not shown.
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="0.8.1" />
<Version value="0.9.0" />
<Website value="https://github.com/jonathan-robertson/amnesia" />
</ModInfo>
</xml>
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ForgetBooks | false | Whether books should be forgotten on memory loss. It's rec
ForgetSchematics | false | Whether schematics should be forgotten on memory loss. *It's recommended to keep this as `false` because A21 is expected to no longer grant crafting recipes when learning skills, so finding/using schematics will be the only way to learn how to craft things.* ***Note that `false` can cause some confusion in A20 because schematics will appear to have been read if the corresponding recipe was already unlocked in a Skill/Perk. The code for how this works is inside C# on the client's end, so changing it for a server-side mod does nto appear to be possible... but again, all the confusion will be gone in A21.***
ForgetKDR | false | Whether players/zombies killed and times died should be forgotten on memory loss. *I'd strongly recommend setting this to `true`, but have left it as `false` by default only because these metrics can't be recovered once wiped and some admins might not want them to reset for that reason.*

> :pencil: This mod is in progress, so plans for many more options are being worked on. As they're added and admins update their servers, the default values will be added for new options without negatively impacting the older options admins have already set.
> 📝 This mod is in progress, so plans for many more options are being worked on. As they're added and admins update their servers, the default values will be added for new options without negatively impacting the older options admins have already set.
### Experimental/Volatile Options

Expand Down Expand Up @@ -69,7 +69,7 @@ I want for there to be a way to keep maps/players in a 'healthy' state of play f

As an 7DTD admin and modder for a few years now, I've noticed some problematic patterns and this mod was created to take a stab at addressing some of them.

> :bar_chart: Progression is a core piece of any RPG. Once the opportunity to progress has faded or become convoluted, player engagement/enjoyment evaporates with time.
> 📊 Progression is a core piece of any RPG. Once the opportunity to progress has faded or become convoluted, player engagement/enjoyment evaporates with time.
Observation | Problem | How Amnesia attempts to address it
--- | --- | ---
Expand Down

0 comments on commit 09749ff

Please sign in to comment.