Merge pull request #200 from addtheice/RunQueryToDatabaseQuery_zone_merc

Run query to database query zone merc
This commit is contained in:
Alex 2014-08-22 13:47:29 -07:00
commit 1bccdf57ee

View File

@ -2773,7 +2773,7 @@ int16 Merc::GetFocusEffect(focusType type, uint16 spell_id) {
int32 Merc::GetActSpellDamage(uint16 spell_id, int32 value, Mob* target) { int32 Merc::GetActSpellDamage(uint16 spell_id, int32 value, Mob* target) {
if (spells[spell_id].targettype == ST_Self) if (spells[spell_id].targettype == ST_Self)
return value; return value;
@ -2784,9 +2784,9 @@ int32 Merc::GetActSpellDamage(uint16 spell_id, int32 value, Mob* target) {
int chance = RuleI(Spells, BaseCritChance); int chance = RuleI(Spells, BaseCritChance);
chance += itembonuses.CriticalSpellChance + spellbonuses.CriticalSpellChance + aabonuses.CriticalSpellChance; chance += itembonuses.CriticalSpellChance + spellbonuses.CriticalSpellChance + aabonuses.CriticalSpellChance;
if (chance > 0){ if (chance > 0){
int32 ratio = RuleI(Spells, BaseCritRatio); //Critical modifier is applied from spell effects only. Keep at 100 for live like criticals. 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){ 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 ratio += RuleI(Spells, WizCritRatio); //Default is zero
if (Critical){ 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; value += int(value_BaseEffect*GetFocusEffect(focusFcDamagePctCrit, spell_id)/100)*ratio/100;
if (target) { if (target) {
value += int(value_BaseEffect*target->GetVulnerability(this, spell_id, 0)/100)*ratio/100; value += int(value_BaseEffect*target->GetVulnerability(this, spell_id, 0)/100)*ratio/100;
value -= target->GetFcDamageAmtIncoming(this, spell_id); 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) if(itembonuses.SpellDmg && spells[spell_id].classes[(GetClass()%16) - 1] >= GetLevel() - 5)
value -= GetExtraSpellAmt(spell_id, itembonuses.SpellDmg, value)*ratio/100; 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, entity_list.MessageClose_StringID(this, false, 100, MT_SpellCrits,
OTHER_CRIT_BLAST, GetName(), itoa(-value)); 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;
value += value_BaseEffect*GetFocusEffect(focusImprovedDamage, spell_id)/100; value += value_BaseEffect*GetFocusEffect(focusImprovedDamage, spell_id)/100;
value += value_BaseEffect*GetFocusEffect(focusFcDamagePctCrit, spell_id)/100; value += value_BaseEffect*GetFocusEffect(focusFcDamagePctCrit, spell_id)/100;
if (target) { if (target) {
value += value_BaseEffect*target->GetVulnerability(this, spell_id, 0)/100; 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) 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; return value;
} }
int32 Merc::GetActSpellHealing(uint16 spell_id, int32 value, Mob* target) { int32 Merc::GetActSpellHealing(uint16 spell_id, int32 value, Mob* target) {
if (target == nullptr) if (target == nullptr)
target = this; target = this;
@ -2863,37 +2863,37 @@ int32 Merc::GetActSpellHealing(uint16 spell_id, int32 value, Mob* target) {
int16 chance = 0; int16 chance = 0;
int8 modifier = 1; int8 modifier = 1;
bool Critical = false; 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 = value_BaseEffect;
value += int(value_BaseEffect*GetFocusEffect(focusImprovedHeal, spell_id)/100); value += int(value_BaseEffect*GetFocusEffect(focusImprovedHeal, spell_id)/100);
// Instant Heals // Instant Heals
if(spells[spell_id].buffduration < 1) { 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) if (spellbonuses.CriticalHealDecay)
chance += GetDecayEffectValue(spell_id, SE_CriticalHealDecay); chance += GetDecayEffectValue(spell_id, SE_CriticalHealDecay);
if(chance && (MakeRandomInt(0,99) < chance)) { if(chance && (MakeRandomInt(0,99) < chance)) {
Critical = true; Critical = true;
modifier = 2; //At present time no critical heal amount modifier SPA exists. modifier = 2; //At present time no critical heal amount modifier SPA exists.
} }
value *= modifier; value *= modifier;
value += GetFocusEffect(focusFcHealAmtCrit, spell_id) * modifier; value += GetFocusEffect(focusFcHealAmtCrit, spell_id) * modifier;
value += GetFocusEffect(focusFcHealAmt, spell_id); value += GetFocusEffect(focusFcHealAmt, spell_id);
value += target->GetFocusIncoming(focusFcHealAmtIncoming, SE_FcHealAmtIncoming, this, spell_id); value += target->GetFocusIncoming(focusFcHealAmtIncoming, SE_FcHealAmtIncoming, this, spell_id);
if(itembonuses.HealAmt && spells[spell_id].classes[(GetClass()%16) - 1] >= GetLevel() - 5) if(itembonuses.HealAmt && spells[spell_id].classes[(GetClass()%16) - 1] >= GetLevel() - 5)
value += GetExtraSpellAmt(spell_id, itembonuses.HealAmt, value) * modifier; 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) if (Critical)
entity_list.MessageClose(this, false, 100, MT_SpellCrits, "%s performs an exceptional heal! (%d)", GetName(), value); 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] //Heal over time spells. [Heal Rate and Additional Healing effects do not increase this value]
else { 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) if (spellbonuses.CriticalRegenDecay)
chance += GetDecayEffectValue(spell_id, SE_CriticalRegenDecay); chance += GetDecayEffectValue(spell_id, SE_CriticalRegenDecay);
if(chance && (MakeRandomInt(0,99) < chance)) if(chance && (MakeRandomInt(0,99) < chance))
return (value * 2); return (value * 2);
} }
@ -5851,71 +5851,64 @@ void Client::SendMercAssignPacket(uint32 entityID, uint32 unk01, uint32 unk02) {
FastQueuePacket(&outapp); FastQueuePacket(&outapp);
} }
void NPC::LoadMercTypes(){ void NPC::LoadMercTypes() {
std::string errorMessage;
char* Query = 0;
char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE];
MYSQL_RES* DatasetResult;
MYSQL_ROW DataRow;
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)) { std::string query = StringFormat("SELECT DISTINCT MTyp.dbstring, MTyp.clientversion "
errorMessage = std::string(TempErrorMessageBuffer); "FROM merc_merchant_entries MME, merc_merchant_template_entries MMTE, "
} "merc_types MTyp, merc_templates MTem "
else { "WHERE MME.merchant_id = %i "
while(DataRow = mysql_fetch_row(DatasetResult)) { "AND MME.merc_merchant_template_id = MMTE.merc_merchant_template_id "
MercType tempMercType; "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]); for (auto row = results.begin(); row != results.end(); ++row) {
tempMercType.ClientVersion = atoi(DataRow[1]); 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(){ void NPC::LoadMercs(){
std::string errorMessage; std::string query = StringFormat("SELECT DISTINCT MTem.merc_template_id, MTyp.dbstring AS merc_type_id, "
char* Query = 0; "MTem.dbstring AS merc_subtype_id, 0 AS CostFormula, "
char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE]; "CASE WHEN MTem.clientversion > MTyp.clientversion "
MYSQL_RES* DatasetResult; "THEN MTem.clientversion "
MYSQL_ROW DataRow; "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)) { for (auto row = results.begin(); row != results.end(); ++row) {
errorMessage = std::string(TempErrorMessageBuffer); MercData tempMerc;
}
else {
while(DataRow = mysql_fetch_row(DatasetResult)) {
MercData tempMerc;
tempMerc.MercTemplateID = atoi(DataRow[0]); tempMerc.MercTemplateID = atoi(row[0]);
tempMerc.MercType = atoi(DataRow[1]); tempMerc.MercType = atoi(row[1]);
tempMerc.MercSubType = atoi(DataRow[2]); tempMerc.MercSubType = atoi(row[2]);
tempMerc.CostFormula = atoi(DataRow[3]); tempMerc.CostFormula = atoi(row[3]);
tempMerc.ClientVersion = atoi(DataRow[4]); tempMerc.ClientVersion = atoi(row[4]);
tempMerc.NPCID = atoi(DataRow[5]); tempMerc.NPCID = atoi(row[5]);
mercDataList.push_back(tempMerc); mercDataList.push_back(tempMerc);
}
mysql_free_result(DatasetResult);
} }
safe_delete_array(Query);
Query = 0;
if(!errorMessage.empty()) {
LogFile->write(EQEMuLog::Error, "Error in NPC::LoadMercTypes()");
}
} }
int NPC::GetNumMercTypes(uint32 clientVersion) int NPC::GetNumMercTypes(uint32 clientVersion)