public static void CreateAndFireStreakTargetingLaser(AttackDirector.AttackSequence sequence, Weapon baseWeapon, out Vector3 floatieVector, bool hitsTarget = true) { //@ToDo: Make this work for turrets and vehicles too floatieVector = sequence.chosenTarget.CurrentPosition; AbstractActor actor = baseWeapon.parent; if (!(actor is Mech mech)) { return; } Logger.Debug($"[Utilities_CreateAndFireStreakTargetingLaser] {actor.DisplayName} prepares its targeting laser for weapon: {baseWeapon.Name}"); // Borrowed from AbstractActor.InitAbilities() WeaponDef weaponDef = actor.Combat.DataManager.WeaponDefs.Get(Fields.StreakTargetingLaserId); MechComponentRef mechComponentRef = new MechComponentRef(weaponDef.Description.Id, weaponDef.Description.Id + "_Reference", ComponentType.Weapon, (ChassisLocations)baseWeapon.Location, -1, ComponentDamageLevel.Functional, false); mechComponentRef.SetComponentDef(weaponDef); mechComponentRef.DataManager = actor.Combat.DataManager; mechComponentRef.RefreshComponentDef(); Weapon TargetingLaser = new Weapon(mech, actor.Combat, mechComponentRef, weaponDef.Description.Id + baseWeapon.GUID); TargetingLaser.Init(); TargetingLaser.InitStats(); //Logger.Debug($"[Utilities_CreateAndFireStreakTargetingLaser] TargetingLaser.Name: {TargetingLaser.Name}, TargetingLaser.uid: {TargetingLaser.uid}, TargetingLaser.GUID: {TargetingLaser.GUID}"); // Borrowed from Mech.InitGameRep() List <string> usedPrefabNames = new List <string>(); TargetingLaser.baseComponentRef.prefabName = MechHardpointRules.GetComponentPrefabName(mech.MechDef.Chassis.HardpointDataDef, TargetingLaser.baseComponentRef, mech.MechDef.Chassis.PrefabBase, TargetingLaser.mechComponentRef.MountedLocation.ToString().ToLower(), ref usedPrefabNames); TargetingLaser.baseComponentRef.hasPrefabName = true; if (!string.IsNullOrEmpty(TargetingLaser.baseComponentRef.prefabName)) { Transform attachTransform = mech.GetAttachTransform(TargetingLaser.mechComponentRef.MountedLocation); TargetingLaser.InitGameRep(TargetingLaser.baseComponentRef.prefabName, attachTransform, actor.LogDisplayName); mech.GameRep.weaponReps.Add(TargetingLaser.weaponRep); // Needed? (Probably only the visuals on the mech, we only need the "effect origin") string componentMountingPointPrefabName = MechHardpointRules.GetComponentMountingPointPrefabName(mech.MechDef, TargetingLaser.mechComponentRef); if (!string.IsNullOrEmpty(componentMountingPointPrefabName)) { WeaponRepresentation component = actor.Combat.DataManager.PooledInstantiate(componentMountingPointPrefabName, BattleTechResourceType.Prefab, null, null, null).GetComponent <WeaponRepresentation>(); component.Init(mech, attachTransform, true, actor.LogDisplayName, TargetingLaser.Location); mech.GameRep.weaponReps.Add(component); } } // Hide targeting laser visually (Otherwise could disturb other weaponReps in the same ChassisLocation) TargetingLaser.weaponRep.OnPlayerVisibilityChanged(VisibilityLevel.None); // Generate WeaponHitInfo for targeting laser float randomFloat = UnityEngine.Random.Range(0f, 1f); WeaponHitInfo targetingLaserHitInfo = default(WeaponHitInfo); targetingLaserHitInfo.attackerId = sequence.attacker.GUID; targetingLaserHitInfo.targetId = sequence.chosenTarget.GUID; targetingLaserHitInfo.numberOfShots = 1; //targetingLaserHitInfo.stackItemUID = sequence.stackItemUID; //targetingLaserHitInfo.attackSequenceId = sequence.id; //targetingLaserHitInfo.attackGroupIndex = 0; //targetingLaserHitInfo.attackWeaponIndex = 0; targetingLaserHitInfo.stackItemUID = -1; targetingLaserHitInfo.attackSequenceId = -1; targetingLaserHitInfo.attackGroupIndex = -1; targetingLaserHitInfo.attackWeaponIndex = -1; targetingLaserHitInfo.toHitRolls = new float[1]; targetingLaserHitInfo.locationRolls = new float[] { randomFloat }; targetingLaserHitInfo.dodgeRolls = new float[1]; targetingLaserHitInfo.dodgeSuccesses = new bool[1]; targetingLaserHitInfo.hitLocations = new int[1]; targetingLaserHitInfo.hitPositions = new Vector3[1]; targetingLaserHitInfo.hitVariance = new int[1]; targetingLaserHitInfo.hitQualities = new AttackImpactQuality[1]; targetingLaserHitInfo.secondaryTargetIds = new string[1]; targetingLaserHitInfo.secondaryHitLocations = new int[1]; targetingLaserHitInfo.attackDirections = new AttackDirection[1]; float calledShotBonusMultiplier = sequence.attacker.CalledShotBonusMultiplier; if (hitsTarget) { Logger.Info($"[Utilities_CreateAndFireStreakTargetingLaser] targetingLaserHitInfo.locationRolls[0]: {targetingLaserHitInfo.locationRolls[0]}"); targetingLaserHitInfo.hitLocations[0] = sequence.chosenTarget.GetHitLocation(sequence.attacker, sequence.attackPosition, targetingLaserHitInfo.locationRolls[0], sequence.calledShotLocation, calledShotBonusMultiplier); targetingLaserHitInfo.hitPositions[0] = sequence.chosenTarget.GetImpactPosition(sequence.attacker, sequence.attackPosition, TargetingLaser, ref targetingLaserHitInfo.hitLocations[0], ref targetingLaserHitInfo.attackDirections[0], ref targetingLaserHitInfo.secondaryTargetIds[0], ref targetingLaserHitInfo.secondaryHitLocations[0]); floatieVector = targetingLaserHitInfo.hitPositions[0]; } else { targetingLaserHitInfo.hitLocations[0] = 0; // None targetingLaserHitInfo.hitPositions[0] = sequence.chosenTarget.GetImpactPosition(sequence.attacker, sequence.attackPosition, TargetingLaser, ref targetingLaserHitInfo.hitLocations[0], ref targetingLaserHitInfo.attackDirections[0], ref targetingLaserHitInfo.secondaryTargetIds[0], ref targetingLaserHitInfo.secondaryHitLocations[0]); floatieVector = sequence.chosenTarget.TargetPosition + UnityEngine.Random.insideUnitSphere * 5f; } Logger.Info($"[Utilities_CreateAndFireStreakTargetingLaser] targetingLaserHitInfo.hitLocations[0]: {targetingLaserHitInfo.hitLocations[0]}"); Logger.Info($"[Utilities_CreateAndFireStreakTargetingLaser] floatieVector: {floatieVector}"); // Check existence, adjust effects and fire if (TargetingLaser.weaponRep != null && TargetingLaser.weaponRep.HasWeaponEffect) { if (TargetingLaser.weaponRep.WeaponEffect is LaserEffect LaserEffect) { // Disable sound for this effect LaserEffect.beamStartSFX = ""; LaserEffect.beamStopSFX = ""; LaserEffect.pulseSFX = ""; LaserEffect.weaponImpactType = AudioSwitch_weapon_type.machinegun; // Not noticable } // Ping (Could be used for Streak LRMs) //RadarPingIndicator.Instance.Ping(sequence.chosenTarget.CurrentPosition); // Fire TargetingLaser.weaponRep.PlayWeaponEffect(targetingLaserHitInfo); Logger.Debug($"[Utilities_CreateAndFireStreakTargetingLaser] {actor.DisplayName} fired its targeting laser({Fields.StreakTargetingLaserId})"); } }
public override void LoadContent(ContentManager content) { // Choose color if (player.PlayerIndex == PlayerIndex.One) // Green this.color = new Color(0, 255, 0); else if (player.PlayerIndex == PlayerIndex.Two) // Blue this.color = new Color(0, 255, 255); else if (player.PlayerIndex == PlayerIndex.Three) // Yellow this.color = new Color(255, 255, 0); else if (player.PlayerIndex == PlayerIndex.Four) // Pink this.color = new Color(255, 200, 255); spriteSheet = new SpriteSheet(); spriteSheet.Sheet = content.Load<Texture2D>("animationsheet"); spriteSheet.Map = content.Load<Dictionary<string, Rectangle>>("animationsheetmap"); spriteEffects = SpriteEffects.None; float spritePaddingScale = 1f; // Load animations: // idle animation int idleFrameTime = 120; idleAnimation = new Animation(); idleAnimation.Initialize(spriteSheet, Vector2.Zero, idleAnimationName, idleFrameTime, this.color, spritePaddingScale, spriteEffects, true); idleAnimation.LayerDepth = playerLayerDepth; // make this the current animation currentAnimation = idleAnimation; // idle frozen animation int idleFrozenFrameTime = 0; idleFrozenAnimation = new Animation(); idleFrozenAnimation.Initialize(spriteSheet, Vector2.Zero, idleAnimationName, idleFrozenFrameTime, this.color, spritePaddingScale, spriteEffects, false); idleFrozenAnimation.LayerDepth = playerLayerDepth; // idle shoot animation int idleShootFrameTime = 30; idleShootAnimation = new Animation(); idleShootAnimation.Initialize(spriteSheet, Vector2.Zero, idleShootAnimationName, idleShootFrameTime, this.color, spritePaddingScale, spriteEffects, false); idleShootAnimation.LayerDepth = playerLayerDepth; // running animation int runFrameTime = 25; runAnimation = new Animation(); runAnimation.Initialize(spriteSheet, Vector2.Zero, runAnimationName, runFrameTime, this.color, spritePaddingScale, spriteEffects, true); runAnimation.LayerDepth = playerLayerDepth; // dash animation int dashFrameTime = 0; dashAnimation = new Animation(); dashAnimation.Initialize(spriteSheet, Vector2.Zero, dashAnimationName, dashFrameTime, this.color, spritePaddingScale, spriteEffects, false); dashAnimation.LayerDepth = playerLayerDepth; // jumping animation int jumpFrameTime = 120; jumpAnimation = new Animation(); jumpAnimation.Initialize(spriteSheet, Vector2.Zero, jumpAnimationName, jumpFrameTime, this.color, spritePaddingScale, spriteEffects, false); jumpAnimation.LayerDepth = playerLayerDepth; // falling animation int fallFrameTime = 120; fallAnimation = new Animation(); fallAnimation.Initialize(spriteSheet, Vector2.Zero, fallAnimationName, fallFrameTime, this.color, spritePaddingScale, spriteEffects, false); fallAnimation.LayerDepth = playerLayerDepth; // gun weapon animations int gunFrameTime = 30; int gunShotFrameTime = 30; gunRepresentation = new WeaponRepresentation<PlayerWeapon>(player, player.Gun, new Vector2(gunOffsetX, gunOffsetY)); gunRepresentation.InitializeAnimation(spriteSheet, Vector2.Zero, gunAnimationName, gunFrameTime, this.color, 1, spriteEffects, false); gunRepresentation.WeaponAnimation.LayerDepth = 0.05f; gunRepresentation.InitializeBullets(spriteSheet, Vector2.Zero, gunShotAnimationName, gunShotFrameTime, this.color, 1, spriteEffects, true); gunRepresentation.BulletsLayerDepth(0.05f); // sword weapon animations int swordFrameTime = 30; int swordShotFrameTime = 30; swordRepresentation = new WeaponRepresentation<PlayerWeapon>(player, player.Sword, new Vector2(swordOffsetX, swordOffsetY)); swordRepresentation.InitializeAnimation(spriteSheet, Vector2.Zero, swordAnimationName, swordFrameTime, this.color, 1, spriteEffects, false); swordRepresentation.WeaponAnimation.LayerDepth = 0.05f; swordRepresentation.InitializeBullets(spriteSheet, Vector2.Zero, swordShotAnimationName, swordShotFrameTime, this.color, 1, spriteEffects, true); swordRepresentation.BulletsLayerDepth(0.05f); // eyes frame eyesFrame = new Frame(); eyesFrame.Initialize(spriteSheet, Vector2.Zero, eyesFrameName, Color.White, spritePaddingScale, spriteEffects); eyesFrame.LayerDepth = playerLayerDepth - 0.001f; // dash trail particle emitter dashTrailEmitter.Initialize(5, 0.05f, 0.2f); }