예제 #1
0
파일: actor.cpp 프로젝트: raketjan/lab3
void Actor::drop(string s) {
    cout << name() << " försöker slänga iväg " << s << endl;
    vector<Item *>::iterator it = find(getPossessions().begin(),getPossessions().end(),s);
    if(it != getPossessions().end()) {
        cout << name() << " släng iväg (dock i samma rum) " << s << endl;
        whereAt->getStuff().push_back(*it);
        possessions.erase(it);
    } else {
        cout << "Du har ju ingen " << s << " för fan. Idiot!" << endl;
    }

}
예제 #2
0
파일: actor.cpp 프로젝트: raketjan/lab3
void Actor::examine(string s) {
    cout << name() << " försöker undersöka " << s << endl;
    // Bär jag den själv ?
    vector<Item *>::iterator it1 = find(getPossessions().begin(),getPossessions().end(),s);
    vector<Item *>::iterator it2 = find(whereAt->getStuff().begin(),whereAt->getStuff().end(),s);
    if(it1 != getPossessions().end()) {
        cout << name() << " Jag hade den ! " << s << endl;
        cout << (*it1)->getDescription() << endl;
    } else if (it2 != whereAt->getStuff().end()) {
        cout << name() << " Den fanns här på denna plats" << s << endl;
        cout << (*it2)->getDescription() << endl;


    } else cout << "Du ser inte nån " << s << " här !!!" << endl;
}
예제 #3
0
void CharacterComponent::serialize(Entity &entity, MessageOut &msg)
{
    auto *beingComponent = entity.getComponent<BeingComponent>();

    // general character properties
    msg.writeInt8(getAccountLevel());
    msg.writeInt8(beingComponent->getGender());
    msg.writeInt8(getHairStyle());
    msg.writeInt8(getHairColor());
    msg.writeInt16(getAttributePoints());
    msg.writeInt16(getCorrectionPoints());


    const AttributeMap &attributes = beingComponent->getAttributes();
    std::map<const AttributeInfo *, const Attribute *> attributesToSend;
    for (auto &attributeIt : attributes)
    {
        if (attributeIt.first->persistent)
            attributesToSend.insert(std::make_pair(attributeIt.first,
                                                   &attributeIt.second));
    }
    msg.writeInt16(attributesToSend.size());
    for (auto &attributeIt : attributesToSend)
    {
        msg.writeInt16(attributeIt.first->id);
        msg.writeDouble(attributeIt.second->getBase());
        msg.writeDouble(attributeIt.second->getModifiedAttribute());
    }

    // status effects currently affecting the character
    auto &statusEffects = beingComponent->getStatusEffects();
    msg.writeInt16(statusEffects.size());
    for (auto &statusIt : statusEffects)
    {
        msg.writeInt16(statusIt.first);
        msg.writeInt16(statusIt.second.time);
    }

    // location
    msg.writeInt16(entity.getMap()->getID());
    const Point &pos = entity.getComponent<ActorComponent>()->getPosition();
    msg.writeInt16(pos.x);
    msg.writeInt16(pos.y);

    // kill count
    msg.writeInt16(getKillCountSize());
    for (auto &killCountIt : mKillCount)
    {
        msg.writeInt16(killCountIt.first);
        msg.writeInt32(killCountIt.second);
    }

    // character abilities
    auto &abilities = entity.getComponent<AbilityComponent>()->getAbilities();
    msg.writeInt16(abilities.size());
    for (auto &abilityIt : abilities) {
        msg.writeInt32(abilityIt.first);
    }

    // questlog
    msg.writeInt16(mQuestlog.size());
    for (auto questlogIt : mQuestlog) {
        QuestInfo &quest = questlogIt.second;
        msg.writeInt16(quest.id);
        msg.writeInt8(quest.state);
        msg.writeString(quest.title);
        msg.writeString(quest.description);
    }

    // inventory - must be last because size isn't transmitted
    const Possessions &poss = getPossessions();

    const InventoryData &inventoryData = poss.getInventory();
    for (InventoryData::const_iterator itemIt = inventoryData.begin(),
         itemIt_end = inventoryData.end(); itemIt != itemIt_end; ++itemIt)
    {
        msg.writeInt16(itemIt->first);           // slot id
        msg.writeInt16(itemIt->second.itemId);
        msg.writeInt16(itemIt->second.amount);
        msg.writeInt8(itemIt->second.equipmentSlot);
    }
}
예제 #4
0
void CharacterComponent::deserialize(Entity &entity, MessageIn &msg)
{
    auto *beingComponent = entity.getComponent<BeingComponent>();

    // general character properties
    setAccountLevel(msg.readInt8());
    beingComponent->setGender(ManaServ::getGender(msg.readInt8()));
    setHairStyle(msg.readInt8());
    setHairColor(msg.readInt8());
    setAttributePoints(msg.readInt16());
    setCorrectionPoints(msg.readInt16());

    // character attributes
    unsigned attrSize = msg.readInt16();
    for (unsigned i = 0; i < attrSize; ++i)
    {
        unsigned id = msg.readInt16();
        double base = msg.readDouble();
        auto *attributeInfo = attributeManager->getAttributeInfo(id);
        if (attributeInfo)
            beingComponent->setAttribute(entity, attributeInfo, base);
    }

    // status effects currently affecting the character
    int statusSize = msg.readInt16();

    for (int i = 0; i < statusSize; i++)
    {
        int status = msg.readInt16();
        int time = msg.readInt16();
        beingComponent->applyStatusEffect(status, time);
    }

    // location
    auto *map = MapManager::getMap(msg.readInt16());
    entity.setMap(map);

    Point temporaryPoint;
    temporaryPoint.x = msg.readInt16();
    temporaryPoint.y = msg.readInt16();
    entity.getComponent<ActorComponent>()->setPosition(entity, temporaryPoint);

    // kill count
    int killSize = msg.readInt16();
    for (int i = 0; i < killSize; i++)
    {
        int monsterId = msg.readInt16();
        int kills = msg.readInt32();
        setKillCount(monsterId, kills);
    }

    // character abilities
    int abilitiesSize = msg.readInt16();
    for (int i = 0; i < abilitiesSize; i++)
    {
        const int id = msg.readInt32();
        entity.getComponent<AbilityComponent>()->giveAbility(id);
    }

    // questlog
    int questlogSize = msg.readInt16();
    for (int i = 0; i < questlogSize; ++i) {
        unsigned id = msg.readInt16();
        QuestState state = (QuestState) msg.readInt8();
        std::string title = msg.readString();
        std::string description = msg.readString();

        setQuestlog(id, state, title, description);
    }

    Possessions &poss = getPossessions();

    // Loads inventory - must be last because size isn't transmitted
    InventoryData inventoryData;
    EquipData equipmentData;
    while (msg.getUnreadLength())
    {
        InventoryItem i;
        i.slot          = msg.readInt16();
        i.itemId        = msg.readInt16();
        i.amount        = msg.readInt16();
        bool isEquipped = msg.readInt8() != 0;
        inventoryData.insert(std::make_pair(i.slot, i));
        if (isEquipped)
            equipmentData.insert(i.slot);
    }
    poss.setInventory(inventoryData);
    poss.setEquipment(equipmentData);
}