예제 #1
0
 public void ResolveOrder(Actor self, Order order)
 {
     if (order.OrderString == "SetUnitStance")
     {
         stance = (UnitStance)order.TargetLocation.X;
     }
 }
예제 #2
0
 public void ResolveOrder(Actor self, Order order)
 {
     if (order.OrderString == "SetUnitStance" && info.EnableStances)
     {
         Stance = (UnitStance)order.TargetLocation.X;
     }
 }
예제 #3
0
 public AutoTarget(Actor self, AutoTargetInfo info)
 {
     Info            = info;
     attack          = self.Trait <AttackBase>();
     stance          = Info.InitialStance;
     predictedStance = stance;
 }
예제 #4
0
    public void ChangeStance(int newStanceID)
    {
        currentStance = stances[newStanceID];

        entity.unitAnimation.ChangeStance(newStanceID);
        entity.unitAnimation.BackToIdle();
    }
예제 #5
0
        void INotifyStanceChanged.StanceChanged(Actor self, AutoTarget autoTarget, UnitStance oldStance, UnitStance newStance)
        {
            // Cancel opportunity targets when switching to a more restrictive stance if they are no longer valid for auto-targeting
            if (newStance > oldStance || opportunityForceAttack)
            {
                return;
            }

            if (OpportunityTarget.Type == TargetType.Actor)
            {
                var a = OpportunityTarget.Actor;
                if (!autoTarget.HasValidTargetPriority(self, a.Owner, a.GetEnabledTargetTypes()))
                {
                    OpportunityTarget = Target.Invalid;
                }
            }
            else if (OpportunityTarget.Type == TargetType.FrozenActor)
            {
                var fa = OpportunityTarget.FrozenActor;
                if (!autoTarget.HasValidTargetPriority(self, fa.Owner, fa.TargetTypes))
                {
                    OpportunityTarget = Target.Invalid;
                }
            }
        }
예제 #6
0
        public void SetStance(Actor self, UnitStance value)
        {
            if (stance == value)
            {
                return;
            }

            var oldStance = stance;

            stance = value;
            ApplyStanceCondition(self);

            foreach (var nsc in notifyStanceChanged)
            {
                nsc.StanceChanged(self, this, oldStance, stance);
            }

            if (self.CurrentActivity != null)
            {
                foreach (var a in self.CurrentActivity.ActivitiesImplementing <IActivityNotifyStanceChanged>())
                {
                    a.StanceChanged(self, this, oldStance, stance);
                }
            }
        }
예제 #7
0
 public void ResolveOrder(Actor self, Order order)
 {
     if (order.OrderString == "SetUnitStance" && Info.EnableStances)
     {
         Stance = (UnitStance)order.ExtraData;
     }
 }
예제 #8
0
 public AutoTarget(Actor self, AutoTargetInfo info)
 {
     this.info       = info;
     attack          = self.Trait <AttackBase>();
     Stance          = info.InitialStance;
     PredictedStance = Stance;
     at = self.TraitOrDefault <AttackFollow>();
 }
        void BindStanceButton(ButtonWidget button, UnitStance stance)
        {
            WidgetUtils.BindButtonIcon(button);

            button.IsDisabled    = () => { UpdateStateIfNecessary(); return(!actorStances.Any()); };
            button.IsHighlighted = () => actorStances.Any(
                at => !at.Trait.IsTraitDisabled && at.Trait.PredictedStance == stance);
            button.OnClick = () => SetSelectionStance(stance);
        }
예제 #10
0
        public void SetStance(Actor self, UnitStance value)
        {
            if (stance == value)
            {
                return;
            }

            stance = value;
            ApplyStanceCondition(self);
        }
예제 #11
0
		public AutoTarget(ActorInitializer init, AutoTargetInfo info)
			: base(info)
		{
			var self = init.Self;
			ActiveAttackBases = self.TraitsImplementing<AttackBase>().ToArray().Where(Exts.IsTraitEnabled);

			stance = init.GetValue<StanceInit, UnitStance>(self.Owner.IsBot || !self.Owner.Playable ? info.InitialStanceAI : info.InitialStance);

			PredictedStance = stance;

			allowMovement = Info.AllowMovement && self.TraitOrDefault<IMove>() != null;
		}
        void BindStanceButton(ButtonWidget button, UnitStance stance, Func <ButtonWidget, Hotkey> getHotkey)
        {
            var icon = button.Get <ImageWidget>("ICON");

            icon.GetImageName = () => button.IsDisabled() ? icon.ImageName + "-disabled" :
                                button.IsHighlighted() ? icon.ImageName + "-active" : icon.ImageName;

            button.GetKey        = getHotkey;
            button.IsDisabled    = () => { UpdateStateIfNecessary(); return(!actorStances.Any()); };
            button.IsHighlighted = () => actorStances.Any(
                at => !at.Trait.IsTraitDisabled && at.Trait.PredictedStance == stance);
            button.OnClick = () => SetSelectionStance(stance);
        }
        void SetSelectionStance(UnitStance stance)
        {
            foreach (var at in actorStances)
            {
                if (!at.Trait.IsTraitDisabled)
                {
                    at.Trait.PredictedStance = stance;
                }

                world.IssueOrder(new Order("SetUnitStance", at.Actor, false)
                {
                    ExtraData = (uint)stance
                });
            }
        }
        void BindStanceButton(ButtonWidget button, UnitStance stance)
        {
            var icon           = button.Get <ImageWidget>("ICON");
            var hasDisabled    = ChromeProvider.GetImage(icon.ImageCollection, icon.ImageName + "-disabled") != null;
            var hasActive      = ChromeProvider.GetImage(icon.ImageCollection, icon.ImageName + "-active") != null;
            var hasActiveHover = ChromeProvider.GetImage(icon.ImageCollection, icon.ImageName + "-active-hover") != null;
            var hasHover       = ChromeProvider.GetImage(icon.ImageCollection, icon.ImageName + "-hover") != null;

            icon.GetImageName = () => hasActive && button.IsHighlighted() ?
                                (hasActiveHover && Ui.MouseOverWidget == button ? icon.ImageName + "-active-hover" : icon.ImageName + "-active") :
                                hasDisabled && button.IsDisabled() ? icon.ImageName + "-disabled" :
                                hasHover && Ui.MouseOverWidget == button ? icon.ImageName + "-hover" : icon.ImageName;

            button.IsDisabled    = () => { UpdateStateIfNecessary(); return(!actorStances.Any()); };
            button.IsHighlighted = () => actorStances.Any(
                at => !at.Trait.IsTraitDisabled && at.Trait.PredictedStance == stance);
            button.OnClick = () => SetSelectionStance(stance);
        }
예제 #15
0
        public AutoTarget(ActorInitializer init, AutoTargetInfo info)
            : base(info)
        {
            var self = init.Self;

            ActiveAttackBases = self.TraitsImplementing <AttackBase>().ToArray().Where(Exts.IsTraitEnabled);

            if (init.Contains <StanceInit>())
            {
                stance = init.Get <StanceInit, UnitStance>();
            }
            else
            {
                stance = self.Owner.IsBot || !self.Owner.Playable ? info.InitialStanceAI : info.InitialStance;
            }

            PredictedStance = stance;
        }
예제 #16
0
        public AutoTarget(ActorInitializer init, AutoTargetInfo info)
        {
            var self = init.Self;

            this.info = info;
            attack    = self.Trait <AttackBase>();

            if (init.Contains <StanceInit>())
            {
                Stance = init.Get <StanceInit, UnitStance>();
            }
            else
            {
                Stance = self.Owner.IsBot || !self.Owner.Playable ? info.InitialStanceAI : info.InitialStance;
            }

            PredictedStance = Stance;
            at = self.TraitOrDefault <AttackFollow>();
        }
예제 #17
0
        bool SetUnitStance(UnitStance unitStance)
        {
            PerformKeyboardOrderOnSelection(a =>
            {
                var at = a.TraitOrDefault <AutoTarget>();
                if (at != null)
                {
                    at.PredictedStance = unitStance;
                }

                return(new Order("SetUnitStance", a, false)
                {
                    ExtraData = (uint)unitStance
                });
            });

            Game.AddChatLine(Color.White, "Battlefield Control", "Unit stance set to: {0}".F(unitStance));

            return(true);
        }
예제 #18
0
    public override void BehaviourUpdate()
    {
        //Profiler.BeginSample("BehaviourUpdate");
        #region debug
        if (Input.GetKeyDown(KeyCode.B))
        {
            combat.Block(currentStance.blocks[0]);
        }
        if (Input.GetKeyDown(KeyCode.N))
        {
            combat.B_BlockFlinch();
        }
        if (Input.GetKeyDown(KeyCode.M))
        {
            combat.Evade(currentStance.evades[1]);
        }
        if (Input.GetKeyDown(KeyCode.L))
        {
            combat.MeleeAttack(null, currentStance.attacks[1]);
        }
        #endregion


        //cache some variables for later
        nearestEnemy        = sensing.nearestEnemy;
        currentStance       = unitAI.currentStance;
        myTransformPosition = entity.myTransform.position;
        enemyIsNull         = nearestEnemy == null;


        //1. look at the enemy, if no enemy present -> continue looking in the movement direction


        if (!enemyIsNull)
        {
            //but only if something chenged
            if (nearestEnemyLastFrame != nearestEnemy)
            {
                nearestEnemysTransform = nearestEnemy.myTransform;
                movement.LookAt(nearestEnemysTransform);
            }

            nearestEnemyPosition = nearestEnemysTransform.position;
            currentSquaredDistanceToNearestEnemy = (nearestEnemyPosition - myTransformPosition).sqrMagnitude;
        }
        else
        {
            if (nearestEnemyLastFrame != nearestEnemy)
            {
                movement.StopLookAt();
            }
        }

        switch (meleeAttackBehaviourState)
        {
        //2. if theres an enemy -> walk towards him
        case MeleeAttackBehaviourState.Idle:

            if (!enemyIsNull)
            {
                movement.MoveTo(nearestEnemyPosition);
                meleeAttackBehaviourState = MeleeAttackBehaviourState.MovingToNearestEnemy;
            }

            break;

        case MeleeAttackBehaviourState.MovingToNearestEnemy:

            //check if the enemy is still alive
            if (enemyIsNull)
            {
                meleeAttackBehaviourState = MeleeAttackBehaviourState.Idle;
                movement.Stop();
            }
            //else check if we reached the destination
            else if (currentSquaredDistanceToNearestEnemy < rangeToEnterMeleeCombatSquared)
            {
                meleeAttackBehaviourState = MeleeAttackBehaviourState.InMeleeFight;
            }
            //if not, check if we need to update the destination
            else
            {
                if (Time.time > nextUpdateDestinationTime)
                {
                    nextUpdateDestinationTime = Time.time + updateDestinationInterval;
                    movement.MoveTo(nearestEnemyPosition);
                }
            }

            break;

        case MeleeAttackBehaviourState.InMeleeFight:

            //check if the enemy is still alive
            if (enemyIsNull)
            {
                meleeAttackBehaviourState = MeleeAttackBehaviourState.Idle;
                movement.Stop();
            }
            //check if the enemy has not escaped
            else if (currentSquaredDistanceToNearestEnemy > rangeToEnterMeleeCombatSquared)
            {
                if (combat.currentCombatState == CombatState.CombatIdle)
                {
                    movement.MoveTo(nearestEnemyPosition);
                    meleeAttackBehaviourState = MeleeAttackBehaviourState.MovingToNearestEnemy;
                }
            }
            //else check if i am in range for an attack - fix range and attack
            else
            {
                //decision making .- thats the tricky part here
                if (combat.currentCombatState == CombatState.CombatIdle)
                {
                    //check if we should block because our adversary was faster
                    if (nearestEnemy.combat.currentCombatState == CombatState.PreparingMeleeAttack)
                    {
                        //if he is lucky he will block or evade, if not then not :D
                        if (Random.Range(0, 2) == 0)
                        {
                            if (Random.Range(0, 2) == 0)
                            {
                                combat.Block(currentStance.blocks[0]);
                            }
                            else
                            {
                                combat.Evade(currentStance.evades[0]);
                            }
                        }
                        else
                        {
                            combat.MeleeAttack(nearestEnemy, currentStance.attacks[Random.Range(0, currentStance.attacks.Length)]);
                        }
                    }
                    else
                    {
                        combat.MeleeAttack(nearestEnemy, currentStance.attacks[Random.Range(0, currentStance.attacks.Length)]);
                    }
                }
                else if (combat.currentCombatState == CombatState.Blocking)
                {
                    //check if we can stop blocking and attack
                    if (nearestEnemy.combat.currentCombatState != CombatState.PreparingMeleeAttack)
                    {
                        combat.MeleeAttack(nearestEnemy, currentStance.attacks[Random.Range(0, currentStance.attacks.Length)]);
                    }
                }
            }
            break;
        }

        nearestEnemyLastFrame = nearestEnemy;

        // Profiler.EndSample();
    }
예제 #19
0
 /*
 *   Function: toggleStance
 *   Return Type: void
 *   Description: This method allows the unit's stance to be toggled quickly.
 *   Parameters: none
 *   Date Reviewed: 08/06/2014 by Nathan Hanlan
 */
 private void toggleStance()
 {
     if (m_UnitStance == UnitStance.STAND)
     {
         m_UnitStance = UnitStance.CROUCH;
     }
     else
     {
         m_UnitStance = UnitStance.STAND;
     }
 }
예제 #20
0
 void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
 {
     PredictedStance = self.Owner.IsBot || !self.Owner.Playable ? Info.InitialStanceAI : Info.InitialStance;
     SetStance(self, PredictedStance);
 }
예제 #21
0
        void IActivityNotifyStanceChanged.StanceChanged(Actor self, AutoTarget autoTarget, UnitStance oldStance, UnitStance newStance)
        {
            // Cancel non-forced targets when switching to a more restrictive stance if they are no longer valid for auto-targeting
            if (newStance > oldStance || forceAttack)
            {
                return;
            }

            if (!autoTarget.HasValidTargetPriority(self, lastVisibleOwner, lastVisibleTargetTypes))
            {
                target = Target.Invalid;
            }
        }
예제 #22
0
    void onInActive()
    {
        m_Grounded = checkGrounded();
        //Apply gravity
        m_Rigidbody.AddForce(new Vector3(0.0f, -m_Gravity * m_Rigidbody.mass, 0.0f));
        //Reset Rigidbody
        m_Rigidbody.angularVelocity = Vector3.zero;

        m_UnitStance = UnitStance.STAND;
        if (m_Grounded == true)
        {
            m_Animation.CrossFade("Male_idle");
        }
        else
        {
            m_Animation.CrossFade("Male_runJump_InAir");
        }
    }
예제 #23
0
        void IActivityNotifyStanceChanged.StanceChanged(Actor self, AutoTarget autoTarget, UnitStance oldStance, UnitStance newStance)
        {
            // Cancel non-forced targets when switching to a more restrictive stance if they are no longer valid for auto-targeting
            if (newStance > oldStance || forceAttack)
            {
                return;
            }

            // If lastVisibleTarget is invalid we could never view the target in the first place, so we just drop it here too
            if (!lastVisibleTarget.IsValidFor(self) || !autoTarget.HasValidTargetPriority(self, lastVisibleOwner, lastVisibleTargetTypes))
            {
                attackAircraft.ClearRequestedTarget();
            }
        }
예제 #24
0
 /*
 *   Function: jump
 *   Return Type: void
 *   Description: Sets the proper stance, velocity and animation
 *   Parameters:  @Vector3 aCurrentVelocity - The current velocity for the x and z axis
 *   Date Reviewed: 08/06/2014 by Nathan Hanlan
 */
 private void jump(Vector3 aCurrentVelocity)
 {
     m_Rigidbody.velocity = new Vector3(aCurrentVelocity.x, calculateJumpVerticalSpeed(), aCurrentVelocity.z);
     m_UnitStance = UnitStance.STAND;
     m_Animation.CrossFade("Male_runJump_InAir");
 }