Exemplo n.º 1
0
        public void Render(IMob mob)
        {
            if (!(mob is IPlayer))
            {
                throw new NullReferenceException("ConnectState can only be used with a player object implementing IPlayer");
            }

            //Store a reference for the GetCommand() method to use.
            this.connectedPlayer = mob as IPlayer;
            var server = mob.Game as IServer;
            var game = mob.Game as IGame;

            // It is not guaranteed that mob.Game will implement IServer. We are only guaranteed that it will implement IGame.
            if (server == null)
            {
                throw new NullReferenceException("LoginState can only be set to a player object that is part of a server.");
            }

            //Output the game information
            mob.Send(new InformationalMessage(game.Name));
            mob.Send(new InformationalMessage(game.Description));
            mob.Send(new InformationalMessage(string.Empty)); //blank line

            //Output the server MOTD information
            mob.Send(new InformationalMessage(string.Join("\n", server.MessageOfTheDay)));
            mob.Send(new InformationalMessage(string.Empty)); //blank line

            this.connectedPlayer.StateManager.SwitchState<LoginState>();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PlatformerPro.DamageInfo"/> class.
 /// </summary>
 /// <param name="amount">Amount.</param>
 /// <param name="damageType">Damage type.</param>
 /// <param name="direction">Direction.</param>
 public DamageInfo(int amount, DamageType damageType, Vector2 direction, IMob damageCauser)
 {
     Amount = amount;
     DamageType = damageType;
     Direction = direction;
     DamageCauser = damageCauser;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="mob">The mob.</param>
 /// <param name="input">The input.</param>
 public void Execute(IMob mob, string input)
 {
     if (mob == null)
         return; // Can happen when the user connection is closed in the middle of a command or state executing
     else
         mob.Send(new InformationalMessage("Invalid command used!"));
 }
 /// <summary>
 /// Unity start hook.
 /// </summary>
 void Start()
 {
     // This is not elegant but its a simple and effective way to handle interfaces in Unity
     animatable = (IMob)gameObject.GetComponentInParent (typeof(IMob));
     if (animatable == null) Debug.LogError ("UnitySpriteDirectionFacer can't find the animatable reference");
     cachedScale = transform.localScale;
     cachedOffset = transform.localPosition;
     // if (gameObject.GetComponent<SpriteRenderer>() == null) Debug.LogError("The UnitySpriteDirectionFacer should be placed on the same game object as the SpriteRenderer");
 }
 /// <summary>UnitySpriteDepthHandler
 /// Unity start hook.
 /// </summary>
 void Start()
 {
     // This is not elegant but its a simple and effective way to handle interfaces in Unity
     animatable = (IMob)gameObject.GetComponentInParent (typeof(IMob));
     if (animatable == null) Debug.LogError ("Depth Handler facer can't find the animatable reference");
     spriteRenderer = gameObject.GetComponent<SpriteRenderer> ();
     if (spriteRenderer == null) Debug.LogError("The UnitySpriteDepthHandler should be placed on the same game object as the SpriteRenderer");
     offset = spriteRenderer.sortingOrder - (animatable.ZLayer * multipler);
 }
 public void Execute(IMob mob, string input)
 {
     if (!this.IsIncomplete)
     {
         mob.Send(new InformationalMessage(string.Format("You entered {0}. More info is required.", input)));
         this.CommandInput = input;
         this.IsIncomplete = true;
         mob.StateManager.SwitchState<ReceivingInputState>();
     }
     else
     {
         this.IsIncomplete = false;
         mob.Send(new InformationalMessage(string.Format("Your {0} data is associated with {1}", this.CommandInput, input)));
         mob.StateManager.SwitchState<TestState>();
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Init this instance, used for projectiles or hit boxes which are not children of a character.
 /// </summary>
 public virtual void Init(DamageInfo info, IMob character, Projectile projectile,  bool destroyOnEnemyHit, bool destroyOnSceneryHit)
 {
     this.character = character;
     if (character == null)
     {
         Debug.LogError ("A ProjectileHitBox (CharacterHitBox) must have a character");
     }
     myCollider = GetComponent<Collider2D>();
     if (myCollider == null)
     {
         Debug.LogError("A ProjectileHitBox (CharacterHitBox) must be on the same GameObject as a Collider2D");
     }
     myCollider.enabled = true;
     this.damageInfo = info;
     this.projectile = projectile;
     this.destroyOnSceneryHit = destroyOnSceneryHit;
     this.destroyOnEnemyHit = destroyOnEnemyHit;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Renders the current state to the players terminal.
        /// </summary>
        /// <param name="mob"></param>
        /// <exception cref="System.NullReferenceException">
        /// ConnectState can only be used with a player object implementing IPlayer
        /// or
        /// LoginState can only be set to a player object that is part of a server.
        /// </exception>
        public void Render(IMob mob)
        {
            if (!(mob is IPlayer))
            {
                throw new NullReferenceException("ConnectState can only be used with a player object implementing IPlayer");
            }

            //Store a reference for the GetCommand() method to use.
            this.connectedPlayer = mob as IPlayer;
            var server = mob.Game as IServer;

            // Register to receive new input from the user.
            mob.ReceivedMessage += connectedPlayer_ReceivedMessage;

            if (server == null)
            {
                throw new NullReferenceException("LoginState can only be set to a player object that is part of a server.");
            }

            if (this.currentState == CurrentState.None)
            {
                this.currentState = CurrentState.FetchUserName;
            }

            switch (this.currentState)
            {
                case CurrentState.FetchUserName:
                    this.connectedPlayer.Send(new InputMessage("Please enter your user name"));
                    break;
                case CurrentState.FetchPassword:
                    this.connectedPlayer.Send(new InputMessage("Please enter your password"));
                    break;
                case CurrentState.InvalidUser:
                    this.connectedPlayer.Send(new InformationalMessage("Invalid username/password specified."));
                    this.currentState = CurrentState.FetchUserName;
                    this.connectedPlayer.Send(new InputMessage("Please enter your user name"));
                    break;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Raises the activated event.
        /// </summary>
        /// <param name="character">Character causing activation, can be null.</param>
        virtual protected void OnPlatformActivated(IMob character)
        {
            if (PlatformActivated != null)
            {
                if (character is Character)
                {
                    characterEventArgs.Update((Character)character);
                }
                else
                {
                    characterEventArgs.Update(null);
                }
                PlatformActivated(this, characterEventArgs);
            }

            // If we have a persistable object attached set the state.
            PersistableObject po = GetComponent <PersistableObject> ();

            if (po != null)
            {
                po.SetState(true);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RoomOccupancyChangedEventArgs" /> class.
        /// </summary>
        /// <param name="occupant">The occupant responsible for the change.</param>
        /// <param name="travelDirection">The direction of travel the occupant is going.</param>
        /// <param name="departureRoom">The room the occupant is departing from.</param>
        /// <param name="arrivalRoom">The room the occupant is arriving in.</param>
        /// <exception cref="System.ArgumentNullException">
        /// A valid Occupant must be provided.
        /// or
        /// A valid travelDirection must be provided.
        /// or
        /// A valid departureRoom must be provided.
        /// or
        /// A valid arrivalRoom must be provided.
        /// </exception>
        public RoomOccupancyChangedEventArgs(IMob occupant, ITravelDirection travelDirection, IRoom departureRoom, IRoom arrivalRoom)
        {
            if (occupant == null)
            {
                throw new ArgumentNullException(nameof(occupant), "A valid Occupant must be provided.");
            }
            else if (travelDirection == null)
            {
                throw new ArgumentNullException(nameof(travelDirection), "A valid travelDirection must be provided.");
            }
            else if (departureRoom == null)
            {
                throw new ArgumentNullException(nameof(departureRoom), "A valid departureRoom must be provided.");
            }
            else if (arrivalRoom == null)
            {
                throw new ArgumentNullException(nameof(arrivalRoom), "A valid arrivalRoom must be provided.");
            }

            this.Occupant        = occupant;
            this.DepartureRoom   = departureRoom;
            this.ArrivalRoom     = arrivalRoom;
            this.TravelDirection = travelDirection;
        }
Exemplo n.º 11
0
    private IEnumerator AcyncDamage()
    {
        permission = false;
        Debug.Log(furnitures.Count);
        if (furnitures.Count > 0)
        {
            foreach (var furniture in furnitures)
            {
                Vector3    vectorFurniture    = furniture.transform.position;
                Vector3    thisVector         = transform.position;
                var        forward            = vectorFurniture - thisVector;
                float      distance           = Vector2.Distance(vectorFurniture, thisVector);
                IFurniture furnitureComponent = furniture.GetComponent <IFurniture>();
                furnitureComponent.Jerk(forward.normalized, powerGarbageFurniture - (distance * weakeningGarbageFurniture));
            }
        }

        if (mobs.Count > 0)
        {
            foreach (var mob in mobs)
            {
                Vector3 vectorFurniture = mob.transform.position;
                Vector3 thisVector      = transform.position;
                var     forward         = vectorFurniture - thisVector;
                float   distance        = Vector2.Distance(vectorFurniture, thisVector);
                IMob    mobComponent    = mob.GetComponent <IMob>();
                mobComponent.SetFreeze(1.5f);
                mobComponent.NoCollision(1.5f);
                mobComponent.SetDamage(damage);
                mobComponent.Jerk(forward.normalized, powerGarbage - (distance * weakeningGarbage));
            }
        }
        yield return(new WaitForSeconds(0f));

        readyDestroy = true;
    }
Exemplo n.º 12
0
 /// <summary>
 /// Called when [leave].
 /// </summary>
 /// <param name="occupant">The occupant.</param>
 /// <param name="arrivalEnvironment">The arrival environment.</param>
 /// <param name="direction">The direction.</param>
 public void OnLeave(IMob occupant, IEnvironment arrivalEnvironment, AvailableTravelDirections direction)
 {
 }
 /// <summary>
 /// Called when the character is unparented from this platform.
 /// </summary>
 override public void UnParent(IMob character)
 {
     base.UnParent(character);
     StopAllCoroutines();
 }
Exemplo n.º 14
0
 public void Execute(IMob mob, string input)
 {
     mob.StateManager.SwitchState <TestState>();
 }
Exemplo n.º 15
0
 public void Execute(IMob mob, string input)
 {
     mob.StateManager.SwitchState<TestState>();
 }
Exemplo n.º 16
0
 public void Render(IMob mob)
 {
     mob.Send(new InformationalMessage("Message from TestState."));
 }
Exemplo n.º 17
0
 public void Render(IMob mob)
 {
     mob.Send(new InformationalMessage("Message from TestState."));
 }
Exemplo n.º 18
0
 public override void Attack(IMob target)
 {
     //Stub
 }
Exemplo n.º 19
0
 /// <summary>
 /// Called when [deal damage].
 /// </summary>
 /// <param name="targets">The targets.</param>
 /// <param name="amount">The amount.</param>
 private void OnDealDamage(IMob[] targets, int amount)
 {
 }
 /// <summary>
 /// Callback for when move is done.
 /// </summary>
 public virtual void MoveComplete(IMob target, Vector3 finalPosition)
 {
     enemy.MovementComplete ();
     tweenStarted = false;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Unity start hook.
 /// </summary>
 void Start()
 {
     // Get character reference
     myCharacter = gameObject.GetComponentInParent<Character>();
     if (myCharacter == null) Debug.LogError ("Legacy Animation Bridge unable to find Character or Enemy reference");
     myCharacter.ChangeAnimationState += AnimationStateChanged;
     myAnimator = GetComponentInChildren<Animation>();
     if (myAnimator == null) Debug.LogError ("Legacy Animation Bridge unable to find Unity Animation reference");
     queuedStates = new Queue<AnimationState> ();
     queuedPriorities = new Queue<int> ();
     state = AnimationState.NONE;
     priority = -1;
     animationLookup = new Dictionary<AnimationState, LegacyAnimation>();
     foreach (LegacyAnimation a in animationData)
     {
         // Populate dictionary
         animationLookup.Add (a.state, a);
         // And add all clips
         myAnimator.AddClip(a.clip, a.state.AsString());
         // Set wrap mode
         a.clip.wrapMode = a.wrapMode;
     }
 }
        /// <summary>
        /// Initialise this animation bridge.
        /// </summary>
        protected void Init()
        {
            // Get character reference
            myCharacter = (IMob) gameObject.GetComponent(typeof(IMob));
            if (myCharacter == null) myCharacter = (IMob) gameObject.GetComponentInParent(typeof(IMob));
            if (myCharacter == null) Debug.LogError ("Mecanim Animation Bridge (2D) unable to find Character or Enemy reference");
            myCharacter.ChangeAnimationState += AnimationStateChanged;
            myAnimator = GetComponentInChildren<Animator>();
            defaultController = myAnimator.runtimeAnimatorController;
            if (myAnimator == null) Debug.LogError ("Platform Animator unable to find Unity Animator reference");

            animationStateOverrideLookup = new Dictionary<string, AnimatorOverrideController> ();
            foreach (AnimatorControllerMapping mapping in mappings)
            {
                animationStateOverrideLookup.Add (mapping.overrrideState, mapping.controller);
            }

            queuedStates = new Queue<string> ();
            queuedPriorities = new Queue<int> ();
            state = AnimationState.NONE.AsString();
            priority = -1;

            TimeManager.Instance.GamePaused += HandleGamePaused;
            TimeManager.Instance.GameUnPaused += HandleGameUnPaused;

            #if UNITY_EDITOR
            #if UNITY_5
            // In editor mode build a list of handled states for error messaging and the like
            if (myAnimator.runtimeAnimatorController is UnityEditor.Animations.AnimatorController)
            {
                editor_stateNames = new List<string>();
                UnityEditor.Animations.AnimatorStateMachine stateMachine = ((UnityEditor.Animations.AnimatorController)defaultController).layers[0].stateMachine;
                for (int i = 0; i < stateMachine.states.Length; i++)
                {
                    editor_stateNames.Add (stateMachine.states[i].state.name);
                }
            }
            #else

            // In editor mode build a list of handled states for error messaging and the like
            if (myAnimator.runtimeAnimatorController is UnityEditorInternal.AnimatorController)
            {
                editor_stateNames = new List<string>();
                UnityEditorInternal.StateMachine stateMachine = ((UnityEditorInternal.AnimatorController)defaultController).GetLayer(0).stateMachine;
                for (int i = 0; i < stateMachine.stateCount; i++)
                {
                    editor_stateNames.Add (stateMachine.GetState(i).name);
                }

            }
            #endif
            #endif
        }
Exemplo n.º 23
0
 public void Render(IMob mob)
 {
     return;
 }
Exemplo n.º 24
0
 /// <summary>
 /// Executes the specified mob.
 /// </summary>
 /// <param name="mob">The mob.</param>
 /// <param name="input">The input.</param>
 public void Execute(IMob mob, string input)
 {
     return; // No operation performed.
 }
Exemplo n.º 25
0
 /// <summary>
 /// Handles a cahracter being loaded.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="e">E.</param>
 void CharacterLoaded(object sender, CharacterEventArgs e)
 {
     target = e.Character;
 }
Exemplo n.º 26
0
 /// <summary>
 /// Broadcasts the specified message to the user.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="message">The message.</param>
 public virtual void BroadcastToPlayer(IMob sender, IMessage message)
 {
     Console.WriteLine(message.FormatMessage());
 }
Exemplo n.º 27
0
 /// <summary>
 /// Called when [attack].
 /// </summary>
 /// <param name="target">The target.</param>
 /// <exception cref="System.NotImplementedException"></exception>
 public void OnAttack(IMob[] target)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 28
0
 public override void Attack(IMob target)
 {
     //Stub
 }
Exemplo n.º 29
0
 /// <summary>
 /// Attacks the specified target.
 /// </summary>
 /// <param name="target">The target.</param>
 public abstract void Attack(IMob target);
Exemplo n.º 30
0
 public override void Attack(IMob[] targets)
 {
     foreach (IMob mob in targets)
         Attack(mob);
 }
        /// <summary>
        /// Initialise this animation bridge.
        /// </summary>
        protected void Init()
        {
            // Get character reference
            myCharacter = (IMob) gameObject.GetComponent(typeof(IMob));
            if (myCharacter == null) myCharacter = (IMob) gameObject.GetComponentInParent(typeof(IMob));
            if (myCharacter == null) Debug.LogError ("2DTK Animation Bridge (with transitions) unable to find Character or Enemy reference");
            myCharacter.ChangeAnimationState += AnimationStateChanged;
            myAnimator = GetComponentInChildren<tk2dSpriteAnimator>();
            if (myAnimator == null) Debug.LogError ("2DTK Animation Bridge (with transitions) unable to find Sprite Animator reference");

            queuedStates = new Queue<string> ();
            queuedPriorities = new Queue<int> ();
            state = AnimationState.NONE.AsString();
            priority = -1;

            TimeManager.Instance.GamePaused += HandleGamePaused;
            TimeManager.Instance.GameUnPaused += HandleGameUnPaused;
        }
Exemplo n.º 32
0
 /// <summary>
 /// Called when the character hits an enemy.
 /// </summary>
 /// <param name="enemy">Enemy that was hit.</param>
 /// <param name="info">Damage info.</param>
 virtual public void HitEnemy(IMob enemy, DamageInfo info)
 {
     // We don't do anything here, but other attacks might
 }
Exemplo n.º 33
0
 /// <summary>
 /// Called when [attack target].
 /// </summary>
 /// <param name="target">The target.</param>
 private void OnAttackTarget(IMob target)
 {
 }
Exemplo n.º 34
0
 /// <summary>
 /// Call to start the projectile moving.
 /// </summary>
 /// <param name="damageAmount">Damage amount.</param>
 /// <param name="damageType">Damage type.</param>
 virtual public void Fire(int damageAmount, DamageType damageType, Vector2 direction, IMob character)
 {
     fired      = true;
     damageInfo = new DamageInfo(damageAmount, damageType, Vector2.zero, character);
     if (projectileHitBox != null)
     {
         projectileHitBox.Init(damageInfo, character, this, destroyOnEnemyHit, destroyOnSceneryHit);
     }
     this.direction = direction;
     this.direction.Normalize();
     actualSpeed = speed;
     if (rotate)
     {
         transform.rotation = Quaternion.FromToRotation(Vector2.right, direction);
     }
     if (autoExplodeDelay > 0)
     {
         remainingLifetime = autoExplodeDelay;
     }
 }
 /// <summary>
 /// Called when the character is parented to this platform.
 /// </summary>
 override public void Parent(IMob character)
 {
     base.Parent(character);
     StartCoroutine(DamageCharacter(character));
 }
Exemplo n.º 36
0
 /// <summary>
 /// Called when [attack target].
 /// </summary>
 /// <param name="target">The target.</param>
 private void OnAttackTarget(IMob target)
 {
 }
Exemplo n.º 37
0
 /// <summary>
 /// Called when [enter].
 /// </summary>
 /// <param name="occupant">The occupant.</param>
 /// <param name="departureEnvironment">The departure environment.</param>
 /// <param name="direction">The direction.</param>
 public virtual void OnEnter(IMob occupant, IEnvironment departureEnvironment, AvailableTravelDirections direction)
 {
 }
Exemplo n.º 38
0
 private void RuleForCactusMob(IMob mob)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="InvalidMobException" /> class.
 /// </summary>
 /// <param name="mob">The character.</param>
 /// <param name="message">The message.</param>
 public InvalidMobException(IMob mob, string message) : base(message)
 {
     this.Mob = mob;
 }
		/// <summary>
		/// Init this instance.
		/// </summary>
		virtual protected void Init()
		{
			// Get character reference
			myCharacter = (IMob) gameObject.GetComponent(typeof(IMob));
			if (myCharacter == null) myCharacter = (IMob) gameObject.GetComponentInParent(typeof(IMob));
			if (myCharacter == null) Debug.LogError ("Mecanim Animation Bridge (3D) unable to find Character or Enemy reference");

			if (myCharacter != null )
			{
				// Events
				myCharacter.ChangeAnimationState += AnimationStateChanged;
				if (myCharacter is Character) ((Character)myCharacter).Respawned += HandleRespawned;

				myAnimator = GetComponentInChildren<Animator>();
				if (myAnimator == null) Debug.LogError ("Platform Animator unable to find Unity Animator reference");
				defaultController = myAnimator.runtimeAnimatorController;

				// Get an aimer if one is present
				ProjectileAimer tmpAimer = ((Component)myCharacter).gameObject.GetComponent<ProjectileAimer> ();
				if (tmpAimer != null && myCharacter is Character && (tmpAimer.aimType == ProjectileAimingTypes.EIGHT_WAY || tmpAimer.aimType == ProjectileAimingTypes.SIX_WAY)) {
					aimer = tmpAimer;
				}

				// Set up animation overrides
				animationStateOverrideLookup = new Dictionary<string, AnimatorOverrideController> ();
				foreach (AnimatorControllerMapping mapping in mappings)
				{
					animationStateOverrideLookup.Add (mapping.overrrideState, mapping.controller);
				}
			}
#if UNITY_EDITOR
	#if UNITY_5
			// In editor mode build a list of handled states for error messaging and the like
			if (myAnimator.runtimeAnimatorController is UnityEditor.Animations.AnimatorController)
			{
				editor_stateNames = new List<string>();
				UnityEditor.Animations.AnimatorStateMachine stateMachine = ((UnityEditor.Animations.AnimatorController)defaultController).layers[0].stateMachine;
				for (int i = 0; i < stateMachine.states.Length; i++)
				{
					editor_stateNames.Add (stateMachine.states[i].state.name);
				}
				if (!editor_stateNames.Contains("IDLE")) Debug.LogWarning("Its recommended that you have a default state called 'IDLE' which can act as a hard reset state for actions like respawning");
			}
	#else
			
			// In editor mode build a list of handled states for error messaging and the like
			if (myAnimator.runtimeAnimatorController is UnityEditorInternal.AnimatorController)
			{
				editor_stateNames = new List<string>();
				UnityEditorInternal.StateMachine stateMachine = ((UnityEditorInternal.AnimatorController)defaultController).GetLayer(0).stateMachine;
				for (int i = 0; i < stateMachine.stateCount; i++)
				{
					editor_stateNames.Add (stateMachine.GetState(i).name);
				}
				if (!editor_stateNames.Contains("IDLE")) Debug.LogWarning("Its recommended that you have a default state called 'IDLE' which can act as a hard reset state for actions like respawning");
			}
	#endif
#endif
		}
Exemplo n.º 41
0
 /// <summary>
 /// Executes the specified mob.
 /// </summary>
 /// <param name="mob">The mob.</param>
 /// <param name="input">The input.</param>
 public void Execute(IMob mob, string input)
 {
     return; // No operation performed.
 }
Exemplo n.º 42
0
        /// <summary>
        /// Sends a message from the character, to the target group of characters
        /// </summary>
        /// <param name="message"></param>
        /// <param name="group"></param>
        public virtual void Talk(string message, IMob[] group)
        {
            if (group == null)
                return;

            foreach (IMob mob in group)
            {
                if (mob == null)
                    return;
                else
                    mob.SendMessage(message);
            }
        }
Exemplo n.º 43
0
 /// <summary>
 /// Offsets the projectile from character position.
 /// </summary>
 /// <returns>The aim offset.</returns>
 /// <param name="character">Character.</param>
 override public Vector2 GetAimOffset(IMob character)
 {
     return(GetAimDirection((Component)character).normalized *offsetDistance);
 }
 /// <summary>
 /// Called when the character is unparented from this platform.
 /// </summary>
 override public void UnParent(IMob character)
 {
     StopCoroutine(DelaySpring());
     character = null;
 }
Exemplo n.º 45
0
 /// <summary>
 /// Callback for when move is done.
 /// </summary>
 virtual public void MoveComplete(IMob target, Vector3 finalPosition)
 {
     enemy.MovementComplete();
     tweenStarted = false;
 }
Exemplo n.º 46
0
 /// <summary>
 /// Sends a message from the character, to the target character
 /// </summary>
 /// <param name="message"></param>
 /// <param name="target"></param>
 public virtual void Talk(string message, IMob target)
 {
     if (target == null)
         return;
     else
         target.SendMessage(message);
 }
Exemplo n.º 47
0
 /// <summary>
 /// Called when [deal damage].
 /// </summary>
 /// <param name="target">The target.</param>
 /// <exception cref="System.NotImplementedException"></exception>
 public void OnDealDamage(IMob[] target)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 48
0
 /// <summary>
 /// Deals damage to this item
 /// </summary>
 /// <param name="dealer">The character that is dealing the damage</param>
 /// <param name="amount">The amount of damage</param>
 public void Damage(IMob dealer, int amount)
 {
 }
Exemplo n.º 49
0
        /// <summary>
        /// Initialise this animation bridge.
        /// </summary>
        protected void Init()
        {
            // Get character reference
            myMob = (IMob)gameObject.GetComponent(typeof(IMob));
            if (myMob == null)
            {
                myMob = (IMob)gameObject.GetComponentInParent(typeof(IMob));
            }
            if (myMob == null)
            {
                Debug.LogError("Mecanim Animation Bridge (2D) unable to find Character or Enemy reference");
            }
            myMob.ChangeAnimationState += AnimationStateChanged;
            myAnimator = GetComponentInChildren <Animator>();
            if (myAnimator == null)
            {
                Debug.LogError("Platform Animator unable to find Unity Animator reference");
            }
            defaultController = myAnimator.runtimeAnimatorController;

            if (myMob is Character && (statesWithAimUpModifer.Count > 0 || statesWithAimDownModifer.Count > 0))
            {
                myCharacter = (Character)myMob;
                aimer       = myCharacter.GetComponentInChildren <ProjectileAimer>();
            }
            if ((statesWithAimUpModifer.Count > 0 || statesWithAimDownModifer.Count > 0) && aimer == null)
            {
                Debug.LogWarning("Can't use UP or DOWN modifiers as no aimer could be found");
            }

            animationStateOverrideLookup = new Dictionary <string, AnimatorOverrideController> ();
            foreach (AnimatorControllerMapping mapping in mappings)
            {
                animationStateOverrideLookup.Add(mapping.overrrideState, mapping.controller);
            }

            queuedStates     = new Queue <string> ();
            queuedPriorities = new Queue <int> ();
            state            = AnimationState.NONE.AsString();
            priority         = -1;

            TimeManager.Instance.GamePaused   += HandleGamePaused;
            TimeManager.Instance.GameUnPaused += HandleGameUnPaused;

#if UNITY_EDITOR
        #if UNITY_5
            // TODO also check for up and down states
            // In editor mode build a list of handled states for error messaging and the like
            if (myAnimator.runtimeAnimatorController is UnityEditor.Animations.AnimatorController)
            {
                editor_stateNames = new List <string>();
                UnityEditor.Animations.AnimatorStateMachine stateMachine = ((UnityEditor.Animations.AnimatorController)defaultController).layers[0].stateMachine;
                for (int i = 0; i < stateMachine.states.Length; i++)
                {
                    editor_stateNames.Add(stateMachine.states[i].state.name);
                }
            }
        #else
            // TODO also check for up and down states
            // In editor mode build a list of handled states for error messaging and the like
            if (myAnimator.runtimeAnimatorController is UnityEditorInternal.AnimatorController)
            {
                editor_stateNames = new List <string>();
                UnityEditorInternal.StateMachine stateMachine = ((UnityEditorInternal.AnimatorController)defaultController).GetLayer(0).stateMachine;
                for (int i = 0; i < stateMachine.stateCount; i++)
                {
                    editor_stateNames.Add(stateMachine.GetState(i).name);
                }
            }
        #endif
#endif
        }
Exemplo n.º 50
0
 /// <summary>
 /// Attacks the specified targets.
 /// </summary>
 /// <param name="targets">The targets.</param>
 public abstract void Attack(IMob[] targets);
 /// <summary>
 /// Call to start the projectile moving.
 /// </summary>
 /// <param name="damageAmount">Damage amount.</param>
 /// <param name="damageType">Damage type.</param>
 override public void Fire(int damageAmount, DamageType damageType, Vector2 direction, IMob character)
 {
     this.transform.parent = null;
     base.Fire(damageAmount, damageType, direction, character);
     actualSpeed = speed;
     StartCoroutine(DelayVisualComponent());
     projectileHitBox.gameObject.SetActive(true);
     if (movement == null && character is Character)
     {
         movement = ((Character)character).GetComponentInChildren <SpecialMovement_GrapplingHook> ();
     }
     if (movement == null)
     {
         Debug.LogWarning("Unable to find grappling hook movement");
     }
 }
        /// <summary>
        /// Init this instance.
        /// </summary>
        virtual protected void Init()
        {
            // Get character reference
            myCharacter = (IMob)gameObject.GetComponent(typeof(IMob));
            if (myCharacter == null)
            {
                myCharacter = (IMob)gameObject.GetComponentInParent(typeof(IMob));
            }
            if (myCharacter == null)
            {
                Debug.LogError("Mecanim Animation Bridge (3D) unable to find Character or Enemy reference");
            }

            if (myCharacter != null)
            {
                // Events
                myCharacter.ChangeAnimationState += AnimationStateChanged;
                if (myCharacter is Character)
                {
                    ((Character)myCharacter).Respawned += HandleRespawned;
                }

                myAnimator = GetComponentInChildren <Animator>();
                if (myAnimator == null)
                {
                    Debug.LogError("Platform Animator unable to find Unity Animator reference");
                }
                defaultController = myAnimator.runtimeAnimatorController;

                // Get an aimer if one is present
                ProjectileAimer tmpAimer = ((Component)myCharacter).gameObject.GetComponent <ProjectileAimer> ();
                if (tmpAimer != null && myCharacter is Character && (tmpAimer.aimType == ProjectileAimingTypes.EIGHT_WAY || tmpAimer.aimType == ProjectileAimingTypes.SIX_WAY))
                {
                    aimer = tmpAimer;
                }

                // Set up animation overrides
                animationStateOverrideLookup = new Dictionary <string, AnimatorOverrideController> ();
                foreach (AnimatorControllerMapping mapping in mappings)
                {
                    animationStateOverrideLookup.Add(mapping.overrrideState, mapping.controller);
                }
            }
#if UNITY_EDITOR
        #if UNITY_5
            // In editor mode build a list of handled states for error messaging and the like
            if (myAnimator.runtimeAnimatorController is UnityEditor.Animations.AnimatorController)
            {
                editor_stateNames = new List <string>();
                UnityEditor.Animations.AnimatorStateMachine stateMachine = ((UnityEditor.Animations.AnimatorController)defaultController).layers[0].stateMachine;
                for (int i = 0; i < stateMachine.states.Length; i++)
                {
                    editor_stateNames.Add(stateMachine.states[i].state.name);
                }
                if (!editor_stateNames.Contains("IDLE"))
                {
                    Debug.LogWarning("Its recommended that you have a default state called 'IDLE' which can act as a hard reset state for actions like respawning");
                }
            }
        #else
            // In editor mode build a list of handled states for error messaging and the like
            if (myAnimator.runtimeAnimatorController is UnityEditorInternal.AnimatorController)
            {
                editor_stateNames = new List <string>();
                UnityEditorInternal.StateMachine stateMachine = ((UnityEditorInternal.AnimatorController)defaultController).GetLayer(0).stateMachine;
                for (int i = 0; i < stateMachine.stateCount; i++)
                {
                    editor_stateNames.Add(stateMachine.GetState(i).name);
                }
                if (!editor_stateNames.Contains("IDLE"))
                {
                    Debug.LogWarning("Its recommended that you have a default state called 'IDLE' which can act as a hard reset state for actions like respawning");
                }
            }
        #endif
#endif
        }
Exemplo n.º 53
0
        /// <summary>
        /// Initialise this animation bridge.
        /// </summary>
        protected void Init()
        {
            // Get character reference
            myCharacter = (IMob)gameObject.GetComponent(typeof(IMob));
            if (myCharacter == null)
            {
                myCharacter = (IMob)gameObject.GetComponentInParent(typeof(IMob));
            }
            if (myCharacter == null)
            {
                Debug.LogError("Mecanim Animation Bridge (2D) unable to find Character or Enemy reference");
            }
            myCharacter.ChangeAnimationState += AnimationStateChanged;
            myAnimator = GetComponentInChildren <Animator>();
            if (myAnimator == null)
            {
                Debug.LogError("Platform Animator unable to find Unity Animator reference");
            }
            defaultController = myAnimator.runtimeAnimatorController;


            animationStateOverrideLookup = new Dictionary <string, AnimatorOverrideController> ();
            foreach (AnimatorControllerMapping mapping in mappings)
            {
                animationStateOverrideLookup.Add(mapping.overrrideState, mapping.controller);
            }

            queuedStates     = new Queue <AnimationState> ();
            queuedPriorities = new Queue <int> ();
            state            = AnimationState.NONE;
            priority         = -1;

            TimeManager.Instance.GamePaused   += HandleGamePaused;
            TimeManager.Instance.GameUnPaused += HandleGameUnPaused;

#if UNITY_EDITOR
        #if UNITY_5
            // In editor mode build a list of handled states for error messaging and the like
            if (myAnimator.runtimeAnimatorController is UnityEditor.Animations.AnimatorController)
            {
                editor_stateNames = new List <string>();
                UnityEditor.Animations.AnimatorStateMachine stateMachine = ((UnityEditor.Animations.AnimatorController)defaultController).layers[0].stateMachine;
                for (int i = 0; i < stateMachine.states.Length; i++)
                {
                    editor_stateNames.Add(stateMachine.states[i].state.name);
                }
            }
        #else
            // In editor mode build a list of handled states for error messaging and the like
            if (myAnimator.runtimeAnimatorController is UnityEditor.Animations.AnimatorController)
            {
                editor_stateNames = new List <string>();
                UnityEditor.Animations.AnimatorStateMachine stateMachine = ((UnityEditor.Animations.AnimatorController)defaultController).layers[0].stateMachine;
                for (int i = 0; i < stateMachine.states.Length; i++)
                {
                    editor_stateNames.Add(stateMachine.states[i].state.name);
                }
            }
        #endif
#endif
        }
Exemplo n.º 54
0
 /// <summary>
 /// Called when [enter].
 /// </summary>
 /// <param name="occupant">The occupant.</param>
 /// <param name="departureEnvironment">The departure environment.</param>
 /// <param name="direction">The direction.</param>
 public void OnEnter(IMob occupant, IEnvironment departureEnvironment, AvailableTravelDirections direction)
 {
 }
Exemplo n.º 55
0
 public void Attack(IMob m)
 {
     m.Health -= totalAt();
 }
Exemplo n.º 56
0
 /// <summary>
 /// Called when [leave].
 /// </summary>
 /// <param name="occupant">The occupant.</param>
 /// <param name="arrivalEnvironment">The arrival environment.</param>
 /// <param name="direction">The direction.</param>
 public void OnLeave(IMob occupant, IEnvironment arrivalEnvironment, AvailableTravelDirections direction)
 {
 }
Exemplo n.º 57
0
 /// <summary>
 /// Attacks the specified target.
 /// </summary>
 /// <param name="target">The target.</param>
 public abstract void Attack(IMob target);
Exemplo n.º 58
0
 /// <summary>
 /// Call to start the projectile moving.
 /// </summary>
 /// <param name="damageAmount">Damage amount.</param>
 /// <param name="damageType">Damage type.</param>
 override public void Fire(int damageAmount, DamageType damageType, Vector2 direction, IMob character)
 {
     rigidbody2D          = GetComponent <Rigidbody2D> ();
     fired                = true;
     damageInfo           = new DamageInfo(damageAmount, damageType, Vector2.zero, character);
     rigidbody2D.velocity = (new Vector2(0, 1) + direction) * speed;
     this.character       = character;
     if (grenadeTrigger == GrenadeType.EXPLODE_AFTER_DELAY)
     {
         StartCoroutine(DoTrigger());
     }
 }
Exemplo n.º 59
0
 public void Render(IMob mob)
 {
     return;
 }
Exemplo n.º 60
0
 /// <summary>
 /// Returns true if the hit box has hit the given mob since it was last enabled.
 /// </summary>
 virtual public bool HasHitMob(IMob mob)
 {
     return(hitMobs.Contains(mob));
 }