Przeglądaj źródła

Follow ups & fix
* Follow up df2f850c, correcting `class_idx` usage that should be compared with `enum e_job` in `pc_calc_basesp` and also in `pc_calc_basehp`
* Follow up 308c4779, fixed typo fix
* Makes `instance_id()` doesn't show debug message when it return 0 for instance id

Signed-off-by: Cydh Ramdh <cydh@pservero.com>

Cydh Ramdh 10 lat temu
rodzic
commit
177ea6c779
3 zmienionych plików z 27 dodań i 17 usunięć
  1. 1 1
      doc/script_commands.txt
  2. 25 15
      src/map/pc.c
  3. 1 1
      src/map/script.c

+ 1 - 1
doc/script_commands.txt

@@ -2304,7 +2304,7 @@ Also useful when passing arrays to functions or accessing another npc's arrays:
 
 This function will return the specified stat of the invoking character, or, if a
 character name is specified, of that player. The stat can either be a number or
-paramater name, defined in 'db/const.txt'.
+parameter name, defined in 'db/const.txt'.
 
 Some example parameters:
 

+ 25 - 15
src/map/pc.c

@@ -10470,35 +10470,44 @@ static bool pc_readdb_levelpenalty(char* fields[], int columns, int current)
 /** [Cydh]
 * Calculates base hp of player. Reference: http://irowiki.org/wiki/Max_HP
 * @param level Base level of player
-* @param idx Index of class
+* @param class_ Job ID @see enum e_job
 * @return base_hp
 */
-static unsigned int pc_calc_basehp(uint16 level, uint16 class_idx) {
+static unsigned int pc_calc_basehp(uint16 level, uint16 class_) {
 	double base_hp;
-	uint16 i;
+	uint16 i, idx = pc_class2idx(class_);
 
-	base_hp = 35 + level * (job_info[class_idx].hp_multiplicator/100.);
+	base_hp = 35 + level * (job_info[idx].hp_multiplicator/100.);
 #ifndef RENEWAL
-	if(level >= 10 && (class_idx == JOB_NINJA || class_idx == JOB_GUNSLINGER)) base_hp += 90;
+	if(level >= 10 && (class_ == JOB_NINJA || class_ == JOB_GUNSLINGER)) base_hp += 90;
 #endif
 	for (i = 2; i <= level; i++)
-		base_hp += floor(((job_info[class_idx].hp_factor/100.) * i) + 0.5); //Don't have round()
+		base_hp += floor(((job_info[idx].hp_factor/100.) * i) + 0.5); //Don't have round()
 	return (unsigned int)base_hp;
 }
 
-/** [Playter]
+/** [Playtester]
 * Calculates base sp of player.
 * @param level Base level of player
-* @param idx Index of class
+* @param class_ Job ID @see enum e_job
 * @return base_sp
 */
-static unsigned int pc_calc_basesp(uint16 level, uint16 class_idx) {
+static unsigned int pc_calc_basesp(uint16 level, uint16 class_) {
 	double base_sp;
+	uint16 idx = pc_class2idx(class_);
 
-	base_sp = 10 + floor(level * (job_info[class_idx].sp_factor / 100.));
+	base_sp = 10 + floor(level * (job_info[idx].sp_factor / 100.));
 #ifndef RENEWAL
-	if(level >= 10 && class_idx == JOB_NINJA) base_sp -= 20;
-	if(level >= 10 && class_idx == JOB_GUNSLINGER) base_sp -= 17;
+	switch (class_) {
+		case JOB_NINJA:
+			if (level >= 10)
+				base_sp -= 20;
+			break;
+		case JOB_GUNSLINGER:
+			if (level >= 10)
+				base_sp -= 17;
+			break;
+	}
 #endif
 	return (unsigned int)base_sp;
 }
@@ -10856,7 +10865,8 @@ void pc_readdb(void) {
 	for (i = 0; i < JOB_MAX; i++) {
 		int idx;
 		uint16 j;
-		if (!pcdb_checkid(i)) continue;
+		if (!pcdb_checkid(i))
+			continue;
 		if (i == JOB_WEDDING || i == JOB_XMAS || i == JOB_SUMMER || i == JOB_HANBOK || i == JOB_OKTOBERFEST)
 			continue; //Classes that do not need exp tables.
 		idx = pc_class2idx(i);
@@ -10868,9 +10878,9 @@ void pc_readdb(void) {
 		//Init and checking the empty value of Base HP/SP [Cydh]
 		for (j = 0; j < (job_info[idx].max_level[0] ? job_info[idx].max_level[0] : MAX_LEVEL); j++) {
 			if (job_info[idx].base_hp[j] == 0)
-				job_info[idx].base_hp[j] = pc_calc_basehp(j+1,idx);
+				job_info[idx].base_hp[j] = pc_calc_basehp(j+1,i);
 			if (job_info[idx].base_sp[j] == 0)
-				job_info[idx].base_sp[j] = pc_calc_basesp(j+1,idx);
+				job_info[idx].base_sp[j] = pc_calc_basesp(j+1,i);
 		}
 	}
 }

+ 1 - 1
src/map/script.c

@@ -18301,7 +18301,7 @@ BUILDIN_FUNC(instance_id)
 	if(!instance_id) {
 		//ShowError("script:instance_id: No instance attached to NPC or player");
 		script_pushint(st, 0);
-		return 1;
+		return SCRIPT_CMD_SUCCESS;
 	}
 	script_pushint(st, instance_id);
 	return SCRIPT_CMD_SUCCESS;