Skip to content

Commit

Permalink
0.4.0 Events Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Attenzes committed Mar 31, 2018
1 parent 2c32726 commit f4ea9a8
Show file tree
Hide file tree
Showing 21 changed files with 1,439 additions and 771 deletions.
101 changes: 36 additions & 65 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,75 +1,46 @@
Version 0.3.0 RPG Update
01 Feb 2018
Version 0.4.0 Events Update
06 Feb 2018
--------------------------------------------------
Description: Third major version of the game.
This update will introduce many features typical of
an RPG game, such as levels, defense values, a basic
economy and NPCs, as well as customizable options
Description: Fourth major version of the game.
This update adds customization of event messages,
when interacting with items/entities, and allows
defining custom descriptions upon inspection.
This update also features a better atk/def algorithm.

Data:
- Additions: Items now have a new data member "value" to add (Default value of item in shop)
- Additions: Mobs now have a new data member "gold" to add (Amount it will drop on death)
- Changes: Item type should now be placed before the name
- Additions: Threats now have an atk stat
- Changes: Player can now have a variable number of inventory slots
- Changes: Starting Exp is now evaluated and the player levelled up accordingly
- Fixes: Typo in comment description of min/max dmg for mobs and threats

Options:
- Additions: New file for custom starting options like map size, position of magical potion/player, max time to complete game
- Additions: Magic potion can now be defined to have a random starting position determined by the game
- Additions: Player can now be defined to have a random starting position determined by the game

NPCs:
- Additions: New file for creating NPCs in the game (Only the merchant for now)
Notes: Merchants can have a maximum of 9 inventory slots
- Additions: NPCs can now be defined to have a random starting position determined by the game

Gameplay:
- Additions: Items can now be inspected to yield a description (To be expanded on in future Events update)
- Additions: Players now have exp and levels that scale their stats
- Additions: Attack value of attacker is compared to defence value of defender to determine effective damage
(^^ Atk and def must be defined to be at least 1)
- Additions: Items now have a functioning success rate (Can now fail to be used)
- Additions: Mobs now drop gold and exp
- Additions: There is now a merchant NPC that will buy and sell items (Basic trading)
- Additions: Unusable item types (Can only be sold)
- Additions: Game now tells the player what his/her roll on whether his/her use of item is successful is (Not for running)
- Changes: UI Overhaul, with more sub-menus for each type of action as opposed to a specific number for each specific action
- Changes: Game now prints map after defeating a mob
- Changes: Changed text describing number of uses left for an item
- Changes: Minor text alignment changes
- Fixes: Typo when printing that player will constantly take damage while on same tile as a threat
- Fixes: Undefined behaviour when choosing an item slot with an item that is not a healing item in encounter with threat
- Fixes: Player character did not appear on screen after defeating a mob, then checking surroundings
- Fixes: Player can try to move right or down out of the map, resulting in a crash
- Fixes: Picking up the magical potion resulted in the game displaying as having medicine in the inventory
- Fixes: Inputting invalid option in swap item menu, game returns to movement/inventory/etc menu without telling user
- Fixes: Game did not print player position if player chooses to go back from swap item menu
- Fixes: Threat can no longer spawn on the same tile as the magical potion

Additional notes:
- Initial values of player's atk and def can be changed in Data.dat but currently the levelled up values are fixed
- If the player starts with more than 5 exp, the level will not updated until the player gains some exp
- The current atk/def algorithm needs work, a simple one has currently been implemented as a trial
- Position of merchant is not checked if it has a conflict with other merchants/players
- There is a chance that if the number of entities to be generated is directly equal to that of the mapsize, and the last
entity to be generated is a threat, and the last tile without an entity is the magical potion, game could infinite loop (unconfirmed)
- All these will be fixed in a future update

Version 0.3.1 Code Patch
02 Feb 2018
--------------------------------------------------
Description: Small patch with a few minor fixes,
mostly not intended to add or change features,
focuses on rebuilding some parts of the game with
revised source code

Data:
- Fixes: Will not infinite loop if number of entities to be generated equal to mapsize

NPCs:
- Fixes: Items generated in inventories were mistakenly added to the check if there were too many items to generate for mapsize
- Fixes: Conflicts in coordinates of NPCs will now be flagged up
Events:
- Additions: Events file where specific event messages can be defined for each item/npc/mob/threat

Gameplay:
- Changes: Some messages such as printing what objects are on the same tile as the player are changed
- Changes: Game now prints if there is nothing on the tile
- Changes: Game now prints time passed before any other events
- Changes: Game now prints more specific event messages when picking up/swapping/dropping items
- Changes: Game used to display only how much a healing item would have healed, not actually heal (If player at/near max health)
- Fixes: Game message says that there is no item in that inventory slot if user inspects a tile with nothing on it
- Fixes: Game did not reprint map after using item despite not being in encounter
- Additions: Can now inspect entities, threats and NPCs
- Additions: Mobs and threats' min dmg and max dmg, def, level details now available to be seen in-game through inspection
- Additions: Can now inspect items in merchants' inventories in the buy menu
- Additions: New atk/def dmg bonus calculation algorithm
- Changes: Inventory is now listed from top down then left to right instead of left to right then top down
- Changes: Inventory is now printed in the buy menu
- Fixes: The atk/def mechanism did not include when mobs attack the player
- Fixes: Typo in message displaying additional damage done due to greater attack stat
- Fixes: No longer displays old menu in encounter with threat despite taking inputs for the new menu
- Fixes: No longer asks if player wants to use inventory slot 1, 2, 3 or 4 but which inventory slot to use when picking up item
- Fixes: Game does not reprint map after going use inventory/inspect menu
- Fixes: Small typo in game over message
- Fixes: Player could use the save option and "escape" an encounter, being on same tile but able to move and not receive damage

Bugs:
- If the end code is missed out in the data files, data loader will try to load same object as previous one loaded

Additional notes:
- Mobs each have a "level" but it currently doesn't do anything and thats as intended for now.
- This will be worked on in the future.
32 changes: 18 additions & 14 deletions Data.dat
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ within the slashes/
//Starting Defense value (At least 1)
//Starting EXP (At least 0)
//Starting level (At least 1)
//Starting inventory slot 1 item ID (-1 for nothing, 0 for first item defined above, item_typeid)
//Starting inventory slot 2 item ID (-1 for nothing, 0 for first item defined above, item_typeid)
//Starting inventory slot 3 item ID (-1 for nothing, 0 for first item defined above, item_typeid)
//Starting inventory slot 4 item ID (-1 for nothing, 0 for first item defined above, item_typeid)
//Starting gold
//Starting gold (At least 0)
//Number of inventory slots
//Starting inventory slot 1 item ID (-1 for nothing, 0 for first baseitem/item defined above, item_typeid)
//Other inventory slot item IDs here...

/Player code/ 1
/Name of Player/ "Player"
Expand All @@ -75,11 +74,14 @@ within the slashes/
/Def/ 1
/EXP/ 0
/Level/ 1
/Inv slot 1 item ID/ -1
/Inv slot 1 item ID/ 2
/Inv slot 1 item ID/ 0
/Inv slot 1 item ID/ 1
/Gold/ 30
/Inventory size/ 6
/Inv slot 1 item ID/ 1
/Inv slot 2 item ID/ 1
/Inv slot 3 item ID/ 2
/Inv slot 4 item ID/ 2
/Inv slot 5 item ID/ 0
/Inv slot 6 item ID/ -1

//Syntax for Mobs:
//Code 2
Expand All @@ -88,8 +90,8 @@ within the slashes/
//Starting HP
//Starting Attack value
//Starting Defense value (At least 1)
//Min heal/damage amount
//Max heal/damage amount
//Min damage amount
//Max damage amount
//Starting EXP (At least 0)
//Starting level (At least 1)
//Player's run chance from this mob (From 0 to 100 up to 5 dp)
Expand All @@ -101,7 +103,7 @@ within the slashes/
/Max HP/ 50
/HP/ 50
/Atk/ 1
/Def/ 1
/Def/ 2
/Min damage/ 12
/Max damage/ 20
/EXP/ 5
Expand All @@ -113,13 +115,15 @@ within the slashes/
//Syntax for Threats:
//Code 3
//Name of threat within double quotes
//Min heal/damage amount
//Max heal/damage amount
//Attack value
//Min damage amount
//Max damage amount
//Player's run chance from this threat (From 0 to 100 up to 5 dp)
//Number of this threat to spawn on the map

/Threat code/ 3
/Name of Threat/ "Threat"
/Atk/ 3
/Min damage/ 10
/Max damage/ 10
/Run chance/ 60.0
Expand Down
73 changes: 73 additions & 0 deletions Events.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//Comments:
//Double slashes will comment out everything until the start of next line
/Double slashes with at least one character between then ignore everything
within the slashes/

//Data.dat
//
//Define all the event messages for each object (Both items and entities) here in order
//Order for each class of object (Code): BaseItem, Item, Mob, Threat, Merchant
//Order for each type of each object: Follow the order of declaration in Data.dat/NPCs.dat
//Comments in this file cannot be placed between individual event messages, only between each object's event messages block
//Note: Comments using /this syntax/ cannot be used on the same line as the event messages (At most beside code number).
//Only the message itself should be on the line or it will be read as part of the event message
//Only sequence character supported is \n

//BaseItem code 0
//Use
//Inspect description

//Gold Ring
0
This item has no use.
A golden ring that can be worth quite some gold.\nHowever, it cannot be equipped for any stat boost or used for any reason.

//Item code 1
//Use success
//Use failure
//Item used up
//Inspect description

1 /Medicine/
You apply the unknown liquid stored in this Medicine successfully!
You tried to use the Medicine but failed to apply it properly!
The Medicine runs out of healing liquid. It can no longer be used.
The Medicine comes in a small container of some weird unknown liquid with medical properties.\nThere seems store only just enough for one use.

1 /Weapon/
You swing the Weapon at your foe!
You tried to use the Weapon but stumbled and failed!
The Weapon breaks! It has run out of durability.
The Weapon is a rusty iron sword that can be used to kill your enemies.\nBut, it has low durability and will definitely break after one use.

//Mob code 2
//Attack
//Death
//Inspect description

2 /Mob/
The Mob uses its claws to, shockingly, claw you!
The Mob dies!
The Mob is a mob. It is a generic mob. It is just a mob.

//Threat code 3
//Attack
//Inspect description

3 /Threat/
The Threat threatens you!
The Threat is well, a threat. Some kind of threat. You should be careful of it because it's a threat.

//Merchant code 4
//Inspect description

4 /Travelling merchant/
A merchant who travels! He who goes across the world in search of goods to buy and sell!\nA nice chap to do some business with.

4 /Dummy merchant/
A dummy, he doesn't do anything and he can't.\nHe might as well not be in the game but is, for some inexplicable reason.

4 /Weapons merchant/
A merchant who specializes in weapon-related goods.\nHe sells more weapon items than other merchants, but also at a higher price.

5 /End code/
29 changes: 28 additions & 1 deletion Quest!/DataLoader.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include "DataLoader.h"

void DataLoader::open(std::string& filename)
void DataLoader::open(const char* filename)
{
m_filereader.open(filename);
m_filename = filename;
}

void DataLoader::open(const std::string& filename)
{
m_filereader.open(filename);
m_filename = filename;
Expand Down Expand Up @@ -79,3 +85,24 @@ int DataLoader::getWithinQuotes(std::string& string)
m_filereader.get(); //Discard the closing double quotation mark
return 0;
}

void DataLoader::handleNewlines(std::string& string) const
{
std::string::size_type pos = 0;
while ((pos = string.find("\\n")) != std::string::npos)
{
string.replace(pos, 2, "\n");
}
}

void DataLoader::checkStatus() const
{
if (m_filereader.eof())
{
throw std::runtime_error(m_filename + ": Data loader unexpectedly reached end of file. File is incomplete/Syntax is wrong.");
}
if (m_filereader.fail())
{
throw std::runtime_error(m_filename + ": Data loader encountered unexpected input. Data is defined wrongly/Syntax is wrong.");
}
}
19 changes: 18 additions & 1 deletion Quest!/DataLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class DataLoader

public:

DataLoader(const char* filename)
: m_filename{ filename }, m_filereader{ filename }
{}

DataLoader(const std::string& filename)
: m_filename{ filename }, m_filereader{ filename }
{}
Expand All @@ -23,7 +27,8 @@ class DataLoader
m_filereader.close();
}

void open(std::string& filename);
void open(const char* filename);
void open(const std::string& filename);
bool is_open() const { return m_filereader.is_open(); }
void close(){m_filereader.close();}

Expand Down Expand Up @@ -51,6 +56,18 @@ class DataLoader
//Reasons for failure: Reached eof/next character after ignoring whitespace and comments is not double quotation mark
int getWithinQuotes(std::string& string);

//Gets a line of characters and sets the string passed in to be equal to it
void getLine(std::string& string) { std::getline(m_filereader, string); }
void ignore(std::streamsize count, int delim) { m_filereader.ignore(count, delim); }

//When "\n" is read from a file, it is read as two characters, '\\' and 'n'
//This function removes \\n from a string and replaces it with \n so that newlines can be streamed properly
void handleNewlines(std::string& string) const;

//Throws if the filereader failed or is at eof
//Note: This function is designed to specifically throw, use only if you are sure that you can't continue if filereader fails or eof
void checkStatus() const;

template <typename T>
friend DataLoader& operator>>(DataLoader& data_loader, T& storage_variable)
{
Expand Down
21 changes: 11 additions & 10 deletions Quest!/EventMsgHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#include "EventMsgHandler.h"

void EventMsgHandler::addEventMsg(const std::string& new_event_msg)
{
m_event_msgs.push_back(new_event_msg);
}

void EventMsgHandler::addEventMsg(std::string&& new_event_msg)
{
if (m_event_msg.size() > 0) //Already has an event message being held
{
m_event_msg += new_event_msg + '\n'; //Append
}
else
{
m_event_msg = new_event_msg + '\n';
}
m_event_msgs.push_back(std::move(new_event_msg));
}

void EventMsgHandler::printMsgs()
{
std::cout << m_event_msg;
m_event_msg.clear();
for (const auto& i : m_event_msgs)
{
std::cout << i << '\n';
}
m_event_msgs.clear();
}
4 changes: 3 additions & 1 deletion Quest!/EventMsgHandler.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#pragma once
#include <iostream>
#include <string>
#include <vector>

class EventMsgHandler
{
std::string m_event_msg;
std::vector<std::string> m_event_msgs;

public:

//Add an event message to be held
void addEventMsg(const std::string& new_event_msg);
void addEventMsg(std::string&& new_event_msg);

//Prints all event messages being held then clears them
Expand Down
Loading

0 comments on commit f4ea9a8

Please sign in to comment.