W.U. 6: Melee Damaging

Check the video. The attacks now damage units. You’ll see the dummy red box has its health reduced when taking hits.

Its not quite visible in the video but I’ve also added swoosh trails on the weapon when attacking.

Actions and Effects

Here’s how the damaging works. There are two things right now at work here, two things I just made up: Actions, and Effects.

Action: Anything a unit can do. This is anything really, like movement, attacking, casting a spell, pulling a lever, etc. All Actions consume Stamina. Actions are named by verbs.

Effect: An event that alters a unit’s properties or behaviour. The most basic Effect is the Damage Effect, which simply reduces a unit’s health.

What does this mean? The concept of what a unit does, is separate from what happens after he does it.

So to make a typical attack, I’d give a Melee Action to a unit, then attach a Damage Effect to that Melee Action.

(You astute programmers will see this is simply a Strategy pattern.)

Why go through all that trouble? The answer is customization. Later on I’m going to have many more Effect types. I can attach more than one Effect on my attack. Say, maybe I have a Heal Effect, or a Poison Effect.

In the video, you saw the enemy also gets pushed back. That’s another effect, Push Effect.

I can also attach Effects to other things, not just attacks. Not just Actions. I can have armor that damages its user as upkeep, or attach the Heal Effect to a ring to make it a ring of healing. The details give more flexibility. Does the ring’s Heal Effect happen automatically? Or does the player need to activate it? Does it run out of charges?

Of course, I’m going to allow myself to have all those options in a mix-and-match approach so I can experiment.

Things can get a lot more complicated. I could have a character that wears provocative clothing. It hardly offers protection, but in return, any male unit near her will receive the Distracted Effect, increasing their chance to fumble their attacks and/or reduce their chance to evade (still working on the specifics).

Here’s my editor for that:

StrikeF1 is the near attack you see in the video. Its reach is 1.25 meters, and costs 40 Stamina points.

It does a Damage Effect and a Push Effect, which both get applied to whatever it is that the attack hit. Looking into each of those Effects, they have their own properties, like damage amount, push force, and push duration.

StrikeF2 is the farther lunging attack. Reaching up to 4 meters and costing 80 Stamina points. It pretty much has the same Effects, only with larger values.

Like I said before, this gets saved as a JSON text file. Here’s how that looks like:

{
  "__type": "MeleeLimits, Assembly-CSharp",
  "Omnidirectional": true,
  "Front": 
    {
      "__type": "MeleeLimits+Limit, Assembly-CSharp",
      "Angle": 0,
      "MinRange": 0,
      "Ranges": 
        [
          {
            "__type": "MeleeLimits+Limit+Attack, Assembly-CSharp",
            "AnimationName": "StrikeF1",
            "Range": 1.25,
            "StaminaCost": 40,
            "Effects": 
              [
                {
                  "__type": "DamageEffect, Assembly-CSharp",
                  "DamageAmount": 10,
                  "TargetType": "Hit"
                },
                {
                  "__type": "PushEffect, Assembly-CSharp",
                  "Force": 5,
                  "Duration": 0.25,
                  "TargetType": "Hit"
                }
              ]
          },
          {
            "__type": "MeleeLimits+Limit+Attack, Assembly-CSharp",
            "AnimationName": "StrikeF2",
            "Range": 4,
            "StaminaCost": 80,
            "Effects": 
              [
                {
                  "__type": "DamageEffect, Assembly-CSharp",
                  "DamageAmount": 30,
                  "TargetType": "Hit"
                },
                {
                  "__type": "PushEffect, Assembly-CSharp",
                  "Force": 7,
                  "Duration": 0.4,
                  "TargetType": "Hit"
                }
              ]
          }
        ]
    },
  "HasSideLimits": false,
  "SideLimitType": "LeftOnly",
  "Side": 
    {
      "__type": "MeleeLimits+Limit, Assembly-CSharp",
      "Angle": 0,
      "MinRange": 0,
      "Ranges": null
    },
  "Right": 
    {
      "__type": "MeleeLimits+Limit, Assembly-CSharp",
      "Angle": 0,
      "MinRange": 0,
      "Ranges": null
    },
  "HasBackLimits": false,
  "Back": 
    {
      "__type": "MeleeLimits+Limit, Assembly-CSharp",
      "Angle": 0,
      "MinRange": 0,
      "Ranges": null
    }
}

An unfortunate side-effect is every object now has that __type property, the type hint for the JSON deserializer so it knows what class each of them corresponds to in my C# code.

This is mainly for the fact that Effects is an array of the Effect class, but the elements of that array are of the different subclasses of Effect (DamageEffect, PushEffect, etc.). Without the type hint, the deserializer thinks all the elements are of type Effect, discarding subclass data like DamageAmount!

Advertisements

One thought on “W.U. 6: Melee Damaging

  1. Pingback: Refactoring | Project Victis

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s