IEnumerator Shoot() { var trans = GetAttr().transform; var enemy = SkillLogic.FindNearestEnemy(trans.gameObject); var physic = GetAttr().GetComponent <GeneraPhysic>(); Log.Sys("FindEnemyIs: " + enemy); if (enemy != null) { var dir = enemy.transform.position - trans.position; dir.y = 0; Log.Sys("EnemyIs: " + dir); //forward = dir; forward = tower.forward; //physic.TurnToImmediately(dir); physic.TurnTower(dir); } else { forward = trans.forward; physic.TurnTower(forward); } attackAniName = GetAttackAniName(); /* * var realAttackTime = activeSkill.skillData.AttackAniTime / GetAttr().GetSpeedCoff(); * var rate = GetAttr().animation [attackAniName].length / realAttackTime; * PlayAni(attackAniName, rate, WrapMode.Once); */ yield return(GetAttr().StartCoroutine(WaitForAttackAnimation(GetAttr().GetComponent <Animation>()))); yield return(new WaitForSeconds(0.1f)); }
/// <summary> /// 首先判断场景模式: /// 普通场景 /// 网络场景 /// </summary> /// <returns><c>true</c> if is enemy the specified a b; otherwise, <c>false</c>.</returns> /// <param name="a">The alpha component.</param> /// <param name="b">The blue component.</param> public static bool IsEnemy(GameObject a, GameObject b) { var scene = WorldManager.worldManager.GetActive(); if (scene.IsNet) { //var battr = NetworkUtil.GetAttr(b); return(scene.IsEnemy(a, b)); /* * if (a != b) * { * return true; * } else * { * return false; * } */ } var enemyTag = SkillLogic.GetEnemyTag(a.tag); if (b.tag == enemyTag) { return(true); } return(false); }
//直接使用技能不切换状态 public static SkillStateMachine UseSkill(NpcAttribute attacker) { var activeSkill = attacker.GetComponent <SkillInfoComponent>().GetActiveSkill(); var skillStateMachine = SkillLogic.CreateSkillStateMachine(attacker.gameObject, activeSkill.skillData, attacker.transform.position); return(skillStateMachine); }
public override void EnterState() { base.EnterState(); cmd = aiCharacter.lastCmd; aiCharacter.blackboard[AIParam.SkillCmd] = new AIEvent() { cmd = cmd.proto }; var target = cmd.skillAction.Target; var targetPlayer = ObjectManager.objectManager.GetPlayer(target); activeSkill = GetAttr().GetComponent <SkillInfoComponent>().GetActiveSkill(); skillStateMachine = SkillLogic.CreateSkillStateMachine(GetAttr().gameObject, activeSkill.skillData, GetAttr().transform.position, targetPlayer); skillStateMachine.cmd = cmd.proto; var time = Util.FrameToFloat(aiCharacter.lastCmd.skillAction.RunFrame); var dir = cmd.skillAction.Dir; var physics = aiCharacter.GetAttr().GetComponent <IPhysicCom>(); physics.TurnToDir(dir); holdTime = time; var npcConfig = aiCharacter.attribute.npcConfig; var actConfig = npcConfig.GetActionBySkillId(cmd.proto.SkillAction.SkillId); if (actConfig == null) { Debug.LogError("NpcSkill:" + MobaUtil.PrintObj(npcConfig) + ":" + cmd.proto); } var aniName = actConfig.aniName; aiCharacter.PlayAniInTime(aniName, time); }
private void Update() { if (!runner || !runner.stateMachine || !runner.stateMachine.attacker || runner.stateMachine.isStop) { return; } var me = runner.stateMachine.attacker; Collider[] hitColliders; hitColliders = Physics.OverlapSphere(me.transform.position, radius, SkillDamageCaculate.GetDamageLayer()); for (int i = 0; i < hitColliders.Length; i++) { var enemy = NetworkUtil.GetAttr(hitColliders[i].gameObject); if (enemy != null && SkillLogic.IsEnemy(me, enemy.gameObject)) { if (!hurtEnemy.Contains(enemy.gameObject)) { var dir = enemy.transform.position - me.transform.position; dir.y = 0; var cos = Vector3.Dot(dir.normalized, transform.forward); Log.AI("DamageHit " + runner.stateMachine.name + " " + enemy.name + " cos " + cos + " a " + cosAngle); if (cos > cosAngle) { DoDamage(enemy.gameObject); hurtEnemy.Add(enemy.gameObject); } } } } Log.AI("Check Damage Shape " + runner.stateMachine.name); }
IEnumerator CastSkill(GameObject targetPlayer) { GetAttr().GetComponent <SkillInfoComponent> ().SetRandomActive(); var activeSkill = GetAttr().GetComponent <SkillInfoComponent>().GetActiveSkill(); var skillStateMachine = SkillLogic.CreateSkillStateMachine(GetAttr().gameObject, activeSkill.skillData, GetAttr().transform.position, targetPlayer); Log.AI("Skill SetAni " + activeSkill.skillData.AnimationName); var realAttackTime = activeSkill.skillData.AttackAniTime / GetAttr().GetSpeedCoff(); var rate = GetAttr().GetComponent <Animation>()[activeSkill.skillData.AnimationName].length / realAttackTime; SetAni(activeSkill.skillData.AnimationName, rate, WrapMode.Once); var physic = GetAttr().GetComponent <PhysicComponent>(); while (GetAttr().GetComponent <Animation>().isPlaying&& !quit) { if (CheckEvent()) { break; } //自动向目标旋转 Vector3 dir = targetPlayer.transform.position - GetAttr().transform.position; dir.y = 0; var newDir = Vector3.Slerp(GetAttr().transform.forward, dir, Time.deltaTime * FastRotateSpeed); physic.TurnTo(newDir); yield return(null); } skillStateMachine.Stop(); }
private IEnumerator WaitForAttackAnimation(Animation animation) { var skillStateMachine = SkillLogic.CreateSkillStateMachine(GetAttr().gameObject, activeSkill.skillData, tower.transform.position); skillStateMachine.SetForwardDirection(forward); //skillStateMachine.SetRelativePos(tower.localPosition); Log.AI("Wait For Combat Animation"); float passTime = 0; //yield return new WaitForSeconds(0.1f); yield return(null); MyEventSystem.PushLocalEventStatic(GetAttr().GetLocalId(), MyEvent.EventType.EventTrigger); var realAttackTime = activeSkill.skillData.AttackAniTime / GetAttr().GetSpeedCoff(); //realAttackTime -= 0.3f; do { if (passTime >= realAttackTime * 0.8f) { break; } passTime += Time.deltaTime; yield return(null); } while(!quit); Log.Ani("Animation is Playing stop "); skillStateMachine.Stop(); }
public static void AddStaticShootBuff(GameObject who, int skillId, Vector3 pos) { var skill = Util.GetSkillData(skillId, 1); var skillInfo = SkillLogic.GetSkillInfo(skill); var evt = skillInfo.eventList[0]; NetDateInterface.FastAddBuff(evt.affix, who, who, skillId, evt.EvtId); }
public static void RemoveSkillBuff(GameObject who, int skillId) { var skill = Util.GetSkillData(skillId, 1); var skillInfo = SkillLogic.GetSkillInfo(skill); var evt = skillInfo.eventList [0]; who.GetComponent <BuffComponent>().RemoveBuff(evt.affix.effectType); }
public static bool AddSkillBuff(GameObject who, int skillId, Vector3 pos) { var skill = Util.GetSkillData(skillId, 1); var skillInfo = SkillLogic.GetSkillInfo(skill); var evt = skillInfo.eventList [0]; var ret = who.GetComponent <BuffComponent>().AddBuff(evt.affix, pos); return(ret); }
public override void EnterState() { base.EnterState(); Log.AI("Enter Skill State "); //启动技能状态机 启动动画 activeSkill = GetAttr().GetComponent <SkillInfoComponent>().GetActiveSkill(); skillStateMachine = SkillLogic.CreateSkillStateMachine(GetAttr().gameObject, activeSkill.skillData, GetAttr().transform.position); }
public void OnlyShowDeadEffect() { _characterState = CharacterState.Dead; var sdata = GetDeadSkill(); if (sdata != null) { StartCoroutine(SkillLogic.MakeSkill(gameObject, sdata, transform.position)); } }
public override void EnterState() { base.EnterState(); Log.AI("Enter Pet Skill State "); //启动技能状态机 启动动画 activeSkill = GetAttr().GetComponent <SkillInfoComponent>().GetActiveSkill(); skillStateMachine = SkillLogic.CreateSkillStateMachine(GetAttr().gameObject, activeSkill.skillData, GetAttr().transform.position, null); SetAni(activeSkill.skillData.AnimationName, 1f, WrapMode.Once); }
/// <summary> /// 技能的朝向 /// 攻击目标由服务器决定 /// </summary> /// <param name="skillId"></param> /// <param name="skillLevel"></param> public static void FastUseSkill(int skillId, int skillLevel) { Log.Sys("FastUseSkill: " + skillId + " lev " + skillLevel); var sc = WorldManager.worldManager.GetActive(); if (sc.IsNet && sc.CanFight) { var me = ObjectManager.objectManager.GetMyPlayer(); var pos = me.transform.position; var dir = (int)me.transform.localRotation.eulerAngles.y; /* * var tower = me.GetComponent<TankPhysicComponent>().tower; * if (tower == null) * { * return; * } * var dir = (int)tower.transform.eulerAngles.y; */ var cg = CGPlayerCmd.CreateBuilder(); var skInfo = SkillAction.CreateBuilder(); skInfo.Who = ObjectManager.objectManager.GetMyServerID(); skInfo.SkillId = skillId; skInfo.SkillLevel = skillLevel; var ip = NetworkUtil.ConvertPos(pos); skInfo.X = ip[0]; skInfo.Y = ip[1]; skInfo.Z = ip[2]; skInfo.Dir = dir; /* * if (skillId == 1) * { * var attribute = me.GetComponent<NpcAttribute>(); * skInfo.IsStaticShoot = attribute.GetStaticShootBuff(); * } */ var target = SkillLogic.FindNearestEnemy(me); var targetId = 0; if (target != null) { targetId = target.GetComponent <NpcAttribute>().GetNetView().GetServerID(); } skInfo.Target = targetId; cg.SkillAction = skInfo.Build(); cg.Cmd = "Skill"; //sc.BroadcastMsg(cg); sc.BroadcastKCP(cg); } }
void OnEvent(MyEvent evt) { if (evt.type == MyEvent.EventType.HitTarget) { var target = evt.target; //在目标身上立即添加这个武器Buff造成的伤害Buff //Hurt Direct 但是伤害数值0 WeaponDamagePCT= 0 var skmachine = SkillLogic.CreateSkillStateMachine(obj, Util.GetSkillData( System.Convert.ToInt32(affix.GetPara(PairEnum.Abs)), 1), Vector3.zero, target); } }
/// <summary> ///子弹伤害计算也交给skillLayoutRunner执行 /// </summary> /// <param name="other">Other.</param> private void DoDamage(Collider other) { var oattr = NetworkUtil.GetAttr(other.gameObject); if (oattr != null && SkillLogic.IsEnemyForBullet(attacker, oattr.gameObject) && !missileData.DontHurtObject) { //MakeSound(); if (runner != null) { runner.DoDamage(oattr.gameObject); } } }
public override void EnterState() { base.EnterState(); Log.AI("sentry Enter Skill State "); activeSkill = GetAttr().GetComponent <SkillInfoComponent>().GetActiveSkill(); skillStateMachine = SkillLogic.CreateSkillStateMachine(GetAttr().gameObject, activeSkill.skillData, GetAttr().transform.position, aiCharacter.GetEnemy()); SetAni(activeSkill.skillData.AnimationName, 1f, WrapMode.Once); if (GetAttr().ObjUnitData.AttachToMaster) { GetAttr().StartCoroutine(TraceMaster()); } }
protected override bool CheckEventOverride(MyAnimationEvent.Message msg) { Log.AI("CheckEventOverride " + msg.type); if (msg.type == MyAnimationEvent.MsgType.BOMB) { Log.AI("CheckBombEvent " + msg.type); var sdata = Util.GetSkillData(137, 1); aiCharacter.GetAttr().StartCoroutine(SkillLogic.MakeSkill(aiCharacter.GetAttr().gameObject, sdata, GetAttr().transform.position)); aiCharacter.ChangeState(AIStateEnum.DEAD); return(true); } return(base.CheckEventOverride(msg)); }
public static bool AddBuffWithNet(GameObject who, int skillId, Vector3 pos, int pid = 0) { var skill = Util.GetSkillData(skillId, 1); var skillInfo = SkillLogic.GetSkillInfo(skill); var evt = skillInfo.eventList [0]; //var ret = who.GetComponent<BuffComponent>().AddBuff(evt.affix, pos, pid); //if (ret) { NetDateInterface.FastAddBuff(evt.affix, who, who, skillId, evt.EvtId); } //return ret; return(true); }
public override void EnterState() { base.EnterState(); cmd = aiCharacter.lastCmd; activeSkill = GetAttr().GetComponent <SkillInfoComponent>().GetActiveSkill(); var target = cmd.skillAction.Target; var targetPlayer = ObjectManager.objectManager.GetPlayer(target); skillStateMachine = SkillLogic.CreateSkillStateMachine(GetAttr().gameObject, activeSkill.skillData, GetAttr().transform.position, targetPlayer); var time = Util.FrameToFloat(aiCharacter.lastCmd.skillAction.RunFrame); var dir = cmd.skillAction.Dir; holdTime = time; }
public void NetworkBuff(GCPlayerCmd cmd) { var sk = Util.GetSkillData(cmd.BuffInfo.SkillId, 1); var skConfig = SkillLogic.GetSkillInfo(sk); var evt = skConfig.GetEvent(cmd.BuffInfo.EventId); if (evt != null) { var pos = cmd.BuffInfo.AttackerPosList; var px = pos [0] / 100.0f; var py = pos [1] / 100.0f; var pz = pos [2] / 100.0f; gameObject.GetComponent <BuffComponent>().AddBuff(evt.affix, new Vector3(px, py, pz)); } }
/// <summary> ///子弹伤害计算也交给skillLayoutRunner执行 /// </summary> /// <param name="other">Other.</param> void DoDamage(Collider other) { if (SkillLogic.IsEnemy(runner.stateMachine.attacker, other.gameObject)) { var skillData = runner.stateMachine.skillFullData.skillData; if (!string.IsNullOrEmpty(skillData.HitSound)) { BackgroundSound.Instance.PlayEffect(skillData.HitSound); } if (runner != null) { runner.DoDamage(other.gameObject); } } }
IEnumerator AdjustTower(NpcAttribute attr) { var passTime = 0.0f; var trans = attr.transform; while (true) { var curDir = transform.forward; curDir.y = 0; var forwardDir = trans.forward; var diffDir = Quaternion.FromToRotation(curDir, forwardDir); var diffY = diffDir.eulerAngles.y; if (diffY > 180) { diffY = diffY - 360; } if (diffY < -180) { diffY = 360 + diffY; } var dy = Mathf.Clamp(diffY, -maxRotateChange, maxRotateChange); var curRot = transform.rotation.eulerAngles.y; var tarDir = Quaternion.Euler(new Vector3(0, curRot + dy, 0)); transform.rotation = tarDir; //yield return null; yield return(new WaitForFixedUpdate()); if (Mathf.Abs(diffY) <= 0.1f) { break; } passTime += Time.deltaTime; if (passTime >= 1) { var tempEnemy = SkillLogic.FindNearestEnemy(trans.gameObject); if (tempEnemy != null) { break; } passTime = 0; } } }
/// <summary> /// 首先判断场景模式: /// 普通场景 /// 网络场景 /// </summary> /// <returns><c>true</c> if is enemy the specified a b; otherwise, <c>false</c>.</returns> /// <param name="a">The alpha component.</param> /// <param name="b">The blue component.</param> public static bool IsEnemy(GameObject a, GameObject b) { var scene = WorldManager.worldManager.GetActive(); if (scene.IsNet) { return(scene.IsEnemy(a, b)); } var enemyTag = SkillLogic.GetEnemyTag(a.tag); if (b.tag == enemyTag) { return(true); } return(false); }
IEnumerator DamageNear() { while (!IsDie) { yield return(new WaitForSeconds(3)); BackgroundSound.Instance.PlayEffect("skill/fireimp1"); var stateMachine = SkillLogic.CreateSkillStateMachine(obj, Util.GetSkillData(129, 1), obj.transform.position, null); if (affix.fireParticle != null) { var evt = new MyEvent(MyEvent.EventType.SpawnParticle); evt.particleOffset = new Vector3(0, 1, 0); evt.particle2 = affix.fireParticle; evt.boneName = null; evt.player = obj; MyEventSystem.myEventSystem.PushEvent(evt); } } }
//自适应炮塔调整 IEnumerator AutoEnemy() { var attr = NetworkUtil.GetAttr(gameObject); var phy = attr.GetComponent <GeneraPhysic>(); var trans = attr.transform; while (true) { var enemy = SkillLogic.FindNearestEnemy(trans.gameObject); if (enemy != null) { yield return(StartCoroutine(AutoTarget(trans, enemy))); } else { yield return(StartCoroutine(AdjustTower(attr))); } yield return(new WaitForSeconds(0.3f)); } }
//根据配置锁定目标 开火 //最近攻击目标 //目标惯性持续目标多久 目标脱离攻击范围多久仍然持续攻击 // IEnumerator AutoTarget(Transform trans, GameObject enemy) { var attr = trans.GetComponent <NpcAttribute>(); var passTime = 0.0f; while (true) { var dir = enemy.transform.position - trans.position; dir.y = 0; var curDir = transform.forward; curDir.y = 0; var forwardDir = dir; var diffDir = Quaternion.FromToRotation(curDir, forwardDir); var diffY = diffDir.eulerAngles.y; if (diffY > 180) { diffY = diffY - 360; } if (diffY < -180) { diffY = 360 + diffY; } var dy = Mathf.Clamp(diffY, -maxRotateChange, maxRotateChange); var curRot = transform.rotation.eulerAngles.y; var tarDir = Quaternion.Euler(new Vector3(0, curRot + dy, 0)); transform.rotation = tarDir; yield return(new WaitForFixedUpdate()); passTime += Time.deltaTime; if (passTime >= 1) { var tempEnemy = SkillLogic.FindNearestEnemy(trans.gameObject); if (tempEnemy != enemy) { break; } passTime = 0; } } }
//为玩家增加Buff void OnTriggerEnter(Collider other) { if (NetworkUtil.IsNetMaster()) { if (other.tag == GameTag.Player) { //击退技能 var pos = other.transform.position; var otherGo = other.gameObject; var skill = Util.GetSkillData(140, 1); var skillInfo = SkillLogic.GetSkillInfo(skill); var evt = skillInfo.eventList[0]; var ret = gameObject.GetComponent <BuffComponent>().AddBuff(evt.affix, pos); if (ret) { NetDateInterface.FastAddBuff(evt.affix, otherGo, gameObject, skill.Id, evt.EvtId); } } } }
/// <summary> ///子弹伤害计算也交给skillLayoutRunner执行 /// </summary> /// <param name="other">Other.</param> void DoDamage(Collider other) { var oattr = other.GetComponent <NpcAttribute>(); if (oattr == null) { oattr = other.transform.parent.GetComponent <NpcAttribute>(); } if (SkillLogic.IsEnemyForBullet(attacker, oattr.gameObject) && !missileData.DontHurtObject) { if (!string.IsNullOrEmpty(skillData.HitSound)) { BackgroundSound.Instance.PlayEffect(skillData.HitSound); } if (runner != null) { runner.DoDamage(oattr.gameObject); } } }
void OnTriggerEnter(Collider other) { Log.Sys("MoveBlock Enter : " + other.gameObject); if (NetworkUtil.IsNetMaster()) { if (other.tag == GameTag.Player) { //击退技能 var pos = other.transform.position; var otherGo = other.gameObject; //dy dx 比较 那个大 保留那个 同时另外一个修正为 自己的pos var par = transform.parent.gameObject; var myPos = par.transform.position; //假设箱子都是 正方体 var dx = myPos.x - pos.x; var dz = myPos.z - pos.z; if (Mathf.Abs(dx) < Mathf.Abs(dz)) { pos.x = myPos.x; } else { pos.z = myPos.z; } var skill = Util.GetSkillData((int)SkillData.SkillConstId.KnockBack, 1); var skillInfo = SkillLogic.GetSkillInfo(skill); var evt = skillInfo.eventList [0]; var ret = par.GetComponent <BuffComponent>().AddBuff(evt.affix, pos); if (ret) { NetDateInterface.FastAddBuff(evt.affix, otherGo, par, skill.Id, evt.EvtId, pos); } } } }