public bool TryAttachToShip(ShipStructure structure) { // Try attaching this to the ship. If this returns false, then the ship // rejected the attachment (possibly because it already had a component of that type, or it hit a max number of components) if (enabled && shipComponent.Attach(structure)) { // Attach was successful, so remove this from the spawner and // disable the floating behaviours // Release from the spawner if it was owned by it, as this is now owned by the ship if (SpawnTag != null) { SpawnTag.spawner.Remove(this); } attachSounds.PlayRandomOneShot(audioSource); // Disable the FloatingComponent, as this has been attached to the ship Destroy(rigidbody2D); rigidbody2D = null; enabled = false; outline.eraseRenderer = true; mouseOver = false; //mask.alphaCutoff = 0; //oldMaskInteraction = renderer.maskInteraction; //renderer.maskInteraction = SpriteMaskInteraction.None; return(true); } return(false); }
public void DamagePlanks(float amount, ShipStructure attacker) { PlanksHealth -= amount; while (PlanksHealth < (healthPerPlank * (planks.Count - 1)) && Planks.Count > 0) { if (!planks[planks.Count - 1].FloatingComponent.TryReturnToSpawner()) { Debug.LogError("Should not happen"); } } if (PlanksHealth <= 0) { if (attacker.CompareTag("Player")) { GameObject.Find("GameManager").GetComponent <Scoring>().ShipsSunk++; } PlanksHealth = 0; OnLose.Invoke(this); onDestroySounds.PlayRandomOneShot(Instantiate(onDestroySoundPrefab, transform.position, Quaternion.identity).GetComponent <AudioSource>()); Instantiate(onDestroyParticles, transform.position, Quaternion.identity); Destroy(gameObject); } }
/// <summary> /// 機体構造の設定 /// </summary> public void SetStructure(ShipStructure structure) { weapon = structure.WeaponController; if (weapon) { weapon.SetBulletExclusionTag("Player"); } thruster = structure.ThrusterController; attitude = structure.AttitudeController; marker = structure.Marker; if (marker) { detector = marker.ObjDetector; detector.OnDetect.RemoveListener(OnDetect); detector.OnDetect.AddListener(OnDetect); detector.OnRelease.RemoveListener(OnRelease); detector.OnRelease.AddListener(OnRelease); } attackable = structure.Attackable; if (attackable) { attackable.OnAttacked.RemoveListener(OnAttacked); attackable.OnAttacked.AddListener(OnAttacked); attackable.OnDied.RemoveListener(OnDied); attackable.OnDied.AddListener(OnDied); } }
// Update is called once per frame void Update() { if (structure.Weapon) { if (acquireTargetCooldown.Check(Time.time)) { ShipStructure[] potentialTargets = shipManager.FindNearbyShips(structure, maxAcquireDistance).ToArray(); if (potentialTargets.Length > 0) { currentTarget = RandomExtensions.RandomElement(potentialTargets); loseTargetCooldown.Reset(Time.time); } } if (currentTarget && loseTargetCooldown.Check(Time.time) && structure.DistanceTo(currentTarget) > maxAcquireDistance) { currentTarget = null; } if (currentTarget) { structure.Weapon.Aim(currentTarget.transform.position); structure.Weapon.Fire(); } } }
public float DistanceTo(ShipStructure structure) { Vector2 closestOtherPoint = structure.ClosestPoint(transform.position); Vector2 closestPoint = ClosestPoint(closestOtherPoint); return(Vector2.Distance(closestOtherPoint, closestPoint)); }
public float DistanceTo(ShipStructure structure) { Vector2 closestShipPoint = structure.ClosestPoint(transform.position); Vector2 closestComponentPoint = collider2d.ClosestPoint(closestShipPoint); return(Vector2.Distance(closestShipPoint, closestComponentPoint)); }
private void OnCollisionEnter2D(Collision2D collision) { if (!collision.rigidbody) { return; } ShipStructure otherStructure = collision.rigidbody.GetComponent <ShipStructure>(); if (!otherStructure) { return; // Not colliding with a ship } // Calculate the damage we should take on collision Vector2 direction = collision.otherRigidbody.position - collision.rigidbody.position; float orthogonalSpeed = Vector2.Dot((lastVelocity + collision.relativeVelocity), direction); if (orthogonalSpeed < 0) { orthogonalSpeed = 0; } float damageMultiplier = orthogonalSpeed * collision.rigidbody.mass; ApplyDamage(collision.otherCollider, new DamageInfo() { source = otherStructure, amount = damageMultiplier * 2, force = (collision.otherRigidbody.position - collision.rigidbody.position) * 100 }); }
/// <summary> /// ランダムな構造の機体を作成 /// </summary> public ShipStructure CreateRandom() { ShipStructure structure = CreateShipStructure(); SetRandomWeapon(structure); SetRandomThruster(structure); return(structure); }
void OnShipDestroyed(ShipStructure structure, ShipManager manager) { // Null out the target if it gets destroyed if (currentBoatTarget == structure) { currentBoatTarget = null; } }
public bool Attach(ShipStructure structure) { if (DoAttach(structure)) { attachedStructure = structure; return(true); } return(false); }
protected override bool DoDetach(ShipStructure structure) { if (structure.RemoveStern(this)) { structureRigidBody = null; return(true); } return(false); }
protected override bool DoAttach(ShipStructure structure) { if (structure.AddStern(this)) { structureRigidBody = structure.GetComponent <Rigidbody2D>(); return(true); } return(false); }
public IEnumerable <ShipStructure> FindNearbyShips(ShipStructure structure, float distance) { foreach (ShipStructure ship in ships) { if (ship != structure && structure.DistanceTo(ship) <= distance) { yield return(ship); } } }
/// <summary> /// ランダムに推進器を設定する /// </summary> public void SetRandomThruster(ShipStructure structure) { var thrusterCon = structure.ThrusterController; foreach (var t in thrusterCon.Coms) { ShipThruster thruster = thrusterList.Get(); t.SetEquipment(Instantiate(thruster)); } }
/// <summary> /// ランダムに武器を設定する /// </summary> public void SetRandomWeapon(ShipStructure structure) { var weaponCon = structure.WeaponController; foreach (var w in weaponCon.Coms) { ShipWeapon weapon = weaponList.Get(); w.SetEquipment(Instantiate(weapon)); SetBullet(w.Equipment); } }
private void Start() { for (uint i = 0; i < SetShipCount.ShipCount; i++) { Vector2 position = RandomExtensions.RandomInsideBounds(spawnVolume); GameObject spawned = Instantiate(npcPrefab, position, Quaternion.identity); ShipStructure structure = spawned.GetComponent <ShipStructure>(); structure.OnLose.AddListener(RemoveShip); ships.Add(structure); } }
public void RemoveShip(ShipStructure structure) { ships.Remove(structure); OnShipDestroyed.Invoke(structure, this); if (structure == player) { Lose(); } else if (ships.Count == 1) { Win(); } }
public IEnumerable <FloatingComponent> FindNearbySpawnedComponents(ShipStructure structure, float distance) { foreach (SpawnInfo info in spawnInfos) { foreach (FloatingComponent spawned in info.spawned) { if (spawned.DistanceTo(structure) <= distance) { yield return(spawned); } } } }
bool FindNearbyBoatTarget(out ShipStructure bestStructure) { bestStructure = null; foreach (ShipStructure structure in shipManager.FindNearbyShips(shipStructure, boatCheckDistance)) { // TODO: Go after the weakest boat if (!bestStructure || bestStructure.Planks.Count <= structure.Planks.Count) { bestStructure = structure; } } return(bestStructure != null); }
/// <summary> /// 機体構造の作成 /// </summary> public ShipStructure CreateShipStructure() { if (structureList) { ShipStructure structure = Instantiate <ShipStructure>(structureList.Get()); structure.InitCom(structure); structure.AwakeCom(); return(structure); } else { return(null); } }
void Start() { GameObject gameManager = GameObject.Find("GameManager"); componentSpawner = gameManager.GetComponent <FloatingComponentSpawner>(); shipManager = gameManager.GetComponent <ShipManager>(); shipManager.OnShipDestroyed.AddListener(OnShipDestroyed); movement = GetComponent <NPCMovement>(); shipStructure = GetComponent <ShipStructure>(); fsm = StateMachine <States> .Initialize(this); fsm.ChangeState(States.Roam); }
public bool TryReturnToSpawner() { ShipStructure structure = shipComponent.AttachedStructure; if (!enabled && shipComponent.Detach()) { rigidbody2D = gameObject.AddComponent <Rigidbody2D>(); rigidbody2D.gravityScale = 0; // Pick a random direction away from structure and eject the component in that direction Vector2 direction = transform.position - structure.transform.position; rigidbody2D.AddForce(direction.normalized * 100); detachSounds.PlayRandomOneShot(audioSource); enabled = true; //renderer.maskInteraction = oldMaskInteraction; if (particlesOnDetach) { Instantiate(particlesOnDetach, transform.position, Quaternion.identity); } if (SpawnTag != null && !destroyOnDetach) { SpawnTag.spawner.Add(this); } else { // Was either not owned by a spawner, or we're set to destroy on detach Destroy(gameObject); } return(true); } return(false); }
private void Start() { GameObject player = GameObject.FindGameObjectWithTag("Player"); if (player) { this.player = player.GetComponent <ShipStructure>(); } audioSource = GetComponent <AudioSource>(); collider2d = GetComponent <Collider2D>(); rigidbody2D = GetComponent <Rigidbody2D>(); outline = GetComponent <Outline>(); positionFollow = GetComponent <PositionFollow>(); shipComponent = GetComponent <ShipComponent>(); outline.eraseRenderer = true; offset = Random.Range(0, 100); basePosition = transform.position; mask = GetComponent <SpriteMask>(); renderer = GetComponent <SpriteRenderer>(); if (mask) { mask.alphaCutoff = UnityEngine.Random.Range(maskMin, maskMax); } // floating component is set to execute after last after othe scripts, but before the floating component spawner if (transform.parent) { // Spawned parented to something, so assume try attaching to it! ShipStructure structure = transform.parent.GetComponent <ShipStructure>(); if (structure) { // Attach to that bad boy TryAttachToShip(structure); } } }
protected override bool DoAttach(ShipStructure structure) { return(structure.AddOar(this)); }
protected override bool DoDetach(ShipStructure structure) { return(structure.RemoveOar(this)); }
/// <summary> /// 初期化 /// </summary> public override void InitCom(ShipStructure ship) { base.InitCom(ship); tInterval = 0f; InitComs(); }
// Start is called before the first frame update void Start() { structure = GetComponent <ShipStructure>(); shipManager = GameObject.Find("GameManager").GetComponent <ShipManager>(); shipManager.OnShipDestroyed.AddListener(OnShipDestroyed); }
protected abstract bool DoDetach(ShipStructure structure);
protected override bool DoAttach(ShipStructure structure) { currentAmmo = maxAmmo; return(structure.AddWeapon(this)); }
public bool CanPickup(ShipStructure structure) { return(DistanceTo(structure) < pickupDistance); }