void ForageManagerImplementation::finishForaging(CreatureObject* player, int forageType, float forageX, float forageY, const String& zoneName) { if (player == NULL) return; Locker playerLocker(player); Locker forageAreasLocker(_this.get()); player->removePendingTask("foraging"); if (player->getZone() == NULL) return; //Check if player moved. float playerX = player->getPositionX(); float playerY = player->getPositionY(); if ((fabs(playerX - forageX) > 2.0) || (fabs(playerY - forageY) > 2.0) || player->getZone()->getZoneName() != zoneName) { player->sendSystemMessage("@skl_use:sys_forage_movefail"); //"You fail to forage because you moved." return; } //Check if player is in combat. if (player->isInCombat()) { player->sendSystemMessage("@skl_use:sys_forage_combatfail"); //"Combat distracts you from your foraging attempt." return; } //Check if player is allowed to forage in this area. if (forageType != ForageManager::SHELLFISH) { Reference<ForageAreaCollection*> forageAreaCollection = forageAreas.get(player->getFirstName()); if (forageAreaCollection != NULL) { //Player has foraged before. if (!forageAreaCollection->checkForageAreas(forageX, forageY, zoneName, forageType)) { if( forageType == LAIR ){ player->sendSystemMessage("There is nothing of interest remaining in the lair."); } else{ player->sendSystemMessage("@skl_use:sys_forage_empty"); //"There is nothing in this area to forage." } return; } } else { //Player has not foraged before. forageAreaCollection = new ForageAreaCollection(player, forageX, forageY, zoneName, forageType); forageAreas.put(player->getFirstName(), forageAreaCollection); } } //Calculate the player's chance to find an item. int chance; int skillMod; switch(forageType) { case ForageManager::SCOUT: case ForageManager::LAIR: skillMod = player->getSkillMod("foraging"); chance = (int)(15 + (skillMod * 0.8)); break; case ForageManager::MEDICAL: skillMod = player->getSkillMod("medical_foraging"); chance = (int)(15 + (skillMod * 0.6)); break; default: skillMod = 20; chance = (int)(15 + (skillMod * 0.6)); break; } //Determine if player finds an item. if (chance > 100) //There could possibly be +foraging skill tapes. chance = 100; if (System::random(80) > chance) { if (forageType == ForageManager::SHELLFISH) player->sendSystemMessage("@harvesting:found_nothing"); else if (forageType == ForageManager::LAIR) player->sendSystemMessage("@lair_n:found_nothing"); else player->sendSystemMessage("@skl_use:sys_forage_fail"); //"You failed to find anything worth foraging." } else { forageGiveItems(player, forageType, forageX, forageY, zoneName); } return; }