Example #1
0
bool Door::click(Object *triggerer) {
	_lastUsedBy = triggerer;

	// If the door is closed, try to open it
	if (!isOpen())
		return open(triggerer);

	// If the door is open and has a click or used script, call that
	if (hasScript(kScriptClick))
		return runScript(kScriptClick, this, triggerer);
	if (hasScript(kScriptUsed))
		return runScript(kScriptUsed , this, triggerer);

	evaluateLink();
	if (_link) {
		float x, y, z;
		_link->getPosition(x, y, z);

		_module->movePC(_link->getArea(), x, y, z);
		return true;
	}

	// If the door is open and has no script, close it
	return close(triggerer);
}
Example #2
0
bool Creature::click(Object *triggerer) {
	// Try the onDialog script first
	if (hasScript(kScriptDialogue))
		return runScript(kScriptDialogue, this, triggerer);

	// Next, look we have a generic onClick script
	if (hasScript(kScriptClick))
		return runScript(kScriptClick, this, triggerer);

	return false;
}
Example #3
0
bool Creature::click(Object *triggerer) {
	// Try the onDialog script first
	if (hasScript(kScriptDialogue))
		return runScript(kScriptDialogue, this, triggerer);

	// Next, look we have a generic onClick script
	if (hasScript(kScriptClick))
		return runScript(kScriptClick, this, triggerer);

	// Lastly, try to start a conversation directly
	return beginConversation(triggerer);
}
Example #4
0
bool Placeable::click(Object *triggerer) {
	// If the door has a used script, call that
	if (hasScript(kScriptUsed))
		return runScript(kScriptUsed, this, triggerer);

	return true;
}
Example #5
0
QScriptValue ScriptManager::getScriptObject(QString name, ScriptComponent* component) {
    if(!hasScript(name)) {
        return QScriptValue::UndefinedValue;
    }

    // save the global object and set an empty one
    QScriptValue global(mScriptEngine->globalObject());
    mScriptEngine->setGlobalObject(mScriptEngine->newObject());

    // write script members/functions as properties into global object
    // like this we have the same engine linked, so the
    executeScript(name);

    // extract the global object and reset the original one
    QScriptValue obj(mScriptEngine->globalObject());
    mScriptEngine->setGlobalObject(global);

    // Set the object's component member.
    QScriptValue componentObject = mScriptEngine->newQObject(component);
    QScriptValue prop = obj.property("component");
    if(prop.isValid()) {
        Logger::get().warning("Overriding member \"component\" in script \"" + name + "\" with ScriptComponent \"" + component->getName() + "\".");
        Logger::get().info(" > Previous Value: " + prop.toString());
        Logger::get().info(" > Previous  Type: " + QString(prop.toVariant().typeName()) );
    }
    obj.setProperty("component", componentObject);

    return obj;
}
Example #6
0
void ScriptNode::update(Field *eventInField) {

#ifdef SUPPORT_JSAI

	if (hasScript()) {

		JScript *jscript = getJavaNode();

		jscript->setValue(this);

		Event event(eventInField);
		jscript->processEvent(&event);

		jscript->getValue(this);

		int nEventOut = getNEventOut();
		for (int n=0; n<nEventOut; n++) {
			Field *field = getEventOut(n);
			sendEvent(field);
		}
	}

#endif

}
Example #7
0
bool ScriptManager::executeScript(QString name) {
    if(name == "" || !hasScript(name)) {
        Logger::get().error("Cannot execute script \"" + name + "\": script not found.");
        return false;
    }

    return _evaluate(mScripts[name]);
}
Example #8
0
bool Door::click(Object *triggerer) {
	_lastUsedBy = triggerer;

	// If the door is closed, try to open it
	if (!isOpen())
		return open(triggerer);

	// If the door is open and has a click or used script, call that
	if (hasScript(kScriptClick))
		return runScript(kScriptClick, this, triggerer);
	if (hasScript(kScriptUsed))
		return runScript(kScriptUsed , this, triggerer);

	if (!_linkedTo.empty())
		_module->movePC(_linkedToModule, _linkedTo);

	// If the door is open and has no script, close it
	return close(triggerer);
}
Example #9
0
void ScriptNode::updateFields() {

#ifdef SUPPORT_JSAI
	if (hasScript()) {
		JScript *jscript = getJavaNode();
		jscript->setValue(this);
		jscript->processEvent(NULL);
		jscript->getValue(this);
	}
#endif

}
Example #10
0
/*!
	Adds an event handler to this object
*/
void cUObject::addScript( cPythonScript* event, bool append )
{
	if ( isScriptChainFrozen() )
	{
		return;
	}

	if ( hasScript( event->name() ) )
	{
		return;
	}

	// Reallocate the ScriptChain
	if ( scriptChain )
	{
		size_t count = reinterpret_cast<size_t>( *scriptChain );

		cPythonScript** newScriptChain = new cPythonScript* [count + 2];
		if ( append || count == 0 )
		{
			memcpy( newScriptChain, scriptChain, ( count + 1 ) * sizeof( cPythonScript * ) );
			newScriptChain[count + 1] = event;
		}
		else
		{
			// make room for the 1st event
			memcpy( &newScriptChain[2], &scriptChain[1], ( count ) * sizeof( cPythonScript * ) );
			newScriptChain[1] = event;
		}
		newScriptChain[0] = reinterpret_cast<cPythonScript*>( count + 1 );

		delete[] scriptChain;
		scriptChain = newScriptChain;
	}
	else
	{
		scriptChain = new cPythonScript * [2];
		scriptChain[0] = reinterpret_cast<cPythonScript*>( 1 );
		scriptChain[1] = event;
	}

	changed_ = true;

	if ( event->canHandleEvent( EVENT_ATTACH ) )
	{
		PyObject* args = Py_BuildValue( "(N)", getPyObject() );
		event->callEvent( EVENT_ATTACH, args );
		Py_DECREF( args );
	}
}
Example #11
0
void ScriptNode::uninitialize() 
{
	setInitialized(false);

#ifdef SUPPORT_JSAI

	if (hasScript()) {
		JScript *jscript = getJavaNode();
		jscript->setValue(this);
		jscript->shutdown();
		jscript->getValue(this);
	}

#endif
}
Example #12
0
TRIGGER( equip )(obj equippedon)
{
  if(isNPC(equippedon))
  {
    return(0x01);
  }
  if(getCompileFlag(0x01))
  {
    if(hasScript(equippedon, "orderguild"))
    {
      return(0x01);
    }
  }
  else
  {
    if(Q4SN(equippedon) >= 0x05)
    {
      return(0x01);
    }
  }
  Q4HV();
  return(0x00);
}
Example #13
0
bool ScriptManager::addScript(QString script, QString name) {
    if(name == "") {
        Logger::get().error("Cannot add script without name.");
        return false;
    }

    if(hasScript(name)) {
        Logger::get().error("Cannot add script \"" + name + "\": a script with this name already exists.");
        return false;
    }

    // check the syntax
    QScriptSyntaxCheckResult syntax = mScriptEngine->checkSyntax(script);
    if(syntax.state() != QScriptSyntaxCheckResult::Valid) {
        Logger::get().error("Syntax error in script \"" + name + "\" at line "
                            + Utils::toString(syntax.errorLineNumber()) + " column "
                            + Utils::toString(syntax.errorColumnNumber()) + ":");
        Logger::get().error("    " +  syntax.errorMessage());
    } else {
        Logger::get().debug("Adding script \"" + name + "\".");
        mScripts[name] = QScriptProgram(script, name);
    }
    return true;
}
Example #14
0
FUNCTION int Q4LV(obj user, obj usedon)
{
  int Q5NC = 0x00;
  if(Q50G(usedon))
  {
    int Q4NC;
    int defenseBonus;
    loc Q4VS = loc( getLocation(user) );
    loc there = loc( getLocation(usedon) );
    faceHere(user, getDirectionInternal(Q4VS, there));
    if(!hasScript(usedon, "remprtct"))
    {
      doMobAnimation(usedon, 0x375A, 0x09, 0x14, 0x00, 0x00);
      sfx(there, 0x01ED, 0x00);
      if(hasObjVar(this, "magicItemModifier"))
      {
        int Q52W = getObjVar(this, "magicItemModifier");
        Q4NC = 0x06 * Q52W;
        defenseBonus = 0x07;
      }
      else
      {
        defenseBonus = (getSkillLevel(user, 0x19) / 0x0A);
        Q4NC = 0x06 * getSkillLevel(user, 0x19) / 0x05;
      }
      setNaturalAC(usedon, getNaturalAC(usedon) + defenseBonus);
      setObjVar(usedon, "defenseBonus", defenseBonus);
      attachScript(usedon, "remprtct");
      int Q527 = Q41J(user, usedon, 0x00, this);
      callback(usedon, Q4NC, 0x13);
      Q5NC = 0x01;
    }
  }
  Q5UQ(this);
  return(Q5NC);
}