oct
This commit is contained in:
@@ -14,7 +14,8 @@ using UnityEngine.SocialPlatforms;
|
||||
using Firebase.Auth;
|
||||
using UnityEngine.UI;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Properties;
|
||||
|
||||
|
||||
|
||||
public class playerNetwork : NetworkBehaviour
|
||||
{
|
||||
@@ -153,6 +154,7 @@ public class playerNetwork : NetworkBehaviour
|
||||
public List<string> completedQuests;
|
||||
|
||||
public GameObject projectile;
|
||||
public GameObject arrowRange;
|
||||
|
||||
public string selectedCharacterJson = CharacterSelection.selectedCharJson;
|
||||
|
||||
@@ -333,7 +335,6 @@ public class playerNetwork : NetworkBehaviour
|
||||
playerName = nameValue;
|
||||
}
|
||||
|
||||
|
||||
[Command(requiresAuthority =false)]
|
||||
void CmdRequestCharJson(){
|
||||
RpcBroadcastCharJson(myCharJson);
|
||||
@@ -359,6 +360,13 @@ public class playerNetwork : NetworkBehaviour
|
||||
character.AnimationManager.SetState((CharacterState)newVal);
|
||||
}
|
||||
|
||||
rangeEnemyFinder rangeEnemyFind;
|
||||
|
||||
enemyScript closestEnemy => rangeEnemyFind.targetEnemy;
|
||||
void Awake(){
|
||||
rangeEnemyFind = GetComponent<rangeEnemyFinder>();
|
||||
}
|
||||
|
||||
float attackTimer = 0;
|
||||
[HideInInspector]
|
||||
public PlayerAttack playerAttack;
|
||||
@@ -455,7 +463,6 @@ public class playerNetwork : NetworkBehaviour
|
||||
int prevLevel = GetLevelByXp(oldVal);
|
||||
int newLevle = GetLevelByXp(newVal);
|
||||
|
||||
|
||||
if(newLevle > prevLevel){
|
||||
int levelChange = newLevle - prevLevel;
|
||||
GameObject newObject = Instantiate(levelUpVfx , character.characterTransform());
|
||||
@@ -614,6 +621,73 @@ public class playerNetwork : NetworkBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] public float arrowSpeed = 2.0f;
|
||||
[SerializeField] public float arrowShootOffset = 1;
|
||||
[SerializeField] public float arrowShootHeightOffset = 1;
|
||||
|
||||
public void OnRangeAttack(){
|
||||
if(attackTimer>0){
|
||||
return;
|
||||
}
|
||||
if(closestEnemy==null){return;}
|
||||
|
||||
attackTimer = ATTACK_COOLDOWN;
|
||||
|
||||
characterMan.EquipBow();
|
||||
PlayAttackAnim();
|
||||
|
||||
StartCoroutine(ArrowShootDelay());
|
||||
// arrowRange.transform.position = startingPosition;
|
||||
|
||||
//TODO: Deal Damage once it hits enemy
|
||||
|
||||
}
|
||||
public float arrowDelay;
|
||||
IEnumerator ArrowShootDelay (){
|
||||
|
||||
yield return new WaitForSeconds(arrowDelay);
|
||||
|
||||
Vector3 startingPosition = transform.position ;
|
||||
Vector3 destination = closestEnemy.transform.position;
|
||||
|
||||
//TODO: Move attack projectile from startingPosition to destination
|
||||
Vector3 direction = (destination - startingPosition).normalized;
|
||||
startingPosition += (direction * arrowShootOffset);
|
||||
startingPosition += (Vector3.up * arrowShootHeightOffset);
|
||||
destination += (Vector3.up * arrowShootHeightOffset);
|
||||
// Quaternion rotation = Quaternion.LookRotation(direction);
|
||||
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
|
||||
Quaternion rotation = Quaternion.Euler(0,0,angle - 90f);
|
||||
|
||||
GameObject newArrow = Instantiate(arrowRange , transform.position + (direction * arrowShootOffset) , rotation);
|
||||
|
||||
StartCoroutine(moveArrow(newArrow.transform , startingPosition , destination , closestEnemy));
|
||||
|
||||
}
|
||||
public int RangeDmg = 10;
|
||||
|
||||
IEnumerator moveArrow (Transform arrow , Vector3 start, Vector3 destination, enemyScript target ){
|
||||
|
||||
float dist = Vector3.Distance(start , destination);
|
||||
|
||||
float duration = dist/arrowSpeed;
|
||||
|
||||
float timer = 0f;
|
||||
|
||||
while(timer < duration){
|
||||
|
||||
arrow.position = Vector3.Lerp(start , destination , timer/duration);
|
||||
|
||||
timer += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
target.TakeDamage(RangeDmg, netId);
|
||||
|
||||
Destroy(arrow.gameObject);
|
||||
|
||||
}
|
||||
|
||||
public int MagicAttackWeaponIndex = 52;
|
||||
public void OnMagicAttack(){
|
||||
if(attackTimer > 0){
|
||||
@@ -621,7 +695,7 @@ public class playerNetwork : NetworkBehaviour
|
||||
}
|
||||
|
||||
attackTimer = ATTACK_COOLDOWN;
|
||||
characterMan.SetActiveWeapon(MagicAttackWeaponIndex);
|
||||
// characterMan.SetActiveWeapon(MagicAttackWeaponIndex);
|
||||
if(isLocalPlayer){
|
||||
PlayAttackAnim();
|
||||
//?
|
||||
@@ -730,10 +804,8 @@ public class playerNetwork : NetworkBehaviour
|
||||
GameManager.instance.SpawnPickup(type,transform.position + new Vector3(4,0));
|
||||
}
|
||||
|
||||
|
||||
int magicalDmg = 0;
|
||||
|
||||
|
||||
public void MagicalAttack(Vector3 direction, float magicalProjectileSpawnOffset, int dmg)
|
||||
{
|
||||
if (isServer)
|
||||
@@ -746,7 +818,6 @@ public class playerNetwork : NetworkBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Command]
|
||||
void CmdMagicalAttack(Vector3 direction, float magicalProjectileSpawnOffset, int dmg)
|
||||
{
|
||||
@@ -763,21 +834,19 @@ public class playerNetwork : NetworkBehaviour
|
||||
_projectile.shooterId = netId;
|
||||
|
||||
NetworkServer.Spawn(projectileSpawned);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OnMagicalHit(enemyScript victim)
|
||||
{
|
||||
int damageamount = magicalDmg + (lvl * 5);
|
||||
|
||||
//magical damage with intelligance stat ?
|
||||
//int damageamount = magicalDmg + (lvl * 5);
|
||||
int damageamount = magicalDmg + (statManager.GetEffectiveValue("intelligence")*2);
|
||||
Debug.Log("magic damage amount " + damageamount);
|
||||
victim.TakeMagicalDamage(damageamount, netId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void GoBackMenu(){
|
||||
startClient.instance.networkManager.StopClient();
|
||||
SceneManager.LoadScene("GameLogin");
|
||||
|
||||
Reference in New Issue
Block a user