Skip to content

Commit

Permalink
feat(port,content): Day and Night, Dusk and Dawn for enchantment cond…
Browse files Browse the repository at this point in the history
…itions (#5871)

* initial commit

* test cases

* adds DUSK and DAWN conditions too

* Update enchantments.json

* style(autofix.ci): automated formatting

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
Zlorthishen and autofix-ci[bot] authored Jan 4, 2025
1 parent 67d2843 commit 27ef8b0
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
42 changes: 42 additions & 0 deletions data/mods/Magiclysm/effects/enchantments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"id": "ench_overcharge_burn_scar",
"type": "enchantment",
"ench_effects": [ { "effect": "burn_scar", "intensity": 1 } ]
},
{
"id": "ench_windrun",
"type": "enchantment",
"has": "WORN",
"ench_effects": [ { "effect": "enchant_windrun", "intensity": 1 } ],
"values": [ { "value": "MOVE_COST", "multiply": -0.25 } ]
},
{
"id": "ench_test_night",
"type": "enchantment",
"has": "WORN",
"condition": "NIGHT",
"values": [ { "value": "PERCEPTION", "multiply": 10 } ]
},
{
"id": "ench_test_day",
"type": "enchantment",
"has": "WORN",
"condition": "DAY",
"values": [ { "value": "STRENGTH", "multiply": 10 } ]
},
{
"id": "ench_test_dawn",
"type": "enchantment",
"has": "WORN",
"condition": "DAWN",
"values": [ { "value": "DEXTERITY", "multiply": 10 } ]
},
{
"id": "ench_test_dusk",
"type": "enchantment",
"has": "WORN",
"condition": "DUSK",
"values": [ { "value": "INTELLIGENCE", "multiply": 10 } ]
}
]
22 changes: 22 additions & 0 deletions data/mods/Magiclysm/items/armor.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,27 @@
"volume": "150 L",
"material_thickness": 6,
"environmental_protection": 8
},
{
"id": "helmet_testNight",
"copy-from": "helmet_chitin",
"type": "ARMOR",
"name": { "str": "Night testing Helmet" },
"description": "I can see EVERYTHING!",
"material": [ "demon_chitin" ],
"proportional": { "weight": 0.9, "encumbrance": 0.9, "price": 10, "warmth": 2 },
"relic_data": { "passive_effects": [ { "id": "ench_test_night" }, { "id": "ench_test_dawn" } ] },
"environmental_protection": 8
},
{
"id": "gauntlets_testDay",
"copy-from": "gauntlets_chitin",
"type": "ARMOR",
"name": { "str": "pair of Day Testing gauntlets" },
"description": "Super strong so long as the sun's on!",
"material": [ "demon_chitin" ],
"proportional": { "weight": 0.9, "encumbrance": 0.9, "price": 10, "warmth": 2 },
"relic_data": { "passive_effects": [ { "id": "ench_test_day" }, { "id": "ench_test_dusk" } ] },
"environmental_protection": 8
}
]
4 changes: 4 additions & 0 deletions doc/src/content/docs/en/mod/json/reference/creatures/magic.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ Values:
- `ALWAYS` (default) - Always active
- `UNDERGROUND` - When the owner of the item is below Z-level 0
- `UNDERWATER` - When the owner is in swimmable terrain
- `NIGHT` - When it is night time
- `DUSK` - When it is dusk
- `DAY` - When it is day time
- `DAWN` - When it is dawn
- `ACTIVE` - whenever the item, mutation, bionic, or whatever the enchantment is attached to is
active.

Expand Down
21 changes: 21 additions & 0 deletions src/magic_enchantment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <set>

#include "bodypart.h"
#include "calendar.h"
#include "character.h"
#include "creature.h"
#include "debug.h"
Expand Down Expand Up @@ -60,6 +61,10 @@ namespace io
case enchantment::condition::ALWAYS: return "ALWAYS";
case enchantment::condition::UNDERGROUND: return "UNDERGROUND";
case enchantment::condition::UNDERWATER: return "UNDERWATER";
case enchantment::condition::DAY: return "DAY";
case enchantment::condition::NIGHT: return "NIGHT";
case enchantment::condition::DUSK: return "DUSK";
case enchantment::condition::DAWN: return "DAWN";
case enchantment::condition::ACTIVE: return "ACTIVE";
case enchantment::condition::NUM_CONDITION: break;
}
Expand Down Expand Up @@ -188,6 +193,22 @@ bool enchantment::is_active( const Character &guy, const bool active ) const
return true;
}

if( active_conditions.second == condition::NIGHT ) {
return is_night( calendar::turn );
}

if( active_conditions.second == condition::DAY ) {
return is_day( calendar::turn );
}

if( active_conditions.second == condition::DUSK ) {
return is_dusk( calendar::turn );
}

if( active_conditions.second == condition::DAWN ) {
return is_dawn( calendar::turn );
}

if( active_conditions.second == condition::UNDERGROUND ) {
return guy.pos().z < 0;
}
Expand Down
4 changes: 4 additions & 0 deletions src/magic_enchantment.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class enchantment
ALWAYS,
UNDERGROUND,
UNDERWATER,
NIGHT,
DAY,
DUSK,
DAWN,
ACTIVE, // the item, mutation, etc. is active
NUM_CONDITION
};
Expand Down

0 comments on commit 27ef8b0

Please sign in to comment.