[Request] npc AI and trait related improvement
詳細 Details
Here are two thoughts that could make npc with more interesting feature in the game
- Npc can not have traits as the player does. npc ican have different skills defined in ability.lua, but they can not have something like "always ignore 30% pv", "healing from cold damage" or "+20% crit rate" as a unique "feat" like the player character, since the latter is stored in vector trait which only serves player.
- Npc actions are dumb and does not know "how to use a skill". For example, shadow_step or draw_shadow should be used if target enemy is not next to the npc but not used when the target is already near. healing_rain should be used when hp is low for any of the party members.
Solution:
Add two vector to store trait and "action on condition", respectively, for npc. I imagine them like this:
in chara.lua:
npc = {
...
trait = {trait1,trait2,trait3}
act_on_condition = {{act1,condition1,condition1_parameter},{act2, condition2,condition2_parameter}}
...
}
They are stored and serialized in charater.hpp as well, of course.
For traits, add code in the area that the trait affects. This may involve messing with different part of the source file though, depending on what the trait does.
For npc actions, add corresponding function to judge the condition for activating an act, maybe function ai_proc_basic in ai.cpp would be a suitable place to add.
It might also be necessary to add menus that could show these traits and actions.
この機能を持つヴァリアント Variants having the feature
For traits, I have not seen or noticed any variants with the feature. Race-based or id-based logic are used for a similar purpose, but I think they are not flexible. For npc actions: In elona plus, player can change npc actions,but only certain actions can be excuted in certain conditions and these are very limited. Some npc can act well with specific act, for example, draw_shadow when not adjacent to a foe, but I find out these are race related, which is not flexible. Omake Overhaul Custom and elona plus custom has Ai customization but I never played them and am not sure how they works. Judging from the description, the logic should be similiar to the description above.
Traits
I am working on save data restructuring now, including the change you wrote. Trait table will be merged to Character and will be available for NPCs in the next release.
Working branch (in progress): https://github.com/ki-foobar/elonafoobar/tree/feature/save-restructure
FYI, omake overhaul and its variants has "faction" system, as extension of traits. All NPCs can have their own traits in the variant.
AI
It would be better to define these conditions in actions, not in characters because a suitable condition to perform a certain action is always the same (or very similar).
For the AI I still think it is necessary to make the action character-specific somehow. For example, letting a "melee" character use healing magic only when self hp<10% and while a "tank" do the same when self hp>50%. It might be more straightforward to store these parameters in character if they do vary from each character.