ソースを参照

Changed gold points to parameters

Lemongrass3110 2 年 前
コミット
b97987e4e7
4 ファイル変更31 行追加20 行削除
  1. 1 1
      src/map/clif.cpp
  2. 1 0
      src/map/map.hpp
  3. 28 19
      src/map/pc.cpp
  4. 1 0
      src/map/script_constants.hpp

+ 1 - 1
src/map/clif.cpp

@@ -24807,7 +24807,7 @@ void clif_goldpc_info( struct map_session_data& sd ){
 		}else{
 			p.unitPoint = 1;
 		}
-		p.point = (int32)pc_readreg2( &sd, GOLDPC_POINT_VAR );
+		p.point = (int32)pc_readparam( &sd, SP_GOLDPC_POINTS );
 		if( sd.goldpc_tid != INVALID_TIMER ){
 			p.accumulatePlaySecond = (int32)( 3600 - battle_config.feature_goldpc_time + pc_readreg2( &sd, GOLDPC_SECONDS_VAR ) );
 		}else{

+ 1 - 0
src/map/map.hpp

@@ -486,6 +486,7 @@ enum _sp {
 	SP_CASHPOINTS, SP_KAFRAPOINTS,
 	SP_PCDIECOUNTER, SP_COOKMASTERY,
 	SP_ACHIEVEMENT_LEVEL,
+	SP_GOLDPC_POINTS,
 
 	// Mercenaries
 	SP_MERCFLEE=165, SP_MERCKILLS=189, SP_MERCFAITH=190,

+ 28 - 19
src/map/pc.cpp

@@ -2156,28 +2156,16 @@ TIMER_FUNC(pc_goldpc_update){
 
 	// TODO: add mapflag to disable?
 
-	int32 points = (int32)pc_readreg2( sd, GOLDPC_POINT_VAR );
+	int64 points = pc_readparam( sd, SP_GOLDPC_POINTS );
 
-	if( points < battle_config.feature_goldpc_max_points ){
-		if( battle_config.feature_goldpc_vip && pc_isvip( sd ) ){
-			points += 2;
-		}else{
-			points += 1;
-		}
-
-		points = std::min( points, battle_config.feature_goldpc_max_points );
-
-		pc_setreg2( sd, GOLDPC_POINT_VAR, points );
-		pc_setreg2( sd, GOLDPC_SECONDS_VAR, 0 );
-
-		if( points < battle_config.feature_goldpc_max_points ){
-			sd->goldpc_tid = add_timer( gettick() + battle_config.feature_goldpc_time * 1000, pc_goldpc_update, sd->bl.id, (intptr_t)nullptr );
-		}
-
-		// Update the client
-		clif_goldpc_info( *sd );
+	if( battle_config.feature_goldpc_vip && pc_isvip( sd ) ){
+		points += 2;
+	}else{
+		points += 1;
 	}
 
+	pc_setparam( sd, SP_GOLDPC_POINTS, points );
+
 	return 0;
 }
 
@@ -10103,6 +10091,7 @@ int64 pc_readparam(struct map_session_data* sd,int64 type)
 #endif
 		case SP_CRIT_DEF_RATE: val = sd->bonus.crit_def_rate; break;
 		case SP_ADD_ITEM_SPHEAL_RATE: val = sd->bonus.itemsphealrate2; break;
+		case SP_GOLDPC_POINTS: val = pc_readreg2( sd, GOLDPC_POINT_VAR ); break;
 		default:
 			ShowError("pc_readparam: Attempt to read unknown parameter '%lld'.\n", type);
 			return -1;
@@ -10354,6 +10343,26 @@ bool pc_setparam(struct map_session_data *sd,int64 type,int64 val_tmp)
 		sd->cook_mastery = val;
 		pc_setglobalreg(sd, add_str(COOKMASTERY_VAR), sd->cook_mastery);
 		return true;
+	case SP_GOLDPC_POINTS:
+		val = cap_value( val, 0, battle_config.feature_goldpc_max_points );
+
+		pc_setreg2( sd, GOLDPC_POINT_VAR, val );
+		pc_setreg2( sd, GOLDPC_SECONDS_VAR, 0 );
+
+		// Make sure to always delete the timer
+		if( sd->goldpc_tid != INVALID_TIMER ){
+			delete_timer( sd->goldpc_tid, pc_goldpc_update );
+			sd->goldpc_tid = INVALID_TIMER;
+		}
+
+		// If the system is enabled and the player can still earn some points restart the timer
+		if( battle_config.feature_goldpc_active && val < battle_config.feature_goldpc_max_points ){
+			sd->goldpc_tid = add_timer( gettick() + battle_config.feature_goldpc_time * 1000, pc_goldpc_update, sd->bl.id, (intptr_t)nullptr );
+		}
+
+		// Update the client
+		clif_goldpc_info( *sd );
+		return true;
 	default:
 		ShowError("pc_setparam: Attempted to set unknown parameter '%lld'.\n", type);
 		return false;

+ 1 - 0
src/map/script_constants.hpp

@@ -612,6 +612,7 @@
 	export_parameter(PCDIECOUNTER_VAR, SP_PCDIECOUNTER);
 	export_parameter(COOKMASTERY_VAR, SP_COOKMASTERY);
 	export_parameter(ACHIEVEMENTLEVEL, SP_ACHIEVEMENT_LEVEL);
+	export_parameter(GOLDPC_POINT_VAR, SP_GOLDPC_POINTS);
 
 	export_constant2("bMaxHP",SP_MAXHP);
 	export_constant2("bMaxSP",SP_MAXSP);