public override bool Execute(object sender, SkillInstance instance, long delta, long curSectionTime)
        {
            GfxSkillSenderInfo senderObj = sender as GfxSkillSenderInfo;
            if (null == senderObj) return false;
            Scene scene = senderObj.Scene;
            EntityInfo obj = senderObj.GfxObj;
            if (null == obj) return false;
            bool isTower = scene.EntityController.GetEntityType(senderObj.GfxObj) == (int)EntityTypeEnum.Tower;
            if (isTower)
                return false;
            if (!m_TargetChecked) {
                m_TargetChecked = true;

                m_RealDuration = m_Duration;
                m_RealVelocity = m_Velocity;
                if (m_RealDuration <= 0) {
                    m_RealDuration += instance.CurSectionDuration;
                }
                if (m_RealDuration <= 0) {
                    LogSystem.Warn("jump duration is 0, skill id:{0} dsl skill id:{1}", senderObj.SkillId, instance.DslSkillId);
                    return false;
                }
                EntityInfo targetObj = senderObj.TargetGfxObj;
                if (null != targetObj) {
                    Vector3 srcPos = obj.GetMovementStateInfo().GetPosition3D();
                    Vector3 targetPos = targetObj.GetMovementStateInfo().GetPosition3D();
                    float degree = Geometry.GetYRadian(new ScriptRuntime.Vector2(srcPos.X, srcPos.Z), new ScriptRuntime.Vector2(targetPos.X, targetPos.Z));
                    ScriptRuntime.Vector2 newPos = new ScriptRuntime.Vector2(targetPos.X, targetPos.Z) + Geometry.GetRotate(new ScriptRuntime.Vector2(m_Offset.X, m_Offset.Z), degree);
                    targetPos = new Vector3(newPos.X, targetPos.Y + m_Offset.Y, newPos.Y);
                    if (m_StopAtTarget == (int)StopAtTargetType.AdjustVelocity) {
                        m_RealVelocity = (long)(1000.0f * (targetPos - srcPos).Length() / m_RealDuration);
                    } else if (m_StopAtTarget == (int)StopAtTargetType.AdjustTime) {
                        m_RealDuration = (long)(1000.0f * (targetPos - targetPos).Length() / m_RealVelocity);
                        CalcYVelocityAndG();
                    }
                    m_Forward = targetPos - srcPos;
                    m_Forward.Normalize();
                } else {
                    m_Forward = Geometry.GetRotate(new Vector3(0, 0, 1), obj.GetMovementStateInfo().GetFaceDir());
                }
                m_InitY = obj.GetMovementStateInfo().PositionY;
            }
            if (curSectionTime < StartTime) {
                return true;
            } else if (curSectionTime <= m_RealDuration) {
                float t = (float)(int)(curSectionTime - StartTime) / 1000.0f;
                float disty = m_YVelocity * t - m_G * t * t / 2;
                float dist = TriggerUtil.ConvertToSecond(delta) * m_RealVelocity;
                Vector3 targetPos = obj.GetMovementStateInfo().GetPosition3D() + m_Forward * dist;
                targetPos.Y = m_InitY + disty;

                TriggerUtil.MoveObjTo(obj, targetPos);
                return true;
            } else {
                return false;
            }
        }
Exemplo n.º 2
0
        public static void AoeQuery(Scene scene, EntityInfo srcObj, EntityInfo targetObj, int aoeType, float range, float angleOrLength, SkillInstance instance, int senderId, int targetType, Vector3 relativeCenter, bool relativeToTarget, MyFunc<float, int, bool> callback)
        {
            float radian;
            Vector3 center;
            Vector3 srcPos = srcObj.GetMovementStateInfo().GetPosition3D();
            if (null != targetObj && relativeToTarget) {
                Vector3 targetPos = targetObj.GetMovementStateInfo().GetPosition3D();
                radian = Geometry.GetYRadian(new ScriptRuntime.Vector2(srcPos.X, srcPos.Z), new ScriptRuntime.Vector2(targetPos.X, targetPos.Z));
                ScriptRuntime.Vector2 newOffset = Geometry.GetRotate(new ScriptRuntime.Vector2(relativeCenter.X, relativeCenter.Z), radian);
                center = targetPos + new Vector3(newOffset.X, relativeCenter.Y, newOffset.Y);
            } else {
                radian = srcObj.GetMovementStateInfo().GetFaceDir();
                ScriptRuntime.Vector2 newOffset = Geometry.GetRotate(new ScriptRuntime.Vector2(relativeCenter.X, relativeCenter.Z), radian);
                center = srcPos + new Vector3(newOffset.X, relativeCenter.Y, newOffset.Y);
            }

            if (aoeType == (int)SkillAoeType.Circle || aoeType == (int)SkillAoeType.Sector) {
                angleOrLength = Geometry.DegreeToRadian(angleOrLength);
                scene.KdTree.Query(center.X, center.Y, center.Z, range, (float distSqr, KdTreeObject kdTreeObj) => {
                    int targetId = kdTreeObj.Object.GetId();
                    if (targetType == (int)SkillTargetType.Enemy && CharacterRelation.RELATION_ENEMY == scene.EntityController.GetRelation(senderId, targetId) ||
                        targetType == (int)SkillTargetType.Friend && CharacterRelation.RELATION_FRIEND == scene.EntityController.GetRelation(senderId, targetId)) {
                        bool isMatch = false;
                        if (aoeType == (int)SkillAoeType.Circle) {
                            isMatch = true;
                        } else {
                            ScriptRuntime.Vector2 u = Geometry.GetRotate(new ScriptRuntime.Vector2(0, 1), radian);
                            isMatch = Geometry.IsSectorDiskIntersect(new ScriptRuntime.Vector2(center.X, center.Z), u, angleOrLength / 2, range, new ScriptRuntime.Vector2(kdTreeObj.Position.X, kdTreeObj.Position.Z), kdTreeObj.Radius);
                        }
                        if (isMatch) {
                            if (!callback(distSqr, kdTreeObj.Object.GetId())) {
                                return false;
                            }
                        }
                    }
                    return true;
                });
            } else {
                ScriptRuntime.Vector2 angleu = Geometry.GetRotate(new ScriptRuntime.Vector2(0, angleOrLength), radian);
                ScriptRuntime.Vector2 c = new ScriptRuntime.Vector2(center.X, center.Z) + angleu / 2;
                scene.KdTree.Query(c.X, 0, c.Y, range + angleOrLength / 2, (float distSqr, GameFramework.KdTreeObject kdTreeObj) => {
                    int targetId = kdTreeObj.Object.GetId();
                    if (targetType == (int)SkillTargetType.Enemy && CharacterRelation.RELATION_ENEMY == scene.EntityController.GetRelation(senderId, targetId) ||
                        targetType == (int)SkillTargetType.Friend && CharacterRelation.RELATION_FRIEND == scene.EntityController.GetRelation(senderId, targetId)) {
                        bool isMatch = false;
                        if (aoeType == (int)SkillAoeType.Capsule) {
                            isMatch = Geometry.IsCapsuleDiskIntersect(new ScriptRuntime.Vector2(center.X, center.Z), angleu, range, new ScriptRuntime.Vector2(kdTreeObj.Position.X, kdTreeObj.Position.Z), kdTreeObj.Radius);
                        } else {
                            ScriptRuntime.Vector2 half = new ScriptRuntime.Vector2(range / 2, angleOrLength / 2);
                            isMatch = Geometry.IsObbDiskIntersect(c, half, radian, new ScriptRuntime.Vector2(kdTreeObj.Position.X, kdTreeObj.Position.Z), kdTreeObj.Radius);
                        }
                        if (isMatch) {
                            if (!callback(distSqr, kdTreeObj.Object.GetId())) {
                                return false;
                            }
                        }
                    }
                    return true;
                });
            }
        }