otherworldly_simulation/scene/test/condition_attack.gd
2024-10-28 19:24:10 +08:00

21 lines
591 B
GDScript

extends ConditionLeaf
func tick(actor:Node,black_board:Blackboard):
var unit:UnitOther=actor
var all_bodys=unit.sense_area.get_overlapping_bodies()
for i in all_bodys:
if i is Unit and i !=unit:
var favour=Global.get_unit_favour(unit.get_unit_id(),i.get_unit_id())
var res=get_res(favour,unit.get_hungry())
if res:
black_board.set_value("target_unit_id",i.get_unit_id())
return SUCCESS
return FAILURE
pass
#返回true攻击判定成功
func get_res(favour:float,hungry:float=0)->bool:
if favour>-50:
return false
else:
return randf()<=(-favour/100)-hungry/300