Пример #1
0
void Actor::onThinkDefense(uint32_t interval)
{
  resetTicks = true;
  defenseTicks += interval;

  for(SpellList::const_iterator it = cType.spellDefenseList().begin(), spell_defense_list_end = cType.spellDefenseList().end(); it != spell_defense_list_end; ++it){
    if(it->speed > defenseTicks){
      resetTicks = false;
      continue;
    }

    if(defenseTicks % it->speed >= interval){
      //already used this spell for this round
      continue;
    }

    if((it->chance >= (uint32_t)random_range(1, 100))){
      g_game.onActorCastSpell(this, NULL, (*it).name);
    }
  }

  if(!isSummon() && (int32_t)summons.size() < cType.maxSummons()){
    for(SummonList::const_iterator it = cType.summonList().begin(), summon_list_end = cType.summonList().end(); it != summon_list_end; ++it){
      if(it->speed > defenseTicks){
        resetTicks = false;
        continue;
      }

      if((int32_t)summons.size() >= cType.maxSummons()){
        continue;
      }

      if(defenseTicks % it->speed >= interval){
        //already used this spell for this round
        continue;
      }

      if((it->chance >= (uint32_t)random_range(1, 100))){
        Actor* summon = Actor::create(it->name);
        if(summon){
          const Position& summonPos = getPosition();

          addSummon(summon);
          if(g_game.placeCreature(summon, summonPos)){
            g_game.addMagicEffect(summon->getPosition(), MAGIC_EFFECT_BLUE_BUBBLE);
            g_game.addMagicEffect(getPosition(), MAGIC_EFFECT_BLUE_BUBBLE);
          }
          else{
            removeSummon(summon);
          }
        }
      }
    }
  }

  if(resetTicks){
    defenseTicks = 0;
  }
}
Пример #2
0
void Monster::onThinkDefense(uint32_t interval)
{
	resetTicks = true;
	defenseTicks += interval;
	for(SpellList::iterator it = mType->spellDefenseList.begin(); it != mType->spellDefenseList.end(); ++it)
	{
		if(it->speed > defenseTicks)
		{
			if(resetTicks)
				resetTicks = false;

			continue;
		}

		if(defenseTicks % it->speed >= interval) //already used this spell for this round
			continue;

		if((it->chance >= (uint32_t)random_range(1, 100)))
		{
			minCombatValue = it->minCombatValue;
			maxCombatValue = it->maxCombatValue;
			it->spell->castSpell(this, this);
		}
	}

	if(!isSummon())
	{
		if(mType->maxSummons < 0 || (int32_t)summons.size() < mType->maxSummons)
		{
			for(SummonList::iterator it = mType->summonList.begin(); it != mType->summonList.end(); ++it)
			{
				if((int32_t)summons.size() >= mType->maxSummons)
					break;

				if(it->interval > defenseTicks)
				{
					if(resetTicks)
						resetTicks = false;

					continue;
				}

				if(defenseTicks % it->interval >= interval)
					continue;

				uint32_t typeCount = 0;
				for(CreatureList::iterator cit = summons.begin(); cit != summons.end(); ++cit)
				{
					if(!(*cit)->isRemoved() && (*cit)->getMonster() &&
						(*cit)->getMonster()->getName() == it->name)
						typeCount++;
				}

				if(typeCount >= it->amount)
					continue;

				if((it->chance >= (uint32_t)random_range(1, 100)))
				{
					if(Monster* summon = Monster::createMonster(it->name))
					{
						addSummon(summon);
						if(g_game.placeCreature(summon, getPosition()))
							g_game.addMagicEffect(getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
						else
							removeSummon(summon);
					}
				}
			}
		}
	}

	if(resetTicks)
		defenseTicks = 0;
}
Пример #3
0
void Monster::onThinkDefense(uint32_t interval)
{
	resetTicks = true;
	defenseTicks += interval;

	for(SpellList::iterator it = mType->spellDefenseList.begin(); it != mType->spellDefenseList.end(); ++it)
	{
		if(it->speed > defenseTicks)
		{
			resetTicks = false;
			continue;
		}

		if(defenseTicks % it->speed >= interval)
		{
			//already used this spell for this round
			continue;
		}

		if((it->chance >= (uint32_t)random_range(1, 100)))
		{
			minCombatValue = it->minCombatValue;
			maxCombatValue = it->maxCombatValue;
			it->spell->castSpell(this, this);
		}
	}

	if(!isSummon() && (int32_t)summons.size() < mType->maxSummons)
	{
		for(SummonList::iterator it = mType->summonList.begin(); it != mType->summonList.end(); ++it)
		{
			if(it->speed > defenseTicks)
			{
				resetTicks = false;
				continue;
			}

			if((int32_t)summons.size() >= mType->maxSummons)
				continue;

			if(defenseTicks % it->speed >= interval)
			{
				//already used this spell for this round
				continue;
			}

			if((it->chance >= (uint32_t)random_range(1, 100)))
			{
				Monster* summon = Monster::createMonster(it->name);
				if(summon)
				{
					const Position& summonPos = getPosition();

					addSummon(summon);
					if(!g_game.placeCreature(summon, summonPos))
						removeSummon(summon);
					else
					{
						g_game.addMagicEffect(getPosition(), NM_ME_MAGIC_ENERGY);
						g_game.addMagicEffect(summon->getPosition(), NM_ME_TELEPORT);
					}
				}
			}
		}
	}

	if(resetTicks)
		defenseTicks = 0;
}