예제 #1
0
    private IEnumerator LateAtk(Character _target, float delay, Skill skill)
    {
        skill.cast(this.character, _target);
        yield return(new WaitForSeconds(delay));

        AbstractAI targetAI = _target.ai;

        if (this.IsDied() || targetAI.IsDied() || !isInAttackArea(_target.gameObject, getAtkRange()))
        {
            yield break;
        }

        bool isCrit  = IsCrit(skill, _target);
        bool isDodge = IsDodge(skill, _target);
        int  damage  = GetDamage(atkTarget, skill, isCrit, isDodge);

        _target.hp -= damage;
        Vector3 attackdir = this.transform.position - _target.gameObject.transform.position;

        attackdir[1] = 0f;
        attackdir    = Vector3.Normalize(attackdir);
        if (_target.type == CharacterType.MONSTER && isCrit && !isDodge)
        {
            cameraCtrl.Hitcam();
        }
        targetAI.OnHit(damage, attackdir, character, isCrit, isDodge);
    }
 public override void Alert(Vector3 direction, bool origin, Vector3 point, AbstractAI alerter)
 {
     if (origin)
     {
         if (underFireTimer <= 0)
         {
             underFireTimer = evadeTime;
             evadeDirection = transform.up * data.hoverDelta * (Random.Range(0f, 1f) < .5f ? -1 : 1) + transform.right * evadeDistance * (Random.Range(0f, 1f) < .5f ? -1 : 1) - transform.forward * evadeDistance;
         }
     }
     else
     {
         if (protectTarget == null)
         {
             foreach (Transform drone in ManageFactions.instance.GetAllyFactionList(transform.GetComponent <Health>().faction))
             {
                 if (drone.GetComponent <DroneAI>().GetAttackTarget() == alerter.transform)
                 {
                     if (underFireTimer <= 0)
                     {
                         underFireTimer = evadeTime;
                         evadeDirection = transform.up * data.hoverDelta * (Random.Range(0f, 1f) < .5f ? -1 : 1) + transform.right * evadeDistance * (Random.Range(0f, 1f) < .5f ? -1 : 1) - transform.forward * evadeDistance;
                     }
                     return;
                 }
             }
             SetAttackTarget(alerter.transform);
         }
     }
 }
예제 #3
0
        public override ActionState update(AbstractAI ai, float delta)
        {
            ActionState state = this;

            /* Check if player isn't seen anymore -> currentActionState == SEARCH
             * Check if waypoint reached -> waypoint index++ , currentActionState == IDLE
             */
            if (ai.currentSenseState == AbstractAI.SenseStates.playerSpotted) //playerSpotted)
            {
                state = new Search();
            }

            if (_timer > 0)
            {
                //... check if npc reach destination
                if (ai.navMeshAgent.remainingDistance <= ai.navMeshAgent.stoppingDistance &&
                    !ai.navMeshAgent.pathPending)
                {
                    ai.IsWalking();
                    _timer = 0.0f;
                    //STOP WALKING WHEN POINT REACHED!
                }
            }
            else if (ai.currentSenseState != AbstractAI.SenseStates.neverSeenPlayer) //Time ran out: next state:
            {
                state = new Search();
            }
            else
            {
                state = new Idle(20);
            }

            _timer -= delta;
            return(state);
        }
예제 #4
0
파일: PlayerAI.cs 프로젝트: dawnx/dsoul
    void updateDist(Vector3 screenPos)
    {
        //Vector3 cursorScreenPosition = Input.mousePosition;//鼠标在屏幕上的位置
        Ray        ray = Camera.main.ScreenPointToRay(screenPos);//在鼠标所在的屏幕位置发出一条射线
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            String tag = hit.collider.gameObject.tag;
            Debug.Log("click tag is:" + tag + "hoverred object is :" + (UICamera.hoveredObject == null));
            if (tag == "Terrain" && UICamera.hoveredObject == null)
            {
                var endposition = hit.point;
                //endposition.y += 4.6f;// 模型的中心点的问题,(模型的高度 * scale /2)

                setDist(endposition);
                atkTarget = null;
            }
            else if (tag == "Enemy")
            {
                AbstractAI ai = GetTargetAI(hit.collider.gameObject);
                if (ai != null)
                {
                    atkTarget         = ai.character;
                    this.currentState = ATK;
                }
            }
        }
    }
예제 #5
0
 public override void Alert(Vector3 direction, bool origin, Vector3 point, AbstractAI alerter)
 {
     if (underFireTimer <= 0)
     {
         underFireTimer = evadeTime;
         evadeDirection = transform.up * data.hoverDelta * (Random.Range(0f, 1f) < .5f ? -1 : 1) + transform.right * evadeDistance * (Random.Range(0f, 1f) < .5f ? -1 : 1);
     }
 }
 public override void Alert(Vector3 direction, bool origin, Vector3 point, AbstractAI alerter)
 {
     if (underFireTimer <= 0)
     {
         underFireTimer = evadeTime;
         Vector3 moveDirection = Quaternion.LookRotation(Vector3.right, Vector3.up) * direction;
         evadePoint = transform.position + moveDirection * evadeDistance * (Random.Range(0f, 1f) < .5f ? -1 : 1);
     }
 }
예제 #7
0
        public void ChangeAI(AbstractAI ai)
        {
            if (AI != null)
            {
                AI.StopAITask();
            }

            AI = ai;
            AI.StartAITask();
        }
예제 #8
0
    public static AbstractAI GetTargetAI(GameObject go)
    {
        if (go == null)
        {
            return(null);
        }

        AbstractAI ai = go.GetComponent <MonsterAI>();

        if (ai == null)
        {
            ai = go.GetComponent <PlayerAI>();
        }

        return(ai);
    }
예제 #9
0
    public void atk()
    {
        if (atkTarget == null)
        {
            Debug.Log("target is null");
            currentState = IDLE;
            return;
        }

        if (atk_ez_time > 0)
        {
            return;
        }

        GameObject target = atkTarget.gameObject;

        if (currentState != ATK)
        {
            currentState = ATK;
        }
        else if (isInAttackArea(target.gameObject, getAtkRange()) && !atkTarget.ai.IsDied())
        {
            //Debug.Log("is attacked " + target.gameObject);
            currentState = ATK;
            //atk_ez_time = GetAnimaLen("attack1") + 0.2f; // TODO 如果有其它的硬直存在?, TODO,这里应该为技能的CD、攻击的CD等设置
            atk_ez_time = character.atkSpeed;

            AbstractAI targetAI = atkTarget.ai;

            if (!targetAI.IsDied())
            {
                Skill skill = getSkill();
                PlayClip(skill.atkClip);
                animation.PlayQueued("idle");

                float delay = 0.5f;// TODO 这里的delay应该是动作播放到到受击帧的时间
                StartCoroutine(LateAtk(atkTarget, delay, skill));
            }
        }

        gameObject.transform.LookAt(target.gameObject.transform.position);
    }
예제 #10
0
 /// <summary>
 /// Activate the %SwitchToAIName% AI.
 /// And deactivate the other AI.
 /// </summary>
 public void SwitchAI(string SwitchToAIName)
 {
     if (CurrentAI != null)
     {
         if (CurrentAI.Name != SwitchToAIName)
         {
             CurrentAI.enabled = false;
             CurrentAI.StopAI();
             AbstractAI newAI = AIDict [SwitchToAIName];
             newAI.StartAI();
             CurrentAI = newAI;
         }
     }
     else
     {
         AbstractAI newAI = AIDict [SwitchToAIName];
         newAI.StartAI();
         this.CurrentAI = newAI;
     }
 }
예제 #11
0
        public override ActionState update(AbstractAI ai, float delta)
        {
            ActionState state = ai.IsIdle();

            if (state == null)
            {
                return(this);
            }
            if (ai.currentSenseState != AbstractAI.SenseStates.neverSeenPlayer)
            {
                _lifetime  = (ai.currentSenseState == AbstractAI.SenseStates.playerSpotted) ? 0 : _lifetime;
                _lifetime -= delta;
                if (_lifetime < 0)
                {
                    return(new Search());
                }
            }

            return(state);
        }
 public override void Alert(Vector3 direction, bool origin, Vector3 point, AbstractAI alerter)
 {
     if (health == null || health.IsDead() || alerter == null)
     {
         return;
     }
     if (mode == BehaviorType.patrol)
     {
         SwitchMode(BehaviorType.alert);
     }
     if (origin)
     {
         RaycastHit hit;
         if (Physics.Raycast(transform.position, direction, out hit, 100, ~ManageFactions.instance.deployableShield, QueryTriggerInteraction.Ignore))
         {
             Vector3 investigatePoint = hit.point - direction * investigateDistance;
             if (Physics.Raycast(investigatePoint, Vector3.down, out hit, CurBehavior().data.hoverHeight.x, ~ManageFactions.instance.deployableShield, QueryTriggerInteraction.Ignore))
             {
                 CurBehavior().Alert(direction, origin, hit.point + Vector3.up * CurBehavior().data.hoverHeight.x, alerter);
                 Debug.DrawLine(transform.position, hit.point + Vector3.up * CurBehavior().data.hoverHeight.x, Color.cyan);
             }
             else
             {
                 CurBehavior().Alert(direction, origin, investigatePoint, alerter);
             }
             foreach (Transform unit in ManageFactions.instance.GetAllyFactionList(health.faction))
             {
                 if (unit != null && unit != transform && Vector3.Distance(transform.position, unit.transform.position) < CurBehavior().data.searchRadius)
                 {
                     unit.GetComponent <AbstractAI>().Alert(direction, false, investigatePoint, alerter);
                 }
             }
         }
     }
     else if (Random.Range(0f, 1f) < investigateChance)
     {
         CurBehavior().Alert(direction, origin, point, alerter);
     }
 }
 public override void Alert(Vector3 direction, bool origin, Vector3 point, AbstractAI alerter)
 {
     throw new System.NotImplementedException();
 }
예제 #14
0
파일: Unit.cs 프로젝트: hiyouke/colonist
 /// <summary>
 /// Activate the %SwitchToAIName% AI.
 /// And deactivate the other AI.
 /// </summary>
 public void SwitchAI(string SwitchToAIName)
 {
     if (CurrentAI != null) {
         if(CurrentAI.Name != SwitchToAIName)
         {
            CurrentAI.enabled = false;
            CurrentAI.StopAI();
            AbstractAI newAI = AIDict [SwitchToAIName];
            newAI.StartAI();
            CurrentAI = newAI;
         }
     }
     else
     {
         AbstractAI newAI = AIDict [SwitchToAIName];
         newAI.StartAI();
         this.CurrentAI = newAI;
     }
 }
예제 #15
0
 public ExecuteAIAction(AbstractAI ai, string description, double duration = 0) : base(description, duration)
 {
     this.AI = ai;
 }
예제 #16
0
        public Monster(string name, EnemyData dataObject, MonsterTemplate template, AbstractAI ai) : base(name, ai)
        {
            Data = dataObject;

            Template = template;
        }
예제 #17
0
 public void assumingDirectControl(AbstractAI _AI)
 {
     human = false;
     AI    = _AI;
 }
예제 #18
0
 protected Character(string name, AbstractAI ai) : base(name)
 {
     Level = 1;
     AI    = ai;
 }
예제 #19
0
 public Boss(string name, EnemyData dataObject, BossTemplate template, AbstractAI ai) : base(name, dataObject, template, ai)
 {
 }
예제 #20
0
        public Player(string name, PlayerData dataObject, ClassTemplate template, AbstractAI ai) : base(name, ai)
        {
            Data = dataObject;

            Template = template;
        }
예제 #21
0
 public Npc(string name, EnemyData dataObject, MonsterTemplate template, AbstractAI ai) : base(name, dataObject, template, ai)
 {
 }
예제 #22
0
파일: CameraCtrl.cs 프로젝트: dawnx/dsoul
 void Awake()
 {
     mytransform = this.transform;
     plyaerAI    = AbstractAI.GetTargetAI(player);
 }
 public abstract void Alert(Vector3 direction, bool origin, Vector3 point, AbstractAI alerter);