/// <summary> /// Releases currently controlled pawn. /// </summary> public virtual void releasePawn() { // Reset the last set simulation velocity before releasing currentMovementVelocity = Vector3.zero; processMovement(); controlledPawn.controller = null; controlledPawn = null; }
/// <summary> /// Method used to take control of a pawn /// <para>Don't forget to register for input event in case of PlayerController</para> /// </summary> /// <param name="pawn">Pawn that will be controlled</param> public virtual void controlPawn(BasicPawn pawn) { if (pawn.controller != null) { pawn.controller.releasePawn(); } pawn.controller = this; controlledPawn = pawn; }
public override void interact(GameObject interactor) { BasicPawn pawn = interactor.GetComponent <BasicPawn>(); if (pawn.controller is NpcController) // If is NPC then set all data that customer is bringing in to counter. { resetData(); waitingController = (NpcController)pawn.controller; progressionBar.gameObject.SetActive(true); // Make controller stop waitingController.IsMobile = false; // Hard coded value to make npc go off screen after waiting waitingController.MoveTo = new Vector3(transform.parent.position.x, transform.parent.position.y + 7, waitingController.GetControlledPawn.transform.position.z); int itemMask = waitingController.attributes.salad; for (int i = 0; i < (int)Vegies.count; i++)// Using bit shifting to find ingredients. { if ((itemMask & 1) > 0) { int veg = (int)Mathf.Pow(2, i); VegetableData vegData = ChefSaladManager.getVegetableData(veg); scoreOnSuccess += vegData.Reward; penaltyOnFailure += vegData.Penalty; saladCanvas.addItem(vegData); } itemMask >>= 1; } scoreOnSuccess += scoreOnSuccess * waitingController.attributes.scoreMultiplier; penaltyOnFailure += waitingController.attributes.scoreMultiplier; } else //If it is player then get salad and do the processing. { Player player = (Player)pawn; int salad = player.PlayerInventory.getFirstItem(false) & (~(int)Vegies.oneItemSaladHandle); #if GAME_DEBUG Debug.Log("Player Serving salad " + salad + " Customer requested salad " + waitingController.attributes.salad); #endif if ((salad ^ waitingController.attributes.salad) == 0) // If salad ingredient match required ingredient do below { playerIds.Clear(); playerIds.Add(player.GetId); waitOver(scoreOnSuccess); } else // If not matching then add the player to player ids that needs to be affected by penalty. { playerIds.Add(player.GetId); if (timeMultiplier == 1)// Only increase time multiplier once rest of failure does not affect { timeMultiplier *= waitingController.attributes.failureTimeMultiplier; } } } }
public override bool canInteract(GameObject interactor) { BasicPawn pawn = interactor.GetComponent <BasicPawn>(); if (pawn.controller is NpcController) // If is customer check only if another customer is already in counter. { #if GAME_DEBUG Debug.Log("Checking NpcController"); #endif return(waitingController == null); } else // If Player then check if there is any customer,the customer is still waiting and Player has salad. { #if GAME_DEBUG Debug.Log("Checking PlayerController and Inventory"); #endif Player player = (Player)pawn; return(waitingController != null && (waitingController.attributes.maxWaitTime - timeConsumed) > 0 && player.PlayerInventory.hasAnySalad()); } }
private void Awake() { // Destroy in case more object exists as it is singleton. if (manager != null) { Destroy(gameObject); return; } HIGHSCORE_SAVE_PATH = Path.Combine(Application.persistentDataPath, "highscores.sav"); manager = this; trashCan.onItemTrashed += itemTrashed; // Creating all Player ,Player controller,Player input manager combination and setting necessary data for them at start of game. foreach (PlayerSpawnData psd in playersToSpawn) { BasicPawn pawn = ((GameObject)Instantiate(playerPrefab, psd.spawnTransform.position, Quaternion.identity)).GetComponent <BasicPawn>(); if (!pawn) { throw new Exception("Add proper Pawn Prefab in game manager"); } pawn.name = psd.playerName; pawn.GetComponent <SpriteRenderer>().color = psd.spriteColor; PlayerController controller = ((GameObject)Instantiate(playerControllerPrefab)).GetComponent <PlayerController>(); if (!controller) { throw new Exception("Add proper Pawn Controller Prefab in game manager"); } controller.name = psd.playerName + "Controller"; InputManager inputManager = new GameObject(controller.name + "InputManager").AddComponent <InputManager>(); playersList.Add(controller.GetID, controller); controller.InputPrefix = psd.playerInputPrefix; controller.playerName = psd.playerName; controller.controlPawn(pawn); controller.setupInputs(inputManager); controller.PlayerState.onScoreChanged += scoreChangedFor; psd.playerHud.PlayerInventory = controller.PlayerInventory; psd.playerHud.PlayerState = controller.PlayerState; psd.stove.userId = psd.dish.userId = controller.GetID; } // Creating all NPC controller needed,One for each counter. foreach (GameObject counterObj in customerCounters) { CustomerCounter counter = counterObj.GetComponentInChildren <CustomerCounter>(); GameObject go = Instantiate(npcControllerPrefab); go.name = counter.name + "NpcController"; BasicController controller = go.GetComponent <BasicController>(); npcControllers.Add(controller); counter.onCustomerLeaving += customerLeft; } resultScreen = gameEndCanvas.GetComponentInChildren <ResultDisplay>(); resultScreen.restartButton.onClick.AddListener(restartLevel); }
public override void controlPawn(BasicPawn pawn) { base.controlPawn(pawn); }