Ejemplo n.º 1
0
    private void ShowNextTrainingMessage()
    {
        TrainingHandler handler =
            MonobehaviorHandler.GetMonobeharior().GetObject <TrainingHandler>("TrainingHandler");

        handler.ShowNext();
    }
Ejemplo n.º 2
0
 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();
     }
 }
Ejemplo n.º 3
0
    public override void OnUpdate()
    {
        if (_conductor.GetDragTarget() == null || !Input.GetMouseButton(0))
        {
            _conductor.StopDrag(false);
            return;
        }
        Vector3 targetPos = new Vector3();

        if (!MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetCurrentMousePosition(ref targetPos))
        {
            return;
        }
        Vector2 dragOffset = _conductor.GetDragOffset();

        if (dragOffset.sqrMagnitude > 0.1f)
        {
            MovableCharacter.Animator.Play("walk");
            Vector3 newPosition = Vector3.MoveTowards(MovableCharacter.transform.position, _conductor.GetDragTarget().transform.position,
                                                      _conductor.MovingToDragTargetVelocity * Time.deltaTime);
            newPosition.z = -1;
            MovableCharacter.transform.position = newPosition;
        }
        else
        {
            MovableCharacter.Animator.Play("drag");
            Vector3 newPos = (Vector2)targetPos + _conductor.GetDragOffset();
            MovableCharacter.CalculateOrientation(newPos);
            MovableCharacter.transform.position = newPos;
        }
    }
Ejemplo n.º 4
0
    public bool FindRunAwayTarget(PassengerSM ps)
    {
        _passengers.RemoveAll(item => item == null);
        foreach (var passenger in _passengers)
        {
            if (passenger != ps)
            {
                float dist = ((Vector2)passenger.transform.position - (Vector2)ps.transform.position).sqrMagnitude;
                if (dist < ps.AttackMaxDistance)
                {
                    if (ps.TryRunAwayFromMovable(passenger))
                    {
                        return(true);
                    }
                }
            }
        }
        ConductorSM hero          = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();
        float       conductorDist = ((Vector2)hero.transform.position - (Vector2)ps.transform.position).sqrMagnitude;

        if (conductorDist < ps.AttackMaxDistance)
        {
            if (ps.TryRunAwayFromMovable(hero))
            {
                return(true);
            }
        }
        return(false);
    }
Ejemplo n.º 5
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;
         }
     }
 }
Ejemplo n.º 6
0
    protected override void Update()
    {
        base.Update();
        ConductorSM hero = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();

        if (hero == null)
        {
            return;
        }
        CalculateIndicator();
        if (!hero.IsDragging())
        {
            StopDrag(false);
        }
        if (AttackTarget != null)
        {
            if (AttackTarget.CanNotInteract())
            {
                AttackTarget = null;
            }
        }
        _attackingDenyPeriod -= Time.deltaTime;
        if (_attackingDenyPeriod <= 0)
        {
            IsAttackingAllowed = true;
        }
        if (AttackTarget != null)
        {
            float dist = AttackTargetDistance();
            if (dist > AttackMaxDistance)
            {
                AttackTarget = null;
            }
        }
    }
Ejemplo n.º 7
0
    public void CalculateMagnet()
    {
        if (_isMagnetActivated)
        {
            if (_hasTicket && _isVisibleToHero)
            {
                _isMagnetActivated = false;
                _isMagnetTurnedOn  = false;
            }
        }
        ConductorSM hero         = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();
        Vector2     heroPosition = hero.transform.position;
        float       heroDist     = ((Vector2)transform.position - heroPosition).sqrMagnitude;

        if (heroDist < _magnetDistance || _isMagnetActivated)
        {
            _isMagnetActivated = true;
            if (heroDist < 0.1f)
            {
                return;
            }
            if (!GetTarget().Equals(heroPosition))
            {
                SetTarget(hero.transform.position);
            }
        }
    }
Ejemplo n.º 8
0
    public override void OnUpdate()
    {
        MovableCharacter.Animator.Play("walk");
        if (_passenger.IsMagnetTurnedOn())
        {
            _passenger.CalculateMagnet();
        }
        float sqrRemainingDistance = MovableCharacter.GetTargetDistance();

        if (sqrRemainingDistance <= 0.1)
        {
            if (MovableCharacter.IsGoingAway)
            {
                if (GameController.GetInstance().IsDoorsOpen() && MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").IsPassengerNearDoors(_passenger))
                {
                    CalculateStickOnExit();
                    if (!_passenger.IsStick())
                    {
                        GameObject.Destroy(_passenger.gameObject);
                        return;
                    }
                }
            }
            else
            {
                if (!_passenger.IsStick())
                {
                    _passenger.MakeIdle();
                }
            }
            return;
        }
        CalculatePosition();
    }
Ejemplo n.º 9
0
 void FixedUpdate()
 {
     if (_isPaused)
     {
         _currentStickSoundRemainingTime -= Time.fixedDeltaTime;
         if (_currentStickSoundRemainingTime <= 0)
         {
             _currentStickSoundRemainingTime = StickSoundDelay;
             _player.PlayAudioById("tramdoorstuck");
         }
         if (_currentStickPassenger == null)
         {
             _currentStickPassenger = GameController.GetInstance().GetStickPassenger();
             if (_currentStickPassenger != null)
             {
                 _currentStickDoor = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetPassengerDoor(_currentStickPassenger)
                                     .GetComponent <DoorsAnimationController>();
             }
         }
         if (_currentStickDoor != null)
         {
             _currentStickDoor.Glitch();
         }
         return;
     }
     if (_isDoorsOpen)
     {
         _currentStopDuration += Time.fixedDeltaTime;
         if (_currentStopDuration > _stopDuration)
         {
             _isDoorsOpen         = false;
             _currentStopDuration = 0;
             UpdateDoors();
         }
     }
     else
     {
         if (!_isMovementTimeLocked)
         {
             _currentMoveDuration += Time.fixedDeltaTime;
         }
         if (_currentMoveDuration > _currentStationTotalMoveDuration)
         {
             _isDoorsOpen         = true;
             _currentMoveDuration = 0;
             GameController.GetInstance().CheckBeforeDoorsOpen();
             UpdateDoors();
             GameController.GetInstance().IncrementStationNumberForPassengers();
             if (_countToFinish > 0)
             {
                 _countToFinish--;
                 if (_countToFinish == 0)
                 {
                     MonobehaviorHandler.GetMonobeharior()
                     .GetObject <TrainingHandler>("TrainingHandler").ShowNext();
                 }
             }
         }
     }
 }
Ejemplo n.º 10
0
 public override void HandleDoubleClick()
 {
     if (Time.timeScale == 0)
     {
         return;
     }
     MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").DoubleClick();
 }
Ejemplo n.º 11
0
    public void RegisterDeath(MovableCharacterSM obj)
    {
        if (obj is ConductorSM)
        {
            GameOver(true);
        }
        else
        {
            if (obj is PassengerSM)
            {
                var ps = obj as PassengerSM;
                if (ps.HasTicket())
                {
                    if (!ps.WasStickWhenFlyAway)
                    {
                        _killedPassengers++;
                    }
                    if (!ps.IsVisibleToHero())
                    {
                        if (_totalHares > 0)
                        {
                            _totalHares--;
                        }
                    }
                }
                else
                {
                    if (!_flyingAwayByKinds.ContainsKey(ps.GetClassName()))
                    {
                        _flyingAwayByKinds.Add(ps.GetClassName(), 1);
                    }
                    else
                    {
                        int currentValue = _flyingAwayByKinds [ps.GetClassName()];
                        _flyingAwayByKinds [ps.GetClassName()] = currentValue + 1;
                    }
                    if (_totalHares > 0)
                    {
                        _totalHares--;
                    }
                }

                _passengers.Remove(ps);
            }
            UpdateStats();
            if (_maxKilledPassengers < 0)
            {
                GameOver(false);
            }
            else
            {
                if (_passengers.Count == 0)
                {
                    MonobehaviorHandler.GetMonobeharior().GetObject <DoorsTimer>("DoorsTimer").StopNow();
                }
            }
        }
    }
Ejemplo n.º 12
0
    public void MoveToRandomPosition()
    {
        Vector2 target = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetRandomPosition();

        if (target != default(Vector2))
        {
            SetTarget(target);
        }
    }
Ejemplo n.º 13
0
 public void IncrementStationCount()
 {
     _currentTramStopCount++;
     if (_currentTramStopCount > _tramStopCount && !IsGoingAway)
     {
         DoorsAnimationController door1 =
             MonobehaviorHandler.GetMonobeharior().GetObject <DoorsAnimationController>("door1");
         DoorsAnimationController door2 =
             MonobehaviorHandler.GetMonobeharior().GetObject <DoorsAnimationController>("door2");
         DoorsAnimationController door3 =
             MonobehaviorHandler.GetMonobeharior().GetObject <DoorsAnimationController>("door3");
         DoorsAnimationController door4 =
             MonobehaviorHandler.GetMonobeharior().GetObject <DoorsAnimationController>("door4");
         List <DoorsAnimationController> selected = new List <DoorsAnimationController>();
         if (door1.IsOpened())
         {
             selected.Add(door1);
         }
         if (door2.IsOpened())
         {
             selected.Add(door2);
         }
         if (door3.IsOpened())
         {
             selected.Add(door3);
         }
         if (door4.IsOpened())
         {
             selected.Add(door4);
         }
         if (selected.Count == 0)
         {
             return;
         }
         int randomPercent = Randomizer.GetRandomPercent();
         int step          = 100 / selected.Count;
         int currentStep   = 0;
         int i             = 0;
         for (i = 0; i < selected.Count - 1; i++)
         {
             if (currentStep > randomPercent)
             {
                 break;
             }
             currentStep += step;
         }
         BoxCollider2D collider = selected[i].GetComponent <BoxCollider2D>();
         Vector2       target   = new Vector2(selected[i].gameObject.transform.position.x, selected[i].gameObject.transform.position.y) + collider.offset;
         Velocity *= 2;
         if (_isGoAwayVelocityIncreased)
         {
             Velocity *= 2;
         }
         IsGoingAway = true;
         base.SetTarget(target);
     }
 }
Ejemplo n.º 14
0
 public override void Deactivate()
 {
     base.Deactivate();
     GameController.GetInstance().BonusEffectToPassengers(this, false);
     if (IsConductorAffected)
     {
         ConductorSM conductor = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();
         RemoveEffectFromConductor(conductor);
     }
 }
Ejemplo n.º 15
0
 public void GameOver(bool isConductorDied)
 {
     MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero().StopDrag(false);
     _isGameFinished = true;
     Time.timeScale  = 0;
     UpdateListeners(isConductorDied);
     foreach (var gameStateNotificationListener in _listeners)
     {
         gameStateNotificationListener.GameOver();
     }
 }
Ejemplo n.º 16
0
 private void CalculateStickOnExit()
 {
     if (_passenger.GetActiveState().Equals((int)MovableCharacterSM.MovableCharacterStates.Stick))
     {
         return;
     }
     _passenger.CalculateStick();
     if (_passenger.IsStick())
     {
         MonobehaviorHandler.GetMonobeharior().GetObject <DoorsTimer>("DoorsTimer").SetPaused(true);
     }
 }
Ejemplo n.º 17
0
    protected override void Update()
    {
        base.Update();
        float newScale = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").CalculateLocalScaleForMovable(this);

        if (Math.Abs(newScale - _currentScale) > 0.01f)
        {
            _currentScale = newScale;
            bool inversed = (CharacterBody.transform.localScale.x < 0);
            CharacterBody.transform.localScale = new Vector3(inversed ? -newScale : newScale, newScale, 1);
        }
    }
Ejemplo n.º 18
0
 protected override void OnStart()
 {
     _timeSinceStateChanged = 0;
     if (_hero == null)
     {
         _hero = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();
     }
     if (_floor == null)
     {
         _floor = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor");
     }
 }
Ejemplo n.º 19
0
 public override void Activate()
 {
     base.Activate();
     if (IsPassengersAffected)
     {
         GameController.GetInstance().BonusEffectToPassengers(this, true);
     }
     if (IsConductorAffected)
     {
         ConductorSM conductor = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();
         AddEffectToConductor(conductor);
     }
 }
Ejemplo n.º 20
0
    public override void OnUpdate()
    {
        RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

        if (Input.GetMouseButtonDown(0))
        {
            Vector2 transform2d = MovableCharacter.transform.position;
            float   distance    = (transform2d - hit.centroid).sqrMagnitude;
            if (distance < 1 && MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero().IsInAttackRadius(MovableCharacter.transform.position))
            {
                _passenger.HandleClick();
            }
        }
    }
Ejemplo n.º 21
0
 protected override void AddEffectAfterCheck(PassengerSM passenger)
 {
     MonobehaviorHandler.GetMonobeharior().GetObject <DoorsTimer>("DoorsTimer").SetPaused(false);
     passenger.ActiveBonuses.Add(GetBonusType());
     if (_data == null)
     {
         _data            = new FreezeData();
         _data.Distance   = Dist;
         _data.StartPoint = Position;
         _floor           = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor");
         _floor.SnowDrop(_data, true);
     }
     passenger.ActivateFreezeBonus(_data);
 }
Ejemplo n.º 22
0
 public void CalculateOrientation(Vector2 target)
 {
     if (_currentScale == 0)
     {
         _currentScale = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").CalculateLocalScaleForMovable(this);
     }
     if (target.x > transform.position.x)
     {
         CharacterBody.transform.localScale = new Vector3(-_currentScale, _currentScale, 1);
     }
     else
     {
         CharacterBody.transform.localScale = new Vector3(_currentScale, _currentScale, 1);
     }
 }
Ejemplo n.º 23
0
    public void AddVortexEffect(Vector2 point, float dist)
    {
        float   randomAngleInDegrees = Randomizer.GetInRange(0, 360);
        float   radians   = randomAngleInDegrees * Mathf.Deg2Rad;
        float   finalDist = Mathf.Min(dist * 0.5f, Randomizer.GetNormalizedRandom() * dist);
        float   xOffset   = finalDist * Mathf.Cos(radians);
        float   yOffset   = finalDist * Mathf.Sin(radians);
        Vector3 oldPos    = transform.position;
        Vector3 newPos    = new Vector3(oldPos.x + xOffset, oldPos.y + yOffset, oldPos.z);

        MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").NormalizePosition(ref newPos, true);
        StopStick();
        MakeIdle();
        transform.position = newPos;
    }
Ejemplo n.º 24
0
    public override void HandleDoubleClick()
    {
        ConductorSM hero = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();

        if (hero.CanKick(this))
        {
            if (_isFlyAwayDenied)
            {
                return;
            }
            hero.Kick(this);
            return;
        }
        hero.StartDrag(this);
    }
Ejemplo n.º 25
0
 void OnMouseDown()
 {
     if (Time.timeScale == 0)
     {
         return;
     }
     if (!TrainingHandler.IsTrainingFinished())
     {
         if (_currentPeriod < WaitTimeForTraining)
         {
             return;
         }
     }
     MonobehaviorHandler.GetMonobeharior()
     .GetObject <BonusTimer>("bonusTimer").ActivateDrop(this);
 }
Ejemplo n.º 26
0
    private void CalculateTarget()
    {
        if (_passenger.GetPursuer() == null)
        {
            _passenger.MakeIdle();
            return;
        }
        float   dot             = Vector2.Dot(_passenger.GetPursuer().transform.position, _passenger.transform.position);
        float   angle           = Mathf.Acos(dot);
        Vector2 incrementVector = new Vector2(_passenger.AttackMaxDistance, 0);
        Vector2 rotated         = Quaternion.Euler(0, 0, angle) * incrementVector;
        Vector3 final           = (Vector2)_passenger.transform.position + rotated;

        MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").NormalizePosition(ref final, true);
        _passenger.SetEscapeTarget(final);
        _targetCalculated = true;
    }
Ejemplo n.º 27
0
 void Update()
 {
     if (_isGlitch)
     {
         if (_currentStickPeriod > 0)
         {
             _currentStickPeriod -= Time.deltaTime;
         }
         else
         {
             _currentStickPeriod = 0;
             GameController.GetInstance().KillStickPassenger();
             MonobehaviorHandler.GetMonobeharior().GetObject <DoorsTimer>("DoorsTimer").SetPaused(false);
             _isGlitch = false;
         }
     }
 }
Ejemplo n.º 28
0
 void FixedUpdate()
 {
     if (_currentStickPeriod > 0)
     {
         _currentStickPeriod -= Time.fixedDeltaTime;
     }
     else
     {
         _currentStickPeriod = 0;
     }
     UpdateText();
     if (_currentStickPeriod == 0)
     {
         GameController.GetInstance().KillStickPassenger();
         MonobehaviorHandler.GetMonobeharior().GetObject <DoorsTimer>("DoorsTimer").SetPaused(false);
     }
 }
Ejemplo n.º 29
0
    public static void ReplacePassenger(PassengerSM passenger)
    {
        Vector3 passengerPosition = passenger.transform.position;
        bool    hasTicket         = passenger.HasTicket();
        bool    isVisibleToHero   = passenger.IsVisibleToHero();
        string  passengerType     = passenger.GetClassName();

        passenger.enabled = false;
        if (_spawner == null)
        {
            _spawner = MonobehaviorHandler.GetMonobeharior().GetObject <Spawner>("Spawner");
        }
        PassengerSM newPassenger = _spawner.SpawnAlternativePassenger(passengerPosition, passengerType);

        newPassenger.SetTicketAndVisibility(hasTicket, isVisibleToHero);
        GameController.GetInstance().ReplacePassenger(newPassenger, passenger);
    }
Ejemplo n.º 30
0
    public override void OnUpdate()
    {
        MovableCharacter.Animator.Play("attacked");
        Vector3 newPosition = Vector3.MoveTowards(MovableCharacter.transform.position, _flyTarget, 50 * Time.deltaTime);

        MovableCharacter.transform.position = newPosition;
        float sqrRemainingDistance = ((Vector2)newPosition - (Vector2)_flyTarget).sqrMagnitude;

        if (sqrRemainingDistance <= 1)
        {
            if (_passenger.IsFlyAwayListenerActivated())
            {
                MonobehaviorHandler.GetMonobeharior().GetObject <TrainingHandler>("TrainingHandler").ShowNext();
            }
            MonoBehaviour.Destroy(MovableCharacter.gameObject);
        }
    }