// Use this for initialization
 void Start()
 {
     if (mainGameSystem == null)
     {
         this.mainGameSystem = GameObject.Find("GameController").GetComponent <MainGameSystem>();
     }
 }
Beispiel #2
0
    public override void InitSys()
    {
        base.InitSys();

        Instance = this;
        PECommon.Log("Init MainGameSystem...");
    }
Beispiel #3
0
        protected override EventResult OnStage(EventStage currentStage)
        {
            switch (currentStage)
            {
            case EventStage.START:
                EventState.currentEventText    = "Your landlord enters the shop.";
                EventState.currentEventOptions = EventState.CONTINUE_OPTION;
                mCurrentOptionOutcomes         = new EventStage[] { EventStage.S1 };
                break;

            case EventStage.S1:
                EventState.currentEventText    = "\"Sorry, but I can't let you stay for free again. You have to leave.\"";
                EventState.currentEventOptions = EventState.CONTINUE_OPTION;
                mCurrentOptionOutcomes         = new EventStage[] { EventStage.S2 };
                break;

            case EventStage.S2:
                EventState.currentEventText    = "You don't have enough money to pay the rent this season. The dream is dead.";
                EventState.currentEventOptions = EventState.currentEventOptions = new string[] { "Aww :(" };
                mCurrentOptionOutcomes         = new EventStage[] { EventStage.ACCEPT };
                break;

            case EventStage.ACCEPT:
                MainGameSystem.GameOver();
                return(EventResult.DONE);
            }

            return(EventResult.CONTINUE);
        }
 public void OnLevelWasLoaded()
 {
     if (7 != SceneManager.GetActiveScene().buildIndex)
     {
         return;
     }
     isgamescene = true;
     GS          = GameObject.Find("GAME SYSTEM").GetComponent <MainGameSystem>();
 }
Beispiel #5
0
    // does this really need to be separate from BusinessState? enh whatever

    // This can be used to change stage for the main game loop.
    // Game over, events, and the time-skip will not use this.
    public static void GameLoopGotoNextStage()
    {
        GameStage prevStage = GameData.singleton.currentStage;

        switch (GameData.singleton.currentStage)
        {
        case GameStage.GS_SIMULATION:
            /* End the Quarter */
            MainGameSystem.CurrentQuarterEnding();
            GameData.singleton.currentStage = GameStage.GS_END_OF_QUARTER;
            break;

        case GameStage.GS_END_OF_QUARTER:
            /* Advance to summary screens */
            MainGameSystem.EndCurrentQuarter();
            GameData.singleton.currentStage = GameStage.GS_OVERLAY_POTION_SALES;
            break;

        case GameStage.GS_OVERLAY_POTION_SALES:
            GameData.singleton.currentStage = GameStage.GS_OVERLAY_FINANCIAL_SUMMARY;
            break;

        case GameStage.GS_OVERLAY_FINANCIAL_SUMMARY:
            /* Pay rent when the OK button is clicked */
            MainGameSystem.PayEndOfQuarterExpenses();
            GameData.singleton.currentStage = GameStage.GS_OVERLAY_FEATHER_COLLECTION;
            break;

        case GameStage.GS_OVERLAY_FEATHER_COLLECTION:
            GameData.singleton.currentStage = GameStage.GS_RESOURCE_ALLOCATION;
            break;

        case GameStage.GS_RESOURCE_ALLOCATION:
            GameData.singleton.currentStage = GameStage.GS_PEACOCK;
            break;

        case GameStage.GS_PEACOCK:
            /* Pay peacock-related expenses*/
            MainGameSystem.PayPeacockExpenses();
            /* Start the next quarter */
            MainGameSystem.StartNextQuarter();
            break;

        default:
            // stay in the current stage
            Debug.LogError("GameLoopGotoNextStage was used from an invalid stage!");
            break;
        }
        GameData.SaveGame();
        Debug.Log("Stage change from " + prevStage.ToString() + " to " + GameData.singleton.currentStage.ToString());
    }
Beispiel #6
0
 // Use this for initialization
 void Start()
 {
     if (sys == null)
     {
         sys = GameObject.Find("GameController").GetComponent <MainGameSystem>();
     }
     if (StartAIButton == null)
     {
         StartAIButton = GameObject.Find("StartAIButton").GetComponent <Button>();
     }
     if (StopAIButton)
     {
         StartAIButton = GameObject.Find("StopAIButton").GetComponent <Button>();
     }
     state = AIState.SLEEPING;
 }
    protected override EventResult OnStage(EventStage currentStage)
    {
        switch (currentStage)
        {
        case EventStage.START:
            EventState.currentEventText    = "The family peacock has died! The business can't go on without it.";
            EventState.currentEventOptions = new string[] { "Nooo! :(" };
            mCurrentOptionOutcomes         = new EventStage[] { EventStage.ACCEPT };
            return(EventResult.CONTINUE);

        case EventStage.ACCEPT:
            MainGameSystem.GameOver();
            return(EventResult.DONE);
        }

        return(EventResult.DONE);
    }
    protected override EventResult OnStage(EventStage currentStage)
    {
        switch (currentStage)
        {
        case EventStage.START:
            EventState.currentEventText    = "You worked the potion shop for a long time now. It's time to retire.";
            EventState.currentEventOptions = EventState.CONTINUE_OPTION;
            mCurrentOptionOutcomes         = new EventStage[] { EventStage.ACCEPT };
            return(EventResult.CONTINUE);

        case EventStage.ACCEPT:
            MainGameSystem.GameOver();
            return(EventResult.DONE);
        }

        return(EventResult.DONE);
    }
    // Update is called once per frame
    void Update()
    {
        if (EventState.currentEvent != null)
        {
            return;                                 // no updating while an event is happening
        }
        if (GameData.singleton.currentStage == GameStage.GS_SIMULATION)
        {
            if (GameData.singleton.totalQuarterlyCustomers <= 0) // no more customers to handle
            {
                if (!EventState.hasMoreEventsRightNow && GameData.singleton.quarterTimeElapsed >= QuarterTotalTime)
                {
                    // transition to "end of quarter" stage
                    Debug.Log("All customers served this quarter.");
                    GameStageExtensions.GameLoopGotoNextStage();
                }
            }
            else
            {
                // yeah like it's slightly gross to do this here in this way...
                // running code on state changes really does want an event-driven style thing, I guess
                if (mPaymentTime == 0)
                {
                    mPaymentTime  = QuarterTotalTime / GameData.singleton.totalQuarterlyCustomers;
                    mPaymentTimer = mPaymentTime;
                }

                mPaymentTimer -= Time.deltaTime;
                if (mPaymentTimer <= 0)
                {
                    int product = Random.Range(0, (int)PotionType.PT_MAX);
                    while (GameData.singleton.quarterlyCustomers[product] == 0)
                    {
                        product = (product + 1) % (int)PotionType.PT_MAX;
                    }

                    if (GameData.singleton.potionsOwned[product] > 0)
                    {
                        SellProduct(product);
                    }
                    else
                    {
                        GameData.singleton.unfulfilledDemand[product] += 1;
                        Debug.Log("A customer wanted " + (PotionType)product + " but we were out of stock");

                        // get enough of this, and we queue up an event where a customer asks for this type specifically
                        if (GameData.singleton.unfulfilledDemand[product] > 3 && GameData.singleton.outOfStockEventCooldown <= GameData.singleton.quarter)
                        {
                            EventState.PushEvent(new OutOfStockEvent((PotionType)product), GameData.singleton.quarter);
                            GameData.singleton.outOfStockEventCooldown = GameData.singleton.quarter + 2;
                        }
                    }

                    mPaymentTimer = Random.Range(mPaymentTime * 0.9f, mPaymentTime * 1.1f);
                    GameData.singleton.quarterlyCustomers[product] -= 1;
                    --GameData.singleton.totalQuarterlyCustomers;
                }
            }
        }
        else if (GameData.singleton.currentStage == GameStage.GS_END_OF_QUARTER)
        {
            if (GameData.singleton.money < GameData.singleton.rent && !GameData.singleton.missedRent)
            {
                if (GameData.singleton.lastMissedRentQuarter == -1)
                {
                    EventState.PushEvent(new MissedRentEvents.MissedRentEvent(), GameData.singleton.quarter, 0, GameStage.GS_END_OF_QUARTER); // going to miss rent? add event
                    GameData.singleton.lastMissedRentQuarter = GameData.singleton.quarter;
                }
                else if (GameData.singleton.lastMissedRentQuarter == GameData.singleton.quarter - 1)
                {
                    EventState.PushEvent(new MissedRentEvents.MissedRentAgainEvent(), GameData.singleton.quarter, 0, GameStage.GS_END_OF_QUARTER); // game over
                    GameData.singleton.missedRent = true;
                }
                else
                {
                    Debug.LogError("Missed rent in quarter " + GameData.singleton.lastMissedRentQuarter + " but it's now " + GameData.singleton.quarter + ", and somehow it wasn't cleared?");
                }
            }
            else if (GameData.singleton.lastMissedRentQuarter < GameData.singleton.quarter)
            {
                GameData.singleton.lastMissedRentQuarter = -1;
            }

            if (GameData.singleton.peacockHealth <= 0 && !GameData.singleton.peacockDied)
            {
                EventState.PushEvent(new PeacockSickEvent(), GameData.singleton.quarter, 0, GameStage.GS_END_OF_QUARTER);
                GameData.singleton.peacockDied = true;
            }

            if (GameData.singleton.quarter >= 16 && !GameData.singleton.reachedEndOfLife && !GameData.singleton.missedRent && !GameData.singleton.peacockDied)
            {
                EventState.PushEvent(new EndOfLifeEvent(), GameData.singleton.quarter, 0);
                GameData.singleton.reachedEndOfLife = true;
            }

            if (!EventState.hasMoreEventsRightNow) // ensure we play through all events before advancing to next quarter
            {
                mPaymentTime = 0;

                // Advance to the next quarter and update any other affected state
                // Go tho the end-of-quarter summary state (or game over state)
                if (GameData.singleton.reachedEndOfLife)
                {
                    MainGameSystem.GameOver();
                }
                else
                {
                    // This will advance to the summaries after the end of the quarter
                    GameStageExtensions.GameLoopGotoNextStage();
                }
                Debug.Log("game stage is now " + GameData.singleton.currentStage);
            }
        }
    }
Beispiel #10
0
 // Start is called before the first frame update
 private void Awake()
 {
     system = GameObject.FindGameObjectWithTag("System").GetComponent <MainGameSystem>();
 }