Ejemplo n.º 1
0
void BeingHandler::handleBeingEnterMessage(Net::MessageIn &msg)
{
    int type = msg.readInt8();
    int id = msg.readInt16();
    Being::Action action = (Being::Action)msg.readInt8();
    int px = msg.readInt16();
    int py = msg.readInt16();
    BeingDirection direction = (BeingDirection)msg.readInt8();
    Being *being;

    if (!Game::instance()->getCurrentMap()->containsPixel(px, py))
    {
        logger->log("Warning: Received GPMSG_BEING_ENTER for being id %i "
                    "with position outside the map boundaries "
                    "(x = %i, y = %i)", id, px, py);
        return;
    }

    switch (type)
    {
        case OBJECT_CHARACTER:
        {
            std::string name = msg.readString();
            if (player_node->getName() == name)
            {
                being = player_node;
                being->setId(id);
            }
            else
            {
                being = actorSpriteManager->createBeing(id,
                                                    ActorSprite::PLAYER, 0);
                being->setName(name);
            }
            int hs = msg.readInt8(), hc = msg.readInt8();
            being->setSprite(SPRITE_HAIR, hs * -1, ColorDB::get(hc));
            being->setGender(msg.readInt8() == GENDER_MALE ?
                             GENDER_MALE : GENDER_FEMALE);
            handleLooks(being, msg);
        } break;

        case OBJECT_MONSTER:
        case OBJECT_NPC:
        {
            int subtype = msg.readInt16();
            being = actorSpriteManager->createBeing(id, type == OBJECT_MONSTER
                           ? ActorSprite::MONSTER : ActorSprite::NPC, subtype);
            std::string name = msg.readString();
            if (name.length() > 0) being->setName(name);
        } break;

        default:
            return;
    }

    being->setPosition(px, py);
    being->setDestination(px, py);
    being->setDirection(direction);
    being->setAction(action);
}
Ejemplo n.º 2
0
void BeingHandler::handleBeingDirChangeMessage(Net::MessageIn &msg)
{
    Being *being = actorSpriteManager->findBeing(msg.readInt16());
    if (!being)
        return;
    int data = msg.readInt8();

    // The direction for the player's character is handled on client side.
    if (being != player_node)
        being->setDirection((BeingDirection) data);
}
Ejemplo n.º 3
0
void BeingHandler::handleBeingAttackMessage(Net::MessageIn &msg)
{
    Being *being = actorSpriteManager->findBeing(msg.readInt16());
    const BeingDirection direction = (BeingDirection) msg.readInt8();
    const int attackType = msg.readInt8();

    if (!being)
        return;

    being->setDirection(direction);

    being->setAction(Being::ATTACK, attackType);
}