Example #1
0
void Creature::removeCondition(ConditionType_t type, ConditionId_t id, bool force/* = false*/)
{
	ConditionList::iterator it = conditions.begin();
	while (it != conditions.end()) {
		Condition* condition = *it;
		if (condition->getType() != type || condition->getId() != id) {
			++it;
			continue;
		}

		if (!force && condition->getType() == CONDITION_PARALYZE) {
			int64_t walkDelay = getWalkDelay();
			if (walkDelay > 0) {
				g_scheduler.addEvent(createSchedulerTask(walkDelay, boost::bind(&Game::forceRemoveCondition, &g_game, getID(), type)));
				return;
			}
		}

		it = conditions.erase(it);

		condition->endCondition(this, CONDITIONEND_ABORT);
		delete condition;

		onEndCondition(type);
	}
}
Example #2
0
void Creature::removeCondition(ConditionType_t type, bool force/* = false*/)
{
	auto it = conditions.begin(), end = conditions.end();
	while (it != end) {
		Condition* condition = *it;
		if (condition->getType() != type) {
			++it;
			continue;
		}

		if (!force && type == CONDITION_PARALYZE) {
			int64_t walkDelay = getWalkDelay();
			if (walkDelay > 0) {
				g_scheduler.addEvent(createSchedulerTask(walkDelay, std::bind(&Game::forceRemoveCondition, &g_game, getID(), type)));
				return;
			}
		}

		it = conditions.erase(it);

		condition->endCondition(this);
		delete condition;

		onEndCondition(type);
	}
}
Example #3
0
void Creature::removeCondition(Condition* condition)
{
	ConditionList::iterator it = std::find(conditions.begin(), conditions.end(), condition);
	if(it != conditions.end())
	{
		Condition* condition = *it;
		it = conditions.erase(it);

		condition->endCondition(this, CONDITIONEND_ABORT);
		onEndCondition(condition->getType());
		delete condition;
	}
}
Example #4
0
void SVGSMILElement::disconnectSyncBaseConditions() {
  if (!m_syncBaseConditionsConnected)
    return;
  m_syncBaseConditionsConnected = false;
  for (unsigned n = 0; n < m_conditions.size(); ++n) {
    Condition* condition = m_conditions[n].get();
    if (condition->getType() == Condition::Syncbase) {
      if (condition->syncBase())
        condition->syncBase()->removeSyncBaseDependent(this);
      condition->setSyncBase(0);
    }
  }
}
Example #5
0
void Creature::executeConditions(uint32_t interval)
{
	for(ConditionList::iterator it = conditions.begin(); it != conditions.end(); )
	{
		if((*it)->executeCondition(this, interval))
		{
			++it;
			continue;
		}

		Condition* condition = *it;
		it = conditions.erase(it);

		condition->endCondition(this, CONDITIONEND_TICKS);
		onEndCondition(condition->getType());
		delete condition;
	}
}
Example #6
0
void Creature::removeConditions(ConditionEnd_t reason, bool onlyPersistent/* = true*/)
{
	for(ConditionList::iterator it = conditions.begin(); it != conditions.end(); )
	{
		if(onlyPersistent && !(*it)->isPersistent())
		{
			++it;
			continue;
		}

		Condition* condition = *it;
		it = conditions.erase(it);

		condition->endCondition(this, reason);
		onEndCondition(condition->getType());
		delete condition;
	}
}
Example #7
0
void Creature::removeCondition(ConditionType_t type, ConditionId_t id)
{
	for(ConditionList::iterator it = conditions.begin(); it != conditions.end(); )
	{
		if((*it)->getType() != type || (*it)->getId() != id)
		{
			++it;
			continue;
		}

		Condition* condition = *it;
		it = conditions.erase(it);

		condition->endCondition(this, CONDITIONEND_ABORT);
		onEndCondition(condition->getType());
		delete condition;
	}
}
Example #8
0
void Creature::executeConditions(uint32_t interval)
{
	for (ConditionList::iterator it = conditions.begin(); it != conditions.end();) {
		if (!(*it)->executeCondition(this, interval)) {
			Condition* condition = *it;

			ConditionType_t type = condition->getType();

			it = conditions.erase(it);

			condition->endCondition(this, CONDITIONEND_TICKS);
			delete condition;

			onEndCondition(type);
		} else {
			++it;
		}
	}
}
Example #9
0
void Creature::executeConditions(uint32_t interval)
{
	auto it = conditions.begin(), end = conditions.end();
	while (it != end) {
		Condition* condition = *it;
		if (!condition->executeCondition(this, interval)) {
			ConditionType_t type = condition->getType();

			it = conditions.erase(it);

			condition->endCondition(this);
			delete condition;

			onEndCondition(type);
		} else {
			++it;
		}
	}
}
void SVGSMILElement::connectEventBaseConditions()
{
    disconnectEventBaseConditions();
    for (unsigned n = 0; n < m_conditions.size(); ++n) {
        Condition* condition = m_conditions[n].get();
        if (condition->getType() == Condition::EventBase) {
            ASSERT(!condition->syncBase());
            SVGElement* eventBase = eventBaseFor(*condition);
            if (!eventBase) {
                if (!condition->baseID().isEmpty() && !document().accessSVGExtensions().isElementPendingResource(this, AtomicString(condition->baseID())))
                    document().accessSVGExtensions().addPendingResource(AtomicString(condition->baseID()), this);
                continue;
            }
            ASSERT(!condition->eventListener());
            condition->setEventListener(ConditionEventListener::create(this, condition));
            eventBase->addEventListener(AtomicString(condition->name()), condition->eventListener(), false);
            addReferenceTo(eventBase);
        }
    }
}
void SVGSMILElement::connectSyncBaseConditions()
{
    if (m_syncBaseConditionsConnected)
        disconnectSyncBaseConditions();
    m_syncBaseConditionsConnected = true;
    for (unsigned n = 0; n < m_conditions.size(); ++n) {
        Condition* condition = m_conditions[n].get();
        if (condition->getType() == Condition::Syncbase) {
            ASSERT(!condition->baseID().isEmpty());
            Element* element = treeScope().getElementById(AtomicString(condition->baseID()));
            if (!element || !isSVGSMILElement(*element)) {
                condition->setSyncBase(0);
                continue;
            }
            SVGSMILElement* svgSMILElement = toSVGSMILElement(element);
            condition->setSyncBase(svgSMILElement);
            svgSMILElement->addSyncBaseDependent(this);
        }
    }
}
void SVGSMILElement::disconnectEventBaseConditions()
{
    for (unsigned n = 0; n < m_conditions.size(); ++n) {
        Condition* condition = m_conditions[n].get();
        if (condition->getType() == Condition::EventBase) {
            ASSERT(!condition->syncBase());
            if (!condition->eventListener())
                continue;
            // Note: It's a memory optimization to try to remove our condition
            // event listener, but it's not guaranteed to work, since we have
            // no guarantee that eventBaseFor() will be able to find our condition's
            // original eventBase. So, we also have to disconnect ourselves from
            // our condition event listener, in case it later fires.
            SVGElement* eventBase = eventBaseFor(*condition);
            if (eventBase)
                eventBase->removeEventListener(AtomicString(condition->name()), condition->eventListener(), false);
            condition->eventListener()->disconnectAnimation();
            condition->setEventListener(nullptr);
        }
    }
}
Example #13
0
void Creature::onWalk(Direction& dir)
{
	int32_t drunk = -1;
	if(!isSuppress(CONDITION_DRUNK))
	{
		Condition* condition = NULL;
		for(ConditionList::const_iterator it = conditions.begin(); it != conditions.end(); ++it)
		{
			if(!(condition = *it) || condition->getType() != CONDITION_DRUNK)
				continue;

			int32_t subId = condition->getSubId();
			if((!condition->getEndTime() || condition->getEndTime() >= OTSYS_TIME()) && subId > drunk)
				drunk = subId;
		}
	}

	if(drunk < 0)
		return;

	drunk += 25;
	int32_t r = random_range(1, 100);
	if(r > drunk)
		return;

	int32_t tmp = (drunk / 5);
	if(r <= tmp)
		dir = NORTH;
	else if(r <= (tmp * 2))
		dir = WEST;
	else if(r <= (tmp * 3))
		dir = SOUTH;
	else if(r <= (tmp * 4))
		dir = EAST;

	g_game.internalCreatureSay(this, MSG_SPEAK_MONSTER_SAY, "Hicks!", isGhost());
}
Example #14
0
void Rule::Print()
{
    cout << "Content of rule \"" << name << " - " << type << "\"" << endl;
    cout << "Conditions (" << conds.size() << ") :" << endl;
    for (uint i = 0;i < conds.size();i++)
    {
        Condition *c = conds[i];
        if (c->getType() == COND_STD)
        {
            cout << "  * Condition Standard : ";
            for (int j = 0;j < c->get_size();j++)
            {
                cout << "\"" << c->get_input(j)->get_param("name") << "\" ";
            }
            cout << endl;
        }
        else if (c->getType() == COND_SCRIPT)
        {
            cout << "  * Condition Script" << endl;
        }
        else if (c->getType() == COND_START)
        {
            cout << "  * Condition Start" << endl;
        }
        else
        {
            cout << "  * Condition UNKNOWN !" << endl;
        }
    }

    cout << "Actions (" << actions.size() << ") :" << endl;
    for (uint i = 0;i < actions.size();i++)
    {
        Action *a = actions[i];
        if (a->getType() == ACTION_STD)
        {
            cout << "  * Action Standard : ";
            for (int j = 0;j < a->get_size();j++)
            {
                cout << "\"" << a->get_output(j)->get_param("name") << "\" ";
            }
            cout << endl;
        }
        else if (a->getType() == ACTION_MAIL)
        {
            cout << "  * Action Mail" << endl;
        }
        else if (a->getType() == ACTION_SCRIPT)
        {
            cout << "  * Action Script" << endl;
        }
        else if (a->getType() == ACTION_TOUCHSCREEN)
        {
            cout << "  * Action Touchscreen" << endl;
        }
        else
        {
            cout << "  * Action UNKNOWN !" << endl;
        }
    }
    cout << endl;
}