diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2016-03-30 08:47:31 -0400 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2016-03-30 08:47:31 -0400 |
commit | 0b1bfa28f33410acc1c3b95df1c1b748ce55b447 (patch) | |
tree | 807e942cfb92cb631b02ec0079da63838dd6741f /src/quest.cpp | |
parent | c35571e37bdd6d2fe9b95e4265c150265585f3a9 (diff) | |
parent | a9a9777190086bd2ce2aa54e20a1101509614463 (diff) |
Inv and textures
Diffstat (limited to 'src/quest.cpp')
-rw-r--r-- | src/quest.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/quest.cpp b/src/quest.cpp new file mode 100644 index 0000000..4ab827f --- /dev/null +++ b/src/quest.cpp @@ -0,0 +1,68 @@ +#include <algorithm>
+
+#include <quest.hpp>
+#include <entities.hpp>
+
+extern Player *player;
+
+int QuestHandler::assign(std::string title,std::string desc,std::string req){
+ Quest tmp;
+ char *tok;
+
+ tmp.title = title;
+ tmp.desc = desc;
+
+ tok = strtok( &req[0], "\n\r\t," );
+ tmp.need.emplace_back( "", 0 );
+
+ while ( tok ) {
+ if ( !tmp.need.back().first.empty() ) {
+ tmp.need.back().second = atoi( tok );
+ tmp.need.emplace_back( "", 0 );
+ } else
+ tmp.need.back().first = tok;
+
+ tok = strtok( NULL, "\n\r\t," );
+ }
+
+ tmp.need.pop_back();
+ current.push_back( tmp );
+
+ return 0;
+}
+
+int QuestHandler::drop(std::string title){
+ current.erase( std::remove_if( current.begin(),
+ current.end(),
+ [&](Quest q){ return q.title == title; }),
+ current.end() );
+
+ return 0;
+}
+
+int QuestHandler::finish(std::string t){
+ for ( auto c = current.begin(); c != current.end(); c++ ) {
+ if ( (*c).title == t ) {
+ for ( auto &n : (*c).need ) {
+ if ( player->inv->hasItem( n.first ) < n.second )
+ return 0;
+ }
+
+ for ( auto &n : (*c).need )
+ player->inv->takeItem( n.first, n.second );
+ current.erase( c );
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+bool QuestHandler::hasQuest(std::string t){
+ for ( auto &c : current ) {
+ if ( c.title == t )
+ return true;
+ }
+
+ return false;
+}
|