Skip to content

Commit

Permalink
fix recent living/stats variable rename to initialize undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelprograms committed Feb 10, 2025
1 parent 7d30a08 commit a7ae2be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/std/living/stats.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @this_object /std/living.c

private mapping __Stat = ([
mapping __Stat = ([
"strength": 0,
"perception": 0,
"endurance": 0,
Expand All @@ -19,7 +19,18 @@ nosave mapping __StatBonus = ([
"luck": 0,
]);

private void initialize_stat_bonus () {
private void initialize_stats () {
if (!mapp(__Stat)) {
__Stat = ([
"strength": 0,
"perception": 0,
"endurance": 0,
"charisma": 0,
"intelligence": 0,
"agility": 0,
"luck": 0,
]);
}
if (!mapp(__StatBonus)) {
__StatBonus = ([
"strength": 0,
Expand All @@ -34,15 +45,15 @@ private void initialize_stat_bonus () {
}

int query_stat_base (string stat) {
initialize_stat_bonus();
initialize_stats();
return __Stat[stat];
}
int query_stat_bonus (string stat) {
initialize_stat_bonus();
initialize_stats();
return __StatBonus[stat];
}
int query_stat (string stat) {
initialize_stat_bonus();
initialize_stats();
return __Stat[stat] + query_stat_bonus(stat);
}

Expand All @@ -55,7 +66,7 @@ void set_stat (string stat, int n) {
this_object()->update_limbs();
}
void add_stat_bonus (string stat, int n) {
initialize_stat_bonus();
initialize_stats();
if (member_array(stat, keys(__StatBonus)) == -1) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions lib/std/living/stats.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void test_query_and_set_stat () {
void test_stat_bonus () {
expect("null stats bonus are initialized", (: ({
assert_equal(testOb->query_stat_bonus("luck"), 0),
store_variable("__Stat", UNDEFINED, testOb),
store_variable("__StatBonus", UNDEFINED, testOb),
assert_equal(testOb->query_stat_bonus("luck"), 0),
}) :));
Expand Down

0 comments on commit a7ae2be

Please sign in to comment.