技能系统演化之路:由数据驱动到图形化编程

技能系统因为其逻辑的复杂性,建立一种纯数据的数据驱动模型应该说是不可能的。比较好的思路是一方面不断提高数据结构的灵活性,让数据尽可能描述更多的情况,另一方面对于不常用甚至一次性的需求不考虑在数据层上解决问题,改为直接调用脚本,这方面的代表是Dota2。另一种思路是直接以图形化编程的方式来完成逻辑,不需要设计任何数据结构,这种思路是近些年图形化编程兴起所带来的,这方面的代表是守望先锋和堡垒之夜。

本文就以火炬之光,Dota2和UE4的Gameplay Ability System(GAS)为例分别讲述纯数据驱动,数据结合脚本驱动和图形化编程三种不同的设计思路。

火炬之光

数据结构

数据结构如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
Skill
└── Events
   ├── Layout
   └── Effects

Layout
├── Timelines
├── Sounds
├── Particles
├── Damage Shapes
├── Camera Shakes
└── Unit Spawners

火炬之光存在两种数据结构,Skill和Layout。前者以事件驱动,事件发生后会触发Layout和零到多个Effect。后者可以理解为时间轴,里面存放着声音,特效,伤害体,震屏和单位生成器,可以说凡是方便在时间轴编辑器里编辑和预览的物体都在其中了。

执行顺序

下面是执行时的顺序:

1
2
3
4
5
6
7
8
9
Event
├──> Effect
└──> Layout
└──> Timeline
├──> Sound : Play
├──> Particle : Start Particle
├──> Damage Shape: Enable/Disable
├──> Camera Shake: Activate
└──> Unit Spawner: Spawn Units

火炬之光是以事件驱动为主,时间轴为辅的驱动方式,与表现相关的都在时间轴里。

Event

事件列表:

  • EVENT_START
  • EVENT_END
  • EVENT_TRIGGER
  • EVENT_TRIGGER_TWO
  • EVENT_TRIGGER_THREE
  • EVENT_TRIGGER_FOUR
  • EVENT_UNITHIT
  • EVENT_UNITDIE
  • EVENT_UNIT_CREATE
  • EVENT_MISSILEHIT
  • EVENT_MISSILEDIE
  • EVENT_MISSILE_PULSE
  • EVENT_DIEBYEFFECT
  • EVENT_CASTERDIE

Effect

Effect列表:

  • ADD CHARGE PERCENT
  • ADD CHARGES
  • ADD STAT
  • ADD STAT TO LEVEL
  • ADD TRIGGERABLE
  • AGRO
  • ARMOR BONUS
  • ARMOR ITEM REQUIREMENTS
  • ATTACK SPELL BONUS
  • AWARD STATPOINT
  • BLIND
  • BLIND RESISTANCE
  • BURN
  • BURN DURATION BONUS
  • CAST SKILL
  • CAST SKILL AT TARGET
  • CAST SKILL FROM TARGET
  • CAST SKILL ON DEATH
  • CAST SKILL ON DEATH FROM EFFECT OWNER
  • CAST SKILL ON KILL
  • CAST SKILL ON KILL AT TARGET
  • CAST SKILL ON MELEE SKILL STRIKE
  • CAST SKILL ON MELEE SKILL STRIKE FROM TARGET
  • CAST SKILL ON MELEE STRIKE
  • CAST SKILL ON MELEE STRIKE FROM TARGET
  • CAST SKILL ON RANGED SKILL STRIKE
  • CAST SKILL ON RANGED SKILL STRIKE FROM TARGET
  • CAST SKILL ON RANGED STRIKE
  • CAST SKILL ON RANGED STRIKE FROM TARGET
  • CAST SKILL ON SKILL STRIKE
  • CAST SKILL ON SKILL STRIKE FROM TARGET
  • CAST SKILL ON STRIKE
  • CAST SKILL ON STRIKE FROM TARGET
  • CAST SKILL ON STRUCK
  • CAST SKILL ON TARGET
  • CHARGE BAR DECAY DELAY
  • CHARGE BAR DECAY RATE
  • CHARM RESISTANCE
  • CHARM SPELL BONUS
  • CHEATED
  • CLEAR STAT
  • CLEAR STAT ON LEVEL
  • CONVERT CHARGE PERCENT TO STAT
  • CONVERT CHARGE TO STAT
  • CRITICAL CHANCE
  • DAMAGE
  • DAMAGE BONUS
  • DAMAGE BONUS SECONDARY
  • DAMAGE CHANCE
  • DAMAGE REFLECTION
  • DAMAGE TAKEN
  • DEFENSE
  • DEFENSE SPELL BONUS
  • DEGRADE ARMOR
  • DEGRADE ARMOR EFFECT
  • DESTRUCTABLE SHIELD
  • DESUMMON MONSTER
  • DESUMMON ON DEATH
  • DEXTERITY BONUS
  • DISENCHANT
  • DODGE CHANCE BONUS
  • DRAW HEALTH
  • DRAW MANA
  • DUAL WIELDING BONUS
  • ELECTRICAL DEFENSE
  • ELEMENTAL EFFECT DURATION BONUS
  • EMOTIONAL DAMAGE
  • EXPLODE DEAD
  • EXPLODE ON DEATH
  • FADE OUT
  • FAME GAIN BONUS
  • FIRE DEFENSE
  • FISHING LUCK
  • FLEE EFFECT
  • FLEE RESIST
  • FREEZE
  • FREEZE DURATION BONUS
  • FUMBLE CHANCE REDUCTION
  • FUMBLE PENALTY REDUCTION
  • FUTURISTICNESS
  • GOLD DROP
  • HP MOD OVER TIME
  • HP RECHARGE
  • HP RECHARGE PLAYER
  • ICE DEFENSE
  • IDENTIFY
  • IMMOBILIZE
  • IMMOBILIZE RESISTANCE
  • INNATE ELECTRIC DEFENSE
  • INNATE FIRE DEFENSE
  • INNATE ICE DEFENSE
  • INNATE POISON DEFENSE
  • INTERRUPT
  • INTERRUPT CHANCE
  • INTERRUPT RESISTANCE
  • JAUNTINESS
  • KILL
  • KNOCK BACK
  • KNOCK BACK EFFECT
  • LEARN SKILL
  • LIFE STEAL
  • LIFE STEAL MASTER
  • LOGIC RESISTANCE
  • MAGIC
  • MAGIC ITEM REQUIREMENTS
  • MAGICAL DEFENSE
  • MANA RECHARGE
  • MANA RECHARGE PLAYER
  • MANA STEAL
  • MARTIAL ITEM REQUIREMENTS
  • MAX CHARGES
  • MAX HP
  • MAX MANA
  • MELEEDAMAGEBONUS
  • MINIONDAMAGE
  • MISS CHANCE
  • MISSILE RANGE BONUS
  • MISSILE REFLECT
  • MISSILE REFLECT VISUAL
  • MODIFY SKILL COOLDOWN REMAINING
  • NONE
  • NOODLE ARMS
  • OPEN PORTAL
  • OPEN WAYPOINT PORTAL
  • PERCENT ACTIVE DISTANCE BONUS
  • PERCENT ARMOR BONUS
  • PERCENT ATTACK SPEED
  • PERCENT BLIND
  • PERCENT BLOCK CHANCE
  • PERCENT BLOCK CHANCE BASE
  • PERCENT CAST SPEED
  • PERCENT CHARGE BAR DECAY RATE
  • PERCENT CHARGING BONUS
  • PERCENT CRITICAL DAMAGE
  • PERCENT DAMAGE BONUS
  • PERCENT DAMAGE BONUS BY MONSTER COUNT
  • PERCENT DAMAGE REFLECTED
  • PERCENT DAMAGE TAKEN
  • PERCENT DAMAGE TAKEN BY MONSTER COUNT
  • PERCENT DEFENSE
  • PERCENT DEXTERITY BONUS
  • PERCENT DUAL WIELDING ATTACK
  • PERCENT GOLD DROP
  • PERCENT HP
  • PERCENT ITEM REQUIREMENTS
  • PERCENT KNOCK BACK RESISTANCE
  • PERCENT LIFE STOLEN
  • PERCENT LIFE STOLEN MASTER
  • PERCENT MAGIC
  • PERCENT MAGIC ITEM DAMAGE BONUS
  • PERCENT MAGICAL DROP
  • PERCENT MANA
  • PERCENT MANA COST BONUS
  • PERCENT MANA STOLEN
  • PERCENT MARTIAL ITEM DAMAGE BONUS
  • PERCENT MELEEDAMAGE
  • PERCENT PET ARMOR
  • PERCENT PET DAMAGE
  • PERCENT PET HEALTH
  • PERCENT PET VELOCITY
  • PERCENT RANGED ITEM DAMAGE BONUS
  • PERCENT RANGEDDAMAGE
  • PERCENT SIGHT BONUS
  • PERCENT SPEED
  • PERCENT STRENGTH BONUS
  • PERCENT TO HIT BONUS
  • PERCENT VIEW ANGLE BONUS
  • PERMANENT DEFENSE
  • PERMANENT DEXTERITY
  • PERMANENT HEALTH
  • PERMANENT MAGIC
  • PERMANENT MANA
  • PERMANENT STRENGTH
  • PET DEPARTURE TIME
  • PHYSICAL DEFENSE
  • POISON
  • POISON DEFENSE
  • POISON DURATION BONUS
  • POTION EFFICIENCY
  • PRICE REDUCTION
  • PULL
  • PULL EFFECT
  • PULL RESISTANCE
  • RANGED ITEM REQUIREMENTS
  • RANGEDDAMAGEBONUS
  • REDUCED ITEM REQUIREMENTS
  • REMOVE EFFECT
  • REMOVE TRIGGERABLE
  • RESPEC
  • RETARGET
  • SCALE
  • SCALE BY HP
  • SET CHARGE PERCENT
  • SET MESH INVISIBLE
  • SET SKILL COOLDOWN REMAINING
  • SET SKILL LEVEL
  • SET STAT
  • SET STAT ON LEVEL
  • SET VISIBLE
  • SHIELD BREAK
  • SHIELD BREAK EFFECT
  • SHIELD BUFFER
  • SHOCK
  • SHOCK DURATION BONUS
  • SIGHT BONUS
  • SILENCE
  • SILENCE_RESISTANCE
  • SKILL BONUS
  • SKILL DISABLE
  • SKILL ENABLE
  • SLOW RESISTANCE
  • SOCKS
  • SPAWN UNIT
  • SPAWN UNIT ON DEATH
  • SPELL REQUIREMENTS
  • STOP SKILL
  • STRENGTH BONUS
  • STUN
  • STUN RESISTANCE
  • SUMMON DURATION
  • SWAP POS WITH PET
  • TARGET LOCKED
  • TELEPORT
  • TELEPORT NOPARTICLE
  • TELEPORT RANDOM
  • TELEPORT RANDOM NOPARTICLE
  • TELEPORT RESISTANCE
  • TO HIT BONUS
  • TRANSFORM
  • TRANSFORM PERMANENT
  • TRANSFORMATION TIME
  • TRAP DISARM CHANCE
  • TURN ALIGNMENT
  • UNIT THEME
  • VELOCITY MULT
  • VIEW ANGLE BONUS
  • WARP
  • WARP TO POI
  • XP GAIN BONUS

Effect的数量达到了239个,Dota2的同类概念Action只有23个。考虑到策划每次都要从长达239的下拉框中选择,实在是过多了。两个原因造成了这种情况:

  1. Effect对属性和状态的修改没有合并,Dota2将其合并到两个
  2. 无法直接调用脚本,理论上Effect列表仅仅应该列出可复用的行为,不常用的行为应该直接调用脚本

Dota2

数据结构

数据结构如下所示:

1
2
3
4
5
6
7
8
9
Ability
├── Events
│   └── Actions
└── Modifilers
   └── Modifier
├── Events
   | └── Actions
   ├── Properties
   └── States

由于Valve提供了全面的文档,这里不再复述,主要对比一下和火炬之光之间的差异:

  1. 支持直接运行脚本,可以通过RunScript来运行脚本
  2. 去掉了时间轴,可以通过DelayedAction来控制时间
  3. 增加了Modifiler,Property和State这些概念

对比火炬之光,Dota2在功能没有减弱的同时,结构大大简化了,更补全了一些必要的概念。个人觉得Dota2已经做到了数据的极致,再往前一步,数据就会变得更像脚本而非数据。现在已经有一些脚本的影子了,比如Modifier可以通过OnInterval事件实现循环逻辑。

执行顺序

下面是执行时的顺序:

1
2
3
4
5
6
Event
└──> Action

Apply Modifier
└──> Modifier Event
└──> Action

对比火炬之光,去掉了时间轴,并增加了Modifier部分。

GAS

TBD