NPCs and defining their data

Avatar

By bitcraft 17 Jul 2017 19:37

Champion · 123 comments

I'm doing a bit of work with NPCs, indirectly at the moment.  I'm wondering if anyone has any comments about how NPCs are created right now.  For instance, it is required to create NPCs with map events.  Also, NPCs must have their animations defined in the map event when created.

I'm wondering if anyone would object to consolidating NPC data into JSON files.  For instance, when creating an NPC, you won't have to define their animations, because it will be available in the JSON files.

Other aspects that could be consolidated are trainer speed, their monsters, and battle sprites.  Unless any one objects, I'd like to combine all this info, so that it isn't duplicated in the map files (and possibly duplicated incorrectly).

The general idea is to gather all the information from the "create_npc" events, create a JSON entry for each NPC, and rewrite the events in the maps.  Opinions?

Avatar

By Sanglorian 18 Jul 2017 08:15

Champion · 407 comments

Sounds good to me!

One thing to consider is whether to spin out "class" from individual NPCs, so you could have a "Beachcomber" class, which has a preset overland animation and a preset in-battle sprite. Then an NPC, "Bob", could have "Class: Beachcomber" instead of individually defining animations and battle sprite.

Would the NPC JSON file also have dialogue? How would that interact with game events? (E.g. "Bob says X" "After A has happened, Bob instead says Y". Or "If you have B, Bob says Z")

Finally, with monsters I'm wondering if the easiest way to do it is to allow monsters to be defined manually, but if details are omitted, for those details to be added procedurally.

For example, I can give Bob a level 5 Rockitten with Melee 1 or Melee 200, and I can give it any techniques I like. However, if I just specify "Rockitten" "Level 5", it gives it the standard stats for a level 5 Rockitten, and it gives it the most recent four techniques that a Rockitten would learn.

Avatar

By xirsoi 18 Jul 2017 11:57

Champion · 62 comments

A note on implementation: perhaps there could be an attribute to define an inheritance relationship with another NPC object? A fairly simple loop over attributes would allow the child object to add to and overwrite the template object. (Simple in concept, at least.)

{
  "slug": "npc_route_1_03",
  "template":"template_hiker"
  ...
}

Avatar

By bitcraft 18 Jul 2017 22:51

Champion · 123 comments
Sanglorian wrote

Would the NPC JSON file also have dialogue?

I don't think the dialog would go in the NPC JSON since that should be a locale/translation issue.  That doesn't mean that the dialog has to go in the master locale, it could be in a separate file, since the JSON loader supports merging multiple files while they are loaded...

Maybe dialogs could be defined in the NPC data though?  Do you think it would make maintenance any easier or difficult?  How would we organize all the translations?

Sanglorian wrote

How would that interact with game events? (E.g. "Bob says X" "After A has happened, Bob instead says Y". Or "If you have B, Bob says Z")

Game events are defined in Tiled, so there isn't really a way to enable the JSON data to do anything with game events, unless there was a parser written to load events from JSON (honestly, probably not hard, but I don't want to go down that rabbit hole of "how many ways can we program the game engine?")

Currently, its possible to handle the different dialogs depending on events, etc, using MapEvents (defined in Tiled).

# doesn't have monster
act1 dialog "I wish I had something to eat,,,,"
cond1 not has_monster, txmn_fruitera

# has monster
act1 dialog "Hey that Fruitera looks good enough to eat!"
cond1 has_monster player, txmn_fruitera

# set condition
act1 set_variable quest_started, True

# react to condition
act1 dialog, "Have fun on your quest!"
cond1 variable_set quest_started, True

# react to condition
act1 dialog, "Go start the quest!"
cond1 variable_set quest_started, False

Using translations would just the the translated_dialog action (assuming they are correctly entered into the JSON DB). 

Sanglorian wrote

Finally, with monsters I'm wondering if the easiest way to do it is to allow monsters to be defined manually, but if details are omitted, for those details to be added procedurally.

I think that this is how it works right now.  If you create a monster with an event, it would be created using the stats in the JSON.  After that, you could modify the attributes as required for the game (maybe at some point you are given a weak monster, or missing a key technique?).  The game probably supports this currently, but there are some limitations right now that would make it impractical (for example, most actions rely on monsters being in a particular slot).

xirsoi wrote

A note on implementation: perhaps there could be an attribute to define an inheritance relationship with another NPC object? A fairly simple loop over attributes would allow the child object to add to and overwrite the template object. (Simple in concept, at least.)

Yeah, this could be a good way to handle it.


BTW, here is a sample NPC JSON definition that I have on my dev branch:

{
    "slug": "npc_maple",
    "name_trans": "npc_maple_name",
    "sprite_name": "maple",
    "monsters": [
        {
            "attack": 50,
            "defense": 7,
            "name": "Snowball",
            "special_attack": 9,
            "level": 5,
            "monster": "txmn_bamboon",
            "hp": 50,
            "speed": 7,
            "special_defense": 7,
            "exp_give_mod": 3,
            "exp_req_mod": 27
        }
    ]
}

A cool side effect of my work so far has been that the player's sprite is configurable through the JSON, and interchangeable with NPCs.....  So you can play the game as the Professor, or some other NPC.  =D

3cWNNax.png

Avatar

By ShadowApex 22 Jul 2017 17:44

Lead Developer · 366 comments
bitcraft wrote

I'm wondering if anyone would object to consolidating NPC data into JSON files.  For instance, when creating an NPC, you won't have to define their animations, because it will be available in the JSON files.

I think this is a great idea. My initial reasoning for the create_npc action was along the lines of what xirsoi was talking about with inheritance. Sometimes we might want to reuse NPC animations for random one off guys wandering around. I think simply including all the details in the JSON file would be much more elegant, and having some kind of inheritance would make it easy to make a bunch of simple NPCs.

Sanglorian wrote

Would the NPC JSON file also have dialogue?

I also agree with bitcraft that I don't think we should include dialog in the NPC objects. I'd prefer to not have to jump around to a bunch of different files for dialog, but it'd be nice to hear from other map creators. If most map creators feel it would be better for the workflow, I think we could consider it. In my experience though, it seems like it would be more painful to work with that way.

xirsoi wrote

A note on implementation: perhaps there could be an attribute to define an inheritance relationship with another NPC object? A fairly simple loop over attributes would allow the child object to add to and overwrite the template object. (Simple in concept, at least.)

I really like this idea. As I mentioned above, this could make it easier to just create one-off NPCs pretty quickly and easily. The only reservation I have about it is it adds extra complexity for map creators. They would have to understand the NPC inheritance system. As long as we make it an optional property, I think it wouldn't be too bad to include though.


Avatar

By bitcraft 31 Jul 2017 14:15

Champion · 123 comments

Thanks for the input.  I think it would be good then, to continue to use the create_npc snytax, to allow creating generic NPCs and small customization at runtime.   Adding the animations and other information to the JSON would be very useful for common sprites, like story line actors (professor, antagonists, etc).

Here's another thought:  Does anyone see any benefit to saving a NPC's state during the course of the game?

Avatar

By Sanglorian 1 Aug 2017 23:10

Champion · 407 comments
bitcraft wrote

Here's another thought:  Does anyone see any benefit to saving a NPC's state during the course of the game?

Would that include whether they've battled the protagonist (and lost)? That would certainly be worth saving. If it's just a question of whether their location would be saved, no I can't think of any.

Avatar

By Sanglorian 9 Aug 2017 12:44

Champion · 407 comments

Two other things I've thought of, that it'd be good to have for the consolidated NPCs/in the Trainer Class inheritance system:

1. Theme: The soundtrack currently has different tracks for different types of trainer.
2. Virus Susceptibility: A binary, because whether a trainer's tuxemon can catch Spyder Bite is a potential plot point.