/// <summary> /// 释放方向技能 /// </summary> /// <param name="self"></param> /// <param name="spellSkill"></param> /// <param name="point"></param> public static void SpellWithDirect(this SpellComponent self, SkillAbility spellSkill, Vector3 point) { if (!self.Enable) { return; } if (self.CurSkillConfigId != 0) { return; } if (!spellSkill.CanUse()) { return; } self.CurSkillConfigId = spellSkill.ConfigId; var nowpos = self.GetParent <CombatUnitComponent>().unit.Position; point = new Vector3(point.x, nowpos.y, point.z); var Rotation = Quaternion.LookRotation(point - nowpos, Vector3.up); self.Para = new SkillPara(); self.Para.Position = point; self.Para.Rotation = Rotation; self.Para.From = self.GetParent <CombatUnitComponent>(); self.Para.Ability = spellSkill; self.GetSkill().LastSpellTime = TimeHelper.ServerNow(); self.PlayNextSkillStep(0); }
/// <summary> /// 释放对目标技能 /// </summary> /// <param name="self"></param> /// <param name="spellSkill"></param> /// <param name="targetEntity"></param> public static void SpellWithTarget(this SpellComponent self, SkillAbility spellSkill, CombatUnitComponent targetEntity) { if (!self.Enable) { return; } if (self.CurSkillConfigId != 0) { return; } if (!spellSkill.CanUse()) { return; } self.CurSkillConfigId = spellSkill.ConfigId; var nowpos = self.GetParent <CombatUnitComponent>().unit.Position; var nowpos2 = targetEntity.unit.Position; if (Vector2.Distance(new Vector2(nowpos.x, nowpos.z), new Vector2(nowpos2.x, nowpos2.z)) > spellSkill.SkillConfig.PreviewRange[0]) { return; } self.Para = new SkillPara(); self.Para.From = self.GetParent <CombatUnitComponent>(); self.Para.Ability = spellSkill; self.Para.To = targetEntity; self.GetSkill().LastSpellTime = TimeHelper.ServerNow(); self.PlayNextSkillStep(0); }
/// <summary> /// 释放对点技能 /// </summary> /// <param name="self"></param> /// <param name="spellSkill"></param> /// <param name="point"></param> public static void SpellWithPoint(this SpellComponent self, SkillAbility spellSkill, Vector3 point) { if (!self.Enable) { return; } if (self.CurSkillConfigId != 0) { return; } if (!spellSkill.CanUse()) { return; } self.CurSkillConfigId = spellSkill.ConfigId; var nowpos = self.GetParent <CombatUnitComponent>().unit.Position; if (Vector2.Distance(new Vector2(nowpos.x, nowpos.z), new Vector2(point.x, point.z)) > spellSkill.SkillConfig.PreviewRange[0]) { var dir = new Vector3(point.x - nowpos.x, 0, point.z - nowpos.z).normalized; point = nowpos + dir * spellSkill.SkillConfig.PreviewRange[0]; } self.Para = new SkillPara(); self.Para.Position = point; self.Para.From = self.GetParent <CombatUnitComponent>(); self.Para.Ability = spellSkill; self.GetSkill().LastSpellTime = TimeHelper.ServerNow(); self.PlayNextSkillStep(0); }
public void Clear() { Position = Vector3.zero; Rotation = Quaternion.identity; From = null; To = null; CostId.Clear(); Cost.Clear(); Ability = null; StepPara.Clear(); }
public static void UseSkill(this SkillAbility skill, Vector3 pos, long id = 0) { C2M_UseSkill msg = new C2M_UseSkill() { SkillConfigId = skill.ConfigId, X = pos.x, Y = pos.y, Z = pos.z, Id = id }; skill.ZoneScene().GetComponent <SessionComponent>().Session.Send(msg); }
/// <summary> /// 释放对目标技能 /// </summary> /// <param name="self"></param> /// <param name="spellSkill"></param> /// <param name="targetEntity"></param> public static void SpellWithTarget(this MoveAndSpellComponent self, SkillAbility spellSkill, CombatUnitComponent targetEntity) { if (!spellSkill.CanUse()) { return; } if (self.Skill != null && self.Skill != spellSkill)//换新技能释放了 { self.Skill = null; self.Target = null; TimerComponent.Instance.Remove(ref self.TimerId); return; } var unit = self.GetParent <CombatUnitComponent>().unit; var nowpos = unit.Position; var point = targetEntity.unit.Position; if (Vector2.Distance(new Vector2(nowpos.x, nowpos.z), new Vector2(point.x, point.z)) > spellSkill.SkillConfig.PreviewRange[0]) { self.MoveTo(unit, point); if (self.Skill == null) { self.Skill = spellSkill; self.Target = targetEntity; self.TimerId = TimerComponent.Instance.NewFrameTimer(TimerType.MoveAndSpellSkill, self); } return; } if (self.Skill != null) { self.Skill = null; self.Target = null; TimerComponent.Instance.Remove(ref self.TimerId); unit.Stop(0); } #if SERVER //单机去掉 self.Parent.GetComponent <SpellComponent>().SpellWithTarget(spellSkill, targetEntity); #else spellSkill.UseSkill(Vector3.zero, targetEntity.Id); #endif }
GetSkillStepInfo(this SkillStepComponent self, int configId, SkillAbility skill) { bool needinit = false; if (!self.TimeLine.ContainsKey(configId)) { needinit = true; self.TimeLine[configId] = new List <int>(); } skill.TimeLine = self.TimeLine[configId]; if (!self.StepType.ContainsKey(configId)) { needinit = true; self.StepType[configId] = new List <int>(); } skill.StepType = self.StepType[configId]; if (!self.Params.ContainsKey(configId)) { needinit = true; self.Params[configId] = new List <object[]>(); } skill.Paras = self.Params[configId]; if (needinit) { Log.Info("GetSkillStepInfo " + configId); var config = SkillConfigCategory.Instance.Get(configId); #if NOT_UNITY var text = File.ReadAllText($"../Skill/{config.JsonFile}.json"); #else var text = (await ResourcesComponent.Instance.LoadAsync <TextAsset>($"Skill/Config/{config.JsonFile}.json")).text; #endif var list = JsonHelper.FromJson <List <SkillStep> >(text); for (int i = 0; i < list.Count; i++) { self.TimeLine[configId].Add(list[i].Trigger); self.StepType[configId].Add(list[i].Type); self.Params[configId].Add(list[i].Params); } } }
/// <summary> /// 绑定技能与按键 /// </summary> /// <param name="self"></param> /// <param name="keyCode"></param> /// <param name="ability"></param> public static void BindSkillKeyCode(this SpellPreviewComponent self, int keyCode, SkillAbility ability) { self.InputSkills[keyCode] = ability; }
public static bool TryGetSkillAbility(this CombatUnitComponent self, int configId, out SkillAbility skill) { if (self.IdSkillMap.ContainsKey(configId)) { skill = self.GetChild <SkillAbility>(self.IdSkillMap[configId]); return(true); } skill = null; return(false); }