diff --git a/common/eq_constants.h b/common/eq_constants.h index b266b3905..2b71d9093 100644 --- a/common/eq_constants.h +++ b/common/eq_constants.h @@ -1052,4 +1052,11 @@ enum ScribeSpellActions Unmemorize }; +enum SpellTimeRestrictions +{ + NoRestriction, + Day, + Night +}; + #endif /*COMMON_EQ_CONSTANTS_H*/ diff --git a/common/eqtime.cpp b/common/eqtime.cpp index eb11d89d8..49d5f32c3 100644 --- a/common/eqtime.cpp +++ b/common/eqtime.cpp @@ -200,3 +200,25 @@ void EQTime::ToString(TimeOfDay_Struct *t, std::string &str) { buf[127] = '\0'; str = buf; } + +bool EQTime::IsDayTime() { + TimeOfDay_Struct tod; //Day time is 5am to 6:59pm (14 hours in-game) + GetCurrentEQTimeOfDay(&tod); //TODO: what if it fails and returns zero? + + if (tod.hour >= 5 || tod.hour < 19) { + return true; + } + + return false; +} + +bool EQTime::IsNightTime() { + TimeOfDay_Struct tod; //Night time is 7pm to 4:59am (10 hours in-game) + GetCurrentEQTimeOfDay(&tod); //TODO: what if it fails and returns zero? + + if (tod.hour >= 19 || tod.hour < 5) { + return true; + } + + return false; +} diff --git a/common/eqtime.h b/common/eqtime.h index 4f3a95fdd..c55689a0f 100644 --- a/common/eqtime.h +++ b/common/eqtime.h @@ -28,6 +28,8 @@ public: uint32 getEQTimeZone() { return timezone; } uint32 getEQTimeZoneHr() { return timezone/60; } uint32 getEQTimeZoneMin() { return timezone%60; } + bool IsDayTime(); + bool IsNightTime(); //Set functions int SetCurrentEQTimeOfDay(TimeOfDay_Struct start_eq, time_t start_real); diff --git a/zone/spells.cpp b/zone/spells.cpp index 3951a352d..115e843b5 100644 --- a/zone/spells.cpp +++ b/zone/spells.cpp @@ -711,6 +711,18 @@ bool Mob::DoCastingChecksZoneRestrictions(bool check_on_casting, int32 spell_id) Message(Chat::Red, "You cannot cast detrimental spells here."); return false; } + /* + Zones where you can not cast a spell that is for daytime or nighttime only + */ + if (spells[spell_id].time_of_day == SpellTimeRestrictions::Day && !zone->zone_time.IsDayTime()) { + MessageString(Chat::Red, CAST_DAYTIME); + return false; + } + + if (spells[spell_id].time_of_day == SpellTimeRestrictions::Night && !zone->zone_time.IsNightTime()) { + MessageString(Chat::Red, CAST_NIGHTTIME); + return false; + } if (check_on_casting) { /* diff --git a/zone/string_ids.h b/zone/string_ids.h index 1ab51ab40..cc09122d8 100644 --- a/zone/string_ids.h +++ b/zone/string_ids.h @@ -63,6 +63,8 @@ #define SAC_TOO_HIGH 204 //This being is too powerful to be a sacrifice. #define CANNOT_SAC_SELF 205 //You cannot sacrifice yourself. #define SILENCED_STRING 207 //You *CANNOT* cast spells, you have been silenced! +#define CAST_DAYTIME 208 //Spell can only be cast during the day. +#define CAST_NIGHTTIME 209 //Spell can only be cast during the night. #define CANNOT_AFFECT_PC 210 //That spell can not affect this target PC. #define SPELL_NEED_TAR 214 //You must first select a target for this spell! #define SUMMON_ONLY_GROUP_CORPSE 215 //You must first target a living group member whose corpse you wish to summon.