Example #1
0
    //---------------------------------------------------------------
    public void WaveChangeHandling()
    {
        if (currentWaveChild)
        {
            if (currentWaveChild.childCount <= 0)
            {
                isWaveCleared = true;
                currentWaveChild.gameObject.SetActive(false);
                //clear the enemy paddle if all the enemy objects are removed

                /*if(enemyPaddleSpawner && enemyPaddleSpawner.transform.childCount>0){
                 *      Destroy(enemyPaddleSpawner.transform.GetChild(0).gameObject);
                 * }*/

                if (currentWaveIndex + 1 < waveLength)
                {
                    currentWaveIndex++;
                    PlayerPrefManager.SetUITextStatus(PlayerPrefManager.GUITEXT_STATUS_CHANGING);
                    UITextController.SetUITextStatusType(UITextController.DISPLAY_TEXT.WAVE, "");
                    currentWaveChild = enemyWaveSpawner.transform.GetChild(currentWaveIndex);
                }
                else if (currentWaveIndex + 1 >= waveLength && !saved)
                {
                    waveHasStarted = false;
                    WinLoseCondition wlCondition = GameObject.FindGameObjectWithTag("Win Lose Condition").GetComponent <WinLoseCondition>();
                    wlCondition.Win();

                    //Saving data when the stage was cleared
                    //store collected gold to player data
                    Inventory inventory = GameObject.FindGameObjectWithTag("Inventory").GetComponent <Inventory>();
                    PlayerProgress.playerData.gold += inventory.GetCollectedCoin();
                    //if the first time completing map
                    if (!PlayerProgress.playerData.completedMaps.Contains(mapName))
                    {
                        //store in to completed map list
                        PlayerProgress.playerData.completedMaps.Add(mapName);
                        if (!MapDictionary.CheckIsSecretMap(mapName))
                        {
                            CheckForTheNextMap();
                        }
                    }
                    else                       // this map had been cleared before
                    {
                        RewardLoot.GetComponent <Reward>().SetHadLooted();
                    }

                    SaveLoadSystem.SaveGame(PlayerProgress.playerData);
                    saved = true;
                }
            }
        }
    }
Example #2
0
    public void OnDestroy()
    {
        if (UnitManager.Instance != null && this.gameObject != null)
        {
            Debug.Log("Removing traces of this game object from unit manager. Object: " + this.gameObject.name);
            UnitManager.Instance.PlayerUnits.Remove(this.gameObject);
            UnitManager.Instance.AllUnits.Remove(this.gameObject);
            Debug.Log("Current unit count: " + UnitManager.Instance.PlayerUnits.Count.ToString());

            if (UnitManager.Instance.PlayerUnits.Count <= 0)
            {
                WinLoseCondition condition = UnitManager.Instance.gameObject.GetComponent <WinLoseCondition>();
                if (condition != null)
                {
                    Debug.Log("WinLoseCondition found! Calling on event and delegate triggers.");
                    condition.PlayerHasLost();
                }
            }
        }
    }
Example #3
0
    void CheckLife()
    {
        if (lostHeathToChangeSprite != 0)
        {
            ChangeSpriteFollowHealth();
        }
        //Handle when health is <= 0
        if (health <= 0)
        {
            //if this health is of base
            if (GetComponent <Vehicle> ())
            {
                WinLoseCondition wlCondition = GameObject.FindGameObjectWithTag("Win Lose Condition").GetComponent <WinLoseCondition> ();
                wlCondition.Lose();
            }
            //if this health is of block
            if (GetComponent <BlockOfStage> ())
            {
                Instantiate(DieEffectPrefab, transform.position, Quaternion.identity);
                GetComponent <BlockOfStage> ().BlockDestroy();

                return;
            }
            //if this health is of enemy
            if (GetComponent <Enemy> ())
            {
                Instantiate(DieEffectPrefab, transform.position, Quaternion.identity);
                GetComponent <Enemy> ().EnemyDestroy();
                return;
            }
        }
        //if this health is of prisoner
        if (GetComponent <Prisoner> () && !isDead)
        {
            SetHealthBar();
            StartCoroutine("PlayHitSpriteAndHitSound");
        }
    }
Example #4
0
    //---------------------------------------------------------------
    public void CheckAlivePrisonerLeft()
    {
        int alivePrisonerNum = prisonerArray.Length;

        foreach (Prisoner thisPrisoner in prisonerArray)
        {
            Health thisPrisonerHealth = thisPrisoner.GetComponent <Health>();
            bool   isDead             = (thisPrisonerHealth.GetHealth() <= 0);
            if (isDead)
            {
                alivePrisonerNum--;
                print("alivePrisonerNum " + alivePrisonerNum);
            }
        }

        if ((alivePrisonerNum <= 0))
        {
            allPrisonerDead = true;
            //as all the prisoners are down, set the game is lost
            WinLoseCondition wlCondition = GameObject.FindGameObjectWithTag("Win Lose Condition").GetComponent <WinLoseCondition>();
            wlCondition.Lose();
        }
    }
Example #5
0
    // Use this for initialization
    void Start()
    {
        items             = new List <Item>();
        newItems          = new List <Item>();
        alreadyExistItems = new List <Item>();

        WinLoseCondition.SetIsWinner(isWinnerForTest);
        //Check whether the reward loot exists or not
        reward = FindObjectOfType <Reward>();
        if (!reward)
        {
            Debug.LogError("Cannot find reward Object to loot");
            return;
        }
        //If there is , then check if game won or lost
        if (!WinLoseCondition.GetIsWinner())
        {
            Debug.Log("Well. Look like you lost. you cannot loot the reward");
            return;
        }
        //if you won, then check whether it has been looted or not

        /*if(reward.GetHadLooted()){
         *      Debug.LogError("You completed this map before. Only gold could be collected");
         *      acquiredGold = reward.GetRewardGold();
         *      PlayerProgress.playerData.gold += acquiredGold;
         *      return;
         * }*/

        //If has ever not been looted
        acquiredGold = reward.GetRewardGold();
        PlayerProgress.playerData.gold += reward.GetRewardGold();

        List <Item> itemsInRewardLoot = reward.GetItemsInReward();

        if (itemsInRewardLoot != null)
        {
            for (int i = 0; i < itemsInRewardLoot.Count; i++)
            {
                if (reward.GetHadLooted() && itemsInRewardLoot[i].isStageItem)
                {
                    Debug.LogError("this item is stage item. As you completed this map before, Only gold could be collected");
                    acquiredGold = reward.GetRewardGold();
                    PlayerProgress.playerData.gold += acquiredGold;
                    continue;
                }

                switch (itemsInRewardLoot[i].itemType)
                {
                case Item.TYPE.CHARACTER:
                    if (PlayerProgress.playerData.availableCharacters.Contains(itemsInRewardLoot[i].itemName))
                    {
                        Debug.Log("This character is already in your group. You will receive gold instead.");
                        itemsInRewardLoot[i].isAlreadyInStock = true;
                        PlayerProgress.playerData.gold       += itemsInRewardLoot[i].itemValue;
                        alreadyExistItems.Add(itemsInRewardLoot[i]);
                        items.Add(itemsInRewardLoot[i]);
                    }
                    else if (CommonData.charNameList.Contains(itemsInRewardLoot[i].itemName))
                    {
                        Debug.Log(itemsInRewardLoot[i].itemName + " is found in datatabase");
                        newItems.Add(itemsInRewardLoot[i]);
                        items.Add(itemsInRewardLoot[i]);
                        PlayerProgress.playerData.availableCharacters.Add(itemsInRewardLoot[i].itemName);
                        //Do stuff here
                    }
                    else
                    {
                        Debug.Log("this prisoner name :" + itemsInRewardLoot[i].itemName + " is not existing in the database");
                    }
                    break;

                case Item.TYPE.VEHICLE:
                    if (PlayerProgress.playerData.availableVehicles.Contains(itemsInRewardLoot[i].itemName))
                    {
                        Debug.Log("This vehicle is already in your group. You will receive gold instead.");
                        itemsInRewardLoot[i].isAlreadyInStock = true;
                        PlayerProgress.playerData.gold       += itemsInRewardLoot[i].itemValue;
                        alreadyExistItems.Add(itemsInRewardLoot[i]);
                        items.Add(itemsInRewardLoot[i]);
                    }
                    else if (CommonData.vehicleList.Contains(itemsInRewardLoot[i].itemName))
                    {
                        Debug.Log(itemsInRewardLoot[i].itemName + " is found in datatabase");
                        PlayerProgress.playerData.availableVehicles.Add(itemsInRewardLoot[i].itemName);
                        newItems.Add(itemsInRewardLoot[i]);
                        items.Add(itemsInRewardLoot[i]);
                        //Do stuff here
                    }
                    else
                    {
                        Debug.Log("this vehicle name :" + itemsInRewardLoot[i].itemName + " is not existing in the database");
                    }
                    break;

                case Item.TYPE.SHOT:

                    break;

                case Item.TYPE.MAP:
                    break;

                case Item.TYPE.GOLD:
                    Debug.Log("this item is gold.");
                    PlayerProgress.playerData.gold += itemsInRewardLoot[i].itemValue;
                    items.Add(itemsInRewardLoot[i]);
                    Debug.Log("there are" + items.Count + "items in total");
                    break;

                default: break;
                }
            }
        }
        SaveLoadSystem.SaveGame(PlayerProgress.playerData);
    }
Example #6
0
    //---------------------------------------------------------------
    void Update()
    {
        if (WinLoseCondition.GetIsGameOver() == true)
        {
            return;
        }

        if (EnemyWaveController.GetWaveHasStarted())
        {
            if (bBeingSilenced)
            {
                silencedTime -= Time.deltaTime;
                if (silencedTime <= 0)
                {
                    SpriteRenderer renderer = transform.GetChild(0).GetComponent <SpriteRenderer>();
                    renderer.color = Color.white;
                    bBeingSilenced = false;
                }
                return;
            }

            //cooldown skill over time
            skillCoolDownTime = skillCoolDownTime - Time.deltaTime;

            //visualize cooldown status
            SetSkillBar();

            if (skillCoolDownTime <= 0)
            {
                if (bIsAutoSkill)
                {
                    CastAutoPlaySkill();
                }
                else
                {
                    //Display shootable notification
                    ToggleShootableNotif(true);
                }
            }
        }

        if (bIsSkillCastEffectShowing)
        {
            //if Wave UI Text is displayed while gauge is displayed
            if (UITextController.GetUITextStatusType() == UITextController.DISPLAY_TEXT.WAVE)
            {
                if (bIsShootingSkill)
                {
                    Destroy(GameObject.FindObjectOfType <GaugeMeter>().gameObject); //hide the gauge (destroying it)
                }

                tapTimes = 0;                      //reset the tap times
                bIsSkillCastEffectShowing = false; //the flag telling the gauge is NOT displayed to shot skill
                Prisoner.UnSetPrisonIsCasting();   //the flag telling prisoner is NOT about to shot skill
                return;
            }

            //Only support skills can be activated right on the adjusting time
            CastSupportSkillWhenAdjTimeIs(true);

            needleAdjustTime = needleAdjustTime - Time.unscaledDeltaTime;

            Prisoner.SetPrisonIsCasting();
            if (needleAdjustTime <= 0)
            {
                //TODO refactor this
                //Unpause to shoot
                Time.timeScale = 1;
                skillCastingEffect.EndEffect();
                ExitStandOut();

                if (!bIsSkillUsedThisCharge)
                {
                    //if the skill is the shooting skill
                    if (bIsShootingSkill)
                    {
                        SkillShootingFromNeedle();
                        // else if the skill is the supporting skill
                    }
                    else
                    {
                        CastSupportSkillWhenAdjTimeIs(false);
                    }
                }

                bIsSkillCastEffectShowing = false;
                needleAdjustTime          = maxAdjustTime;
                Prisoner.UnSetPrisonIsCasting();
                prisonerJustUsedSkill = this.gameObject;
                FindNotYetSkillUsersToDelaySkill();
                pausingForSkill = false;
                PlayerPrefManager.SetUITextStatus(PlayerPrefManager.GUITEXT_STATUS_CHANGING);
                UITextController.SetUITextStatusType(UITextController.DISPLAY_TEXT.SKILL_NAME, playingSkillName);
            }
        }
    }