2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* NetPacksServer.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2023-02-12 09:23:39 +02:00
|
|
|
#include "ServerNetPackVisitors.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2009-03-09 12:37:49 +02:00
|
|
|
#include "CGameHandler.h"
|
2023-07-23 23:20:35 +02:00
|
|
|
#include "battles/BattleProcessor.h"
|
|
|
|
#include "processors/HeroPoolProcessor.h"
|
|
|
|
#include "processors/PlayerMessageProcessor.h"
|
2023-08-22 17:45:13 +02:00
|
|
|
#include "processors/TurnOrderProcessor.h"
|
2023-07-23 23:46:29 +02:00
|
|
|
#include "queries/QueriesProcessor.h"
|
2023-07-11 14:16:02 +02:00
|
|
|
|
2010-05-18 10:01:54 +03:00
|
|
|
#include "../lib/IGameCallback.h"
|
2023-05-24 01:05:59 +02:00
|
|
|
#include "../lib/mapObjects/CGTownInstance.h"
|
2023-06-23 17:02:48 +02:00
|
|
|
#include "../lib/gameState/CGameState.h"
|
2023-08-28 16:43:57 +02:00
|
|
|
#include "../lib/battle/IBattleState.h"
|
2017-06-24 16:42:05 +02:00
|
|
|
#include "../lib/battle/BattleAction.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "../lib/battle/Unit.h"
|
2016-09-10 02:32:40 +02:00
|
|
|
#include "../lib/serializer/Connection.h"
|
2017-07-03 20:09:27 +02:00
|
|
|
#include "../lib/spells/CSpellHandler.h"
|
|
|
|
#include "../lib/spells/ISpellMechanics.h"
|
2018-08-13 23:48:00 +02:00
|
|
|
#include "../lib/serializer/Cast.h"
|
2009-03-09 12:37:49 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitSaveGame(SaveGame & pack)
|
2018-01-25 19:21:34 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
gh.save(pack.fname);
|
|
|
|
logGlobal->info("Game has been saved as %s", pack.fname);
|
|
|
|
result = true;
|
2018-01-25 19:21:34 +02:00
|
|
|
}
|
2009-03-09 12:37:49 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitEndTurn(EndTurn & pack)
|
2018-01-25 19:21:34 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack);
|
2023-08-24 12:36:35 +02:00
|
|
|
result = gh.turnOrder->onPlayerEndsTurn(pack.player);
|
2018-01-25 19:21:34 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitDismissHero(DismissHero & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongOwner(&pack, pack.hid);
|
2023-09-18 21:09:55 +02:00
|
|
|
result = gh.removeObject(gh.getObj(pack.hid), pack.player);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitMoveHero(MoveHero & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongOwner(&pack, pack.hid);
|
|
|
|
result = gh.moveHero(pack.hid, pack.dest, 0, pack.transit, pack.player);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitCastleTeleportHero(CastleTeleportHero & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongOwner(&pack, pack.hid);
|
2022-12-14 22:13:26 +02:00
|
|
|
|
2023-08-25 00:08:48 +02:00
|
|
|
result = gh.teleportHero(pack.hid, pack.dest, pack.source, pack.player);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitArrangeStacks(ArrangeStacks & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack);
|
|
|
|
result = gh.arrangeStacks(pack.id1, pack.id2, pack.what, pack.p1, pack.p2, pack.val, pack.player);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitBulkMoveArmy(BulkMoveArmy & pack)
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = gh.bulkMoveArmy(pack.srcArmy, pack.destArmy, pack.srcSlot);
|
2021-11-28 14:57:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitBulkSplitStack(BulkSplitStack & pack)
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = gh.bulkSplitStack(pack.src, pack.srcOwner, pack.amount);
|
2021-11-28 14:57:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitBulkMergeStacks(BulkMergeStacks & pack)
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = gh.bulkMergeStacks(pack.src, pack.srcOwner);
|
2021-11-28 14:57:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitBulkSmartSplitStack(BulkSmartSplitStack & pack)
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = gh.bulkSmartSplitStack(pack.src, pack.srcOwner);
|
2021-11-28 14:57:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitDisbandCreature(DisbandCreature & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongOwner(&pack, pack.id);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = gh.disbandCreature(pack.id, pack.pos);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitBuildStructure(BuildStructure & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongOwner(&pack, pack.tid);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = gh.buildStructure(pack.tid, pack.bid);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitRecruitCreatures(RecruitCreatures & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-09-05 22:12:57 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack);
|
|
|
|
// ownership checks are inside recruitCreatures
|
|
|
|
result = gh.recruitCreatures(pack.tid, pack.dst, pack.crid, pack.amount, pack.level, pack.player);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitUpgradeCreature(UpgradeCreature & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongOwner(&pack, pack.id);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = gh.upgradeCreature(pack.id, pack.pos, pack.cid);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitGarrisonHeroSwap(GarrisonHeroSwap & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
const CGTownInstance * town = gh.getTown(pack.tid);
|
|
|
|
if(!gh.isPlayerOwns(&pack, pack.tid) && !(town->garrisonHero && gh.isPlayerOwns(&pack, town->garrisonHero->id)))
|
|
|
|
gh.throwNotAllowedAction(&pack); //neither town nor garrisoned hero (if present) is ours
|
|
|
|
result = gh.garrisonSwap(pack.tid);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitExchangeArtifacts(ExchangeArtifacts & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack, pack.src.owningPlayer()); //second hero can be ally
|
2023-02-12 09:23:39 +02:00
|
|
|
result = gh.moveArtifact(pack.src, pack.dst);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitBulkExchangeArtifacts(BulkExchangeArtifacts & pack)
|
2022-11-06 23:54:50 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongOwner(&pack, pack.srcHero);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = gh.bulkMoveArtifacts(pack.srcHero, pack.dstHero, pack.swap);
|
2022-11-06 23:54:50 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitAssembleArtifacts(AssembleArtifacts & pack)
|
2010-02-16 16:39:56 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongOwner(&pack, pack.heroID);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = gh.assembleArtifacts(pack.heroID, pack.artifactSlot, pack.assemble, pack.assembleTo);
|
2010-02-16 16:39:56 +02:00
|
|
|
}
|
|
|
|
|
2023-04-07 23:41:55 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitEraseArtifactByClient(EraseArtifactByClient & pack)
|
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack, pack.al.owningPlayer());
|
2023-04-07 23:41:55 +02:00
|
|
|
result = gh.eraseArtifactByClient(pack.al);
|
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitBuyArtifact(BuyArtifact & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongOwner(&pack, pack.hid);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = gh.buyArtifact(pack.hid, pack.aid);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitTradeOnMarketplace(TradeOnMarketplace & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-09-18 16:22:30 +02:00
|
|
|
const CGObjectInstance * object = gh.getObj(pack.marketId);
|
|
|
|
const CGHeroInstance * hero = gh.getHero(pack.heroId);
|
|
|
|
const IMarket * market = IMarket::castFrom(object);
|
|
|
|
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack);
|
|
|
|
|
2023-09-18 16:22:30 +02:00
|
|
|
if(!object)
|
2023-02-12 09:23:39 +02:00
|
|
|
gh.throwAndComplain(&pack, "Invalid market object");
|
2018-03-10 21:19:55 +02:00
|
|
|
|
2023-09-18 16:22:30 +02:00
|
|
|
if(!market)
|
2023-02-12 09:23:39 +02:00
|
|
|
gh.throwAndComplain(&pack, "market is not-a-market! :/");
|
2010-05-18 10:01:54 +03:00
|
|
|
|
2023-09-18 16:22:30 +02:00
|
|
|
bool heroCanBeInvalid = false;
|
2010-05-18 10:01:54 +03:00
|
|
|
|
2023-09-18 16:22:30 +02:00
|
|
|
if (pack.mode == EMarketMode::RESOURCE_RESOURCE || pack.mode == EMarketMode::RESOURCE_PLAYER)
|
|
|
|
{
|
|
|
|
// For resource exchange we must use our own market or visit neutral market
|
|
|
|
if (object->getOwner().isValidPlayer())
|
|
|
|
{
|
|
|
|
gh.throwIfWrongOwner(&pack, pack.marketId);
|
|
|
|
heroCanBeInvalid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pack.mode == EMarketMode::CREATURE_UNDEAD)
|
|
|
|
{
|
|
|
|
// For skeleton transformer, if hero is null then object must be owned
|
|
|
|
if (!hero)
|
|
|
|
{
|
|
|
|
gh.throwIfWrongOwner(&pack, pack.marketId);
|
|
|
|
heroCanBeInvalid = true;
|
|
|
|
}
|
|
|
|
}
|
2010-05-18 10:01:54 +03:00
|
|
|
|
2023-09-18 16:22:30 +02:00
|
|
|
if (!heroCanBeInvalid)
|
|
|
|
{
|
|
|
|
gh.throwIfWrongOwner(&pack, pack.heroId);
|
2010-05-18 10:01:54 +03:00
|
|
|
|
2023-09-18 16:22:30 +02:00
|
|
|
if (!hero)
|
|
|
|
gh.throwAndComplain(&pack, "Can not trade - no hero!");
|
2019-03-24 20:20:08 +02:00
|
|
|
|
2023-09-18 16:22:30 +02:00
|
|
|
// TODO: check that object is actually being visited (e.g. Query exists)
|
|
|
|
if (!object->visitableAt(hero->visitablePos().x, hero->visitablePos().y))
|
|
|
|
gh.throwAndComplain(&pack, "Can not trade - object not visited!");
|
2010-05-18 10:01:54 +03:00
|
|
|
|
2023-09-18 16:22:30 +02:00
|
|
|
if (object->getOwner().isValidPlayer() && gh.getPlayerRelations(object->getOwner(), hero->getOwner()) == PlayerRelations::ENEMIES)
|
|
|
|
gh.throwAndComplain(&pack, "Can not trade - market not owned!");
|
|
|
|
}
|
2010-05-18 10:01:54 +03:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
result = true;
|
2017-10-14 21:30:56 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
switch(pack.mode)
|
2010-05-08 01:10:32 +03:00
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::RESOURCE_RESOURCE:
|
2023-02-12 09:23:39 +02:00
|
|
|
for(int i = 0; i < pack.r1.size(); ++i)
|
2023-09-18 16:22:30 +02:00
|
|
|
result &= gh.tradeResources(market, pack.val[i], pack.player, pack.r1[i], pack.r2[i]);
|
2017-10-14 21:30:56 +02:00
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::RESOURCE_PLAYER:
|
2023-02-12 09:23:39 +02:00
|
|
|
for(int i = 0; i < pack.r1.size(); ++i)
|
2023-09-18 16:22:30 +02:00
|
|
|
result &= gh.sendResources(pack.val[i], pack.player, GameResID(pack.r1[i]), PlayerColor(pack.r2[i]));
|
2017-10-14 21:30:56 +02:00
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::CREATURE_RESOURCE:
|
2023-02-12 09:23:39 +02:00
|
|
|
for(int i = 0; i < pack.r1.size(); ++i)
|
2023-09-18 16:22:30 +02:00
|
|
|
result &= gh.sellCreatures(pack.val[i], market, hero, SlotID(pack.r1[i]), GameResID(pack.r2[i]));
|
2017-10-14 21:30:56 +02:00
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::RESOURCE_ARTIFACT:
|
2023-02-12 09:23:39 +02:00
|
|
|
for(int i = 0; i < pack.r1.size(); ++i)
|
2023-09-18 16:22:30 +02:00
|
|
|
result &= gh.buyArtifact(market, hero, GameResID(pack.r1[i]), ArtifactID(pack.r2[i]));
|
2017-10-14 21:30:56 +02:00
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::ARTIFACT_RESOURCE:
|
2023-02-12 09:23:39 +02:00
|
|
|
for(int i = 0; i < pack.r1.size(); ++i)
|
2023-09-18 16:22:30 +02:00
|
|
|
result &= gh.sellArtifact(market, hero, ArtifactInstanceID(pack.r1[i]), GameResID(pack.r2[i]));
|
2017-10-14 21:30:56 +02:00
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::CREATURE_UNDEAD:
|
2023-02-12 09:23:39 +02:00
|
|
|
for(int i = 0; i < pack.r1.size(); ++i)
|
2023-09-18 16:22:30 +02:00
|
|
|
result &= gh.transformInUndead(market, hero, SlotID(pack.r1[i]));
|
2017-10-14 21:30:56 +02:00
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::RESOURCE_SKILL:
|
2023-02-12 09:23:39 +02:00
|
|
|
for(int i = 0; i < pack.r2.size(); ++i)
|
2023-09-18 16:22:30 +02:00
|
|
|
result &= gh.buySecSkill(market, hero, SecondarySkill(pack.r2[i]));
|
2017-10-14 21:30:56 +02:00
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::CREATURE_EXP:
|
2017-10-14 21:30:56 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
std::vector<SlotID> slotIDs(pack.r1.begin(), pack.r1.end());
|
|
|
|
std::vector<ui32> count(pack.val.begin(), pack.val.end());
|
2023-09-18 16:22:30 +02:00
|
|
|
result = gh.sacrificeCreatures(market, hero, slotIDs, count);
|
2023-02-12 09:23:39 +02:00
|
|
|
return;
|
2017-10-14 21:30:56 +02:00
|
|
|
}
|
2011-12-14 00:23:17 +03:00
|
|
|
case EMarketMode::ARTIFACT_EXP:
|
2017-10-14 21:30:56 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
std::vector<ArtifactPosition> positions(pack.r1.begin(), pack.r1.end());
|
2023-09-18 16:22:30 +02:00
|
|
|
result = gh.sacrificeArtifact(market, hero, positions);
|
2023-02-12 09:23:39 +02:00
|
|
|
return;
|
2017-10-14 21:30:56 +02:00
|
|
|
}
|
2010-05-08 01:10:32 +03:00
|
|
|
default:
|
2023-02-12 09:23:39 +02:00
|
|
|
gh.throwAndComplain(&pack, "Unknown exchange pack.mode!");
|
2010-05-08 01:10:32 +03:00
|
|
|
}
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitSetFormation(SetFormation & pack)
|
2015-10-31 17:04:06 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongOwner(&pack, pack.hid);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = gh.setFormation(pack.hid, pack.formation);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitHireHero(HireHero & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack);
|
2010-07-09 02:03:27 +03:00
|
|
|
|
2023-07-12 11:29:05 +02:00
|
|
|
result = gh.heroPool->hireHero(pack.tid, pack.hid, pack.player);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitBuildBoat(BuildBoat & pack)
|
2009-07-26 06:33:13 +03:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack);
|
|
|
|
|
|
|
|
if(gh.getPlayerRelations(gh.getOwner(pack.objid), pack.player) == PlayerRelations::ENEMIES)
|
2023-02-12 09:23:39 +02:00
|
|
|
gh.throwAndComplain(&pack, "Can't build boat at enemy shipyard");
|
2018-11-17 15:02:47 +02:00
|
|
|
|
2023-08-25 00:08:48 +02:00
|
|
|
result = gh.buildBoat(pack.objid, pack.player);
|
2009-07-26 06:33:13 +03:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitQueryReply(QueryReply & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack);
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
auto playerToConnection = gh.connections.find(pack.player);
|
|
|
|
if(playerToConnection == gh.connections.end())
|
|
|
|
gh.throwAndComplain(&pack, "No such pack.player!");
|
|
|
|
if(!vstd::contains(playerToConnection->second, pack.c))
|
|
|
|
gh.throwAndComplain(&pack, "Message came from wrong connection!");
|
|
|
|
if(pack.qid == QueryID(-1))
|
|
|
|
gh.throwAndComplain(&pack, "Cannot answer the query with pack.id -1!");
|
|
|
|
|
|
|
|
result = gh.queryReply(pack.qid, pack.reply, pack.player);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitMakeAction(MakeAction & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack);
|
2023-02-12 09:23:39 +02:00
|
|
|
|
2023-08-25 17:23:15 +02:00
|
|
|
result = gh.battles->makePlayerBattleAction(pack.battleID, pack.player, pack.ba);
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitDigWithHero(DigWithHero & pack)
|
2010-02-21 17:03:30 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongOwner(&pack, pack.id);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = gh.dig(gh.getHero(pack.id));
|
2010-02-21 17:03:30 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitCastAdvSpell(CastAdvSpell & pack)
|
2010-03-11 01:16:30 +02:00
|
|
|
{
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongOwner(&pack, pack.hid);
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
const CSpell * s = pack.sid.toSpell();
|
2017-06-06 06:53:51 +02:00
|
|
|
if(!s)
|
2023-02-12 09:23:39 +02:00
|
|
|
gh.throwNotAllowedAction(&pack);
|
|
|
|
const CGHeroInstance * h = gh.getHero(pack.hid);
|
2017-06-06 06:53:51 +02:00
|
|
|
if(!h)
|
2023-02-12 09:23:39 +02:00
|
|
|
gh.throwNotAllowedAction(&pack);
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-03 20:09:27 +02:00
|
|
|
AdventureSpellCastParameters p;
|
|
|
|
p.caster = h;
|
2023-02-12 09:23:39 +02:00
|
|
|
p.pos = pack.pos;
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
result = s->adventureCast(gh.spellEnv, p);
|
2010-03-11 01:16:30 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 09:23:39 +02:00
|
|
|
void ApplyGhNetPackVisitor::visitPlayerMessage(PlayerMessage & pack)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2023-02-12 09:23:39 +02:00
|
|
|
if(!pack.player.isSpectator()) // TODO: clearly not a great way to verify permissions
|
2023-08-25 00:08:48 +02:00
|
|
|
gh.throwIfWrongPlayer(&pack, pack.player);
|
2022-10-05 17:04:51 +02:00
|
|
|
|
2023-07-12 20:13:17 +02:00
|
|
|
gh.playerMessages->playerMessage(pack.player, pack.text, pack.currObj);
|
2023-02-12 09:23:39 +02:00
|
|
|
result = true;
|
2009-03-09 12:37:49 +02:00
|
|
|
}
|