feat: user always play bottom
This commit is contained in:
parent
bebb7b467b
commit
2c4e9d90f3
5 changed files with 25 additions and 72 deletions
63
demo_game.gd
63
demo_game.gd
|
|
@ -18,14 +18,14 @@ var id_to_card: Dictionary = {}
|
|||
var player_action_queue: Dictionary
|
||||
var player_1_action: Action:
|
||||
get:
|
||||
return player_action_queue.get(MatchManager.PLAYER_1_ID)
|
||||
return player_action_queue.get(own_side.player_id)
|
||||
set(value):
|
||||
player_action_queue[MatchManager.PLAYER_1_ID] = value
|
||||
player_action_queue[own_side.player_id] = value
|
||||
var player_2_action: Action:
|
||||
get:
|
||||
return player_action_queue.get(MatchManager.PLAYER_2_ID)
|
||||
return player_action_queue.get(opponent_side.player_id)
|
||||
set(value):
|
||||
player_action_queue[MatchManager.PLAYER_2_ID] = value
|
||||
player_action_queue[opponent_side.player_id] = value
|
||||
|
||||
var id
|
||||
var signal_connected := false
|
||||
|
|
@ -33,6 +33,9 @@ var signal_connected := false
|
|||
func init(player_id: int) -> void:
|
||||
id = player_id
|
||||
|
||||
own_side.player_id = player_id
|
||||
opponent_side.player_id = MatchManager.PLAYER_2_ID if player_id == MatchManager.PLAYER_1_ID else MatchManager.PLAYER_1_ID
|
||||
|
||||
id_to_card.clear()
|
||||
|
||||
var cards = player_1_deck.duplicate()
|
||||
|
|
@ -44,9 +47,9 @@ func init(player_id: int) -> void:
|
|||
match_manager.init({
|
||||
MatchManager.PLAYER_1_ID: player_1_deck,
|
||||
MatchManager.PLAYER_2_ID: player_2_deck
|
||||
})
|
||||
own_side.attach(match_manager, player_id == MatchManager.PLAYER_1_ID)
|
||||
opponent_side.attach(match_manager, player_id == MatchManager.PLAYER_2_ID)
|
||||
}, own_side.player_id, opponent_side.player_id)
|
||||
own_side.attach(match_manager, true)
|
||||
opponent_side.attach(match_manager, false)
|
||||
|
||||
if !signal_connected:
|
||||
match_manager.state_transitioned.connect(_on_match_manager_state_transitioned)
|
||||
|
|
@ -65,19 +68,6 @@ func _on_start_game_button_button_up() -> void:
|
|||
func rpc_start_game() -> void:
|
||||
match_manager.resolve({})
|
||||
|
||||
func rpc_own_play_card(id: String) -> void:
|
||||
if !id.is_empty():
|
||||
var card = id_to_card[id]
|
||||
player_1_action = ActionPlayCard.new(card)
|
||||
else:
|
||||
player_1_action = ActionSkipCard.new()
|
||||
|
||||
print(self.id, " rpc_own_play_card", player_1_action, player_2_action)
|
||||
|
||||
if player_2_action:
|
||||
match_manager.resolve(player_action_queue)
|
||||
player_action_queue.clear()
|
||||
|
||||
func _on_own_play_card(card: Card) -> void:
|
||||
if card:
|
||||
player_1_action = ActionPlayCard.new(card)
|
||||
|
|
@ -105,29 +95,6 @@ func rpc_opponent_play_card(id: String) -> void:
|
|||
match_manager.resolve(player_action_queue)
|
||||
player_action_queue.clear()
|
||||
|
||||
func _on_opponent_play_card(card: Card) -> void:
|
||||
if card:
|
||||
player_2_action = ActionPlayCard.new(card)
|
||||
opponent_played_card.emit(card)
|
||||
else:
|
||||
player_2_action = ActionSkipCard.new()
|
||||
opponent_played_card.emit(null)
|
||||
|
||||
print(id, " _on_opponent_play_card", player_1_action, player_2_action)
|
||||
|
||||
if player_1_action:
|
||||
match_manager.resolve(player_action_queue)
|
||||
player_action_queue.clear()
|
||||
|
||||
func rpc_own_rps_move(move: String) -> void:
|
||||
player_1_action = ActionRPSMove.new(move)
|
||||
|
||||
print(id, " rpc_own_rps_move", player_1_action, player_2_action, move)
|
||||
|
||||
if player_2_action:
|
||||
match_manager.resolve(player_action_queue)
|
||||
player_action_queue.clear()
|
||||
|
||||
func _on_own_rps_move(move: String) -> void:
|
||||
player_1_action = ActionRPSMove.new(move)
|
||||
own_played_rts.emit(move)
|
||||
|
|
@ -146,13 +113,3 @@ func rpc_opponent_rps_move(move: String) -> void:
|
|||
if player_1_action:
|
||||
match_manager.resolve(player_action_queue)
|
||||
player_action_queue.clear()
|
||||
|
||||
func _on_opponent_rps_move(move: String) -> void:
|
||||
player_2_action = ActionRPSMove.new(move)
|
||||
opponent_played_rts.emit(move)
|
||||
|
||||
print(id, " rpc_opponent_rps_move", player_1_action, player_2_action, move)
|
||||
|
||||
if player_1_action:
|
||||
match_manager.resolve(player_action_queue)
|
||||
player_action_queue.clear()
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://bgc0u117jqyr1"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://l2ehohbd1xhk"]
|
||||
|
||||
[ext_resource type="Script" path="res://demo_game.gd" id="1_jn16u"]
|
||||
[ext_resource type="Script" path="res://player_side.gd" id="2_w4tnt"]
|
||||
[ext_resource type="Script" path="res://tcg/card/card.gd" id="2_xuft0"]
|
||||
[ext_resource type="PackedScene" uid="uid://cikstg43mudkn" path="res://tcg/match/match_manager.tscn" id="3_3yhrl"]
|
||||
[ext_resource type="Resource" uid="uid://cs7q8i7bvohmj" path="res://data/cards/monster/capytain.tres" id="3_we1tk"]
|
||||
[ext_resource type="Resource" path="res://data/cards/monster/capytain.tres" id="3_we1tk"]
|
||||
[ext_resource type="Resource" uid="uid://4eod3m0vc5a8" path="res://data/cards/support/potion.tres" id="4_kkhfk"]
|
||||
[ext_resource type="Resource" uid="uid://di76avwc0gn8e" path="res://data/cards/monster/axoluna.tres" id="5_3cm5x"]
|
||||
[ext_resource type="Resource" path="res://data/cards/monster/axoluna.tres" id="5_3cm5x"]
|
||||
|
||||
[node name="DemoGame" type="Control"]
|
||||
layout_mode = 3
|
||||
|
|
|
|||
10
main.gd
10
main.gd
|
|
@ -58,24 +58,14 @@ func _ready() -> void:
|
|||
server_discovery.server_removed.connect(_on_server_removed)
|
||||
|
||||
demo_game.own_played_card.connect(func (card): _on_own_played_card.rpc(card.id if card else ""))
|
||||
demo_game.opponent_played_card.connect(func (card): _on_opponent_played_card.rpc(card.id if card else ""))
|
||||
demo_game.own_played_rts.connect(func (move): _on_own_played_rts.rpc(move))
|
||||
demo_game.opponent_played_rts.connect(func (move): _on_opponent_played_rts.rpc(move))
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func _on_own_played_card(card_id: String):
|
||||
demo_game.rpc_own_play_card(card_id)
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func _on_opponent_played_card(card_id: String):
|
||||
demo_game.rpc_opponent_play_card(card_id)
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func _on_own_played_rts(move: String):
|
||||
demo_game.rpc_own_rps_move(move)
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func _on_opponent_played_rts(move: String):
|
||||
demo_game.rpc_opponent_rps_move(move)
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
[ext_resource type="Script" path="res://main.gd" id="1_e0ud3"]
|
||||
[ext_resource type="Script" path="res://server_discovery.gd" id="2_hed18"]
|
||||
[ext_resource type="PackedScene" uid="uid://bgc0u117jqyr1" path="res://demo_game.tscn" id="3_2ln6b"]
|
||||
[ext_resource type="PackedScene" uid="uid://l2ehohbd1xhk" path="res://demo_game.tscn" id="3_2ln6b"]
|
||||
|
||||
[node name="Main" type="Control"]
|
||||
layout_mode = 3
|
||||
|
|
|
|||
|
|
@ -16,16 +16,22 @@ var rps_wins = {
|
|||
var players: Dictionary
|
||||
var player_1: MatchPlayer:
|
||||
get:
|
||||
return players[PLAYER_1_ID] as MatchPlayer
|
||||
return players[actual_p1_id] as MatchPlayer
|
||||
var player_2: MatchPlayer:
|
||||
get:
|
||||
return players[PLAYER_2_ID] as MatchPlayer
|
||||
return players[actual_p2_id] as MatchPlayer
|
||||
var phase: Match.Phase = Match.Phase.PREGAME
|
||||
|
||||
var actual_p1_id: int
|
||||
var actual_p2_id: int
|
||||
|
||||
func _ready() -> void:
|
||||
cleanup()
|
||||
|
||||
func init(decks: Dictionary):
|
||||
func init(decks: Dictionary, actual_p1_id: int, actual_p2_id: int):
|
||||
self.actual_p1_id = actual_p1_id
|
||||
self.actual_p2_id = actual_p2_id
|
||||
|
||||
cleanup()
|
||||
for player_id in [PLAYER_1_ID, PLAYER_2_ID]:
|
||||
var deck_shuffled = decks[player_id].duplicate() as Array[Card]
|
||||
|
|
@ -50,8 +56,8 @@ func cleanup():
|
|||
func resolve(action_by_player_id: Dictionary) -> PhaseTransition:
|
||||
var initial_phase = phase
|
||||
var events = [] as Array[Event]
|
||||
var player_1_action = action_by_player_id.get(PLAYER_1_ID) as Action
|
||||
var player_2_action = action_by_player_id.get(PLAYER_2_ID) as Action
|
||||
var player_1_action = action_by_player_id.get(actual_p1_id) as Action
|
||||
var player_2_action = action_by_player_id.get(actual_p2_id) as Action
|
||||
match phase:
|
||||
Match.Phase.PREGAME:
|
||||
var CARDS_TO_DRAW: int = 3
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue