public bool add_upgrade(ref upgrade_description upgrade, SavedUnitGroup group) { Debug.Log("unit upgrade add"); if(upgrade != null && upgrade.upgrade_type == vars.upgrade_type.units){ Debug.Log("upgrade check"); base_manager thisBase = GameObject.FindGameObjectWithTag(vars.base_tag+""+vars.friendly_tag+""+vars.attackable_tag).GetComponent<base_manager>(); if(thisBase.res_a_storage >= upgrade.costs_res_a && thisBase.res_b_storage >= upgrade.costs_res_b && thisBase.res_c_storage >= upgrade.costs_res_c){ Debug.Log("costs check"); // remove resources from base thisBase.res_a_storage -= upgrade.costs_res_a; thisBase.res_b_storage -= upgrade.costs_res_b; thisBase.res_c_storage -= upgrade.costs_res_c; if(group.upgrade_slot_0 == null || group.upgrade_slot_1 == null || group.upgrade_slot_2 == null){ switch (upgrade.upgrade_add_to_value) { case vars.upgrade_values.ant_life: group.health += upgrade.increase_value; break; case vars.upgrade_values.ant_damage: group.damage += upgrade.increase_value; break; case vars.upgrade_values.ant_speed: group.movementspeed += upgrade.increase_value; break; case vars.upgrade_values.ant_regeneration: group.regeneration += upgrade.increase_value; break; default: break; } if(group.upgrade_slot_0 == null){ group.upgrade_slot_0 = upgrade; //Debug.Log("set upgrade to slot 0"); GameObject.Find(vars.ui_manager_name).GetComponent<ui_manager>().upgrade_unit_button_0.GetComponent<Image>().sprite = group.upgrade_slot_0.upgrade_icon; }else if(group.upgrade_slot_1 == null){ group.upgrade_slot_1 = upgrade; //Debug.Log("set upgrade to slot 1"); GameObject.Find(vars.ui_manager_name).GetComponent<ui_manager>().upgrade_unit_button_1.GetComponent<Image>().sprite = group.upgrade_slot_1.upgrade_icon; }else if(group.upgrade_slot_2 == null){ group.upgrade_slot_2 = upgrade; //Debug.Log("set upgrade to slot 2"); GameObject.Find(vars.ui_manager_name).GetComponent<ui_manager>().upgrade_unit_button_2.GetComponent<Image>().sprite = group.upgrade_slot_2.upgrade_icon; } return true; } }else{ Debug.Log("err 2"); } }else{ Debug.Log("err 1"); } return false; }
public bool add_upgrade(ref upgrade_description upgrade) { Debug.Log("call add"); if(upgrade != null && !upgrade.taken && upgrade.active & upgrade.upgrade_type == vars.upgrade_type.ressources){ Debug.Log("upgrade check"); if(GameObject.Find(vars.base_name).GetComponent<base_manager>().res_a_storage >= upgrade.costs_res_a && GameObject.Find(vars.base_name).GetComponent<base_manager>().res_b_storage >= upgrade.costs_res_b && GameObject.Find(vars.base_name).GetComponent<base_manager>().res_c_storage >= upgrade.costs_res_c){ Debug.Log("costs check"); if(upgrade_slot_0 == null || upgrade_slot_1 == null || upgrade_slot_2 == null || upgrade_slot_3 == null){ Debug.Log("slot check"); upgrade.GetComponent<upgrade_description>().taken = true; GameObject.Find(vars.base_name).GetComponent<base_manager>().res_a_storage -= upgrade.costs_res_a; GameObject.Find(vars.base_name).GetComponent<base_manager>().res_b_storage -= upgrade.costs_res_b; GameObject.Find(vars.base_name).GetComponent<base_manager>().res_c_storage -= upgrade.costs_res_c; Debug.Log("costs sub"); switch (upgrade.GetComponent<upgrade_description>().upgrade_add_to_value) { case vars.upgrade_values.antbitedescrease: res.ant_bite_decrease += upgrade.increase_value; break; case vars.upgrade_values.productioneffiency: res.effiency -= upgrade.increase_value; break; case vars.upgrade_values.leben: res.health_percentage += (int)upgrade.increase_value; break; default: break; } Debug.Log("add values"); if(upgrade_slot_0 == null){ upgrade_slot_0 = upgrade; Debug.Log("set upgrade to slot 0"); }else if(upgrade_slot_1 == null){ upgrade_slot_1 = upgrade; Debug.Log("set upgrade to slot 1"); }else if(upgrade_slot_2 == null){ upgrade_slot_2 = upgrade; Debug.Log("set upgrade to slot 2"); }else if(upgrade_slot_3 == null){ upgrade_slot_3 = upgrade; Debug.Log("set upgrade to slot 3"); //GameObject.Find(vars.ui_manager_name).GetComponent<ui_manager>().upgrade_base_button_0.GetComponent<Image>().sprite = upgrade_slot_0.upgrade_icon; } Debug.Log("upgrade taken"); return true; } }else{ Debug.Log("err 2"); } }else{ Debug.Log("err 1"); } return false; }
//0-8 public void select_upgrade(int btn_id) { //if array an pos i = 0 if(view_specific_upgrades[btn_id] != null){ upgrade_ui_headline_text.GetComponent<Text>().text = view_specific_upgrades[btn_id].upgrade_headline; upgrade_ui_description_text.GetComponent<Text>().text = view_specific_upgrades[btn_id].upgrade_desc; selected_upgrade = view_specific_upgrades[btn_id]; } //update_upgrade_ui = true; }
public bool add_upgrade(ref upgrade_description upgrade) { Debug.Log("call add"); if(upgrade != null && !upgrade.taken && upgrade.active & upgrade.upgrade_type == vars.upgrade_type.ant_base){ Debug.Log("upgrade check"); if(res_a_storage >= upgrade.costs_res_a && res_b_storage >= upgrade.costs_res_b && res_c_storage >= upgrade.costs_res_c){ Debug.Log("costs check"); if(upgrade_slot_0 == null || upgrade_slot_1 == null || upgrade_slot_2 == null || upgrade_slot_3 == null){ Debug.Log("slot check"); upgrade.GetComponent<upgrade_description>().taken = true; res_a_storage -= upgrade.costs_res_a; res_b_storage -= upgrade.costs_res_b; res_c_storage -= upgrade.costs_res_c; Debug.Log("costs sub"); switch (upgrade.GetComponent<upgrade_description>().upgrade_add_to_value) { case vars.upgrade_values.lagerplatz_res_all: vars.max_storage_res_a += (int)upgrade.increase_value; vars.max_storage_res_b += (int)upgrade.increase_value; vars.max_storage_res_c += (int)upgrade.increase_value; break; case vars.upgrade_values.lagerplatz_res_a: vars.max_storage_res_a += (int)upgrade.increase_value; break; case vars.upgrade_values.lagerplatz_res_b: vars.max_storage_res_b += (int)upgrade.increase_value; break; case vars.upgrade_values.lagerplatz_res_c: vars.max_storage_res_c += (int)upgrade.increase_value; break; case vars.upgrade_values.leben: health += (int)upgrade.increase_value; break; case vars.upgrade_values.ant_query_waittime: vars.costs_scout_ants.ant_query_waittime -= upgrade.increase_value; break; default: break; } Debug.Log("add values"); if(upgrade_slot_0 == null){ upgrade_slot_0 = upgrade; Debug.Log("set upgrade to slot 0"); GameObject.Find(vars.ui_manager_name).GetComponent<ui_manager>().upgrade_base_button_0.GetComponent<Image>().sprite = upgrade_slot_0.upgrade_icon; }else if(upgrade_slot_1 == null){ upgrade_slot_1 = upgrade; Debug.Log("set upgrade to slot 1"); GameObject.Find(vars.ui_manager_name).GetComponent<ui_manager>().upgrade_base_button_1.GetComponent<Image>().sprite = upgrade_slot_1.upgrade_icon; }else if(upgrade_slot_2 == null){ upgrade_slot_2 = upgrade; Debug.Log("set upgrade to slot 2"); GameObject.Find(vars.ui_manager_name).GetComponent<ui_manager>().upgrade_base_button_2.GetComponent<Image>().sprite = upgrade_slot_2.upgrade_icon; }else if(upgrade_slot_3 == null){ upgrade_slot_3 = upgrade; Debug.Log("set upgrade to slot 3"); //GameObject.Find(vars.ui_manager_name).GetComponent<ui_manager>().upgrade_base_button_0.GetComponent<Image>().sprite = upgrade_slot_0.upgrade_icon; } Debug.Log("upgrade taken"); return true; } }else{ Debug.Log("err 2"); } }else{ Debug.Log("err 1"); } return false; }
public void buy_selected_upgrade() { Debug.Log("buy btn"); //if(ui_view_slot_0 == selected_ui_in_slot_0.base_ui){ if(selected_upgrade.gameObject != null){ Debug.Log("selected not empty"); switch (ui_view_slot_0) { case selected_ui_in_slot_0.base_ui: if(base_manager_cache.add_upgrade(ref selected_upgrade)){ show_upgrade_ui = false; selected_upgrade = null; upgrade_ui_headline_text.GetComponent<Text>().text = "NO UPGRADE SELECTED"; upgrade_ui_description_text.GetComponent<Text>().text = "Please select an Upgrade on the left side"; } break; case selected_ui_in_slot_0.ressource_ui: if(GameObject.Find(vars.res_name + "_" + connected_res_to_ui).GetComponent<ressource>().add_upgrade(ref selected_upgrade)){ show_upgrade_ui = false; selected_upgrade = null; upgrade_ui_headline_text.GetComponent<Text>().text = "NO UPGRADE SELECTED"; upgrade_ui_description_text.GetComponent<Text>().text = "Please select an Upgrade on the left side"; } break; case selected_ui_in_slot_0.unit_ui: if(is_saved_group && unit_group_chache_cache.add_upgrade(ref selected_upgrade, sug) && ui_view_slot_0 == selected_ui_in_slot_0.unit_ui){ show_upgrade_ui = false; selected_upgrade = null; upgrade_ui_headline_text.GetComponent<Text>().text = "NO UPGRADE SELECTED"; upgrade_ui_description_text.GetComponent<Text>().text = "Please select an Upgrade on the left side"; } break; default: break; } }else{ Debug.Log("selected empty"); } update_upgrade_ui = true; }