RPG多人回合制战斗框架设计《五:Buff设计》

RPG战斗框架包含以下四部分的内容:


一、基本战斗流程

二、战斗角色设计

三、战斗伤害计算

四、技能设计

五、BUFF设计

六、战斗AI

五、BUFF设计

BUFF类似被动技能,存在战斗角色身上,只不过功能多些,是被动技能的升级版本

除了可增益减益,还可以叠加buff,有固定回合等功能

其实也就是

1、buff叠加叠加规则

2、buff回合管理

3、有buff时候触发各种事件

BUFFOVERLAY_ADD = 0  # 叠加规则

class CBuffBase(object):
	m_name = "未知Buff"
	m_id = 1
	m_overlay_max = 1
	m_overlay_type = BUFFOVERLAY_ADD
	m_Hold = True
	m_base_effects = {
	}

	def __init__(self, arg):
		super(CBuffBase, self).__init__()
		self.m_overlay = 1
		self.m_ratio = arg[0] if isinstance(arg, (list, tuple)) else arg
		self.m_Arg = arg
		self.m_effects = {}

		self.m_bout_max = 0
		self.m_bout = 0
		self.m_skill_id = 0
		self.m_skill_level = 0
		self.init_effect(self.m_ratio)

	def __str__(self):
		return self.m_name

	def init_effect(self, ratio):
		for k, v in self.m_base_effects.iteritems():
			self.m_effects[k] = v * ratio

	def set_args(self, sid, lv):
		self.m_skill_id = sid
		self.m_skill_level = lv

	def on_fight_ready(self, wobj):
		pass

	def on_hurt(self, wobj, att, damage, dtype):
		return damage

	def apply(self, wobj, bout=None):
		wobj.AddapplyDict(self.m_effects)
		self.m_bout_max = bout
		self.m_bout = 0

	def on_bout(self, wobj):
		if self.m_bout_max == 0:
			return 1
		self.m_bout += 1
		return self.m_bout_max - self.m_bout

	def release(self, wobj):
		wobj.remove_apply(self.m_effects)

	def replace(self, bobj):
		bobj.m_bout += self.m_bout
		return bobj


class CBuffSlot(object):
	def __init__(self):
		self.m_buff_group = {}
		self.m_buff_order = []

	def add_buff(self, wobj, bobj, bout):
		lst = self.m_buff_group.setdefault(bobj.m_ID, [])
		if len(lst) == 0:
			lst.append(bobj)
			bobj.apply(wobj, bout)
		else:
			head = lst[0]
			if head.m_overlay_type == BUFFOVERLAY_ADD:
				# 叠加
				head.Replace(bobj)

	def remove_buff(self, wobj, bid):
		lst = self.m_buff_group.pop(bid)
		self.m_buff_order.remove(bid)

	def get_buff(self, bid):
		return self.m_buff_group.get(bid)

	def bout(self, wobj, bobj):
		if bobj.do_bout(wobj) == 0:
			bobj.m_release = True

	def DoBout(self, wobj):
		self.Call(wobj, self.bout)

	def Call(self, wobj, func, *args):
		order = self.m_buff_order[:]
		for bid in order:
			bobj_lst = self.m_buff_group.get(bid)
			for bobj in bobj_lst:
				func(att, wobj, bobj, *args)

	def hurt(self, att, wobj, bobj):
		self.m_hurtdamage = bobj.on_hurt(wobj, att, self.m_hurt_damage)

	def on_hurt(self, wobj, att, damage):
		self.m_hurt_damage = damage
		self.Call(wobj, att, self.hurt)
		return self.m_hurt_damage

例子:

class CBuff(CBuffBase):
	m_id = 1001
	m_name = ",增加最大血量"
	m_base_effects = {
		"m_hp_max": 1,
	}


 战斗角色对象增加buff槽

class CWarrior(CWarriorProp):
    def __init__(self):
        self.m_buff_slots = buff.CBuffSlots()

 给战斗对象增加buff例子

buff_ob = buff.load_buff(1001, 10)
warrior.m_buff_slots.add_buff(warrior, buff_ob, 1)

你可能感兴趣的:(游戏服务器,python,MMORPG,游戏服务器,回合制战斗框架)