mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-02 00:10:22 +02:00
client is able to erase artifact
This commit is contained in:
parent
307065a633
commit
ea7dd14d8b
@ -185,6 +185,12 @@ void CCallback::bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dst
|
|||||||
sendRequest(&bma);
|
sendRequest(&bma);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCallback::eraseArtifactByClient(const ArtifactLocation & al)
|
||||||
|
{
|
||||||
|
EraseArtifactByClient ea(al);
|
||||||
|
sendRequest(&ea);
|
||||||
|
}
|
||||||
|
|
||||||
bool CCallback::buildBuilding(const CGTownInstance *town, BuildingID buildingID)
|
bool CCallback::buildBuilding(const CGTownInstance *town, BuildingID buildingID)
|
||||||
{
|
{
|
||||||
if(town->tempOwner!=player)
|
if(town->tempOwner!=player)
|
||||||
|
@ -85,6 +85,7 @@ public:
|
|||||||
//virtual bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)=0; //swaps artifacts between two given heroes
|
//virtual bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)=0; //swaps artifacts between two given heroes
|
||||||
virtual bool swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation &l2)=0;
|
virtual bool swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation &l2)=0;
|
||||||
virtual bool assembleArtifacts(const CGHeroInstance * hero, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo)=0;
|
virtual bool assembleArtifacts(const CGHeroInstance * hero, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo)=0;
|
||||||
|
virtual void eraseArtifactByClient(const ArtifactLocation & al)=0;
|
||||||
virtual bool dismissCreature(const CArmedInstance *obj, SlotID stackPos)=0;
|
virtual bool dismissCreature(const CArmedInstance *obj, SlotID stackPos)=0;
|
||||||
virtual void endTurn()=0;
|
virtual void endTurn()=0;
|
||||||
virtual void buyArtifact(const CGHeroInstance *hero, ArtifactID aid)=0; //used to buy artifacts in towns (including spell book in the guild and war machines in blacksmith)
|
virtual void buyArtifact(const CGHeroInstance *hero, ArtifactID aid)=0; //used to buy artifacts in towns (including spell book in the guild and war machines in blacksmith)
|
||||||
@ -159,6 +160,7 @@ public:
|
|||||||
bool swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation &l2) override;
|
bool swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation &l2) override;
|
||||||
bool assembleArtifacts(const CGHeroInstance * hero, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo) override;
|
bool assembleArtifacts(const CGHeroInstance * hero, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo) override;
|
||||||
void bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap) override;
|
void bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap) override;
|
||||||
|
void eraseArtifactByClient(const ArtifactLocation & al) override;
|
||||||
bool buildBuilding(const CGTownInstance *town, BuildingID buildingID) override;
|
bool buildBuilding(const CGTownInstance *town, BuildingID buildingID) override;
|
||||||
void recruitCreatures(const CGDwelling * obj, const CArmedInstance * dst, CreatureID ID, ui32 amount, si32 level=-1) override;
|
void recruitCreatures(const CGDwelling * obj, const CArmedInstance * dst, CreatureID ID, ui32 amount, si32 level=-1) override;
|
||||||
bool dismissCreature(const CArmedInstance *obj, SlotID stackPos) override;
|
bool dismissCreature(const CArmedInstance *obj, SlotID stackPos) override;
|
||||||
|
@ -654,7 +654,7 @@ CArtifactsOfHero::~CArtifactsOfHero()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//TODO remove artifact
|
LOCPLINT->cb->eraseArtifactByClient(ArtifactLocation(curHero, ArtifactPosition::TRANSITION_POS));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,6 +126,7 @@ public:
|
|||||||
virtual void visitExchangeArtifacts(ExchangeArtifacts & pack) {}
|
virtual void visitExchangeArtifacts(ExchangeArtifacts & pack) {}
|
||||||
virtual void visitBulkExchangeArtifacts(BulkExchangeArtifacts & pack) {}
|
virtual void visitBulkExchangeArtifacts(BulkExchangeArtifacts & pack) {}
|
||||||
virtual void visitAssembleArtifacts(AssembleArtifacts & pack) {}
|
virtual void visitAssembleArtifacts(AssembleArtifacts & pack) {}
|
||||||
|
virtual void visitEraseArtifactByClient(EraseArtifactByClient & pack) {}
|
||||||
virtual void visitBuyArtifact(BuyArtifact & pack) {}
|
virtual void visitBuyArtifact(BuyArtifact & pack) {}
|
||||||
virtual void visitTradeOnMarketplace(TradeOnMarketplace & pack) {}
|
virtual void visitTradeOnMarketplace(TradeOnMarketplace & pack) {}
|
||||||
virtual void visitSetFormation(SetFormation & pack) {}
|
virtual void visitSetFormation(SetFormation & pack) {}
|
||||||
|
@ -2298,6 +2298,24 @@ struct DLL_LINKAGE AssembleArtifacts : public CPackForServer
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DLL_LINKAGE EraseArtifactByClient : public CPackForServer
|
||||||
|
{
|
||||||
|
EraseArtifactByClient() = default;
|
||||||
|
EraseArtifactByClient(const ArtifactLocation & al)
|
||||||
|
: al(al)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
ArtifactLocation al;
|
||||||
|
|
||||||
|
virtual void visitTyped(ICPackVisitor & visitor) override;
|
||||||
|
|
||||||
|
template <typename Handler> void serialize(Handler & h, const int version)
|
||||||
|
{
|
||||||
|
h & static_cast<CPackForServer&>(*this);
|
||||||
|
h & al;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct DLL_LINKAGE BuyArtifact : public CPackForServer
|
struct DLL_LINKAGE BuyArtifact : public CPackForServer
|
||||||
{
|
{
|
||||||
BuyArtifact() = default;
|
BuyArtifact() = default;
|
||||||
|
@ -593,6 +593,11 @@ void AssembleArtifacts::visitTyped(ICPackVisitor & visitor)
|
|||||||
visitor.visitAssembleArtifacts(*this);
|
visitor.visitAssembleArtifacts(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EraseArtifactByClient::visitTyped(ICPackVisitor & visitor)
|
||||||
|
{
|
||||||
|
visitor.visitEraseArtifactByClient(*this);
|
||||||
|
}
|
||||||
|
|
||||||
void BuyArtifact::visitTyped(ICPackVisitor & visitor)
|
void BuyArtifact::visitTyped(ICPackVisitor & visitor)
|
||||||
{
|
{
|
||||||
visitor.visitBuyArtifact(*this);
|
visitor.visitBuyArtifact(*this);
|
||||||
|
@ -346,6 +346,7 @@ void registerTypesServerPacks(Serializer &s)
|
|||||||
s.template registerType<CPackForServer, BulkSmartSplitStack>();
|
s.template registerType<CPackForServer, BulkSmartSplitStack>();
|
||||||
s.template registerType<CPackForServer, BulkMoveArmy>();
|
s.template registerType<CPackForServer, BulkMoveArmy>();
|
||||||
s.template registerType<CPackForServer, BulkExchangeArtifacts>();
|
s.template registerType<CPackForServer, BulkExchangeArtifacts>();
|
||||||
|
s.template registerType<CPackForServer, EraseArtifactByClient>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Serializer>
|
template<typename Serializer>
|
||||||
|
@ -4063,6 +4063,23 @@ bool CGameHandler::assembleArtifacts (ObjectInstanceID heroID, ArtifactPosition
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CGameHandler::eraseArtifactByClient(const ArtifactLocation & al)
|
||||||
|
{
|
||||||
|
const auto * hero = getHero(al.relatedObj()->id);
|
||||||
|
if(hero == nullptr)
|
||||||
|
COMPLAIN_RET("eraseArtifactByClient: wrong hero's ID");
|
||||||
|
|
||||||
|
const auto * art = al.getArt();
|
||||||
|
if(art == nullptr)
|
||||||
|
COMPLAIN_RET("Cannot remove artifact!");
|
||||||
|
|
||||||
|
if(al.getArt()->artType->canBePutAt(hero) || al.slot != ArtifactPosition::TRANSITION_POS)
|
||||||
|
COMPLAIN_RET("Unlegal removing artifact");
|
||||||
|
|
||||||
|
removeArtifact(al);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CGameHandler::buyArtifact(ObjectInstanceID hid, ArtifactID aid)
|
bool CGameHandler::buyArtifact(ObjectInstanceID hid, ArtifactID aid)
|
||||||
{
|
{
|
||||||
const CGHeroInstance * hero = getHero(hid);
|
const CGHeroInstance * hero = getHero(hid);
|
||||||
|
@ -182,6 +182,7 @@ public:
|
|||||||
void removeArtifact(const ArtifactLocation &al) override;
|
void removeArtifact(const ArtifactLocation &al) override;
|
||||||
bool moveArtifact(const ArtifactLocation & al1, const ArtifactLocation & al2) override;
|
bool moveArtifact(const ArtifactLocation & al1, const ArtifactLocation & al2) override;
|
||||||
bool bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap);
|
bool bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap);
|
||||||
|
bool eraseArtifactByClient(const ArtifactLocation & al);
|
||||||
void synchronizeArtifactHandlerLists();
|
void synchronizeArtifactHandlerLists();
|
||||||
|
|
||||||
void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero) override;
|
void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero) override;
|
||||||
|
@ -374,6 +374,12 @@ bool CGarrisonDialogQuery::blocksPack(const CPack * pack) const
|
|||||||
if(auto arts = dynamic_ptr_cast<BulkExchangeArtifacts>(pack))
|
if(auto arts = dynamic_ptr_cast<BulkExchangeArtifacts>(pack))
|
||||||
return !vstd::contains(ourIds, arts->srcHero) || !vstd::contains(ourIds, arts->dstHero);
|
return !vstd::contains(ourIds, arts->srcHero) || !vstd::contains(ourIds, arts->dstHero);
|
||||||
|
|
||||||
|
if(auto art = dynamic_ptr_cast<EraseArtifactByClient>(pack))
|
||||||
|
{
|
||||||
|
if (auto id = boost::apply_visitor(GetEngagedHeroIds(), art->al.artHolder))
|
||||||
|
return !vstd::contains(ourIds, *id);
|
||||||
|
}
|
||||||
|
|
||||||
if(auto dismiss = dynamic_ptr_cast<AssembleArtifacts>(pack))
|
if(auto dismiss = dynamic_ptr_cast<AssembleArtifacts>(pack))
|
||||||
return !vstd::contains(ourIds, dismiss->heroID);
|
return !vstd::contains(ourIds, dismiss->heroID);
|
||||||
|
|
||||||
|
@ -146,6 +146,12 @@ void ApplyGhNetPackVisitor::visitAssembleArtifacts(AssembleArtifacts & pack)
|
|||||||
result = gh.assembleArtifacts(pack.heroID, pack.artifactSlot, pack.assemble, pack.assembleTo);
|
result = gh.assembleArtifacts(pack.heroID, pack.artifactSlot, pack.assemble, pack.assembleTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ApplyGhNetPackVisitor::visitEraseArtifactByClient(EraseArtifactByClient & pack)
|
||||||
|
{
|
||||||
|
gh.throwOnWrongPlayer(&pack, pack.al.owningPlayer());
|
||||||
|
result = gh.eraseArtifactByClient(pack.al);
|
||||||
|
}
|
||||||
|
|
||||||
void ApplyGhNetPackVisitor::visitBuyArtifact(BuyArtifact & pack)
|
void ApplyGhNetPackVisitor::visitBuyArtifact(BuyArtifact & pack)
|
||||||
{
|
{
|
||||||
gh.throwOnWrongOwner(&pack, pack.hid);
|
gh.throwOnWrongOwner(&pack, pack.hid);
|
||||||
|
@ -47,6 +47,7 @@ public:
|
|||||||
virtual void visitExchangeArtifacts(ExchangeArtifacts & pack) override;
|
virtual void visitExchangeArtifacts(ExchangeArtifacts & pack) override;
|
||||||
virtual void visitBulkExchangeArtifacts(BulkExchangeArtifacts & pack) override;
|
virtual void visitBulkExchangeArtifacts(BulkExchangeArtifacts & pack) override;
|
||||||
virtual void visitAssembleArtifacts(AssembleArtifacts & pack) override;
|
virtual void visitAssembleArtifacts(AssembleArtifacts & pack) override;
|
||||||
|
virtual void visitEraseArtifactByClient(EraseArtifactByClient & pack) override;
|
||||||
virtual void visitBuyArtifact(BuyArtifact & pack) override;
|
virtual void visitBuyArtifact(BuyArtifact & pack) override;
|
||||||
virtual void visitTradeOnMarketplace(TradeOnMarketplace & pack) override;
|
virtual void visitTradeOnMarketplace(TradeOnMarketplace & pack) override;
|
||||||
virtual void visitSetFormation(SetFormation & pack) override;
|
virtual void visitSetFormation(SetFormation & pack) override;
|
||||||
|
Loading…
Reference in New Issue
Block a user