added look and travel
This commit is contained in:
parent
a3b8f75aa7
commit
9c44781fd3
@ -114,50 +114,91 @@ QString RPGModule::getTerrainName(int type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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]));
|
||||||
|
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]));
|
||||||
|
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]));
|
||||||
|
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]));
|
||||||
|
else
|
||||||
|
return QString("%1 is not a valid target").arg(target);
|
||||||
|
}
|
||||||
|
|
||||||
QString RPGModule::playerTravel(RPGCharacter *c, QString dir, bool repeat)
|
QString RPGModule::playerTravel(RPGCharacter *c, QString dir, bool repeat)
|
||||||
{
|
{
|
||||||
char terrainType = WORLDMAP[c->x][c->y];
|
char terrainType = WORLDMAP[c->x][c->y];
|
||||||
QString direction;
|
QString direction;
|
||||||
QString currentArea = getTerrainName(terrainType);
|
QString currentArea = getTerrainName(terrainType);
|
||||||
bool blocked = false;
|
bool blocked = false;
|
||||||
|
int dist = 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
if(dir.compare("north") == 0 || dir.compare("n") == 0)
|
if(dir.compare("north") == 0 || dir.compare("n") == 0)
|
||||||
{
|
{
|
||||||
if(c->y == 0)
|
if(c->y == 0 || (repeat && terrainType != WORLDMAP[c->x][c->y-1]))
|
||||||
blocked = true;
|
blocked = true;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
c->y -= 1;
|
c->y -= 1;
|
||||||
|
++dist;
|
||||||
|
}
|
||||||
direction = "north";
|
direction = "north";
|
||||||
}
|
}
|
||||||
else if(dir.compare("south") == 0 || dir.compare("s") == 0)
|
else if(dir.compare("south") == 0 || dir.compare("s") == 0)
|
||||||
{
|
{
|
||||||
if(c->y == 24)
|
if(c->y == 24 || (repeat && terrainType != WORLDMAP[c->x][c->y+1]))
|
||||||
blocked = true;
|
blocked = true;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
c->y += 1;
|
c->y += 1;
|
||||||
|
++dist;
|
||||||
|
}
|
||||||
direction = "south";
|
direction = "south";
|
||||||
}
|
}
|
||||||
else if(dir.compare("west") == 0 || dir.compare("w") == 0)
|
else if(dir.compare("west") == 0 || dir.compare("w") == 0)
|
||||||
{
|
{
|
||||||
if(c->x == 0)
|
if(c->x == 0 || (repeat && terrainType != WORLDMAP[c->x-1][c->y]))
|
||||||
blocked = true;
|
blocked = true;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
c->x -= 1;
|
c->x -= 1;
|
||||||
|
++dist;
|
||||||
|
}
|
||||||
direction = "west";
|
direction = "west";
|
||||||
}
|
}
|
||||||
else if(dir.compare("east") == 0 || dir.compare("e") == 0)
|
else if(dir.compare("east") == 0 || dir.compare("e") == 0)
|
||||||
{
|
{
|
||||||
if(c->x == 24)
|
if(c->x == 24 || (repeat && terrainType != WORLDMAP[c->x+1][c->y]))
|
||||||
blocked = true;
|
blocked = true;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
c->x += 1;
|
c->x += 1;
|
||||||
|
++dist;
|
||||||
|
}
|
||||||
direction = "east";
|
direction = "east";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return QString("%1 is not a valid direction, use : north, south, west, east").arg(dir);
|
return QString("%1 is not a valid direction, use : north, south, west, east").arg(dir);
|
||||||
|
}
|
||||||
|
while(!blocked && repeat);
|
||||||
|
|
||||||
if(blocked)
|
if(blocked)
|
||||||
|
{
|
||||||
|
if(repeat && dist > 0)
|
||||||
|
{
|
||||||
|
QString("%1 travels %2 during %3 hours through %4")
|
||||||
|
.arg(c->pseudo).arg(direction).arg(dist).arg(currentArea);
|
||||||
|
}
|
||||||
|
else
|
||||||
return QString("%1 cannot go %2, a hill is blocking his way").arg(c->pseudo).arg(direction);
|
return QString("%1 cannot go %2, a hill is blocking his way").arg(c->pseudo).arg(direction);
|
||||||
|
}
|
||||||
|
|
||||||
char newTerrainType = WORLDMAP[c->x][c->y];
|
char newTerrainType = WORLDMAP[c->x][c->y];
|
||||||
if(terrainType == newTerrainType)
|
if(terrainType == newTerrainType)
|
||||||
@ -206,7 +247,7 @@ bool RPGModule::messageHandler(Message msg)
|
|||||||
answer = say(QString("%1 joins the RPG as %2").arg(msg.nick).arg(paramList[2]));
|
answer = say(QString("%1 joins the RPG as %2").arg(msg.nick).arg(paramList[2]));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
privateSay(QString("ERROR : Wrong password"), msg.nick);
|
answer = privateSay(QString("ERROR : Wrong password"), msg.nick);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
answer = privateSay(QString("ERROR : Character name \"%1\" does not exists").arg(paramList[2]), msg.nick);
|
answer = privateSay(QString("ERROR : Character name \"%1\" does not exists").arg(paramList[2]), msg.nick);
|
||||||
@ -225,16 +266,12 @@ bool RPGModule::messageHandler(Message msg)
|
|||||||
{
|
{
|
||||||
if(c->password.compare(paramList[3]) == 0)
|
if(c->password.compare(paramList[3]) == 0)
|
||||||
{
|
{
|
||||||
for(const std::pair<User*, RPGCharacter*> &it : charOnline)
|
charOnline.erase(c->user);
|
||||||
{
|
|
||||||
if(it.second == c)
|
|
||||||
charOnline.erase(it.first);
|
|
||||||
}
|
|
||||||
charList.erase(paramList[2].toStdString());
|
charList.erase(paramList[2].toStdString());
|
||||||
answer = say(QString("Character %2 has been deleted").arg(paramList[2]));
|
answer = say(QString("Character %2 has been deleted").arg(paramList[2]));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
privateSay(QString("ERROR : Wrong password"), msg.nick);
|
answer = privateSay(QString("ERROR : Wrong password"), msg.nick);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
answer = privateSay(QString("ERROR : Character name \"%1\" does not exists").arg(paramList[2]), msg.nick);
|
answer = privateSay(QString("ERROR : Character name \"%1\" does not exists").arg(paramList[2]), msg.nick);
|
||||||
@ -289,7 +326,7 @@ bool RPGModule::messageHandler(Message msg)
|
|||||||
QStringList paramList = msg.args.split(' ');
|
QStringList paramList = msg.args.split(' ');
|
||||||
if(charOnline.count(src) > 0 && paramList.size() == 2)
|
if(charOnline.count(src) > 0 && paramList.size() == 2)
|
||||||
{
|
{
|
||||||
answer = say(playerTravel(charOnline[src], paramList[1]));
|
answer = say(playerTravel(charOnline[src], paramList[1], false));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -304,9 +341,13 @@ bool RPGModule::messageHandler(Message msg)
|
|||||||
}
|
}
|
||||||
else if(msg.args.startsWith("look "))
|
else if(msg.args.startsWith("look "))
|
||||||
{
|
{
|
||||||
answer = say("you look around and you find a walnut.");
|
QStringList paramList = msg.args.split(' ');
|
||||||
|
if(charOnline.count(src) > 0 && paramList.size() == 2)
|
||||||
|
{
|
||||||
|
answer = say(lookAt(charOnline[src], paramList[1]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if(msg.args.compare("!rpg help") == 0)
|
else if(msg.args.compare("!rpg help") == 0)
|
||||||
{
|
{
|
||||||
answer = privateSay("Commands : register, join, delete, leave, save, stats, list", msg.nick);
|
answer = privateSay("Commands : register, join, delete, leave, save, stats, list", msg.nick);
|
||||||
|
@ -121,6 +121,7 @@ public:
|
|||||||
|
|
||||||
void playerJoin(User* user, RPGCharacter *c);
|
void playerJoin(User* user, RPGCharacter *c);
|
||||||
void playerLeave(User* user);
|
void playerLeave(User* user);
|
||||||
|
QString lookAt(RPGCharacter *c, QString target);
|
||||||
QString playerTravel(RPGCharacter *c, QString dir, bool repeat=false);
|
QString playerTravel(RPGCharacter *c, QString dir, bool repeat=false);
|
||||||
QString getTerrainName(int type);
|
QString getTerrainName(int type);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user