IEnumerator doLoadPrograss() { if (iswait) { yield break; } else { foreach (var item in messageActor) { //暂定总长100 标速 40为1s float per = pubPer * item.UnitData["speed"]; item.CurSpeed += per; combat.setRelative(item); if (item.CurSpeed >= 100) { //willActionActor.Add(item); willActionActor = item; item.CurSpeed = 0; break; //暂且先这样 } } checkAction(); } yield return(new WaitForSeconds(0.02f)); StartCoroutine(doLoadPrograss()); }
public CombatMessage enemyToCombat(int id) //单位数据 转换 战斗场景数据 { CombatMessage mess = new CombatMessage(); string[] enemy = AllUnitData.getUnitData(id); mess.UnitData["physical"] = int.Parse(enemy[2]); mess.UnitData["vigor"] = int.Parse(enemy[3]); mess.UnitData["attack"] = int.Parse(enemy[4]); mess.UnitData["speed"] = int.Parse(enemy[5]); mess.UnitData["type"] = int.Parse(enemy[6]); mess.UnitData["adPat"] = int.Parse(enemy[7]); mess.UnitData["apPat"] = int.Parse(enemy[8]); mess.UnitData["strike"] = int.Parse(enemy[9]); mess.UnitData["dodge"] = int.Parse(enemy[10]); mess.UnitData["curHp"] = int.Parse(enemy[2]); mess.UnitData["curMp"] = int.Parse(enemy[3]); mess.UnitData["defence"] = int.Parse(enemy[11]); mess.IconName = enemy[1]; mess.IsPlayer = false; skillSave skill; List <skillSave> list = new List <skillSave>(); string[] skills = AllUnitData.getUnitSkillData(id); mess.AttackID = int.Parse(skills[1]); for (int i = 2; i < skills.Length; i += 2) { skill = new skillSave(); skill.skillID = int.Parse(skills[i]); skill.skillLevel = int.Parse(skills[i + 1]); list.Add(skill); } mess.SkillData = list; return(mess); }
public void OnChatMessage(ChatMessage c) { if (c.IsCombat) { CombatMessage msg = c as CombatMessage; if (msg.CombatType == CombatLogType.DamageTaken) { string str = msg.Damage.Source; string ability = msg.Damage.SourceAbility; if (ability == "") { // **TODO** i18n required ability = "default"; } if (!dmg.ContainsKey(str)) { // add reference dmg[str] = new MonsterDamage(); } if (!summary.ContainsKey(str)) { // Add if it doesn't exist. summary[str] = new Damage(); } dmg[str].Create(ability); dmg[str][ability] += msg.Damage; summary[str] += msg.Damage; } } }
private void OnIsAliveChanged(bool alive) { m_IsActive &= alive; if (alive) { return; } CombatMessage message = CombatMessage.Allocate(); if (message != null) { message.ID = EnumMessageID.MSG_COMBAT_DEFENDER_KILLED; message.StyleIndex = -1; // Random message.Defender = m_MotionController.gameObject; m_MotionController.SendMessage(message); message.Release(); } if (m_NavMeshAgent != null) { m_NavMeshAgent.isStopped = true; } if (message.IsHandled) { m_DeathMotion = message.Recipient as MotionControllerMotion; } }
//----------------------------------总处理--------------------------------------------------------------------------- //普通的战斗处理 public AttackResult normalAction(AnalyzeResult action) { atkResult = new AttackResult(); string type = AllUnitData.getSkillData(action.skillID)[SKILL_TYPE];//获取技能类型 sourceActor = dataList[action.selfNum]; takeActors = new List <CombatMessage>(); switch (type) { case "101": territoryTypeAction(action); break; //场地类型处理 case "102": stateTypeAction(action); break; //增益类型处理 case "103": harmTypeAction(action); break; //攻击类型处理 case "111": break; //道具类处理1 default: break; } //行动结算 settleOnceAction(); //计算消耗 settleExpend(action.skillID); if (atkResult == null) { Debug.Log("动画赋值错误"); } //战斗结果分析 settleActionEnd(); return(atkResult); }
public override void OnChatMessage(ChatMessage msg) { if (State == MeterState.Stopped) { return; } if (msg.IsCombat) { CombatMessage c = msg as CombatMessage; if (c.CombatType == CombatLogType.DamageDone) { if (String.Compare(c.Damage.Target, target, true) == 0 || String.IsNullOrEmpty(target)) { damagedone += c.Damage.Points; if (State != MeterState.Running) { // change state to running since we hit our target State = MeterState.Running; } } } else if (c.CombatType == CombatLogType.TargetKilled) { // Stop if our target was killed. if (String.Compare(c.Target, target, true) == 0) { Stop(); } } } }
/// <summary> /// Used to test if the reactor should process /// </summary> /// <returns></returns> public override bool TestActivate(IMessage rMessage) { if (!base.TestActivate(rMessage)) { return(false); } if (mActorCore == null || !mActorCore.IsAlive) { return(false); } if (rMessage.ID != CombatMessage.MSG_DEFENDER_ATTACKED) { return(false); } CombatMessage lCombatMessage = rMessage as CombatMessage; if (lCombatMessage != null && lCombatMessage.Defender != mActorCore.gameObject) { return(false); } mMessage = lCombatMessage; return(true); }
/// <summary> /// Called when the reactor is first activated /// </summary> /// <returns>Determines if other reactors should process.</returns> public override bool Activate() { base.Activate(); CombatMessage combatMessage = (CombatMessage)mMessage; IDamageSource damageSource = (IDamageSource)combatMessage.Weapon; NeoFPSWeaponCore weapon = (NeoFPSWeaponCore)combatMessage.Weapon; mDamageHandler.AddDamage(combatMessage.Damage, damageSource); // Get character kicker var character = mOwner.GetComponent <NeoFPS.ICharacter>(); if (character != null) { var kicker = character.headTransformHandler.GetComponent <NeoFPS.AdditiveKicker>(); if (kicker != null) { // Kick the camera position & rotation float kickDuration = 0.25f; float kickRotation = 5f; kicker.KickPosition(combatMessage.HitDirection * combatMessage.ImpactPower, kickDuration); kicker.KickRotation(Quaternion.AngleAxis(kickRotation, Vector3.Cross(combatMessage.HitDirection, Vector3.up)), kickDuration); } } //Debug.Log(damageMessage.Sender + " hit for " + ((DamageMessage)mMessage).Damage + " on " + mOwner); Deactivate(); return(true); }
/// <summary> /// Used to test if the reactor should process /// </summary> /// <returns></returns> public override bool TestActivate(IMessage rMessage) { if (!base.TestActivate(rMessage)) { return(false); } if (mActorCore == null || !mActorCore.IsAlive) { return(false); } DamageMessage lDamageMessage = rMessage as DamageMessage; if (lDamageMessage == null) { return(false); } if (lDamageMessage.Damage == 0f) { return(false); } if (lDamageMessage.ID != 0) { if (lDamageMessage.ID == CombatMessage.MSG_DEFENDER_KILLED) { return(false); } if (lDamageMessage.ID != CombatMessage.MSG_DEFENDER_ATTACKED) { return(false); } } CombatMessage lCombatMessage = rMessage as CombatMessage; if (lCombatMessage != null && lCombatMessage.Defender.transform.root.gameObject != mActorCore.gameObject) { return(false); } mDamageHandler = lCombatMessage.Defender.GetComponent <IDamageHandler>(); if (mDamageHandler == null) { Debug.LogError(mOwner + " recieved a damage message with a hit on " + lCombatMessage.Defender.transform + " but there is no IDamageHandler attached. Damage is ignored."); return(false); } mMessage = lDamageMessage; return(true); }
/// <summary> /// Look at the incoming message to determine if it means we should react /// </summary> /// <param name="rMessage"></param> public override void OnMessageReceived(IMessage rMessage) { if (rMessage == null) { return; } if (rMessage.IsHandled) { return; } if (mActorController.State.Stance != EnumControllerStance.TRAVERSAL) { return; } if (rMessage is CombatMessage) { CombatMessage lCombatMessage = rMessage as CombatMessage; // Attack messages if (lCombatMessage.Attacker == mMotionController.gameObject) { } // Defender messages else if (lCombatMessage.Defender == mMotionController.gameObject) { if (rMessage.ID == CombatMessage.MSG_DEFENDER_DAMAGED) { if (!mIsActive) { Vector3 lLocalPosition = mMotionController._Transform.InverseTransformPoint(lCombatMessage.HitPoint); Vector3 lLocalDirection = (lLocalPosition - Vector3.zero).normalized; float lAttackAngle = Vector3Ext.HorizontalAngleTo(Vector3.forward, lLocalDirection, Vector3.up); mMotionController.ActivateMotion(this, (int)lAttackAngle); } else { mMotionController.SetAnimatorMotionPhase(mMotionLayer._AnimatorLayerIndex, PHASE_START, Parameter, true); } rMessage.IsHandled = true; } } } else if (rMessage is DamageMessage) { if (rMessage.ID == CombatMessage.MSG_DEFENDER_DAMAGED) { mMotionController.ActivateMotion(this, 0); rMessage.IsHandled = true; } } }
public void OnChatMessage(ChatMessage c) { if (c.IsCombat) { CombatMessage msg = c as CombatMessage; if (msg.CombatType == CombatLogType.DamageTaken) { damagetaken += msg.Damage.Points; damageblocked += msg.Damage.Blocked; } } }
/// <summary> /// Tells the actor when to block /// </summary> public void DetermineBlock() { if (_Target == null) { return; } #if USE_SWORD_SHIELD_MP || OOTII_SSMP Vector3 lToTarget = _Target.transform.position - transform.position; float lToTargetDistance = lToTarget.magnitude; BasicMeleeBlock lMeleeBlock = mMotionController.GetMotion <BasicMeleeBlock>(); if (lMeleeBlock != null) { if (lMeleeBlock.IsActive) { if (lMeleeBlock.Age > 1f) { CombatMessage lMessage = CombatMessage.Allocate(); lMessage.ID = CombatMessage.MSG_COMBATANT_CANCEL; lMessage.Defender = gameObject; lMeleeBlock.OnMessageReceived(lMessage); CombatMessage.Release(lMessage); mActorCore.SetStateValue("State", IDLE); } } else { BasicMeleeAttack lMeleeAttack = mTargetMotionController.GetMotion <BasicMeleeAttack>(); if (lMeleeAttack != null && lMeleeAttack.IsActive) { if (lMeleeAttack.Age < 0.1f && !lMeleeBlock.IsActive) { if (mActorCore.GetStateValue("Stance") == EnumControllerStance.COMBAT_MELEE) { mMotionController.ActivateMotion(lMeleeBlock); mActorCore.SetStateValue("State", BLOCKING); } } } #if USE_ARCHERY_MP || OOTII_AYMP BasicRangedAttack lRangedAttack = mTargetMotionController.GetMotion <BasicRangedAttack>(); if (lRangedAttack != null && lRangedAttack.IsActive) { } #endif } } #endif }
//--------------------------------------------第三级调用-工具类、计算类方法---------------------------------------------------------------------------- //计算攻击特效附加 public int settleExtraSubjoin(CombatMessage taken, int hit) { int[] extraType = new int[sourceActor.AtkExtra.Count]; int[] extrahit = new int[sourceActor.AtkExtra.Count]; int count = 0; int mix = 0; int hitnum = 0; int addlist = 0; foreach (var list in sourceActor.AtkExtra) { hitnum = 0; addlist = 0; if (list.target == 200)//参考自身 { if (list.specialRefer != 0) { //特殊取值 if (list.specialRefer == 1001) { //特殊参考1001 参考当次伤害 addlist = Mathf.CeilToInt((float)list.multi / 100 * hit); sourceActor.UnitData[AllUnitData.getEncode(list.actOn.ToString())] += addlist; } //+++治疗型 采用定义doonce布尔量 仅执行一次 } else { hitnum = Mathf.CeilToInt((float)sourceActor.UnitData[AllUnitData.getEncode(list.refer.ToString())] * list.multi / 100) + list.constant; addlist = hitnum; } } else//参考目标 { hitnum = Mathf.CeilToInt((float)taken.UnitData[AllUnitData.getEncode(list.refer.ToString())] * list.multi / 100) + list.constant; addlist = hitnum; } extrahit[count] = addlist; extraType[count] = list.specialRefer; //如果0 则为伤害 其他单独处理 count++; mix += hitnum; } for (int i = 0; i < sourceActor.AtkExtra.Count; i++) { sourceActor.AtkExtra[i].round--; if (sourceActor.AtkExtra[i].round <= 0) { sourceActor.AtkExtra.Remove(sourceActor.AtkExtra[i]); i--; } } atkResult.extraHit = extrahit; return(mix); }
//进行完操作 接着跑进度 public void nextStep() { Debug.Log("开始计算速度.."); if (!checkCombatResult()) { combatSettle(); //+++如果结束 执行结算判断 胜利或失败 继续结算动画 return; } iswait = false; willActionActor = null; StartCoroutine(doLoadPrograss()); }
private void HandleMeleeAttackMotion(GameObject target) { CombatMessage message = CombatMessage.Allocate(); if (message != null) { message.ID = CombatMessage.MSG_COMBATANT_ATTACK; message.Attacker = m_Owner; message.Defender = target; m_MotionController.SendMessage(message); CombatMessage.Release(message); } }
private IEnumerator HandleDamageMotion(float damage) { CombatMessage message = CombatMessage.Allocate(); if (message != null) { message.ID = EnumMessageID.MSG_COMBAT_DEFENDER_DAMAGED; message.Damage = damage * m_Multiplier; message.Defender = gameObject; m_MotionController.SendMessage(message); message.Release(); } yield return null; }
public void initItemData(List <CombatMessage> data) {//创建头像图标 单位实体 并存储 _Data = data; int count = 0; foreach (var item in data) { if (count > 3) { break; } actorIcon[count].transform.position = startPos.transform.position; actorIcon[count].SetActive(true); /* * GameObject actor = Resources.Load<GameObject>("Entity/combat/actorIcon"); * GameObject loadactor = Instantiate(actor); * loadactor.name = item.Name; * //loadactor.transform.SetParent(line.transform); * loadactor.transform.SetParent(transform); * loadactor.transform.position = startPos.transform.position; * loadactor.transform.lossyScale.Set(1, 1,1); * loadactor.SetActive(true); //todo 待修改 */ item.IconActor = actorIcon[count]; count++; //加载单位 GameObject actorbody = Resources.Load <GameObject>("Entity/combat/combatActor"); GameObject loadactorBody = Instantiate(actorbody); SpriteRenderer spr = loadactorBody.GetComponentInChildren <SpriteRenderer>(); spr.sprite = Resources.Load("Picture/load/" + item.IconName, typeof(Sprite)) as Sprite; //换图 loadactorBody.name = item.Name; loadactorBody.SetActive(false); item.Prefab = loadactorBody; actorBody.Add(loadactorBody); loadactorBody.GetComponent <CombatActorItem>().chooseArrowChange(false); if (item.IsPlayer) { playerActor = item; } else { loadactorBody.AddComponent <Button>().onClick.AddListener(clickChoose); //+++添加点击事件 } } initLayout(); }
/// <summary> /// Allows us to choose the attack style we'll attack with /// </summary> /// <param name="rAction"></param> public void SelectAttackStyle(ReactorAction rAction) { if (rAction == null || rAction.Message == null) { return; } CombatMessage lCombatMessage = rAction.Message as CombatMessage; if (lCombatMessage == null) { return; } //lCombatMessage.StyleIndex = 2; }
//目标击败 public void settleActorDead(CombatMessage actor) { for (int i = 0; i < dataList.Count; i++) { if (dataList[i].Name == actor.Name) { //增加战利品 if (actor.Name != PLAYER) { comulativeReword(actor.UnitData["id"]); } //dataList.Remove(dataList[i]); //i--; } } }
public void OnChatMessage(ChatMessage c) { if (c.IsCombat) { CombatMessage msg = c as CombatMessage; if (msg.CombatType == CombatLogType.DamageTaken) { DamageType str = msg.Damage.Type; if (!dmg.ContainsKey(str)) { // add reference dmg[str] = new Damage(); } dmg[str] += msg.Damage; } } }
/// <summary> /// Allows us to choose the attack style we'll attack with /// </summary> /// <param name="rAction"></param> public void OnPostAttack(ReactorAction rAction) { mActorCore.SetStateValue("State", IDLE); if (rAction == null || rAction.Message == null) { return; } #if USE_ARCHERY_MP || OOTII_AYMP // Decrease the arrows CombatMessage lCombatMessage = rAction.Message as CombatMessage; if (lCombatMessage.CombatMotion is BasicRangedAttack) { ArrowCount--; } #endif }
/// <summary> /// Called when the action is first activated /// <param name="rPreviousSpellActionState">State of the action prior to this one activating</param> public override void Activate(int rPreviousSpellActionState = -1, object rData = null) { base.Activate(rPreviousSpellActionState, rData); MotionController lMotionController = _Spell.Owner.GetComponent <MotionController>(); if (lMotionController != null) { CombatMessage lMessage = CombatMessage.Allocate(); lMessage.ID = MessageID; lMotionController.SendMessage(lMessage); lMessage.Release(); } base.Deactivate(); }
/// <summary> /// Raised by the controller when a message is received /// </summary> public override void OnMessageReceived(IMessage rMessage) { if (rMessage == null) { return; } //if (mActorController.State.Stance != EnumControllerStance.SPELL_CASTING) { return; } CombatMessage lCombatMessage = rMessage as CombatMessage; if (lCombatMessage != null) { // Attack messages if (lCombatMessage.Attacker == mMotionController.gameObject) { // Call for an attack if (rMessage.ID == CombatMessage.MSG_COMBATANT_ATTACK) { } // Attack has been activated (pre attack) else if (rMessage.ID == CombatMessage.MSG_DEFENDER_ATTACKED) { } // Gives us a chance to respond to the defender's reaction (post attack) else if (rMessage.ID == CombatMessage.MSG_DEFENDER_ATTACKED_BLOCKED) { } // Final hit (post attack) else if (rMessage.ID == CombatMessage.MSG_DEFENDER_ATTACKED_PARRIED || rMessage.ID == CombatMessage.MSG_DEFENDER_DAMAGED || rMessage.ID == CombatMessage.MSG_DEFENDER_KILLED) { } } // Defender messages else if (lCombatMessage.Defender == mMotionController.gameObject) { } } }
public AnalyzeResult analyseCombatAttack(List <CombatMessage> list, CombatMessage item, CombatMessage play) { player = play; AnalyzeResult result = new AnalyzeResult(); //可能需要设置目标 或者多加一个目标分析 //技能解析 skillAnalyze(item.SkillData); //分析行动 //派发攻击事件 //如果是伤害型技能 或 指向性debuff //测试 result.takeNum = player.NumID; result.selfNum = item.NumID; int skillid = item.AttackID;//测试 result.skillID = skillid; result.skillType = int.Parse(AllUnitData.getSkillData(skillid)[3]); //combatNextStep(); return(result); }
/// <summary> /// Allows us to choose the attack style we'll attack with /// </summary> /// <param name="rAction"></param> public void OnPreAttack(ReactorAction rAction) { mActorCore.SetStateValue("State", ATTACKING); if (rAction == null || rAction.Message == null) { return; } #if USE_SWORD_SHIELD_MP || OOTII_SSMP // Choose the attack style CombatMessage lCombatMessage = rAction.Message as CombatMessage; if (lCombatMessage == null) { return; } if (lCombatMessage.CombatMotion is BasicMeleeAttack) { //lCombatMessage.StyleIndex = 2; } #endif }
//------------------------------------------------------------------------------------------------------------------------- //类型转换工具类 public CombatMessage playerSaveToCombat(PlayerMessage play) //玩家数据 转换 战斗场景数据 { CombatMessage mess = new CombatMessage(); mess.UnitData["id"] = 0; mess.UnitData["physical"] = play.hpmax; mess.UnitData["vigor"] = play.mpmax; mess.UnitData["attack"] = play.atk; mess.UnitData["speed"] = play.speed; mess.UnitData["type"] = 0; mess.UnitData["adPat"] = play.adPat; mess.UnitData["apPat"] = play.apPat; mess.UnitData["strike"] = play.strike; mess.UnitData["dodge"] = play.dodge; mess.UnitData["curHp"] = play.hpcur; mess.UnitData["curMp"] = play.mpcur; mess.UnitData["defence"] = play.def; mess.IconName = GameData.Data.PLAYER; mess.IsPlayer = true; mess.NumID = 0; mess.AttackID = 2; mess.SkillData = play.skills; return(mess); }
private void Start() { uiMessage = FindObjects.GameLogic.GetComponent <UIMessage>(); gameMessage = FindObjects.GameLogic.GetComponent <CombatMessage>(); }
//战斗处理 (不用了) public void doAttackAction(CombatMessage atk, CombatMessage behit, string atkType) { //假装读取了攻击数据 //全部进行完之后 //nextStep(); }
/// <summary> /// Called each frame /// </summary> private void Update() { if (!IsActive) { return; } if (mCombatant == null) { return; } if (Target == null) { return; } MotionControllerMotion lMotion = mMotionController.ActiveMotion; if (lMotion == null) { return; } MotionControllerMotion lTargetMotion = mTargetMotionController.ActiveMotion; // Determine if we rotate to the target bool lRotate = true; // Ensure our weapon is equipped //if (!mBasicInventory.IsWeaponSetEquipped(2)) //{ // if (mLastEquipTime + AttackDelay < Time.time) // { // mBasicInventory.EquipWeaponSet(2); // mLastEquipTime = Time.time; // } //} //// The main AI loop //else //{ Vector3 lToTarget = Target._Transform.position - transform.position; lToTarget.y = 0f; Vector3 lToTargetDirection = lToTarget.normalized; float lToTargetDistance = lToTarget.magnitude; bool lIsTargetAimingAtMe = false; #if USE_ARCHERY_MP || OOTII_AYMP //float lTargetToMeHorizontalAngle = NumberHelper.GetHorizontalAngle(Target._Transform.forward, -lToTargetDirection, Target._Transform.up); //lIsTargetAimingAtMe = ((lTargetMotion is Bow_WalkRunTarget || lTargetMotion is Bow_BasicAttacks) && Mathf.Abs(lTargetToMeHorizontalAngle) < 10f); #endif // Determine if we should move to the target float lRange = Range; if (!mFollow && lToTargetDistance > lRange + 1f) { mFollow = true; } if (mFollow && lToTargetDistance <= lRange) { mFollow = false; } if (mFollow && (lMotion.Category != EnumMotionCategories.IDLE && lMotion.Category != EnumMotionCategories.WALK)) { mFollow = false; } if (mFollow && lIsTargetAimingAtMe) { mFollow = false; } if (!Move) { mFollow = false; } // Ensure we're not casting if (mMotionController.ActiveMotion is BasicSpellCasting) { } // Cast a healing spell else if (Cast && mLastCastTime + CastDelay < Time.time && mBasicAttributes != null && mBasicAttributes.GetAttributeValue <float>("Health", 100f) < 40f && mSpellInventory != null && mSpellInventory.GetSpellIndex("Heal Self") >= 0) { int lSpellIndex = mSpellInventory.GetSpellIndex("Heal Self"); if (lSpellIndex >= 0) { BasicSpellCasting lCastMotion = mMotionController.GetMotion <BasicSpellCasting>(); mMotionController.ActivateMotion(lCastMotion, lSpellIndex); mLastCastTime = Time.time; } } // Move to the target else if (mFollow) { float lSpeed = Mathf.Min(MovementSpeed * Time.deltaTime, lToTargetDistance); transform.position = transform.position + (lToTargetDirection * lSpeed); } // If we're being shot at, block else if (Block && lIsTargetAimingAtMe) { mFollow = false; CombatMessage lMessage = CombatMessage.Allocate(); lMessage.ID = CombatMessage.MSG_COMBATANT_BLOCK; lMessage.Attacker = null; lMessage.Defender = gameObject; mMotionController.SendMessage(lMessage); CombatMessage.Release(lMessage); } // Let the movement finish up else if (lMotion.Category == EnumMotionCategories.WALK) { } // Attack with the sword else if (Attack && lMotion.Category == EnumMotionCategories.IDLE && (mLastAttackTime + AttackDelay < Time.time)) { CombatMessage lMessage = CombatMessage.Allocate(); lMessage.ID = CombatMessage.MSG_COMBATANT_ATTACK; lMessage.Attacker = gameObject; lMessage.Defender = Target.gameObject; mMotionController.SendMessage(lMessage); CombatMessage.Release(lMessage); mLastAttackTime = Time.time; } // Block with the shield else if (Block && lMotion.Category == EnumMotionCategories.IDLE && lMotion.Age > 0.5f) { CombatMessage lMessage = CombatMessage.Allocate(); lMessage.ID = CombatMessage.MSG_COMBATANT_BLOCK; lMessage.Attacker = null; lMessage.Defender = gameObject; mMotionController.SendMessage(lMessage); CombatMessage.Release(lMessage); } // Free the block else if (lMotion.Category == EnumMotionCategories.COMBAT_MELEE_BLOCK && (lToTargetDistance > lRange + 1f || lMotion.Age > BlockHold)) { CombatMessage lMessage = CombatMessage.Allocate(); lMessage.ID = CombatMessage.MSG_COMBATANT_CANCEL; lMessage.Attacker = null; lMessage.Defender = gameObject; mMotionController.SendMessage(lMessage); CombatMessage.Release(lMessage); } // Allow rotation only if (mMotionController.enabled && lRotate) { float lAngle = NumberHelper.GetHorizontalAngle(transform.forward, lToTargetDirection, transform.up); if (lAngle != 0f) { float lRotationSpeed = Mathf.Sign(lAngle) * Mathf.Min(RotationSpeed * Time.deltaTime, Mathf.Abs(lAngle)); transform.rotation = transform.rotation * Quaternion.AngleAxis(lRotationSpeed, transform.up); } } //} // If we're dead, we can just stop if (lMotion.Category == EnumMotionCategories.DEATH) { IsActive = false; } // Clear the target if they are dead else if (Target != null && !Target.enabled) { Target = null; //StartCoroutine(WaitAndStoreEquipment(2f)); } }
/// <summary> /// Raised by the controller when a message is received /// </summary> public override void OnMessageReceived(IMessage rMessage) { if (rMessage == null) { return; } //if (mActorController.State.Stance != EnumControllerStance.SPELL_CASTING) { return; } MagicMessage lMagicMessage = rMessage as MagicMessage; if (lMagicMessage != null) { if (lMagicMessage.ID == MagicMessage.MSG_MAGIC_CAST) { mSpellIndex = lMagicMessage.SpellIndex; mMotionController.ActivateMotion(this); lMagicMessage.IsHandled = true; lMagicMessage.Recipient = this; } else if (lMagicMessage.ID == MagicMessage.MSG_MAGIC_CONTINUE) { if (mIsActive) { if (mStoredAnimatorSpeed > 0f) { mMotionController.Animator.speed = mStoredAnimatorSpeed; } mMotionController.SetAnimatorMotionPhase(mMotionLayer.AnimatorLayerIndex, PHASE_CONTINUE, mSpellInstance.CastingStyle, 0, false); lMagicMessage.IsHandled = true; lMagicMessage.Recipient = this; } } return; } // If we're not active, the other coditions don't matter if (!mIsActive) { CombatMessage lCombatMessage = rMessage as CombatMessage; if (lCombatMessage != null) { // Attack message if (lCombatMessage.Attacker == mMotionController.gameObject) { // Call for an attack if (rMessage.ID == CombatMessage.MSG_COMBATANT_ATTACK) { if (lCombatMessage.Defender != null) { mTargetForward = (lCombatMessage.Defender.transform.position - mMotionController._Transform.position).normalized; } else if (lCombatMessage.HitDirection.sqrMagnitude > 0f) { mTargetForward = lCombatMessage.HitDirection; } else { mTargetForward = mMotionController._Transform.forward; } lCombatMessage.IsHandled = true; lCombatMessage.Recipient = this; mMotionController.ActivateMotion(this); } } } } // If we are, we may need to cancel else { MotionMessage lMotionMessage = rMessage as MotionMessage; if (lMotionMessage != null) { // Continue with the casting if (lMotionMessage.ID == MotionMessage.MSG_MOTION_CONTINUE) { if (mStoredAnimatorSpeed > 0f) { mMotionController.Animator.speed = mStoredAnimatorSpeed; } mMotionController.SetAnimatorMotionPhase(mMotionLayer.AnimatorLayerIndex, PHASE_CONTINUE, mSpellInstance.CastingStyle, 0, false); lMotionMessage.IsHandled = true; lMotionMessage.Recipient = this; } // Cancel the casting else if (lMotionMessage.ID == MotionMessage.MSG_MOTION_DEACTIVATE) { if (mStoredAnimatorSpeed > 0f) { mMotionController.Animator.speed = mStoredAnimatorSpeed; } int lMotionParameter = (mWasTraversal ? 1 : 0); mMotionController.SetAnimatorMotionPhase(mMotionLayer.AnimatorLayerIndex, PHASE_CANCEL, lMotionParameter, false); lMotionMessage.IsHandled = true; lMotionMessage.Recipient = this; } } CombatMessage lCombatMessage = rMessage as CombatMessage; if (lCombatMessage != null) { // Attack messages if (lCombatMessage.Defender == mMotionController.gameObject) { // Determine if we're being attacked if (rMessage.ID == CombatMessage.MSG_DEFENDER_ATTACKED) { } // Gives us a chance to respond to the defender's reaction (post attack) else if (rMessage.ID == CombatMessage.MSG_DEFENDER_ATTACKED_BLOCKED) { mIsInterrupted = true; // The damaged and death animation may take over. So, cancel the instance now. if (mSpellInstance != null) { mSpellInstance.Cancel(); } } // Final hit (post attack) else if (rMessage.ID == CombatMessage.MSG_DEFENDER_ATTACKED_PARRIED || rMessage.ID == CombatMessage.MSG_DEFENDER_DAMAGED || rMessage.ID == CombatMessage.MSG_DEFENDER_KILLED) { mIsInterrupted = true; // The damaged and death animation may take over. So, cancel the instance now. if (mSpellInstance != null) { mSpellInstance.Cancel(); } } } // Defender messages else if (lCombatMessage.Defender == mMotionController.gameObject) { } } DamageMessage lDamageMessage = rMessage as DamageMessage; if (lDamageMessage != null) { mIsInterrupted = true; // The damaged and death animation may take over. So, cancel the instance now. if (mSpellInstance != null) { mSpellInstance.Cancel(); } } } }