internal static Vector3 TransformPoint(Vector3 pos, Vector3 offset, float radian) { ScriptRuntime.Vector2 newOffset = Geometry.GetRotate(new ScriptRuntime.Vector2(offset.X, offset.Z), radian); Vector3 result = pos + new Vector3(newOffset.X, offset.Y, newOffset.Y); return(result); }
public static bool GetResult(out ScriptRuntime.Vector2 res) { object obj; bool ret = GetResult(out obj); res = (ScriptRuntime.Vector2)obj; return(ret); }
static public int constructor(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); ScriptRuntime.Vector2 o; if (argc == 3) { System.Single a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); o = new ScriptRuntime.Vector2(a1, a2); pushValue(l, true); pushValue(l, o); return(2); } else if (argc == 2) { System.Single a1; checkType(l, 2, out a1); o = new ScriptRuntime.Vector2(a1); pushValue(l, true); pushValue(l, o); return(2); } else if (argc <= 1) { o = new ScriptRuntime.Vector2(); pushValue(l, true); pushObject(l, o); return(2); } return(error(l, "New object failed.")); } catch (Exception e) { return(error(l, e)); } }
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); } }
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; } }
public bool Execute(object sender, SkillInstance instance, long delta, long curSectionTime) { GfxSkillSenderInfo senderObj = sender as GfxSkillSenderInfo; if (null == senderObj) { return(false); } if (senderObj.ConfigData.type == (int)SkillOrImpactType.Skill) { return(false);//track只能在impact或buff里使用 } GameObject obj = senderObj.GfxObj; if (null != obj) { if (curSectionTime >= m_TriggerProxy.StartTime) { if (!m_IsStarted) { m_IsStarted = true; Vector3 dest; string trackBone = m_TrackBone.Get(instance); m_BoneTransform = Utility.FindChildRecursive(obj.transform, trackBone); if (null != m_BoneTransform) { dest = m_BoneTransform.position; } else { dest = obj.transform.position; dest.y += 1.5f; LogSystem.Warn("[skill:{0} dsl skill id:{1}] trackbullet bone {2} can't find.", senderObj.SkillId, instance.DslSkillId, trackBone); } m_StartPos = EntityController.Instance.GetImpactSenderPosition(senderObj.ObjId, senderObj.SkillId, senderObj.Seq); object speedObj; if (instance.Variables.TryGetValue("emitSpeed", out speedObj)) { m_Speed = (float)speedObj; } else { return(false); } long duration = m_Duration.Get(instance); m_Lifetime = duration / 1000.0f; if (Geometry.DistanceSquare(m_StartPos.x, m_StartPos.z, dest.x, dest.z) > 0.01f) { m_TargetPos = Utility.FrontOfTarget(dest, m_StartPos, m_Speed * m_Lifetime); } else { m_TargetPos = obj.transform.TransformPoint(0, 0, m_Speed * m_Lifetime); } long newSectionDuration = m_TriggerProxy.StartTime + (long)(m_Lifetime * 1000); if (instance.CurSectionDuration < newSectionDuration) { instance.SetCurSectionDuration(newSectionDuration); } Quaternion dir; object dirObj; if (instance.Variables.TryGetValue("emitDir", out dirObj)) { dir = (Quaternion)dirObj; } else { dir = Quaternion.identity; } Vector3 scale; object scaleObj; if (instance.Variables.TryGetValue("emitScale", out scaleObj)) { scale = (Vector3)scaleObj; } else { scale = Vector3.one; } Vector3 lookDir = dest - m_StartPos; Quaternion q = Quaternion.LookRotation(lookDir); m_ControlPos = m_StartPos + Vector3.Scale(q * dir * Vector3.forward, scale * lookDir.magnitude * 0.5f); string effectPath = SkillParamUtility.RefixResourceVariable("emitEffect", instance, senderObj.ConfigData.resources); m_Effect = ResourceSystem.Instance.NewObject(effectPath, m_Lifetime) as GameObject; if (null != m_Effect) { senderObj.TrackEffectObj = m_Effect; TriggerUtil.SetObjVisible(m_Effect, true); m_Effect.SetActive(false); m_Effect.transform.position = m_StartPos; m_Effect.transform.localRotation = q; m_Effect.SetActive(true); EffectManager em = instance.CustomDatas.GetData <EffectManager>(); if (em == null) { em = new EffectManager(); instance.CustomDatas.AddData <EffectManager>(em); } em.AddEffect(m_Effect); em.SetParticleSpeed(instance.EffectScale); } else { if (string.IsNullOrEmpty(effectPath)) { LogSystem.Warn("[skill:{0} dsl skill id:{1}] trackbullet effect is empty.", senderObj.SkillId, instance.DslSkillId); } else { LogSystem.Warn("[skill:{0} dsl skill id:{1}] trackbullet effect {2} can't find.", senderObj.SkillId, instance.DslSkillId, effectPath); } } } else if (null != m_Effect) { Vector3 dest; if (null != m_BoneTransform) { dest = m_BoneTransform.position; } else { dest = obj.transform.position; dest.y += 1.5f; } dest = Utility.FrontOfTarget(m_StartPos, dest, 0.1f); //m_Effect.transform.position = Vector3.MoveTowards(m_Effect.transform.position, m_TargetPos, m_RealSpeed * Time.deltaTime); m_Effect.transform.position = Utility.GetBezierPoint(m_StartPos, m_ControlPos, m_TargetPos, (curSectionTime - m_TriggerProxy.StartTime) / 1000.0f / m_Lifetime); var pos = m_Effect.transform.position; if (!m_IsHit) { float distSqr = float.MaxValue; if (m_LastPos.sqrMagnitude > Geometry.c_FloatPrecision) { ScriptRuntime.Vector2 np; ScriptRuntime.Vector2 targetPos = new ScriptRuntime.Vector2(dest.x, dest.z); ScriptRuntime.Vector2 lastPos = new ScriptRuntime.Vector2(m_LastPos.x, m_LastPos.z); distSqr = Geometry.PointToLineSegmentDistanceSquare(targetPos, lastPos, new ScriptRuntime.Vector2(pos.x, pos.z), out np); } else { distSqr = (dest - pos).sqrMagnitude; } m_LastPos = pos; if (distSqr <= m_BulletRadiusSquare) { float curTime = Time.time; float interval = m_DamageInterval.Get(instance) / 1000.0f; if (m_LastTime + interval <= curTime) { m_LastTime = curTime; m_HitEffectRotation = Quaternion.LookRotation(m_StartPos - dest); int impactId = TriggerUtil.GetSkillImpactId(instance.Variables, senderObj.ConfigData); Dictionary <string, object> args; TriggerUtil.CalcImpactConfig(0, impactId, instance, senderObj.ConfigData, out args); if (args.ContainsKey("hitEffectRotation")) { args["hitEffectRotation"] = m_HitEffectRotation; } else { args.Add("hitEffectRotation", m_HitEffectRotation); } EntityController.Instance.TrackSendImpact(senderObj.ObjId, senderObj.SkillId, senderObj.Seq, impactId, args); //m_IsHit = true; } } } if (curSectionTime > m_TriggerProxy.StartTime + m_Lifetime * 1000) { m_Effect.SetActive(false); ResourceSystem.Instance.RecycleObject(m_Effect); m_Effect = null; instance.StopCurSection(); return(false); } } else { return(false); } return(true); } else { return(true); } } else { instance.StopCurSection(); return(false); } }
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); }); } }
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; }); } }