void VendorDataComponent::handleWithdrawMaintanence(int value) { ManagedReference<SceneObject*> strongParent = parent.get(); if (strongParent == NULL || strongParent->getZoneServer() == NULL) return; ManagedReference<CreatureObject*> owner = strongParent->getZoneServer()->getObject(getOwnerId()).castTo<CreatureObject*>(); if(owner == NULL) return; if(value > maintAmount) { StringIdChatParameter message("@player_structure:vendor_withdraw_fail"); // The vendor maintenance pool doesn't have %DI credits! message.setDI(value); owner->sendSystemMessage(message); return; } if(value <= 0) { owner->sendSystemMessage("@player_structure:amt_greater_than_zero"); // The amount must be greater than zero. return; } maintAmount -= value; owner->addBankCredits(value, true); StringIdChatParameter message("@player_structure:vendor_withdraw"); // You successfully withdraw %DI credits from the maintenance pool. message.setDI(value); owner->sendSystemMessage(message); }
SingleFoodData SingleFoodImpl::serialize() const { SingleFoodData sfdata; sfdata.set_id(id); sfdata.set_name(getName().toStdString()); sfdata.set_ownerid(getOwnerId()); sfdata.set_entrysource(static_cast<SingleFoodData::EntrySource>(entrySource)); sfdata.set_groupid(group->getId().toStdString()); sfdata.set_percentrefuse(percentRefuse); sfdata.set_refusedescription(refuseDescription.toStdString()); for (QMap<QString, NutrientAmount>::const_iterator i = nutrients.begin(); i != nutrients.end(); ++i) { SingleFoodData_NutrientAmount* namt = sfdata.add_nutrientamounts(); namt->set_nutrientid(i.value().getNutrient()->getId().toStdString()); namt->set_amount(i.value().getAmount()); namt->set_unitabbreviation(i.value().getUnit()->getAbbreviation().toStdString()); } sfdata.set_weightamount(getBaseAmount(Unit::Dimensions::Weight).getAmount()); sfdata.set_volumeamount(getBaseAmount(Unit::Dimensions::Volume).getAmount()); sfdata.set_quantityamount(getBaseAmount(Unit::Dimensions::Quantity).getAmount()); sfdata.set_servingamount(getBaseAmount(Unit::Dimensions::Serving).getAmount()); sfdata.set_energydensityfat(calorieDensities[Nutrient::FAT_NAME]); sfdata.set_energydensityprotein(calorieDensities[Nutrient::PROTEIN_NAME]); sfdata.set_energydensitycarbohydrate(calorieDensities[Nutrient::CARBOHYDRATE_NAME]); sfdata.set_energydensityalcohol(calorieDensities[Nutrient::ALCOHOL_NAME]); return sfdata; }
void VendorDataComponent::withdrawMaintanence() { ManagedReference<SceneObject*> strongParent = parent.get(); if (strongParent == NULL || strongParent->getZoneServer() == NULL) return; ManagedReference<CreatureObject*> owner = strongParent->getZoneServer()->getObject(getOwnerId()).castTo<CreatureObject*>(); if(owner == NULL) return; ManagedReference<SuiInputBox*> input = new SuiInputBox(owner, SuiWindowType::STRUCTURE_VENDOR_WITHDRAW); input->setPromptTitle("@player_structure:withdraw_vendor_t"); //Add Militia Member input->setPromptText("@player_structure:withdraw_vendor_d"); input->setUsingObject(strongParent); input->setForceCloseDistance(5.f); input->setCallback(new VendorMaintSuiCallback(strongParent->getZoneServer())); owner->getPlayerObject()->addSuiBox(input); owner->sendMessage(input->generateMessage()); }
float VendorDataComponent::getMaintenanceRate() { ManagedReference<SceneObject*> strongParent = parent.get(); if (strongParent == NULL || strongParent->getZoneServer() == NULL) return 15.f; // 15 credits base maintenance float maintRate = 15.f; // Apply reduction for merchant skills ManagedReference<CreatureObject*> owner = strongParent->getZoneServer()->getObject(getOwnerId()).castTo<CreatureObject*>(); if (owner != NULL && owner->isPlayerCreature() ) { if(owner->hasSkill("crafting_merchant_master")) maintRate *= .60f; else if(owner->hasSkill("crafting_merchant_sales_02")) maintRate *= .80f; } // Additional 6 credits per hour to be registered on the map if(registered) maintRate += 6.f; return maintRate; }
void VendorDataComponent::handlePayMaintanence(int value) { ManagedReference<SceneObject*> strongParent = parent.get(); if (strongParent == NULL || strongParent->getZoneServer() == NULL) return; ManagedReference<CreatureObject*> owner = strongParent->getZoneServer()->getObject(getOwnerId()).castTo<CreatureObject*>(); if(owner == NULL) return; if(value > 100000) { owner->sendSystemMessage("@player_structure:vendor_maint_invalid"); return; } if(value <= 0) { owner->sendSystemMessage("@player_structure:amt_greater_than_zero"); return; } if(owner->getBankCredits() + owner->getCashCredits() >= value) { maintAmount += value; if(owner->getBankCredits() > value) { owner->subtractBankCredits(value); } else { owner->subtractCashCredits(value - owner->getBankCredits()); owner->subtractBankCredits(owner->getBankCredits()); } StringIdChatParameter message("@player_structure:vendor_maint_accepted"); message.setDI(maintAmount); owner->sendSystemMessage(message); } else { owner->sendSystemMessage("@player_structure:vendor_maint_denied"); } }
void VendorDataComponent::runVendorUpdate() { ManagedReference<SceneObject*> strongParent = parent.get(); if (strongParent == NULL || strongParent->getZoneServer() == NULL) return; ManagedReference<CreatureObject*> owner = strongParent->getZoneServer()->getObject(getOwnerId()).castTo<CreatureObject*>(); ManagedReference<PlayerManager*> playerManager = strongParent->getZoneServer()->getPlayerManager(); ManagedReference<TangibleObject*> vendor = cast<TangibleObject*>(strongParent.get()); if (owner == NULL || !owner->isPlayerCreature() || playerManager == NULL || vendor == NULL) { return; } scheduleVendorCheckTask(VENDORCHECKINTERVAL); removeAllVendorBarks(); int now = time(0); int last = lastSuccessfulUpdate.getTime(); float hoursSinceLastUpdate = now - last; hoursSinceLastUpdate /= 3600.f; if (maintAmount > 0) inactiveTimer.updateToCurrentTime(); /// parent salaries Locker vlocker(owner, vendor); maintAmount -= getMaintenanceRate() * hoursSinceLastUpdate; if (maintAmount < 0) { vendor->setConditionDamage(-maintAmount, true); } else { vendor->setConditionDamage(0, true); vendor->setMaxCondition(1000, true); } if (isEmpty()) { ManagedReference<ChatManager*> cman = strongParent->getZoneServer()->getChatManager(); String sender = strongParent->getDisplayedName(); UnicodeString subject("@auction:vendor_status_subject"); if (!mail1Sent && time(0) - emptyTimer.getTime() > FIRSTWARNING) { StringIdChatParameter body("@auction:vendor_status_unaccessed"); body.setTO(strongParent->getDisplayedName()); if (cman != NULL) cman->sendMail(sender, subject, body, owner->getFirstName()); mail1Sent = true; } else if (!mail2Sent && time(0) - emptyTimer.getTime() > SECONDWARNING) { StringIdChatParameter body("@auction:vendor_status_endangered"); body.setTO(strongParent->getDisplayedName()); if (cman != NULL) cman->sendMail(sender, subject, body, owner->getFirstName()); mail2Sent = true; } else if (time(0) - emptyTimer.getTime() > EMPTYDELETE) { StringIdChatParameter body("@auction:vendor_status_deleted"); if (cman != NULL) cman->sendMail(sender, subject, body, owner->getFirstName()); VendorManager::instance()->destroyVendor(vendor); vendorCheckTask->cancel(); return; } } else { mail1Sent = false; mail2Sent = false; emptyTimer.updateToCurrentTime(); } if (isOnStrike()) { if (isRegistered()) VendorManager::instance()->handleUnregisterVendor(owner, vendor); if (isVendorSearchEnabled()) setVendorSearchEnabled(false); if (time(0) - inactiveTimer.getTime() > DELETEWARNING) { ManagedReference<ChatManager*> cman = strongParent->getZoneServer()->getChatManager(); String sender = strongParent->getDisplayedName(); UnicodeString subject("@auction:vendor_status_subject"); StringIdChatParameter body("@auction:vendor_status_deleted"); if (cman != NULL) cman->sendMail(sender, subject, body, owner->getFirstName()); VendorManager::instance()->destroyVendor(vendor); vendorCheckTask->cancel(); } } else { /// Award hourly XP assert(vendor->isLockedByCurrentThread()); Locker locker(owner, vendor); playerManager->awardExperience(owner, "merchant", 150 * hoursSinceLastUpdate, false); playerManager->awardExperience(owner, "merchant", awardUsageXP * 50, false); } awardUsageXP = 0; lastSuccessfulUpdate.updateToCurrentTime(); }
void World::addedToEntity() { { std::random_device dev; std::uniform_int_distribution<int> rand(0, 3); std::uniform_real_distribution<float> randAng(0, 360); sf::RenderTexture render; auto size = std::min(sf::Texture::getMaximumSize(), 1024U); render.create(size, size); sf::Sprite sprite(Resources::Texture_Ground); sprite.setTextureRect(mSheet.getRect(0, 0)); sprite.setOrigin(sprite.getTextureRect().width / 2, sprite.getTextureRect().height / 2); sprite.setPosition(sprite.getTextureRect().width / 2, sprite.getTextureRect().height / 2); sprite.rotate(90); for (int x = 0; x <= size;) { for (int y = 0; y <= size;) { sprite.setTextureRect(mSheet.getRect(rand(dev)%2, rand(dev) % 2)); sprite.setRotation(rand(dev) * 90); render.draw(sprite); if (randAng(dev) > 300) { sprite.setTextureRect(mSheet.getRect(2 + rand(dev) % 2, rand(dev) % 2)); sprite.setRotation(randAng(dev)); render.draw(sprite); } sprite.move(0, sprite.getTextureRect().height); y += sprite.getTextureRect().height; } sprite.setPosition(sprite.getPosition().x, 0); sprite.move(sprite.getTextureRect().width, 0); x += sprite.getTextureRect().width; } render.display(); mBigOne = render.getTexture(); } requestMessage("Event.Update", [this](const Kunlaboro::Message& msg) { static float timer = 0; float dt = boost::any_cast<float>(msg.payload); timer += dt; if (timer > 1) { timer = 0; std::list<Enemy*> list; sendGlobalMessage("Would the real slim shady please stand up?", &list); if (list.size() < 15) { auto& sys = *getEntitySystem(); auto ent = sys.createEntity(); sys.addComponent(ent, "Game.Enemy"); sys.addComponent(ent, "Game.Weapon"); } } }); requestMessage("Event.Draw", [this](const Kunlaboro::Message& msg) { auto& target = *std::get<0>(boost::any_cast<std::tuple<sf::RenderTarget*,float>>(msg.payload)); sf::Vector2f vC = target.getView().getCenter(), vS = (sf::Vector2f)mBigOne.getSize(), vS2 = target.getView().getSize(); //vC += vS/2.f; sf::Vector2i centerPos = sf::Vector2i(vC.x / vS.x, vC.y / vS.x); sf::Sprite sprite(mBigOne); sprite.setOrigin((sf::Vector2f)mBigOne.getSize() / 2.f); sprite.setPosition(centerPos.x * vS.x, centerPos.y * vS.y); int xRes = vS2.x / vS.x + 1; int yRes = vS2.y / vS.y + 1; for (int x = -xRes; x <= xRes; ++x) { for (int y = -yRes; y <= yRes; ++y) { sprite.setPosition((centerPos.x + x) * vS.x, (centerPos.y + y) * vS.y); target.draw(sprite); } } }); changeRequestPriority("Event.Draw", -9001); requestMessage("I'm ending this!", [this](const Kunlaboro::Message& msg) { getEntitySystem()->destroyEntity(getOwnerId()); }); requestMessage("Did I accidentally all the stats?", [this](Kunlaboro::Message& msg) { msg.handled = true; msg.payload = mStats; }); ///< No, no you didn't. requestMessage("I am bullet!", [this](const Kunlaboro::Message&) { mStats.ShotsFired++; }); requestMessage("I am bullethole!", [this](const Kunlaboro::Message&) { mStats.ShotsHit++; }); requestMessage("Is dead now", [this](const Kunlaboro::Message& msg) { if (boost::any_cast<bool>(msg.payload)) mStats.EnemiesDeadByPlayer++; else mStats.EnemiesDead++; }); requestMessage("Demon Speeding", [this](const Kunlaboro::Message& msg) { float s = boost::any_cast<float>(msg.payload); mStats.MaxSpeed = std::max(mStats.MaxSpeed, s); }); requestMessage("Road to Rouen", [this](const Kunlaboro::Message& msg) { float s = boost::any_cast<float>(msg.payload); mStats.DistanceTraveled += s; }); }