public WeaponTags(WeaponType aWeaponType, WeaponDistance aWeaponDistance, int aDmgMin, int aDmgMax, int aArmorPenetration, int aCritChance, int aCritMulti, AttackTags aAttackTags1, AttackTags aAttackTags2, AttackTags aAttackTags3) { armorPenetration = aArmorPenetration; critChance = aCritChance; critMulti = aCritMulti; dmgMax = aDmgMax; dmgMin = aDmgMin; weaponDistance = aWeaponDistance; weaponType = aWeaponType; attack1 = aAttackTags1; attack2 = aAttackTags2; attack3 = aAttackTags3; }
public void Fire(Vector3 direction) { if (CurrentWeaponPrefab != null) { if (CurrentWeaponPrefab.RequireClearance) { Vector3 start = moveTransform.position; Vector3 end = moveTransform.position + direction.normalized * CurrentWeaponPrefab.StartDistance; #if DEBUG_LINES Debug.DrawLine(start, end, Color.white); #endif RaycastHit info = new RaycastHit(); if (Physics.Raycast(new Ray(start, end - start), out info, (end - start).magnitude, ~LayerMask.GetMask(new string[] { "Projectile" }))) { Debug.Log("weapon hit on raycast: " + name); return; } } if (CurrentWeaponPrefab.AttackClosestWithinRadius) { Collider[] cds = Physics.OverlapSphere(transform.position, CurrentWeaponPrefab.AttackDistance, LayerMask.GetMask(new string[] { "Character" })); Transform closest = null; float shortestDistance = CurrentWeaponPrefab.AttackDistance; foreach (var coll in cds) { if (coll.transform == transform) { continue; } Tags tags = coll.GetComponent <Tags>(); if (tags != null && tags.HasAnyTag(AttackTags.ToArray())) { // NOTE this ignores the size of the collider; only uses position float distance = Vector3.Distance(coll.transform.position, transform.position); if (distance < shortestDistance) { closest = coll.transform; shortestDistance = distance; } } } if (closest != null) { direction = closest.position - transform.position; } } if (CurrentWeaponPrefab.type == Attack.Type.Melee) { GameObject go = (GameObject)GameObject.Instantiate(CurrentWeaponPrefab.gameObject, moveTransform.position + direction.normalized * CurrentWeaponPrefab.StartDistance, Quaternion.LookRotation(direction), moveTransform); go.name = CurrentWeaponPrefab.gameObject.name; if (go != null) { CurrentWeaponPrefab.FireWeapon(go, direction, audioSource, moveTransform); } body.AddForce(direction.normalized * StabbyStabBodyForce * body.mass); //RightHandAnimation.Play( "melee-0-attack" ); //RightHandAnimation.PlayQueued( "melee-0-idle" ); } if (CurrentWeaponPrefab.type == Attack.Type.Projectile) { GameObject go = (GameObject)GameObject.Instantiate(CurrentWeaponPrefab.gameObject, moveTransform.position + direction.normalized * CurrentWeaponPrefab.StartDistance, Quaternion.LookRotation(direction)); go.name = CurrentWeaponPrefab.gameObject.name; if (go != null) { CurrentWeaponPrefab.FireWeapon(go, direction, audioSource, moveTransform); } } if (CurrentWeaponPrefab.type == Attack.Type.Spawner) { GameObject prefab = CurrentWeaponPrefab.SpawnerPrefabs[Random.Range(0, CurrentWeaponPrefab.SpawnerPrefabs.Length)]; GameObject go = Global.Instance.Spawn(prefab, moveTransform.position + direction.normalized * CurrentWeaponPrefab.StartDistance, Quaternion.LookRotation(direction)); if (go != null) { Character cha = go.GetComponent <Character>(); if (cha != null) { cha.ModifyAffinity(id, 20); //cha.Follow( this, null ); } CurrentWeaponPrefab.FireWeapon(go, direction, audioSource, moveTransform); } } } }