2017-07-20 06:08:49 +02:00
|
|
|
/*
|
|
|
|
* CloneTest.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
|
|
|
|
#include "EffectFixture.h"
|
|
|
|
|
|
|
|
#include <vstd/RNG.h>
|
|
|
|
|
|
|
|
#include "../../../lib/battle/CUnitState.h"
|
2024-02-11 23:09:01 +02:00
|
|
|
#include "../../../lib/json/JsonNode.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
namespace test
|
|
|
|
{
|
|
|
|
using namespace ::spells;
|
|
|
|
using namespace ::spells::effects;
|
|
|
|
using namespace ::testing;
|
|
|
|
|
|
|
|
class CloneTest : public Test, public EffectFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CloneTest()
|
|
|
|
: EffectFixture("core:clone")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void SetUp() override
|
|
|
|
{
|
|
|
|
EffectFixture::setUp();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(CloneTest, ApplicableToValidTarget)
|
|
|
|
{
|
|
|
|
{
|
2024-02-13 14:34:16 +02:00
|
|
|
JsonNode config;
|
2017-07-20 06:08:49 +02:00
|
|
|
config["maxTier"].Integer() = 7;
|
|
|
|
EffectFixture::setupEffect(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto & unit = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, isValidTarget(Eq(false))).Times(AtLeast(1)).WillRepeatedly(Return(true));
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, hasClone()).WillRepeatedly(Return(false));
|
|
|
|
EXPECT_CALL(unit, isClone()).Times(AtLeast(1)).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unit))).Times(AtLeast(1)).WillRepeatedly(Return(true));
|
|
|
|
EXPECT_CALL(mechanicsMock, isSmart()).Times(AtLeast(1)).WillRepeatedly(Return(true));
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, getPosition()).WillOnce(Return(BattleHex(5, 5)));
|
|
|
|
EffectTarget target;
|
|
|
|
target.emplace_back(&unit);
|
|
|
|
|
|
|
|
EXPECT_TRUE(subject->applicable(problemMock, &mechanicsMock, target));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CloneTest, CloneIsNotClonable)
|
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
setupEffect(JsonNode());
|
2017-07-20 06:08:49 +02:00
|
|
|
auto & unit = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, hasClone()).WillRepeatedly(Return(false));
|
|
|
|
EXPECT_CALL(unit, isClone()).Times(AtLeast(1)).WillRepeatedly(Return(true));
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, getPosition()).WillOnce(Return(BattleHex(5, 5)));
|
|
|
|
EffectTarget target;
|
|
|
|
target.emplace_back(&unit);
|
|
|
|
|
|
|
|
EXPECT_FALSE(subject->applicable(problemMock, &mechanicsMock, target));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CloneTest, SecondCloneRejected)
|
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
setupEffect(JsonNode());
|
2017-07-20 06:08:49 +02:00
|
|
|
auto & unit = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, hasClone()).Times(AtLeast(1)).WillRepeatedly(Return(true));
|
|
|
|
EXPECT_CALL(unit, isClone()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
EXPECT_CALL(unit, getPosition()).WillOnce(Return(BattleHex(5, 5)));
|
|
|
|
EffectTarget target;
|
|
|
|
target.emplace_back(&unit);
|
|
|
|
|
|
|
|
EXPECT_FALSE(subject->applicable(problemMock, &mechanicsMock, target));
|
|
|
|
}
|
|
|
|
|
|
|
|
class CloneApplyTest : public Test, public EffectFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::shared_ptr<::battle::UnitInfo> cloneAddInfo;
|
|
|
|
std::shared_ptr<::battle::CUnitState> cloneState;
|
|
|
|
std::shared_ptr<::battle::CUnitState> originalState;
|
|
|
|
|
|
|
|
const uint32_t originalId = 40;
|
|
|
|
const uint32_t cloneId = 42;
|
|
|
|
const int32_t expectedAmount = 10;
|
|
|
|
const int32_t effectDuration = 6;
|
|
|
|
const BattleHex originalPosition = BattleHex(5,5);
|
|
|
|
|
|
|
|
EffectTarget target;
|
|
|
|
|
|
|
|
CloneApplyTest()
|
|
|
|
: EffectFixture("core:clone")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void onUnitAdded(uint32_t id, const JsonNode & data)
|
|
|
|
{
|
|
|
|
using namespace ::battle;
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
auto & clone = unitsFake.add(BattleSide::ATTACKER);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
EXPECT_CALL(clone, unitId()).WillRepeatedly(Return(id));
|
|
|
|
|
|
|
|
cloneState = std::make_shared<CUnitStateDetached>(&clone, &clone);
|
|
|
|
|
|
|
|
EXPECT_CALL(clone, acquireState()).WillOnce(Return(cloneState));
|
|
|
|
|
|
|
|
cloneAddInfo->load(id, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkCloneLifetimeMarker(uint32_t id, const std::vector<Bonus> & bonus)
|
|
|
|
{
|
|
|
|
EXPECT_EQ(id, cloneId);
|
|
|
|
|
|
|
|
GTEST_ASSERT_EQ(bonus.size(), 1);
|
|
|
|
|
|
|
|
const Bonus & marker = bonus.front();
|
|
|
|
|
2023-05-01 00:20:01 +02:00
|
|
|
EXPECT_EQ(marker.type, BonusType::NONE);
|
|
|
|
EXPECT_EQ(marker.duration, BonusDuration::N_TURNS);
|
2017-07-20 06:08:49 +02:00
|
|
|
EXPECT_EQ(marker.turnsRemain, effectDuration);
|
2023-05-01 00:20:01 +02:00
|
|
|
EXPECT_EQ(marker.source, BonusSource::SPELL_EFFECT);
|
2023-10-21 13:50:42 +02:00
|
|
|
EXPECT_EQ(marker.sid, BonusSourceID(SpellID(SpellID::CLONE)));
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setDefaultExpectations()
|
|
|
|
{
|
|
|
|
using namespace ::battle;
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
battleFake->setupEmptyBattlefield();
|
|
|
|
|
2024-10-04 20:59:51 +02:00
|
|
|
EXPECT_CALL(serverMock, apply(Matcher<BattleUnitsChanged &>(_))).Times(2);
|
|
|
|
EXPECT_CALL(serverMock, apply(Matcher<SetStackEffect &>(_))).Times(1);
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
EXPECT_CALL(mechanicsMock, getEffectDuration()).WillOnce(Return(effectDuration));
|
|
|
|
EXPECT_CALL(*battleFake, getUnitsIf(_)).Times(AtLeast(1));
|
|
|
|
|
|
|
|
EXPECT_CALL(*battleFake, nextUnitId()).WillOnce(Return(cloneId));
|
|
|
|
EXPECT_CALL(*battleFake, addUnit(_, _)).WillOnce(Invoke(this, &CloneApplyTest::onUnitAdded));
|
|
|
|
|
|
|
|
EXPECT_CALL(*battleFake, setUnitState(Eq(originalId), _, Eq(0))).Times(AtLeast(1));
|
|
|
|
EXPECT_CALL(*battleFake, setUnitState(Eq(cloneId), _, Eq(0))).Times(AtLeast(1));
|
|
|
|
|
|
|
|
auto & original = unitsFake.add(BattleSide::ATTACKER);
|
|
|
|
EXPECT_CALL(original, isValidTarget(Eq(false))).Times(AtLeast(1)).WillRepeatedly(Return(true));
|
|
|
|
EXPECT_CALL(original, getCount()).WillRepeatedly(Return(expectedAmount));
|
|
|
|
EXPECT_CALL(original, unitId()).WillRepeatedly(Return(originalId));
|
|
|
|
EXPECT_CALL(original, creatureId()).WillRepeatedly(Return(CreatureID(0)));
|
|
|
|
EXPECT_CALL(original, creatureIndex()).WillRepeatedly(Return(0));
|
|
|
|
EXPECT_CALL(original, doubleWide()).WillRepeatedly(Return(false));
|
|
|
|
EXPECT_CALL(original, getPosition()).WillRepeatedly(Return(originalPosition));
|
|
|
|
EXPECT_CALL(original, unitSide()).Times(AnyNumber());
|
|
|
|
|
|
|
|
originalState = std::make_shared<CUnitStateDetached>(&original, &original);
|
|
|
|
|
|
|
|
EXPECT_CALL(original, acquireState()).WillOnce(Return(originalState));
|
|
|
|
|
|
|
|
target.emplace_back(&original);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void SetUp() override
|
|
|
|
{
|
|
|
|
EffectFixture::setUp();
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
setupEffect(JsonNode());
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
cloneAddInfo = std::make_shared<::battle::UnitInfo>();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2024-01-03 02:26:15 +02:00
|
|
|
TEST_F(CloneApplyTest, DISABLED_AddsNewUnit)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
EXPECT_CALL(*battleFake, addUnitBonus(_,_)).Times(AtLeast(1));
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
subject->apply(&serverMock, &mechanicsMock, target);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
EXPECT_EQ(cloneAddInfo->id, cloneId);
|
|
|
|
EXPECT_EQ(cloneAddInfo->count, expectedAmount);
|
|
|
|
EXPECT_EQ(cloneAddInfo->type, CreatureID(0));
|
|
|
|
EXPECT_EQ(cloneAddInfo->side, BattleSide::ATTACKER);
|
|
|
|
EXPECT_TRUE(cloneAddInfo->position.isValid());
|
|
|
|
EXPECT_NE(cloneAddInfo->position, originalPosition);
|
|
|
|
EXPECT_TRUE(cloneAddInfo->summoned);
|
|
|
|
}
|
|
|
|
|
2024-01-03 02:26:15 +02:00
|
|
|
TEST_F(CloneApplyTest, DISABLED_SetsClonedFlag)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
EXPECT_CALL(*battleFake, addUnitBonus(_,_)).Times(AtLeast(1));
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
subject->apply(&serverMock, &mechanicsMock, target);
|
|
|
|
|
|
|
|
GTEST_ASSERT_NE(cloneState, nullptr);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(cloneState->cloned);
|
|
|
|
}
|
|
|
|
|
2024-01-03 02:26:15 +02:00
|
|
|
TEST_F(CloneApplyTest, DISABLED_SetsCloneLink)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
|
|
|
EXPECT_CALL(*battleFake, addUnitBonus(_,_)).Times(AtLeast(1));
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
subject->apply(&serverMock, &mechanicsMock, target);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
EXPECT_EQ(originalState->cloneID, cloneId);
|
|
|
|
}
|
|
|
|
|
2024-01-03 02:26:15 +02:00
|
|
|
TEST_F(CloneApplyTest, DISABLED_SetsLifetimeMarker)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
setDefaultExpectations();
|
|
|
|
|
2022-06-28 10:05:30 +02:00
|
|
|
EXPECT_CALL(*battleFake, addUnitBonus(_, _)).WillOnce(Invoke(this, &CloneApplyTest::checkCloneLifetimeMarker));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
subject->apply(&serverMock, &mechanicsMock, target);
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|