// *************************************************************** // Function: AddPlayerToInstance.cpp // *************************************************************** #include "Main.h" //************************************ // Name: GetPForItem // // Accesses the item with the specified location and position. // // Parameters: // location - Location of the item // position - Position of the item // pLir - Player's data // // Return: // NOT NULL - Pointer to the requested item // NULL - No item found //************************************ Item* GetPForItem(int location, int position, PLAYER_DATA* pLir) { for (unsigned int i=0; imyItems.size(); i++) { if (pLir->myItems[i].GetItemStorageLocation()==location) { if (pLir->myItems[i].GetItemStoragePosition()==position) { return &pLir->myItems[i]; } } } return 0; } //************************************ // Name: AddPlayerToInstance // // Adds a player to an instance. If the instance does not exist it is created. // // Parameters: // pResult - Database query result // pLir - Player's data // // Return: // - zero //************************************ int AddPlayerToInstance(QUERY_RESULT* pResult, PLAYER_DATA* pLir) { //Is this zone ID for a town or normally separate instance bool is_town=true; //Find an instance with this zone ID long f_instance=-1; hash_map::iterator itr; for (itr=gInstances.begin(); itr!=gInstances.end(); itr++) { if (itr->second.GetZoneId()==pLir->zoneId) { f_instance=itr->second.GetInstanceId(); break; } } //If an instance already exists //Only add if: //The zone is a town. //The shared flag is set if (f_instance>-1 && !gInstances[f_instance].IsFull() && (is_town || gServerConfig.sharedInstances)){} //If the requested instance does not exist, create it else { f_instance=gInstanceIds.GetFreeID(); typedef pair ipair; gInstances.insert(ipair(f_instance, Instance(pLir->zoneId))); gInstances[f_instance].SetCapacity(gServerConfig.maxPerInstance); gInstances[f_instance].SetInstanceId(f_instance); gInstances[f_instance].InitZone(); } //We have our instance made and now we must add the player to the instance MYSQL_ROW row=mysql_fetch_row(pResult->pResult); //First we must get the character name from the database char name[20]; memset(name, 0, 20); strcpy(name, row[0]); //Create and add a new player to the instance Player *p=new Player(name, pLir); gInstances[f_instance].AddPlayer(p); Agent *pAgent=p->GetAgent(); BattleData *pBd=pAgent->GetBattleData(); pLir->pPlayer=p; pLir->instanceId=f_instance; p->SetIdManagers(&gInstances[f_instance].mIsaMan, &gInstances[f_instance].mEisaMan); p->SetAppearance(atoi(row[1]), CHAR_APP_HEIGHT_SEX); p->SetAppearance(atoi(row[2]), CHAR_APP_HAIR_SKIN_COLOR); p->SetAppearance(atoi(row[3]), CHAR_APP_PROFESSION_HAIR_STYLE); p->SetAppearance(atoi(row[4]), CHAR_APP_CAMPAIGN_FACE); //Extract the secondary profession char tmp[5]; sprintf(tmp, "%x", atoi(row[5])); tmp[0]=tmp[1]; memset(tmp+1, 0, 4); p->SetProfession(atoi(tmp), CHAR_PROF_SECONDARY); //Set the PvP value int pvp=atoi(row[6]); if (pvp==1) { p->SetCharacterType(true); } //Set the permissions group ID p->SetGroupId(atoi(row[8])); //Generate the indexes for the player's items p->SetEquippedArmor(INT_HEAD, GetPForItem(LOC_IN_EQUIPPED, EXT_HEAD, pLir)->GetId()); p->SetEquippedArmor(INT_CHEST, GetPForItem(LOC_IN_EQUIPPED, EXT_CHEST, pLir)->GetId()); p->SetEquippedArmor(INT_ARMS, GetPForItem(LOC_IN_EQUIPPED, EXT_ARMS, pLir)->GetId()); p->SetEquippedArmor(INT_LEGS, GetPForItem(LOC_IN_EQUIPPED, EXT_LEGS, pLir)->GetId()); p->SetEquippedArmor(INT_FEET, GetPForItem(LOC_IN_EQUIPPED, EXT_FEET, pLir)->GetId()); //TODO: need the same for weapon here //Set the agent stuff pBd->level=atoi(row[7]); pBd->currentMorale=100; //pAgent->SetCurrentSpeed(288*2); //Give them random skill bar for now xD for (int i=0; i<8; i++) { pBd->equippedSkills[i]=1+rand()%2000; } //Copy over all the loaded player items to the player class vector::iterator itr2; for (itr2=pLir->myItems.begin(); itr2!=pLir->myItems.end(); itr2++) { p->AddItem(&(*itr2)); } pLir->myItems.clear(); return 0; }