-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First unstable buggy release!
- Loading branch information
Showing
83 changed files
with
22,977 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
*.[oa] | ||
*vgcore* | ||
.vscode/** | ||
*.txt | ||
*.out | ||
*.exe | ||
*test* | ||
*.gch | ||
.idea | ||
*.pro.user* | ||
libAdapter.a | ||
*Makefile | ||
*debug* | ||
*Debug* | ||
*qmake* | ||
rasseki_game | ||
temp | ||
ui_*.h | ||
qrc_resource.cpp | ||
*.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* by stanford */ | ||
|
||
#include <cstdlib> | ||
#include <chrono> | ||
#include <thread> | ||
|
||
#include "action.h" | ||
#include "actions_config.h" | ||
|
||
#include "session_data.h" | ||
#include "libAdapter.h" | ||
using namespace SessionData; | ||
|
||
#include <iostream> | ||
using std::cout; | ||
using std::endl; | ||
|
||
Action::Action(int chance, str sNote, str fNote, int dur) | ||
: chance(chance), successNote(sNote), failureNote(fNote), duration(dur) {} | ||
|
||
void Action::Run() const { | ||
bool result = ThrowDice(); | ||
if (result) { | ||
gameData.WriteToDiary(successNote); | ||
MakeAction(); | ||
std::chrono::milliseconds ms(duration * DURATION_FACTOR); | ||
std::this_thread::sleep_for(ms); | ||
} else { | ||
gameData.WriteToDiary(failureNote); | ||
} | ||
} | ||
|
||
bool Action::CheckCondition() const { | ||
return true; | ||
} | ||
|
||
bool Action::ThrowDice() const { | ||
srand(time(NULL)); | ||
return (rand() % MAX_CHANCE_PERCENT) < chance; | ||
} | ||
|
||
|
||
GiveArtifact::GiveArtifact( | ||
int chance, | ||
str sNote, str fNote, | ||
int dur, | ||
str artID | ||
) : Action(chance, sNote, fNote, dur), artifactID(artID) {} | ||
|
||
void GiveArtifact::MakeAction() const { | ||
/* by salman */ | ||
gameData.hero.GetInventory()->AddArtifact(artifactID); | ||
gameData.changeInventory = true; | ||
|
||
// prepared for best times, when artifact modifiers will be added | ||
// artifact.ApplyModifier() | ||
} | ||
|
||
|
||
TakeAwayArtifact::TakeAwayArtifact( | ||
int chance, | ||
str sNote, str fNote, | ||
int dur, | ||
str artID | ||
) : Action(chance, sNote, fNote, dur), artifactID(artID) {} | ||
|
||
void TakeAwayArtifact::MakeAction() const { | ||
/* by salman */ | ||
gameData.hero.GetInventory()->RemoveArtifact(artifactID); | ||
gameData.changeInventory = true; | ||
} | ||
|
||
|
||
Teleport::Teleport( | ||
int chance, | ||
str sNote, str fNote, | ||
int dur, | ||
Coord dest | ||
) : Action(chance, sNote, fNote, dur), destination(dest) {} | ||
|
||
void Teleport::MakeAction() const { | ||
/* by salman */ | ||
} | ||
|
||
|
||
Wait::Wait(int chance, str sNote, str fNote, int dur) | ||
: Action(chance, sNote, fNote, dur) {} | ||
|
||
void Wait::MakeAction() const { | ||
/* just waiting */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* by stanford */ | ||
|
||
#ifndef ACTIONS | ||
#define ACTIONS | ||
|
||
#include <string> | ||
using str = std::string; | ||
|
||
#include "matrix.hpp" | ||
|
||
|
||
class Action { | ||
public: | ||
void Run() const; | ||
Action(int chance, str sNote, str fNote, int dur); | ||
private: | ||
virtual void MakeAction() const = 0; | ||
virtual bool CheckCondition() const; | ||
|
||
bool ThrowDice() const; // decides, if action may be run, using chance | ||
int chance; // percents, 0 - 100 | ||
void PrintToDiary(const bool success = true) const; | ||
str successNote; | ||
str failureNote; | ||
short duration; | ||
}; | ||
|
||
|
||
/* ***************************** ACTION TYPES *************************** */ | ||
|
||
class ActionFactory; // forward declaration | ||
|
||
class GiveArtifact : public Action { | ||
friend ActionFactory; | ||
private: | ||
str artifactID; | ||
GiveArtifact(int chance, str sNote, str fNote, int dur, str artID); | ||
void MakeAction() const; | ||
}; | ||
|
||
class TakeAwayArtifact : public Action { | ||
friend ActionFactory; | ||
private: | ||
str artifactID; | ||
TakeAwayArtifact(int chance, str sNote, str fNote, int dur, str artID); | ||
void MakeAction() const; | ||
}; | ||
|
||
class Teleport : public Action { | ||
friend ActionFactory; | ||
private: | ||
Coord destination; | ||
Teleport(int chance, str sNote, str fNote, int dur, Coord dest); | ||
void MakeAction() const; | ||
}; | ||
|
||
class Wait : public Action { | ||
friend ActionFactory; | ||
private: | ||
Wait(int chance, str sNote, str fNote, int dur); | ||
void MakeAction() const; | ||
}; | ||
|
||
|
||
// prepared for better times, when creatures will be added | ||
/* class BeginFight : public Action { | ||
friend ActionFactory; | ||
private: | ||
BeginFight(int chance, str sNote, str fNote, int dur, str enemyID); | ||
str enemyID; | ||
void MakeAction() const; | ||
}; | ||
class Fight : public Action { | ||
friend ActionFactory; | ||
private: | ||
BeginFight(int chance, str sNote, str fNote, int dur, str enemyID); | ||
str enemyID; | ||
void MakeAction() const; | ||
}; */ | ||
|
||
#endif // ACTIONS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* by stanford */ | ||
|
||
#include "action_factory.h" | ||
#include "actions_config.h" | ||
#include "session_data.h" | ||
|
||
// for error printing, should be changed to QT error printer | ||
#include <iostream> | ||
using std::cout; | ||
using std::endl; | ||
|
||
using std::stoi; | ||
|
||
bool ActionData::isValid() { | ||
|
||
if (/* actionList.find(type) == actionList.end() */0) { | ||
cout << "FAIL" << endl; | ||
cout << "Action type \"" << type << "\" is invalid." << endl; | ||
return false; | ||
} | ||
|
||
if (chance > MAX_CHANCE_PERCENT | ||
|| chance < MIN_CHANCE_PERCENT) { | ||
cout << "FAIL" << endl; | ||
cout << "In action with type \"" << type | ||
<< "\": chance is invalid." << endl; | ||
return false; | ||
} | ||
|
||
if (duration > MAX_ACTION_DURATION | ||
|| duration < MIN_ACTION_DURATION) { | ||
cout << "FAIL" << endl; | ||
cout << "In action with type \"" << type | ||
<< "\": invalid action duration, it can be between " | ||
<< MIN_ACTION_DURATION << " and " << MAX_ACTION_DURATION | ||
<< " seconds." << endl; | ||
return false; | ||
} | ||
|
||
if (successNote.empty() | ||
|| failureNote.empty() | ||
) { | ||
cout << "FAIL" << endl; | ||
cout << "In action with type \"" << type | ||
<< "\": diary notes can't be empty." << endl; | ||
return false; | ||
} | ||
|
||
if (type == "give" | ||
|| type == "take_away") { | ||
if (!SessionData::artifactsData.ArtifactExists(artifactID)) { | ||
cout << "FAIL" << endl; | ||
cout << "In action with type \"" << type | ||
<< "\": artifact with ID " << artifactID | ||
<< " does not exist." << endl; | ||
return false; | ||
} | ||
} else if (type == "teleport") { | ||
if (!SessionData::surfaceData.CoordIsValid(coord)) { | ||
cout << "FAIL" << endl; | ||
cout << "In action with type \"" << type | ||
<< "\": invalid teleport point for this location." << endl; | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
unique_ptr<Action> ActionFactory::Create(ActionData &a) { | ||
if (a.type == "give") { | ||
/* create GiveArtifact action */ | ||
unique_ptr<Action> newAction( new GiveArtifact( | ||
a.chance, | ||
a.successNote, | ||
a.failureNote, | ||
a.duration, | ||
a.artifactID | ||
) ); | ||
return newAction; | ||
} else if (a.type == "take_away") { | ||
/* create TakeAwayArtifact action */ | ||
unique_ptr<Action> newAction( new TakeAwayArtifact( | ||
a.chance, | ||
a.successNote, | ||
a.failureNote, | ||
a.duration, | ||
a.artifactID | ||
) ); | ||
return newAction; | ||
} else if (a.type == "wait") { | ||
/* create Wait action */ | ||
unique_ptr<Action> newAction( new Wait( | ||
a.chance, | ||
a.successNote, | ||
a.failureNote, | ||
a.duration | ||
) ); | ||
return newAction; | ||
} else if (a.type == "teleport") { | ||
/* create Teleport action */ | ||
unique_ptr<Action> newAction( new Teleport( | ||
a.chance, | ||
a.successNote, | ||
a.failureNote, | ||
a.duration, | ||
a.coord | ||
) ); | ||
return newAction; | ||
} | ||
|
||
return nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* by stanford */ | ||
|
||
#ifndef ACTION_FACTORY | ||
#define ACTION_FACTORY | ||
|
||
#include <unordered_map> | ||
using std::unordered_map; | ||
|
||
#include <memory> | ||
using std::move; | ||
using std::unique_ptr; | ||
|
||
#include "action.h" | ||
|
||
struct ActionData { | ||
|
||
// common values | ||
str type; | ||
int chance; | ||
str successNote, failureNote; | ||
int duration; | ||
|
||
// for artifact-using actions | ||
str artifactID; | ||
|
||
// for coord-using actions | ||
Coord coord; | ||
|
||
bool isValid(); | ||
}; | ||
|
||
class ActionFactory { | ||
public: | ||
unique_ptr<Action> Create(ActionData &actionData); | ||
}; | ||
|
||
#endif // ACTION_FACTORY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* by stanford */ | ||
|
||
#include "libs/json.hpp" | ||
using json = nlohmann::json; | ||
|
||
#include "action_factory.h" | ||
|
||
void from_json(const json &j, Coord &c) { | ||
c.x = j.at("x").get<int>(); | ||
c.y = j.at("y").get<int>(); | ||
} | ||
|
||
void from_json(const json &j, ActionData &action) { | ||
action.type = j.at("type").get<str>(); | ||
action.chance = j.at("chance").get<int>(); | ||
action.successNote = j.at("successNote").get<str>(); | ||
action.failureNote = j.at("failureNote").get<str>(); | ||
action.duration = j.at("duration").get<int>(); | ||
|
||
try { action.artifactID = j.at("artifact_id").get<str>(); | ||
} catch(nlohmann::detail::out_of_range) {} | ||
|
||
try { action.coord = j.at("coordinate").get<Coord>(); | ||
} catch(nlohmann::detail::out_of_range) {} | ||
|
||
// prepared for better times, when creatures will be added | ||
/* try { action.values["enemy_ID"] = j.at("enemy_ID").get<str>(); | ||
} catch(nlohmann::detail::out_of_range) {} */ | ||
} |
Oops, something went wrong.