int characterShell::getAgility(lua_State* pLua) { auto pCharacter = worldShell::CWorldSingleton::instance()->getPlayer()->getCharacter(); if(pCharacter != nullptr) lua_pushinteger(pLua, pCharacter->getAgility()); return 1; }
bool Entity::attack(){ if (Victim == NULL) return false; // Don't attack dead or hurt people if (Victim->Action == CHAR_DIE || Victim->Action == CHAR_HURT) return false; // Set attacker and victim Victim->Attacker = this; this->Victim = Victim; notify(*this, EVENT_ATTACK); // Return if hit missed if ((rand() % 1000) > getToHit(Victim)) { std::string miss_msg = getEntityType().c_str() + std::string(" missed!"); log_message->setString(miss_msg); log_message->setColor(sf::Color::Yellow); addMessage(miss_msg.c_str(), 1000, sf::Color::Yellow); return false; } // Return if hit dodged if ((rand() % 1000) <= getAgility(Victim)) { std::string dodge_msg = getEntityType().c_str() + std::string(" dodged!"); log_message->setString(dodge_msg); log_message->setColor(sf::Color::Yellow); addMessage(dodge_msg.c_str(), 1000, sf::Color::Yellow); return false; } // If this is asleep, randomly wake them up (50% chance) if (Victim->Ailments & AILMENT_SLEEP) { if ((rand() % 100) < 50) Victim->Ailments &= ~AILMENT_SLEEP; } // Attack landed, apply damage damage(Victim, true, getAttack(this), -1, -1); return true; }