Loading...   

  • Created By Uleat On: 08:07 PM December 25, 2015
  • Link

void bot_command_clone(Client *c, const Seperator *sep)
{
	if (!is_bot_command_alias(sep->arg[0], "clone")) {
		c->Message(15, "Undefined linker usage in bot_command_clone (%c%s)", BOT_COMMAND_CHAR, sep->arg[0]);
		return;
	}
	if (!strcasecmp(sep->arg[1], "usage")) {
		c->Message(0, "usage: <target> %c%s [name]", BOT_COMMAND_CHAR, sep->arg[0]);
		return;
	}

	Bot* b = MyBot::AsTarget_ByBot(c);
	if (!b) {
		c->Message(15, "You must <target> a bot that you own to use this command");
		return;
	}
	if (!b->GetBotID()) {
		c->Message(15, "An unknown error has occured - BotName: %s, BotID: %u", b->GetCleanName(), b->GetBotID());
		Log.Out(Logs::General, Logs::Commands, "bot_command_clone(): - Error: Active bot reported invalid ID (BotName: %s, BotID: %u, OwnerName: %s, OwnerID: %u, AcctName: %s, AcctID: %u)",
			b->GetCleanName(), b->GetBotID(), c->GetCleanName(), c->CharacterID(), c->AccountName(), c->AccountID());
		return;
	}

	if (sep->arg[1][0] == '\0' || sep->IsNumber(1)) {
		c->Message(15, "You must [name] your bot clone");
		return;
	}
	std::string bot_name = sep->arg[1];

	uint32 bot_id = helper_create_bot(c, bot_name, b->GetClass(), b->GetRace(), b->GetGender());
	if (!bot_id) {
		c->Message(15, "Clone creation of bot '%s' failed...", b->GetCleanName());
		return;
	}

	std::string query = StringFormat(
		"INSERT INTO `bot_inventories`"
		" ("
		"`bot_id`,"
		" `slot_id`,"
		" `item_id`,"
		" `inst_charges`,"
		" `inst_color`,"
		" `inst_no_drop`,"
		" `inst_custom_data`,"
		" `ornament_icon`,"
		" `ornament_id_file`,"
		" `ornament_hero_model`,"
		" `augment_1`,"
		" `augment_2`,"
		" `augment_3`,"
		" `augment_4`,"
		" `augment_5`,"
		" `augment_6`,"
		")"
		" SELECT"
		" '%u' bot_id,"
		" bi.`slot_id`,"
		" bi.`item_id`,"
		" bi.`inst_charges`,"
		" bi.`inst_color`,"
		" bi.`inst_no_drop`,"
		" bi.`inst_custom_data`,"
		" bi.`ornament_icon`,"
		" bi.`ornament_id_file`,"
		" bi.`ornament_hero_model`,"
		" bi.`augment_1`,"
		" bi.`augment_2`,"
		" bi.`augment_3`,"
		" bi.`augment_4`,"
		" bi.`augment_5`,"
		" bi.`augment_6`"
		" FROM `bot_inventories` bi"
		" WHERE"
		" bi.`bot_id` = '%u'",
		bot_id,
		b->GetBotID()
	);
	auto results = database.QueryDatabase(query);
	if (!results.Success()) {
		c->Message(15, "Inventory import for bot clone '%s' failed...", bot_name.c_str());
		return;
	}

	c->Message(0, "Bot '%s' was successfully cloned to bot '%s'", b->GetCleanName(), bot_name.c_str());

	// TODO: Finalization
}

Raw Paste Data