Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Achievement update #2470

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions db/pre-re/achievement_db.conf
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ achievement_db: (
ACH_ITEM_GET_COUNT_ITEMTYPE: Acquire N amount of items of a particular type mask. (Acquire Item)
ACH_ITEM_GET_WORTH: Acquire an item of buy value N. (Acquire Item)
ACH_ITEM_SELL_WORTH: Sell an item of sell value N. (NPC Sell Item)
ACH_PET_CREATE: Successfully tame a pet of a particular mob class. (Successful Pet Tame)
ACH_PET_CREATE: (Accumulative) Successfully tame a pet of a particular mob class. (Successful Pet Tame)
ACH_PET_INTIMACY: (Accumulative) Successfully reach a specific pet intimacy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting here too

ACH_PET_RUNAWAY: (Accumulative) Successfully make a pet runaway
ACH_ACHIEVE: Achieve an Achievement. (Achievement Completion)
ACH_ACHIEVEMENT_RANK: Achieve an Achievement Rank. (Achievement Rank Increase)
Objectives: { [Mandatory Field] Objectives of an achievement. Up to 10 objectives per achievement.
Expand All @@ -91,7 +93,7 @@ achievement_db: (
Criteria: { This is a field for achievements whose objectives must meet
certain criteria before evaluating the player's progress for it.
MobId: (mixed) MonsterId required for an objective.
For types such as ACH_KILL_MOB_CLASS and ACH_PET_CREATE.
For types such as ACH_KILL_MOB_CLASS, ACH_PET_CREATE, ACH_PET_INTIMACY, ACH_PET_RUNAWAY.
Can be either int or string constant. If set to 0 would apply to any monster.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here formatting different

JobId: (mixed) Array or Single entry of JobIds.
For types - ACH_KILL_PC_JOBTYPE, ACH_JOB_CHANGE or ACH_STATUS_BY_JOBTYPE.
Expand All @@ -118,6 +120,9 @@ achievement_db: (
For Types such as ACH_EQUIP_REFINE_SUCCESS_WLV and ACH_EQUIP_REFINE_FAILURE_WLV.
Achieve: (int) AchievementID to be achieved.
For Type - ACH_ACHIEVE.
Intimacy: (int) For types such as ACH_PET_INTIMACY, The desired pet intimacy for this achievement,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here formatting

unlike other criteria this one checked for equal or bigger than, since Intimacy is not increased
or decreased by a predictable amount
}
Goal: (int) Target amount to be met for the completion of the objective. Default is 1.
}
Expand Down
9 changes: 7 additions & 2 deletions db/re/achievement_db.conf
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ achievement_db: (
ACH_ITEM_GET_COUNT_ITEMTYPE: Acquire N amount of items of a particular type mask. (Acquire Item)
ACH_ITEM_GET_WORTH: Acquire an item of buy value N. (Acquire Item)
ACH_ITEM_SELL_WORTH: Sell an item of sell value N. (NPC Sell Item)
ACH_PET_CREATE: Successfully tame a pet of a particular mob class. (Successful Pet Tame)
ACH_PET_CREATE: (Accumulative) Successfully tame a pet of a particular mob class. (Successful Pet Tame)
ACH_PET_INTIMACY: (Accumulative) Successfully reach a specific pet intimacy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

ACH_PET_RUNAWAY: (Accumulative) Successfully make a pet runaway
ACH_ACHIEVE: Achieve an Achievement. (Achievement Completion)
ACH_ACHIEVEMENT_RANK: Achieve an Achievement Rank. (Achievement Rank Increase)
Objectives: { [Mandatory Field] Objectives of an achievement. Up to 10 objectives per achievement.
Expand All @@ -91,7 +93,7 @@ achievement_db: (
Criteria: { This is a field for achievements whose objectives must meet
certain criteria before evaluating the player's progress for it.
MobId: (mixed) MonsterId required for an objective.
For types such as ACH_KILL_MOB_CLASS and ACH_PET_CREATE.
For types such as ACH_KILL_MOB_CLASS, ACH_PET_CREATE, ACH_PET_INTIMACY, ACH_PET_RUNAWAY.
Can be either int or string constant. If set to 0 would apply to any monster.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

JobId: (mixed) Array or Single entry of JobIds.
For types - ACH_KILL_PC_JOBTYPE, ACH_JOB_CHANGE or ACH_STATUS_BY_JOBTYPE.
Expand All @@ -118,6 +120,9 @@ achievement_db: (
For Types such as ACH_EQUIP_REFINE_SUCCESS_WLV and ACH_EQUIP_REFINE_FAILURE_WLV.
Achieve: (int) AchievementID to be achieved.
For Type - ACH_ACHIEVE.
Intimacy: (int) For types such as ACH_PET_INTIMACY, The desired pet intimacy for this achievement,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

unlike other criteria this one checked for equal or bigger than, since Intimacy is not increased
or decreased by a predictable amount
}
Goal: (int) Target amount to be met for the completion of the objective. Default is 1.
}
Expand Down
100 changes: 93 additions & 7 deletions src/map/achievement.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
#include "map/itemdb.h"
#include "map/mob.h"
#include "map/party.h"
#include "map/pet.h"
#include "map/pc.h"
#include "map/script.h"

#include "common/conf.h"
#include "common/db.h"
#include "common/memmgr.h"
#include "common/mmo.h"
#include "common/nullpo.h"
#include "common/showmsg.h"
#include "common/strlib.h"
Expand Down Expand Up @@ -280,6 +282,10 @@ static bool achievement_check_criteria(const struct achievement_objective *objec
return false;
}

/* Pet intimacy */
if (objective->intimacy > 0 && objective->intimacy > criteria->intimacy)
return false;

return true;
}

Expand Down Expand Up @@ -928,14 +934,14 @@ static void achievement_validate_achieve(struct map_session_data *sd, int achid)
}

/**
* Validates taming type objectives.
* @type ACH_PET_CREATE
* @param[in] sd pointer to session data.
* @param[in] class (criteria) class of the monster tamed.
*/
* Validates taming type objectives.
* @type ACH_PET_CREATE
* @param[in] sd pointer to session data.
* @param[in] class (criteria) class of the monster tamed.
*/
static void achievement_validate_taming(struct map_session_data *sd, int class)
{
struct achievement_objective criteria = { 0 };
struct achievement_objective criteria = {0};

nullpo_retv(sd);

Expand All @@ -951,6 +957,47 @@ static void achievement_validate_taming(struct map_session_data *sd, int class)
achievement->validate_type(sd, ACH_PET_CREATE, &criteria, true);
}

/**
* Validates pet intimacy type objectives.
* @type ACH_PET_INTIMACY
* @param[in] sd pointer to session data.
*/
static void achievement_validate_pet_intimacy(struct map_session_data *sd)
{
nullpo_retv(sd);
nullpo_retv(sd->pd);

if (sd->achievements_received == false)
return;

struct achievement_objective criteria = {0};
criteria.mobid = sd->pd->pet.class_;
criteria.intimacy = sd->pd->pet.intimate;
criteria.goal = 1;

achievement->validate_type(sd, ACH_PET_INTIMACY, &criteria, true);
}

/**
* Validates pet runaway type objectives.
* @type ACH_PET_RUNAWAY
* @param[in] sd pointer to session data.
* @param[in] class (criteria) class of the monster tamed.
*/
static void achievement_validate_pet_runaway(struct map_session_data *sd, int class)
{
nullpo_retv(sd);

if (sd->achievements_received == false)
return;

struct achievement_objective criteria = {0};
criteria.mobid = class;
criteria.goal = 1;

achievement->validate_type(sd, ACH_PET_RUNAWAY, &criteria, true);
}

/**
* Validated achievement rank type objectives.
* @type ACH_ACHIEVEMENT_RANK
Expand All @@ -959,7 +1006,7 @@ static void achievement_validate_taming(struct map_session_data *sd, int class)
*/
static void achievement_validate_achievement_rank(struct map_session_data *sd, int rank)
{
struct achievement_objective criteria = { 0 };
struct achievement_objective criteria = {0};

nullpo_retv(sd);

Expand Down Expand Up @@ -993,6 +1040,8 @@ static bool achievement_type_requires_criteria(enum achievement_types type)
|| type == ACH_EQUIP_REFINE_FAILURE_ID
|| type == ACH_ITEM_GET_COUNT
|| type == ACH_PET_CREATE
|| type == ACH_PET_INTIMACY
|| type == ACH_PET_RUNAWAY
|| type == ACH_ACHIEVE)
return true;

Expand Down Expand Up @@ -1531,6 +1580,36 @@ static bool achievement_readdb_validate_criteria_achievement(const struct config
return true;
}

/**
* Validates achievement Id criteria of an objective while parsing an achievement entry.
* @param[in] t pointer to the config setting.
* @param[out] obj pointer to the achievement objective entry being parsed.
* @param[in] type Type of the achievement being parsed.
* @param[in] entry_id Id of the entry being parsed.
* @param[in] obj_idx Index of the objective entry being parsed.
* @return false on failure, true on success.
*/
static bool achievement_readdb_validate_criteria_intimacy(const struct config_setting_t *t, struct achievement_objective *obj, enum achievement_types type, int entry_id, int obj_idx)
{
nullpo_retr(false, t);
nullpo_retr(false, obj);

int val = 0;
if (libconfig->setting_lookup_int(t, "Intimacy", &val)) {
if (val < 1 || val > 1000) {
ShowError("achievement_readdb_validate_criteria_intimacy: Invalid intimacy range given %d (Max: %d Low: %d). Skipping...\n", val, 1, 1000);
return false;
}

obj->intimacy = val;
} else if (achievement_criteria_intimacy(type)) {
ShowError("achievement_readdb_validate_criteria_intimacy: Achievement type of ID %d requires an Intimacy field in the objective criteria, setting not provided. Skipping...\n", entry_id);
return false;
}

return true;
}

/**
* Read a single objective entry of an achievement.
* @param[in] conf config pointer.
Expand Down Expand Up @@ -1583,6 +1662,10 @@ static bool achievement_readdb_objective_sub(const struct config_setting_t *conf
if (achievement->readdb_validate_criteria_achievement(c, &obj, entry->type, entry->id, index) == false)
return false;

/* Intimacy */
if (achievement->readdb_validate_criteria_intimacy(c, &obj, entry->type, entry->id, index) == false)
return false;

/**
* Vectors are read last to avoid memory leaks if either of the above break, in cases where they are stacked with other criteria.
* Note to future editors - be sure to cleanup previous vectors before breaks.
Expand Down Expand Up @@ -1978,6 +2061,7 @@ void achievement_defaults(void)
achievement->readdb_validate_criteria_itemtype = achievement_readdb_validate_criteria_itemtype;
achievement->readdb_validate_criteria_weaponlv = achievement_readdb_validate_criteria_weaponlv;
achievement->readdb_validate_criteria_achievement = achievement_readdb_validate_criteria_achievement;
achievement->readdb_validate_criteria_intimacy = achievement_readdb_validate_criteria_intimacy;
/* */
achievement->readdb_rewards = achievement_readdb_rewards;
achievement->readdb_validate_reward_items = achievement_readdb_validate_reward_items;
Expand Down Expand Up @@ -2020,6 +2104,8 @@ void achievement_defaults(void)
achievement->validate_item_sell = achievement_validate_item_sell;
achievement->validate_achieve = achievement_validate_achieve;
achievement->validate_taming = achievement_validate_taming;
achievement->validate_pet_intimacy = achievement_validate_pet_intimacy;
achievement->validate_pet_runaway = achievement_validate_pet_runaway;
achievement->validate_achievement_rank = achievement_validate_achievement_rank;
/* */
achievement->type_requires_criteria = achievement_type_requires_criteria;
Expand Down
14 changes: 13 additions & 1 deletion src/map/achievement.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ enum achievement_types {
ACH_ACHIEVEMENT_RANK,
ACH_ZENY_SPEND_VENDING,
ACH_ZENY_SPEND_VENDING_TOTAL,
ACH_PET_INTIMACY,
ACH_PET_RUNAWAY,
ACH_TYPE_MAX
};

Expand Down Expand Up @@ -140,6 +142,7 @@ struct achievement_objective {
/* */
uint32 item_type;
int mobid;
int intimacy;
VECTOR_DECL(int) jobid;
};

Expand Down Expand Up @@ -168,7 +171,9 @@ struct achievement_data {
// Achievements types that use Mob ID as criteria.
#define achievement_criteria_mobid(t) ( \
(t) == ACH_KILL_MOB_CLASS \
|| (t) == ACH_PET_CREATE )
|| (t) == ACH_PET_CREATE \
|| (t) == ACH_PET_INTIMACY \
|| (t) == ACH_PET_RUNAWAY )

// Achievements types that use JobID vector as criteria.
#define achievement_criteria_jobid(t) ( \
Expand Down Expand Up @@ -199,6 +204,10 @@ struct achievement_data {
(t) == ACH_EQUIP_REFINE_SUCCESS_WLV \
|| (t) == ACH_EQUIP_REFINE_FAILURE_WLV )

// Achievement types that uses intimacy as criteria
#define achievement_criteria_intimacy(t) ( \
(t) == ACH_PET_INTIMACY )

// Valid status types for objective criteria.
#define achievement_valid_status_types(s) ( \
(s) == SP_STR \
Expand Down Expand Up @@ -232,6 +241,7 @@ struct achievement_interface {
bool (*readdb_validate_criteria_itemtype) (const struct config_setting_t *t, struct achievement_objective *obj, enum achievement_types type, int entry_id, int obj_idx);
bool (*readdb_validate_criteria_weaponlv) (const struct config_setting_t *t, struct achievement_objective *obj, enum achievement_types type, int entry_id, int obj_idx);
bool (*readdb_validate_criteria_achievement) (const struct config_setting_t *t, struct achievement_objective *obj, enum achievement_types type, int entry_id, int obj_idx);
bool (*readdb_validate_criteria_intimacy) (const struct config_setting_t *t, struct achievement_objective *obj, enum achievement_types type, int entry_id, int obj_idx);
/* */
bool (*readdb_rewards) (const struct config_setting_t *conf, struct achievement_data *entry, const char *source);
void (*readdb_validate_reward_items) (const struct config_setting_t *t, struct achievement_data *entry);
Expand Down Expand Up @@ -274,6 +284,8 @@ struct achievement_interface {
void (*validate_item_sell) (struct map_session_data *sd, int nameid, int amount);
void (*validate_achieve) (struct map_session_data *sd, int achid);
void (*validate_taming) (struct map_session_data *sd, int class);
void (*validate_pet_intimacy) (struct map_session_data *sd);
void (*validate_pet_runaway) (struct map_session_data *sd, int class);
void (*validate_achievement_rank) (struct map_session_data *sd, int rank);
/* */
bool (*type_requires_criteria) (enum achievement_types type);
Expand Down
4 changes: 4 additions & 0 deletions src/map/pet.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ static void pet_set_intimate(struct pet_data *pd, int value)
if( (intimate >= battle_config.pet_equip_min_friendly && pd->pet.intimate < battle_config.pet_equip_min_friendly) || (intimate < battle_config.pet_equip_min_friendly && pd->pet.intimate >= battle_config.pet_equip_min_friendly) )
status_calc_pc(sd,SCO_NONE);

if (value > 0)
achievement->validate_pet_intimacy(sd);
achievement->validate_pet_runaway(sd, pd->pet.class_);

/* Pet is lost, delete the egg */
if (value <= 0) {
int i;
Expand Down
2 changes: 2 additions & 0 deletions src/map/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -26649,6 +26649,8 @@ static void script_hardcoded_constants(void)
script->set_constant("ACH_ACHIEVEMENT_RANK", ACH_ACHIEVEMENT_RANK, false, false);
script->set_constant("ACH_ZENY_SPEND_VENDING", ACH_ZENY_SPEND_VENDING, false, false);
script->set_constant("ACH_ZENY_SPEND_VENDING_TOTAL", ACH_ZENY_SPEND_VENDING_TOTAL, false, false);
script->set_constant("ACH_PET_INTIMACY", ACH_PET_INTIMACY, false, false);
script->set_constant("ACH_PET_RUNAWAY", ACH_PET_RUNAWAY, false, false);

script->constdb_comment("Renewal");
#ifdef RENEWAL
Expand Down