Ejemplo n.º 1
0
    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));
        }
    }
Ejemplo n.º 2
0
    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();
            }
        }
    }