int ManufactureSchematicImplementation::removeIngredientFromSlot(CreatureObject* player, TangibleObject* tano, int slot) {

	Reference<IngredientSlot*> ingredientSlot = ingredientSlots.get(slot);

	if(ingredientSlot == NULL)
		return IngredientSlot::INVALID;

	if(!ingredientSlot->removeAll(player))
		return IngredientSlot::BADTARGETCONTAINER;

	decreaseComplexity();
	updateIngredientCounter();

	/// Send delta 7
	sendDelta7(ingredientSlot, slot, player);

	// Start DMSCO3 ***********************************************************
	// Updates the Complexity
	ManufactureSchematicObjectDeltaMessage3* dMsco3 =
			new ManufactureSchematicObjectDeltaMessage3(_this.getReferenceUnsafeStaticCast());
	dMsco3->updateComplexity(getComplexity());
	dMsco3->close();

	player->sendMessage(dMsco3);
	// End DMSCO3 *************************************************************

	return IngredientSlot::OK;
}
Example #2
0
float Task::getExpectedDuration()
{
    if (expectedDuration == -1.0f) {
        expectedDuration = 0.0f;
        const type_info *id = getTypeInfo();
        pthread_mutex_lock((pthread_mutex_t*) mutex);
        map<type_info const*, TaskStatistics*, TypeInfoSort>::iterator i = statistics.find(id);
        if (i != statistics.end()) {
            TaskStatistics *stats = i->second;
            // to get "valid" statistics, we wait until we have enough samples,
            // and we ignore the min and max values
            const int MIN_SAMPLES = 64;
            if (stats->n >= MIN_SAMPLES) {
                if (!stats->corrected) {
                    float sum = stats->durationSum - stats->maxDuration - stats->minDuration;
                    float squareSum = stats->durationSum - stats->maxDuration * stats->maxDuration - stats->minDuration * stats->minDuration;
                    stats->durationSum = (sum * stats->n) / (stats->n - 2) ;
                    stats->durationSquareSum = (squareSum * stats->n) / (stats->n - 2);
                    stats->corrected = true;
                }
                float mean = stats->durationSum / stats->n;
                float squareMean = stats->durationSquareSum / stats->n;
                float variance = squareMean - mean * mean;
                float standardDeviation = sqrt(variance);
                expectedDuration = (mean + 2.0f * standardDeviation) * getComplexity();
            }
        }
        pthread_mutex_unlock((pthread_mutex_t*) mutex);
    }
    return expectedDuration;
}
Example #3
0
void Task::setActualDuration(float duration)
{
    TaskStatistics *stats;
    const type_info *id = getTypeInfo();
    pthread_mutex_lock((pthread_mutex_t*) mutex);
    map<type_info const*, TaskStatistics*, TypeInfoSort>::iterator i = statistics.find(id);
    if (i == statistics.end()) {
        stats = new TaskStatistics();
        statistics.insert(make_pair(id, stats));
    } else {
        stats = i->second;
    }
    duration = duration / getComplexity();
    stats->durationSum += duration;
    stats->durationSquareSum += duration * duration;
    stats->minDuration = min(duration, stats->minDuration);
    stats->maxDuration = max(duration, stats->maxDuration);
    stats->n += 1;
    pthread_mutex_unlock((pthread_mutex_t*) mutex);
}
Example #4
0
//show the whole tree with infor: type, name, lineCount and complexity
void ASTree::ShowTree() {
	tree<Element>::iterator iterStart = astree.begin();
	tree<Element>::iterator end = astree.end();
	while (iterStart != end) {
		for (int i = 0; i < astree.depth(iterStart); ++i)
			std::cout << "	";
		if ((*iterStart).type == "Namespace")
			std::cout << (*iterStart).type << ", " << (*iterStart).name << std::endl;
		else
			std::cout <<std::setw(10)<<std::setfill('-')<< "-> (" <<(*iterStart).type << ", " << (*iterStart).name << ", " << (*iterStart).lineCount << ", " << getComplexity(iterStart) << ")" << std::endl;
		++iterStart;
	}
}
void TangibleObjectImplementation::repair(CreatureObject* player) {

	if(player == NULL || player->getZoneServer() == NULL)
		return;

	if(!isASubChildOf(player))
		return;

	if (getConditionDamage() == 0) {
		player->sendSystemMessage("That item is not in need of repair.");
		return;
	}

	//Condition is unrepairable
	if ((getMaxCondition() - getConditionDamage()) <= 0) {
		StringIdChatParameter cantrepair("error_message", "sys_repair_unrepairable");
		cantrepair.setTT(getDisplayedName());
		player->sendSystemMessage(cantrepair); //%TT's condition is beyond repair even for your skills.
		return;
	}

	SceneObject* inventory = player->getSlottedObject("inventory");
	if(inventory == NULL)
		return;

	ManagedReference<RepairTool*> repairTool = NULL;
	Reference<RepairToolTemplate*> repairTemplate = NULL;

	for(int i = 0; i < inventory->getContainerObjectsSize(); ++i) {
		ManagedReference<SceneObject*> item = inventory->getContainerObject(i);
		if(item->isRepairTool()) {
			repairTemplate = cast<RepairToolTemplate*>(item->getObjectTemplate());

			if (repairTemplate == NULL) {
				error("No RepairToolTemplate for: " + String::valueOf(item->getServerObjectCRC()));
				return;
			}

			if(repairTemplate->getRepairType() & getGameObjectType()) {
				repairTool = cast<RepairTool*>(item.get());
				break;
			}
			repairTemplate = NULL;
		}
	}

	if(repairTool == NULL)
		return;

	/// Luck Roll + Profession Mod(25) + Luck Tapes
	/// + Station Mod - BF

	/// Luck Roll
	int roll = System::random(100);
	int repairChance = roll;

	/// Profession Bonus
	if(player->hasSkill(repairTemplate->getSkill()))
		repairChance += 35;

	/// Get Skill mods
	repairChance += player->getSkillMod(repairTemplate->getSkillMod());
	repairChance += player->getSkillMod("crafting_repair");
	repairChance += player->getSkillMod("force_repair_bonus");

	/// use tool quality to lower chances if bad tool
	float quality = 1.f - (((100.f - repairTool->getQuality()) / 2) / 100.f);
	repairChance *= quality;

	ManagedReference<PlayerManager*> playerMan = player->getZoneServer()->getPlayerManager();

	/// Increase if near station
	if(playerMan->getNearbyCraftingStation(player, repairTemplate->getStationType()) != NULL) {
		repairChance += 15;
	}

	/// Subtract battle fatigue
	repairChance -= (player->getShockWounds() / 2);

	/// Subtract complexity
	repairChance -= (getComplexity() / 3);

	/// 5% random failure
	if(getMaxCondition() < 20 || roll < 5)
		repairChance = 0;

	if(roll > 95)
		repairChance = 100;

	String result = repairAttempt(repairChance);

	Locker locker(repairTool);

	repairTool->destroyObjectFromWorld(true);
	repairTool->destroyObjectFromDatabase(true);

	player->sendSystemMessage(result);
}
Actor *WeakZombie::copy() const
{
    return new WeakZombie(getComplexity(), getPosition());
}
int ManufactureSchematicImplementation::addIngredientToSlot(CreatureObject* player, SceneObject* satchel, TangibleObject* tano, int slot) {
	if (slot >= ingredientSlots.size())
		return IngredientSlot::INVALID;

	Reference<IngredientSlot*> ingredientSlot = ingredientSlots.get(slot);

	if (ingredientSlot == NULL)
		return IngredientSlot::INVALID;

	bool wasEmpty = false;

	if(ingredientSlot->isFull())
		return IngredientSlot::FULL;

	if(ingredientSlot->isEmpty())
		wasEmpty = true;

	if(!ingredientSlot->add(player, satchel, tano))
		return IngredientSlot::INVALIDINGREDIENT;

	if(wasEmpty) {

		updateIngredientCounter();
		increaseComplexity();

		// DMSCO6 ***************************************************
		ManufactureSchematicObjectDeltaMessage6* dMsco6 =
				new ManufactureSchematicObjectDeltaMessage6(_this.getReferenceUnsafeStaticCast());

		dMsco6->insertToResourceSlot(slot);
		dMsco6->close();

		player->sendMessage(dMsco6);
		// End DMSCO6 ****************************************************

		sendDelta7(ingredientSlot, slot, player);

		if(possibleSyncIssue) {
			sendMsco7(player);
			possibleSyncIssue = false;
		}

	} else {

		possibleSyncIssue = true;
		/// Delta 7
		sendDelta7(ingredientSlot, slot, player);
	}


	// Start DMSCO3 ***********************************************************
	// Updates the Complexity
	ManufactureSchematicObjectDeltaMessage3* dMsco3 =
				new ManufactureSchematicObjectDeltaMessage3(_this.getReferenceUnsafeStaticCast());
	dMsco3->updateComplexity(getComplexity());
	dMsco3->close();

	player->sendMessage(dMsco3);
	// End DMSCO3 *************************************************************

	return IngredientSlot::OK;
}