bool CooldownMgr::resetCooldown(CooldownType type) { const CooldownPtr& c = cooldown(type); if (!c) { return false; } c->reset(); return true; }
bool CooldownMgr::cancelCooldown(CooldownType type) { const CooldownPtr& c = cooldown(type); if (!c) { return false; } c->cancel(); return true; }
bool CooldownMgr::isCooldown(CooldownType type) { const CooldownPtr& c = cooldown(type); if (!c || !c->running()) { Log::trace("Cooldown of type %i is not running", type); return false; } Log::debug("Cooldown of type %i is running and has a runtime of %lims", type, c->duration()); return true; }
int maxProfit(vector<int>& prices) { if(prices.size() <= 1) return 0; int n = prices.size(); vector<int> sell(n, 0); vector<int> cooldown(n, 0); sell[1] = max(0, prices[1]-prices[0]); for(int i = 2;i < n;i++) { cooldown[i] = max(cooldown[i-1], sell[i-1]); sell[i] = max(cooldown[i-1], sell[i-1]+prices[i]-prices[i-1]); } return max(sell[n-1], cooldown[n-1]); }
bool Action::resolve(Actor* source, Actor* target) const { if (!isUsable(source)) { return false; } if (cooldown().count()) { source->triggerCooldown(identifierHash(), cooldown()); } if (!isOffGlobalCooldown()) { source->triggerGlobalCooldown(); } source->triggerAnimationLock(animationLock()); source->setTP(source->tp() - tpCost() + tpRestoration()); source->setMP(source->mp() - mpCost(source) + mpRestoration(source)); Damage damage; if (this->damage(source, target)) { damage = target->acceptDamage(source->generateDamage(this, target)); } resolution(source, target, damage.isCritical); for (auto& aura : sourceAuras()) { source->applyAura(aura, source); } for (auto& aura : targetAuras()) { target->applyAura(aura, source); } source->integrateDamageStats(damage, identifier().c_str()); return true; }
void Grunt::act(BattleState& state) { cooldown(state); if (m_turnCD <= 0) { m_turnCD = RAND(300, 800) / 1000.f; sf::Vector2f unit = util::getUnitVector(m_pos, state.player->getPos()); m_dir = util::toDir(unit.x, unit.y); float dist = util::getDist(m_pos, state.player->getPos()); if (dist > m_radiusFar) m_vel = m_velMax * sf::Vector2f(unit.x, unit.y); else if (dist < m_radiusClose) m_vel = m_velMax * sf::Vector2f(-unit.x, -unit.y); else m_vel = sf::Vector2f(0, 0); } sf::Vector2f nextPos = m_pos + m_vel * state.elapsed.asSeconds(); if (util::inside(m_pos, state.map) && !util::inside(nextPos, state.map)) m_vel = sf::Vector2f(0, 0); m_pos += m_vel * state.elapsed.asSeconds(); if (m_attackCD <= 0) attack(state); }
std::string special_effect_t::to_string() const { std::ostringstream s; s << name(); s << " type=" << util::special_effect_string( type ); s << " source=" << util::special_effect_source_string( source ); if ( ! trigger_str.empty() ) s << " proc=" << trigger_str; if ( spell_id > 0 ) s << " driver=" << spell_id; if ( trigger() -> ok() ) s << " trigger=" << trigger() -> id(); if ( is_stat_buff() ) { s << " stat=" << util::stat_type_abbrev( stat ); s << " amount=" << stat_amount; s << " duration=" << duration().total_seconds(); if ( tick_time() != timespan_t::zero() ) s << " tick=" << tick_time().total_seconds(); if ( reverse ) s << " Reverse"; } if ( school != SCHOOL_NONE ) { s << " school=" << util::school_type_string( school ); s << " amount=" << discharge_amount; if ( discharge_scaling > 0 ) s << " coeff=" << discharge_scaling; } if ( max_stacks > 0 ) s << " max_stack=" << max_stacks; if ( proc_chance() > 0 ) s << " proc_chance=" << proc_chance() * 100.0 << "%"; if ( ppm() > 0 ) s << " ppm=" << ppm(); if ( rppm() > 0 ) { s << " rppm=" << rppm(); switch ( rppm_scale ) { case RPPM_HASTE: s << " (Haste)"; break; case RPPM_ATTACK_CRIT: s << " (AttackCrit)"; break; case RPPM_SPELL_CRIT: s << " (SpellCrit)"; break; default: break; } } if ( cooldown() > timespan_t::zero() ) { if ( type == SPECIAL_EFFECT_EQUIP ) s << " icd="; else if ( type == SPECIAL_EFFECT_USE ) s << " cd="; else s << " (i)cd="; s << cooldown().total_seconds(); } if ( weapon_proc ) s << " weaponproc"; return s.str(); }
void navigation(void){ int i; IR_Read ir; Data_t data; List_t *list=NULL; ringInit(&list,RINGSIZE); /* Get initial readings */ for(i=0;i<RINGSIZE;i++) { /* Read from IRs */ readIR(&ir); /* Convert to distance */ convertFullDistance(&ir,&data); data.trackState = DEFAULT; /* Push data onto the ring */ ringPush(&list,data); delay(20); } //delay(9000); setSpeed(); i=0; while(1) { if(i>80) { setSpeed(); i=0; } data.trackState = DEFAULT; if(cooldown(list)) turnstate = STRAIGHT; /* Read from IRs */ readIR(&ir); /* Convert to distance */ convertFullDistance(&ir,&data); /* Determine track state */ trackDetection(list,&data); if(analogRead(AIN4)*0.0114 < 10) { digitalWrite(P8_9,HIGH); } else { digitalWrite(P8_9,LOW); } ringPush(&list,data); if(turnstate==FOLLOWRIGHT) { data.turn_angle = right(&data,&list->data); } else if(turnstate==FOLLOWLEFT) { data.turn_angle = left(&data,&list->data); } else if(turnstate==STRAIGHT) { data.turn_angle = straight(&data,&list->data); } /* Update servo */ setSteeringAngle(data.turn_angle); // printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); // printf("Front Left Distance: %f, Front Left Sensor: %d\n",data.frontLeft,ir.FrontLeft); // printf("Front Right Distance: %f, Front Right Sensor: %d\n",data.frontRight,ir.FrontRight); // printf("Back Left Distance: %f, Back Left Sensor: %d\n",data.backLeft,ir.BackLeft); // printf("Back Right Distance: %f, Back Right Sensor: %d\n",data.backRight,ir.BackRight); // printf("Turn angle calculated: %d\n\n",data.turn_angle); delay(60); // if(data.trackState==FOLLOWRIGHT) turn_angle=trackStateHandling; // else printf("Follow left\n"); // printf("Cooldown: %d\n",*cooldown); i+=1; } }
int HeroRingMenuComponent::handleObjectMenuSelect(SceneObject* sceneObject, CreatureObject* player, byte selectedID) const { if (selectedID == 20) { // Restore Life if (!sceneObject->isASubChildOf(player)) return 0; WearableObject* wearable = cast<WearableObject*>(sceneObject); if (wearable == NULL) return 0; HeroRingDataComponent* data = cast<HeroRingDataComponent*>(wearable->getDataObjectComponent()->get()); if (data == NULL || !data->isHeroRingData()) return 0; int charges = data->getCharges(); if (charges <= 0) return 0; if (!wearable->isEquipped()) { player->sendSystemMessage("@quest/hero_of_tatooine/system_messages:restore_not_equipped"); return 0; } if (!player->isDead()) { player->sendSystemMessage("@quest/hero_of_tatooine/system_messages:restore_not_dead"); return 0; } if (!player->checkCooldownRecovery("mark_of_hero")) { Time* timeRemaining = player->getCooldownTime("mark_of_hero"); StringIdChatParameter cooldown("quest/hero_of_tatooine/system_messages", "restore_not_yet"); cooldown.setTO(getCooldownString(timeRemaining->miliDifference() * -1)); player->sendSystemMessage(cooldown); return 0; } player->healDamage(player, CreatureAttribute::HEALTH, 200); player->healDamage(player, CreatureAttribute::ACTION, 200); player->healDamage(player, CreatureAttribute::MIND, 200); data->setCharges(charges - 1); String hardpoint = ""; if (player->getSlottedObject("ring_r") != NULL && player->getSlottedObject("ring_r")->getObjectID() == sceneObject->getObjectID()) hardpoint = "hold_r"; else if (player->getSlottedObject("ring_l") != NULL && player->getSlottedObject("ring_l")->getObjectID() == sceneObject->getObjectID()) hardpoint = "hold_l"; PlayClientEffectObjectMessage* effect = new PlayClientEffectObjectMessage(player, "clienteffect/item_ring_hero_mark.cef", hardpoint); player->broadcastMessage(effect, false); player->sendSystemMessage("@quest/hero_of_tatooine/system_messages:restore_msg"); player->addCooldown("mark_of_hero", 23 * 3600 * 1000); // 23 hours return 0; } else { return TangibleObjectMenuComponent::handleObjectMenuSelect(sceneObject, player, selectedID); } }
void Sprinkler::act(BattleState& state) { Actor::act(state); cooldown(state); if (m_attack_cd <= 0) attack(state); }
bool Action::isReady(const Actor* source) const { if (cooldown().count() && source->cooldownRemaining(identifierHash()).count()) { return false; } return requirements(source); }
int main(int argc, char **argv) { int k, j, kmax; proxel *currproxel; double val, z, valhpm, vallpm; int s, tau1k, tau2k; /* initialise the simulation */ root[0] = NULL; root[1] = NULL; eerror = 0.0; totcnt = 0; maxccp = 0; double tmax = ENDTIME; dt = DELTA; e = EMISSION; if (e) { printf("Using Symbol Emission...\n\n"); } else { printf("No Symbol Emission...\n\n"); } kmax = (int)floor(tmax / dt + 0.5); TAUMAX = kmax; /* initialize the solution vector for each time step */ for (k = 0; k < 3; k++) { y[k] = malloc(sizeof(double) * (kmax + 2)); for (j = 0; j < kmax + 2; j++) y[k][j] = 0.0; } if (e) { for (k = 0; k < 3; k++) { /* rows */ em[k] = malloc(sizeof(double) * 2); for (j = 0; j < 2; j++) { /* cols */ em[k][j] = 0.0; } } em[HPM][WP] = 0.95; em[HPM][DP] = 0.05; em[LPM][WP] = 0.8; em[LPM][DP] = 0.2; printf("Emission Matrix:\nHPM->WP: %11.10f\nHPM->DP: %11.10f\nLPM->WP: %11.10f\nLPM->DP: %11.10f\n\n", em[HPM][WP], em[HPM][DP], em[LPM][WP], em[LPM][DP]); /* initialize the emission sum vector */ for (k = 0; k < 2; k++) { /* cols */ emsum[k] = malloc(sizeof(double) * (kmax + 2)); for (j = 0; j < kmax + 2; j++) { emsum[k][j] = 0.0; } } /* initialize the emission sequence */ emsequence = malloc(sizeof(int) * (kmax + 2)); for (k = 1; k < kmax + 2; ++k) { if (k % 2 == 0) { emsequence[k] = WP; } else { emsequence[k] = DP; } emsequence[k] = WP; } printemissionsequence(kmax); /* initialize the most likely paths */ for (k = 0; k < 5; k++) { empaths[k] = malloc(sizeof(int) * (kmax + 2)); for (j = 0; j < kmax + 2; j++) empaths[k][j] = 0; } } /* set initial proxel */ addproxel(HPM, 0, 0, 1.0); /* first loop: iteration over all time steps*/ /* current model time is k*dt */ for (k = 1; k < kmax + 2; k++) { /* print progress information if (k % 100 == 0) { printf("Step %d\n", k); printf("Size of tree %d\n", size(root[sw])); } */ sw = 1 - sw; /* second loop: iterating over all proxels of a time step */ while (root[1 - sw] != NULL) { totcnt++; currproxel = getproxel(); while ((currproxel->val < MINPROB) && (root[1 - sw] != NULL)) { val = currproxel->val; eerror += val; currproxel = getproxel(); } val = currproxel->val; tau1k = currproxel->tau1k; tau2k = currproxel->tau2k; s = currproxel->s; y[s][k - 1] += val; /* create child proxels */ switch (s) { case HPM: /* probability to overheat the machine */ z = dt * overheat(tau1k*dt); if (z < 1.0) { if (e) { vallpm = emission(k, s, LPM, val*z, emsequence[k]); valhpm = emission(k, s, HPM, val*(1 - z), emsequence[k]); } else { vallpm = val*z; valhpm = val*(1 - z); } addproxel(LPM, 0, 0, vallpm); addproxel(HPM, tau1k + 1, 0, valhpm); } else { if (e) { vallpm = emission(k, s, LPM, val, emsequence[k]); } else { vallpm = val; } addproxel(LPM, 0, 0, vallpm); } break; case LPM: /* probability to cooldown the machine */ z = dt * cooldown(tau1k*dt); if (z < 1.0) { if (e) { valhpm = emission(k, s, HPM, val*z, emsequence[k]); vallpm = emission(k, s, LPM, val*(1 - z), emsequence[k]); } else { valhpm = val*z; vallpm = val*(1 - z); } addproxel(HPM, 0, 0, valhpm); addproxel(LPM, tau1k + 1, 0, vallpm); } else { if (e) { valhpm = emission(k, s, HPM, val, emsequence[k]); } else { valhpm = val; } addproxel(HPM, 0, 0, valhpm); } break; default: printf("something went wrong!"); break; } } } /* printf("\n"); printtree(root[sw]); printf("\n"); */ plotsolution(kmax); printf("Tree Size = %d\n", size(root[sw])); printf("Proxels (Max Concurrent) = %d\n", maxccp); printf("Proxels (Total) = %d\n", totcnt); printf("Leafs (Total) = %i\n", countleafs(root[sw])); printf("Accumulated Error = %7.5le\n", eerror); printf("\n"); // last carriage return before exit return(0); }
void trackDetection(List_t *list, Data_t * data) { /* Look for Y fork */ if(cooldown(list)) { setForkLEDLow(); setMergeLEDLow(); } // setCarSpeed(0); // setForkLEDHigh(); // delay(10000); // setMergeLEDLow(); // setCarSpeed(CARSPEED); if(gradient(list,data,3) && gradient(list,data,4)) { /* Y fork confirmed */ // printf("Y fork found\n"); setForkLEDHigh(); /* Consult the index */ if(cooldown(list)) { //setCarSpeed(0); if(alternate==0) { alternate = 1; turnstate = FOLLOWRIGHT; } else { alternate = 0; turnstate = FOLLOWLEFT; } } data->trackState = FORK; } if(gradient(list,data,2)) { setMergeLEDHigh(); if(cooldown(list)) { turnstate = FOLLOWLEFT; } data->trackState = MERGERIGHT; } if(gradient(list,data,1)) { setMergeLEDHigh(); if(cooldown(list)) { turnstate = FOLLOWRIGHT; } data->trackState = MERGELEFT; } /* Look at the right side for merges and forks */ // if(isMuchLarger(data->frontRight,data->backRight) && data->frontRight > 33 && // !isMuchLarger(data->frontLeft,data->backLeft)) // { // if(checkGradientRight(list,data)&& data->frontRight > 33) // { // /* If the gradient is large, then assume Merge */ // // printf("Right Merge\n"); // if(cooldown(list)) turnstate = FOLLOWLEFT; // // setMergeLEDHigh(); // // fp = fopen("forkResults.txt","a+"); // // fprintf(fp,"Right merge detected!\n"); // // fprintf(fp,"front left = %f, front right = %f\n",data->frontLeft,data->frontRight); // // fprintf(fp,"back left = %f, back right = %f\n\n",data->backLeft,data->backRight); // // fclose(fp); // // data->trackState = MERGERIGHT; // // setCarSpeed(0); // // setMergeLEDHigh(); // // delay(10000); // // setMergeLEDLow(); // // setCarSpeed(CARSPEED); // // } // else if(isMuchLarger(list->data.frontRight,list->data.backRight) && // isRoughlyEqual(list->data.frontLeft,list->data.backLeft) && // isRoughlyEqual(data->frontLeft,data->backLeft) && // data->frontLeft < 18 && data->backLeft < 18 && // data->frontLeft > data->backLeft) // { // /* If the previous set of right distances were also // much larger, then assume a right fork */ // // printf("Straight Right Fork\n"); // /* Consult the index */ // if(cooldown(list)) // { // if(alternate==0) // { // alternate = 1; // turnstate = FOLLOWRIGHT; // } // else // { // alternate = 0; // turnstate = FOLLOWLEFT; // } // setForkLEDHigh(); // } // // // fp = fopen("forkResults.txt","a+"); // // fprintf(fp,"Right fork detected!\n"); // // fprintf(fp,"front left = %f, front right = %f\n",data->frontLeft,data->frontRight); // // fprintf(fp,"back left = %f, back right = %f\n\n",data->backLeft,data->backRight); // // fclose(fp); // // // data->trackState = RIGHTFORK; // // setCarSpeed(0); // // setForkLEDHigh(); // // delay(10000); // // setForkLEDLow(); // // setCarSpeed(CARSPEED); // // } // } // /* Look at the left side for merges or forks */ // else if(isMuchLarger(data->frontLeft,data->backLeft) && data->frontLeft > 33 && // !isMuchLarger(data->frontRight,data->backRight)) // { // if(checkGradientLeft(list,data) && data->frontLeft > 33) // { // /* If the gradient is large, then assume Merge */ // // printf("Left Merge\n"); // setMergeLEDHigh(); // // fp = fopen("forkResults.txt","a+"); // // fprintf(fp,"Left merge detected!\n"); // // fprintf(fp,"front left = %f, front right = %f\n",data->frontLeft,data->frontRight); // // fprintf(fp,"back left = %f, back right = %f\n\n",data->backLeft,data->backRight); // // fclose(fp); // turnstate = FOLLOWRIGHT; // // data->trackState = MERGELEFT; // // setMergeLEDHigh(); // // setCarSpeed(0); // // delay(10000); // // setMergeLEDLow(); // // setCarSpeed(CARSPEED); // // } // else if(isMuchLarger(list->data.frontLeft,list->data.backLeft) && // isRoughlyEqual(list->data.frontRight,list->data.backRight) && // isRoughlyEqual(data->frontRight,data->backRight) && // data->frontRight < 18 && data->frontRight < 18 && // data->frontRight > data->backRight) // { // /* If the previous set of right distances were also // much larger, then assume a left fork */ // // printf("Straight Left Fork\n"); // /* Consult the index */ // if(cooldown(list)) // { // if(alternate==0) // { // alternate = 1; // turnstate = FOLLOWRIGHT; // } // else // { // alternate = 0; // turnstate = FOLLOWLEFT; // } // data->trackState = LEFTFORK; // } // // // // fp = fopen("forkResults.txt","a+"); // // fprintf(fp,"Left fork detected!\n"); // // fprintf(fp,"front left = %f, front right = %f\n",data->frontLeft,data->frontRight); // // fprintf(fp,"back left = %f, back right = %f\n\n",data->backLeft,data->backRight); // // fclose(fp); // // setForkLEDHigh(); // // // setForkLEDHigh(); // // setCarSpeed(0); // // delay(10000); // // setForkLEDLow(); // // setCarSpeed(CARSPEED); // // } // } }