Esempio n. 1
0
        /// <summary>
        /// Event when exiting a state
        /// </summary>
        public void OnStateExit(PetState state, PetState toState)
        {
            switch (state)
            {
            case PetState.Default:
            {
                MaxStableMoveSpeed = 7f;
                StopActiveCoroutine(ForceDeviationChangeCoroutine);
                break;
            }

            case PetState.Crouched:
            {
                MaxStableMoveSpeed = 7f;
                StopActiveCoroutine(ForceDeviationChangeCoroutine);
                Motor.SetCapsuleDimensions(0.5f, 1f, .25f);       //Scales the hitbox.
                MeshRoot.localScale = new Vector3(1f, .5f, 1.2f); //Scales the mesh root.
                break;
            }

            case PetState.FollowPath:
            {
                _canCheckPathfinding = true;
                break;
            }
            }
        }
Esempio n. 2
0
        private void OnRealMinuteChanged(object sender, MinuteChangedEventArgs e)
        {
            PetState        state = new PetState(Pet.Mood, Pet.Satiety, Pet.CleanessRate, Pet.Health);
            PetUpdateParams param = PetUpdateUtil.CreateHourParamsFromPetState(state);

            Pet.UpdatePetFromParams(param);
        }
Esempio n. 3
0
        public static PetUpdateParams CreateHourParamsFromPetState(PetState state)
        {
            var petParams = new PetUpdateParams();

            ConfigureHourParamsFromPetState(petParams, state);
            return(petParams);
        }
        /// <summary>
        /// Event when exiting a state
        /// </summary>
        public void OnStateExit(PetState state, PetState toState)
        {
            switch (state)
            {
            case PetState.Default:
            {
                switch (currentDefaultState)
                {
                case PetDefaultState.Run:
                {
                    break;
                }

                case PetDefaultState.Walk:
                {
                    break;
                }
                }
                break;
            }

            case PetState.Crouched:
            {
                Motor.SetCapsuleDimensions(0.5f, 1f, .25f);       //Scales the hitbox.
                MeshRoot.localScale = new Vector3(1f, .5f, 1.2f); //Scales the mesh root.
                break;
            }
            }
        }
        public virtual void Create(string _prefabName, Vector3 _offset)
        {
            if (!this.actorPtr || this.parentObj == null || this.parentObj.transform == null)
            {
                return;
            }
            this.offset         = _offset;
            this.offsetDistance = Vector3.Distance(new Vector3(0f, 0f, 0f), this.offset);
            this.deltaTime      = 0;
            Vector3 pos = this.parentObj.transform.localToWorldMatrix.MultiplyPoint(this.offset);

            this.meshObj = MonoSingleton <SceneMgr> .GetInstance().GetPooledGameObjLOD(_prefabName, false, SceneObjType.ActionRes, pos, this.parentObj.transform.rotation);

            if (this.meshObj != null)
            {
                this.animSet = this.meshObj.GetComponent <Animation>();
                if (this.animSet != null)
                {
                    this.animSet.Play("Idle");
                }
                this.petTrans    = this.meshObj.transform;
                this.parentTrans = this.parentObj.transform;
                this.bActive     = true;
                this.curState    = PetState.Idle;
                return;
            }
            this.bActive = false;
        }
Esempio n. 6
0
        //public void GetPlayerState()

        /// <summary>
        /// Event when entering a state
        /// </summary>
        public void OnStateEnter(PetState state, PetState fromState)
        {
            switch (state)
            {
            case PetState.Default:
            {
                canChangeDeviationDirection = true;
                _canForceDeviation          = true;
                MaxStableMoveSpeed          = 7f;
                targetMoveSpeed             = 7f;
                _canSetFollowPoint          = true;
                //radiusSize = 5f;
                currentDefaultState = PetDefaultState.Idle;
                break;
            }

            case PetState.Crouched:
            {
                canChangeDeviationDirection = true;
                _canForceDeviation          = true;
                MaxStableMoveSpeed          = 3f;
                _canSetFollowPoint          = true;
                //radiusSize = 5f;
                currentDefaultState     = PetDefaultState.Idle;
                StableMovementSharpness = 7f;

                //Set dimensions and scale
                Motor.SetCapsuleDimensions(0.5f, 1f, 0.25f);        //Scales the hitbox.
                MeshRoot.localScale = new Vector3(1f, 0.35f, 1.2f); //Scales the mesh root.
                break;
            }
            }
        }
        /// <summary>
        /// Event when exiting a state
        /// </summary>
        public void OnStateExit(PetState state, PetState toState)
        {
            switch (state)
            {
            case PetState.Default:
            {
                MaxStableMoveSpeed = 7f;
                break;
            }

            case PetState.Crouched:
            {
                MaxStableMoveSpeed = 3f;
                Motor.SetCapsuleDimensions(0.5f, 1f, .25f);       //Scales the hitbox.
                MeshRoot.localScale = new Vector3(1f, .5f, 1.2f); //Scales the mesh root.
                break;
            }

            case PetState.MoveStraightToPlayer:
            {
                walkRadius = 3.75f;     //3.2f
                break;
            }

            case PetState.FollowPath:
            {
                _canCheckPathfinding = true;
                break;
            }
            }
        }
Esempio n. 8
0
    private void Point()
    {
        _petState = PetState.Targeted;
        PlayerWatchData playerWatchData = _camera.GetComponent <PlayerWatchData>();

        if (playerWatchData)
        {
            (GameObject hit, Transform potentialTarget, float touchDistance) = playerWatchData.GetRaycast();
            if (hit.GetComponent <ObjectiveCompanionReachPoint>() || hit.GetComponent <Bush>())
            {
                _currentTarget       = potentialTarget;
                _interactionDistance = touchDistance;
                Move(potentialTarget, touchDistance);
            }

            else
            {
                Debug.Log(string.Format("Hit missed. Reason: {0} {1} {2}", hit, hit.GetComponent <ObjectiveCompanionReachPoint>(), potentialTarget));
                _petState = PetState.Follow;
            }
        }

        else
        {
            _petState = PetState.Follow;
            return;
        }
    }
Esempio n. 9
0
    // If Player Health is below x, the Pet will heal the Player to for x seconds.
    private void PetHeal(Vector3 _petDesti)
    {
        if (!HasPetHeal)
        {
            // Pet will walk to Player smoothly.
            transform.position = Vector2.SmoothDamp(transform.position, _petDesti, ref currentVelocity, followTimer, maxSpeed, Time.deltaTime);

            // Distance between Player and Pet.
            distanceApart = (transform.position - _petDesti).magnitude;

            if (distanceApart < PetHealRange)
            {
                // Activate Healing Sprite
                playerHealingSprite.SetActive(true);
                CanActivateSprite = true;
                // Increase Player Health from Pet's HP.
                playerStats.Health += addPlayerHP;
                health             -= addPlayerHP;
                HasPetHeal          = true;
            }
        }

        if (HasPetHeal)
        {
            // Start the cool down timer.
            CanHealCoolDown = true;
            // Changing to Guard State.
            petState = PetState.GUARD;
        }
    }
Esempio n. 10
0
 private static void ConfigureHourParamsFromMood(PetUpdateParams petParams, PetState petState)
 {
     if (petState.Mood < GameConstants.CriticalLimit)
     {
         petParams.HealthDifference -= 5;
     }
 }
Esempio n. 11
0
 void OutOfRange()
 {
     Debug.Log("Pet OutOfRange");
     transform.position = PlayerTransform.initialPos;
     CurrentState       = PetState.Idle;
     ResetAttack();
 }
Esempio n. 12
0
    // If there Player Health is 1/2, Pet State will deal damage to the nearest Enemy.
    private void PetAttack(GameObject _closest)
    {
        // Distance between Enemy and Pet.
        distanceApart = (transform.position - _closest.transform.position).magnitude;

        // If Pet is not within Attack Range, walk to Enemy smoothly.
        if (distanceApart > PetAttackRange)
        {
            // Pet will walk to Enemy smoothly.
            transform.position = Vector2.SmoothDamp(transform.position, _closest.transform.position, ref currentVelocity, followTimer, maxSpeed, Time.deltaTime);
        }
        // Pet is within its Attack Range.
        else if (distanceApart < PetAttackRange)
        {
            // Minus Enemy Health.
            if (!HasPetAttack)
            {
                _closest.GetComponent <SkeletonEnemyManager>().Health -= (Attack * 0.5f);
                HasPetAttack = true;
            }
            else if (HasPetAttack)
            {
                HasPetAttack = false;
            }

            if (_closest.GetComponent <SkeletonEnemyManager>().Health <= 0f)
            {
                petState = PetState.GUARD;
            }
        }
    }
Esempio n. 13
0
    void ChaseTarget(Vector3 targetPosition, float chaseInterval, float minDistance)
    {
        if (CurrentState == PetState.Mutate)
        {
            return;
        }

        //var masterPosition = petMaster.position;
        targetPosition.y = transform.position.y;

        if (CurrentState != PetState.Chase && !IsCloseEnough(targetPosition, minDistance + chaseInterval))
        {
            CurrentState = PetState.Chase;
        }

        if (IsCloseEnough(targetPosition, minDistance))
        {
            CurrentState = PetState.None;
            anim.SetFloat(Hash.Speed, 0f);
            return;
        }

        if (CurrentState == PetState.Chase)
        {
            transform.LookAt(targetPosition);
            anim.SetFloat(Hash.Speed, 3.0f);
        }
    }
    void StateManager()
    {
        activeStateName = PetRunFSM.ActiveStateName;

        updateStateHistory(activeStateName);

        foreach (PetState s in states)
        {
            if (s.GetName() == activeStateName)
            {
                currentState = s;
            }
        }

        //If the state has changed since last frame, run that state's init function
        if (previousState != currentState)
        {
            //Debug.Log("Initializing " + currentState.GetName() + " State");
            currentState.Init();
            previousState = currentState;
        }

        if (currentState != null)
        {
            if (currentState.GetType() == typeof(OutOfEnergyState))
            {
                (currentState as OutOfEnergyState).SetPreviousState(getPreviousState());
            }

            currentState.Run();
        }
    }
Esempio n. 15
0
 void Start()
 {
     anim  = GetComponent <Animator>();
     agent = GetComponent <UnityEngine.AI.NavMeshAgent>();
     state = GetComponent <PetState>();
     // Don’t update position automatically, happens during OnAnimator.
     agent.updatePosition = false;
 }
Esempio n. 16
0
    private void Start()
    {
        Button btn = yourButton.GetComponent <Button>();

        btn.onClick.AddListener(OnMouseDown);

        PS = GameObject.FindGameObjectWithTag("Pet").GetComponent <PetState>();
    }
Esempio n. 17
0
        /// <summary>
        /// Handles movement state transitions and enter/exit callbacks
        /// </summary>
        public void TransitionToState(PetState newState)
        {
            PetState tmpInitialState = CurrentPetState; //Get current state.

            OnStateExit(tmpInitialState, newState);     //Do the OnStateExit stuff from current state to new state.
            CurrentPetState = newState;                 //Current state = new state.
            Debug.Log("Pet's state set to " + newState + ".");
            OnStateEnter(newState, tmpInitialState);    //Do the OnStateEnter stuff to new state from the last state.
        }
Esempio n. 18
0
        public void PlayMotion(PetState state)
        {
            if (!IsMine)
            {
                return;
            }

            _photonView.RPC(RPCDefine.PetRPC.GetRPCMethod(RPCDefine.PetRPC.RPCEnum.PlayMotion), PhotonTargets.All, state);
        }
Esempio n. 19
0
    private void EnterState(PetState newState)
    {
        State = newState;
        var js = GetComponent <Jumping>();

        switch (newState)
        {
        case PetState.Satisfied:
            IdleTime = Random.Range(MinIdleTime, MaxIdleTime);
            if (null != DemandIcon)
            {
                DemandIcon.sprite = null;
            }
            if (null != js)
            {
                js.Active = false;
            }
            break;

        case PetState.Hungry:
            PlayPetSound();
            if (null != DemandIcon)
            {
                DemandIcon.sprite = HungrySprite;
            }
            if (null != js)
            {
                js.Active = false;
            }
            break;

        case PetState.Eating:
            EatingTime = Random.Range(MinEatingTime, MaxEatingTime);
            if (null != DemandIcon)
            {
                DemandIcon.sprite = null;
            }
            if (null != js)
            {
                js.Active = false;
            }
            break;

        case PetState.NeedsAShit:
            PlayPetSound();
            if (null != DemandIcon)
            {
                DemandIcon.sprite = NeedsShitSprite;
            }
            if (null != js)
            {
                js.Active = true;
            }
            break;
        }
    }
Esempio n. 20
0
    //When a path can't be created to the enemy...
    private IEnumerator CantReachEnemyDelay()
    {
        CanReachEnemy = false;
        CurrentState  = PetState.Wait;
        Debug.Log("Entered wait state");
        CanCheckDist = false;
        yield return(CustomTimer.Timer(.75f));

        CanCheckDist = true;
    }
Esempio n. 21
0
    // Use this for initialization
    void Start()
    {
        CurrentState = PetState.None;

        anim           = GetComponent <Animator>();
        petConstructor = GetComponent <ARPetConstructor>();
        //anim.CrossFade(idle.name);

        currentTarget = petMaster;
    }
Esempio n. 22
0
        public static AnimationClip GetPetMotion(PetState state)
        {
            if (state == PetState.None)
            {
                Debug.LogError("Invalid Pet State For Animation Clip Resource Loading");
                return(null);
            }

            return(Resources.Load <AnimationClip>(CLIP_PATH[(int)state + 1]));
        }
Esempio n. 23
0
    // Similar to IDLE state of Enemy, Pet will stay still when it's near the Player and "Guard" it.
    private void PetGuard(Vector3 _petDesti)
    {
        // Distance between Player and Pet.
        distanceApart = (transform.position - _petDesti).magnitude;

        // If Player is out of Pet range, change to FOLLOW.
        if (distanceApart > PetGuardRange && distanceApart < PetFollowRange)
        {
            petState = PetState.FOLLOW;
        }
    }
Esempio n. 24
0
 void Start()
 {
     CanAttack    = true;
     CurrentState = PetState.Idle;
     TargetTransform.initialPos = PlayerTransform.initialPos;
     CanFollowPath.initialBool  = true;
     PetIsAttacking.initialBool = false;
     EnemyIsInLOS.initialBool   = false;
     CanGetReposDir             = true;
     CanReachEnemy  = true;
     CanCheckDist   = true;
     CanAttackDelay = true;
 }
Esempio n. 25
0
        /// <summary>
        /// Создать питомца
        /// </summary>
        /// <param name="petId">Идентификатор питомца</param>
        /// <param name="organisationId">Идентификатор организации</param>
        /// <param name="name">Имя питомца</param>
        /// <param name="gender">Пол питомца</param>
        /// <param name="type">Тип питомца</param>
        /// <param name="petState">Статус питомца</param>
        /// <param name="afterPhotoLink">Ссылка на фотку после</param>
        /// <param name="beforePhotoLink">Ссылка на фотку До</param>
        /// <param name="mdShortBody">Краткий текст</param>
        /// <param name="mdBody">Длинный текст</param>
        /// <param name="cancellationToken">Токен признака отмены запроса</param>
        /// <exception cref="PetAlreadyExistsException"></exception>
        /// <exception cref="IdempotencyCheckException"></exception>
        /// <returns></returns>
        public async Task <Guid> Create(
            Guid petId,
            Guid organisationId,
            String name,
            PetGender gender,
            PetType type,
            PetState petState,
            String?afterPhotoLink,
            String?beforePhotoLink,
            String?mdShortBody,
            String?mdBody,
            CancellationToken cancellationToken)
        {
            var pet = await _petRepository.GetAsync(petId : petId, organisation : (Organisation)organisationId, cancellationToken : cancellationToken);

            // если с таким id пет уже был найден, то выполняем проверку идемпотентности
            if (pet is not null)
            {
                if (pet.Gender != gender ||
                    pet.Type != type ||
                    pet.PetState != petState ||
                    !name.Equals(pet.Name, StringComparison.InvariantCultureIgnoreCase) ||
                    (mdShortBody is not null && !mdShortBody.Equals(pet.MdShortBody, StringComparison.InvariantCultureIgnoreCase)) ||
                    (mdBody is not null && !mdBody.Equals(pet.MdBody, StringComparison.InvariantCultureIgnoreCase))
                    )
                {
                    throw new PetAlreadyExistsException(petId);
                }

                return(pet.Id);
            }

            await _petRepository.SaveAsync(
                pet : new Entity.Pet(
                    petId: petId,
                    organisation: new Organisation(organisationId),
                    name: name,
                    gender: gender,
                    type: type,
                    petState: petState,
                    afterPhotoLink: afterPhotoLink,
                    beforePhotoLink: beforePhotoLink,
                    mdShortBody: mdShortBody,
                    mdBody: mdBody,
                    createDate: _dateTimeGetter.Get(),
                    updateDate: _dateTimeGetter.Get()),
                cancellationToken : cancellationToken
                );

            return(petId);
        }
Esempio n. 26
0
        private void OnKill()
        {
            state = PetState.Dead;

            if (animator != null)
            {
                animator.SetTrigger("Death");
            }

            if (onDeath != null)
            {
                onDeath.Invoke();
            }
        }
    void SearchNextPerformer()
    {
        currentState = TurnState.PROCESSING;

        PetState PS = BS.notPerformer.GetComponent <PetState>();

        PS.currentState = PetState.TurnState.PROCESSING;

        for (int i = 0; i < BS.MonstersInBattle.Count; i++)
        {
            BS.notPerformers = GameObject.Find(BS.MonstersInBattle[i].name);
            MonsterState MS = BS.notPerformers.GetComponent <MonsterState>();
            MS.currentState = MonsterState.TurnState.PROCESSING;
        }
    }
Esempio n. 28
0
 public virtual void OnUse()
 {
     this.bActive        = false;
     this.curAnimName    = null;
     this.deltaTime      = 0;
     this.moveDir        = Vector3.zero;
     this.moveSpeed      = 0f;
     this.curState       = PetState.Idle;
     this.offset         = Vector3.zero;
     this.offsetDistance = 0f;
     this.meshObj        = null;
     this.animSet        = null;
     this.parentObj      = null;
     this.actorPtr.Release();
 }
Esempio n. 29
0
        public static void SetState(PetState state)
        {
            if (petState == state)
            {
                return;
            }

            petState = state;
            ModEntry.Log("Set state to " + petState);

            switch (state)
            {
            case PetState.Vanilla:
                throwing = false;
                break;

            case PetState.CatchingUp:
                break;

            case PetState.Waiting:
                Sit();
                CurrentPath.Clear();
                break;

            case PetState.Chasing:
                SetTimer();
                break;

            case PetState.WaitingToFetch:
                SetTimer();
                break;

            case PetState.Fetching:
                SetTimer();
                break;

            case PetState.Retrieve:
                throwing = false;
                break;
            }

            if (state != PetState.Retrieve && state != PetState.Waiting && Stick != null)
            {
                Game1.createItemDebris(Stick, GetPet().Position, 5, Game1.currentLocation);
                Stick = null;
            }
        }
Esempio n. 30
0
    public void WanderAnimation()
    {
        PetState petState = (PetState)this.GetComponent(typeof(PetState));

        if (!this.wanderFirstTime)
        {
            if (!this.get_animation().IsPlaying("WanderActions[0].anim"))
            {
                this.get_animation().CrossFade(this.WanderActions[0].anim);
            }
            float num  = (float)20;
            float num2 = 0f;
            if (Time.get_time() - this.timeLastTurn > (float)4)
            {
                num2                = (float)0;
                this.randomRot      = (float)Random.Range(25, 45);
                this.startDirection = this.get_transform().get_rotation();
                this.newDirection   = Quaternion.get_identity();
                float num3 = this.get_transform().get_eulerAngles().y + this.randomRot;
                this.newDirection.set_eulerAngles(new Vector3((float)0, num3, (float)0));
                int num4 = Random.Range(1, 3);
                this.turnIncr     = (float)num4 * num / Mathf.Abs(this.randomRot);
                this.turnIncr     = (float)1 / Mathf.Abs(this.randomRot);
                this.turnTimer    = this.turnIncr;
                this.timeLastTurn = Time.get_time();
            }
            if (this.turnTimer < this.randomRot)
            {
                this.get_transform().set_rotation(Quaternion.Slerp(this.startDirection, this.newDirection, this.turnTimer));
                this.get_transform().set_eulerAngles(new Vector3((float)0, this.get_transform().get_eulerAngles().y, (float)0));
                this.turnTimer += this.turnIncr;
                if (this.turnTimer >= this.randomRot)
                {
                    this.randomRot = (float)0;
                    this.turnTimer = (float)0;
                }
            }
            Vector3 vector  = this.get_transform().TransformDirection(Vector3.get_forward());
            Vector3 vector2 = vector * this.moveSpeed;
            UnityRuntimeServices.Invoke(this.GetComponent(typeof(CharacterController)), "SimpleMove", new object[]
            {
                vector2
            }, typeof(MonoBehaviour));
        }
    }
Esempio n. 31
0
    public int GetPetState()
    {
        PetState    petState    = (PetState)this.GetComponent(typeof(PetState));
        IdleLogic   idleLogic   = (IdleLogic)this.GetComponent(typeof(IdleLogic));
        FollowLogic followLogic = (FollowLogic)this.GetComponent(typeof(FollowLogic));
        WanderLogic wanderLogic = (WanderLogic)this.GetComponent(typeof(WanderLogic));
        int         result      = this.indexAction;

        this.useTimer = true;
        if (this.calledByPlayer != 0)
        {
            float num = Vector3.Distance(this.get_transform().get_position(), this.owner.get_transform().get_position());
            if (num <= this.ownerDist && RuntimeServices.ToBool(RuntimeServices.InvokeBinaryOperator("op_LessThan", RuntimeServices.GetProperty(RuntimeServices.GetProperty(this.owner.GetComponent(typeof(CharacterController)), "velocity"), "magnitude"), 1)))
            {
                result = 0;
            }
            else if (num > this.ownerDist)
            {
                result = 2;
            }
            this.useTimer = false;
        }
        else if (this.calledByPlayer == 0 && this.indexAction == 2)
        {
            result = Random.Range(0, 2);
        }
        else if (Time.get_time() - (float)this.stateStartTime > this.stateTimeOut)
        {
            int num2 = this.indexAction;
            if (num2 == 0)
            {
                result = 1;
            }
            else if (num2 == 1)
            {
                result = 0;
            }
            else
            {
                result = this.indexAction;
            }
        }
        return(result);
    }