The specific design and implementation of the skill system of the online game combat system

    In the battle system of online games, the skill is the release of the battle unit to cause a series of skill effects on the target. A combat unit can have multiple skills. According to the player's operation or automatically, it is judged that the skill release meets the conditions (cd, magic, etc.) to release the skill. At this time, a skill Action object is generated according to the skill, and finally takes effect on the target.

    Each combat unit needs a skillManger object to manage its own skills (skill object). The skill object stores the basic configuration data of the skill, the last release time of the skill and other information, which is used to generate the skillAction object. The skillAction object is executed according to the timeline, and finally produces a skill effect on the target.

    The combat unit release skill becomes a skill Action, which can be divided into: start, chant, shoot, fly, take effect, and end. The specific duration of each stage is controlled by the configuration table. The duration of each stage is consistent with the front-end playback action time. At the beginning of each stage, the back-end will send a message to the front-end to inform the skills of the stage and duration, and then the front-end Play the corresponding action according to the stage.

    If the skill is shooting bullets remotely, the shot phase ends and the bullets are generated to fly, which can be called the bullet phase. Pick points according to the time interval, check the collision to take effect, the bullet disappears, enter the end phase, and the entire skill action ends.

 

skill class

class skill
{
public:
	skill(const cSkillCfg* _cfg, unsigned int _skillId, unsigned short _skillLv);
	virtual ~skill() {}
	//使用技能是检查技能的CD 时间精确到毫秒
	bool checkSkillCD(unsigned long long currentTm) const;
	//使用技能是的一些操作,比如记录此次释放技能的时间
	void onUseSkill(unsigned long long currentTm);
	//根据需要添加一些处理函数
public:
	const cSkillCfg* cfg;//关于技能的配置信息
	unsigned int skillId;//技能ID
	unsigned short skillLv;//技能等级
	unsigned long long lastUseTime;//上次释放技能的时间用于计算CD
};

skillManger skills for managing combat units

class skillManager
{
public:
	skillManager(FightUnit* _owner);
	virtual ~skillManager();
	//战斗开始先根据战斗单元数据,初始化技能表,并将生成的技能存skills表中
	void setup();
	//取出要释放的技能,进行操作
	skill* getSkill(unsigned short skillIndex);
	//管理战斗单元的所有技能,根据需求添加逻辑
public:
	FightUnit* owner;//所属战斗单元
	std::vector<skill*> skillList;//技能列表
};

    The skill release is based on the skill generated skillAction to deal with the specific effective situation of the skill

class skillAction
{
public:
	skillAction(fightScene* _scene, skill* _skill, fightUnit* _fighter);//传入战斗场景的指针,战斗技能,技能释放者
	virtual ~skillAction() {}
	void doSkillOnTimer(unsigned long long currentTm);//在战斗主循环中调用,每次调用到,根据时间检查所处阶段,以及结束时间,推进技能逻辑
	//与战斗效果相关函数处理,根据技能效果编号定义一组技能生效基础函数,将函数指针存存入列表,根据效果编号调用
public:
	fightScene* scene;
	skill* s;
	fightUnit* fighter;
	eSkillActionStage skillStage; //当前所处阶段(开始、吟唱、出手、飞行、生效、结束)
	unsigned long long stageEndTime; //当前阶段结束时间
}

    Skills have one or more effects in effect. Different skills are formed through combination, and some basic skill mechanism effects are also needed to be combined to form different skills. A skill can add a debug to the target while causing damage. This skill is composed of two basic skill mechanism effects, skill damage + buff. In this way, we only need to implement the basic skill effect mechanism, store the pointers of the realization function of different skill mechanism effects in an array, and call the function according to the skill mechanism effect number to realize the skill effect.

    

Guess you like

Origin blog.csdn.net/qq_19825249/article/details/108327033