public Transform ReturnNearestOpenAttackSlot(Transform unitTransform) { float distance = Mathf.Infinity; int runningIndex = -1; for (int i = 0; i < possibleSlots.Count; i++) { AttackSlot slot = possibleSlots[i].GetComponent <AttackSlot>(); if (slot.isOpen) { float currentDistance = (possibleSlots[i].position - unitTransform.position).magnitude; if (currentDistance < distance) { distance = currentDistance; runningIndex = i; } } } if (runningIndex < 0) { Debug.Log("No open spots found!"); return(unitTransform); } else { possibleSlots[runningIndex].GetComponent <AttackSlot>().isOpen = false; return(possibleSlots[runningIndex]); } }
public void SwitchState(State newState, AttackSlot attack) { currentState.OnStateExit(); currentState = newState; attackType = attack; newState.OnStateEnter(); }
private void Start() { if (transform.childCount > 0) { AttackSlot firstChild = transform.GetChild(0).GetComponent <AttackSlot>(); if (firstChild.IsLightAttack && lightAttackComboContinuation == null) { lightAttackComboContinuation = firstChild; } else if (firstChild.IsHeavyAttack && heavyAttackComboContinuation == null) { heavyAttackComboContinuation = firstChild; } if (transform.childCount > 1) { AttackSlot secondChild = transform.GetChild(1).GetComponent <AttackSlot>(); if (secondChild.IsLightAttack && lightAttackComboContinuation == null) { lightAttackComboContinuation = secondChild; } else if (secondChild.IsHeavyAttack && heavyAttackComboContinuation == null) { heavyAttackComboContinuation = secondChild; } } } }
public void LoadDefense() { GameObject slot = Instantiate(_attackSlot); slot.transform.SetParent(transform.Find("ActionMask").Find("GridView")); slot.transform.localScale = new Vector3(1, 1, 1); slot.transform.localPosition = Vector3.zero; slot.transform.Find("Crystal").GetComponentInChildren <Text>().text = 1 + ""; slot.transform.Find("Image").GetComponent <Image>().sprite = _defenseIcon[0]; slot.transform.Find("Icon").gameObject.SetActive(false); SkillBlock skill = new SkillBlock(); skill.slotId = _blockCount; skill.defCrystal = 1; skill.heroStoreId = 1; skill.color = 5; skill.isAttack = false; skill.blockStack = 1; skill.crystal = 1; skill.obj = slot; AttackSlot atk = slot.GetComponent <AttackSlot>(); atk._skill = skill; _attackList.Add(skill); _blockCount++; transform.Find("ActionMask").Find("GridView").localPosition = new Vector3(1, 0, 0); }
public override void OnStateEnter() { base.OnStateEnter(); character.timer = 0; attack = character.attackType; character.canAttack = false; character.stateString = "attack"; //Debug.Log(attack); Step(); }
public void LoadAttack() { if (_core == null) { _core = Camera.main.GetComponent <MainCore>(); } if (_battleCon == null) { _battleCon = _core._battleCon; } int ranSlot = Random.Range(0, _battleCon._heroData.Length); if (_battleCon._heroData[ranSlot].hero.hp == 0) { //Debug.Log("old block "+ranSlot); ranSlot = Random.Range(0, _battleCon._heroData.Length); //Debug.Log("new ran block "+ ranSlot); } GameObject slot = Instantiate(_attackSlot); slot.transform.SetParent(transform.Find("ActionMask").Find("GridView")); slot.transform.localScale = new Vector3(1, 1, 1); slot.transform.localPosition = Vector3.zero; if (getSpriteSet != _battleCon._heroData[ranSlot].hero.hero.spriteSet) { getSpriteSet = _battleCon._heroData[ranSlot].hero.hero.spriteSet; loadSprite = Resources.LoadAll <Sprite>("Sprites/Character/Hero/" + getSpriteSet); } slot.transform.Find("Icon").GetComponent <Image>().sprite = loadSprite.Single(s => s.name == "Map_" + _battleCon._heroData[ranSlot].hero.hero.spriteName); SkillBlock skill = new SkillBlock(); skill.slotId = _blockCount; skill.defCrystal = _battleCon._heroData[ranSlot].hero.attack[0].skill.crystal; slot.transform.Find("Crystal").GetComponentInChildren <Text>().text = skill.defCrystal.ToString(); slot.transform.Find("Image").GetComponent <Image>().sprite = loadSprite.Single(s => s.name == "Skill_" + _battleCon._heroData[ranSlot].hero.hero.spriteName); skill.heroStoreId = _battleCon._heroData[ranSlot].hero.id; skill.blockStack = 1; skill.color = _battleCon._heroData[ranSlot].slotId; skill.isAttack = true; skill.isUltimate = false; skill.crystal = skill.defCrystal; skill.obj = slot; AttackSlot atk = slot.GetComponent <AttackSlot>(); atk._skill = skill; _attackList.Add(skill); _blockCount++; transform.Find("ActionMask").Find("GridView").localPosition = new Vector3(1, 0, 0); }
private void AcquireAttackSlots() { for (int i = 0; i < attackSlotHolder.childCount; i++) { Transform child = attackSlotHolder.GetChild(i); AttackSlot slot = child.GetComponent <AttackSlot>(); if (slot != null) { slot.isOpen = true; possibleSlots.Add(child); } } }
public void UseAttack(AttackSlot attack) { if (getCore().getMenuCon().UseCrystal(attack.crystal)) { getCore().getBattCon()._currentHeroBatt.Attack(attack.skillSlot, attack.blockStack); DeleteBlock(attack); UpdateAttackSlot(); } else { getCore().NotifyCrystal("Not enough crystal!"); } }
public void LoadAttack() { #pragma warning disable CS0618 // Type or member is obsolete int skillSlot = Random.RandomRange(0, 3); #pragma warning restore CS0618 // Type or member is obsolete Hero hero = getCore().getBattCon()._currentHeroBatt; if (hero.getStatus().hate == 100) { skillSlot = 3; hero.getStatus().hate = 0; } GameObject slot = Instantiate(_attackSlot); slot.transform.SetParent(transform.Find("ActionMask").Find("GridView")); slot.transform.localScale = new Vector3(1, 1, 1); slot.transform.localPosition = Vector3.zero; if (getSpriteSet != hero.getSpriteSet()) { getSpriteSet = hero.getSpriteSet(); loadSkillIcons = Resources.LoadAll <Sprite>("Sprites/IconSkill/"); } slot.transform.Find("Image").GetComponent <Image>().sprite = loadSkillIcons.Single(s => s.name == "Skill_" + hero.getSpriteName() + "_" + skillSlot); AttackSlot script = slot.GetComponent <AttackSlot>(); script.skillSlot = skillSlot; script.number = _blockCount; script.defCrystal = hero.getStatus().attack[skillSlot].crystal; slot.transform.Find("Crystal").GetComponentInChildren <Text>().text = script.defCrystal.ToString(); script.blockStack = 1; script.color = skillSlot; script.crystal = script.defCrystal; script.obj = slot; _attackList.Add(script); _blockCount++; transform.Find("ActionMask").Find("GridView").localPosition = new Vector3(1, 0, 0); }
void DeleteBlock(AttackSlot attack) { string numberIsDelete = ""; for (int i = 0; i < _attackList.Count; i++) { if (_attackList[i].number == attack.number) { if (_attackList[i].blockStack == 3) { Destroy(_attackList[i - 1].obj); numberIsDelete += _attackList[i - 1].number + ":"; Destroy(_attackList[i - 2].obj); numberIsDelete += _attackList[i - 2].number + ":"; } else if (_attackList[i].blockStack == 2) { Destroy(_attackList[i - 1].obj); numberIsDelete += _attackList[i - 1].number + ":"; } Destroy(_attackList[i].obj); numberIsDelete += _attackList[i].number + ""; break; } } string[] splitSlotId = numberIsDelete.Split(':'); for (int a = 0; a < splitSlotId.Length; a++) { foreach (AttackSlot data in _attackList.ToList()) { if (data.number == System.Int32.Parse(splitSlotId[a])) { _attackList.Remove(data); break; } } } }
/// <summary> /// Actually switches the animation to the next attack /// </summary> /// <param name="attackType"></param> private void SwitchToNextAttack(AttackSlot.AttackType attackType) { _Animator.SetBool("AttackFine", false); _CurrentAttackCombo = attackType == AttackSlot.AttackType.Light? _CurrentAttackCombo.LightComboContinuation: _CurrentAttackCombo.HeavyComboContinuation; comboCounter++; _AnimatorOverride[_NextComboLabel] = _CurrentAttackCombo.AnimationToPlay; if (comboCounter % 2 == 1) { //_CurrentAnimLabelA = _CurrentAttackCombo.AnimationToPlay.name; _CurrentAnimClipA = _CurrentAttackCombo.AnimationToPlay; } else { //_CurrentAnimLabelB = _CurrentAttackCombo.AnimationToPlay.name; _CurrentAnimClipB = _CurrentAttackCombo.AnimationToPlay; } _Animator.SetTrigger("Attack"); canDoSomethingElseAfterAttacking = false; checkIfPlayerWantsToKeepCombo = false; transitioningToAnotherCombo = true; playerWantsToKeepCombo = false; }
private void CheckAttack() { bool wantsToLightAttack = Input.GetButton("NormalAttack"); bool wantsToHeavyAttack = Input.GetButton("HeavyAttack"); bool wantsToAttack = wantsToLightAttack || wantsToHeavyAttack; if (checkIfPlayerWantsToKeepCombo && wantsToAttack) { nextComboIsLight = wantsToLightAttack; playerWantsToKeepCombo = true; checkIfPlayerWantsToKeepCombo = false; } else if (canDoSomethingElseAfterAttacking) { bool canComboLight = wantsToLightAttack && _CurrentAttackCombo.HasLightCombo; if (canComboLight || (wantsToHeavyAttack && _CurrentAttackCombo.HasHeavyCombo)) { transitioningToAnotherCombo = true; if (m_ShowAttackDebugs) { Debug.Log("[PlayerAttack] While he could choose something else, the player decided to attack!"); } canDoSomethingElseAfterAttacking = false; checkIfPlayerWantsToKeepCombo = false; playerWantsToKeepCombo = false; SwitchToNextAttack(canComboLight?AttackSlot.AttackType.Light:AttackSlot.AttackType.Heavy); } else if (_TriesToDoSomethingElse) { if (m_ShowAttackDebugs) { Debug.Log("[PlayerAttack] While he could choose something else, the player decided to choose something else!"); } ChangeToIdle(); //Since the attack method occurs before any other method, the player will be able to actually dash } } else if (_CanStartAttacking && wantsToAttack) { if (m_ShowAttackDebugs) { Debug.Log("[PlayerAttack] While idling, the player decided to attack!"); } comboCounter = 1; _CurrentAttackCombo = wantsToLightAttack ? m_StartingLightAttack : m_StartingHeavyAttack; _Animator.SetBool("AttackFine", false); if (_CurrentAnimClipA == null) { _CurrentAnimClipA = _AnimatorOverride["AttackAPlaceHolder"]; } if (_CurrentAnimClipB == null) { _CurrentAnimClipB = _AnimatorOverride["AttackBPlaceHolder"]; } animatorOverride[_NextComboLabel] = _CurrentAttackCombo.AnimationToPlay; _CurrentAnimClipA = _CurrentAttackCombo.AnimationToPlay; _Animator.SetTrigger("Attack"); ChangeState(PlayerState.Attacking); //Animation takes care of collision activation, what moment to deal damage and } }