Esempio n. 1
0
 // Use this for initialization
 void Start()
 {
     _activatableComponent = GetComponent<ActivatableComponent>();
     _rendererComponent = GetComponent<Renderer>();
     canBeActivated = false;
     //rotation = this.transform.localRotation;
 }
Esempio n. 2
0
 public static bool Prefix(Mech __instance, int previousStackID, string sourceID, Vector2 attackDirection, SequenceFinished fallSequenceCompletedCallback)
 {
     try {
         Log.Debug?.TWL(0, "Mech.GenerateFallSequence");
         foreach (MechComponent component in __instance.allComponents)
         {
             ActivatableComponent activatable = component.componentDef.GetComponent <ActivatableComponent>();
             if (activatable == null)
             {
                 continue;
             }
             if (activatable.SwitchOffOnFall == false)
             {
                 continue;
             }
             if (ActivatableComponent.isComponentActivated(component))
             {
                 ActivatableComponent.deactivateComponent(component);
             }
         }
     } catch (Exception e) {
         Log.Debug?.TWL(0, e.ToString());
     }
     return(true);
 }
Esempio n. 3
0
 // Use this for initialization
 void Start()
 {
     _activatableComponent = GetComponent<ActivatableComponent>();
     _rendererComponent = GetComponent<Renderer>();
     _rendererComponent.material.color = Color.red;
     canBeActivated = true;
     //rotation = this.transform.localRotation;
 }
Esempio n. 4
0
 // Use this for initialization
 void Start()
 {
     _activatableComponent             = GetComponent <ActivatableComponent>();
     _rendererComponent                = GetComponent <Renderer>();
     _rendererComponent.material.color = Color.red;
     canBeActivated = true;
     //rotation = this.transform.localRotation;
 }
        public static void ActivateComponentsBasedOnHeatDamage(Mech defender, int heatDamage)
        {
            if (heatDamage <= 0)
            {
                Log.Debug?.Write("No heat damage\n");
                return;
            }

            if (defender == null)
            {
                Log.Debug?.Write("No mech\n");
                return;
            }

            if (defender.IsDead || defender.IsFlaggedForDeath || defender.IsShutDown)
            {
                Log.Debug?.Write($"{defender.DisplayName} dead or shutdown.\n");//<check> do we need to handle incoming damage when shutdown on startup?
                return;
            }

            foreach (MechComponent component in defender.allComponents)
            {
                ActivatableComponent tactivatable = component.componentDef.GetComponent <ActivatableComponent>();
                if (tactivatable == null)
                {
                    continue;
                }
                if (ActivatableComponent.canBeDamageActivated(component) == false)
                {
                    continue;
                }
                ;
                if (defender.IsLocationDestroyed((ChassisLocations)component.Location))
                {
                    Log.Debug?.Write($"Ignored {component.Name} installed in destroyed {((ChassisLocations)component.Location).ToString()}\n");
                    continue;
                }
                ;
                if (defender is Mech mech)
                {
                    Log.Debug?.Write($"Damage >>> D: {0:F3} DS: {0:F3} H: {heatDamage}\n");
                }
                else
                {
                    Log.Debug?.Write($"Not a mech, somethings broken\n");
                }

                if (defender.isHasHeat())//if not battle armor
                {
                    ActivatableComponent.ActivateOnIncomingHeat(component, heatDamage);
                }
                else
                {
                    Log.Debug?.Write($" { defender.DisplayName } can't have incoming heat damage\n");
                }
            }
        }
 public static bool Prefix(MechComponent __instance, bool performAuraRefresh)
 {
     try {
         Log.LogWrite("MechComponent.RestartPassiveEffects " + __instance.defId + "\n");
         ActivatableComponent.startupComponent(__instance);
     } catch (Exception e) {
         Log.LogWrite(e.ToString() + "\n");
     }
     return(true);
 }
Esempio n. 7
0
 public static bool Prefix(MechComponent __instance, bool performAuraRefresh)
 {
     try {
         Log.Debug?.Write("MechComponent.CancelCreatedEffects " + __instance.defId + "\n");
         ActivatableComponent.shutdownComponent(__instance);
     } catch (Exception e) {
         Log.Debug?.Write(e.ToString() + "\n");
     }
     return(true);
 }
        public HashSet <int> getSensibleLocations(MechComponent component)
        {
            HashSet <int>        result       = new HashSet <int>();
            ActivatableComponent tactivatable = component.componentDef.GetComponent <ActivatableComponent>();

            if (tactivatable == null)
            {
                return(result);
            }
            if (component.parent.GUID != this.owner.GUID)
            {
                return(result);
            }
            Mech    mech    = owner as Mech;
            Vehicle vehicle = owner as Vehicle;

            if (tactivatable.ActivateOnDamageToInstalledLocation)
            {
                result.Add(component.Location);
                if (mech != null)
                {
                    switch (component.mechComponentRef.MountedLocation)
                    {
                    case ChassisLocations.CenterTorso:  result.Add((int)ArmorLocation.CenterTorsoRear); break;

                    case ChassisLocations.LeftTorso: result.Add((int)ArmorLocation.LeftTorsoRear); break;

                    case ChassisLocations.RightTorso: result.Add((int)ArmorLocation.RightTorsoRear); break;
                    }
                }
            }
            if (mech != null)
            {
                foreach (ArmorLocation location in tactivatable.ActivateOnDamageToMechLocations)
                {
                    result.Add((int)location);
                }
            }
            else if (vehicle != null)
            {
                foreach (VehicleChassisLocations location in tactivatable.ActivateOnDamageToVehicleLocations)
                {
                    result.Add((int)location);
                }
            }
            else
            {
                result.Add((int)BuildingLocation.Structure);
            }
            return(result);
        }
 public static void ActiveDefaultComponents(this AbstractActor unit)
 {
     foreach (MechComponent component in unit.allComponents)
     {
         ActivatableComponent activatable = component.componentDef.GetComponent <ActivatableComponent>();
         if (activatable == null)
         {
             continue;
         }
         if (activatable.ActiveByDefault == true)
         {
             ActivatableComponent.activateComponent(component, true, true);
         }
         else
         {
             activatable.applyOfflineEffects(component, true);
         }
     }
 }
 public static void ActiveDefaultComponents(this AbstractActor unit)
 {
     Log.Debug?.WL(1, "ActiveDefaultComponents:" + unit.PilotableActorDef.Description.Id);
     foreach (MechComponent component in unit.allComponents)
     {
         ActivatableComponent activatable = component.componentDef.GetComponent <ActivatableComponent>();
         if (activatable == null)
         {
             continue;
         }
         Log.Debug?.WL(2, "component:" + component.Description.Id + " ActiveByDefault:" + activatable.ActiveByDefault);
         if (activatable.ActiveByDefault == true)
         {
             ActivatableComponent.activateComponent(component, true, true);
         }
         else
         {
             activatable.applyOfflineEffects(component, true);
         }
     }
     activatedActors.Add(unit);
 }
        public static void ActivateComponentsBasedOnDamage(Mech defender)
        {
            if (defender == null)
            {
                Log.Debug?.Write("No mech\n");
                return;
            }
            if (defender.IsDead || defender.IsFlaggedForDeath || defender.IsShutDown)
            {
                Log.Debug?.Write($"{defender.DisplayName} dead or shutdown.\n");//<check> do we need to handle incoming damage when shutdown on startup?
                return;
            }

            bool gotdamagevalues = false;

            float Head_s        = 0;
            float LeftArm_s     = 0;
            float LeftTorso_s   = 0;
            float CenterTorso_s = 0;
            float RightTorso_s  = 0;
            float RightArm_s    = 0;
            float LeftLeg_s     = 0;
            float RightLeg_s    = 0;

            float Head_a        = 0;
            float LeftArm_a     = 0;
            float LeftTorso_a   = 0;
            float CenterTorso_a = 0;
            float RightTorso_a  = 0;
            float RightArm_a    = 0;
            float LeftLeg_a     = 0;
            float RightLeg_a    = 0;

            foreach (MechComponent component in defender.allComponents)
            {
                ActivatableComponent tactivatable = component.componentDef.GetComponent <ActivatableComponent>();
                if (tactivatable == null)
                {
                    continue;
                }
                if (ActivatableComponent.canBeDamageActivated(component) == false)
                {
                    continue;
                }
                ;
                if (defender.IsLocationDestroyed((ChassisLocations)component.Location))
                {
                    Log.Debug?.Write($"Ignored {component.Name} installed in destroyed {((ChassisLocations)component.Location).ToString()}\n");
                    continue;
                }
                ;
                if (!gotdamagevalues)//have atleast 1 damage activateable component get the damage values
                {
                    Mech mech = defender;

                    Log.Debug?.Write($"{new string('-', 46)}\n");
                    Log.Debug?.Write($"{"Location",-20} | {"Armor Damage",12} | {"Structure Damage",12}\n");
                    Log.Debug?.Write($"{new string('-', 46)}\n");
                    Head_s = MaxStructureForLocation(mech, (int)ChassisLocations.Head) - defender.HeadStructure;
                    Head_a = MaxArmorForLocation(mech, (int)ChassisLocations.Head) - defender.HeadArmor;
                    Log.Debug?.Write($"{ChassisLocations.Head.ToString(),-20} | {Head_a,12:F3} | {Head_s,12:F3}\n");
                    CenterTorso_s = MaxStructureForLocation(mech, (int)ChassisLocations.CenterTorso) - defender.CenterTorsoStructure;
                    CenterTorso_a = MaxArmorForLocation(mech, (int)ArmorLocation.CenterTorso) + MaxArmorForLocation(mech, (int)ArmorLocation.CenterTorsoRear) - defender.CenterTorsoFrontArmor - defender.CenterTorsoRearArmor;
                    Log.Debug?.Write($"{ChassisLocations.CenterTorso.ToString(),-20} |  {CenterTorso_a,12:F3} | {CenterTorso_s,12:F3}\n");
                    LeftTorso_s = MaxStructureForLocation(mech, (int)ChassisLocations.LeftTorso) - defender.LeftTorsoStructure;
                    LeftTorso_a = MaxArmorForLocation(mech, (int)ArmorLocation.LeftTorso) + MaxArmorForLocation(mech, (int)ArmorLocation.LeftTorsoRear) - defender.LeftTorsoFrontArmor - defender.LeftTorsoRearArmor;
                    Log.Debug?.Write($"{ChassisLocations.LeftTorso.ToString(),-20} |  {LeftTorso_a,12:F3} | {LeftTorso_s,12:F3}\n");
                    RightTorso_s = MaxStructureForLocation(mech, (int)ChassisLocations.RightTorso) - defender.RightTorsoStructure;
                    RightTorso_a = MaxArmorForLocation(mech, (int)ArmorLocation.RightTorso) + MaxArmorForLocation(mech, (int)ArmorLocation.RightTorsoRear) - defender.RightTorsoFrontArmor - defender.RightTorsoRearArmor;
                    Log.Debug?.Write($"{ChassisLocations.RightTorso.ToString(),-20} |  {RightTorso_a,12:F3} | {RightTorso_s,12:F3}\n");
                    LeftLeg_s = MaxStructureForLocation(mech, (int)ChassisLocations.LeftLeg) - defender.LeftLegStructure;
                    LeftLeg_a = MaxArmorForLocation(mech, (int)ArmorLocation.LeftLeg) - defender.LeftLegArmor;
                    Log.Debug?.Write($"{ChassisLocations.LeftLeg.ToString(),-20} |  {LeftLeg_a,12:F3} | {LeftLeg_s,12:F3}\n");
                    RightLeg_s = MaxStructureForLocation(mech, (int)ChassisLocations.RightLeg) - defender.RightLegStructure;
                    RightLeg_a = MaxArmorForLocation(mech, (int)ArmorLocation.RightLeg) - defender.RightLegArmor;
                    Log.Debug?.Write($"{ChassisLocations.RightLeg.ToString(),-20} |  {RightLeg_a,12:F3} | {RightLeg_s,12:F3}\n");
                    LeftArm_s = MaxStructureForLocation(mech, (int)ChassisLocations.LeftArm) - defender.LeftArmStructure;
                    LeftArm_a = MaxArmorForLocation(mech, (int)ArmorLocation.LeftArm) - defender.LeftArmArmor;
                    Log.Debug?.Write($"{ChassisLocations.LeftArm.ToString(),-20} |  {LeftArm_a,12:F3} | {LeftArm_s,12:F3}\n");
                    RightArm_s = MaxStructureForLocation(mech, (int)ChassisLocations.RightArm) - defender.RightArmStructure;
                    RightArm_a = MaxArmorForLocation(mech, (int)ArmorLocation.RightArm) - defender.RightArmArmor;
                    Log.Debug?.Write($"{ChassisLocations.RightArm.ToString(),-20} |  {RightArm_a,12:F3} | {RightArm_s,12:F3}\n");

                    Log.Debug?.Write($"{ChassisLocations.Torso.ToString(),-20} |  {CenterTorso_a + LeftTorso_a + RightTorso_a,12:F3} | {CenterTorso_s + LeftTorso_s + RightTorso_s,12:F3}\n");
                    Log.Debug?.Write($"{ChassisLocations.Legs.ToString(),-20} |  {LeftLeg_a + RightLeg_a,12:F3} | { LeftLeg_s + RightLeg_s,12:F3}\n");
                    Log.Debug?.Write($"{ChassisLocations.Arms.ToString(),-20} |  {LeftArm_a + RightArm_a,12:F3} | { LeftArm_s + RightArm_s,12:F3}\n");
                    Log.Debug?.Write($"{ChassisLocations.All.ToString(),-20} |  {CenterTorso_a + LeftTorso_a + RightTorso_a + LeftLeg_a + RightLeg_a + LeftArm_a + RightArm_a,12:F3} | {CenterTorso_s + LeftTorso_s + RightTorso_s + LeftLeg_s + RightLeg_s + LeftArm_s + RightArm_s,12:F3}\n");
                    gotdamagevalues = true;
                }
                // we stop trying to activate the component if any of these return true i.e activated;
                //ignore the damage from this hit and use the current damage levels.
                //Not handling ChassisLocation MainBody as i dont know what locations it covers.
                if (
                    ActivatableComponent.ActivateOnDamage(component, Head_a, Head_s, ChassisLocations.Head) ||
                    ActivatableComponent.ActivateOnDamage(component, CenterTorso_a, CenterTorso_s, ChassisLocations.CenterTorso) ||
                    ActivatableComponent.ActivateOnDamage(component, LeftTorso_a, LeftTorso_s, ChassisLocations.LeftTorso) ||
                    ActivatableComponent.ActivateOnDamage(component, RightTorso_a, RightTorso_s, ChassisLocations.RightTorso) ||
                    ActivatableComponent.ActivateOnDamage(component, LeftLeg_a, LeftLeg_s, ChassisLocations.LeftLeg) ||
                    ActivatableComponent.ActivateOnDamage(component, RightLeg_a, RightLeg_s, ChassisLocations.RightLeg) ||
                    ActivatableComponent.ActivateOnDamage(component, LeftArm_a, LeftArm_s, ChassisLocations.LeftArm) ||
                    ActivatableComponent.ActivateOnDamage(component, RightArm_a, RightArm_s, ChassisLocations.RightArm) ||
                    ActivatableComponent.ActivateOnDamage(component, CenterTorso_a + LeftTorso_a + RightTorso_a, CenterTorso_s + LeftTorso_s + RightTorso_s, ChassisLocations.Torso) ||
                    ActivatableComponent.ActivateOnDamage(component, LeftLeg_a + RightLeg_a, LeftLeg_s + RightLeg_s, ChassisLocations.Legs) ||
                    ActivatableComponent.ActivateOnDamage(component, LeftArm_a + RightArm_a, LeftArm_s + RightArm_s, ChassisLocations.Arms) ||
                    ActivatableComponent.ActivateOnDamage(component, CenterTorso_a + LeftTorso_a + RightTorso_a + LeftLeg_a + RightLeg_a + LeftArm_a + RightArm_a, CenterTorso_s + LeftTorso_s + RightTorso_s + LeftLeg_s + RightLeg_s + LeftArm_s + RightArm_s, ChassisLocations.All)
                    )
                {
                    continue;
                }
            }
        }
        public void commitDamage()
        {
            if (owner.IsDead || owner.IsFlaggedForDeath || owner.IsShutDown)
            {
                Clear(); return;
            }
            if ((thresholdHeat < Core.Epsilon) && (thresholdStability < Core.Epsilon) &&
                (armorDamgeLocationThreshold.Count == 0) && (structureDamgeLocationThreshold.Count == 0))
            {
                Clear(); return;
            }
            ;
            Mech    mech    = owner as Mech;
            Vehicle vehicle = owner as Vehicle;

            foreach (MechComponent component in owner.allComponents)
            {
                if (component.IsFunctional == false)
                {
                    continue;
                }
                if (owner.StructureForLocation(component.Location) < Core.Epsilon)
                {
                    continue;
                }
                ActivatableComponent tactivatable = component.componentDef.GetComponent <ActivatableComponent>();
                if (tactivatable == null)
                {
                    continue;
                }
                if (ActivatableComponent.canBeDamageActivated(component) == false)
                {
                    continue;
                }
                ;
                if (ActivatableComponent.isOutOfCharges(component))
                {
                    continue;
                }
                if (component.isActive())
                {
                    continue;
                }
                bool activate = false;
                if (tactivatable.AutoActivateOnIncomingHeat > Core.Epsilon)
                {
                    switch (tactivatable.incomingHeatActivationType)
                    {
                    case DamageActivationType.Threshhold: activate = tactivatable.AutoActivateOnIncomingHeat < thresholdHeat; break;

                    case DamageActivationType.Single: activate = tactivatable.AutoActivateOnIncomingHeat < highestHeat; break;

                    case DamageActivationType.Level: activate = tactivatable.AutoActivateOnIncomingHeat < (mech != null?thresholdHeat / mech.MaxHeat:0f); break;
                    }
                }
                if (activate)
                {
                    ActivatableComponent.activateComponent(component, true, false); continue;
                }
                HashSet <int> sensibleLocations = getSensibleLocations(component);
                foreach (int location in sensibleLocations)
                {
                    float maxArmor        = armorLocationMax.ContainsKey(location)?armorLocationMax[location]:1f;
                    float maxStruct       = structureLocaltionMax.ContainsKey(location) ? structureLocaltionMax[location] : 1f;
                    float thresholdArmor  = structureDamgeLocationThreshold.ContainsKey(location) ? structureDamgeLocationThreshold[location] : 0f;
                    float thresholdStruct = structureDamgeLocationThreshold.ContainsKey(location) ? structureDamgeLocationThreshold[location] : 0f;
                    float singleArmor     = armorDamageLocationHighest.ContainsKey(location) ? armorDamageLocationHighest[location] : 0f;
                    float singleStruct    = structureDamageLocationHighest.ContainsKey(location) ? structureDamageLocationHighest[location] : 0f;
                    if (tactivatable.AutoActivateOnArmorDamage > Core.Epsilon)
                    {
                        switch (tactivatable.damageActivationType)
                        {
                        case DamageActivationType.Threshhold: activate = tactivatable.AutoActivateOnArmorDamage < thresholdArmor; break;

                        case DamageActivationType.Single: activate = tactivatable.AutoActivateOnArmorDamage < singleArmor; break;

                        case DamageActivationType.Level: activate = tactivatable.AutoActivateOnArmorDamage < thresholdArmor / maxArmor; break;
                        }
                        if (activate)
                        {
                            break;
                        }
                    }
                    if (tactivatable.AutoActivateOnStructureDamage > Core.Epsilon)
                    {
                        switch (tactivatable.damageActivationType)
                        {
                        case DamageActivationType.Threshhold: activate = tactivatable.AutoActivateOnStructureDamage < thresholdStruct; break;

                        case DamageActivationType.Single: activate = tactivatable.AutoActivateOnStructureDamage < singleStruct; break;

                        case DamageActivationType.Level: activate = tactivatable.AutoActivateOnStructureDamage < thresholdStruct / maxStruct; break;
                        }
                        if (activate)
                        {
                            break;
                        }
                    }
                }
                if (activate)
                {
                    ActivatableComponent.activateComponent(component, true, false); continue;
                }
            }
            Clear();
        }
Esempio n. 13
0
 void Start()
 {
     _activatableComponent = GetComponent <ActivatableComponent>();
     _rendererComponent    = GetComponent <Renderer>();
 }
Esempio n. 14
0
 void Start()
 {
     _activatableComponent = GetComponent<ActivatableComponent>();
     _rendererComponent = GetComponent<Renderer>();
 }