Files
vcmi/luascript/api/library/Bonus.h
T

67 lines
2.1 KiB
C++
Raw Normal View History

2026-05-30 17:34:02 +03:00
/*
* Bonus.h, 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
*
*/
#pragma once
#include "../../LuaWrapper.h"
2026-06-06 08:14:44 +03:00
#include "../MethodRegistrar.h"
2026-05-30 17:34:02 +03:00
#include "../../../lib/bonuses/Bonus.h"
#include "../../../lib/bonuses/BonusList.h"
#include "../../../lib/bonuses/BonusEnum.h"
VCMI_LIB_NAMESPACE_BEGIN
namespace scripting::api
2026-05-30 17:34:02 +03:00
{
class BonusProxy : public CopyableWrapper<Bonus, BonusProxy>
{
public:
2026-06-06 08:14:44 +03:00
static constexpr std::string_view luaName = "Bonus";
2026-06-06 23:19:45 +03:00
static constexpr std::string_view luaDescription =
2026-06-09 03:47:06 +03:00
"A single effect contributing to target abilities (e.g. +5 attack, "
2026-06-06 23:19:45 +03:00
"immunity to fire spells). Carries type, value, source, duration, stacking key. "
"Scripts read bonuses through `getBonuses(...)` and construct new ones via "
2026-06-09 03:47:06 +03:00
"addUnitBonus or addBattleBonus in ServerCallback.";
2026-06-06 08:14:44 +03:00
static void registerMethods(MethodRegistrar & R);
2026-05-30 17:34:02 +03:00
2026-05-31 20:06:18 +03:00
static std::string getType(const Bonus & b);
static si32 getVal(const Bonus & b);
static std::string getSubtype(const Bonus & b);
static std::string getSourceID(const Bonus & b);
static BonusSource getSource(const Bonus & b);
2026-05-31 20:06:18 +03:00
static std::vector<BonusDuration::BonusDuration> getDuration(const Bonus & b);
static BonusValueType getValType(const Bonus & b);
2026-05-31 20:06:18 +03:00
static std::string getStacking(const Bonus & b);
static si16 getTurnsRemain(const Bonus & b);
static bool isHidden(const Bonus & b);
static si32 getParametersAsNumber(const Bonus & b);
2026-05-30 17:34:02 +03:00
};
class BonusListProxy : public CopyableWrapper<BonusList, BonusListProxy>
{
public:
2026-06-06 08:14:44 +03:00
static constexpr std::string_view luaName = "BonusList";
2026-06-06 23:19:45 +03:00
static constexpr std::string_view luaDescription =
2026-06-09 03:47:06 +03:00
"A collection of Bonus values returned by `getBonuses(...)`. Use `size()` and "
2026-06-06 23:19:45 +03:00
"`getBonus(index)` to iterate. A copy of the engine's internal list at the moment of "
2026-06-09 03:47:06 +03:00
"the call — changes to holder afterwards will not affect this snapshot.";
2026-06-06 08:14:44 +03:00
static void registerMethods(MethodRegistrar & R);
2026-05-30 17:34:02 +03:00
2026-05-31 20:06:18 +03:00
static int32_t size(const BonusList & list);
static Bonus getBonus(const BonusList & list, int32_t index);
2026-05-30 17:34:02 +03:00
};
}
VCMI_LIB_NAMESPACE_END