예제 #1
0
        void OnStartClientInternal()
        {
            GameObject vehicleGo = NetManager.GetNetworkObjectById(m_net_vehicleNetId);

            if (null == vehicleGo)
            {
                // this should only happen when vehicle has been destroyed before client connected, but it's detached parts are still alive
                // load vehicle's model, and attach it's frames to dummy object, and detach a frame from that dummy object



                VehicleDef def = Item.GetDefinitionOrThrow <VehicleDef>(m_net_vehicleModelId);

                int[] colors = VehicleController.DeserializeColors(m_net_vehicleColors);

                var geometryParts = Vehicle.LoadGeometryParts(def);


                VehicleInfo vehicleInfo;
                if (s_dummyObjectsPerVehicle.TryGetValue(m_net_vehicleNetId, out vehicleInfo))
                {
                    // we already created dummy object for this vehicle
                    vehicleInfo.numReferences++;
                }
                else
                {
                    // need to create dummy object for this vehicle, and attach all vehicle's frames to it
                    Transform transformDummy = new GameObject($"{def.GameName}_detached_part_{m_net_frameName}").transform;
                    vehicleInfo        = new VehicleInfo();
                    vehicleInfo.frames = geometryParts.AttachFrames(transformDummy, Importing.Conversion.MaterialFlags.Vehicle);
                    SetColors(vehicleInfo.frames, colors);
                    vehicleInfo.numReferences = 1;
                    s_dummyObjectsPerVehicle.Add(m_net_vehicleNetId, vehicleInfo);
                }

                m_isReferencingFrame = true;

                Frame frame = vehicleInfo.frames.FirstOrDefault(f => f.gameObject.name == m_net_frameName);
                if (null == frame)
                {
                    throw new System.Exception($"Failed to find frame by name {m_net_frameName}");
                }

                // detach frame from dummy object
                Vehicle.DetachFrameFromTransformDuringExplosion(vehicleInfo.frames.transform, frame, m_net_mass, this.gameObject, m_net_vehicleNetId, m_net_vehicleModelId, colors);
            }
            else
            {
                Vehicle vehicle = vehicleGo.GetComponentOrThrow <Vehicle>();
                vehicle.DetachFrameDuringExplosion(m_net_frameName, m_net_mass, this.gameObject);
            }

            var rb = this.GetComponentInChildren <Rigidbody>();

            if (rb != null)
            {
                rb.interpolation = RigidbodyInterpolation.Interpolate;
            }
            this.NetworkRigidBody.Rigidbody = rb;
        }
예제 #2
0
        private Vehicle CreatePathFindingVehicle()
        {
            GameInstance    game        = UnityGameInstance.BattleTechGame;
            CombatGameState combatState = game.Combat;
            string          spawnerId   = Guid.NewGuid().ToString();
            string          uniqueId    = $"{spawnerId}.9999999998";

            HeraldryDef heraldryDef = null;

            combatState.DataManager.Heraldries.TryGet(HeraldryDef.HeraldyrDef_SinglePlayerSkirmishPlayer1, out heraldryDef);

            VehicleDef vehicleDef = null;

            combatState.DataManager.VehicleDefs.TryGet("vehicledef_DEMOLISHER", out vehicleDef);

            PilotDef pilotDef = null;

            combatState.DataManager.PilotDefs.TryGet("pilot_default", out pilotDef);
            Vehicle vehicle = new Vehicle(vehicleDef, pilotDef, new TagSet(), uniqueId, combatState, spawnerId, heraldryDef);

            string teamId = TeamUtils.GetTeamGuid("NeutralToAll");
            Team   team   = UnityGameInstance.BattleTechGame.Combat.ItemRegistry.GetItemByGUID <Team>(teamId);

            AccessTools.Field(typeof(AbstractActor), "_team").SetValue(vehicle, team);
            AccessTools.Field(typeof(AbstractActor), "_teamId").SetValue(vehicle, teamId);

            return(vehicle);
        }
예제 #3
0
 public static Vector3 Get(VehicleDef def)
 {
     return(Get(
                identifier: def.Description.Id,
                tags: def.VehicleTags,
                type: typeof(Vehicle),
                prefab: def.Chassis.PrefabBase));
 }
 private static void AddVechicleToSalvage(VehicleDef vechicle, ContractHelper contract, SimGameState simgame)
 {
     foreach (var component in vechicle.Inventory)
     {
         if (component.DamageLevel != ComponentDamageLevel.Destroyed)
         {
             contract.AddComponentToPotentialSalvage(component.Def, component.DamageLevel, true);
         }
     }
 }
예제 #5
0
 public static string getOriginal(this VehicleDef def)
 {
     if (originals.TryGetValue(def.GetType(), out Dictionary <string, string> origs) == false)
     {
         return(def.ToJSON());
     }
     if (origs.TryGetValue(def.Description.Id, out string result) == false)
     {
         return(def.ToJSON());
     }
     return(result);
 }
예제 #6
0
 public static void setOriginal(this VehicleDef def, string json)
 {
     if (originals.TryGetValue(def.GetType(), out Dictionary <string, string> origs) == false)
     {
         origs = new Dictionary <string, string>();
         originals.Add(def.GetType(), origs);
     }
     if (origs.ContainsKey(def.Description.Id))
     {
         origs[def.Description.Id] = json;
     }
     else
     {
         origs.Add(def.Description.Id, json);
     }
 }
        public static AbstractActor SpawnAmbushVehicle(Team team, Lance ambushLance, Vector3 ambushOrigin, Vector3 spawnPos, Quaternion spawnRot)
        {
            // Randomly determine one of the spawnpairs from the current ambushdef
            List <VehicleAndPilotDef> shuffledSpawns = new List <VehicleAndPilotDef>();

            shuffledSpawns.AddRange(ModState.VehicleAmbushDefForContract.SpawnPool);
            shuffledSpawns.Shuffle();
            VehicleAndPilotDef ambushDef = shuffledSpawns[0];

            PilotDef   pilotDef   = ModState.Combat.DataManager.PilotDefs.Get(ambushDef.PilotDefId);
            VehicleDef vehicleDef = ModState.Combat.DataManager.VehicleDefs.Get(ambushDef.VehicleDefId);

            vehicleDef.Refresh();

            // Adjust position so we don't spawn in the ground.
            spawnPos.y = ModState.Combat.MapMetaData.GetLerpedHeightAt(spawnPos, true);

            // Rotate to face the ambush origin
            Vector3    spawnDirection = Vector3.RotateTowards(spawnRot.eulerAngles, ambushOrigin, 1f, 0f);
            Quaternion spawnRotation  = Quaternion.LookRotation(spawnDirection);

            Vehicle vehicle = ActorFactory.CreateVehicle(vehicleDef, pilotDef, team.EncounterTags, ModState.Combat, team.GetNextSupportUnitGuid(), "", null);

            vehicle.Init(spawnPos, spawnRotation.eulerAngles.y, true);
            vehicle.InitGameRep(null);
            Mod.Log.Debug?.Write($"Spawned vehicle {CombatantUtils.Label(vehicle)} at position: {spawnPos}");

            if (vehicle == null)
            {
                Mod.Log.Error?.Write($"Failed to spawn vehicleDefId: {ambushDef.VehicleDefId} / pilotDefId: {ambushDef.PilotDefId} !");
            }

            Mod.Log.Debug?.Write($" Spawned ambush vehicle, adding to team: {team} and lance: {ambushLance}");
            team.AddUnit(vehicle);
            vehicle.AddToTeam(team);
            vehicle.AddToLance(ambushLance);

            vehicle.BehaviorTree = BehaviorTreeFactory.MakeBehaviorTree(ModState.Combat.BattleTechGame, vehicle, BehaviorTreeIDEnum.CoreAITree);
            Mod.Log.Debug?.Write("Enabled vehicle behavior tree");

            UnitSpawnedMessage message = new UnitSpawnedMessage("CJ_VEHICLE", vehicle.GUID);

            ModState.Combat.MessageCenter.PublishMessage(message);

            return(vehicle);
        }
예제 #8
0
        private static DumperDataEntry FillVehicle(VehicleDef v)
        {
            DumperDataEntry d = new DumperDataEntry();

            d.DataTxt    = new string[3];
            d.Sort       = $"{v.Chassis.Tonnage,3}_{TryLoc(v.Description.Name)}";
            d.DataTxt[0] = v.Chassis.Tonnage + "t " + v.Description.Name;
            d.DataTxt[1] = v.Chassis.MovementCapDef.MaxWalkDistance + "";
            Dictionary <string, int> eq = new Dictionary <string, int>();

            foreach (VehicleComponentRef c in v.Inventory)
            {
                if (c.ComponentDefType == ComponentType.Weapon)
                {
                    WeaponDef wep = c.Def as WeaponDef;
                    if (wep != null && wep.WeaponCategoryValue.IsMelee || wep.WeaponSubType == WeaponSubType.AIImaginary || wep.WeaponEffectID.Contains("WeaponEffect-Artillery"))
                    {
                        continue;
                    }
                }
                string key = c.Def.Description.Id;
                if (eq.ContainsKey(key))
                {
                    eq[key]++;
                }
                else
                {
                    eq.Add(key, 1);
                }
            }
            string txteq = "";

            foreach (string key in eq.Keys.OrderBy((k) => k))
            {
                if (!string.IsNullOrEmpty(txteq))
                {
                    txteq += ",";
                }
                txteq += key + ":" + eq[key];
            }
            d.DataTxt[2] = txteq;
            d.DataCsv    = v.Chassis.Tonnage + ";" + TryLoc(v.Description.Name) + ";" + v.Chassis.MovementCapDef.MaxWalkDistance + ";" + v.Description.Id + ";" + v.Chassis.Description.Id + ";" + txteq;
            return(d);
        }
예제 #9
0
        private Vehicle CreatePathFindingVehicle()
        {
            GameInstance    game        = UnityGameInstance.BattleTechGame;
            CombatGameState combatState = game.Combat;
            string          spawnerId   = Guid.NewGuid().ToString();
            string          uniqueId    = $"{spawnerId}.9999999998";

            HeraldryDef heraldryDef = null;

            combatState.DataManager.Heraldries.TryGet(HeraldryDef.HeraldyrDef_SinglePlayerSkirmishPlayer1, out heraldryDef);

            VehicleDef vehicleDef = null;

            combatState.DataManager.VehicleDefs.TryGet("vehicledef_DEMOLISHER", out vehicleDef);

            PilotDef pilotDef = null;

            combatState.DataManager.PilotDefs.TryGet("pilot_default", out pilotDef);
            Vehicle vehicle = new Vehicle(vehicleDef, pilotDef, new TagSet(), uniqueId, combatState, spawnerId, heraldryDef);

            return(vehicle);
        }
예제 #10
0
        public static Graphic GhostGraphicFor(this VehicleDef vehicleDef, VehicleTurret cannon, Color ghostColor)
        {
            int num = 0;

            num = Gen.HashCombine(num, vehicleDef);
            num = Gen.HashCombine(num, cannon);
            num = Gen.HashCombineStruct(num, ghostColor);
            if (!cachedGhostGraphics.TryGetValue(num, out Graphic graphic))
            {
                cannon.ResolveCannonGraphics(vehicleDef, true);
                graphic = cannon.CannonGraphic;

                GraphicData graphicData = new GraphicData();
                AccessTools.Method(typeof(GraphicData), "Init").Invoke(graphicData, new object[] { });
                graphicData.CopyFrom(graphic.data);
                graphicData.shadowData = null;

                graphic = GraphicDatabase.Get(graphic.GetType(), graphic.path, ShaderTypeDefOf.EdgeDetect.Shader, graphic.drawSize, ghostColor, Color.white, graphicData, null);

                cachedGhostGraphics.Add(num, graphic);
            }
            return(graphic);
        }
예제 #11
0
        public static void DrawGhostCannonTextures(this VehicleDef vehicleDef, Vector3 loc, Rot8 rot, Color ghostCol)
        {
            if (vehicleDef.GetSortedCompProperties <CompProperties_Cannons>() is CompProperties_Cannons props)
            {
                foreach (VehicleTurret cannon in props.turrets)
                {
                    if (cannon.NoGraphic)
                    {
                        continue;
                    }

                    cannon.ResolveCannonGraphics(vehicleDef);

                    try
                    {
                        Graphic graphic = vehicleDef.GhostGraphicFor(cannon, ghostCol);

                        Vector3 topVectorRotation = new Vector3(loc.x, 1f, loc.y).RotatedBy(0f);
                        float   locationRotation  = cannon.defaultAngleRotated + rot.AsAngle;
                        if (cannon.attachedTo != null)
                        {
                            locationRotation += cannon.attachedTo.defaultAngleRotated + rot.AsAngle;
                        }
                        Pair <float, float> drawOffset = RenderHelper.ShipDrawOffset(Rot8.North, cannon.turretRenderLocation.x, cannon.turretRenderLocation.y, out Pair <float, float> rotOffset1, locationRotation, cannon.attachedTo);

                        Vector3 topVectorLocation = new Vector3(loc.x + drawOffset.First + rotOffset1.First, loc.y + cannon.drawLayer, loc.z + drawOffset.Second + rotOffset1.Second);
                        Mesh    cannonMesh        = graphic.MeshAt(Rot4.North);

                        Graphics.DrawMesh(cannonMesh, topVectorLocation, locationRotation.ToQuat(), graphic.MatAt(Rot4.North), 0);
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"Failed to render Cannon=\"{cannon.turretDef.defName}\" for VehicleDef=\"{vehicleDef.defName}\", Exception: {ex.Message}");
                    }
                }
            }
        }
예제 #12
0
        static bool Prefix(Contract __instance, List <UnitResult> enemyMechs, List <VehicleDef> enemyVehicles, List <UnitResult> lostUnits, bool logResults = false)
        {
            try {
                Settings settings = Helper.LoadSettings();
                if (__instance.BattleTechGame.Simulation == null)
                {
                    return(false);
                }
                ReflectionHelper.SetPrivateField(__instance, "finalPotentialSalvage", new List <SalvageDef>());
                ReflectionHelper.InvokePrivateMethode(__instance, "set_SalvagedChassis", new object[] { new List <SalvageDef>() });
                ReflectionHelper.InvokePrivateMethode(__instance, "set_LostMechs", new object[] { new List <MechDef>() });
                ReflectionHelper.InvokePrivateMethode(__instance, "set_SalvageResults", new object[] { new List <SalvageDef>() });
                SimGameState     simulation = __instance.BattleTechGame.Simulation;
                SimGameConstants constants  = simulation.Constants;
                for (int i = 0; i < lostUnits.Count; i++)
                {
                    MechDef mech  = lostUnits[i].mech;
                    Pilot   pilot = lostUnits[i].pilot;
                    float   num   = simulation.NetworkRandom.Float(0f, 1f);
                    float   ejectRecoveryBonus         = 0;
                    float   incapacitatedRecoveryBonus = 0;
                    bool    notDestroyed = !mech.IsLocationDestroyed(ChassisLocations.CenterTorso) && !mech.IsLocationDestroyed(ChassisLocations.Head) &&
                                           (!mech.IsLocationDestroyed(ChassisLocations.LeftLeg) && !mech.IsLocationDestroyed(ChassisLocations.RightLeg));
                    if (pilot.HasEjected)
                    {
                        ejectRecoveryBonus = settings.ejectRecoveryBonus;
                    }
                    else if (mech.IsLocationDestroyed(ChassisLocations.Head) || (pilot.IsIncapacitated && notDestroyed))
                    {
                        incapacitatedRecoveryBonus = settings.incapacitatedRecoveryBonus;
                    }
                    bool flag = num <= constants.Salvage.DestroyedMechRecoveryChance + ejectRecoveryBonus + incapacitatedRecoveryBonus;

                    // keep mech if the roll is good enough, or if CT + head + legs are intact and the pilot isn't incapacitated
                    if (flag || (notDestroyed && !pilot.IsIncapacitated))
                    {
                        lostUnits[i].mechLost = false;
                    }
                    else
                    {
                        lostUnits[i].mechLost = true;

                        float mechparts = simulation.Constants.Story.DefaultMechPartMax;
                        if (mech.IsLocationDestroyed(ChassisLocations.CenterTorso))
                        {
                            mechparts = settings.centerTorsoSalvageValue;
                        }
                        else
                        {
                            if (mech.IsLocationDestroyed(ChassisLocations.LeftArm))
                            {
                                mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5);
                            }
                            if (mech.IsLocationDestroyed(ChassisLocations.RightArm))
                            {
                                mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5);
                            }
                            if (mech.IsLocationDestroyed(ChassisLocations.LeftLeg))
                            {
                                mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5);
                            }
                            if (mech.IsLocationDestroyed(ChassisLocations.RightLeg))
                            {
                                mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5);
                            }
                        }


                        SalvageDef def = (SalvageDef)ReflectionHelper.InvokePrivateMethode(__instance, "CreateMechPart", new object[] { constants, mech });
                        if (settings.ownMechsForFree)
                        {
                            for (int s = 0; s < Mathf.RoundToInt(mechparts); s++)
                            {
                                __instance.SalvageResults.Add(def);
                            }
                        }
                        else
                        {
                            List <SalvageDef> finalPotentialSalvage = (List <SalvageDef>)ReflectionHelper.GetPrivateField(__instance, "finalPotentialSalvage");
                            ReflectionHelper.InvokePrivateMethode(__instance, "CreateAndAddMechPart", new object[] { constants, mech, Mathf.RoundToInt(mechparts), finalPotentialSalvage });
                        }
                        if (settings.ownMechsForFree)
                        {
                            foreach (MechComponentRef mechComponentRef in mech.Inventory)
                            {
                                if (!mech.IsLocationDestroyed(mechComponentRef.MountedLocation) && mechComponentRef.DamageLevel != ComponentDamageLevel.Destroyed)
                                {
                                    ReflectionHelper.InvokePrivateMethode(__instance, "AddToFinalSalvage", new object[] { new SalvageDef {
                                                                                                                              MechComponentDef = mechComponentRef.Def,
                                                                                                                              Description      = new DescriptionDef(mechComponentRef.Def.Description),
                                                                                                                              RewardID         = __instance.GenerateRewardUID(),
                                                                                                                              Type             = SalvageDef.SalvageType.COMPONENT,
                                                                                                                              ComponentType    = mechComponentRef.Def.ComponentType,
                                                                                                                              Damaged          = false,
                                                                                                                              Count            = 1
                                                                                                                          } });
                                }
                            }
                        }
                        else
                        {
                            foreach (MechComponentRef mechComponentRef in mech.Inventory)
                            {
                                if (!mech.IsLocationDestroyed(mechComponentRef.MountedLocation) && mechComponentRef.DamageLevel != ComponentDamageLevel.Destroyed)
                                {
                                    List <SalvageDef> finalPotentialSalvage = (List <SalvageDef>)ReflectionHelper.GetPrivateField(__instance, "finalPotentialSalvage");
                                    ReflectionHelper.InvokePrivateMethode(__instance, "AddMechComponentToSalvage", new object[] { finalPotentialSalvage, mechComponentRef.Def, ComponentDamageLevel.Functional, false, constants, simulation.NetworkRandom, true });
                                }
                            }
                        }
                    }
                }
                int k = 0;
                while (k < enemyMechs.Count)
                {
                    MechDef           mech2                 = enemyMechs[k].mech;
                    Pilot             pilot                 = enemyMechs[k].pilot;
                    SalvageDef        salvageDef            = null;
                    bool              flag2                 = false;
                    bool              flag3                 = false;
                    List <SalvageDef> finalPotentialSalvage = (List <SalvageDef>)ReflectionHelper.GetPrivateField(__instance, "finalPotentialSalvage");

                    if (pilot.IsIncapacitated || mech2.IsDestroyed || mech2.Inventory.Any(cref => cref.Def != null && cref.Def.CriticalComponent && cref.DamageLevel == ComponentDamageLevel.Destroyed))
                    {
                        float mechparts = simulation.Constants.Story.DefaultMechPartMax;
                        if (mech2.IsLocationDestroyed(ChassisLocations.CenterTorso))
                        {
                            mechparts = settings.centerTorsoSalvageValue;
                        }
                        else
                        {
                            if (mech2.IsLocationDestroyed(ChassisLocations.LeftArm))
                            {
                                mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5);
                            }
                            if (mech2.IsLocationDestroyed(ChassisLocations.RightArm))
                            {
                                mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5);
                            }
                            if (mech2.IsLocationDestroyed(ChassisLocations.LeftLeg))
                            {
                                mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5);
                            }
                            if (mech2.IsLocationDestroyed(ChassisLocations.RightLeg))
                            {
                                mechparts -= (simulation.Constants.Story.DefaultMechPartMax / 5);
                            }
                        }

                        ReflectionHelper.InvokePrivateMethode(__instance, "CreateAndAddMechPart", new object[] { constants, mech2, Mathf.RoundToInt(mechparts), finalPotentialSalvage });
                        goto IL_2E4;
                    }
IL_4AB:
                    k++;
                    continue;
IL_2E4:
                    foreach (MechComponentRef mechComponentRef2 in mech2.Inventory)
                    {
                        if (!mech2.IsLocationDestroyed(mechComponentRef2.MountedLocation) && mechComponentRef2.DamageLevel != ComponentDamageLevel.Destroyed)
                        {
                            ReflectionHelper.InvokePrivateMethode(__instance, "AddMechComponentToSalvage", new object[] { finalPotentialSalvage, mechComponentRef2.Def, ComponentDamageLevel.Functional, false, constants, simulation.NetworkRandom, true });
                        }
                    }
                    if (flag3)
                    {
                        salvageDef             = new SalvageDef();
                        salvageDef.Type        = SalvageDef.SalvageType.CHASSIS;
                        salvageDef.Description = new DescriptionDef(mech2.Chassis.Description);
                        salvageDef.Count       = 1;
                        IEnumerator enumerator = Enum.GetValues(typeof(ChassisLocations)).GetEnumerator();
                        try {
                            while (enumerator.MoveNext())
                            {
                                object           obj = enumerator.Current;
                                ChassisLocations chassisLocations = (ChassisLocations)obj;
                                if (chassisLocations != ChassisLocations.None && chassisLocations != ChassisLocations.All && chassisLocations != ChassisLocations.Arms && chassisLocations != ChassisLocations.Legs && chassisLocations != ChassisLocations.Torso && chassisLocations != ChassisLocations.MainBody)
                                {
                                    salvageDef.ChassisLocations.Add(chassisLocations);
                                    salvageDef.ChassisStructure.Add(mech2.GetLocationLoadoutDef(chassisLocations).CurrentInternalStructure);
                                }
                            }
                        }
                        finally {
                            IDisposable disposable;
                            if ((disposable = (enumerator as IDisposable)) != null)
                            {
                                disposable.Dispose();
                            }
                        }
                        if (flag2)
                        {
                            for (int m = 0; m < salvageDef.ChassisLocations.Count; m++)
                            {
                                List <float> chassisStructure;
                                int          index;
                                (chassisStructure = salvageDef.ChassisStructure)[index = m] = chassisStructure[index] / 2f;
                            }
                        }
                        salvageDef.Weight = constants.Salvage.DefaultChassisWeight;
                        __instance.SalvagedChassis.Add(salvageDef);
                        goto IL_4AB;
                    }
                    goto IL_4AB;
                }
                for (int n = 0; n < enemyVehicles.Count; n++)
                {
                    VehicleDef        vehicleDef            = enemyVehicles[n];
                    List <SalvageDef> finalPotentialSalvage = (List <SalvageDef>)ReflectionHelper.GetPrivateField(__instance, "finalPotentialSalvage");
                    foreach (VehicleComponentRef vehicleComponentRef in vehicleDef.Inventory)
                    {
                        ReflectionHelper.InvokePrivateMethode(__instance, "AddMechComponentToSalvage", new object[] { finalPotentialSalvage, vehicleComponentRef.Def, ComponentDamageLevel.Functional, false, constants, simulation.NetworkRandom, true });
                    }
                }
                int   num2 = __instance.SalvagePotential;
                float num3 = constants.Salvage.VictorySalvageChance;
                float num4 = constants.Salvage.VictorySalvageLostPerMechDestroyed;
                if (__instance.State == Contract.ContractState.Failed)
                {
                    num3 = constants.Salvage.DefeatSalvageChance;
                    num4 = constants.Salvage.DefeatSalvageLostPerMechDestroyed;
                }
                else if (__instance.State == Contract.ContractState.Retreated)
                {
                    num3 = constants.Salvage.RetreatSalvageChance;
                    num4 = constants.Salvage.RetreatSalvageLostPerMechDestroyed;
                }
                float num5 = num3;
                float num6 = (float)num2 * __instance.PercentageContractSalvage;
                if (num2 > 0)
                {
                    num6 += (float)constants.Finances.ContractFloorSalvageBonus;
                }
                num3 = Mathf.Max(0f, num5 - num4 * (float)lostUnits.Count);
                int num7 = Mathf.FloorToInt(num6 * num3);
                if (num2 > 0)
                {
                    num2 += constants.Finances.ContractFloorSalvageBonus;
                }
                ReflectionHelper.InvokePrivateMethode(__instance, "set_FinalSalvageCount", new object[] { num7 });
                ReflectionHelper.InvokePrivateMethode(__instance, "set_FinalPrioritySalvageCount", new object[] { Mathf.FloorToInt((float)num7 * constants.Salvage.PrioritySalvageModifier) });

                return(false);
            }
            catch (Exception e) {
                Logger.LogError(e);
                return(false);
            }
        }
예제 #13
0
            public static bool Prefix(UnitSpawnPointGameLogic __instance, SpawnableUnit spawnableUnit, MechDef ___mechDefOverride, ref PilotDef ___pilotDefOverride, VehicleDef ___vehicleDefOverride, TurretDef ___turretDefOverride)
            {
                if (ModState.PlayerGetsAIMechs && __instance.team == TeamDefinition.Player1TeamDefinitionGuid && spawnableUnit.unitType == UnitType.Mech)
                {
                    ModInit.modLog.LogMessage(
                        $"PLAYER UNIT: First mech in AIMechVariants was {ModState.AIMechs.First().mechDef.Name} with count {ModState.AIMechs.First().count}");
                    var AIMechVariants = ModState.AIMechs.OrderBy(x => x.count).ToList();
                    ModInit.modLog.LogMessage(
                        $"PLAYER UNIT: Filtered to match mechdef IDs and reordered! First mech in AIMechVariants is now {AIMechVariants.First().mechDef.Name} with count {AIMechVariants.First().count}");
                    ModState.AIMechs.First().count += 1;
                    var newMechDef = AIMechVariants.FirstOrDefault()?.mechDef;
                    newMechDef.DependenciesLoaded(1000U);

                    ___mechDefOverride = newMechDef;
                    ModInit.modLog.LogMessage(
                        $"PLAYER UNIT: mechDefOverride set to {___mechDefOverride.Description.Id}");

                    ___pilotDefOverride = spawnableUnit.Pilot;
                    ModInit.modLog.LogMessage(
                        $"PLAYER UNIT: pilotDefOverride set to {___pilotDefOverride.Description.Id}");

                    __instance.pilotDefId = spawnableUnit.PilotId;
                    ModInit.modLog.LogMessage(
                        $"PLAYER UNIT: __instance.pilotDefId is {__instance.pilotDefId}, should be {___pilotDefOverride.Description.Id}");

                    __instance.mechDefId = newMechDef.Description.Id;
                    ModInit.modLog.LogMessage(
                        $"PLAYER UNIT: __instance.mechDefId is {__instance.mechDefId}, should be {___mechDefOverride.Description.Id}");

                    __instance.unitType     = spawnableUnit.unitType;
                    ___vehicleDefOverride   = spawnableUnit.VUnit;
                    ___turretDefOverride    = spawnableUnit.TUnit;
                    __instance.vehicleDefId = spawnableUnit.UnitId;
                    __instance.turretDefId  = spawnableUnit.UnitId;
                    return(false);
                }

                return(true);
            }
예제 #14
0
        public void    Load()
        {
            string modelName = "";
            string textDict  = "";

            if (modelLoadType == ModelLoadType.Weapon)
            {
                WeaponDef def = Item.GetDefinition <WeaponDef> (modelId);
                if (null == def)
                {
                    return;
                }
                modelName = def.ModelName;
                textDict  = def.TextureDictionaryName;
            }
            else if (modelLoadType == ModelLoadType.Ped)
            {
                PedestrianDef def = Item.GetDefinition <PedestrianDef> (modelId);
                if (null == def)
                {
                    return;
                }
                modelName = def.ModelName;
                textDict  = def.TextureDictionaryName;
            }
            else if (modelLoadType == ModelLoadType.Vehicle)
            {
                VehicleDef def = Item.GetDefinition <VehicleDef> (modelId);
                if (null == def)
                {
                    return;
                }
                modelName = def.ModelName;
                textDict  = def.TextureDictionaryName;
            }
            else
            {
                return;
            }

            var geoms = Geometry.Load(modelName, textDict);

            if (null == geoms)
            {
                return;
            }

            if (m_frameContainer != null)
            {
                Destroy(m_frameContainer.Root.gameObject);
                Destroy(m_frameContainer);
            }

            Transform tr = null == targetParent ? transform : targetParent;

            m_frameContainer = geoms.AttachFrames(tr, MaterialFlags.Default);

            m_currentModelId = modelId;
            m_currentTextureDictionaryName = textureDictionaryName;
            m_modelLoadType = modelLoadType;
        }