Example #1
0
        public override void Fire()
        {
            base.Fire();

            if (playerOwner)
            {
                // check brithPostion is suitable

                PathAgent  agent       = owner.pathAgent;
                FixVector3 destination = owner.position + owner.direction.normalized * 3; // 3 meter front of owner
                FixVector3 hitPosition;
                FixVector3 simpleOnMapPoint = FixVector3.zero;

                // mapping destination on navmesh
                bool sampleResult = agent.SamplePosition(destination, out simpleOnMapPoint);
                if (sampleResult)
                {
                    destination = simpleOnMapPoint;
                }

                bool result = agent.Raycast(destination, out hitPosition);
                if (result)
                {
                    // didn't encountered obstruction
                    destination = hitPosition;
                }

                UpdateC2S message = new UpdateC2S();
                message.timestamp = DataManager.GetInstance().GetFrame();
                Operation op = new Operation();
                op.unitId         = id;
                op.targetId       = owner.id;                              // test
                op.unitMetaId     = metaId;                                // test
                op.opType         = OperationType.SyncSkillTargetPosition; // wrong type
                op.x              = destination.vector3.x;
                op.y              = destination.vector3.y;
                op.z              = destination.vector3.z;
                message.operation = op;
                PostBattleMessage(MsgCode.UpdateMessage, message);

                DebugUtils.LogWarning(DebugUtils.Type.AI_Skill, string.Format("skill {0} {1},send sync position ", id, skillName));
            }

            DebugUtils.LogWarning(DebugUtils.Type.AI_Skill, string.Format("Fire skill {0} {1},waiting sync position ", id, skillName));
        }
        private void SprintState(int deltaTime)
        {
            LogicUnit  target   = owner.target;
            FixVector3 position = owner.position;
            PathAgent  agent    = owner.pathAgent;

            if (target != null && target.Alive() && target.id == owner.target.id)
            {
                if (FixVector3.SqrDistance(target.position, owner.targetPosition) > GameConstants.BEGINCHASE_DISTANCE)     // 5f is a testing distance
                {
                    // if target leave the position too far, need to refresh chase path
                    owner.targetPosition = target.position;
                    owner.FindChasePath(owner.target.position);
                    return;
                }

                if (TargetWithInAttackArea())
                {
                    if (target != null && target.Alive() && target.id == owner.target.id)
                    {
                        if (playerOwner)
                        {
                            FixVector3 direction   = (target.position - position).normalized;
                            FixVector3 destination = owner.position + direction * 5f;// Temp distance.

                            FixVector3 hitPosition      = FixVector3.zero;
                            FixVector3 simpleOnMapPoint = FixVector3.zero;

                            // mapping destination on navmesh
                            bool sampleResult = agent.SamplePosition(destination, out simpleOnMapPoint);
                            if (sampleResult)
                            {
                                destination = simpleOnMapPoint;
                            }

                            bool result = agent.Raycast(destination, out hitPosition);
                            if (result)
                            {
                                destination = hitPosition;
                            }

                            DataManager clientData = DataManager.GetInstance();

                            UpdateC2S message = new UpdateC2S();
                            message.timestamp = clientData.GetFrame();
                            Operation op = new Operation();
                            op.playerId       = clientData.GetPlayerId();
                            op.unitId         = id;
                            op.targetId       = owner.id;                              // test
                            op.unitMetaId     = metaId;                                // test
                            op.opType         = OperationType.SyncSkillTargetPosition; // wrong type
                            op.x              = destination.vector3.x;
                            op.y              = destination.vector3.y;
                            op.z              = destination.vector3.z;
                            message.operation = op;
                            PostBattleMessage(MsgCode.UpdateMessage, message);

                            DebugUtils.Log(DebugUtils.Type.AI_Skill, string.Format("YueGuangChongCi sync destination : {0}", destination));
                        }
                    }
                    else
                    {
                        Stop();
                    }
                }
                else
                {
                    if (!owner.CurrentPathAlreadyFinished())
                    {
                        owner.WaypointHandler();
                        FixVector3 d = owner.speed * deltaTime;
                        agent.Move(d);
                    }
                    else
                    {
                        // wait for chase path
                    }
                }
            }
            else
            {
                // Skill will be shut down when target death.
                Stop();
                owner.Idle();
            }
        }