From e9cf9b73a4e7b1925745abb6b1cf2ac4f008d96b Mon Sep 17 00:00:00 2001 From: STEINMETZ THOMAS <thomas.steinmetz2@etu.unistra.fr> Date: Tue, 14 Apr 2020 17:29:41 +0200 Subject: [PATCH] #125 fix spawn item with object --- server/autoloads/gamestate.gd | 4 ++-- server/entities/characters/player.gd | 7 +++--- server/entities/items/beer.gd | 34 +++++----------------------- server/entities/items/trumpet.gd | 22 +----------------- 4 files changed, 13 insertions(+), 54 deletions(-) diff --git a/server/autoloads/gamestate.gd b/server/autoloads/gamestate.gd index 2954893..ac65b48 100644 --- a/server/autoloads/gamestate.gd +++ b/server/autoloads/gamestate.gd @@ -15,7 +15,7 @@ const MAX_ITEMS = 5 var nbItemTotal:int = 0 var timer = null -var item_delay = 30 +var item_delay = 15 signal deleteItem var rng = RandomNumberGenerator.new() @@ -122,7 +122,7 @@ func spawnInitItem(): var i=rng.randi_range(0,len(listAvailableItem)-1) var position = get_node(GAMEPATH+"spawnCollection/spawn"+str(listAvailableItem[i]+1)).get_translation() var newitemScene:Object = itemScene.new(nbItemTotal,typeItem,position) - newitemScene.set_name("item"+str(newitemScene.get_instance_id())) + newitemScene.set_name("item"+str(newitemScene.id)) get_node(GAMEPATH+"itemCollection").add_child(newitemScene) self.connect("deleteItem",newitemScene,"on_timeout_complete") newitemScene.translate(position) diff --git a/server/entities/characters/player.gd b/server/entities/characters/player.gd index 786c22d..6bae220 100644 --- a/server/entities/characters/player.gd +++ b/server/entities/characters/player.gd @@ -192,9 +192,10 @@ mouseX:int, mouseY:int, itemInput:bool): # Pick and Drop Item if itemInput : print("input") - for node in get_node(GAMEPATH+"spawnCollection/"): - print("node :"+node.name()) -# node.nearItem() + var list = get_node(GAMEPATH+"itemCollection/").get_children() +# for i in list: +## print("node :"+str(i.id)) +# i.nearItem() pass diff --git a/server/entities/items/beer.gd b/server/entities/items/beer.gd index 735be7e..4824238 100644 --- a/server/entities/items/beer.gd +++ b/server/entities/items/beer.gd @@ -1,12 +1,13 @@ extends Area +const player: = preload("res://entities/characters/player.gd") + const GAMEPATH = "/root/game/" -const player: = preload("res://entities/characters/player.gd") var id:int -var typeItem: int -var position: Vector3 +var typeItem:int +var position:Vector3 func _init(id: int, typeItem: int, position:Vector3): @@ -14,35 +15,12 @@ func _init(id: int, typeItem: int, position:Vector3): self.typeItem = typeItem self.position = position - - + func nearItem(): var listBody = self.get_overlapping_bodies() print(listBody) -#var timer = null -#var beer_delay = 15 -# -#signal createNewItem - -#func _ready(): -# timer = Timer.new() -# timer.set_one_shot(true) -# timer.autostart = true -# timer.set_wait_time(beer_delay) -# timer.connect("timeout",self,"on_timeout_complete") -# get_node(GAMEPATH).add_child(timer) - - func on_timeout_complete(): -# timer.free() rpc("deleteItemClient") -# var x = self.name -# x.erase(0,4) -# x.to_int() -# print("x :",x) -# emit_signal("createNewItem",x) -# timer.stop() -# timer.queue_free() - queue_free() \ No newline at end of file + queue_free() diff --git a/server/entities/items/trumpet.gd b/server/entities/items/trumpet.gd index 22becae..4824238 100644 --- a/server/entities/items/trumpet.gd +++ b/server/entities/items/trumpet.gd @@ -19,28 +19,8 @@ func _init(id: int, typeItem: int, position:Vector3): func nearItem(): var listBody = self.get_overlapping_bodies() print(listBody) -#var timer = null -#var beer_delay = 15 -# -# -#func _ready(): -# timer = Timer.new() -# timer.set_one_shot(true) -# timer.autostart = true -# timer.set_wait_time(beer_delay) -# timer.connect("timeout",self,"on_timeout_complete") -# get_node(GAMEPATH).add_child(timer) - + func on_timeout_complete(): rpc("deleteItemClient") queue_free() - - - - - - -#func _on_beer_body_entered(body): -# if body is player: -# queue_free() -- GitLab