Browse Source

Merge pull request #17 from cydh/master

Added addspiritball, delspiritball, and countspiritball script command
Cydh Ramdh 11 years ago
parent
commit
6bf1c27023
4 changed files with 123 additions and 14 deletions
  1. 18 0
      doc/script_commands.txt
  2. 22 12
      src/map/pc.c
  3. 2 2
      src/map/pc.h
  4. 81 0
      src/map/script.c

+ 18 - 0
doc/script_commands.txt

@@ -2375,6 +2375,24 @@ negative value will decrease time.
 
 NOTE: This command is only available if the VIP System is enabled.
 
+---------------------------------------
+
+*addspiritball <count>,<duration>{,<char_id>};
+
+Adds spirit ball to player for 'duration' in milisecond.
+
+---------------------------------------
+
+*delspiritball <count>{,<char_id>};
+
+Deletes the spirit ball(s) from player.
+
+---------------------------------------
+
+*countspiritball {<char_id>};
+
+Counts the spirit ball that player has.
+
 ---------------------------------------
 \\
 2,2 Item-related commands

+ 22 - 12
src/map/pc.c

@@ -179,11 +179,18 @@ static int pc_spiritball_timer(int tid, unsigned int tick, int id, intptr_t data
 	return 0;
 }
 
-int pc_addspiritball(struct map_session_data *sd,int interval,int max)
+/**
+* Adds a spiritball to player for 'interval' ms
+* @param sd
+* @param interval
+* @param max
+*/
+void pc_addspiritball(struct map_session_data *sd,int interval,int max)
 {
-	int tid, i;
+	int tid;
+	uint8 i;
 
-	nullpo_ret(sd);
+	nullpo_retv(sd);
 
 	if(max > MAX_SKILL_LEVEL)
 		max = MAX_SKILL_LEVEL;
@@ -210,23 +217,27 @@ int pc_addspiritball(struct map_session_data *sd,int interval,int max)
 		clif_millenniumshield(sd,sd->spiritball);
 	else
 		clif_spiritball(&sd->bl);
-
-	return 0;
 }
 
-int pc_delspiritball(struct map_session_data *sd,int count,int type)
+/**
+* Removes number of spiritball from player
+* @param sd
+* @param count
+* @param type 1 = doesn't give client effect
+*/
+void pc_delspiritball(struct map_session_data *sd,int count,int type)
 {
-	int i;
+	uint8 i;
 
-	nullpo_ret(sd);
+	nullpo_retv(sd);
 
 	if(sd->spiritball <= 0) {
 		sd->spiritball = 0;
-		return 0;
+		return;
 	}
 
-	if(count <= 0)
-		return 0;
+	if(count == 0)
+		return;
 	if(count > sd->spiritball)
 		count = sd->spiritball;
 	sd->spiritball -= count;
@@ -250,7 +261,6 @@ int pc_delspiritball(struct map_session_data *sd,int count,int type)
 		else
 			clif_spiritball(&sd->bl);
 	}
-	return 0;
 }
 
 static int pc_check_banding( struct block_list *bl, va_list ap ) {

+ 2 - 2
src/map/pc.h

@@ -1016,8 +1016,8 @@ extern const struct sg_data sg_info[MAX_PC_FEELHATE];
 void pc_setinvincibletimer(struct map_session_data* sd, int val);
 void pc_delinvincibletimer(struct map_session_data* sd);
 
-int pc_addspiritball(struct map_session_data *sd,int,int);
-int pc_delspiritball(struct map_session_data *sd,int,int);
+void pc_addspiritball(struct map_session_data *sd,int interval,int max);
+void pc_delspiritball(struct map_session_data *sd,int count,int type);
 void pc_addfame(struct map_session_data *sd,int count);
 unsigned char pc_famerank(int char_id, int job);
 bool pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_list *bl);

+ 81 - 0
src/map/script.c

@@ -18546,6 +18546,84 @@ BUILDIN_FUNC(getguildmember)
 	return SCRIPT_CMD_SUCCESS;
 }
 
+/** Adds spirit ball to player for 'duration' in milisecond
+* @param count How many spirit ball will be added
+* @param duration How long spiritball is active until it disappears
+* @param char_id Target player (Optional)
+* @author [Cydh]
+*/
+BUILDIN_FUNC(addspiritball) {
+	uint8 i, count = script_getnum(st,2);
+	uint16 duration = script_getnum(st,3);
+	struct map_session_data *sd = NULL;
+	
+	if (count == 0)
+		return SCRIPT_CMD_SUCCESS;
+
+	if (script_hasdata(st,4)) {
+		if (script_isstring(st,4))
+			sd = map_charid2sd(script_getnum(st,4));
+		else
+			sd = map_nick2sd(script_getstr(st,4));
+	}
+	else
+		sd = script_rid2sd(st);
+	if (!sd)
+		return SCRIPT_CMD_FAILURE;
+
+	for (i = 0; i < count; i++)
+		pc_addspiritball(sd,duration,10);
+	return SCRIPT_CMD_SUCCESS;
+}
+
+/** Deletes the spirit ball(s) from player
+* @param count How many spirit ball will be deleted
+* @param char_id Target player (Optional)
+* @author [Cydh]
+*/
+BUILDIN_FUNC(delspiritball) {
+	uint8 count = script_getnum(st,2);
+	struct map_session_data *sd = NULL;
+	
+	if (count == 0)
+		count = 1;
+	
+	if (script_hasdata(st,3)) {
+		if (script_isstring(st,3))
+			sd = map_charid2sd(script_getnum(st,3));
+		else
+			sd = map_nick2sd(script_getstr(st,3));
+	}
+	else
+		sd = script_rid2sd(st);
+	if (!sd)
+		return SCRIPT_CMD_FAILURE;
+
+	pc_delspiritball(sd,count,0);
+	return SCRIPT_CMD_SUCCESS;
+}
+
+/** Counts the spirit ball that player has
+* @param char_id Target player (Optional)
+* @author [Cydh]
+*/
+BUILDIN_FUNC(countspiritball) {
+	struct map_session_data *sd;
+
+	if (script_hasdata(st,2)) {
+		if (script_isstring(st,2))
+			sd = map_charid2sd(script_getnum(st,2));
+		else
+			sd = map_nick2sd(script_getstr(st,2));
+	}
+	else
+		sd = script_rid2sd(st);
+	if (!sd)
+		return SCRIPT_CMD_FAILURE;
+	script_pushint(st,sd->spiritball);
+	return SCRIPT_CMD_SUCCESS;
+}
+
 #include "../custom/script.inc"
 
 // declarations that were supposed to be exported from npc_chat.c
@@ -19076,6 +19154,9 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(enable_command,""),
 	BUILDIN_DEF(disable_command,""),
 	BUILDIN_DEF(getguildmember,"i?"),
+	BUILDIN_DEF(addspiritball,"ii?"),
+	BUILDIN_DEF(delspiritball,"i?"),
+	BUILDIN_DEF(countspiritball,"?"),
 
 #include "../custom/script_def.inc"