예제 #1
0
 protected virtual void Start()
 {
     if (isServer)
     {
         shipResource = GetComponent <ShipResource>();
         InvokeRepeating(nameof(DecreaseTime), 0, decreaseFrequency);
     }
 }
예제 #2
0
        private void ServerStartupStuff()
        {
            gold              = GameObject.Find("CurrentGold").GetComponent <ShipResource>();
            minimumGoldValue += (int)(-transform.position.y / minimumGoldValueDepthIncrease);
            maximumGoldValue  = (int)(-transform.position.y / maximumGoldValueDepthIncrease) + minimumGoldValue;
            Random random = new Random(transform.position.y.ToString().GetHashCode() + Environment.TickCount.ToString().GetHashCode());

            value = (int)(random.Next(minimumGoldValue, maximumGoldValue) * goldMultiplier.Value);
            UpdatePosition(transform.position);
        }
예제 #3
0
        private void Start()
        {
            if (electricity == null)
            {
                electricity = GameObject.Find("Game/Ship/Resources/ElectricityGeneration").GetComponent <ShipResource>();
            }

            light = GetComponent <Light>();
            InvokeRepeating(nameof(ToggleLight), 0, 0.25f);
        }
예제 #4
0
        protected virtual void Start()
        {
            rb     = GetComponent <Rigidbody2D>();
            hullHP = GetComponent <ShipResource>();

            if (isServer)
            {
                hullHP.EventResourceEmpty += Die;
            }

            SetTarget();
        }
예제 #5
0
        private void Start()
        {
            subController          = stations.GetComponentInChildren <SubController>();
            enginePower            = GameObject.Find("EnginePower").GetComponent <ShipResource>();
            rb2D                   = GetComponent <Rigidbody2D>();
            spriteRenderer         = GetComponent <SpriteRenderer>();
            submarineComponents    = GetComponentsInChildren <FlipSubmarineComponent>();
            subSpeed               = 40;
            submarineRotationSpeed = 2f;
            submarineRotation      = rb2D.rotation;
            submarinePosition      = rb2D.position;

            if (isServer)
            {
                InvokeRepeating(nameof(CheckIfNeedSynchronization), 1, syncInterval);
            }
        }
예제 #6
0
        private void OnTriggerEnter2D(Collider2D collision)
        {
            if (collision.CompareTag(ReferenceManager.Singleton.SubmarineTag) || collision.CompareTag(ReferenceManager.Singleton.EnemyTag))
            {
                bool alliedShip = (npc && collision.CompareTag(ReferenceManager.Singleton.EnemyTag)) || (!npc && collision.CompareTag(ReferenceManager.Singleton.SubmarineTag));

                if (debugCollision)
                {
                    string info = transform.name + " was hit by a ";
                    if (alliedShip)
                    {
                        Debug.Log(info + nameof(alliedShip));
                    }
                    else
                    {
                        Debug.Log(info + "enemy bullet");
                    }
                }

                if (!alliedShip)
                {
                    //TODO fix Bubba's health so that it's not null
                    //Todo change this if collider position is standardized
                    ShipResource health = collision.gameObject.GetComponent <ShipResource>();

                    if (health == null)
                    {
                        health = collision.gameObject.GetComponentInParent <ShipResource>();
                    }

                    if (debugCollision && health == null)
                    {
                        Debug.Log("Health is null");
                    }

                    if (debugCollision)
                    {
                        Debug.Log("Damage is: " + damage + "\nHealth before: " + health.CurrentValue);
                    }

                    health.ApplyChange(-Damage);

                    if (debugCollision)
                    {
                        Debug.Log("Health after: " + health.CurrentValue);
                    }

                    if (npc && health.CurrentValue == 0)
                    {
                        NetworkServer.Destroy(collision.gameObject);
                    }
                }
            }

            if (isServer)
            {
                ServerPlaySound();
            }
            else
            {
                CommandPlaySound();
            }

            NetworkServer.Destroy(gameObject);
        }
예제 #7
0
 private void Start()
 {
     hullHealth = GetComponent <ShipResource>();
     npc        = CompareTag(ReferenceManager.Singleton.EnemyTag);
 }
예제 #8
0
 private void Awake() => electricity = GetComponent <ShipResource>();