There are different methods. The Finite State Machine and the Goal Oriented Descision Making like in IntenseX
Finite State Machine.
if(see_enemy)
{
my.state = attack;
}
if(see_atombomb)
{
my.state = run_away;
}
if(my.state == attack)
{
do something...
}
if(my.state == run_away)
{
do something...
}
Goal Oriented Descision Making
my.guard_value = 20;
my.attack_value = 0;
my.run_away_value = 0;
if(see_enemy)
{
my.attack_value += 60;
}
if(enemy.health > my.health)
{
my.attack_value -= 20;
my.run_away_value += 20;
}
if(enemy.type == atom_bomb)
{
my.attack_value -= 50;
my.run_away_value += 80;
}
my.goal = guard_goal;
if(my.attack_value > my.guard_value || my.attack_value > my.run_away_value)
{
my.goal = attack_goal;
}
if(my.run_away_value > my.guard_value || my.run_away_value > my.attack_value)
{
my.goal = run_away_goal;
}
if(my.goal = guad_goal)
{
...
}
....and so on
The second one is better, more human, cause as you can see the values are influenced by many things and so there could be more different action that the npc is going to do. With Finite State Machine the npc is always doing the same, but with GOAP the npc could react in another way then before in the same situation. I hope you understood the examples. The code is not optimized

. For example the finding of the highest value could be in a loop or something like this!