public float Damage(CombatChar target, Weapons weapon, bool isCrit) { // Causa the damage, based on the attacker, the weapon and the target attributes float wepDamage = Random.Range(weapon.minDamage, weapon.maxDamage); wepDamage = (weapon.minDamage + weapon.maxDamage) / 2; //Debug.Log(wepDamage); wepDamage += weapon.bonusDamage.getBon(); wepDamage *= weapon.multDamage; // get damage between characters stats //ToDo float charDamage = damageModifier(weapon.attackSkill, target.C.lvl); charDamage -= target.Fortitude(target.C.lvl); charDamage *= weapon.multAttr; charDamage += C.attributes[weapon.damageAttr].GetMod(target.C.lvl) * 2; //Debug.Log(charDamage); //get protection float prot = target.Protection() - ArmorPenetration(weapon); prot = prot < 0 ? 0 : prot; //Debug.Log("prot Bonus == " + properties["protection"].GetValue()); //Debug.Log(prot); //Debug.Log(ArmorPenetration(wep)); float total = wepDamage + charDamage - prot; total = total < 0 ? 0 : total; total *= isCrit ? 2f + C.Properties[Properties.CriticalDamage].GetValue() / 100f : 1; return(total); }
public IEnumerator AttackAnim(Weapons weapon, CombatChar target, bool isCounter) { //Vector3 initialPos = sprite.transform.position; Vector3 newPos; float count = 0f; while (count <= 1f) { Vector3 tarPos = target.C.sprite.transform.position; count += Time.deltaTime * 4; newPos = Vector3.Lerp(transform.position, tarPos, count); C.sprite.transform.position = newPos; if (Vector3.Distance(C.sprite.transform.position, tarPos) <= 1) { //inRange = true; Attack(weapon, target, isCounter); count = 0; Vector3 newInitialPos = C.sprite.transform.position; while (count <= 1f) { count += Time.deltaTime * 4; newPos = Vector3.Lerp(newInitialPos, transform.position + initialPos, count); C.sprite.transform.position = newPos; yield return(null); } isMoving = false; break; } yield return(null); } }
public override void Effect(CombatChar target) { targetChar = target; targetChar.takeDamage(castDamage, false, false, true); target.sprite.GetComponent <SpriteRenderer>().color = Color.green; target.C.fillLife.color = Color.green; }
public CombatChar GetAttackTarget(List <CombatChar> targets) { // Get target from a list of possible targets, ahd pick the one with the highest aggro if (targets == null) { return(null); } CombatChar target = null; foreach (CombatChar tar in targets) { if (target == null) { target = tar; } else { if (tar.GetAggro() > target.GetAggro()) { target = tar; } } } return(target); }
public void Attack(Weapons weapon, CombatChar target, bool isCounter) { // Perform the rolls to see if the attacks was succeded and if its a counter attack already, it doesn't cause another counter. int attkRoll = C.skills[weapon.attackSkill].GetMod(target.C.lvl); attkRoll += C.attributes[weapon.attackAttr].GetMod(target.C.lvl); attkRoll += C.Properties[Properties.Attack].GetValue(); attkRoll += (int)weapon.hitMod; attkRoll += Random.Range(1, 101); //attkRoll += CheckForArmorAndWeaponCritical(target); int evadeRoll = target.EvadeRoll(this.C.lvl); //Debug.Log("attacking " + attkRoll + " x " + evadeRoll ); if (attkRoll >= evadeRoll) { bool isCrit = CriticalRoll(weapon, target); float damage = Damage(target, weapon, isCrit); target.takeDamage(damage, isCrit, isCounter); } else if (!isCounter) { target.CheckForCounter(weapon, this); } }
void OnTriggerStay2D(Collider2D coll) { if (target != null && coll.transform == target.transform) { return; } if (coll.CompareTag("Player")) { if (InLineOfSight(coll.transform)) { CombatChar collCombat = coll.GetComponent <CombatChar>(); if (target == null) { target = collCombat; } if (collCombat.GetAggro() >= target.GetAggro()) { target = collCombat; } StartCoroutine(pathfinder.GetWaypoints(transform.position, target.transform.position, this)); //Debug.DrawLine(transform.position, coll.transform.position); } else { //Debug.DrawLine(transform.position, coll.transform.position, Color.red); } } }
public bool checkInRange(CombatChar target, float range) { // Function used just before the attack or cast // If the target is itself you are always in range if (target != this) { float distance = target.GetComponent <Collider2D>().Distance(transform.GetComponent <Collider2D>()).distance; if (distance <= range) { return(true); } else { return(false); } } else { return(true); } //Vector3 closestPoint = castTarget.GetComponent<Collider2D>().ClosestPointOnBounds(transform.position); //float distance = Vector3.Distance(transform.position, closestPoint); }
public List <CombatChar> GetTargetsOnRange(float range, CombatManager.Targets t) { // Get a list of possible targets, based if they are friendly or foe List <CombatChar> targets = new List <CombatChar>(); LayerMask mask = t == CombatManager.Targets.Enemies ? enemy : allies; Collider2D[] hitCollider = Physics2D.OverlapCircleAll(transform.position, range, mask); foreach (Collider2D coll in hitCollider) { CombatChar Char = coll.GetComponent <CombatChar>(); if (Char.isAlive && Char.isTarget) { if (InLOS(Char.transform)) { targets.Add(Char); } } } if (targets.Count <= 0) { return(null); } else { return(targets); } }
public void CheckForCounter(Weapons weapon, CombatChar target) { int counter = (int)weapon.counterRating + C.Properties[Properties.Counter].GetValue(); counter += CheckForArmorAndWeaponCounter(weapon, target); int roll = Random.Range(0, 100); if (roll <= counter) { StartCoroutine(AttackAnim(weapon, target, true)); // int lvlDif = target.C.lvl; // //StartCoroutine(CounterAnim(target)); // //Debug.Log("Target is: "+attackTarget); // if (target.isTarget && target != null) { // int attkRoll = C.skills[weapon.attackSkill].GetMod(lvlDif); // attkRoll += C.attributes[weapon.attackAttr].GetMod(lvlDif); // attkRoll += C.Properties[Properties.Attack].GetValue(); // attkRoll += (int)weapon.hitMod; // attkRoll += Random.Range(1, 101); // //attkRoll += CheckForArmorAndWeaponCritical(target); // int evadeRoll = target.EvadeRoll(lvlDif); // //Debug.Log("attacking " + attkRoll + " x " + evadeRoll ); // if (attkRoll >= evadeRoll) { // bool isCrit = CriticalRoll(weapon,target); // float damage = Damage(target ,weapon, isCrit); // target.takeDamage(damage, isCrit); // } // } } }
public override void OnTurnEnd(CombatChar combatChar) { Duration -= 1; if (Duration <= 0) { expired = true; } }
public override void OnTurnEnd(CombatChar combatChar) { combatChar.TakeDamage(Damage, "None"); Duration -= 1; if (Duration <= 0) { expired = true; } }
public override void usePower(CombatChar caster, CombatChar[] targets) { for (int count = 0; count < 1; count++) { PoisonEffect effect = Instantiate(poisonEffect).GetComponent <PoisonEffect>(); effect.castDamage = 10; targets[count].AddEffect(effect as Effects); } }
public void Awake() { cB = GetComponent <CombatChar>(); foreach (Attributes attr in System.Enum.GetValues(typeof(Attributes))) { Attribute attribute = new Attribute(attr.ToString(), this); this.attributes.Add(attr, attribute); //Debug.Log(attr+ " " +this.getFlatValue(attr)); } foreach (Skills sk in System.Enum.GetValues(typeof(Skills))) { Skill skill = new Skill(sk.ToString(), this); this.skills.Add(sk, skill); //Debug.Log(sk); } foreach (string def in GlobalData.Defenses) { Defense defense = new Defense(def); this.defenses.Add(defense.name, defense); //Debug.Log(def); } foreach (string res in GlobalData.Resists) { Resist resist = new Resist(res); this.resists.Add(resist.name, resist); //Debug.Log(res); } foreach (Slots slot in System.Enum.GetValues(typeof(Slots))) { this.equipment.Add(slot, null); //Debug.Log(slot); } foreach (string prop in GlobalData.Properties) { Property property = new Property(prop); this.properties.Add(property.name, property); //Debug.Log(prop); } foreach (Properties prop in System.Enum.GetValues(typeof(Properties))) { Property property = new Property(prop.ToString()); this.Properties.Add(prop, property); //Debug.Log(attr+ " " +this.getFlatValue(attr)); } //inventory = new Inventory(this); life = maxLife(); Power pow = Resources.Load <GoblinPunch>("Goblin Punch") as Power; knownPowers.Add(pow.name, pow); pow = Resources.Load <Heal>("Heal") as Power; knownPowers.Add(pow.name, pow); pow = Resources.Load <Poison>("Poison") as Power; knownPowers.Add(pow.name, pow); }
// Update is called once per frame void Update() { //se chegou no waypoint, pega o proximo if (!combChar.isAlive || !combChar.isActive) { return; } if (Vector3.Distance(transform.position, waypoint) < 0.1f) { if (waypoints.Count > 0) { waypoint = waypoints.Dequeue(); } else { hasArrived = true; } } // se ficou sem visao por 5 segundos if (aggroTimer >= aggroMaxTime) { target = null; StartCoroutine(pathfinder.GetWaypoints(transform.position, initialPos, this)); aggroTimer = 0f; } // Pega novo caminho para o alvo, e se nao ta perto, se move na diferencao dele if (target != null) { InLineOfSight(target.transform); waypointTimer += Time.deltaTime; if (waypointTimer >= 0.2f) { StartCoroutine(pathfinder.GetWaypoints(transform.position, target.transform.position, this)); waypointTimer = 0f; } if (Vector3.Distance(transform.position, target.transform.position) >= minimumRange || (target != null && !InLineOfSight(target.transform))) { hasArrived = false; MoveToTarget(waypoint); } else { hasArrived = true; } } // Sem alvo e voltando pro inicio if (target == null && C.transform.position != initialPos) { MoveToTarget(waypoint); } }
public override void usePower(CombatChar caster, CombatChar[] targets) { int lvl = targets[0].C.lvl; float healAmount = caster.C.attributes[Attributes.Wisdom].Roll(lvl); healAmount += caster.C.skills[Skills.Healing].Roll(lvl); healAmount += caster.C.skills[Skills.Magery].Roll(lvl); healAmount *= healMult; healAmount += Random.Range(baseHeal / 2f, baseHeal * 1.5f); targets[0].takeHealing(healAmount); //base.usePower (caster, targets); }
//public new string name = "Goblin Punch"; public override void usePower(CombatChar caster, CombatChar[] targets) { int lvl = targets[0].C.lvl; float damage = caster.C.attributes[Attributes.Strength].GetMod(lvl); damage += caster.C.skills[Skills.Wrestling].GetMod(lvl); damage += caster.C.attributes[Attributes.Vitality].GetMod(lvl); //damage /= 3; damage += caster.C.Properties[Properties.PowerDamage].GetValue(); damage /= targets[0].C.percentLife() / 100; damage += Random.Range(baseDamage / 2, baseDamage * 1.5f); targets[0].takeDamage(damage, false); //Debug.Log("powwx"); }
// Use this for initialization void Start() { pathfinder = GameObject.FindGameObjectWithTag("Pathfinder").GetComponent <Pathfinder>(); targets = new List <CombatChar>(); combChar = transform.root.GetComponent <CombatChar>(); C = transform.root.GetComponent <Character>(); AggroRange = GetComponent <CircleCollider2D>(); AggroRange.radius = aggroRange; minimumRange = combChar.weapons[0].range * 0.75f; aggroTimer = 0f; initialPos = transform.position; waypoints = new Queue <Vector3>(); //minumumRange = combChar.weapons[0].range; }
// Use this for initialization void Start() { Char = GetComponent <Character>(); CombChar = GetComponent <CombatChar>(); outLine = sprite.GetComponent <SpriteOutline>(); partyNumberText = partyNumber.GetComponent <Text>(); PartyManager.instance.Parties[0].Add(this); //Menu = GetComponentInChildren<Canvas>(); //aiMenu = GetComponentInChildren<AiMenu>(); wayPoints = new List <Vector2>(); if (transform.name == "Ramiro") { // StartCoroutine (pathfinder.GetWaypoints(transform.position, testChar.transform.position)); } }
public int CheckForArmorAndWeaponCounter(Weapons weapon, CombatChar target) { Armor arm = target.C.equipment[Slots.Chest] as Armor; if (weapon.size == Weapons.WeaponsSize.Light && arm.category == Armor.ArmorCat.Heavy) { return(30); } else if (weapon.size == Weapons.WeaponsSize.Heavy && arm.category == Armor.ArmorCat.Light) { return(30); } else { return(0); } }
// Use this for initialization void Start() { Owner = GetComponentInParent <CombatChar>(); // Dropdown.OptionData op = new Dropdown.OptionData(); // op.text = "coco"; // targetTab.options.Add(op); foreach (string target in Enum.GetNames(typeof(CombatManager.Targets))) { Dropdown.OptionData op = new Dropdown.OptionData(); op.text = target; op.image = null; targetTab.options.Add(op); } targetTab.RefreshShownValue(); foreach (string test in Enum.GetNames(typeof(CombatAI.AITests))) { Dropdown.OptionData op = new Dropdown.OptionData(); op.text = test; op.image = null; testTab.options.Add(op); } testTab.RefreshShownValue(); foreach (string condition in Enum.GetNames(typeof(CombatAI.AIConditions))) { Dropdown.OptionData op = new Dropdown.OptionData(); op.text = condition; op.image = null; conditionTab.options.Add(op); } foreach (string value in Enum.GetNames(typeof(CombatAI.AIValues))) { Dropdown.OptionData op = new Dropdown.OptionData(); op.text = value; op.image = null; valueTab.options.Add(op); } conditionTab.RefreshShownValue(); foreach (string power in Owner.C.knownPowers.Keys) { Dropdown.OptionData op = new Dropdown.OptionData(); op.text = power; op.image = null; powerTab.options.Add(op); } powerTab.RefreshShownValue(); }
public override void OnTurnEnd(CombatChar combatChar) { _nextDamage -= 1; GD.Print($"NEXT FIRE DAMAGE : {_nextDamage}"); if (_nextDamage <= 0) { GD.Print($"APPLY FIRE DAMAGE TO: {combatChar.Name}"); combatChar.TakeDamage(Damage, "Fire"); _nextDamage = Delay + 1; } Duration -= 1; if (Duration <= 0) { expired = true; } }
public bool CriticalRoll(Weapons weapon, CombatChar target) { //Check if it was a critical hit, comparing the attacker and the target int crit = C.Properties[Properties.Critical].GetValue() + 15; crit += CheckForArmorAndWeaponCritical(weapon, target); int resilience = target.C.Properties[Properties.Resiliense].GetValue(); int roll = Random.Range(0, 100); //Debug.Log(roll + " " + crit +" " + resilience); if (roll <= crit - resilience) { // Debug.Log("CritouU"); return(true); } else { return(false); } }
// Use this for initialization void Start() { combatChar = transform.root.GetComponent <CombatChar>(); attackSlider = attackBar.GetComponent <Slider>(); castingSlider = castingBar.GetComponent <Slider>(); }
public virtual void usePower(CombatChar caster, CombatChar[] targets) { }
public void usePower(CombatChar caster, CombatChar target) { CombatChar[] targets = { target }; usePower(caster, targets); }
public virtual void Effect(CombatChar target) { }
void Awake() { owner = GetComponent <CombatChar>(); }
// Use this for initialization void Start() { C = transform.root.GetComponent <Character>(); combatChar = transform.root.GetComponent <CombatChar>(); effects = new List <Effects>(); }
// Update is called once per frame void Update() { // Make one sprite appears before the others that are UP to the screen spriteR.sortingOrder = Mathf.RoundToInt(transform.position.y * 100f) * -1; // Run combat checks if (isCombat && isAlive) { if (isActive) { if (!isMoving && !isCasting) { // Recuce the time from the attack countdown. foreach (Weapons wep in weapons) { // If the char hasn't attacked for a time, it resets the attack countdown, but just as half of the speed. if (wep.attackCooldown > -wep.attackSpeed / 2) { wep.attackCooldown -= Time.deltaTime * (1 + C.Properties[Properties.AttackSpeed].GetValue() / 100f); } else { wep.attackCooldown += wep.attackSpeed; } } // reduce the time from the casting countdown castingTimer -= Time.deltaTime * (1 + C.Properties[Properties.CastingSpeed].GetValue() / 100f); } // Check each weapon to see if its time to attack foreach (Weapons wep in weapons) { if (wep.attackCooldown <= 0 && !isMoving && isActive && !isCasting) { // Get a list of possibler targets in range of its weapon List <CombatChar> targets = GetTargetsOnRange(wep.range, CombatManager.Targets.Enemies); // ignore weapons attack if there is no target in range. if (targets == null) { //Debug.Log("no target"); continue; } else { // Get one target based on its Threat level. CombatChar target = GetAttackTarget(targets); // Check is has LOS and perform the attack if (InLOS(target.transform)) { StartCoroutine(AttackAnim(wep, target, false)); wep.attackCooldown += wep.attackSpeed; } } } } // Decide which power is going to be used. if (castTarget == null && chargedPower == null && castingTimer <= 0f) { combatAI.CheckPower(); } if (castTarget != null && chargedPower != null && castingTimer <= -0.5f) { castTarget.sprite.GetComponent <SpriteOutline>().enabled = false; castTarget = null; chargedPower = null; combatAI.CheckPower(); } // Show casting spell name and give the chance to be interrupted. if (castTarget != null && chargedPower != null && castingTimer <= 1.5f && !canBeInterruped) { InitCBT(chargedPower.name, "SpellName"); canBeInterruped = true; } // Check is can cast the spell and then cast it if (castingTimer <= 0 && castTarget != null && chargedPower != null && castTarget.isTarget && !isMoving && castTarget.isAlive) { if (checkInRange(castTarget, chargedPower.range) && InLOS(castTarget.transform)) { chargedPower.usePower(this, castTarget); } // Clean ewverything about the power and the target castTarget.sprite.GetComponent <SpriteOutline>().enabled = false; castTarget = null; chargedPower = null; canBeInterruped = false; } } } }
// Use this for initialization void Start() { Owner = transform.root.GetComponent <CombatChar>(); }