{"id":1278,"date":"2021-03-01T17:25:33","date_gmt":"2021-03-01T22:25:33","guid":{"rendered":"https:\/\/badecho.com\/?p=1278"},"modified":"2021-06-06T21:38:29","modified_gmt":"2021-06-07T02:38:29","slug":"apocalypse-system-adding-fatalis-debuff","status":"publish","type":"post","link":"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/","title":{"rendered":"Adding the Fatalis Debuff to the Apocalypse System"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"1024\" height=\"576\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/AddingFatalisDebuff-1024x576.png\" alt=\"Let's add a new timed debuff to the Apocalypse system that, when active, causes the player to be one shot!\" class=\"wp-image-1281\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/AddingFatalisDebuff-1024x576.png 1024w, https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/AddingFatalisDebuff-300x169.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/AddingFatalisDebuff-768x432.png 768w, https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/AddingFatalisDebuff-480x270.png 480w, https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/AddingFatalisDebuff.png 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>Prior to the creation of the <a href=\"https:\/\/badecho.com\/index.php\/2020\/10\/19\/apocalypse-system\/\" target=\"_blank\" rel=\"noreferrer noopener\">Apocalypse system<\/a>, <a href=\"https:\/\/badecho.com\/index.php\/what-is-omnified\/\" target=\"_blank\" rel=\"noreferrer noopener\">Omnified<\/a> games, for the most part, exercised a simple maxim: if you get hit, you die. Indeed, my very first Omnified hack was to kill the player dead whenever an enemy managed to inflict any damage at all. If I didn&#8217;t simply have some kill code go off when the player was struck, I&#8217;d achieve the same goal by multiplying all damage done by 69x, or by some other catchy number.<\/p>\n\n\n\n<h5>Then, one fateful eve&#8230;the Apocalypse system was born!<\/h5>\n\n\n\n<p>It was the result of me setting goals for myself to learn more and more for each game that I hacked. For every new game, I needed to do something a bit fancier; changes that relied on more complicated rules getting set up, as well as deeper and more complicated injections into code found through intensive sessions of reverse engineering.<\/p>\n\n\n\n<p>Now, ever since the Apocalypse was born, Omnified gameplay consists of random effects going off in response to the player receiving damage. Many of these effects can easily kill the character, but, more or less, there is technically a smaller chance we end up dying immediately from Apocalypse rules than when there was a simple &#8220;one hit == kill&#8221; hack implemented.<\/p>\n\n\n\n<p>Now, don&#8217;t get me wrong, I love the Apocalypse system, the kind of gameplay it offers is amazing and always keeps me on my toes. Still, I sometimes pine for the incredibly frantic days of old where I had to fear damage from <em>anything<\/em> killing me very dead in one hit. So, I started to think to myself: is there any way to enjoy the best of both worlds?<\/p>\n\n\n\n<p>And this line of thought inspired the latest addition to the Apocalypse system: the dreaded temporary status effect and malady known as <em><strong>Fatalis<\/strong><\/em>.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_11 counter-hierarchy counter-decimal ez-toc-grey\">\r\n<div class=\"ez-toc-title-container\">\r\n<p class=\"ez-toc-title\">Table of Contents<\/p>\r\n<span class=\"ez-toc-title-toggle\"><a class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\"><i class=\"ez-toc-glyphicon ez-toc-icon-toggle\"><\/i><\/a><\/span><\/div>\r\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Mechanics_of_Fatalis\" title=\"Mechanics of Fatalis\">Mechanics of Fatalis<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Fatalis_How_It%E2%80%99s_Applied,_Its_Effects,_and_Lifetime\" title=\"Fatalis: How It&#8217;s Applied, Its Effects, and Lifetime\">Fatalis: How It&#8217;s Applied, Its Effects, and Lifetime<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Changes_to_the_Omnified_Framework_Library\" title=\"Changes to the Omnified Framework Library\">Changes to the Omnified Framework Library<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Apocalypse_Assembly_Function_Changes\" title=\"Apocalypse Assembly Function Changes\">Apocalypse Assembly Function Changes<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Player_Apocalypse_Code_%E2%80%93_New_Symbols\" title=\"Player Apocalypse Code &#8211; New Symbols\">Player Apocalypse Code &#8211; New Symbols<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Player_Apocalypse_Code_%E2%80%93_Fatalis_Death_Dealin%E2%80%99\" title=\"Player Apocalypse Code &#8211; Fatalis Death Dealin&#8217;\">Player Apocalypse Code &#8211; Fatalis Death Dealin&#8217;<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Player_Apocalypse_Code_%E2%80%93_Fatalis_Affliction\" title=\"Player Apocalypse Code &#8211; Fatalis Affliction\">Player Apocalypse Code &#8211; Fatalis Affliction<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Player_Apocalypse_Code_%E2%80%93_Fatalis_Symbol_Defaults\" title=\"Player Apocalypse Code &#8211; Fatalis Symbol Defaults\">Player Apocalypse Code &#8211; Fatalis Symbol Defaults<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Omnified_LUA_Changes\" title=\"Omnified LUA Changes\">Omnified LUA Changes<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Omnified_Registration_Code_%E2%80%93_Fatalis_Timers\" title=\"Omnified Registration Code &#8211; Fatalis Timers\">Omnified Registration Code &#8211; Fatalis Timers<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Omnified_Cleanup_Code_%E2%80%93_Fatalis_Timers\" title=\"Omnified Cleanup Code &#8211; Fatalis Timers\">Omnified Cleanup Code &#8211; Fatalis Timers<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Omnified_Display_LUA_Changes\" title=\"Omnified Display LUA Changes\">Omnified Display LUA Changes<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Apocalypse_Log_Display_Code_%E2%80%93_Fatalis_Death\" title=\"Apocalypse Log Display Code &#8211; Fatalis Death\">Apocalypse Log Display Code &#8211; Fatalis Death<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Apocalypse_Log_Display_Code_%E2%80%93_Fatalis_Affliction\" title=\"Apocalypse Log Display Code &#8211; Fatalis Affliction\">Apocalypse Log Display Code &#8211; Fatalis Affliction<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#Apocalypse_Log_Display_Code_%E2%80%93_Fatalis_Cured\" title=\"Apocalypse Log Display Code &#8211; Fatalis Cured\">Apocalypse Log Display Code &#8211; Fatalis Cured<\/a><\/li><\/ul><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#That%E2%80%99s_It!_Looking_Forward_to_the_Fun\" title=\"That&#8217;s It! Looking Forward to the Fun.\">That&#8217;s It! Looking Forward to the Fun.<\/a><\/li><\/ul><\/nav><\/div>\r\n<h2><span class=\"ez-toc-section\" id=\"Mechanics_of_Fatalis\"><\/span>Mechanics of Fatalis<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Fatalis is a status effect that, when active on the player, will result in all damage done to the player resulting in immediate and irrevocable death. Through magical and mysterious means, this status effect persists across deaths, and only dissipates after a certain period of time has elapsed. In a sense, the Fatalis status effect is a temporary &#8220;one-hit kill&#8221; mode.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"635\" height=\"510\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/DeadPlayer.png\" alt=\"Shows the player character, either sleeping soundly in the grass, or very dead.\" class=\"wp-image-1282\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/DeadPlayer.png 635w, https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/DeadPlayer-300x241.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/DeadPlayer-480x386.png 480w\" sizes=\"(max-width: 635px) 100vw, 635px\" \/><figcaption>Here in the Omnified world, we work hard to kill the player as much as possible.<\/figcaption><\/figure><\/div>\n\n\n\n<p>By adding Fatalis to Apocalypse, it basically allows for the gameplay to be able to shift to the terrifying old school Omnified one-hit-and-you-dead mechanics at the drop of a dime. So, I get to enjoy the structured randomness of the Apocalypse system, and whenever that randomness happens to fall on the tiny chance of afflicting us with Fatalis, I get to enjoy the original whirlpool of murderous one-shot mayhem.<\/p>\n\n\n\n<h5>And although it&#8217;s going to be lots of fun, Fatalis afflictions should be a rare occurrence.<\/h5>\n\n\n\n<p>All of Apocalypse&#8217;s random effects go off in response to the results of various &#8220;dice&#8221; rolls. It is very much on purpose that the whole theme of Apocalypse reeks a bit of the rolls of dice that happen during a D&amp;D game. Currently, the majority of the effects that go off are based on the rolls of a ten sided die and a five sided die. Simply adding another side to the dice and sticking Fatalis on that side would not do, as the probability of it coming up would be far too common.<\/p>\n\n\n\n<p>Instead, we&#8217;ll be adding a chance for Fatalis to go off in conjunction with another effect occurring; ideally, a benign effect that doesn&#8217;t do much on its own. When this benign effect goes off, we then do a many-sided die roll that will result in Fatalis if the roll results in one specific number coming up. Let&#8217;s now look at a listing of all the mechanics related to Fatalis, including how it is applied and when it dissipates.<\/p>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Fatalis_How_It%E2%80%99s_Applied,_Its_Effects,_and_Lifetime\"><\/span>Fatalis: How It&#8217;s Applied, Its Effects, and Lifetime<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ol><li>If Apocalypse&#8217;s primary dice roll results in values 7, 8, or 9, a Risk of Murder roll occurs.<\/li><li>If the Risk of Murder roll results in a 4 or 5, the player is sixty nined, and is pretty much screwed right there. However, if the player lucks out and it lands on a 1, 2, or 3, normal damage is applied instead.<\/li><li>This &#8220;normal damage&#8221; effect is quite benign! Therefore, it is a great place to do the check for whether or not Fatalis is getting applied. At this point in time then, we will roll a many-sided die, and if it results in the highest possible number, the player now has Fatalis.<\/li><li>An appropriate sound effect will go off heralding the player being afflicted with Fatalis, and a notification will be logged in the Apocalypse event log informing all viewers of this fact as well.<\/li><li>For the next ten minutes (or whatever we set the duration to in the end), every time the player is hit, the player is immediately killed instead of normal Apocalypse rolls going off. These instant deaths should be accompanied with their own sound effect as well, along with a notification about this instant death also appearing in the event log.<\/li><li>After the Fatalis effect has expired, a final, very cheery and positive sound effect will go off announcing the end of the suffering, along with a notification in the event log regarding the Fatalis debuff being cured. Normal Apocalypse operation resumes.<\/li><\/ol>\n\n\n\n<p>The above list basically describes everything we need the Fatalis debuff to do. When we get afflicted with it, we die in one hit. After some time, it goes away and things go back to normal.<\/p>\n\n\n\n<h5>This is the first time I&#8217;ve ever added a timed status effect to Omnified code.<\/h5>\n\n\n\n<p>And hopefully it&#8217;ll be the first of many. Very excited. Let&#8217;s get to work on implementing it now then.<\/p>\n\n\n\n<h2><span class=\"ez-toc-section\" id=\"Changes_to_the_Omnified_Framework_Library\"><\/span>Changes to the Omnified Framework Library<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Game-neutral code for my Omnified systems can be found in the Omnified framework library file: <strong>Omnified.lua<\/strong>. At the time of writing, I don&#8217;t have my Omnified hacking code uploaded to the <a href=\"https:\/\/github.com\/BadEcho\/core\" target=\"_blank\" rel=\"noreferrer noopener\">Bad Echo source repository<\/a>, but I will make sure I do so not long after publishing this. <\/p>\n\n\n\n<p>This file contains all the game-neutral assembly code as well as LUA functions needed in order to bring it to life. I&#8217;ll be writing a nice little article about why I have it all packaged in a LUA file as well, so stay tuned for that. <\/p>\n\n\n\n<p>We&#8217;re going to need to do a few things in order to get Fatalis implemented:<\/p>\n\n\n\n<ol><li>Add the new Fatalis dice roll mechanics in the assembly function <code>executePlayerApocalypse<\/code>.<\/li><li>Add a means to monitor for status effects and remove them upon their expiration in the LUA initialization routine of the Omnified framework.<\/li><li>Add new display logic regarding Fatalis to the Omnified display routines found in <strong>OmnifiedDisplay.lua<\/strong>.<\/li><\/ol>\n\n\n\n<p>Let&#8217;s start with the assembly changes.<\/p>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Apocalypse_Assembly_Function_Changes\"><\/span>Apocalypse Assembly Function Changes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>All of our changes will be occurring to the Player Apocalypse Function. First, we&#8217;ll need to add a few new symbols.<\/p>\n\n\n\n<h4><span class=\"ez-toc-section\" id=\"Player_Apocalypse_Code_%E2%80%93_New_Symbols\"><\/span>Player Apocalypse Code &#8211; New Symbols<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nalloc(fatalisResult,8)\nalloc(fatalisResultUpper,8)\nalloc(fatalisResultLower,8)\n\/\/ fatalisState: 0 = not active; 1 = active; 2 = cured (used for announcement, then set to 0)\nalloc(fatalisState,8)\n\/\/ The rest of the symbol allocations follows...\n\/\/ ...and then we register some of our new symbols.\nregistersymbol(fatalisResult)\nregistersymbol(fatalisResultUpper)\nregistersymbol(fatalisState)\n<\/pre>\n\n\n<p>We create a number of new symbols here. The first three deal with the random number generation involved when checking for Fatalis affliction, and the last new symbol deals with the current state of Fatalis affliction. The dice roll result and state are both made public here as it we need to inspect their values from outside of the assembly code. <\/p>\n\n\n\n<p>The upper limit on the Fatalis dice roll is also public because that is the value that determines whether or not it actually ends up getting applied, so it will be useful to the display-related functions in determining whether we need to make an announcement or not.<\/p>\n\n\n\n<p>Next up we&#8217;ll modify the part of the Apocalypse function found right before the primary dice roll. If the player has the Fatalis debuff, we will kill them right then and there and forego the rest of the normal dice rollings.<\/p>\n\n\n\n<h4><span class=\"ez-toc-section\" id=\"Player_Apocalypse_Code_%E2%80%93_Fatalis_Death_Dealin%E2%80%99\"><\/span>Player Apocalypse Code &#8211; Fatalis Death Dealin&#8217;<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\napplyApocalypse:\n  \/\/ If the player has the Fatalis debuff, all damage is fatal.\n  cmp [fatalisState],1\n  jne applyApocalypseRoll\n  \/\/ To make good on the Fatalis debuff, we set the damage equal to the health.\n  movss xmm0,xmm3\n  jmp updateEnemyDamageStats\napplyApocalypseRoll:\n  \/\/ Load the parameters for generating the dice roll random number.\n  push [apocalypseResultLower]\n  push [apocalypseResultUpper]\n  mov rax,playerApocalypseRandomState\n  push rax\n  call generateRandomNumber\n<\/pre>\n\n\n<p>If the <code>fatalisState<\/code> symbol is 1, then it is game over man.<\/p>\n\n\n\n<p>We now need to write the code that will actually apply the affliction. We stated earlier that we were going to attach the roll to check for Fatalis in the event that a &#8220;normal damage&#8221; Risk of Murder effect occurs, so let&#8217;s insert some new instructions there.<\/p>\n\n\n\n<h4><span class=\"ez-toc-section\" id=\"Player_Apocalypse_Code_%E2%80%93_Fatalis_Affliction\"><\/span>Player Apocalypse Code &#8211; Fatalis Affliction<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nriskOfMurder:\n  \/\/ Load the parameters for generating the Risk of Murder dice roll random \n  \/\/ number.\n  push [riskOfMurderResultLower]\n  push [riskOfMurderResultUpper]\n  mov rax,playerApocalypseRandomState\n  push rax\n  call generateRandomNumber\n  \/\/ Our Risk of Murder roll is in eax -- we back it up to the &quot;riskOfMurderResult&quot; \n  \/\/ symbol so that the value can be displayed by the event logging display code.\n  mov [riskOfMurderResult],eax\n  cmp eax,3\n  \/\/ If the resulting roll is 4 or 5, then the player is getting sixty nined.\n  jg sixtyNine\n  \/\/ Otherwise, normal damage applies, however there is also now a very slight chance\n  \/\/ of Fatalis being applied, but only if it is not already active.  \n  cmp [fatalisState],1\n  je updateEnemyDamageStats\n  push [fatalisResultLower]\n  push [fatalisResultUpper]\n  mov rax,playerApocalypseRandomState\n  push rax\n  call generateRandomNumber\n  \/\/ The Fatalis roll is in eax -- we throw it into the &quot;fatalisResult&quot; symbol\n  \/\/ so we can report on it.\n  mov [fatalisResult],eax\n  \/\/ Fatalis will only be applied if the roll landed on the maximum possible value.\n  cmp eax,[fatalisResultUpper]\n  jne updateEnemyDamageStats\n  mov [fatalisState],1\n  jmp updateEnemyDamageStats  \n<\/pre>\n\n\n<p>The above is the existing Risk of Murder code coupled with some new random number generation instructions purposed to check for whether or not the player is now afflicted with Fatalis.<\/p>\n\n\n\n<p>And that&#8217;s pretty much it for the assembly side of things. We&#8217;ll just need to define some defaults for our new symbols&#8230;<\/p>\n\n\n\n<h4><span class=\"ez-toc-section\" id=\"Player_Apocalypse_Code_%E2%80%93_Fatalis_Symbol_Defaults\"><\/span>Player Apocalypse Code &#8211; Fatalis Symbol Defaults<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nfatalisResult:\n  dd 0\n  \nfatalisResultUpper:\n  dd 5\n  \nfatalisResultLower:\n  dd 1\n  \nfatalisState:\n  dd 0\n<\/pre>\n\n\n<p>So, as it stands now, the probability that Fatalis is applied is a 1 in 5 chance upon a &#8220;normal effect&#8221; Risk of Murder roll occurring. I settled on using this particular probability by thinking through all the various rolls in play in order for a Fatalis affliction to occur:<\/p>\n\n\n\n<ul><li>Every time we&#8217;re hit, there&#8217;s a 30% chance a Risk of Murder roll happens (10 sided die, value landing on 7, 8, or 9).<\/li><li>With a Risk of Murder roll, there&#8217;s a 60% chance of normal damage occurring (5 sided die, value landing on 1, 2, or 3).<\/li><li>Taking that into account, we can then say that every time we&#8217;re hit, there is an 18% chance that Fatalis might get applied to the player.<\/li><li>Given that there&#8217;s a 1 in 5 chance that Fatalis might be applied when we&#8217;re checking for it, coupled with an 18% chance for the check, we can say that there&#8217;s a 3.6% chance that an attack done to the player will result in Fatalis.<\/li><\/ul>\n\n\n\n<p>I&#8217;d like the effect to be frequent enough that I get it perhaps a few times per stream, but not so frequent that gameplay becomes wall-to-wall Fatalis sessions. I think 3.6% of all attacks is a good probability to satisfy this desire, but in the event I&#8217;m wrong, I&#8217;ll be tweaking the value as we go!<\/p>\n\n\n\n<p>Now that we have the &#8220;meat&#8221; of the matter inserted into our core assembly code, we&#8217;re going to need to now build up a monitoring system that will check for the Fatalis affliction and &#8220;cure&#8221; the player at the appropriate time.<\/p>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Omnified_LUA_Changes\"><\/span>Omnified LUA Changes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Up until now, we&#8217;ve never engaged in any kind of &#8220;timed effects&#8221; with Omnified hackery. We need some way to establish a system of monitoring for and making good the expiration of these timed buffs and debuffs. I have many plans for the future where we&#8217;ll be adding a whole slew of additional timed status effects, with a bunch of visual indications of their state to boot, so it is good that we&#8217;re starting to create some kind of infrastructure for them now.<\/p>\n\n\n\n<p>In order to monitor and manage status effects, we&#8217;re going to need to make use of one or more timers that will be constantly checking the state of the player, changing the relevant bits at the appointed time of said effects&#8217; expiration. The best place to initialize and use these higher level constructs is outside of the scary realm of assembly and in the less mind-numbingly complex land of LUA.<\/p>\n\n\n\n<p>In <strong>Omnified.lua<\/strong>, we have several registration and unregistration methods responsible for injecting and uninjecting the assembly code from the target process in memory. After we successfully inject our code into the process, we&#8217;ll want to then create the status effect timers. Conversely, when we uninject our assembly code from the process, we&#8217;ll want to clean up these timers.<\/p>\n\n\n\n<h4><span class=\"ez-toc-section\" id=\"Omnified_Registration_Code_%E2%80%93_Fatalis_Timers\"><\/span>Omnified Registration Code &#8211; Fatalis Timers<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<pre class=\"brush: lua; title: ; notranslate\" title=\"\">\nfunction registerOmnification()\n\tif registered == false then\n\t\tregistered, disableInfo = autoAssemble(omnifiedAssembly)\n\t\t\n\t\tif registered == false then\n\t\t\tprint(&quot;Failed to register Omnification.&quot;)\n\t\t\tdo return end\n\t\tend\n\t\t\n\t\tif statusTimer == nil then\n\t\t\tstatusTimer = createTimer(getMainForm())\n\t\tend\n\t\t\n\t\tstatusTimer.Interval = 400\n\t\tstatusTimer.OnTimer = function()\n\t\t\tlocal fatalisState \n\t\t\t\t= readInteger(&quot;fatalisState&quot;)\n\t\t\t\t\n\t\t\tif fatalisState == 1 and fatalisTimer == nil then\n\t\t\t\tfatalisTimer = createTimer(getMainForm())\n\t\t\t\tfatalisTimer.Interval = 600000\n\t\t\t\tfatalisTimer.OnTimer = function()\n\t\t\t\t\twriteInteger(&quot;fatalisState&quot;,2)\t\t\n\t\t\t\t\t\n\t\t\t\t\tfatalisTimer.Enabled = false\n\t\t\t\t\tfatalisTimer.Destroy()\n\t\t\t\t\tfatalisTimer = nil\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\nend\n<\/pre>\n\n\n<p>By setting <code>fatalisState<\/code> to 2 the player will no longer be instantly murdered by damage from an enemy, as it must equal 1 in order for that to happen. The display logic will then detect the state has been changed to 2 and will make an announcement saying that the player is cured before finally setting it to 0.<\/p>\n\n\n\n<p>As it stands, the duration of the Fatalis debuff (essentially defined by the <code>fatalisTimer<\/code> interval) is hardcoded at 10 minutes. I will probably make this a value that can be changed more easily from code in the future.<\/p>\n\n\n\n<p>And then here is our updated cleanup code.<\/p>\n\n\n\n<h4><span class=\"ez-toc-section\" id=\"Omnified_Cleanup_Code_%E2%80%93_Fatalis_Timers\"><\/span>Omnified Cleanup Code &#8211; Fatalis Timers<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<pre class=\"brush: lua; title: ; notranslate\" title=\"\">\nfunction unregisterOmnification()\n\tif registered == true and disableInfo ~= nil then\n\t\tlocal disabled = autoAssemble(omnifiedDisableAssembly, disableInfo)\n\t\t\n\t\tif disabled == false then\n\t\t\tprint(&quot;Failed to uninject.&quot;)\n\t\telse \n\t\t\tregistered = false\n\t\t\t\n\t\t\tif statusTimer ~= nil then\n\t\t\t\tif fatalisTimer ~= nil then\n\t\t\t\t\tfatalisTimer.Enabled = false\n\t\t\t\t\tfatalisTimer.Destroy()\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\tstatusTimer.Enabled = false\n\t\t\t\tstatusTimer.Destroy()\n\t\t\t\tstatusTimer = nil\n\t\t\tend\n\t\tend\t\t\n\telse \n\t\tprint(&quot;Nothing to unregister.&quot;)\n\tend\nend\n<\/pre>\n\n\n<p>There we have it. This is where all of our status timers will probably go, albeit I&#8217;ll probably add a level of organization to it that pleases me first. I&#8217;m still learning LUA, so bear with me until I have it mastered!<\/p>\n\n\n\n<p>We&#8217;re almost done. We now need to update the display library found in <strong>OmnifiedDisplay.lua<\/strong> to inform the audience about the changes and effects of the Fatalis affliction.<\/p>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Omnified_Display_LUA_Changes\"><\/span>Omnified Display LUA Changes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>I haven&#8217;t published much about the internal workings of <strong>OmnifiedDisplay.lua<\/strong> before, mainly because it will probably get a very proper refactoring along the time I have completed work on my <em>Vision<\/em> product (an Omnified technology in the form of comprehensive screen overlay software that displays all the extracted data pertinent to the Omnified experience).<\/p>\n\n\n\n<p>But, since we&#8217;re writing about adding the Fatalis debuff, I&#8217;ll just include the sections that need to be modified. First, we need to be able to detect and tell the audience when the player has just been one-shot due to Fatalis.<\/p>\n\n\n\n<h4><span class=\"ez-toc-section\" id=\"Apocalypse_Log_Display_Code_%E2%80%93_Fatalis_Death\"><\/span>Apocalypse Log Display Code &#8211; Fatalis Death<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<pre class=\"brush: lua; title: ; notranslate\" title=\"\">\nif logApocalypse == 1 and apocalypseResult ~= nil\n\t\t\t\t\t  and lastDamageToPlayer ~= nil\n\t\t\t\t\t  and playerHealth ~= nil\n\t\t\t\t\t  and timestamp ~= nil\n\t\t\t\t\t  and extraDamageX ~= nil\n\t\t\t\t\t  and fatalisResult ~= nil\n\t\t\t\t\t  and fatalisResultUpper ~= nil\n\t\t\t\t\t  and fatalisState ~= nil\n\t\t\t\t\t  then\n\n\tif fatalisState == 1 and fatalisResult == 0 then\n\t\tlog:write(timestamp, &quot;The player, afflicted with Fatalis, dies immediately from the enemy attack!\\n&quot;)\n\t\tplaySound(findTableFile('fatalisDeath.wav'))\t\t\t\t\t\t\n\telse\n\t\t-- The normal display logic follows.\n\t\tlocal apocalypseEnemyRoll =\n\t\t\tstring.format(&quot;%s%s %i: &quot;, timestamp,\n\t\t\t\t\t\t\t\t\t   logEntryEnemyRoll,\n\t\t\t\t\t\t\t\t\t   apocalypseResult)\n<\/pre>\n\n\n<p>If <code>fatalisState<\/code> is equal to 1 (indicating we have Fatalis) but <code>fatalisResult<\/code> is not 0, that means we <em>just<\/em> became afflicted with the status malady as the result of an Apocalypse roll. In order for <code>fatalisState<\/code> to become set to 1, a <code>fatalisResult<\/code> must have been rolled equal to the maximum possible number. We actually don&#8217;t want to kill the player with the same blow that gave them the Fatalis, we want the next attack to do it.<\/p>\n\n\n\n<p>Once <code>fatalisState<\/code> is 1, no more Apocalypse rolls happens, only instant death. That means the onus on resetting <code>fatalisResult<\/code> to 0 is on us, outside of the assembly, and the perfect place to do it is when announcing the player has become afflicted.<\/p>\n\n\n\n<h4><span class=\"ez-toc-section\" id=\"Apocalypse_Log_Display_Code_%E2%80%93_Fatalis_Affliction\"><\/span>Apocalypse Log Display Code &#8211; Fatalis Affliction<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<pre class=\"brush: lua; title: ; notranslate\" title=\"\">\nif riskOfMurderResult &lt;= 3 then\n\tlog:write(riskOfMurderEnemyRoll,\n\t\t\t  &quot;WHEW! Just normal damage causing &quot;,\n\t\t\t  apocalypseDamagedHealth)\n\tif fatalisResult == fatalisResultUpper then\n\t\tlog:write(timestamp, &quot;Unfortunately the player has been stricken with Fatalis for the next ten minutes...\\n&quot;)\t\t\t\t\t\t\n\t\tplaySound(findTableFile('fatalisAfflication.wav'))\n\t\twriteInteger(&quot;fatalisResult&quot;,0)\n\tend\t\t\t\t\t\t\t\t  \nelse\n\t-- The remaining possible effects are logged below.\n<\/pre>\n\n\n<p>Remember, Fatalis affliction occurs when we get normal damage from a Risk of Murder roll. So, that&#8217;s where we insert the logic to announce that the player has acquired it. As you&#8217;ll notice in this example and the one above, we not only log the event to the display log, but also play some sounds for the event as well. Sounds that I think will be thought as quite funny, I hope!<\/p>\n\n\n\n<p>The remaining thing to do is to announce the player being cured from Fatalis. This actually occurs outside of this particular section of code (which only goes off when the player has been damaged), and is in fact right above it, and will execute independently from anything else.<\/p>\n\n\n\n<h4><span class=\"ez-toc-section\" id=\"Apocalypse_Log_Display_Code_%E2%80%93_Fatalis_Cured\"><\/span>Apocalypse Log Display Code &#8211; Fatalis Cured<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<pre class=\"brush: lua; title: ; notranslate\" title=\"\">\nif fatalisState == 2 then\n\tlog:write(timestamp, &quot;Miraculously, the player has been cured of Fatalis!&quot;)\n\tplaySound(findTableFile('fatalisCured.wav'))\n\twriteInteger(&quot;fatalisState&quot;, 0)\nend\n<\/pre>\n\n\n<p>Very simple. We detect the cured state by check for a value of 2, and then reset the state to 0 once we announce the event via text and audio.<\/p>\n\n\n\n<h2><span class=\"ez-toc-section\" id=\"That%E2%80%99s_It!_Looking_Forward_to_the_Fun\"><\/span>That&#8217;s It! Looking Forward to the Fun.<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The Fatalis debuff has come alive.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"924\" height=\"144\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/FatalisExample.png\" alt=\"Shows the new Fatalis related events in the Apocalypse event log.\" class=\"wp-image-1283\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/FatalisExample.png 924w, https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/FatalisExample-300x47.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/FatalisExample-768x120.png 768w, https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/FatalisExample-480x75.png 480w\" sizes=\"(max-width: 924px) 100vw, 924px\" \/><figcaption>Catching the Fatalis debuff, dying from it, and being cured from it are all displayed in the event log.<\/figcaption><\/figure>\n\n\n\n<p>To see the code in its entirety, know that I will soon relocate my &#8220;hackspace&#8221; to a source control folder, and all that work will start showing up on my <a href=\"https:\/\/github.com\/BadEcho\/core\" target=\"_blank\" rel=\"noreferrer noopener\">Bad Echo source repo<\/a>. I&#8217;ll also be updating the <a href=\"https:\/\/badecho.com\/index.php\/2020\/10\/19\/apocalypse-system\/\" target=\"_blank\" rel=\"noreferrer noopener\">original Apocalypse article<\/a> to include these changes, sometime in the future.<\/p>\n\n\n\n<p>As for what sounds I&#8217;m using for the new effects, you&#8217;ll have to tune in on my <a href=\"https:\/\/twitch.tv\/omni\" target=\"_blank\" rel=\"noreferrer noopener\">Twitch stream<\/a> to find out! I&#8217;ll be showcasing it during my very next stream, so check out my <a href=\"https:\/\/badecho.com\/index.php\/2021\/02\/07\/stream-schedule-2021\/\" target=\"_blank\" rel=\"noreferrer noopener\">current schedule<\/a> to know when that will be. And, as always, feel free to join the strange Omni community on my <a href=\"https:\/\/discord.gg\/omni\" target=\"_blank\" rel=\"noreferrer noopener\">Discord<\/a>.<\/p>\n\n\n\n<p>Until next time, thank you for your interest and your time! Have a good one.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prior to the creation of the Apocalypse system, Omnified games, for the most part, exercised a simple maxim: if you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[26,29,24,28],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>Adding the Fatalis Debuff to the Apocalypse System - omni&#039;s hackpad<\/title>\r\n<meta name=\"description\" content=\"Shows how I added a new effect to the Apocalypse system, this one being a timed debuff that results in the player getting one-shot.\" \/>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"Adding the Fatalis Debuff to the Apocalypse System - omni&#039;s hackpad\" \/>\r\n<meta property=\"og:description\" content=\"Shows how I added a new effect to the Apocalypse system, this one being a timed debuff that results in the player getting one-shot.\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/\" \/>\r\n<meta property=\"og:site_name\" content=\"omni&#039;s hackpad\" \/>\r\n<meta property=\"article:published_time\" content=\"2021-03-01T22:25:33+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2021-06-07T02:38:29+00:00\" \/>\r\n<meta property=\"og:image\" content=\"https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/AddingFatalisDebuff-1024x576.png\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/badecho.com\/#website\",\"url\":\"https:\/\/badecho.com\/\",\"name\":\"omni&#039;s hackpad\",\"description\":\"Game Code Disassembly. Omnified Modification. Madness.\",\"publisher\":{\"@id\":\"https:\/\/badecho.com\/#\/schema\/person\/3de67496328be7ae6e1f52faf582e9d2\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/badecho.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/badecho.com\/wp-content\/uploads\/2021\/02\/AddingFatalisDebuff.png\",\"width\":1200,\"height\":675,\"caption\":\"Let's add a new timed debuff to the Apocalypse system that, when active, causes the player to be one shot!\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#webpage\",\"url\":\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/\",\"name\":\"Adding the Fatalis Debuff to the Apocalypse System - omni&#039;s hackpad\",\"isPartOf\":{\"@id\":\"https:\/\/badecho.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#primaryimage\"},\"datePublished\":\"2021-03-01T22:25:33+00:00\",\"dateModified\":\"2021-06-07T02:38:29+00:00\",\"description\":\"Shows how I added a new effect to the Apocalypse system, this one being a timed debuff that results in the player getting one-shot.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/\"]}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#webpage\"},\"author\":{\"@id\":\"https:\/\/badecho.com\/#\/schema\/person\/3de67496328be7ae6e1f52faf582e9d2\"},\"headline\":\"Adding the Fatalis Debuff to the Apocalypse System\",\"datePublished\":\"2021-03-01T22:25:33+00:00\",\"dateModified\":\"2021-06-07T02:38:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#webpage\"},\"publisher\":{\"@id\":\"https:\/\/badecho.com\/#\/schema\/person\/3de67496328be7ae6e1f52faf582e9d2\"},\"image\":{\"@id\":\"https:\/\/badecho.com\/index.php\/2021\/03\/01\/apocalypse-system-adding-fatalis-debuff\/#primaryimage\"},\"keywords\":\"Apocalypse,Design,Hacking,Omnified\",\"articleSection\":\"Omnified Design\",\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/badecho.com\/#\/schema\/person\/3de67496328be7ae6e1f52faf582e9d2\",\"name\":\"Matt Weber\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/badecho.com\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7e345ac2708b3a41c7bd70a4a0440d41?s=96&d=mm&r=g\",\"caption\":\"Matt Weber\"},\"logo\":{\"@id\":\"https:\/\/badecho.com\/#personlogo\"}}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/posts\/1278"}],"collection":[{"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/comments?post=1278"}],"version-history":[{"count":22,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/posts\/1278\/revisions"}],"predecessor-version":[{"id":1328,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/posts\/1278\/revisions\/1328"}],"wp:attachment":[{"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/media?parent=1278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/categories?post=1278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/tags?post=1278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}