Interrupt / delverengine

Delver game engine and editor
zlib License
800 stars 78 forks source link

Entity Tag System #129

Open joshuaskelly opened 4 years ago

joshuaskelly commented 4 years ago

Summary

This feature introduces a tag system for entities that can be used to make decisions.

Goals

  1. Simple straight forward API for working with tags.
  2. Simple JSON serialization types.
  3. Existing systems (status effects, item condition, etc) should participate in to tag system to allow decision marking.

Use Cases

  1. A breakable that only breaks when hit with a weapon with a specific tag. A boulder is only broken by a mattock. The mattock would be a weapon with the tag rock-breaker.
  2. Triggers only fire when the encroaching entity has a specific tag. A special door only opens if the player is poisoned.
  3. Monster only takes damage from certain tags. A ghost might only be hurt with magical tagged weapons.

Proposed JSON

{
  "id": "MyEntity",
  "tags": "poisoned,broken,unique"
}

Proposed Data Structure

public interface TagCollection {
    void add(String value);
    void add(TagCollection values);

    void remove(String value);
    void remove(TagCollection values);

    void toggle(String value);
    void toggle(TagCollection values);

    void contains(String value);
    void containsAny(TagCollection values);
    void containsAll(TagCollection values);
}
PythooonUser commented 4 years ago

I could imagine that passing a TagCollection to those methods would not be easy?! How about just passing an array of strings instead, e.g. tags.remove(["foo", "bar"]).

joshuaskelly commented 4 years ago

Why would that be difficult? It would look like:

Trigger t;
Player p;
p.tags.remove(t.tags);

Mock example of a trigger that removes a set of tags

evrimoztamur commented 4 years ago

@PythooonUser I agree with @joshuaskelly as initialisation would be done mainly in the data files. How about a generic collection which also adds method overloads for Array<E> and E[] though?

public interface TagCollection<E> { 
    void add(E value);
    void add(Array<E> value);
    void add(E[] value);
}
joshuaskelly commented 4 years ago

I'd also like to present a pretty easy view in the editor. Which typically is a comma separate list of strings.

PythooonUser commented 4 years ago

That mock example makes sense. I thought of a non-cached use-case where you would just test for some tags, and not creating a collection first etc.

joshuaskelly commented 4 years ago

@evrimoztamur I don't know what being generic gets us?

evrimoztamur commented 4 years ago

@joshuaskelly because Java has generics and generics are cool 😎

joshuaskelly commented 4 years ago

I think it would over complicate the editor experience.

evrimoztamur commented 4 years ago

Completely forgot about the editor, you're right!

Is there a way to add an 'editor representation'? As in, have the internal data structure be an array but be represented as string array (or other complex form) in the editor. Not too involved with editor param pane code.