Add Snus Dealer example vendor NPC
parent
3c8ebd8dcd
commit
a590aa9209
|
@ -3,6 +3,7 @@
|
|||
using Godot;
|
||||
using SupaLidlGame.Extensions;
|
||||
using SupaLidlGame.Items;
|
||||
using SupaLidlGame.Utils;
|
||||
using System;
|
||||
|
||||
namespace SupaLidlGame.Characters;
|
||||
|
@ -127,6 +128,37 @@ public partial class NPC : Character
|
|||
return bestChar;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the best character whose faction aligns with this character's.
|
||||
/// </summary>
|
||||
public virtual Character FindBestNeutral()
|
||||
{
|
||||
float bestScore = float.MaxValue;
|
||||
Character bestChar = null;
|
||||
// NOTE: this relies on all Characters being under the Entities node
|
||||
foreach (Node node in GetParent().GetChildren())
|
||||
{
|
||||
if (node is Character character)
|
||||
{
|
||||
bool isFriendly = ((IFaction)this).AlignsWith(character);
|
||||
if (isFriendly || character.Health <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float score = 0;
|
||||
score -= Position.DistanceTo(character.Position);
|
||||
|
||||
if (score < bestScore)
|
||||
{
|
||||
bestScore = score;
|
||||
bestChar = character;
|
||||
}
|
||||
}
|
||||
}
|
||||
return bestChar;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
ThinkerStateMachine.Process(delta);
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
[ext_resource type="Script" path="res://State/Character/CharacterStateMachine.cs" id="2_kynkg"]
|
||||
[ext_resource type="Texture2D" uid="uid://bej8thq7ruyty" path="res://Assets/Sprites/Characters/forsen2.png" id="2_s5nik"]
|
||||
[ext_resource type="Script" path="res://State/Character/NPCIdleState.cs" id="3_pcrll"]
|
||||
[ext_resource type="Script" path="res://State/Thinker/IdleState.cs" id="3_rgc42"]
|
||||
[ext_resource type="Script" path="res://State/Thinker/ThinkerStateMachine.cs" id="4_mo4wj"]
|
||||
[ext_resource type="Script" path="res://State/Thinker/VendorIdle.cs" id="5_oau5d"]
|
||||
[ext_resource type="PackedScene" uid="uid://dldnp8eunxj3q" path="res://BoundingBoxes/InteractionTrigger.tscn" id="5_sjs24"]
|
||||
[ext_resource type="Script" path="res://Utils/InteractionTriggerDialogue.cs" id="5_yknpw"]
|
||||
[ext_resource type="Resource" uid="uid://c4n7vhoxybu70" path="res://Dialogue/snus-dealer.dialogue" id="6_isvnq"]
|
||||
[ext_resource type="Script" path="res://Items/Inventory.cs" id="7_vip6b"]
|
||||
|
||||
[node name="Character" type="CharacterBody2D" node_paths=PackedStringArray("ThinkerStateMachine", "Sprite", "Inventory", "StateMachine")]
|
||||
[node name="SnusDealer" type="CharacterBody2D" node_paths=PackedStringArray("ThinkerStateMachine", "Sprite", "Inventory", "StateMachine")]
|
||||
script = ExtResource("1_04gcf")
|
||||
ThinkerStateMachine = NodePath("Thinker")
|
||||
Sprite = NodePath("Sprites/Sprite")
|
||||
|
@ -32,7 +32,7 @@ script = ExtResource("4_mo4wj")
|
|||
InitialState = NodePath("Idle")
|
||||
|
||||
[node name="Idle" type="Node" parent="Thinker" node_paths=PackedStringArray("NPC")]
|
||||
script = ExtResource("3_rgc42")
|
||||
script = ExtResource("5_oau5d")
|
||||
NPC = NodePath("../..")
|
||||
|
||||
[node name="Animations" type="Node" parent="."]
|
||||
|
@ -64,7 +64,7 @@ position = Vector2(0, -4)
|
|||
script = ExtResource("5_yknpw")
|
||||
InteractionTrigger = NodePath("InteractionTrigger")
|
||||
DialogueResource = ExtResource("6_isvnq")
|
||||
DialogueTitle = "shop"
|
||||
DialogueTitle = "start"
|
||||
|
||||
[node name="InteractionTrigger" parent="Interaction" instance=ExtResource("5_sjs24")]
|
||||
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
~ start
|
||||
|
||||
Snus Dealer: d
|
||||
|
||||
% => test
|
||||
% => dont_snus
|
||||
|
||||
=> END
|
||||
|
||||
~ test
|
||||
|
||||
Snus Dealer: asdadsadasd
|
||||
Snus Dealer: Hey kid, wanna buy some snus?
|
||||
- Alright. => shop
|
||||
- No, I don't think so. => END
|
||||
- Snus? => dont_snus
|
||||
|
||||
=> END
|
||||
|
||||
~ dont_snus
|
||||
|
||||
Snus Dealer: You know what they say.
|
||||
Snus Dealer: If you don't snus...
|
||||
Snus Dealer: you lose.
|
||||
- Pepepains
|
||||
|
||||
=> start
|
||||
|
||||
~ shop
|
||||
|
||||
do emit("EnterShop", "res://Items/Shops/SnusDealer.tres")
|
||||
|
||||
=> END
|
||||
|
||||
~ shop
|
|
@ -0,0 +1,17 @@
|
|||
using Godot;
|
||||
using GodotUtilities;
|
||||
|
||||
namespace SupaLidlGame.State.Thinker;
|
||||
|
||||
public partial class VendorIdle : ThinkerState
|
||||
{
|
||||
public override ThinkerState Think()
|
||||
{
|
||||
var bestNeutral = NPC.FindBestNeutral();
|
||||
if (bestNeutral is not null)
|
||||
{
|
||||
NPC.Target = bestNeutral.Position - NPC.Position;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue