private void OnWeaponFired(BaseProjectile aProjectile, BasePlayer aPlayer, ItemModProjectile aMod, ProtoBuf.ProjectileShoot aProjectileProtoBuf) { TaserController theController = aProjectile.GetComponent <TaserController>(); if (theController) { theController.ResetTaser(); if (!permission.UserHasPermission(aPlayer.UserIDString, PERMISSION_USETASER)) { Effect.server.Run(config.PrefabShock, aProjectile, StringPool.Get(aProjectile.MuzzleTransform.name), aProjectile.MuzzleTransform.localPosition, Vector3.zero); aPlayer.OnAttacked(new HitInfo(aPlayer, aPlayer, DamageType.ElectricShock, config.NoUsePermissionDamage, aPlayer.transform.position + aPlayer.transform.forward * 1f)); Message(aPlayer, I18N_NOT_ALLOWED_TO_USE); } } }
private void setupSubscriptions() { this.UpdateAsObservable() .Where(_ => Input.GetMouseButtonDown(0)) .SelectMany(_ => gameObject.UpdateAsObservable()) .TakeUntil(this.UpdateAsObservable().Where(_ => Input.GetMouseButtonUp(0))) .Select(_ => Input.mousePosition) .Where(x => x.y < Screen.height - TopMargin) .RepeatUntilDestroy(this) .Subscribe( x => { //Debug.Log(string.Format("{0} : {1}", force.magnitude, IsValidThrowPoint(x))); if (IsValidThrowPoint(x)) { var force = GetForceFrom(Projectile.transform.position, Camera.main.ScreenToWorldPoint(x)); float angle = Mathf.Atan2(force.y, force.x) * Mathf.Rad2Deg; transform.eulerAngles = new Vector3(0, 0, angle); SetupTrajectory(transform.position, force / Projectile.GetComponent <Rigidbody2D>().mass); } else { trajectoryPoints.ForEach(p => p.GetComponent <SpriteRenderer>().enabled = false); } }) .AddTo(disposables); this.UpdateAsObservable() .Where(_ => Input.GetMouseButtonUp(0)) .Select(_ => Input.mousePosition) .Subscribe( x => { if (x.y < Screen.height - TopMargin && IsValidThrowPoint(x)) { ThrowBall(); this.enabled = false; trajectoryPoints.ForEach(p => Destroy(p.gameObject)); } else { trajectoryPoints.ForEach(p => p.GetComponent <SpriteRenderer>().enabled = false); } }) .AddTo(disposables); }
private void DisableTaserBehaviour(BaseProjectile aBaseProjectile) { Item theItem = aBaseProjectile.GetItem(); if (theItem != null) { theItem.name = null; } aBaseProjectile.canUnloadAmmo = true; aBaseProjectile.primaryMagazine.contents = 0; aBaseProjectile.primaryMagazine.capacity = 16; TaserController theController = aBaseProjectile.GetComponent <TaserController>(); if (theController) { UnityEngine.Object.Destroy(theController); } aBaseProjectile.SendNetworkUpdateImmediate(); }
private void EnableTaserBehaviour(BaseProjectile aBaseProjectile) { Item theItem = aBaseProjectile.GetItem(); if (theItem != null) { theItem.name = GetText(I18N_TASER, theItem.GetOwnerPlayer()?.UserIDString); } aBaseProjectile.canUnloadAmmo = false; aBaseProjectile.primaryMagazine.contents = 1; aBaseProjectile.primaryMagazine.capacity = 0; TaserController theController = aBaseProjectile.GetComponent <TaserController>(); if (theController) { UnityEngine.Object.Destroy(theController); } aBaseProjectile.gameObject.AddComponent <TaserController>().Config = config; aBaseProjectile.SendNetworkUpdateImmediate(); }
private void Awake() { Projectile = LevelStructure.gameObject.GetComponentInChildren <BaseProjectile>(); Targets = LevelStructure.GetComponentsInChildren <BaseTarget>(); Projectile.GetComponent <Rigidbody2D>().gravityScale = GravityScale; }