View Single Post
  #1  
Old 08-01-2009, 10:19 PM
Secrets's Avatar
Secrets
Demi-God
 
Join Date: May 2007
Location: b
Posts: 1,450
Default Maxlevel in addition to NPC level

This will add a maxlevel field for NPCs you want to scale dynamically to level. Currently, it does everything except set HP automatically. That will have to be set manually but can be changed by server admins. It also allows ATK to be calculated for NPCs with 0 attack also regardless of settings, and it sets generic stats for NPCS if they are 0.

If you set the field to 0, it will do nothing, so it does not affect anything past what is currently there. If someone wants to make their own formulas for generating NPCs, tweak npc.cpp. By default all stats are 75 so i'd say if you want NPCs to have custom stats, go for it or set it manually in the database, as it only checks for if stats are 0.

The minlevel field itself chooses a random number between level and maxlevel, so if you have maxlevel as 10 and level as 1, it will choose a random number between 1 and 10. There's existing calculations for min/max dmg, so I left them there.

Required SQL:

Code:
ALTER TABLE `npc_types` ADD COLUMN `maxlevel` tinyint NOT NULL DEFAULT 0;
Diff @ rev 830:

Code:
Index: beacon.cpp
===================================================================
--- beacon.cpp	(revision 830)
+++ beacon.cpp	(working copy)
@@ -45,7 +45,7 @@
 :Mob
 (
 	NULL, NULL, 0, 0, 0, INVISIBLE_MAN, 0, BT_NoTarget, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 ),
 		remove_timer(lifetime),
 		spell_timer(0)
Index: client.cpp
===================================================================
--- client.cpp	(revision 830)
+++ client.cpp	(working copy)
@@ -137,7 +137,8 @@
 	0,
 	0,
 	0,	// qglobal
-	0	//Drakelord:  slow_mitigation
+	0,	//Drakelord:  slow_mitigation
+	0	//Secrets: Maxlevel
 
 	),
 	//these must be listed in the order they appear in client.h
@@ -933,6 +934,7 @@
 void Client::ChannelMessageSend(const char* from, const char* to, int8 chan_num, int8 language, int8 lang_skill, const char* message, ...) {
 	if ((chan_num==11 && !(this->GetGM())) || (chan_num==10 && this->Admin()<80)) // dont need to send /pr & /petition to everybody
 		return;
+
 	va_list argptr;
 	char buffer[4096];
 
Index: mob.cpp
===================================================================
--- mob.cpp	(revision 830)
+++ mob.cpp	(working copy)
@@ -96,7 +96,8 @@
 		 sint16 in_hp_regen,
 		 sint16 in_mana_regen,
 		 int8	in_qglobal,
-		 float	in_slow_mitigation	//Drakelord:  Allows for mobs to mitigate how much they are slowed.
+		 float	in_slow_mitigation,	//Drakelord:  Allows for mobs to mitigate how much they are slowed.
+		 int8	in_maxlevel
 
 		 ) : 
 		attack_timer(2000),
@@ -214,6 +215,7 @@
 	mana_regen = in_mana_regen;
 	oocregen = RuleI(NPC, OOCRegen); //default Out of Combat Regen
 	slow_mitigation = in_slow_mitigation;
+	maxlevel = in_maxlevel;
 	invisible = false;
 	invisible_undead = false;
 	invisible_animals = false;
Index: mob.h
===================================================================
--- mob.h	(revision 830)
+++ mob.h	(working copy)
@@ -389,7 +389,8 @@
 		sint16	in_hp_regen,
 		sint16	in_mana_regen,
 		int8	in_qglobal,
-		float	in_slow_mitigation	//Drakelord:  Allows for mobs to mitigate how much they are slowed.
+		float	in_slow_mitigation,	//Drakelord:  Allows for mobs to mitigate how much they are slowed.
+		int8	in_maxlevel
 
 	);
 	virtual ~Mob();
@@ -1082,6 +1083,7 @@
 	sint16	mana_regen;
 	sint32	oocregen; //Out of Combat Regen, % per tick
 	float 	slow_mitigation;	//Allows for a slow mitigation based on a % in decimal form.  IE, 1 = 100% mitigation, .5 is 50%
+	int8	maxlevel;
 	Buffs_Struct	buffs[BUFF_COUNT];
 	StatBonuses		itembonuses;
 	StatBonuses		spellbonuses;
Index: npc.cpp
===================================================================
--- npc.cpp	(revision 830)
+++ npc.cpp	(working copy)
@@ -103,7 +103,8 @@
 	  d->hp_regen,
 	  d->mana_regen,
 	  d->qglobal,
-	  d->slow_mitigation ),
+	  d->slow_mitigation,
+	  d->maxlevel),
 	attacked_timer(CombatEventTimer_expire),
 	swarm_timer(100),
 	classattack_timer(1000),
@@ -125,7 +126,18 @@
 	NPCTypedata_ours = NULL;
 	respawn2 = in_respawn;
 	swarm_timer.Disable();
-	
+
+	// sanity check for lazy people
+	if(maxlevel < moblevel) {
+		int8 tmp = moblevel;
+		maxlevel = tmp;
+	}
+	//maxlevel stuff
+	if(maxlevel)
+	{
+	level = (MakeRandomInt(moblevel, maxlevel));
+	}
+
 	taunting = false;
 	proximity = NULL;
 	copper = 0;
@@ -249,6 +261,25 @@
 	accuracy_rating = d->accuracy_rating;
 	ATK = d->ATK;
 
+	//defaults for maxlevel
+
+	if (!ATK || ATK == 0)
+		ATK = (moblevel * 5); // attack is typically higher than stats, should make this a rule because it can and will change depending on server
+	if (!STR || STR == 0)
+        STR = 75; // these need to be reworked, till then use it on trash mobs
+	if (!STA || STA == 0) 
+        STA = 75;
+	if (!DEX || DEX == 0)
+        DEX = 75;
+	if (!AGI || AGI == 0)
+        AGI = 75;
+	if (!INT || INT == 0)
+        INT = 75;
+	if (!WIS || WIS == 0)
+        WIS = 75;
+	if (!CHA || CHA == 0)
+       CHA = 75;
+
     CalcMaxMana();
     SetMana(GetMaxMana());
 
@@ -308,19 +339,20 @@
     FR = d->FR;
     PR = d->PR;
 
-    if (!MR)
+    if (!MR || MR == 0)
         MR = (moblevel * 11)/10;
-    if (!CR)
+    if (!CR || CR == 0)
         CR = (moblevel * 11)/10;
-    if (!DR)
+    if (!DR || DR == 0)
         DR = (moblevel * 11)/10;
-    if (!FR)
+    if (!FR || FR == 0)
         FR = (moblevel * 11)/10;
-    if (!PR)
+    if (!PR || PR == 0)
         PR = (moblevel * 11)/10;
 
 	npc_aggro = d->npc_aggro;
 
+
 	AI_Start();
 
 	d_meele_texture1 = d->d_meele_texture1;
Index: PlayerCorpse.cpp
===================================================================
--- PlayerCorpse.cpp	(revision 830)
+++ PlayerCorpse.cpp	(working copy)
@@ -198,7 +198,7 @@
 	 in_npc->GetHeading(),in_npc->GetX(),in_npc->GetY(),in_npc->GetZ(),0,
 	 in_npc->GetTexture(),in_npc->GetHelmTexture(),
 	 0,0,0,0,0,0,0,0,0,
-	 0,0,0,0,0,0,0,0,0,0,0,0xff,0,0,0,0,0,0,0,0),
+	 0,0,0,0,0,0,0,0,0,0,0,0xff,0,0,0,0,0,0,0,0,0),
 	 corpse_decay_timer(in_decaytime),
 	corpse_delay_timer(RuleI(NPC, CorpseUnlockTimer)),
 	corpse_graveyard_timer(0)
@@ -294,6 +294,7 @@
 	0,
 	0,
 	0,	// qglobal
+	0,
 	0	//Drakelord:  slow_mitigation
 ),
 	corpse_decay_timer(RuleI(Character, CorpseDecayTimeMS)),
@@ -403,7 +404,7 @@
  : Mob("Unnamed_Corpse","",0,0,in_gender, in_race, in_class, BT_Humanoid, in_deity, in_level,0, in_size, 0, in_heading, in_x, in_y, in_z,0,in_texture,in_helmtexture,
 	 0,0,0,0,0,0,0,0,0,
 	 0,0,0,0,0,0,0,0,0,0,0,0xff,
-	 0,0,0,0,0,0,0,0),
+	 0,0,0,0,0,0,0,0,0),
 	corpse_decay_timer(RuleI(Character, CorpseDecayTimeMS)),
 	corpse_delay_timer(RuleI(NPC, CorpseUnlockTimer)),
 	corpse_graveyard_timer(RuleI(Zone, GraveyardTimeMS))
Index: zonedb.cpp
===================================================================
--- zonedb.cpp	(revision 830)
+++ zonedb.cpp	(working copy)
@@ -1065,7 +1065,8 @@
 			"npc_types.see_improved_hide,"
 			"npc_types.ATK,"
 			"npc_types.Accuracy,"
-			"npc_types.slow_mitigation";
+			"npc_types.slow_mitigation,"
+			"npc_types.maxlevel";
 
 		MakeAnyLenString(&query, "%s FROM npc_types WHERE id=%d", basic_query, id);
 
@@ -1229,6 +1230,7 @@
 				tmpNPCType->ATK = atoi(row[r++]);
 				tmpNPCType->accuracy_rating = atoi(row[r++]);
 				tmpNPCType->slow_mitigation = atoi(row[r++]);
+				tmpNPCType->maxlevel = atoi(row[r++]);
 
 				// If NPC with duplicate NPC id already in table,
 				// free item we attempted to add.
Index: zonedump.h
===================================================================
--- zonedump.h	(revision 830)
+++ zonedump.h	(working copy)
@@ -111,6 +111,7 @@
 	bool	findable;		//can be found with find command
 	bool	trackable;
 	float	slow_mitigation;	//Drakelord:  Slow mitigation % in decimal form.
+	int8	maxlevel;
 };
 
 struct ZSDump_Spawn2 {
Reply With Quote