using System.Collections; using System.Collections.Generic; using BITFALL; using BITFALL.Bullet; using BITKit; using BITKit.Entities; using Microsoft.Extensions.DependencyInjection; using NodeCanvas.Framework; using UnityEngine; namespace Net.Project.B.NodeCanvas { public class BulletTask : ActionTask { public BBParameter Target; public BBParameter GameObject; public BBParameter ViewPosition; public BBParameter AccuracyOffset; public BBParameter Interval; private readonly IntervalUpdate _intervalUpdate = new(1); private IBulletService _bulletService; private readonly BulletData _bulletData = new() { InitialDamage = 10, MaxDamage = 10, StartSpeed = 256, }; protected override string OnInit() { _bulletService = BITApp.ServiceProvider.GetRequiredService(); var entitiesService = BITApp.ServiceProvider.GetRequiredService(); if (entitiesService.TryGetEntity(GameObject.value.GetInstanceID(), out var entity)) { _bulletData.Initiator = entity.Id; } return base.OnInit(); } protected override void OnExecute() { EndAction(); _intervalUpdate.Interval = Interval.value; if (_intervalUpdate.AllowUpdate is false) { return; } if (!Target.value)return; var targetPosition = Target.value.transform.position; if (Target.value.TryGetComponent(out var capsuleCollider)) { targetPosition = capsuleCollider.transform.position + capsuleCollider.transform.rotation * capsuleCollider.center; } var direction = targetPosition - ViewPosition.value.position; direction = Quaternion.LookRotation(direction) * Quaternion.Euler(Random.onUnitSphere * AccuracyOffset.value) * Vector3.forward; _bulletData.Rotation = Quaternion.LookRotation(direction); _bulletData.Forward = direction; _bulletData.Position = ViewPosition.value.position; _bulletService.Spawn(_bulletData); } } }