From e907ab4f3e2b210e7011dfbe02587e2a2a4052f4 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Mon, 18 Aug 2014 21:01:27 -0700 Subject: [PATCH 1/2] LoadMercTypes converted to QueryDatabase --- zone/merc.cpp | 129 ++++++++++++++++++++++++-------------------------- 1 file changed, 62 insertions(+), 67 deletions(-) diff --git a/zone/merc.cpp b/zone/merc.cpp index ff4581489..8c34d2e05 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -2773,7 +2773,7 @@ int16 Merc::GetFocusEffect(focusType type, uint16 spell_id) { int32 Merc::GetActSpellDamage(uint16 spell_id, int32 value, Mob* target) { - + if (spells[spell_id].targettype == ST_Self) return value; @@ -2784,9 +2784,9 @@ int32 Merc::GetActSpellDamage(uint16 spell_id, int32 value, Mob* target) { int chance = RuleI(Spells, BaseCritChance); chance += itembonuses.CriticalSpellChance + spellbonuses.CriticalSpellChance + aabonuses.CriticalSpellChance; - + if (chance > 0){ - + int32 ratio = RuleI(Spells, BaseCritRatio); //Critical modifier is applied from spell effects only. Keep at 100 for live like criticals. if (MakeRandomInt(1,100) <= chance){ @@ -2801,29 +2801,29 @@ int32 Merc::GetActSpellDamage(uint16 spell_id, int32 value, Mob* target) { } ratio += RuleI(Spells, WizCritRatio); //Default is zero - + if (Critical){ - value = value_BaseEffect*ratio/100; + value = value_BaseEffect*ratio/100; - value += value_BaseEffect*GetFocusEffect(focusImprovedDamage, spell_id)/100; + value += value_BaseEffect*GetFocusEffect(focusImprovedDamage, spell_id)/100; value += int(value_BaseEffect*GetFocusEffect(focusFcDamagePctCrit, spell_id)/100)*ratio/100; if (target) { - value += int(value_BaseEffect*target->GetVulnerability(this, spell_id, 0)/100)*ratio/100; - value -= target->GetFcDamageAmtIncoming(this, spell_id); + value += int(value_BaseEffect*target->GetVulnerability(this, spell_id, 0)/100)*ratio/100; + value -= target->GetFcDamageAmtIncoming(this, spell_id); } - value -= GetFocusEffect(focusFcDamageAmtCrit, spell_id)*ratio/100; + value -= GetFocusEffect(focusFcDamageAmtCrit, spell_id)*ratio/100; - value -= GetFocusEffect(focusFcDamageAmt, spell_id); + value -= GetFocusEffect(focusFcDamageAmt, spell_id); if(itembonuses.SpellDmg && spells[spell_id].classes[(GetClass()%16) - 1] >= GetLevel() - 5) value -= GetExtraSpellAmt(spell_id, itembonuses.SpellDmg, value)*ratio/100; - value = (value * GetSpellScale() / 100); - + value = (value * GetSpellScale() / 100); + entity_list.MessageClose_StringID(this, false, 100, MT_SpellCrits, OTHER_CRIT_BLAST, GetName(), itoa(-value)); @@ -2832,30 +2832,30 @@ int32 Merc::GetActSpellDamage(uint16 spell_id, int32 value, Mob* target) { } value = value_BaseEffect; - - value += value_BaseEffect*GetFocusEffect(focusImprovedDamage, spell_id)/100; - + + value += value_BaseEffect*GetFocusEffect(focusImprovedDamage, spell_id)/100; + value += value_BaseEffect*GetFocusEffect(focusFcDamagePctCrit, spell_id)/100; if (target) { value += value_BaseEffect*target->GetVulnerability(this, spell_id, 0)/100; - value -= target->GetFcDamageAmtIncoming(this, spell_id); + value -= target->GetFcDamageAmtIncoming(this, spell_id); } - value -= GetFocusEffect(focusFcDamageAmtCrit, spell_id); + value -= GetFocusEffect(focusFcDamageAmtCrit, spell_id); + + value -= GetFocusEffect(focusFcDamageAmt, spell_id); - value -= GetFocusEffect(focusFcDamageAmt, spell_id); - if(itembonuses.SpellDmg && spells[spell_id].classes[(GetClass()%16) - 1] >= GetLevel() - 5) - value -= GetExtraSpellAmt(spell_id, itembonuses.SpellDmg, value); + value -= GetExtraSpellAmt(spell_id, itembonuses.SpellDmg, value); + + value = (value * GetSpellScale() / 100); - value = (value * GetSpellScale() / 100); - return value; } int32 Merc::GetActSpellHealing(uint16 spell_id, int32 value, Mob* target) { - + if (target == nullptr) target = this; @@ -2863,37 +2863,37 @@ int32 Merc::GetActSpellHealing(uint16 spell_id, int32 value, Mob* target) { int16 chance = 0; int8 modifier = 1; bool Critical = false; - - value_BaseEffect = value + (value*GetFocusEffect(focusFcBaseEffects, spell_id)/100); - + + value_BaseEffect = value + (value*GetFocusEffect(focusFcBaseEffects, spell_id)/100); + value = value_BaseEffect; - value += int(value_BaseEffect*GetFocusEffect(focusImprovedHeal, spell_id)/100); - + value += int(value_BaseEffect*GetFocusEffect(focusImprovedHeal, spell_id)/100); + // Instant Heals if(spells[spell_id].buffduration < 1) { - chance += itembonuses.CriticalHealChance + spellbonuses.CriticalHealChance + aabonuses.CriticalHealChance; + chance += itembonuses.CriticalHealChance + spellbonuses.CriticalHealChance + aabonuses.CriticalHealChance; + + chance += target->GetFocusIncoming(focusFcHealPctCritIncoming, SE_FcHealPctCritIncoming, this, spell_id); - chance += target->GetFocusIncoming(focusFcHealPctCritIncoming, SE_FcHealPctCritIncoming, this, spell_id); - if (spellbonuses.CriticalHealDecay) - chance += GetDecayEffectValue(spell_id, SE_CriticalHealDecay); - + chance += GetDecayEffectValue(spell_id, SE_CriticalHealDecay); + if(chance && (MakeRandomInt(0,99) < chance)) { Critical = true; modifier = 2; //At present time no critical heal amount modifier SPA exists. } - + value *= modifier; - value += GetFocusEffect(focusFcHealAmtCrit, spell_id) * modifier; - value += GetFocusEffect(focusFcHealAmt, spell_id); - value += target->GetFocusIncoming(focusFcHealAmtIncoming, SE_FcHealAmtIncoming, this, spell_id); - + value += GetFocusEffect(focusFcHealAmtCrit, spell_id) * modifier; + value += GetFocusEffect(focusFcHealAmt, spell_id); + value += target->GetFocusIncoming(focusFcHealAmtIncoming, SE_FcHealAmtIncoming, this, spell_id); + if(itembonuses.HealAmt && spells[spell_id].classes[(GetClass()%16) - 1] >= GetLevel() - 5) value += GetExtraSpellAmt(spell_id, itembonuses.HealAmt, value) * modifier; - value += value*target->GetHealRate(spell_id, this)/100; + value += value*target->GetHealRate(spell_id, this)/100; if (Critical) entity_list.MessageClose(this, false, 100, MT_SpellCrits, "%s performs an exceptional heal! (%d)", GetName(), value); @@ -2903,14 +2903,14 @@ int32 Merc::GetActSpellHealing(uint16 spell_id, int32 value, Mob* target) { //Heal over time spells. [Heal Rate and Additional Healing effects do not increase this value] else { - - chance = itembonuses.CriticalHealOverTime + spellbonuses.CriticalHealOverTime + aabonuses.CriticalHealOverTime; - chance += target->GetFocusIncoming(focusFcHealPctCritIncoming, SE_FcHealPctCritIncoming, this, spell_id); - + chance = itembonuses.CriticalHealOverTime + spellbonuses.CriticalHealOverTime + aabonuses.CriticalHealOverTime; + + chance += target->GetFocusIncoming(focusFcHealPctCritIncoming, SE_FcHealPctCritIncoming, this, spell_id); + if (spellbonuses.CriticalRegenDecay) chance += GetDecayEffectValue(spell_id, SE_CriticalRegenDecay); - + if(chance && (MakeRandomInt(0,99) < chance)) return (value * 2); } @@ -5851,35 +5851,30 @@ void Client::SendMercAssignPacket(uint32 entityID, uint32 unk01, uint32 unk02) { FastQueuePacket(&outapp); } -void NPC::LoadMercTypes(){ - std::string errorMessage; - char* Query = 0; - char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE]; - MYSQL_RES* DatasetResult; - MYSQL_ROW DataRow; +void NPC::LoadMercTypes() { - if(!database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT DISTINCT MTyp.dbstring, MTyp.clientversion FROM merc_merchant_entries MME, merc_merchant_template_entries MMTE, merc_types MTyp, merc_templates MTem WHERE MME.merchant_id = %i AND MME.merc_merchant_template_id = MMTE.merc_merchant_template_id AND MMTE.merc_template_id = MTem.merc_template_id AND MTem.merc_type_id = MTyp.merc_type_id;", GetNPCTypeID()), TempErrorMessageBuffer, &DatasetResult)) { - errorMessage = std::string(TempErrorMessageBuffer); - } - else { - while(DataRow = mysql_fetch_row(DatasetResult)) { - MercType tempMercType; + std::string query = StringFormat("SELECT DISTINCT MTyp.dbstring, MTyp.clientversion " + "FROM merc_merchant_entries MME, merc_merchant_template_entries MMTE, " + "merc_types MTyp, merc_templates MTem " + "WHERE MME.merchant_id = %i " + "AND MME.merc_merchant_template_id = MMTE.merc_merchant_template_id " + "AND MMTE.merc_template_id = MTem.merc_template_id " + "AND MTem.merc_type_id = MTyp.merc_type_id;", GetNPCTypeID()); + auto results = database.QueryDatabase(query); + if (!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in NPC::LoadMercTypes()"); + return; + } - tempMercType.Type = atoi(DataRow[0]); - tempMercType.ClientVersion = atoi(DataRow[1]); + for (auto row = results.begin(); row != results.end(); ++row) { + MercType tempMercType; - mercTypeList.push_back(tempMercType); - } + tempMercType.Type = atoi(row[0]); + tempMercType.ClientVersion = atoi(row[1]); - mysql_free_result(DatasetResult); + mercTypeList.push_back(tempMercType); } - safe_delete_array(Query); - Query = 0; - - if(!errorMessage.empty()) { - LogFile->write(EQEMuLog::Error, "Error in NPC::LoadMercTypes()"); - } } void NPC::LoadMercs(){ From 49d231f5ddb583964667332e7d4b147a9f89ceba Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Mon, 18 Aug 2014 21:05:38 -0700 Subject: [PATCH 2/2] LoadMercs converted to QueryDatabase --- zone/merc.cpp | 52 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/zone/merc.cpp b/zone/merc.cpp index 8c34d2e05..16550908f 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -5879,38 +5879,36 @@ void NPC::LoadMercTypes() { void NPC::LoadMercs(){ - std::string errorMessage; - char* Query = 0; - char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE]; - MYSQL_RES* DatasetResult; - MYSQL_ROW DataRow; + std::string query = StringFormat("SELECT DISTINCT MTem.merc_template_id, MTyp.dbstring AS merc_type_id, " + "MTem.dbstring AS merc_subtype_id, 0 AS CostFormula, " + "CASE WHEN MTem.clientversion > MTyp.clientversion " + "THEN MTem.clientversion " + "ELSE MTyp.clientversion END AS clientversion, MTem.merc_npc_type_id " + "FROM merc_merchant_entries MME, merc_merchant_template_entries MMTE, " + "merc_types MTyp, merc_templates MTem " + "WHERE MME.merchant_id = %i AND " + "MME.merc_merchant_template_id = MMTE.merc_merchant_template_id " + "AND MMTE.merc_template_id = MTem.merc_template_id " + "AND MTem.merc_type_id = MTyp.merc_type_id;", GetNPCTypeID()); + auto results = database.QueryDatabase(query); + if (!results.Success()) { + LogFile->write(EQEMuLog::Error, "Error in NPC::LoadMercTypes()"); + return; + } - if(!database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT DISTINCT MTem.merc_template_id, MTyp.dbstring AS merc_type_id, MTem.dbstring AS merc_subtype_id, 0 AS CostFormula, CASE WHEN MTem.clientversion > MTyp.clientversion then MTem.clientversion ELSE MTyp.clientversion END AS clientversion, MTem.merc_npc_type_id FROM merc_merchant_entries MME, merc_merchant_template_entries MMTE, merc_types MTyp, merc_templates MTem WHERE MME.merchant_id = %i AND MME.merc_merchant_template_id = MMTE.merc_merchant_template_id AND MMTE.merc_template_id = MTem.merc_template_id AND MTem.merc_type_id = MTyp.merc_type_id;", GetNPCTypeID()), TempErrorMessageBuffer, &DatasetResult)) { - errorMessage = std::string(TempErrorMessageBuffer); - } - else { - while(DataRow = mysql_fetch_row(DatasetResult)) { - MercData tempMerc; + for (auto row = results.begin(); row != results.end(); ++row) { + MercData tempMerc; - tempMerc.MercTemplateID = atoi(DataRow[0]); - tempMerc.MercType = atoi(DataRow[1]); - tempMerc.MercSubType = atoi(DataRow[2]); - tempMerc.CostFormula = atoi(DataRow[3]); - tempMerc.ClientVersion = atoi(DataRow[4]); - tempMerc.NPCID = atoi(DataRow[5]); + tempMerc.MercTemplateID = atoi(row[0]); + tempMerc.MercType = atoi(row[1]); + tempMerc.MercSubType = atoi(row[2]); + tempMerc.CostFormula = atoi(row[3]); + tempMerc.ClientVersion = atoi(row[4]); + tempMerc.NPCID = atoi(row[5]); - mercDataList.push_back(tempMerc); - } - - mysql_free_result(DatasetResult); + mercDataList.push_back(tempMerc); } - safe_delete_array(Query); - Query = 0; - - if(!errorMessage.empty()) { - LogFile->write(EQEMuLog::Error, "Error in NPC::LoadMercTypes()"); - } } int NPC::GetNumMercTypes(uint32 clientVersion)