protected IEnumerator SellOrReactToItem(string sellMessage, string soldMessage, float soldMessageDuration, string skipMeesage, float skipMessageDuration, GameObject itemPrefab, int price, string reactionToItemMessage, float reactionToItemMessageDuration, bool customReact = false, bool shouldTakeItem = false)// TODO: account this when there's a sell area instead of dropping item. { string message = sellMessage; Item item = GiveItem(itemPrefab).GetComponent <Item>(); ForSaleBehaviour forSale = item.gameObject.AddComponent <ForSaleBehaviour>(); forSale.Price = price; message = message.Replace("#price#", forSale.Price.ToString()).Replace("#name#", item.Name); yield return(Say(message, 0.05f)); Speech.Instance.Cancelable(); bool x = false; while (item.GetComponent <ForSaleBehaviour>() != null && !(x = Input.GetKeyDown(KeyCode.X)) && Item == null) { yield return(null); } if (Item != null) { Bought = false; Sequence s = DOTween.Sequence() .Append(item.transform.DOMove(ClientsManager.Instance.ActivePosition, 1)) .Join(item.transform.DOScale(0, 1f)) .OnComplete(() => Destroy(item.gameObject)); if (!customReact) { yield return(Say(reactionToItemMessage.Replace("#price#", forSale.Price.ToString()).Replace("#name#", item.Name), reactionToItemMessageDuration)); } } else if (item.GetComponent <ForSaleBehaviour>() == null) { Bought = true; GetComponent <AudioSource>().PlayOneShot(YesAudioClip); yield return(Say(soldMessage.Replace("#price#", forSale.Price.ToString()).Replace("#name#", item.Name), soldMessageDuration)); } else { Bought = false; Sequence s = DOTween.Sequence() .Append(item.transform.DOMove(ClientsManager.Instance.ActivePosition, 1)) .Join(item.transform.DOScale(0, 1f)) .OnComplete(() => Destroy(item.gameObject)); //Destroy(item.gameObject); GetComponent <AudioSource>().PlayOneShot(NoAudioClip); yield return(Say(skipMeesage.Replace("#price#", forSale.Price.ToString()).Replace("#name#", item.Name), skipMessageDuration)); } }
protected IEnumerator Sell(string sellMessage, string soldMessage, float soldMessageDuration, string skipMeesage, float skipMessageDuration, GameObject itemPrefab, int price) { yield return(new WaitForEndOfFrame()); string message = sellMessage; Item item = GiveItem(itemPrefab).GetComponent <Item>(); ForSaleBehaviour forSale = item.gameObject.AddComponent <ForSaleBehaviour>(); forSale.Price = price; message = message.Replace("#price#", forSale.Price.ToString()).Replace("#name#", item.Name); yield return(Say(message, 0.05f)); yield return(new WaitForEndOfFrame()); Speech.Instance.Cancelable(); bool x = false; while (item.GetComponent <ForSaleBehaviour>() != null && !(x = Input.GetKeyDown(KeyCode.X))) { yield return(null); } yield return(new WaitForEndOfFrame()); if (item.GetComponent <ForSaleBehaviour>() == null) { Bought = true; GetComponent <AudioSource>().PlayOneShot(YesAudioClip); yield return(Say(soldMessage.Replace("#price#", forSale.Price.ToString()).Replace("#name#", item.Name), soldMessageDuration)); yield return(new WaitForEndOfFrame()); } else { Bought = false; Sequence s = DOTween.Sequence() .Append(item.transform.DOMove(ClientsManager.Instance.ActivePosition, 1)) .Join(item.transform.DOScale(0, 1f)) .OnComplete(() => Destroy(item.gameObject)); //Destroy(item.gameObject); GetComponent <AudioSource>().PlayOneShot(NoAudioClip); yield return(Say(skipMeesage.Replace("#price#", forSale.Price.ToString()).Replace("#name#", item.Name), skipMessageDuration)); yield return(new WaitForEndOfFrame()); } }