public void AddToControlledUnits(unit_control_script unit) { if (controlled_units.Contains(unit)) { return; } controlled_units.Add(unit); }
public void MagicDamage(float amount, unit_control_script attacker) { if (!is_dead && !magic_immune) { float total_damage = amount; //Add spell amp total_damage += total_damage * attacker.GetSpellamp() / 100.0f; total_damage -= total_damage * (MagicResist / 100.0f); //reduce hp by the amount of magic damage being done hp -= total_damage; } }
public void SetOwner(GameObject owner) { this.owner = owner; if ((enemy_handle = owner.GetComponent <enemy_controller>()) != null) { on_enemy = true; enemy_handle.RegisterBuff(this); return; } on_enemy = false; unit_handle = owner.GetComponent <unit_control_script>(); unit_handle.RegisterBuff(this); }
// Start is called before the first frame update void Start() { //locate the navMeshAgent navmeshAgent = GetComponent <NavMeshAgent>(); //get the unit unit = GetComponent <unit_control_script>(); // MoveTo(new Vector3(50, 0, 0)); //disable rotation of the nav mesh navmeshAgent.updateRotation = false; navmeshAgent.angularSpeed = 0; //set the stopping distance to be the same as the obstacle avoidance radius navmeshAgent.stoppingDistance = 30;//navmeshAgent.radius*2; }
public void DamageEnemy(float amount, unit_control_script attacker) { if (is_dead || !can_be_attacked) { return; } //make the particle system activate bleed_system.Play(); hp -= amount * 1 - ((0.06f * Armor) / (1 + 0.06f * Mathf.Abs(Armor))); if (target == null) { target = attacker; } }
public virtual void SetParentUnit(GameObject parent_unit) { this.parent_unit = parent_unit; //decide whther we are on an enemy or a player if (parent_unit.GetComponent <unit_control_script>() == null) { on_enemy = true; enemy_control_handle = parent_unit.GetComponent <enemy_controller>(); } else { on_enemy = false; unit_control_handle = parent_unit.GetComponent <unit_control_script>(); } }
// Start is called before the first frame update void Start() { //Get the ui script ui = GetComponent <ui_script>(); //get the camera script camera = GetComponent <Camera_script>(); controlled_units = new List <unit_control_script>(); canvas = GetComponent <Canvas>(); //add all of the manually added units to the controlled units group foreach (GameObject unit in ManuallyAddedUnits) { controlled_units.Add(unit.GetComponent <unit_control_script>()); main_unit = unit.GetComponent <unit_control_script>(); //set the unit control script unit } ui.SetActiveUnit(main_unit); camera.SetActiveUnit(main_unit); //register player with the game manager game_manager.GetGameManager().RegisterPlayer(gameObject); }
private void Start() { //set the hp to full hp = MaxHp; //create the hp bar hp_bar = Instantiate(HpBar); //create the bleed effect bleed_system = Instantiate(BleedEffect, transform.position + Vector3.up * HealthBarHeight, Quaternion.identity, transform).GetComponent <ParticleSystem>(); bleed_system.Stop(); //Get the player controller //player_controller = GameObject.Find("PlayerController").GetComponent<player_controller_script>(); //get the camera cam = GameObject.FindObjectOfType <Camera>(); hp_controller = hp_bar.GetComponent <hp_bar_controller>(); hp_controller.SetHpAndMaxHp(hp, MaxHp); //set default values can_attack = CanAttack; can_be_attacked = _CanBeAttacked; can_move = CanMove; can_cast = CanCast; magic_immune = MagicImmune; physical_immune = PhysicalImmune; can_die = CanDie; //make sure the enemy is alive is_dead = false; //set the target to null target = null; GlobalManager.GetGlobalManager().GetLevelManager().AddEnemy(this); //get the nav agent if (can_attack) { nav_agent = GetComponent <NavMeshAgent>(); } }
public void OnAttach(unit_control_script unit) { for (int i = 0; i < types.Length; i++) { //add each attribute to the player switch (types[i]) { case AttributeType.Agility: unit.AddAgility(values[i]); break; case AttributeType.Strength: unit.AddStrength(values[i]); break; case AttributeType.Int: unit.AddInt(values[i]); break; case AttributeType.Damage: unit.AddDamage(values[i]); break; case AttributeType.Armor: unit.AddArmor(values[i]); break; case AttributeType.Attack_Range: unit.AddAttackRange(values[i]); break; case AttributeType.Attack_Speed: unit.AddAttackSpeed(values[i]); break; case AttributeType.CastSpeed_Reduction: unit.AddCastSpeedReduction(values[i]); break; case AttributeType.Cast_Range: unit.AddCastRange(values[i]); break; case AttributeType.Cleave: unit.AddCleave(values[i]); break; case AttributeType.Cooldown_Reduction: unit.AddCooldownReduction(values[i]); break; case AttributeType.Crit_Chance: unit.AddCritChance(values[i]); break; case AttributeType.Crit_Damage: unit.AddCritDamage(values[i]); break; case AttributeType.Hp: unit.AddMaxHp(values[i]); break; case AttributeType.Hp_Regen: unit.AddHpRegen(values[i]); break; case AttributeType.Magice_Resistance: unit.AddMagicResistance(values[i]); break; case AttributeType.Mana: unit.AddMaxMana(values[i]); break; case AttributeType.Mana_Regen: unit.AddManaRegen(values[i]); break; case AttributeType.Pure_Damage: unit.AddPureDamage(values[i]); break; case AttributeType.SpellAmp: unit.AddSpellAmp(values[i]); break; case AttributeType.LifeSteal: unit.AddLifeSteal(values[i]); break; case AttributeType.SpellLifeSteal: unit.AddSpellLifeSteal(values[i]); break; case AttributeType.Splash: unit.AddSplash(values[i]); break; case AttributeType.Status_Resist: unit.AddStatusResist(values[i]); break; } } }
public void RemovePlayerUnit(unit_control_script unit) { player_units.Remove(unit); }
public void AddPlayerUnit(unit_control_script unit) { player_units.Add(unit); }
public void RemoveFromControlled(unit_control_script unit) { controlled_units.Remove(unit); }
public void SetActiveUnit(unit_control_script unit) { active_unit = unit; }
public void SetAttackOrder(unit_control_script target) { //set the nav agent target to the attack target nav_agent.destination = target.GetPosition(); nav_agent.stoppingDistance = (AttackRange / 100) - AttackRange / 1000.0f; }
public void SetOwner(unit_control_script owner) { this.owner = owner; }
public void SetActiveUnit(unit_control_script unit) { active_unit = unit; //set up the level indicators setupLevelIndicators(); }
// Update is called once per frame void Update() { int reee; if (can_move == !CanMove) { reee = 3; } if (is_dead) { return; } if (hp < 0.0001) { hp = 0; gameObject.AddComponent <DieAndFall>().Duration = 2.0f; can_be_attacked = false; //destroy hp bar Destroy(hp_bar); Destroy(gameObject.GetComponent <NavMeshAgent>()); Destroy(gameObject.GetComponent <CapsuleCollider>()); Destroy(gameObject.GetComponent <NavMeshObstacle>()); is_dead = true; return; } //set hp bar position //hp_bar_back.transform.position = cam.WorldToScreenPoint(transform.position); hp_controller.SetPosition(transform.position + Vector3.up * HealthBarHeight); //update the hp bars hp hp_controller.SetHpAndMaxHp(hp, MaxHp); //decide whether we can attack the player or noy //set attack target to something in range if we dont have one if (can_attack && heading_target == null && (target == null || target.IsDead())) { //get the units in range and choose one randomly List <unit_control_script> units_in_range = GlobalManager.GetGlobalManager().GetLevelManager().GetPlayerUnitsInRange(GetPosition(), DetectionRange); if (units_in_range.Count > 0) { heading_target = units_in_range[Random.Range(0, units_in_range.Count)]; } else { heading_target = null; } } //Check to see if there are any units in attack range if (can_attack && (target == null || target.IsDead())) { List <unit_control_script> units_in_range = GlobalManager.GetGlobalManager().GetLevelManager().GetPlayerUnitsInRange(GetPosition(), AttackRange); if (units_in_range.Count > 0) { target = units_in_range[Random.Range(0, units_in_range.Count)]; } } if (can_attack && target != null) { SetAttackOrder(target); } else if (can_attack && heading_target != null) { SetAttackOrder(heading_target); } ////get the nav agent //if (can_attack && nav_agent == null) // nav_agent = GetComponent<NavMeshAgent>(); //set the movespeed and acceleration if (can_move) { nav_agent.speed = MoveSpeed / 10; nav_agent.angularSpeed = MoveSpeed; nav_agent.acceleration = MoveSpeed; } else { if (nav_agent != null) { nav_agent.speed = 0; nav_agent.acceleration = 0; } } //check to see if we can attack the player if (can_attack && (target != null || !target.IsDead()) && Vector3.Distance(target.transform.position, transform.position) < AttackRange / 100.0f) { windup -= Time.deltaTime; } else { //reset windup windup = BaseAttackTime; } if (can_attack && windup <= 0) { //attack the enemy target target.Damage(Damage, this); //reset windup windup = BaseAttackTime; } }