uint32 ResourceManagerImplementation::getAvailablePowerFromPlayer(CreatureObject* player) { SceneObject* inventory = player->getSlottedObject("inventory"); uint32 power = 0; for (int i = 0; i < inventory->getContainerObjectsSize(); i++) { Reference<SceneObject*> obj = inventory->getContainerObject(i).castTo<SceneObject*>(); if (obj == NULL || !obj->isResourceContainer()) continue; ResourceContainer* rcno = cast<ResourceContainer*>( obj.get()); ManagedReference<ResourceSpawn*> spawn = rcno->getSpawnObject(); if (spawn == NULL || !spawn->isEnergy()) continue; int quantity = rcno->getQuantity(); int pe = spawn->getValueOf(CraftingManager::PE); // potential energy float modifier = MAX(1.0f, pe / 500.0f); power += (uint32) (modifier * quantity); } return power; }
ResourceContainer* InstallationObjectImplementation::getContainerFromHopper(ResourceSpawn* spawn) { for (int i = 0; i < resourceHopper.size(); ++i) { ResourceContainer* entry = resourceHopper.get(i); if (entry->getSpawnObject() == spawn) return entry; } return NULL; }
int InstallationObjectImplementation::getHopperItemQuantity(ResourceSpawn* spawn) { for (int i = 0; i < resourceHopper.size(); ++i) { ResourceContainer* entry = resourceHopper.get(i); if (entry->getSpawnObject() == spawn) return entry->getQuantity(); } return -1; }
void ResourceManagerImplementation::removePowerFromPlayer(CreatureObject* player, uint32 power) { if (power == 0) return; SceneObject* inventory = player->getSlottedObject("inventory"); uint32 containerPower = 0; for (int i = 0; i < inventory->getContainerObjectsSize() && power > 0; ++i) { ManagedReference<SceneObject*> obj = inventory->getContainerObject(i); if (obj == NULL || !obj->isResourceContainer()) continue; ResourceContainer* rcno = cast<ResourceContainer*>( obj.get()); Locker locker(rcno); ManagedReference<ResourceSpawn*> spawn = rcno->getSpawnObject(); if (spawn == NULL || !spawn->isEnergy()) continue; int quantity = rcno->getQuantity(); int pe = spawn->getValueOf(CraftingManager::PE); // potential energy float modifier = MAX(1.0f, pe / 500.0f); containerPower = modifier * quantity; if (containerPower > power) { uint32 consumedUnits = (uint64) power / modifier; rcno->setQuantity(quantity - consumedUnits); ResourceContainerObjectDeltaMessage3* drcno3 = new ResourceContainerObjectDeltaMessage3(rcno); drcno3->updateQuantity(); drcno3->close(); player->sendMessage(drcno3); return; } else { rcno->destroyObjectFromWorld(true); rcno->destroyObjectFromDatabase(true); } power -= containerPower; } }