Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Monster::onThinkDefense(uint32_t interval)
- {
- bool resetTicks = true;
- defenseTicks += interval;
- uint32_t spell_interval;
- for (const spellBlock_t& spellBlock : mType->info.defenseSpells) {
- if (attackedCreature) {
- const Position& pos = getPosition();
- const Position& targetPos = attackedCreature->getPosition();
- if (std::max(std::abs(pos.x - targetPos.x), std::abs(pos.y - targetPos.y)) <= 1) {
- spell_interval = spellBlock.speed;
- } else {
- spell_interval = spellBlock.speed / 2;
- }
- } else {
- spell_interval = spellBlock.speed / 2;
- }
- if(spell_interval > defenseTicks){
- resetTicks = false;
- continue;
- }
- if (defenseTicks % spell_interval >= interval) {
- //already used this spell for this round
- continue;
- }
- if ((spellBlock.chance >= static_cast<uint32_t>(uniform_random(1, 100)))) {
- minCombatValue = spellBlock.minCombatValue;
- maxCombatValue = spellBlock.maxCombatValue;
- spellBlock.spell->castSpell(this, this);
- }
- }
- if (attackedCreature && !isSummon() && summons.size() < mType->info.maxSummons && hasFollowPath) {
- for (const summonBlock_t& summonBlock : mType->info.summons) {
- const Position& pos = getPosition();
- const Position& targetPos = attackedCreature->getPosition();
- if (std::max(std::abs(pos.x - targetPos.x), std::abs(pos.y - targetPos.y)) <= 1) {
- spell_interval = summonBlock.speed;
- } else {
- spell_interval = summonBlock.speed / 2;
- }
- if (spell_interval > defenseTicks) {
- resetTicks = false;
- continue;
- }
- if (summons.size() >= mType->info.maxSummons) {
- continue;
- }
- if (defenseTicks % spell_interval >= interval) {
- //already used this spell for this round
- continue;
- }
- uint32_t summonCount = 0;
- for (Creature* summon : summons) {
- if (summon->getName() == summonBlock.name) {
- ++summonCount;
- }
- }
- if (summonCount >= summonBlock.max) {
- continue;
- }
- if (summonBlock.chance < static_cast<uint32_t>(uniform_random(1, 100))) {
- continue;
- }
- Monster* summon = Monster::createMonster(summonBlock.name);
- if (summon) {
- if (g_game.placeCreature(summon, getPosition(), false, summonBlock.force)) {
- summon->setDropLoot(false);
- summon->setSkillLoss(false);
- summon->setMaster(this);
- g_game.addMagicEffect(getPosition(), CONST_ME_MAGIC_BLUE);
- g_game.addMagicEffect(summon->getPosition(), CONST_ME_TELEPORT);
- } else {
- delete summon;
- }
- }
- }
- }
- if (resetTicks) {
- defenseTicks = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment