Fix randomization of new state not working as intended
This commit is contained in:
parent
f96188e06a
commit
529fea79b3
@ -186,6 +186,9 @@ function mob_state.callback(entity,now,dstep)
|
||||
end
|
||||
end
|
||||
|
||||
dbg_mobf.mob_state_lvl2("MOBF: " .. entity.data.name .. " "
|
||||
.. dump(#state_table) .. " states do pass pecondition check ")
|
||||
|
||||
--try to get a random state to change to
|
||||
for i=1, #state_table, 1 do
|
||||
|
||||
@ -200,12 +203,22 @@ function mob_state.callback(entity,now,dstep)
|
||||
end
|
||||
end
|
||||
|
||||
if math.random() < current_chance then
|
||||
local random_value = math.random()
|
||||
|
||||
if random_value < current_chance then
|
||||
dbg_mobf.mob_state_lvl2("MOBF: " .. entity.data.name
|
||||
.. " switching to state " .. state_table[rand_state].name)
|
||||
mob_state.change_state(entity,state_table[rand_state])
|
||||
return true
|
||||
else
|
||||
dbg_mobf.mob_state_lvl2("MOBF: " .. entity.data.name
|
||||
.. " not switching to state " .. state_table[rand_state].name
|
||||
.. " rand was: " .. random_value)
|
||||
table.remove(state_table,rand_state)
|
||||
end
|
||||
end
|
||||
|
||||
dbg_mobf.mob_state_lvl2("MOBF: " .. entity.data.name
|
||||
.. " no specific state selected switching to default state ")
|
||||
--switch to default state (only reached if no change has been done
|
||||
mob_state.change_state(entity,mob_state.get_state_by_name(entity,"default"))
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user