feat(Core/Creature): Allow 3 ids per spawn point. TESTING (#10169)

* feat(Core/Creature): Allow 3 ids per spawn point.

* Move GetRandomId to a function

* Update id to id1

* Fixed some errors crashing core and text

* Set ids to lowercase for GetRandomId function

* Update src/server/database/Database/Implementation/WorldDatabase.cpp

Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>

Co-authored-by: acidmanifesto <joshua.lee.betts@gmail.com>
Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
This commit is contained in:
Malcrom
2022-01-14 19:21:50 -04:00
committed by GitHub
parent cdca93aa7f
commit dfac47a562
17 changed files with 123 additions and 80 deletions

View File

@@ -1310,7 +1310,7 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
dynamicflags = 0;
}
data.id = GetEntry();
data.id1 = GetEntry();
data.mapid = mapid;
data.phaseMask = phaseMask;
data.displayid = displayId;
@@ -1357,7 +1357,7 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
stmt->setUInt32(index++, m_spawnId);
stmt->setUInt32(index++, GetEntry());
stmt->setUInt32(index++, 0);
stmt->setFloat(index++, 100.0f);
stmt->setUInt32(index++, 0);
stmt->setUInt16(index++, uint16(mapid));
stmt->setUInt8(index++, spawnMask);
stmt->setUInt32(index++, GetPhaseMask());
@@ -1613,9 +1613,7 @@ bool Creature::LoadCreatureFromDB(ObjectGuid::LowType spawnId, Map* map, bool ad
m_spawnId = spawnId;
// Add to world
uint32 entry = data->id;
if(data->id2)
entry = (roll_chance_f(data->chance_id1)) ? data->id : data->id2;
uint32 entry = GetRandomId(data->id1, data->id2, data->id3);
if (!Create(map->GenerateLowGuid<HighGuid::Unit>(), map, data->phaseMask, entry, 0, data->posX, data->posY, data->posZ, data->orientation, data))
return false;
@@ -1913,7 +1911,7 @@ void Creature::Respawn(bool force)
// Respawn check if spawn has 2 entries
if (data->id2)
{
uint32 entry = (roll_chance_f(data->chance_id1)) ? data->id : data->id2;
uint32 entry = GetRandomId(data->id1, data->id2, data->id3);
UpdateEntry(entry, data, true); // Select Random Entry
m_defaultMovementType = MovementGeneratorType(data->movementType); // Reload Movement Type
LoadEquipment(data->equipmentId); // Reload Equipment
@@ -3458,3 +3456,33 @@ bool Creature::CanPeriodicallyCallForAssistance() const
return true;
}
uint32 Creature::GetRandomId(uint32 id1, uint32 id2, uint32 id3)
{
uint32 id = id1;
uint8 ids = 0;
if (id2)
{
++ids;
if (id3) ++ids;
}
if (ids)
{
uint8 idNumber = urand(0, ids);
switch (idNumber)
{
case 0:
id = id1;
break;
case 1:
id = id2;
break;
case 2:
id = id3;
break;
}
}
return id;
}

View File

@@ -167,7 +167,7 @@ public:
[[nodiscard]] bool HasSpell(uint32 spellID) const override;
void UpdateMovementFlags();
uint32 GetRandomId(uint32 id1, uint32 id2, uint32 id3);
bool UpdateEntry(uint32 entry, const CreatureData* data = nullptr, bool changelevel = true );
bool UpdateStats(Stats stat) override;
bool UpdateAllStats() override;

View File

@@ -359,9 +359,9 @@ typedef std::unordered_map<uint32, EquipmentInfoContainerInternal> EquipmentInfo
struct CreatureData
{
CreatureData() { }
uint32 id{0}; // entry in creature_template
uint32 id1{0}; // entry in creature_template
uint32 id2{0}; // entry in creature_template
float chance_id1{0}; // Chance for first id to spawn
uint32 id3{0}; // entry in creature_template
uint16 mapid{0};
uint32 phaseMask{0};
uint32 displayid{0};