Skip to content

Commit

Permalink
#26: finished implementing Being respawn
Browse files Browse the repository at this point in the history
  • Loading branch information
crankycyclops committed May 29, 2013
1 parent fe396b9 commit d63b559
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/core/event/triggers/respawn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "../../include/event/triggers/respawn.h"
#include "../../include/timer/jobs/respawn.h"

using namespace std;

namespace core { namespace event {


void RespawnEventTrigger::execute(EventArgumentList args) {

Game *game = boost::get<Game *>(args[0]);
Being *being = static_cast<Being *>(boost::get<Entity *>(args[1]));

if (being->getRespawnEnabled()) {

int in = being->getRespawnInterval();

// we have to wait a certain number of clock ticks
if (in > 0) {
RespawnTimerJob *j = new RespawnTimerJob(game, in, 1, in, being);
game->insertTimerJob(j);
}

// respawn right away
else {
being->doRespawn();
}
}

continueExecutionFlag = true;
allowActionFlag = true;
}
}}

4 changes: 4 additions & 0 deletions src/core/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "include/event/triggers/autoattack.h"
#include "include/event/triggers/deathdrop.h"
#include "include/event/triggers/respawn.h"


using namespace std;
Expand Down Expand Up @@ -130,10 +131,13 @@ namespace core {
actions->setAction("fight", attack);
}

// NOTE: order is important!
void Game::initEvents() {

eventListener->add("afterGotoLocation", new AutoAttackEventTrigger());

eventListener->add("afterDie", new DeathDropEventTrigger());
eventListener->add("afterDie", new RespawnEventTrigger());
}


Expand Down
32 changes: 32 additions & 0 deletions src/core/include/event/triggers/respawn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef RESPAWNEVENTTRIGGER_H
#define RESPAWNEVENTTRIGGER_H


#include "../eventtrigger.h"


using namespace std;

namespace core { namespace event {


class RespawnEventTrigger: public EventTrigger {

public:

/*
Triggers a Being's respawning.
Input:
list of arguments
Output:
(none)
*/
virtual void execute(EventArgumentList args);
};
}}


#endif

0 comments on commit d63b559

Please sign in to comment.