Skip to content

Commit

Permalink
Quakes now disable grow spells. PVP quakes are now supported (type 2,…
Browse files Browse the repository at this point in the history
… manual only) and PVP state 2 is now supported (temp pvp).

Fixed an issue with bootup & dynamic zones that let people enter / bootup dynamics of zones when zoning zone-to-zone.
  • Loading branch information
SecretsOTheP committed Dec 25, 2023
1 parent e51f718 commit 338a824
Show file tree
Hide file tree
Showing 21 changed files with 176 additions and 48 deletions.
10 changes: 4 additions & 6 deletions common/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2312,12 +2312,11 @@ bool Database::LoadNextQuakeTime(ServerEarthquakeImminent_Struct& earthquake_str
if (!results.Success() || results.RowCount() == 0)
{
random.Reseed();
QuakeType ruleset = (QuakeType)(random.Int(QuakeType::QuakeDisabled + 1, QuakeType::QuakeMax - 1));
uint32 random_timestamp = random.Int(RuleI(Quarm, QuakeMinVariance), RuleI(Quarm, QuakeMaxVariance));
Log(Logs::Detail, Logs::WorldServer, "Loading quake time failed. Using default rules values and a random ruleset...");
earthquake_struct.start_timestamp = Timer::GetTimeSeconds() + RuleI(Quarm, QuakeRepopDelay);
earthquake_struct.next_start_timestamp = earthquake_struct.start_timestamp + random_timestamp;
earthquake_struct.quake_type = ruleset;
earthquake_struct.quake_type = QuakeNormal;

std::string query1 = StringFormat("DELETE FROM quake_data");
auto results1 = QueryDatabase(query1);
Expand All @@ -2340,7 +2339,7 @@ bool Database::LoadNextQuakeTime(ServerEarthquakeImminent_Struct& earthquake_str
if (Timer::GetTimeSeconds() < earthquake_struct.start_timestamp + RuleI(Quarm, QuakeEndTimeDuration))
{
Log(Logs::Detail, Logs::WorldServer, "Recovering-from-downtime within 24 hour window. Using default rules values and a random ruleset...");
QuakeType ruleset = (QuakeType)(random.Int(QuakeType::QuakeDisabled + 1, QuakeType::QuakeMax - 1));
QuakeType ruleset = QuakeNormal;
uint32 random_timestamp = random.Int(RuleI(Quarm, QuakeMinVariance), RuleI(Quarm, QuakeMaxVariance));
earthquake_struct.start_timestamp = Timer::GetTimeSeconds() + RuleI(Quarm, QuakeRepopDelay);
earthquake_struct.quake_type = ruleset;
Expand All @@ -2361,15 +2360,14 @@ bool Database::LoadNextQuakeTime(ServerEarthquakeImminent_Struct& earthquake_str
}

//For usage on quake trigger. Does the 'fail logic' from above in the load process to set the next timer and current timer.
bool Database::SaveNextQuakeTime(ServerEarthquakeImminent_Struct& earthquake_struct)
bool Database::SaveNextQuakeTime(ServerEarthquakeImminent_Struct& earthquake_struct, QuakeType in_quake_type)
{
EQ::Random random;
random.Reseed();
QuakeType ruleset = (QuakeType)(random.Int(QuakeType::QuakeDisabled + 1, QuakeType::QuakeMax - 1));
uint32 random_timestamp = random.Int(RuleI(Quarm, QuakeMinVariance), RuleI(Quarm, QuakeMaxVariance));
earthquake_struct.start_timestamp = Timer::GetTimeSeconds() + RuleI(Quarm, QuakeRepopDelay);
earthquake_struct.next_start_timestamp = earthquake_struct.start_timestamp + random_timestamp;
earthquake_struct.quake_type = ruleset;
earthquake_struct.quake_type = in_quake_type;


std::string query1 = StringFormat("DELETE FROM quake_data");
Expand Down
2 changes: 1 addition & 1 deletion common/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class Database : public DBcore {
struct TimeOfDay_Struct LoadTime(time_t &realtime);
void LoadQuakeData(ServerEarthquakeImminent_Struct & earthquake_struct);
bool LoadNextQuakeTime(ServerEarthquakeImminent_Struct &realtime);
bool SaveNextQuakeTime(ServerEarthquakeImminent_Struct & earthquake_struct);
bool SaveNextQuakeTime(ServerEarthquakeImminent_Struct & earthquake_struct, QuakeType in_quake_type = QuakeType::QuakeNormal);
bool SaveTime(int8 minute, int8 hour, int8 day, int8 month, int16 year);
bool AdjustSpawnTimes();
uint8 GetZoneRandomLoc(uint32 zoneid);
Expand Down
8 changes: 4 additions & 4 deletions common/emu_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ std::string QuakeTypeToString(QuakeType in_type)

switch (in_type)
{
case QuakeType::QuakeFTE:
out_stringtype = "First to Engage";
case QuakeType::QuakeNormal:
out_stringtype = "Quake";
break;
case QuakeType::QuakeDPSRace:
out_stringtype = "DPS Race";
case QuakeType::QuakePVP:
out_stringtype = "PVP Quake";
break;
//case QuakeType::QuakeExtraMob:
// out_stringtype = "Extra Target for Server Rotation";
Expand Down
4 changes: 2 additions & 2 deletions common/emu_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ enum ConsiderLevel : uint8 {
enum QuakeType : uint8_t
{
QuakeDisabled = 0,
QuakeFTE = 1,
QuakeDPSRace = 2,
QuakeNormal = 1,
QuakePVP = 2,
QuakeMax
};

Expand Down
4 changes: 4 additions & 0 deletions common/servertalk.h
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,10 @@ struct ServerEarthquakeImminent_Struct {
QuakeType quake_type; // Player-imposed ruleset with quake. uint8_t enum
};

struct ServerEarthquakeRequest_Struct {
QuakeType type; // Time the last quake began, in seconds. UNIX Timestamp. QuakeType enforcement is supposed to cease 84600 seconds following this time. Raid mobs are supposed to respawn 86400 seconds after this time. Actual type will be unknown and stored in memory.
};

#pragma pack()

#endif
2 changes: 1 addition & 1 deletion world/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ void Client::EnterWorld(bool TryBootup) {
}
else
{
if (TryBootup && !RuleB(World, DontBootDynamics) && zoneGuildID != 0xFFFFFFFF) {
if (TryBootup && !RuleB(World, DontBootDynamics) || TryBootup && zoneGuildID != 0xFFFFFFFF) {
Log(Logs::Detail, Logs::WorldServer, "Attempting autobootup of (%d) (%d)", zoneID, zoneGuildID);
autobootup_timeout.Start();
pwaitingforbootup = zoneserver_list.TriggerBootup(zoneID, zoneGuildID);
Expand Down
12 changes: 7 additions & 5 deletions world/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ void LoadDatabaseConnections()
Timer NextQuakeTimer(900000);
Timer DisableQuakeTimer(900000);

void TriggerManualQuake()
void TriggerManualQuake(QuakeType in_quake_type)
{
uint32 cur_time = Timer::GetTimeSeconds();
database.SaveNextQuakeTime(next_quake);
database.SaveNextQuakeTime(next_quake, in_quake_type);

NextQuakeTimer.Enable();
NextQuakeTimer.Start((next_quake.next_start_timestamp - cur_time) * 1000);
Expand All @@ -161,7 +161,7 @@ void TriggerManualQuake()
//Inform of imminent quake. This happens after the MOTD so zone denizens are informed again with relevant information.
auto pack = new ServerPacket(ServerOP_QuakeImminent, sizeof(ServerEarthquakeImminent_Struct));
ServerEarthquakeImminent_Struct* seis = (ServerEarthquakeImminent_Struct*)pack->pBuffer;
seis->quake_type = next_quake.quake_type;
seis->quake_type = in_quake_type;
seis->next_start_timestamp = next_quake.next_start_timestamp;
seis->start_timestamp = next_quake.start_timestamp;
zoneserver_list.SendPacket(pack);
Expand Down Expand Up @@ -542,7 +542,9 @@ int main(int argc, char** argv) {
NextQuakeTimer.Start((next_quake.next_start_timestamp - cur_time) * 1000);

std::string motd_str = "Welcome to Project Quarm! ";
motd_str += "An earthquake ruleset is currently in effect in raid zones.";
motd_str += "The '";
motd_str += QuakeTypeToString(next_quake.quake_type);
motd_str += "' earthquake ruleset is currently in effect in raid zones.";

database.SetVariable("MOTD", motd_str.c_str());

Expand Down Expand Up @@ -590,7 +592,7 @@ int main(int argc, char** argv) {
//Inform of imminent quake. This happens after the MOTD so zone denizens are informed again with relevant information.
auto pack4 = new ServerPacket(ServerOP_QuakeEnded, sizeof(ServerEarthquakeImminent_Struct));
ServerEarthquakeImminent_Struct* seis = (ServerEarthquakeImminent_Struct*)pack4->pBuffer;
next_quake.quake_type == QuakeType::QuakeDisabled;
next_quake.quake_type = QuakeType::QuakeDisabled;
seis->quake_type = next_quake.quake_type;
seis->next_start_timestamp = next_quake.next_start_timestamp;
seis->start_timestamp = next_quake.start_timestamp;
Expand Down
12 changes: 8 additions & 4 deletions world/zoneserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void ZoneServer::LSSleepUpdate(uint32 zoneid){
}
}

extern void TriggerManualQuake();
extern void TriggerManualQuake(QuakeType in_quake_type);

bool ZoneServer::Process() {
if (!tcpc->Connected())
Expand Down Expand Up @@ -918,7 +918,7 @@ bool ZoneServer::Process() {
/* Boot the Zone*/
else {
int server_id;
if (!RuleB(World, DontBootDynamics))
if (!RuleB(World, DontBootDynamics) || ztz->requested_zone_guild_id != 0xFFFFFFFF)
{
if ((server_id = zoneserver_list.TriggerBootup(ztz->requested_zone_id, ztz->requested_zone_guild_id))) {
Log(Logs::Detail, Logs::WorldServer, "Successfully booted a zone for %s", ztz->name);
Expand Down Expand Up @@ -1418,8 +1418,12 @@ bool ZoneServer::Process() {

case ServerOP_QuakeRequest:
{

TriggerManualQuake();
if (pack->size != sizeof(ServerEarthquakeRequest_Struct))
{
break;
}
ServerEarthquakeRequest_Struct* s = (ServerEarthquakeRequest_Struct*)pack->pBuffer;
TriggerManualQuake(s->type);
break;
}

Expand Down
6 changes: 3 additions & 3 deletions zone/aggro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,8 @@ bool Mob::IsAttackAllowed(Mob *target, bool isSpellAttack, int16 spellid)

if // if both are pvp they can fight
(
c1->GetPVP() &&
c2->GetPVP()
(bool)c1->GetPVP() &&
(bool)c2->GetPVP()
)
return true;
else if // if they're dueling they can go at it
Expand Down Expand Up @@ -1075,7 +1075,7 @@ bool Mob::IsBeneficialAllowed(Mob *target)
return false;
}

if (c1->GetPVP() == c2->GetPVP())
if ((bool)c1->GetPVP() == (bool)c2->GetPVP())
return true;

}
Expand Down
6 changes: 3 additions & 3 deletions zone/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2296,15 +2296,15 @@ uint16 Client::GetSkill(EQ::skills::SkillType skill_id) const
return tmp_skill;
}

void Client::SetPVP(bool toggle) {
m_pp.pvp = toggle ? 1 : 0;
void Client::SetPVP(uint8 toggle) {
m_pp.pvp = toggle;

if(GetPVP())
this->Message_StringID(CC_Red,PVP_ON);
else
Message(CC_Red, "You no longer follow the ways of discord.");

SendAppearancePacket(AT_PVP, GetPVP());
SendAppearancePacket(AT_PVP, (bool)GetPVP());
Save();
}

Expand Down
4 changes: 2 additions & 2 deletions zone/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ class Client : public Mob
virtual void SetMaxHP();
static int32 LevelRegen(int level, bool is_sitting, bool is_resting, bool is_feigned, bool is_famished, bool has_racial_regen_bonus);
void SetGM(bool toggle);
void SetPVP(bool toggle);
void SetPVP(uint8 toggle);
void SetAnon(bool toogle);

inline bool GetPVP() const { return m_pp.pvp != 0; }
inline uint8 GetPVP() const { return m_pp.pvp; }
inline bool GetGM() const { return m_pp.gm != 0; }

inline void SetBaseClass(uint32 i) { m_pp.class_=i; }
Expand Down
18 changes: 16 additions & 2 deletions zone/client_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,12 @@ void Client::CompleteConnect()
ClearPlayerInfoAndGrantStartingItems();
ForceGoToDeath();
}

// Evac player to zonein during PVP quakes if they log in on first login in this zone.
//if (firstlogon && zone && zone->GetGuildID() == GUILD_NONE && zone->last_quake_struct.quake_type != QuakeType::QuakeDisabled && zone->last_quake_struct.start_timestamp > 0 && prev_last_login_time > 0 && prev_last_login_time < zone->last_quake_struct.start_timestamp)
//{
// MovePCGuildID(zone->GetZoneID(), GUILD_NONE, 0, 0, 0, 0, 0, EvacToSafeCoords);
//}
}


Expand Down Expand Up @@ -893,8 +899,16 @@ void Client::Handle_Connect_OP_SendExpZonein(const EQApplicationPacket *app)
safe_delete_array(out_app.pBuffer);

SetSpawned();

if (GetPVP() == 2 && zone && zone->last_quake_struct.quake_type != QuakeType::QuakePVP)
SetPVP(0);

if (GetPVP() == 0 && zone && zone->last_quake_struct.quake_type == QuakeType::QuakePVP)
SetPVP(2);

if (GetPVP()) //force a PVP update until we fix the spawn struct
SendAppearancePacket(AT_PVP, GetPVP(), true, false);
SendAppearancePacket(AT_PVP, (bool)GetPVP(), true, false);


//Send AA Exp packet:
if (GetLevel() >= 51)
Expand Down Expand Up @@ -3382,7 +3396,7 @@ void Client::Handle_OP_Consider(const EQApplicationPacket *app)
con->level = GetLevelCon(tmob->GetLevel());
if (zone->IsPVPZone()) {
if (!tmob->IsNPC())
con->pvpcon = tmob->CastToClient()->GetPVP();
con->pvpcon = (bool)tmob->CastToClient()->GetPVP();
}

// If we're feigned show NPC as indifferent
Expand Down
19 changes: 16 additions & 3 deletions zone/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ int command_init(void)

command_add("qglobal", "[on/off/view] - Toggles qglobal functionality on an NPC.", AccountStatus::GMImpossible, command_qglobal) ||
command_add("qtest", "- QueryServ testing command.", AccountStatus::GMTester, command_qtest) ||
command_add("quaketrigger", "- Triggers an earthquake manually", AccountStatus::GMImpossible, command_quaketrigger) ||
command_add("quaketrigger", "- [type_num (1 = Normal, 2 = PVP)] Triggers an earthquake manually", AccountStatus::GMImpossible, command_quaketrigger) ||
command_add("questerrors", "Shows quest errors.",AccountStatus::Player, command_questerrors) ||

command_add("race", "[racenum] - Change your or your target's race. Use racenum 0 to return to normal.", AccountStatus::QuestMaster, command_race) ||
Expand Down Expand Up @@ -11330,8 +11330,21 @@ void command_viewzoneloot(Client* c, const Seperator* sep)

void command_quaketrigger(Client* c, const Seperator* sep)
{
ServerPacket pack(ServerOP_QuakeRequest, 0);
worldserver.SendPacket(&pack);
//Arguments?
if (sep->IsNumber(1))
{
uint8_t quaketype = atoi(sep->arg[1]);
auto pack = new ServerPacket(ServerOP_QuakeRequest, sizeof(ServerEarthquakeRequest_Struct));
ServerEarthquakeRequest_Struct* sqr = (ServerEarthquakeRequest_Struct*)pack->pBuffer;
sqr->type = (QuakeType)quaketype;
worldserver.SendPacket(pack);
safe_delete(pack);
c->Message(15, "Triggered an earthquake!");
}
else
{
c->Message(15, "Invalid parameters. Usage: #quaketrigger [type_num]");
}
}

void command_betabuff(Client* c, const Seperator* sep)
Expand Down
37 changes: 34 additions & 3 deletions zone/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5210,10 +5210,7 @@ bool EntityList::HasCharmedNPC()

void EntityList::EvacAllPlayers()
{

// update distances to us for clients.
auto it = client_list.begin();
// go through the list and update distances
while (it != client_list.end()) {
if (it->second && it->second->GetID() > 0) {

Expand All @@ -5223,6 +5220,40 @@ void EntityList::EvacAllPlayers()
}
}

void EntityList::TogglePVPForQuake()
{
if (!zone)
return;

if (zone && zone->last_quake_struct.quake_type == QuakeType::QuakePVP)
{
// update distances to us for clients.
auto it = client_list.begin();
// go through the list and update distances
while (it != client_list.end()) {
if (it->second && it->second->GetPVP() == 0) {

it->second->SetPVP(2);
}
++it;
}
return;
}
else if (zone)
{
// update distances to us for clients.
auto it = client_list.begin();
// go through the list and update distances
while (it != client_list.end()) {
if (it->second && it->second->GetPVP() == 2) {

it->second->SetPVP(0);
}
++it;
}
}
}

void EntityList::ReportUnderworldNPCs(Client* sendto, float min_z)
{
float underworld_z = zone->newzone_data.underworld;
Expand Down
3 changes: 2 additions & 1 deletion zone/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ class EntityList
void AreaCastSpell(float minx, float miny, float maxx,float maxy, uint16 spellid, uint16 regeant_itemid = 0);
void RepopNPCsByNPCID(uint32 npcid);
bool HasCharmedNPC();
void EvacAllPlayers();
void EvacAllPlayers();
void TogglePVPForQuake();
void ReportUnderworldNPCs(Client* sendto, float min_z);

protected:
Expand Down
25 changes: 24 additions & 1 deletion zone/spawn2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ void Spawn2::DeathReset(bool realdeath)
//set our timer to our reset local
timer.Start(cur);

//zero out our NPC since he is now gone
npcthis = nullptr;

if(realdeath) { killcount++; }
Expand All @@ -496,6 +495,30 @@ void Spawn2::DeathReset(bool realdeath)
}
}


//resets our spawn as if we just died
void Spawn2::QuakeReset()
{
//get our reset based on variance etc and store it locally
uint32 cur = resetTimer();
//set our timer to our reset local
timer.Start(cur);

if (npcthis)
{
npcthis->Depop();
}
npcthis = nullptr;
//if we have a valid spawn id
if (spawn2_id)
{
database.UpdateRespawnTime(spawn2_id, (cur / 1000), zone ? zone->GetGuildID() : GUILD_NONE);
Log(Logs::General, Logs::Spawns, "Spawn2 %d: Spawn reset by death, repop in %d ms", spawn2_id, timer.GetRemainingTime());
//store it to database too
}
}


bool ZoneDatabase::PopulateZoneSpawnListClose(uint32 zoneid, LinkedList<Spawn2*> &spawn2_list, const glm::vec4& client_position, uint32 repop_distance, uint32 guildid)
{
std::unordered_map<uint32, uint32> spawn_times;
Expand Down
Loading

0 comments on commit 338a824

Please sign in to comment.