Refactoring crap
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
class_name Recipe extends Node
|
||||
|
||||
enum Type {
|
||||
BAKED_SWEET_POTATO,
|
||||
}
|
||||
|
||||
@export_multiline var title:String = ""
|
||||
@export var type:Type = Type.BAKED_SWEET_POTATO
|
||||
@export var ingredients:Array[ItemResource] = []
|
||||
@export var outputs:Array[ItemResource] = []
|
||||
|
||||
var learned:bool = false
|
||||
var timesMade:int = 0
|
||||
|
||||
func hasIngredients(inventory:Inventory = null) -> bool:
|
||||
if inventory == null:
|
||||
inventory = ITEM.PLAYER_INVENTORY
|
||||
|
||||
for ingredient in ingredients:
|
||||
if !inventory.hasItem(ingredient.type, ingredient.quantity):
|
||||
return false
|
||||
return true
|
||||
|
||||
func make(inventory:Inventory = null) -> void:
|
||||
if inventory == null:
|
||||
inventory = ITEM.PLAYER_INVENTORY
|
||||
|
||||
for ingredient in ingredients:
|
||||
inventory.removeItem(ingredient.type, ingredient.quantity)
|
||||
|
||||
for output in outputs:
|
||||
inventory.addItem(output.type, output.quantity)
|
||||
|
||||
timesMade += 1
|
||||
|
||||
func getTransContext() -> TransContext:
|
||||
var ctx = TransContext.new()
|
||||
ctx.addTrans("title", title)
|
||||
return ctx
|
@@ -1 +0,0 @@
|
||||
uid://dipvg4uwjv6p2
|
@@ -1 +0,0 @@
|
||||
uid://cy01crjsvohfc
|
@@ -1,22 +0,0 @@
|
||||
class_name BasicNPCEntity extends CharacterBody3D
|
||||
|
||||
@export var interactEvent:Event = null
|
||||
|
||||
func _ready() -> void:
|
||||
$Entity/EntityInteractable.onInteract.connect(
|
||||
self.onEntityInteract
|
||||
)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
$Entity/EntityInteractable.onInteract.disconnect(
|
||||
self.onEntityInteract
|
||||
)
|
||||
|
||||
func onEntityInteract(
|
||||
interactor:EntityInteractor,
|
||||
interactee:EntityInteractable
|
||||
) -> void:
|
||||
if interactEvent == null || (interactEvent.started && !interactEvent.isDone()):
|
||||
return
|
||||
|
||||
interactEvent.onEntityInteract(interactor, $Entity/EntityInteractable)
|
@@ -1 +0,0 @@
|
||||
uid://d23qg1ovkbxst
|
@@ -1,83 +0,0 @@
|
||||
@tool
|
||||
class_name EntityDirection extends Node
|
||||
|
||||
enum Direction {
|
||||
SOUTH,
|
||||
WEST,
|
||||
NORTH,
|
||||
EAST,
|
||||
}
|
||||
|
||||
@export var meshInstance:MeshInstance3D = null:
|
||||
set(newInstance):
|
||||
meshInstance = newInstance;
|
||||
_updateMaterial();
|
||||
|
||||
@export var direction = Direction.SOUTH:
|
||||
set(newDirection):
|
||||
direction = newDirection;
|
||||
_updateMaterial();
|
||||
|
||||
@export var characterBody:CharacterBody3D = null
|
||||
|
||||
func _ready() -> void:
|
||||
_updateMaterial();
|
||||
|
||||
func _updateMaterial() -> void:
|
||||
if !meshInstance:
|
||||
return
|
||||
|
||||
for i in range(meshInstance.get_surface_override_material_count()):
|
||||
var material:ShaderMaterial = meshInstance.get_surface_override_material(i)
|
||||
if !material:
|
||||
continue
|
||||
material.set_shader_parameter("direction", direction)
|
||||
|
||||
func getDirectionVector() -> Vector3:
|
||||
match direction:
|
||||
Direction.NORTH:
|
||||
return Vector3(0, 0, -1);
|
||||
Direction.SOUTH:
|
||||
return Vector3(0, 0, 1);
|
||||
Direction.WEST:
|
||||
return Vector3(-1, 0, 0);
|
||||
Direction.EAST:
|
||||
return Vector3(1, 0, 0);
|
||||
_:
|
||||
assert(false, "Invalid direction");
|
||||
return Vector3(0, 0, 0);
|
||||
|
||||
func updateDirectionFromMovement(movement:Vector2) -> void:
|
||||
if movement.x >= abs(movement.y) and(
|
||||
movement.y == 0 or
|
||||
(movement.y > 0 and direction != Direction.SOUTH) or
|
||||
(movement.y < 0 and direction != Direction.NORTH)
|
||||
):
|
||||
direction = Direction.EAST;
|
||||
elif (movement.x <= -abs(movement.y) and (
|
||||
movement.y == 0 or
|
||||
(movement.y > 0 and direction != Direction.SOUTH) or
|
||||
(movement.y < 0 and direction != Direction.NORTH)
|
||||
)):
|
||||
direction = Direction.WEST;
|
||||
elif (movement.y > 0):
|
||||
direction = Direction.SOUTH;
|
||||
elif (movement.y < 0):
|
||||
direction = Direction.NORTH;
|
||||
|
||||
func getDirectionToFace(position:Vector3) -> Direction:
|
||||
if !characterBody:
|
||||
return Direction.SOUTH;
|
||||
|
||||
var diff = position - characterBody.global_position;
|
||||
if abs(diff.x) > abs(diff.z):
|
||||
if diff.x > 0:
|
||||
return Direction.EAST;
|
||||
else:
|
||||
return Direction.WEST;
|
||||
else:
|
||||
if diff.z > 0:
|
||||
return Direction.SOUTH;
|
||||
else:
|
||||
return Direction.NORTH;
|
||||
return Direction.SOUTH;
|
@@ -1 +0,0 @@
|
||||
uid://cjfcpi7sxentf
|
@@ -1,10 +0,0 @@
|
||||
class_name EntityInteractable extends Node
|
||||
|
||||
@export var entityDirection:EntityDirection = null
|
||||
@export var entity:Entity = null
|
||||
@export var characterBody:CharacterBody3D = null;
|
||||
|
||||
signal onInteract(interactor:EntityInteractor, interactable:EntityInteractable)
|
||||
|
||||
func interact(interactor:EntityInteractor) -> void:
|
||||
onInteract.emit(interactor, self)
|
@@ -1 +0,0 @@
|
||||
uid://03dqknw7v4mr
|
@@ -1,65 +0,0 @@
|
||||
class_name EntityInteractor extends Node
|
||||
|
||||
enum InteractorType {
|
||||
PLAYER_INPUT,
|
||||
UNDECIDED
|
||||
}
|
||||
|
||||
@export var interactorType:InteractorType = InteractorType.UNDECIDED;
|
||||
@export var entityDirection:EntityDirection = null;
|
||||
@export var characterBody:CharacterBody3D = null;
|
||||
@export var interactRange = 0.7;
|
||||
@export var entity:Entity = null
|
||||
@export_flags_3d_physics() var interactLayers = 2;
|
||||
|
||||
func interactWith(interactable:EntityInteractable) -> void:
|
||||
interactable.interact(self)
|
||||
|
||||
func getRaycastInteractable() -> EntityInteractable:
|
||||
if !entityDirection or !characterBody:
|
||||
return null
|
||||
|
||||
var rayDirection = entityDirection.getDirectionVector()
|
||||
var query = PhysicsRayQueryParameters3D.create(
|
||||
characterBody.global_position,
|
||||
characterBody.global_position + (rayDirection * interactRange)
|
||||
)
|
||||
query.collide_with_bodies = true;
|
||||
query.collide_with_areas = true;
|
||||
query.collision_mask = interactLayers;
|
||||
query.exclude = [ characterBody ];
|
||||
|
||||
var result = characterBody.get_world_3d().direct_space_state.intersect_ray(query)
|
||||
if !result or !result.collider:
|
||||
return null
|
||||
|
||||
var coll:Node3D = result.collider;
|
||||
var interactable:EntityInteractable = coll.find_child("EntityInteractable")
|
||||
return interactable
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if !entity or entity.isPaused():
|
||||
return
|
||||
|
||||
match interactorType:
|
||||
InteractorType.PLAYER_INPUT:
|
||||
_processPlayerInput()
|
||||
InteractorType.UNDECIDED:
|
||||
_processUndecided()
|
||||
_:
|
||||
assert(false, "Invalid interactor type")
|
||||
|
||||
func _processPlayerInput() -> void:
|
||||
if !Input.is_action_just_pressed("interact"):
|
||||
return
|
||||
|
||||
# Conditions where player cannot interact.
|
||||
if UI.hasInteractionFocus():
|
||||
return
|
||||
|
||||
var interactable:EntityInteractable = getRaycastInteractable()
|
||||
if interactable:
|
||||
self.interactWith(interactable)
|
||||
|
||||
func _processUndecided() -> void:
|
||||
pass
|
@@ -1 +0,0 @@
|
||||
uid://dfh2rh8idx267
|
@@ -1,77 +0,0 @@
|
||||
class_name EntityMovement extends Node
|
||||
|
||||
enum MovementType {
|
||||
PLAYER_INPUT,
|
||||
STILL,
|
||||
NPC_RANDOM_LOOK
|
||||
};
|
||||
|
||||
@export var characterBody:CharacterBody3D = null;
|
||||
@export var entity:Entity = null;
|
||||
@export var entityDirection:EntityDirection = null;
|
||||
|
||||
@export var speed:float = 200;
|
||||
@export var runSpeed:float = 400;
|
||||
@export var friction:float = 8.5;
|
||||
@export var gravity:float = 30;
|
||||
|
||||
@export var movementType:MovementType = MovementType.STILL;
|
||||
|
||||
@export var randomLookMinTime:float = 1.5;
|
||||
@export var randomLookMaxTime:float = 4.0;
|
||||
var randomLookTimer:float = 0.0;
|
||||
|
||||
func _physics_process(delta:float) -> void:
|
||||
if !entity || entity.isPaused() || !characterBody:
|
||||
return;
|
||||
|
||||
# Update movement
|
||||
_updateVelocity(delta)
|
||||
|
||||
# Gravity and friction
|
||||
if !characterBody.is_on_floor():
|
||||
characterBody.velocity.y -= gravity * delta;
|
||||
else:
|
||||
characterBody.velocity += -(characterBody.velocity * friction * delta);
|
||||
# if velocity.length() != 0:
|
||||
# _updateTileData();
|
||||
|
||||
# Update character controller.
|
||||
characterBody.move_and_slide();
|
||||
|
||||
func _updateVelocity(delta:float):
|
||||
match movementType:
|
||||
MovementType.PLAYER_INPUT:
|
||||
_updatePlayerInput(delta);
|
||||
MovementType.STILL:
|
||||
_updateStill(delta);
|
||||
MovementType.NPC_RANDOM_LOOK:
|
||||
_updateNPCRandomLook(delta);
|
||||
|
||||
func _updatePlayerInput(delta:float) -> void:
|
||||
var dir:Vector2 = Input.get_vector("left", "right", "up", "down");
|
||||
|
||||
var moveSpeed:float;
|
||||
if Input.is_action_pressed("run"):
|
||||
moveSpeed = runSpeed;
|
||||
else:
|
||||
moveSpeed = speed;
|
||||
|
||||
if dir.x != 0 or dir.y != 0:
|
||||
characterBody.velocity.x = dir.x * moveSpeed * delta;
|
||||
characterBody.velocity.z = dir.y * moveSpeed * delta;
|
||||
|
||||
if entityDirection:
|
||||
entityDirection.updateDirectionFromMovement(dir);
|
||||
|
||||
func _updateStill(delta:float):
|
||||
pass
|
||||
|
||||
func _updateNPCRandomLook(delta:float):
|
||||
if !entityDirection:
|
||||
return
|
||||
randomLookTimer -= delta;
|
||||
|
||||
if randomLookTimer <= 0:
|
||||
randomLookTimer = randf_range(randomLookMinTime, randomLookMaxTime);
|
||||
entityDirection.direction = randi_range(0, 3);
|
@@ -1 +0,0 @@
|
||||
uid://c5nfs0m6ua4eb
|
@@ -1 +0,0 @@
|
||||
uid://dp6itsmbl0ucn
|
@@ -1,88 +0,0 @@
|
||||
class_name Entity extends Node
|
||||
|
||||
# var meshInstance:MeshInstance3D;
|
||||
# var underFootTile:int = -1;
|
||||
# var underFootPosition:Vector3;
|
||||
# var material:ShaderMaterial;
|
||||
|
||||
# func updateMaterial() -> bool:
|
||||
# if !meshInstance:
|
||||
# return false
|
||||
# if !material:
|
||||
# return false
|
||||
# return true
|
||||
|
||||
# # Virtual Methods
|
||||
# func updateMovement(delta) -> void:
|
||||
# pass
|
||||
|
||||
# func updateOverworldLogic(delta) -> void:
|
||||
# pass
|
||||
|
||||
func isPaused() -> bool:
|
||||
var ps = PAUSE.getPauseState();
|
||||
match ps:
|
||||
PauseSystem.PauseType.NOT_PAUSED:
|
||||
return false;
|
||||
PauseSystem.PauseType.FULLY_PAUSED:
|
||||
return true;
|
||||
PauseSystem.PauseType.ENTITY_PAUSED:
|
||||
if PAUSE.entities.find(self) != -1:
|
||||
return true;
|
||||
return false;
|
||||
PauseSystem.PauseType.CUTSCENE_PAUSED:
|
||||
if PAUSE.entities.find(self) != -1:
|
||||
return false;
|
||||
return true;
|
||||
_:
|
||||
assert(false, "Invalid pause state");
|
||||
|
||||
return false;
|
||||
|
||||
# Private methods
|
||||
# func _updateTileData() -> void:
|
||||
# # ray cast down
|
||||
# var offset = Vector3(0, 0, 0.426);
|
||||
# var query = PhysicsRayQueryParameters3D.create(
|
||||
# position + offset,
|
||||
# position + Vector3(0, -1, 0) + offset
|
||||
# )
|
||||
# query.collide_with_areas = true
|
||||
# query.exclude = [self]
|
||||
|
||||
# var result = get_world_3d().direct_space_state.intersect_ray(query)
|
||||
# if !result or !result.collider:
|
||||
# return;
|
||||
|
||||
# var collider = result.collider;
|
||||
# var colliderMesh = collider.get_node("../");
|
||||
# if !colliderMesh or !(colliderMesh is ArrayMesh) or !colliderMesh.mesh or colliderMesh.mesh.get_surface_count() == 0:
|
||||
# return;
|
||||
|
||||
# # Get the face index (triangle)
|
||||
# var arrays = colliderMesh.mesh.surface_get_arrays(0);
|
||||
# var indiceIdx = result.face_index * 3;
|
||||
|
||||
# # Get each indice of the triangle
|
||||
# var index0 = arrays[Mesh.ARRAY_INDEX][indiceIdx+0];
|
||||
# var index1 = arrays[Mesh.ARRAY_INDEX][indiceIdx+1];
|
||||
# var index2 = arrays[Mesh.ARRAY_INDEX][indiceIdx+2];
|
||||
|
||||
# # Get each uv of each indice
|
||||
# var uv0:Vector2 = arrays[Mesh.ARRAY_TEX_UV][index0];
|
||||
# var uv1:Vector2 = arrays[Mesh.ARRAY_TEX_UV][index1];
|
||||
# var uv2:Vector2 = arrays[Mesh.ARRAY_TEX_UV][index2];
|
||||
|
||||
# # Determine the lowest texture coordinate
|
||||
# var min = Vector2(min(uv0.x, uv1.x, uv2.x), min(uv0.y, uv1.y, uv2.y));
|
||||
|
||||
# # Convert to column/row
|
||||
# var w = 256;
|
||||
# var h = w;
|
||||
# var tw = 48;
|
||||
# var th = tw;
|
||||
# var column = int(roundf(min.x * w)) / tw;
|
||||
# var row = int(roundf(min.y * h)) / th;
|
||||
# var columns = 768 / tw;
|
||||
# underFootPosition = result.position;
|
||||
# underFootTile = column % columns + row * columns;
|
@@ -1 +0,0 @@
|
||||
uid://dtjjqp2atjyhr
|
@@ -1,30 +0,0 @@
|
||||
class_name ItemOnGround extends StaticBody3D
|
||||
|
||||
enum Type {
|
||||
SPAWNS_WITH_MAP,
|
||||
AQUIRED_ONCE
|
||||
}
|
||||
|
||||
@export var itemType:Item.Type = Item.Type.POTION;
|
||||
@export var quantity:int = 1;
|
||||
|
||||
func _ready() -> void:
|
||||
$Entity/EntityInteractable.onInteract.connect(
|
||||
self.onEntityInteract
|
||||
)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
$Entity/EntityInteractable.onInteract.disconnect(
|
||||
self.onEntityInteract
|
||||
)
|
||||
|
||||
func onEntityInteract(
|
||||
interactor:EntityInteractor,
|
||||
interactee:EntityInteractable
|
||||
) -> void:
|
||||
var event = EventGetItem.new()
|
||||
event.itemType = itemType;
|
||||
event.quantity = quantity;
|
||||
event.removeNode = self
|
||||
EVENT.addEvent(event)
|
||||
event.onEntityInteract(interactor, interactee)
|
@@ -1 +0,0 @@
|
||||
uid://d2jqsiapy07ii
|
@@ -1 +0,0 @@
|
||||
uid://bcei5b2x3gu8y
|
@@ -1 +0,0 @@
|
||||
uid://0nn3ix2nwk3f
|
@@ -1 +0,0 @@
|
||||
uid://bpwbaptqu4bm5
|
@@ -1 +0,0 @@
|
||||
class_name Rosa extends CharacterBody3D
|
@@ -1 +0,0 @@
|
||||
uid://ixwikdguyhf0
|
@@ -1,29 +0,0 @@
|
||||
extends Camera3D
|
||||
|
||||
@export var pixelScale:float = 1.0;
|
||||
@export var follow:Node3D;
|
||||
|
||||
const WORLD_UNITS:float = 32.0;
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
# I tried a few things but this is most consistent for both backbuffer and
|
||||
# framebuffer viewports.
|
||||
var viewportHeight = get_viewport().get_visible_rect().size.y;
|
||||
var unitScale = pixelScale * WORLD_UNITS;
|
||||
|
||||
var z:float = (
|
||||
tan((deg_to_rad(180) - deg_to_rad(fov)) / 2.0) *
|
||||
(viewportHeight / 2.0)
|
||||
) / unitScale;
|
||||
|
||||
var look = follow.global_position;
|
||||
var position = Vector3(0, 0, 2) + look;
|
||||
|
||||
look_at_from_position(
|
||||
Vector3(position.x, position.y + z, position.z),
|
||||
look
|
||||
);
|
@@ -1 +0,0 @@
|
||||
uid://jd50n00bo05y
|
@@ -1,22 +0,0 @@
|
||||
class_name Sign extends StaticBody3D
|
||||
|
||||
@export var interactEvent:Event = null
|
||||
|
||||
func _ready() -> void:
|
||||
$Entity/EntityInteractable.onInteract.connect(
|
||||
self.onEntityInteract
|
||||
)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
$Entity/EntityInteractable.onInteract.disconnect(
|
||||
self.onEntityInteract
|
||||
)
|
||||
|
||||
func onEntityInteract(
|
||||
interactor:EntityInteractor,
|
||||
interactee:EntityInteractable
|
||||
) -> void:
|
||||
if interactEvent == null || (interactEvent.started && !interactEvent.isDone()):
|
||||
return
|
||||
|
||||
interactEvent.onEntityInteract(interactor, $Entity/EntityInteractable)
|
@@ -1 +0,0 @@
|
||||
uid://bitykguiignfu
|
@@ -1,34 +0,0 @@
|
||||
class_name EventIf extends "res://scripts/Event/Flow/EventGroup.gd"
|
||||
|
||||
signal eventConditionMet
|
||||
|
||||
func ifCondition() -> bool:
|
||||
return false
|
||||
|
||||
func subscribeEvents() -> void:
|
||||
# Override this method to subscribe to any events needed for the condition check
|
||||
pass
|
||||
|
||||
func unsubscribeEvents() -> void:
|
||||
# Override this method to unsubscribe from any events when the condition is no longer needed
|
||||
pass
|
||||
|
||||
func shouldAutoStart() -> bool:
|
||||
return false
|
||||
|
||||
func start() -> void:
|
||||
super.start()
|
||||
|
||||
if ifCondition():
|
||||
startEventGroup()
|
||||
|
||||
func onEventTrigger() -> void:
|
||||
if !ifCondition():
|
||||
return
|
||||
eventConditionMet.emit()
|
||||
|
||||
func onTriggerListening(_trigger:EventTrigger) -> void:
|
||||
subscribeEvents()
|
||||
|
||||
func onTriggerNotListening(_trigger:EventTrigger) -> void:
|
||||
unsubscribeEvents()
|
@@ -1 +0,0 @@
|
||||
uid://bn2nw17cf11wp
|
@@ -1,58 +0,0 @@
|
||||
class_name EventIfFlag extends "res://scripts/Event/Condition/EventIf.gd"
|
||||
|
||||
enum Type {
|
||||
ANY_OF_FLAGS_ON,
|
||||
ALL_OF_FLAGS_ON,
|
||||
ANY_OF_FLAGS_OFF,
|
||||
ALL_OF_FLAGS_OFF,
|
||||
}
|
||||
|
||||
@export var event:EventSystem.SpecialEvent;
|
||||
@export var type:Type = Type.ANY_OF_FLAGS_ON;
|
||||
@export_flags(
|
||||
"1:1",
|
||||
"2:2",
|
||||
"3:4",
|
||||
"4:8",
|
||||
"5:16",
|
||||
"6:32",
|
||||
"7:64",
|
||||
"8:128",
|
||||
"9:256",
|
||||
"10:512",
|
||||
"11:1024",
|
||||
"12:2048",
|
||||
"13:4096",
|
||||
"14:8192",
|
||||
"15:16384",
|
||||
"16:32768",
|
||||
"17:65536",
|
||||
"18:131072",
|
||||
"19:262144",
|
||||
"20:524288",
|
||||
"21:1048576",
|
||||
"22:2097152",
|
||||
"23:4194304",
|
||||
"24:8388608",
|
||||
"25:16777216",
|
||||
"26:33554432",
|
||||
"27:67108864",
|
||||
"28:134217728",
|
||||
"29:268435456",
|
||||
"30:536870912",
|
||||
"31:1073741824",
|
||||
"32:2147483648"
|
||||
)
|
||||
var eventFlag:int = 0;
|
||||
|
||||
func ifCondition() -> bool:
|
||||
match type:
|
||||
Type.ANY_OF_FLAGS_ON:
|
||||
return EVENT.eventIsAnyOfFlagsOn(event, eventFlag)
|
||||
Type.ALL_OF_FLAGS_ON:
|
||||
return EVENT.eventAreFlagsOn(event, eventFlag)
|
||||
Type.ANY_OF_FLAGS_OFF:
|
||||
return EVENT.eventIsAnyOfFlagsOff(event, eventFlag)
|
||||
Type.ALL_OF_FLAGS_OFF:
|
||||
return EVENT.eventAreFlagsOff(event, eventFlag)
|
||||
return false
|
@@ -1 +0,0 @@
|
||||
uid://ccujhcc446mvh
|
@@ -1 +0,0 @@
|
||||
uid://dwcd277pv3p1t
|
@@ -1 +0,0 @@
|
||||
uid://cvrib7pjlip8g
|
@@ -1,9 +0,0 @@
|
||||
class_name EventEntityTurn extends "res://scripts/Event/Event.gd"
|
||||
|
||||
@export var entity:EntityDirection = null
|
||||
@export var direction:EntityDirection.Direction = EntityDirection.Direction.SOUTH
|
||||
|
||||
func start():
|
||||
if entity == null:
|
||||
return
|
||||
entity.direction = direction
|
@@ -1 +0,0 @@
|
||||
uid://bmcrd2ugqan43
|
@@ -1,62 +0,0 @@
|
||||
class_name Event extends Node
|
||||
|
||||
const Entity = preload("res://scripts/Entity/Entity.gd");
|
||||
|
||||
var inEventSystemTree:bool = false;
|
||||
var started:bool = false;
|
||||
var ended:bool = false;
|
||||
var interactor:EntityInteractor = null
|
||||
var interactee:EntityInteractable = null
|
||||
|
||||
signal eventEnded()
|
||||
|
||||
# Godot Methods
|
||||
func _process(delta: float) -> void:
|
||||
if !started || ended:
|
||||
return
|
||||
self.update(delta)
|
||||
|
||||
if self.isDone():
|
||||
self.end()
|
||||
|
||||
# Event methods (cleaned up)
|
||||
func start() -> void:
|
||||
assert(
|
||||
self.is_inside_tree(),
|
||||
"Event is trying to start but the node is not part of the scene tree. "+
|
||||
"Refer to EventSystem.addEvent"
|
||||
)
|
||||
assert(started == false)
|
||||
started = true
|
||||
|
||||
func update(_delta:float) -> void:
|
||||
assert(started == true)
|
||||
assert(ended == false)
|
||||
|
||||
func isDone() -> bool:
|
||||
return true
|
||||
|
||||
func end() -> void:
|
||||
assert(ended == false)
|
||||
ended = true
|
||||
self.eventEnded.emit()
|
||||
if self.inEventSystemTree:
|
||||
EVENT.removeEvent(self)
|
||||
|
||||
func isEndingEvent() -> bool:
|
||||
return false
|
||||
|
||||
func reset() -> void:
|
||||
started = false
|
||||
ended = false
|
||||
interactor = null
|
||||
interactee = null
|
||||
|
||||
func onEntityInteract(
|
||||
interactor:EntityInteractor,
|
||||
interactee:EntityInteractable
|
||||
) -> void:
|
||||
self.reset()
|
||||
self.interactor = interactor
|
||||
self.interactee = interactee
|
||||
self.start()
|
@@ -1 +0,0 @@
|
||||
uid://cl3vqv8bwyoeu
|
@@ -1,63 +0,0 @@
|
||||
class_name EventConversation extends "res://scripts/Event/Flow/EventGroup.gd"
|
||||
|
||||
@export var startPauseType:PauseSystem.PauseType = PauseSystem.PauseType.ENTITY_PAUSED
|
||||
@export var endPauseType:PauseSystem.PauseType = PauseSystem.PauseType.NOT_PAUSED
|
||||
|
||||
@export var entities:Array[Entity] = []
|
||||
|
||||
@export var pauseInteractee:bool = true
|
||||
@export var pauseInteractor:bool = true
|
||||
@export var turnInteractee:bool = true
|
||||
@export var turnInteractor:bool = true
|
||||
|
||||
var endPauseEvent:EventPause = null
|
||||
|
||||
func start() -> void:
|
||||
# Turn events
|
||||
if interactee && interactor:
|
||||
if turnInteractee && interactee.entityDirection && interactor.characterBody:
|
||||
var turn = EventEntityTurn.new()
|
||||
turn.name = "Conversation Turn Interactee"
|
||||
turn.entity = interactee.entityDirection
|
||||
turn.direction = turn.entity.getDirectionToFace(interactor.characterBody.global_position)
|
||||
addChildEvent(turn, 0)
|
||||
|
||||
if turnInteractor && interactor.entityDirection && interactee.characterBody:
|
||||
var turn = EventEntityTurn.new()
|
||||
turn.name = "Conversation Turn Interactor"
|
||||
turn.entity = interactor.entityDirection
|
||||
turn.direction = turn.entity.getDirectionToFace(interactee.characterBody.global_position)
|
||||
addChildEvent(turn, 0)
|
||||
|
||||
# Create start pause event
|
||||
if (pauseInteractee && interactee.entity) || (pauseInteractor && interactor.entity):
|
||||
var startPause = EventPause.new()
|
||||
startPause.name = "Conversation Start Pause"
|
||||
startPause.pauseType = startPauseType
|
||||
startPause.entities = entities
|
||||
if pauseInteractee && interactee.entity:
|
||||
startPause.includeInteractee = pauseInteractee
|
||||
if pauseInteractor && interactor.entity:
|
||||
startPause.includeInteractor = pauseInteractor
|
||||
addChildEvent(startPause, 0)
|
||||
|
||||
# Create end pause event.
|
||||
endPauseEvent = EventPause.new()
|
||||
endPauseEvent.name = "Conversation End Pause"
|
||||
endPauseEvent.pauseType = endPauseType
|
||||
endPauseEvent.entities = entities
|
||||
if pauseInteractee && interactee.entity:
|
||||
endPauseEvent.includeInteractee = pauseInteractee
|
||||
if pauseInteractor && interactor.entity:
|
||||
endPauseEvent.includeInteractor = pauseInteractor
|
||||
addChildEvent(endPauseEvent, -1)
|
||||
|
||||
# Pass off to event group
|
||||
super.start()
|
||||
|
||||
func end() -> void:
|
||||
print("Ending conversation event: ", self)
|
||||
# Manually end pause
|
||||
if endPauseEvent != null && !endPauseEvent.started:
|
||||
endPauseEvent.start()
|
||||
super.end()
|
@@ -1 +0,0 @@
|
||||
uid://tkfc88q8m86f
|
@@ -1 +0,0 @@
|
||||
uid://dq35fj8r206nj
|
@@ -1,63 +0,0 @@
|
||||
class_name EventFlagModify extends "res://scripts/Event/Event.gd"
|
||||
|
||||
enum Action {
|
||||
TURN_ON,
|
||||
TURN_OFF,
|
||||
SET_TO,
|
||||
ALL_ON,
|
||||
ALL_OFF
|
||||
}
|
||||
|
||||
@export var action:Action = Action.TURN_ON;
|
||||
@export var event:EventSystem.SpecialEvent;
|
||||
@export_flags(
|
||||
"1:1",
|
||||
"2:2",
|
||||
"3:4",
|
||||
"4:8",
|
||||
"5:16",
|
||||
"6:32",
|
||||
"7:64",
|
||||
"8:128",
|
||||
"9:256",
|
||||
"10:512",
|
||||
"11:1024",
|
||||
"12:2048",
|
||||
"13:4096",
|
||||
"14:8192",
|
||||
"15:16384",
|
||||
"16:32768",
|
||||
"17:65536",
|
||||
"18:131072",
|
||||
"19:262144",
|
||||
"20:524288",
|
||||
"21:1048576",
|
||||
"22:2097152",
|
||||
"23:4194304",
|
||||
"24:8388608",
|
||||
"25:16777216",
|
||||
"26:33554432",
|
||||
"27:67108864",
|
||||
"28:134217728",
|
||||
"29:268435456",
|
||||
"30:536870912",
|
||||
"31:1073741824",
|
||||
"32:2147483648"
|
||||
)
|
||||
var eventFlag:int = 0;
|
||||
|
||||
func start() -> void:
|
||||
super.start()
|
||||
match action:
|
||||
Action.TURN_ON:
|
||||
EVENT.eventFlagOn(event, eventFlag)
|
||||
Action.TURN_OFF:
|
||||
EVENT.eventFlagOff(event, eventFlag)
|
||||
Action.SET_TO:
|
||||
EVENT.eventFlagSetTo(event, eventFlag)
|
||||
Action.ALL_ON:
|
||||
EVENT.eventFlagSetTo(event, 0xffffffff)
|
||||
Action.ALL_OFF:
|
||||
EVENT.eventFlagSetTo(event, 0)
|
||||
_:
|
||||
print("Invalid action: %s" % str(action))
|
@@ -1 +0,0 @@
|
||||
uid://0ygswaohp7kj
|
@@ -1,42 +0,0 @@
|
||||
class_name EventFlagOn extends "res://scripts/Event/Event.gd"
|
||||
|
||||
@export var event:EventSystem.SpecialEvent;
|
||||
@export_flags(
|
||||
"1:1",
|
||||
"2:2",
|
||||
"3:4",
|
||||
"4:8",
|
||||
"5:16",
|
||||
"6:32",
|
||||
"7:64",
|
||||
"8:128",
|
||||
"9:256",
|
||||
"10:512",
|
||||
"11:1024",
|
||||
"12:2048",
|
||||
"13:4096",
|
||||
"14:8192",
|
||||
"15:16384",
|
||||
"16:32768",
|
||||
"17:65536",
|
||||
"18:131072",
|
||||
"19:262144",
|
||||
"20:524288",
|
||||
"21:1048576",
|
||||
"22:2097152",
|
||||
"23:4194304",
|
||||
"24:8388608",
|
||||
"25:16777216",
|
||||
"26:33554432",
|
||||
"27:67108864",
|
||||
"28:134217728",
|
||||
"29:268435456",
|
||||
"30:536870912",
|
||||
"31:1073741824",
|
||||
"32:2147483648"
|
||||
)
|
||||
var eventFlag:int = 0;
|
||||
|
||||
func start() -> void:
|
||||
super.start()
|
||||
EVENT.eventFlagOn(event, eventFlag)
|
@@ -1 +0,0 @@
|
||||
uid://cbd7wpvkf76ux
|
@@ -1 +0,0 @@
|
||||
uid://sqi2ehu4sqa1
|
@@ -1,15 +0,0 @@
|
||||
class_name EventPause extends "res://scripts/Event/Event.gd"
|
||||
|
||||
@export var pauseType:PauseSystem.PauseType = PauseSystem.PauseType.ENTITY_PAUSED
|
||||
@export var entities:Array[Entity] = []
|
||||
@export var includeInteractee:bool = true
|
||||
@export var includeInteractor:bool = true
|
||||
|
||||
func end() -> void:
|
||||
super.end()
|
||||
var ents:Array[Entity] = entities
|
||||
if interactor && includeInteractor && interactor.entity:
|
||||
ents.append(interactor.entity)
|
||||
if interactee && includeInteractee && interactee.entity:
|
||||
ents.append(interactee.entity)
|
||||
PAUSE.pause(pauseType, ents)
|
@@ -1 +0,0 @@
|
||||
uid://bv36suxm08vqe
|
@@ -1,25 +0,0 @@
|
||||
class_name EventTextbox extends "res://scripts/Event/Event.gd"
|
||||
|
||||
@export_multiline var text:String = ""
|
||||
|
||||
var textPlural:String = ""
|
||||
var count:int = 1
|
||||
var transContext:TransContext = null
|
||||
|
||||
func start() -> void:
|
||||
super.start()
|
||||
|
||||
if text.is_empty() && transContext == null:
|
||||
push_error("EventTextbox text is empty and no TransContext provided.")
|
||||
return
|
||||
|
||||
if transContext == null:
|
||||
transContext = TransContext.new()
|
||||
|
||||
if textPlural.is_empty():
|
||||
VN.getTextbox().setText(transContext.trans(text))
|
||||
else:
|
||||
VN.getTextbox().setText(transContext.transPlural(text, textPlural, count));
|
||||
|
||||
func isDone() -> bool:
|
||||
return super.isDone() && VN.getTextbox().isClosed;
|
@@ -1 +0,0 @@
|
||||
uid://y7ckj1tn5cro
|
@@ -1,32 +0,0 @@
|
||||
class_name EventTrigger extends Node
|
||||
|
||||
@export var triggerMultipleTimes: bool = false
|
||||
|
||||
var eventIf:EventIf = null
|
||||
|
||||
func _enter_tree() -> void:
|
||||
for child in get_children():
|
||||
if !(child is EventIf):
|
||||
continue
|
||||
eventIf = child
|
||||
break
|
||||
|
||||
if eventIf == null:
|
||||
push_error(self, "requires an EventIf child to function properly")
|
||||
return
|
||||
|
||||
eventIf.eventConditionMet.connect(onConditionTriggered)
|
||||
eventIf.onTriggerListening(self)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
if eventIf != null:
|
||||
eventIf.eventConditionMet.disconnect(onConditionTriggered)
|
||||
eventIf.onTriggerNotListening(self)
|
||||
|
||||
eventIf = null
|
||||
|
||||
func onConditionTriggered() -> void:
|
||||
if !triggerMultipleTimes:
|
||||
eventIf.eventConditionMet.disconnect(onConditionTriggered)
|
||||
eventIf.onTriggerNotListening(self)
|
||||
eventIf.start()
|
@@ -1 +0,0 @@
|
||||
uid://cs7voh47aoca8
|
@@ -1 +0,0 @@
|
||||
uid://dj5wl682sbohc
|
@@ -1,35 +0,0 @@
|
||||
class_name EventGoTo extends "res://scripts/Event/Event.gd"
|
||||
|
||||
enum Type {
|
||||
GO_TO,
|
||||
GO_TO_AND_WAIT,
|
||||
GO_TO_AND_CONTINUE
|
||||
}
|
||||
|
||||
@export var event:Event = null
|
||||
@export var type:Type = Type.GO_TO
|
||||
|
||||
func start() -> void:
|
||||
super.start()
|
||||
if event == null:
|
||||
print("EventGoTo: No event set")
|
||||
return
|
||||
|
||||
event.start()
|
||||
|
||||
func isDone():
|
||||
if !super.isDone():
|
||||
return false
|
||||
|
||||
if event == null:
|
||||
return true
|
||||
|
||||
if type == Type.GO_TO_AND_WAIT:
|
||||
return event.isDone()
|
||||
|
||||
return true
|
||||
|
||||
func isEndingEvent() -> bool:
|
||||
if type == Type.GO_TO:
|
||||
return true
|
||||
return false
|
@@ -1 +0,0 @@
|
||||
uid://da7fr2bave0c
|
@@ -1,83 +0,0 @@
|
||||
class_name EventGroup extends "res://scripts/Event/Flow/EventWithChildren.gd"
|
||||
|
||||
enum ProcessType {
|
||||
SEQUENTIAL,
|
||||
PARALLEL,
|
||||
}
|
||||
|
||||
@export var processType:ProcessType = ProcessType.SEQUENTIAL;
|
||||
|
||||
var childIndex:int = 0
|
||||
var eventGroupStarted:bool = false
|
||||
|
||||
func shouldAutoStart() -> bool:
|
||||
return true
|
||||
|
||||
func start() -> void:
|
||||
super.start()
|
||||
|
||||
if shouldAutoStart():
|
||||
startEventGroup()
|
||||
|
||||
func startEventGroup() -> void:
|
||||
eventGroupStarted = true
|
||||
|
||||
# This is called by the parent event to start the group
|
||||
if processType == ProcessType.SEQUENTIAL:
|
||||
childIndex = -1
|
||||
nextChild()
|
||||
elif processType == ProcessType.PARALLEL:
|
||||
for child in childEvents:
|
||||
startChild(child)
|
||||
|
||||
func update(delta:float) -> void:
|
||||
super.update(delta)
|
||||
|
||||
# If sequential, see if the current child is done, if so go to next child
|
||||
if processType == ProcessType.SEQUENTIAL:
|
||||
if childIndex < 0 || childIndex >= childEvents.size():
|
||||
return
|
||||
if childEvents[childIndex].isDone():
|
||||
nextChild()
|
||||
|
||||
func nextChild() -> void:
|
||||
childIndex += 1
|
||||
if childIndex >= childEvents.size():
|
||||
return
|
||||
startChild(childEvents[childIndex])
|
||||
|
||||
func isDone() -> bool:
|
||||
if !super.isDone():
|
||||
return false
|
||||
|
||||
if started && !eventGroupStarted:
|
||||
return true
|
||||
|
||||
# If sequential, check if we've reached the end of the children
|
||||
if processType == ProcessType.SEQUENTIAL:
|
||||
return childIndex >= childEvents.size()
|
||||
|
||||
# If parallel, check if all children are done
|
||||
elif processType == ProcessType.PARALLEL:
|
||||
for child in childEvents:
|
||||
if !child.isDone():
|
||||
return false
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
func end() -> void:
|
||||
for child in childEvents:
|
||||
if child.ended || !child.started:
|
||||
continue
|
||||
child.end()
|
||||
# Send to the parent to end the extra events
|
||||
super.end()
|
||||
|
||||
func reset() -> void:
|
||||
childIndex = -1
|
||||
eventGroupStarted = false
|
||||
for child in childEvents:
|
||||
child.reset()
|
||||
# Send to the parent to reset the extra events
|
||||
super.reset()
|
@@ -1 +0,0 @@
|
||||
uid://bb1qpptyr1rec
|
@@ -1,50 +0,0 @@
|
||||
class_name EventWithChildren extends "res://scripts/Event/Event.gd"
|
||||
|
||||
var childEvents:Array[Event] = []
|
||||
var addedEvents:Array[Event] = []
|
||||
|
||||
func start():
|
||||
super.start()
|
||||
_updateChildEvents()
|
||||
|
||||
func reset() -> void:
|
||||
super.reset()
|
||||
_cleanupExtraEvents()
|
||||
|
||||
func end() -> void:
|
||||
super.end()
|
||||
_cleanupExtraEvents()
|
||||
|
||||
func _updateChildEvents() -> void:
|
||||
childEvents = []
|
||||
for child in get_children():
|
||||
if child is Event:
|
||||
childEvents.append(child)
|
||||
|
||||
func _cleanupExtraEvents():
|
||||
for event in addedEvents:
|
||||
remove_child(event)
|
||||
event.queue_free()
|
||||
addedEvents = []
|
||||
_updateChildEvents()
|
||||
|
||||
func addChildEvent(child:Event, position:int = -1) -> void:
|
||||
assert(started == false || ended == true)
|
||||
if position < 0:
|
||||
position = childEvents.size() + position + 1
|
||||
|
||||
add_child(child)
|
||||
move_child(child, position)
|
||||
addedEvents.append(child)
|
||||
_updateChildEvents()
|
||||
|
||||
func startChild(child:Event) -> void:
|
||||
assert(child.get_parent() == self)
|
||||
|
||||
# Inherits some properties from this event.
|
||||
child.interactee = self.interactee
|
||||
child.interactor = self.interactor
|
||||
child.start()
|
||||
|
||||
if child.isEndingEvent():
|
||||
self.end()
|
@@ -1 +0,0 @@
|
||||
uid://bs78jtft61ro6
|
@@ -1,74 +0,0 @@
|
||||
class_name EventGetItem extends "res://scripts/Event/Item/EventItem.gd"
|
||||
|
||||
const EventConversation = preload("res://scripts/Event/EventConversation.gd")
|
||||
|
||||
enum GetType {
|
||||
FOUND,
|
||||
GIVEN,
|
||||
}
|
||||
|
||||
@export var showText: bool = true
|
||||
@export var getType:GetType = GetType.FOUND;
|
||||
@export var removeNode:Node = null
|
||||
|
||||
var conversationEvent:EventConversation = null
|
||||
var textboxEvent:EventTextbox = null
|
||||
|
||||
func start() -> void:
|
||||
# Should show text?
|
||||
if !showText:
|
||||
super.start()
|
||||
return
|
||||
|
||||
# What text to show?
|
||||
var textKey:String
|
||||
match getType:
|
||||
GetType.FOUND:
|
||||
textKey = "event.get_item.found"
|
||||
GetType.GIVEN:
|
||||
textKey = "event.get_item.given"
|
||||
_:
|
||||
super.start()
|
||||
return
|
||||
|
||||
# Create translation context
|
||||
var ctx = TransContext.new()
|
||||
ctx.addInteger("quantity", quantity)
|
||||
ctx.addContext("item", ITEM.getItem(itemType).getTransContext())
|
||||
|
||||
# Create conversation
|
||||
conversationEvent = EventConversation.new()
|
||||
addChildEvent(conversationEvent)
|
||||
|
||||
# Create textbox
|
||||
textboxEvent = EventTextbox.new()
|
||||
textboxEvent.transContext = ctx
|
||||
textboxEvent.text = textKey
|
||||
textboxEvent.textPlural = textKey + "_plural"
|
||||
textboxEvent.count = quantity
|
||||
conversationEvent.addChildEvent(textboxEvent)
|
||||
|
||||
# Begin processing
|
||||
super.start()
|
||||
startChild(conversationEvent)
|
||||
|
||||
func rewardItem():
|
||||
getInventory().addItem(itemType, quantity)
|
||||
|
||||
func isDone() -> bool:
|
||||
if !super.isDone():
|
||||
return false
|
||||
|
||||
if !showText:
|
||||
return true
|
||||
return conversationEvent.isDone()
|
||||
|
||||
func end() -> void:
|
||||
rewardItem()
|
||||
if removeNode:
|
||||
var parent = removeNode.get_parent()
|
||||
if parent:
|
||||
parent.remove_child(removeNode)
|
||||
removeNode.queue_free()
|
||||
removeNode = null
|
||||
super.end()
|
@@ -1 +0,0 @@
|
||||
uid://b41umpbgqfuc2
|
@@ -1,11 +0,0 @@
|
||||
class_name EventItem extends "res://scripts/Event/Flow/EventWithChildren.gd"
|
||||
const Inventory = preload("res://scripts/Item/Inventory.gd")
|
||||
|
||||
@export var itemType:Item.Type = Item.Type.POTION
|
||||
@export var quantity:int = 1
|
||||
var inventory:Inventory = null
|
||||
|
||||
func getInventory() -> Inventory:
|
||||
if inventory == null:
|
||||
inventory = ITEM.PLAYER_INVENTORY
|
||||
return inventory
|
@@ -1 +0,0 @@
|
||||
uid://bgd2nkg5ni2et
|
@@ -1,77 +0,0 @@
|
||||
class_name EventIfQuest extends "res://scripts/Event/Condition/EventIf.gd"
|
||||
## Event that checks if a quest is in a specific state, if the condition is met
|
||||
## then all children events will be run through.
|
||||
##
|
||||
## Can also be used as part of a trigger condition to fire if the quest state
|
||||
## is updated.
|
||||
|
||||
enum Type {
|
||||
ANY_OF_OBJECTIVES_COMPLETED,
|
||||
ALL_OF_OBJECTIVES_COMPLETED,
|
||||
ANY_OF_OBJECTIVES_NOT_COMPLETED,
|
||||
ALL_OF_OBJECTIVES_NOT_COMPLETED,
|
||||
SPECIFIC_OBJECTIVE_COMPLETED,
|
||||
SPECIFIC_OBJECTIVE_NOT_COMPLETED,
|
||||
QUEST_STARTED,
|
||||
QUEST_NOT_STARTED,
|
||||
}
|
||||
|
||||
@export var questKey:QuestSystem.QuestKey = QuestSystem.QuestKey.TEST_QUEST
|
||||
@export var type:Type = Type.ALL_OF_OBJECTIVES_COMPLETED
|
||||
@export var objective:int = 0
|
||||
|
||||
func ifCondition() -> bool:
|
||||
var quest:Quest = QUEST.quests.get(questKey)
|
||||
|
||||
match type:
|
||||
Type.ANY_OF_OBJECTIVES_COMPLETED:
|
||||
for objective in quest.objecitves:
|
||||
if !objective.isCompleted():
|
||||
return true
|
||||
|
||||
Type.ALL_OF_OBJECTIVES_COMPLETED:
|
||||
for objective in quest.objectives:
|
||||
if !objective.isCompleted():
|
||||
return false
|
||||
return true
|
||||
|
||||
Type.ANY_OF_OBJECTIVES_NOT_COMPLETED:
|
||||
for objective in quest.objectives:
|
||||
if !objective.isCompleted():
|
||||
return true
|
||||
|
||||
Type.ALL_OF_OBJECTIVES_NOT_COMPLETED:
|
||||
for objective in quest.objectives:
|
||||
if objective.isCompleted():
|
||||
return false
|
||||
return true
|
||||
|
||||
Type.SPECIFIC_OBJECTIVE_COMPLETED:
|
||||
if quest.objectives[objective].isCompleted():
|
||||
return true
|
||||
|
||||
Type.SPECIFIC_OBJECTIVE_NOT_COMPLETED:
|
||||
if quest.objectives[objective].isCompleted():
|
||||
return false
|
||||
return true
|
||||
|
||||
Type.QUEST_STARTED:
|
||||
if quest.isStarted():
|
||||
return true
|
||||
|
||||
Type.QUEST_NOT_STARTED:
|
||||
if !quest.isStarted():
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
func subscribeEvents() -> void:
|
||||
QUEST.questUpdated.connect(onQuestUpdated)
|
||||
|
||||
func unsubscribeEvents() -> void:
|
||||
QUEST.questUpdated.disconnect(onQuestUpdated)
|
||||
|
||||
func onQuestUpdated(quest:Quest) -> void:
|
||||
if quest.questKey != questKey:
|
||||
return
|
||||
self.onEventTrigger()
|
@@ -1 +0,0 @@
|
||||
uid://0ev1l0bf85gj
|
@@ -1 +0,0 @@
|
||||
uid://0aipsu5ele44
|
@@ -1 +0,0 @@
|
||||
uid://cnbl4x8p2xsx5
|
@@ -1 +0,0 @@
|
||||
uid://c2aj13e48jjd4
|
@@ -1,19 +0,0 @@
|
||||
class_name EventShowQuest extends "res://scripts/Event/Event.gd"
|
||||
|
||||
@export var quest:QuestSystem.QuestKey = QuestSystem.QuestKey.TEST_QUEST
|
||||
@export var waitUntilClosed:bool = true
|
||||
@export var showQuest:bool = true
|
||||
|
||||
func start():
|
||||
if showQuest:
|
||||
UI.QUEST_MENU.open(quest)
|
||||
pass
|
||||
|
||||
func isDone() -> bool:
|
||||
if !super.isDone():
|
||||
return false
|
||||
|
||||
if waitUntilClosed and showQuest:
|
||||
return !UI.QUEST_MENU.isOpen()
|
||||
|
||||
return true
|
@@ -1 +0,0 @@
|
||||
uid://dd6ppw243a5x7
|
@@ -1,9 +0,0 @@
|
||||
class_name EventStartQuest extends "res://scripts/Event/Quest/EventShowQuest.gd"
|
||||
|
||||
@export_category("Event Start Quest")
|
||||
var nothing:bool = false
|
||||
|
||||
func start():
|
||||
assert(QUEST.quests.has(quest), "Quest not found.")
|
||||
QUEST.quests[quest].start()
|
||||
super.start()
|
@@ -1 +0,0 @@
|
||||
uid://c4d7nithqnx5y
|
3
scripts/InteractableArea.gd
Normal file
3
scripts/InteractableArea.gd
Normal file
@@ -0,0 +1,3 @@
|
||||
class_name InteractableArea extends Area3D
|
||||
|
||||
signal interactEvent
|
1
scripts/InteractableArea.gd.uid
Normal file
1
scripts/InteractableArea.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b00rxpveu3v4m
|
@@ -1,114 +0,0 @@
|
||||
class_name Inventory
|
||||
|
||||
enum ItemSortType {
|
||||
NAME,
|
||||
TYPE
|
||||
};
|
||||
|
||||
class ItemStackNameComparator:
|
||||
static func _sort(a, b):
|
||||
assert(false, "Going to change implementation of this later.")
|
||||
# return ITEM.getItemName(a).to_lower() < ITEM.getItemName(b).to_lower()
|
||||
|
||||
class ItemStackTypeComparator:
|
||||
static func _sort(a, b):
|
||||
return a.item.getCategory() < b.item.getCategory()
|
||||
|
||||
const ITEM_STACK_SIZE_MAX = 99;
|
||||
|
||||
var contents:Array[ItemStack] = [];
|
||||
signal inventoryUpdated()
|
||||
|
||||
func isPlayerInventory() -> bool:
|
||||
return self == ITEM.PLAYER_INVENTORY
|
||||
|
||||
func addItem(type:Item.Type, quantity: int = 1) -> void:
|
||||
if !ITEM.isStackable(type):
|
||||
# Item cannot be stacked, add each item to inv
|
||||
for i in range(quantity):
|
||||
contents.append(ItemStack.new(type, 1))
|
||||
_contentsUpdated()
|
||||
return
|
||||
|
||||
# Check for existing stacks
|
||||
for stack in contents:
|
||||
if stack.type != type or stack.quantity >= ITEM_STACK_SIZE_MAX:
|
||||
continue
|
||||
|
||||
var spaceAvailable = ITEM_STACK_SIZE_MAX - stack.quantity
|
||||
|
||||
if quantity <= spaceAvailable:
|
||||
stack.quantity += quantity;
|
||||
_contentsUpdated()
|
||||
return
|
||||
|
||||
stack.quantity = ITEM_STACK_SIZE_MAX;
|
||||
quantity -= spaceAvailable;
|
||||
|
||||
# Add any remaining inventory as new stack.
|
||||
while quantity > 0:
|
||||
var newStackQuantity = min(quantity, ITEM_STACK_SIZE_MAX);
|
||||
contents.append(ItemStack.new(type, newStackQuantity));
|
||||
quantity -= newStackQuantity;
|
||||
_contentsUpdated()
|
||||
|
||||
func removeItem(type:Item.Type, quantity:int) -> void:
|
||||
var totalQuantity = 0
|
||||
|
||||
# Calculate total quantity of the item in the inventory
|
||||
for stack in contents:
|
||||
if stack.type != type:
|
||||
continue
|
||||
totalQuantity += stack.quantity
|
||||
|
||||
if totalQuantity < quantity:
|
||||
push_error("Not enough quantity to remove");
|
||||
return
|
||||
|
||||
# Remove the quantity from the stacks
|
||||
for stack in contents:
|
||||
if stack.type != type:
|
||||
continue
|
||||
|
||||
if stack.quantity < quantity:
|
||||
quantity -= stack.quantity
|
||||
contents.erase(stack)
|
||||
|
||||
stack.quantity -= quantity
|
||||
if stack.quantity == 0:
|
||||
contents.erase(stack)
|
||||
|
||||
if quantity == 0:
|
||||
self._contentsUpdated()
|
||||
return
|
||||
|
||||
func removeStack(stack: ItemStack) -> void:
|
||||
self.removeItem(stack.item, stack.quantity);
|
||||
|
||||
func hasItem(type:Item.Type, quantity: int = 1) -> bool:
|
||||
var totalQuantity = 0
|
||||
|
||||
for stack in contents:
|
||||
if stack.type != type:
|
||||
continue
|
||||
|
||||
totalQuantity += stack.quantity
|
||||
|
||||
if totalQuantity >= quantity:
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
func sortBy(by:ItemSortType) -> void:
|
||||
match by:
|
||||
ItemSortType.NAME:
|
||||
contents.sort_custom(ItemStackNameComparator._sort)
|
||||
ItemSortType.TYPE:
|
||||
contents.sort_custom(ItemStackTypeComparator._sort)
|
||||
_:
|
||||
assert(false, "Invalid sort type: %s" % by)
|
||||
|
||||
func _contentsUpdated() -> void:
|
||||
inventoryUpdated.emit()
|
||||
if isPlayerInventory():
|
||||
QUEST.playerInventoryUpdated.emit()
|
@@ -1 +0,0 @@
|
||||
uid://dgunweso54t2t
|
@@ -1,37 +0,0 @@
|
||||
class_name Item extends Node
|
||||
|
||||
enum Type {
|
||||
# Items
|
||||
POTION = 1,
|
||||
|
||||
# Ingredients
|
||||
ONION = 2,
|
||||
SWEET_POTATO = 3,
|
||||
|
||||
# Recipe outputs
|
||||
BAKED_SWEET_POTATO = 4,
|
||||
};
|
||||
|
||||
enum Category {
|
||||
MEDICINE,
|
||||
KEY_ITEM,
|
||||
INGREDIENT,
|
||||
FOOD
|
||||
};
|
||||
|
||||
static func getCategoryTitleKey(cat:Category) -> String:
|
||||
return "item.category." + str(cat).to_lower() + ".title"
|
||||
|
||||
@export var title:String = ""
|
||||
@export var description_text:String = ""
|
||||
@export var type:Type = Type.POTION
|
||||
@export var category:Category = Category.INGREDIENT
|
||||
@export var stackable:bool = true
|
||||
|
||||
func getTransContext() -> TransContext:
|
||||
var ctx:TransContext = TransContext.new()
|
||||
ctx.addTransPlural("title", title)
|
||||
ctx.addTrans("description", description_text)
|
||||
ctx.addTrans("category", getCategoryTitleKey(category))
|
||||
ctx.addBool("stackable", stackable)
|
||||
return ctx
|
@@ -1 +0,0 @@
|
||||
uid://c6t5tprnd23t0
|
@@ -1,4 +0,0 @@
|
||||
class_name ItemResource extends Resource
|
||||
|
||||
@export var itemType:Item.Type = Item.Type.ONION;
|
||||
@export var quantity:int = 1;
|
@@ -1 +0,0 @@
|
||||
uid://c26aptwsjs044
|
@@ -1,8 +0,0 @@
|
||||
class_name ItemStack
|
||||
|
||||
var type:Item.Type;
|
||||
var quantity:int;
|
||||
|
||||
func _init(type:Item.Type, quantity:int = 1):
|
||||
self.type = type;
|
||||
self.quantity = quantity;
|
@@ -1 +0,0 @@
|
||||
uid://re7dg4hpp804
|
@@ -1 +0,0 @@
|
||||
uid://nibssdy3ardv
|
@@ -1 +0,0 @@
|
||||
uid://dpns5iesd08rl
|
@@ -1 +0,0 @@
|
||||
class_name ItemOnion extends "res://scripts/Item/Item.gd"
|
@@ -1 +0,0 @@
|
||||
uid://dipe47ljyvycv
|
@@ -1 +0,0 @@
|
||||
class_name ItemPotion extends Item
|
@@ -1 +0,0 @@
|
||||
uid://b6v2o563casay
|
@@ -1,13 +0,0 @@
|
||||
class_name Map extends Node
|
||||
|
||||
@export_multiline var title:String = ""
|
||||
@export var mapEnterEvent:Event = null
|
||||
|
||||
func _ready() -> void:
|
||||
if mapEnterEvent:
|
||||
mapEnterEvent.start()
|
||||
|
||||
func getTransContext() -> TransContext:
|
||||
var ctx = TransContext.new()
|
||||
ctx.set("title", title)
|
||||
return ctx
|
@@ -1 +0,0 @@
|
||||
uid://c37crdel0m5mw
|
@@ -1,36 +0,0 @@
|
||||
class_name Quest extends Node
|
||||
|
||||
@export_multiline var title:String = ""
|
||||
@export var questKey:QuestSystem.QuestKey = QuestSystem.QuestKey.TEST_QUEST
|
||||
|
||||
var questStarted:bool = false
|
||||
var questComplete:bool = false
|
||||
|
||||
var objectives:Array[QuestObjective]
|
||||
|
||||
func _ready() -> void:
|
||||
objectives = []
|
||||
for child in get_children():
|
||||
if child is QuestObjective:
|
||||
objectives.append(child)
|
||||
child.onQuestReady(self)
|
||||
|
||||
func start() -> void:
|
||||
questStarted = true
|
||||
questComplete = false
|
||||
QUEST.questStarted.emit(self)
|
||||
QUEST.questUpdated.emit(self)
|
||||
|
||||
func isCompleted() -> bool:
|
||||
return questComplete
|
||||
|
||||
func isStarted() -> bool:
|
||||
return questStarted
|
||||
|
||||
func objectiveUpdated(_objective:QuestObjective) -> void:
|
||||
QUEST.questUpdated.emit(self)
|
||||
|
||||
func getTransContext() -> TransContext:
|
||||
var ctx:TransContext = TransContext.new()
|
||||
ctx.addTransPlural("title", title)
|
||||
return ctx
|
@@ -1 +0,0 @@
|
||||
uid://dn0kxbe85n40f
|
@@ -1,53 +0,0 @@
|
||||
class_name QuestObjective extends Node
|
||||
|
||||
enum Type {
|
||||
Item,
|
||||
}
|
||||
|
||||
@export_multiline var title:String = ""
|
||||
@export_multiline var description:String = ""
|
||||
@export var objectiveType:Type = Type.Item
|
||||
|
||||
@export var itemType:Item.Type = Item.Type.POTION
|
||||
@export var quantity:int = 1
|
||||
|
||||
var completed:bool = false
|
||||
var quest:Quest = null
|
||||
|
||||
func onQuestReady(_quest:Quest) -> void:
|
||||
self.quest = _quest
|
||||
if objectiveType == Type.Item:
|
||||
QUEST.playerInventoryUpdated.connect(_onPlayerInventoryUpdated)
|
||||
_onPlayerInventoryUpdated()
|
||||
|
||||
func _exit_tree() -> void:
|
||||
QUEST.playerInventoryUpdated.disconnect(_onPlayerInventoryUpdated)
|
||||
|
||||
func _onPlayerInventoryUpdated() -> void:
|
||||
if !quest.isStarted():
|
||||
return
|
||||
|
||||
# Ensure player has the item
|
||||
var hasItem = ITEM.PLAYER_INVENTORY.hasItem(itemType, quantity)
|
||||
|
||||
if hasItem && !completed:
|
||||
self.completed = true
|
||||
quest.objectiveUpdated(self)
|
||||
else:
|
||||
self.completed = false
|
||||
quest.objectiveUpdated(self)
|
||||
|
||||
func isCompleted() -> bool:
|
||||
return completed
|
||||
|
||||
func getTransContext() -> TransContext:
|
||||
var ctx = TransContext.new()
|
||||
|
||||
ctx.addTrans("title", title)
|
||||
ctx.addTrans("description", description)
|
||||
|
||||
if objectiveType == Type.Item:
|
||||
ctx.addInteger("quantity", quantity)
|
||||
ctx.addContext("item", ITEM.getItem(itemType).getTransContext())
|
||||
|
||||
return ctx
|
@@ -1 +0,0 @@
|
||||
uid://de1ao4huhy0hm
|
@@ -1 +0,0 @@
|
||||
uid://db4yhcxyhiosq
|
@@ -1 +0,0 @@
|
||||
uid://ckxjs4wty6sju
|
@@ -1 +0,0 @@
|
||||
uid://kwnx0enmgk54
|
@@ -1,4 +0,0 @@
|
||||
class_name MainMenuScene extends Node
|
||||
|
||||
func _enter_tree() -> void:
|
||||
pass
|
@@ -1 +0,0 @@
|
||||
uid://cak4lch21nq30
|
@@ -1,25 +0,0 @@
|
||||
class_name OverworldScene extends Node3D
|
||||
|
||||
func _ready() -> void:
|
||||
_updateMap()
|
||||
|
||||
OVERWORLD.mapChanged.connect(_onMapChanged)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
OVERWORLD.mapChanged.disconnect(_onMapChanged)
|
||||
|
||||
func _updateMap() -> void:
|
||||
# Remove all children
|
||||
for child in $Map.get_children():
|
||||
child.queue_free()
|
||||
$Map.remove_child(child)
|
||||
|
||||
# Load the new map
|
||||
if not OVERWORLD.MAPS.has(OVERWORLD.currentMap):
|
||||
return
|
||||
var map = load(OVERWORLD.MAPS[OVERWORLD.currentMap])
|
||||
var mapInstance = map.instantiate()
|
||||
$Map.add_child(mapInstance)
|
||||
|
||||
func _onMapChanged(mapHandle:String, mapScene:String) -> void:
|
||||
_updateMap()
|
@@ -1 +0,0 @@
|
||||
uid://pcncoc6wum4q
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user