📄 startup.cpp.svn-base
字号:
thisquest->script = atoi( row[12] );
thisquest->value1 = atoi( row[13] );
thisquest->value2 = atoi( row[14] );
thisquest->value3 = atoi( row[15] );
QuestList.push_back( thisquest );
}
DB->QFree( );
return true;
}
bool CWorldServer::LoadRespawnData( )
{
Log( MSG_LOAD, "RespawnZones data " );
MYSQL_ROW row;
MYSQL_RES *result = DB->QStore("SELECT id,x,y,map,radius,type FROM list_respawnzones");
if(result==NULL) return false;
while( row = mysql_fetch_row(result) )
{
CRespawnPoint* thisrespawnpoint = new (nothrow) CRespawnPoint;
if(thisrespawnpoint==NULL)
{
Log(MSG_ERROR, "Error allocing memory" );
DB->QFree( );
return false;
}
thisrespawnpoint->id = atoi(row[0]);
thisrespawnpoint->dest.x = (float)atof(row[1]);
thisrespawnpoint->dest.y = (float)atof(row[2]);
thisrespawnpoint->destMap = atoi(row[3]);
thisrespawnpoint->radius = atoi(row[4]);
thisrespawnpoint->masterdest = (atoi(row[5]) == 1);
MapList.Index[thisrespawnpoint->destMap]->RespawnList.push_back( thisrespawnpoint );
}
DB->QFree( );
return true;
}
bool CWorldServer::LoadMonsterSpawn( )
{
Log( MSG_LOAD, "SpawnZones data " );
MYSQL_ROW row;
MYSQL_RES *result = DB->QStore("SELECT id,map,montype,min,max,respawntime,points FROM list_spawnareas");
if(result==NULL) return false;
while(row = mysql_fetch_row(result))
{
bool flag = true;
char* tmp;
CSpawnArea* thisspawn = new (nothrow) CSpawnArea;
if(thisspawn==NULL)
{
Log(MSG_ERROR, "Error allocing memory" );
DB->QFree( );
return false;
}
thisspawn->id=atoi(row[0]);
thisspawn->map=atoi(row[1]);
thisspawn->montype=atoi(row[2]);
thisspawn->min=atoi(row[3]);
thisspawn->max=atoi(row[4]);
thisspawn->respawntime=atoi(row[5]);
thisspawn->amon = 0;
char* points;
points = row[6];
thisspawn->pcount = atoi(strtok( points , ",|"));
thisspawn->points = new (nothrow) fPoint[thisspawn->pcount];
if(thisspawn->points==NULL)
{
Log(MSG_ERROR, "Error allocing memory " );
delete thisspawn;
DB->QFree( );
return false;
}
thisspawn->lastRespawnTime = clock();
for(int i=0; i<thisspawn->pcount; i++)
{
if ((tmp = strtok(NULL, ",|"))==NULL)
{
Log( MSG_ERROR, "Spawn area %i have invalid points",thisspawn->id );
flag = false;
break;
}
float x=(float)atof(tmp);
if ((tmp = strtok(NULL, ",|"))==NULL)
{
Log( MSG_ERROR, "Spawn area %i have invalid points",thisspawn->id );
flag = false;
break;
}
float y=(float)atof(tmp);
thisspawn->points[i].x = x;
thisspawn->points[i].y = y;
}
if(flag)
{
thisspawn->thisnpc = GetNPCDataByID( thisspawn->montype );
if(thisspawn->thisnpc==NULL)
{
Log( MSG_WARNING, "Invalid montype - Spawn %i will not be added", thisspawn->id );
delete thisspawn;
continue;
}
MapList.Index[thisspawn->map]->MonsterSpawnList.push_back( thisspawn );
}
}
DB->QFree( );
return true;
}
bool CWorldServer::LoadNPCs( )
{
Log( MSG_LOAD, "NPC spawn " );
MYSQL_ROW row;
MYSQL_RES *result = DB->QStore("SELECT type,map,dir,x,y FROM list_npcs");
if(result==NULL) return false;
while(row = mysql_fetch_row(result))
{
CNPC* thisnpc = new (nothrow) CNPC;
if(thisnpc==NULL)
{
Log(MSG_ERROR, "Error allocing memory" );
DB->QFree( );
return false;
}
thisnpc->clientid = GetNewClientID();
thisnpc->npctype = atoi(row[0]);
thisnpc->posMap = atoi(row[1]);
thisnpc->dir = (float)atof(row[2]);
thisnpc->pos.x = (float)atof(row[3]);
thisnpc->pos.y = (float)atof(row[4]);
thisnpc->thisnpc = GetNPCDataByID( thisnpc->npctype );
if( thisnpc->thisnpc == NULL)
{
delete thisnpc;
continue;
}
MapList.Index[thisnpc->posMap]->AddNPC( thisnpc );
}
DB->QFree( );
return true;
}
bool CWorldServer::LoadDropsData( )
{
Log( MSG_LOAD, "Drops Data " );
FILE* fh = NULL;
fh = fopen("data/drops_data.csv", "r");
if(fh==NULL)
{
Log(MSG_ERROR, "\nError loading file data/drops_data.csv" );
return false;
}
char line[500];
fgets( line, 500, fh );// this is the column name
while(!feof(fh))
{
memset( &line, '\0', 500 );
fgets( line, 500, fh );
CMDrops* newdrop = new (nothrow) CMDrops;
if(newdrop==NULL)
{
fclose(fh);
continue;
}
newdrop->id = GetUIntValue(",", &line);
char* items = GetStrValue(",");
char* prob = GetStrValue(",");
newdrop->level_min = GetUIntValue(",");
newdrop->level_max = GetUIntValue(",");
newdrop->level_boss = GetUIntValue(",");
UINT value = 0;
bool First = true;
// items
while((value=GetUIntValue("|", First?items:NULL))!=0)
{
First = false;
CDropInfo* DropInfo = new (nothrow) CDropInfo;
if(DropInfo==NULL)
{
Log(MSG_WARNING, "\nError allocing memory [dropinfo]" );
continue;
}
if(value<20000)
{
DropInfo->type = value/1000;
DropInfo->item = value%1000;
}
else
{
DropInfo->type = value/1000000;
DropInfo->item = value%1000000;
}
newdrop->Drops.push_back( DropInfo );
}
newdrop->probmax = 0;
value = 0;
// probability
for(UINT j=0;j<newdrop->Drops.size();j++)
{
value = GetUIntValue("|",(j==0?prob:NULL));
if(value==0)
{
newdrop->Drops.at(j)->prob = 1;
if(newdrop->Drops.at(j)->type<10 || newdrop->Drops.at(j)->type==14)
newdrop->Drops.at(j)->prob *= Config.DROP_RATE;
Log(MSG_WARNING, "Probability is not complete, dropid: %i - temporal probability will be 1 * rate", newdrop->id );
}
else
{
newdrop->Drops.at(j)->prob = value;
if(newdrop->Drops.at(j)->type<10 || newdrop->Drops.at(j)->type==14)
newdrop->Drops.at(j)->prob *= Config.DROP_RATE;
}
newdrop->probmax += newdrop->Drops.at(j)->prob;
}
// sort time
for(UINT j=0;j<newdrop->Drops.size();j++)
{
for(UINT k=j;k<newdrop->Drops.size();k++)
{
if(newdrop->Drops.at(j)>newdrop->Drops.at(k))
{
CDropInfo* DropInfo = newdrop->Drops.at(j);
newdrop->Drops.at(j) = newdrop->Drops.at(k);
newdrop->Drops.at(k) = DropInfo;
}
}
}
MDropList.push_back( newdrop );
}
fclose(fh);
return true;
}
bool CWorldServer::LoadMonsters( )
{
Log( MSG_LOAD, "Monsters Spawn " );
// Do our monster spawnin
for(UINT i=0;i<MapList.Map.size();i++)
{
CMap* thismap = MapList.Map.at(i);
for(UINT j=0;j<thismap->MonsterSpawnList.size();j++)
{
CSpawnArea* thisspawn = thismap->MonsterSpawnList.at(j);
thisspawn->mapdrop = GetDropData( thisspawn->map );
thisspawn->mobdrop = GetDropData( thisspawn->thisnpc->dropid );
for(UINT k=0;k<thisspawn->max;k++)
{
fPoint position = RandInPoly( thisspawn->points, thisspawn->pcount );
thismap->AddMonster( thisspawn->montype, position, 0, thisspawn->mobdrop, thisspawn->mapdrop, thisspawn->id );
}
}
}
return true;
}
bool CWorldServer::LoadUpgrade( )
{
Log( MSG_LOAD, "Refine Data " );
FILE* fh = NULL;
fh = fopen("data/refine_data.csv", "r");
if(fh==NULL)
{
Log(MSG_ERROR, "\nError loading file data/refine_data.csv" );
return false;
}
char line[50];
fgets( line, 50, fh );// this is the column name
while(!feof(fh))
{
memset( &line, '\0', 50 );
fgets( line, 50, fh );
upgrade[GetUIntValue(",",&line)] = GetUIntValue(",");
}
fclose(fh);
return true;
}
bool CWorldServer::CleanConnectedList( )
{
Log( MSG_LOAD, "Cleaning Connected Clients " );
DB->QExecute("UPDATE accounts set online=false");
return true;
}
bool CWorldServer::LoadEquip( )
{
Log( MSG_LOAD, "Equip Data " );
FILE* fh = NULL;
fh = fopen("data/equip_data.csv", "r");
if(fh==NULL)
{
Log(MSG_ERROR, "\nError loading file data/equip_data.csv" );
return false;
}
char line[500];
fgets( line, 500, fh );// this is the column name
while(!feof(fh))
{
memset( &line, '\0', 500 );
fgets( line, 500, fh );
CEquip* newequip = new (nothrow) CEquip;
if(newequip==NULL)
{
Log(MSG_WARNING, "\nError allocing memory: equip" );
fclose(fh);
return false;
}
newequip->id = GetUIntValue(",", &line);
newequip->equiptype = GetUIntValue(",");
newequip->type = GetUIntValue(",");
newequip->price = GetUIntValue(",");
newequip->pricerate = GetUIntValue(",");
newequip->weight = GetUIntValue(",");
newequip->quality = GetUIntValue(",");
newequip->level = GetUIntValue(",");
newequip->material = GetUIntValue(",");
char* occupation = GetStrValue(",");
char* condition1 = GetStrValue(",");
char* condition2 = GetStrValue(",");
char* stat1 = GetStrValue(",");
char* stat2 = GetStrValue(",");
newequip->defense = GetUIntValue(",");
newequip->magicresistence = GetUIntValue(",");
newequip->attackdistance = GetUIntValue(",");
if(newequip->equiptype==SHOE)
{
newequip->movespeed = newequip->attackdistance;
}
else
{
newequip->movespeed = 0;
}
newequip->attackpower = GetUIntValue(",");
newequip->attackspeed =GetUIntValue(",");
newequip->itemgrade = GetUIntValue(",");
for(int i=0;i<3;i++)
newequip->occupation[i] = GetUIntValue("|", i==0?occupation:NULL);
for(int i=0;i<3;i++)
newequip->condition1[i] = GetUIntValue("|", i==0?condition1:NULL);
for(int i=0;i<3;i++)
newequip->condition2[i] = GetUIntValue("|", i==0?condition2:NULL);
for(int i=0;i<2;i++)
newequip->stat1[i] = GetUIntValue("|", i==0?stat1:NULL);
for(int i=0;i<2;i++)
newequip->stat2[i] = GetUIntValue("|", i==0?stat2:NULL);
EquipList[newequip->equiptype].Data.push_back( newequip );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -