peonso

Untitled

Sep 28th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.14 KB | None | 0 0
  1. void Monster::onThinkDefense(uint32_t interval)
  2. {
  3.     bool resetTicks = true;
  4.     defenseTicks += interval;
  5.     uint32_t spell_interval;
  6.  
  7.     for (const spellBlock_t& spellBlock : mType->info.defenseSpells) {
  8.         if (attackedCreature) {
  9.             const Position& pos = getPosition();
  10.             const Position& targetPos = attackedCreature->getPosition();
  11.             if (std::max(std::abs(pos.x - targetPos.x), std::abs(pos.y - targetPos.y)) <= 1) {
  12.                 spell_interval = spellBlock.speed;
  13.             } else {
  14.                 spell_interval = spellBlock.speed / 2;
  15.             }
  16.         } else {
  17.                 spell_interval = spellBlock.speed / 2;
  18.         }
  19.  
  20.         if(spell_interval > defenseTicks){
  21.             resetTicks = false;
  22.             continue;
  23.         }
  24.  
  25.         if (defenseTicks % spell_interval >= interval) {
  26.             //already used this spell for this round
  27.             continue;
  28.         }
  29.  
  30.         if ((spellBlock.chance >= static_cast<uint32_t>(uniform_random(1, 100)))) {
  31.             minCombatValue = spellBlock.minCombatValue;
  32.             maxCombatValue = spellBlock.maxCombatValue;
  33.             spellBlock.spell->castSpell(this, this);
  34.         }
  35.     }
  36.  
  37.     if (attackedCreature && !isSummon() && summons.size() < mType->info.maxSummons && hasFollowPath) {
  38.         for (const summonBlock_t& summonBlock : mType->info.summons) {
  39.             const Position& pos = getPosition();
  40.             const Position& targetPos = attackedCreature->getPosition();
  41.  
  42.             if (std::max(std::abs(pos.x - targetPos.x), std::abs(pos.y - targetPos.y)) <= 1) {
  43.                 spell_interval = summonBlock.speed;
  44.             } else {
  45.                 spell_interval = summonBlock.speed / 2;
  46.             }
  47.  
  48.             if (spell_interval > defenseTicks) {
  49.                 resetTicks = false;
  50.                 continue;
  51.             }
  52.  
  53.             if (summons.size() >= mType->info.maxSummons) {
  54.                 continue;
  55.             }
  56.  
  57.             if (defenseTicks % spell_interval >= interval) {
  58.                 //already used this spell for this round
  59.                 continue;
  60.             }
  61.  
  62.             uint32_t summonCount = 0;
  63.             for (Creature* summon : summons) {
  64.                 if (summon->getName() == summonBlock.name) {
  65.                     ++summonCount;
  66.                 }
  67.             }
  68.  
  69.             if (summonCount >= summonBlock.max) {
  70.                 continue;
  71.             }
  72.  
  73.             if (summonBlock.chance < static_cast<uint32_t>(uniform_random(1, 100))) {
  74.                 continue;
  75.             }
  76.  
  77.             Monster* summon = Monster::createMonster(summonBlock.name);
  78.             if (summon) {
  79.                 if (g_game.placeCreature(summon, getPosition(), false, summonBlock.force)) {
  80.                     summon->setDropLoot(false);
  81.                     summon->setSkillLoss(false);
  82.                     summon->setMaster(this);
  83.                     g_game.addMagicEffect(getPosition(), CONST_ME_MAGIC_BLUE);
  84.                     g_game.addMagicEffect(summon->getPosition(), CONST_ME_TELEPORT);
  85.                 } else {
  86.                     delete summon;
  87.                 }
  88.             }
  89.         }
  90.     }
  91.  
  92.     if (resetTicks) {
  93.         defenseTicks = 0;
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment