Core/Creatures: Changed the spawn health field in creature table to a percentage

Port From (https://github.com/TrinityCore/TrinityCore/commit/def601b4ff82ec8a90af60408a87cac92fdf070d)
This commit is contained in:
Hondacrx
2024-08-04 16:31:25 -04:00
parent 8969d59a41
commit cb16de1f15
10 changed files with 112 additions and 87 deletions
+1 -1
View File
@@ -1979,7 +1979,7 @@ namespace Framework.Constants
ContinueRegenWhileFatigued = 0x200,
RegenAffectedByHaste = 0x400,
SetToMaxOnLevelUp = 0x1000,
SetToMaxLevelOnInitialLogIn = 0x2000,
SetToMaxOnInitialLogIn = 0x2000,
AllowCostModsForPlayers = 0x4000
}
@@ -1,6 +1,6 @@
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
namespace Framework.Database
{
public class WorldDatabase : MySqlBase<WorldStatements>
@@ -50,7 +50,7 @@ namespace Framework.Database
PrepareStatement(WorldStatements.SEL_CREATURE_BY_ID, "SELECT guid FROM creature WHERE id = ?");
PrepareStatement(WorldStatements.SEL_GAMEOBJECT_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM gameobject WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_");
PrepareStatement(WorldStatements.SEL_CREATURE_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM creature WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_");
PrepareStatement(WorldStatements.INS_CREATURE, "INSERT INTO creature (guid, id , map, spawnDifficulties, PhaseId, PhaseGroup, modelid, equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, wander_distance, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, unit_flags2, unit_flags3) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
PrepareStatement(WorldStatements.INS_CREATURE, "INSERT INTO creature(guid, id, map, spawnDifficulties, PhaseId, PhaseGroup, modelid, equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, wander_distance, currentwaypoint, curHealthPct, MovementType, npcflag, unit_flags, unit_flags2, unit_flags3) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
PrepareStatement(WorldStatements.DEL_GAME_EVENT_CREATURE, "DELETE FROM game_event_creature WHERE guid = ?");
PrepareStatement(WorldStatements.DEL_GAME_EVENT_MODEL_EQUIP, "DELETE FROM game_event_model_equip WHERE guid = ?");
PrepareStatement(WorldStatements.INS_GAMEOBJECT, "INSERT INTO gameobject (guid, id, map, spawnDifficulties, PhaseId, PhaseGroup, position_x, position_y, position_z, orientation, rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+1 -2
View File
@@ -990,9 +990,8 @@ namespace Game.Chat
return false;
}
creature.SetMaxHealth((uint)(100 + 30 * lvl));
creature.SetHealth((uint)(100 + 30 * lvl));
creature.SetLevel(lvl);
creature.UpdateLevelDependantStats();
creature.SaveToDB();
return true;
+6 -38
View File
@@ -1399,8 +1399,7 @@ namespace Game.Entities
// prevent add data integrity problems
data.WanderDistance = GetDefaultMovementType() == MovementGeneratorType.Idle ? 0.0f : m_wanderDistance;
data.currentwaypoint = 0;
data.curhealth = (uint)GetHealth();
data.curmana = (uint)GetPower(PowerType.Mana);
data.curHealthPct = (uint)GetHealthPct();
// prevent add data integrity problems
data.movementType = (byte)(m_wanderDistance == 0 && GetDefaultMovementType() == MovementGeneratorType.Random
? MovementGeneratorType.Idle : GetDefaultMovementType());
@@ -1440,8 +1439,7 @@ namespace Game.Entities
stmt.AddValue(index++, m_respawnDelay);
stmt.AddValue(index++, m_wanderDistance);
stmt.AddValue(index++, 0);
stmt.AddValue(index++, GetHealth());
stmt.AddValue(index++, GetPower(PowerType.Mana));
stmt.AddValue(index++, (uint)GetHealthPct());
stmt.AddValue(index++, (byte)GetDefaultMovementType());
if (npcflag.HasValue)
stmt.AddValue(index++, npcflag.Value);
@@ -1478,7 +1476,7 @@ namespace Game.Entities
UpdateLevelDependantStats();
}
void UpdateLevelDependantStats()
public void UpdateLevelDependantStats()
{
CreatureTemplate cInfo = GetCreatureTemplate();
CreatureClassifications classification = IsPet() ? CreatureClassifications.Normal : cInfo.Classification;
@@ -1502,16 +1500,7 @@ namespace Game.Entities
PowerType powerType = CalculateDisplayPowerType();
SetCreateMana(stats.BaseMana);
SetStatPctModifier(UnitMods.PowerStart + (int)powerType, UnitModifierPctType.Base, GetCreatureDifficulty().ManaModifier);
SetPowerType(powerType);
PowerTypeRecord powerTypeEntry = Global.DB2Mgr.GetPowerTypeEntry(powerType);
if (powerTypeEntry != null)
{
if (powerTypeEntry.HasFlag(PowerTypeFlags.UnitsUseDefaultPowerOnInit))
SetPower(powerType, powerTypeEntry.DefaultPower);
else
SetFullPower(powerType);
}
SetPowerType(powerType, true, true);
//Damage
float basedamage = GetBaseDamageForLevel(level);
@@ -1764,29 +1753,8 @@ namespace Game.Entities
public void SetSpawnHealth()
{
if (_staticFlags.HasFlag(CreatureStaticFlags5.NoHealthRegen))
return;
ulong curhealth;
if (m_creatureData != null && !_regenerateHealth)
{
curhealth = m_creatureData.curhealth;
if (curhealth != 0)
{
curhealth = (uint)(curhealth * GetHealthMod(GetCreatureTemplate().Classification));
if (curhealth < 1)
curhealth = 1;
}
SetPower(PowerType.Mana, (int)m_creatureData.curmana);
}
else
{
curhealth = GetMaxHealth();
SetFullPower(PowerType.Mana);
}
SetHealth((m_deathState == DeathState.Alive || m_deathState == DeathState.JustRespawned) ? curhealth : 0);
SetHealth(CountPctFromMaxHealth(m_creatureData != null ? (int)m_creatureData.curHealthPct : 100));
SetInitialPowerValue(GetPowerType());
}
public override bool HasQuest(uint questId)
@@ -266,8 +266,7 @@ namespace Game.Entities
public sbyte equipmentId;
public float WanderDistance;
public uint currentwaypoint;
public uint curhealth;
public uint curmana;
public uint curHealthPct;
public byte movementType;
public ulong? npcflag;
public uint? unit_flags; // enum UnitFlags mask values
+45 -20
View File
@@ -577,12 +577,43 @@ namespace Game.Entities
//Powers
public PowerType GetPowerType() { return (PowerType)(byte)m_unitData.DisplayPower; }
public void SetPowerType(PowerType powerType, bool sendUpdate = true)
public void SetPowerType(PowerType power, bool sendUpdate = true, bool onInit = false)
{
if (GetPowerType() == powerType)
if (!onInit && GetPowerType() == power)
return;
SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.DisplayPower), (byte)powerType);
PowerTypeRecord powerTypeEntry = Global.DB2Mgr.GetPowerTypeEntry(power);
if (powerTypeEntry == null)
return;
if (IsCreature() && !powerTypeEntry.HasFlag(PowerTypeFlags.IsUsedByNPCs))
return;
SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.DisplayPower), (byte)power);
// Update max power
UpdateMaxPower(power);
// Update current power
if (!onInit)
{
switch (power)
{
case PowerType.Mana: // Keep the same (druid form switching...)
case PowerType.Energy:
break;
case PowerType.Rage: // Reset to zero
SetPower(PowerType.Rage, 0);
break;
case PowerType.Focus: // Make it full
SetFullPower(power);
break;
default:
break;
}
}
else
SetInitialPowerValue(power);
if (!sendUpdate)
return;
@@ -600,24 +631,18 @@ namespace Game.Entities
pet.SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE);
}*/
// Update max power
UpdateMaxPower(powerType);
}
// Update current power
switch (powerType)
{
case PowerType.Mana: // Keep the same (druid form switching...)
case PowerType.Energy:
break;
case PowerType.Rage: // Reset to zero
SetPower(PowerType.Rage, 0);
break;
case PowerType.Focus: // Make it full
SetFullPower(powerType);
break;
default:
break;
}
public void SetInitialPowerValue(PowerType power)
{
PowerTypeRecord powerTypeEntry = Global.DB2Mgr.GetPowerTypeEntry(power);
if (powerTypeEntry == null)
return;
if (powerTypeEntry.HasFlag(PowerTypeFlags.UnitsUseDefaultPowerOnInit))
SetPower(power, powerTypeEntry.DefaultPower);
else
SetFullPower(power);
}
public void SetOverrideDisplayPowerId(uint powerDisplayId) { SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.OverrideDisplayPowerID), powerDisplayId); }
+26 -20
View File
@@ -3446,9 +3446,9 @@ namespace Game
// 0 1 2 3 4 5 6 7 8 9 10
SQLResult result = DB.World.Query("SELECT creature.guid, id, map, position_x, position_y, position_z, orientation, modelid, equipment_id, spawntimesecs, wander_distance, " +
//11 12 13 14 15 16 17 18 19 20 21
"currentwaypoint, curhealth, curmana, MovementType, spawnDifficulties, eventEntry, poolSpawnId, creature.npcflag, creature.unit_flags, creature.unit_flags2, creature.unit_flags3, " +
//22 23 24 25 26 27
//11 12 13 14 15 16 17 18 19 20
"currentwaypoint, curHealthPct, MovementType, spawnDifficulties, eventEntry, poolSpawnId, creature.npcflag, creature.unit_flags, creature.unit_flags2, creature.unit_flags3, " +
//21 22 23 24 25 26
"creature.phaseUseFlags, creature.phaseid, creature.phasegroup, creature.terrainSwapMap, creature.ScriptName, creature.StringId " +
"FROM creature LEFT OUTER JOIN game_event_creature ON creature.guid = game_event_creature.guid LEFT OUTER JOIN pool_members ON pool_members.type = 0 AND creature.guid = pool_members.spawnId");
@@ -3499,28 +3499,27 @@ namespace Game
data.spawntimesecs = result.Read<int>(9);
data.WanderDistance = result.Read<float>(10);
data.currentwaypoint = result.Read<uint>(11);
data.curhealth = result.Read<uint>(12);
data.curmana = result.Read<uint>(13);
data.movementType = result.Read<byte>(14);
data.SpawnDifficulties = ParseSpawnDifficulties(result.Read<string>(15), "creature", guid, data.MapId, spawnMasks.LookupByKey(data.MapId));
short gameEvent = result.Read<short>(16);
data.poolId = result.Read<uint>(17);
data.curHealthPct = result.Read<uint>(12);
data.movementType = result.Read<byte>(13);
data.SpawnDifficulties = ParseSpawnDifficulties(result.Read<string>(14), "creature", guid, data.MapId, spawnMasks.LookupByKey(data.MapId));
short gameEvent = result.Read<short>(15);
data.poolId = result.Read<uint>(16);
if (!result.IsNull(17))
data.npcflag = result.Read<ulong>(17);
if (!result.IsNull(18))
data.npcflag = result.Read<ulong>(18);
data.unit_flags = result.Read<uint>(18);
if (!result.IsNull(19))
data.unit_flags = result.Read<uint>(19);
data.unit_flags2 = result.Read<uint>(19);
if (!result.IsNull(20))
data.unit_flags2 = result.Read<uint>(20);
if (!result.IsNull(21))
data.unit_flags3 = result.Read<uint>(21);
data.unit_flags3 = result.Read<uint>(20);
data.PhaseUseFlags = (PhaseUseFlagsValues)result.Read<byte>(22);
data.PhaseId = result.Read<uint>(23);
data.PhaseGroup = result.Read<uint>(24);
data.terrainSwapMap = result.Read<int>(25);
data.ScriptId = GetScriptId(result.Read<string>(26));
data.StringId = result.Read<string>(27);
data.PhaseUseFlags = (PhaseUseFlagsValues)result.Read<byte>(21);
data.PhaseId = result.Read<uint>(22);
data.PhaseGroup = result.Read<uint>(23);
data.terrainSwapMap = result.Read<int>(24);
data.ScriptId = GetScriptId(result.Read<string>(25));
data.StringId = result.Read<string>(26);
data.spawnGroupData = _spawnGroupDataStorage[IsTransportMap(data.MapId) ? 1 : 0u]; // transport spawns default to compatibility group
var mapEntry = CliDB.MapStorage.LookupByKey(data.MapId);
@@ -3662,6 +3661,13 @@ namespace Game
}
}
uint healthPct = Math.Clamp(data.curHealthPct, 1, 100);
if (data.curHealthPct != healthPct)
{
Log.outError(LogFilter.Sql, $"Table `creature` has creature (GUID: {guid} Entry: {data.Id}) with invalid `curHealthPct` {data.curHealthPct}, set to {healthPct}.");
data.curHealthPct = healthPct;
}
if (WorldConfig.GetBoolValue(WorldCfg.CalculateCreatureZoneAreaData))
{
PhasingHandler.InitDbVisibleMapId(phaseShift, data.terrainSwapMap);
@@ -56,6 +56,7 @@ namespace Scripts.EasternKingdoms.BlackrockMountain.BlackwingLair.Vaelastrasz
{
_Reset();
me.SetSpawnHealth();
me.SetStandState(UnitStandStateType.Dead);
Initialize();
}
@@ -65,7 +66,6 @@ namespace Scripts.EasternKingdoms.BlackrockMountain.BlackwingLair.Vaelastrasz
base.JustEngagedWith(who);
DoCast(me, SpellIds.Essenceofthered);
me.SetHealth(me.CountPctFromMaxHealth(30));
// now drop damage requirement to be able to take loot
me.ResetPlayerDamageReq();
+28
View File
@@ -5102,4 +5102,32 @@ namespace Scripts.Spells.Generic
DoEffectCalcDamageAndHealing.Add(new(CalculateHealingBonus, SpellConst.EffectAll, AuraType.Any));
}
}
// 24931 - 100 Health
// 24959 - 500 Health
// 28838 - 1 Health
// 43645 - 1 Health
// 73342 - 1 Health
[Script] // 86562 - 1 Health
class spell_gen_set_health : SpellScript
{
ulong _health;
public spell_gen_set_health(ulong health)
{
_health = health;
}
void HandleHit(uint effIndex)
{
if (GetHitUnit().IsAlive() && _health > 0)
GetHitUnit().SetHealth(_health);
}
public override void Register()
{
OnEffectHitTarget.Add(new EffectHandler(HandleHit, 0, SpellEffectName.ScriptEffect));
}
}
}
+1 -1
View File
@@ -868,7 +868,7 @@ namespace Scripts.World.NpcsSpecial
me.SetStandState(UnitStandStateType.Kneel);
// expect database to have RegenHealth=0
me.SetHealth(me.CountPctFromMaxHealth(70));
me.SetSpawnHealth();
}
public override void JustEngagedWith(Unit who) { }