protected override void OnMouseDown()
 {
     if (Time.timeScale == 0)
     {
         return;
     }
     if (!TrainingHandler.IsTrainingFinished())
     {
         if (!MonobehaviorHandler.GetMonobeharior().GetObject <TrainingHandler>("TrainingHandler").IsPassengerClickAllowed())
         {
             return;
         }
     }
     if (
         MonobehaviorHandler.GetMonobeharior()
         .GetObject <BonusTimer>("bonusTimer")
         .IsAnyBonusActive())
     {
         bool    isDoubleClick = Character.TimeSincePreviousClickMade < MovableCharacterSM.MaxClickDuration;
         Vector2 targetPos     = MonobehaviorHandler.GetMonobeharior()
                                 .GetObject <Floor>("Floor").GetCurrentMousePosition();
         List <MovableCharacterSM> affectedCharacters = MonobehaviorHandler.GetMonobeharior()
                                                        .GetObject <BonusTimer>("bonusTimer").HandleClick(targetPos, isDoubleClick);
         if (!affectedCharacters.Contains(Character))
         {
             base.OnMouseDown();
         }
     }
     else
     {
         base.OnMouseDown();
     }
 }
Exemple #2
0
 public void KillStickPassenger()
 {
     foreach (var passengerSm in _passengers)
     {
         if (passengerSm.IsStick())
         {
             if (!TrainingHandler.IsTrainingFinished())
             {
                 if (passengerSm.IsStickModifiedForTraining())
                 {
                     TrainingHandler handler =
                         MonobehaviorHandler.GetMonobeharior().GetObject <TrainingHandler>("TrainingHandler");
                     handler.SetIsGnomeSurvived(false);
                     handler.ShowNext();
                 }
             }
             else
             {
                 RegisterDeath(passengerSm);
             }
             if (passengerSm != null)
             {
                 MonoBehaviour.Destroy(passengerSm.gameObject);
             }
             return;
         }
     }
 }
Exemple #3
0
 void FixedUpdate()
 {
     _currentPeriod += Time.fixedDeltaTime;
     if (_currentPeriod > _destroyPeriod && TrainingHandler.IsTrainingFinished())
     {
         Destroy(gameObject);
     }
 }
Exemple #4
0
 void Start()
 {
     _currentMoveDuration = 0;
     _currentStopDuration = 0;
     _isDoorsOpen         = true;
     if (TrainingHandler.IsTrainingFinished())
     {
         UpdateDoors();
     }
 }
Exemple #5
0
 void OnMouseDown()
 {
     if (Time.timeScale == 0)
     {
         return;
     }
     if (!TrainingHandler.IsTrainingFinished())
     {
         if (_currentPeriod < WaitTimeForTraining)
         {
             return;
         }
     }
     MonobehaviorHandler.GetMonobeharior()
     .GetObject <BonusTimer>("bonusTimer").ActivateDrop(this);
 }
    public virtual void AddDamageValue(float damage)
    {
        Hp -= damage;
        if (Hp > InitialLifes)
        {
            Hp = InitialLifes;
        }
        float lifesPercent  = Hp / InitialLifes;
        float originalValue = _lifebar.bounds.min.x;

        _lifebar.transform.localScale = new Vector3(lifesPercent, 1, 1);
        float newValue   = _lifebar.bounds.min.x;
        float difference = newValue - originalValue;

        _lifebar.transform.Translate(new Vector3(-difference, 0, 0));
        if (lifesPercent > 0.5f)
        {
            _lifebar.color = Color.green;
        }
        if (lifesPercent < 0.5f && lifesPercent > 0.1f)
        {
            _lifebar.color = Color.yellow;
        }
        if (lifesPercent < 0.1f)
        {
            _lifebar.color = Color.red;
        }
        if (Hp <= 0)
        {
            Hp     = 0;
            IsDead = true;
            GameController.GetInstance().RegisterDeath(this);
            if (!TrainingHandler.IsTrainingFinished())
            {
                if (this is ConductorSM)
                {
                    return;
                }
            }
            Destroy(this.gameObject);
        }
    }
Exemple #7
0
    public void DropBonus()
    {
        if (!TrainingHandler.IsTrainingFinished())
        {
            if (
                !MonobehaviorHandler.GetMonobeharior()
                .GetObject <TrainingHandler>("TrainingHandler")
                .IsBonusDropEnabled())
            {
                return;
            }
        }
        if (MonobehaviorHandler.GetMonobeharior()
            .GetObject <BonusTimer>("bonusTimer")
            .IsAnyBonusActive())
        {
            return;
        }
        if (!Randomizer.GetPercentageBasedBoolean((int)_passenger.BonusProbability))
        {
            return;
        }
        GameController.BonusTypes bonusType = Randomizer.CalculateValue <GameController.BonusTypes>(_passenger.BonusProbabilities);
        IBonus drop = null;

        switch (bonusType)
        {
        case GameController.BonusTypes.Wheel:
            drop = new WheelBonus();
            break;

        case GameController.BonusTypes.Ticket:
            drop = new TicketBonus();
            break;

        case GameController.BonusTypes.Boot:
            drop = new BootBonus();
            break;

        case GameController.BonusTypes.Magnet:
            drop = new MagnetBonus();
            break;

        case GameController.BonusTypes.Smile:
            drop = new SmileBonus();
            break;

        case GameController.BonusTypes.AntiHare:
            drop = new AntiHareBonus();
            break;

        case GameController.BonusTypes.SandGlass:
            drop = new SandGlassBonus();
            break;

        case GameController.BonusTypes.Vortex:
            drop = new VortexBonus();
            break;

        case GameController.BonusTypes.Snow:
            drop = new SnowBonus();
            break;

        case GameController.BonusTypes.Wrench:
            drop = new WrenchBonus();
            break;

        case GameController.BonusTypes.Cogwheel:
            break;

        case GameController.BonusTypes.Heal:
            drop = new HealBonus();
            break;

        default:
            return;
        }
        if (!TrainingHandler.IsTrainingFinished())
        {
            TrainingHandler handler = MonobehaviorHandler.GetMonobeharior()
                                      .GetObject <TrainingHandler>("TrainingHandler");
            if (handler.IsDropTypeLocked())
            {
                drop = new AntiHareBonus();
            }
        }
        if (drop != null)
        {
            MonobehaviorHandler.GetMonobeharior()
            .GetObject <BonusTimer>("bonusTimer").DropBonus(drop, _passenger.transform.position);
        }
    }
Exemple #8
0
    public void GameOver()
    {
        Time.timeScale = 0;
        if (_stateInfo.IsLevelFinished)
        {
            _reasonText.text  = StringResources.GetLocalizedString("GameOverVictory");
            _captionText.text = StringResources.GetLocalizedString("GameOverVictoryCaption");
            _restartButton.onClick.RemoveAllListeners();
            _exitButton.onClick.RemoveAllListeners();
            _restartButton.onClick.AddListener(() =>
            {
                Time.timeScale       = 1;
                string nextStationId = MapManager.GetInstance().GetLastOpenedStationId();
                if (!MapManager.GetInstance().IsNewWorldAnimationNeedToBePlayed())
                {
                    MapManager.GetInstance().SetCurrentStation(nextStationId);
                    SceneManager.LoadScene("main");
                }
                else
                {
                    SceneManager.LoadScene("Map");
                }
            });
            _exitButton.onClick.AddListener(() =>
            {
                Time.timeScale = 1;
                SceneManager.LoadScene("Map");
            });
        }
        else
        {
            if (_stateInfo.Hares > GameController.GetInstance().MaxHaresPercent)
            {
                if (TrainingHandler.IsTrainingFinished())
                {
                    _reasonText.text = StringResources.GetLocalizedString("GameOverHare");
                }
                else
                {
                    GameController.GetInstance().ResetHarePercent();
                    _trainingHandler.TrainingFailHare();
                    gameOverMenu.gameObject.SetActive(false);
                    return;
                }
            }
            if (_stateInfo.RemainKilled < 0)
            {
                if (TrainingHandler.IsTrainingFinished())
                {
                    _reasonText.text = StringResources.GetLocalizedString("GameOverKilledPassengers");
                }
                else
                {
                    GameController.GetInstance().ResetDiedPassengersPercent();
                    _trainingHandler.TrainingFailPassengers();
                    gameOverMenu.gameObject.SetActive(false);
                    return;
                }
            }
            if (_stateInfo.IsConductorDied)
            {
                if (TrainingHandler.IsTrainingFinished())
                {
                    _reasonText.text = StringResources.GetLocalizedString("GameOverDeath");
                }
                else
                {
                    _hero.Resurrect();
                    _trainingHandler.TrainingFailDeath();
                    gameOverMenu.gameObject.SetActive(false);
                    return;
                }
            }
        }

        int    leadingZeroCount = ZeroCount - _stateInfo.TicketCount.ToString().Length;
        string countText        = string.Empty;

        for (int i = 0; i < leadingZeroCount; i++)
        {
            countText += "0";
        }
        countText      += _stateInfo.TicketCount;
        countText       = countText.Insert(3, " ");
        _countText.text = countText;
        gameOverMenu.SetActive(true);
        _client.DecreaseTramLives((response) => {
            if (!response.HasField("error"))
            {
                if (response.HasField("tramLivesCount"))
                {
                    float count    = response.GetField("tramLivesCount").n;
                    string message = String.Format(StringResources.GetLocalizedString("remainLivesCount"), count);
                    _messages.AddMessage(message);
                }
            }
        });
        if (_stateInfo.TicketCount > 0)
        {
            RecordsManager.GetInstance().AddRecord(_stateInfo.TicketCount);
            _client.SendRecord(_stateInfo.TicketCount, false, (result) => {
                if (!result.HasField("error"))
                {
                    string message = string.Format(StringResources.GetLocalizedString("newTicketsRecord"),
                                                   _stateInfo.TicketCount) + Environment.NewLine + StringResources.GetLocalizedString("reward");
                    MessageSender.SendRewardMessage(result, _messages, message);
                }
            });
        }
        int flyingAwayCount = 0;

        foreach (KeyValuePair <string, int> pair in GameController.GetInstance().GetFlyingAwayDuringGame())
        {
            flyingAwayCount += pair.Value;
            var pair1 = pair;
            _client.SendDangerRecord(pair.Value, pair.Key, false, (result) => {
                string message = string.Format(StringResources.GetLocalizedString("newDangerRecord"),
                                               StringResources.GetLocalizedString(pair1.Key + "Name"), pair1.Value) + Environment.NewLine + StringResources.GetLocalizedString("reward");
                MessageSender.SendRewardMessage(result, _messages, message);
            });
        }
        int stationNumber = GameController.GetInstance().GetCurrentStationNumber();

        if (stationNumber > 0 && flyingAwayCount == 0)
        {
            _client.SendPacifistRecord(stationNumber, (result) => {
                if (!result.HasField("error"))
                {
                    string message = string.Format(StringResources.GetLocalizedString("newPacifistRecord"),
                                                   stationNumber);
                    MessageSender.SendRewardMessage(result, _messages, message);
                }
            });
        }
        int antistick = GameController.GetInstance().GetAntiStick();

        if (antistick > 0)
        {
            _client.SendAntiStickRecord(antistick, (result) =>
            {
                if (!result.HasField("error"))
                {
                    string message = string.Format(StringResources.GetLocalizedString("newAntistickRecord"),
                                                   antistick);
                    MessageSender.SendRewardMessage(result, _messages, message);
                }
            });
        }
        int bigStationsCount = GameController.GetInstance().GetBigStationsCount();

        if (bigStationsCount > 0)
        {
            if (GameController.GetInstance().GetKilledPassengersCount() == 0)
            {
                _client.SendLivesaverRecord(bigStationsCount, (result) => {
                    if (!result.HasField("error"))
                    {
                        string message = string.Format(StringResources.GetLocalizedString("newLivesaverRecord"),
                                                       bigStationsCount);
                        MessageSender.SendRewardMessage(result, _messages, message);
                    }
                });
            }
            if (bigStationsCount > 1)
            {
                _client.SendTruckerRecord(bigStationsCount, (result) => {
                    if (!result.HasField("error"))
                    {
                        string message = string.Format(StringResources.GetLocalizedString("newTruckerRecord"),
                                                       bigStationsCount);
                        MessageSender.SendRewardMessage(result, _messages, message);
                    }
                });
            }
        }
    }