Exemple #1
0
    //check if player is close enough to attack
    public virtual void detectPlayer()
    {
        RaycastHit hit;

        if (state != stateType.dead && state != stateType.stunned)
        {
            //if player is in sight it will attack
            if (Physics.Raycast(transform.position, (player.transform.position - this.transform.position).normalized, out hit))
            {
                if (hit.transform.gameObject.tag == "Wall")
                {
                    state = stateType.wounder;
                }
                else
                {
                    state = stateType.active;
                }
            }

            //even if the play can be seen, if hes too far the ennmy won't attack
            if ((player.transform.position.normalized - transform.position.normalized).magnitude * 1000 > 5000)
            {
                state = stateType.wounder;
            }
        }
    }
Exemple #2
0
    public float stunDuration = 5.0f; // in seconds

    // Use this for initialization
    void Start()
    {
        if (level1GameState == null)
        {
            level1GameState = GameObject.Find("GameManager").GetComponent <Level1GameState>();
        }

        if (globalBehavior == null)
        {
            globalBehavior = FirstGameManager.TheGameState;
        }

        NewDirection();
        if (mAbduct == null)
        {
            mAbduct = Resources.Load("Prefabs/AbductSplash") as GameObject;
        }

        if (hero == null)
        {
            hero = GameObject.Find("Hero") as GameObject;
        }

        renderer = GetComponent <SpriteRenderer>();
        if (null != renderer)
        {
            spriteDefault = Resources.Load("Textures/enemyDefault", typeof(Sprite)) as Sprite;
            spriteStunned = Resources.Load("Textures/enemyStunned", typeof(Sprite)) as Sprite;
            spriteAfraid  = Resources.Load("Textures/enemyAfraid", typeof(Sprite)) as Sprite;
        }

        state = stateType.Default;
    }
 public AIState(NavMeshAgent ag, FiniStateMachine st, KitchenHelper hp, STATUS _status, stateType stateTYPE, Animator an)
 {
     stateMachine = st;
     agent        = ag;
     helper       = hp;
     status       = _status;
     stateType    = stateTYPE;
     anim         = an;
 }
Exemple #4
0
 //method for filling core varables. All ennemies will do this the same way
 public void init()
 {
     rigidbody  = GetComponent <Rigidbody>();
     player     = GameObject.Find("Player");
     invTimer   = 51;
     inState    = inStateType.none;
     state      = stateType.wounder;
     startPos   = transform.position;
     startPos.y = 0;
     finalForce = new Vector3(0, 0, 0);
 }
Exemple #5
0
    // Update is called once per frame
    void Update()
    {
        heroDiff = hero.transform.position - transform.position;
        heroDot  = Vector2.Dot(heroDiff, -hero.transform.up);

        if (state == stateType.Default)
        {
            if (heroDiff.magnitude < maxScare && heroDot > 0)
            {
                state           = stateType.Afraid;
                renderer.sprite = spriteAfraid;
            }
            transform.position += (mSpeed * Time.smoothDeltaTime) * transform.up;
        }
        else if (state == stateType.Stunned)
        {
            mRotation          = transform.rotation.eulerAngles;
            mRotation.z       += (9 * Time.deltaTime);
            transform.rotation = Quaternion.Euler(mRotation);

            stunTimer += Time.deltaTime;
            if (stunTimer > stunDuration)
            {
                state           = stateType.Default;
                renderer.sprite = spriteDefault;
            }
        }
        else if (state == stateType.Afraid)
        {
            if (heroDiff.magnitude > maxScare || heroDot < 0)
            {
                state           = stateType.Default;
                renderer.sprite = spriteDefault;
            }

            run = (mSpeed * .2f * Time.smoothDeltaTime) * (-1 * heroDiff).normalized;

            transform.position += run;

            //transform.rotation = Quaternion.AngleAxis(rotateAngle, transform.forward);
            var angle = Mathf.Atan2(run.y, run.x) * Mathf.Rad2Deg;
            transform.rotation = Quaternion.AngleAxis(angle, transform.forward);
            transform.Rotate(Vector3.forward * -90);
        }

        status = globalBehavior.ObjectCollideWorldBound(GetComponent <Renderer>().bounds);

        if (status != GlobalBehavior.WorldBoundStatus.Inside)
        {
            NewDirection();
        }
    }
Exemple #6
0
    //method for checking invisnbility frames
    void invCheck()
    {
        if (state != stateType.stunned && state != stateType.dead)
        {
            sTimer = 0;


            if (invTimer < 30 * Time.deltaTime)
            {
                invTimer += 1 * Time.deltaTime;
                inState   = inStateType.damage;
                GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 0.8f); // displaying invcibility
                state = stateType.recoil;
            }
            else
            {
                inState = inStateType.none;

                //restart velociy and accl

                if (!behindPlayer) //fill opacity if ennemy is not invicle or behind player
                {
                    GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f);
                }
            }
        }
        else
        {
            sTimer += 1 * Time.deltaTime;
            if (state == stateType.stunned)
            {
                inState = inStateType.none;
                if (sTimer >= sTimeStop * Time.deltaTime)
                {
                    state = stateType.wounder;
                }
            }
            else if (state == stateType.dead)
            {
                inState = inStateType.damage;
                if (sTimer >= 200 * Time.deltaTime)
                {
                    if (this.gameObject.name.Contains("Boss"))
                    {
                        SceneManager.LoadScene("VictoryScreen");
                    }
                    Destroy(gameObject);
                }
            }
        }
    }
Exemple #7
0
    IEnumerator changeState()
    {
        //yield return new WaitForSeconds(0.5f);
        if (states != null && states.Length > 0)
        {
            int       n  = Random.Range(1, states.Length + 1);
            int       i  = 0;
            stateType st = null;
            while (n > 0)
            {
                if (i >= states.Length)
                {
                    i = 0;
                }

                st = states[i];
                if ((canMove != movement.NONE && st.state == stateName.MOVE) || st.state == stateName.IDLE)
                {
                    n--;
                }
                i++;
                yield return(null);
            }

            // Выбрали новое состояние случайным образом
            if (animator != null)
            {
                animator.Play(st.animationName);
            }

            if (st.state == stateName.IDLE)
            {
                timer = st.time;
            }
            else
            {
                destPos = new Vector3(basePos.x, basePos.y, basePos.z);
                if (canMove == movement.BOTH || canMove == movement.HORISONTAL)
                {
                    destPos.x += Random.value * moveRadius / 2f - Random.value * moveRadius / 2f;
                }
                if (canMove == movement.BOTH || canMove == movement.VERTICAL)
                {
                    destPos.y += Random.value * moveRadius / 2f - Random.value * moveRadius / 2f;
                }
            }
            curState  = st;
            activated = true;
        }
        yield return(null);
    }
Exemple #8
0
        /// <see cref="IFunctionalService.CreateToState(Guid, string, stateType, string, string)"/>
        public virtual stateType CreateToState(Guid id, string phaseName, stateType item = null, string zone = null, string context = null)
        {
            Job   job   = repository.Retrieve(id);
            Phase phase = getPhase(job, phaseName);

            RightsUtils.CheckRight(phase.StatesRights, new Right(RightType.CREATE, RightValue.APPROVED));

            PhaseState state = MapperFactory.CreateInstance <stateType, PhaseState>(item);

            job.UpdatePhaseState(phaseName, state.Type, state.Description);
            repository.Save(job);

            return(MapperFactory.CreateInstance <PhaseState, stateType>(phase.GetCurrentState()));
        }
Exemple #9
0
    void Stunned()
    {
        state = stateType.Stunned;
        if (null != renderer)
        {
            renderer.sprite = spriteStunned;
        }
        stunTimer = 0;

        stunCount++;
        if (stunCount > stunMax)
        {
            Destroy(gameObject);
            GlobalBehavior.score++;
        }
    }
 internal void changeState(stateType statetype)
 {
     pastState = currentState;
     currentState.ExitState();
     if (validStates.ContainsKey(statetype))
     {
         currentState = validStates[statetype];
     }
     else
     {
         Debug.LogError("don't have this state assigned");
     }
     if (pastState.stateType != statetype || statetype == stateType.attack)
     {
         currentState.EnterState();
     }
 }
Exemple #11
0
    /// <summary>
    /// The Initializer for the <seealso cref="StateNode"/> when it is being loaded from an XML
    /// </summary>
    /// <param name="typeNumber"></param>
    /// <param name="posx"></param>
    /// <param name="posy"></param>
    public void InitStateNodeFromXML(ClickableElement parent, stateType type, float posx, float posy, string id, string name, ClickableElement subElem = null)
    {
        InitBaseNode(parent, id);

        if (subElem != null)
        {
            this.subElem = subElem;
            nodeName     = this.subElem.elementName;
            windowRect   = new Rect(posx, posy, ClickableElement.width, ClickableElement.height);
        }
        else
        {
            nodeName   = parent.elementNamer.AddName(id, name);
            windowRect = new Rect(posx, posy, width, height);
        }

        this.type = type;
    }
Exemple #12
0
        public virtual HttpResponseMessage Post([FromUri] string serviceName, [FromUri] Guid id, [FromUri] string phaseName, [FromBody] stateType item, [MatrixParameter] string[] zone = null, [MatrixParameter] string[] context = null)
        {
            string sessionToken = CheckAuthorisation(serviceName, zone, context, new Right(RightType.UPDATE, RightValue.APPROVED));

            preventPagingHeaders();

            HttpResponseMessage result;

            try
            {
                IFunctionalService service = getService(serviceName);
                if (SettingsManager.ProviderSettings.JobBinding &&
                    !service.IsBound(id, getOwnerId(sessionToken)))
                {
                    throw new InvalidSessionException("Request failed as the job referred to in this request does not belong to this consumer.");
                }
                stateType state = service.CreateToState(id, phaseName, item, zone: (zone == null ? null : zone[0]), context: (context == null ? null : context[0]));

                string uri = Url.Link("ServiceStatesRoute", new { controller = serviceName, id = id, phaseName = phaseName, stateId = state.id });
                result = Request.CreateResponse <stateType>(HttpStatusCode.Created, state);
                result.Headers.Location = new Uri(uri);
            }
            catch (ArgumentException e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid argument: id=" + id + ", phaseName=" + phaseName + ".\n" + e.Message));
            }
            catch (CreateException e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Problem creating state data for " + phaseName + "@" + id + ".\n", e));
            }
            catch (RejectedException e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Problem creating state data for " + phaseName + "@" + id + ".\n", e));
            }
            catch (Exception e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Request failed for creating state for phase " + phaseName + " in job " + id + ".\n " + e.Message));
            }

            return(result);
        }
Exemple #13
0
    //method for making the ennemy knock backword
    public void knockBack(Vector3 force, float weight, float dmg, bool isBeam)
    {
        if (state == stateType.stunned)
        {
            weight = weight / 2;
        }

        if (inState == inStateType.none)
        {
            force *= weight;
            this.GetComponent <Rigidbody>().AddForce(force);
            health -= dmg;
        }
        if (!isBeam)
        {
            invTimer = 0;
        }

        //if health drops to 0 baddie dies
        if (health <= 0)
        {
            state = stateType.dead;
        }
    }
 public MakeCakeSM(NavMeshAgent ag, FiniStateMachine st, KitchenHelper hp, STATUS _status, stateType stateTYPE, Animator an) : base(ag, st, hp, _status, stateTYPE, an)
 {
     helper.onReciveMaterial += OnReciveMaterial;
     pettingrange             = status.pettingrange;
 }
Exemple #15
0
 public AttackSM(NavMeshAgent ag, FiniStateMachine st, KitchenHelper hp, STATUS _status, stateType stateTYPE, Animator an) : base(ag, st, hp, _status, stateTYPE, an)
 {
     attackingTime = status.getCurrentweapon.attackdelay;
     attacktimer   = attackingTime;
 }
 public IdleSM(NavMeshAgent ag, FiniStateMachine st, KitchenHelper hp, STATUS _status, stateType stateTYPE, Animator an) : base(ag, st, hp, _status, stateTYPE, an)
 {
 }
 public DefenceSM(NavMeshAgent ag, FiniStateMachine st, KitchenHelper hp, STATUS _status, stateType stateTYPE, Animator an) : base(ag, st, hp, _status, stateTYPE, an)
 {
     chasingDistance = status.getCurrentweapon.chasingdistance;
     attackingTime   = status.getCurrentweapon.attackdelay;
     attackRange     = status.getCurrentweapon.attackrange;
     attacktimer     = attackingTime;
 }
Exemple #18
0
 public void stunned(float sT)
 {
     sTimeStop = sT;
     state     = stateType.stunned;
 }