public void RegisterGhost(ConstructionGhost ghost) { if (!this.m_AllGhosts.Contains(ghost)) { this.m_AllGhosts.Add(ghost); } }
public void Load() { for (int i = 0; i < this.m_AllGhosts.Count; i++) { UnityEngine.Object.Destroy(this.m_AllGhosts[i].gameObject); } this.m_AllGhosts.Clear(); int num = SaveGame.LoadIVal("GhostCount"); for (int j = 0; j < num; j++) { string text = SaveGame.LoadSVal("Ghost" + j); GameObject prefab = GreenHellGame.Instance.GetPrefab(text); if (!prefab) { DebugUtils.Assert("[ConstructionGhostManager:Load] ERROR - Can't load prefab - " + text, true, DebugUtils.AssertType.Info); } else { GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(prefab); gameObject.name = prefab.name; ConstructionGhost component = gameObject.GetComponent <ConstructionGhost>(); component.Load(j); } } }
public override void Activate(GameObject parent) { this.m_Boat = null; this.m_Supplies = null; for (int i = 0; i < parent.transform.childCount; i++) { GameObject gameObject = parent.transform.GetChild(i).gameObject; if (gameObject.name == this.m_BoatGhostName) { ConstructionGhost component = gameObject.GetComponent <ConstructionGhost>(); this.m_Boat = component; this.m_Boat.RegisterObserver(this); } else if (gameObject.name == this.m_SuppliesGhostName) { ConstructionGhost component2 = gameObject.GetComponent <ConstructionGhost>(); component2.gameObject.SetActive(false); this.m_Supplies = component2; this.m_Supplies.RegisterObserver(this); } } DebugUtils.Assert(this.m_Boat != null && this.m_Supplies != null, "Missing Boat ghost in challenge objects!", true, DebugUtils.AssertType.Info); base.Activate(parent); this.m_Supplies.gameObject.SetActive(false); }
protected override bool ShouldShow() { if (!ConstructionController.Get().IsActive()) { return(false); } ConstructionGhost ghost = ConstructionController.Get().GetGhost(); return(ghost != null && ghost.GetState() == ConstructionGhost.GhostState.Dragging); }
public void OnCreateConstruction(ConstructionGhost ghost, Item created_item) { if (ghost == this.m_Boat) { this.m_Supplies.gameObject.SetActive(true); base.NextObjective(); } else if (ghost == this.m_Supplies) { this.Success(); } }
private void UpdateActivity() { if (this.m_AllGhosts.Count == 0) { return; } if (Time.time - this.m_LastUpdateActivityTime < this.m_UpdateActivityInterval) { return; } float num = (float)Mathf.Min(20, this.m_AllGhosts.Count); int num2 = 0; while ((float)num2 < num) { if (this.m_CurrentIndex >= this.m_AllGhosts.Count) { this.m_CurrentIndex = 0; } ConstructionGhost constructionGhost = this.m_AllGhosts[this.m_CurrentIndex]; if (constructionGhost.m_Challenge) { this.m_CurrentIndex++; } else if (ScenarioManager.Get().IsPreDream()) { if (constructionGhost.gameObject.activeSelf) { constructionGhost.gameObject.SetActive(false); } this.m_CurrentIndex++; } else if (constructionGhost.m_ResultItemID == ItemID.Bamboo_Bridge && GreenHellGame.Instance.m_GameMode == GameMode.Story) { if (constructionGhost.gameObject.activeSelf) { constructionGhost.gameObject.SetActive(false); } this.m_CurrentIndex++; } else { bool flag = Player.Get().transform.position.Distance(constructionGhost.transform.position) < this.m_ActivityDist; if (constructionGhost.gameObject.activeSelf != flag && !constructionGhost.IsReady()) { constructionGhost.gameObject.SetActive(flag); } this.m_CurrentIndex++; } num2++; } this.m_LastUpdateActivityTime = Time.time; }
public void SetupAfterLoad() { bool flag = false; int num = SaveGame.LoadIVal("GhostCount"); for (int i = 0; i < num; i++) { string text = SaveGame.LoadSVal("Ghost" + i); GameObject prefab = GreenHellGame.Instance.GetPrefab(text); if (!prefab) { DebugUtils.Assert("[ConstructionGhostManager:Load] ERROR - Can't load prefab - " + text, true, DebugUtils.AssertType.Info); } else { GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(prefab); gameObject.name = prefab.name; ConstructionGhost component = gameObject.GetComponent <ConstructionGhost>(); component.Load(i); if (component.m_ResultItemID == ItemID.Bamboo_Bridge) { flag = true; } } } if (!flag && GreenHellGame.Instance.m_GameMode == GameMode.Survival) { GameObject gameObject2 = null; bool flag2 = false; foreach (Item item in Item.s_AllItems) { if (item.GetInfoID() == ItemID.Bamboo_Bridge) { flag2 = true; gameObject2 = item.gameObject; break; } } Vector3 zero = Vector3.zero; zero.Set(842.39f, 138.569f, 1617.97f); Quaternion identity = Quaternion.identity; identity.Set(-0.5448493f, -0.450922f, -0.451856f, 0.543723f); if (!flag2) { gameObject2 = UnityEngine.Object.Instantiate <GameObject>(GreenHellGame.Instance.GetPrefab("Bamboo_Bridge")); gameObject2.transform.position = zero; gameObject2.transform.rotation = identity; return; } gameObject2.transform.position = zero; gameObject2.transform.rotation = identity; } }
public void OnCreateConstruction(ConstructionGhost ghost, Item created_item) { foreach (ConstructionGhost y in this.m_Ghosts) { if (ghost == y) { Construction component = created_item.gameObject.GetComponent <Construction>(); DebugUtils.Assert(component, true); this.m_Constructions.Add(component); break; } } }
public void OnCreateConstruction(ConstructionGhost ghost, Item created_item) { foreach (ConstructionGhost y in this.m_Data.Keys) { if (ghost == y) { Construction component = created_item.gameObject.GetComponent <Construction>(); DebugUtils.Assert(component, true); this.m_Data[ghost] = component; HUDChallengeInfo.Get().SetupText(this); component.RegisterObserver(this); break; } } }
public void Save() { int num = 0; for (int i = 0; i < this.m_AllGhosts.Count; i++) { ConstructionGhost constructionGhost = this.m_AllGhosts[i]; if (constructionGhost.m_State == ConstructionGhost.GhostState.Building) { SaveGame.SaveVal("Ghost" + num, constructionGhost.name); constructionGhost.Save(num); num++; } } SaveGame.SaveVal("GhostCount", num); }
public override void Activate(GameObject parent) { this.m_Data.Clear(); for (int i = 0; i < parent.transform.childCount; i++) { ConstructionGhost component = parent.transform.GetChild(i).gameObject.GetComponent <ConstructionGhost>(); if (component) { component.m_DestroyOnCreateConstruction = false; component.RegisterObserver(this); this.m_Data.Add(component, null); } } this.m_Count = this.m_Data.Count; base.Activate(parent); }
public override void Activate(GameObject parent) { this.m_Ghosts.Clear(); this.m_Firecamps.Clear(); for (int i = 0; i < parent.transform.childCount; i++) { ConstructionGhost component = parent.transform.GetChild(i).gameObject.GetComponent <ConstructionGhost>(); if (component) { component.RegisterObserver(this); this.m_Ghosts.Add(component); } } this.m_Count = this.m_Ghosts.Count; base.Activate(parent); }
private void DestroyMe() { GameObject prefab = GreenHellGame.Instance.GetPrefab(this.m_Info.m_ID.ToString() + "Ghost"); ConstructionGhost component = prefab.GetComponent <ConstructionGhost>(); foreach (GhostStep ghostStep in component.m_Steps) { foreach (GhostSlot ghostSlot in ghostStep.m_Slots) { if (UnityEngine.Random.Range(0f, 1f) < 0.5f) { ItemsManager.Get().CreateItem((ItemID)Enum.Parse(typeof(ItemID), ghostSlot.m_ItemName), true, base.transform.TransformPoint(ghostSlot.transform.localPosition), Quaternion.identity); } } } GameObject gameObject = new GameObject(); OneShotSoundObject oneShotSoundObject = gameObject.AddComponent <OneShotSoundObject>(); gameObject.name = "OneShotSoundObject from Construction"; oneShotSoundObject.m_SoundNameWithPath = this.m_DestroySounds[UnityEngine.Random.Range(0, this.m_DestroySounds.Count)]; oneShotSoundObject.gameObject.transform.position = base.transform.position; UnityEngine.Object.Destroy(base.gameObject); }
private void Setup() { foreach (MenuConstructionSlot menuConstructionSlot in this.m_Slots) { menuConstructionSlot.parent.SetActive(false); } this.m_ActiveSlots.Clear(); int num = 0; foreach (ConstructionInfo constructionInfo in this.m_Infos) { if (constructionInfo.m_ConstructionType == this.m_ConstructionType) { if (num >= this.m_Slots.Count) { DebugUtils.Assert("[MenuConstruction:Setup] Not enough slots for constructions - " + this.m_ConstructionType.ToString(), true, DebugUtils.AssertType.Info); break; } string name = constructionInfo.m_ID.ToString() + "Ghost"; ConstructionGhost component = GreenHellGame.Instance.GetPrefab(name).GetComponent <ConstructionGhost>(); Dictionary <string, int> dictionary = new Dictionary <string, int>(); foreach (GhostStep ghostStep in component.m_Steps) { foreach (GhostSlot ghostSlot in ghostStep.m_Slots) { if (dictionary.ContainsKey(ghostSlot.m_ItemName)) { Dictionary <string, int> dictionary2 = dictionary; string itemName = ghostSlot.m_ItemName; int value = dictionary2[itemName] + 1; dictionary2[itemName] = value; } else { dictionary.Add(ghostSlot.m_ItemName, 1); } } } MenuConstructionSlot menuConstructionSlot2 = this.m_Slots[num]; num++; menuConstructionSlot2.parent.SetActive(true); menuConstructionSlot2.name.text = constructionInfo.m_ID.ToString(); menuConstructionSlot2.name.color = this.m_NormalColor; menuConstructionSlot2.info = constructionInfo; menuConstructionSlot2.components.text = string.Empty; menuConstructionSlot2.components.color = this.m_NormalColor; foreach (string text in dictionary.Keys) { Text components = menuConstructionSlot2.components; components.text = string.Concat(new object[] { components.text, text, "*", dictionary[text], ", " }); } this.m_ActiveSlots.Add(menuConstructionSlot2); } } }
public void UnregisterGhost(ConstructionGhost ghost) { this.m_AllGhosts.Remove(ghost); }
private void UpdateProhibitionType() { this.m_ProhibitionType = ConstructionGhost.ProhibitionType.None; if (this.m_AllignToTerrain && !this.m_Smoker && this.m_FirecampRacks.Count == 0) { float num = Vector3.Angle(base.transform.up, Vector3.up); if (num > this.m_MaxAllignAngle) { this.ClearCollidingPlants(); this.m_ProhibitionType = ConstructionGhost.ProhibitionType.Hard; return; } } Vector3 center = this.m_BoxCollider.bounds.center; Vector3 halfExtents = this.m_BoxCollider.size * 0.5f; center.y += this.m_ColliderShrinkBottom * 0.5f; halfExtents.y -= this.m_ColliderShrinkBottom; halfExtents.y = Mathf.Max(halfExtents.y, this.m_ColliderShrinkBottom); Collider[] collection = Physics.OverlapBox(center, halfExtents, this.m_BoxCollider.transform.rotation); List <Collider> list = new List <Collider>(collection); list.Remove(this.m_BoxCollider); if (this.m_PlacingCondition == ConstructionGhost.GhostPlacingCondition.NeedFirecamp && this.m_Firecamp) { list.Remove(this.m_Firecamp.m_Collider); } if ((ItemInfo.IsFirecamp(this.m_ResultItemID) || ItemInfo.IsStoneRing(this.m_ResultItemID)) && this.m_FirecampRacks.Count > 0) { foreach (FirecampRack firecampRack in this.m_FirecampRacks) { list.Remove(firecampRack.m_Collider); } } if ((ItemInfo.IsFirecamp(this.m_ResultItemID) || ItemInfo.IsStoneRing(this.m_ResultItemID)) && this.m_Smoker) { list.Remove(this.m_Smoker.m_Collider); } foreach (Collider collider in list) { if (!(collider.tag == "Sectr_trigger")) { if (this.m_ConstructionToAttachTo) { if (collider.gameObject == this.m_ConstructionToAttachTo.gameObject) { continue; } if (collider.gameObject == Terrain.activeTerrain.gameObject) { continue; } } if (!collider.gameObject.IsWater() && !this.m_LayerMasksToIgnore.Contains(collider.gameObject.layer) && !collider.isTrigger) { this.ClearCollidingPlants(); this.m_ProhibitionType = ConstructionGhost.ProhibitionType.Hard; return; } ConstructionGhost component = collider.gameObject.GetComponent <ConstructionGhost>(); if (component != null) { foreach (GhostStep ghostStep in component.m_Steps) { foreach (GhostSlot ghostSlot in ghostStep.m_Slots) { if (this.m_Collider.bounds.Intersects(ghostSlot.m_Collider.bounds)) { this.ClearCollidingPlants(); this.m_ProhibitionType = ConstructionGhost.ProhibitionType.Hard; return; } } } } Construction component2 = collider.gameObject.GetComponent <Construction>(); if (component2) { this.ClearCollidingPlants(); this.m_ProhibitionType = ConstructionGhost.ProhibitionType.Hard; return; } } } Collider collider2 = null; foreach (Collider collider3 in list) { if (collider3.gameObject.IsWater()) { collider2 = collider3; break; } } if (this.m_PlacingCondition == ConstructionGhost.GhostPlacingCondition.MustBeInWater && !collider2) { this.ClearCollidingPlants(); this.m_ProhibitionType = ConstructionGhost.ProhibitionType.Hard; return; } if ((this.m_PlacingCondition == ConstructionGhost.GhostPlacingCondition.CantBeInWater || this.m_PlacingCondition == ConstructionGhost.GhostPlacingCondition.NeedFirecamp) && collider2) { this.ClearCollidingPlants(); this.m_ProhibitionType = ConstructionGhost.ProhibitionType.Hard; return; } if (collider2 && this.m_MaxDepthOfWater > 0f) { float num2 = collider2.bounds.max.y - this.m_BoxCollider.bounds.min.y; if (num2 > this.m_MaxDepthOfWater) { this.ClearCollidingPlants(); this.m_ProhibitionType = ConstructionGhost.ProhibitionType.Hard; return; } } if (this.m_PlacingCondition == ConstructionGhost.GhostPlacingCondition.Whatever || this.m_PlacingCondition == ConstructionGhost.GhostPlacingCondition.CantBeInWater) { List <GameObject> list2 = new List <GameObject>(); foreach (Collider collider4 in list) { if (this.m_LayerMasksToIgnore.Contains(collider4.gameObject.layer) && collider4.gameObject.layer != this.m_ItemLayer) { if (!this.m_CollidingPlants.ContainsKey(collider4.gameObject)) { this.AddCollidingPlant(collider4.gameObject); } list2.Add(collider4.gameObject); } } int i = 0; while (i < this.m_CollidingPlants.Keys.Count) { if (!list2.Contains(this.m_CollidingPlants.ElementAt(i).Key)) { this.RemoveCollidingPlant(this.m_CollidingPlants.ElementAt(i).Key); } else { i++; } } } if (this.m_CollidingPlants.Count > 0) { this.m_ProhibitionType = ConstructionGhost.ProhibitionType.Soft; return; } }