コード例 #1
0
ファイル: Tasktest.cpp プロジェクト: Arsakes/cyphesis
void Tasktest::test_sequence()
{
    m_task->nextTick(1.5);

    Atlas::Message::Element val;
    m_task->getAttr("foo", val);
    assert(val.isNone());
    m_task->setAttr("foo", 1);
    m_task->getAttr("foo", val);
    assert(val.isInt());

    assert(!m_task->obsolete());

    OpVector res;

    assert(res.empty());

    Atlas::Objects::Operation::Generic c;
    c->setParents(std::list<std::string>(1, "generic"));

    m_task->initTask(c, res);

    Operation op;

    m_task->operation(op, res);

    m_task->irrelevant();

    assert(m_task->obsolete());
}
コード例 #2
0
ファイル: Entity.cpp プロジェクト: cyclefusion/cyphesis
/// \brief Handle a relay operation
void Entity::RelayOperation(const Operation & op, OpVector & res)
{
    if (op->getArgs().empty()) {
        log(ERROR, "Entity::RelayOperation no args.");
        return;
    }
    Operation relayedOp = Atlas::Objects::smart_dynamic_cast<Operation>(
            op->getArgs().front());

    if (!relayedOp.isValid()) {
        log(ERROR,
                "Entity::RelayOperation first arg is not an operation.");
        return;
    }

    if (op->isDefaultSerialno()) {
        log(ERROR, "Entity::RelayOperation no serial number.");
        return;
    }

    //Add a sight of the operation
    Sight sight;
    sight->setArgs1(relayedOp);

    Atlas::Objects::Operation::Generic responseOp;
    responseOp->setType("relay", Atlas::Objects::Operation::RELAY_NO);
    responseOp->setArgs1(sight);
    responseOp->setTo(op->getFrom());
    res.push_back(responseOp);

    //Make sure that the contained op is addressed to the entity
    relayedOp->setTo(getId());
    operation(relayedOp, res);

}
コード例 #3
0
ファイル: ConnectedAdapter.cpp プロジェクト: mpreisler/ember
void ConnectedAdapter::eat(Eris::Entity* entity)
{
	try {
		Atlas::Objects::Entity::Anonymous what;
		what->setId(entity->getId());

		Atlas::Objects::Operation::Generic op;
		op->setType("eat", -1);
		op->setFrom(mAvatar.getEntity()->getId());
		op->setArgs1(what);

		S_LOG_INFO("Eating entity with id " << entity->getId() << ", named " << entity->getName());
		mConnection.send(op);
	} catch (const std::exception& ex) {
		S_LOG_WARNING("Got error on eating entity." << ex);
	}
}
コード例 #4
0
ファイル: EntityEditor.cpp プロジェクト: Laefy/ember
void EntityEditor::getGoalInfo(const std::string& id)
{

	Eris::Account* account = EmberServices::getSingleton().getServerService().getAccount();

	Atlas::Objects::Operation::Generic get;
	std::list<std::string> parents;
	parents.emplace_back("commune");
	get->setParents(parents);
	get->setTo(mEntity.getId());

	//By setting it TO an entity and FROM our avatar we'll make the server deliver it as
	//if it came from the entity itself (the server rewrites the FROM to be of the entity).
	get->setFrom(mWorld.getAvatar()->getEmberEntity().getId());
	//By setting a serial number we tell the server to "relay" the operation. This means that any
	//response operation from the target entity will be sent back to us.
	get->setSerialno(Eris::getNewSerialno());

	Atlas::Message::MapType goalMap;
	goalMap["id"] = id;
	Atlas::Objects::Entity::Anonymous getArg;
	getArg->setAttr("goal_info", goalMap);
	get->setArgs1(getArg);

	Eris::Connection* connection = account->getConnection();

	connection->getResponder()->await(get->getSerialno(), this, &EntityEditor::operationGetGoalInfoResult);
	connection->send(get);
}
コード例 #5
0
ファイル: TaskScripttest.cpp プロジェクト: alriddoch/cyphesis
int main()
{
    int ret = 0;

    Operation op;

    Character chr("3", 3);

    {
        Task ts(chr);

        OpVector res;
        Atlas::Objects::Operation::Generic c;
        c->setParents(std::list<std::string>(1, "generic"));

        // It has no script, so init will fail, and it will be irrelevant
        ts.initTask(c, res);

        assert(ts.obsolete());
    }

    {
        Task ts(chr);

        Script * script1 = new Script;
        Script * script2 = new Script;

        ts.setScript(script1);
        ts.setScript(script2);

        assert(!ts.obsolete());

        OpVector res;
        Atlas::Objects::Operation::Generic c;
        c->setParents(std::list<std::string>(1, "generic"));

        ts.initTask(c, res);

        // It has useless script, so init will fail, and it will be irrelevant
        ts.TickOperation(op, res);

        assert(ts.obsolete());
    }

    {
        Task ts(chr);

        Script * script1 = new TestScript;

        ts.setScript(script1);

        assert(!ts.obsolete());

        OpVector res;
        Atlas::Objects::Operation::Generic c;
        c->setParents(std::list<std::string>(1, "generic"));

        assert(res.empty());

        ts.initTask(c, res);

        // It has useless script, so init will fail, and it will be irrelevant
        ts.TickOperation(op, res);

        assert(!ts.obsolete());
        assert(!res.empty());
    }

    return ret;
}