Ejemplo n.º 1
0
//Initialization from DB (Editor, Server)
CurrentCharacter::CurrentCharacter(SqliteResult sqliteResult, Location* location) :
	CurrentMapObject<Character>::CurrentMapObject(sqliteResult, Game::instance->resources->characters, Game::instance->resources->charactersCount, location)
{
	movingX = x;
	movingY = y;

	strcpy(login, sqliteResult.strings["login"].c_str());
	strcpy(password, sqliteResult.strings["password"].c_str());

	hp = 100;

	char query[256];
	int rowsCount;
	std::vector<SqliteResult> sqliteResultsChildren;

	if (node)
		setTitle(login);

	//CurrentItems
	sprintf(query, "SELECT * FROM CurrentItem WHERE locationId=0 AND currentCharacterId=%d", id);
	sqliteResultsChildren = SqliteGetRows(Game::instance->db, query);
	currentItems = NULL;
	currentItemsCount = 0;
	rowsCount = sqliteResultsChildren.size();
	while (currentItemsCount < rowsCount)
	{
		SpawnItem(new CurrentItem(sqliteResultsChildren[currentItemsCount], NULL, this));
	}

	//CurrentQuests
	sprintf(query, "SELECT * FROM CurrentQuest WHERE currentCharacterId=%d", id);
	sqliteResultsChildren = SqliteGetRows(Game::instance->db, query);
	currentQuests = NULL;
	currentQuestsCount = 0;
	rowsCount = sqliteResultsChildren.size();
	while (currentQuestsCount < rowsCount)
	{
		currentQuestsCount++;
		currentQuests = (CurrentQuest**)realloc(currentQuests, currentQuestsCount * sizeof(CurrentQuest*));
		currentQuests[currentQuestsCount - 1] = new CurrentQuest(sqliteResultsChildren[currentQuestsCount - 1], this);
	}

	//CurrentSkills
	sprintf(query, "SELECT * FROM CurrentSkill WHERE currentCharacterId=%d", id);
	sqliteResultsChildren = SqliteGetRows(Game::instance->db, query);
	currentSkills = NULL;
	currentSkillsCount = 0;
	rowsCount = sqliteResultsChildren.size();
	while (currentSkillsCount < rowsCount)
	{
		SpawnSkill(new CurrentSkill(sqliteResultsChildren[currentSkillsCount], this));
	}
}
Ejemplo n.º 2
0
CurrentSkill* CurrentCharacter::AddSkill(Skill* base)
{
	char query[256];

	sprintf(query, "INSERT INTO CurrentSkill(baseId, currentCharacterId) VALUES(%d, %d)", base->id, this->id);
	sqlite3_exec(Game::instance->db, query, NULL, NULL, NULL);
	sprintf(query, "SELECT * FROM CurrentSkill WHERE id=%d", sqlite3_last_insert_rowid(Game::instance->db));
	SqliteResult sqliteResult = SqliteGetRows(Game::instance->db, query)[0];
	CurrentSkill* currentSkill = new CurrentSkill(sqliteResult, this);
	SpawnSkill(currentSkill);
	return currentSkill;
}
Ejemplo n.º 3
0
CurrentItem* CurrentCharacter::AddItem(Item* base, int count)
{
	char query[256];

	sprintf(query, "INSERT INTO CurrentItem(baseId, x, y, locationId, currentCharacterId, `count`) VALUES(%d, 0, 0, NULL, %d, %d)", base->id, this->id, count);
	sqlite3_exec(Game::instance->db, query, NULL, NULL, NULL);
	sprintf(query, "SELECT * FROM CurrentItem WHERE id=%d", sqlite3_last_insert_rowid(Game::instance->db));
	SqliteResult sqliteResult = SqliteGetRows(Game::instance->db, query)[0];
	CurrentItem* currentItem = new CurrentItem(sqliteResult, NULL, this);
	SpawnItem(currentItem);
	return currentItem;
}
Ejemplo n.º 4
0
void Location::CurrentMapObjectsInit(T** &currentMapObjects, int &currentMapObjectsCount, char* tableName)
{
	char query[64];
	std::vector<SqliteResult> sqliteResults;
	
	sprintf(query, "SELECT * FROM %s WHERE locationId=%d;", tableName, id); //TODO: Get class T name
	sqliteResults = SqliteGetRows(Game::instance->db, query);
	
	currentMapObjectsCount = 0;
	currentMapObjects = NULL;
	
	int rowsCount = sqliteResults.size();
	while (currentMapObjectsCount < rowsCount)
		SpawnCurrentMapObject<T>(currentMapObjects, currentMapObjectsCount, new T(sqliteResults[currentMapObjectsCount], this));
}
Ejemplo n.º 5
0
T* GameResources::AddMapObject(T** &mapObjects, int &mapObjectsCount, char* tableName, char* modelPath)
{
	char path[256];
	char query[256];

	sprintf(query, "SELECT * FROM `%s` WHERE id=%d", tableName, sqlite3_last_insert_rowid(Game::instance->db));
	SqliteResult sqliteResult = SqliteGetRows(Game::instance->db, query)[0];
	
	//Warning! 'Double' model files in 'path' (e. g. if we put *.3ds after *.md2 that loaded with an editor) can cause 'any model loading' (e. g. *.3ds instead of *.md2, that we loaded earlier in editor)
	sprintf(path, "editor/%s/model/%s", Game::instance->name, tableName);
	ImportModel(modelPath, path, sqliteResult.integers["id"]);

	T* mapObject = new T(sqliteResult, path);
	SpawnMapObject<T>(mapObjects, mapObjectsCount, mapObject);
	return mapObject;
}
Ejemplo n.º 6
0
void GameResources::MapObjectsInit(T** &mapObjects, int &mapObjectsCount, char* tableName, InitializationType initializationType)
{
	char query[64];
	char* path;
	std::vector<SqliteResult> sqliteResults;
	
	sprintf(query, "SELECT * FROM `%s`;", tableName); //TODO: Get class T name
	sqliteResults = SqliteGetRows(Game::instance->db, query);
	
	mapObjectsCount = 0;
	mapObjects = NULL;

	switch (initializationType)
	{
		case Editor:
			path = new char[256];
			sprintf(path, "editor/%s/model/%s", Game::instance->name, tableName);
			break;
		case Client:
			path = new char[256];
			sprintf(path, "client/%s/model/%s", Game::instance->name, tableName);
			break;
		case Server:
			path = NULL;
			break;
	}
	
	int rowsCount = sqliteResults.size();
	while (mapObjectsCount < rowsCount)
	{
		mapObjectsCount++;
		mapObjects = (T**)realloc(mapObjects, mapObjectsCount * sizeof(T*));
		mapObjects[mapObjectsCount - 1] = new T(sqliteResults[mapObjectsCount - 1], path);
	}

	if (path)
		delete path;
}