public void add_to_storage(vars.ressource_type _type, float _amount) { switch (_type) { case vars.ressource_type.A: res_a_storage += _amount; if (res_a_storage > vars.max_storage_res_a) { res_a_storage = vars.max_storage_res_a; } break; case vars.ressource_type.B: res_b_storage += _amount; if (res_b_storage > vars.max_storage_res_b) { res_b_storage = vars.max_storage_res_b; } break; case vars.ressource_type.C: res_c_storage += _amount; if (res_c_storage > vars.max_storage_res_c) { res_c_storage = vars.max_storage_res_c; } break; default: break; } }
public void loose_percentage_value_of_storage(vars.ressource_type _type, int percentage) { float npercentage = percentage / 100; npercentage = 1 - npercentage; switch (_type) { case vars.ressource_type.A: res_a_storage = res_a_storage * npercentage; if (res_a_storage < 0.0f) { res_a_storage = 0.0f; } break; case vars.ressource_type.B: res_a_storage = res_b_storage * npercentage; if (res_b_storage < 0.0f) { res_b_storage = 0.0f; } break; case vars.ressource_type.C: res_a_storage = res_c_storage * npercentage; if (res_c_storage < 0.0f) { res_c_storage = 0.0f; } break; default: break; } }
public void harvest() { GameObject.Find ("ui_manager").GetComponent<ui_manager>().refresh_ressource_ui(); GameObject.Find ("ui_manager").GetComponent<ui_manager>().refresh_ressource_ui_slots(); navMeshAgent.enabled = true; navMeshObstacle.enabled = false; //navMeshAgent.Resume(); meshRenderer.material.mainTexture = fullTexture; currentResourceAmount = targetRessource.ant_bite(); ressourceType = targetRessource.res_type; hasRessource = true; bitten = false; animator.SetBool("harvesting", false); animator.SetBool("isrunning", true); }
public void harvest() { GameObject.Find("ui_manager").GetComponent <ui_manager>().refresh_ressource_ui(); GameObject.Find("ui_manager").GetComponent <ui_manager>().refresh_ressource_ui_slots(); navMeshAgent.enabled = true; navMeshObstacle.enabled = false; //navMeshAgent.Resume(); meshRenderer.material.mainTexture = fullTexture; currentResourceAmount = targetRessource.ant_bite(); ressourceType = targetRessource.res_type; hasRessource = true; bitten = false; animator.SetBool("harvesting", false); animator.SetBool("isrunning", true); }
// Update is called once per frame void FixedUpdate() { if(currentPointInPath == 0) { //NavMeshHit test; //NavMesh.SamplePosition(baseManager.gameObject.transform.position, out test, 2.0f, NavMesh.AllAreas); Vector3 t = baseManager.gameObject.transform.position + (Vector3.Normalize(transform.position - baseManager.gameObject.transform.position) * 2.0f); updateNavmesh(t); } else { updateNavmesh(currentPointPosition()); } if(!hasRessource) { if(Vector3.Distance(transform.position, currentPointPosition()) < currentMovementOffset && isActive) { if(currentPointInPath < targetWP.path_to_base.Count-1) { currentPointInPath++; currentMovementOffset = Random.Range(movementLowerOffset, movementUpperOffset); } else if(!bitten){ if(targetRessource.res.current_harvest_amount >= 5) { animator.SetBool("harvesting", true); animator.SetBool("isrunning", false); navMeshAgent.enabled = false; navMeshObstacle.enabled = true; transform.LookAt(pathManager.getNodeObjectById(currentPointID()).transform); Invoke ("harvest", 5.0f); bitten = true; } else { bitten = false; hasRessource = true; retreat = true; } } } } else { if(Vector3.Distance(transform.position, currentPointPosition()) < currentMovementOffset && isActive) { if(pathManager.getNodeObjectById(currentPath[currentPointInPath]).GetComponent<path_point>().type == path_point.node_type.base_node) { baseManager.add_to_storage(ressourceType, currentResourceAmount); hasRessource = false; currentResourceAmount = 0; meshRenderer.material.mainTexture = normalTexture; ressourceType = vars.ressource_type.default_type; GameObject.Find ("ui_manager").GetComponent<ui_manager>().refresh_ressource_ui(); GameObject.Find ("ui_manager").GetComponent<ui_manager>().refresh_ressource_ui_slots(); if(retreat) { retreatToBase(); } } if(currentPointInPath > 0) { currentPointInPath--; if(pathManager.getNodeObjectById(currentPath[currentPointInPath]).GetComponent<path_point>().type == path_point.node_type.base_node) { currentMovementOffset = 3.0f; } else { currentMovementOffset = Random.Range(movementLowerOffset, movementUpperOffset); } } } } }
// Update is called once per frame void FixedUpdate() { if (currentPointInPath == 0) { //NavMeshHit test; //NavMesh.SamplePosition(baseManager.gameObject.transform.position, out test, 2.0f, NavMesh.AllAreas); Vector3 t = baseManager.gameObject.transform.position + (Vector3.Normalize(transform.position - baseManager.gameObject.transform.position) * 2.0f); updateNavmesh(t); } else { updateNavmesh(currentPointPosition()); } if (!hasRessource) { if (Vector3.Distance(transform.position, currentPointPosition()) < currentMovementOffset && isActive) { if (currentPointInPath < targetWP.path_to_base.Count - 1) { currentPointInPath++; currentMovementOffset = Random.Range(movementLowerOffset, movementUpperOffset); } else if (!bitten) { if (targetRessource.res.current_harvest_amount >= 5) { animator.SetBool("harvesting", true); animator.SetBool("isrunning", false); navMeshAgent.enabled = false; navMeshObstacle.enabled = true; transform.LookAt(pathManager.getNodeObjectById(currentPointID()).transform); Invoke("harvest", 5.0f); bitten = true; } else { bitten = false; hasRessource = true; retreat = true; } } } } else { if (Vector3.Distance(transform.position, currentPointPosition()) < currentMovementOffset && isActive) { if (pathManager.getNodeObjectById(currentPath[currentPointInPath]).GetComponent <path_point>().type == path_point.node_type.base_node) { baseManager.add_to_storage(ressourceType, currentResourceAmount); hasRessource = false; currentResourceAmount = 0; meshRenderer.material.mainTexture = normalTexture; ressourceType = vars.ressource_type.default_type; GameObject.Find("ui_manager").GetComponent <ui_manager>().refresh_ressource_ui(); GameObject.Find("ui_manager").GetComponent <ui_manager>().refresh_ressource_ui_slots(); if (retreat) { retreatToBase(); } } if (currentPointInPath > 0) { currentPointInPath--; if (pathManager.getNodeObjectById(currentPath[currentPointInPath]).GetComponent <path_point>().type == path_point.node_type.base_node) { currentMovementOffset = 3.0f; } else { currentMovementOffset = Random.Range(movementLowerOffset, movementUpperOffset); } } } } }