Skip to content

Commit

Permalink
Fixes bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
theMr17 committed Aug 9, 2023
1 parent 4a26a45 commit d95d95c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
18 changes: 12 additions & 6 deletions Assets/Scripts/Counters/CuttingCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public override void InteractAlternate(Player player)

[ServerRpc(RequireOwnership = false)]
private void CutObjectServerRpc() {
CutObjectClientRpc();
if(HasKitchenObject() && HasRecipeWithInput(GetKitchenObject().GetKitchenObjectSO())) {
// There is a KitchenObject here and it can be cut
CutObjectClientRpc();
}
}

[ClientRpc]
Expand All @@ -92,12 +95,15 @@ private void CutObjectClientRpc() {

[ServerRpc(RequireOwnership = false)]
private void TestCuttingProgressDoneServerRpc() {
CuttingRecipeSO cuttingRecipeSO = GetCuttingRecipeSOWithInput(GetKitchenObject().GetKitchenObjectSO());
if(HasKitchenObject() && HasRecipeWithInput(GetKitchenObject().GetKitchenObjectSO())) {
// There is a KitchenObject here and it can be cut
CuttingRecipeSO cuttingRecipeSO = GetCuttingRecipeSOWithInput(GetKitchenObject().GetKitchenObjectSO());

if(cuttingProgress >= cuttingRecipeSO.cuttingProgressMax) {
KitchenObjectSO outputKitchenObjectSO = GetOutputForInput(GetKitchenObject().GetKitchenObjectSO());
KitchenObject.DestroyKitchenObject(GetKitchenObject());
KitchenObject.SpawnKitchenObject(outputKitchenObjectSO, this);
if(cuttingProgress >= cuttingRecipeSO.cuttingProgressMax) {
KitchenObjectSO outputKitchenObjectSO = GetOutputForInput(GetKitchenObject().GetKitchenObjectSO());
KitchenObject.DestroyKitchenObject(GetKitchenObject());
KitchenObject.SpawnKitchenObject(outputKitchenObjectSO, this);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/KitchenGameLobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private async void ListLobbies() {
private async void InitializeUnityAuthentication() {
if(UnityServices.State != ServicesInitializationState.Initialized) {
InitializationOptions initializationOptions = new InitializationOptions();
initializationOptions.SetProfile(UnityEngine.Random.Range(0, 10000).ToString());
//initializationOptions.SetProfile(UnityEngine.Random.Range(0, 10000).ToString());
await UnityServices.InitializeAsync();

await AuthenticationService.Instance.SignInAnonymouslyAsync();
Expand Down
16 changes: 14 additions & 2 deletions Assets/Scripts/KitchenGameMultiplayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,21 @@ public void SpawnKitchenObject(KitchenObjectSO kitchenObjectSO, IKitchenObjectPa
private void SpawnKitchenObjectServerRpc(int kitchenObjectSOIndex, NetworkObjectReference kitchenObjectParentNetworkObjectReference) {
KitchenObjectSO kitchenObjectSO = GetKitchenObjectSOFromIndex(kitchenObjectSOIndex);

kitchenObjectParentNetworkObjectReference.TryGet(out NetworkObject kitchenObjectParentNetworkObject);
IKitchenObjectParent kitchenObjectParent = kitchenObjectParentNetworkObject.GetComponent<IKitchenObjectParent>();

if(kitchenObjectParent.HasKitchenObject()) {
// Kitchen object already spawned
return;
}

Transform kitchenObjectTransform = Instantiate(kitchenObjectSO.prefab);

NetworkObject kitchenObjectNetworkObject = kitchenObjectTransform.GetComponent<NetworkObject>();
kitchenObjectNetworkObject.Spawn(true);

KitchenObject kitchenObject = kitchenObjectTransform.GetComponent<KitchenObject>();

kitchenObjectParentNetworkObjectReference.TryGet(out NetworkObject kitchenObjectParentNetworkObject);
IKitchenObjectParent kitchenObjectParent = kitchenObjectParentNetworkObject.GetComponent<IKitchenObjectParent>();
kitchenObject.SetKitchenObjectParent(kitchenObjectParent);
}

Expand Down Expand Up @@ -159,6 +165,12 @@ private void DestroyKitchenObjectServerRpc(NetworkObjectReference kitchenObjectN
[ClientRpc]
private void ClearKitchenObjectOnParentClientRpc(NetworkObjectReference kitchenObjectNetworkObjectReference) {
kitchenObjectNetworkObjectReference.TryGet(out NetworkObject kitchenObjectNetworkObject);

if(kitchenObjectNetworkObject == null) {
// This object is already destroyed
return;
}

KitchenObject kitchenObject = kitchenObjectNetworkObject.GetComponent<KitchenObject>();

kitchenObject.ClearKitchenObjectOnParent();
Expand Down

0 comments on commit d95d95c

Please sign in to comment.