Guest User

Untitled

a guest
Jul 14th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.86 KB | None | 0 0
  1. else if(this->Data()->type == ENF::Aggressive)
  2.           {
  3. UTIL_PTR_VECTOR_FOREACH(this->map->npcs, NPC, npc)
  4.         {
  5. int distance = util::path_length(npc->x, npc->y, this->x, this->y);
  6.  if (npc->Data()->type == ENF::Pet && distance > 1 && distance < 5 && npc->alive)     //?
  7.             {
  8.     int xdiff = this->x - npc->x;
  9.     int ydiff = this->y - npc->y;
  10.     int absxdiff = std::abs(xdiff);
  11.     int absydiff = std::abs(ydiff);
  12.  
  13.  if ((absxdiff == 1 && absydiff == 0) || (absxdiff == 0 && absydiff == 1) || (absxdiff == 0 && absydiff == 0))
  14.      {
  15.            //if(attacker != this->owner)
  16.            //this->Attack(this->owner);
  17.       return;
  18.      }
  19.  
  20.         else if (absxdiff > absydiff)
  21.         {
  22.             if (xdiff < 0)
  23.             {
  24.                 this->direction = DIRECTION_RIGHT;
  25.             }
  26.             else
  27.             {
  28.                 this->direction = DIRECTION_LEFT;
  29.             }
  30.         }
  31.         else
  32.         {
  33.             if (ydiff < 0)
  34.             {
  35.                 this->direction = DIRECTION_DOWN;
  36.             }
  37.             else
  38.             {
  39.                 this->direction = DIRECTION_UP;
  40.             }
  41.         }
  42.  
  43.         if (!this->Walk(this->direction))
  44.         {
  45.             this->Walk(static_cast<Direction>(util::rand(0,3)));
  46.         }
  47.      return;
  48.         }
  49.         }
  50.   if (this->Data()->type == ENF::Aggressive || this->Data()->type == ENF::Passive)
  51.     {
  52.      UTIL_PTR_LIST_FOREACH(this->map->characters, Character, character)
  53.         {
  54.             UTIL_PTR_VECTOR_FOREACH(this->map->npcs, NPC, npc)
  55.             {
  56.                 int distance = util::path_length(npc->x, npc->y, this->x, this->y);
  57.                  if ((distance > 0 && distance < 2 && npc->Data()->type == ENF::Pet && npc->alive))
  58.             {
  59.  if(distance < 2)
  60.             {
  61.         int xdiff = this->x - npc->x;
  62.         int ydiff = this->y - npc->y;
  63.  
  64.         if (std::abs(xdiff) > std::abs(ydiff))
  65.         {
  66.             if (xdiff < 0)
  67.             {
  68.                 this->direction = DIRECTION_RIGHT;
  69.             }
  70.             else
  71.             {
  72.                 this->direction = DIRECTION_LEFT;
  73.             }
  74.         }
  75.         else
  76.         {
  77.             if (ydiff < 0)
  78.             {
  79.                 this->direction = DIRECTION_DOWN;
  80.             }
  81.             else
  82.             {
  83.                 this->direction = DIRECTION_UP;
  84.             }
  85.         }
  86.  
  87.         PacketBuilder builder(PACKET_NPC, PACKET_PLAYER);
  88.         builder.AddByte(255);
  89.         builder.AddChar(this->index);
  90.         builder.AddChar(1 + (character->hp == 0));
  91.         builder.AddChar(this->direction);
  92.         builder.AddShort(0);
  93.         builder.AddThree(0);
  94.         builder.AddThree(int(double(character->hp) / double(character->maxhp) * 100.0));
  95.         builder.AddByte(255);
  96.         builder.AddByte(255);
  97.  
  98.         UTIL_PTR_LIST_FOREACH(this->map->characters, Character, character)
  99.         {
  100.             if (*character == npc->owner || !character->InRange(this))
  101.             {
  102.                 continue;
  103.             }
  104.  
  105.             character->player->client->SendBuilder(builder);
  106.         }
  107.         npc->owner->player->client->SendBuilder(builder);
  108.         }
  109.             int amount = util::rand(this->Data()->mindam, this->Data()->maxdam + static_cast<int>(this->map->world->config["NPCAdjustMaxDam"]));
  110.                         double rand = util::rand(0.0, 1.0);
  111.                         // Checks if target is facing you
  112.                         bool critical = std::abs(int(npc->direction) - npc->owner->direction) != 2 || rand < static_cast<double>(this->map->world->config["CriticalRate"]);
  113.  
  114.                         std::tr1::unordered_map<std::string, double> formula_vars;
  115.  
  116.                         npc->owner->FormulaVars(formula_vars);
  117.                         npc->FormulaVars(formula_vars, "target_");
  118.                         formula_vars["modifier"] = this->map->world->config["MobRate"];
  119.                         formula_vars["damage"] = amount;
  120.                         formula_vars["critical"] = critical;
  121.  
  122.                         amount = rpn_eval(rpn_parse(this->map->world->formulas_config["damage"]), formula_vars);
  123.                         double hit_rate = rpn_eval(rpn_parse(this->map->world->formulas_config["hit_rate"]), formula_vars);
  124.  
  125.                         if (rand > hit_rate)
  126.                         {
  127.                             amount = 0;
  128.                         }
  129.  
  130.                         amount = std::max(amount, 0);
  131.  
  132.                         int limitamount = std::min(amount, int(npc->hp));
  133.  
  134.                         if (this->map->world->config["LimitDamage"])
  135.                         {
  136.                             amount = limitamount;
  137.                         }
  138.  
  139.                         npc->Damage(npc->owner, amount);
  140.  
  141.                         return;
  142.                     }
  143.                 }
  144.             }
  145.         }
  146.     }
Advertisement
Add Comment
Please, Sign In to add comment