2022-11-24 16:30:04 +02:00
|
|
|
/*
|
2022-12-11 23:16:23 +02:00
|
|
|
* BattleEffectsController.cpp, part of VCMI engine
|
2022-11-24 16:30:04 +02:00
|
|
|
*
|
|
|
|
* 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"
|
2022-12-09 13:38:46 +02:00
|
|
|
#include "BattleEffectsController.h"
|
2022-11-24 16:30:04 +02:00
|
|
|
|
2022-12-09 13:38:46 +02:00
|
|
|
#include "BattleAnimationClasses.h"
|
2022-12-21 17:06:47 +02:00
|
|
|
#include "BattleWindow.h"
|
2022-12-09 13:38:46 +02:00
|
|
|
#include "BattleInterface.h"
|
|
|
|
#include "BattleInterfaceClasses.h"
|
|
|
|
#include "BattleFieldController.h"
|
|
|
|
#include "BattleStacksController.h"
|
|
|
|
#include "BattleRenderer.h"
|
2022-11-28 16:43:38 +02:00
|
|
|
|
2022-11-24 16:30:04 +02:00
|
|
|
#include "../CMusicHandler.h"
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../render/Canvas.h"
|
|
|
|
#include "../render/CAnimation.h"
|
2023-07-31 18:50:55 +02:00
|
|
|
#include "../render/Graphics.h"
|
2022-11-28 16:43:38 +02:00
|
|
|
|
2022-11-24 16:30:04 +02:00
|
|
|
#include "../../CCallback.h"
|
|
|
|
#include "../../lib/battle/BattleAction.h"
|
2023-08-23 14:07:50 +02:00
|
|
|
#include "../../lib/filesystem/ResourcePath.h"
|
2022-11-24 16:30:04 +02:00
|
|
|
#include "../../lib/NetPacks.h"
|
|
|
|
#include "../../lib/CStack.h"
|
|
|
|
#include "../../lib/IGameEventsReceiver.h"
|
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
BattleEffectsController::BattleEffectsController(BattleInterface & owner):
|
2022-11-24 16:30:04 +02:00
|
|
|
owner(owner)
|
2022-12-21 23:29:56 +02:00
|
|
|
{
|
|
|
|
loadColorMuxers();
|
|
|
|
}
|
2022-11-24 16:30:04 +02:00
|
|
|
|
2022-12-17 17:35:15 +02:00
|
|
|
void BattleEffectsController::displayEffect(EBattleEffect effect, const BattleHex & destTile)
|
2022-11-24 16:30:04 +02:00
|
|
|
{
|
2023-09-04 12:03:15 +02:00
|
|
|
displayEffect(effect, AudioPath(), destTile);
|
2022-11-24 16:30:04 +02:00
|
|
|
}
|
|
|
|
|
2023-09-04 12:03:15 +02:00
|
|
|
void BattleEffectsController::displayEffect(EBattleEffect effect, const AudioPath & soundFile, const BattleHex & destTile)
|
2022-11-24 16:30:04 +02:00
|
|
|
{
|
2022-12-17 17:35:15 +02:00
|
|
|
size_t effectID = static_cast<size_t>(effect);
|
2022-12-01 22:06:42 +02:00
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
AnimationPath customAnim = AnimationPath::builtinTODO(graphics->battleACToDef[effectID][0]);
|
2022-12-01 22:06:42 +02:00
|
|
|
|
2022-12-25 21:35:13 +02:00
|
|
|
CCS->soundh->playSound( soundFile );
|
|
|
|
|
2022-12-25 21:39:55 +02:00
|
|
|
owner.stacksController->addNewAnim(new EffectAnimation(owner, customAnim, destTile));
|
2022-11-24 16:30:04 +02:00
|
|
|
}
|
|
|
|
|
2022-12-09 13:26:17 +02:00
|
|
|
void BattleEffectsController::battleTriggerEffect(const BattleTriggerEffect & bte)
|
2022-11-24 16:30:04 +02:00
|
|
|
{
|
2023-03-19 01:40:31 +02:00
|
|
|
owner.checkForAnimations();
|
2022-12-10 00:25:11 +02:00
|
|
|
|
2023-08-30 21:07:02 +02:00
|
|
|
const CStack * stack = owner.getBattle()->battleGetStackByID(bte.stackID);
|
2022-11-24 16:30:04 +02:00
|
|
|
if(!stack)
|
|
|
|
{
|
|
|
|
logGlobal->error("Invalid stack ID %d", bte.stackID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//don't show animation when no HP is regenerated
|
2023-05-01 00:20:01 +02:00
|
|
|
switch(static_cast<BonusType>(bte.effect))
|
2022-11-24 16:30:04 +02:00
|
|
|
{
|
2023-05-01 00:20:01 +02:00
|
|
|
case BonusType::HP_REGENERATION:
|
2023-09-04 12:03:15 +02:00
|
|
|
displayEffect(EBattleEffect::REGENERATION, AudioPath::builtin("REGENER"), stack->getPosition());
|
2022-11-24 16:30:04 +02:00
|
|
|
break;
|
2023-05-01 00:20:01 +02:00
|
|
|
case BonusType::MANA_DRAIN:
|
2023-09-04 12:03:15 +02:00
|
|
|
displayEffect(EBattleEffect::MANA_DRAIN, AudioPath::builtin("MANADRAI"), stack->getPosition());
|
2022-11-24 16:30:04 +02:00
|
|
|
break;
|
2023-05-01 00:20:01 +02:00
|
|
|
case BonusType::POISON:
|
2023-09-04 12:03:15 +02:00
|
|
|
displayEffect(EBattleEffect::POISON, AudioPath::builtin("POISON"), stack->getPosition());
|
2022-11-24 16:30:04 +02:00
|
|
|
break;
|
2023-05-01 00:20:01 +02:00
|
|
|
case BonusType::FEAR:
|
2023-09-04 12:03:15 +02:00
|
|
|
displayEffect(EBattleEffect::FEAR, AudioPath::builtin("FEAR"), stack->getPosition());
|
2022-11-24 16:30:04 +02:00
|
|
|
break;
|
2023-05-01 00:20:01 +02:00
|
|
|
case BonusType::MORALE:
|
2022-11-24 16:30:04 +02:00
|
|
|
{
|
|
|
|
std::string hlp = CGI->generaltexth->allTexts[33];
|
|
|
|
boost::algorithm::replace_first(hlp,"%s",(stack->getName()));
|
2023-09-04 12:03:15 +02:00
|
|
|
displayEffect(EBattleEffect::GOOD_MORALE, AudioPath::builtin("GOODMRLE"), stack->getPosition());
|
2022-12-21 17:02:53 +02:00
|
|
|
owner.appendBattleLog(hlp);
|
2022-11-24 16:30:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2023-03-19 01:40:31 +02:00
|
|
|
owner.waitForAnimations();
|
2022-11-24 16:30:04 +02:00
|
|
|
}
|
|
|
|
|
2023-08-17 18:18:14 +02:00
|
|
|
void BattleEffectsController::startAction(const BattleAction & action)
|
2022-11-24 16:30:04 +02:00
|
|
|
{
|
2023-03-19 01:40:31 +02:00
|
|
|
owner.checkForAnimations();
|
2022-12-10 00:25:11 +02:00
|
|
|
|
2023-08-30 21:07:02 +02:00
|
|
|
const CStack *stack = owner.getBattle()->battleGetStackByID(action.stackNumber);
|
2022-11-24 16:30:04 +02:00
|
|
|
|
2023-08-17 18:18:14 +02:00
|
|
|
switch(action.actionType)
|
2022-11-24 16:30:04 +02:00
|
|
|
{
|
|
|
|
case EActionType::WAIT:
|
2022-12-21 17:02:53 +02:00
|
|
|
owner.appendBattleLog(stack->formatGeneralMessage(136));
|
2022-11-24 16:30:04 +02:00
|
|
|
break;
|
|
|
|
case EActionType::BAD_MORALE:
|
2022-12-21 17:02:53 +02:00
|
|
|
owner.appendBattleLog(stack->formatGeneralMessage(-34));
|
2023-09-04 12:03:15 +02:00
|
|
|
displayEffect(EBattleEffect::BAD_MORALE, AudioPath::builtin("BADMRLE"), stack->getPosition());
|
2022-11-24 16:30:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-03-19 01:40:31 +02:00
|
|
|
owner.waitForAnimations();
|
2022-11-24 16:30:04 +02:00
|
|
|
}
|
|
|
|
|
2022-12-09 13:26:17 +02:00
|
|
|
void BattleEffectsController::collectRenderableObjects(BattleRenderer & renderer)
|
2022-11-24 16:30:04 +02:00
|
|
|
{
|
|
|
|
for (auto & elem : battleEffects)
|
|
|
|
{
|
2023-01-05 14:16:01 +02:00
|
|
|
renderer.insert( EBattleFieldLayer::EFFECTS, elem.tile, [&elem](BattleRenderer::RendererRef canvas)
|
2022-12-02 17:49:38 +02:00
|
|
|
{
|
|
|
|
int currentFrame = static_cast<int>(floor(elem.currentFrame));
|
|
|
|
currentFrame %= elem.animation->size();
|
2022-11-24 16:30:04 +02:00
|
|
|
|
2023-03-26 02:48:11 +02:00
|
|
|
auto img = elem.animation->getImage(currentFrame, static_cast<size_t>(elem.type));
|
2022-11-24 16:30:04 +02:00
|
|
|
|
2023-01-05 14:16:01 +02:00
|
|
|
canvas.draw(img, elem.pos);
|
2022-12-02 17:49:38 +02:00
|
|
|
});
|
2022-11-24 16:30:04 +02:00
|
|
|
}
|
|
|
|
}
|
2022-12-21 23:29:56 +02:00
|
|
|
|
|
|
|
void BattleEffectsController::loadColorMuxers()
|
|
|
|
{
|
2023-09-01 23:26:14 +02:00
|
|
|
const JsonNode config(JsonPath::builtin("config/battleEffects.json"));
|
2022-12-21 23:29:56 +02:00
|
|
|
|
|
|
|
for(auto & muxer : config["colorMuxers"].Struct())
|
|
|
|
{
|
|
|
|
ColorMuxerEffect effect;
|
|
|
|
std::string identifier = muxer.first;
|
|
|
|
|
|
|
|
for (const JsonNode & entry : muxer.second.Vector() )
|
|
|
|
{
|
|
|
|
effect.timePoints.push_back(entry["time"].Float());
|
|
|
|
effect.filters.push_back(ColorFilter::genFromJson(entry));
|
|
|
|
}
|
|
|
|
colorMuxerEffects[identifier] = effect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const ColorMuxerEffect & BattleEffectsController::getMuxerEffect(const std::string & name)
|
|
|
|
{
|
|
|
|
static const ColorMuxerEffect emptyEffect;
|
|
|
|
|
|
|
|
if (colorMuxerEffects.count(name))
|
|
|
|
return colorMuxerEffects[name];
|
|
|
|
|
|
|
|
logAnim->error("Failed to find color muxer effect named '%s'!", name);
|
|
|
|
return emptyEffect;
|
|
|
|
}
|