Skip to content

Commit

Permalink
Breaking change - Entites become SKEntities
Browse files Browse the repository at this point in the history
  • Loading branch information
SlashScreen committed May 7, 2024
1 parent 5c4804d commit fbb8782
Show file tree
Hide file tree
Showing 55 changed files with 139 additions and 146 deletions.
18 changes: 9 additions & 9 deletions scripts/ai/Modules/default_threat_response.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var pull_out_of_thread = false

func _initialize() -> void:
_npc.perception_transition.connect(_handle_perception_info.bind())
_npc.hit_by.connect(func(who): _aggress(EntityManager.instance.get_entity(who)))
_npc.hit_by.connect(func(who): _aggress(SKEntityManager.instance.get_entity(who)))


func _handle_perception_info(what:StringName, transition:String, fsm:PerceptionFSM_Machine) -> void:
Expand All @@ -73,7 +73,7 @@ func _handle_perception_info(what:StringName, transition:String, fsm:PerceptionF
if below_attack_threshold: # if attack threshold or frenzied
if not _npc.in_combat:
_npc.printe("start vigilance")
var e = EntityManager.instance.get_entity(what)
var e = SKEntityManager.instance.get_entity(what)

# attack immediately if frenzied
if aggression == 3:
Expand Down Expand Up @@ -103,7 +103,7 @@ func _handle_perception_info(what:StringName, transition:String, fsm:PerceptionF


## Will keep watch until the entity is out of range. TODO: Visibility?
func _stay_vigilant(e:Entity) -> void:
func _stay_vigilant(e:SKEntity) -> void:
# may need to change the order of this, im not sure where to put it yet
if _npc.in_combat: # don't react if already in combat
_add_enemy(e)
Expand Down Expand Up @@ -150,7 +150,7 @@ func _stay_vigilant(e:Entity) -> void:
return


func _begin_attack(e:Entity) -> void:
func _begin_attack(e:SKEntity) -> void:
# figure out response to confrontation
print("beginning attack")
match aggression:
Expand All @@ -168,7 +168,7 @@ func _begin_attack(e:Entity) -> void:
# This will begin combat, because NPCs have a recurring goal where all enemies must be dead


func _add_enemy(e:Entity) -> void:
func _add_enemy(e:SKEntity) -> void:
if _npc.goap_memory.has("enemies"):
if not _npc.goap_memory["enemies"].has(e.name):
print("Adding enemy %s" % e.name)
Expand All @@ -179,7 +179,7 @@ func _add_enemy(e:Entity) -> void:
_npc._goap_component.interrupt() # interrupt current task if entering combat


func _warn(e:Entity) -> void:
func _warn(e:SKEntity) -> void:
# Issue warning to entity
print("warning!")
_npc.warning.emit(e.name)
Expand All @@ -196,15 +196,15 @@ func _enter_vigilant_stance() -> void:
print("enter vigilant stance")


func _flee(e:Entity) -> void:
func _flee(e:SKEntity) -> void:
# tell GOAP to flee from enemies
print("flee")
_npc.add_objective({"flee_from_enemies" : true}, true, 10)
_npc.flee.emit(e.name)


## Response to being hit.
func _aggress(e:Entity) -> void:
func _aggress(e:SKEntity) -> void:
# "Coward", "Cautious", "Average", "Brave", "Foolhardy"
# TODO: Friendly fire
var threat = _determine_threat(e)
Expand Down Expand Up @@ -244,7 +244,7 @@ func _aggress(e:Entity) -> void:
## 1: Stronger [br]
## 2: Significantly stronger [br]
## See [constant THREAT_LEVEL_WEAKER_INTERVAL], [constant THREAT_LEVEL_GREATER_INTERVAL], [constant THREAT_LEVEL_MUCH_GREATER_INTERVAL]
func _determine_threat(e:Entity) -> int:
func _determine_threat(e:SKEntity) -> int:
var e_sc = e.get_component("SkillsComponent")
# if no skills component associated with the entity, default is 0
if not e_sc.some():
Expand Down
4 changes: 2 additions & 2 deletions scripts/ai/PerceptionFSM/state_aware_visible.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extends FSMState


var _npc:NPCComponent
var e:Entity
var e:SKEntity


func _get_state_name() -> String:
Expand All @@ -23,4 +23,4 @@ func update(delta:float) -> void:


func enter(msg:Dictionary = {}) -> void:
e = EntityManager.instance.get_entity((state_machine as PerceptionFSM_Machine).tracked)
e = SKEntityManager.instance.get_entity((state_machine as PerceptionFSM_Machine).tracked)
2 changes: 1 addition & 1 deletion scripts/ai/PerceptionFSM/state_unaware.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ func update(delta:float) -> void:

func enter(message:Dictionary) -> void:
# if we are tracking an item, skip right to aware visible
if EntityManager.instance.get_entity((state_machine as PerceptionFSM_Machine).tracked).get_component("ItemComponent"):
if SKEntityManager.instance.get_entity((state_machine as PerceptionFSM_Machine).tracked).get_component("ItemComponent"):
state_machine.transition("AwareVisible")
2 changes: 1 addition & 1 deletion scripts/ai/goap_action.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var running:bool:
var parent_goap:GOAPComponent:
get:
return goap_behavior.parent_goap
var entity:Entity:
var entity:SKEntity:
get:
return goap_behavior.entity

Expand Down
2 changes: 1 addition & 1 deletion scripts/ai/goap_behavior.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extends Resource
## Whether this objective is actively being worked on
var running:bool = false
var parent_goap:GOAPComponent
var entity:Entity
var entity:SKEntity


func is_achievable_given(state:Dictionary) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion scripts/ai/perception_ears.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class_name PerceptionEars
extends CollisionShape3D
## Add to something to make it be able to hear.
## Isn't an [EntityComponent], so can be added to anything.
## Isn't an [SKEntityComponent], so can be added to anything.
## Be sure to add a shape.


Expand Down
6 changes: 3 additions & 3 deletions scripts/ai/perception_eyes.gd
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func get_thing_under_sight(pt:NavPoint) -> PerceptionData:

## Looks for a specific entity, and returns with the data. Null if not found.
func look_for_entity(refID:StringName) -> PerceptionData:
var entity = EntityManager.instance.get_entity(refID)
var entity = SKEntityManager.instance.get_entity(refID)
if entity:
var pt = NavPoint.new(entity.world, entity.position)
var res = await get_thing_under_sight(pt)
Expand Down Expand Up @@ -133,8 +133,8 @@ func try_perception() -> void:
func _find_ref_id(n:Node) -> String:
var check:Node = n.get_parent()
while check.get_parent():
if check is Entity:
return (check as Entity).name
if check is SKEntity:
return (check as SKEntity).name
check = check.get_parent()
return ""

Expand Down
6 changes: 3 additions & 3 deletions scripts/barter/barter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func accept_barter(selling_modifier:float, buying_modifier:float, currency: Stri
#? Could optimize
for item in current_transaction.selling:
# Move from customer to vendor.
EntityManager.instance\
SKEntityManager.instance\
.get_entity(item)\
.get_component("ItemComponent")\
.move_to_inventory(current_transaction.vendor.parent_entity.name)
for item in current_transaction.buying:
# Move from vendor to customer.
EntityManager.instance\
SKEntityManager.instance\
.get_entity(item)\
.get_component("ItemComponent")\
.move_to_inventory(current_transaction.customer.parent_entity.name)
Expand All @@ -106,7 +106,7 @@ func accept_barter(selling_modifier:float, buying_modifier:float, currency: Stri

## Determine whether a shop will accept an item or not.
func shop_will_accept_iten(shop:ShopInstance, item:StringName) -> bool:
var ic:ItemComponent = EntityManager.instance.get_entity(item).get_component("ItemComponent")
var ic:ItemComponent = SKEntityManager.instance.get_entity(item).get_component("ItemComponent")

if not shop.whitelist.is_empty():
if not ic.data.tags.any(func(tag): return shop.whitelist.has(tag)): # if no tags in whitelist
Expand Down
4 changes: 2 additions & 2 deletions scripts/barter/transaction.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func total_transaction(selling_modifier:float, buying_modifier:float) -> int:
# Total selling amount and add
total += selling.reduce(
func(accum: int, item:String):
return accum + roundi(( EntityManager.instance.get_entity(item)\
return accum + roundi(( SKEntityManager.instance.get_entity(item)\
.get_component("ItemComponent")\
as ItemComponent)\
.data\
Expand All @@ -36,7 +36,7 @@ func total_transaction(selling_modifier:float, buying_modifier:float) -> int:
# Total selling amount and subtract
total -= buying.reduce(
func(accum: int, item:String):
return accum + roundi(( EntityManager.instance.get_entity(item)\
return accum + roundi(( SKEntityManager.instance.get_entity(item)\
.get_component("ItemComponent")\
as ItemComponent)\
.data\
Expand Down
10 changes: 5 additions & 5 deletions scripts/components/attributes_component.gd
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class_name AttributesComponent
extends EntityComponent
## Holds the attributes of an Entity, such as the D&D abilities - Charisma, Dexterity, etc.
extends SKEntityComponent
## Holds the attributes of an SKEntity, such as the D&D abilities - Charisma, Dexterity, etc.


## The attributes of this Entity.
## The attributes of this SKEntity.
## It is in a dictionary so you can add, remove, and customize at will.
## On startup, it will clone the list in the [member EntityManager.config] singleton.
@onready var attributes:Dictionary = EntityManager.instance.config.attributes.duplicate():
## On startup, it will clone the list in the [member SKEntityManager.config] singleton.
@onready var attributes:Dictionary = SKEntityManager.instance.config.attributes.duplicate():
get:
return attributes
set(val):
Expand Down
6 changes: 3 additions & 3 deletions scripts/components/chest_component.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class_name ChestComponent
extends EntityComponent
extends SKEntityComponent


## Optionally refreshing inventories.
Expand Down Expand Up @@ -35,7 +35,7 @@ func _check_should_restore() -> void:
func clear() -> void:
var ic:InventoryComponent = parent_entity.get_component("InventoryComponent")
for i:StringName in ic.inventory:
EntityManager.instance.remove_entity(i)
SKEntityManager.instance.remove_entity(i)
ic.inventory.clear() # Doing this instead of the remove item function since looping and removing stuff is bad and I don't need the signal
ic.currencies.clear()

Expand All @@ -51,7 +51,7 @@ func reroll() -> void:
item.item_owner = owner_id
item.ref_id = preload("res://addons/skelerealms/scripts/vendor/uuid.gd").v4()

var e:Entity = EntityManager.instance.add_entity(item)
var e:SKEntity = SKEntityManager.instance.add_entity(item)
ic.add_to_inventory(e.name)

ic.currencies = res.currencies
4 changes: 2 additions & 2 deletions scripts/components/covens_component.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class_name CovensComponent
extends EntityComponent
## Allows an Entity to be part of a [Coven].
extends SKEntityComponent
## Allows an SKEntity to be part of a [Coven].
## Covens in this context are analagous to Bethesda games' Factions- groups of NPCs that behave in a similar way.
## Coven membership is also reflected in groups that the entity is in.

Expand Down
2 changes: 1 addition & 1 deletion scripts/components/damageable_component.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class_name DamageableComponent
extends EntityComponent
extends SKEntityComponent
## Allows an entity to be damaged.


Expand Down
2 changes: 1 addition & 1 deletion scripts/components/effects_component.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class_name EffectsComponent
extends EntityComponent
extends SKEntityComponent


## This component governs active effects on this entity.
Expand Down
4 changes: 2 additions & 2 deletions scripts/components/equipment_component.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class_name EquipmentComponent
extends EntityComponent
extends SKEntityComponent


var equipment_slot:Dictionary
Expand All @@ -18,7 +18,7 @@ func _ready() -> void:

func equip(item:StringName, slot:EquipmentSlots.Slots, silent:bool = false) -> bool:
# Get component
var e = EntityManager.instance.get_entity(item)
var e = SKEntityManager.instance.get_entity(item)
if not e:
return false
# Get item component
Expand Down
2 changes: 1 addition & 1 deletion scripts/components/goap_component.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class_name GOAPComponent
extends EntityComponent
extends SKEntityComponent
## Planner for [GOAPAction]s that creates action sequences to complete a set of [Objective]s.


Expand Down
2 changes: 1 addition & 1 deletion scripts/components/interactive_component.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class_name InteractiveComponent
extends EntityComponent
extends SKEntityComponent
## Handles interactions on an entity

## Emitted when this entity is interacted with.
Expand Down
6 changes: 3 additions & 3 deletions scripts/components/inventory_component.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class_name InventoryComponent
extends EntityComponent
extends SKEntityComponent
## Keeps track of an inventory.

## The RefIDs of the items in the inventory.
Expand Down Expand Up @@ -28,7 +28,7 @@ func _ready() -> void:

## Add an item to the inventory.
func add_to_inventory(id:String):
var e = EntityManager.instance.get_entity(id)
var e = SKEntityManager.instance.get_entity(id)
if e:
var ic = e.get_component("ItemComponent")
if ic:
Expand Down Expand Up @@ -74,7 +74,7 @@ func _clamp_money(currency:StringName):
func count_item_by_data(data_id:String) -> int:
var amount: int = 0
for i in inventory:
var ic:ItemComponent = EntityManager.instance.get_entity(i).get_component("ItemComponent")
var ic:ItemComponent = SKEntityManager.instance.get_entity(i).get_component("ItemComponent")
if ic.data.id == data_id:
amount += 1
return amount
Expand Down
17 changes: 9 additions & 8 deletions scripts/components/item_component.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class_name ItemComponent
extends EntityComponent
extends SKEntityComponent
## Keeps track of item data


Expand Down Expand Up @@ -36,11 +36,12 @@ var item_owner:StringName = NONE:
# TODO: Determine using worth and owner relationships
$"../InteractiveComponent".interact_verb = "STEAL"
var stolen:bool ## If this has been stolen or not.
var durability:float ## This item's durability, if your game has condition/durability mechanics like Fallout or Morrowind.


## Shorthand to get an item component for an entity by ID.
static func get_item_component(id:StringName) -> ItemComponent:
var eop = EntityManager.instance.get_entity(id)
var eop = SKEntityManager.instance.get_entity(id)
if not eop:
return null
var icop = eop.get_component("ItemComponent")
Expand Down Expand Up @@ -89,15 +90,15 @@ func _despawn():

func _process(delta):
if in_inventory:
parent_entity.position = EntityManager.instance.get_entity(contained_inventory).position
parent_entity.world = EntityManager.instance.get_entity(contained_inventory).world
parent_entity.position = SKEntityManager.instance.get_entity(contained_inventory).position
parent_entity.world = SKEntityManager.instance.get_entity(contained_inventory).world


## Move this to another inventory. Adds and removes the item from the inventories.
func move_to_inventory(refID:StringName):
# remove from inventory if we are in one
if in_inventory:
EntityManager.instance\
SKEntityManager.instance\
.get_entity(contained_inventory)\
.get_component("InventoryComponent")\
.remove_from_inventory(parent_entity.name)
Expand All @@ -108,7 +109,7 @@ func move_to_inventory(refID:StringName):
return

# add to new inventory
EntityManager.instance\
SKEntityManager.instance\
.get_entity(refID)\
.get_component("InventoryComponent")\
.add_to_inventory(parent_entity.name)
Expand All @@ -121,12 +122,12 @@ func move_to_inventory(refID:StringName):

## Drop this on the ground.
func drop():
var e:Entity = EntityManager.instance.get_entity(contained_inventory)
var e:SKEntity = SKEntityManager.instance.get_entity(contained_inventory)
var drop_dir:Quaternion = e.rotation
print(drop_dir.get_euler().normalized() * DROP_DISTANCE)
# This whole bit is genericizing dropping the item in front of the player. It's meant to be used with the player, it should work with anything with a puppet.
if in_inventory:
EntityManager.instance.get_entity(contained_inventory)\
SKEntityManager.instance.get_entity(contained_inventory)\
.get_component(&"InventoryComponent")\
.remove_from_inventory(parent_entity.name)

Expand Down
2 changes: 1 addition & 1 deletion scripts/components/marker_component.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class_name MarkerComponent
extends EntityComponent
extends SKEntityComponent
## Component tag for [WorldMarker]s.


Expand Down
2 changes: 1 addition & 1 deletion scripts/components/navigator_component.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class_name NavigatorComponent
extends EntityComponent
extends SKEntityComponent
## Handles finding paths through the granular navigation system. See [NavigationMaster].


Expand Down
Loading

0 comments on commit fbb8782

Please sign in to comment.