Skip to content

Commit

Permalink
Refactored a bit of the instance modes
Browse files Browse the repository at this point in the history
* Follow up to c97be60.
* Added some safety measures when sending the instance name to the client.
* Adjusted the stored maps of instances to dynamic arrays to conserve memory.
- Max amount of possible maps increased to 255.
* Removed Map1 from the instance_db as the EnterMap is always the same value.
* Instances will now be destroyed even if the owner cannot be found.
* Corrected the return value when entering an instance when a character, party, or guild does not have an instance.
* Corrected a few script commands to properly stop the script engine on failures for instance script commands.
* Removed the instance name lookup for when entering an instance as instance_id is now passed.
- Adjusted script command instance_enter to no longer require the instance name.
* Adjusted script command instance_create to keep backwards compatibility.
* Cleaned up script command instance_warpall.
* Updated script documentation to reflect changes.
* Updated instance_db to reflect changes.
  • Loading branch information
aleos89 committed May 23, 2016
1 parent 9c89b0e commit 2cfb844
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 217 deletions.
5 changes: 3 additions & 2 deletions db/import-tmpl/instance_db.txt
@@ -1,5 +1,6 @@
// Instance Database
//
// Structure of Database:
// ID,Name,LimitTime,IdleTimeout,EnterMap,EnterX,EnterY,Map1,Map2,Map3,Map4,Map5,Map6,Map7,Map8

// ID,Name,LimitTime,IdleTimeOut,EnterMap,EnterX,EnterY,Map2,Map3,Map4,Map5,Map6,Map7,Map8,Map9,Map10
//
// EnterMap is considered as Map1
12 changes: 7 additions & 5 deletions db/pre-re/instance_db.txt
@@ -1,9 +1,11 @@
// Instance Database
//
// Structure of Database:
// ID,Name,LimitTime,IdleTimeout,EnterMap,EnterX,EnterY,Map1,Map2,Map3,Map4,Map5,Map6,Map7,Map8
// ID,Name,LimitTime,IdleTimeOut,EnterMap,EnterX,EnterY,Map2,Map3,Map4,Map5,Map6,Map7,Map8,Map9,Map10
//
// EnterMap is considered as Map1

1,Endless Tower,14400,300,1@tower,50,355,1@tower,2@tower,3@tower,4@tower,5@tower,6@tower
2,Sealed Catacomb,7200,300,1@cata,100,224,1@cata,2@cata
3,Orc's Memory,3600,300,1@orcs,179,15,1@orcs,2@orcs
4,Nidhoggur's Nest,14400,300,1@nyd,32,36,1@nyd,2@nyd
1,Endless Tower,14400,300,1@tower,50,355,2@tower,3@tower,4@tower,5@tower,6@tower
2,Sealed Catacomb,7200,300,1@cata,100,224,2@cata
3,Orc's Memory,3600,300,1@orcs,179,15,2@orcs
4,Nidhoggur's Nest,14400,300,1@nyd,32,36,2@nyd
30 changes: 16 additions & 14 deletions db/re/instance_db.txt
@@ -1,18 +1,20 @@
// Instance Database
//
// Structure of Database:
// ID,Name,LimitTime,IdleTime,EnterMap,EnterX,EnterY,Map1,Map2,Map3,Map4,Map5,Map6,Map7,Map8
// ID,Name,LimitTime,IdleTimeOut,EnterMap,EnterX,EnterY,Map2,Map3,Map4,Map5,Map6,Map7,Map8,Map9,Map10
//
// EnterMap is considered as Map1

1,Endless Tower,14400,300,1@tower,50,355,1@tower,2@tower,3@tower,4@tower,5@tower,6@tower
2,Sealed Catacomb,7200,300,1@cata,100,224,1@cata,2@cata
3,Orc's Memory,3600,300,1@orcs,179,15,1@orcs,2@orcs
4,Nidhoggur's Nest,14400,300,1@nyd,32,36,1@nyd,2@nyd
5,Mistwood Maze,7200,300,1@mist,89,29,1@mist
6,Culvert,3600,300,1@pump,63,98,1@pump,2@pump
7,Octopus Cave,3600,300,1@cash,199,99,1@cash
8,Bangungot Hospital 2F,3600,300,1@ma_h,40,157,1@ma_h
9,Buwaya Cave,3600,300,1@ma_c,35,57,1@ma_c
10,Bakonawa Lake,7200,300,1@ma_b,64,51,1@ma_b
11,Wolfchev's Laboratory,14400,300,1@lhz,45,148,1@lhz
12,Old Glast Heim,3600,300,1@gl_k,150,20,1@gl_k,2@gl_k
13,Eclage Interior,1200,300,1@ecl,60,50,1@ecl
1,Endless Tower,14400,300,1@tower,50,355,2@tower,3@tower,4@tower,5@tower,6@tower
2,Sealed Catacomb,7200,300,1@cata,100,224,2@cata
3,Orc's Memory,3600,300,1@orcs,179,15,2@orcs
4,Nidhoggur's Nest,14400,300,1@nyd,32,36,2@nyd
5,Mistwood Maze,7200,300,1@mist,89,29
6,Culvert,3600,300,1@pump,63,98,2@pump
7,Octopus Cave,3600,300,1@cash,199,99
8,Bangungot Hospital 2F,3600,300,1@ma_h,40,157
9,Buwaya Cave,3600,300,1@ma_c,35,57
10,Bakonawa Lake,7200,300,1@ma_b,64,51
11,Wolfchev's Laboratory,14400,300,1@lhz,45,148
12,Old Glast Heim,3600,300,1@gl_k,150,20,2@gl_k
13,Eclage Interior,1200,300,1@ecl,60,50
34 changes: 17 additions & 17 deletions doc/script_commands.txt
Expand Up @@ -3,7 +3,7 @@
//===== By: ==================================================
//= rAthena Dev Team
//===== Last Updated: ========================================
//= 20150610
//= 20160523
//===== Description: =========================================
//= A reference manual for the rAthena scripting language.
//= Commands are sorted depending on their functionality.
Expand Down Expand Up @@ -8113,9 +8113,9 @@ This command will open a book item at the specified page.
========================
---------------------------------------

*instance_create("<instance name>",<owner_id>{,<mode>});
*instance_create("<instance name>"{,<instance mode>{,<owner id>}});

Creates an instance for the <owner_id> of <mode>. The instance name, along with
Creates an instance for the <owner id> of <mode>. The instance name, along with
all other instance data, is read from 'db/(pre-)re/instance_db.txt'. Upon success,
the command generates a unique instance ID, duplicates all listed maps and NPCs,
sets the alive time, and triggers the "OnInstanceInit" label in all NPCs inside
Expand All @@ -8129,7 +8129,7 @@ Instance Mode options:

The command returns the instance ID upon success, and these values upon failure:
-1: Invalid type.
-2: Party not found.
-2: Character/Party/Guild not found.
-3: Instance already exists.
-4: No free instances (MAX_INSTANCE exceeded).

Expand All @@ -8139,13 +8139,13 @@ The command returns the instance ID upon success, and these values upon failure:

Destroys instance with the ID <instance id>. If no ID is specified, the instance
the script is attached to is used. If the script is not attached to an instance,
the instance of the currently attached player is used (if it is a party or guild
mode). If it is not owned by anyone, no player needs to be attached. If that
fails, the script will come to a halt.
the instance of the currently attached player is used (if it is a character, party,
or guild mode). If it is not owned by anyone, no player needs to be attached. If
that fails, the script will come to a halt.

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

*instance_enter("<instance name>"{,<x>,<y>,<char_id>});
*instance_enter({<x>,<y>,<char_id>});

Warps player to the specified instance after the script terminates. The map and
coordinates are located in 'db/(pre-)re/instance_db.txt'.
Expand All @@ -8163,8 +8163,8 @@ Put -1 for x and y if want to warp player with default entrance coordinates.

Returns the unique name of the instanced script. If no ID is specified,
the instance the script is attached to is used. If the script is not attached to
an instance, the instance of the currently attached player's party is used. If
that fails, the script will come to a halt.
an instance, the instance of the currently attached NPC, player, party, or guild
is used. If that fails, the script will come to a halt.

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

Expand All @@ -8173,16 +8173,16 @@ that fails, the script will come to a halt.
Returns the unique name of the instanced map. If no instance ID is specified,
the instance the script is attached to is used. If the script is not attached to
an instance, the instance of the currently attached player is used (if it is a
party or guild mode). If it is not owned by anyone, no player needs to be
attached. If that fails, the command returns an empty string instead.
character, party, or guild mode). If it is not owned by anyone, no player needs
to be attached. If that fails, the command returns an empty string instead.

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

*instance_id()

Returns the unique instance id of the attached script. If the script is not
attached to an instance, the instance of the currently attached player is
used (if it is a party or guild mode). If it is not owned by anyone, no
used (if it is a character, party, or guild mode). If it is not owned by anyone, no
player needs to be attached. If that fails, the function will return 0.

---------------------------------------
Expand All @@ -8192,8 +8192,8 @@ player needs to be attached. If that fails, the function will return 0.
Warps all players in the instance <instance id> to <map name> at given
coordinates. If no ID is specified, the instance the script is attached to
is used. If the script is not attached to an instance, the instance of the
currently attached player is used (if it is a party or guild mode). If it
is not owned by anyone, no player needs to be attached. If that
currently attached player is used (if it is a character, party, or guild
mode). If it is not owned by anyone, no player needs to be attached. If that
fails, the script will come to a halt.

---------------------------------------
Expand All @@ -8203,8 +8203,8 @@ fails, the script will come to a halt.
Broadcasts a message to all players in the instance <instance id> currently
residing on an instance map. If -1 is specified for <instance id>, the instance
the script is attached to is used. If the script is not attached to an instance,
the instance of the currently attached player is used (if it is a party or guild
mode). If it is not owned by anyone, no player needs to be attached.
the instance of the currently attached player is used (if it is a character,
party, or guild mode). If it is not owned by anyone, no player needs to be attached.

For details on the other parameters, see 'announce'.

Expand Down
8 changes: 6 additions & 2 deletions src/map/clif.c
Expand Up @@ -16578,6 +16578,7 @@ void clif_font(struct map_session_data *sd)
void clif_instance_create(unsigned short instance_id, int num)
{
#if PACKETVER >= 20071128
struct instance_db *db = NULL;
struct map_session_data *sd = NULL;
enum send_target target = PARTY;
unsigned char buf[65];
Expand All @@ -16587,8 +16588,9 @@ void clif_instance_create(unsigned short instance_id, int num)
if (!sd)
return;

db = instance_searchtype_db(instance_data[instance_id].type);
WBUFW(buf,0) = 0x2cb;
memcpy(WBUFP(buf,2), instance_data[instance_id].name, 62);
safestrncpy(WBUFP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
WBUFW(buf,63) = num;
clif_send(buf,packet_len(0x2cb),&sd->bl,target);
#endif
Expand Down Expand Up @@ -16623,6 +16625,7 @@ void clif_instance_changewait(unsigned short instance_id, int num)
void clif_instance_status(unsigned short instance_id, unsigned int limit1, unsigned int limit2)
{
#if PACKETVER >= 20071128
struct instance_db *db = NULL;
struct map_session_data *sd = NULL;
enum send_target target = PARTY;
unsigned char buf[71];
Expand All @@ -16632,8 +16635,9 @@ void clif_instance_status(unsigned short instance_id, unsigned int limit1, unsig
if (!sd)
return;

db = instance_searchtype_db(instance_data[instance_id].type);
WBUFW(buf,0) = 0x2cd;
memcpy(WBUFP(buf,2), instance_data[instance_id].name, 62);
safestrncpy(WBUFP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
WBUFL(buf,63) = limit1;
WBUFL(buf,67) = limit2;
clif_send(buf,packet_len(0x2cd),&sd->bl,target);
Expand Down

0 comments on commit 2cfb844

Please sign in to comment.