diff --git a/common/gameplay/item_type.hpp b/common/gameplay/item_type.hpp new file mode 100644 index 0000000..f21761c --- /dev/null +++ b/common/gameplay/item_type.hpp @@ -0,0 +1,32 @@ +/* Copyright: (c) Kayne Ruse 2013-2016 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#pragma once + +enum ItemType { + //basics + POTION = 101, + + //weapons + SWORD = 201, + DAGGER = 202, + STAFF = 203 +}; \ No newline at end of file diff --git a/rsc/fonts/Final-Fantasy.ttf b/rsc/fonts/Final-Fantasy.ttf new file mode 100644 index 0000000..1c219b2 Binary files /dev/null and b/rsc/fonts/Final-Fantasy.ttf differ diff --git a/rsc/graphics/interface/button_blue_30.png b/rsc/graphics/interface/button_blue_30.png new file mode 100644 index 0000000..e5fae1e Binary files /dev/null and b/rsc/graphics/interface/button_blue_30.png differ diff --git a/rsc/graphics/interface/button_blue_30.xcf b/rsc/graphics/interface/button_blue_30.xcf new file mode 100644 index 0000000..0302fad Binary files /dev/null and b/rsc/graphics/interface/button_blue_30.xcf differ diff --git a/rsc/scripts/setup_server.sql b/rsc/scripts/setup_server.sql index 572fd7b..7741519 100644 --- a/rsc/scripts/setup_server.sql +++ b/rsc/scripts/setup_server.sql @@ -20,6 +20,17 @@ * distribution. */ +------------------------- +--defines +------------------------- + +PRAGMA foreign_keys = ON; + +------------------------- +--table definitions +------------------------- + + CREATE TABLE IF NOT EXISTS UserAccounts ( uid INTEGER PRIMARY KEY AUTOINCREMENT, username varchar(100) UNIQUE, --TODO: (3) Swap username for email address @@ -39,7 +50,7 @@ CREATE TABLE IF NOT EXISTS LiveCharacters ( uid INTEGER PRIMARY KEY AUTOINCREMENT, --metadata - owner INTEGER REFERENCES Accounts(uid), + owner INTEGER REFERENCES UserAccounts(uid), handle varchar(100) UNIQUE, avatar varchar(100), birth timestamp NOT NULL DEFAULT (datetime()), @@ -47,24 +58,21 @@ CREATE TABLE IF NOT EXISTS LiveCharacters ( --physically exists in the world roomIndex INTEGER DEFAULT 0, originX INTEGER DEFAULT 0, - originY INTEGER DEFAULT 0, - boundsX INTEGER DEFAULT 0, - boundsY INTEGER DEFAULT 0, - boundsW INTEGER DEFAULT 0, - boundsH INTEGER DEFAULT 0 + originY INTEGER DEFAULT 0 ); CREATE TABLE IF NOT EXISTS DeadCharacters ( uid INTEGER PRIMARY KEY, --metadata - owner INTEGER REFERENCES Accounts(uid), + owner INTEGER REFERENCES UserAccounts(uid), handle varchar(100), avatar varchar(100), - birth timestamp NOT NULL + birth timestamp NOT NULL, + death timestamp NOT NULL DEFAULT (datetime()) ); -CREATE TABLE IF NOT EXISTS LiveMonsters ( +CREATE TABLE IF NOT EXISTS LiveCreatures ( uid INTEGER PRIMARY KEY AUTOINCREMENT, --metadata @@ -77,26 +85,14 @@ CREATE TABLE IF NOT EXISTS LiveMonsters ( --physically exists in the world roomIndex INTEGER DEFAULT 0, originX INTEGER DEFAULT 0, - originY INTEGER DEFAULT 0, - boundsX INTEGER DEFAULT 0, - boundsY INTEGER DEFAULT 0, - boundsW INTEGER DEFAULT 0, - boundsH INTEGER DEFAULT 0 -); - -CREATE TABLE IF NOT EXISTS DeadMonsters ( - uid INTEGER PRIMARY KEY, - - --metadata - handle varchar(100) UNIQUE, - avatar varchar(100) + originY INTEGER DEFAULT 0 ); ------------------------- ---Utility tables +--member tables ------------------------- -CREATE TABLE IF NOT EXISTS StatisticSets ( +CREATE TABLE IF NOT EXISTS CombatStatistics ( --metadata uid INTEGER PRIMARY KEY AUTOINCREMENT, @@ -111,48 +107,44 @@ CREATE TABLE IF NOT EXISTS StatisticSets ( defence INTEGER DEFAULT 0, intelligence INTEGER DEFAULT 0, resistance INTEGER DEFAULT 0, - speed INTEGER DEFAULT 0, accuracy REAL DEFAULT 0.0, evasion REAL DEFAULT 0.0, + speed INTEGER DEFAULT 0, luck REAL DEFAULT 0.0 ); -CREATE TABLE IF NOT EXISTS InWorldItems ( - --metadata - uid INTEGER PRIMARY KEY AUTOINCREMENT, - itemType INTEGER, - - --position in the world - roomIndex INTEGER DEFAULT 0, - originX INTEGER DEFAULT 0, - originY INTEGER DEFAULT 0, - - --unique information - stackSize INTEGER DEFAULT 0, - durability INTEGER DEFAULT 0, - stats INTEGER REFERENCES StatisticSets(uid) -); - CREATE TABLE IF NOT EXISTS InventoryItems ( --metadata uid INTEGER PRIMARY KEY AUTOINCREMENT, - owner INTEGER REFERENCES Characters(uid), itemType INTEGER, --unique information stackSize INTEGER DEFAULT 0, - durability INTEGER DEFAULT 0, - stats INTEGER REFERENCES StatisticSets(uid) + durability INTEGER DEFAULT 0 ); -CREATE TABLE IF NOT EXISTS WornEquipment ( - --metadata - uid INTEGER PRIMARY KEY AUTOINCREMENT, - owner INTEGER REFERENCES Characters(uid), - itemType INTEGER, +------------------------- +--cross reference tables +------------------------- - --unique information - durability INTEGER DEFAULT 0, - stats INTEGER REFERENCES StatisticSets(uid) - --attached script? +CREATE TABLE IF NOT EXISTS CharacterStatistics ( + character INTEGER, + statistic INTEGER, + FOREIGN KEY (character) REFERENCES LiveCharacters(uid), + FOREIGN KEY (statistic) REFERENCES CombatStatistics(uid) ); + +CREATE TABLE IF NOT EXISTS CharacterItems ( + character INTEGER, + item INTEGER, + FOREIGN KEY (character) REFERENCES LiveCharacters(uid), + FOREIGN KEY (item) REFERENCES InventoryItem(uid) +); + +CREATE TABLE IF NOT EXISTS CharacterEquipment ( + character INTEGER, + item INTEGER, + FOREIGN KEY (character) REFERENCES LiveCharacters(uid), + FOREIGN KEY (item) REFERENCES InventoryItem(uid) +); + diff --git a/server/Inventory/item_data.cpp b/server/Inventory/item_data.cpp new file mode 100644 index 0000000..d850464 --- /dev/null +++ b/server/Inventory/item_data.cpp @@ -0,0 +1,38 @@ +/* Copyright: (c) Kayne Ruse 2013-2016 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#include "item_data.hpp" + +ItemType ItemData::SetItemType(ItemType t) { + return type = t; +} + +ItemType ItemData::GetItemType() { + return type; +} + +int ItemData::SetQuantity(int i) { + return quantity = i; +} + +int ItemData::GetQuantity() { + return quantity; +} diff --git a/server/Inventory/item_data.hpp b/server/Inventory/item_data.hpp new file mode 100644 index 0000000..0b8a4e0 --- /dev/null +++ b/server/Inventory/item_data.hpp @@ -0,0 +1,41 @@ +/* Copyright: (c) Kayne Ruse 2013-2016 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#pragma once + +#include "item_type.hpp" + +class ItemData { +public: + ItemData() = default; + ~ItemData() = default; + + //accessors and mutators + ItemType SetItemType(ItemType); + ItemType GetItemType(); + + int SetQuantity(int); + int GetQuantity(); + +private: + ItemType type; + int quantity = 1; +}; \ No newline at end of file diff --git a/server/Inventory/makefile b/server/Inventory/makefile new file mode 100644 index 0000000..8ec0cec --- /dev/null +++ b/server/Inventory/makefile @@ -0,0 +1,32 @@ +#config +INCLUDES+=. ../../common/gameplay +LIBS+= +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) + +#source +CXXSRC=$(wildcard *.cpp) + +#objects +OBJDIR=obj +OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) + +#output +OUTDIR=.. +OUT=$(addprefix $(OUTDIR)/,server.a) + +#targets +all: $(OBJ) $(OUT) + ar -crs $(OUT) $(OBJ) + +$(OBJ): | $(OBJDIR) + +$(OUT): | $(OUTDIR) + +$(OBJDIR): + mkdir $(OBJDIR) + +$(OUTDIR): + mkdir $(OUTDIR) + +$(OBJDIR)/%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< diff --git a/server/characters/character_manager.cpp b/server/characters/character_manager.cpp index 159edbb..39d8267 100644 --- a/server/characters/character_manager.cpp +++ b/server/characters/character_manager.cpp @@ -39,12 +39,8 @@ static const char* CREATE_CHARACTER = "INSERT INTO LiveCharacters (" "owner, " "handle, " - "avatar, " - "boundsX, " - "boundsY, " - "boundsW, " - "boundsH" - ") VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7);"; + "avatar " + ") VALUES (?1, ?2, ?3);"; static const char* LOAD_CHARACTER = "SELECT " "uid, " @@ -53,21 +49,13 @@ static const char* LOAD_CHARACTER = "SELECT " "avatar, " "roomIndex, " "originX, " - "originY, " - "boundsX, " - "boundsY, " - "boundsW, " - "boundsH " + "originY " "FROM LiveCharacters WHERE handle = ?;"; static const char* SAVE_CHARACTER = "UPDATE OR FAIL LiveCharacters SET " "roomIndex = ?2, " "originX = ?3, " - "originY = ?4, " - "boundsX = ?5, " - "boundsY = ?6, " - "boundsW = ?7, " - "boundsH = ?8 " + "originY = ?4 " "WHERE uid = ?1;"; static const char* DELETE_CHARACTER = "DELETE FROM LiveCharacters WHERE uid = ?;"; @@ -93,10 +81,6 @@ int CharacterManager::Create(int owner, std::string handle, std::string avatar) ret |= sqlite3_bind_int(statement, 1, owner); ret |= sqlite3_bind_text(statement, 2, handle.c_str(), handle.size() + 1, SQLITE_STATIC); ret |= sqlite3_bind_text(statement, 3, avatar.c_str(), avatar.size() + 1, SQLITE_STATIC); - ret |= sqlite3_bind_int(statement, 4, CHARACTER_BOUNDS_X); - ret |= sqlite3_bind_int(statement, 5, CHARACTER_BOUNDS_Y); - ret |= sqlite3_bind_int(statement, 6, CHARACTER_BOUNDS_WIDTH); - ret |= sqlite3_bind_int(statement, 7, CHARACTER_BOUNDS_HEIGHT); //check for binding errors if (ret) { @@ -167,10 +151,10 @@ int CharacterManager::Load(int owner, std::string handle, std::string avatar) { newChar.origin.x = (double)sqlite3_column_int(statement, 5); newChar.origin.y = (double)sqlite3_column_int(statement, 6); //bounds - newChar.bounds.x = (int)sqlite3_column_int(statement, 7); - newChar.bounds.y = (int)sqlite3_column_int(statement, 8); - newChar.bounds.w = (int)sqlite3_column_int(statement, 9); - newChar.bounds.h = (int)sqlite3_column_int(statement, 10); + newChar.bounds.x = CHARACTER_BOUNDS_X; + newChar.bounds.y = CHARACTER_BOUNDS_Y; + newChar.bounds.w = CHARACTER_BOUNDS_WIDTH; + newChar.bounds.h = CHARACTER_BOUNDS_HEIGHT; //gameplay components: equipment, items, buffs, debuffs... @@ -212,12 +196,8 @@ int CharacterManager::Save(int uid) { ret |= sqlite3_bind_int(statement, 2, character.roomIndex) != SQLITE_OK; ret |= sqlite3_bind_int(statement, 3, (int)character.origin.x) != SQLITE_OK; ret |= sqlite3_bind_int(statement, 4, (int)character.origin.y) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 5, character.bounds.x) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 6, character.bounds.y) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 7, character.bounds.w) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 8, character.bounds.h) != SQLITE_OK; - //gameplay components: equipment, items, buffs, debuffs... + //TODO: gameplay components: equipment, items, buffs, debuffs... //check for binding errors if (ret) { diff --git a/server/makefile b/server/makefile index 96b7fc8..e31dbf9 100644 --- a/server/makefile +++ b/server/makefile @@ -1,5 +1,5 @@ #include directories -INCLUDES+=. accounts characters clients combat creatures entities rooms triggers ../common/debugging ../common/gameplay ../common/map ../common/network ../common/network/packet_types ../common/utilities +INCLUDES+=. accounts characters clients combat creatures entities inventory rooms triggers ../common/debugging ../common/gameplay ../common/map ../common/network ../common/network/packet_types ../common/utilities #libraries #the order of the $(LIBS) is important, at least for MinGW @@ -35,6 +35,7 @@ all: $(OBJ) $(OUT) $(MAKE) -C combat $(MAKE) -C creatures $(MAKE) -C entities + $(MAKE) -C inventory $(MAKE) -C rooms $(MAKE) -C triggers $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)