Skyrim style item system

2

I'm developing a 2D RPG in Skyrim style C #, and I'm in the part of implementing the game items, but with a lot of difficulties. I wanted to do a Skyrim-like mechanic in which you have a range of items sorted in a variety of ways such as armaduras , armas , poções , anéis , amuletos . Some items can be encantados and desencantados , but some items are restricted to specific incantations . I've created a class diagram to represent the system but I do not think it's very flexible. As it stands, it seems that if I want to create more types of items in the future, new classes will have to be created. If there are 1000 items in the game and I have to create a class for each one I am, as it says, "chipped".

Another problem I am facing is the implementation of spells. Whoever played Skyrim knows very well how it works. Suppose you want to enchant a ring with an enchantment that increases the player's HP. For this it is necessary to use a charmer and possess the enchantment of HP. I will not use the soul stones scheme . The effectiveness of the enchantment will depend on the player's current attributes. The more skillful in enchantment, the greater the amount of HP added by enchantment. But I end up falling in the same case of the items; for each incantation a class?

Here's the diagram:

TogetaroundexcessiveclasscreationI'vecreatedanexampleonlywithclassItemandinterfacesConsumableandEquipablebutIdonotknowifitwasagoodchoice.HowdoIidentifyanitem?Howtodifferentiateoneitemfromanother?Enumsmaybe?IhadtopassaPlayertotheconstructorofItemtobeabletomodifyitsfieldsinequip(),unequip()andconsume()andthatsoundsalotlikeagambiarra

publicclassPlayer{inthp;publicPlayer(inthp){this.hp=hp;}}
publicabstractclassItemimplementsEquipable,Consumable{Playerpossesor;Stringname="";
    int price = 0;
    boolean questItem = false;
    boolean equiped = false;

    public Item(Player p) {
        possesor = p;
    }
}
public interface Equipable {
    void equip();
    void unequip();
}
public interface Consumable {
    void consume();
}
package br.com.interfaces;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

public class Tester {

    public static void main(String[] args) {

        Item ringOfLife = new Item(new Player(0)) {

            @Override
            public void consume() {
                throw new NotImplementedException();
            }

            @Override
            public void unequip() {
                if (equiped) {
                    possesor.hp -= 10;
                    equiped = false;
                }
            }

            @Override
            public void equip() {
                // Ok, eu sei, isso deveria ser um encantamento ,-,
                if (!equiped) {
                    possesor.hp += 10;
                    equiped = true;
                }
            }
        };

        assert(ringOfLife.possesor.hp == 0);
        assert(ringOfLife.equiped == false);
        ringOfLife.equip();
        assert(ringOfLife.possesor.hp == 10);
        assert(ringOfLife.equiped == true);
        ringOfLife.unequip();
        assert(ringOfLife.possesor.hp == 0);
        assert(ringOfLife.equiped == false);
    }
}

I think I've provided all the necessary information. What do you think? Do you recommend some Design Pattern ?

    
asked by anonymous 20.09.2016 / 07:15

1 answer

2

I only recommend that you work with Interfaces , rather than just inheritance. This article has a legal example, including characters and weapons, about Dependency Injection .

I do not recommend using Ninject specifically as your DI. I recommend the SimpleInjector , because it is also simple to implement, is lighter and also the faster on the market .

    
20.09.2016 / 10:41