Guest User

Fire_ScorchRay

a guest
Mar 7th, 2025
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.75 KB | Gaming | 0 0
  1. using Elementers.Handlers.damage;
  2. using Elementers.Handlers.Npc;
  3. using Elementers.Magic.Wizards;
  4. using Elementers.Managers;
  5. using Mirror;
  6. using RT.GameObjectPool;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using UnityEngine;
  11.  
  12. namespace Elementers.Magic.Abilities.Fire
  13. {
  14.     [RequireComponent(typeof(FireWizard))]
  15.     public class Fire_ScorchRay : FireAbilityBase
  16.     {
  17.         public ScorchRayVisualObject VisualObj;
  18.         public Transform SpawnSpot;
  19.  
  20.         private Coroutine RayC = null;
  21.         private RTGameObjectPool pool;
  22.         private WaitForSeconds waitDelay;
  23.         protected override void Awake()
  24.         {
  25.             Dictionary<int, (GameObject, int)> objects = new()
  26.             {
  27.                 {0, (VisualObj.gameObject, 4)}
  28.             };
  29.             waitDelay = new(AbilityData.ActionInterval);
  30.             pool = new RTGameObjectPool(objects, gameObject.transform);
  31.             pool.PopulatePool();
  32.             base.Awake();
  33.         }
  34.  
  35.         [TargetRpc]
  36.         protected override void TargetClientOnAbilityEnabled()
  37.         {
  38.             EntityInput.OnMouseRightPress.AddListener(ClientCallSpawnRay);
  39.             WizardParent.ClientSetAbilityArea(AbilityAreaType.Arrow, new object[] { transform, EntityInput });
  40.         }
  41.  
  42.         [TargetRpc]
  43.         protected override void TargetClientOnAbilityDisabled()
  44.         {
  45.             EntityInput.OnMouseRightPress.RemoveListener(ClientCallSpawnRay);
  46.         }
  47.  
  48.         [Server]
  49.         protected override void SrvOnAbilityEnabled()
  50.         {
  51.             if (!WizardParent.damageHandle.IsPlayer)
  52.             {
  53.                 EntityInput.OnMouseRightPress.AddListener(SrvCallSpawnRay);
  54.             }
  55.         }
  56.  
  57.         [Server]
  58.         protected override void SrvOnAbilityDisabled()
  59.         {
  60.             if (!WizardParent.damageHandle.IsPlayer)
  61.             {
  62.                 EntityInput.OnMouseRightPress.RemoveListener(SrvCallSpawnRay);
  63.             }
  64.         }
  65.  
  66.         [Client]
  67.         private void ClientCallSpawnRay(Vector3 location, string tag)
  68.         {
  69.             if (!isOwned) return;
  70.             if (!IsAbilityReady) return;
  71.             if (!IsAbilityActive) return;
  72.  
  73.             WizardParent.Animationhandler.TriggerAnimation(AnimationNames.PointStaff, AnimationsDuration);
  74.             CmdCallSpawnRay(location);
  75.         }
  76.  
  77.         [Command]
  78.         private void CmdCallSpawnRay(Vector3 location)
  79.         {
  80.             if (!IsAbilityReady) return;
  81.             if (!IsAbilityActive) return;
  82.             SrvSpawnRay(location);
  83.         }
  84.  
  85.         [Server]
  86.         private void SrvCallSpawnRay(Vector3 location, string tag)
  87.         {
  88.             WizardParent.Animationhandler.TriggerAnimation(AnimationNames.PointStaff, AnimationsDuration);
  89.             SrvSpawnRay(location);
  90.         }
  91.  
  92.         [Server]
  93.         private void SrvSpawnRay(Vector3 location)
  94.         {
  95.             if(RayC == null)
  96.             {
  97.                 RayC = StartCoroutine(SrvSpawnRayLoop(location));
  98.             }
  99.         }
  100.  
  101.         [Server]
  102.         private IEnumerator SrvSpawnRayLoop(Vector3 location)
  103.         {
  104.             for(int i = 0; i < AbilityData.ActionCount; i++)
  105.             {
  106.                 Vector3 endbeamposition = SpawnSpot.position - -transform.forward * AbilityData.Range;
  107.                 if (Physics.Raycast(SpawnSpot.position, transform.forward, out RaycastHit hit, AbilityData.Range))
  108.                 {
  109.                     if (hit.collider.gameObject.TryGetComponent(out DamageHandle handler))
  110.                     {
  111.                         DamageData data = new(AbilityData, hit.point, transform.forward, WizardParent.damageHandle.TeamId, WizardParent.damageHandle);
  112.                         handler.SrvDamage(data);
  113.                         RpcSpawnParticles(hit.point);
  114.                     }
  115.                     endbeamposition = hit.point;
  116.                 }
  117.                 RpcSpawnRayVisuals(endbeamposition);
  118.                 yield return waitDelay;
  119.             }
  120.             RayC = null;
  121.             SrvStartCooldown();
  122.         }
  123.  
  124.         [ClientRpc]
  125.         private void RpcSpawnRayVisuals(Vector3 location)
  126.         {
  127.             GameObject ray = pool.RequiestObject(0, SpawnSpot.position, Vector3.one, Quaternion.identity);
  128.             ray.GetComponent<ScorchRayVisualObject>().ClientFireRay(SpawnSpot.position, location);
  129.         }
  130.  
  131.         [ClientRpc]
  132.         private void RpcSpawnParticles(Vector3 position)
  133.         {
  134.             Vector3 size = new Vector3(.5f, .5f, .5f);
  135.             ParticleManager.Instance.RequestParticle(PType.FireExplosion, position, size);
  136.         }
  137.  
  138.         public override void OnDestroy()
  139.         {
  140.             base.OnDestroy();
  141.             pool.DestroyAll();
  142.         }
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment