bool CanEncounter(SpecimenBehavior npc) { switch (state) { case State.Idle: case State.Walking: return(!npc.Equals(lastEncounter)); case State.Talking: case State.Trapped: return(false); default: throw new ArgumentOutOfRangeException("Unknown state: " + state); } }
public static IEnumerator Create(IEncounterable sender, SpecimenBehavior receiver) { sender.PrepareEncounter(receiver); receiver.PrepareEncounter(sender); float distance = 2f; float x = sender.GetTransform().position.x + distance; float y = sender.GetTransform().position.y; var list = receiver.MoveToPositionRoutine(new Vector2(x, y)); while (list.MoveNext()) { yield return(list.Current); } yield return(new WaitForSeconds(0.5f)); var package = sender.CreatePackage(); yield return(new WaitForSeconds(0.8f)); bool communicationSuccessful = receiver.ReceivePackage(package); yield return(new WaitForSeconds(0.8f)); if (communicationSuccessful) { var thoughts = sender.ApplyThoughtRoutine(package.thought, receiver); while (thoughts.MoveNext()) { yield return(thoughts.Current); } } sender.FinishEncounter(); receiver.FinishEncounter(); }
public IEnumerator ApplyThoughtRoutine(Thought senderThought, SpecimenBehavior receiver) { receiver.SetThought(senderThought); yield return(null); }
public IEnumerator ApplyThoughtRoutine(Thought senderThought, SpecimenBehavior receiver) { var receiverThought = receiver.GetThought(); if (senderThought == receiverThought) { switch (senderThought) { case Thought.Danger: var danger = FindObjectsOfType <DangerBehavior>().RandomElement().gameObject.transform; SetWalkingTarget(danger); receiver.SetWalkingTarget(danger); yield return(new WaitForSeconds(0.25f)); break; case Thought.Food: var foodSteps = receiver.MoveToPositionRoutine(new Vector2(transform.position.x + 0.5f, transform.position.y)); while (foodSteps.MoveNext()) { yield return(foodSteps.Current); } AudioManager.instance.PlaySound("NPCEatingNPC"); while (transform.localScale.z > 0) { transform.localScale -= 0.1f * Vector3.one; yield return(new WaitForSeconds(0.1f)); } transform.Find("Sprites").gameObject.SetActive(false); isDying = true; receiver.SetThought(Thought.Nothing); yield return(new WaitForSeconds(0.25f)); break; case Thought.Love: var loveSteps = receiver.MoveToPositionRoutine(new Vector2(transform.position.x + 1f, transform.position.y)); while (loveSteps.MoveNext()) { yield return(loveSteps.Current); } //@TODO play love-making sound here yield return(new WaitForSeconds(1.0f)); AudioManager.instance.PlaySound("SpawnNewNPC"); manager.SpawnSpecimen(transform.position + new Vector3(0, 0.5f, 0), transform.localScale); SetThought(Thought.Nothing); receiver.SetThought(Thought.Nothing); yield return(new WaitForSeconds(0.5f)); break; case Thought.Money: //@TODO ? SetThought(Thought.Nothing); receiver.SetThought(Thought.Nothing); break; case Thought.Nothing: new[] { this, receiver }.RandomElement().SetThought(new[] { Thought.Love, Thought.Money, Thought.Food }.RandomElement()); yield return(new WaitForSeconds(0.25f)); break; } } else { if (HasThought()) { if (receiver.HasThought()) { var thoughts = new[] { receiverThought, senderThought }; SetThought(thoughts.RandomElement()); receiver.SetThought(thoughts.RandomElement()); } else { receiver.SetThought(senderThought); } } else { SetThought(receiverThought); } } yield return(new WaitForSeconds(0.5f)); }