Exemplo n.º 1
0
    /// <summary>
    /// Result 0 = Items repossessed, Result 1 = Lifelines used, all items gone
    /// </summary>
    /// <param name="debtValue"></param>
    /// <param name="result"></param>
    /// <returns></returns>
    public bool RepossessItems(float debtValue, out int result)
    {
        bool sufficientValue = true;

        float officeValue      = GetTotalValue();
        float accumulatedValue = 0f;
        float remainingValue   = 0f;

        result = -1;

        if (officeValue >= debtValue)
        {
            result = 0;

            while (accumulatedValue < debtValue)
            {
                float lowestValue     = Mathf.Infinity;
                int   iObjectToRemove = -1;

                for (int iObject = 0; iObject < CurrentObjects.Count; iObject++)
                {
                    OfficeObjectScript obj = CurrentObjects[iObject].GetComponent <OfficeObjectScript>();

                    if (!obj.Essential)
                    {
                        if (obj.SO.Price < lowestValue)
                        {
                            lowestValue     = obj.SO.Price;
                            iObjectToRemove = iObject;
                        }
                    }
                }

                Debug.Log("*REMOVE: " + CurrentObjects[iObjectToRemove].name);
                RemoveOfficeObject(iObjectToRemove);
                accumulatedValue += lowestValue;
            }

            remainingValue = accumulatedValue - debtValue;

            Debug.Log("*REQUIRED VALUE: " + debtValue.ToString());
            Debug.Log("*ACCUMULATED VALUE: " + accumulatedValue.ToString());
        }
        else if (GameMaster.Instance.Player.HasLifeLine)
        {
            result = 1;

            GameMaster.Instance.Player.HasLifeLine = false;

            Debug.Log("*LIFELINE USED");

            RemoveAllOfficeObjects();
        }
        else
        {
            sufficientValue = false;
        }

        return(sufficientValue);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Returns save data for current office state.
    /// </summary>
    /// <returns></returns>
    public OfficeCustomizationData GetCustomizationData()
    {
        OfficeCustomizationData data = new OfficeCustomizationData(MaterialWallsCurrent.color, MaterialWallsShopCurrent.color, MaterialFloorCurrent.color, MaterialCeilingCurrent.color);

        UnsetAllObjectParents();

        if (CurrentObjects.Count > 0)
        {
            OfficeItem officeItem;

            for (int i = 0; i < CurrentObjects.Count; i++)
            {
                GameObject         obj       = CurrentObjects[i];
                OfficeObjectScript objScript = obj.GetComponent <OfficeObjectScript>();

                if (objScript.OfficeItemID > -1)
                {
                    officeItem = new OfficeItem(objScript.OfficeItemID, obj.transform.position, obj.transform.rotation);
                }
                else
                {
                    officeItem = new OfficeItem(obj.name, obj.transform.position, obj.transform.rotation);
                }

                data.OfficeItems.Add(officeItem);

                if (objScript.ParentIndex != -1)
                {
                    data.Dependencies.Add(new OfficeObjectDependency(objScript.ObjectIndex, objScript.ParentIndex));
                }
            }

            //foreach (GameObject obj in CurrentObjects)
            //{
            //    OfficeObjectScript objScript = obj.GetComponent<OfficeObjectScript>();

            //    if (objScript.OfficeItemID > -1)
            //    {
            //        officeItem = new OfficeItem(objScript.OfficeItemID, obj.transform.position, obj.transform.rotation);
            //    }
            //    else
            //    {
            //        officeItem = new OfficeItem(obj.name, obj.transform.position, obj.transform.rotation);
            //    }

            //    data.OfficeItems.Add(officeItem);

            //    if (objScript.ParentIndex != -1)
            //    {
            //        data.Dependencies.Add(new OfficeObjectDependency(objScript.ObjectIndex, objScript.ParentIndex));
            //    }
            //}
        }

        ResetAllObjectParents();

        return(data);
    }
Exemplo n.º 3
0
    /// <summary>
    /// (Call after user selects to remove an object from their office?)
    /// </summary>
    /// <param name="objectIndex"></param>
    public void RemoveOfficeObject(int objectIndex)
    {
        GameObject obj = CurrentObjects[objectIndex];

        if (!obj.GetComponent <OfficeObjectScript>().Essential)
        {
            RaycastHit hit;

            List <Transform> children = new List <Transform>();

            for (int i = 0; i < obj.transform.childCount; i++)
            {
                GameObject child = obj.transform.GetChild(i).gameObject;

                if (child.GetComponent <OfficeObjectScript>() != null)
                {
                    children.Add(child.transform);

                    child.GetComponent <OfficeObjectScript>().ParentIndex = -1;
                    child.GetComponent <OfficeObjectScript>().Deselect();
                    child.transform.parent = officeObjectTransform;

                    i--;
                }
            }

            obj.layer = 2;
            Destroy(obj);
            CurrentObjects.RemoveAt(objectIndex);

            SelectedObjectIndex = -1;

            foreach (Transform child in children)
            {
                if (Physics.Raycast(child.position, Vector3.down, out hit))
                {
                    child.position = hit.point;

                    OfficeObjectScript objScript = hit.collider.gameObject.GetComponent <OfficeObjectScript>();

                    if (objScript != null)
                    {
                        child.gameObject.GetComponent <OfficeObjectScript>().SetParent(objScript.ObjectIndex);

                        //Debug.Log("New parent: " + objScript.gameObject.name);
                    }
                    //else
                    //    Debug.Log("New parent: " + child.parent.name);
                }
            }

            UpdateObjectIndexes();
        }
        else
        {
            Debug.Log("Cannot remove essential office items!");
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// Sets up the office by using the specified customization data.
    /// </summary>
    /// <param name="customizationData"></param>
    public void SetUpOffice(OfficeCustomizationData data)
    {
        RemoveAllOfficeObjects();

        MaterialWallsCurrent.color   = data.GetWallsColor();
        MaterialFloorCurrent.color   = data.GetFloorColor();
        MaterialCeilingCurrent.color = data.GetCeilingColor();

        if (data.OfficeItems.Count > 0)
        {
            for (int i = 0; i < data.OfficeItems.Count; i++)
            {
                OfficeItem officeItem      = data.OfficeItems[i];
                GameObject newOfficeObject = null;

                if (officeItem.ItemID > -1)
                {
                    int iObject;

                    InitializeOfficeObject(officeItem.ItemID, out iObject);

                    newOfficeObject = CurrentObjects[iObject];
                }
                else
                {
                    foreach (GameObject obj in CurrentObjects)
                    {
                        if (obj.name == officeItem.ObjectName)
                        {
                            newOfficeObject = obj;
                            break;
                        }
                    }
                }

                newOfficeObject.transform.position = officeItem.GetPosition();
                newOfficeObject.transform.rotation = officeItem.GetRotation();
            }

            int iCurrentObjectsStart = 0;

            foreach (OfficeObjectDependency dependency in data.Dependencies)
            {
                for (int iCurrentObjects = iCurrentObjectsStart; iCurrentObjects < CurrentObjects.Count; iCurrentObjects++)
                {
                    OfficeObjectScript objScript = CurrentObjects[iCurrentObjects].GetComponent <OfficeObjectScript>();

                    if (objScript.ObjectIndex == dependency.ObjectIndexChild)
                    {
                        objScript.SetParent(dependency.ObjectIndexParent);

                        iCurrentObjectsStart++;
                        iCurrentObjects = CurrentObjects.Count; //break;
                    }
                }
            }
        }
    }
Exemplo n.º 5
0
    public void ResetAllObjectParents()
    {
        foreach (GameObject obj in CurrentObjects)
        {
            OfficeObjectScript objScript = obj.GetComponent <OfficeObjectScript>();

            if (objScript.ParentIndex != -1)
            {
                objScript.SetParent(objScript.ParentIndex);
            }
            else
            {
                obj.transform.parent = officeObjectTransform;
            }
        }
    }
Exemplo n.º 6
0
    public float GetTotalValue()
    {
        float value = 0;

        foreach (GameObject obj in CurrentObjects)
        {
            OfficeObjectScript objScript = obj.GetComponent <OfficeObjectScript>();

            if (objScript != null)
            {
                if (!objScript.Essential)
                {
                    value += Items[objScript.OfficeItemID].Price;
                }
            }
            else
            {
                Debug.Log("*INVALID ITEM IN OFFICE ITEMS*");
            }
        }

        return(value);
    }