IN3D / Pokemon

Recreation of pokemon, in C#.
0 stars 0 forks source link

A way to do abilities? #34

Closed IN3D closed 9 years ago

IN3D commented 10 years ago

@Daxter304 @BradMackey


So since I put the idea of abilities on hold because I just couldn't think of how to make them happen I haven't been completely happy with that decision and have been trying to think of a way to do it off and on. I think I finally just had a flash of inspiration that might make this work. Consider this:

  1. We have for during a battle a method solely dedicated to reducing the HP of a Pokemon.Something separate from it's properties get or set.
  2. The abilities class will need to have methods for anything that an ability would respond to. For example, Moxie would handle KO'ing a target, and Magic Bounce needs to handle anytime the current Pokemon takes damage.
  3. Inside of the method for reducing the current pokemon's HP there is a call to that Pokemon's ability's onDamage method.

Basically, what I'm envisioning is, as the computer communicating. The attacker calculates how much damage it is going to deal. It then passes this information to the target saying "I'm going to deal this much raw damage to you, how do you handle it?". This allows us to wrap up the logic for natural reductions of damage via Defense Sp. Defense, but also for conditional things like Magic Bounce. To better illustrate my idea, this is the pseudocode that I have in my head.

// This would be the method inside of the Pokemon class that handles it taking damage.
public void handleDamage(int damage)
{
    this.ability.onDamage(damage);
    // ...the rest of the logic for standard damage reduction goes here.
    // finally
    this.CurrentHP -= damage;
}

// here again, taken outside of where it would reside inside of the Abilities class is the
// onDamage method. We'll use Sturdy for as an example for how it would take damage.
public void onDamage(ref int damage)
{
    if (this.currentHP == this.MaxHP && damage >= this.currentHP)
    {
        damage = this.currentHP - 1;
    }
    else
    {
        // do nothing
    }
}

Because the parameter is passed by reference and not value, the method is allowed to interact directly with the value of the variable it is passed. In the case of Sturdy, this means that on the condition that the pokemon taking the attack is at full health, and the attack it is going to take would do more damage than it has health, the attacks damage is set to 1 less than it's maximum health (obviously leaving it with 1 HP).

Please let me know what you think, or if you can think of a better way to handle this. Thanks.

IN3D commented 9 years ago

This code was discussed by the group in our meeting on 08/04/2014, and something similar to this implementation will be followed in the project.