virtual protected void Awake() { gM = GameManager.Instance; myTownCenter = gM.myTownCenter; mMovement = GetComponent <MinerMovement>(); mActions = GetComponent <MinerAction>(); mAnimations = GetComponentInChildren <MinerAnimations>(); timeLeft = timeToTryFinding; }
/// <summary> /// Determines if an NPC should undock /// </summary> /// <remarks> /// <para> /// All eligble NPCs can undock at the same time. An NPC is eligible if they have been /// docked greater than or equal to their dockTime value plus a small random value. /// </para> /// <para> /// This method handles both merchants and miners in the same query. /// </para> /// <para> /// The NPC should have already had their facing set to their next destination /// in the NPCMovement script, so when they reactivate, they'll be facing in /// the proper direction already. /// </para> /// </remarks> void UndockNPC() { float currentTime = Time.time; List <GameObject> dockedNPCs = (from m in merchantNPCList where m.GetComponent <MerchantMovement>().isDocked.Equals(true) && (m.GetComponent <MerchantMovement>().dockTime + sc.GetRandomInt(5, 30) + 5.0f) < currentTime select m) .Union (from m in minerNPCList where m.GetComponent <MinerMovement>().isDocked.Equals(true) && (m.GetComponent <MinerMovement>().dockTime + sc.GetRandomInt(5, 30) + 5.0f) < currentTime select m ).ToList(); //All eligible NPCs. Clear their IsDocked flags and reset their dockTime //Individual movement scripts will handle the forward movement at that point foreach (GameObject go in dockedNPCs) { NPC thisNPC = go.GetComponent <NPC>(); switch (thisNPC.NPCType) { case NPC.NPCTYPE.Merchant: MerchantMovement merchantMovement = go.GetComponent <MerchantMovement>(); merchantMovement.isDocked = false; merchantMovement.dockTime = 0.0f; break; case NPC.NPCTYPE.Pirate: break; case NPC.NPCTYPE.Police: break; case NPC.NPCTYPE.Miner: MinerMovement minerMovement = go.GetComponent <MinerMovement>(); minerMovement.isDocked = false; minerMovement.dockTime = 0.0f; break; default: break; } //Activate the docked object go.SetActive(true); } }
/// <summary> /// Spawns a miner and places them in the world /// </summary> /// <param name="minerCount">The current iterator from the merchant pool</param> /// <remarks> /// <para> /// Miner spawning is the more complex of the NPCs. /// </para> /// <para> /// For each Miner we're spawning, we have to pick a random asteroid. Asteroids /// have an AsteroidController which creates a series of eligible spawn points around the /// center point of the game object. Using the minerCount in conjunction with these /// spawn points, we place miners at unique spawn points around the asteroid game object. /// </para> /// <para> /// We do this because miners need to not spawn on top of one another, and to the /// point where the miners spawn, they must return when they leave the station. /// </para> /// <para> /// Myabe in the future we can spawn NPCs at asteroids which have the most lucritive /// yield, although that would take up all slots on the asteroid. /// </para> /// <para> /// Note2Dev: If we have 6 spawn points per asteroid, and all spots are taken up, /// then the minerCount value will exceed the ability to place new miners because we use that /// value to determine the numbered spawn point. Maybe we can randomly select a /// spawn point rather than rely on the number scheme. /// </para> /// </remarks> IEnumerator SpawnMinerNPC(int minerCount) { if (minerNPCList.Count > 0) { GameObject newNPC = GetMinerFromPool(); NPC npcComponent = newNPC.GetComponent <NPC>(); MinerMovement npcMove = newNPC.GetComponent <MinerMovement>(); //Get a random asteroid in the scene. GameObject startingObject = sc.GetRandomAsteroid(); AsteroidController ac = startingObject.GetComponent <AsteroidController>(); if (startingObject != null) { //Each asteroid should have some children named "ast_egressPoint[X]", where X is an integer. if (startingObject.transform.childCount > 0) { //Find an egressPoint which matches the minerCount. GameObject child = startingObject.transform.FindChild("ast_egressPoint" + minerCount).gameObject; //Check the asteroid's assigned points list. If this point isn't in there, use it if (child != null && !ac.egressAssigned.Contains(child.name)) { //Mark as used ac.egressAssigned.Add(child.name); //Spawn the NPC at this point Vector3 spawnPos = child.transform.position; newNPC.transform.position = spawnPos; //Set demographics, turn, and activate npcComponent.currentSector = sc.sectorID; npcMove.isMining = true; transform.LookAt(startingObject.transform, Vector3.up); newNPC.SetActive(true); } } } } yield return(null); }