Пример #1
0
SceneEntity::SceneEntity()
{
    modelName = QString();
    id = 0;
    netviewId = 0;
    pos=UVector(0,0,0);
    rot=UQuaternion(0,0,0,0);
    sceneName = QString();
}
Пример #2
0
void sendEntitiesList(Player *player)
{
    levelLoadMutex.lock(); // Protect player->inGame
    if (player->inGame == 0) // Not yet in game, send player's ponies list (Characters scene)
    {
        levelLoadMutex.unlock();
        sendPonies(player);
        return;
    }
    else if (player->inGame > 1) // Not supposed to happen, let's do it anyway
    {
        //levelLoadMutex.unlock();
        win.logMessage(QString("UDP: Entities list already sent to ")+QString().setNum(player->pony.netviewId)
                       +", resending anyway");
        //return;
    }
    else // Loading finished, sending entities list
    win.logMessage(QString("UDP: Sending entities list to ")+QString().setNum(player->pony.netviewId));
    Scene* scene = findScene(player->pony.sceneName); // Spawn all the players on the client
    for (int i=0; i<scene->players.size(); i++)
        sendNetviewInstantiate(scene->players[i], player);

    /// SEND DONUT STEEL (in front of the mirror)
    if (scene->name == "RaritysBoutique")
    {
        win.logMessage(QString("UDP: Sending Donut Steel to ")+QString().setNum(player->pony.netviewId));
        sendNetviewInstantiate(player,"PlayerBase",0,0,UVector(24.7333,-1.16802,-51.7106), UQuaternion(0,-0.25,0,1));
    }

    player->inGame = 2;
    levelLoadMutex.unlock();

    // Send stats of the client's pony
    sendSetMaxStatRPC(player, 0, 100);
    sendSetStatRPC(player, 0, 100);
    sendSetMaxStatRPC(player, 1, 100);
    sendSetStatRPC(player, 1, 100);
}
Пример #3
0
Quest::Quest(QString path, Player *Owner)
{
    QFile file(path);
    if (!file.open(QFile::ReadOnly))
    {
        app.logError(QObject::tr("Error reading quest DB"));
        app.stopGameServer();
        throw std::exception();
    }

    QList<QString> lines = QString(file.readAll().replace('\r',"")).split('\n');

    owner = Owner;
    commands = new QList<QList<QString> >;
    name = new QString();
    descr = new QString();
    npc = new Pony(nullptr); // A NPC doesn't have an owner player !
    npc->id = 0;
    npc->netviewId = 0;
    id = 0;
    state = 0;
    eip = 0;

    // Parse the metadata, add everything else as quest commands
    for (int i=0; i<lines.size(); i++)
    {
        QList<QString> line = lines[i].split(" ", QString::SkipEmptyParts);
        if (!line.size() || lines[i][0]=='#')
            continue;
        if (line[0] == "name")
            if (line.size()>=2)
                npc->name = lines[i].mid(line[0].size()+1);
            else throw QString(QObject::tr("Quest::Quest: Error reading name, quest %1").arg(path));
        else if (line[0] == "scene")
            if (line.size()>=2)
                npc->sceneName = lines[i].mid(line[0].size()+1).toLower();
            else throw QString(QObject::tr("Quest::Quest: Error reading scene, quest %1").arg(path));
        else if (line[0] == "ponyData")
        {
            if (line.size()==2)
            {
                QByteArray ponyData = QByteArray::fromBase64(line[1].toLatin1());
                // Read the ponyData
                unsigned strlen;
                unsigned lensize=0;
                {
                    unsigned char num3; int num=0, num2=0;
                    do {
                        num3 = ponyData[lensize]; lensize++;
                        num |= (num3 & 0x7f) << num2;
                        num2 += 7;
                    } while ((num3 & 0x80) != 0);
                    strlen = (uint) num;
                }
                int nameSize = strlen + lensize;
                int ponyDataSize = ponyData.size() - nameSize;
                if (ponyDataSize == 43)
                {
                    app.logMessage(QString("Quest::Quest: PonyData of quest %1 is in old format, converting")
                                   .arg(path));
                    ponyData += uint32ToData(0); // Member ID
                    ponyData.insert(nameSize+17+3,ponyData.mid(nameSize+17,3)); // Hair color 2 (copy of color 1)
                }
                npc->ponyData = ponyData;
            }
            else throw QString(QObject::tr("Quest::Quest: Error reading ponyData, quest %1").arg(path));
        }
        else if (line[0] == "pos")
            if (line.size()==4)
            {
                bool ok1, ok2, ok3;
                npc->pos = UVector(line[1].toFloat(&ok1), line[2].toFloat(&ok2),
                                    line[3].toFloat(&ok3));
                if (!(ok1 && ok2 && ok3))
                    throw QString(QObject::tr("Quest::Quest: Error reading pos, quest %1").arg(path));
            }
            else throw QString(QObject::tr("Quest::Quest: Error reading pos, quest %1").arg(path));
        else if (line[0] == "rot")
            if (line.size()==5)
            {
                bool ok1, ok2, ok3, ok4;
                npc->rot = UQuaternion(line[1].toFloat(&ok1), line[2].toFloat(&ok2),
                                        line[3].toFloat(&ok3), line[4].toFloat(&ok4));
                if (!(ok1 && ok2 && ok3 && ok4))
                    throw QString(QObject::tr("Quest::Quest: Error reading rot, quest %1").arg(path));
            }
            else throw QString(QObject::tr("Quest::Quest: Error reading rot, quest %1").arg(path));
        else if (line[0] == "wear")
        {
            for (int i=1; i<line.size(); i++)
            {
                bool ok;
                int itemId = line[i].toInt(&ok);
                if (!ok)
                    throw QString(QObject::tr("Quest::Quest: Error reading wear, quest %1").arg(path));
                WearableItem item;
                item.id = itemId;
                item.index = wearablePositionsToSlot(wearablePositionsMap[itemId]);
                npc->worn << item;
            }
        }
        else if (line[0] == "shop")
        {
            for (int i=1; i<line.size(); i++)
            {
                bool ok;
                int itemId = line[i].toInt(&ok);
                if (!ok)
                    throw QString(QObject::tr("Quest::Quest: Error reading shop, quest %1").arg(path));
                InventoryItem item;
                item.id = itemId;
                item.index = i-1;
                item.amount = (quint32)-1;
                npc->inv << item;
            }
        }
        else if (line[0] == "questId")
            if (line.size()==2)
            {
                id = line[1].toInt();

                SceneEntity::lastIdMutex.lock();
                npc->id = 0;
                npc->netviewId = id;
                SceneEntity::lastIdMutex.unlock();
            }
            else throw QString(QObject::tr("Quest::Quest: Error reading questId, quest %1").arg(path));
        else if (line[0] == "questName")
            if (line.size()>=2)
                *name = lines[i].mid(line[0].size()+1);
            else throw QString(QObject::tr("Quest::Quest: Error reading questName, quest %1").arg(path));
        else if (line[0] == "questDescr")
            if (line.size()>=2)
                *descr = lines[i].mid(line[0].size()+1);
            else throw QString(QObject::tr("Quest::Quest: Error reading questDescr, quest %1").arg(path));
        else
            commands->append(line);
    }
}
Пример #4
0
Quest::Quest(QString path, Player *Owner)
{
    QFile file(path);
    if (!file.open(QFile::ReadOnly))
    {
        win.logMessage("Error reading quest DB.", sysTag);
        win.stopServer();
        throw std::exception();
    }

    QList<QString> lines = QString(file.readAll().replace('\r',"")).split('\n');

    owner = Owner;
    commands = new QList<QList<QString> >;
    name = new QString();
    descr = new QString();
    npc = new Pony(nullptr); // A NPC doesn't have an owner player !
    npc->id = 0;
    npc->netviewId = 0;
    id = 0;
    state = 0;
    eip = 0;

    try
    {
        // Parse the metadata, add everything else as quest commands
        for (int i=0; i<lines.size(); i++)
        {
            QList<QString> line = lines[i].split(" ", QString::SkipEmptyParts);
            if (!line.size() || lines[i][0]=='#')
                continue;
            if (line[0] == "name")
                if (line.size()>=2)
                    npc->name = lines[i].mid(line[0].size()+1);
                else throw QString("Quest::Quest: Error reading name, quest "+path);
            else if (line[0] == "scene")
                if (line.size()>=2)
                    npc->sceneName = lines[i].mid(line[0].size()+1).toLower();
                else throw QString("Quest::Quest: Error reading scene, quest "+path);
            else if (line[0] == "ponyData")
                if (line.size()==2)
                    npc->ponyData = QByteArray::fromBase64(line[1].toLatin1());
                else throw QString("Quest::Quest: Error reading ponyData, quest "+path);
            else if (line[0] == "pos")
                if (line.size()==4)
                {
                    bool ok1, ok2, ok3;
                    npc->pos = UVector(line[1].toFloat(&ok1), line[2].toFloat(&ok2),
                                        line[3].toFloat(&ok3));
                    if (!(ok1 && ok2 && ok3))
                        throw QString("Quest::Quest: Error reading pos, quest "+path);
                }
                else throw QString("Quest::Quest: Error reading pos, quest "+path);
            else if (line[0] == "rot")
                if (line.size()==5)
                {
                    bool ok1, ok2, ok3, ok4;
                    npc->rot = UQuaternion(line[1].toFloat(&ok1), line[2].toFloat(&ok2),
                                            line[3].toFloat(&ok3), line[4].toFloat(&ok4));
                    if (!(ok1 && ok2 && ok3 && ok4))
                        throw QString("Quest::Quest: Error reading rot, quest "+path);
                }
                else throw QString("Quest::Quest: Error reading rot, quest "+path);
            else if (line[0] == "wear")
            {
                for (int i=1; i<line.size(); i++)
                {
                    bool ok;
                    int itemId = line[i].toInt(&ok);
                    if (!ok)
                        throw QString("Quest::Quest: Error reading wear, quest "+path);
                    WearableItem item;
                    item.id = itemId;
                    item.index = wearablePositionsToSlot(win.wearablePositionsMap[itemId]);
                    npc->worn << item;
                }
            }
            else if (line[0] == "questId")
                if (line.size()==2)
                {
                    id = line[1].toInt();

                    win.lastIdMutex.lock();
                    npc->id = 0;
                    npc->netviewId = id;
                    win.lastIdMutex.unlock();
                }
                else throw QString("Quest::Quest: Error reading questId, quest "+path);
            else if (line[0] == "questName")
                if (line.size()>=2)
                    *name = lines[i].mid(line[0].size()+1);
                else throw QString("Quest::Quest: Error reading questName, quest "+path);
            else if (line[0] == "questDescr")
                if (line.size()>=2)
                    *descr = lines[i].mid(line[0].size()+1);
                else throw QString("Quest::Quest: Error reading questDescr, quest "+path);
            else
                commands->append(line);
        }
    }
    catch (QString& error)
    {
        win.logMessage(error, sysTag);
        win.stopServer();
    }
}