private void OnUpgradeSkill(Event a_Event, params object[] a_Params) { IUsesSkills unit = a_Params[0] as IUsesSkills; int skillIndex = (int)a_Params[1]; if (unit == null || unit.GetHashCode() != GetHashCode() || m_SkillPrefabs.Count == 0) { return; } Skill skill = unit.skills[skillIndex]; ICastable <IUsesSkills> castable = m_SkillPrefabs[skillIndex].GetComponent <ICastable <IUsesSkills> >(); ++skill.level; skill.skillData.cost = castable.baseCost + (skill.level - 1) * castable.costGrowth; skill.skillData.damage = castable.baseDamage + (skill.level - 1) * castable.damageGrowth; skill.skillData.maxCooldown = castable.baseMaxCooldown - (skill.level - 1) * castable.maxCooldownGrowth; skill.skillData.description = castable.UpdateDescription(skill); --m_StoredSkillUpgrades; if (m_StoredSkillUpgrades != 0) { Publisher.self.DelayedBroadcast(Event.UnitCanUpgradeSkill, this); } }
private void OnUseSkill(Event a_Event, params object[] a_Params) { IUsesSkills unit = a_Params[0] as IUsesSkills; if (unit == null) { return; } int skillIndex = (int)a_Params[1]; if (unit.GetHashCode() != GetHashCode() || m_Skills.Count <= skillIndex || m_Skills[skillIndex].level <= 0 || !(m_Skills[skillIndex].remainingCooldown <= 0.0f) || !(m_Skills[skillIndex].skillData.cost <= m_Mana)) { return; } GameObject newObject = Instantiate(m_Skills[skillIndex].skillPrefab); ICastable <IUsesSkills> newSkill = newObject.GetComponent <ICastable <IUsesSkills> >(); newSkill.parent = this; newSkill.skillData = m_Skills[skillIndex].skillData.Clone(); mana -= m_Skills[skillIndex].skillData.cost; m_Skills[skillIndex].PutOnCooldown(); }
private void Search() { foreach (IControllable controlable in m_Controlables) { if (controlable.following == null) { SetFollowing(controlable); } if (controlable.following != null) { IUsesSkills skillUser = controlable as IUsesSkills; controlable.navMashAgent.SetDestination(controlable.following.transform.position); float distanceFromEnemyToTarget = Vector3.Distance(controlable.following.transform.position, controlable.transform.position); if ((distanceFromEnemyToTarget < 7 && controlable.controllerType == ControllerType.GoblinMage) || (distanceFromEnemyToTarget < 2 && controlable.controllerType == ControllerType.Goblin)) { Publisher.self.Broadcast(Event.UseSkill, skillUser, 0); } } } }
private void OnCanUpgradeSkill(Event a_Event, params object[] a_Params) { IUsesSkills unit = a_Params[0] as IUsesSkills; if (unit == null) { return; } if (m_Controlables.Contains(unit as IControllable)) { int skillindex = Random.Range(0, unit.skills.Count - 1); Publisher.self.Broadcast(Event.UpgradeSkill, unit, skillindex); } }
private void Update() { if (Input.GetKeyDown(KeyConfiguration.self.userConfigurations[m_PlayerIndex].targetModeKey.keyCode) || #if !UNITY_WEBGL GameManager.self.GetButtonState(m_PlayerIndex, KeyConfiguration.self.userConfigurations[m_PlayerIndex].targetModeButton.keyCode)) #else false) #endif { if (m_Player.playerCamera.isTargeting) { m_Player.playerCamera.target = null; } else { Vector3 direction = new Vector3( Mathf.Sin(m_Controllable.transform.eulerAngles.y * (Mathf.PI / 180f)), 0, Mathf.Cos(m_Controllable.transform.eulerAngles.y * (Mathf.PI / 180f))); RaycastHit objectHit; Physics.SphereCast( new Ray(m_Controllable.transform.position, direction), 3f, out objectHit); IAttackable unit = objectHit.transform.gameObject.GetComponent <IAttackable>(); if (objectHit.transform.gameObject != null && unit != null && unit.faction != m_Controllable.gameObject.GetComponent <IAttackable>().faction) { m_Player.playerCamera.target = objectHit.transform.gameObject; } } } if (Input.GetKeyDown(KeyConfiguration.self.userConfigurations[m_PlayerIndex].switchTargetKey.keyCode) && m_Player.playerCamera.isTargeting) { List <Collider> objectsHit = Physics.OverlapSphere(m_Player.playerCamera.target.transform.position, 10f).ToList(); List <Collider> parsedUnits = objectsHit.Where( x => x.gameObject.GetComponent <Unit>() != null && x.gameObject.GetComponent <Unit>() != m_Player.unit && x.gameObject != m_Player.playerCamera.target).ToList(); foreach (Collider parsedUnit in parsedUnits) { Debug.Log(parsedUnit.gameObject.name); } if (parsedUnits.Count > 0) { m_Player.playerCamera.target = parsedUnits[0].gameObject; } } if (m_Controllable.canMoveWithInput) { m_Controllable.velocity = Vector3.zero; Moving dPad = Moving.nowhere; #if !UNITY_WEBGL dPad.forward = GameManager.self.GetButtonState( m_PlayerIndex, KeyConfiguration.self.userConfigurations[m_PlayerIndex].verticalButtonAxis.positive.keyCode); dPad.back = GameManager.self.GetButtonState( m_PlayerIndex, KeyConfiguration.self.userConfigurations[m_PlayerIndex].verticalButtonAxis.negative.keyCode); dPad.left = GameManager.self.GetButtonState( m_PlayerIndex, KeyConfiguration.self.userConfigurations[m_PlayerIndex].horizontalButtonAxis.negative.keyCode); dPad.right = GameManager.self.GetButtonState( m_PlayerIndex, KeyConfiguration.self.userConfigurations[m_PlayerIndex].horizontalButtonAxis.positive.keyCode); #else dPad.forward = Input.GetAxisRaw("POV Vertical") > 0.0f; dPad.back = Input.GetAxisRaw("POV Vertical") < 0.0f; dPad.left = Input.GetAxisRaw("POV Horizontal") < 0.0f; dPad.right = Input.GetAxisRaw("POV Horizontal") > 0.0f; #endif m_Controllable.isMoving = new Moving { forward = Input.GetKey(KeyConfiguration.self.userConfigurations[m_PlayerIndex].verticalKeyAxis.positive.keyCode) | dPad.forward, back = Input.GetKey(KeyConfiguration.self.userConfigurations[m_PlayerIndex].verticalKeyAxis.negative.keyCode) | dPad.back, left = Input.GetKey(KeyConfiguration.self.userConfigurations[m_PlayerIndex].horizontalKeyAxis.negative.keyCode) | dPad.left, right = Input.GetKey(KeyConfiguration.self.userConfigurations[m_PlayerIndex].horizontalKeyAxis.positive.keyCode) | dPad.right }; if (m_Controllable.isMoving.forward) { m_Controllable.velocity += Vector3.forward; } if (m_Controllable.isMoving.back) { m_Controllable.velocity += Vector3.back; } if (m_Controllable.isMoving.left) { m_Controllable.velocity += Vector3.left; } if (m_Controllable.isMoving.right) { m_Controllable.velocity += Vector3.right; } if (m_Player.playerCamera.isTargeting) { m_Controllable.transform.eulerAngles = new Vector3( m_Controllable.transform.eulerAngles.x, m_Player.playerCamera.transform.eulerAngles.y + 25f, m_Controllable.transform.eulerAngles.z); } else if (Input.GetMouseButton(1)) { m_Controllable.transform.eulerAngles = new Vector3( m_Controllable.transform.eulerAngles.x, m_Player.playerCamera.transform.eulerAngles.y, m_Controllable.transform.eulerAngles.z); } if (m_Controllable.velocity != Vector3.zero) { float angle = 0f; if (m_Player.playerCamera.isTargeting) { angle = (m_Player.playerCamera.transform.eulerAngles.y + 25f) * (Mathf.PI / 180); } else { angle = m_Player.playerCamera.transform.eulerAngles.y * (Mathf.PI / 180); } angle += Mathf.Atan(m_Controllable.velocity.x / m_Controllable.velocity.z); if ((m_Controllable.velocity.x < 0.0f && m_Controllable.velocity.z < 0.0f) || (m_Controllable.velocity.x > 0.0f && m_Controllable.velocity.z < 0.0f) || (m_Controllable.velocity.x == 0.0f && m_Controllable.velocity.z < 0.0f)) { angle += Mathf.PI; } m_Controllable.velocity = new Vector3( m_Controllable.speed * Mathf.Sin(angle), 0, m_Controllable.speed * Mathf.Cos(angle)); if (!Input.GetMouseButton(1) && !m_Player.playerCamera.isTargeting) { m_Controllable.transform.eulerAngles = new Vector3( m_Controllable.transform.eulerAngles.x, angle * (180 / Mathf.PI), m_Controllable.transform.eulerAngles.z); } } Vector2 leftStick; Vector2 rightStick; #if !UNITY_WEBGL leftStick.x = GameManager.self.GetStickValue(m_PlayerIndex, GameManager.Stick.Left).X; leftStick.y = GameManager.self.GetStickValue(m_PlayerIndex, GameManager.Stick.Left).Y; rightStick.x = GameManager.self.GetStickValue(m_PlayerIndex, GameManager.Stick.Right).X; rightStick.y = GameManager.self.GetStickValue(m_PlayerIndex, GameManager.Stick.Right).Y; #else leftStick.x = Input.GetAxisRaw("Horizontal"); leftStick.y = Input.GetAxisRaw("Vertical"); rightStick.x = Input.GetAxisRaw("Right Stick X"); rightStick.y = Input.GetAxisRaw("Right Stick Y"); #endif if (rightStick.x != 0.0f || rightStick.y != 0.0f) { if (m_Player.playerCamera.isTargeting) { if (Mathf.Abs(rightStick.x) > Mathf.Abs(rightStick.y)) { ; } } else { Vector3 newAngle = m_Player.playerCamera.transform.eulerAngles; newAngle += new Vector3( rightStick.y * 100 * Time.deltaTime, rightStick.x * 100 * Time.deltaTime, 0); newAngle = new Vector3( Mathf.Clamp( newAngle.x, 10, 90), newAngle.y, newAngle.z); m_Player.playerCamera.transform.eulerAngles = newAngle; } } if (leftStick.x != 0.0f || leftStick.y != 0.0f) { m_Controllable.velocity = new Vector3( leftStick.x * m_Controllable.speed, m_Controllable.velocity.y, leftStick.y * m_Controllable.speed); float angle = m_Player.playerCamera.transform.eulerAngles.y * (Mathf.PI / 180); angle += Mathf.Atan(m_Controllable.velocity.x / m_Controllable.velocity.z); if ((m_Controllable.velocity.x < 0.0f && m_Controllable.velocity.z < 0.0f) || (m_Controllable.velocity.x > 0.0f && m_Controllable.velocity.z < 0.0f) || (m_Controllable.velocity.x == 0.0f && m_Controllable.velocity.z < 0.0f)) { angle += Mathf.PI; } m_Controllable.velocity = new Vector3( m_Controllable.speed * Mathf.Sin(angle), 0, m_Controllable.speed * Mathf.Cos(angle)); m_Controllable.transform.eulerAngles = new Vector3( m_Controllable.transform.eulerAngles.x, angle * (180f / Mathf.PI), m_Controllable.transform.eulerAngles.z); } } IUsesSkills skillUser = m_Controllable as IUsesSkills; #if !UNITY_WEBGL bool[] isPressed = new bool[skillUser.skills.Count]; for (int j = 0; j < skillUser.skills.Count; ++j) { isPressed[j] = GameManager.self.GetButtonState( m_PlayerIndex, KeyConfiguration.self.userConfigurations[m_PlayerIndex].skillButtons[j].keyCode); } #else bool[] isPressed = { Input.GetAxisRaw("Skill 1") != 0.0f, Input.GetAxisRaw("Skill 2") != 0.0f, Input.GetAxisRaw("Skill 3") != 0.0f, Input.GetAxisRaw("Skill 4") != 0.0f }; #endif if (skillUser != null) { for (int j = 0; j < skillUser.skills.Count; ++j) { if (Input.GetKey(KeyConfiguration.self.userConfigurations[m_PlayerIndex].skillKeys[j].keyCode) || isPressed[j]) { Publisher.self.Broadcast(Event.UseSkill, skillUser, j); } } } }