Exemplo n.º 1
0
        public override void execute(FSMContext fsmc, object o)
        {
            Actor actor = (Actor) o;
            Vector3 direction = actor.TargetPosition - actor.Position;

            //Debug.Log("Moving to: " + actor.TargetPosition);
            Debug.DrawLine(actor.Position, actor.TargetPosition);

            // Quick Rotation
            //actor.controller.transform.LookAt(actor.TargetPosition);

            // Slow Rotation
            if (Quaternion.Angle(actor.Rotation, actor.TargetRotation) > 5.0f){
                actor.Rotation = Quaternion.Slerp(actor.Rotation, actor.TargetRotation, Time.deltaTime *
                    (actor.TurnSpeed));
            }

            Debug.DrawRay(actor.Position, actor.controller.transform.forward);

            if (direction.magnitude > 0.2f){
                actor.controller.Move(new Vector3((direction.normalized * (actor.MoveSpeed * 0.01f)).x, 0,
                    (direction.normalized * (actor.MoveSpeed * 0.01f)).z));
            }

            if (actor.Animation){
                if (actor.Animation["Walk"]){
                    actor.Animation.CrossFade("Walk");
                }
            }
        }
Exemplo n.º 2
0
        public override void execute(FSMContext fsmc, object o)
        {
            Actor actor = (Actor) o;

            if (actor.Animation)
                actor.Animation.Stop();
        }
		public override void execute(FSMContext c, object o){
			A_Fighter fighter;
			fighter = (A_Fighter)o;
			
			fighter.gobj.animation[ fighter.animationNameMap[FighterAnimation.BLOCK] ].wrapMode = UnityEngine.WrapMode.ClampForever;
			fighter.gobj.animation.CrossFade(fighter.animationNameMap[FighterAnimation.BLOCK], 0.03f);
			
			
			// Get knocked back when you are hit
			/*
			if(fighter.gotHit)
			{
				Debug.Log("slide back");
				fighter.gob.transform.Translate(fighter.localForwardVector*-1*fighter.slide* Time.deltaTime);
			}
			*/
			
			if (fighter.currentAction == ActionCommand.NONE){
				c.dispatch("idle", o);
			}
			
			/*
			if(fighter.controllerDirection == "forward" || fighter.controllerDirection == "back")
			{
				fighter.Dispatch("walk");
			}*/
		}
Exemplo n.º 4
0
		public override void execute(FSMContext c, object o){
			//UnityEngine.Debug.Log("in hit state");
			A_Fighter fighter;
			fighter = (A_Fighter)o;				
			GameObject gobj = fighter.gobj;
			
			FighterAnimation animation = FighterAnimation.FLINCH_UP;
			
			if (fighter.hurtLocation == Location.HIGH){
				animation = FighterAnimation.FLINCH_UP;
			}
			else if (fighter.hurtLocation == Location.LOW){
				animation = FighterAnimation.FLINCH_DOWN;
			}

			if(fighter.globalActionTimer > 
				(gobj.animation[fighter.animationNameMap[animation]].length / gobj.animation[fighter.animationNameMap[animation]].speed))
			{
				c.dispatch("idle", o);
			}
			
			fighter.globalActionTimer += UnityEngine.Time.deltaTime;
			
			gobj.animation.Play(fighter.animationNameMap[animation]);
				
		}
Exemplo n.º 5
0
 public override void execute(FSMContext fsmc, object o)
 {
     Actor actor = (Actor) o;
     actor.ActionTimer = 0.0f;
     Debug.Log("jumping");
     //actor.controller.transform.LookAt(actor.TargetPosition);
 }
		public override void execute(FSMContext c, object o)
		{
			A_Fighter 	fighter = (A_Fighter)o;
			A_Attack 	attack 	= fighter.currentAttack;
			
			attack.Execute();
			attack.SpecialExecute();
			
<<<<<<< HEAD
			fighter.currentAttack.SpecialExecute(time);
			if(fighter.takeDamage)
			{
				fighter.Dispatch("takeDamage");			
			}
			
			if(time >= fighter.currentAttack.attackLength)
			{
				//Debug.Log ("attackinginginginging");
				time=0f;
				fighter.currentAttack = new Attack_None(fighter,0,0,0);
				fighter.Dispatch("idle");
			}	
			time+=Time.deltaTime;
=======
			if( attack.CheckComplete() ) { c.dispatch("idle", o); }
			fighter.gobj.animation.CrossFade(attack.AnimationName);
>>>>>>> fd2511965e41334cb3fce993bcedcd531205f267
		}
		public override void execute(FSMContext c, object o){
			A_Fighter fighter;
			fighter = (A_Fighter)o;
			
			fighter.gobj.animation[ fighter.animationNameMap[FighterAnimation.DEATH] ].wrapMode = UnityEngine.WrapMode.ClampForever;
			fighter.gobj.animation.CrossFade(fighter.animationNameMap[FighterAnimation.DEATH]);
		}
Exemplo n.º 8
0
 public override void execute(FSMContext fsmc, object o)
 {
     Actor actor = (Actor) o;
     actor.ActionTimer = 0.0f;
     actor.HasAttacked = false;
     if (actor.Animation)
         actor.Animation.Stop();
 }
		public override void execute(FSMContext c, object o){
			A_Fighter fighter = (A_Fighter)o;				
			GameObject gobj = fighter.gobj;
			
			fighter.globalActionTimer = 0.0f;
			
			gobj.animation.Stop();
		}
Exemplo n.º 10
0
		public override void execute(FSMContext c, object o){
			A_Fighter fighter;
			fighter = (A_Fighter)o;
			GameObject gobj = fighter.gobj;
			
			//fighter.hurtLocation = Location.NONE;
			fighter.globalActionTimer = 0.0f;
		}
		public override void execute(FSMContext c, object o){
			A_Fighter fighter;
			fighter = (A_Fighter)o;
			GameObject gobj = fighter.gobj;
			
			//fighter.isKnockDown = false;
			fighter.globalActionTimer = 0.0f;
		}
Exemplo n.º 12
0
		public override void execute(FSMContext c, object o){
			A_Fighter fighter = (A_Fighter)o;				
			GameObject gobj = fighter.gobj;
			float moveSpeed = fighter.moveSpeed;
			
<<<<<<< HEAD
			A_Fighter fighter;
			fighter = (A_Fighter)o;				
			GameObject gobj = fighter.GetGOB();
			
			//Debug.Log ("fighter "+fighter.playerNumber+" "+"localforwardvector "+fighter.localForwardVector);
			
			
			if(fighter.controllerDirection == "forward" )
			{
				if(!GameManager.CheckCollideAnotherPlayer())
				{
					gobj.transform.Translate(fighter.localForwardVector*fighter.movespeed*Time.deltaTime);	
				}
			}
			else if(fighter.controllerDirection == "back")
			{		
				if(!GameManager.CheckCollideEdge(fighter,fighter.playerNumber))
				gobj.transform.Translate(fighter.localForwardVector*-1*fighter.movespeed*Time.deltaTime);	
			}		
			
			if(fighter.takeDamage)
=======
			if(fighter.currentMovement == MoveCommand.FORWARD || fighter.currentMovement == MoveCommand.FORWARD_UP)
>>>>>>> fd2511965e41334cb3fce993bcedcd531205f267
			{
				if ( GameManager.CheckCanMoveForward(fighter) ){
					gobj.transform.Translate(fighter.localForwardVector * moveSpeed * Time.deltaTime);
				}
				gobj.animation.CrossFade(fighter.animationNameMap[FighterAnimation.WALK_FORWARD]);
			}
			else if(fighter.currentMovement == MoveCommand.BACK || fighter.currentMovement == MoveCommand.BACK_UP)
			{
				if ( GameManager.CheckCanMoveBackward(fighter) ){
					gobj.transform.Translate(fighter.localForwardVector * -1 * moveSpeed * Time.deltaTime);
				}
				gobj.animation.CrossFade(fighter.animationNameMap[FighterAnimation.WALK_BACKWARD]);
			}
			
			
			if( fighter.currentMovement == MoveCommand.NONE)
			{
				c.dispatch("idle", o);
			}
<<<<<<< HEAD
			 
			else if( fighter.controllerDirection != "forward" || fighter.controllerDirection != "back"  )
			{
				fighter.Dispatch("idle");
			}
=======
>>>>>>> fd2511965e41334cb3fce993bcedcd531205f267
		}
Exemplo n.º 13
0
 //dispatch - triggers a state transition
 public void dispatch(FSMContext fsmc, string eventName)
 {
     if (transitionList.ContainsKey(eventName))
     {
         fsmc.CurrentState.exitAction.execute(fsmc);
         transitionList[eventName].execute(fsmc);
         fsmc.CurrentState.entryAction.execute(fsmc);
     }
 }
Exemplo n.º 14
0
        public override void execute(FSMContext fsmc, object o)
        {
            Actor actor = (Actor) o;

            if (actor.Animation){
                if (actor.Animation["Idle"]){
                    actor.Animation.CrossFade("Idle");
                }
            }
        }
Exemplo n.º 15
0
        public override void execute(FSMContext fsmc, object o)
        {
            Actor actor = (Actor) o;
            actor.ActionTimer = 0.0f;
            Debug.Log("hurt");

            GameObject attackSparks = (GameObject)Resources.LoadAssetAtPath("Assets/Prefabs/Particles/AttackSparks.prefab", typeof(GameObject));
            GameObject newParticles = (GameObject)GameObject.Instantiate(attackSparks, actor.Position + new Vector3(0.0f, 2.0f, 0.0f), Quaternion.identity);
            GameObject.Destroy(newParticles, 1.0f);
        }
Exemplo n.º 16
0
        //dispatch - triggers a state transition
        public void dispatch(FSMContext fsmc, string eventName, object o)
        {
            if (transitionList.ContainsKey(eventName))
            {
				fsmc.CurrentState.exitAction.execute(fsmc, o);
                transitionList[eventName].execute(fsmc, o);
				fsmc.CurrentState.entryAction.execute(fsmc, o);
            }
			else
				Debug.Log("Cannot Transition to "+eventName+". "+name+"'s transitions does not contain "+eventName);
        }
Exemplo n.º 17
0
        public override void execute(FSMContext fsmc, object o)
        {
            Actor actor = (Actor) o;
            actor.ActionTimer = 0.0f;
            Debug.Log("attacking");

            if (actor.Animation){
                if (actor.Animation["Attack"]){
                    actor.Animation["Attack"].speed = 1.0f;
                }
            }
        }
		//float animationTime =0f;	
		public override void execute(FSMContext c, Object o){
			/*
			UnityEngine.Debug.Log("unique attack");
			
			animationTime+= UnityEngine.Time.deltaTime;
			if( animationTime > 2.0f)
			{
				//GameManager.P1.Fighter.Dispatch("idle");
				//animationTime =0f;
			}
			*/
		}
		public override void execute(FSMContext c, object o)
		{
			A_Fighter fighter = (A_Fighter)o;			

			if (fighter.currentAction != ActionCommand.NONE){
				fighter.currentAttack = fighter.actionsCommandMap[fighter.currentAction];
			}
			
			fighter.currentAttack.Init();
			fighter.gobj.animation[fighter.currentAttack.AnimationName].speed = fighter.currentAttack.speed;
			fighter.gobj.animation.Stop();
		}
Exemplo n.º 20
0
        public override void execute(FSMContext fsmc, object o)
        {
            Actor actor = (Actor) o;
            float animationLength = 3.0f;

            if (actor.Animation){
                if (actor.Animation["Attack"]){
                    animationLength = actor.Animation["Attack"].clip.length * (1.0f/actor.AttackSpeed);
                    actor.Animation["Attack"].speed = actor.AttackSpeed;
                    actor.Animation.CrossFade("Attack");
                }
            }

            // Quick Rotation
            actor.controller.transform.LookAt(actor.TargetPosition);
            Debug.DrawLine(actor.Position, actor.TargetPosition);

            // Check to see if the enemy has attacked yet
            if (!actor.HasAttacked && (actor.ActionTimer > actor.AttackTime)){
                if (actor.IsRanged){
                    if (actor.Projectile != null){
                        GameObject attackProjectile = actor.Projectile;
                        GameObject newProjectile = (GameObject)GameObject.Instantiate(attackProjectile, actor.Hitbox.transform.position, Quaternion.identity);

                        // Enemy Shoots Forward
                        //newProjectile.GetComponent<ProjectileScript>().Direction = (actor.TargetPosition - actor.Position).normalized;

                        // Enemy Shoots Toward Player
                        // START
                        newProjectile.transform.LookAt(actor.TargetPlayer.transform.position + new Vector3(0.0f, actor.controller.height/2.0f, 0.0f));
                        newProjectile.GetComponent<ProjectileScript>().Direction = newProjectile.transform.forward;
                        // END

                        newProjectile.GetComponent<ProjectileScript>().Damage = actor.Damage;
                        newProjectile.GetComponent<ProjectileScript>().Speed = actor.ProjectileSpeed;
                        newProjectile.GetComponent<ProjectileScript>().Source = (Enemy)actor;
                        GameObject.Destroy(newProjectile, actor.ProjectileDuration);
                    }
                    actor.HasAttacked = true;
                }
                else{
                    actor.Hitbox.collider.enabled = true;
                    actor.HasAttacked = true;
                }
            }

            if (actor.ActionTimer > (animationLength)){
                actor.Hitbox.collider.enabled = false;
                actor.Hitbox.renderer.enabled = false;
                fsmc.dispatch("idle", o);
            }
            actor.ActionTimer += Time.deltaTime;
        }
Exemplo n.º 21
0
Arquivo: State.cs Projeto: sseng/fsm
 public void dispatch(FSMContext fsmc, string eventName, GameObject o)
 {
     if (transitions.ContainsKey(eventName))
     {
         Debug.Log("changing the state by  " + eventName + " in " + name);
         Transition t = (transitions[eventName] as Transition);
         fsmc.CurrentState.exitAction.execute(fsmc, o);
         t.execute(fsmc, o);
         fsmc.CurrentState = t.Target;
         fsmc.CurrentState.entryAction.execute(fsmc, o);
         Debug.LogWarning(" the current state is " + fsmc.CurrentState.name);
     }
 }
Exemplo n.º 22
0
        public override void execute(FSMContext fsmc, object o)
        {
            Actor actor = (Actor) o;
            float animationLength = 3.0f;

            if (actor.Animation){
                if (actor.Animation["Hurt"]){
                    animationLength = actor.Animation["Hurt"].clip.length;
                    actor.Animation.CrossFade("Hurt");
                }
            }

            if (actor.ActionTimer > animationLength){
                fsmc.dispatch("idle", o);
            }
            actor.ActionTimer += Time.deltaTime;
        }
Exemplo n.º 23
0
        public override void execute(FSMContext fsmc, object o)
        {
            Actor actor = (Actor) o;
            float animationLength = 3.0f;
            float jumpPower = actor.JumpPower;

            if (actor.Animation){
                if (actor.Animation["Jump"]){
                    animationLength = actor.Animation["Jump"].clip.length;
                    actor.Animation.CrossFade("Jump");
                }
            }

            // Quick Rotation
            actor.controller.transform.LookAt(actor.TargetPosition);
            Debug.DrawLine(actor.Position, actor.TargetPosition);

            Vector3 direction = actor.TargetPosition - actor.Position;

            // Slow Rotation
            if (Quaternion.Angle(actor.Rotation, actor.TargetRotation) > 5.0f){
                actor.Rotation = Quaternion.Slerp(actor.Rotation, actor.TargetRotation, Time.deltaTime *
                    (actor.TurnSpeed));
            }

            Debug.DrawRay(actor.Position, actor.controller.transform.forward);
            /*
            if (direction.magnitude > 0.2f){
                actor.controller.Move(new Vector3((direction.normalized * (actor.MoveSpeed * 0.01f)).x, 0,
                    (direction.normalized * (actor.MoveSpeed * 0.01f)).z));
            }

            if (actor.Animation){
                if (actor.Animation["Attack"]){
                    actor.Animation.CrossFade("Attack");
                }
            }
            */
            if (actor.ActionTimer > animationLength){
                fsmc.dispatch("idle", o);
            }
            actor.ActionTimer += Time.deltaTime;
        }
Exemplo n.º 24
0
		public override void execute(FSMContext c, Object o){
			/*
			A_Fighter fighter;
			fighter = (A_Fighter)o;
			
			
			
			if(fighter.controllerDirection == "forward" )
			{
				string animationName = fighter.GetAnimationName(fighter,"walk_forward");
				fighter.GetGOB().animation.CrossFade(animationName);
			}
			else if(fighter.controllerDirection == "back")
			{
				string animationName = fighter.GetAnimationName(fighter,"walk_backward");
				fighter.GetGOB().animation.CrossFade(animationName);
			}
			*/
		}
		public override void execute(FSMContext c, object o){
			//UnityEngine.Debug.Log("in hit state");
			A_Fighter fighter;
			fighter = (A_Fighter)o;				
			GameObject gobj = fighter.gobj;
			
			FighterAnimation animation = FighterAnimation.KNOCKDOWN;

			if(fighter.globalActionTimer > 
				(gobj.animation[fighter.animationNameMap[animation]].length / gobj.animation[fighter.animationNameMap[animation]].speed))
			{
				//fighter.isKnockDown = false;
				c.dispatch("idle", o);
			}
			
			fighter.globalActionTimer += UnityEngine.Time.deltaTime;
			gobj.animation.Play(fighter.animationNameMap[animation]);
				
		}
Exemplo n.º 26
0
		public override void execute(FSMContext c, object o){
			A_Fighter fighter = (A_Fighter)o;
			GameObject gobj = fighter.gobj;
			
			gobj.animation.Stop();
			fighter.movement = Vector3.zero;
			/*
			if (fighter.currentAttack.animationName != "char_amaterasu_Fury"){
				if (fighter.extraDamage != 1){
					fighter.extraDamage = 1.0f;
					fighter.extraDamageTimer = 0.0f;
					Debug.Log(fighter.extraDamage);
				}
			}
			*/
			
			fighter.currentAttack.Reset();
			fighter.currentAttack = null;
		}
Exemplo n.º 27
0
        public override void execute(FSMContext fsmc, object o)
        {
            Actor actor = (Actor) o;
            actor.ActionTimer = 0.0f;

            GameObject deathParts = (GameObject)GameObject.Instantiate(actor.DeathParts, actor.Position, Quaternion.identity);
            GameObject.Destroy(deathParts, actor.FadeTime);

            Vector3 offset = new Vector3(0.0f, 2.0f, 0.0f);

            if (actor.SocketedDrop != null){
                GameObject socketedDrop = (GameObject)GameObject.Instantiate(actor.SocketedDrop, actor.Position + offset, Quaternion.identity);
            }

            if (actor.OnDeathLoadLevel){
                GameObject.Find("Fader").GetComponent<fadeToBlackScript>().SetLoadLevel(actor.LevelToLoad);
                GameObject.Find("Fader").GetComponent<fadeToBlackScript>().FadeOut();
            }

            Debug.Log("death");
            GameObject.Destroy(actor.gameObject);
        }
Exemplo n.º 28
0
        public override void execute(FSMContext fsmc, object o)
        {
            Vehicle v = (Vehicle) o;
            Vector3 target = v.steering.GetTarget();

            if ((v.Position() - v.waypoint1).magnitude < .01){
                v.steering.SetTarget(v.waypoint2);
            }
            else if ((v.Position() - v.waypoint2).magnitude < .01){
                v.steering.SetTarget(v.waypoint3);
            }
            else if ((v.Position() - v.waypoint3).magnitude < .01){
                v.steering.SetTarget(v.waypoint1);
            }

            if ((Vector3.Magnitude(v.Position() - target) < 5) && (!v.steering.ArriveIsOn())){
                v.steering.SeekOff();
                v.steering.ArriveOn();
            }

             			if (Vector3.Magnitude(v.Position() - target) < .1){
                v.steering.ArriveOff();
            }
        }
Exemplo n.º 29
0
 public override void execute(FSMContext fsmc, object o)
 {
     Vehicle v = (Vehicle) o;
     v.steering.AllOff();
     v.steering.PatrolOn();
 }
Exemplo n.º 30
0
 public void execute(FSMContext c)
 {
     action.execute(c);
     c.CurrentState = target;
 }
Exemplo n.º 31
0
		public override void execute(FSMContext c, object o){
		}
Exemplo n.º 32
0
		public override void execute(FSMContext c, object o){
			A_Fighter fighter = (A_Fighter)o;
			fighter.gobj.animation.CrossFade(fighter.animationNameMap[FighterAnimation.IDLE]);
		}
Exemplo n.º 33
0
 public void update(FSMContext fsmc)
 {
     updateAction.execute(fsmc);
 }
Exemplo n.º 34
0
 public abstract void execute(FSMContext c);