public void AddItemToRefiner(GameObject go) { float maxbin = this.settings.Items_max; if (go.tag == "material" && processing_bin.Count < maxbin) { ItemResorce mr = go.GetComponent <ItemResorce>(); ModuleSystemInfo msi = go.GetComponent <ModuleSystemInfo>(); if (mr != null && msi == null) { if (mr.GetNeedsRefining() == true) { //Storing material processing_bin.Add(mr.Item_type); Destroy(go); } else { UnityFunctions.ship_manager.Store_Material(mr.Item_type); Destroy(go); } } else if (mr != null && msi != null) { //Storing a module UnityFunctions.ship_manager.Store_Module(go); } } else if (go.tag == "blueprint") { ItemResorce mr = go.GetComponent <ItemResorce>(); UnityFunctions.ship_manager.Store_Material(mr.Item_type); Destroy(go); } }
public void SetModule(ModuleSystemInfo m) { this.module_info = m; if (this.module_info != null) { SetToggleNameAndValue(this.module_info.name, this.module_info.active, this.module_info.current_health, this.module_info.Is_Malfunctioning()); } }
public void SetInvetoryInfo(InventoryItem inv) { //This will display the info this.inv = inv; this.module_info = this.inv.item.GetComponent <ModuleSystemInfo>(); //********************* //Load the upgrade info //********************* this.LoadUpgradeList(); }
private void Start() { rb = gameObject.GetComponent <Rigidbody2D>(); if (command_module != null) { this.command_mod_system_info = command_module.GetComponent <ModuleSystemInfo>(); } this.child_Start(); CalcUpgrades(); }
private IEnumerator RepairItem() { while (true) { this.repair_ammount = this.settings.Action_speed; this.time_between_repair = this.settings.Action_speed2; this.max_repair = this.settings.Ammount; if (this.is_online && this.active) { if (current_item == null) { float smallest_health = 999999; //find somthing that needs repairing ModuleSystemInfo[] items = GeEquipedItems(); foreach (ModuleSystemInfo i in items) { if (i.Is_Destroyed() == false && i.current_health < smallest_health && i.current_health < this.max_repair) { current_item = i; smallest_health = i.current_health; } } if (current_item != null) { StartUsage(); UnityFunctions.SendAlert(Enums.enum_status.Info, "Repairing " + current_item.name); } } else { if (current_item.current_health >= this.max_repair) { UnityFunctions.SendAlert(Enums.enum_status.Info, current_item.name + " Repaired "); current_item = null; } else { current_item.current_health += repair_ammount; if (current_item.current_health > this.max_repair) { current_item.current_health = this.max_repair; current_item = null; StopUsage(); } } } } yield return(new WaitForSeconds(time_between_repair)); } }
//****************************************** //Lets see whats in range and give it damage //****************************************** private void ApplyExplosionForce(Vector2 center, float radius, float forceMultiplier) { int hit_mask = (1 << LayerMask.NameToLayer("Player")); Collider2D[] hitColliders = Physics2D.OverlapCircleAll(center, radius, hit_mask); int i = 0; //Apply force if (hitColliders.Length > 0) { //GameObject player = GameObject.Find("Player"); Rigidbody2D rb = UnityFunctions.player.GetComponent <Rigidbody2D>(); Vector2 force = (UnityFunctions.player.transform.position - transform.position) * (forceMultiplier * 100); rb.AddForce(force); } //********************************** //We need to see if we have a shield //********************************** var res = (from n in hitColliders where n.name == "Shield(Clone)" select n).FirstOrDefault(); if (res != null) { Shield s = res.GetComponent <Shield>(); if (s.shield_online == true) { ApplyDamageByForceToShield(res.gameObject, transform); } } else { while (i < hitColliders.Length) { ModuleSystemInfo ir = hitColliders[i].GetComponent <ModuleSystemInfo>(); if (ir != null) { ApplyDamageByForce(hitColliders[i].gameObject, transform); } i++; } } }
public void ReadData(GameObject module) { ModuleSystemInfo sys = module.GetComponent <ModuleSystemInfo>(); ItemResorce ir = module.GetComponent <ItemResorce>(); //Save the upgrades foreach (Upgrade_Settings u in sys.upgrades) { upgrades.Add(u.Full_name); } module_name = ir.Item_Data.recipe_name; //id = module.name; item_type = ir.Item_Data.item_type; mount_point = sys.mount_point; health = sys.current_health; order_layer = sys.order_layer; is_in_storage = sys.is_in_storage; enabled = sys.active; is_internal_module = sys.is_internal_module; }
private void ApplyDamageByForce(GameObject game_obj, Transform source_transform = null) { ModuleSystemInfo ship_managment = game_obj.GetComponent <ModuleSystemInfo>(); if (ship_managment != null && source_transform != null) { float ratio = 1 / (source_transform.position - game_obj.transform.position).sqrMagnitude; if (ratio > 0) { ship_managment.DamageShip(shockwave_damagefactor * ratio); } } else { DamageDealer damageDealer = game_obj.gameObject.GetComponent <DamageDealer>(); if (damageDealer) { ProcessHit(damageDealer); } } }
public void Equip(GameObject obj) { if (modules_game_object == null) { modules_game_object = GameObject.Find("Modules"); } ModuleSystemInfo module_info = obj.GetComponent <ModuleSystemInfo>(); ItemResorce ir = obj.GetComponent <ItemResorce>(); SpaceShipMovment controls = gameObject.GetComponent <SpaceShipMovment>(); obj.transform.parent = modules_game_object.transform; if (ir.Item_type == Enums.enum_item.module_command_module_type1) { command_module = obj.GetComponent <ShipModule>(); //First we need to store the item command_module.LoadMountPoints(); MountPoint mp = command_module.mount_points[0]; //Set the max storage command_module.ShowMountPoints(); max_storage_items = module_info.max_storage_items; mp.max_mounting = max_storage_items; } else { MountPoint mp = command_module.mount_points[module_info.mount_point]; obj.transform.position = mp.transform.position; obj.transform.rotation = mp.transform.rotation; module_info.mount_point = mp.index; module_info.key_mappings = mp.key_mappings; module_info.SetRenderOrder(mp.render_order); } foreach (KeyMappingModel e in module_info.key_mappings) { controls.AddKeyBinding(e, obj); } module_info.IteminUse(module_info.is_internal_module); }
/// <summary> /// This function stores the modules /// </summary> /// <param name="module"></param> public void Store_Module(GameObject module) { if (Stored_Modules_game_object == null) { Stored_Modules_game_object = GameObject.Find("Stored_Modules"); } ModuleSystemInfo module_info = module.GetComponent <ModuleSystemInfo>(); if (module_info.is_command_module) { if (command_module != null) { command_module.HideMountPoints(); } this.command_module = null; } ItemResorce ir = module.GetComponent <ItemResorce>(); module_info.IteminStorage(); module.transform.parent = Stored_Modules_game_object.transform; // if (!module_info.is_command_module) { // inventory.Add(new InventoryManager.Item(ir.Item_type, module)); // } }
public void SetItem(GameObject item) { Debug.Log("Adding item"); //WriteLine(item); ItemResorce ir = item.GetComponent <ItemResorce>(); sr = GetComponent <Image>(); this.item_type = ir.Item_type; ModuleSystemInfo module_sys = item.GetComponent <ModuleSystemInfo>(); this.mount_type_util_side = module_sys.mount_type_util_side; this.mount_type_util_top = module_sys.mount_type_util_top; this.mount_type_internal = module_sys.is_internal_module; this.mount_type_thruster = module_sys.mount_type_thruster; this.mount_type_engine = module_sys.mount_type_engine; this.is_command_module = module_sys.is_command_module; this.item = item; //SpriteRenderer isr = item.GetComponent<SpriteRenderer>(); sr.sprite = module_sys.settings.Sprite; //module_sys.settings.ico //************* //Set the image //************* /* switch (this.item_type) { * case Enums.enum_item.module_command_module_type1: * sr.sprite = single_blaster; * break; * * case Enums.enum_item.module_single_blaster: * sr.sprite = single_blaster; * break; * * case Enums.enum_item.module_double_blaster: * sr.sprite = double_blaster; * break; * * case Enums.enum_item.module_mining_laser: * sr.sprite = mining_laser; * break; * * case Enums.enum_item.module_main_engine: * sr.sprite = main_engine; * break; * * case Enums.enum_item.module_thruster: * sr.sprite = thruster; * break; * * case Enums.enum_item.module_refiner: * sr.sprite = refiner; * break; * * case Enums.enum_item.module_tracktor_beam: * sr.sprite = tracktor_beam; * break; * * case Enums.enum_item.module_power_reactor: * sr.sprite = power; * break; * * default: * sr.sprite = unknown; * break; * }*/ }
public void OnDrop(PointerEventData eventData) { ItemDragHandler d = eventData.pointerDrag.GetComponent <ItemDragHandler>(); InventoryItem inv_item = eventData.pointerDrag.gameObject.GetComponent <InventoryItem>(); EnabledDisabled enable_disable = gameObject.GetComponentInParent <EnabledDisabled>(); ModuleSystemInfo sys_info = inv_item.item.GetComponent <ModuleSystemInfo>(); if (sys_info.allow_multiple_install == false && inventory_box == Enums.emun_inventory.Selected) { if (UnityFunctions.ModuleInstalled(inv_item.item_type)) { return; } } //***************************************************** //Couple of test to make sure we can drop the item here //***************************************************** if (enable_disable != null) { if (enable_disable.Is_Enabled == false) { return; } } if (inv_item != null) { if (inv_item.is_disabled) { d.parentToReturnTo = this.transform; return; } } if (d != null) { if (enforce_max == true) { InventoryItem[] i = GetComponentsInChildren <InventoryItem>(); if (i != null) { if (i.Length + 1 > max_items) { return; } } } if (inventory_box == Enums.emun_inventory.Selected) { MountPoint mp = GetComponentInParent <MountPoint>(); if (mp != null) { if (inv_item.is_command_module) { storage.Equip(inv_item.item); storage.Build_Mount_Point_Drop_Panels(); } else { MountPoint amp = mp.associated_mountpoint.GetComponent <MountPoint>(); sys_info.mount_point = amp.index; storage.Equip(inv_item.item); } } } else { storage.Store_Module(inv_item.item); if (sys_info.is_command_module) { Destroy(eventData.pointerDrag.gameObject); storage.SetScreenNoCommandModule(); } } d.parentToReturnTo = this.transform; } }
public GameObject Create_Module(ModuleSaveModel model) { //GameObject refab = Resources.Load(model.module_name.ToString()) as GameObject; Recipe r = UnityFunctions.GetItemTypeItem(model.item_type); if (r.preFab != null) { GameObject modules = GameObject.Find("Modules"); GameObject stored_modules = GameObject.Find("Stored_Modules"); ShipModule sm = modules.GetComponentInChildren <ShipModule>(); GameObject obj_module = null; if (sm == null) { //Debug.Log("Loading Model"); obj_module = Instantiate(r.preFab, gameObject.transform.position, gameObject.transform.rotation) as GameObject; sm = obj_module.GetComponent <ShipModule>(); if (sm != null) { sm.LoadMountPoints(); } } else { if (model.is_internal_module == false) { MountPoint mp = null; if (model.is_in_storage == false) { mp = sm.mount_points[0]; } else { mp = sm.mount_points[model.mount_point - 1]; } if (mp != null) { obj_module = Instantiate(r.preFab, mp.transform.position, mp.transform.rotation) as GameObject; } } else { obj_module = Instantiate(r.preFab, stored_modules.transform) as GameObject; } } //Need to add the keybindings if (obj_module == null) { return(null); } ModuleSystemInfo mod_sys = obj_module.GetComponent <ModuleSystemInfo>(); ItemResorce ir = obj_module.GetComponent <ItemResorce>(); //mod_sys.key_mappings = model.key_mappings; //mod_sys.id = model.id; mod_sys.current_health = model.health; mod_sys.mount_point = model.mount_point; mod_sys.order_layer = model.order_layer; mod_sys.is_internal_module = model.is_internal_module; mod_sys.active = model.enabled; mod_sys.upgrades.Clear(); //Load upgrades foreach (string s in model.upgrades) { Upgrade_Settings upgrade = Resources.Load(s) as Upgrade_Settings; mod_sys.upgrades.Add(upgrade); } return(obj_module); } else { return(null); } }
private void OnCollisionEnter2D(Collision2D other) { Enums.enum_resorce_type rt = enum_resorce_type.asset; ItemResorce ir = other.gameObject.GetComponent <ItemResorce>(); if (ir != null) { rt = ir.GetResorceType(); } if (rt == enum_resorce_type.material || rt == enum_resorce_type.pickup || rt == enum_resorce_type.blueprint) { //********************************** //We need to see if this is a pickup //********************************** if (ir != null && ir.Item_type == enum_item.pickup) { Recipe item = ir.Spawn_Any_Module_Upgrade_Material(); InventoryManager storage = GetComponentInParent <InventoryManager>(); if (item.resorce_type == enum_resorce_type.material) { UnityFunctions.SendAlert(enum_status.Info, "Collected Item: " + item.item_type.ToString()); storage.Store_Material(item.item_type); Destroy(other.gameObject); } else if (item.resorce_type == enum_resorce_type.module) { //GameObject refab = Resources.Load(item.prefab_path) as GameObject; GameObject refab = item.preFab; if (refab == null) { UnityFunctions.SendAlert(enum_status.Info, "Null object"); } GameObject obj_module = Instantiate(refab, gameObject.transform.position, gameObject.transform.rotation) as GameObject; UnityFunctions.SendAlert(enum_status.Info, "Collected Module: " + obj_module.name.ToString()); ModuleSystemInfo ms = obj_module.GetComponent <ModuleSystemInfo>(); ms.SetStartHealth(); storage.Store_Module(obj_module); Destroy(other.gameObject); } } else { //************************************************ //Else must be a material this goes to the refiner //************************************************ refiner = gameObject.transform.parent.GetComponentInChildren <Refiner>(); if (refiner != null) { //Need to be added to the refiner refiner.AddItemToRefiner(other.gameObject); if (ir.GetNeedsRefining() == true) { UnityFunctions.SendAlert(enum_status.Info, "Refining Material: " + other.gameObject.name.ToString()); } else { UnityFunctions.SendAlert(enum_status.Info, "Collected: " + other.gameObject.name.ToString()); } } } } else { if (module_ir != null && module_ir.Item_type == enum_item.module_shield) { DamageShield(); } else { DamageShip(); } } }