AboutLUAInOnline GamesThe application in the task is the content to be introduced in this article, mainly to understandLUAMediumOnline Games.LUABornGamesRelated; Since Warcraft launched it, more and moreGamesThe company uses it.
GamesIn the logic, it is closely related to accessing the NPC part. A transaction box, a creation box, and a task dialog box are displayed, which are basically implemented by LUA. In this article, I want to learn more about it, write down the lua Implementation of game tasks;
In last December, the new game project was established. The first task assigned to me was to compile the game task. At that time, I still did not know what lua was doing, it took a day to get familiar with the lua syntax, mainly about the table structure.) C and lua call each other to the interface, and then I found myself on the road.
I personally prefer the top-down learning method, so here I will first give a rough outline of the access task NPC:
1. When a player accesses the NPC, the client sends the click message with the NPCid to the server;
2. Check whether the task menu of this NPC is actually a lua table) to determine whether the player meets the criteria, whether the prerequisite task is completed, and whether the task has been done .. Etc)
3. If yes, the server fills in the form information and assigns an id index starting from 0 to each task button because there may be more than one task at one NPC, register a callback function for each button, which is indexed by the id. The form information is sent to the client and executed by the client to display the appropriate dialog interface;
4. When a player clicks a task button, the client sends the corresponding id information to the server and the server performs the corresponding callback. For example, when receiving a task, this callback is probably acceptTask (taskid) and so on. When submitting a task, this callback is probably commitTask (taskid ))
There are many other real situations. because the task is the simplest, you can choose to explain it.
To compile a program, you must first determine the data structure. The final definition of a struct task includes the following members: unique task id, type, pre-task, task reward item, experience, money, and task start NPC ), the task description, unfinished description, completion description, task element, and other fields are not mentioned here. It took me two weeks to make sure that the structure was intermittent... I have never played any online games. I started several online game clients in the first few days. I registered a number to go in and play it. I simply understood what the task was like.
I want to explain in detail the task elements:
In my initial understanding, the task is to let you do something, and then you can complete this task and get a reward. Therefore, it is abstracted as a task element. The name may be a bit strange, and it seems a little cool, so I decided.
Task elements can be of different types. The two most common types are monsters and items. Many tasks require how many monsters are killed and how many items are collected. This is also the simplest and most basic.
Later, due to the continuous submission of planning requirements, I added some types. For example, if a task requires you to search for some NPCs, the type is VISIT, that is, access.
Some tasks enable you to answer questions, and have the QUESTION type.
InGamesAt startup, the task data is imported to lua to construct a lua table for each task-related NPC. The table name suffix is the corresponding npc ID for easy search.
The start of the process for receiving a task has been briefly described. Here we will briefly describe the completion of the task.
Each time a Player receives a new Task, the Task element of the Task is added to the Task Manager of the Player structure (class Player. The task manager uses a map to manage multiple tasks.
When a player accesses the termination NPC of the task, it determines whether the task element is complete. if the task is completed, a dialog box for task submission is constructed. The Player clicks finish to obtain the task reward.
If the task is not completed, the end of the NPC will be a "unfinished description" of the corresponding task ". For example, you may say, "You can't even clean up those monkeys. You really disappoint me ".
The preceding describes the simplest and most common task types. It is difficult to implement the actual game task in a unified framework. However, due to the flexibility of LUA, I personally think that the table structure is flexible and omnipotent.) they use the tasks of Warcraft to describe the requirements for planning, but I have never touched Warcraft. So some gaming experience is quite good.) In many cases, I use lua table to configure tables and write several functional functions. However, I feel that some of my ideas may be "willful". At present, it is enough, and it will be hard to say in the future. After all, I cannot imagine what kind of tasks are there.
Summary: AboutLUAInOnline GamesThe content of the application tutorial in the task has been introduced. I hope this article will help you!