public override void StartAction(GameObject g) { this.targetGameObject = g; this.targetResource = g.GetComponent <Resource>(); this.followerAgent = follower.GetComponent <NavMeshAgent>(); this.followerAgent.SetDestination(this.targetPosition); this.followerScript = follower.GetComponent <Follower>(); this.storagePoint = GameObject.FindGameObjectWithTag("Storage"); this.resourceWeight = g.GetComponent <Resource>().resourceWeight; this.followerAgent.SetDestination(targetGameObject.transform.position); this.followerAgent.stoppingDistance = 0f; if (followerScript.resource.GetType() != targetResource.GetType() && followerScript.currentLoad > 0) { hasPreviousResource = true; } else { followerScript.resource = ResourceTypes.GetByType(targetResource.resourceType); } }
public override void PerformAction() { if (followerScript.currentCollidingObject != null && followerScript.currentCollidingObject == storagePoint && !hasResource) { if (followerScript.resource != null && followerScript.currentLoad > 0) { gameManager.AddResource(followerScript.resource.resourceType, followerScript.itemAmount); followerScript.currentLoad = 0; followerScript.itemAmount = 0; if (isFinished) { followerScript.RemoveAction(); } } foreach (Building.Requirements r in blueprints.requirementsList) { if (r.currentAmount < r.requiredAmount) { followerScript.resource = ResourceTypes.GetByType(r.type); while (followerScript.currentLoad <= followerScript.storageCapacity - followerScript.resource.resourceWeight) { followerScript.itemAmount++; followerScript.currentLoad += followerScript.resource.resourceWeight; gameManager.RemoveResource(followerScript.resource.resourceType, 1); } followerAgent.SetDestination(building.transform.position); hasResource = true; break; } } } if (followerScript.currentCollidingObject != null && followerScript.currentCollidingObject == building && hasResource) { if (isFinished) { followerAgent.SetDestination(storagePoint.transform.position); } else { if (followerScript.itemAmount > 0) { foreach (Building.Requirements r in blueprints.requirementsList) { if (r.currentAmount < r.requiredAmount) { while (r.currentAmount < r.requiredAmount) { r.currentAmount++; followerScript.itemAmount--; followerScript.currentLoad -= followerScript.resource.resourceWeight; } followerAgent.SetDestination(storagePoint.transform.position); break; } } hasResource = false; } else { followerAgent.SetDestination(storagePoint.transform.position); } } } }
public override void PerformAction() { //Check if follower still has leftover resource of a different type if (hasPreviousResource) { followerAgent.SetDestination(storagePoint.transform.position); if (followerScript.currentCollidingObject == storagePoint) { this.gameManager.AddResource(followerScript.resource.resourceType, followerScript.itemAmount); this.followerScript.itemAmount = 0; this.followerScript.currentLoad = 0; this.hasPreviousResource = false; followerScript.resource = ResourceTypes.GetByType(targetResource.resourceType); } } else { if (followerScript.currentCollidingObject == targetGameObject) { if (!isFull && !isCooldown && followerScript.currentLoad <= followerScript.storageCapacity - resourceWeight && targetGameObject.GetComponent <Resource>().resourceAmount > 0 && lastCall == false) { this.followerScript.itemAmount++; this.followerScript.currentLoad += resourceWeight; this.targetGameObject.GetComponent <Resource>().resourceAmount--; isCooldown = true; } else if (!(followerScript.currentLoad < followerScript.storageCapacity - resourceWeight)) { this.isFull = true; } else if (targetGameObject.GetComponent <Resource>().resourceAmount <= 0) { lastCall = true; this.followerAgent.SetDestination(storagePoint.transform.position); } if (isFull) { this.followerAgent.SetDestination(storagePoint.transform.position); } } else if (followerScript.currentCollidingObject == storagePoint) { this.gameManager.AddResource(followerScript.resource.resourceType, followerScript.itemAmount); this.followerScript.itemAmount = 0; this.followerScript.currentLoad = 0; this.isFull = false; if (!lastCall) { this.followerAgent.SetDestination(targetGameObject.transform.position); } else { EndAction(); } } if (isCooldown) { cooldownTimer += Time.deltaTime; if (cooldownTimer > 1f) { isCooldown = false; cooldownTimer = 0f; } } } }