private void HandleFluidHealthChange(CComponentInterface _Component, CActorHealth _ComponentHealth)
	{
		if(CNetwork.IsServer)
		{
			m_AtmosphereGenerator.AtmosphereGenerationRate = m_MaxAtmosphereGenerationRate * (_ComponentHealth.health / _ComponentHealth.health_initial);
		}
	}
Beispiel #2
0
 private void HandleCalibrationHealthChange(CComponentInterface _Component, CActorHealth _ComponentHealth)
 {
     if (CNetwork.IsServer)
     {
         m_PowerGenerator.PowerGenerationRate = m_MaxPowerGenerationRate * (_ComponentHealth.health / _ComponentHealth.health_initial);
     }
 }
 private void HandleFluidHealthChange(CComponentInterface _Component, CActorHealth _ComponentHealth)
 {
     if (CNetwork.IsServer)
     {
         m_AtmosphereGenerator.AtmosphereGenerationRate = m_MaxAtmosphereGenerationRate * (_ComponentHealth.health / _ComponentHealth.health_initial);
     }
 }
Beispiel #4
0
    void Update()
    {
        if (CNetwork.IsServer && burning)
        {
            //timeUntilNextSpreadProcess -= Time.deltaTime;
            //while(timeUntilNextSpreadProcess <= 0.0f)
            //{
            //    timeUntilNextSpreadProcess += timeBetweenSpreadProcess;

            //    // Drain health of all fires within range, including one's self (which is included in the list of neighbours).
            //    foreach(CFireHazard fireHazard in s_AllFires)
            //        if((fireHazard.transform.position - transform.position).sqrMagnitude - (spreadRadius * spreadRadius + fireHazard.spreadRadius * fireHazard.spreadRadius) <= 0.0f)
            //            fireHazard.GetComponent<CActorHealth>().health -= timeBetweenSpreadProcess;
            //}

            CFacilityAtmosphere fa = GetComponent <CActorLocator>().LastEnteredFacility.GetComponent <CFacilityAtmosphere>();
            CActorHealth        ah = GetComponent <CActorHealth>();

            float thresholdPercentage = 0.25f;
            if (fa.AtmospherePercentage < thresholdPercentage)
            {
                ah.health += (1.0f / (fa.AtmospherePercentage / thresholdPercentage)) * Time.deltaTime;
            }
        }
    }
Beispiel #5
0
 void OnTriggerStay(Collider collider)
 {
     if (CNetwork.IsServer)
     {
         if (burning)
         {
             // Damage everything within radius that is flammable.
             CActorHealth victimHealth = collider.GetComponent <CActorHealth>();
             if (victimHealth != null)
             {
                 if (victimHealth.flammable)
                 {
                     victimHealth.health -= Time.fixedDeltaTime;
                 }
                 else
                 {
                     // Damage players - they use their own health script.
                     CPlayerHealth otherPlayerhealth = collider.GetComponent <CPlayerHealth>();
                     if (otherPlayerhealth != null)
                     {
                         otherPlayerhealth.ApplyDamage(Time.fixedDeltaTime);
                     }
                 }
             }
         }
     }
 }
Beispiel #6
0
	private void HandleCalibrationHealthChange(CComponentInterface _Component, CActorHealth _ComponentHealth)
	{
		if(CNetwork.IsServer)
		{
			m_PowerGenerator.PowerGenerationRate = m_MaxPowerGenerationRate * (_ComponentHealth.health / _ComponentHealth.health_initial);
		}
	}
Beispiel #7
0
    void OnHealthChange(CComponentInterface _Sender, CActorHealth _SenderHealth)
    {
        m_CurrentHealth  = _SenderHealth.health;
        m_PreviousHealth = _SenderHealth.health_previous;
        float maxHealth = _SenderHealth.health_initial;

        transform.FindChild("Model").renderer.material.color = Color.Lerp(Color.red, Color.green, m_CurrentHealth / maxHealth);
    }
Beispiel #8
0
	void OnHealthChange(CComponentInterface _Sender, CActorHealth _SenderHealth)
	{
		m_CurrentHealth = _SenderHealth.health;
		m_PreviousHealth = _SenderHealth.health_previous;
		float maxHealth = _SenderHealth.health_initial;
		
		transform.FindChild("Model").renderer.material.color = Color.Lerp(Color.red, Color.green, m_CurrentHealth / maxHealth);
	}
Beispiel #9
0
    private void HandleMechanicalHealthChange(CComponentInterface _Component, CActorHealth _ComponentHealth)
    {
        if (CNetwork.IsServer)
        {
            // Get the combined health of the mechanical components
            float currentCombinedHealth = 0.0f;
            float combinedInitialHealth = 0.0f;

            currentCombinedHealth += m_MechanicalComponent1.GetComponent <CActorHealth>().health;
            currentCombinedHealth += m_MechanicalComponent2.GetComponent <CActorHealth>().health;

            combinedInitialHealth += m_MechanicalComponent1.GetComponent <CActorHealth>().health_initial;
            combinedInitialHealth += m_MechanicalComponent2.GetComponent <CActorHealth>().health_initial;

            m_PropulsionGenerator.PropulsionForce = m_MaxPropulsion * (currentCombinedHealth / combinedInitialHealth);
        }
    }
Beispiel #10
0
	private void HandleMechanicalHealthChange(CComponentInterface _Component, CActorHealth _ComponentHealth)
	{
		if(CNetwork.IsServer)
		{
			// Get the combined health of the mechanical components
			float currentCombinedHealth = 0.0f;
			float combinedInitialHealth = 0.0f;

			currentCombinedHealth += m_MechanicalComponent1.GetComponent<CActorHealth>().health;
			currentCombinedHealth += m_MechanicalComponent2.GetComponent<CActorHealth>().health;

			combinedInitialHealth += m_MechanicalComponent1.GetComponent<CActorHealth>().health_initial;
			combinedInitialHealth += m_MechanicalComponent2.GetComponent<CActorHealth>().health_initial;

			m_PropulsionGenerator.PropulsionForce = m_MaxPropulsion * (currentCombinedHealth / combinedInitialHealth);
		}
	}
Beispiel #11
0
    static void OnChildSetBreached(GameObject gameObject, bool breached)
    {
        CHullBreachNode hullBreachNode = gameObject.transform.parent.GetComponent <CHullBreachNode>();

        if (breached)           // If the child is now breached...
        {
            ++hullBreachNode.numChildrenBreached;

            if (hullBreachNode.numChildrenBreached >= hullBreachNode.childBreaches.Count)               // If all children are breached...
            {
                CActorHealth hullBreachActorHealth = hullBreachNode.GetComponent <CActorHealth>();
                hullBreachActorHealth.health = hullBreachActorHealth.health_min;                        // Force this parent to breach.
            }
        }
        else
        {
            --hullBreachNode.numChildrenBreached;
        }
    }
Beispiel #12
0
    static void OnSetState(GameObject gameObject, byte prevState, byte currState)
    {
        switch (currState)
        {
        case 0:                 // Hull breach threshold.
        {
            CHullBreachNode hullBreachNode = gameObject.GetComponent <CHullBreachNode>();

            if (!hullBreachNode.breached)                               // If the hull was not breached before passing the breach threshold...
            {
                // Breach the hull.
                if (hullBreachNode.childBreaches.Count > 0)                                     // If this breach is a parent...
                {
                    // Remove the models set by children.
                    foreach (CHullBreachNode childBreach in hullBreachNode.childBreaches)
                    {
                        childBreach.GetComponent <MeshFilter>().sharedMesh   = null;
                        childBreach.GetComponent <MeshCollider>().sharedMesh = null;
                    }
                }

                // Set breached mesh model and collider.
                gameObject.GetComponent <MeshFilter>().sharedMesh   = hullBreachNode.breachedMesh;
                gameObject.GetComponent <MeshCollider>().sharedMesh = hullBreachNode.breachedMesh;

                // Set breached state.
                hullBreachNode.breached = true;

                // Inform the facility this breach resides in.
                if (hullBreachNode.parentFacilityHull != null)
                {
                    hullBreachNode.parentFacilityHull.AddBreach(gameObject);
                }
            }
        }
        break;

        case 2:                 // Hull fix threshold.
        {
            CHullBreachNode hullBreachNode = gameObject.GetComponent <CHullBreachNode>();

            if (hullBreachNode.breached)                                // If the hull was breached before passing the fix threshold...
            {
                // Fix the breach.
                if (hullBreachNode.childBreaches.Count > 0)                                     // If this breach is a parent...
                {
                    // Fix the children.
                    foreach (CHullBreachNode childBreach in hullBreachNode.childBreaches)
                    {
                        CActorHealth childActorHealth = childBreach.GetComponent <CActorHealth>();
                        childActorHealth.health = childActorHealth.health_max;                                          // Force all children to repair.
                    }
                }

                // Set breached mesh model and collider.
                gameObject.GetComponent <MeshFilter>().sharedMesh   = hullBreachNode.goodMesh;
                gameObject.GetComponent <MeshCollider>().sharedMesh = hullBreachNode.goodMesh;

                // Set breached state.
                hullBreachNode.breached = false;

                // Inform the facility this breach resides in.
                if (hullBreachNode.parentFacilityHull != null)
                {
                    hullBreachNode.parentFacilityHull.RemoveBreach(gameObject);
                }
            }
        }
        break;
        }
    }
Beispiel #13
0
    //SerializedProperty syncNetworkHealth;
    //SerializedProperty destroyOnZeroHealth;
    //SerializedProperty takeDamageOnImpact;
    //SerializedProperty syncNetworkState;
    //SerializedProperty health_initial;
    //SerializedProperty state_initial;
    //SerializedProperty stateTransitions;
    //
    //void OnEnable()
    //{
    //	syncNetworkHealth = serializedObject.FindProperty("syncNetworkHealth");
    //	destroyOnZeroHealth = serializedObject.FindProperty("destroyOnZeroHealth");
    //	takeDamageOnImpact = serializedObject.FindProperty("takeDamageOnImpact");
    //	syncNetworkState = serializedObject.FindProperty("syncNetworkState");
    //	health_initial = serializedObject.FindProperty("health_initial");
    //	state_initial = serializedObject.FindProperty("state_initial");
    //	stateTransitions = serializedObject.FindProperty("stateTransitions");
    //}

    public override void OnInspectorGUI()
    {
        //serializedObject.Update();

        CActorHealth myTarget = (CActorHealth)target;

        foldoutHealth = EditorGUILayout.Foldout(foldoutHealth, "Health");
        if (foldoutHealth)
        {
            //EditorGUILayout.IntSlider(health_initial, 0, 100, new UnityEngine.GUIContent("Health"));
            //EditorGUILayout.FloatField(health_initial, new UnityEngine.GUIContent("Initial Health"));

            myTarget.health_initial = EditorGUILayout.FloatField("Initial Value", myTarget.health_initial);
            myTarget.health_max     = EditorGUILayout.FloatField("Max Value", myTarget.health_max);
            myTarget.health_min     = EditorGUILayout.FloatField("Min Value", myTarget.health_min);
            if (EditorApplication.isPlaying)
            {
                float current = myTarget.health;
                float result  = EditorGUILayout.FloatField("Current Value", current);
                if (current != result)
                {
                    myTarget.health = result;
                }
            }
            else
            {
                EditorGUILayout.LabelField("Current value\t\t\t  " + myTarget.health);
            }
            myTarget.syncNetworkHealth   = EditorGUILayout.Toggle("Sync Network", myTarget.syncNetworkHealth);
            myTarget.destroyOnZeroHealth = EditorGUILayout.Toggle("Destroy On Zero", myTarget.destroyOnZeroHealth);
            myTarget.takeDamageOnImpact  = EditorGUILayout.Toggle("Impact Damage", myTarget.takeDamageOnImpact);
            myTarget.flammable           = EditorGUILayout.Toggle("Flammable", myTarget.flammable);
        }

        foldoutState = EditorGUILayout.Foldout(foldoutState, "State");
        if (foldoutState)
        {
            int initialState = EditorGUILayout.IntField("Initial Value", myTarget.state_initial); myTarget.state_initial = (byte)(initialState < 0 ? 0 : initialState > 255 ? 255 : initialState);
            EditorGUILayout.LabelField("Current Value\t\t\t  " + myTarget.state);
            myTarget.syncNetworkState = EditorGUILayout.Toggle("Sync Network", myTarget.syncNetworkState);

            int currentStateTransitionLength = myTarget.stateTransitions != null ? myTarget.stateTransitions.Length : 0;
            int newStateTransitionLength     = EditorGUILayout.IntField("Transition Count", currentStateTransitionLength);
            if (newStateTransitionLength != currentStateTransitionLength)
            {
                float[] newStateArray = new float[newStateTransitionLength];
                for (int i = 0; i < newStateTransitionLength; ++i)
                {
                    newStateArray[i] = (i < currentStateTransitionLength) ? myTarget.stateTransitions[i] : i != 0 ? newStateArray[i - 1] : 0;
                }

                myTarget.stateTransitions = newStateArray;
            }

            for (int i = 0; i < newStateTransitionLength; ++i)
            {
                myTarget.stateTransitions[i] = EditorGUILayout.FloatField("State " + (i + 1).ToString() + " if health >=", myTarget.stateTransitions[i]);
            }
        }

        myTarget.callEventsOnStart = EditorGUILayout.Toggle("Call Events On Start", myTarget.callEventsOnStart);

        if (myTarget.syncNetworkState || myTarget.syncNetworkHealth)
        {
            float result = EditorGUILayout.FloatField("Syncs Per Second", 1.0f / myTarget.timeBetweenNetworkSyncs);
            myTarget.timeBetweenNetworkSyncs = result <= 0.0f ? float.PositiveInfinity : 1.0f / result;
        }

        //serializedObject.ApplyModifiedProperties();
    }
Beispiel #14
0
    void OnInsufficientAtmosphere()
    {
        CActorHealth ah = GetComponent <CActorHealth>();

        ah.health = ah.health_max;
    }