From 0c2a075e5a7653c6f906258f6d31e9b88ba1c97d Mon Sep 17 00:00:00 2001 From: Joa2 Date: Thu, 16 Nov 2023 16:10:09 +0100 Subject: [PATCH] Pathfinding networking works now --- Client/autoloads/WorldManager.gd | 12 ++++++-- Client/region/Region.gd | 6 ++-- Client/region/SuperUnit.gd | 6 ++-- Client/region/Unit.gd | 3 +- Server/autoloads/PlayerManager.gd | 46 ++++++++++++++----------------- Server/autoloads/WorldManager.gd | 6 ++++ 6 files changed, 42 insertions(+), 37 deletions(-) diff --git a/Client/autoloads/WorldManager.gd b/Client/autoloads/WorldManager.gd index a82b6ec..25fc3d2 100644 --- a/Client/autoloads/WorldManager.gd +++ b/Client/autoloads/WorldManager.gd @@ -233,9 +233,8 @@ func _load_worldmap(): func requestTiles(unit = null): - print("a") rpc_id(1, 'requestTiles', unit) - + signal receiveTiles remote func receiveTiles(bundledTileStuff): @@ -246,8 +245,15 @@ remote func receiveTiles(bundledTileStuff): func requestUnits(): rpc_id(1, 'requestUnits') - + signal receiveUnits remote func receiveUnits(newBoardUnits): emit_signal("receiveUnits", newBoardUnits) + +func requestMove(route, unitID): + rpc_id(1, 'requestMove', route, unitID) + +func endTurn(): + rpc_id(1, 'endTurn') + diff --git a/Client/region/Region.gd b/Client/region/Region.gd index ff9d3fb..5a49f15 100644 --- a/Client/region/Region.gd +++ b/Client/region/Region.gd @@ -125,11 +125,11 @@ func hoverPath(coord = hoveredCoords):#this gets the hovered tile and tells the func nextRound():#this sends a nextRound signal to units on the board and refreshes their ap. resetPathing() - rpc_id(1, 'nextRound') +# rpc_id(1, 'nextRound') func executePath(route, vertices):#this takes the current selected route and tells the unit to execute it/ follow the selected route. - rpc_id(1, 'moveUnit', route, selectedUnit.id) + WorldManager.requestMove(route,selectedUnit.id) var convertedRoute = [] for coords in route: convertedRoute.append($TileMap.map_to_world(coords)) @@ -375,7 +375,7 @@ func clickSuperPath(): executeSuperPath(route, routeVertices) func executeSuperPath(route, vertices):#this takes the current selected route and tells the unit to execute it/ follow the selected route. - rpc_id(1, 'moveUnit', route, selectedUnit.id) + WorldManager.requestMove(route,selectedUnit.id) var convertedRoute = [] for coords in route: convertedRoute.append($TileMap.map_to_world(coords)) diff --git a/Client/region/SuperUnit.gd b/Client/region/SuperUnit.gd index f9399b4..c2b5d19 100644 --- a/Client/region/SuperUnit.gd +++ b/Client/region/SuperUnit.gd @@ -32,15 +32,15 @@ func snapToPosition(): func _input(event):#this selects unit and signals the selected node to the main node if event is InputEventMouseButton and Input.is_action_just_released("ui_right_mouse_button")and isMoving==false: var localEvent = (self.make_input_local(event)) + print(localEvent.position) + print(self.position) if isSelected== true: emit_signal("unitSelected",null) isSelected = false - if localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < self.position.x + 128 and localEvent.position.y < self.position.y + 128: - print("superunit") + if localEvent.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < self.position.x + 64 and localEvent.position.y < self.position.y + 64: if isSelected== false: emit_signal("unitSelected",self) isSelected = true - return func moveOnPath(route:Array):#this coordinates the movement/animation isMoving=true diff --git a/Client/region/Unit.gd b/Client/region/Unit.gd index 822a228..9448556 100644 --- a/Client/region/Unit.gd +++ b/Client/region/Unit.gd @@ -28,10 +28,9 @@ func _input(event):#this selects unit and signals the selected node to the main if isSelected== true: emit_signal("unitSelected",null) isSelected = false - elif event.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < self.position.x + 64 and localEvent.position.y < self.position.y + 64: + elif event.position.x > 0 and localEvent.position.y > 0 and localEvent.position.x < self.position.x + 32 and localEvent.position.y < self.position.y + 32: emit_signal("unitSelected",self) isSelected = true - return func moveOnPath(route:Array):#this coordinates the movement/animation isMoving=true diff --git a/Server/autoloads/PlayerManager.gd b/Server/autoloads/PlayerManager.gd index 52a244a..e06d09b 100644 --- a/Server/autoloads/PlayerManager.gd +++ b/Server/autoloads/PlayerManager.gd @@ -10,7 +10,26 @@ var player:Array = [] var knownPlayers = {} var pathToPlayers = 'user://users/' var clients_factions = {} #used to recognize if networkrequest are allowed to do an action {networkid:factionname} -var factions = {} +var factions = { + playerFaction = { + diplomacy={ + enemies =['enemyFaction'], + allies=['allyFaction'] + } + }, + allyFaction = { + diplomacy={ + enemies =[], + allies=['playerFaction','enemyFaction'] + } + }, + enemyFaction = { + diplomacy={ + enemies =['playerFaction',], + allies=['allyFaction'] + } + } + } var diplomacyStates = {'neutral': 1, 'own' : 2, 'enemies':3, "allies":4} @@ -34,31 +53,6 @@ func checkdiplo(factionA, factionB): return response return response -#returns neutral for neutral, allies for allies, own for own and enemies for enemies -func checkDiplo(faction): - var data = authcache['response'] - var authed = data['found'] - var response = 'neutral' - if faction==data['faction']: - response = 'own' - return response - elif authed: - if data.has('factiondata'): - var factiondata = data['factiondata'] - if factiondata.has('diplomacy'): - var diplo = factiondata['diplomacy'] - for key in diplo: - if diplo[key].has(faction): - response = key - return response -# print("checking diplo") -# print(data, faction) -# print("considered ", response) -# print(" ") -# print("illegal move attempt") - return response - #var diplo = factiondata['diplomacy'] - pass func confirmFaction(id, factionname): diff --git a/Server/autoloads/WorldManager.gd b/Server/autoloads/WorldManager.gd index ec31738..b97f025 100644 --- a/Server/autoloads/WorldManager.gd +++ b/Server/autoloads/WorldManager.gd @@ -216,3 +216,9 @@ remote func requestUnits(regionId = 123): var clientId = get_tree().get_rpc_sender_id() var boardUnits = regions[regionId].requestUnits() rpc_id(clientId, 'receiveUnits', boardUnits) + +remote func requestMove(route, unitID, regionId = 123): + regions[regionId].moveUnit(route, unitID) + +remote func endTurn(regionId = 123): + regions[regionId].nextRound()