From a9a925ca4781a892fe55139a39a07589a049bc6f Mon Sep 17 00:00:00 2001 From: Anselme Date: Thu, 17 Mar 2016 15:16:18 +0100 Subject: [PATCH] added Event structures, fixed a few bugs --- app/rpgmodule.cpp | 81 +++++++++++++++++++++++++++++++++++++++++------ app/rpgmodule.h | 63 ++++++++++++++++++++++++++++++++++-- 2 files changed, 133 insertions(+), 11 deletions(-) diff --git a/app/rpgmodule.cpp b/app/rpgmodule.cpp index a3a534d..96aecd6 100644 --- a/app/rpgmodule.cpp +++ b/app/rpgmodule.cpp @@ -18,6 +18,66 @@ QString RPGCharacter::toString() return str; } +void RPGModule::initVillages() +{ + Village v; + + Event eventBlacksmith; + eventBlacksmith.name = "blacksmith"; + eventBlacksmith.description = "you approach the strong bearded blacksmith, and asks him to show his goods."; + eventBlacksmith.type = Event::TRADER; + Trade t; + t.goldPrice = 100; + t.item = "rusty sword"; + Trader *blacksmithTrader = new Trader(); + blacksmithTrader->push_back(t); + eventBlacksmith.trader = blacksmithTrader; + + Event eventInn; + eventInn.name = "inn"; + eventInn.description = "you enter the inn, there are plenty of townsfolk drinking and eating loudly."; + eventInn.type = Event::TRADER; + t.goldPrice = 20; + t.item = "night of rest"; + Trader *innkeeperTrader = new Trader(); + innkeeperTrader->push_back(t); + eventInn.trader = innkeeperTrader; + + v.x = 7; + v.y = 4; + v.name = "Dornwich"; + v.events.push_back(eventInn); + v.events.push_back(eventBlacksmith); + villages.push_back(v); + v.x = 1; + v.y = 11; + v.name = "Dawsbury"; + v.events.push_back(eventInn); + villages.push_back(v); + v.x = 17; + v.y = 8; + v.name = "Willowdale"; + v.events.push_back(eventInn); + v.events.push_back(eventBlacksmith); + villages.push_back(v); + v.x = 19; + v.y = 22; + v.name = "Myrefall"; + v.events.push_back(eventInn); + villages.push_back(v); + v.x = 12; + v.y = 15; + v.name = "Calmarnock"; + v.events.push_back(eventInn); + villages.push_back(v); + v.x = 3; + v.y = 18; + v.name = "Waeldestone"; + v.events.push_back(eventInn); + v.events.push_back(eventBlacksmith); + villages.push_back(v); +} + bool RPGCharacter::fromString(QString str) { QStringList list = str.split(QChar(' ')); @@ -46,6 +106,7 @@ bool RPGCharacter::fromString(QString str) RPGModule::RPGModule() { + initVillages(); QFile f("../../res/rpg.save"); if(!f.open(QFile::ReadOnly | QFile::Text)) { @@ -57,7 +118,9 @@ RPGModule::RPGModule() do { line = in.readLine(); - charList.add(new RPGCharacter(line)); + RPGCharacter *c = new RPGCharacter(line); + if(c->pseudo.compare("trash") != 0) + charList.add(c); } while(!line.isNull()); f.close(); @@ -119,13 +182,13 @@ QString RPGModule::lookAt(RPGCharacter *c, QString target) if(target.compare("around") == 0) return QString("%1 is in %2").arg(c->pseudo).arg(getTerrainName(WORLDMAP[c->x][c->y])); else if(target.compare("north") == 0 || target.compare("n") == 0) - return QString("%1 looks north and sees %2").arg(c->pseudo).arg(getTerrainName(WORLDMAP[c->x][c->y-1])); + return QString("%1 looks north and sees %2").arg(c->pseudo).arg(getTerrainName(WORLDMAP[c->x-1][c->y])); else if(target.compare("south") == 0 || target.compare("s") == 0) - return QString("%1 looks south and sees %2").arg(c->pseudo).arg(getTerrainName(WORLDMAP[c->x][c->y+1])); + return QString("%1 looks south and sees %2").arg(c->pseudo).arg(getTerrainName(WORLDMAP[c->x+1][c->y])); else if(target.compare("west") == 0 || target.compare("w") == 0) - return QString("%1 looks west and sees %2").arg(c->pseudo).arg(getTerrainName(WORLDMAP[c->x-1][c->y])); + return QString("%1 looks west and sees %2").arg(c->pseudo).arg(getTerrainName(WORLDMAP[c->x][c->y-1])); else if(target.compare("east") == 0 || target.compare("e") == 0) - return QString("%1 looks east and sees %2").arg(c->pseudo).arg(getTerrainName(WORLDMAP[c->x+1][c->y])); + return QString("%1 looks east and sees %2").arg(c->pseudo).arg(getTerrainName(WORLDMAP[c->x][c->y+1])); else return QString("%1 is not a valid target").arg(target); } @@ -142,7 +205,7 @@ QString RPGModule::playerTravel(RPGCharacter *c, QString dir, bool repeat) { if(dir.compare("north") == 0 || dir.compare("n") == 0) { - bool isDiff = repeat && terrainType != WORLDMAP[c->x][c->y-1]; + bool isDiff = repeat && terrainType != WORLDMAP[c->x-1][c->y]; if(c->y == 0 || (isDiff && dist != 0)) blocked = true; else @@ -156,7 +219,7 @@ QString RPGModule::playerTravel(RPGCharacter *c, QString dir, bool repeat) } else if(dir.compare("south") == 0 || dir.compare("s") == 0) { - bool isDiff = repeat && terrainType != WORLDMAP[c->x][c->y+1]; + bool isDiff = repeat && terrainType != WORLDMAP[c->x+1][c->y]; if(c->y == 24 || (isDiff && dist != 0)) blocked = true; else @@ -170,7 +233,7 @@ QString RPGModule::playerTravel(RPGCharacter *c, QString dir, bool repeat) } else if(dir.compare("west") == 0 || dir.compare("w") == 0) { - bool isDiff = repeat && terrainType != WORLDMAP[c->x-1][c->y]; + bool isDiff = repeat && terrainType != WORLDMAP[c->x][c->y-1]; if(c->x == 0 || (isDiff && dist != 0)) blocked = true; else @@ -184,7 +247,7 @@ QString RPGModule::playerTravel(RPGCharacter *c, QString dir, bool repeat) } else if(dir.compare("east") == 0 || dir.compare("e") == 0) { - bool isDiff = repeat && terrainType != WORLDMAP[c->x+1][c->y]; + bool isDiff = repeat && terrainType != WORLDMAP[c->x][c->y+1]; if(c->x == 24 || (isDiff && dist != 0)) blocked = true; else diff --git a/app/rpgmodule.h b/app/rpgmodule.h index b876618..9668142 100644 --- a/app/rpgmodule.h +++ b/app/rpgmodule.h @@ -15,6 +15,65 @@ enum VILLAGE = 'O' }; +struct Event; + +struct Enemy +{ + QString name; + int hp; + // TODO stats +}; + +struct Trade +{ + int goldPrice; + QString itemPrice; + QString item; + Event *reward; +}; + +struct Roleplay +{ + QString trigger; + Event *reward; +}; + +struct Fight +{ + Enemy enemy; + Event *reward; +}; + +typedef std::vector Trader; + +struct Event +{ + enum Type + { + TRADER, + TRADE, + FIGHT, + ROLEPLAY + }; + + QString name; + QString description; + Type type; + + Trader *trader; + Trade *trade; + Fight *fight; + Roleplay *roleplay; +}; + +struct Village +{ + int x; + int y; + QString name; + std::vector events; +}; + const char WORLDMAP[25][26] = { "^^^^^^^^^^^^^^^^^^^^^^^^^", "^^^^^^^^^^^^^^^^^^^^^^^^^", @@ -42,7 +101,6 @@ const char WORLDMAP[25][26] = { "XXXXXX^^^^^^^^^^^^^^^^^^^", "XX^^^^^^^^^^^^^^^^^^^^^^^"}; - struct RPGCharacter { static const int VERSION = 1; @@ -112,13 +170,14 @@ public: class RPGModule : public Module { + std::vector villages; CharacterMap charList; std::unordered_map charOnline; public: RPGModule(); void saveCharacters(); - + void initVillages(); void playerJoin(User* user, RPGCharacter *c); void playerLeave(User* user); QString lookAt(RPGCharacter *c, QString target);