| 323 | } |
| 324 | |
| 325 | bool RoomLibrary::useRoom(Creature& creature, bool forced) |
| 326 | { |
| 327 | int32_t skillEntityPoints = ConfigManager::getSingleton().getRoomConfigInt32("LibrarySkillPointsBook"); |
| 328 | auto it = mCreaturesSpots.find(&creature); |
| 329 | if(it == mCreaturesSpots.end()) |
| 330 | { |
| 331 | OD_LOG_ERR("room=" + getName() + ", creature=" + creature.getName()); |
| 332 | return false; |
| 333 | } |
| 334 | |
| 335 | Tile* tileSpot = it->second; |
| 336 | Tile* tileCreature = creature.getPositionTile(); |
| 337 | if(tileCreature == nullptr) |
| 338 | { |
| 339 | OD_LOG_ERR("room=" + getName() + ", creature=" + creature.getName() + ", pos=" + Helper::toString(creature.getPosition())); |
| 340 | return false; |
| 341 | } |
| 342 | |
| 343 | Ogre::Real wantedX = -1; |
| 344 | Ogre::Real wantedY = -1; |
| 345 | getCreatureWantedPos(&creature, tileSpot, wantedX, wantedY); |
| 346 | |
| 347 | BuildingObject* ro = getBuildingObjectFromTile(tileSpot); |
| 348 | if(ro == nullptr) |
| 349 | { |
| 350 | OD_LOG_ERR("unexpected null building object"); |
| 351 | return false; |
| 352 | } |
| 353 | // We consider that the creature is in the good place if it is in the expected tile and not moving |
| 354 | Tile* expectedDest = getGameMap()->getTile(Helper::round(wantedX), Helper::round(wantedY)); |
| 355 | if(expectedDest == nullptr) |
| 356 | { |
| 357 | OD_LOG_ERR("room=" + getName() + ", creature=" + creature.getName()); |
| 358 | return false; |
| 359 | } |
| 360 | |
| 361 | if(tileCreature != expectedDest) |
| 362 | { |
| 363 | creature.setDestination(expectedDest); |
| 364 | return false; |
| 365 | } |
| 366 | |
| 367 | Ogre::Vector3 walkDirection(ro->getPosition().x - creature.getPosition().x, ro->getPosition().y - creature.getPosition().y, 0); |
| 368 | walkDirection.normalise(); |
| 369 | creature.setAnimationState(EntityAnimation::attack_anim, false, walkDirection); |
| 370 | |
| 371 | ro->setAnimationState("Triggered", false); |
| 372 | |
| 373 | const CreatureRoomAffinity& creatureRoomAffinity = creature.getDefinition()->getRoomAffinity(getType()); |
| 374 | OD_ASSERT_TRUE_MSG(creatureRoomAffinity.getRoomType() == getType(), "name=" + getName() + ", creature=" + creature.getName() |
| 375 | + ", creatureRoomAffinityType=" + Helper::toString(static_cast<int>(creatureRoomAffinity.getRoomType()))); |
| 376 | |
| 377 | int32_t pointsEarned = static_cast<int32_t>(creatureRoomAffinity.getEfficiency() * ConfigManager::getSingleton().getRoomConfigDouble("LibraryPointsPerWork")); |
| 378 | creature.jobDone(ConfigManager::getSingleton().getRoomConfigDouble("LibraryWakefulnessPerWork")); |
| 379 | creature.setJobCooldown(Random::Uint(ConfigManager::getSingleton().getRoomConfigUInt32("LibraryCooldownWorkMin"), |
| 380 | ConfigManager::getSingleton().getRoomConfigUInt32("LibraryCooldownWorkMax"))); |
| 381 | |
| 382 | // We check if we have enough points to create a skill entity |
nothing calls this directly
no test coverage detected