-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrap_spell.cpp
More file actions
24 lines (20 loc) · 758 Bytes
/
trap_spell.cpp
File metadata and controls
24 lines (20 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "trap_spell.h"
#include "game_map.h"
bool TrapSpell::cast(GameMap& map, Position casterPos, Position targetPos) {
int distance = abs(casterPos.getX() - targetPos.getX()) +
abs(casterPos.getY() - targetPos.getY());
if (distance > range) {
return false;
}
if (!map.isPositionValid(targetPos)) {
return false;
}
if(map.getCell(targetPos).getType() == MapCell::Type::EMPTY && !map.getCell(targetPos).isUsed()){
MapCell& cell = map.getCell(casterPos);
Entity* entity = cell.getEntity();
map.getCell(targetPos).setType(MapCell::Type::TRAP);
map.getCell(targetPos).setTrapDamage(damage * entity->getLevel());
return true;
}
return false;
}