/// <summary>
        /// return to guard position state
        /// </summary>
        private void _return_state()
        {
            m_CurrentDest = m_StartPosition;

            m_Direction2target   = m_CurrentDest - transform.position;
            m_Distance2target    = m_Direction2target.magnitude;
            m_Direction2target.y = 0.0f;
            m_Direction2target.Normalize();

            _calc_ranges();

            m_Character.setMoveMode(TPCharacter.MovingMode.RotateToDirection);


            _calculate_path(ref m_Move);

            m_Move.y      = 0.0f;
            m_Move       *= m_Stats.DefaultMoveSpeed;
            m_BodyLookDir = m_Move;
            if (takingHit)
            {
                m_Move        = Vector3.zero;
                m_BodyLookDir = Vector3.zero;
            }
            m_Character.move(m_Move, false, false, false, m_BodyLookDir, Vector3.zero);

            if (m_InAttackRange)
            {
                m_NpcState = NPCState.Idle;
                m_Character.setMoveMode(TPCharacter.MovingMode.RotateToDirection);
                m_Move = Vector3.zero;
                m_Character.fullStop();
                m_OnStartPosition = true;
            }
        }
Beispiel #2
0
 private void CheckIfCanCraft()
 {
     foreach (var recipe in npcClass.craftingRecipes)
     {
         bool canCraftThis = true;
         foreach (var item in recipe.inputs)
         {
             if (!inventory.Contains(item))
             {
                 canCraftThis = false;
                 break;
             }
             else
             {
                 if (inventory.ItemQty(item.name) < item.qty)
                 {
                     canCraftThis = false;
                     break;
                 }
             }
         }
         if (canCraftThis)
         {
             state = new CraftingState(recipe);
         }
     }
 }
Beispiel #3
0
 // Token: 0x06000B98 RID: 2968 RVA: 0x0010CDB8 File Offset: 0x0010AFB8
 public NPC(Vector2 inipos, byte npcKindID, NPCState npcState, MapTileNPC npcControl)
 {
     this.NPCControl                 = npcControl;
     this.NPCGameObject              = new GameObject("npc");
     this.NPCTransform               = this.NPCGameObject.transform;
     this.NPCSpriteRenderer          = this.NPCGameObject.AddComponent <SpriteRenderer>();
     this.NPCSpriteRenderer.material = npcControl.NPCMaterial[(int)npcKindID];
     this.NPCTransform.localScale    = Vector3.one * npcControl.npcscale;
     this.NPCTransform.SetParent(npcControl.NPCLayout, false);
     this.NPCKindID    = npcKindID;
     this.NPCAnimation = npcControl.NPCSprite[(int)npcKindID];
     this.CurNPCState  = ((npcState < NPCState.NPC_Hit) ? npcState : NPCState.NPC_Attack);
     this.IdelNPCState = NPCState.NPC_Idle;
     this.HitFrame     = npcControl.HitFrame[(int)npcKindID];
     this.NPCDir       = (sbyte)UnityEngine.Random.Range(0, 2);
     if ((int)this.NPCDir == 0)
     {
         this.NPCDir = -1;
         this.NPCTransform.localRotation = Quaternion.Euler(0f, 180f, 0f);
     }
     else
     {
         this.NPCTransform.localRotation = Quaternion.Euler(0f, 0f, 0f);
     }
     this.NPCSheetID     = (byte)UnityEngine.Random.Range(0, this.NPCAnimation[(int)this.CurNPCState].Length);
     this.AnimationSpeed = 15f;
     this.AnimationTimer = 1f;
     this.posxoffset     = (this.posyoffset = (this.HurtTimer = (this.HitTimer = (this.DieTimer = 0f))));
     this.damage         = new List <Damage>(3);
     this.fighters       = new List <LineNode>(16);
     this.hurt           = new List <float>(16);
     this.updateNPC(inipos);
     this.SetActive(false);
 }
Beispiel #4
0
    public void FindPath(Vector2Int target)
    {
        Vector3    currentPos = grid.WorldToCell(gameObject.transform.position);
        Vector2Int source     = new Vector2Int((int)currentPos.x, (int)currentPos.y);

        pathFinder.SetObstacles(currentMap.PathFindingGrid);
        pathFinder.Initialise(new Vector2Int(currentMap.MapWidth, currentMap.MapHeight), source, target);
        if (pathFinder.StartFindPath(10))
        {
            currentPath = pathFinder.GetFoundPath();
            if (currentPath.Count > 0)
            {
                destination = currentPath[0];
                state       = NPCState.FollowingPath;
                SetAnimation();
            }
            else
            {
                state = NPCState.Idle;
            }
        }
        else
        {
            state = NPCState.FindingPath;
        }
    }
Beispiel #5
0
    public void RecalculatePath(GameObject objectToAvoid)
    {
        StopMoving();
        if (currentPath.Count > 0)
        {
            Vector3    currentPos = grid.WorldToCell(gameObject.transform.position);
            Vector2Int source     = new Vector2Int((int)currentPos.x, (int)currentPos.y);
            Vector2Int dest       = new Vector2Int((int)(currentPath[currentPath.Count - 1].x - 0.5f), (int)(currentPath[currentPath.Count - 1].y - 0.5f));
            currentPath.Clear();

            pathFinder.SetObstacles(currentMap.PathFindingGrid);
            pathFinder.SetObstacles(objectToAvoid);

            pathFinder.Initialise(new Vector2Int(currentMap.MapWidth, currentMap.MapHeight), source, dest);
            if (pathFinder.StartFindPath(10))
            {
                currentPath = pathFinder.GetFoundPath();
                if (currentPath.Count > 0)
                {
                    destination = currentPath[0];
                    state       = NPCState.FollowingPath;
                    SetAnimation();
                }
                else
                {
                    state = NPCState.Idle;
                }
            }
            else
            {
                state = NPCState.FindingPath;
            }
        }
    }
    public void AddState(NPCState newState)
    {
        if (newState == null)
        {
            Debug.LogError("StateManager AddState(): Null state");
        }

        if (states.Count == 0)
        {
            states.Add(newState);
            currentState = newState;
            currentStateID = newState.ID;
            return;
        }

        foreach (NPCState state in states)
        {
            if (state.ID == newState.ID)
            {
                Debug.LogError("StateManager AddState(): " + newState.ID.ToString() + " already exists");
                return;
            }
        }
        states.Add(newState);
    }
Beispiel #7
0
    protected virtual void FindNearestPatrolPoint()
    {
        float nearest      = 0;
        int   nearestPoint = 0;

        for (int i = 0; i < patrolArray.Length; i++)
        {
            float distanceToPoint = Vector3.Distance(patrolArray[i].position, transform.position);
            if (nearest > distanceToPoint || nearest == 0)
            {
                nearest      = distanceToPoint;
                nearestPoint = i;
            }
        }

        if (nearest > 0)
        {
            npcState    = NPCState.Patrol;
            patrolIndex = nearestPoint;
        }
        else
        {
            npcState = NPCState.Idle;
        }
    }
    //과일채집 명령 수행
    public void Fruit_Gathering()
    {
        //과일개수가 최대저장 개수보다 많은경우 자유이동으로 변경
        if (CaveStorage.Instance.storedFruitObjs.Count >= variable.MAX_Fruit)
        {
            StandardMode();
        }

        //과일 채집시간에 맞춰 과일 개수가 증가함
        else
        {
            if (Instruction_time >= variable.Fruit_Picking_Time)
            {
                fruittree         = target.GetComponent <FruitTree> ();
                npcitem.have_Item = fruittree.GetFruit();
                npcitem.have_Item.transform.position      = Vector3.zero;
                npcitem.have_Item.transform.parent        = this.transform;
                npcitem.have_Item.transform.localPosition = new Vector3(0, -0.04f, 0.04f);
                npcitem.have_Item.transform.localScale    = new Vector3(1, 1, 1) * 0.2f;

                Instruction_time  = 0;
                agent.destination = Cave.transform.position;
                npcstate          = NPCState.CAVE_MOVEMENT_STATUS;
            }

            else
            {
                Instruction_time += Time.deltaTime;
            }
        }
    }
Beispiel #9
0
    void GetAction()
    {
        if (Input.GetKeyDown(KeyCode.R))
        {
            SelectedState = NPCState.Gather;
        }
        else
        if (Input.GetKeyDown(KeyCode.A))
        {
            SelectedState = NPCState.Attack;
        }
        else
        if (Input.GetKeyDown(KeyCode.B))
        {
            SelectedState = NPCState.Rest;
        }
        else
        {
            return;
        }

        if (currentNPC)
        {
            currentNPC.State = SelectedState;
        }
    }
Beispiel #10
0
        // Awake is called when the script instance is being loaded
        protected override void Awake()
        {
            npcState = NPCState.WaitingForPlayer;
            //combatState = CombatState.None;

            eyePosition = new Vector2();
        }
    //돌채집 명령 수행
    public void Stone_Gathering()
    {
        //돌개수가 최대 돌 소유 개수보다 많은경우 자유이동으로 변경
        if (CaveStorage.Instance.storedStoneObjs.Count >= variable.MAX_Stone)
        {
            StandardMode();
        }

        //돌 채집시간에 맞춰 돌 개수가 증가하며 반복작업하지 않고 자유이동으로 변경된다
        else
        {
            if (Instruction_time >= variable.Stone_Picking_Time)
            {
                mine = target.GetComponent <Mine> ();
                npcitem.have_Item = mine.GetStone();
                npcitem.have_Item.transform.position      = Vector3.zero;
                npcitem.have_Item.transform.parent        = this.transform;
                npcitem.have_Item.transform.localPosition = new Vector3(0, -0.04f, 0.04f);
                npcitem.have_Item.transform.localScale    = new Vector3(1, 1, 1) * 0.2f;

                Instruction_time  = 0;
                agent.destination = Cave.transform.position;
                npcstate          = NPCState.CAVE_MOVEMENT_STATUS;
            }
            else
            {
                Instruction_time += Time.deltaTime;
            }
        }
    }
Beispiel #12
0
 public virtual void Enter(Movement owner, NPCState prevState, float newDuration) // if you're "resuming" a previous state
 {
     myOwner       = owner;
     anim          = myOwner.anim;
     previousState = prevState;
     duration      = newDuration;
 }
 //초기화로 되돌림
 public void StandardMode()
 {
     npcstate     = NPCState.FREEMOVE;
     commandstate = CommandState.NONE;
     nextidx      = Random.Range(0, wayPoint.Count);
     ReemoveList();
 }
Beispiel #14
0
    // If the user becomes close enough to either NPC, their trigger is set.
    void FixedUpdate()
    {
        if (markPlay)
        {
            var distance = Vector3.Distance(player.transform.position, markNPC.transform.position);
            curAnimator.SetFloat("Distance", distance);

            if (distance < ACTIVATION_DISTANCE)
            {
                Debug.Log("PLAYING ~~~MARK~~~ after " + reactionTimer.ElapsedMilliseconds / 1000.0 + " seconds");

                markPlay = false;

                NPCState curNPCState = NPCStates[NPCIndex];
                curNPCState.Audio.PlayDelayed(curNPCState.AudioDelay);
                NPCIndex++;

                PlayPrompt();
                stateIndex++;
            }
        }

        if (johnPlay)
        {
            var distance = Vector3.Distance(player.transform.position, johnNPC.transform.position);
            curAnimator.SetFloat("Distance", distance);

            if (distance < ACTIVATION_DISTANCE)
            {
                prompt.GetComponentInChildren <Text>().text = promptState.GetPrompt();
                prompt.transform.Find("Continue").gameObject.SetActive(true);
                johnPlay = false;
            }
        }
    }
Beispiel #15
0
 void CheckOtherCivs()
 {
     foreach (GameObject child in civilianList)
     {
         if (child.gameObject != this.gameObject)
         {
             if (child.gameObject.GetComponent <NPCcivController>().GetNPCState() == NPCState.Evacuating)
             {
                 if ((child.transform.position - this.transform.position).magnitude < detectionRange)                            //within range
                 {
                     if (Vector3.Angle(this.transform.forward, child.transform.position - this.transform.position) <= (120 / 2)) // AI can see AI
                     {
                         RaycastHit hit;
                         if (Physics.Linecast(this.transform.position, child.transform.position, out hit))
                         {
                             if (hit.transform.gameObject == child.gameObject)
                             {
                                 NPCStateCurrent = NPCState.Alerted;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #16
0
 // Start is called before the first frame update
 void Start()
 {
     PP.profile.TryGetSettings(out vignette);
     m_Anim         = GetComponent <Animator>();
     z_NPCState     = NPCState.IDLE;
     z_navMeshAgent = GetComponent <NavMeshAgent>();
 }
Beispiel #17
0
    public void MoveToNPC()
    {
        Vector3 tmpDist = (m_target.position - transform.position);

        if (tmpDist.magnitude < 2)
        {
            if (npcState == NPCState.eRun)
            {
                timeCount = 0;
                npcState  = NPCState.eAttack;
                npcAnimalMsg.ChangeEventId((ushort)NPCMonsterEvent.eAnimalAttack);
                SendMsg(npcAnimalMsg);
            }
        }
        else
        {
            if (npcState == NPCState.eAttack)
            {
                timeCount = 0;
                npcState  = NPCState.eRun;
                npcAnimalMsg.ChangeEventId((ushort)NPCMonsterEvent.eAnimalRun);
                SendMsg(npcAnimalMsg);
            }
        }
        Debug.DrawLine(transform.position, m_target.position, Color.cyan);
        Vector3 tmpLoc = tmpDist - tmpDist.normalized * deltaDist;

        agent.destination = tmpLoc + transform.position;
        Debug.DrawLine(transform.position, agent.destination, Color.red);
        transform.LookAt(m_target.position);
    }
    //명령을 이행하러 이동하는 상태
    public void IndicationPos()
    {
        //명령을 지정하는 순간 선택 리스트에서 제거
        ReemoveList();

        //명령이 사냥이면 바로 상태 넘김
        if (commandstate == CommandState.HIT_SMALL_ANIMALL)
        {
            npcstate = NPCState.COMMAND_EXCUTION;
        }

        //아니면 그위치로 이동
        else
        {
            if (agent.velocity.sqrMagnitude <= 0.1f * 0.1f && agent.remainingDistance <= Target_Distance)
            {
                npcstate = NPCState.COMMAND_EXCUTION;
                PauseMove();
            }
            else
            {
                agent.destination = target.transform.position;
                LookToward(target.transform.position);
                ResumeMove();
            }
        }
    }
 public override void Enter(Movement owner, NPCState prevState)
 {
     base.Enter(owner, prevState);
     anim.Play("Attack");
     myOwner.attack(myOwner.attackTarget.position);
     Debug.Log(myOwner.transform.name + " attacks!");
 }
Beispiel #20
0
 void onDialogueEnd()
 {
     if (state == NPCState.DEBATING)
     {
         state = NPCState.ENTERED;
     }
 }
Beispiel #21
0
        private void UpdateFlying()
        {
            if (currDist < 5f)
            {
                currState       = NPCState.Pollinating;
                pollinateTimer  = Time.time;
                lastPatrolTimer = Time.time;
            }
            else if (Time.time - lastPatrolTimer > 30f)
            {
                // taking too long to get to the flower, probably stuck
                ChooseNextFlower();
                lastPatrolTimer = Time.time;
            }

            // fly to target
            Vector3 toTarget = (currFlowerPos - transform.position);

            Vector3 move        = toTarget.normalized * (flySpeed * Time.deltaTime);
            float   hoverOffset = hoverDist * Mathf.Sin(hoverSpeed * Time.time);

            move.y = hoverOffset;
            ctrl.Move(move);

            Vector3 ctrlVel = ctrl.velocity;

            ctrlVel.y = transform.forward.y;
            FaceDirection(ctrlVel);
        }
Beispiel #22
0
        private static void checkNPCs(GameLocation loc)
        {
            foreach (NPC npc in loc.characters)
            {
                if (npc.name == "Junimo" || npc.name == "Green Slime" || npc.name == "Frost Helly" || npc.IsMonster || npc is Child)
                {
                    continue;
                }
                if (npc.isMarried() && npc.name != Game1.player.spouse)
                {
                    continue;
                }

                NPCState state = new NPCState(npc);
                if (!npcs.ContainsKey(npc.name))
                {
                    npcs.Add(npc.name, state);
                    continue;
                }

                NPCState oldState = npcs[npc.name];
                if (state.isDifferentEnoughFromOldStateToSend(oldState))
                {
                    npcs[npc.name] = state;
                    if (!ignoreUpdates)
                    {
                        Multiplayer.sendFunc(new NPCUpdatePacket(npc));
                    }
                }
            }
        }
Beispiel #23
0
 IEnumerator FollowToTarget()
 {
     while (state == NPCState.Follow)
     {
         if (Vector3.Distance(_transform.position, target.transform.position) > 2)
         {
             if (Vector3.Distance(_transform.position, followee.position) > 2)
             {
                 direction = followee.position - _transform.position;
                 characterMover.Move(direction.normalized);
                 yield return(null);
             }
             else
             {
                 characterMover.Move(Vector3.zero);
                 yield return(null);
             }
         }
         else
         {
             characterMover.Move(Vector3.zero);
             if (Vector3.Distance(_transform.position, target.transform.position) > 0.5f)
             {
                 transform.DOMove(target.transform.position, 0.5f);
                 yield return(new WaitForSeconds(0.5f));
             }
             else
             {
                 state = NPCState.Follow;
                 yield return(null);
             }
         }
     }
 }
Beispiel #24
0
        //main thinking process
        private void Think()
        {
            if (IsDead || !GameManager.Instance.IsGameLoadedAndStarted)
            {
                return;
            }
            CheckIfAlarm();
            if (CurrentAttidude == Attidude.Flee)
            {
                CurrentState = NPCState.Flee;
            }
            _mover.Think();
            if (CurrentState == NPCState.Attack && _attacker != null && !_attacker.IsAttacking)
            {
                //lets see if we are close enough to attack, otherwise, we must get closer
                if (_attacker.IsAttackDistance())
                {
                    StartAttack();
                }
                else
                {
                    StartChargeRun(); //we must get closer to player
                }
            }

            _sceneNPC.GoGround();
        }
Beispiel #25
0
 // Update is called once per frame
 void Update()
 {
     switch (state) {
         case NPCState.READY:
             nextPoint ();
             nav.SetDestination (points [currentPoint].position);
             state = NPCState.WALKING;
             //anim.enabled = true;
             anim.Play();
             break;
         case NPCState.WALKING:
             if (nav.remainingDistance == 0) {
                 state = NPCState.WAITING;
                 //anim.enabled = false;
                 anim.Stop();
      					waitingTime = 0;
             }
             break;
         case NPCState.WAITING:
             if (waitingTime > 0) {
                 state = NPCState.READY;
             }
             waitingTime++;
             break;
     }
 }
Beispiel #26
0
 public bool ImHit()
 {
     if (!IsDead && !_firstUpdate)
     {
         if (CurrentState != NPCState.Flee)
         {
             ChangeAttidude(Attidude.AlwaysHostile);
         }
         if (_attacker == null)
         {
             CurrentState = NPCState.Flee;
         }
         else
         {
             _attacker.StopAttack();
             //     CurrentState = (_attacker.IsDistanceAttacker || _attacker.IsMeleeAttacker) ? NPCState.Attack : NPCState.Flee;
             //   _attacker.TryToStopCurrentAttack();
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #27
0
    void CheckPlayer()
    {
        if (z_NPCState == NPCState.PATROL && z_PlayerNear == true)
        {
            z_NPCState = NPCState.CHASE;
            AnimationFloat();
            return;
        }
        if (z_NPCState == NPCState.CHASE && z_PlayerNear == false)
        {
            z_NPCState = NPCState.PATROL;
            AnimationFloat();
        }
        if (health <= 0)
        {
            z_NPCState = NPCState.DIE;
            AnimationFloat();
        }

        /* if(dance == true)
         * {
         *   z_NPCState = NPCState.DANCE;
         *   AnimationFloat();
         * }*/
    }
Beispiel #28
0
 override public void Initialize(int maxHP, float maxSpeed)
 {
     base.Initialize(maxHP, maxSpeed);
     m_state = NPCState.Wandering;
     ResetWanderTarget();
     GameplayManager.Instance.AddNPC(this);
 }
Beispiel #29
0
    private int useTime;                                // Variable integer that holds the usage time of the machine

    // Start is called before the first frame update
    void Start()
    {
        // Testing purposes
        // StartCoroutine(CurrentState());

        // Enter state
        state = NPCState.Standby;
    }
Beispiel #30
0
 public virtual void OnNPCAtStockpile(BlockJobInstance blockJobInstance, ref NPCState state)
 {
     ((ConstructionJobInstance)blockJobInstance).OnNPCAtConstructionStockpile();
     state.Inventory.Dump(blockJobInstance.Owner.Stockpile);
     state.SetCooldown(0.3);
     state.JobIsDone = true;
     blockJobInstance.ShouldTakeItems = false;
 }
Beispiel #31
0
    IEnumerator WaitBeforeSwitch()
    {
        int wait_time = Random.Range(0, 4);

        yield return(new WaitForSeconds(wait_time));

        npcState = NPCState.Walk;
    }
Beispiel #32
0
        //start melee attack or shooting
        public void StartAttack()
        {
//            if (_attacker.IsBlocked || IsDead)
//              return;
            CurrentState = NPCState.Attack;
            _mover.StopWalking();
            _attacker.StartAttack();
        }
Beispiel #33
0
 // Use this for initialization
 void Start()
 {
     points = route.GetComponentsInChildren<Transform> ();
     Debug.Log (points.Length);
     currentPoint = 0;
     nav = GetComponent<NavMeshAgent> ();
     anim = GetComponent<Animation> ();
     state = NPCState.READY;
 }
 public bool CheckForState(NPCState inList)
 {
     foreach (NPCState state in states)
     {
         if (state == inList)
         {
             return true;
         }
     }
     return false;
 }
Beispiel #35
0
    public void Update()
    {
        if (this.currentState == null) return;

        NPCState transitionState = currentState.Update();

        if (currentState != transitionState)
        {
            transitionState.Entry();
            currentState = transitionState;
        }
    }
Beispiel #36
0
 //changes the current point of interest if its weight equals zero
 public void ChangePointOfInterest()
 {
     PointofInterest p = FindHighestWeight();
     if (p != null && p.CurrentWeight == 0)
     {
         followPlayer = true;
         Goal = GameObject.FindGameObjectWithTag("Player").transform;
         NpcState = NPCState.Follow;
     }
     else
     {
         Goal = FindHighestWeight().transform;
     }
 }
Beispiel #37
0
        public void Move(GSPlay play, Direction moveDir)
        {
            if (npcState != NPCState.Idle) return;
            direction = moveDir;

            //check for collision

            if (moveDir == Direction.North && !play.CheckCollide(gridX, gridY - 1)) gridY--;
            if (moveDir == Direction.South && !play.CheckCollide(gridX, gridY + 1)) gridY++;
            if (moveDir == Direction.East && !play.CheckCollide(gridX + 1, gridY)) gridX++;
            if (moveDir == Direction.West && !play.CheckCollide(gridX - 1, gridY)) gridX--;

            npcState = NPCState.Walk;
            UpdateTarget(); // <- do this
        }
Beispiel #38
0
 //finds the PoI with the highest weight, sets its transform as the goal, then changes it if the weight = 0
 public void PointOfInterestCheck()
 {
     PointofInterest pointToVisit = FindHighestWeight();
     if (pointToVisit == null)
     {
         followPlayer = true;
         NpcState = NPCState.Follow;
         Goal = player.transform;
     }
     else
     {
         NpcState = NPCState.Wander;
         Goal = pointToVisit.transform;
         pointToVisit.isVisiting = true;
         if (pointToVisit.CurrentWeight == 0)
         {
             ChangePointOfInterest();
         }
     }
 }
Beispiel #39
0
	void Update () 
	{

		state = npcProperties.currentNPCState;

		
		if (path == null) 
		{
			Debug.Log("path = null");
			return;
		}
		if (currentWaypoint >= path.Count) 
		{
			Debug.Log ("Path zuende");
			DetermineNextAction();
			return;
		}
		Debug.Log ("MoveToNext Start");
		MoveToNextWayPoint();
		Debug.Log ("MoveToNext Finish");
		
		return;
	}
Beispiel #40
0
		public static NPC Create(int npcKid, int eventKid, NPCState state = NPCState.Normal)
		{
			ResourceManager resManager = ResourceManager.Instance;
			
			NPC npc = null;
			if (!resManager.ContainsObjectKey(ObjectKey.NPC))
			{
				for (int i = 0; i < PRE_CACHE_COUNT; ++i)
				{
					npc = new NPC();
					resManager.AddObject(ObjectKey.NPC, npc);
				}
			}
			npc = new NPC();
			npc.Uid = Guid.NewGuid().ToString();
			npc.Data = NPCDataManager.Instance.GetData(npcKid) as NPCData;
			npc.EventData = NPCDataManager.Instance.GetEventDataByID(eventKid);
			npc.Script = ResourceManager.Instance.LoadAsset<NPCScript>(ObjectType.GameObject, npc.Data.GetResPath());
            npc.Script.Uid = npc.Uid;
            npc.Script.transform.parent = RootTransform.Instance.NPCRoot;
			npc.Script.CallbackClick = npc.OnNPCClick;
			npc.State = state;
			return npc;
		}
Beispiel #41
0
	public void InsertStateAsPreviousStateInStack(NPCState insertedState)
	{
		NPCState currentState = this.stateStack.Pop();
		this.stateStack.Push(insertedState);
		this.stateStack.Push (currentState);
	}
Beispiel #42
0
	public void PushStateOnStack(NPCState state)
	{
		this.stateStack.Push(state);
	}
Beispiel #43
0
 public void ChangeCurrentState(NPCState newState)
 {
     this.currentState = newState;
 }
Beispiel #44
0
        //update movement based upon location
        public void UpdateNpcPathing()
        {
            //throw coin to decide what side it takes? learn pathing through pacman?
            //this walks the sprite downt the left wall, across the map and up the right wall towards
            //the top right corner
            mSpeed = Vector2.Zero;
            mDirection = Vector2.Zero;
               //keep update clear. do working here
            if (npcRectangle.X == 0 && npcRectangle.Y != 400)//means left side
            {
                //then move down
                mSpeed.Y = NPC_SPEED;
                mDirection.Y = MOVE_DOWN;
                npcState = NPCState.Walking;

            }

            if (npcRectangle.Y == 400)
            {
                if (npcRectangle.X >= 0 && npcRectangle.X != 709)
                {
                //you've gone down far enough. send it across the screen.
                //walk to 700, 400
                mSpeed.X = NPC_SPEED;
                mDirection.X = MOVE_RIGHT;
                npcState = NPCState.Inspecting;
                }
            }

            if (npcRectangle.X == 709)
            {
                //go up. you're 709 across. move to final postion.
                //Veritical = Y axes. Horizontal = X axis.
                if (npcRectangle.Y >= 0 && npcRectangle.Y <= 700)
                {
                    mSpeed.Y = NPC_SPEED;
                    mDirection.Y = MOVE_UP;
                    npcState = NPCState.Walking;
                }

            }
        }
Beispiel #45
0
 public void randomizeBehavior()
 {
     state = (NPCState)Random.Range(0, 2);
     print(state);
     myAnim.SetInteger("AnimState", (int)state);
 }
Beispiel #46
0
 public void Start()
 {
     // Initiallize state
     State = state;
 }
Beispiel #47
0
 protected override void Awake()
 {
     base.Awake();
     m_state = NPCState.None;
 }
Beispiel #48
0
        public virtual void Update(GameTime gameTime)
        {
            if (npcState == NPCState.Walk)
            {
                if (position.X < target.X) position.X += 8;
                if (position.X > target.X) position.X -= 8;
                if (position.Y < target.Y) position.Y += 8;
                if (position.Y > target.Y) position.Y -= 8;

                if (position == target) npcState = NPCState.Idle;
            }
            UpdateAnim(gameTime);
        }
Beispiel #49
0
	public void ResetStackToDefaultState(NPCState defaultState) 
	{
		this.stateStack.Clear();
		this.stateStack.Push(defaultState);
	}
    public void PerformTransition(Transition transition)
    {
        if (transition == Transition.NullTransition)
        {
            Debug.LogError("StateManager PerformTransition(): NullTransition not allowed");
            return;
        }

        StateID id = currentState.GetOutputState(transition);
        if (id == StateID.NullStateID)
        {
            Debug.LogError("StateManager PerformTransition(): " + currentStateID.ToString() +
                           " does not have a next state for transition " + transition.ToString());
            return;
        }

        currentStateID = id;
        foreach (NPCState state in states)
        {
            if (state.ID == currentStateID)
            {
                currentState.OnStateExit();

                currentState = state;

                currentState.OnStateEntered();
                break;
            }
        }
    }
Beispiel #51
0
 //Instantiate Variables
 void Start()
 {
     agent = GetComponent<NavMeshAgent>();
     NpcState = NPCState.Follow;
     player = GameObject.Find("Player");
     followPlayer = true;
 }
Beispiel #52
0
 public override void OnHitFinished()
 {
     base.OnHitFinished();
     Color c = m_renderer.color;
     c.a = 1.0f;
     m_renderer.color = c;
     m_state = NPCState.Wandering;
 }
Beispiel #53
0
 public override void Initialize(int maxHP, float maxSpeed)
 {
     base.Initialize(maxHP, maxSpeed);
     m_state = NPCState.Wandering;
     ResetWanderTarget();
     GameplayManager.Instance.AddNPC(this);
 }
Beispiel #54
0
 protected override void SetDying()
 {
     m_state = NPCState.Dying;
 }
Beispiel #55
0
    protected override bool HitReaction(Entity attacker)
    {
        m_state = NPCState.Hit;

        attacker.HitLanded();
        Color c = m_renderer.color;
        c.a = 0.5f;
        m_renderer.color = c;
        return true;
    }
Beispiel #56
0
	public NPCState ResetStackToDefaultState(NPCState defaultState) 
	{
		this.stateMachine.ResetStackToDefaultState(defaultState);

		return this.stateMachine.PeekAtTopStateInStack();
	}
Beispiel #57
0
	public void InsertStateAsPreviousStateInStack(NPCState insertedState)
	{
		this.stateMachine.InsertStateAsPreviousStateInStack(insertedState);
	}