示例#1
0
    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);
    }
示例#2
0
    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);
        }
    }
示例#3
0
 /// <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);
     }
 }
示例#4
0
    // 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();
            }
        }
    }
示例#5
0
    public float DistanceTo(ShipStructure structure)
    {
        Vector2 closestOtherPoint = structure.ClosestPoint(transform.position);
        Vector2 closestPoint      = ClosestPoint(closestOtherPoint);

        return(Vector2.Distance(closestOtherPoint, closestPoint));
    }
示例#6
0
    public float DistanceTo(ShipStructure structure)
    {
        Vector2 closestShipPoint      = structure.ClosestPoint(transform.position);
        Vector2 closestComponentPoint = collider2d.ClosestPoint(closestShipPoint);

        return(Vector2.Distance(closestShipPoint, closestComponentPoint));
    }
示例#7
0
    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
        });
    }
示例#8
0
        /// <summary>
        /// ランダムな構造の機体を作成
        /// </summary>
        public ShipStructure CreateRandom()
        {
            ShipStructure structure = CreateShipStructure();

            SetRandomWeapon(structure);
            SetRandomThruster(structure);
            return(structure);
        }
示例#9
0
 void OnShipDestroyed(ShipStructure structure, ShipManager manager)
 {
     // Null out the target if it gets destroyed
     if (currentBoatTarget == structure)
     {
         currentBoatTarget = null;
     }
 }
示例#10
0
 public bool Attach(ShipStructure structure)
 {
     if (DoAttach(structure))
     {
         attachedStructure = structure;
         return(true);
     }
     return(false);
 }
示例#11
0
文件: Stern.cs 项目: sam6321/Decay
 protected override bool DoDetach(ShipStructure structure)
 {
     if (structure.RemoveStern(this))
     {
         structureRigidBody = null;
         return(true);
     }
     return(false);
 }
示例#12
0
文件: Stern.cs 项目: sam6321/Decay
 protected override bool DoAttach(ShipStructure structure)
 {
     if (structure.AddStern(this))
     {
         structureRigidBody = structure.GetComponent <Rigidbody2D>();
         return(true);
     }
     return(false);
 }
示例#13
0
 public IEnumerable <ShipStructure> FindNearbyShips(ShipStructure structure, float distance)
 {
     foreach (ShipStructure ship in ships)
     {
         if (ship != structure && structure.DistanceTo(ship) <= distance)
         {
             yield return(ship);
         }
     }
 }
示例#14
0
        /// <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));
            }
        }
示例#15
0
        /// <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);
            }
        }
示例#16
0
    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);
        }
    }
示例#17
0
 public void RemoveShip(ShipStructure structure)
 {
     ships.Remove(structure);
     OnShipDestroyed.Invoke(structure, this);
     if (structure == player)
     {
         Lose();
     }
     else if (ships.Count == 1)
     {
         Win();
     }
 }
示例#18
0
 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);
             }
         }
     }
 }
示例#19
0
 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);
 }
示例#20
0
 /// <summary>
 /// 機体構造の作成
 /// </summary>
 public ShipStructure CreateShipStructure()
 {
     if (structureList)
     {
         ShipStructure structure = Instantiate <ShipStructure>(structureList.Get());
         structure.InitCom(structure);
         structure.AwakeCom();
         return(structure);
     }
     else
     {
         return(null);
     }
 }
示例#21
0
    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);
    }
示例#22
0
    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);
    }
示例#23
0
    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);
            }
        }
    }
示例#24
0
 protected override bool DoAttach(ShipStructure structure)
 {
     return(structure.AddOar(this));
 }
示例#25
0
 protected override bool DoDetach(ShipStructure structure)
 {
     return(structure.RemoveOar(this));
 }
示例#26
0
 /// <summary>
 /// 初期化
 /// </summary>
 public override void InitCom(ShipStructure ship)
 {
     base.InitCom(ship);
     tInterval = 0f;
     InitComs();
 }
示例#27
0
 // Start is called before the first frame update
 void Start()
 {
     structure   = GetComponent <ShipStructure>();
     shipManager = GameObject.Find("GameManager").GetComponent <ShipManager>();
     shipManager.OnShipDestroyed.AddListener(OnShipDestroyed);
 }
示例#28
0
 protected abstract bool DoDetach(ShipStructure structure);
示例#29
0
 protected override bool DoAttach(ShipStructure structure)
 {
     currentAmmo = maxAmmo;
     return(structure.AddWeapon(this));
 }
示例#30
0
 public bool CanPickup(ShipStructure structure)
 {
     return(DistanceTo(structure) < pickupDistance);
 }