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

    There are many forms of fighting in online games, and the fighting logic of different games is also very different. However, the skill system and the buff system are generally involved. The two are related to each other. Skills can generate buffs and affect the target. At the same time, buff will also affect the release effect of skills, both of which can be regarded as the most important elements of the game's combat system.

    There are many complex buffs and skills in the game battle. These buffs and skills are formed by the combination of basic buff and skill effect mechanism. Through the combination of basic mechanism effects, various complex buffs and skills are formed. These basic buff effect mechanisms and skill effect mechanisms support planning to affect the actual effects of these buffs and skills through the configuration table configuration data.

    The battles of different types of games may vary, but as long as you grasp the core elements, the same buff system and skill system can be adapted to different types of games.

    The following introduces my understanding of the buff system, which can be regarded as an introduction.

    The source of the buff may be the skills released by the battle unit, it may be the buff effect that generates a new buff, or it may be because of wearing a certain piece of equipment at the beginning of the battle.

    There are various effects produced by buffs, such as increasing/decreasing attribute value, loss/recovery of life, magic, etc. within a certain period of time, stun, silence, shield, taunt, anti-damage, attack damage increase when attacking, and damage reduction when attacked. , Injure the opponent when killed, return blood when killing the target, etc. The same combat unit can have multiple buffs.

    In order to increase the usability and flexibility of the buff system, we can split a buff into one or more basic buff effects. By implementing the basic buff effects, flexibly combine to form a variety of buffs. For example, applying a buff effect to a hero is to restore 10% of the hero's HP when the shield is removed. This buff has two basic effects, one is the shield, and the other is the HP recovery when the buff is removed. A buff can have one or more buff effects, and a hero has multiple buffs.

    In order to manage the many buffs in the combat unit, a buff manager is needed to manage the entire life cycle of buff addition, effect, and removal. The interface for external use can only be buffManger, such as adding buffs, sending buff lists, and checking buff effects Status, called at the trigger point to perform buff effects, etc. The relationship between the basic effects of buff, buff and buff manager is as follows:

 

    The specific implementation needs to design a base class for the buff effect, in which member variables have the buff effect number and the virtual function for the buff effect. All buff mechanism effects need to inherit the base class, and implement the void perform ( unsigned  char  buffStep ) function according to the specific buff effect . Each buff effect number is used to distinguish the buff effect to which it belongs, so that it is convenient for buff management to contain the buff effect.

struct basePerform
{
	eBuffPerfrom perfromType;//可以定义一个枚举
Buff* owner;				//所属buff
	basePerform(eBuffPerfrom _perfromType, Buff* _owner):perfromType(_perfromType),owner(_owner)
	{}
virtual void perform(unsigned char buffStep)=0;//buff效果具体执行
	virtual ~basePerform(){}
};

    Buff manages one or more subclass objects inherited from basePerform. The effect number determines the basic effect of the buff. The buff also records the pointer to release the buffer's battle unit, the pointer of the buffManger, the number of buff stacks, buff configuration data, buff generation time, buff type, buff removal flag and other data.

class Buff
{
public:
	Buff(FightUnit* _attacker,buffManger* _manger,  const cBuffCfg* _cfg, eBuffType _buffType, DWORD _putTime);
	virtual ~Buff();
//一些函数实现,诸如buff效果的实现,buff初始化,标记移除等等
public:
	FightUnit* attacker;     //产生buff的FightUnit
buffManger* _manger;
	const cBuffCfg* _cfg;	   // buff配置表数据
	unsigned long putTime;    //buff的产生时间
	unsigned short overlay;   //叠加层数
	eBuffType buffType; 		//buff类型
	bool bRemove; 			//移除标记
unsigned char buffStep; 	//buff执行步骤
	std::vector<basePerform*> vecBuffPerform;//buff的所有效果
}

buffManger saves this group of buffs, the battle unit to which buffManger belongs and other data. Controls the entire life cycle of the buff

class buffManger
{
public:
	buffManger(FightUnit* _owner);
	virtual ~buffManger();
//一些函数实现,比如添加/移除buff函数,timetick函数,buff触发函数,检查buff效果函数等等
privet:
	FightUnit* owner;
	std::vector<Buff*> vecBuffs;
unsigned short buffPerformStatus[eBuffPerfrom_Max];
}

There are various buff effects. The buff effect may be a certain state, such as stun. When the combat unit is acting or releasing skills, check the buffManger of the combat unit to traverse all the vecBuffs. The buff effect of all the buffs has a stun effect, and if there is no action Or release skills. It may also add attribute values. When adding or removing a buff, the attribute value of the combat unit is recalculated according to the effect of the buff. Or it can be triggered. For example, for turn-based, churn may cause blood loss every round, and for non-turn-based ones, it may cause blood loss every second. There are many points in the trigger that will cause the trigger, such as death, attack, attack, crit, block, etc., so every time you reach the trigger point, you have to traverse all the buff mechanisms to find the qualified execution buff effect .

In order to reduce the number of traversal, you can add the buffPerformStatus array variable to buffManger, imitating that only a pointer can do a count. Each member represents the count of the buff effect of this buffManger. If there is no corresponding buff effect, the count value is zero. If there is a corresponding buff effect when adding a buff, the count is increased by one, and the corresponding buff effect is also removed when the buff is removed, and the count is reduced by one. . In this way, we are checking a certain buff state, such as vertigo, and we don't need to traverse the buff that is said to be. If there is a corresponding buff effect when triggered, go to traverse.

In this way, this buff system model can be suitable for most battles, and can be used in different battles with a slight modification.

Guess you like

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