From bc33da2c9ca14348832cc3de60966a1149fa7204 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Tue, 3 Oct 2006 00:21:28 +0000 Subject: Committed inventory and itemhandler structure part 1. Also made the server tell which handler is listening on a port. --- ChangeLog | 9 +++ src/Makefile.am | 8 ++- src/accounthandler.cpp | 6 ++ src/accounthandler.h | 7 ++ src/chathandler.cpp | 7 ++ src/chathandler.h | 6 ++ src/dalstoragesql.h | 6 ++ src/gamehandler.cpp | 7 ++ src/gamehandler.h | 6 ++ src/inventory.cpp | 97 +++++++++++++++++++++++++++ src/inventory.h | 175 +++++++++++++++++++++++++++++++++++++++++++++++++ src/item.cpp | 34 ++++++++++ src/item.h | 136 ++++++++++++++++++++++++++++++++++++++ src/itemhandler.cpp | 29 ++++++++ src/itemhandler.h | 56 ++++++++++++++++ src/items.cpp | 29 -------- src/items.h | 64 ------------------ 17 files changed, 587 insertions(+), 95 deletions(-) create mode 100644 src/inventory.cpp create mode 100644 src/inventory.h create mode 100644 src/item.cpp create mode 100644 src/item.h create mode 100644 src/itemhandler.cpp create mode 100644 src/itemhandler.h delete mode 100644 src/items.cpp delete mode 100644 src/items.h diff --git a/ChangeLog b/ChangeLog index 72b89bc1..0c0478c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-10-03 Yohann Ferreira + + * src/item.cpp, src/item.h, src/inventory.h, src.inventory.cpp, + src/itemhandler.h, src/itemhandler.cpp, src/dalstoragesql.h, + src/Makefile.am: Committed itemhandler structure part rc1. + src/accounthandler.cpp, src/accounthandler.h, src/chathandler.h, + src/chathandler.cpp, src/gamehandler.h, src/gamehandler.cpp: Made the + server tells which server is listening on a port. + 2006-09-09 Guillaume Melquiond * src/map.cpp: Merged client pathfinder changes. diff --git a/src/Makefile.am b/src/Makefile.am index 1950aac8..40631398 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -39,8 +39,12 @@ tmwserv_SOURCES = main.cpp \ gameclient.cpp \ gamehandler.h \ gamehandler.cpp \ - items.h \ - items.cpp \ + inventory.h \ + inventory.cpp \ + item.h \ + item.cpp \ + itemhandler.h \ + itemhandler.cpp \ map.h \ map.cpp \ mapcomposite.h \ diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp index 717f5581..2e2e4a29 100644 --- a/src/accounthandler.cpp +++ b/src/accounthandler.cpp @@ -39,6 +39,12 @@ #include "utils/logger.h" #include "utils/stringfilter.h" +bool +AccountHandler::startListen(enet_uint16 port) +{ + LOG_INFO("Account handler started:", 0); + ConnectionHandler::startListen(port); +} NetComputer* AccountHandler::computerConnected(ENetPeer *peer) diff --git a/src/accounthandler.h b/src/accounthandler.h index 6345fa87..5a1a38db 100644 --- a/src/accounthandler.h +++ b/src/accounthandler.h @@ -38,6 +38,13 @@ class AccountClient; */ class AccountHandler : public ConnectionHandler { + public: + /** + * Start the handler + */ + bool + startListen(enet_uint16 port); + protected: /** * Process account related messages. diff --git a/src/chathandler.cpp b/src/chathandler.cpp index 93aaa7d3..88a62b59 100644 --- a/src/chathandler.cpp +++ b/src/chathandler.cpp @@ -88,6 +88,13 @@ void registerChatClient(std::string const &token, std::string const &name, int l } } +bool +ChatHandler::startListen(enet_uint16 port) +{ + LOG_INFO("Chat handler started:", 0); + ConnectionHandler::startListen(port); +} + void ChatHandler::removeOutdatedPending() { ChatPendingLogins::iterator i = pendingLogins.begin(), next; diff --git a/src/chathandler.h b/src/chathandler.h index 6f71733b..fb5e4a7f 100644 --- a/src/chathandler.h +++ b/src/chathandler.h @@ -38,6 +38,12 @@ class ChatHandler : public ConnectionHandler public: void process(); + /** + * Start the handler + */ + bool + startListen(enet_uint16 port); + protected: /** * Process chat related messages. diff --git a/src/dalstoragesql.h b/src/dalstoragesql.h index 7614445a..582b21fe 100644 --- a/src/dalstoragesql.h +++ b/src/dalstoragesql.h @@ -300,16 +300,22 @@ const std::string SQL_INVENTORIES_TABLE( #if defined (MYSQL_SUPPORT) "id SMALLINT NOT NULL," "owner_id INTEGER NOT NULL," + "amount SMALLINT NOT NULL," + "equipped TINYINT NOT NULL," "FOREIGN KEY (id) REFERENCES tmw_items(id)," "FOREIGN KEY (owner_id) REFERENCES tmw_characters(id)" #elif defined (SQLITE_SUPPORT) "id INTEGER NOT NULL," "owner_id INTEGER NOT NULL," + "amount INTEGER NOT NULL," + "equipped INTEGER NOT NULL," "FOREIGN KEY (id) REFERENCES tmw_items(id)," "FOREIGN KEY (owner_id) REFERENCES tmw_characters(id)" #elif defined (POSTGRESQL_SUPPORT) "id INTEGER NOT NULL," "owner_id INTEGER NOT NULL," + "amount INTEGER NOT NULL," + "equipped INTEGER NOT NULL," "FOREIGN KEY (id) REFERENCES tmw_items(id)," "FOREIGN KEY (owner_id) REFERENCES tmw_characters(id)" #endif diff --git a/src/gamehandler.cpp b/src/gamehandler.cpp index a91fbbc6..42cb0c70 100644 --- a/src/gamehandler.cpp +++ b/src/gamehandler.cpp @@ -86,6 +86,13 @@ void registerGameClient(std::string const &token, PlayerPtr ch) } } +bool +GameHandler::startListen(enet_uint16 port) +{ + LOG_INFO("Game handler started:", 0); + ConnectionHandler::startListen(port); +} + void GameHandler::removeOutdatedPending() { GamePendingLogins::iterator i = pendingLogins.begin(); diff --git a/src/gamehandler.h b/src/gamehandler.h index 41d5f780..a66bd509 100644 --- a/src/gamehandler.h +++ b/src/gamehandler.h @@ -38,6 +38,12 @@ class GameHandler: public ConnectionHandler public: void process(); + /** + * Start the handler + */ + bool + startListen(enet_uint16 port); + /** * Send message to the given player. */ diff --git a/src/inventory.cpp b/src/inventory.cpp new file mode 100644 index 00000000..187c641f --- /dev/null +++ b/src/inventory.cpp @@ -0,0 +1,97 @@ +/* + * The Mana World Server + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: $ + */ + +#include "inventory.h" + +unsigned short +getSlotIndex(const unsigned int itemId) +{ + return 0; +} + +bool +addItem(unsigned int itemId, unsigned short amount) +{ + return false; +} + +bool +removeItem(unsigned int itemId, unsigned short amount = 0) +{ + return false; +} + +bool +removeItem(unsigned short index, unsigned short amount = 0) +{ + return false; +} + +bool +equipItem(unsigned int itemId) +{ + return false; +} + +bool +unequipItem(unsigned int itemId) +{ + return false; +} + +bool +equipItem(unsigned short index) +{ + return false; +} + +bool +unequipItem(unsigned short index) +{ + return false; +} + + +bool +use(unsigned short index, BeingPtr itemUser) +{ + return false; +} + +bool +use(unsigned int itemId, BeingPtr itemUser) +{ + return false; +} + +bool +useWithScript(unsigned short index, const std::string scriptFile) +{ + return false; +} + +bool +useWithScript(unsigned int itemId, const std::string scriptFile) +{ + return false; +} diff --git a/src/inventory.h b/src/inventory.h new file mode 100644 index 00000000..79d54b26 --- /dev/null +++ b/src/inventory.h @@ -0,0 +1,175 @@ +/* + * The Mana World Server + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: items.h 2636 2006-09-02 12:03:22Z gmelquio $ + */ + +#ifndef INVENTORY_H +#define INVENTORY_H + +#include "item.h" + +/** + * Stored Item only contains id reference to items + * in the order not to carry every item info for each carried items + * in the inventory. + * Also contains amount, and if equipped. + */ +struct StoredItem +{ + unsigned int itemId; + unsigned short amount; + bool equipped; +}; + +/** + * Class used to store minimal info on player's inventories + * to keep it fast. + * See Item and ItemReference to get more info on an item. + */ +class Inventory +{ + public: + /** + * ctor. + */ + Inventory() {} + + /** + * Convenience function to get index from ItemId. + * If more than one occurence is found, the first is given. + */ + unsigned short + getSlotIndex(const unsigned int itemId); + + /** + * Return StoredItem + */ + StoredItem + getStoredItemAt(unsigned short index) const { return itemList.at(index); }; + + /** + * Return Item reference from ItemReference + */ + //ItemPtr getItem(unsigned short index) const + //{ return itemReferencegetItem(itemList.at(index).itemId); }; + + /** + * Tells if an item is equipped + */ + bool + isEquipped(unsigned short index) const { return itemList.at(index).equipped; }; + + /** + * Tells an item's amount + */ + unsigned short + getItemAmount(unsigned short index) const { return itemList.at(index).amount; }; + + /** + * Return Item reference Id + */ + unsigned int + getItemId(unsigned short index) const { return itemList.at(index).itemId; }; + + /** + * add an item with amount + * (creates it non-equipped if amount was 0) + */ + bool + addItem(unsigned int itemId, unsigned short amount); + + /** + * Remove an item searched by ItemId. + * Delete if amount = 0. + */ + bool + removeItem(unsigned int itemId, unsigned short amount = 0); + + /** + * Remove an item searched by slot index. + * Delete if amount = 0. + */ + bool + removeItem(unsigned short index, unsigned short amount = 0); + + /** + * Equip an item searched by its id. + */ + bool + equipItem(unsigned int itemId); + + /** + * Unequip an item searched by its id. + */ + bool + unequipItem(unsigned int itemId); + + /** + * Equip an item searched by its slot index. + */ + bool + equipItem(unsigned short index); + + /** + * Unequip an item searched by its slot index. + */ + bool + unequipItem(unsigned short index); + + /** + * The function called to use an item applying + * only the modifiers (for simple items...) + */ + bool + use(unsigned short index, BeingPtr itemUser); + + /** + * The function called to use an item applying + * only the modifiers (for simple items...) + */ + bool + use(unsigned int itemId, BeingPtr itemUser); + + /** + * The function called to use an item + * using a script (for complex actions) + */ + bool + useWithScript(unsigned short index, const std::string scriptFile); + + /** + * The function called to use an item + * using a script (for complex actions) + */ + bool + useWithScript(unsigned int itemId, const std::string scriptFile); + + private: + //Item type + std::vector itemList; +}; + +/** + * Type definition for a smart pointer to Being. + */ +typedef utils::CountedPtr InventoryPtr; + +#endif diff --git a/src/item.cpp b/src/item.cpp new file mode 100644 index 00000000..b0008134 --- /dev/null +++ b/src/item.cpp @@ -0,0 +1,34 @@ +/* + * The Mana World Server + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: items.cpp 2512 2006-08-04 16:58:20Z b_lindeijer $ + */ + +#include "item.h" + +void Item::use(BeingPtr itemUser) +{ + // +} + +void Item::useWithScript(const std::string scriptFile) +{ + // +} diff --git a/src/item.h b/src/item.h new file mode 100644 index 00000000..302c4f6a --- /dev/null +++ b/src/item.h @@ -0,0 +1,136 @@ +/* + * The Mana World Server + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: items.h 2636 2006-09-02 12:03:22Z gmelquio $ + */ + +#ifndef ITEM_H +#define ITEM_H + +#include "being.h" + +/** + * Enumeration of available Item types. + */ +enum { + ITEM_USABLE = 0, + ITEM_EQUIPMENT_WEAPON, + ITEM_EQUIPMENT_BREST, + ITEM_EQUIPMENT_ARMS, + ITEM_EQUIPMENT_HEAD, + ITEM_EQUIPMENT_LEGS, + ITEM_EQUIPMENT_SHIELD, + ITEM_EQUIPMENT_RING, + ITEM_EQUIPMENT_NECKLACE +}; + +/** + * statistics modifiers. + * once for usables. + * Permanent for equipment. + */ +struct StatisticsModifiers +{ + short rawStatsMod[NB_RSTAT]; /**< Raw Stats modifiers */ + short compStatsMod[NB_CSTAT]; /**< Computed Stats modifiers */ + int hpMod; /**< HP modifier */ + int mpMod; /**< MP Modifier */ + /**< More to come */ +}; + + +/** + * Class for simple reference to item information. + * See WorldItem to get full featured Item Objects. + */ +class Item +{ + public: + + Item(StatisticsModifiers statsModifiers, + unsigned short mItemType = 0, + unsigned int weight = 0, + unsigned short slot = 0, + unsigned int value = 0): + mWeight(weight), + mSlot(slot), + mValue(value), + mStatsModifiers(statsModifiers) {} + + virtual ~Item() throw() { } + + /** + * The function called to use an item applying + * only the modifiers (for simple items...) + */ + void use(BeingPtr itemUser); + + /** + * The function called to use an item + * using a script (for complex actions) + */ + void useWithScript(const std::string scriptFile); + + /** + * Return item Type + */ + unsigned short getItemType() const { return mItemType; } + + /** + * Return Weight of item + */ + unsigned int getWeight() const { return mWeight; } + + /** + * Return usual slot of item + */ + unsigned short getSlot() const { return mSlot; } + + /** + * Return gold value of item + */ + unsigned int getGoldValue() const { return mValue; } + + /** + * Return item's modifiers + */ + StatisticsModifiers + getItemStatsModifiers() const { return mStatsModifiers; } + + private: + //Item type + unsigned short mItemType; /**< ItemType: Usable, equipment */ + unsigned int mWeight; /**< Weight of the item */ + unsigned short mSlot; /**< Current slot of the item */ + unsigned int mValue; /**< Gold value of the item */ + StatisticsModifiers mStatsModifiers; /**< Stats Mod of the items */ +}; + +/** + * Type definition for a smart pointer to Item. + */ +typedef utils::CountedPtr ItemPtr; + +/** + * Type definition for a list of Items. + */ +typedef std::vector Items; + +#endif diff --git a/src/itemhandler.cpp b/src/itemhandler.cpp new file mode 100644 index 00000000..f1030df6 --- /dev/null +++ b/src/itemhandler.cpp @@ -0,0 +1,29 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: $ + */ + +#include "itemhandler.h" + +#include "storage.h" + +#include "utils/logger.h" + diff --git a/src/itemhandler.h b/src/itemhandler.h new file mode 100644 index 00000000..ff57fb44 --- /dev/null +++ b/src/itemhandler.h @@ -0,0 +1,56 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: $ + */ + +#ifndef _TMW_ITEMHANDLER_H +#define _TMW_ITEMHANDLER_H + +#include +#include + +/** + * The Item Handler loads the item reference database + * and also manage everyone items interaction with other objects + * (including other players) and the world. + */ +class ItemHandler +{ + public: + ItemHandler(std::string itemReferenceFile); + + /** + * Drop items on the map. + */ + bool + drop(BeingPtr beingPtr, unsigned int itemId, unsigned short amount); + + /** + * Pick an item on the ground + */ + bool + getItem(BeingPtr beingPtr, ItemPtr itemPtr); + + private: + std::pair ItemReference; +}; + +#endif diff --git a/src/items.cpp b/src/items.cpp deleted file mode 100644 index 659e24db..00000000 --- a/src/items.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * The Mana World Server - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#include "items.h" - -void Item::use() -{ - // -} diff --git a/src/items.h b/src/items.h deleted file mode 100644 index 191b90a4..00000000 --- a/src/items.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * The Mana World Server - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#ifndef ITEMS_H -#define ITEMS_H - -#include "object.h" - -/** - * Class for all types of in-game items. - */ -class Item : public Object -{ - public: - /** - * Enumeration of available Item types. - */ - enum { - Usable, - Equipment - }; - - Item(int type): - Object(type) - {} - - virtual ~Item() throw() { } - - /** - * The function called to use an item - */ - void use(); - - /** - * Return type of item - */ - unsigned int getType() const { return type; } - - private: - //Item type - unsigned int type; -}; - -#endif -- cgit v1.2.3-70-g09d2