public void CreateProjectile(Guid ownerGuid, ProjectileSpawnData projectileSpawnData) { var projectile = new ProjectileEntity(projectileSpawnData); SignalBus.Fire(new ProjectileCreatedSignal(projectile.EntityGuid, projectileSpawnData, ownerGuid)); _projectileDataItems.Add(projectile); }
protected override void ExplicitExecute(FireProjectileCommand command) { var projectileSpawnData = new ProjectileSpawnData(command.ProjectileOwnerType, command.ProjectilePosition, command.ProjectileDirection, command.ProjectilePower); _projectilesSystemsManager.CreateProjectile(command.OwnerGuid, projectileSpawnData); }
public void DecodeJson(string json) { //TODO: Strategy Pattern try { PacketData jsonData = JsonUtility.FromJson <PacketData>(json); if (jsonData.DataType == typeof(CharacterData).ToString()) { CharacterData charData = JsonUtility.FromJson <CharacterData>(json); otherPlayerLastData = charData; NetUpdate(); } else { if (jsonData.DataType == typeof(ScriptableData).ToString()) { ScriptableData scriptData = JsonUtility.FromJson <ScriptableData>(json); ScriptInfo info = ScriptDatabase.GetInstance().GetScript(scriptData.ScriptId); SkillBehaviour skill = ScriptableObject.CreateInstance(info.Script.GetClass()) as SkillBehaviour; skill.Caster = otherPlayer; skill.Initialize(); if (skill.OnCast != null) { Debug.Log("Cast"); skill.OnCast.RunContext(); } } else if (jsonData.DataType == typeof(ProjectileSpawnData).ToString()) { ProjectileSpawnData projData = JsonUtility.FromJson <ProjectileSpawnData>(json); UnityMainThreadDispatcher.Instance().Enqueue(() => { spawner.SpawnProjectile(projData.PrefabResourcePath, projData); }); } else { SpawnData objSpawnData = JsonUtility.FromJson <SpawnData>(json); UnityMainThreadDispatcher.Instance().Enqueue(() => { spawner.SpawnObject(objSpawnData.PrefabResourcePath, objSpawnData); }); } } } catch { return; } }
public void Setup(ProjectileSpawnData projectileSpawnData) { switch (projectileSpawnData.ProjectileOwnerType) { case ProjectileOwnerType.Player: gameObject.layer = LayerMask.NameToLayer("Player"); break; case ProjectileOwnerType.Enemy: gameObject.layer = LayerMask.NameToLayer("Enemy"); break; } var projectileTransform = transform; projectileTransform.position = projectileSpawnData.SpawnPosition; projectileTransform.forward = -projectileSpawnData.Direction; }
public void Shoot(Vector3 target = default) { if (currentShotInterval > 0) { return; } AttachedEntity.AsItem().Owner.ReadyTimer += Settings.ShotInterval + 0.2f; Vector3 mousePos = InputManager.Instance.MouseWorldPosition; Quaternion startRotation = Quaternion.LookRotation(new Vector3(mousePos.x, ProjectileSpawn.position.y, mousePos.z) - ProjectileSpawn.position); if (target != default) { startRotation = Quaternion.LookRotation(target - ProjectileSpawn.position); } Projectile proj = Instantiate(LoadedProjectile.Prefab, ProjectileSpawn.position, startRotation).GetComponent <Projectile>(); proj.Direction = proj.transform.forward; proj.Creator = AttachedEntity; proj.Settings = LoadedProjectile; proj.Initialize(); float spreadRandomX = Random.Range(-currentSpreading, currentSpreading); float spreadRandomY = Random.Range(-currentSpreading, currentSpreading); float spreadRandomZ = Random.Range(-currentSpreading, currentSpreading); proj.Direction += new Vector3(spreadRandomX, spreadRandomY, spreadRandomZ); proj.GetComponent <Rigidbody>().AddForce(proj.Direction * proj.ProjectileStats["Speed"].EffectiveValue); EffectsManager.Instance.SpawnEffect(ShotEffect, ProjectileSpawn.position, Quaternion.identity); if (Settings.ShootSounds.Count > 0) { SoundManager.Instance.PlayClipAtPoint(Settings.ShootSounds.RandomItem(), transform.position, Settings.ShootVolume); } if (NetManager.Instance.Connect) { //Sending packet to the server using (Packet packet = new Packet()) { ProjectileSpawnData data = new ProjectileSpawnData(); data.DataType = typeof(ProjectileSpawnData).ToString(); data.Prefix = "PREFIX: PROJECTILE"; data.Force = proj.Direction * proj.ProjectileStats["Speed"].EffectiveValue; data.DataId = LoadedProjectile.Id; data.PrefabResourcePath = LoadedProjectile.Prefab.name; data.Position = ProjectileSpawn.position; data.Rotation = startRotation.eulerAngles; data.DeathEffectPath = LoadedProjectile.DeathEffect.name; data.Speed = LoadedProjectile.Speed; data.Heatlh = LoadedProjectile.Heatlh; packet.Write(JsonUtility.ToJson(data, true)); NetManager.Instance.SendData(packet); } //------------------- } ((Weapon)AttachedEntity).OnShoot?.Invoke(); currentShotInterval = Settings.ShotInterval; // Recoil grow (spreading grows) currentSpreading = Mathf.Clamp(currentSpreading + Settings.Recoil, Settings.Spreading, Settings.Spreading + Settings.MaxRecoil); currentClipSize--; if (currentClipSize == 0) { currentShotInterval += Settings.ReloadTime - Settings.ShotInterval; currentClipSize = Settings.ClipSize; if (Settings.ReloadSounds.Count > 0) { StartCoroutine(PlayReloadSounds()); } } }