public void Purchase() { Unlock(); // Unselect the currently selected one if (gameObject.name.Contains("Trail")) { string trail = PlayerPrefs.GetString("CurrentTrail", null); if (trail.Length > 0) { GameObject.Find(trail).GetComponent <BallCustomization>().UnEquip(); } } else { GameObject.Find(PlayerPrefs.GetString("CurrentBall")).GetComponent <BallCustomization>().UnEquip(); } Equip(); PlayerPrefs.SetInt("TotalStars", totalStars - cost); totalStars -= cost; totalStarText.text = "x " + totalStars; confirmWin.SetActive(false); state = BuyState.Equipped; string key = gameObject.name + "BuyState"; PlayerPrefs.SetInt(key, (int)state); }
private void GoToQueue(WorldState.SalesmanCharacterName salesman) { Transform position; for (int i = 0; i < WorldState.instance.SalesmanList.Count; i++) { if (WorldState.instance.SalesmanList[i].GetComponent <Salesman>().characterName == salesman) { position = WorldState.instance.SalesmanList[i].GetComponent <Salesman>().InsertInQueueLastPosition(gameObject); if (position == GetComponent <Npc>().GetStartPosition()) //queue full { //wait some seconds StartCoroutine(WaitToQueueDrop()); } else { positionInQueue = WorldState.instance.SalesmanList[i].GetComponent <Salesman>().GetLastPositionInQueue() - 1; //if we enter here, salesman has included the npc in queue if (buyState == BuyState.GOING_TO_SEE) { shopsChecked.Add(salesman);// we should add this later when the character gets the first position } //, but then we have to save this value somewhere, soo this is a easy solution buyState = BuyState.ON_ROUTE; } GetComponent <Npc>().GoToPosition(position); } } }
// Start is called before the first frame update void Start() { manager = new HFSMManagerSystem(); HomeSystem homeSystem = new HomeSystem("HomeSystem", manager); ReadBookState readBookState = new ReadBookState("ReadBookState", homeSystem, systemText, stateText); readBookState.AddTransition("Cook", "CookState"); CookState cookState = new CookState("CookState", homeSystem, systemText, stateText); cookState.AddTransition("Sleep", "SleepState"); SleepState sleepState = new SleepState("SleepState", homeSystem, systemText, stateText); sleepState.AddTransition("ReadBook", "ReadBookState"); homeSystem.AddState(readBookState); homeSystem.AddState(cookState); homeSystem.AddState(sleepState); MarketSystem marketSystem = new MarketSystem("MarketSystem", manager); BuyState buyState = new BuyState("BuyState", marketSystem, systemText, stateText); buyState.AddTransition("Pay", "PayState"); PayState payState = new PayState("PayState", marketSystem, systemText, stateText); payState.AddTransition("Buy", "BuyState"); marketSystem.AddState(buyState); marketSystem.AddState(payState); manager.AddSubSystem(homeSystem); manager.AddSubSystem(marketSystem); }
IEnumerator SeeShop() { yield return(new WaitForSeconds(WaitTimeToBuy)); for (int i = 0; i < WorldState.instance.SalesmanList.Count; i++) //move to exit { if (WorldState.instance.SalesmanList[i].GetComponent <Salesman>().characterName == shopsChecked[shopsChecked.Count - 1]) { gameObject.GetComponent <Npc>().GoToPosition(WorldState.instance.SalesmanList[i].GetComponent <Salesman>().GetShopExitPoint()); WorldState.instance.SalesmanList[i].GetComponent <Salesman>().UpdateQueue(); } } if (shopsChecked.Count == WorldState.instance.activeSalesman) // all open shops visited { Debug.Log(gameObject.name + " is planing the buy"); WorldState.instance.hud.UpdateDebugText(gameObject.name + " is planing the buy."); if (MakeBuyDecision()) { buyState = BuyState.END; GetComponent <Npc>().CheckIfEndedAll(); } else { buyState = BuyState.PLANNED; } } else if (GetComponent <Npc>().GetPersonality() == Personality.PersonalityType.PERFECTIONIST) { Debug.Log(gameObject.name + " is going to see another shop"); WorldState.instance.hud.UpdateDebugText(gameObject.name + " is going to see another shop."); buyState = BuyState.GOING_TO_SEE; } else { if (Random.Range(0, 100) > ProbabilityToSeeAnotherShop) { Debug.Log(gameObject.name + " is going to see another shop"); WorldState.instance.hud.UpdateDebugText(gameObject.name + " is going to see another shop."); buyState = BuyState.GOING_TO_SEE; } else { Debug.Log(gameObject.name + " is planing the buy"); WorldState.instance.hud.UpdateDebugText(gameObject.name + " is planing the buy."); if (MakeBuyDecision()) { buyState = BuyState.END; GetComponent <Npc>().CheckIfEndedAll(); } else { buyState = BuyState.PLANNED; } } } coroutineStarted = false; }
/// <summary> /// Unequips this ball customization /// Used to make sure only one is equipped at a time /// </summary> public void UnEquip() { state = BuyState.Unlocked; equip.GetComponent <Text>().text = "Equip"; string key = gameObject.name + "BuyState"; PlayerPrefs.SetInt(key, (int)state); Destroy(gameObject.GetComponent <Outline>()); }
void OnTriggerEnter(Collider col) { if (buyState == BuyState.FinishedTotal && col.transform.name == "Allocation Area") { bool allocated = QManager.Instance().allocatePersonToFittestQueue(this.GetComponent <Person> ()); if (!allocated) { buyState = BuyState.ExitingIntermmediate1; goToInterrmediateLocation(); } } }
public void OnMouseDown() { totalStars = PlayerPrefs.GetInt("TotalStars"); switch (state) { case BuyState.Equipped: break; case BuyState.Unlocked: { // Set this one to be selected state = BuyState.Equipped; equip.GetComponent <Text>().text = "Equipped"; // Unselect the currently selected one if (gameObject.name.Contains("Trail")) { GameObject.Find(PlayerPrefs.GetString("CurrentTrail")).GetComponent <BallCustomization>().UnEquip(); } else { GameObject.Find(PlayerPrefs.GetString("CurrentBall")).GetComponent <BallCustomization>().UnEquip(); } // Set the customization to be the new selection Equip(); } break; case BuyState.Locked: { confirmWin.SetActive(true); confirmWin.transform.GetChild(1).GetChild(1).GetComponent <Text>().text = " = " + cost + " of "; confirmWin.transform.GetChild(3).GetComponent <Text>().text = "Unlock for " + cost + " Stars?"; confirmWin.transform.GetChild(2).GetChild(1).GetComponent <Button>().onClick.RemoveAllListeners(); confirmWin.transform.GetChild(2).GetChild(1).GetComponent <Button>().onClick.AddListener(Purchase); confirmWin.transform.GetChild(1).GetChild(0).GetComponent <Image>().sprite = ball.sprite; confirmWin.transform.GetChild(1).GetChild(0).GetComponent <Image>().color = ball.color; if (cost > totalStars) { confirmWin.transform.GetChild(2).GetChild(1).GetComponent <Button>().interactable = false; } else { confirmWin.transform.GetChild(2).GetChild(1).GetComponent <Button>().interactable = true; } } break; } }
void Start() { StartCoroutine("startCountingInsideTime"); if (QManager.Instance().isThereAnySlotsLeft() == false) { buyState = BuyState.ExitingIntermmediate1; agent.SetDestination(Locations.intermediateExitLocation1); } else { agent.autoRepath = true; currentDestination = PersonManager.Instance().getNextBuyPosition(); buyState = BuyState.Buying; agent.SetDestination(currentDestination); } }
private void OnEnable() { shopsChecked = new List <WorldState.SalesmanCharacterName>(); shopToBuy = new List <WorldState.SalesmanCharacterName>(); itemToBuyType = new List <Item.ItemType>(); if (buyState == BuyState.NEED_TO_BUY) { buyState = BuyState.GOING_TO_SEE; GoToSeeShop(); } else { buyState = BuyState.END; } }
// Use this for initialization void Awake() { hasAbandoned = false; bucket = PersonManager.Instance().getNewBucket(); bucketItemCount = bucket.items.Count; agent = GetComponent <NavMeshAgent> (); thisTransform = GetComponent <Transform> (); thisTransform.SetParent(GameObject.Find("People").transform); shoulders = GetComponentsInChildren <Renderer> (); shoulderColor = PersonColors.Instance().getNewColor(); buyState = BuyState.Start; for (int i = 1; i < 3; i++) { shoulders[i].material.color = shoulderColor; } }
IEnumerator startCountingQWaitTime() { while (this.buyState == BuyState.Waiting || this.buyState == BuyState.WaitingFirstInLine) { totalTimeInQueue += 1; if (this.buyState == BuyState.WaitingFirstInLine) { totalTimeFirstInQ += 1; } if (this.buyState == BuyState.WaitingFirstInLine && totalTimeFirstInQ > bucket.totalWaitingTime) { this.buyState = BuyState.ExitingIntermmediate2; } yield return(new WaitForSeconds(1)); } }
public void Buy(string purchaseID, string productID, string name, double price, double originalPrice, int quantity, string description) { if (Application.platform == RuntimePlatform.IPhonePlayer) { this.m_BuyError = null; if (Bonjour.IsLogined()) { Bonjour.UniPay(purchaseID, productID, name, price, price, quantity, description); this.m_BuyState = BuyState.Buying; } else { this.m_BuyState = BuyState.Fail; this.m_BuyError = "Not Login yet!"; } } }
/// <summary> /// Equips this ball customization /// </summary> private void Equip() { equip.GetComponent <Text>().text = "Equipped"; Outline line = gameObject.AddComponent <Outline>(); line.effectDistance = new Vector2(3, -3); line.effectColor = Color.blue; line.useGraphicAlpha = false; if (gameObject.name.Contains("Trail")) { PlayerPrefs.SetInt("Trail", id); customizationManager.UpdateCurrentTrail(id); } else { PlayerPrefs.SetInt("Ball", id); customizationManager.UpdateCurrentBall(id); } // Set the customization to be the new selection if (gameObject.name.Contains("Trail")) { PlayerPrefs.SetString("CurrentTrail", gameObject.name); } else { PlayerPrefs.SetString("CurrentBall", gameObject.name); } state = BuyState.Equipped; string key = gameObject.name + "BuyState"; PlayerPrefs.SetInt(key, (int)state); }
// Use this for initialization void Start() { // Get the current states through playerprefs totalStars = PlayerPrefs.GetInt("TotalStars", 0); currentCustomization = PlayerPrefs.GetString("CurrentBall", "White"); string key = gameObject.name + "BuyState"; state = (BuyState)PlayerPrefs.GetInt(key, 0); customizationManager = GameObject.Find("CustomizationManager").GetComponent <CustomizationManager>(); id = transform.GetSiblingIndex(); if (gameObject.name == "White" && currentCustomization != "White") { state = BuyState.Unlocked; Unlock(); } else if (gameObject.name == "White") { state = BuyState.Equipped; Unlock(); Equip(); } if (state == BuyState.Equipped) { Unlock(); Equip(); } if (state == BuyState.Unlocked) { Unlock(); } totalStarText.text = "x " + totalStars; }
public void EnteredInQueue() { buyState = BuyState.ON_QUEUE; }
IEnumerator BuyShop() { yield return(new WaitForSeconds(WaitTimeToBuy)); WorldState.SalesmanCharacterName searchedSalesman = shopToBuy[0]; int salesmanNum = 0; int searchPos = 0; Item itemToBuy; bool allBought = true; //search the salesman index while (salesmanNum < WorldState.instance.SalesmanList.Count) { if (WorldState.instance.SalesmanList[salesmanNum].GetComponent <Salesman>().characterName == shopToBuy[0]) { break; } else { salesmanNum++; } } //buy while (searchPos < shopToBuy.Count) { if (shopToBuy[searchPos] == searchedSalesman) //buy in this shop { //search item to buy itemToBuy = null; switch (itemToBuyType[searchPos]) { case Item.ItemType.FRIDGE: { if (WorldState.instance.SalesmanList[salesmanNum].GetComponent <ShopInventory>().FridgeList.Count != 0) { itemToBuy = WorldState.instance.SalesmanList[salesmanNum].GetComponent <ShopInventory>().FridgeList[0]; } break; } case Item.ItemType.WASHER: { if (WorldState.instance.SalesmanList[salesmanNum].GetComponent <ShopInventory>().WasherList.Count != 0) { itemToBuy = WorldState.instance.SalesmanList[salesmanNum].GetComponent <ShopInventory>().WasherList[0]; } break; } case Item.ItemType.FOOD: { if (WorldState.instance.SalesmanList[salesmanNum].GetComponent <ShopInventory>().FoodList.Count != 0) { itemToBuy = WorldState.instance.SalesmanList[salesmanNum].GetComponent <ShopInventory>().FoodList[0]; } break; } case Item.ItemType.DETERGENT: { if (WorldState.instance.SalesmanList[salesmanNum].GetComponent <ShopInventory>().DetergentList.Count != 0) { itemToBuy = WorldState.instance.SalesmanList[salesmanNum].GetComponent <ShopInventory>().DetergentList[0]; } break; } default: { Debug.LogError("Item out of list"); break; } } //test if have an item avaible if (itemToBuy != null) { if (GetComponent <Npc>().money >= itemToBuy.itemValue) { //buy Debug.Log(gameObject.name + " has bought " + itemToBuy.itemType + "."); WorldState.instance.hud.UpdateDebugText(gameObject.name + " has bought " + itemToBuy.itemType + "."); GetComponent <Npc>().money -= itemToBuy.itemValue; GetComponent <Inventory>().AddNewItem(itemToBuy); WorldState.instance.SalesmanList[salesmanNum].GetComponent <ShopInventory>().ItemBought(itemToBuy); shopToBuy.RemoveAt(searchPos); itemToBuyType.RemoveAt(searchPos); WorldState.instance.hud.UpdateInventoryAndMoneyHud(); } else { Debug.Log(gameObject.name + " not enought money"); WorldState.instance.hud.UpdateDebugText(gameObject.name + " not enought money."); shopToBuy.RemoveAt(searchPos); itemToBuyType.RemoveAt(searchPos); allBought = false; } } else { WorldState.instance.hud.UpdateDebugText(gameObject.name + " item not avaible."); Debug.Log(gameObject.name + " item not avaible"); allBought = false; shopToBuy.RemoveAt(searchPos); itemToBuyType.RemoveAt(searchPos); } } else //next { searchPos++; } } //move to exit gameObject.GetComponent <Npc>().GoToPosition(WorldState.instance.SalesmanList[salesmanNum].GetComponent <Salesman>().GetShopExitPoint()); WorldState.instance.SalesmanList[salesmanNum].GetComponent <Salesman>().UpdateQueue(); //has buy all? if (allBought && shopToBuy.Count == 0) //all bought in all { Debug.Log(gameObject.name + " has bought all"); buyState = BuyState.END; GetComponent <Npc>().CheckIfEndedAll(); } else if (allBought) //all bought in this shop { Debug.Log(gameObject.name + " has bought all in this shop"); WorldState.instance.hud.UpdateDebugText(gameObject.name + " has bought all in this shop."); buyState = BuyState.PLANNED; } else { if (MakeBuyDecision()) { buyState = BuyState.END; //has not enought money or stock GetComponent <Npc>().CheckIfEndedAll(); } else { buyState = BuyState.PLANNED; } } coroutineStarted = false; }
// Update is called once per frame void Update() { if (!agent.pathPending && buyState != BuyState.FinishedTotal) { if (Mathf.Floor(agent.remainingDistance) < 1 && buyState == BuyState.Buying) { finishedTime = Time.timeSinceLevelLoad; buyState = BuyState.FinishedItem; } } if (buyState == BuyState.FinishedItem) { if (finishedTime + PersonManager.Instance().shelfWaitingTime < Time.timeSinceLevelLoad) { bucket.finishItem(); if (bucket.isBucketFinished() == false) { currentDestination = PersonManager.Instance().getNextBuyPosition(); agent.SetDestination(currentDestination); buyState = BuyState.Buying; } else { //Code to go and be queueded buyState = BuyState.FinishedTotal; agent.SetDestination(getClosestQAllocationArea()); } } } //DETECT IF PERSON REACHED QUEUE SPOT if (!agent.pathPending) { if (Mathf.Floor(agent.remainingDistance) < 1 && (buyState == BuyState.WaitingFirstInLine || buyState == BuyState.Waiting)) { if (this.totalTimeInQueue == 0) { StartCoroutine("startCountingQWaitTime"); } } } if (!agent.pathPending) { if (Mathf.Floor(agent.remainingDistance) < 1 && buyState == BuyState.ExitingIntermmediate1) { agent.SetDestination(Locations.intermediateExitLocation2); buyState = BuyState.ExitingIntermmediate2; } } if (!agent.pathPending) { if (Mathf.Floor(agent.remainingDistance) < 1 && buyState == BuyState.ExitingIntermmediate2) { buyState = BuyState.Exiting; agent.SetDestination(Locations.exitLocation); } } if (!agent.pathPending) { if (Mathf.Floor(agent.remainingDistance) < 1 && buyState == BuyState.Exiting) { if (hasAbandoned == true) { PersonManager.Instance().numberOfPersonsAborted++; } PersonManager.Instance().persons.Remove(this.gameObject); StatisticsManager.gatherPersonData(this); Destroy(this.gameObject); } } }
public void BuySuccess() { this.m_BuyState = BuyState.Success; }
public void BuyFail(string error) { this.m_BuyState = BuyState.Fail; this.m_BuyError = error; }
void UpdateBuyState(Simulator sim) { //Console.WriteLine(" " + _buyState.ToString()); if (_buyState == BuyState.Idle) { Console.WriteLine(" buy a card:"); // Print cards available to buy _handTreasure = CountMoneyFromTreasure(); Console.WriteLine(" Treasure: " + _handTreasure); Console.WriteLine(" Treasure Modifier: " + _treasureModifier); PrintCardsToBuy(sim); _buyState = BuyState.Choose; } else if (_buyState == BuyState.Choose) { // Wait for input if (sim._lastNumberPressed > -1) { //Console.WriteLine(" Pressed: " + sim._lastNumberPressed); if (BuyCard(sim._lastNumberPressed, sim)) { _buyState = BuyState.Idle; _currentPhase = Phase.Cleanup; } sim._lastNumberPressed = -1; } else { Console.Write(" buy a card.\n"); } } }