override public void SetTarget(Targetable target) { if (!target) { Debug.Log($"Spell {name} has no target. Target probably has been destroyed."); return; } base.SetTarget(target); HP hp = target.GetComponent <HP>( ); hp.DoDamage(effectAmount, transform.position, targetFreezTime > 0); if (targetShockTime > 0 || targetFreezTime > 0) { Unit unit = target.GetComponent <Unit>( ); unit.Freez(targetShockTime, targetFreezTime); UnitVisuals unitVis = target.GetComponent <UnitVisuals>( ); unitVis.Shocked(targetShockTime); } if (shakeStrength > 0) { ScreenshakeManager.Instance.DoShake(shakeStrength); } }
void Hit(NodeBehaviour targetNode, Targetable pTarget) { Debug.Log("Target Node " + targetNode); Debug.Log("Targetable " + pTarget); if (pTarget.GetComponent <Pawn>() != null) { double hitChance = 1 - (1 - 0.5) * (Vector3.Distance(owner.transform.position, targetNode.transform.position) - 1) / (range - 1); if (RNG.NextDouble() < hitChance) { double accuracy = Vector3.Distance(targetNode.transform.position, pTarget.GetComponent <Pawn>().transform.position) / 200d; double tmpDamageMod = (1 - accuracy) * RNG.NextDouble() + accuracy; if (tmpDamageMod > 1d) { tmpDamageMod = 1d; } int tmpDamage = (int)System.Math.Round((double)damage * tmpDamageMod); if (tmpDamage < 1) { tmpDamage = 1; } Debug.Log(owner + " hit " + (pTarget.GetComponent <Pawn>()) + " and dealt " + tmpDamage + " damage."); pTarget.GetComponent <Health>().Damage(owner, tmpDamage); } } else if (pTarget.GetComponent <DestroyableProp>() != null) { pTarget.GetComponent <Health>().Damage(owner, 1); } }
public double getProbabilityOfWin(Targetable target) { NodeData otherNode = target.GetComponent <NodeData>(); NodeData thisNode = getNode(); bool isStrong = (otherNode.type == strongAgainst); // Find attacker attack score and defender defense score int defense = otherNode.power; int attack = thisNode.power; int minAttack = attack / 2; int maxAttack = attack * (isStrong ? 3 : 2); // Determine if node is captured double probability = 0; if (defense <= minAttack) { probability = 1; } else if (defense >= maxAttack) { probability = 0; } else { probability = ((double)(maxAttack - defense)) / ((double)(maxAttack - minAttack)); } return(probability); }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity, -1, QueryTriggerInteraction.Ignore)) { if (targetable != null) { targetable.ClearTarget(); } targetable = hit.collider.gameObject.transform.root.GetComponent <Targetable>(); if (targetable != null) { targetable.SetTarget(); Attack attack = GetComponent <Attack>(); if (attack != null) { Attackable attackable = targetable.GetComponent <Attackable>(); if (attackable != null) { //this object can attack, and the target is attackable attack.target = targetable.gameObject; } } } } } }
override protected void doActivate(Targetable target) { NodeData otherNode = target.GetComponent <NodeData>(); NodeData thisNode = getNode(); EdgeData edge = graphUtility.getConnectingEdge(thisNode, otherNode); if (edge.direction == EdgeData.EdgeDirection.Unusable) { return; } bool isWin = gen.NextDouble() <= getProbabilityOfWin(target); // Take node if (isWin) { graphUtility.CaptureNode(otherNode, thisNode); } if (effect != null) { effect.additionalEffect(thisNode, target, isWin); } effect = null; }
public static AttackTask Create(Targetable ship) { AttackTask task = CreateInstance<AttackTask>(); task.attackTarget = ship; task.attackShip = ship.GetComponent<Ship>(); return task; }
public static bool DefaultAttackIsValidTarget(Targetable t, Pawn owner) { Pawn p = t.GetComponent <Pawn>(); DestroyableProp d = t.GetComponent <DestroyableProp>(); if (p != null) { return((!p.isDead) && (p.owner != owner.owner) && (Vector3.Distance(owner.transform.position, p.transform.position) < owner.weapon.range)); } else if (d != null) { return(Vector3.Distance(owner.transform.position, d.transform.position) < owner.weapon.range); } else { return(false); } }
public override bool Execute() { if (!CheckTarget() || !CheckCost(actionCost)) { return(false); } LinkPositions direction = owner.currentNode.GetRelativePosition(target.GetComponent <NodeBehaviour>()); NodeBehaviour n = owner.currentNode; for (int i = 0; i < range; i++) { if (n.GetLinkInDirection(direction) != null) { n = n.GetLinkInDirection(direction); if (n.currentObject != null && n.currentObject.GetComponent <DestroyableProp>() != null) { n.currentObject.GetComponent <Health>().Damage(owner, 1); } foreach (LinkPositions d in LinkPositions.GetValues(typeof(LinkPositions))) { if (n.GetLinkInDirection(d) != null) { Targetable c = n.GetLinkInDirection(d).currentObject; if (c != null && c.GetComponent <DestroyableProp>() != null) { c.GetComponent <Health>().Damage(owner, 1); } } } } } List <NodeBehaviour> path = Pathfinder.GetPath(owner.currentNode, n); owner.GetComponent <GridNavMeshWrapper>().SetPath(path); Debug.Log(owner + " Executes " + name); return(true); }
public void AddTarget(Targetable target) { if (maxTracked == -1 || targets.Count < maxTracked) { HealthSystem hs = target.GetComponent <HealthSystem>(); if (hs != null) { hs.OnKilled += RemoveTarget; } targets.Add(target); } }
override public void SetTarget(Targetable target) { if (!target) { Debug.Log($"Spell {name} has no target. Target probably has been destroyed."); } base.SetTarget(target); HP hp = target.GetComponent <HP>( ); hp.Heal(effectAmount); }
public void SetShooting(Targetable p) { if (debug) { Debug.Log("Set Shooting Called"); } animator.SetBool("Shooting", true); SoundManager.instance.PlaySound(_ShootSound, _audioSource); animator.gameObject.transform.LookAt(new Vector3(p.transform.position.x, animator.transform.position.y, p.transform.position.z)); if (p.GetComponent <Pawn> () != null) { //animator.SetBool ("HighCoverInWay", GetComponent<Pawn> ().GetCoverState (p.GetComponent<Pawn>()) == CoverState.Full); } isAnimating = true; skipFrame = true; }
public override bool IsValidTarget(Targetable t) { NodeBehaviour n = t.GetComponent <NodeBehaviour>(); return((n != null) && (Pathfinder.NodesWithinSteps(owner.currentNode, owner.Movement).Contains(n))); }
public override bool IsValidTarget(Targetable t) { Pawn p = t.GetComponent <Pawn>(); return((p != null) && (owner.owner == p.owner)); }
public override bool IsValidTarget(Targetable t) { Pawn p = t.GetComponent <Pawn>(); return((p != null) && (p.owner != owner.owner) && (Vector3.Distance(owner.transform.position, p.transform.position) < owner.weapon.range) && (p.GetComponent <Health>().health < p.GetComponent <Health>().maxHealth / 3)); }
public static void Attack(Pawn owner, Targetable target) { if (target.GetComponent <DestroyableProp>() != null) { Weapon weapon = owner.weapon; int effectiveRange = weapon.range; if (owner.transform.position.y - target.transform.position.y > 0) { effectiveRange += (int)((owner.transform.position.y - target.transform.position.y) / 2f); } double hitChance = 1 - (1 - 0.5) * (Vector3.Distance(owner.transform.position, target.transform.position) - 1) / (effectiveRange - 1); if (owner.hitMulti != 0) { hitChance *= owner.hitMulti; } Debug.Log(System.Math.Round(hitChance * 100) + "% chance to hit"); if (RNG.NextDouble() < hitChance) { Debug.Log(owner + " hit " + target); target.GetComponent <Health>().Damage(owner, 1); } else { Debug.Log(owner + " missed " + target); } for (int i = owner.EffectList.Count - 1; i >= 0; i--) { owner.EffectList[i].OnRemove(); } } else if (target.GetComponent <Pawn>() != null) { Weapon weapon = owner.weapon; int effectiveRange = weapon.range; if (owner.transform.position.y - target.transform.position.y > 0) { effectiveRange += (int)((owner.transform.position.y - target.transform.position.y) / 2f); } double hitChance = 1 - (1 - 0.5) * (Vector3.Distance(owner.transform.position, target.transform.position) - 1) / (effectiveRange - 1); CoverState coverState = target.GetComponent <Pawn>().GetCoverState(owner); switch (coverState) { case CoverState.Half: owner.EffectList.Add(new HalfCoverDebuff(owner)); break; case CoverState.Full: owner.EffectList.Add(new FullCoverDebuff(owner)); break; } if (owner.hitMulti != 0) { hitChance *= owner.hitMulti; } Debug.Log(System.Math.Round(hitChance * 100) + "% chance to hit"); if (RNG.NextDouble() < hitChance) { int damage = weapon.damage; double accuracy = owner.Accuracy; if (owner.accuracyMulti != 0) { accuracy *= owner.accuracyMulti; } accuracy = (accuracy + owner.accuracyMod) / 100d; if (1 - accuracy <= 0) { accuracy = 1d; } double tmpDamageMod = (1 - accuracy) * RNG.NextDouble() + accuracy; if (tmpDamageMod > 1d) { tmpDamageMod = 1d; } if (owner.damageMulti != 0) { tmpDamageMod *= owner.damageMulti; } if (RNG.NextDouble() < weapon.criticalChance + owner.critChanceMod) { damage = (int)System.Math.Round((double)weapon.damage * 1.5d * tmpDamageMod); if (damage < 1) { damage = 1; } Debug.Log(owner + " critically hit " + target + " and dealt " + damage + " damage."); target.GetComponent <Health>().Damage(owner, damage); } else { damage = (int)System.Math.Round((double)weapon.damage * tmpDamageMod); if (damage < 1) { damage = 1; } Debug.Log(owner + " hit " + target + " and dealt " + damage + " damage."); target.GetComponent <Health>().Damage(owner, damage); } if (weapon.weaponEffects != null) { for (int i = weapon.weaponEffects.Count - 1; i >= 0; i--) { Factory.GetWeaponEffect(weapon.weaponEffects[i]).Execute(owner, weapon, target.GetComponent <Pawn>()); } } for (int i = target.GetComponent <Pawn>().EffectList.Count - 1; i >= 0; i--) { target.GetComponent <Pawn>().EffectList[i].OnHit(owner, damage); } } else { Debug.Log(owner + " missed " + target); } for (int i = owner.EffectList.Count - 1; i >= 0; i--) { owner.EffectList[i].OnRemove(); } } }
public override Vector3? PredictTarget(Ship activator, int slot, Targetable target) { Vector3 speedDiff; var targetBody = target.GetComponent<Rigidbody>(); var activatorBody = activator.GetComponent<Rigidbody>(); if (bulletType.applyBaseVelocity) { if (targetBody && activatorBody) { speedDiff = targetBody.velocity - activatorBody.velocity; } else if (activatorBody) { speedDiff = -activatorBody.velocity; } else { speedDiff = Vector3.zero; } } else { if (targetBody) { speedDiff = targetBody.velocity; } else { speedDiff = Vector3.zero; } } float distToTarget = (target.transform.position - activator.transform.position).magnitude; float timeToHit = distToTarget / bulletType.velocity; speedDiff *= timeToHit; var targetPos = target.transform.position; targetPos += speedDiff; return targetPos; }
public override bool IsValidTarget(Targetable t) { Pawn p = t.GetComponent <Pawn>(); return((p != null) && (p.owner == owner.owner) && (Vector3.Distance(owner.transform.position, p.transform.position) < firstAidRange)); }
public override bool IsValidTarget(Targetable t) { NodeBehaviour n = t.GetComponent <NodeBehaviour>(); return((n != null) && (CheckLines().Contains(n))); }
public static bool IsAllyWithCastle(Targetable caster, Targetable castle) { return(caster.GetComponent <Shop>() && caster.Allegiance == castle.Allegiance); }
public override bool IsValidTarget(Targetable t) { Pawn p = t.GetComponent <Pawn>(); return(p == owner); }