Reworked the AI Objectives

This commit is contained in:
Patrick_Pluto 2024-12-13 18:28:06 +01:00
parent 27964084ff
commit a6c9909f26
8 changed files with 31 additions and 11 deletions

View file

@ -24,3 +24,9 @@ avoidance_enabled = true
height = 2.0 height = 2.0
[node name="Timer" type="Timer" parent="."] [node name="Timer" type="Timer" parent="."]
[node name="Label3D" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.25, 0)
pixel_size = 0.01
billboard = 1
no_depth_test = true

View file

@ -21,3 +21,10 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
[node name="Label" type="Label" parent="."] [node name="Label" type="Label" parent="."]
offset_right = 40.0 offset_right = 40.0
offset_bottom = 23.0 offset_bottom = 23.0
[node name="Label3D" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.25, 0)
pixel_size = 0.01
billboard = 1
no_depth_test = true
text = "SamplePlayer"

View file

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://bn60ywtwfn7bq"] [gd_scene load_steps=2 format=3 uid="uid://bn60ywtwfn7bq"]
[ext_resource type="Script" path="res://scripts/maps/rest.gd" id="1_m76x3"] [ext_resource type="Script" path="res://scripts/maps/objectives/objective.gd" id="1_m76x3"]
[node name="Rest" type="Node3D"] [node name="Rest" type="Node3D"]
script = ExtResource("1_m76x3") script = ExtResource("1_m76x3")

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=9 format=3 uid="uid://cbyee7drds7qu"] [gd_scene load_steps=9 format=3 uid="uid://cbyee7drds7qu"]
[ext_resource type="Script" path="res://scripts/maps/map.gd" id="1_4npcs"] [ext_resource type="Script" path="res://scripts/maps/map.gd" id="1_4npcs"]
[ext_resource type="Script" path="res://scripts/maps/rest.gd" id="2_yv1d0"] [ext_resource type="Script" path="res://scripts/maps/objectives/objective.gd" id="2_yv1d0"]
[ext_resource type="PackedScene" uid="uid://bsghm187n6ykx" path="res://scenes/objects/closet.tscn" id="2_yvpvm"] [ext_resource type="PackedScene" uid="uid://bsghm187n6ykx" path="res://scenes/objects/closet.tscn" id="2_yvpvm"]
[ext_resource type="PackedScene" uid="uid://cvnjpnvchvakj" path="res://scenes/entities/npc.tscn" id="3_x3gyc"] [ext_resource type="PackedScene" uid="uid://cvnjpnvchvakj" path="res://scenes/entities/npc.tscn" id="3_x3gyc"]
@ -23,7 +23,6 @@ script = ExtResource("1_4npcs")
[node name="PlayerSpawn" type="Node3D" parent="."] [node name="PlayerSpawn" type="Node3D" parent="."]
[node name="0" type="Node3D" parent="PlayerSpawn"] [node name="0" type="Node3D" parent="PlayerSpawn"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -17, 3, 0)
[node name="1" type="Node3D" parent="PlayerSpawn"] [node name="1" type="Node3D" parent="PlayerSpawn"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 16, 4, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 16, 4, 0)
@ -55,7 +54,7 @@ environment = SubResource("Environment_pq0iv")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2, 10, 2) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2, 10, 2)
[node name="Npc1" parent="." instance=ExtResource("3_x3gyc")] [node name="Npc1" parent="." instance=ExtResource("3_x3gyc")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 40, 20, 40) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 25, 6, -33)
[node name="NavigationRegion3D" type="NavigationRegion3D" parent="."] [node name="NavigationRegion3D" type="NavigationRegion3D" parent="."]
navigation_mesh = SubResource("NavigationMesh_hqhxb") navigation_mesh = SubResource("NavigationMesh_hqhxb")

View file

@ -28,7 +28,10 @@ func _ready() -> void:
func _timer_done() -> void: func _timer_done() -> void:
if angry_meter > 0: if angry_meter > 0:
angry_meter -= 1 angry_meter -= 1
if target is Objective:
($Label3D as Label3D).text = "%s %ds left" % [(target as Objective).displayed, angry_meter]
else: else:
($Label3D as Label3D).text = ""
timer.stop() timer.stop()
phase = 2 phase = 2
find_player(99999999999999) find_player(99999999999999)
@ -37,7 +40,7 @@ func _timer_done() -> void:
func find_rest() -> void: func find_rest() -> void:
var lowest_distance: float = 99999999999999 var lowest_distance: float = 99999999999999
for child: Node in get_tree().root.get_node("/root/"+Game.mapname+"/NPCRestPlaces").get_children(): for child: Node in get_tree().root.get_node("/root/"+Game.mapname+"/NPCRestPlaces").get_children():
if child is Rest and position.distance_to((child as Rest).position) < lowest_distance and !(child as Rest).occupied: if child is Objective and position.distance_to((child as Objective).position) < lowest_distance and !(child as Objective).occupied:
target = child target = child
navigation_agent.set_target_position(target.position) navigation_agent.set_target_position(target.position)
@ -59,8 +62,8 @@ func _physics_process(_delta: float) -> void:
if navigation_agent.is_navigation_finished(): if navigation_agent.is_navigation_finished():
if phase == 0: if phase == 0:
if target is Rest: if target is Objective:
(target as Rest).occupied = false (target as Objective).occupied = false
phase = 1 phase = 1
timer.start() timer.start()
return return
@ -74,5 +77,3 @@ func _physics_process(_delta: float) -> void:
pass pass
Networking.npc_sync_call(position, rotation, name) Networking.npc_sync_call(position, rotation, name)

View file

@ -15,11 +15,12 @@ var freecam: bool = false
var camera_rotation: Vector2 = Vector2(0,0) var camera_rotation: Vector2 = Vector2(0,0)
func _ready() -> void: func _ready() -> void:
($Label3D as Label3D).text = name
if name == Game.username: if name == Game.username:
activated = true activated = true
camera.current = true camera.current = true
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
($Label3D as Label3D).hide()
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
if activated: if activated:

View file

@ -0,0 +1,5 @@
class_name Hungry
extends Objective
func _ready() -> void:
displayed = "Hungry"

View file

@ -1,7 +1,8 @@
## SPDX-License-Identifier: GPL-3.0-or-later ## SPDX-License-Identifier: GPL-3.0-or-later
## Copyright (c) 2024 interstellardevelopment.org ## Copyright (c) 2024 interstellardevelopment.org
class_name Rest class_name Objective
extends Node3D extends Node3D
var occupied: bool = false var occupied: bool = false
var displayed: String