override public void OnDeactivate() { Action.SetSuccess(); Action = null; base.OnDeactivate(); }
void attackAction() { ActionAttack a = gameObject.AddComponent <ActionAttack> (); //a.targetAttack = aiGroup.groupMembers [0]; a.triggered = true; a.DoAction(); }
override public void OnDeactivate() { Time.timeScale = 1.0f; Action.SetSuccess(); Action = null; base.OnDeactivate(); }
virtual public void Initialize() { IsDead = false; MovementAction = gameObject.AddComponent <ActionMovement>(); MovementAction.Initialize(this, new ActionData()); ActionAttack attack = gameObject.AddComponent <ActionAttack>(); attack.Initialize(this, new ActionData()); ActionList.Add(attack); }
override protected void Initialize(ActionBase action) { base.Initialize(action); Action = action as ActionAttack; SetFinished(false); if (Action.Data == null) { Action.Data = Owner.AnimSet.GetFirstAttackAnim(Owner.BlackBoard.WeaponSelected, Action.AttackType); } AnimAttackData = Action.Data; StartRotation = Transform.rotation; Action.AttackPhaseDone = false; Action.Hit = false; float angle = 0; if (Action.Target != null) { Vector3 dir = Action.Target.Position - Transform.position; //float distance = dir.magnitude; if (dir.sqrMagnitude > 0.1f * 0.1f) { dir.Normalize(); angle = Vector3.Angle(Transform.forward, dir); } else { dir = Transform.forward; } FinalRotation.SetLookRotation(dir); RotationTime = angle / 180.0f; } else { //Debug.Log("attacking dir " + Action.AttackDir.ToString()); FinalRotation.SetLookRotation(Action.AttackDir); RotationTime = Vector3.Angle(Transform.forward, Action.AttackDir) / 1040.0f; } //Debug.Log("RT " + RotationTime + " MT " + MoveTime + " Angle " + angle); RotationOk = RotationTime == 0; CurrentRotationTime = 0; PlayAnim(); }
private void testEquipableAction() { Dictionary <string, int> m1Stats = new Dictionary <string, int> { { BattleStats.CURRENT_HEALTH, 10 }, { BattleStats.MAX_HEALTH, 10 } }; Dictionary <string, int> m2Stats = new Dictionary <string, int>(m1Stats); PMMob m1 = new PMMob(m1Stats); PMMob m2 = new PMMob(m2Stats); PMAction swordSlash = new ActionAttack(5); IEquipable attackSword = new ActionEquipable(EquipSlots.MAIN_HAND, swordSlash); m1.equip(attackSword); IEquipable e = m1.peekEquipmentSlot(EquipSlots.MAIN_HAND); if (e.targetSlot() == EquipSlots.MAIN_HAND) { Debug.Log("Nocab test 1.1 passed"); } else { Debug.Log("Nocab test 1.1 fail"); } PMBattleController bc = new PMBattleController(m1, m2); PMAction a = m1.getNextAction(bc); a.activate(m2); if (m2.getStat(BattleStats.CURRENT_HEALTH) == 5) { Debug.Log("Nocab test 1.2 passed"); } else { Debug.Log("Nocab test 1.2 failed"); } m1.unequip(EquipSlots.MAIN_HAND); }
public static IEquipable makeSword() { HashSet <IEquipable> behaviors = new HashSet <IEquipable>(); Flagable f = new Flagable(); f.addFlag(BattleStats.ATTACK); Pipe <int> attackup = new PipeSum(new ExpireNever <Pipe <int> >(), f, 2); IEquipable addAttachBehavior = new EquipablePipe(EquipSlots.MAIN_HAND, attackup); PMAction slashAction = new ActionAttack(3); IEquipable slashBehavior = new ActionEquipable(EquipSlots.MAIN_HAND, slashAction); behaviors.Add(addAttachBehavior); behaviors.Add(slashBehavior); MultiBehaviorEquipable sword = new MultiBehaviorEquipable(EquipSlots.MAIN_HAND, behaviors); return(sword); }
public FighterStateMachine( Fighter fighter, float runSpeed ) : base() { Character.Anim.FighterAnimation fighterAnimation = fighter.GetComponent <Character.Anim.FighterAnimation> (); Character.Anim.MoveableAnimation moveableAnimation = fighter.GetComponent <Character.Anim.MoveableAnimation> (); CharacterController characterController = fighter.GetComponent <CharacterController> (); mActionIdle = new ActionIdle((int)eCharacterState.idle, moveableAnimation); mActionAttack = new ActionAttack((int)eCharacterState.attack, fighter); mActionRun = new ActionRun((int)eCharacterState.run, moveableAnimation, fighter.transform, characterController, runSpeed); mActionDie = new ActionDie((int)eCharacterState.die, fighterAnimation); addAction(mActionIdle); addAction(mActionAttack); addAction(mActionRun); addAction(mActionDie); startNewAction((int)eCharacterState.idle, false); }
// 攻击动作 private void CreateOrderAttack(E_AttackType type) { if (CouldBufferNewOrder() == false && CouldAddnewOrder() == false) { // Debug.Log(Time.timeSinceLevelLoad + " attack order rejected, already buffered one "); return; } AgentOrder order = AgentOrderFactory.Create(AgentOrder.E_OrderType.E_ATTACK); order.Direction = Owner.Transform.forward; order.AnimAttackData = ProcessCombo(type); // 查找最优的目标对象 order.Target = GetBestTarget(false); if (CouldAddnewOrder()) { //Debug.Log("order " + (order.Target != null ? order.Target.name : "no target") + " " + order.AnimAttackData.AnimName); Owner.BlackBoard.OrderAdd(order); } else { //Debug.Log("order to queue " + (order.Target != null ? order.Target.name : "no target") + " " + order.AnimAttackData.AnimName); bufferedOrders.Enqueue(order); } ActionAttack attack = ActionFactory.Create(ActionFactory.E_Type.E_ATTACK) as ActionAttack; attack.Data = order.AnimAttackData; attack.AttackDir = Owner.Transform.forward; attack.Target = order.Target; Owner.BlackBoard.WeaponState = E_WeaponState.Ready; // currentAttackAction = attack; weaponStartTime = 0; GetComponent <AnimComponent>().HandleAction(attack); }
public IAGuardStateMachine(Fighter fighter) : base() { //construct mActionGuardWatching = new ActionGuardWatching((int)eState.watching, fighter); mActionChase = new ActionChase((int)eState.chase, fighter); mActionAttack = new ActionAttack((int)eState.attack, fighter); //Add addAction(mActionGuardWatching); addAction(mActionChase); addAction(mActionAttack); //Trigger mActionGuardWatching.addTrigger((int)ActionGuardWatching.eTrigger.found, mActionChase); mActionChase.addTrigger((int)ActionChase.eTrigger.reached, mActionAttack); mActionAttack.addTrigger((int)ActionAttack.eTrigger.hit, mActionAttack); // m_actionIdle = new ActionIdle ((int)eCharacterState.idle, moveableAnimation); //addAction (m_actionIdle); startNewState(eState.watching); //ACTION_DEFAULT = m_actionIdle; }
IEnumerator Combat() { //Debug.Log("Warrior combat"); if (owner.equip[(int)ItemSlot.Weapon]==null) { Debug.Log("AI: I have no weapon equipped!"); foreach (KeyValuePair<int,BaseItem> i in owner.inventory) { //TODO: choose the best weapon if (i.Value.type=="weapon") { owner.equip[(int)ItemSlot.Weapon] = i.Value; /* Test */ GameObject wprefab = Resources.Load (i.Value.prefab) as GameObject; GameObject weapon = Instantiate (wprefab) as GameObject; foreach (Transform t in gameObject.GetComponentsInChildren<Transform>()) { if (t.name == i.Value.attach) { weapon.transform.SetParent (t); weapon.transform.localPosition = new Vector3(9.2f, -9.9f,-12.4f); weapon.transform.localRotation = Quaternion.Euler (new Vector3(35.56f, 358.5f, 358.9f)); weapon.transform.localScale = new Vector3(1,7f,7); } } /* Test**/ break; } } owner.anim.SetInteger ("CharacterState", (int)CharacterState.Combat1h); owner.AnimState = (int)CharacterState.Combat1h; yield return null; } else { if (Vector3.Distance (owner.gameObject.transform.position, owner.target.transform.position) > owner.equip[(int)ItemSlot.Weapon].range && !owner.agent.hasPath) { //move towards enemy owner.MoveTo(owner.target.transform.position); yield return null; } else if (owner.agent.hasPath) { if (Vector3.Distance (owner.gameObject.transform.position, owner.target.transform.position)<owner.equip[(int)ItemSlot.Weapon].range) { //swing Debug.Log("We are close. Attacking"); owner.agent.ResetPath(); ActionAttack a = new ActionAttack(); a.type = ActionType.UseItem; a.loop = true; a.time = 1.0f; a.cooldown = 0; a.OriginCharacter = gameObject; a.TargetCharacter = owner.target; a.OriginItem = owner.equip[(int)ItemSlot.Weapon]; owner.actions.addAction(a); //owner.anim.SetInteger ("CharacterState", (int)CharacterState.AttackMelee1h); //owner.state = (int)CharacterState.AttackMelee1h; owner.anim.SetInteger ("CharacterState", (int)CharacterState.Combat1h); owner.AnimState = (int)CharacterState.Combat1h; } yield return null; } } //check if target is dead if (owner.target.GetComponent<BaseCharacter> ().HitPoints [0] < 0) { Debug.Log("Target dead!"); //TODO: check if group fight and get another target owner.AIstate = (int)AIStates.Idle; owner.actions.Clear(); owner.anim.SetInteger ("CharacterState", (int)CharacterState.Idle); owner.AnimState = (int)CharacterState.Idle; yield return null; } }
private void testMultiPipe() { Dictionary <string, int> m1Stats = new Dictionary <string, int> { { BattleStats.CURRENT_HEALTH, 10 }, { BattleStats.MAX_HEALTH, 10 }, { BattleStats.SPEED, 0 } }; Dictionary <string, int> m2Stats = new Dictionary <string, int>(m1Stats); PMMob m1 = new PMMob(m1Stats); PMMob m2 = new PMMob(m2Stats); Pipe <int> speedUp = new PipeSum(new ExpireNever <Pipe <int> >(), new Flagable(), 5); speedUp.addFlag(BattleStats.SPEED); IEquipable helmOfSpeed = new EquipablePipe(EquipSlots.HELM, speedUp); PMAction swordSlash = new ActionAttack(5); IEquipable attackSword = new ActionEquipable(EquipSlots.MAIN_HAND, swordSlash); HashSet <IEquipable> subEquips = new HashSet <IEquipable>() { helmOfSpeed, attackSword }; IEquipable multiItem = new MultiBehaviorEquipable(EquipSlots.HELM, subEquips); m1.equip(multiItem); IEquipable e = m1.peekEquipmentSlot(EquipSlots.HELM); if (e.targetSlot() == EquipSlots.HELM) { Debug.Log("Nocab test 3.1 passed"); } else { Debug.Log("Nocab test 3.1 fail"); } PMBattleController bc = new PMBattleController(m1, m2); PMAction a = m1.getNextAction(bc); a.activate(m2); if (m2.getStat(BattleStats.CURRENT_HEALTH) == 5) { Debug.Log("Nocab test 3.2 passed"); } else { Debug.Log("Nocab test 3.2 failed"); } if (m1.getStat(BattleStats.SPEED) == 5) { Debug.Log("Nocab test 3.3 passed"); } else { Debug.Log("Nocab test 3.3 failed"); } m1.unequip(EquipSlots.HELM); if (m1.getStat(BattleStats.SPEED) == 0) { Debug.Log("Nocab test 3.4 passed"); } else { Debug.Log("Nocab test 3.4 failed"); } if (m2.getStat(BattleStats.CURRENT_HEALTH) == 5) { Debug.Log("Nocab test 3.5 passed"); } else { Debug.Log("Nocab test 3.5 failed"); } }
// Update is called once per frame void Update() { if (!GameInstance.pause) { if (!anim.enabled) anim.enabled = true; if (Vector3.Distance(agent.destination,transform.position)<0.5 && AnimState==(int)CharacterState.Walking) { Debug.Log("Destination reached"); anim.SetInteger ("CharacterState", (int)CharacterState.Idle); AnimState = (int)CharacterState.Idle; } if (AnimState == (int)CharacterState.Combat1h) { anim.SetInteger ("CharacterState", (int)CharacterState.Combat1h); if (actions.isEmpty()) { //set default attack ActionAttack a = new ActionAttack(); a.type = ActionType.UseItem; a.OriginItem = equip[(int)ItemSlot.Weapon]; a.loop = true; a.time = 1.5f; a.cooldown = 0; a.OriginCharacter = gameObject; a.TargetCharacter = target; actions.addAction(a); } } ExecuteActions(); //Check countdown timers for bonus or buffs //Regenerate life and energy /*if (Input.GetKey (KeyCode.Mouse1)) { anim.SetInteger ("CharacterState", (int)CharacterState.AttackMelee1h); }*/ /*if (Input.GetKey (KeyCode.C)) { anim.SetInteger ("CharacterState", (int)CharacterState.Combat1h); } */ /*if (Input.GetKeyDown (KeyCode.T)) { //attach tests //automatyically set combat stance anim.SetInteger ("CharacterState", (int)CharacterState.Combat1h); GameObject wprefab = Resources.Load ("Weapons/ancient-grtsword") as GameObject; GameObject weapon = Instantiate (wprefab) as GameObject; foreach (Transform t in gameObject.GetComponentsInChildren<Transform>()) { if (t.name == "weapon_target_side.R_end") AttachPoint = t; } weapon.transform.SetParent (AttachPoint.transform); weapon.transform.localPosition = Vector3.zero; weapon.transform.localRotation = Quaternion.Euler (Vector3.zero); weapon.transform.localScale = new Vector3(7,7,7); //CreateDamagePopup (200); }*/ } else { anim.enabled =false; } }
public void DetermineAction(GameObject behaviorReceiber, GameObject aux) { if (aux.tag == "IA") { aux.GetComponent <VisibilityConeCycleIA>().enabled = false; if (Mathf.Abs(Vector3.Distance(behaviorReceiber.transform.position, aux.transform.position)) <= MinDistanceOpenMenu && menuOpened) { // Debug.Log("estan cerca, abro menu"); behaviourController.openConversationMenu(behaviorReceiber, aux); } else { // Debug.Log("esta lejos, me acercare"); clickedOnTile = true; lastLinear = movementScript.linearVelocity; string[] behaviours = { "Arrive", "AvoidWall", "LookWhereYouAreGoing" }; float[] weightedBehavs = { 1f, 5f, 1 }; GameObject[] targets = { aux, aux, aux }; behaviourController.addBehavioursOver(this.gameObject, targets, behaviours, weightedBehavs); //if IA character is too far, we need to arrive/pursue him in order to be near, so we can talk to him if (attack) { aux.GetComponent <PersonalityBase>().interactionFromOtherCharacter = ActionsEnum.Actions.ATTACK; ActionAttack a = gameObject.AddComponent <ActionAttack>(); a.targetAttack = aux; a.triggered = true; a.DoAction(); DecisionTreeReactionAfterInteraction reaction = aux.GetComponent <DecisionTreeReactionAfterInteraction>(); if (reaction != null) { DestroyImmediate(reaction); } DecisionTreeNode[] oldNodes = aux.GetComponents <DecisionTreeNode>(); foreach (DecisionTreeNode n in oldNodes) { DestroyImmediate(n); } reaction = aux.AddComponent <DecisionTreeReactionAfterInteraction>(); // Debug.Log("h collider es :" + aux.name + " reaction es " + reaction); reaction.target = this.gameObject; attack = false; // Debug.Log("reaction target es :" + reaction.target); } } } else if (aux.tag == "MenuButton") { aux.GetComponent <ButtonAction>().Action(); } else if (aux.tag == "Player") { //Debug.Log("Pa k clikas en el player, jaja salu2"); } else if (aux.layer == 8 || aux.layer == 10) { //Esto es para que al clickar en un muro o en los muebles no haga nada } else { // target is floor string[] behaviours = { "Arrive", "AvoidWall", "LookWhereYouAreGoing" }; float[] weightedBehavs = { 0.7f, 1, 1 }; GameObject[] targets = { aux, aux, aux, }; behaviourController.addBehavioursOver(behaviorReceiber, targets, behaviours, weightedBehavs); //ActionWhenClick(behaviorReceiber, aux); //if IA character is too far, we need to arrive/pursue him in order to be near, so we can talk to him } }
public override void CommunicateAction(Action actionNew) { // Debug.Log("He acabado y comunico accion"); if (target.gameObject.tag == "IA" || target.tag == "Player") { //avisar de que vamos a interactuar con él ActionAttack attack = new ActionAttack(); ActionOffer offer = new ActionOffer(); ActionOfferOtherJoinMyGroup join = new ActionOfferOtherJoinMyGroup(); // Debug.Log(actionNew.GetType() + ", " + attack.GetType()); bool decision = true; if (Object.ReferenceEquals(actionNew.GetType(), attack.GetType())) // compare classes { if (target.tag == "Player") { target.GetComponent <PlayerPersonality>().interactionFromOtherCharacter = ActionsEnum.Actions.ATTACK; GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController>().OpenMenu(PlayerMenuController.MenuTypes.MENU_ATTACKED, target); GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController> ().SetTargetIA(this.gameObject); } else { target.GetComponent <AIPersonality>().interactionFromOtherCharacter = ActionsEnum.Actions.ATTACK; } // Debug.Log("Le he dicho que le ataco"); } else if (Object.ReferenceEquals(actionNew.GetType(), offer.GetType())) // compare classes { if (target.tag == "Player") { target.GetComponent <PlayerPersonality> ().interactionFromOtherCharacter = ActionsEnum.Actions.OFFER; GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController> ().OpenMenu(PlayerMenuController.MenuTypes.MENU_OFFERED_OBJECT, target); GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController> ().SetTargetIA(this.gameObject); } else { target.GetComponent <AIPersonality> ().interactionFromOtherCharacter = ActionsEnum.Actions.OFFER; } } else if (Object.ReferenceEquals(actionNew.GetType(), join.GetType())) // compare classes { if (this.gameObject.GetComponent <GroupScript> ().groupMembers.Count + target.GetComponent <GroupScript> ().groupMembers.Count < 2) { if (target.tag == "Player") { target.GetComponent <PlayerPersonality> ().interactionFromOtherCharacter = ActionsEnum.Actions.JOIN; GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController> ().OpenMenu(PlayerMenuController.MenuTypes.MENU_OFFERED_JOIN, target); GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController> ().SetTargetIA(this.gameObject); } else { target.GetComponent <AIPersonality> ().interactionFromOtherCharacter = ActionsEnum.Actions.JOIN; } //Debug.Log("Le he dicho que se una a mi grupo"); } else { //Debug.Log ("El grupo es muy grande te jodes"); decision = false; } } else { //Debug.Log("Mi accion es NOTHING y NO le digo nada"); decision = false; } if (decision) { if (target.tag != "Player") { if (reaction != null) { Destroy(reaction); } reaction = target.AddComponent <DecisionTreeReactionAfterInteraction> (); if (this != null) { reaction.target = this.gameObject; } target.GetComponent <VisibilityConeCycleIA>().enabled = false; } } } }
// 生成动作 static public ActionBase Create(E_Type type) { int index = (int)type; ActionBase a; if (m_UnusedActions[index].Count > 0) { a = m_UnusedActions[index].Dequeue(); } else { switch (type) { case E_Type.E_IDLE: a = new ActionIdle(); break; case E_Type.E_MOVE: a = new ActionMove(); break; case E_Type.E_GOTO: a = new ActionGoTo(); break; case E_Type.E_COMBAT_MOVE: a = new ActionCombatMove(); break; case E_Type.E_ATTACK: a = new ActionAttack(); break; case E_Type.E_ATTACK_ROLL: a = new ActionAttackRoll(); break; case E_Type.E_ATTACK_WHIRL: a = new ActionAttackWhirl(); break; case E_Type.E_INJURY: a = new ActionInjury(); break; case E_Type.E_DAMAGE_BLOCKED: a = new ActionDamageBlocked(); break; case E_Type.E_BLOCK: a = new ActionBlock(); break; case E_Type.E_ROLL: a = new ActionRoll(); break; case E_Type.E_INCOMMING_ATTACK: a = new ActionIncommingAttack(); break; case E_Type.E_WEAPON_SHOW: a = new ActionWeaponShow(); break; case E_Type.E_Rotate: a = new ActionRotate(); break; case E_Type.E_USE_LEVER: a = new ActionUseLever(); break; case E_Type.E_PLAY_ANIM: a = new ActionPlayAnim(); break; case E_Type.E_PLAY_IDLE_ANIM: a = new ActionPlayIdleAnim(); break; case E_Type.E_DEATH: a = new ActionDeath(); break; case E_Type.E_KNOCKDOWN: a = new ActionKnockdown(); break; case E_Type.E_Teleport: a = new ActionTeleport(); break; default: Debug.LogError("no Action to create"); return(null); } } a.Reset(); a.SetActive(); m_ActionsInAction.Add(a); return(a); }
void Update() { if (Owner.BlackBoard.Health <= 0) { if (!isDeath) { StartCoroutine(PlayTeleport()); isDeath = true; } return; } else { Owner.CharacterController.SimpleMove(Vector3.zero); } // 只有当在警觉状态下,才会进行警戒计时 if (Alert() && Owner.Status == E_CurrentStatus.E_Idle) { alertStartTime += Time.deltaTime; ActionRotate actionRotate = ActionFactory.Create(ActionFactory.E_Type.E_Rotate) as ActionRotate; actionRotate.Direction = targetDir; animComponent.HandleAction(actionRotate); Owner.BlackBoard.WeaponState = E_WeaponState.Ready; } else { ActionIdle actionIdle = ActionFactory.Create(ActionFactory.E_Type.E_IDLE) as ActionIdle; animComponent.HandleAction(actionIdle); alertStartTime = 0; Owner.BlackBoard.WeaponState = E_WeaponState.NotInHands; } // 当超过警觉时间,切换为移动状态 if (alertStartTime > alertTime) { Owner.Status = E_CurrentStatus.E_Move; alertStartTime = 0; } if (Owner.Status == E_CurrentStatus.E_Move) { // 当进入移动状态时,判断敌人是否在视野范围内,如果是追击敌人,如果不在,返回到Idl状态,接着之前的行为 if (InView()) { ActionGoTo actionGoto = ActionFactory.Create(ActionFactory.E_Type.E_GOTO) as ActionGoTo; Owner.BlackBoard.MoveDir = targetDir.normalized; // 更新移动方向 Owner.BlackBoard.WeaponState = E_WeaponState.Ready; actionGoto.FinalPosition = targetPos; actionGoto.MoveType = E_MoveType.Forward; actionGoto.Motion = E_MotionType.Sprint; animComponent.HandleAction(actionGoto); } else { Owner.Status = E_CurrentStatus.E_Idle; Owner.BlackBoard.WeaponState = E_WeaponState.NotInHands; } } // 只要在攻击距离内,就直接切换到攻击状态 if (InAttackView() && Owner.Status == E_CurrentStatus.E_Move) { ActionAttack actionAttack = ActionFactory.Create(ActionFactory.E_Type.E_ATTACK) as ActionAttack; actionAttack.Target = Player.Instance.Agent; actionAttack.AttackDir = Player.Instance.transform.position - transform.position; animComponent.HandleAction(actionAttack); Owner.WorldState.SetWSProperty(E_PropKey.E_IDLING, false); Owner.Status = E_CurrentStatus.E_Attack; } if (Owner.Status == E_CurrentStatus.E_Attack && Owner.WorldState.GetWSProperty(E_PropKey.E_IDLING).GetBool()) { // Owner.Status = E_CurrentStatus.E_Idle; Owner.Status = E_CurrentStatus.E_Injury; } // 如果在受伤或者格挡状态,隔0.3s回Idle if (Owner.Status == E_CurrentStatus.E_Injury || Owner.Status == E_CurrentStatus.E_Block) { injuryStartTime += Time.deltaTime; } if (injuryStartTime > injuryTime) { Owner.Status = E_CurrentStatus.E_Idle; injuryStartTime = 0; } }
override protected void Initialize(ActionBase action) { base.Initialize(action); SetFinished(false); State = E_State.E_PREPARING; Owner.BlackBoard.MotionType = E_MotionType.Attack; Action = action as ActionAttack; Action.AttackPhaseDone = false; Action.Hit = false; if (Action.Data == null) { Action.Data = Owner.AnimSet.GetFirstAttackAnim(Owner.BlackBoard.WeaponSelected, Action.AttackType); } AnimAttackData = Action.Data; if (AnimAttackData == null) { Debug.LogError("AnimAttackData == null"); } StartRotation = Transform.rotation; StartPosition = Transform.position; float angle = 0; bool backstab = false; float distance = 0; if (Action.Target != null) { Vector3 dir = Action.Target.Position - Transform.position; distance = dir.magnitude; if (distance > 0.1f) { dir.Normalize(); angle = Vector3.Angle(Transform.forward, dir); //attacker uhel k cili je mensi nez 40 and uhel enemace a utocnika je mensi nez 80 stupnu if (angle < 40 && Vector3.Angle(Owner.Forward, Action.Target.Forward) < 80) { backstab = true; } } else { dir = Transform.forward; } FinalRotation.SetLookRotation(dir); if (distance < Owner.BlackBoard.WeaponRange) { FinalPosition = StartPosition; } else { FinalPosition = Action.Target.Transform.position - dir * Owner.BlackBoard.WeaponRange; } MoveTime = (FinalPosition - StartPosition).magnitude / 20.0f; RotationTime = angle / 720.0f; } else { FinalRotation.SetLookRotation(Action.AttackDir); RotationTime = Vector3.Angle(Transform.forward, Action.AttackDir) / 720.0f; MoveTime = 0; } RotationOk = RotationTime == 0; PositionOK = MoveTime == 0; CurrentRotationTime = 0; CurrentMoveTime = 0; if (Owner.IsPlayer && AnimAttackData.HitCriticalType != E_CriticalHitType.None && Action.Target && Action.Target.BlackBoard.CriticalAllowed && Action.Target.IsBlocking == false && Action.Target.IsInvulnerable == false && Action.Target.IsKnockedDown == false) { if (backstab) { Critical = true; } else { // Debug.Log("critical chance" + Owner.GetCriticalChance() * AnimAttackData.CriticalModificator * Action.Target.BlackBoard.CriticalHitModifier); Critical = Random.Range(0, 100) < Owner.GetCriticalChance() * AnimAttackData.CriticalModificator * Action.Target.BlackBoard.CriticalHitModifier; } } else { Critical = false; } Knockdown = AnimAttackData.HitAreaKnockdown && Random.Range(0, 100) < 60 * Owner.GetCriticalChance(); }