[Commands] Cleanup #modifynpcstat Command. (#2499)

* [Commands] Cleanup #modifynpcstat Command.

Cleanup messages and logic,

Add map and loop through it to display all stats, can add to this in the future if we add more stuff modifiable by this command.

* Delete settings.json

* Update modifynpcstat.cpp

* Update modifynpcstat.cpp

* Update questmgr.h
This commit is contained in:
Kinglykrab
2022-10-29 21:22:07 -04:00
committed by GitHub
parent b512447448
commit dcbc9a358f
11 changed files with 288 additions and 192 deletions
+155 -157
View File
@@ -2445,54 +2445,57 @@ void NPC::SetLevel(uint8 in_level, bool command)
SendAppearancePacket(AT_WhoLevel, in_level);
}
void NPC::ModifyNPCStat(const char *identifier, const char *new_value)
void NPC::ModifyNPCStat(std::string stat, std::string value)
{
std::string id = Strings::ToLower(identifier);
std::string val = new_value;
auto stat_lower = Strings::ToLower(stat);
std::string variable_key = StringFormat("modify_stat_%s", id.c_str());
SetEntityVariable(variable_key.c_str(), new_value);
auto variable_key = fmt::format(
"modify_stat_{}",
stat_lower
);
LogNPCScaling("NPC::ModifyNPCStat key: [{}] val: [{}] ", variable_key.c_str(), new_value);
SetEntityVariable(variable_key.c_str(), value.c_str());
if (id == "ac") {
AC = atoi(val.c_str());
LogNPCScaling("NPC::ModifyNPCStat: Key [{}] Value [{}] ", variable_key, value);
if (stat_lower == "ac") {
AC = atoi(value.c_str());
CalcAC();
return;
}
else if (id == "str") {
STR = atoi(val.c_str());
else if (stat_lower == "str") {
STR = atoi(value.c_str());
return;
}
else if (id == "sta") {
STA = atoi(val.c_str());
else if (stat_lower == "sta") {
STA = atoi(value.c_str());
return;
}
else if (id == "agi") {
AGI = atoi(val.c_str());
else if (stat_lower == "agi") {
AGI = atoi(value.c_str());
CalcAC();
return;
}
else if (id == "dex") {
DEX = atoi(val.c_str());
else if (stat_lower == "dex") {
DEX = atoi(value.c_str());
return;
}
else if (id == "wis") {
WIS = atoi(val.c_str());
else if (stat_lower == "wis") {
WIS = atoi(value.c_str());
CalcMaxMana();
return;
}
else if (id == "int" || id == "_int") {
INT = atoi(val.c_str());
else if (stat_lower == "int" || stat_lower == "_int") {
INT = atoi(value.c_str());
CalcMaxMana();
return;
}
else if (id == "cha") {
CHA = atoi(val.c_str());
else if (stat_lower == "cha") {
CHA = atoi(value.c_str());
return;
}
else if (id == "max_hp") {
base_hp = std::stoull(val.c_str());
else if (stat_lower == "max_hp") {
base_hp = std::stoull(value.c_str());
CalcMaxHP();
if (current_hp > max_hp) {
@@ -2501,48 +2504,44 @@ void NPC::ModifyNPCStat(const char *identifier, const char *new_value)
return;
}
else if (id == "max_mana") {
npc_mana = std::stoull(val.c_str());
else if (stat_lower == "max_mana") {
npc_mana = std::stoull(value.c_str());
CalcMaxMana();
if (current_mana > max_mana) {
current_mana = max_mana;
}
return;
}
else if (id == "mr") {
MR = atoi(val.c_str());
else if (stat_lower == "mr") {
MR = atoi(value.c_str());
return;
}
else if (id == "fr") {
FR = atoi(val.c_str());
else if (stat_lower == "fr") {
FR = atoi(value.c_str());
return;
}
else if (id == "cr") {
CR = atoi(val.c_str());
else if (stat_lower == "cr") {
CR = atoi(value.c_str());
return;
}
else if (id == "cor") {
Corrup = atoi(val.c_str());
else if (stat_lower == "cor") {
Corrup = atoi(value.c_str());
return;
}
else if (id == "phr") {
PhR = atoi(val.c_str());
else if (stat_lower == "pr") {
PR = atoi(value.c_str());
return;
}
else if (id == "pr") {
PR = atoi(val.c_str());
else if (stat_lower == "dr") {
DR = atoi(value.c_str());
return;
}
else if (id == "dr") {
DR = atoi(val.c_str());
else if (stat_lower == "phr") {
PhR = atoi(value.c_str());
return;
}
else if (id == "phr") {
PhR = atoi(val.c_str());
return;
}
else if (id == "runspeed") {
runspeed = (float) atof(val.c_str());
else if (stat_lower == "runspeed") {
runspeed = (float) atof(value.c_str());
base_runspeed = (int) ((float) runspeed * 40.0f);
base_walkspeed = base_runspeed * 100 / 265;
walkspeed = ((float) base_walkspeed) * 0.025f;
@@ -2551,290 +2550,289 @@ void NPC::ModifyNPCStat(const char *identifier, const char *new_value)
CalcBonuses();
return;
}
else if (id == "special_attacks") {
NPCSpecialAttacks(val.c_str(), 0, 1);
else if (stat_lower == "special_attacks") {
NPCSpecialAttacks(value.c_str(), 0, 1);
return;
}
else if (id == "special_abilities") {
ProcessSpecialAbilities(val.c_str());
else if (stat_lower == "special_abilities") {
ProcessSpecialAbilities(value.c_str());
return;
}
else if (id == "attack_speed") {
attack_speed = (float) atof(val.c_str());
else if (stat_lower == "attack_speed") {
attack_speed = (float) atof(value.c_str());
CalcBonuses();
return;
}
else if (id == "attack_delay") {
else if (stat_lower == "attack_delay") {
/* TODO: fix DB */
attack_delay = atoi(val.c_str()) * 100;
attack_delay = atoi(value.c_str()) * 100;
CalcBonuses();
return;
}
else if (id == "atk") {
ATK = atoi(val.c_str());
else if (stat_lower == "atk") {
ATK = atoi(value.c_str());
return;
}
else if (id == "accuracy") {
accuracy_rating = atoi(val.c_str());
else if (stat_lower == "accuracy") {
accuracy_rating = atoi(value.c_str());
return;
}
else if (id == "avoidance") {
avoidance_rating = atoi(val.c_str());
else if (stat_lower == "avoidance") {
avoidance_rating = atoi(value.c_str());
return;
}
else if (id == "trackable") {
trackable = atoi(val.c_str());
else if (stat_lower == "trackable") {
trackable = atoi(value.c_str());
return;
}
else if (id == "min_hit") {
min_dmg = atoi(val.c_str());
else if (stat_lower == "min_hit") {
min_dmg = atoi(value.c_str());
// TODO: fix DB
base_damage = round((max_dmg - min_dmg) / 1.9);
min_damage = min_dmg - round(base_damage / 10.0);
return;
}
else if (id == "max_hit") {
max_dmg = atoi(val.c_str());
else if (stat_lower == "max_hit") {
max_dmg = atoi(value.c_str());
// TODO: fix DB
base_damage = round((max_dmg - min_dmg) / 1.9);
min_damage = min_dmg - round(base_damage / 10.0);
return;
}
else if (id == "attack_count") {
attack_count = atoi(val.c_str());
else if (stat_lower == "attack_count") {
attack_count = atoi(value.c_str());
return;
}
else if (id == "see_invis") {
see_invis = atoi(val.c_str());
else if (stat_lower == "see_invis") {
see_invis = atoi(value.c_str());
return;
}
else if (id == "see_invis_undead") {
see_invis_undead = atoi(val.c_str());
else if (stat_lower == "see_invis_undead") {
see_invis_undead = atoi(value.c_str());
return;
}
else if (id == "see_hide") {
see_hide = atoi(val.c_str());
else if (stat_lower == "see_hide") {
see_hide = atoi(value.c_str());
return;
}
else if (id == "see_improved_hide") {
see_improved_hide = atoi(val.c_str());
else if (stat_lower == "see_improved_hide") {
see_improved_hide = atoi(value.c_str());
return;
}
else if (id == "hp_regen") {
hp_regen = strtoll(val.c_str(), nullptr, 10);
else if (stat_lower == "hp_regen") {
hp_regen = strtoll(value.c_str(), nullptr, 10);
return;
}
else if (id == "hp_regen_per_second") {
hp_regen_per_second = strtoll(val.c_str(), nullptr, 10);
else if (stat_lower == "hp_regen_per_second") {
hp_regen_per_second = strtoll(value.c_str(), nullptr, 10);
return;
}
else if (id == "mana_regen") {
mana_regen = strtoll(val.c_str(), nullptr, 10);
else if (stat_lower == "mana_regen") {
mana_regen = strtoll(value.c_str(), nullptr, 10);
return;
}
else if (id == "level") {
SetLevel(atoi(val.c_str()));
else if (stat_lower == "level") {
SetLevel(atoi(value.c_str()));
return;
}
else if (id == "aggro") {
pAggroRange = atof(val.c_str());
else if (stat_lower == "aggro") {
pAggroRange = atof(value.c_str());
return;
}
else if (id == "assist") {
pAssistRange = atof(val.c_str());
else if (stat_lower == "assist") {
pAssistRange = atof(value.c_str());
return;
}
else if (id == "slow_mitigation") {
slow_mitigation = atoi(val.c_str());
else if (stat_lower == "slow_mitigation") {
slow_mitigation = atoi(value.c_str());
return;
}
else if (id == "loottable_id") {
loottable_id = atof(val.c_str());
else if (stat_lower == "loottable_id") {
loottable_id = atof(value.c_str());
return;
}
else if (id == "healscale") {
healscale = atof(val.c_str());
else if (stat_lower == "healscale") {
healscale = atof(value.c_str());
return;
}
else if (id == "spellscale") {
spellscale = atof(val.c_str());
else if (stat_lower == "spellscale") {
spellscale = atof(value.c_str());
return;
}
else if (id == "npc_spells_id") {
AI_AddNPCSpells(atoi(val.c_str()));
else if (stat_lower == "npc_spells_id") {
AI_AddNPCSpells(atoi(value.c_str()));
return;
}
else if (id == "npc_spells_effects_id") {
AI_AddNPCSpellsEffects(atoi(val.c_str()));
else if (stat_lower == "npc_spells_effects_id") {
AI_AddNPCSpellsEffects(atoi(value.c_str()));
CalcBonuses();
return;
}
else if (id == "heroic_strikethrough") {
heroic_strikethrough = atoi(val.c_str());
else if (stat_lower == "heroic_strikethrough") {
heroic_strikethrough = atoi(value.c_str());
return;
}
}
float NPC::GetNPCStat(const char *identifier)
float NPC::GetNPCStat(std::string stat)
{
std::string id = Strings::ToLower(identifier);
auto stat_lower = Strings::ToLower(stat);
if (id == "ac") {
if (stat_lower == "ac") {
return AC;
}
else if (id == "str") {
else if (stat_lower == "str") {
return STR;
}
else if (id == "sta") {
else if (stat_lower == "sta") {
return STA;
}
else if (id == "agi") {
else if (stat_lower == "agi") {
return AGI;
}
else if (id == "dex") {
else if (stat_lower == "dex") {
return DEX;
}
else if (id == "wis") {
else if (stat_lower == "wis") {
return WIS;
}
else if (id == "int" || id == "_int") {
else if (stat_lower == "int" || stat_lower == "_int") {
return INT;
}
else if (id == "cha") {
else if (stat_lower == "cha") {
return CHA;
}
else if (id == "max_hp") {
else if (stat_lower == "max_hp") {
return base_hp;
}
else if (id == "max_mana") {
else if (stat_lower == "max_mana") {
return npc_mana;
}
else if (id == "mr") {
else if (stat_lower == "mr") {
return MR;
}
else if (id == "fr") {
else if (stat_lower == "fr") {
return FR;
}
else if (id == "cr") {
else if (stat_lower == "cr") {
return CR;
}
else if (id == "cor") {
else if (stat_lower == "cor") {
return Corrup;
}
else if (id == "phr") {
else if (stat_lower == "phr") {
return PhR;
}
else if (id == "pr") {
else if (stat_lower == "pr") {
return PR;
}
else if (id == "dr") {
else if (stat_lower == "dr") {
return DR;
}
else if (id == "phr") {
else if (stat_lower == "phr") {
return PhR;
}
else if (id == "runspeed") {
else if (stat_lower == "runspeed") {
return runspeed;
}
else if (id == "attack_speed") {
else if (stat_lower == "attack_speed") {
return attack_speed;
}
else if (id == "attack_delay") {
else if (stat_lower == "attack_delay") {
return attack_delay;
}
else if (id == "atk") {
else if (stat_lower == "atk") {
return ATK;
}
else if (id == "accuracy") {
else if (stat_lower == "accuracy") {
return accuracy_rating;
}
else if (id == "avoidance") {
else if (stat_lower == "avoidance") {
return avoidance_rating;
}
else if (id == "trackable") {
else if (stat_lower == "trackable") {
return trackable;
}
else if (id == "min_hit") {
else if (stat_lower == "min_hit") {
return min_dmg;
}
else if (id == "max_hit") {
else if (stat_lower == "max_hit") {
return max_dmg;
}
else if (id == "attack_count") {
else if (stat_lower == "attack_count") {
return attack_count;
}
else if (id == "see_invis") {
else if (stat_lower == "see_invis") {
return see_invis;
}
else if (id == "see_invis_undead") {
else if (stat_lower == "see_invis_undead") {
return see_invis_undead;
}
else if (id == "see_hide") {
else if (stat_lower == "see_hide") {
return see_hide;
}
else if (id == "see_improved_hide") {
else if (stat_lower == "see_improved_hide") {
return see_improved_hide;
}
else if (id == "hp_regen") {
else if (stat_lower == "hp_regen") {
return hp_regen;
}
else if (id == "hp_regen_per_second") {
else if (stat_lower == "hp_regen_per_second") {
return hp_regen_per_second;
}
else if (id == "mana_regen") {
else if (stat_lower == "mana_regen") {
return mana_regen;
}
else if (id == "level") {
else if (stat_lower == "level") {
return GetOrigLevel();
}
else if (id == "aggro") {
else if (stat_lower == "aggro") {
return pAggroRange;
}
else if (id == "assist") {
else if (stat_lower == "assist") {
return pAssistRange;
}
else if (id == "slow_mitigation") {
else if (stat_lower == "slow_mitigation") {
return slow_mitigation;
}
else if (id == "loottable_id") {
else if (stat_lower == "loottable_id") {
return loottable_id;
}
else if (id == "healscale") {
else if (stat_lower == "healscale") {
return healscale;
}
else if (id == "spellscale") {
else if (stat_lower == "spellscale") {
return spellscale;
}
else if (id == "npc_spells_id") {
else if (stat_lower == "npc_spells_id") {
return npc_spells_id;
}
else if (id == "npc_spells_effects_id") {
else if (stat_lower == "npc_spells_effects_id") {
return npc_spells_effects_id;
}
else if (id == "heroic_strikethrough") {
else if (stat_lower == "heroic_strikethrough") {
return heroic_strikethrough;
}
//default values
else if (id == "default_ac") {
else if (stat_lower == "default_ac") {
return default_ac;
}
else if (id == "default_min_hit") {
else if (stat_lower == "default_min_hit") {
return default_min_dmg;
}
else if (id == "default_max_hit") {
else if (stat_lower == "default_max_hit") {
return default_max_dmg;
}
else if (id == "default_attack_delay") {
else if (stat_lower == "default_attack_delay") {
return default_attack_delay;
}
else if (id == "default_accuracy") {
else if (stat_lower == "default_accuracy") {
return default_accuracy_rating;
}
else if (id == "default_avoidance") {
else if (stat_lower == "default_avoidance") {
return default_avoidance_rating;
}
else if (id == "default_atk") {
else if (stat_lower == "default_atk") {
return default_atk;
}