Implemented some spell achievements

This commit is contained in:
arrai 2008-11-08 23:07:39 +01:00
parent 7a384e9374
commit 73e595ef87
4 changed files with 142 additions and 13 deletions

View file

@ -27,6 +27,61 @@
#include "GameEvent.h"
#include "World.h"
const CriteriaCastSpellRequirement* AchievementMgr::criteriaCastSpellRequirements[] =
{
new CriteriaCastSpellRequirement(5272, 3057, 0, 0),
new CriteriaCastSpellRequirement(5273, 2784, 0, 0),
new CriteriaCastSpellRequirement(5752, 9099, 0, 0),
new CriteriaCastSpellRequirement(5753, 8403, 0, 0),
new CriteriaCastSpellRequirement(5772, 0, 0, RACE_GNOME),
new CriteriaCastSpellRequirement(5774, 0, 0, RACE_BLOODELF),
new CriteriaCastSpellRequirement(5775, 0, 0, RACE_DRAENEI),
new CriteriaCastSpellRequirement(5776, 0, 0, RACE_DWARF),
new CriteriaCastSpellRequirement(5777, 0, 0, RACE_HUMAN),
new CriteriaCastSpellRequirement(5778, 0, 0, RACE_NIGHTELF),
new CriteriaCastSpellRequirement(5779, 0, 0, RACE_ORC),
new CriteriaCastSpellRequirement(5780, 0, 0, RACE_TAUREN),
new CriteriaCastSpellRequirement(5781, 0, 0, RACE_TROLL),
new CriteriaCastSpellRequirement(5782, 0, 0, RACE_UNDEAD_PLAYER),
new CriteriaCastSpellRequirement(6225, 5661, 0, 0),
new CriteriaCastSpellRequirement(6226, 26044, 0, 0),
new CriteriaCastSpellRequirement(6228, 739, 0, 0),
new CriteriaCastSpellRequirement(6229, 927, 0, 0),
new CriteriaCastSpellRequirement(6230, 1444, 0, 0),
new CriteriaCastSpellRequirement(6231, 8140, 0, 0),
new CriteriaCastSpellRequirement(6232, 5489, 0, 0),
new CriteriaCastSpellRequirement(6233,12336, 0, 0),
new CriteriaCastSpellRequirement(6234, 1351, 0, 0),
new CriteriaCastSpellRequirement(6235, 5484, 0, 0),
new CriteriaCastSpellRequirement(6236, 1182, 0, 0),
new CriteriaCastSpellRequirement(6237, 0, CLASS_DEATH_KNIGHT, RACE_ORC),
new CriteriaCastSpellRequirement(6238, 0, CLASS_WARRIOR, RACE_HUMAN),
new CriteriaCastSpellRequirement(6239, 0, CLASS_SHAMAN, RACE_TAUREN),
new CriteriaCastSpellRequirement(6240, 0, CLASS_DRUID, RACE_NIGHTELF),
new CriteriaCastSpellRequirement(6241, 0, CLASS_ROGUE, RACE_UNDEAD_PLAYER),
new CriteriaCastSpellRequirement(6242, 0, CLASS_HUNTER, RACE_TROLL),
new CriteriaCastSpellRequirement(6243, 0, CLASS_MAGE, RACE_GNOME),
new CriteriaCastSpellRequirement(6244, 0, CLASS_PALADIN, RACE_DWARF),
new CriteriaCastSpellRequirement(6245, 0, CLASS_WARLOCK, RACE_BLOODELF),
new CriteriaCastSpellRequirement(6246, 0, CLASS_PRIEST, RACE_DRAENEI),
new CriteriaCastSpellRequirement(6312, 0, CLASS_WARLOCK, RACE_GNOME),
new CriteriaCastSpellRequirement(6313, 0, CLASS_DEATH_KNIGHT, RACE_HUMAN),
new CriteriaCastSpellRequirement(6314, 0, CLASS_PRIEST, RACE_NIGHTELF),
new CriteriaCastSpellRequirement(6315, 0, CLASS_SHAMAN, RACE_ORC),
new CriteriaCastSpellRequirement(6316, 0, CLASS_DRUID, RACE_TAUREN),
new CriteriaCastSpellRequirement(6317, 0, CLASS_ROGUE, RACE_TROLL),
new CriteriaCastSpellRequirement(6318, 0, CLASS_WARRIOR, RACE_UNDEAD_PLAYER),
new CriteriaCastSpellRequirement(6319, 0, CLASS_MAGE, RACE_BLOODELF),
new CriteriaCastSpellRequirement(6320, 0, CLASS_PALADIN, RACE_DRAENEI),
new CriteriaCastSpellRequirement(6321, 0, CLASS_HUNTER, RACE_DWARF),
new CriteriaCastSpellRequirement(6662, 31261, 0, 0),
NULL};
AchievementMgr::AchievementMgr(Player *player)
{
m_player = player;
@ -187,7 +242,7 @@ void AchievementMgr::CheckAllAchievementCriteria()
/**
* this function will be called whenever the user might have done a criteria relevant action
*/
void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscvalue1, uint32 miscvalue2, uint32 time)
void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscvalue1, uint32 miscvalue2, Unit *unit, uint32 time)
{
sLog.outString("AchievementMgr::UpdateAchievementCriteria(%u, %u, %u, %u)", type, miscvalue1, miscvalue2, time);
AchievementCriteriaEntryList const& achievementCriteriaList = objmgr.GetAchievementCriteriaByType(type);
@ -334,11 +389,54 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
continue;
SetCriteriaProgress(achievementCriteria, miscvalue2, true);
break;
case ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET:
case ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2:
if (!miscvalue1 || miscvalue1 != achievementCriteria->be_spell_target.spellID)
continue;
SetCriteriaProgress(achievementCriteria, 1, true);
break;
case ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL:
if (!miscvalue1 || miscvalue1 != achievementCriteria->cast_spell.spellID)
continue;
SetCriteriaProgress(achievementCriteria, 1, true);
break;
case ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2:
if (!miscvalue1 || miscvalue1 != achievementCriteria->cast_spell.spellID)
continue;
// those requirements couldn't be found in the dbc
const CriteriaCastSpellRequirement *requirement = NULL;
for (uint32 i=0; criteriaCastSpellRequirements[i]; i++)
{
if (criteriaCastSpellRequirements[i]->achievementCriteriaId == achievementCriteria->ID)
{
requirement = criteriaCastSpellRequirements[i];
break;
}
}
if (requirement)
{
if (!unit)
continue;
if (requirement->creatureEntry && unit->GetEntry() != requirement->creatureEntry)
continue;
if (requirement->playerRace && (unit->GetTypeId() != TYPEID_PLAYER || unit->getRace()!=requirement->playerRace))
continue;
if (requirement->playerClass && (unit->GetTypeId() != TYPEID_PLAYER || unit->getClass()!=requirement->playerClass))
continue;
}
SetCriteriaProgress(achievementCriteria, 1, true);
break;
}
if(IsCompletedCriteria(achievementCriteria))
CompletedCriteria(achievementCriteria);
}
}
bool AchievementMgr::IsCompletedCriteria(AchievementCriteriaEntry const* achievementCriteria)
{
AchievementEntry const* achievement = sAchievementStore.LookupEntry(achievementCriteria->referredAchievement);
@ -412,6 +510,12 @@ bool AchievementMgr::IsCompletedCriteria(AchievementCriteriaEntry const* achieve
return progress->counter >= achievementCriteria->own_item.itemCount;
case ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM:
return progress->counter >= achievementCriteria->loot_item.itemCount;
case ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET:
case ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2:
return progress->counter >= achievementCriteria->be_spell_target.spellCount;
case ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL:
case ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2:
return progress->counter >= achievementCriteria->cast_spell.castCount;
// handle all statistic-only criteria here
case ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_BATTLEGROUND:

View file

@ -36,9 +36,25 @@ struct CriteriaProgress
time_t date;
};
struct CriteriaCastSpellRequirement
{
CriteriaCastSpellRequirement(uint32 achievementCriteriaId, uint32 creatureEntry, uint32 playerClass, uint32 playerRace)
{
this->achievementCriteriaId = achievementCriteriaId;
this->creatureEntry = creatureEntry;
this->playerClass = playerClass;
this->playerRace = playerRace;
}
uint32 achievementCriteriaId;
uint32 creatureEntry;
uint8 playerClass;
uint8 playerRace;
};
typedef UNORDERED_MAP<uint32, CriteriaProgress*> CriteriaProgressMap;
typedef UNORDERED_MAP<uint32, time_t> CompletedAchievementMap;
class Unit;
class Player;
class WorldPacket;
@ -57,7 +73,7 @@ class AchievementMgr
void LoadFromDB(QueryResult *achievementResult, QueryResult *criteriaResult);
void SaveToDB();
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscvalue1=0, uint32 miscvalue2=0, uint32 time=0);
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscvalue1=0, uint32 miscvalue2=0, Unit *unit=NULL, uint32 time=0);
void CheckAllAchievementCriteria();
void SendAllAchievementData();
void SendRespondInspectAchievements(Player* player);
@ -76,7 +92,6 @@ class AchievementMgr
Player* m_player;
CriteriaProgressMap m_criteriaProgress;
CompletedAchievementMap m_completedAchievements;
static const CriteriaCastSpellRequirement* criteriaCastSpellRequirements[];
};
#endif

View file

@ -959,6 +959,17 @@ void Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask)
return;
}
if (unit->GetTypeId() == TYPEID_PLAYER)
{
((Player*)unit)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET, m_spellInfo->Id);
((Player*)unit)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2, m_spellInfo->Id);
}
if(m_caster->GetTypeId() == TYPEID_PLAYER)
{
((Player*)m_caster)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2, m_spellInfo->Id, 0, unit);
}
if( m_caster != unit )
{
if( !m_caster->IsFriendlyTo(unit) )
@ -2081,9 +2092,14 @@ void Spell::cast(bool skipCheck)
// set to real guid to be sent later to the client
m_targets.updateTradeSlotItem();
if(m_CastItem && m_caster->GetTypeId() == TYPEID_PLAYER)
if (m_caster->GetTypeId() == TYPEID_PLAYER)
{
if (m_CastItem)
((Player*)m_caster)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM, m_CastItem->GetEntry());
((Player*)m_caster)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL, m_spellInfo->Id);
}
// CAST SPELL
SendSpellCooldown();

View file

@ -182,6 +182,7 @@ struct AchievementCriteriaEntry
} be_spell_target;
// ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL= 29
// ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2 = 110
struct
{
uint32 spellID; // 3
@ -422,13 +423,6 @@ struct AchievementCriteriaEntry
uint32 lootTypeCount; // 4
} loot_type;
// ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2 = 110
struct
{
uint32 skillLine; // 3
uint32 spellCount; // 4
} cast_spell2;
// ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE= 112
struct
{