From cf6e4f1292ca4e2dd81a0ad21155a37ca31e171a Mon Sep 17 00:00:00 2001 From: ratkosrb Date: Thu, 24 Jan 2019 08:46:01 +0200 Subject: [PATCH] Use percent hp and mana in creature spawns table. --- sql/migrations/20190123062532_world.sql | 3 + sql/migrations/20190124061618_world.sql | 28 ++++++++ src/game/ObjectMgr.cpp | 87 +++++++++++++++---------- src/game/Objects/Creature.cpp | 29 +++++---- src/game/Objects/Object.cpp | 2 +- src/game/Objects/Unit.cpp | 6 ++ src/game/Objects/Unit.h | 3 +- 7 files changed, 108 insertions(+), 50 deletions(-) create mode 100644 sql/migrations/20190124061618_world.sql diff --git a/sql/migrations/20190123062532_world.sql b/sql/migrations/20190123062532_world.sql index 0e88e0e62..b4d59675c 100644 --- a/sql/migrations/20190123062532_world.sql +++ b/sql/migrations/20190123062532_world.sql @@ -88,6 +88,9 @@ ALTER TABLE `map_template` ALTER TABLE `creature_template` CHANGE COLUMN `regeneration` `regeneration` TINYINT(3) UNSIGNED NOT NULL DEFAULT '3' AFTER `racial_leader`; UPDATE `creature_template` SET `regeneration`=3 WHERE `regeneration`=1; +ALTER TABLE `creature_template` + CHANGE COLUMN `dmg_school` `dmg_school` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0' AFTER `dmg_max`, + CHANGE COLUMN `movement_type` `movement_type` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER `ai_name`; -- End of migration. diff --git a/sql/migrations/20190124061618_world.sql b/sql/migrations/20190124061618_world.sql new file mode 100644 index 000000000..56cb5ec08 --- /dev/null +++ b/sql/migrations/20190124061618_world.sql @@ -0,0 +1,28 @@ +DROP PROCEDURE IF EXISTS add_migration; +delimiter ?? +CREATE PROCEDURE `add_migration`() +BEGIN +DECLARE v INT DEFAULT 1; +SET v = (SELECT COUNT(*) FROM `migrations` WHERE `id`='20190124061618'); +IF v=0 THEN +INSERT INTO `migrations` VALUES ('20190124061618'); +-- Add your query below. + + +-- Use percent health and mana in creature spawn table. +ALTER TABLE `creature` + CHANGE COLUMN `curhealth` `curhealth` FLOAT NOT NULL DEFAULT '100' AFTER `currentwaypoint`, + CHANGE COLUMN `curmana` `curmana` FLOAT UNSIGNED NOT NULL DEFAULT '100' AFTER `curhealth`; + +UPDATE `creature` SET `curhealth`=100 WHERE `curhealth` > 0; +UPDATE `creature` SET `curhealth`=60 WHERE `id` IN (12423, 12427, 12428, 12429, 12430); +UPDATE `creature` SET `curhealth`=29 WHERE `id`=13020; +UPDATE `creature` SET `curmana`=100 WHERE `curmana` > 0; + + +-- End of migration. +END IF; +END?? +delimiter ; +CALL add_migration(); +DROP PROCEDURE IF EXISTS add_migration; diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 331d069ba..9f4f644b3 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -1159,8 +1159,8 @@ void ObjectMgr::CheckCreatureTemplates() CreatureDisplayInfoEntry const* displayEntry = sCreatureDisplayInfoStore.LookupEntry(cInfo->display_id[i]); if (!displayEntry) { - sLog.outErrorDb("Creature (Entry: %u) has nonexistent modelid_%d (%u), can crash client", cInfo->entry, i + 1, cInfo->display_id[i]); - sLog.out(LOG_DBERRFIX, "UPDATE creature_template SET `modelid_%d`=0 WHERE entry=%u;", i + 1, cInfo->entry); + sLog.outErrorDb("Creature (Entry: %u) has nonexistent display_id%d (%u), can crash client", cInfo->entry, i + 1, cInfo->display_id[i]); + sLog.out(LOG_DBERRFIX, "UPDATE creature_template SET `display_id%d`=0 WHERE entry=%u;", i + 1, cInfo->entry); const_cast(cInfo)->display_id[i] = 0; } else if (!displayScaleEntry) @@ -1168,23 +1168,23 @@ void ObjectMgr::CheckCreatureTemplates() CreatureModelInfo const* minfo = sCreatureModelStorage.LookupEntry(cInfo->display_id[i]); if (!minfo) - sLog.outErrorDb("Creature (Entry: %u) are using modelid_%d (%u), but creature_model_info are missing for this model.", cInfo->entry, i + 1, cInfo->display_id[i]); + sLog.outErrorDb("Creature (Entry: %u) is using display_id%d (%u), but creature_model_info data is missing for this model.", cInfo->entry, i + 1, cInfo->display_id[i]); } } if (!displayScaleEntry) - sLog.outErrorDb("Creature (Entry: %u) has nonexistent modelid in modelid_1/modelid_2", cInfo->entry); + sLog.outErrorDb("Creature (Entry: %u) does not have any valid display id", cInfo->entry); // use below code for 0-checks for unit_class if (!cInfo->unit_class) - ERROR_DB_STRICT_LOG("Creature (Entry: %u) not has proper unit_class(%u) for creature_template", cInfo->entry, cInfo->unit_class); + ERROR_DB_STRICT_LOG("Creature (Entry: %u) does not have proper unit_class(%u) for creature_template", cInfo->entry, cInfo->unit_class); else if (((1 << (cInfo->unit_class - 1)) & CLASSMASK_ALL_CREATURES) == 0) sLog.outErrorDb("Creature (Entry: %u) has invalid unit_class(%u) for creature_template", cInfo->entry, cInfo->unit_class); if (cInfo->dmg_school >= MAX_SPELL_SCHOOL) { - sLog.outErrorDb("Creature (Entry: %u) has invalid spell school value (%u) in `dmgschool`", cInfo->entry, cInfo->dmg_school); - sLog.out(LOG_DBERRFIX, "UPDATE creature_template SET `dmgschool`=%u WHERE entry=%u;", SPELL_SCHOOL_NORMAL, cInfo->entry); + sLog.outErrorDb("Creature (Entry: %u) has invalid spell school value (%u) in `dmg_school`", cInfo->entry, cInfo->dmg_school); + sLog.out(LOG_DBERRFIX, "UPDATE creature_template SET `dmg_school`=%u WHERE entry=%u;", SPELL_SCHOOL_NORMAL, cInfo->entry); const_cast(cInfo)->dmg_school = SPELL_SCHOOL_NORMAL; } @@ -1213,15 +1213,15 @@ void ObjectMgr::CheckCreatureTemplates() // must exist or used hidden but used in data horse case if (cInfo->beast_family && !sCreatureFamilyStore.LookupEntry(cInfo->beast_family) && cInfo->beast_family != CREATURE_FAMILY_HORSE_CUSTOM) { - sLog.outErrorDb("Creature (Entry: %u) has invalid creature family (%u) in `family`", cInfo->entry, cInfo->beast_family); - sLog.out(LOG_DBERRFIX, "UPDATE creature_template SET `family`=%u WHERE entry=%u;", 0, cInfo->entry); + sLog.outErrorDb("Creature (Entry: %u) has invalid creature family (%u) in `beast_family`", cInfo->entry, cInfo->beast_family); + sLog.out(LOG_DBERRFIX, "UPDATE creature_template SET `beast_family`=%u WHERE entry=%u;", 0, cInfo->entry); const_cast(cInfo)->beast_family = 0; } if (cInfo->inhabit_type <= 0 || cInfo->inhabit_type > INHABIT_ANYWHERE) { - sLog.outErrorDb("Creature (Entry: %u) has wrong value (%u) in `InhabitType`, creature will not correctly walk/swim", cInfo->entry, cInfo->inhabit_type); - sLog.out(LOG_DBERRFIX, "UPDATE creature_template SET `InhabitType`=%u WHERE entry=%u;", INHABIT_ANYWHERE, cInfo->entry); + sLog.outErrorDb("Creature (Entry: %u) has wrong value (%u) in `inhabit_type`, creature will not correctly walk/swim", cInfo->entry, cInfo->inhabit_type); + sLog.out(LOG_DBERRFIX, "UPDATE creature_template SET `inhabit_type`=%u WHERE entry=%u;", INHABIT_ANYWHERE, cInfo->entry); const_cast(cInfo)->inhabit_type = INHABIT_ANYWHERE; } @@ -1229,7 +1229,7 @@ void ObjectMgr::CheckCreatureTemplates() { CreatureSpellDataEntry const* spellDataId = sCreatureSpellDataStore.LookupEntry(cInfo->pet_spell_list_id); if (!spellDataId) - sLog.outErrorDb("Creature (Entry: %u) has non-existing pet_spell_list_id (%u)", cInfo->entry, cInfo->pet_spell_list_id); + sLog.outErrorDb("Creature (Entry: %u) has nonexistent pet_spell_list_id (%u)", cInfo->entry, cInfo->pet_spell_list_id); } if (cInfo->spell_list_id) @@ -1237,7 +1237,7 @@ void ObjectMgr::CheckCreatureTemplates() CreatureSpellsList const* spellsList = GetCreatureSpellsList((cInfo->spell_list_id)); if (!spellsList) { - sLog.outErrorDb("Creature (Entry: %u) has non-existing spells template (%u)", cInfo->entry, cInfo->spell_list_id); + sLog.outErrorDb("Creature (Entry: %u) has nonexistent spell list id (%u)", cInfo->entry, cInfo->spell_list_id); const_cast(cInfo)->spell_list_id = 0; } } @@ -1246,16 +1246,16 @@ void ObjectMgr::CheckCreatureTemplates() { if (cInfo->spells[j] && !sSpellMgr.GetSpellEntry(cInfo->spells[j])) { - sLog.outErrorDb("Creature (Entry: %u) has non-existing Spell%d (%u), set to 0", cInfo->entry, j + 1, cInfo->spells[j]); - sLog.out(LOG_DBERRFIX, "UPDATE creature_template SET `spell%u`=0 WHERE entry=%u;", j + 1, cInfo->entry); + sLog.outErrorDb("Creature (Entry: %u) has nonexistent spell_id%d (%u), set to 0", cInfo->entry, j + 1, cInfo->spells[j]); + sLog.out(LOG_DBERRFIX, "UPDATE creature_template SET `spell_id%u`=0 WHERE entry=%u;", j + 1, cInfo->entry); const_cast(cInfo)->spells[j] = 0; } } if (cInfo->movement_type >= MAX_DB_MOTION_TYPE) { - sLog.outErrorDb("Creature (Entry: %u) has wrong movement generator type (%u), ignore and set to IDLE.", cInfo->entry, cInfo->movement_type); - sLog.out(LOG_DBERRFIX, "UPDATE creature_template SET `MovementType`=%u WHERE entry=%u;", IDLE_MOTION_TYPE, cInfo->entry); + sLog.outErrorDb("Creature (Entry: %u) has wrong movement generator type (%u), ignored and set to IDLE.", cInfo->entry, cInfo->movement_type); + sLog.out(LOG_DBERRFIX, "UPDATE creature_template SET `movement_type`=%u WHERE entry=%u;", IDLE_MOTION_TYPE, cInfo->entry); const_cast(cInfo)->movement_type = IDLE_MOTION_TYPE; } @@ -1841,8 +1841,8 @@ void ObjectMgr::LoadCreatures(bool reload) data.spawntimesecsmax = fields[10].GetUInt32(); data.spawndist = fields[11].GetFloat(); data.currentwaypoint = fields[12].GetUInt32(); - data.curhealth = fields[13].GetUInt32(); - data.curmana = fields[14].GetUInt32(); + float curhealth = fields[13].GetFloat(); + float curmana = fields[14].GetFloat(); data.is_dead = fields[15].GetBool(); data.movementType = fields[16].GetUInt8(); data.spawnFlags = fields[20].GetUInt32(); @@ -1852,6 +1852,38 @@ void ObjectMgr::LoadCreatures(bool reload) int16 GuidPoolId = fields[18].GetInt16(); int16 EntryPoolId = fields[19].GetInt16(); + if ((cInfo->regeneration & REGEN_FLAG_HEALTH) && (cInfo->health_min > 0) && (curhealth < 100.0f) && !data.is_dead) + { + sLog.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with REGEN_FLAG_HEALTH and low current health percent (%g%%).", guid, data.id, curhealth); + sLog.out(LOG_DBERRFIX, "UPDATE creature SET curhealth=100 WHERE guid=%u AND id=%u;", guid, data.id); + curhealth = 100.0f; + } + + if ((cInfo->regeneration & REGEN_FLAG_POWER) && (cInfo->mana_min > 0) && (curmana < 100.0f)) + { + sLog.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with REGEN_FLAG_POWER and low current mana percent (%g%%).", guid, data.id, curmana); + sLog.out(LOG_DBERRFIX, "UPDATE creature SET curmana=100 WHERE guid=%u AND id=%u;", guid, data.id); + curmana = 100.0f; + } + + if (curhealth > 100.0f) + { + sLog.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with more than 100%% health.", guid, data.id); + sLog.out(LOG_DBERRFIX, "UPDATE creature SET curhealth=100 WHERE guid=%u AND id=%u;", guid, data.id); + curhealth = 100.0f; + } + + if (curmana > 100.0f) + { + sLog.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with more than 100%% mana.", guid, data.id); + sLog.out(LOG_DBERRFIX, "UPDATE creature SET curmana=100 WHERE guid=%u AND id=%u;", guid, data.id); + curmana = 100.0f; + } + + // Calculate exact health and mana for spawn. + data.curhealth = cInfo->health_max * curhealth / 100.0f; + data.curmana = cInfo->mana_max * curmana / 100.0f; + MapEntry const* mapEntry = sMapStorage.LookupEntry(data.mapid); if (!mapEntry) { @@ -1886,13 +1918,6 @@ void ObjectMgr::LoadCreatures(bool reload) } } - if (cInfo->regeneration && data.curhealth < cInfo->health_min) - { - sLog.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with `creature_template`.`RegenHealth`=1 and low current health (%u), `creature_template`.`minhealth`=%u.", guid, data.id, data.curhealth, cInfo->health_min); - sLog.out(LOG_DBERRFIX, "UPDATE creature SET curhealth=%u WHERE guid=%u AND id=%u;", cInfo->health_min, guid, data.id); - data.curhealth = cInfo->health_min; - } - if (cInfo->flags_extra & CREATURE_FLAG_EXTRA_INSTANCE_BIND) { if (!mapEntry || !mapEntry->IsDungeon()) @@ -1907,13 +1932,6 @@ void ObjectMgr::LoadCreatures(bool reload) guid, data.id, CREATURE_FLAG_EXTRA_AGGRO_ZONE); } - if (data.curmana < cInfo->mana_min) - { - sLog.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with low current mana (%u), `creature_template`.`minmana`=%u.", guid, data.id, data.curmana, cInfo->mana_min); - sLog.out(LOG_DBERRFIX, "UPDATE creature SET curmana=%u WHERE guid=%u AND id=%u;", cInfo->mana_min, guid, data.id); - data.curmana = cInfo->mana_min; - } - if (data.spawndist < 0.0f) { sLog.outErrorDb("Table `creature` have creature (GUID: %u Entry: %u) with `spawndist`< 0, set to 0.", guid, data.id); @@ -10101,8 +10119,6 @@ uint32 ObjectMgr::AddCreData(uint32 entry, uint32 /*team*/, uint32 mapId, float if (!map) return 0; - uint32 level = cInfo->level_min == cInfo->level_max ? cInfo->level_min : urand(cInfo->level_min, cInfo->level_max); // Only used for extracting creature base stats - uint32 guid = map->GenerateLocalLowGuid(HIGHGUID_UNIT); CreatureData& data = NewOrExistCreatureData(guid); data.id = entry; @@ -10121,7 +10137,6 @@ uint32 ObjectMgr::AddCreData(uint32 entry, uint32 /*team*/, uint32 mapId, float data.is_dead = false; data.movementType = cInfo->movement_type; - AddCreatureToGrid(guid, &data); // Spawn if necessary (loaded grids only) diff --git a/src/game/Objects/Creature.cpp b/src/game/Objects/Creature.cpp index 8dbf7c4b8..e8baf04b5 100644 --- a/src/game/Objects/Creature.cpp +++ b/src/game/Objects/Creature.cpp @@ -483,7 +483,7 @@ bool Creature::UpdateEntry(uint32 Entry, Team team, const CreatureData *data /*= SetSheath(SHEATH_STATE_MELEE); SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_AURAS); - SelectLevel(GetCreatureInfo(), preserveHPAndPower ? GetHealthPercent() : 100.0f, 100.0f); + SelectLevel(GetCreatureInfo(), preserveHPAndPower ? GetHealthPercent() : 100.0f, preserveHPAndPower ? GetPowerPercent(POWER_MANA) : 100.0f); setFaction(GetCreatureInfo()->faction); @@ -1420,6 +1420,9 @@ void Creature::SaveToDB(uint32 mapid) ? IDLE_MOTION_TYPE : GetDefaultMovementType(); data.spawnFlags = m_isActiveObject ? SPAWN_FLAG_ACTIVE : 0; + float const spawndist = GetDefaultMovementType() == RANDOM_MOTION_TYPE ? m_respawnradius : 0.0f; + float const curmana = GetMaxPower(POWER_MANA) ? GetPowerPercent(POWER_MANA) : 0.0f; + // updated in DB WorldDatabase.BeginTransaction(); @@ -1438,16 +1441,16 @@ void Creature::SaveToDB(uint32 mapid) << GetOrientation() << "," << data.spawntimesecsmin << "," // respawn time minimum << data.spawntimesecsmax << "," // respawn time maximum - << (float) m_respawnradius << "," //spawn distance (float) - << (uint32)(0) << "," //currentwaypoint - << GetHealth() << "," //curhealth - << GetPower(POWER_MANA) << "," //curmana - << (m_isDeadByDefault ? 1 : 0) << "," //is_dead - << GetDefaultMovementType() << "," //default movement generator type + << spawndist << "," // spawn distance + << (uint32)(0) << "," // currentwaypoint + << GetHealthPercent() << "," // curhealth + << curmana << "," // curmana + << (m_isDeadByDefault ? 1 : 0) << "," // is_dead + << GetDefaultMovementType() << "," // default movement generator type << m_isActiveObject << "," << m_visibilityModifier << "," - << "0," //patch_min - << "10)"; //patch_max + << "0," // patch_min + << "10)"; // patch_max WorldDatabase.PExecuteLog("%s", ss.str().c_str()); @@ -1487,10 +1490,12 @@ void Creature::SelectLevel(const CreatureInfo *cinfo, float percentHealth, float uint32 mana = minmana + uint32(rellevel * (maxmana - minmana)); SetCreateMana(mana); - SetMaxPower(POWER_MANA, mana); //MAX Mana - SetPower(POWER_MANA, mana); + SetMaxPower(POWER_MANA, mana); - // TODO: set UNIT_FIELD_POWER*, for some creature class case (energy, etc) + if (percentMana == 100.0f) + SetPower(POWER_MANA, mana); + else + SetPowerPercent(POWER_MANA, percentMana); SetModifierValue(UNIT_MOD_HEALTH, BASE_VALUE, float(health)); SetModifierValue(UNIT_MOD_MANA, BASE_VALUE, float(mana)); diff --git a/src/game/Objects/Object.cpp b/src/game/Objects/Object.cpp index 7a45bc82b..db7bb21f9 100644 --- a/src/game/Objects/Object.cpp +++ b/src/game/Objects/Object.cpp @@ -680,7 +680,7 @@ void Object::BuildValuesUpdate(uint8 updatetype, ByteBuffer * data, UpdateMask * else *data << uint32(m_uint32Values[index]); } - // Hide real health value. Send a percent instead. See ShowHealth.Values option in mangosd.conf + // Hide real health value. Send a percent instead. See ShowHealthValues option in mangosd.conf else if (!ShowHealthValues && (index == UNIT_FIELD_HEALTH || index == UNIT_FIELD_MAXHEALTH)) { Player* owner = ((Unit*)this)->GetCharmerOrOwnerPlayerOrPlayerItself(); diff --git a/src/game/Objects/Unit.cpp b/src/game/Objects/Unit.cpp index f6b0a1c2d..cd83deaa3 100644 --- a/src/game/Objects/Unit.cpp +++ b/src/game/Objects/Unit.cpp @@ -9034,6 +9034,12 @@ void Unit::SetHealthPercent(float percent) SetHealth(newHealth); } +void Unit::SetPowerPercent(Powers power, float percent) +{ + uint32 newMana = GetMaxPower(power) * percent / 100.0f; + SetPower(power, newMana); +} + void Unit::SetPower(Powers power, uint32 val) { if (GetPower(power) == val) diff --git a/src/game/Objects/Unit.h b/src/game/Objects/Unit.h index eda1cf4a1..1c1983359 100644 --- a/src/game/Objects/Unit.h +++ b/src/game/Objects/Unit.h @@ -1258,9 +1258,10 @@ class MANGOS_DLL_SPEC Unit : public WorldObject void SetInitCreaturePowerType(); uint32 GetPower( Powers power) const { return GetUInt32Value(UNIT_FIELD_POWER1 +power); } uint32 GetMaxPower(Powers power) const { return GetUInt32Value(UNIT_FIELD_MAXPOWER1+power); } - float GetPowerPercent(Powers power) const { return (GetPower(power)*100.0f) / GetMaxPower(power); } + float GetPowerPercent(Powers power) const { return GetMaxPower(power) ? ((GetPower(power)*100.0f) / GetMaxPower(power)) : 100.0f; } void SetPower( Powers power, uint32 val); void SetMaxPower(Powers power, uint32 val); + void SetPowerPercent(Powers power, float percent); int32 ModifyPower(Powers power, int32 val); void ApplyPowerMod(Powers power, uint32 val, bool apply); void ApplyMaxPowerMod(Powers power, uint32 val, bool apply);