void Player::onAlarmEvent(const Level* l, Vec2 pos) { if (pos == creature->getPosition()) privateMessage("An alarm sounds near you."); else privateMessage("An alarm sounds in the " + getCardinalName((pos - creature->getPosition()).getBearing().getCardinalDir())); }
void Player::hideAction() { if (creature->canHide()) { privateMessage("You hide behind the " + creature->getConstSquare()->getName()); creature->hide(); } else { if (!creature->hasSkill(Skill::ambush)) privateMessage("You don't have this skill."); else privateMessage("You can't hide here."); } }
void Player::itemsMessage() { vector<View::ListElem> names; vector<vector<Item*> > groups; getItemNames(creature->getPickUpOptions(), names, groups); if (names.size() > 1) privateMessage(creature->isBlind() ? "You feel here some items" : "You see here some items."); else if (names.size() == 1) privateMessage((creature->isBlind() ? string("You feel here ") : ("You see here ")) + (groups[0].size() == 1 ? "a " + groups[0][0]->getNameAndModifiers(false, creature->isBlind()) : names[0].getText())); }
void Player::payDebtAction() { for (Vec2 v : Vec2::directions8()) if (const Creature* c = creature->getConstSquare(v)->getCreature()) { if (int debt = c->getDebt(creature)) { vector<Item*> gold = creature->getGold(debt); if (gold.size() < debt) { privateMessage("You don't have enough gold to pay."); } else if (model->getView()->yesOrNoPrompt("Buy items for " + convertToString(debt) + " zorkmids?")) { privateMessage("You pay " + c->getName() + " " + convertToString(debt) + " zorkmids."); creature->give(c, gold); } } else { Debug() << "No debt " << c->getName(); } } }
void Player::chatAction(Optional<Vec2> dir) { vector<const Creature*> creatures; for (Vec2 v : Vec2::directions8()) if (const Creature* c = creature->getConstSquare(v)->getCreature()) creatures.push_back(c); if (creatures.size() == 1 && !dir) { privateMessage("You chat with " + creatures[0]->getTheName()); creature->chatTo(creatures[0]->getPosition() - creature->getPosition()); } else if (creatures.size() > 1 || dir) { if (!dir) dir = model->getView()->chooseDirection("Which direction?"); if (!dir) return; if (const Creature* c = creature->getConstSquare(*dir)->getCreature()) { privateMessage("You chat with " + c->getTheName()); creature->chatTo(*dir); } } }
void Player::grantIdentify(int numItems) { auto unidentFun = [this](const Item* item) { return item->canIdentify() && !item->isIdentified();}; vector<Item*> unIded = creature->getEquipment().getItems(unidentFun); if (unIded.empty()) { privateMessage("All your posessions are already identified"); return; } if (numItems > unIded.size()) { privateMessage("You identify all your posessions"); for (Item* it : unIded) it->identify(); } else for (int i : Range(numItems)) { vector<Item*> items = chooseItem("Choose an item to identify:", unidentFun); if (items.size() == 0) return; items[0]->identify(); privateMessage("You identify " + items[0]->getTheName()); } }
void Player::throwItem(vector<Item*> items, Optional<Vec2> dir) { if (items[0]->getType() == ItemType::AMMO && Options::getValue(OptionId::HINTS)) privateMessage(MessageBuffer::important("To fire arrows equip a bow and use alt + direction key")); if (!dir) { auto cDir = model->getView()->chooseDirection("Which direction do you want to throw?"); if (!cDir) return; dir = *cDir; } tryToPerform(creature->throwItem(items[0], *dir)); }
void Player::applyItem(vector<Item*> items) { if (creature->isBlind() && contains({ItemType::SCROLL, ItemType::BOOK}, items[0]->getType())) { privateMessage("You can't read while blind!"); return; } if (items[0]->getApplyTime() > 1) { for (const Creature* c : creature->getVisibleEnemies()) if ((c->getPosition() - creature->getPosition()).length8() < 3) { if (!model->getView()->yesOrNoPrompt("Applying " + items[0]->getAName() + " takes " + convertToString(items[0]->getApplyTime()) + " turns. Are you sure you want to continue?")) return; else break; } } if (creature->canApplyItem(items[0])) { privateMessage("You " + items[0]->getApplyMsgFirstPerson()); creature->applyItem(items[0]); } }
bool Player::interruptedByEnemy() { vector<const Creature*> enemies = creature->getVisibleEnemies(); vector<string> ignoreCreatures { "a boar" ,"a deer", "a fox", "a vulture", "a rat", "a jackal", "a boulder" }; if (enemies.size() > 0) { for (const Creature* c : enemies) if (!contains(ignoreCreatures, c->getAName())) { model->getView()->refreshView(creature); privateMessage("You notice " + c->getAName()); return true; } } return false; }
void Player::applyAction() { if (!creature->isHumanoid()) return; if (creature->numGoodArms() == 0) { privateMessage("You don't have hands!"); return; } vector<Item*> items = chooseItem("Choose an item to apply:", [this](const Item* item) { return creature->canApplyItem(item);}, ActionId::APPLY_ITEM); if (items.size() == 0) return; applyItem(items); }
void Player::equipmentAction() { if (!creature->isHumanoid()) { privateMessage("You can't use any equipment."); return; } vector<EquipmentSlot> slots; for (auto slot : Equipment::slotTitles) slots.push_back(slot.first); int index = 0; creature->startEquipChain(); while (1) { vector<View::ListElem> list; for (auto slot : slots) { list.push_back(View::ListElem(Equipment::slotTitles.at(slot), View::TITLE)); Item* item = creature->getEquipment().getItem(slot); if (item) list.push_back(item->getNameAndModifiers()); else list.push_back("[Nothing]"); } model->getView()->updateView(creature); Optional<int> newIndex = model->getView()->chooseFromList("Equipment", list, index, View::NORMAL_MENU, nullptr, UserInput::Type::EQUIPMENT); if (!newIndex) { creature->finishEquipChain(); return; } index = *newIndex; EquipmentSlot slot = slots[index]; if (Item* item = creature->getEquipment().getItem(slot)) { tryToPerform(creature->unequip(item)); } else { vector<Item*> items = chooseItem("Choose an item to equip:", [=](const Item* item) { return item->canEquip() && !creature->getEquipment().isEquiped(item) && item->getEquipmentSlot() == slot;}); if (items.size() == 0) { continue; } if (slot == EquipmentSlot::WEAPON && creature->getAttr(AttrType::STRENGTH) < items[0]->getMinStrength() && !model->getView()->yesOrNoPrompt(items[0]->getTheName() + " is too heavy for you, and you will get an accuracy penaulty.\n Do you want to equip it?")) { creature->finishEquipChain(); return; } tryToPerform(creature->equip(items[0])); } } }
void Player::onItemsAppeared(vector<Item*> items, const Creature* from) { if (!creature->pickUp(items)) return; vector<View::ListElem> names; vector<vector<Item*> > groups; getItemNames(items, names, groups); CHECK(!names.empty()); Optional<int> index = model->getView()->chooseFromList("Do you want to take this item?", names); if (!index) { return; } int num = groups[*index].size(); //groups[index].size() == 1 ? 1 : howMany(model->getView(), groups[index].size()); if (num < 1) return; privateMessage("You take " + creature->getPluralName(groups[*index][0], num)); tryToPerform(creature->pickUp(getPrefix(groups[*index], 0, num), false)); }
void QwcPrivateMessager::setSocket(QwcSocket *socket) { if (m_socket) { disconnect(m_socket, 0, this, 0); } m_socket = socket; if (!socket) { return; } // Install new delegate if (fMessageList->itemDelegate()) { delete fMessageList->itemDelegate(); } QwcUserlistDelegate *listDelegate = new QwcUserlistDelegate; listDelegate->setSocket(m_socket); fMessageList->setItemDelegate(listDelegate); connect(m_socket, SIGNAL(userChanged(QwcUserInfo, QwcUserInfo)), this, SLOT(handleUserChanged(QwcUserInfo, QwcUserInfo)) ); connect(m_socket, SIGNAL(userLeftRoom(int, QwcUserInfo)), this, SLOT(handleUserLeft(int, QwcUserInfo))); connect(m_socket, SIGNAL(privateMessage(QwcUserInfo,QString)), this, SLOT(handleNewMessage(QwcUserInfo,QString))); m_socket = socket; }
void Player::travelAction() { if (!creature->canMove(travelDir) || model->getView()->travelInterrupt() || interruptedByEnemy()) { travelling = false; return; } creature->move(travelDir); itemsMessage(); const Location* currentLocation = creature->getLevel()->getLocation(creature->getPosition()); if (lastLocation != currentLocation && currentLocation != nullptr && currentLocation->hasName()) { privateMessage("You arrive at " + addAParticle(currentLocation->getName())); travelling = false; return; } vector<Vec2> squareDirs = creature->getConstSquare()->getTravelDir(); if (squareDirs.size() != 2) { travelling = false; Debug() << "Stopped by multiple routes"; return; } Optional<int> myIndex = findElement(squareDirs, -travelDir); CHECK(myIndex) << "Bad travel data in square"; travelDir = squareDirs[(*myIndex + 1) % 2]; }
void Player::makeMove() { vector<Vec2> squareDirs = creature->getConstSquare()->getTravelDir(); const vector<Creature*>& creatures = creature->getLevel()->getAllCreatures(); if (creature->isAffected(Creature::HALLU)) ViewObject::setHallu(true); else ViewObject::setHallu(false); MEASURE( model->getView()->refreshView(creature), "level render time"); if (Options::getValue(OptionId::HINTS) && displayTravelInfo && creature->getConstSquare()->getName() == "road") { model->getView()->presentText("", "Use ctrl + arrows to travel quickly on roads and corridors."); displayTravelInfo = false; } static bool greeting = false; if (Options::getValue(OptionId::HINTS) && displayGreeting) { CHECK(creature->getFirstName()); model->getView()->presentText("", "Dear " + *creature->getFirstName() + ",\n \n \tIf you are reading this letter, then you have arrived in the valley of " + NameGenerator::worldNames.getNext() + ". There is a band of dwarves dwelling in caves under a mountain. Find them, talk to them, they will help you. Let your sword guide you.\n \n \nYours, " + NameGenerator::firstNames.getNext() + "\n \nPS.: Beware the goblins!"); model->getView()->presentText("", "Every settlement that you find has a leader, and they may have quests for you." "\n \nYou can turn these messages off in the options (press F2)."); displayGreeting = false; model->getView()->refreshView(creature); } for (const Creature* c : creature->getVisibleEnemies()) { if (c->isSpecialMonster() && !contains(specialCreatures, c)) { privateMessage(MessageBuffer::important(c->getDescription())); model->getView()->refreshView(creature); specialCreatures.push_back(c); } } if (travelling) travelAction(); else if (target) targetAction(); else { Action action = model->getView()->getAction(); vector<Vec2> direction; bool travel = false; switch (action.getId()) { case ActionId::FIRE: fireAction(action.getDirection()); break; case ActionId::TRAVEL: travel = true; case ActionId::MOVE: direction.push_back(action.getDirection()); break; case ActionId::MOVE_TO: if (action.getDirection().dist8(creature->getPosition()) == 1) { Vec2 dir = action.getDirection() - creature->getPosition(); if (const Creature* c = creature->getConstSquare(dir)->getCreature()) { if (!creature->isEnemy(c)) { chatAction(dir); break; } } direction.push_back(dir); } else if (action.getDirection() != creature->getPosition()) { target = action.getDirection(); target = Vec2(min(creature->getLevel()->getBounds().getKX() - 1, max(0, target->x)), min(creature->getLevel()->getBounds().getKY() - 1, max(0, target->y))); // Just in case if (!target->inRectangle(creature->getLevel()->getBounds())) target = Nothing(); } else pickUpAction(false); break; case ActionId::SHOW_INVENTORY: displayInventory(); break; case ActionId::PICK_UP: pickUpAction(false); break; case ActionId::EXT_PICK_UP: pickUpAction(true); break; case ActionId::DROP: dropAction(false); break; case ActionId::EXT_DROP: dropAction(true); break; case ActionId::WAIT: creature->wait(); break; case ActionId::APPLY_ITEM: applyAction(); break; case ActionId::THROW: throwAction(); break; case ActionId::THROW_DIR: throwAction(action.getDirection()); break; case ActionId::EQUIPMENT: equipmentAction(); break; case ActionId::HIDE: hideAction(); break; case ActionId::PAY_DEBT: payDebtAction(); break; case ActionId::CHAT: chatAction(); break; case ActionId::SHOW_HISTORY: messageBuffer.showHistory(); break; case ActionId::UNPOSSESS: if (creature->canPopController()) { creature->popController(); return; } break; case ActionId::CAST_SPELL: spellAction(); break; case ActionId::DRAW_LEVEL_MAP: model->getView()->drawLevelMap(creature); break; case ActionId::EXIT: model->exitAction(); break; case ActionId::IDLE: break; } if (creature->isAffected(Creature::SLEEP) && creature->canPopController()) { if (model->getView()->yesOrNoPrompt("You fell asleep. Do you want to leave your minion?")) creature->popController(); return; } for (Vec2 dir : direction) if (travel) { vector<Vec2> squareDirs = creature->getConstSquare()->getTravelDir(); if (findElement(squareDirs, dir)) { travelDir = dir; lastLocation = creature->getLevel()->getLocation(creature->getPosition()); travelling = true; travelAction(); } } else if (creature->canMove(dir)) { creature->move(dir); itemsMessage(); break; } else { const Creature *c = creature->getConstSquare(dir)->getCreature(); if (creature->canBumpInto(dir)) { creature->bumpInto(dir); break; } else if (creature->canDestroy(dir)) { privateMessage("You bash the " + creature->getSquare(dir)->getName()); creature->destroy(dir); break; } } } for (Vec2 pos : creature->getLevel()->getVisibleTiles(creature)) { ViewIndex index = creature->getLevel()->getSquare(pos)->getViewIndex(creature); (*levelMemory)[creature->getLevel()].clearSquare(pos); for (ViewLayer l : { ViewLayer::ITEM, ViewLayer::FLOOR_BACKGROUND, ViewLayer::FLOOR, ViewLayer::LARGE_ITEM}) if (index.hasObject(l)) remember(pos, index.getObject(l)); } }
void Player::onExplosionEvent(const Level* level, Vec2 pos) { if (creature->canSee(pos)) model->getView()->animation(pos, AnimationId::EXPLOSION); else privateMessage("BOOM!"); }
void Player::you(const string& param) const { privateMessage("You " + param); }
// [+] IRainman fix. bool Client::allowPrivateMessagefromUser(const ChatMessage& message) { if (isMe(message.m_replyTo)) { if (UserManager::expectPasswordFromUser(message.m_to->getUser()) #ifdef IRAINMAN_ENABLE_AUTO_BAN || UploadManager::getInstance()->isBanReply(message.m_to->getUser()) // !SMT!-S #endif ) { return false; } else { return true; } } else if (message.thirdPerson && BOOLSETTING(NSL_IGNORE_ME)) { return false; } else if (UserManager::isInIgnoreList(message.m_replyTo->getIdentity().getNick())) // !SMT!-S { return false; } else if (BOOLSETTING(SUPPRESS_PMS)) { #ifdef IRAINMAN_ENABLE_AUTO_BAN if (UploadManager::getInstance()->isBanReply(message.m_replyTo->getUser())) // !SMT!-S { return false; } else #endif if (FavoriteManager::getInstance()->isNoFavUserOrUserIgnorePrivate(message.m_replyTo->getUser())) { if (BOOLSETTING(LOG_IF_SUPPRESS_PMS)) { LocalArray<char, 200> l_buf; snprintf(l_buf.data(), l_buf.size(), CSTRING(LOG_IF_SUPPRESS_PMS), message.m_replyTo->getIdentity().getNick().c_str(), getHubName().c_str(), getHubUrl().c_str()); LogManager::getInstance()->message(l_buf.data()); } return false; } else { return true; } } else if (message.m_replyTo->getIdentity().isHub()) { if (BOOLSETTING(IGNORE_HUB_PMS) && !isInOperatorList(message.m_replyTo->getIdentity().getNick())) { fire(ClientListener::StatusMessage(), this, STRING(IGNORED_HUB_BOT_PM) + ": " + message.m_text); return false; } else if (FavoriteManager::getInstance()->hasIgnorePM(message.m_replyTo->getUser())) { return false; } else { return true; } } else if (message.m_replyTo->getIdentity().isBot()) { if (BOOLSETTING(IGNORE_BOT_PMS) && !isInOperatorList(message.m_replyTo->getIdentity().getNick())) { fire(ClientListener::StatusMessage(), this, STRING(IGNORED_HUB_BOT_PM) + ": " + message.m_text); return false; } else if (FavoriteManager::getInstance()->hasIgnorePM(message.m_replyTo->getUser())) { return false; } else { return true; } } else if (BOOLSETTING(PROTECT_PRIVATE) && !FavoriteManager::getInstance()->hasFreePM(message.m_replyTo->getUser())) // !SMT!-PSW { switch (UserManager::checkPrivateMessagePassword(message)) { case UserManager::FREE: { return true; } case UserManager::WAITING: { return false; } case UserManager::FIRST: { StringMap params; params["pm_pass"] = SETTING(PM_PASSWORD); privateMessage(message.m_replyTo, Util::formatParams(SETTING(PM_PASSWORD_HINT), params, false), false); if (BOOLSETTING(PROTECT_PRIVATE_SAY)) { fire(ClientListener::StatusMessage(), this, STRING(REJECTED_PRIVATE_MESSAGE_FROM) + ": " + message.m_replyTo->getIdentity().getNick()); } return false; } case UserManager::CHECKED: { privateMessage(message.m_replyTo, SETTING(PM_PASSWORD_OK_HINT), true); // TODO needs? // const tstring passwordOKMessage = _T('<') + message.m_replyTo->getUser()->getLastNickT() + _T("> ") + TSTRING(PRIVATE_CHAT_PASSWORD_OK_STARTED); // PrivateFrame::gotMessage(from, to, replyTo, passwordOKMessage, getHubHint(), myPM, pm.thirdPerson); // !SMT!-S return true; } default: // Only for compiler. { dcassert(0); return false; } } } else { if (FavoriteManager::getInstance()->hasIgnorePM(message.m_replyTo->getUser()) #ifdef IRAINMAN_ENABLE_AUTO_BAN || UploadManager::getInstance()->isBanReply(message.m_replyTo->getUser()) // !SMT!-S #endif ) { return false; } else { return true; } } }