Skip to content

Instantly share code, notes, and snippets.

@egocarib
Created October 11, 2014 21:19
Show Gist options
  • Save egocarib/e49d644fc817fc22d4e6 to your computer and use it in GitHub Desktop.
Save egocarib/e49d644fc817fc22d4e6 to your computer and use it in GitHub Desktop.
EventResult TESHitEventHandler::ReceiveEvent(TESHitEvent* evn, EventDispatcher<TESHitEvent>* dispatcher)
{
_MESSAGE("0");
if (evn->caster->baseForm != (*g_thePlayer)->baseForm)
return kEvent_Continue; //Ignore non-player attackers
_MESSAGE("1");
EnchantmentItem* enchantment = evn->GetMagicHitEnchantment();
_MESSAGE("2");
if (!enchantment) //Can't retrieve enchantment info
return kEvent_Continue;
if (enchantment->data.unk14 == 0x0C) //Staff enchantment
return kEvent_Continue;
_MESSAGE("3");
//Timer is used to ignore multiple hit events triggered by a single enchantment (and to add slight delay for learn framework)
time_t thisTime = time(NULL);
if (difftime(thisTime, hitDelayMap[enchantment]) < 1.0) //(could make this delay an ini setting?)
return kEvent_Continue; //Ignore multiple hit events from this enchantment
hitDelayMap[enchantment] = thisTime;
_MESSAGE("4");
//Find base enchantment and advance learning
if (enchantment->formID >= 0xFF000000)
{
_MESSAGE("5");
std::vector<EnchantmentItem*> baseEnchantments;
_MESSAGE("6");
if (g_enchantmentFramework->GetCraftedEnchantmentParents(enchantment, baseEnchantments))
_MESSAGE("enchantment framework returned true");
_MESSAGE("7");
for (UInt32 i = 0; i < baseEnchantments.size(); i++)
{
EnchantmentItem* baseCopy = DYNAMIC_CAST(LookupFormByID(baseEnchantments[i]->formID), TESForm, EnchantmentItem);
g_learnedExperienceMap.AdvanceLearning(baseCopy/*baseEnchantments[i]*/);
}
// g_learnedExperienceMap.AdvanceLearning(DYNAMIC_CAST(LookupFormByID(0x0010FB95), TESForm, EnchantmentItem));
_MESSAGE("9");
}
else
{
if (g_userExclusions.ShouldExcludeHitEventSource(evn))
return kEvent_Continue;
if (enchantment->data.baseEnchantment)
enchantment = enchantment->data.baseEnchantment;
g_learnedExperienceMap.AdvanceLearning(enchantment);
}
_MESSAGE("10");
return kEvent_Continue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment