Skip to content

Commit

Permalink
[9026] Implement ACHIEVEMENT_CRITERIA_REQUIRE_INSTANCE_SCRIPT.
Browse files Browse the repository at this point in the history
This achievement criteria requirement type let set in table `achievement_criteria_requirement`
that specific criteria id for achievmenet connected with some instance
must be checked by new InstanceData call
  bool CheckAchievementCriteriaMeet(uint32 criteria_id,Player const* source, Unit const* target, uint32 miscvalue1)

It expected to be used for cases: kill boss without raid members death or for some limited time
or without kill before some other boss helpers and etc. Implementation expected base at collection some data/counters update
in instance data at specific event and then make check by query and retunr success for specific criteri or fail requirements.
  • Loading branch information
VladimirMangos committed Dec 19, 2009
1 parent 1e66682 commit 1b87014
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
20 changes: 16 additions & 4 deletions src/game/AchievementMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "MapManager.h"
#include "BattleGround.h"
#include "BattleGroundAB.h"
#include "Map.h"
#include "InstanceData.h"

#include "Policies/SingletonImp.h"

Expand Down Expand Up @@ -102,6 +104,8 @@ bool AchievementCriteriaRequirement::IsValid(AchievementCriteriaEntry const* cri
case ACHIEVEMENT_CRITERIA_REQUIRE_NONE:
case ACHIEVEMENT_CRITERIA_REQUIRE_VALUE:
case ACHIEVEMENT_CRITERIA_REQUIRE_DISABLED:
case ACHIEVEMENT_CRITERIA_REQUIRE_BG_LOSS_TEAM_SCORE:
case ACHIEVEMENT_CRITERIA_REQUIRE_INSTANCE_SCRIPT:
return true;
case ACHIEVEMENT_CRITERIA_REQUIRE_T_CREATURE:
if (!creature.id || !ObjectMgr::GetCreatureTemplate(creature.id))
Expand Down Expand Up @@ -235,16 +239,14 @@ bool AchievementCriteriaRequirement::IsValid(AchievementCriteriaEntry const* cri
return false;
}
return true;
case ACHIEVEMENT_CRITERIA_REQUIRE_BG_LOSS_TEAM_SCORE:
return true; // not check correctness node indexes
default:
sLog.outErrorDb( "Table `achievement_criteria_requirement` (Entry: %u Type: %u) have data for not supported data type (%u), ignore.", criteria->ID, criteria->requiredType,requirementType);
return false;
}
return false;
}

bool AchievementCriteriaRequirement::Meets(Player const* source, Unit const* target, uint32 miscvalue1 /*= 0*/) const
bool AchievementCriteriaRequirement::Meets(uint32 criteria_id, Player const* source, Unit const* target, uint32 miscvalue1 /*= 0*/) const
{
switch(requirementType)
{
Expand Down Expand Up @@ -312,14 +314,24 @@ bool AchievementCriteriaRequirement::Meets(Player const* source, Unit const* tar
return false;
return bg->IsTeamScoreInRange(source->GetTeam()==ALLIANCE ? HORDE : ALLIANCE,bg_loss_team_score.min_score,bg_loss_team_score.max_score);
}
case ACHIEVEMENT_CRITERIA_REQUIRE_INSTANCE_SCRIPT:
if (!source->IsInWorld())
return false;
Map* map = source->GetMap();
if (!map->Instanceable())
return false;
InstanceData* data = ((InstanceMap*)map)->GetInstanceData();
if (!data)
return false;
return data->CheckAchievementCriteriaMeet(criteria_id, source, target, miscvalue1);
}
return false;
}

bool AchievementCriteriaRequirementSet::Meets(Player const* source, Unit const* target, uint32 miscvalue /*= 0*/) const
{
for(Storage::const_iterator itr = storage.begin(); itr != storage.end(); ++itr)
if(!itr->Meets(source,target,miscvalue))
if(!itr->Meets(criteria_id, source, target, miscvalue))
return false;

return true;
Expand Down
8 changes: 6 additions & 2 deletions src/game/AchievementMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ enum AchievementCriteriaRequirementType
ACHIEVEMENT_CRITERIA_REQUIRE_S_DRUNK = 15, // drunken_state 0 (enum DrunkenState) of player
ACHIEVEMENT_CRITERIA_REQUIRE_HOLIDAY = 16, // holiday_id 0 event in holiday time
ACHIEVEMENT_CRITERIA_REQUIRE_BG_LOSS_TEAM_SCORE = 17, // min_score max_score player's team win bg and opposition team have team score in range
ACHIEVEMENT_CRITERIA_REQUIRE_INSTANCE_SCRIPT = 18, // 0 0 maker instance script call for check curent criteria requirements fit
};

#define MAX_ACHIEVEMENT_CRITERIA_REQUIREMENT_TYPE 18 // maximum value in AchievementCriteriaRequirementType enum
#define MAX_ACHIEVEMENT_CRITERIA_REQUIREMENT_TYPE 19 // maximum value in AchievementCriteriaRequirementType enum

class Player;
class Unit;
Expand Down Expand Up @@ -175,15 +176,18 @@ struct AchievementCriteriaRequirement
}

bool IsValid(AchievementCriteriaEntry const* criteria);
bool Meets(Player const* source, Unit const* target, uint32 miscvalue1 = 0) const;
bool Meets(uint32 criteria_id, Player const* source, Unit const* target, uint32 miscvalue1 = 0) const;
};

struct AchievementCriteriaRequirementSet
{
AchievementCriteriaRequirementSet() : criteria_id(0) {}
explicit AchievementCriteriaRequirementSet(uint32 id) : criteria_id(id) {}
typedef std::vector<AchievementCriteriaRequirement> Storage;
void Add(AchievementCriteriaRequirement const& data) { storage.push_back(data); }
bool Meets(Player const* source, Unit const* target, uint32 miscvalue = 0) const;
private:
uint32 criteria_id;
Storage storage;
};

Expand Down
7 changes: 7 additions & 0 deletions src/game/InstanceData.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,12 @@ class MANGOS_DLL_SPEC InstanceData
//All-purpose data storage 32 bit
virtual uint32 GetData(uint32 /*Type*/) { return 0; }
virtual void SetData(uint32 /*Type*/, uint32 /*Data*/) {}

// Achievement criteria additional requirements check
// NOTE: not use this if same can be checked existed requirement types from AchievementCriteriaRequirementType
virtual bool CheckAchievementCriteriaMeet(uint32 /*criteria_id*/, Player const* /*source*/, Unit const* /*target*/ = NULL, uint32 /*miscvalue1*/ = 0)
{
return false;
}
};
#endif
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9025"
#define REVISION_NR "9026"
#endif // __REVISION_NR_H__

1 comment on commit 1b87014

@VladimirMangos
Copy link

Choose a reason for hiding this comment

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

with proper data in achievement_criteria_requirement this criterias in past has been diabled and can't be completed. All ofc dependent from DB.

You can drop wrong data in character_achievement_progress/character_achievement

Please sign in to comment.