Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Server Code Submissions

Reply
 
Thread Tools Display Modes
  #1  
Old 08-15-2010, 11:18 AM
pfyon's Avatar
pfyon
Discordant
 
Join Date: Mar 2009
Location: Ottawa
Posts: 495
Default COMMITTED: quest::createBot()

I have wanted to add this for a while so some bot commands can be removed from the client and then provide bots as rewards from quests. Creates a bot given name,race,etc.

Usage: quest::createBot(firstname, lastname, int level, int race, int class, int gender);

returns true if successful, false if not for some reason.

Note, the level parameter isn't really useful right now as the bot receives the level of the client who summons it when it's summoned. Also note, it'll fail if you provide the name of a bot that already exists so, (for the moment) it's up to the quest creator to ensure that unique names are given.

Code:
Index: perlparser.cpp
===================================================================
--- perlparser.cpp	(revision 75)
+++ perlparser.cpp	(working copy)
@@ -2064,6 +2064,30 @@
 	XSRETURN(1);
 }
 
+XS(XS__createBot);
+XS(XS__createBot)
+{
+	dXSARGS;
+	bool		RETVAL;
+	dXSTARG;
+
+	if(items != 6)
+	{
+		Perl_croak(aTHX_ "Usage: createBot(firstname, lastname, level, race, class, gender)");
+	}
+
+	char *firstname = (char *)SvPV_nolen(ST(0));
+	char *lastname = (char *)SvPV_nolen(ST(1));
+	int level = (int) SvIV(ST(2));
+	int race = (int) SvIV(ST(3));
+	int botclass = (int) SvIV(ST(4));
+	int gender = (int) SvIV(ST(5));
+
+	RETVAL = quest_manager.createBot(firstname, lastname, level, race, botclass, gender);
+	XSprePUSH; PUSHu((IV)RETVAL);
+	XSRETURN(1);
+}
+
 #endif //BOTS
 
 XS(XS__taskselector);
@@ -3167,6 +3191,7 @@
 		newXS(strcpy(buf, "botquest"), XS__botquest, file);
 		newXS(strcpy(buf, "spawnbotcount"), XS__spawnbotcount, file);
 		newXS(strcpy(buf, "createbotcount"), XS__createbotcount, file);
+		newXS(strcpy(buf, "createBot"), XS__createBot, file);
 #endif //BOTS
 
 		newXS(strcpy(buf, "taskselector"), XS__taskselector, file);
Index: questmgr.cpp
===================================================================
--- questmgr.cpp	(revision 75)
+++ questmgr.cpp	(working copy)
@@ -75,6 +75,7 @@
 #include "guild_mgr.h"
 #include "../common/rulesys.h"
 #include "QGlobals.h"
+#include "bot.h"
 
 
 extern Zone* zone;
@@ -1708,6 +1709,62 @@
 	return RuleB(Bots, BotQuest);
 }
 
+bool QuestManager::createBot(const char *name, const char *lastname, uint8 level, uint16 race, uint8 botclass, uint8 gender)
+{
+	std::string TempErrorMessage;
+	int32 MaxBotCreate = RuleI(Bots, CreateBotCount);
+
+	if (initiator && initiator->IsClient())
+	{
+		if(Bot::SpawnedBotCount(initiator->CharacterID(), &TempErrorMessage) >= MaxBotCreate)
+		{
+			initiator->Message(15,"You have the maximum number of bots allowed.");
+			return false;
+		}
+
+		if(!TempErrorMessage.empty())
+		{
+			initiator->Message(13, "Database Error: %s", TempErrorMessage.c_str());
+			return false;
+		}
+
+		NPCType DefaultNPCTypeStruct = Bot::CreateDefaultNPCTypeStructForBot(name, lastname, level, race, botclass, gender);
+		Bot* NewBot = new Bot(DefaultNPCTypeStruct, initiator);
+
+		if(NewBot)
+		{
+			if(!NewBot->IsValidRaceClassCombo()) {
+				initiator->Message(0, "That Race/Class combination cannot be created.");
+				return false;
+			}
+
+			if(!NewBot->IsValidName()) {
+				initiator->Message(0, "%s has invalid characters. You can use only the A-Z, a-z and _ characters in a bot name.", NewBot->GetCleanName());
+				return false;
+			}
+
+			if(!NewBot->IsBotNameAvailable(&TempErrorMessage)) {
+				initiator->Message(0, "The name %s is already being used. Please choose a different name.", NewBot->GetCleanName());
+				return false;
+			}
+
+			if(!TempErrorMessage.empty()) {
+				initiator->Message(13, "Database Error: %s", TempErrorMessage.c_str());
+				return false;
+			}
+
+			// Now that all validation is complete, we can save our newly created bot
+			if(!NewBot->Save())
+			{
+				initiator->Message(0, "Unable to save %s as a bot.", NewBot->GetCleanName());
+			} else
+			{
+				initiator->Message(0, "%s saved as bot %u.", NewBot->GetCleanName(), NewBot->GetBotID());
+			}
+		}
+	}
+}
+
 #endif //BOTS
 
 void QuestManager::taskselector(int taskcount, int *tasks) {
Index: bot.h
===================================================================
--- bot.h	(revision 75)
+++ bot.h	(working copy)
@@ -234,6 +234,7 @@
 	static std::string GetBotMagicianPetType(Bot* botCaster);
 	static BotSpell GetBestBotSpellForNukeByTargetType(Bot* botCaster, SpellTargetType targetType);
 	static BotSpell GetBestBotWizardNukeSpellByTargetResists(Bot* botCaster, Mob* target);
+	static NPCType CreateDefaultNPCTypeStructForBot(std::string botName, std::string botLastName, uint8 botLevel, uint16 botRace, uint8 botClass, uint8 gender);
 
 	// Static Bot Group Methods
 	static bool AddBotToGroup(Bot* bot, Group* group);
@@ -281,7 +282,6 @@
 protected:
 	virtual void PetAIProcess();
 	static NPCType FillNPCTypeStruct(uint32 botSpellsID, std::string botName, std::string botLastName, uint8 botLevel, uint16 botRace, uint8 botClass, uint8 gender, float size, uint32 face, uint32 hairStyle, uint32 hairColor, uint32 eyeColor, uint32 eyeColor2, uint32 beardColor, uint32 beard, uint32 drakkinHeritage, uint32 drakkinTattoo, uint32 drakkinDetails, sint16 mr, sint16 cr, sint16 dr, sint16 fr, sint16 pr, sint16 ac, uint16 str, uint16 sta, uint16 dex, uint16 agi, uint16 _int, uint16 wis, uint16 cha, uint16 attack);
-	static NPCType CreateDefaultNPCTypeStructForBot(std::string botName, std::string botLastName, uint8 botLevel, uint16 botRace, uint8 botClass, uint8 gender);
 	virtual void BotMeditate(bool isSitting);
 	virtual bool BotRangedAttack(Mob* other);
 	virtual bool CheckBotDoubleAttack(bool Triple = false);
Index: questmgr.h
===================================================================
--- questmgr.h	(revision 75)
+++ questmgr.h	(working copy)
@@ -230,6 +230,7 @@
 	int createbotcount();
 	int spawnbotcount();
 	bool botquest();
+	bool createBot(const char *name, const char *lastname, uint8 level, uint16 race, uint8 botclass, uint8 gender);
 #endif
 
 protected:
edit: tested on ubuntu server 10.04 with server code revision 1621
Reply With Quote
  #2  
Old 09-11-2010, 11:00 AM
Derision
Developer
 
Join Date: Feb 2004
Location: UK
Posts: 1,540
Default

I've committed this, although I didn't test it, beyond making sure it compiled in both bot and none-bot builds. Thanks.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 12:01 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3