Ejemplo n.º 1
0
        public override void OnUpdate(Context context)
        {
            if (context.LivingEnitites.Count == 0 || context.LocalPlayer == null)
            {
                return;
            }
            WeaponBase weapon = context.LocalPlayer.WeaponComponent.GetCurrentWeapon();
            bool       targetFound;

            HitUtils.HitData data;
            weapon.ComputeAimAssistDir(weapon.AttackPos, weapon.AttackDir, out targetFound, out data);
            if (targetFound)
            {
                context.LocalPlayer.BlackBoard.ActionAdd(AgentActionAttack.CreateAction(weapon.AttackDir));
            }

            /*
             * Transform camTransform = Camera.main.transform;
             * RaycastHit hit;
             * if (Physics.SphereCast(camTransform.position, 5f, camTransform.forward, out hit, 100f, -5))
             * {
             *  if (context.SearchForEntity(hit.transform) != null)
             *      context.LocalPlayer.BlackBoard.ActionAdd(AgentActionAttack.CreateAction(camTransform.forward));
             * }
             */
        }
Ejemplo n.º 2
0
    protected override void Initialize(AgentAction _action)
    {
        base.Initialize(_action);
        SetFinished(false);
        State = E_State.E_Preparing;
        Owner.BlackBoard.MotionType = E_MotionType.Attack;
        Action       = _action as AgentActionAttack;
        Action.IsHit = false;
        if (Action.Data == null)
        {
            Action.Data = null;//AnimSet Get
        }
        AnimAttackData = Action.Data;
        if (AnimAttackData == null)
        {
            Debug.LogError("AnimAttackData is null");
        }
        StartPosition = Transform.position;
        StartRotation = Transform.rotation;
        float angle    = 0;
        float distance = 0;

        if (Action.Target != null)
        {
            Vector3 dir = Action.Target.Position - Transform.position;
            distance = dir.magnitude;
            if (distance > 0.1f)
            {
                dir.Normalize();
                angle = Vector3.Angle(Transform.forward, dir);
                //todo : add back logic
            }
            else
            {
                dir = Transform.forward;
            }
            FinalRotation.SetLookRotation(dir);

            if (distance < Owner.BlackBoard.WeaponRange)
            {
                FinalPosition = StartPosition;
            }
            else
            {
                FinalPosition = Action.Target.Transform.position - dir * Owner.BlackBoard.WeaponRange;
            }
            MoveTime     = (FinalPosition - StartPosition).magnitude / 10.0f;
            RotationTime = angle / 720.0f;
        }
        else
        {
            FinalRotation.SetLookRotation(Action.AttackDir);
            RotationTime = Vector3.Angle(Transform.forward, Action.AttackDir) / 720.0f;
            MoveTime     = 0;
        }
        PositionOk          = MoveTime == 0;
        RotationOk          = RotationTime == 0;
        CurrentMoveTime     = 0;
        CurrentRotationTime = 0;
    }
Ejemplo n.º 3
0
    public void HandleAction(AgentAction action)
    {
        if (action.IsFailed())
        {
            return;
        }

        if (action is AgentActionAttack)
        {
            AgentActionAttack a      = action as AgentActionAttack;
            WeaponBase        weapon = Weapons[CurrentWeapon];

            weapon.Fire(a.FromPos, a.AttackDir);

            PlayerPersistantInfo ppi = PPIManager.Instance.GetPPI(Owner.NetworkView.owner);
            if (ppi != null)
            {
                ppi.AddWeaponUse(CurrentWeapon);
            }
        }
        else if (action is AgentActionReload)
        {
            WeaponBase weapon = Weapons[CurrentWeapon];
            weapon.Reload();
            //            Owner.WorldState.SetWSProperty(E_PropKey.WeaponLoaded, true);
        }
    }
Ejemplo n.º 4
0
    public void HandleAction(AgentAction a)
    {
        if (a is AgentActionAttack)
        {
            CurrentAttackAction = a as AgentActionAttack;
            Agent.WorldState.SetWSProperty(E_PropKey.E_ALERTED, true);
        }
        else if (a is AgentActionInjury)
        {
            Agent.WorldState.SetWSProperty(E_PropKey.E_ORDER, AgentOrder.E_OrderType.E_NONE);
            ComboProgress.Clear();
            ClearBufferedOrder();
            //GuiManager.Instance.ShowComboProgress(ComboProgress);
            Game.Instance.Hits = 0;
            Game.Instance.NumberOfInjuries++;
        }
        else if (a is AgentActionDeath)
        {
            Agent.WorldState.SetWSProperty(E_PropKey.E_ORDER, AgentOrder.E_OrderType.E_NONE);
            ComboProgress.Clear();
            ClearBufferedOrder();
            //GuiManager.Instance.ShowComboProgress(ComboProgress);
            Game.Instance.Hits = 0;
            Game.Instance.NumberOfDeath++;
            MissionZone.Instance.EndOfMission(false);
            // of	unlockAchievement
//			if(Game.Instance.NumberOfDeath >= 100) {
//				Achievements.UnlockAchievement(2);
//			} else if(Game.Instance.NumberOfDeath >= 50) {
//				Achievements.UnlockAchievement(1);
//			}
        }
    }
Ejemplo n.º 5
0
    override public void OnDeactivate()
    {
        Action.SetSuccess();
        Action = null;

        base.OnDeactivate();
    }
Ejemplo n.º 6
0
    void DoAttackAction()
    {
        Action            = AgentActionFactory.Create(AgentActionFactory.E_Type.E_ATTACK) as AgentActionAttack;
        Action.Target     = null;// Owner.BlackBoard.DesiredTarget != null && Owner.BlackBoard.DesiredTarget.IsAlive ? Owner.BlackBoard.DesiredTarget : null;
        Action.AttackType = E_AttackType.X;

        if (Owner.BlackBoard.DesiredTarget != null && Owner.BlackBoard.DesiredTarget.IsAlive)
        {
            Vector3 dir = Owner.BlackBoard.DesiredTarget.Position - Owner.Position;
            dir.Normalize();
            Owner.BlackBoard.DesiredDirection = dir;
        }
        else
        {
            Owner.BlackBoard.DesiredDirection = Owner.Forward;
        }

        Action.AttackDir = Owner.BlackBoard.DesiredDirection;

        Action.Hit             = false;
        Action.AttackPhaseDone = false;

        // Debug.Log("action attack  " + (Action.AttackTarget != null ? Action.AttackTarget.name : "no target"));

        Owner.BlackBoard.ActionAdd(Action);
    }
Ejemplo n.º 7
0
    public override void Update()
    {
        if (Owner.IsAlive == false)
        {
            Interruptible = true;
        }

        if (Count == 3)
        {
            if (Action.IsActive() == false && ActionAttack == null)
            {
                Owner.SoundPlayBerserk();
                Owner.BlackBoard.Invulnerable = true;
                ActionAttack           = AgentActionFactory.Create(AgentActionFactory.E_Type.E_ATTACK) as AgentActionAttack;
                ActionAttack.Data      = Owner.AnimSet.GetFirstAttackAnim(Owner.BlackBoard.WeaponSelected, E_AttackType.O);
                ActionAttack.AttackDir = Owner.Forward;
                Owner.BlackBoard.ActionAdd(ActionAttack);
            }
            return;
        }

        WorldStateProp prop = Owner.WorldState.GetWSProperty(E_PropKey.E_EVENT);

        if (prop == null || prop.GetEvent() != E_EventTypes.Hit || Owner.IsAlive == false)
        {
            return;
        }

        SendAction();
    }
Ejemplo n.º 8
0
	protected override void OnEnter(AgentAction action)
	{
		this.mLocomotion.StopMove();

		mAction = action as AgentActionAttack;
		
		mStartRotation = this.mAgent.transform.rotation;

		if (mAction.mTargetAgent != null)
		{
			float angle = 0;
			Vector3 dir = mAction.mTargetAgent.transform.position - this.mAgent.transform.position;
			if (dir.sqrMagnitude > 0.1f * 0.1f)
			{
				dir.Normalize();
				angle = Vector3.Angle(this.mAgent.transform.forward, dir);
			}
			else
			{
				dir = this.mAgent.transform.forward;
			}

			mFinalRotation.SetLookRotation(dir);
			mRotationTime = angle / 1000.0f;
		}
		else
		{
			mFinalRotation.SetLookRotation(mAction.mAttackDir);
			mRotationTime = Vector3.Angle(this.mAgent.transform.forward, mAction.mAttackDir) / 1000.0f;
		}

		isRotationOk = mRotationTime == 0;

		mCurrentRotationTime = 0;
	}
Ejemplo n.º 9
0
    public void HandleAction(AgentAction action)
    {
        if (action.IsFailed())
        {
            return;
        }

        if (action is AgentActionAttack)
        {
            AttackAction = action as AgentActionAttack;

            WeaponBase weapon = Weapons[CurrentWeapon];

            weapon.Fire(AttackAction.AttackDir);

            if (weapon.ClipAmmo == 0)
            {
                Owner.WorldState.SetWSProperty(E_PropKey.WeaponLoaded, false);
            }
        }
        else if (action is AgentActionReload)
        {
            WeaponBase weapon = Weapons[CurrentWeapon];
            weapon.Reload();
            Owner.WorldState.SetWSProperty(E_PropKey.WeaponLoaded, true);
        }
    }
Ejemplo n.º 10
0
    void LateUpdate()
    {
        if (StepTime < Time.timeSinceLevelLoad)
        {
            if (Owner.BlackBoard.MotionType == E_MotionType.Run)
            {
                Owner.SoundPlayStep();
                StepTime = Time.timeSinceLevelLoad + Random.Range(0.25f, 0.28f);
            }
            else if (Owner.BlackBoard.MotionType == E_MotionType.Walk)
            {
                Owner.SoundPlayStep();
                StepTime = Time.timeSinceLevelLoad + Random.Range(0.40f, 0.43f);
            }
        }

        if (CurrentAttackAction != null && CurrentAttackAction.IsActive() == false)
        {// no continue in combos !!!
            if (BufferedOrders.Count == 0 && Owner.WorldState.GetWSProperty(E_PropKey.E_ORDER).GetOrder() != AgentOrder.E_OrderType.E_ATTACK)
            {
                //Debug.Log("clear combo progress " + CurrentAttackAction.Data.AnimName);
                ComboProgress.Clear();
                GuiManager.Instance.ShowComboProgress(ComboProgress);
            }
            CurrentAttackAction = null;
        }
    }
Ejemplo n.º 11
0
 //FSM每一帧检测当前状态是否完成,IsFinished=true时的时候调用OnDeactivate,
 override public void OnDeactivate()
 {
     //if (Owner.IsPlayer)
     //    Owner.BlackBoard.DesiredTarget = null;
     Action.SetSuccess();
     Action = null;
     base.OnDeactivate();
 }
Ejemplo n.º 12
0
    override public void OnDeactivate()
    {
        Time.timeScale = 1.0f;

        Action.SetSuccess();
        Action = null;

        base.OnDeactivate();
    }
Ejemplo n.º 13
0
 public override void OnDeactivate()
 {
     if (null != Action)
     {
         Action.SetSuccess();
         Action = null;
     }
     base.OnDeactivate();
 }
Ejemplo n.º 14
0
    void DoAttackAction()
    {
        Action = null;

        Action           = AgentActionFactory.Create(AgentActionFactory.E_Type.E_ATTACK) as AgentActionAttack;
        Action.Data      = Owner.AnimSet.GetFirstAttackAnim(Owner.BlackBoard.WeaponSelected, E_AttackType.Berserk);
        Action.AttackDir = Owner.Forward;
        Owner.BlackBoard.ActionAdd(Action);
    }
Ejemplo n.º 15
0
    override protected void Initialize(AgentAction action)
    {
        base.Initialize(action);

        Action = action as AgentActionAttack;

        SetFinished(false);

        if (Action.Data == null)
        {
            Action.Data = Owner.AnimSet.GetFirstAttackAnim(Owner.BlackBoard.WeaponSelected, Action.AttackType);
        }

        AnimAttackData = Action.Data;

        StartRotation = Transform.rotation;

        Action.AttackPhaseDone = false;
        Action.Hit             = false;

        float angle = 0;

        if (Action.Target != null)
        {
            Vector3 dir = Action.Target.Position - Transform.position;
            //float distance = dir.magnitude;

            if (dir.sqrMagnitude > 0.1f * 0.1f)
            {
                dir.Normalize();
                angle = Vector3.Angle(Transform.forward, dir);
            }
            else
            {
                dir = Transform.forward;
            }

            FinalRotation.SetLookRotation(dir);
            RotationTime = angle / 180.0f;
        }
        else
        {
            //Debug.Log("attacking dir " + Action.AttackDir.ToString());
            FinalRotation.SetLookRotation(Action.AttackDir);
            RotationTime = Vector3.Angle(Transform.forward, Action.AttackDir) / 1040.0f;
        }

        //Debug.Log("RT " + RotationTime + " MT " + MoveTime + " Angle " + angle);

        RotationOk = RotationTime == 0;

        CurrentRotationTime = 0;

        PlayAnim();
    }
Ejemplo n.º 16
0
    void SendAttackAction()
    {
        Owner.BlackBoard.ReactOnHits = false;
        ActionAttack           = AgentActionFactory.Create(AgentActionFactory.E_Type.E_ATTACK) as AgentActionAttack;
        ActionAttack.Data      = Owner.AnimSet.GetFirstAttackAnim(Owner.BlackBoard.WeaponSelected, E_AttackType.Berserk);
        ActionAttack.AttackDir = Owner.Forward;

        // Debug.Log("action attack  " + (Action.AttackTarget != null ? Action.AttackTarget.name : "no target"));

        Owner.BlackBoard.ActionAdd(ActionAttack);
    }
Ejemplo n.º 17
0
    void DoAttackAction()
    {
        Owner.SoundPlayBerserk();

        Action            = AgentActionFactory.Create(AgentActionFactory.E_Type.E_ATTACK) as AgentActionAttack;
        Action.Target     = Owner.BlackBoard.DesiredTarget != null && Owner.BlackBoard.DesiredTarget.IsAlive ? Owner.BlackBoard.DesiredTarget : null;
        Action.AttackType = E_AttackType.Counter;
        Action.AttackDir  = Owner.BlackBoard.DesiredDirection;

        Action.Hit             = false;
        Action.AttackPhaseDone = false;
        Owner.BlackBoard.ActionAdd(Action);
    }
Ejemplo n.º 18
0
    void DoAttackAction()
    {
        Action            = AgentActionFactory.Create(AgentActionFactory.E_Type.E_ATTACK) as AgentActionAttack;
        Action.Target     = Owner.BlackBoard.DesiredTarget != null && Owner.BlackBoard.DesiredTarget.IsAlive ? Owner.BlackBoard.DesiredTarget : null;
        Action.AttackType = E_AttackType.X;
        Action.AttackDir  = Owner.BlackBoard.DesiredDirection;


        Action.Hit             = false;
        Action.AttackPhaseDone = false;

        // Debug.Log("action attack  " + (Action.AttackTarget != null ? Action.AttackTarget.name : "no target"));

        Owner.BlackBoard.AddAction(Action);
    }
Ejemplo n.º 19
0
    void CreateAttack()
    {
        AgentActionAttack _action = AgentActionFactory.Create(AgentActionFactory.E_Type.E_ATTACK) as AgentActionAttack;

        _action.AttackType = E_AttackType.X;
        if (MoveDirection != Vector3.zero)
        {
            _action.AttackDir = MoveDirection;
        }
        else
        {
            _action.AttackDir = Agent.Transform.forward;
        }
        _action.Target = null;
        Agent.BlackBoard.AddAction(_action);
    }
Ejemplo n.º 20
0
    public override void Deactivate()
    {
        Owner.BlackBoard.Invulnerable = false;
        Action       = null;
        ActionAttack = null;
        base.Deactivate();

        WorldStateProp prop = Owner.WorldState.GetWSProperty(E_PropKey.E_EVENT);

        if (prop == null || prop.GetEvent() != E_EventTypes.Hit)
        {
            return;
        }
        // if there is some hit, clear it !!
        Owner.WorldState.SetWSProperty(E_PropKey.E_EVENT, E_EventTypes.None);
    }
Ejemplo n.º 21
0
    void CreateAttack()
    {
        AgentActionAttack _action = AgentActionFactory.Create(AgentActionFactory.E_Type.E_ATTACK) as AgentActionAttack;

        _action.AttackType = E_AttackType.X;
        if (MoveDirection != Vector3.zero)
        {
            _action.AttackDir = MoveDirection;
        }
        else
        {
            _action.AttackDir = Agent.Transform.forward;
        }
        _action.Target = null;
        _action.Data   = new AnimAttackData("attackO", 0.5f, 0.1f, 1.0f, 111, 30);
        Agent.BlackBoard.AddAction(_action);
    }
Ejemplo n.º 22
0
    /// <summary>
    /// 使用E_Type创建AgentAction命令.
    /// </summary>
    /// <param name="_type">_type.</param>
    static public AgentAction Create(E_Type _type)
    {
        int         index = (int)_type;
        AgentAction a;

        if (_UnusedActions[index].Count > 0)
        {
            a = _UnusedActions[index].Dequeue();
        }
        else
        {
            switch (_type)
            {
            case E_Type.E_Idle:
                a = new AgentActionIdle();
                break;

            case E_Type.E_Move:
                a = new AgentActionMove();
                break;

            case E_Type.E_Weapon_Show:
                a = new AgentActionWeaponShow();
                break;

            case E_Type.E_Attack:
                a = new AgentActionAttack();
                break;

            case E_Type.E_Play_Anim:
                a = new AgentActionPlayAnim();
                break;

            default:
                Debug.LogError("No AgentAction Create!!! Type: " + _type.ToString());
                return(null);
            }
        }
        a.Reset();
        a.SetActive();
#if DEBUG
        _ActiveActions.Add(a);
#endif
        return(a);
    }
Ejemplo n.º 23
0
    public override void Activate()
    {
        base.Activate();

        Action        = null;
        ActionAttack  = null;
        Count         = 0;
        Interruptible = false;

        WorldStateProp prop = Owner.WorldState.GetWSProperty(E_PropKey.E_EVENT);

        if (prop == null || prop.GetEvent() != E_EventTypes.Hit)
        {
            return;
        }

        SendAction();
    }
Ejemplo n.º 24
0
    protected void AttackC(Vector3 attackDir)
    {
        // TODO: I'm not sure what causes DontUpdate to be set to true on clients (especially proxies) but I would
        //say f**k it on proxies! The proxy has to do what server says. No way to ignore to spawn a projectile.
        //if (Owner.BlackBoard.DontUpdate)
        //	return;

#if !DEADZONE_CLIENT
        if (Owner.IsServer)
        {
            ServerAnticheat.ReportPotentialCheatAttempt("AttackC", "should never be called on the server side", Owner.NetworkView.owner);
            return;
        }
#endif

        AgentActionAttack action = AgentActionFactory.Create(AgentActionFactory.E_Type.Attack) as AgentActionAttack;
        action.AttackDir = attackDir;
        Owner.BlackBoard.ActionAdd(action);
    }
Ejemplo n.º 25
0
    void ProcessServerAttack(WeaponBase weapon, Vector3 fromPos, Vector3 attackDir)
    {
        //FIXME: tenhle zpusob volani se musi vyresit - zatim to zpusobuje exceptions ( in progress )
        //Medved: Moc rad bych vedel, co to bylo za problemy... Predpokladam, ze neco na clientovi diky
        //prehozeni poradi garantovanych a negarantovanych packetu v pripade, kdy garantovany zazil re-send.

        /*
         * if(weapon.FireTime < 0.15f)
         *      Owner.NetworkView.UnreliableRPC("AttackC",uLink.RPCMode.OthersExceptOwner, attackDir);
         * else
         */
        Owner.NetworkView.RPC("AttackC", uLink.RPCMode.OthersExceptOwner, attackDir);

        AgentActionAttack action = AgentActionFactory.Create(AgentActionFactory.E_Type.Attack) as AgentActionAttack;

        action.AttackDir = attackDir;
        action.FromPos   = fromPos;
        Owner.BlackBoard.ActionAdd(action);

        LastServerWeaponShotTime = Time.timeSinceLevelLoad;
    }
Ejemplo n.º 26
0
    void DoAttackAction(Agent target)
    {
        Action            = AgentActionFactory.Create(AgentActionFactory.E_Type.E_ATTACK) as AgentActionAttack;
        Action.AttackType = CurrentAttacktype;

        if (Owner.BlackBoard.DesiredTarget)
        {
            Owner.BlackBoard.DesiredDirection = Owner.BlackBoard.DesiredTarget.Position - Owner.Position;
            Owner.BlackBoard.DesiredDirection.Normalize();
            Action.AttackDir = Owner.BlackBoard.DesiredDirection;
        }
        else
        {
            Action.AttackDir = Owner.Forward;
        }

        Action.Hit             = false;
        Action.AttackPhaseDone = false;
        Owner.BlackBoard.AddAction(Action);

        NumberOfAttacks--;
    }
Ejemplo n.º 27
0
    void DoAttackAction()
    {
        Action = AgentActionFactory.Create(AgentActionFactory.E_Type.E_ATTACK) as AgentActionAttack;
        Owner.BlackBoard.DesiredTarget = Action.Target = MissionZone.Instance.GetBestTarget(Owner, LastAttacketTarget);
        Action.AttackType = Owner.BlackBoard.DesiredAttackType;
        Action.AttackDir  = Owner.BlackBoard.DesiredDirection;
        Action.Data       = Owner.BlackBoard.DesiredAttackPhase;

        if (Action.Target != null)
        {
            if (Action.Target.BlackBoard.MotionType == E_MotionType.Knockdown)
            {
                Action.Data       = Owner.AnimSet.GetFirstAttackAnim(Owner.BlackBoard.WeaponSelected, E_AttackType.Fatality);
                Action.AttackType = E_AttackType.Fatality;
            }
        }

        if (Action.Data != null && (Action.Data.FullCombo || Action.AttackType == E_AttackType.Fatality))
        {
            Owner.Sound.PlayBerserk();
        }
        else if (UnityEngine.Random.Range(0, 100) < 20)
        {
            Owner.Sound.PlayPrepareAttack();
        }

        Action.Hit             = false;
        Action.AttackPhaseDone = false;

        //派发数据到FSM里面
        Owner.BlackBoard.AddAction(Action);

        if (Owner.WorldState.GetWSProperty(E_PropKey.E_ORDER).GetOrder() == AgentOrder.E_OrderType.E_ATTACK)
        {
            Owner.WorldState.SetWSProperty(E_PropKey.E_ORDER, AgentOrder.E_OrderType.E_NONE);
        }

        LastAttacketTarget = Action.Target;
    }
Ejemplo n.º 28
0
 public void HandleAction(AgentAction a)
 {
     //Debug.Log("ComponentPlayer.HandleAction("+a);
     if (a is AgentActionAttack)
     {
         CurrentAttackAction = a as AgentActionAttack;
         Owner.WorldState.SetWSProperty(E_PropKey.E_ALERTED, true);
     }
     else if (a is AgentActionInjury)
     {
         Owner.WorldState.SetWSProperty(E_PropKey.E_ORDER, AgentOrder.E_OrderType.E_NONE);
         ComboProgress.Clear();
         ClearBufferedOrder();
         GuiManager.Instance.ShowComboProgress(ComboProgress);
         Game.Instance.Hits = 0;
         Game.Instance.NumberOfInjuries++;
     }
     else if (a is AgentActionDeath)
     {
         Owner.WorldState.SetWSProperty(E_PropKey.E_ORDER, AgentOrder.E_OrderType.E_NONE);
         ComboProgress.Clear();
         ClearBufferedOrder();
         GuiManager.Instance.ShowComboProgress(ComboProgress);
         Game.Instance.Hits = 0;
         Game.Instance.NumberOfDeath++;
         //Game.Instance.Score -= 50;
         Mission.Instance.EndOfMission(false);
         // of	unlockAchievement
         if (Game.Instance.NumberOfDeath >= 100)
         {
             Achievements.UnlockAchievement(2);
         }
         else if (Game.Instance.NumberOfDeath >= 50)
         {
             Achievements.UnlockAchievement(1);
         }
     }
 }
Ejemplo n.º 29
0
    void LateUpdate()
    {
        if (CurrentWeapon == E_WeaponID.None)
        {
            return;
        }

        WeaponBase weapon = Weapons[CurrentWeapon];

        if (weapon.IsBusy())
        {
            weapon.PrepareForFire(false);
            Owner.BlackBoard.Desires.WeaponTriggerUp = false;
            if (!Owner.IsInCover && !weapon.IsFiring())
            {
                float fov = GameCamera.Instance.DefaultFOV;
                if (!Mathf.Approximately(GameCamera.Instance.DesiredCameraFov, fov))
                {
                    GameCamera.Instance.SetFov(fov, 60);
                }
            }
            return;
        }

        if (Owner.BlackBoard.Desires.WeaponTriggerOn && !weapon.UseFireUp ||
            Owner.BlackBoard.Desires.WeaponTriggerUp && weapon.UseFireUp && Owner.CanFire())
        {
            if (!Owner.IsInCover)
            {
                float fov = GameCamera.Instance.DefaultFOV;
                fov *= Owner.WeaponComponent.GetCurrentWeapon().FireFovModificator;
                if (!Mathf.Approximately(GameCamera.Instance.DesiredCameraFov, fov))
                {
                    GameCamera.Instance.SetFov(fov, 60);
                }
            }

            if ((weapon.ClipAmmo > 0) && weapon.PreparedForFire)
            {
                AgentActionAttack      a       = AgentActionFactory.Create(AgentActionFactory.E_Type.Attack) as AgentActionAttack;
                ComponentPlayerMPOwner MPOwner = Owner.PlayerComponent as ComponentPlayerMPOwner;
                if (null != MPOwner)
                {
                    a.AttackDir = MPOwner.GetRealFireDir();                     //Owner.BlackBoard.FireDir;
                }
                else
                {
                    Debug.LogWarning("Missing ComponentPlayerMPOwner on " + Owner);
                    a.AttackDir = Owner.BlackBoard.FireDir;
                }
                a.FromPos = GetCurrentWeapon().ShotPos;
                Owner.BlackBoard.ActionAdd(a);
            }
            else
            {
                weapon.PrepareForFire(true);
                Owner.BlackBoard.Desires.WeaponTriggerUp = false;
                return;
            }

            if (weapon.IsFullAuto == false)
            {
                Owner.BlackBoard.Desires.WeaponTriggerOn = false;
            }
            Owner.BlackBoard.Desires.WeaponTriggerUp = false;
        }
        else if (Owner.BlackBoard.Desires.WeaponTriggerOn && weapon.UseFireUp)
        {
            weapon.PrepareForFire(true);
            if (!Owner.IsInCover)
            {
                float fov = GameCamera.Instance.DefaultFOV;
                fov *= Owner.WeaponComponent.GetCurrentWeapon().FireFovModificator;
                if (!Mathf.Approximately(GameCamera.Instance.DesiredCameraFov, fov))
                {
                    GameCamera.Instance.SetFov(fov, 60);
                }
            }
        }
        else
        {
            weapon.PrepareForFire(false);
            if (!Owner.IsInCover && Owner.IsAlive)
            {
                float fov = GameCamera.Instance.DefaultFOV;
                if (!Mathf.Approximately(GameCamera.Instance.DesiredCameraFov, fov))
                {
                    GameCamera.Instance.SetFov(fov, 60);
                }
            }
        }
    }
Ejemplo n.º 30
0
    override protected void Initialize(AgentAction action)
    {
        base.Initialize(action);
        SetFinished(false);

        State = E_State.E_PREPARING;
        Owner.BlackBoard.MotionType = E_MotionType.Attack;

        Action = action as AgentActionAttack;
        Action.AttackPhaseDone = false;
        Action.Hit             = false;

        if (Action.Data == null)
        {
            Action.Data = Owner.AnimSet.GetFirstAttackAnim(Owner.BlackBoard.WeaponSelected, Action.AttackType);
        }

        AnimAttackData = Action.Data;

        if (AnimAttackData == null)
        {
            Debug.LogError("AnimAttackData == null");
        }

        StartRotation = Transform.rotation;
        StartPosition = Transform.position;

        float angle = 0;

        bool backstab = false;

        float distance = 0;

        if (Action.Target != null)
        {
            Vector3 dir = Action.Target.Position - Transform.position;
            distance = dir.magnitude;

            if (distance > 0.1f)
            {
                dir.Normalize();
                angle = Vector3.Angle(Transform.forward, dir);

                //attacker uhel k cili je mensi nez 40 and uhel enemace a utocnika je mensi nez 80 stupnu
                if (angle < 40 && Vector3.Angle(Owner.Forward, Action.Target.Forward) < 80)
                {
                    backstab = true;
                }
            }
            else
            {
                dir = Transform.forward;
            }


            FinalRotation.SetLookRotation(dir);

            if (distance < Owner.BlackBoard.WeaponRange)
            {
                FinalPosition = StartPosition;
            }
            else
            {
                FinalPosition = Action.Target.Transform.position - dir * Owner.BlackBoard.WeaponRange;
            }

            MoveTime     = (FinalPosition - StartPosition).magnitude / 20.0f;
            RotationTime = angle / 720.0f;
        }
        else
        {
            FinalRotation.SetLookRotation(Action.AttackDir);

            RotationTime = Vector3.Angle(Transform.forward, Action.AttackDir) / 720.0f;
            MoveTime     = 0;
        }

        RotationOk = RotationTime == 0;
        PositionOK = MoveTime == 0;

        CurrentRotationTime = 0;
        CurrentMoveTime     = 0;

        if (Owner.IsPlayer && AnimAttackData.HitCriticalType != E_CriticalHitType.None && Action.Target && Action.Target.BlackBoard.CriticalAllowed && Action.Target.IsBlocking == false && Action.Target.IsInvulnerable == false && Action.Target.IsKnockedDown == false)
        {
            if (backstab)
            {
                Critical = true;
            }
            else
            {
                //           Debug.Log("critical chance" + Owner.GetCriticalChance() * AnimAttackData.CriticalModificator * Action.Target.BlackBoard.CriticalHitModifier);
                Critical = Random.Range(0, 100) < Owner.GetCriticalChance() * AnimAttackData.CriticalModificator * Action.Target.BlackBoard.CriticalHitModifier;
            }
        }
        else
        {
            Critical = false;
        }

        Knockdown = AnimAttackData.HitAreaKnockdown && Random.Range(0, 100) < 60 * Owner.GetCriticalChance();
    }
Ejemplo n.º 31
0
    /// <summary>
    /// 使用E_Type创建AgentAction命令.
    /// </summary>
    /// <param name="_type">_type.</param>
    static public AgentAction Create(E_Type _type)
    {
        int         index = (int)_type;
        AgentAction a;

        if (_UnusedActions[index].Count > 0)
        {
            a = _UnusedActions[index].Dequeue();
        }
        else
        {
            switch (_type)
            {
            case E_Type.E_IDLE:
                a = new AgentActionIdle();
                break;

            case E_Type.E_MOVE:
                a = new AgentActionMove();
                break;

            case E_Type.E_WEAPON_SHOW:
                a = new AgentActionWeaponShow();
                break;

            case E_Type.E_ATTACK:
                a = new AgentActionAttack();
                break;

            case E_Type.E_PLAY_ANIM:
                a = new AgentActionPlayAnim();
                break;

            case E_Type.E_GOTO:
                a = new AgentActionGoTo();
                break;
            //case E_Type.E_COMBAT_MOVE:
            //    a = new AgentActioCombatMove();
            //    break;
            //case E_Type.E_ATTACK_ROLL:
            //    a = new AgentActionAttackRoll();
            //    break;
            //case E_Type.E_ATTACK_WHIRL:
            //    a = new AgentActionAttackWhirl();
            //    break;
            //case E_Type.E_INJURY:
            //    a = new AgentActionInjury();
            //    break;
            //case E_Type.E_DAMAGE_BLOCKED:
            //    a = new AgentActionDamageBlocked();
            //    break;
            //case E_Type.E_BLOCK:
            //    a = new AgentActionBlock();
            //    break;
            //case E_Type.E_ROLL:
            //    a = new AgentActionRoll();
            //    break;
            //case E_Type.E_INCOMMING_ATTACK:
            //    a = new AgentActionIncommingAttack();
            //    break;

            //case E_Type.Rotate:
            //    a = new AgentActionRotate();
            //    break;
            //case E_Type.E_USE_LEVER:
            //    a = new AgentActionUseLever();
            //    break;


            //case E_Type.E_PLAY_IDLE_ANIM:
            //    a = new AgentActionPlayIdleAnim();
            //    break;
            //case E_Type.E_DEATH:
            //    a = new AgentActionDeath();
            //    break;
            //case E_Type.E_KNOCKDOWN:
            //    a = new AgentActionKnockdown();
            //    break;
            //case E_Type.Teleport:
            //    a = new AgentActionTeleport();
            //    break;
            default:
                Debug.LogError("No AgentAction Create!!! Type: " + _type.ToString());
                return(null);
            }
        }
        a.Reset();
        a.SetActive();
#if DEBUG
        _ActiveActions.Add(a);
#endif
        return(a);
    }