Item system is one of the core systems of the game, common business functions including “character backpack”, “item shop”, “monster drop”, etc., all rely on item system.
Before we can implement these features, the first problem we need to solve is to define what items will be in our game world and how they will be classified.
That’s our item dictionary. First there must be a “dictionary” to tell you what the item is, and then there can be a “backpack” system to tell you what items the character has in his backpack and how many.
1. Classification of props
1. Concept design
We first refer to the world of Warcraft item classification, sorted out the classification roughly as follows (see brain map).
Figure 1. Classification of props
Figure 2. Equipment classification diagram
As can be seen from the figure, the whole classification is a tree structure.
The category of “props” is currently a two-story tree structure, including “gligraph”, “mount”, “food”, etc. These categories are not closely related to the existing system, so additional gameplay systems using these props need to be developed, which can be temporarily considered.
Under the “equipment” category, there is a three-tier tree structure. The equipment system is closely related to battle settlement and character battle attributes, so we will focus on the design of the equipment dictionary next.
2. Database design
In the previous chapters, we implemented a data dictionary for the system, but that dictionary is mainly used for enumeration options and is a flat data structure, not for equipment types.
For example, if you want to select “weapon” -> “one-handed weapon” -> “One-handed sword” in the category selection, it is difficult to choose the next step down.
Therefore, you need to design an additional “item type table” that can handle the tree structure. Add two fields level (current level) and rootCode (root node code) to the table.
The construction sentences are as follows:
CREATE TABLE 'item_type' (' id' bigint NOT NULL AUTO_INCREMENT COMMENT '主键 iD ', Parent_code varchar(20) NOT NULL DEFAULT COMMENT, 'parent_code' varchar(20) NOT NULL DEFAULT COMMENT, 'root_code' varchar(20) NOT NULL DEFAULT COMMENT ', 'level' int NOT NULL DEFAULT '0' COMMENT 'hierarchy ', 'value' varchar(20) NOT NULL DEFAULT COMMENT 'value ',' remark 'varchar(100) NOT NULL DEFAULT COMMENT ', 'create_user' varchar(20) NOT NULL DEFAULT COMMENT 'create ', 'update_user' varchar(20) NOT NULL DEFAULT COMMENT ', 'create_time' datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create_time ', 'update_time' datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'UPDATE time ', 'is_delete' tinyInt NOT NULL DEFAULT '0' COMMENT 'whether to delete 0- No 1- Yes ',' version 'int NOT NULL DEFAULT '0' COMMENT' version ', PRIMARY KEY (`id`), UNIQUE KEY `uidx_code` (`code`), KEY `idx_parent_code` (`parent_code`) ) ENGINE=InnoDB AUTO_INCREMENT=90 DEFAULT CHARSET=utf8mb4 COLLATE= UTf8MB4_0900_ai_CI COMMENT=' props type dictionary table ';Copy the code
item_type.sql
3. Content management
Table structure has, refer to the previous chapter, as long as the establishment of the corresponding entity class, in the RMS system, add the corresponding menu, to achieve the corresponding logic.
Note that at startup, the item categories are also loaded into the cache (in the StartUpListener class).
(Can refer to the source code, will not expand. The specific type is coded in the planning document in the source code, or can be defined by yourself.
2. Prop dictionary
With categories in place, it’s time to define the item dictionary (which defines all possible items in the game).
1. Prop coding
In order to distinguish item types, it is necessary to have a code specification that uniquely identifies an item. The format is as follows:
Item type identifier = type code (5 digits) + serial number (5 digits), for example: One-handed sword = 61101, blunt sword is the first item of this type, the number is 6110100001.
Backpack items ID = prop type identification (10) + timestamp (12) + serial number (4), such as: have dropped a blunt sword, the player backpack items with ID 61101000012103151200360001.
That is, a maximum of 100,000 devices of the same type can be defined in the system. The same equipment can produce up to 10,000 units per second.
Here, the type encoding is defined in the planning document, and the serial number is obtained by incR operation in Redis. For details, please refer to the source code.
2. Data table structure design
When designing spreadsheets, take into account that both regular and equipment items have common attributes such as name, description, quality, tradable, unique, disposable, and so on.
To do this, you can design an item base table, Item_common, to record the basic information of all items.
The attributes specific to the equipment table, such as damage, armor, health, strength, agility, etc., are included in the Equipment table in item_EQUIPmen.
When you design a list of normal items, such as cooking, scrolls, mounts, etc., you can extend it to item_normal.
This design prevents a single table from having too many fields.
CREATE TABLE 'item_common' (' id 'varchar(20) NOT NULL COMMENT' 1 ', 'type_code' varchar(10) NOT NULL DEFAULT COMMENT ', 'name' varchar(20) NOT NULL DEFAULT COMMENT ', 'description' varchar(500) NOT NULL DEFAULT COMMENT ', 'quality' varchar(10) NOT NULL DEFAULT 'COMMENT ',' item_level 'int NOT NULL DEFAULT '1' COMMENT ', 'required_level' int NOT NULL DEFAULT '1' COMMENT 'DEFAULT ', 'required_job' varchar(10) NOT NULL DEFAULT COMMENT ', 'stack_size' int NOT NULL DEFAULT '1' COMMENT 'stack number ', 'price_buy' int NOT NULL DEFAULT '0' COMMENT 'buy price ',' price_buy 'int NOT NULL DEFAULT '0' COMMENT' sell price ', 'can_trade' tinyint NOT NULL DEFAULT '1' COMMENT 'whether to trade 0: no 1: Yes ', 'can_DROP' TINyINT NOT NULL DEFAULT '1' COMMENT 'Whether the COMMENT can be discarded 0: no 1: Is_unique 'tinyint NOT NULL DEFAULT '0' COMMENT' whether 0: no 1: Yes ', 'extend_prop' varchar(8000) NOT NULL DEFAULT COMMENT ', 'create_user' varchar(20) NOT NULL DEFAULT COMMENT 'create ', 'update_user' varchar(20) NOT NULL DEFAULT COMMENT ', 'create_time' datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create_time ', 'update_time' datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'UPDATE time ', 'is_delete' tinyInt NOT NULL DEFAULT '0' COMMENT 'whether to delete 0- No 1- Yes ',' version 'int NOT NULL DEFAULT '0' COMMENT' version ', PRIMARY KEY (`id`), KEY `idx_item_type_code` (`type_code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT=' item dictionary table ';Copy the code
item_common
CREATE TABLE 'item_equipment' (' id 'varchar(20) NOT NULL COMMENT' id ', 'type_code' varchar(10) NOT NULL DEFAULT COMMENT ', 'name' varchar(20) NOT NULL DEFAULT COMMENT ', 'damage_min' int NOT NULL DEFAULT '0' COMMENT, 'damage_max' int NOT NULL DEFAULT '0' COMMENT, Armour 'int NOT NULL DEFAULT '0' COMMENT' HP 'int NOT NULL DEFAULT '0' COMMENT' health ', 'strength' int NOT NULL DEFAULT '0' COMMENT ', 'agility' int NOT NULL DEFAULT '0' COMMENT 'agility ', Intellect 'int NOT NULL DEFAULT '0' COMMENT' stamina ', 'intellect' int NOT NULL DEFAULT '0' COMMENT 'stamina ', 'extend_attr' varchar(8000) NOT NULL DEFAULT COMMENT ', 'create_user' varchar(20) NOT NULL DEFAULT COMMENT 'create ', 'update_user' varchar(20) NOT NULL DEFAULT COMMENT ', 'create_time' datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create_time ', 'update_time' datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'UPDATE time ', 'is_delete' tinyInt NOT NULL DEFAULT '0' COMMENT 'whether to delete 0- No 1- Yes ',' version 'int NOT NULL DEFAULT '0' COMMENT' version ', PRIMARY KEY (`id`), KEY `idx_equipment_type_code` (`type_code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT=' table ';Copy the code
item_equipment
The class diagram, modeled in code, looks like this:
Third, the effect demonstration
Four, summary
This chapter mainly realizes the basic configuration of prop classification and prop dictionary.
There are many kinds of props, which need to be planned and matched one by one. Here I only matched a dozen attributes of one-handed swords for demonstration.
The next chapter is expected to be a simple implementation of the character backpack in the game module
In this paper, the original address: www.cnblogs.com/lyosaki88/p…
Download this chapter source code address: 474b.com/f/14960372-… (Access Password: 9502)
Project Exchange Group: 329989095