otherworldly_simulation/scene/test/condition_attack.gd

21 lines
591 B
GDScript3
Raw Permalink Normal View History

2024-10-25 15:41:39 +08:00
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:
2024-10-25 17:45:08 +08:00
if i is Unit and i !=unit:
2024-10-28 19:24:10 +08:00
var favour=Global.get_unit_favour(unit.get_unit_id(),i.get_unit_id())
2024-10-25 15:41:39 +08:00
var res=get_res(favour,unit.get_hungry())
if res:
2024-10-28 19:24:10 +08:00
black_board.set_value("target_unit_id",i.get_unit_id())
2024-10-25 15:41:39 +08:00
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