Beispiel #1
0
    public static IEnumerator <float> WakeUpHospital()
    {
        GameTime.Clock.ResetSpeed();
        GameLibOfMethods.blackScreen.CrossFadeAlpha(1, 0.5f, false);
        yield return(MEC.Timing.WaitForSeconds(2));

        Player.anim.enabled = true;


        foreach (PlayerStats.Status.Type type in Stats.PlayerStatus.Keys)
        {
            Stats.Add(type, float.MaxValue);
        }

        Player.transform.rotation = Quaternion.Euler(0, 0, 0);

        Stats.RemoveMoney(GameLibOfMethods.HospitalFee);

        Vector3 SpawnPosition = GameLibOfMethods.HospitalRespawnPoint.position;

        SpawnPosition.z = Player.transform.position.z;

        Player.transform.position = SpawnPosition;

        GameLibOfMethods.blackScreen.CrossFadeAlpha(0, 2, false);
        GameLibOfMethods.cantMove = false;
        CameraFollow.Instance.ResetCamera();

        PlayerAnimationHelper.ResetPlayer();
    }
Beispiel #2
0
 public void OnFix()
 {
     BrokenParticleSystem.Stop();
     Progress.transform.parent.gameObject.SetActive(false);
     isBroken            = false;
     RepairProgress      = 0;
     Progress.fillAmount = RepairProgress;
     PlayerAnimationHelper.ResetPlayer();
     Stats.AddXP(Type.Repair, 10);
 }
 public void UnloadFromCar()
 {
     if (anim.GetBool("PlayerIsInCar") == true)
     {
         PlayerAnimationHelper.ResetPlayer();
         PlayerCommands.MoveTo(PlayerCommands.LastPositionBeforeWalk, PlayerAnimationHelper.ResetPlayer);
         anim.SetBool("PlayerIsInCar", false);
         JobManager.Instance.isWorking = false;
         CarDriveFromHouseToLeft();
     }
 }
 void Cancel()
 {
     if (currentHandle == null)
     {
         return;
     }
     MEC.Timing.KillCoroutines(currentHandle.Value);
     currentHandle = null;
     anim.SetBool("Walking", false);
     //IgnoreAllCollisionExcept(false);
     GameLibOfMethods.player.GetComponent <Collider2D>().isTrigger = false;
     PlayerAnimationHelper.ResetPlayer();
 }
Beispiel #5
0
 void Cancel()
 {
     if (currentHandle == null)
     {
         return;
     }
     MEC.Timing.KillCoroutines(currentHandle.Value);
     currentHandle = null;
     currentTarget = null;
     anim.SetBool("Walking", false);
     //IgnoreAllCollisionExcept(false);
     col.isTrigger = false;
     PlayerAnimationHelper.ResetPlayer();
 }
Beispiel #6
0
    public void UnloadFromCar()
    {
        if (!anim.GetBool("PlayerIsInCar"))
        {
            return;
        }

        PlayerAnimationHelper.ResetPlayer();
        PlayerCommands.MoveTo(PlayerCommands.LastPositionBeforeWalk, delegate { PlayerAnimationHelper.ResetPlayer();
                                                                                Player.col.enabled = true; });
        anim.SetBool("PlayerIsInCar", false);
        JobManager.Instance.isWorking = false;
        CarDriveFromHouseToLeft();
        Player.col.enabled = true;
        IgnorePlayer       = false;
    }
    public static IEnumerator DoAction(UnityAction action, float SecondsToComplete, string animationToPlay)
    {
        GameTime.Clock.ResetSpeed();
        if (!GameLibOfMethods.doingSomething && !isSleeping && canInteract)
        {
            cantMove           = true;
            doingSomething     = true;
            canInteract        = false;
            requiredActionTime = SecondsToComplete;

            GameLibOfMethods.animator.SetBool(animationToPlay, true);

            while (true)
            {
                //GameLibOfMethods.doingSomething = true;

                if (progress < 1 && !GameLibOfMethods.animator.GetBool("Walking"))
                {
                    GameLibOfMethods.animator.SetBool(animationToPlay, true);
                    currentActionTime += Time.deltaTime;
                    progress           = currentActionTime / requiredActionTime;
                }
                else
                {
                    GameLibOfMethods.animator.SetBool(animationToPlay, false);
                }
                if (progress >= 1)
                {
                    PlayerAnimationHelper.ResetPlayer();
                    action();
                    currentActionTime = 0;
                    progress          = 0;

                    GameLibOfMethods.doingSomething = false;

                    yield break;
                }



                yield return(new WaitForFixedUpdate());
            }
        }
    }
Beispiel #8
0
    public IEnumerator Fix()
    {
        yield return(new WaitForEndOfFrame());

        if (GameLibOfMethods.canInteract && !GameLibOfMethods.doingSomething && isBroken)
        {
            yield return(new WaitForEndOfFrame());

            GameLibOfMethods.cantMove       = true;
            GameLibOfMethods.canInteract    = false;
            GameLibOfMethods.doingSomething = true;
            GameLibOfMethods.animator.SetBool("Fixing", true);
            Progress.transform.parent.gameObject.SetActive(true);
            Break();
            yield return(new WaitForEndOfFrame());

            while (!Input.GetKey(KeyCode.E))
            {
                RepairProgress     += (Time.deltaTime * repairSpeed) * Stats.RepairSpeed;
                Progress.fillAmount = RepairProgress / 100;
                if (RepairProgress >= 100)
                {
                    OnFix();
                    yield break;
                }

                yield return(new WaitForFixedUpdate());
            }
            yield return(new WaitForSecondsRealtime(0.1f));



            GameLibOfMethods.player.GetComponent <Rigidbody2D>().velocity = Vector3.zero;
            PlayerAnimationHelper.ResetPlayer();
            yield return(null);
        }
        else
        {
            yield break;
        }
    }
Beispiel #9
0
        public override void Use()
        {
            CurrentAction.ApplyStatsOnUse();

            if (breakFunctionality.isBroken)
            {
                SpriteControler.Instance.FaceDOWN();

                if (shouldCancel)
                {
                    ResetObjectState(true);
                    ProgressBar.HideUI(progressBarID);
                    PlayerAnimationHelper.ResetPlayer();
                }
                else if (breakFunctionality.AttemptFix())
                {
                    gameObject.GetComponent <Interactivity>().options = originalOptions;
                    breakFunctionality.isBroken = false;
                    PlayerAnimationHelper.ResetPlayer();
                    useState = ObjectUseState.Unused;
                    ResetObjectState(false);
                    ProgressBar.HideUI(progressBarID);
                }
            }
            else
            {
                SpriteControler.Instance.FaceLEFT();

                if (shouldCancel)
                {
                    FinishUsing(true);
                }
                else if (!CurrentAction.ValidateStats())
                {
                    useState = ObjectUseState.Preparation;
                    ExitAfterDelay(false);
                }
            }
        }
Beispiel #10
0
 public static void WalkBackToLastPosition(Action callback) => StartWalking(LastPositionBeforeWalk, () => { PlayerAnimationHelper.ResetPlayer(); callback(); }).Start();
Beispiel #11
0
        IEnumerator <float> WalkTo(Vector3 Position, float StartingSpeedPercentage, float MaxSpeed, System.Action Callback)
        {
            Position = new Vector3(Position.x, Position.y, 1);
            PlayerAnimationHelper.StopPlayer();
            //RequestPath.GetPath(rb.position, Position, path, Resolution.High);
            RequestPath.GetPath_Avoidance(rb.position, Position, path, Resolution.High, col);
            //IgnoreAllCollisionExcept(true, 31, 9, 10);
            col.isTrigger = true;

            float   minSqrDist        = 0;
            Vector3 pathFindingCenter = Vector3.zero;

            if (currentTarget != null)
            {
                minSqrDist        = Mathf.Pow(currentTarget.interactionOptions.InteractionRange, 2);
                pathFindingCenter = currentTarget.gameObject.transform.position + (Vector3)currentTarget.interactionOptions.InteractionCenterOffset;
            }

            yield return(0f);

            if (path.Count != 0)
            {
                anim.SetBool("Walking", true);
            }
            MaxSpeed *= Stats.MoveSpeed;

            float _spd  = StartingSpeedPercentage * MaxSpeed;
            int   index = 0;

            while (this)
            {
                if (index >= path.Count)
                {
                    break;
                }

                if (!CanWalkAt(path[index]))
                {
                    yield return(0f);

                    //RequestPath.GetPath(rb.position, Position, path, Resolution.High);
                    RequestPath.GetPath_Avoidance(rb.position, Position, path, Resolution.High, col);
                    index = 0;
                    continue;
                }

                Vector3 currentPos = rb.position;
                Vector3 targetPos  = grid.PosFromNode(path[index]);

                var offset = new Vector3(targetPos.x - currentPos.x, targetPos.y - currentPos.y, 1);
                if (_spd != MaxSpeed)
                {
                    _spd = Mathf.MoveTowards(_spd, MaxSpeed, 10 * MaxSpeed * GameTime.Time.fixedDeltaTime);
                }
                float currentSpeed = _spd * GameTime.Time.fixedDeltaTime;

                var posAfterMovement = Vector3.MoveTowards(currentPos, targetPos, currentSpeed);

                // Update the index and increase the movement point without losing a frame of movement.
                if (posAfterMovement == targetPos)
                {
                    index++;

                    if (index >= path.Count)
                    {
                    }
                    else
                    {
                        targetPos = new Vector3(grid.PosFromNode(path[index]).x, grid.PosFromNode(path[index]).y, 1);
                        offset    = new Vector3(targetPos.x - currentPos.x, targetPos.y - currentPos.y, 1);

                        posAfterMovement = Vector3.MoveTowards(currentPos, targetPos, currentSpeed);
                    }
                }

                /// Check if we've reached the <see cref="Objects.Functionality.InteractionOptions.InteractionRange"/>.
                if (currentTarget != null)
                {
                    float sqrDistanceToTarget = Vector2.SqrMagnitude(posAfterMovement - pathFindingCenter);
                    if (sqrDistanceToTarget <= minSqrDist)
                    {
                        break;
                    }
                }

                rb.MovePosition(posAfterMovement);

                if (index >= path.Count)
                {
                    break;
                }

                CalculateFacing(offset);

                yield return(0f);
            }

            if (!this)
            {
                yield break;
            }

            anim.SetBool("Walking", false);
            yield return(0f);

            col.isTrigger = false;
            PlayerAnimationHelper.ResetPlayer();
            currentHandle = null;
            currentTarget = null;

            if (Callback != null)
            {
                Callback();
            }
        }
Beispiel #12
0
        private IEnumerator <float> StartCooking(List <ItemList.ItemInfo> itemsToCook)
        {
            cookData.itemsToCook = itemsToCook;

            isCooking = true;
            fryingPan.SetActive(false);

            CookingHandler.ForceClose();

            GameLibOfMethods.canInteract = false;
            GameLibOfMethods.cantMove    = true;
            GameLibOfMethods.Walking     = true;
            SpriteControler.Instance.FaceUP();

            GameLibOfMethods.animator.SetBool("Cooking", true);
            UIManager.Instance.ActionText.text = "Cooking";

            float timeLapse = cookingCanceled ? cookData.timeLapse : 0;

            cookingEXP = cookingCanceled ? cookData.exp : 10f;

            while (timeLapse < timeToCook)
            {
                timeLapse += Time.deltaTime;
                GameLibOfMethods.progress = timeLapse / timeToCook;
                if (Input.GetKeyUp(KeyCode.E) || Input.GetKeyUp(KeyCode.Escape))
                {
                    resumeCooking      = false;
                    cookingCanceled    = true;
                    cookData.exp       = cookingEXP;
                    cookData.timeLapse = timeLapse;
                    break;
                }

                if (Stats.Status(Type.Energy).CurrentAmount <= 0 ||
                    Stats.Status(Type.Health).CurrentAmount <= 0)
                {
                    break;
                }

                yield return(0f);
            }

            GameTime.Clock.ChangeSpeed(5);

            fryingPan.SetActive(true);
            yield return(0f);

            isCooking = false;

            GameLibOfMethods.progress = 0;
            PlayerAnimationHelper.ResetPlayer();

            if (Stats.Status(Type.Energy).CurrentAmount <= 0 || Stats.Status(Type.Health).CurrentAmount <= 0)
            {
                yield return(0f);

                GameLibOfMethods.animator.SetBool("PassOut", true);
            }
            else if (resumeCooking || !cookingCanceled)
            {
                Stats.AddXP(Skill.Type.Cooking, cookingEXP);

                yield return(0f);

                CookingHandler.AddCookedRecipes(itemsToCook);
                Inventory.PlaceOnBag(itemsToCook);

                if (itemsToCook.Count > 0)
                {
                    lastCookItem = itemsToCook[itemsToCook.Count - 1].itemCode;
                }

                yield return(0f);

                cookingCanceled = false;
                resumeCooking   = false;
                cookData.Reset();
            }
        }
Beispiel #13
0
 // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
 override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     GameTime.Clock.ResetSpeed();
     PlayerAnimationHelper.ResetPlayer();
 }
Beispiel #14
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    //{
    //
    //}


    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        PlayerAnimationHelper.ResetPlayer();
    }
        IEnumerator <float> WalkTo(Vector3 Position, float StartingSpeedPercentage, float MaxSpeed, System.Action Callback)
        {
            Position = new Vector3(Position.x, Position.y, 1);
            PlayerAnimationHelper.StopPlayer();
            //RequestPath.GetPath(rb.position, Position, path, Resolution.High);
            RequestPath.GetPath_Avoidance(rb.position, Position, path, Resolution.High, col);
            //IgnoreAllCollisionExcept(true, 31, 9, 10);
            col.isTrigger = true;

            yield return(0f);

            if (path.Count != 0)
            {
                anim.SetBool("Walking", true);
            }
            MaxSpeed *= Stats.MoveSpeed;

            float _spd  = StartingSpeedPercentage * MaxSpeed;
            int   index = 0;

            while (this)
            {
                if (index >= path.Count)
                {
                    break;
                }

                if (!CanWalkAt(path[index]))
                {
                    yield return(0f);

                    //RequestPath.GetPath(rb.position, Position, path, Resolution.High);
                    RequestPath.GetPath_Avoidance(rb.position, Position, path, Resolution.High, col);
                    index = 0;
                    continue;
                }

                Vector3 targetPos = grid.PosFromNode(path[index]);

                Vector3 offset = new Vector3(targetPos.x - rb.position.x, targetPos.y - rb.position.y, 1);
                if (_spd != MaxSpeed)
                {
                    _spd = Mathf.MoveTowards(_spd, MaxSpeed, 10 * MaxSpeed * Time.fixedDeltaTime);
                }
                float currentSpeed = _spd * Time.fixedDeltaTime;

                var posAfterMovement = Vector3.MoveTowards(rb.position, targetPos, currentSpeed);

                if (posAfterMovement == targetPos)
                {
                    index++;

                    if (index >= path.Count)
                    {
                    }
                    else
                    {
                        targetPos = new Vector3(grid.PosFromNode(path[index]).x, grid.PosFromNode(path[index]).y, 1);
                        offset    = new Vector3(targetPos.x - rb.position.x, targetPos.y - rb.position.y, 1);

                        posAfterMovement = Vector3.MoveTowards(rb.position, targetPos, currentSpeed);
                    }
                }

                rb.MovePosition(posAfterMovement);

                if (index >= path.Count)
                {
                    break;
                }

                CalculateFacing(offset);

                yield return(0f);
            }

            if (!this)
            {
                yield break;
            }

            anim.SetBool("Walking", false);
            yield return(0f);

            GameLibOfMethods.player.GetComponent <Collider2D>().isTrigger = false;
            PlayerAnimationHelper.ResetPlayer();
            currentHandle = null;

            if (Callback != null)
            {
                Callback();
            }
        }