Core/Vehicles: Remove vehicle stat scaling hack and implement it properly trough the spell system. NOTE: This does need some further research on coefficients for different vehicles.

Signed-off-by: Machiavelli <[email protected]>
This commit is contained in:
Sarjuuk
2011-06-27 14:23:58 +02:00
committed by Machiavelli
parent 8fd3c912c1
commit 249692b54b
8 changed files with 67 additions and 78 deletions
+6
View File
@@ -1988,6 +1988,12 @@ INSERT INTO `spell_script_names` (`spell_id`,`ScriptName`) VALUES
( 12749, 'spell_gen_allow_cast_from_item_only'), ( 12749, 'spell_gen_allow_cast_from_item_only'),
( 13258, 'spell_gen_allow_cast_from_item_only'), ( 13258, 'spell_gen_allow_cast_from_item_only'),
( 13166, 'spell_gen_allow_cast_from_item_only'), ( 13166, 'spell_gen_allow_cast_from_item_only'),
(65266, 'spell_gen_vehicle_scaling'),
(65635, 'spell_gen_vehicle_scaling'),
(65636, 'spell_gen_vehicle_scaling'),
(66666, 'spell_gen_vehicle_scaling'),
(66667, 'spell_gen_vehicle_scaling'),
(66668, 'spell_gen_vehicle_scaling'),
-- instances -- instances
-- Black Temple -- Black Temple
( 41475, 'spell_boss_lady_malande_shield'), ( 41475, 'spell_boss_lady_malande_shield'),
@@ -0,0 +1,8 @@
DELETE FROM `spell_script_names` WHERE `spell_id` IN(65266,65635,65636,66666,66667,66668);
INSERT INTO `spell_script_names` (`spell_id`,`ScriptName`) VALUES
(65266,'spell_gen_vehicle_scaling'),
(65635,'spell_gen_vehicle_scaling'),
(65636,'spell_gen_vehicle_scaling'),
(66666,'spell_gen_vehicle_scaling'),
(66667,'spell_gen_vehicle_scaling'),
(66668,'spell_gen_vehicle_scaling');
@@ -361,21 +361,6 @@ bool Vehicle::AddPassenger(Unit* unit, int8 seatId)
{ {
if (!me->SetCharmedBy(unit, CHARM_TYPE_VEHICLE)) if (!me->SetCharmedBy(unit, CHARM_TYPE_VEHICLE))
ASSERT(false); ASSERT(false);
// hack: should be done by aura system
if (VehicleScalingInfo const* scalingInfo = sObjectMgr->GetVehicleScalingInfo(m_vehicleInfo->m_ID))
{
Player* player = unit->ToPlayer();
float averageItemLevel = player->GetAverageItemLevel();
if (averageItemLevel < scalingInfo->baseItemLevel)
averageItemLevel = scalingInfo->baseItemLevel;
averageItemLevel -= scalingInfo->baseItemLevel;
float currentHealthPct = float(me->GetHealth() / me->GetMaxHealth());
m_bonusHP = uint32(me->GetMaxHealth() * (averageItemLevel * scalingInfo->scalingFactor));
me->SetMaxHealth(me->GetMaxHealth() + m_bonusHP);
me->SetHealth(uint32((me->GetHealth() + m_bonusHP) * currentHealthPct));
}
} }
if (me->IsInWorld()) if (me->IsInWorld())
@@ -95,16 +95,8 @@ struct VehicleAccessory
uint32 SummonTime; uint32 SummonTime;
}; };
struct VehicleScalingInfo
{
uint32 ID;
float baseItemLevel;
float scalingFactor;
};
typedef std::vector<VehicleAccessory> VehicleAccessoryList; typedef std::vector<VehicleAccessory> VehicleAccessoryList;
typedef std::map<uint32, VehicleAccessoryList> VehicleAccessoryMap; typedef std::map<uint32, VehicleAccessoryList> VehicleAccessoryMap;
typedef std::map<uint32, VehicleScalingInfo> VehicleScalingMap;
typedef std::map<int8, VehicleSeat> SeatMap; typedef std::map<int8, VehicleSeat> SeatMap;
class Vehicle class Vehicle
-42
View File
@@ -2935,48 +2935,6 @@ void ObjectMgr::LoadVehicleAccessories()
sLog->outString(); sLog->outString();
} }
void ObjectMgr::LoadVehicleScaling()
{
uint32 oldMSTime = getMSTime();
m_VehicleScalingMap.clear(); // needed for reload case
uint32 count = 0;
QueryResult result = WorldDatabase.Query("SELECT `entry`, `baseItemLevel`, `scalingFactor` FROM `vehicle_scaling_info`");
if (!result)
{
sLog->outString(">> Loaded 0 vehicle scaling entries. DB table `vehicle_scaling_info` is empty.");
sLog->outString();
return;
}
do
{
Field *fields = result->Fetch();
uint32 vehicleEntry = fields[0].GetUInt32();
float baseItemLevel = fields[1].GetFloat();
float scalingFactor = fields[2].GetFloat();
if (!sVehicleStore.LookupEntry(vehicleEntry))
{
sLog->outErrorDb("Table `vehicle_scaling_info`: vehicle entry %u does not exist.", vehicleEntry);
continue;
}
m_VehicleScalingMap[vehicleEntry].ID = vehicleEntry;
m_VehicleScalingMap[vehicleEntry].baseItemLevel = baseItemLevel;
m_VehicleScalingMap[vehicleEntry].scalingFactor = scalingFactor;
++count;
} while (result->NextRow());
sLog->outString(">> Loaded %u vehicle scaling entries in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
sLog->outString();
}
void ObjectMgr::LoadPetLevelInfo() void ObjectMgr::LoadPetLevelInfo()
{ {
uint32 oldMSTime = getMSTime(); uint32 oldMSTime = getMSTime();
-10
View File
@@ -791,14 +791,6 @@ class ObjectMgr
return NULL; return NULL;
} }
VehicleScalingInfo const* GetVehicleScalingInfo(uint32 vehicleEntry) const
{
VehicleScalingMap::const_iterator itr = m_VehicleScalingMap.find(vehicleEntry);
if (itr != m_VehicleScalingMap.end())
return &itr->second;
return NULL;
}
DungeonEncounterList const* GetDungeonEncounterList(uint32 mapId, Difficulty difficulty) DungeonEncounterList const* GetDungeonEncounterList(uint32 mapId, Difficulty difficulty)
{ {
UNORDERED_MAP<uint32, DungeonEncounterList>::const_iterator itr = mDungeonEncounters.find(MAKE_PAIR32(mapId, difficulty)); UNORDERED_MAP<uint32, DungeonEncounterList>::const_iterator itr = mDungeonEncounters.find(MAKE_PAIR32(mapId, difficulty));
@@ -896,7 +888,6 @@ class ObjectMgr
void LoadMailLevelRewards(); void LoadMailLevelRewards();
void LoadVehicleTemplateAccessories(); void LoadVehicleTemplateAccessories();
void LoadVehicleAccessories(); void LoadVehicleAccessories();
void LoadVehicleScaling();
void LoadGossipText(); void LoadGossipText();
@@ -1280,7 +1271,6 @@ class ObjectMgr
VehicleAccessoryMap m_VehicleTemplateAccessoryMap; VehicleAccessoryMap m_VehicleTemplateAccessoryMap;
VehicleAccessoryMap m_VehicleAccessoryMap; VehicleAccessoryMap m_VehicleAccessoryMap;
VehicleScalingMap m_VehicleScalingMap;
typedef std::vector<LocaleConstant> LocalForIndex; typedef std::vector<LocaleConstant> LocalForIndex;
LocalForIndex m_LocalForIndex; LocalForIndex m_LocalForIndex;
-3
View File
@@ -1349,9 +1349,6 @@ void World::SetInitialWorldSettings()
sLog->outString("Loading Creature template addons..."); sLog->outString("Loading Creature template addons...");
sObjectMgr->LoadCreatureTemplateAddons(); sObjectMgr->LoadCreatureTemplateAddons();
sLog->outString("Loading Vehicle scaling information...");
sObjectMgr->LoadVehicleScaling();
sLog->outString("Loading Reputation Reward Rates..."); sLog->outString("Loading Reputation Reward Rates...");
sObjectMgr->LoadReputationRewardRate(); sObjectMgr->LoadReputationRewardRate();
@@ -1213,6 +1213,58 @@ class spell_gen_launch : public SpellScriptLoader
} }
}; };
class spell_gen_vehicle_scaling : public SpellScriptLoader
{
public:
spell_gen_vehicle_scaling() : SpellScriptLoader("spell_gen_vehicle_scaling") { }
class spell_gen_vehicle_scaling_AuraScript : public AuraScript
{
PrepareAuraScript(spell_gen_vehicle_scaling_AuraScript);
void CalculateAmount(AuraEffect const* /*aurEff*/, int32& amount, bool& /*canBeRecalculated*/)
{
Unit* caster = GetCaster();
if (!caster || !caster->ToPlayer())
return;
float factor;
uint16 baseItemLevel;
// TODO: Reserach coeffs for different vehicles
switch (GetId())
{
case 66668:
factor = 0.01;
baseItemLevel = 205;
break;
default:
factor = 0.01f;
baseItemLevel = 170;
break;
}
float avgILvl = caster->ToPlayer()->GetAverageItemLevel();
if (avgILvl < baseItemLevel)
return;
amount = 100 - uint16(100.0f * avgILvl / baseItemLevel);
}
void Register()
{
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_vehicle_scaling_AuraScript::CalculateAmount, EFFECT_0, SPELL_AURA_MOD_HEALING_PCT);
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_vehicle_scaling_AuraScript::CalculateAmount, EFFECT_1, SPELL_AURA_MOD_DAMAGE_PERCENT_DONE);
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_vehicle_scaling_AuraScript::CalculateAmount, EFFECT_2, SPELL_AURA_MOD_INCREASE_HEALTH_PERCENT);
}
};
AuraScript* GetAuraScript() const
{
return new spell_gen_vehicle_scaling_AuraScript();
}
};
void AddSC_generic_spell_scripts() void AddSC_generic_spell_scripts()
{ {
new spell_gen_absorb0_hitlimit1(); new spell_gen_absorb0_hitlimit1();
@@ -1241,4 +1293,5 @@ void AddSC_generic_spell_scripts()
new spell_gen_magic_rooster(); new spell_gen_magic_rooster();
new spell_gen_allow_cast_from_item_only(); new spell_gen_allow_cast_from_item_only();
new spell_gen_launch(); new spell_gen_launch();
new spell_gen_vehicle_scaling();
} }