OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
touchdamage.cpp
Go to the documentation of this file.
1#include "touchdamage.h"
2
3#include "world/objects/npc.h"
4#include "world/world.h"
5#include "game/serialize.h"
6
7TouchDamage::TouchDamage(Vob* parent, World &world, const zenkit::VTouchDamage& dmg, Flags flags)
8 :AbstractTrigger(parent,world,dmg,flags) {
9 barrier = dmg.barrier;
10 blunt = dmg.blunt;
11 edge = dmg.edge;
12 fire = dmg.fire;
13 fly = dmg.fly;
14 magic = dmg.magic;
15 point = dmg.point;
16 fall = dmg.fall;
17 damage = dmg.damage;
18 repeatDelaySec = dmg.repeat_delay_sec;
19 }
20
21void TouchDamage::onTrigger(const TriggerEvent&/*evt*/) {
22 }
23
24void TouchDamage::onIntersect(Npc& n) {
27 }
28
29void TouchDamage::tick(uint64_t dt) {
31
32 if(world.tickCount()<=repeatTimeout)
33 return;
34
35 for(auto npc:intersections()) {
36 bool mask[zenkit::DamageType::NUM] = {};
37 mask[zenkit::DamageType::BARRIER] = barrier;
38 mask[zenkit::DamageType::BLUNT] = blunt;
39 mask[zenkit::DamageType::EDGE] = edge;
40 mask[zenkit::DamageType::FIRE] = fire;
41 mask[zenkit::DamageType::FLY] = fly;
42 mask[zenkit::DamageType::MAGIC] = magic;
43 mask[zenkit::DamageType::POINT] = point;
44 mask[zenkit::DamageType::FALL] = fall;
45
46 auto& hnpc = npc->handle();
47 for(size_t i=0; i<zenkit::DamageType::NUM; ++i) {
48 if(!mask[i])
49 continue;
50 takeDamage(*npc,int32_t(damage),hnpc.protection[i]);
51 }
52 }
53
54 repeatTimeout = world.tickCount() + uint64_t(repeatDelaySec*1000);
55
56 if(intersections().empty())
58 }
59
60void TouchDamage::takeDamage(Npc& npc, int32_t val, int32_t prot) {
61 if(prot<0) // Filter immune
62 return;
63 npc.changeAttribute(ATR_HITPOINTS,-std::max(val-prot,0),false);
64 }
const std::vector< Npc * > & intersections() const
virtual void onIntersect(Npc &n)
virtual void tick(uint64_t dt)
Definition npc.h:25
void changeAttribute(Attribute a, int32_t val, bool allowUnconscious)
Definition npc.cpp:1177
TouchDamage(Vob *parent, World &world, const zenkit::VTouchDamage &data, Flags flags)
Definition vob.h:11
Flags
Definition vob.h:13
World & world
Definition vob.h:45
Definition world.h:31
uint64_t tickCount() const
Definition world.cpp:387
@ ATR_HITPOINTS
Definition constants.h:463