void DroidHarvestModuleDataComponent::deactivate() { active = false; ManagedReference<DroidObject*> droid = getDroidObject(); if( droid == NULL ){ info( "Droid is null" ); return; } Locker dlock( droid ); // remove observer ManagedReference<CreatureObject*> player = droid->getLinkedCreature().get(); if (player != NULL) { Locker clock(player, droid); player->dropObserver(ObserverEventType::KILLEDCREATURE, observer); droid->dropObserver(ObserverEventType::DESTINATIONREACHED, observer); } if(droid->getPendingTask("droid_harvest")) { droid->removePendingTask("droid_harvest"); } harvestTargets.removeAll(0,10); }
static int lua_fn_packet_lock(lua_State *L) { dbuf_t *d = luaL_checkuserdata(L, 1); dlock(d); lua_pushlightuserdata(L, d); return 1; }
StimPack* DroidStimpackModuleDataComponent::compatibleStimpack(float power) { DroidComponent* droidComponent = cast<DroidComponent*>(getParent()); if (droidComponent == NULL) { info("droidComponent was null"); return NULL; } DroidObject* droid = getDroidObject(); if (droid == NULL) { return NULL; } Locker dlock(droid); ManagedReference<SceneObject*> craftingComponents = droidComponent->getSlottedObject("crafted_components"); if(craftingComponents != NULL) { SceneObject* satchel = craftingComponents->getContainerObject(0); if(satchel == NULL) { return NULL; } for (int i = 0; i < satchel->getContainerObjectsSize(); ++i) { SceneObject* item = satchel->getContainerObject(i); if (!item->isTangibleObject()) continue; TangibleObject* tano = cast<TangibleObject*>( item); if (tano->isPharmaceuticalObject()) { StimPack* stim = cast<StimPack*>(tano); if(stim->getEffectiveness() == power) { return stim; } } } } return NULL; }
void dsend(int idx, dbuf_t * d) { debug(DBG_GLOBAL, 5, "pushing %d bytes for index %d", d->dsize, idx); debug_dump(DBG_GLOBAL, 100, d->buf, d->dsize); lpush(&cdata[idx].xmit_list, d); ufds[idx].events |= POLLOUT; // Will be unlocked by the send mechanism dlock(d); }
void DroidDetonationModuleDataComponent::deactivate() { ManagedReference<DroidObject*> droid = getDroidObject(); if (droid == NULL) { info("Droid is null"); return; } Locker dlock(droid); droid->removePendingTask("droid_detonation"); }
qint64 DeviceMuxer::readData(channel_t chan, char* data, qint64 maxSize) { QMutexLocker rLock(_readLock); QMutexLocker dlock(_dataLock); QByteArray& buf = _data[chan]; // Determine length, copy data and remove from buffer qint64 size = buf.size() < maxSize ? buf.size() : maxSize; if (!size) return 0; memcpy(data, buf.constData(), size); buf.remove(0, size); return size; }
/** * * _pwd(debug); * * Print current working directory. * **/ PUBLIC void _pwd(DEBUG *debug) { DISPLAY *display = debug->display; dlock(display); #ifdef OLDCODE dprintf(display, "Current Directory is %s", debug->env.Objv[0]->Name); #endif /* -- crf : 12/08/91 - clean up use of Environment Objv */ dprintf(display, "Current Directory is %s", debug->env.Objv[OV_Cdir]->Name); dunlock(display); }
void DroidHarvestModuleDataComponent::onCall(){ deactivate(); ManagedReference<DroidObject*> droid = getDroidObject(); if( droid == NULL ){ info( "Droid is null"); return; } if (observer == NULL) { observer = new DroidHarvestObserver(this); observer->deploy(); } Locker dlock( droid ); // add observer for the droid //droid->registerObserver(ObserverEventType::DESTINATIONREACHED, observer); Reference<Task*> task = new DroidHarvestTask( this ); droid->addPendingTask("droid_harvest", task, 1000); // 1 sec }
void DroidHarvestModuleDataComponent::handlePetCommand(String cmd, CreatureObject* speaker){ ManagedReference<DroidObject*> droid = getDroidObject(); if( droid == NULL ){ return; } ManagedReference<PetControlDevice*> pcd = droid->getControlDevice().get().castTo<PetControlDevice*>(); if( pcd == NULL ) { return; } PetManager* petManager = droid->getZoneServer()->getPetManager(); if( petManager == NULL ) { return; } // Owner-only command if( droid->getLinkedCreature().get() != speaker ) { return; } if( petManager->isTrainedCommand( pcd, PetManager::HARVEST, cmd ) ){ Locker dlock(droid); uint64 targetID = speaker->getTargetID(); Reference<CreatureObject*> target = droid->getZoneServer()->getObject(targetID, true).castTo<CreatureObject*>(); if (target != NULL) { // this check should occur in the pet speaking handling. if(!target->isInRange(droid,64)) { speaker->sendSystemMessage("@pet/droid_modules:corpse_too_far"); return; } harvestTargets.add(targetID); } for(int i=0;i<harvestTargets.size();i++){ if (harvestTargets.get(i) == targetID) return; } harvestTargets.add(targetID); } }
int DroidDetonationModuleDataComponent::handleObjectMenuSelect(CreatureObject* player, byte selectedID, PetControlDevice* controller) { if (selectedID == DETONATE_DROID) { ManagedReference<DroidObject*> droid = getDroidObject(); if (droid == NULL) { info("Droid is null"); return 0; } Locker dlock(droid, player); if (droid->isDead()) { player->sendSystemMessage("@pet/droid_modules:droid_bomb_failed"); return 0; } // Droid must have power if (!droid->hasPower()) { droid->showFlyText("npc_reaction/flytext","low_power", 204, 0, 0); // "*Low Power*" return 0; } // if the droid is already in detonation countdown we need to ignore this command if (droid->getPendingTask("droid_detonation") != NULL) { if (countdownInProgress()) player->sendSystemMessage("@pet/droid_modules:countdown_already_started"); else player->sendSystemMessage("@pet/droid_modules:detonation_warmup"); return 0; } // droid has power and is not dead we can fire off the task Reference<Task*> task = new DroidDetonationTask(this, player); droid->addPendingTask("droid_detonation", task, 0); // queue the task for the droid to occur in 0 MS the task will handle init phase } return 0; }
void DroidStimpackModuleDataComponent::countUses() { DroidComponent* droidComponent = cast<DroidComponent*>(getParent()); if (droidComponent == NULL) { info("droidComponent was null"); return; } DroidObject* droid = getDroidObject(); if (droid == NULL) { return ; } Locker dlock(droid); ManagedReference<SceneObject*> craftingComponents = droidComponent->getSlottedObject("crafted_components"); if (craftingComponents == NULL) { return; } SceneObject* satchel = craftingComponents->getContainerObject(0); if (satchel == NULL) { return; } loaded = 0; for (int i = 0; i < satchel->getContainerObjectsSize(); ++i) { ManagedReference<SceneObject*> item = satchel->getContainerObject(i); if (!item->isPharmaceuticalObject()) continue; PharmaceuticalObject* pharma = item.castTo<PharmaceuticalObject*>(); if (pharma->isStimPack()) loaded += pharma->getUseCount(); } }
uint32_t start_timer(int interval, int timer_kind, timer_callback_t callback, uint32_t param_int, void *param_uuid, void *param_dbuf) { uint32_t mytimer = grab_timer_index(); uint32_t out; timerwheel_entry_t *timers; if(mytimer == 0) { return 0; } timers = (timerwheel_entry_t *) timers_list->buf; if(param_dbuf != NULL) { dlock(param_dbuf); } timers[mytimer].state = timer_kind; // increment the generation - it will automatically overflow when needed timers[mytimer].generation++; timers[mytimer].user.callback = callback; timers[mytimer].user.param_int = param_int; if (param_uuid) { memcpy(&timers[mytimer].user.param_uuid, param_uuid, sizeof(timers[mytimer].user.param_uuid)); } else { memset(&timers[mytimer].user.param_uuid, 0, sizeof(timers[mytimer].user.param_uuid)); } timers[mytimer].user.param_dbuf = param_dbuf; if(timer_kind == TIMER_PERIODIC) { timers[mytimer].period = interval; } timer_enqueue_internal(mytimer, interval); out = (timers[mytimer].generation << 24) + mytimer; debug(DBG_TIMERS, 10, "Started timer %p of kind %d with interval %d", out, timer_kind, interval); return out; }
int DroidHarvestModuleDataComponent::handleObjectMenuSelect(CreatureObject* player, byte selectedID, PetControlDevice* controller) { if (selectedID == HARVEST_SET_INTEREST) { ManagedReference<DroidObject*> droid = getDroidObject(); if( droid == NULL ){ info( "Droid is null"); return 0; } if( !droid->hasPower() ){ player->sendSystemMessage("@pet/droid_modules:playback_msg_play_out_of_power"); return 0; } // popup a ui to choose the correct interest. ManagedReference<SuiListBox*> box = new SuiListBox(player, SuiWindowType::DROID_SET_INTEREST, SuiListBox::HANDLETWOBUTTON); box->setCallback(new SelectHarvestSuiCallback(player->getZoneServer())); box->setPromptText("@pet/droid_modules:set_interest_d"); box->setPromptTitle("@pet/droid_modules:set_interest_d"); box->setOkButton(true,"@ok"); box->setCancelButton(true, "@cancel"); // Add tracks box->addMenuItem("@pet/droid_modules:set_interest_random",INTREST_RANDOM); box->addMenuItem("@pet/droid_modules:set_interest_bone",INTREST_BONE); box->addMenuItem("@pet/droid_modules:set_interest_meat",INTREST_MEAT); box->addMenuItem("@pet/droid_modules:set_interest_hide",INTREST_HIDE); box->setUsingObject(droid); player->getPlayerObject()->addSuiBox(box); player->sendMessage(box->generateMessage()); return 0; } // Handle toggle on/off if (selectedID == HARVEST_PROGRAM_COMMAND) { if( controller == NULL ) return 0; controller->setTrainingCommand( PetManager::HARVEST ); return 0; } if( selectedID == HARVEST_TOGGLE ){ ManagedReference<DroidObject*> droid = getDroidObject(); if( droid == NULL ){ info( "Droid is null"); return 0; } Locker dlock( droid, player ); // Toggle off if (active){ deactivate(); player->sendSystemMessage("@pet/droid_modules:auto_harvest_off"); // You turn off auto-repair } else{ // Toggle on // Check droid states if( droid->isDead() || droid->isIncapacitated()) return 0; // Droid must have power if( !droid->hasPower() ){ droid->showFlyText("npc_reaction/flytext","low_power", 204, 0, 0); // "*Low Power*" return 0; } // Ensure we don't accidentally have another task outstanding deactivate(); player->sendSystemMessage("@pet/droid_modules:auto_harvest_on"); // You turn on auto-repair if (observer == NULL) { observer = new DroidHarvestObserver(this); observer->deploy(); } Locker plock(player); player->registerObserver(ObserverEventType::KILLEDCREATURE, observer); active = true; } } return 0; }
int DroidMaintenanceModuleDataComponent::handleObjectMenuSelect(CreatureObject* player, byte selectedID, PetControlDevice* controller) { ManagedReference<DroidObject*> droid = getDroidObject(); if( droid == NULL ){ info( "Droid is null"); return 0; } Locker dlock( droid, player ); // Perform Maintenance Run if( selectedID == MAINT_MODULE_PERFORM ){ // Init Maintenance Run Session //droid->getCooldownTimerMap()->updateToCurrentAndAddMili("Droid_Cooldown",1800000); // Interplanetary Time + 1 hour 40 minutes, 33 seconds // Local time: distance < 432 == 15 mins + (1s per 3 meters to next structure for that planet @ < 432m from first structure) // Local time: distance > 432 == 48 minutes 20 seconds // Start a session for the player and this module! ManagedReference<DroidMaintenanceSession*> session = new DroidMaintenanceSession(this, player); session->initialize(); player->addActiveSession(SessionFacadeType::DROIDMAINTENANCERUN, session); session->sendMaintanceRunBox(); return 0; } // Edit Maintenance List else if( selectedID == MAINT_MODULE_EDIT ){ if( assignedStructures.isEmpty() ){ player->sendSystemMessage( "@pet/droid_modules:droid_maint_empty_list" ); // The maintenance list for this droid is empty. Go to one of your structures and assign this droid to maintain it. return 0; } // Build List of Assigned Structures ManagedReference<SuiListBox*> box = new SuiListBox(player, SuiWindowType::DROID_EDIT_ASSIGNED_STRUCTURES, SuiListBox::HANDLETWOBUTTON); box->setCallback(new RemoveDroidStructureSuiCallback(player->getZoneServer(), this)); box->setPromptTitle("@pet/droid_modules:droid_maint_edit_title"); // Edit Maintenance List box->setPromptText("@pet/droid_modules:droid_maint_edit_prompt"); // Please select a structure to remove from this droid's maintenance list. box->setOkButton(true, "@delete"); box->setCancelButton(true, "@cancel"); for (int i = 0; i < assignedStructures.size(); i++) { uint64 objectId = assignedStructures.elementAt(i); ManagedReference<SceneObject*> obj = player->getZoneServer()->getObject(objectId); if( obj != NULL && obj->isStructureObject() ){ StructureObject* structureObject = cast<StructureObject*>(obj.get()); if( structureObject != NULL ){ box->addMenuItem( structureObject->getDisplayedName(), objectId ); } } } box->setUsingObject(droid); player->getPlayerObject()->addSuiBox(box); player->sendMessage(box->generateMessage()); } return 0; }