Skip to content

Instantly share code, notes, and snippets.

@WideWord
Last active December 16, 2015 12:19
Show Gist options
  • Select an option

  • Save WideWord/5433674 to your computer and use it in GitHub Desktop.

Select an option

Save WideWord/5433674 to your computer and use it in GitHub Desktop.
if (cmd.checkCommand("/inv")) {
std::stringstream msg;
Inventory* inv = player->inventory;
if (inv->things.empty()) {
player->showDialog(DialogStyle::msgbox, "Инвентарь", "Ваш инвентарь пуст!", "Закрыть", "Закрыть",
[](bool response, int listitem, std::string inputtext){});
} else {
std::vector<std::string> playerThingsNames;
for (auto it = inv->things.begin(); it != inv->things.end(); ++it) {
if (it->second > 0) msg << thingsNames[it->first] << "\t" << it->second;
playerThingsNames.push_back(it->first);
}
player->showDialog(DialogStyle::list, "Инвентарь", msg.str(), "Использовать", "Закрыть",
[player, playerThingsNames](bool response, int itemid, std::string inputtext){
if (!response) return;
std::string itemname = playerThingsNames[itemid];
player->showDialog(DialogStyle::list, "Инвентарь", "Использовать\nПодать/передать\nПоложить в хранилище\nВыбросить", "ОК", "Назад",
[player, itemid, itemname](bool response, int listitem, std::string inputtext){
if (!response) {
player->callCommand("/inv");
return;
}
if (listitem == 0) {
useThing(player, itemname);
} else if (listitem == 1) { // продажа
player->showDialog(DialogStyle::input, "Продать/передать", "Введите id или часть имени игрока", "OK", "Назад",
[player, itemid, itemname](bool response, int listitem, std::string inputtext){
Player* op = Player::get(inputtext);
if (!op) {
player->sendClientMessage(0xCCCCCCFF, "Игрок не найден");
player->callCommand("/inv");
return;
}
int opid = op->id;
player->showDialog(DialogStyle::input, "Продать/передать", "Введите количество", "OK", "Назад",
[player, itemid, opid, itemname](bool response, int listitem, std::string inputtext){
if (!isInt64(inputtext)) {
player->sendClientMessage(0xCCCCCCFF, "Неверное количество");
return;
}
int count = atoi(inputtext.c_str());
if (count > player->inventory->things[itemname] || count < 1) {
player->sendClientMessage(0xCCCCCCFF, "У вас нет такого количества");
return;
}
player->showDialog(DialogStyle::input, "Продать/передать", "Введите цену", "OK", "Назад",
[player, itemid, opid, itemname, count](bool response, int listitem, std::string inputtext){
if (!isInt64(inputtext)) {
player->sendClientMessage(0xCCCCCCFF, "Неверная цена");
return;
}
int price = atoi(inputtext.c_str());
int playerid = player->id;
Player* op = Player::get(opid);
if (!op) {
player->sendClientMessage(0xCCCCCCFF, "Игрок вышел!");
return;
}
op->showDialog(DialogStyle::msgbox, "Продать/передать",
MakeString() << player->getNameid() << "{FFFFFF} хочет отдать вам {FF0000}" << getThingName(itemname) << "{FFFFFF} за {00FFFF}$" << price
, "Взять", "Не брать",
[playerid, itemid, op, itemname, count, price](bool response, int listitem, std::string inputtext){
Player* player = Player::get(playerid);
if (!player) return;
if (!response) {
player->sendClientMessage(0xFFFFFFFF, "Игрок отказался");
return;
} else {
if (op->money < price) {
player->sendClientMessage(0xCCCCCCFF, "Не хватило денег");
op->sendClientMessage(0xCCCCCCFF, "Нехватает денег");
return;
}
{
float x, y, z;
float ox, oy, oz;
player->getPos(x, y, z);
op->getPos(ox, oy, oz);
if (fakeDist(x, y, z, ox, oy, oz) < 2.0f) {
op->sendClientMessage(0xCCCCCCFF, "Вы слишком далеко");
player->sendClientMessage(0xCCCCCCFF, "Вы слишком далеко");
return;
}
}
op->giveMoney(-price);
player->giveMoney(price);
player->inventory->things[itemname] -= count;
if (op->inventory->things.find(itemname) == op->inventory->things.end())
op->inventory->things[itemname] = count;
else
op->inventory->things[itemname] += count;
player->emitMessage(COLOR_DO, 5.0f, MakeString() << "* " << player->getName() << " что то передал " << op->getName());
}
});
});
});
});
} else if (listitem == 2) { //положить в хранилище
} else if (listitem == 3) { // выбрость
}
});
});
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment