Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi barrel offset #3642

Open
wants to merge 1 commit into
base: Development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;

namespace CombatExtended
{
public class MultiBarrelExtension : DefModExtension
{
public List<Vector2> offsets = new List<Vector2>();

public Vector2 GetOffsetFor(int index)
{
if (offsets.NullOrEmpty())
{
return Vector2.zero;
}
int i = index % offsets.Count;
return offsets[i];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class Verb_LaunchProjectileCE : Verb
public CompFireModes compFireModes = null;
public CompChangeableProjectile compChangeable = null;
public CompApparelReloadable compReloadable = null;
protected int multiBarrelIndex;

private float shotSpeed = -1;

private float rotationDegrees = 0f;
Expand All @@ -63,6 +65,7 @@ public class Verb_LaunchProjectileCE : Verb

public VerbPropertiesCE VerbPropsCE => verbProps as VerbPropertiesCE;
public ProjectilePropertiesCE projectilePropsCE => Projectile.projectile as ProjectilePropertiesCE;
public MultiBarrelExtension multiBarrelExt => EquipmentSource.def.GetModExtension<MultiBarrelExtension>();

// Returns either the pawn aiming the weapon or in case of turret guns the turret operator or null if neither exists
public Pawn ShooterPawn => CasterPawn ?? CE_Utility.TryGetTurretOperator(caster);
Expand Down Expand Up @@ -542,6 +545,16 @@ public virtual void ShiftTarget(ShiftVecReport report, bool calculateMechanicalO
shotRotation = (lastShotRotation + rotationDegrees + spreadVec.x) % 360;
shotAngle = angleRadians + spreadVec.y * Mathf.Deg2Rad;
distance = (newTargetLoc - sourceLoc).magnitude;
sourceLoc += IncrementBarrelCount();
}

/// <summary>
/// Add 1 to multi barrel index then returns the barrel offset.
/// </summary>
protected Vector2 IncrementBarrelCount()
{
multiBarrelIndex++;
return multiBarrelExt?.GetOffsetFor(multiBarrelIndex).RotatedBy(shotRotation) ?? Vector2.zero;
}

/// <summary>
Expand Down
Loading