2020-04-18 14:35:28 +02:00
|
|
|
extends ESSEntitySpawner
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2019-11-21 13:10:00 +01:00
|
|
|
# Copyright Péter Magyar relintai@gmail.com
|
|
|
|
# MIT License, functionality from this class needs to be protable to the entity spell system
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2021-04-15 11:52:32 +02:00
|
|
|
# Copyright (c) 2019-2021 Péter Magyar
|
2019-12-01 23:21:48 +01:00
|
|
|
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
# copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
|
2019-12-02 19:19:49 +01:00
|
|
|
export(PackedScene) var player_display_scene : PackedScene
|
|
|
|
export(String) var spawn_parent_path : String = "/root/Main"
|
|
|
|
export(int) var default_level_override : int = 0
|
2019-11-20 13:51:26 +01:00
|
|
|
|
|
|
|
var _spawn_parent : Node = null
|
|
|
|
|
|
|
|
var _next_entity_guid : int = 0
|
|
|
|
|
2021-08-31 00:40:45 +02:00
|
|
|
var _debug : bool = false
|
|
|
|
|
2019-11-20 13:51:26 +01:00
|
|
|
func _ready():
|
2020-04-18 14:35:28 +02:00
|
|
|
# get_scene_tree().multiplayer.connect("network_peer_packet", self, "on_network_peer_packet")
|
2020-02-03 18:37:11 +01:00
|
|
|
|
2020-04-18 14:35:28 +02:00
|
|
|
# ProfileManager.load()
|
|
|
|
# ESS.load_resource_db()
|
|
|
|
# ESS.get_resource_db().load_all()
|
|
|
|
# ESS.connect("on_entity_spawn_requested", self, "on_entity_spawn_requested")
|
2020-02-01 11:20:05 +01:00
|
|
|
|
2019-11-20 13:51:26 +01:00
|
|
|
# get_tree().connect("network_peer_connected", self, "_player_connected")
|
|
|
|
# get_tree().connect("network_peer_disconnected", self, "_player_disconnected")
|
|
|
|
# get_tree().connect("connected_to_server", self, "_connected_ok")
|
|
|
|
# get_tree().connect("connection_failed", self, "_connected_fail")
|
|
|
|
# get_tree().connect("server_disconnected", self, "_server_disconnected")
|
2020-04-18 14:35:28 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
func on_network_peer_packet(id : int, packet : PoolByteArray) ->void:
|
|
|
|
#todo
|
|
|
|
pass
|
2019-11-20 13:51:26 +01:00
|
|
|
|
|
|
|
func spawn_for(player : Entity, target: Entity) -> void:
|
2022-06-11 18:15:31 +02:00
|
|
|
PLogger.log_message("spawnfor " + target.name)
|
2021-08-31 00:40:45 +02:00
|
|
|
|
|
|
|
if _debug:
|
|
|
|
print("spawnfor " + player.name + " - " + target.name)
|
|
|
|
|
|
|
|
if player == target:
|
|
|
|
if _debug:
|
|
|
|
print("spawn_for: player == target!")
|
|
|
|
return
|
|
|
|
|
2021-08-30 00:35:27 +02:00
|
|
|
rpc_id(player.get_network_master(), "creceive_spawn_for", to_json(target.to_dict()), target.name, target.get_transform_3d().origin)
|
2019-11-20 13:51:26 +01:00
|
|
|
|
|
|
|
func despawn_for(player : Entity, target: Entity) -> void:
|
2022-06-11 18:15:31 +02:00
|
|
|
PLogger.log_message("despawnfor " + target.name)
|
2021-08-31 00:40:45 +02:00
|
|
|
|
|
|
|
if _debug:
|
|
|
|
print("despawnfor " + target.name)
|
|
|
|
|
2021-04-21 21:55:15 +02:00
|
|
|
rpc_id(player.get_network_master(), "creceive_despawn_for", target.get_path())
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2020-02-03 18:37:11 +01:00
|
|
|
remote func creceive_spawn_for(data: String, global_name : String, position: Vector3) -> Entity:
|
|
|
|
var createinfo : EntityCreateInfo = EntityCreateInfo.new()
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2021-08-31 00:40:45 +02:00
|
|
|
createinfo.node_name = global_name
|
2020-02-03 18:37:11 +01:00
|
|
|
createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER
|
|
|
|
createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_NETWORKED
|
|
|
|
createinfo.serialized_data = parse_json(data)
|
|
|
|
createinfo.transform.origin = position
|
|
|
|
|
2020-04-14 17:04:59 +02:00
|
|
|
ESS.request_entity_spawn(createinfo)
|
2020-02-03 18:37:11 +01:00
|
|
|
|
2022-06-11 18:15:31 +02:00
|
|
|
PLogger.log_message("Player spawned ")
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2021-08-31 00:40:45 +02:00
|
|
|
if _debug:
|
|
|
|
print("creceive_spawn_for " + global_name)
|
|
|
|
|
2020-02-03 18:37:11 +01:00
|
|
|
return createinfo.created_entity
|
2019-11-20 13:51:26 +01:00
|
|
|
|
|
|
|
remote func creceive_despawn_for(path : NodePath) -> void:
|
|
|
|
# print("recdespawnfor " + path)
|
2020-09-22 14:00:57 +02:00
|
|
|
var ent = get_tree().root.get_node_or_null(path)
|
2019-11-20 13:51:26 +01:00
|
|
|
|
|
|
|
if ent:
|
|
|
|
ent.queue_free()
|
|
|
|
|
2021-08-30 00:35:27 +02:00
|
|
|
remote func spawn_owned_player(data : String, position : Vector3) -> Entity:
|
2020-02-03 18:37:11 +01:00
|
|
|
var createinfo : EntityCreateInfo = EntityCreateInfo.new()
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2021-08-31 00:40:45 +02:00
|
|
|
#createinfo.guid = _next_entity_guid
|
|
|
|
#_next_entity_guid += 1
|
|
|
|
#createinfo.node_name = global_name
|
2021-08-29 21:39:51 +02:00
|
|
|
createinfo.network_owner = multiplayer.get_network_unique_id()
|
2020-04-18 14:35:28 +02:00
|
|
|
# createinfo.player_name = ""
|
2020-02-03 18:37:11 +01:00
|
|
|
createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER
|
|
|
|
createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_PLAYER
|
|
|
|
createinfo.serialized_data = parse_json(data)
|
|
|
|
createinfo.transform.origin = position
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2020-04-14 17:04:59 +02:00
|
|
|
ESS.request_entity_spawn(createinfo)
|
2021-08-30 00:35:27 +02:00
|
|
|
var e : Entity = createinfo.created_entity
|
2021-08-31 00:40:45 +02:00
|
|
|
#e.set_network_master(multiplayer.get_network_unique_id())
|
2021-08-30 00:35:27 +02:00
|
|
|
|
2021-08-31 00:40:45 +02:00
|
|
|
if _debug:
|
|
|
|
print("spawn_owned_player " + e.name)
|
|
|
|
|
2022-06-11 18:15:31 +02:00
|
|
|
PLogger.log_message("Player spawned ")
|
2020-02-03 18:37:11 +01:00
|
|
|
|
2021-08-30 00:35:27 +02:00
|
|
|
return e
|
2019-11-20 13:51:26 +01:00
|
|
|
|
|
|
|
func load_player(file_name : String, position : Vector3, network_owner : int) -> Entity:
|
2020-02-03 18:37:11 +01:00
|
|
|
var createinfo : EntityCreateInfo = EntityCreateInfo.new()
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2021-08-31 00:40:45 +02:00
|
|
|
#createinfo.guid = _next_entity_guid
|
|
|
|
#_next_entity_guid += 1
|
2021-08-29 21:39:51 +02:00
|
|
|
createinfo.network_owner = network_owner
|
2020-04-18 14:35:28 +02:00
|
|
|
# createinfo.player_name = name
|
2020-02-03 18:37:11 +01:00
|
|
|
createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER
|
|
|
|
createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_PLAYER
|
|
|
|
createinfo.serialized_data = load_file(file_name)
|
|
|
|
createinfo.transform.origin = position
|
2020-03-12 13:50:14 +01:00
|
|
|
createinfo.networked = false
|
2022-06-11 18:15:31 +02:00
|
|
|
PLogger.log_message("Player spawned ")
|
2021-04-21 21:55:15 +02:00
|
|
|
ESS.request_entity_spawn(createinfo)
|
2021-08-31 00:40:45 +02:00
|
|
|
|
|
|
|
if _debug:
|
|
|
|
print("load_player " + file_name)
|
2021-04-21 21:55:15 +02:00
|
|
|
|
|
|
|
return createinfo.created_entity
|
|
|
|
|
|
|
|
func load_uploaded_character(data : String, position : Vector3, network_owner : int) -> Entity:
|
2021-08-31 00:40:45 +02:00
|
|
|
if _debug:
|
|
|
|
print("load_uploaded_character ")
|
|
|
|
|
|
|
|
rpc_id(network_owner, "spawn_owned_player", data, position)
|
|
|
|
|
2021-04-21 21:55:15 +02:00
|
|
|
var createinfo : EntityCreateInfo = EntityCreateInfo.new()
|
2021-08-29 21:39:51 +02:00
|
|
|
|
2021-08-31 00:40:45 +02:00
|
|
|
#createinfo.guid = _next_entity_guid
|
|
|
|
#_next_entity_guid += 1
|
2021-08-29 21:39:51 +02:00
|
|
|
createinfo.network_owner = network_owner
|
2021-04-21 21:55:15 +02:00
|
|
|
# createinfo.player_name = name
|
|
|
|
createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER
|
2021-04-21 22:00:06 +02:00
|
|
|
createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_NETWORKED
|
2021-04-21 21:55:15 +02:00
|
|
|
createinfo.serialized_data = parse_json(data)
|
|
|
|
createinfo.transform.origin = position
|
|
|
|
createinfo.networked = false
|
2022-06-11 18:15:31 +02:00
|
|
|
PLogger.log_message("Player spawned ")
|
2020-04-14 17:04:59 +02:00
|
|
|
ESS.request_entity_spawn(createinfo)
|
2021-08-30 00:35:27 +02:00
|
|
|
var e : Entity = createinfo.created_entity
|
2021-08-31 00:40:45 +02:00
|
|
|
|
|
|
|
#e.set_network_master(network_owner)
|
|
|
|
#e.centity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER
|
2021-08-30 00:35:27 +02:00
|
|
|
|
|
|
|
return e
|
2019-11-20 13:51:26 +01:00
|
|
|
|
|
|
|
func spawn_player_for_menu(class_id : int, name : String, parent : Node) -> Entity:
|
|
|
|
var createinfo : EntityCreateInfo = EntityCreateInfo.new()
|
2020-04-18 20:58:43 +02:00
|
|
|
var cls : EntityData = ESS.resource_db.get_entity_data(class_id)
|
2020-04-19 18:27:38 +02:00
|
|
|
var class_profile : ClassProfile = ProfileManager.getc_player_profile().get_class_profile(cls.resource_path)
|
2020-02-03 18:37:11 +01:00
|
|
|
|
2020-03-20 03:32:44 +01:00
|
|
|
var level : int = 1
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2020-02-03 18:37:11 +01:00
|
|
|
if default_level_override > 0:
|
|
|
|
level = default_level_override
|
|
|
|
|
|
|
|
createinfo.class_id = class_id
|
2019-11-20 13:51:26 +01:00
|
|
|
createinfo.entity_data = cls
|
|
|
|
createinfo.player_name = name
|
2020-07-10 15:25:32 +02:00
|
|
|
createinfo.level = level
|
|
|
|
createinfo.xp = 0
|
|
|
|
# createinfo.class_xp = class_profile.xp
|
2019-11-20 13:51:26 +01:00
|
|
|
createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER
|
2020-02-03 18:37:11 +01:00
|
|
|
createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_DISPLAY
|
|
|
|
createinfo.networked = false
|
|
|
|
createinfo.parent_path = parent.get_path()
|
2019-12-02 19:19:49 +01:00
|
|
|
|
2020-04-14 17:04:59 +02:00
|
|
|
ESS.request_entity_spawn(createinfo)
|
2020-02-03 18:37:11 +01:00
|
|
|
|
2022-06-11 18:15:31 +02:00
|
|
|
PLogger.log_message("Player spawned " + str(createinfo))
|
2020-02-03 18:37:11 +01:00
|
|
|
|
|
|
|
return createinfo.created_entity
|
|
|
|
|
|
|
|
func spawn_display_player(file_name : String, node_path : NodePath) -> Entity:
|
|
|
|
var createinfo : EntityCreateInfo = EntityCreateInfo.new()
|
2019-12-02 19:19:49 +01:00
|
|
|
|
2021-08-31 00:40:45 +02:00
|
|
|
#createinfo.guid = _next_entity_guid
|
|
|
|
#_next_entity_guid += 1
|
2020-04-18 14:35:28 +02:00
|
|
|
# createinfo.player_name = name
|
2020-02-03 18:37:11 +01:00
|
|
|
createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER
|
|
|
|
createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_DISPLAY
|
|
|
|
createinfo.serialized_data = load_file(file_name)
|
|
|
|
createinfo.parent_path = node_path
|
2019-12-02 19:19:49 +01:00
|
|
|
|
2022-06-11 18:15:31 +02:00
|
|
|
PLogger.log_message("Player spawned ")
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2020-04-14 17:04:59 +02:00
|
|
|
ESS.request_entity_spawn(createinfo)
|
2020-02-03 18:37:11 +01:00
|
|
|
|
|
|
|
return createinfo.created_entity
|
2019-11-20 13:51:26 +01:00
|
|
|
|
|
|
|
func spawn_networked_player(class_id : int, position : Vector3, name : String, node_name : String, sid : int) -> Entity:
|
|
|
|
var createinfo : EntityCreateInfo = EntityCreateInfo.new()
|
2020-04-18 14:35:28 +02:00
|
|
|
var cls : EntityData = ESS.resource_db.get_player_character_data(class_id)
|
2020-02-01 15:44:22 +01:00
|
|
|
var class_profile : ClassProfile = ProfileManager.get_class_profile(class_id)
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2019-12-02 19:19:49 +01:00
|
|
|
var level : int = class_profile.level
|
|
|
|
|
|
|
|
if default_level_override > 0:
|
|
|
|
level = default_level_override
|
|
|
|
|
2020-02-03 18:37:11 +01:00
|
|
|
createinfo.class_id = class_id
|
|
|
|
createinfo.entity_data = cls
|
2021-08-31 00:40:45 +02:00
|
|
|
createinfo.node_name = node_name
|
2020-07-10 15:25:32 +02:00
|
|
|
createinfo.level = 1
|
|
|
|
# createinfo.class_level = level
|
|
|
|
createinfo.xp = 0
|
|
|
|
# createinfo.class_xp = class_profile.xp
|
2020-02-03 18:37:11 +01:00
|
|
|
createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER
|
|
|
|
createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_NETWORKED
|
|
|
|
createinfo.network_owner = sid
|
|
|
|
createinfo.transform.origin = position
|
|
|
|
createinfo.networked = false
|
|
|
|
createinfo.transform.origin = position
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2020-04-14 17:04:59 +02:00
|
|
|
ESS.request_entity_spawn(createinfo)
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2022-06-11 18:15:31 +02:00
|
|
|
PLogger.log_message("Player spawned " + str(createinfo))
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2020-02-03 18:37:11 +01:00
|
|
|
return createinfo.created_entity
|
2019-11-20 13:51:26 +01:00
|
|
|
|
|
|
|
func spawn_player(class_id : int, position : Vector3, name : String, node_name : String, network_owner : int) -> Entity:
|
|
|
|
var createinfo : EntityCreateInfo = EntityCreateInfo.new()
|
2020-04-18 14:35:28 +02:00
|
|
|
var cls : EntityData = ESS.resource_db.get_player_character_data(class_id)
|
2020-02-01 15:44:22 +01:00
|
|
|
var class_profile : ClassProfile = ProfileManager.get_class_profile(class_id)
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2019-12-02 19:19:49 +01:00
|
|
|
var level : int = class_profile.level
|
2020-04-18 21:27:22 +02:00
|
|
|
|
2019-12-02 19:19:49 +01:00
|
|
|
if default_level_override > 0:
|
|
|
|
level = default_level_override
|
|
|
|
|
2020-02-03 18:37:11 +01:00
|
|
|
createinfo.class_id = class_id
|
|
|
|
createinfo.entity_data = cls
|
2021-08-31 00:40:45 +02:00
|
|
|
createinfo.node_name = node_name
|
2020-07-10 15:25:32 +02:00
|
|
|
createinfo.level = 1
|
|
|
|
# createinfo.class_level = level
|
|
|
|
createinfo.xp = 0
|
|
|
|
# createinfo.class_xp = class_profile.xp
|
2020-02-03 18:37:11 +01:00
|
|
|
createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER
|
|
|
|
createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_PLAYER
|
|
|
|
createinfo.network_owner = network_owner
|
|
|
|
createinfo.transform.origin = position
|
|
|
|
createinfo.networked = false
|
|
|
|
|
2020-04-14 17:04:59 +02:00
|
|
|
ESS.request_entity_spawn(createinfo)
|
2019-12-02 19:19:49 +01:00
|
|
|
|
2022-06-11 18:15:31 +02:00
|
|
|
PLogger.log_message("Player spawned " + str(createinfo))
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2020-02-03 18:37:11 +01:00
|
|
|
return createinfo.created_entity
|
|
|
|
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2020-02-16 16:23:45 +01:00
|
|
|
func spawn_mob(class_id : int, level : int, position : Vector3) -> void:
|
2019-11-20 13:51:26 +01:00
|
|
|
var createinfo : EntityCreateInfo = EntityCreateInfo.new()
|
|
|
|
|
2020-04-14 17:04:59 +02:00
|
|
|
var cls : EntityData = ESS.get_resource_db().get_entity_data(class_id)
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2020-02-03 18:37:11 +01:00
|
|
|
createinfo.class_id = class_id
|
2019-11-20 13:51:26 +01:00
|
|
|
createinfo.entity_data = cls
|
2021-08-31 00:40:45 +02:00
|
|
|
#createinfo.node_name = "Mob"
|
2020-07-10 15:25:32 +02:00
|
|
|
createinfo.level = level
|
|
|
|
# createinfo.class_level = level
|
2019-12-02 19:19:49 +01:00
|
|
|
createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_AI
|
2020-02-03 18:37:11 +01:00
|
|
|
createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_AI
|
|
|
|
createinfo.transform.origin = position
|
2019-12-02 19:19:49 +01:00
|
|
|
|
2020-04-14 17:04:59 +02:00
|
|
|
ESS.request_entity_spawn_deferred(createinfo)
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2022-06-11 18:15:31 +02:00
|
|
|
PLogger.log_message("Mob spawned " + str(createinfo))
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2020-02-16 16:23:45 +01:00
|
|
|
#return createinfo.created_entity
|
2020-02-03 18:37:11 +01:00
|
|
|
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2020-04-18 14:35:28 +02:00
|
|
|
func _request_entity_spawn(createinfo : EntityCreateInfo):
|
2019-11-20 13:51:26 +01:00
|
|
|
var entity_node : Entity = null
|
|
|
|
|
2020-02-03 18:37:11 +01:00
|
|
|
if createinfo.entity_player_type == EntityEnums.ENTITY_PLAYER_TYPE_DISPLAY:
|
|
|
|
entity_node = player_display_scene.instance()
|
2019-11-20 13:51:26 +01:00
|
|
|
else:
|
2020-02-03 18:37:11 +01:00
|
|
|
if not createinfo.networked:
|
|
|
|
if createinfo.entity_controller == EntityEnums.ENITIY_CONTROLLER_PLAYER:
|
2020-04-24 14:41:31 +02:00
|
|
|
entity_node = PlayerGD.new()
|
2020-02-03 18:37:11 +01:00
|
|
|
else:
|
2020-04-24 14:41:31 +02:00
|
|
|
entity_node = MobGD.new()
|
2020-02-03 18:37:11 +01:00
|
|
|
else:
|
2020-04-24 14:41:31 +02:00
|
|
|
entity_node = NetworkedPlayerGD.new()
|
2019-11-20 13:51:26 +01:00
|
|
|
|
|
|
|
if entity_node == null:
|
|
|
|
print("EntityManager: entity node is null")
|
|
|
|
return null
|
|
|
|
|
2020-04-24 13:48:54 +02:00
|
|
|
entity_node.set_transform_3d(createinfo.transform)
|
2021-08-31 00:40:45 +02:00
|
|
|
|
2020-02-03 18:37:11 +01:00
|
|
|
if (createinfo.parent_path == ""):
|
2020-04-18 14:35:28 +02:00
|
|
|
if _spawn_parent == null:
|
2020-09-22 14:00:57 +02:00
|
|
|
_spawn_parent = get_tree().root.get_node(spawn_parent_path)
|
2020-04-18 14:35:28 +02:00
|
|
|
|
2020-02-03 18:37:11 +01:00
|
|
|
if _spawn_parent.current_scene != null:
|
|
|
|
var spawn_parent = _spawn_parent.current_scene
|
2019-11-20 13:51:26 +01:00
|
|
|
|
2020-02-03 18:37:11 +01:00
|
|
|
spawn_parent.add_child(entity_node)
|
|
|
|
else:
|
2020-09-22 14:00:57 +02:00
|
|
|
get_tree().root.get_node(createinfo.parent_path).add_child(entity_node)
|
2021-08-31 00:40:45 +02:00
|
|
|
|
|
|
|
#print(entity_node.name)
|
|
|
|
|
|
|
|
if createinfo.network_owner == 0:
|
|
|
|
if createinfo.node_name == "":
|
|
|
|
entity_node.name = "Entity_" + str(_next_entity_guid)
|
|
|
|
_next_entity_guid += 1
|
|
|
|
else:
|
|
|
|
entity_node.name = createinfo.node_name
|
|
|
|
else:
|
|
|
|
entity_node.name = "Player_" + str(createinfo.network_owner)
|
|
|
|
|
|
|
|
#print(entity_node.name)
|
|
|
|
|
2020-02-03 18:37:11 +01:00
|
|
|
entity_node.setup(createinfo)
|
|
|
|
|
|
|
|
createinfo.created_entity = entity_node
|
2019-11-20 13:51:26 +01:00
|
|
|
|
|
|
|
func _player_connected(id):
|
|
|
|
pass # Will go unused; not useful here.
|
|
|
|
|
|
|
|
func _player_disconnected(id):
|
|
|
|
#player_info.erase(id) # Erase player from info.
|
|
|
|
pass
|
|
|
|
|
|
|
|
func _connected_ok():
|
|
|
|
# Only called on clients, not server. Send my ID and info to all the other peers.
|
|
|
|
#rpc("register_player", get_tree().get_network_unique_id(), my_info)
|
|
|
|
pass
|
|
|
|
|
|
|
|
func _server_disconnected():
|
|
|
|
pass # Server kicked us; show error and abort.
|
|
|
|
|
|
|
|
func _connected_fail():
|
|
|
|
pass # Could not even connect to server; abort.
|
|
|
|
|
|
|
|
remote func register_player(id, info):
|
|
|
|
# Store the info
|
|
|
|
# player_info[id] = info
|
|
|
|
# If I'm the server, let the new guy know about existing players.
|
|
|
|
# if get_tree().is_network_server():
|
|
|
|
# # Send my info to new player
|
|
|
|
# rpc_id(id, "register_player", 1, my_info)
|
|
|
|
# # Send the info of existing players
|
|
|
|
# for peer_id in player_info:
|
|
|
|
# rpc_id(id, "register_player", peer_id, player_info[peer_id])
|
|
|
|
|
|
|
|
# Call function to update lobby UI here
|
|
|
|
pass
|
|
|
|
|
|
|
|
func load_file(file_name : String) -> Dictionary:
|
|
|
|
|
|
|
|
var f : File = File.new()
|
|
|
|
|
|
|
|
if f.open("user://characters/" + file_name, File.READ) == OK:
|
|
|
|
var st : String = f.get_as_text()
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
var json_err : String = validate_json(st)
|
|
|
|
|
|
|
|
if json_err != "":
|
2022-06-11 18:15:31 +02:00
|
|
|
PLogger.log_error("Save corrupted! " + file_name)
|
|
|
|
PLogger.log_error(json_err)
|
2019-11-20 13:51:26 +01:00
|
|
|
return Dictionary()
|
|
|
|
|
|
|
|
var p = parse_json(st)
|
|
|
|
|
|
|
|
if typeof(p) != TYPE_DICTIONARY:
|
2022-06-11 18:15:31 +02:00
|
|
|
PLogger.log_error("Save corrupted! Not Dict! " + file_name)
|
2019-11-20 13:51:26 +01:00
|
|
|
return Dictionary()
|
|
|
|
|
|
|
|
if p is Dictionary:
|
|
|
|
return p as Dictionary
|
|
|
|
|
|
|
|
return Dictionary()
|
|
|
|
|
|
|
|
func save_player(player: Entity, file_name : String) -> void:
|
|
|
|
var f : File = File.new()
|
|
|
|
|
|
|
|
if f.open("user://characters/" + file_name, File.WRITE) == OK:
|
|
|
|
f.store_string(to_json(player.to_dict()))
|
|
|
|
f.close()
|