RPG多人回合制战斗框架设计《三:战斗伤害计算》

韦业
2023-12-01

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


一、基本战斗流程

二、战斗角色设计

三、战斗伤害计算

四、技能设计

五、BUFF设计

六、战斗AI

三、战斗计算

1、角色出手和施法物理、法术技能施法

2、战斗伤害的计算

warcommand.py

施法操作:

# -*- coding: utf-8-*-

from war_def import *


class CWarPhysics(object):
	def attack(self, tid, att):
		vic = self.get_warrior(tid)
		delay = self.do_attack(att, vic)
		return delay, False

	def do_attack(self, att, vic):
		delay = 0
		damage = self.physics_damage(att, vic)
		damage = att.on_hit(vic, damage, None, 0)
		vic.receive_damage(damage, att)
		return delay


class CWarPerform:
	def perform(self, tid, skob, lv, att):
		vic = self.get_warrior(tid)
		delay = 0
		targets = skob.get_targets(self, att, vic, lv)
		if targets:
			skob.pre_cast(self, att, targets, lv)
			delay += skob.do_cast(self, att, targets, lv)
			skob.end_cast(self, att, targets, lv)

	return delay, False


class CWarCommand(CWarPhysics, CWarPerform):
	def escape(self, rate, wobj):
		pass

	def defence(self, rate, wobj):
		pass

warformulas.py

伤害计算:

# -*- coding: utf-8-*-

from war_def import *


class CWarFormulas(object):
	def physics_damage(self, att, vic, add=0, def_add=0):
		rate = 500
		damage = (att.get_attack() + add - vic.get_defense() * (1000 - rate) / 1000) * rand_int(*RANDOM_DAMAGE) / 100
		damage = max(0, damage)
		return damage

	def magic_damage(self, att, vic, add=0):
		rate = 500
		damage = (att.get_magic_attack() + add - vic.get_magic_defense() * (1000 - rate) / 1000) * rand_int(
			*RANDOM_DAMAGE) / 100
		damage = max(0, damage)
		return damage

 类似资料: