Skip to content

Commit

Permalink
Merge pull request #3224 from MishimaHaruna/localtime
Browse files Browse the repository at this point in the history
Localtime/daylight savings enhancements and fixes
  • Loading branch information
MishimaHaruna authored Aug 12, 2023
2 parents 82265ef + 87be781 commit 3faa147
Show file tree
Hide file tree
Showing 34 changed files with 335 additions and 246 deletions.
10 changes: 0 additions & 10 deletions db/constants.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3877,16 +3877,6 @@ constants_db: {
MOUNT_DRAGON_BLUE: 7
MOUNT_DRAGON_RED: 8

comment__: "Gettime Types"
GETTIME_SECOND: 1
GETTIME_MINUTE: 2
GETTIME_HOUR: 3
GETTIME_WEEKDAY: 4
GETTIME_DAYOFMONTH: 5
GETTIME_MONTH: 6
GETTIME_YEAR: 7
GETTIME_DAYOFYEAR: 8

comment__: "gettimer"
TIMER_COUNT: 0
TIMER_TICK_NEXT: 1
Expand Down
28 changes: 17 additions & 11 deletions doc/constants_pre-re.md
Original file line number Diff line number Diff line change
Expand Up @@ -3816,17 +3816,6 @@
- `MOUNT_DRAGON_BLUE`: 7
- `MOUNT_DRAGON_RED`: 8

### Gettime Types

- `GETTIME_SECOND`: 1
- `GETTIME_MINUTE`: 2
- `GETTIME_HOUR`: 3
- `GETTIME_WEEKDAY`: 4
- `GETTIME_DAYOFMONTH`: 5
- `GETTIME_MONTH`: 6
- `GETTIME_YEAR`: 7
- `GETTIME_DAYOFYEAR`: 8

### gettimer

- `TIMER_COUNT`: 0
Expand Down Expand Up @@ -5358,6 +5347,23 @@
- `QINFO_QUEST`: 7
- `QINFO_MERCENARY_CLASS`: 8

### Gettime Types

- `GETTIME_SECOND`: 1
- `GETTIME_MINUTE`: 2
- `GETTIME_HOUR`: 3
- `GETTIME_WEEKDAY`: 4
- `GETTIME_DAYOFMONTH`: 5
- `GETTIME_MONTH`: 6
- `GETTIME_YEAR`: 7
- `GETTIME_DAYOFYEAR`: 8

### Gettimetick Types

- `GETTIMETICK_SYSTEM_MS`: 0
- `GETTIMETICK_HOUROFDAY_S`: 1
- `GETTIMETICK_UNIXTIME`: 2

### function types

- `FUNCTION_IS_COMMAND`: 1
Expand Down
28 changes: 17 additions & 11 deletions doc/constants_re.md
Original file line number Diff line number Diff line change
Expand Up @@ -3816,17 +3816,6 @@
- `MOUNT_DRAGON_BLUE`: 7
- `MOUNT_DRAGON_RED`: 8

### Gettime Types

- `GETTIME_SECOND`: 1
- `GETTIME_MINUTE`: 2
- `GETTIME_HOUR`: 3
- `GETTIME_WEEKDAY`: 4
- `GETTIME_DAYOFMONTH`: 5
- `GETTIME_MONTH`: 6
- `GETTIME_YEAR`: 7
- `GETTIME_DAYOFYEAR`: 8

### gettimer

- `TIMER_COUNT`: 0
Expand Down Expand Up @@ -5358,6 +5347,23 @@
- `QINFO_QUEST`: 7
- `QINFO_MERCENARY_CLASS`: 8

### Gettime Types

- `GETTIME_SECOND`: 1
- `GETTIME_MINUTE`: 2
- `GETTIME_HOUR`: 3
- `GETTIME_WEEKDAY`: 4
- `GETTIME_DAYOFMONTH`: 5
- `GETTIME_MONTH`: 6
- `GETTIME_YEAR`: 7
- `GETTIME_DAYOFYEAR`: 8

### Gettimetick Types

- `GETTIMETICK_SYSTEM_MS`: 0
- `GETTIMETICK_HOUROFDAY_S`: 1
- `GETTIMETICK_UNIXTIME`: 2

### function types

- `FUNCTION_IS_COMMAND`: 1
Expand Down
26 changes: 13 additions & 13 deletions doc/sample/npc_test_time.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
//============================================================

prontera,157,181,6 script Time Sample 8W_SOLDIER,{
mes "[Time Sample]";
mes " System Tick : " + gettimetick(0);
mes " Time Tick : " + gettimetick(1);
mes " GETTIME_SECOND : " + gettime(GETTIME_SECOND) + " (Sec)";
mes " GETTIME_MINUTE : " + gettime(GETTIME_MINUTE) + " (Min)";
mes " GETTIME_HOUR : " + gettime(GETTIME_HOUR) + " (Hour)";
mes " GETTIME_WEEKDAY : " + gettime(GETTIME_WEEKDAY) + " (WeekDay)";
mes "GETTIME_DAYOFMONTH : " + gettime(GETTIME_DAYOFMONTH) + " (MonthDay)";
mes " GETTIME_MONTH : " + gettime(GETTIME_MONTH) + " (Month)";
mes " GETTIME_YEAR : " + gettime(GETTIME_YEAR) + " (Year)";
mes " GETTIME_DAYOFYEAR : " + gettime(GETTIME_DAYOFYEAR) + " (Day of Year)";
mes " gettimestr : " + gettimestr("%Y-%m/%d %H:%M:%S",19);
close;
mes("[Time Sample]");
mesf(" System Tick : %d", gettimetick(GETTIMETICK_SYSTEM_MS));
mesf(" Time Tick : %d", gettimetick(GETTIMETICK_HOUROFDAY_S));
mesf(" GETTIME_SECOND : %d (Sec)", gettime(GETTIME_SECOND));
mesf(" GETTIME_MINUTE : %d (Min)", gettime(GETTIME_MINUTE));
mesf(" GETTIME_HOUR : %d (Hour)", gettime(GETTIME_HOUR));
mesf(" GETTIME_WEEKDAY : %d (WeekDay)", gettime(GETTIME_WEEKDAY));
mesf("GETTIME_DAYOFMONTH : %d (MonthDay)", gettime(GETTIME_DAYOFMONTH));
mesf(" GETTIME_MONTH : %d (Month)", gettime(GETTIME_MONTH));
mesf(" GETTIME_YEAR : %d (Year)", gettime(GETTIME_YEAR));
mesf(" GETTIME_DAYOFYEAR : %d (Day of Year)", gettime(GETTIME_DAYOFYEAR));
mesf(" gettimestr : %s", gettimestr("%Y-%m/%d %H:%M:%S",19));
close();
}
19 changes: 14 additions & 5 deletions doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3781,13 +3781,15 @@ If the player is not found, returns -1.
*gettimetick(<type>)

Valid types are :
0 - server's tick (milliseconds), unsigned int, loops every ~25 days
1 - time since the start of the current day in seconds
2 - UNIX epoch time (number of seconds elapsed since 1st of January 1970)
0 - GETTIMETICK_SYSTEM_MS - server's tick (milliseconds), unsigned int, loops every ~25 days
1 - GETTIMETICK_HOUROFDAY_S - time since the start of the current day in seconds
- Note: this only considers the value of the current hour and disregards daylight savings.
- On the day DST starts and ends, this value will have discontinuties.
2 - GETTIMETICK_UNIXTIME - UNIX epoch time (number of seconds elapsed since 1st of January 1970)

---------------------------------------

*gettime(<type>)
*gettime(<type>{, <is_localtime>})

This function returns specified information about the current system time.

Expand All @@ -3803,6 +3805,9 @@ Valid types:
7 - GETTIME_YEAR - Year
8 - GETTIME_DAYOFYEAR - Day of the year.

If <is_localtime> is true (or omitted), the output refers to the current timezone and daylight savings.
Otherwise it is in UTC.

It will only return numbers based on types.
Example :
if (gettime(GETTIME_WEEKDAY) == SATURDAY) {
Expand All @@ -3815,7 +3820,7 @@ Example :

---------------------------------------

*getcalendartime(<hour>, <minute>{, <day of month>{, <day of week>}})
*getcalendartime(<hour>, <minute>{, <day of month>{, <day of week>{, <input_is_localtime>}}})

This function returns the timestamp of the next occurrence of a given time.
If this time is later today, it will stay in the same day, otherwise, it will adjust to a future
Expand All @@ -3834,10 +3839,14 @@ Day of Week specifies a day in the week and its valid values are:
In order to use Day of Week, you must use Day of Month as -1.
If for some reason the command fails, it'll return -1.

If <input_is_localtime> is true (or omitted), then the hour and minute are interpreted according to the current timezone
and daylight savings. Otherwise they're treated as UTC.

Examples :
getcalendartime(19, 00); // Next 7 pm
getcalendartime(19, 00, 6); // Next day 6 of the month, at 7pm
getcalendartime(19, 10, -1, 1); // Next Monday, at 7:10pm
getcalendartime(19, 00, -1, -1, false); // Next 7 pm UTC

Note: If supplied with the current hour and minute, you will get the timestamp for the same
hour and minute in the next day. For example, if is now August 1st 7:00pm and you use:
Expand Down
4 changes: 2 additions & 2 deletions npc/battleground/kvm/kvm01.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ OnCroixJoin:
end;

OnGuillaumeQuit:
//BG_Delay_Tick = gettimetick(2) + 1200;
//BG_Delay_Tick = gettimetick(GETTIMETICK_UNIXTIME) + 1200;
OnGuillaumeDie:
if ($@KvM01BG == 2) {
--.Guillaume_Count;
Expand All @@ -167,7 +167,7 @@ OnGuillaumeDie:
end;

OnCroixQuit:
//BG_Delay_Tick = gettimetick(2) + 1200;
//BG_Delay_Tick = gettimetick(GETTIMETICK_UNIXTIME) + 1200;
OnCroixDie:
if ($@KvM01BG == 2) {
--.Croix_Count;
Expand Down
4 changes: 2 additions & 2 deletions npc/battleground/kvm/kvm02.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ OnCroixJoin:
end;

OnGuillaumeQuit:
//BG_Delay_Tick = gettimetick(2) + 1200;
//BG_Delay_Tick = gettimetick(GETTIMETICK_UNIXTIME) + 1200;
OnGuillaumeDie:
if ($@KvM02BG == 2) {
--.Guillaume_Count;
Expand All @@ -168,7 +168,7 @@ OnGuillaumeDie:
end;

OnCroixQuit:
//BG_Delay_Tick = gettimetick(2) + 1200;
//BG_Delay_Tick = gettimetick(GETTIMETICK_UNIXTIME) + 1200;
OnCroixDie:
if ($@KvM02BG == 2) {
--.Croix_Count;
Expand Down
4 changes: 2 additions & 2 deletions npc/battleground/kvm/kvm03.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ OnCroixJoin:
end;

OnGuillaumeQuit:
//BG_Delay_Tick = gettimetick(2) + 1200;
//BG_Delay_Tick = gettimetick(GETTIMETICK_UNIXTIME) + 1200;
OnGuillaumeDie:
if ($@KvM03BG == 2) {
--.Guillaume_Count;
Expand All @@ -168,7 +168,7 @@ OnGuillaumeDie:
end;

OnCroixQuit:
//BG_Delay_Tick = gettimetick(2) + 1200;
//BG_Delay_Tick = gettimetick(GETTIMETICK_UNIXTIME) + 1200;
OnCroixDie:
if ($@KvM03BG == 2) {
--.Croix_Count;
Expand Down
8 changes: 4 additions & 4 deletions npc/cities/niflheim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ niflheim,350,258,1 script Cursed Spirit#nif 4_NFWISP,{
next;
switch(select("Touch the first book.", "Touch the second book.", "Touch the third book.", "Okay, I am leaving.")) {
case 1:
if (.last_mob_summon + 60 < gettimetick(2)) { // only spawn every 60 seconds, to prevent farming exploits
if (.last_mob_summon + 60 < gettimetick(GETTIMETICK_UNIXTIME)) { // only spawn every 60 seconds, to prevent farming exploits
.@label$ = sprintf("%s::OnMyMobDead", strnpcinfo(NPC_NAME_UNIQUE));
killmonster("niflheim", .@label$);
.last_mob_summon = gettimetick(2);
.last_mob_summon = gettimetick(GETTIMETICK_UNIXTIME);
monster("niflheim", 349, 259, "--ja--", G_RIDEWORD, 1, .@label$);
}
mes "[Ashe Bruce]";
Expand Down Expand Up @@ -343,10 +343,10 @@ niflheim,350,258,1 script Cursed Spirit#nif 4_NFWISP,{
close;
}
}
if (.last_mob_summon + 60 < gettimetick(2)) { // only spawn every 60 seconds, to prevent farming exploits
if (.last_mob_summon + 60 < gettimetick(GETTIMETICK_UNIXTIME)) { // only spawn every 60 seconds, to prevent farming exploits
.@label$ = sprintf("%s::OnMyMobDead", strnpcinfo(NPC_NAME_UNIQUE));
killmonster("niflheim", .@label$);
.last_mob_summon = gettimetick(2);
.last_mob_summon = gettimetick(GETTIMETICK_UNIXTIME);
monster("niflheim", 345, 259, "--ja--", G_ORC_SKELETON, 1, .@label$);
monster("niflheim", 347, 261, "--ja--", G_ORC_SKELETON, 1, .@label$);
monster("niflheim", 344, 253, "--ja--", G_ORC_SKELETON, 1, .@label$);
Expand Down
Loading

0 comments on commit 3faa147

Please sign in to comment.