Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        options = new Options();

        ConfirmationScript[] sdsdfd = GameObject.FindObjectsOfType<ConfirmationScript>();

        ticketQueue = new CustomerQueue(11, 38.5f, 6.8f, 0);

        #region Find Objects
        theTileManager = GameObject.Find("TileManagement").GetComponent<TileManager>();

        GameObject custStatus = GameObject.Find("Customer Status");
        movementScript.customerStatus = custStatus;
        GameObject[] tmpArray = GameObject.FindGameObjectsWithTag("Floor Tile");
        steps = GameObject.Find("Steps");
        mouseDrag.staffAttributePanel = GameObject.Find("Staff Attributes");
        #endregion

        Customer.tiles = floorTiles;

        #region Hide Objects on Start
        custStatus.SetActive(false);

        shopController.redCarpet.SetActive(false);
        mouseDrag.staffAttributePanel.SetActive(false);
        #endregion

        #region Add Delegate references
        mouseDrag.getStaffJobById += GetStaffJobById;
        mouseDrag.changeStaffJob += UpdateStaffJob;
        movementScript.addToQueueTickets += AddToQueueTickets;
        movementScript.getQueueTicketsSize += GetTicketQueueSize;
        movementScript.addToQueueFood += AddToQueueFood;
        movementScript.getQueueFoodSize += GetFoodQueueSize;
        #endregion

        #region Facebook stuff
        GameObject pnlNoFriends = GameObject.Find("pnlNoFriends");

        try
        {
            string fbUserID = FBScript.current.id;
            if (fbUserID.Length > 0)
            {
                cmdFriends.SetActive(true);
                facebookProfile = new FacebookFriend();
                facebookProfile.name = FBScript.current.firstname + " " + FBScript.current.surname;
                facebookProfile.id = FBScript.current.id;
                facebookProfile.friends = FBScript.current.friendList;

                if (facebookProfile.friends.Count > 0)
                {
                    pnlNoFriends.SetActive(false);
                }
                else
                {
                    pnlNoFriends.SetActive(true);
                }

                for (int i = 0; i < facebookProfile.friends.Count; i++)
                {
                    GameObject go = (GameObject)Instantiate(friendObject.gameObject, new Vector3(0, 0, 0), Quaternion.identity);
                    go.transform.SetParent(popupController.friendList, false);

                    Text[] textComponents = go.GetComponentsInChildren<Text>();
                    textComponents[0].text = facebookProfile.friends[i].name;

                    Button[] buttonComponents = go.GetComponentsInChildren<Button>();
                    string idToSend = facebookProfile.friends[i].id;
                    string nameToSend = facebookProfile.friends[i].name;
                    buttonComponents[0].onClick.AddListener(() => ViewFriendsCinema(idToSend, nameToSend));
                    buttonComponents[1].onClick.AddListener(() => ViewFriendsCinema(idToSend, nameToSend));

                }
            }
            else
            {
                pnlNoFriends.SetActive(true);
                // if the user has not logged into Facebook, hide the facebook friends button
                cmdFriends.SetActive(false);
            }
        }
        catch (Exception) { }
        #endregion

        // this will change depending on starting upgrade levels and other queues etc

        #region Load / New Game

        if (ButtonScript.friendData != null)
        {
            GameObject.Find("Bottom Panel").SetActive(false);
            GameObject.Find("lblOwnerName").GetComponent<Text>().text = ButtonScript.owner + "'s Cinema";
            ButtonScript.dataCopy = ButtonScript.loadGame;
            ButtonScript.loadGame = ButtonScript.friendData;
            ButtonScript.friendData = null;
        }
        else
        {
            GameObject.Find("FriendPanel").SetActive(false);
        }

        // get Player data. If not null, load game
        if (ButtonScript.loadGame == null)
        {
            financeController.Inititalise(45000, 4);

            carpetColour = GetColourFromID(1);

            customerController.reputation = new Reputation();
            customerController.reputation.Initialise();

            OtherObjectScript.CreateStaffSlot(1, new Vector3(37.8f, 12.3f, 0));

            #region Floor Tiles
            floorTiles = new GameObject[40, 80];

            // initialise the floor tiles
            for (int i = 0; i < tmpArray.Length; i++)
            {
                string name = tmpArray[i].name;

                string[] tmp = name.Split('~');
                int x = int.Parse(tmp[1]);
                int y = int.Parse(tmp[2]);

                tmpArray[i].GetComponent<SpriteRenderer>().color = carpetColour;
                tmpArray[i].GetComponent<SpriteRenderer>().sprite = ColourBackground;
                //tmpArray[i].GetComponent<SpriteRenderer>().sprite = profilePicture;   // for funny times, uncomment this line

                floorTiles[x, y] = tmpArray[i];
            }
            #endregion

            for (int i = 0; i < 1; i++)
            {
                Vector3 pos = floorTiles[i * 11, 0].transform.position;
                ShopController.theScreens.Add(new ScreenObject((i + 1), 0));
                ShopController.theScreens[i].SetPosition((int)pos.x, (int)pos.y);
            }
            ShopController.theScreens[0].Upgrade();
            ShopController.theScreens[0].UpgradeComplete();
            // NYAH

            NextDay(false, false);

            // do staff intro thing here
            popupController.ShowPopup(99, "Welcome!!! This is your cinema!\nLets get started by hiring some staff shall we?");

            foodArea = null;

        }
        else
        {
            statusCode = 0;

            PlayerData data = ButtonScript.loadGame;

            carpetColour = new Color(data.carpetColour[0], data.carpetColour[1], data.carpetColour[2]);

            shopController.LoadDecorations(data.hasRedCarpet, data.posters);

            isMarbleFloor = data.marbleFloor;
            customerController.reputation = data.reputation;
            foodArea = data.foodArea;

            options.Load(data.options);

            int boxLevel = data.boxOfficeLevel;
            OtherObjectScript.CreateStaffSlot(1, new Vector3(37.8f, 12.3f, 0));

            for (int i = 0; i < boxLevel - 1; i++)
            {
                OtherObjectScript.UpgradeBoxOffice();
            }

            #region Floor Tiles
            // initialise the floor tiles
            floorTiles = new GameObject[40, 80];

            for (int i = 0; i < tmpArray.Length; i++)
            {
                string name = tmpArray[i].name;

                string[] tmp = name.Split('~');
                int x = int.Parse(tmp[1]);
                int y = int.Parse(tmp[2]);

                tmpArray[i].GetComponent<SpriteRenderer>().color = carpetColour;
                if (!isMarbleFloor)
                {
                    tmpArray[i].GetComponent<SpriteRenderer>().sprite = ColourBackground;
                }
                else
                {
                    tmpArray[i].GetComponent<SpriteRenderer>().sprite = marbleSquares[UnityEngine.Random.Range(0, 3)];
                }

                floorTiles[x, y] = tmpArray[i];
            }
            #endregion

            ShopController.theScreens = new List<ScreenObject>(data.theScreens);

            SaveableStaff[] s = data.staffMembers;

            for (int i = 0; i < s.Length; i++)
            {
                int id = s[i].index;
                string name = s[i].name;
                Transform transform = staffPrefab;
                int dayHired = s[i].dayHired;
                int tID = s[i].transformID;
                int[] attributes = s[i].attributes;
                float[,] cols = s[i].colourArrays;
                int hair = s[i].hairStyleID;
                int extras = s[i].extrasID;

                GameObject go = GameObject.Find("AppearanceController");
                AppearanceScript aS = go.GetComponent<AppearanceScript>();

                Sprite hairSprite = null;
                Sprite extraSprite = null;

                if (hair != 9)
                {
                    hairSprite = aS.hairStyles[hair];
                }
                if (extras != 5)
                {
                    extraSprite = aS.extraImages[extras];
                }
                Color[] c = new Color[3];

                for (int colID = 0; colID < 3; colID++)
                {
                    c[colID] = new Color(cols[colID, 0], cols[colID, 1], cols[colID, 2]);
                }

                StaffMember newStaff = new StaffMember(id, name, transform, dayHired, tID, hairSprite);
                newStaff.SetColours(c, hair, extras);
                newStaff.SetSprites(hairSprite, extraSprite);
                newStaff.SetAttributes(attributes);

                int x = 35 + (2 * (newStaff.GetIndex() % 6)); ;
                int y = 2 * (newStaff.GetIndex() / 6);

                staffMembers.Add(newStaff);
                CreateStaff(newStaff, x, y);
            }

            filmShowings = new List<FilmShowing>(data.filmShowings);
            currDay = data.currentDay;
            numScreens = ShopController.theScreens.Count;
            financeController.Inititalise(data.totalCoins, data.numPopcorn);
            ShopController.otherObjects = new List<OtherObject>(data.otherObjects);

            NextDay(false, false);
            currDay--; // needed for some reason

            // hopefully un-breaks things
            for (int i = 0; i < ShopController.theScreens.Count; i++)
            {
                Vector3 pos = new Vector3(ShopController.theScreens[i].GetX(), ShopController.theScreens[i].GetY(), 0);
                ShopController.theScreens[i].SetPosition((int)pos.x, (int)(pos.y));
            }

            // sort staff appearance
            GameObject[] staffs = GameObject.FindGameObjectsWithTag("Staff");
            for (int i = 0; i < staffs.Length; i++)
            {
                SpriteRenderer[] srs = staffs[i].GetComponentsInChildren<SpriteRenderer>();
                srs[0].color = staffMembers[i].GetColourByIndex(0);
                srs[1].color = staffMembers[i].GetColourByIndex(2);
                srs[2].color = staffMembers[i].GetColourByIndex(2);
                srs[3].color = staffMembers[i].GetColourByIndex(1);
                srs[4].color = staffMembers[i].GetColourByIndex(1);

                srs[3].sprite = staffMembers[i].GetHairStyle();
                srs[4].sprite = staffMembers[i].GetExtras();
            }

            shopController.ShowPosters(0);
            shopController.ShowPosters(1);

            if (popcornSpent > 0)
            {
                financeController.RemovePopcorn(Controller.popcornSpent);
                financeController.popcornLabel.text = financeController.GetNumPopcorn().ToString();
                Controller.popcornSpent = 0;
                DoAutosave();
            }

            string fbID = FBScript.current.id;

            try
            {
                if (isOwned)
                {
                    Gifting g = new Gifting();
                    List<String> gifts = g.GetGifts(fbID);

                    if (gifts.Count > 0)
                    {

                        List<int> counts = new List<int>();
                        List<string> names = new List<string>();

                        // group together - i.e. Susan McDonaldman: 3
                        for (int i = 0; i < gifts.Count; i++)
                        {

                            bool found = false;

                            for (int checkLoop = 0; checkLoop < names.Count; checkLoop++)
                            {
                                if (names[checkLoop].Equals(gifts[i]))
                                {
                                    found = true;
                                    counts[checkLoop]++;
                                    break;
                                }
                            }

                            if (!found)
                            {
                                names.Add(gifts[i]);
                                counts.Add(1);
                            }
                        }

                        financeController.AddPopcorn(gifts.Count);

                        for (int i = 0; i < names.Count; i++)
                        {
                            // add the element / objects
                            Transform t = Instantiate(giftObject, new Vector2(0, 0), Quaternion.identity) as Transform;
                            // set parent to the element container

                            Transform giftContainer = GameObject.Find("GiftContainer").transform;

                            t.SetParent(giftContainer);
                            // change the values
                            Text[] txts = t.GetComponentsInChildren<Text>();
                            txts[0].text = names[i];
                            txts[1].text = counts[i].ToString();
                        }

                        // show the popup
                        GameObject giftPanel = GameObject.Find("GiftList");
                        giftPanel.GetComponent<Canvas>().enabled = true;

                        DoAutosave();

                    }

                }
            }
            catch (Exception)
            {
                popupController.ShowPopup(0, "Error getting Gifts");
            }
        }

        #endregion

        // create some test screens
        for (int i = 0; i < ShopController.theScreens.Count; i++)
        {
            Vector3 pos = new Vector3(ShopController.theScreens[i].GetX(), ShopController.theScreens[i].GetY() * 0.8f, 0);

            // change pos and element here
            pos.y += 0.8f;

            shopController.AddScreen(ShopController.theScreens[i], pos, height);

            SetTiles(2, (int)(ShopController.theScreens[i].GetX()), (int)(ShopController.theScreens[i].GetY()), 11, 15);
        }

        // do same for other objects
        for (int i = 0; i < ShopController.otherObjects.Count; i++)
        {
            Vector3 pos = new Vector3(ShopController.otherObjects[i].xPos, ShopController.otherObjects[i].yPos * 0.8f, 0);

            DimensionTuple t = shopController.GetBounds(ShopController.otherObjects[i].type);

            shopController.AddObject(pos, i, height, ShopController.otherObjects[i].type, true);

            SetTiles(2, (int)(ShopController.otherObjects[i].xPos), (int)(ShopController.otherObjects[i].yPos), t.width, t.height);
        }

        //createColourPicker();

        if (updateTileState != null)
        {
            updateTileState(33, 0, 14, 16, 1, true);
            updateTileState(33, 16, 14, 4, 2, true);
        }

        GameObject[] pointers = GameObject.FindGameObjectsWithTag("Pointer");

        for (int i = 0; i < pointers.Length; i++)
        {
            pointers[i].GetComponent<Transform>().GetComponent<SpriteRenderer>().enabled = false;
        }

        dayLabel.text = "DAY: " + currDay.ToString();

        // create staff slots for food area if not null
        if (foodArea != null)
        {
            GameObject go = GameObject.FindGameObjectWithTag("Food Area");
            Vector2 pos = go.transform.position;

            for (int i = 0; i < foodArea.tableStatus + 1; i++) {
                OtherObjectScript.CreateStaffSlot(2, pos + new Vector2(3 + (2.5f * i), 7.95f));
            }

            if (foodArea.tableStatus == 1)
            {
                foodQueue.Upgrade();
            }
        }

        NewShowTimes();
    }
    /// <summary>
    /// When the user clicks 'Confirm'
    /// </summary>
    public void Confirmed()
    {
        // get the cost from the parameter list
        int cost = int.Parse(parameters[1]);

        // if the user has enough coins / popcorn to afford the action
        if ((financeController.GetNumCoins() >= cost && parameters[2].Equals("0") && actionCode != 13) || (financeController.GetNumPopcorn() >= cost && parameters[2].Equals("1") && actionCode != 13) || actionCode == 6 || (actionCode == 13 && Controller.numPopcorn > 0))
        {
            // hide the panel
            popupController.confirmationPanel.SetActive(false);

            #region Remove money / Add Money (if selling item)
            // depending on which currency is to be used, remove the necessary amount from the players balance
            if (parameters[2].Equals("0"))
            {
                if (actionCode != 6)
                {
                    financeController.RemoveCoins(cost);
                }
                else
                {
                    financeController.AddCoins(cost);
                }
            }
            else
            {
                financeController.RemovePopcorn(cost);
            }
            #endregion

            #region Carry out actions
            switch (actionCode)
            {
                #region Add a new object
                case 0:
                    mainController.AddNewObject(int.Parse(parameters[3]), int.Parse(parameters[4]));
                    mainController.statusCode = 0;
                    mainController.DoAutosave();
                    break;
                #endregion

                #region Upgrade staff attribute
                case 1:
                    // get the index of the attribute to upgrade
                    int index = int.Parse(parameters[3]);
                    mainController.UpgradeStaffAttribute(index);
                    mainController.statusCode = 7;
                    mainController.DoAutosave();
                    break;
                #endregion

                #region Hire new staff
                case 2:

                    // set the status code
                    mainController.statusCode = 99;

                    // initialise the values for the staff customisation
                    AppearanceScript.Initialise(true, null, 1, mainController.staffMembers[0].GetColourByIndex(0), -1, AppearanceScript.hairStyle, "", AppearanceScript.extraOption);

                    // show the necessary menus / objects
                    mainController.staffModel.SetActive(true);
                    mainController.staffAppearanceMenu.SetActive(true);
                    theShop.gameObject.SetActive(false);
                    popupController.bottomPanel.SetActive(false);
                    popupController.settingsButton.SetActive(false);

                    // move the camera into place
                    Camera.main.transform.position = new Vector3(32.68f, 0, 1);
                    Camera.main.orthographicSize = 14;

                    break;
                #endregion

                #region Upgrade a screen
                case 3:
                    // get the index of the screen to upgrade
                    int screenIndex = int.Parse(parameters[3]);
                    // get the actual screen object
                    ScreenObject theScreen = shopController.screenObjectList[screenIndex].GetComponent<Screen_Script>().theScreen;
                    // upgrade the screen
                    theScreen.Upgrade();
                    // change the image to the contruction image
                    shopController.screenObjectList[screenIndex].GetComponent<SpriteRenderer>().sprite = shopController.screenImages[0];

                    // hide the object info info menu
                    popupController.objectInfo.SetActive(false);
                    popupController.closeInfo.SetActive(false);

                    // generate new show times
                    mainController.NewShowTimes();
                    mainController.statusCode = 0;

                    // create a builder for the screen
                    shopController.CreateBuilder(theScreen.GetX(), theScreen.GetY(), theScreen.GetScreenNumber());

                    mainController.DoAutosave();

                    break;
                #endregion

                #region Red carpet
                case 4:
                    // show the carpet
                    shopController.redCarpet.SetActive(true);
                    shopController.hasUnlockedRedCarpet = true;
                    mainController.statusCode = 5;
                    popupController.HideObjectInfo();
                    mainController.DoAutosave();
                    break;
                #endregion

                #region Upgrade Box Office
                case 5:
                    OtherObjectScript.UpgradeBoxOffice();
                    mainController.statusCode = 0;
                    mainController.DoAutosave();
                    break;
                #endregion

                #region Remove an object
                case 6:

                    // get the height, width, xPos and yPos
                    int xPos = int.Parse(parameters[3]);
                    int yPos = int.Parse(parameters[4]);
                    int width = int.Parse(parameters[5]);
                    int height = int.Parse(parameters[6]);

                    // remove the object
                    mainController.RemoveObject(xPos, yPos, width, height);
                    mainController.statusCode = 0;
                    mainController.DoAutosave();
                    break;
                #endregion

                #region Clear all projectors
                case 7:
                    projectorController.ClearAllProjectors();
                    mainController.statusCode = 0;
                    break;
                #endregion

                #region Purchase Food Area Component
                case 8:
                    // get which component is to be purchased
                    int theIndex = int.Parse(parameters[3]);
                    // unlock the component
                    FoodAreaScript.ComponentUnlocked(theIndex);
                    mainController.statusCode = 10;
                    mainController.DoAutosave();
                    break;
                #endregion

                #region Purchase Poster pack 1
                case 9:
                    shopController.UnlockPosterPack(0);
                    mainController.DoAutosave();
                    break;
                #endregion

                #region Purchase Poster pack 2
                case 10:
                    shopController.UnlockPosterPack(1);
                    mainController.DoAutosave();
                    break;
                #endregion

                #region Coin Bundle (8000)
                case 11:
                    financeController.AddCoins(8000);
                    mainController.DoAutosave();
                    break;
                #endregion

                #region Finish Construction
                case 12:
                    mainController.CompleteConstructionNow();
                    mainController.DoAutosave();
                    break;
                #endregion

                #region Send Gift
                case 13:
                    Gifting g = new Gifting();
                    bool success = g.SendGift(parameters[3], parameters[4]);       // TODO: Actual values
                    Controller.popcornSpent++;
                    mainController.statusCode = 0;

                    if (success)
                    {
                        popupController.ShowPopup(0, "Gift successfully sent!");
                    }
                    else
                    {
                        popupController.ShowPopup(0, "Uh-Oh! Something went wrong");
                    }

                    break;
                    #endregion
            }
            #endregion
        }
        else
        {
            popupController.ShowPopup(5, "You do not have enough money for this purchase. You can buy more in the shop");
        }
    }