Jump to content
  • Advertisement
Sign in to follow this  
sp00kymulder

Help with Coding Random Loot Generator

This topic is 1091 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm teaching myself programming by coding video game components because its about the only thing that holds my interest when things get challenging. I have starting planning a simple Diablo style loot generator, but I have a question. If I use XML to store magic prefixes/suffixes and their modifiers, will my weapon class need to have every possible attribute as a field. For example, if prefix 'chilling' adds.bonus cold damage, would bonusColdDamage need to be a part of the weapon class and be set to 0 if not used? I can try to clarify more if needed.

Share this post


Link to post
Share on other sites
Advertisement
That's one way to do it, but it's rather inflexible, as you'd end up having to implement every stat you can think of on the base weapon. It also doesn't really cover fancier effects like maybe you have a chance on hit of spawning a friendly zombie to attack your enemies.

If I were to do it, I'd basically treat prefixes/suffixes/modifiers as magic effects that are applied to the weapon, resulting in something like this (I do not pretend the formulas here are good ones, use your own math smile.png ):
 
class MagicEffect
{
public:
  MagicEffect {}
  virtual ~MagicEffect() {}

  virtual void ApplyEffect(const Actor& aCaster, Actor& aTarget) const = 0;
};

class ColdEffect final: public MagicEffect
{
public:
  ColdEffect(const float aBaseDmg): MagicEffect(), BaseDmg(aBaseDmg) {}

  virtual void ApplyEffect(const Weapon& aWeapon, const Actor& aCaster, Actor& aTarget) const override
  {
    float actualDamage = CalculateDamageBoost(aCaster, aWeapon) + BaseDmg;
    float resist = aTarget.GetResistance(Resistance::COLD);
    aTarget.TakeDamage(actualDamage * resist);
  }

private:
  float BaseDmg;
};

class Weapon
{
public:
  void AddEffect(std::unique_ptr<MagicEffect> aEffect)
  {
    Effects.push_back(std::move(aEffect));
  }

  void HitTarget(const Actor& aAttacker, Actor& aTarget) const
  {
    // <insert melee damage code here>
    for (const auto& effect : Effects)
    {
      effect->ApplyEffect(*this, aAttacker, aTarget);
    }
  }

private:
  std::vector<std::unique_ptr<MagicEffect>> Effects;
};
Then you just need to make a sub-class for each kind of effect you want, and data files containing the stats and names and such of each effect. You could even make a "combo" effect that contained multiple effects inside it and applied them all at once too.

(The above example is also a little overly hard-coded. You could make the damage type another parameter and just call the effect MagicDamageEffect, passing in the "cold" damage type which you would get from an asset file) Edited by SmkViper

Share this post


Link to post
Share on other sites

I've been reading up on the decorator pattern, and what you suggested above sounds kind of similar, so that may be a good choice for this.  Thanks for the input!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!