Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Elementers.Handlers.damage;
- using Elementers.Handlers.Npc;
- using Elementers.Magic.Wizards;
- using Elementers.Managers;
- using Mirror;
- using RT.GameObjectPool;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace Elementers.Magic.Abilities.Fire
- {
- [RequireComponent(typeof(FireWizard))]
- public class Fire_ScorchRay : FireAbilityBase
- {
- public ScorchRayVisualObject VisualObj;
- public Transform SpawnSpot;
- private Coroutine RayC = null;
- private RTGameObjectPool pool;
- private WaitForSeconds waitDelay;
- protected override void Awake()
- {
- Dictionary<int, (GameObject, int)> objects = new()
- {
- {0, (VisualObj.gameObject, 4)}
- };
- waitDelay = new(AbilityData.ActionInterval);
- pool = new RTGameObjectPool(objects, gameObject.transform);
- pool.PopulatePool();
- base.Awake();
- }
- [TargetRpc]
- protected override void TargetClientOnAbilityEnabled()
- {
- EntityInput.OnMouseRightPress.AddListener(ClientCallSpawnRay);
- WizardParent.ClientSetAbilityArea(AbilityAreaType.Arrow, new object[] { transform, EntityInput });
- }
- [TargetRpc]
- protected override void TargetClientOnAbilityDisabled()
- {
- EntityInput.OnMouseRightPress.RemoveListener(ClientCallSpawnRay);
- }
- [Server]
- protected override void SrvOnAbilityEnabled()
- {
- if (!WizardParent.damageHandle.IsPlayer)
- {
- EntityInput.OnMouseRightPress.AddListener(SrvCallSpawnRay);
- }
- }
- [Server]
- protected override void SrvOnAbilityDisabled()
- {
- if (!WizardParent.damageHandle.IsPlayer)
- {
- EntityInput.OnMouseRightPress.RemoveListener(SrvCallSpawnRay);
- }
- }
- [Client]
- private void ClientCallSpawnRay(Vector3 location, string tag)
- {
- if (!isOwned) return;
- if (!IsAbilityReady) return;
- if (!IsAbilityActive) return;
- WizardParent.Animationhandler.TriggerAnimation(AnimationNames.PointStaff, AnimationsDuration);
- CmdCallSpawnRay(location);
- }
- [Command]
- private void CmdCallSpawnRay(Vector3 location)
- {
- if (!IsAbilityReady) return;
- if (!IsAbilityActive) return;
- SrvSpawnRay(location);
- }
- [Server]
- private void SrvCallSpawnRay(Vector3 location, string tag)
- {
- WizardParent.Animationhandler.TriggerAnimation(AnimationNames.PointStaff, AnimationsDuration);
- SrvSpawnRay(location);
- }
- [Server]
- private void SrvSpawnRay(Vector3 location)
- {
- if(RayC == null)
- {
- RayC = StartCoroutine(SrvSpawnRayLoop(location));
- }
- }
- [Server]
- private IEnumerator SrvSpawnRayLoop(Vector3 location)
- {
- for(int i = 0; i < AbilityData.ActionCount; i++)
- {
- Vector3 endbeamposition = SpawnSpot.position - -transform.forward * AbilityData.Range;
- if (Physics.Raycast(SpawnSpot.position, transform.forward, out RaycastHit hit, AbilityData.Range))
- {
- if (hit.collider.gameObject.TryGetComponent(out DamageHandle handler))
- {
- DamageData data = new(AbilityData, hit.point, transform.forward, WizardParent.damageHandle.TeamId, WizardParent.damageHandle);
- handler.SrvDamage(data);
- RpcSpawnParticles(hit.point);
- }
- endbeamposition = hit.point;
- }
- RpcSpawnRayVisuals(endbeamposition);
- yield return waitDelay;
- }
- RayC = null;
- SrvStartCooldown();
- }
- [ClientRpc]
- private void RpcSpawnRayVisuals(Vector3 location)
- {
- GameObject ray = pool.RequiestObject(0, SpawnSpot.position, Vector3.one, Quaternion.identity);
- ray.GetComponent<ScorchRayVisualObject>().ClientFireRay(SpawnSpot.position, location);
- }
- [ClientRpc]
- private void RpcSpawnParticles(Vector3 position)
- {
- Vector3 size = new Vector3(.5f, .5f, .5f);
- ParticleManager.Instance.RequestParticle(PType.FireExplosion, position, size);
- }
- public override void OnDestroy()
- {
- base.OnDestroy();
- pool.DestroyAll();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment