Updated SQL script
This commit is contained in:
@@ -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
|
||||||
|
};
|
||||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 316 B |
Binary file not shown.
@@ -20,6 +20,17 @@
|
|||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
-------------------------
|
||||||
|
--defines
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
PRAGMA foreign_keys = ON;
|
||||||
|
|
||||||
|
-------------------------
|
||||||
|
--table definitions
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS UserAccounts (
|
CREATE TABLE IF NOT EXISTS UserAccounts (
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
username varchar(100) UNIQUE, --TODO: (3) Swap username for email address
|
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,
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
||||||
--metadata
|
--metadata
|
||||||
owner INTEGER REFERENCES Accounts(uid),
|
owner INTEGER REFERENCES UserAccounts(uid),
|
||||||
handle varchar(100) UNIQUE,
|
handle varchar(100) UNIQUE,
|
||||||
avatar varchar(100),
|
avatar varchar(100),
|
||||||
birth timestamp NOT NULL DEFAULT (datetime()),
|
birth timestamp NOT NULL DEFAULT (datetime()),
|
||||||
@@ -47,24 +58,21 @@ CREATE TABLE IF NOT EXISTS LiveCharacters (
|
|||||||
--physically exists in the world
|
--physically exists in the world
|
||||||
roomIndex INTEGER DEFAULT 0,
|
roomIndex INTEGER DEFAULT 0,
|
||||||
originX INTEGER DEFAULT 0,
|
originX INTEGER DEFAULT 0,
|
||||||
originY 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 DeadCharacters (
|
CREATE TABLE IF NOT EXISTS DeadCharacters (
|
||||||
uid INTEGER PRIMARY KEY,
|
uid INTEGER PRIMARY KEY,
|
||||||
|
|
||||||
--metadata
|
--metadata
|
||||||
owner INTEGER REFERENCES Accounts(uid),
|
owner INTEGER REFERENCES UserAccounts(uid),
|
||||||
handle varchar(100),
|
handle varchar(100),
|
||||||
avatar 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,
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
||||||
--metadata
|
--metadata
|
||||||
@@ -77,26 +85,14 @@ CREATE TABLE IF NOT EXISTS LiveMonsters (
|
|||||||
--physically exists in the world
|
--physically exists in the world
|
||||||
roomIndex INTEGER DEFAULT 0,
|
roomIndex INTEGER DEFAULT 0,
|
||||||
originX INTEGER DEFAULT 0,
|
originX INTEGER DEFAULT 0,
|
||||||
originY 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)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
--Utility tables
|
--member tables
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS StatisticSets (
|
CREATE TABLE IF NOT EXISTS CombatStatistics (
|
||||||
--metadata
|
--metadata
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
||||||
@@ -111,48 +107,44 @@ CREATE TABLE IF NOT EXISTS StatisticSets (
|
|||||||
defence INTEGER DEFAULT 0,
|
defence INTEGER DEFAULT 0,
|
||||||
intelligence INTEGER DEFAULT 0,
|
intelligence INTEGER DEFAULT 0,
|
||||||
resistance INTEGER DEFAULT 0,
|
resistance INTEGER DEFAULT 0,
|
||||||
speed INTEGER DEFAULT 0,
|
|
||||||
accuracy REAL DEFAULT 0.0,
|
accuracy REAL DEFAULT 0.0,
|
||||||
evasion REAL DEFAULT 0.0,
|
evasion REAL DEFAULT 0.0,
|
||||||
|
speed INTEGER DEFAULT 0,
|
||||||
luck REAL DEFAULT 0.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 (
|
CREATE TABLE IF NOT EXISTS InventoryItems (
|
||||||
--metadata
|
--metadata
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
owner INTEGER REFERENCES Characters(uid),
|
|
||||||
itemType INTEGER,
|
itemType INTEGER,
|
||||||
|
|
||||||
--unique information
|
--unique information
|
||||||
stackSize INTEGER DEFAULT 0,
|
stackSize INTEGER DEFAULT 0,
|
||||||
durability INTEGER DEFAULT 0,
|
durability INTEGER DEFAULT 0
|
||||||
stats INTEGER REFERENCES StatisticSets(uid)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS WornEquipment (
|
-------------------------
|
||||||
--metadata
|
--cross reference tables
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
-------------------------
|
||||||
owner INTEGER REFERENCES Characters(uid),
|
|
||||||
itemType INTEGER,
|
|
||||||
|
|
||||||
--unique information
|
CREATE TABLE IF NOT EXISTS CharacterStatistics (
|
||||||
durability INTEGER DEFAULT 0,
|
character INTEGER,
|
||||||
stats INTEGER REFERENCES StatisticSets(uid)
|
statistic INTEGER,
|
||||||
--attached script?
|
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)
|
||||||
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
};
|
||||||
@@ -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 $@ $<
|
||||||
@@ -39,12 +39,8 @@
|
|||||||
static const char* CREATE_CHARACTER = "INSERT INTO LiveCharacters ("
|
static const char* CREATE_CHARACTER = "INSERT INTO LiveCharacters ("
|
||||||
"owner, "
|
"owner, "
|
||||||
"handle, "
|
"handle, "
|
||||||
"avatar, "
|
"avatar "
|
||||||
"boundsX, "
|
") VALUES (?1, ?2, ?3);";
|
||||||
"boundsY, "
|
|
||||||
"boundsW, "
|
|
||||||
"boundsH"
|
|
||||||
") VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7);";
|
|
||||||
|
|
||||||
static const char* LOAD_CHARACTER = "SELECT "
|
static const char* LOAD_CHARACTER = "SELECT "
|
||||||
"uid, "
|
"uid, "
|
||||||
@@ -53,21 +49,13 @@ static const char* LOAD_CHARACTER = "SELECT "
|
|||||||
"avatar, "
|
"avatar, "
|
||||||
"roomIndex, "
|
"roomIndex, "
|
||||||
"originX, "
|
"originX, "
|
||||||
"originY, "
|
"originY "
|
||||||
"boundsX, "
|
|
||||||
"boundsY, "
|
|
||||||
"boundsW, "
|
|
||||||
"boundsH "
|
|
||||||
"FROM LiveCharacters WHERE handle = ?;";
|
"FROM LiveCharacters WHERE handle = ?;";
|
||||||
|
|
||||||
static const char* SAVE_CHARACTER = "UPDATE OR FAIL LiveCharacters SET "
|
static const char* SAVE_CHARACTER = "UPDATE OR FAIL LiveCharacters SET "
|
||||||
"roomIndex = ?2, "
|
"roomIndex = ?2, "
|
||||||
"originX = ?3, "
|
"originX = ?3, "
|
||||||
"originY = ?4, "
|
"originY = ?4 "
|
||||||
"boundsX = ?5, "
|
|
||||||
"boundsY = ?6, "
|
|
||||||
"boundsW = ?7, "
|
|
||||||
"boundsH = ?8 "
|
|
||||||
"WHERE uid = ?1;";
|
"WHERE uid = ?1;";
|
||||||
|
|
||||||
static const char* DELETE_CHARACTER = "DELETE FROM LiveCharacters WHERE uid = ?;";
|
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_int(statement, 1, owner);
|
||||||
ret |= sqlite3_bind_text(statement, 2, handle.c_str(), handle.size() + 1, SQLITE_STATIC);
|
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_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
|
//check for binding errors
|
||||||
if (ret) {
|
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.x = (double)sqlite3_column_int(statement, 5);
|
||||||
newChar.origin.y = (double)sqlite3_column_int(statement, 6);
|
newChar.origin.y = (double)sqlite3_column_int(statement, 6);
|
||||||
//bounds
|
//bounds
|
||||||
newChar.bounds.x = (int)sqlite3_column_int(statement, 7);
|
newChar.bounds.x = CHARACTER_BOUNDS_X;
|
||||||
newChar.bounds.y = (int)sqlite3_column_int(statement, 8);
|
newChar.bounds.y = CHARACTER_BOUNDS_Y;
|
||||||
newChar.bounds.w = (int)sqlite3_column_int(statement, 9);
|
newChar.bounds.w = CHARACTER_BOUNDS_WIDTH;
|
||||||
newChar.bounds.h = (int)sqlite3_column_int(statement, 10);
|
newChar.bounds.h = CHARACTER_BOUNDS_HEIGHT;
|
||||||
|
|
||||||
//gameplay components: equipment, items, buffs, debuffs...
|
//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, 2, character.roomIndex) != SQLITE_OK;
|
||||||
ret |= sqlite3_bind_int(statement, 3, (int)character.origin.x) != 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, 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
|
//check for binding errors
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,5 @@
|
|||||||
#include directories
|
#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
|
#libraries
|
||||||
#the order of the $(LIBS) is important, at least for MinGW
|
#the order of the $(LIBS) is important, at least for MinGW
|
||||||
@@ -35,6 +35,7 @@ all: $(OBJ) $(OUT)
|
|||||||
$(MAKE) -C combat
|
$(MAKE) -C combat
|
||||||
$(MAKE) -C creatures
|
$(MAKE) -C creatures
|
||||||
$(MAKE) -C entities
|
$(MAKE) -C entities
|
||||||
|
$(MAKE) -C inventory
|
||||||
$(MAKE) -C rooms
|
$(MAKE) -C rooms
|
||||||
$(MAKE) -C triggers
|
$(MAKE) -C triggers
|
||||||
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
||||||
|
|||||||
Reference in New Issue
Block a user