public static List <GameObject> GetUsableParts(BodyPartSlot.BodyPartType bodyPartSlot, bool isPlayer = false, HashSet <BodyPart.ElementType> types = null) { List <GameObject> parts = new List <GameObject>(); parts.AddRange(usableBodyParts [bodyPartSlot]); if (bodyPartSlot == BodyPartSlot.BodyPartType.LeftArm || bodyPartSlot == BodyPartSlot.BodyPartType.RightArm) { parts.AddRange(usableBodyParts [BodyPartSlot.BodyPartType.Arm]); } else if (bodyPartSlot == BodyPartSlot.BodyPartType.LeftLeg || bodyPartSlot == BodyPartSlot.BodyPartType.RightLeg) { parts.AddRange(usableBodyParts [BodyPartSlot.BodyPartType.Leg]); } else if (bodyPartSlot == BodyPartSlot.BodyPartType.LeftEar || bodyPartSlot == BodyPartSlot.BodyPartType.RightEar) { parts.AddRange(usableBodyParts [BodyPartSlot.BodyPartType.Ear]); } if (isPlayer) { int minTypes = Mathf.Min(PlayerPrefs.GetInt("Level", 0) / 2, BodyPart.ElementType.GetNames(typeof(BodyPart.ElementType)).Length); if (types == null || minTypes < types.Count) { return(parts); } foreach (BodyPart.ElementType type in types) { parts = RemoveAllOfType(parts, type); } if (parts.Count == 0) { parts = usableBodyParts[bodyPartSlot]; if (bodyPartSlot == BodyPartSlot.BodyPartType.LeftArm || bodyPartSlot == BodyPartSlot.BodyPartType.RightArm) { parts.AddRange(usableBodyParts[BodyPartSlot.BodyPartType.Arm]); } else if (bodyPartSlot == BodyPartSlot.BodyPartType.LeftLeg || bodyPartSlot == BodyPartSlot.BodyPartType.RightLeg) { parts.AddRange(usableBodyParts[BodyPartSlot.BodyPartType.Leg]); } else if (bodyPartSlot == BodyPartSlot.BodyPartType.LeftEar || bodyPartSlot == BodyPartSlot.BodyPartType.RightEar) { parts.AddRange(usableBodyParts[BodyPartSlot.BodyPartType.Ear]); } } } return(parts); }
public IEnumerator GenerateBodyCoroutine(int depth = 0, Orientation orientation = Orientation.Neutral) { BodyPart.RemoveConflicts(this); if (orientation == Orientation.Neutral) { switch (this.GetBodyPartType()) { case BodyPartSlot.BodyPartType.LeftArm: orientation = Orientation.Left; break; case BodyPartSlot.BodyPartType.LeftEar: orientation = Orientation.Left; break; case BodyPartSlot.BodyPartType.LeftLeg: orientation = Orientation.Left; break; case BodyPartSlot.BodyPartType.RightArm: orientation = Orientation.Right; break; case BodyPartSlot.BodyPartType.RightEar: orientation = Orientation.Right; break; case BodyPartSlot.BodyPartType.RightLeg: orientation = Orientation.Right; break; } } slots = this.GetComponentsInChildren <BodyPartSlot> (); if (slots == null) { yield break; } foreach (BodyPartSlot slot in slots) { bool isHead = slot.GetBodyPartType() == BodyPartSlot.BodyPartType.Head; if (Random.Range(0, depth) > Random.Range(2, 5) && isHead == false) { continue; } bool shouldContinue = false; if (isHead == false) { Collider2D [] hits = Physics2D.OverlapCircleAll(new Vector2(slot.transform.position.x, slot.transform.position.y), ms_collisionTolerance); Collider2D thisCollider = this.GetComponent <Collider2D> (); Collider2D spriteCollider = this.m_spriteRenderer.GetComponent <Collider2D> (); foreach (Collider2D hit in hits) { if (!((thisCollider != null && hit == thisCollider) || (spriteCollider != null && spriteCollider == hit))) { shouldContinue = true; break; } } } if (shouldContinue) { continue; } BodyPartSlot.BodyPartType bodyPartSlotType = slot.GetBodyPartType(); List <GameObject> parts = GetUsableParts(slot.GetBodyPartType()); if (parts == null) { yield break; } //TODO: remove from parts all parts that cause a weakness int partCount = parts.Count; if (partCount == 0) { continue; } BodyPart part = slot.AddPart(parts [Random.Range(0, partCount)].GetComponent <BodyPart>(), this, this.MinRotation(), this.MaxRotation()); //if the slot is within a trigger do not create a new gameobjec part.GenerateBody(++depth, orientation); } yield return(new WaitForEndOfFrame()); }
//TODO: force the player to pick more than one type //TODO: no duplicate choice private IEnumerator GeneratePlayerBody() { DontDestroyOnLoad(this.gameObject); BodyPart.Init(); Stack <BodyPartSlot> frontier = new Stack <BodyPartSlot>(); m_bodySlot.GetComponent <BodyPartSlot> ().m_depth = 0; frontier.Push(m_bodySlot.GetComponent <BodyPartSlot>()); HashSet <BodyPart.ElementType> elements = new HashSet <BodyPart.ElementType>(); while (frontier.Count > 0) { m_NahButton.SetActive(false); BodyPartSlot slot = frontier.Pop(); bool isHead = slot.GetBodyPartType() == BodyPartSlot.BodyPartType.Head; if (slot.m_depth > 5 && isHead == false) { continue; } BodyPartSlot.BodyPartType bodyPartSlotType = slot.GetBodyPartType(); //TODO:pick three bodyparts HashSet <BodyPart.ElementType> types = new HashSet <BodyPart.ElementType>(); List <GameObject> parts; if (m_body == null) { parts = BodyPart.GetUsableParts(slot.GetBodyPartType(), true, null); } else { parts = BodyPart.GetUsableParts(slot.GetBodyPartType(), true, m_body.CountTypes(ref types)); } if (slot.m_depth >= 1 && isHead == false && frontier.Count - elements.Count >= Mathf.Max(PlayerPrefs.GetInt("Level", 0) / 3, 6)) { m_NahButton.SetActive(true); } bool shouldContinue = false; foreach (BodyPartDisplay display in m_bodyPartDisplays) { BodyPart bp = null; if (parts.Count > 0) { bp = parts [Random.Range(0, parts.Count)].GetComponent <BodyPart> (); } if (bp == null) { display.Display(null, 0, 0); shouldContinue = true; } else { display.Display(bp.gameObject, bp.MinRotation(), bp.MaxRotation()); } } if (shouldContinue) { continue; } m_spawnIndicator.transform.position = slot.transform.position; m_choice = null; //TODO:Let the player choose one while (m_choice == null && !(skip == true && slot.GetBodyPartType() != BodyPartSlot.BodyPartType.Body)) { yield return(new WaitForEndOfFrame()); } if (skip == true) { skip = false; continue; } BodyPart.RemoveConflicts(m_choice); m_choice.transform.localScale *= .25f; //TODO:Add the choice to the body m_audioSource.PlayOneShot(m_audioClip); m_choice = slot.AddPart(m_choice, slot.m_parentPart); elements.Add(m_choice.GetElementType()); if (m_body == null) { m_body = m_choice; } foreach (BodyPartSlot s in m_choice.GetSlots()) { s.m_parentPart = m_choice; s.m_depth = slot.m_depth + 1; frontier.Push(s); } yield return(new WaitForEndOfFrame()); } Destroy(m_spawnIndicator); m_body.CalculateScore(ref m_typeScores); CacheIfMatchProfile(); m_body.transform.parent = this.transform; //TODO: go to the next scene Fader.Instance.FadeIn().LoadLevel("PrototypeScene").FadeIn(3.0f).FadeOut(3.0f); }