1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00
This commit is contained in:
Laserlicht 2024-05-01 01:26:51 +02:00
parent e505aab29a
commit 5413fc2c7e
3 changed files with 26 additions and 15 deletions

View File

@ -126,6 +126,12 @@
"vcmi.lobby.mod.state.version" : "Version mismatch",
"vcmi.lobby.mod.state.excessive" : "Must be disabled",
"vcmi.lobby.mod.state.missing" : "Not installed",
"vcmi.lobby.pvp.coin.hover" : "Coin",
"vcmi.lobby.pvp.coin.help" : "Flips a coin",
"vcmi.lobby.pvp.randomTown.hover" : "Random town",
"vcmi.lobby.pvp.randomTown.help" : "Write a random city in the chat",
"vcmi.lobby.pvp.randomTownVs.hover" : "Random town vs.",
"vcmi.lobby.pvp.randomTownVs.help" : "Write two random cities in the chat",
"vcmi.client.errors.invalidMap" : "{Invalid map or campaign}\n\nFailed to start game! Selected map or campaign might be invalid or corrupted. Reason:\n%s",
"vcmi.client.errors.missingCampaigns" : "{Missing data files}\n\nCampaigns data files were not found! You may be using incomplete or corrupted Heroes 3 data files. Please reinstall game data.",

View File

@ -413,28 +413,33 @@ PvPBox::PvPBox(const Rect & rect)
return bannedTowns;
};
buttonFlipCoin = std::make_shared<CButton>(Point(190, 6), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("flip coin"), [](){
auto buttonColor = CSH->isGuest() ? Colors::WHITE : Colors::ORANGE;
buttonFlipCoin = std::make_shared<CButton>(Point(190, 6), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.pvp.coin.help")), [](){
LobbyPvPAction lpa;
lpa.action = LobbyPvPAction::COIN;
CSH->sendLobbyPack(lpa);
}, EShortcut::NONE);
buttonFlipCoin->setTextOverlay("Flip coin2", EFonts::FONT_SMALL, Colors::WHITE);
buttonFlipCoin->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.coin.hover"), EFonts::FONT_SMALL, buttonColor);
buttonFlipCoin->block(!CSH->isGuest());
buttonRandomTown = std::make_shared<CButton>(Point(190, 31), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("random town"), [getBannedTowns](){
buttonRandomTown = std::make_shared<CButton>(Point(190, 31), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.pvp.randomTown.help")), [getBannedTowns](){
LobbyPvPAction lpa;
lpa.action = LobbyPvPAction::RANDOM_TOWN;
lpa.bannedTowns = getBannedTowns();
CSH->sendLobbyPack(lpa);
}, EShortcut::NONE);
buttonRandomTown->setTextOverlay("random town", EFonts::FONT_SMALL, Colors::WHITE);
buttonRandomTown->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.randomTown.hover"), EFonts::FONT_SMALL, buttonColor);
buttonRandomTown->block(!CSH->isGuest());
buttonRandomTownVs = std::make_shared<CButton>(Point(190, 56), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("random town vs"), [getBannedTowns](){
buttonRandomTownVs = std::make_shared<CButton>(Point(190, 56), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.pvp.randomTownVs.help")), [getBannedTowns](){
LobbyPvPAction lpa;
lpa.action = LobbyPvPAction::RANDOM_TOWN_VS;
lpa.bannedTowns = getBannedTowns();
CSH->sendLobbyPack(lpa);
}, EShortcut::NONE);
buttonRandomTownVs->setTextOverlay("random town vs", EFonts::FONT_SMALL, Colors::WHITE);
buttonRandomTownVs->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.randomTownVs.hover"), EFonts::FONT_SMALL, buttonColor);
buttonRandomTownVs->block(!CSH->isGuest());
}
FactionSelector::FactionSelector(const Point & loc)

View File

@ -372,32 +372,32 @@ void ApplyOnServerNetPackVisitor::visitLobbyForceSetPlayer(LobbyForceSetPlayer &
void ApplyOnServerNetPackVisitor::visitLobbyPvPAction(LobbyPvPAction & pack)
{
std::vector<FactionID> allowedFactions;
std::vector<FactionID> allowedTowns;
VLC->townh->forEach([pack, &allowedFactions](const Faction *entity, bool &stop){
VLC->townh->forEach([pack, &allowedTowns](const Faction *entity, bool &stop){
if(!entity->hasTown())
return;
if(std::find(pack.bannedTowns.begin(), pack.bannedTowns.end(), entity->getId()) == pack.bannedTowns.end()) {
allowedFactions.push_back(entity->getId());
allowedTowns.push_back(entity->getId());
}
});
std::vector<FactionID> randomFaction1;
std::sample(allowedFactions.begin(), allowedFactions.end(), std::back_inserter(randomFaction1), 1, std::mt19937{std::random_device{}()});
std::sample(allowedTowns.begin(), allowedTowns.end(), std::back_inserter(randomFaction1), 1, std::mt19937{std::random_device{}()});
std::vector<FactionID> randomFaction2;
std::sample(allowedFactions.begin(), allowedFactions.end(), std::back_inserter(randomFaction2), 1, std::mt19937{std::random_device{}()});
std::sample(allowedTowns.begin(), allowedTowns.end(), std::back_inserter(randomFaction2), 1, std::mt19937{std::random_device{}()});
switch(pack.action) {
case LobbyPvPAction::COIN:
srv.announceTxt("Coin - " + std::to_string(std::rand()%2));
break;
case LobbyPvPAction::RANDOM_TOWN:
if(allowedFactions.size())
srv.announceTxt("Faction - " + VLC->townh->getById(randomFaction1[0])->getNameTranslated());
if(allowedTowns.size())
srv.announceTxt("Town - " + VLC->townh->getById(randomFaction1[0])->getNameTranslated());
break;
case LobbyPvPAction::RANDOM_TOWN_VS:
if(allowedFactions.size())
srv.announceTxt("Factions - " + VLC->townh->getById(randomFaction1[0])->getNameTranslated() + " vs. " + VLC->townh->getById(randomFaction2[0])->getNameTranslated());
if(allowedTowns.size())
srv.announceTxt("Towns - " + VLC->townh->getById(randomFaction1[0])->getNameTranslated() + " vs. " + VLC->townh->getById(randomFaction2[0])->getNameTranslated());
break;
}
result = true;