summaryrefslogtreecommitdiff
path: root/src/being/castingeffect.cpp
blob: b0218647697381a22993e554230aa248763a3cbf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 *  The ManaVerse Client
 *  Copyright (C) 2011-2019  The ManaPlus Developers
 *
 *  This file is part of The ManaVerse Client.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "being/castingeffect.h"

#include "configuration.h"

#include "const/resources/map/map.h"

#include "gui/userpalette.h"

#include "render/graphics.h"

#include "resources/sprite/animatedsprite.h"

#include "utils/checkutils.h"
#include "utils/delete2.h"

#include "debug.h"

CastingEffect::CastingEffect(const int skillId,
                             const int skillLevel,
                             const std::string &animation,
                             const int x,
                             const int y,
                             const int range) :
    Actor(),
    mSprite(animation.empty() ? nullptr :
        AnimatedSprite::load(paths.getStringValue("sprites") + animation, 0)),
    mRectX((x - range) * mapTileSize),
    mRectY((y - range) * mapTileSize),
    mRectSize(range * mapTileSize * 2 + mapTileSize),
    mAnimationX(mRectX + (mRectSize - (mSprite != nullptr ?
        mSprite->getWidth() : 0)) / 2),
    mAnimationY(mRectY + (mRectSize - (mSprite != nullptr ?
        mSprite->getHeight() : 0)) / 2)
{
    mPixelX = x * mapTileSize;
    mPixelY = y * mapTileSize;
    mYDiff = range * mapTileSize + 31;
    if (mSprite == nullptr)
    {
        reportAlways("Skill %d/%d casting animation '%s' load failed",
            skillId,
            skillLevel,
            animation.c_str())
    }
}

CastingEffect::~CastingEffect()
{
    delete2(mSprite)
}

void CastingEffect::draw(Graphics *const graphics,
                         const int offsetX,
                         const int offsetY) const
{
    graphics->setColor(userPalette->getColorWithAlpha(
        UserColorId::ATTACK_RANGE_BORDER));

    graphics->drawRectangle(Rect(
        mRectX + offsetX,
        mRectY + offsetY,
        mRectSize,
        mRectSize));
    if (mSprite != nullptr)
    {
        mSprite->drawRescaled(graphics,
            mRectX + offsetX,
            mRectY + offsetY,
            mRectSize,
            mRectSize);
    }
}

void CastingEffect::update(const int time)
{
    if (mSprite != nullptr)
        mSprite->update(time);
}

bool CastingEffect::isTerminated() const
{
    if (mSprite != nullptr)
        return mSprite->isTerminated();
    return false;
}