aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Custom/mod/scripts/vscripts/weapons/mp_titanweapon_arc_cannon.nut
blob: 09faafa575b85cab2dca2cfba1ec08eef43ab711 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
ArcCannon_PrecacheFX( self )

function OnWeaponActivate( activateParams )
{
	local weaponOwner = self.GetWeaponOwner()
	thread DelayedArcCannonStart( self, weaponOwner )
	if( !("weaponOwner" in self.s) )
		self.s.weaponOwner <- weaponOwner
}

function DelayedArcCannonStart( weapon, weaponOwner )
{
	weapon.EndSignal( "WeaponDeactivateEvent" )

	wait 0

	if ( IsValid( weapon ) && IsValid( weaponOwner ) && weapon == weaponOwner.GetActiveWeapon() )
	{
		if( weaponOwner.IsPlayer() )
		{
			local modelEnt = weaponOwner.GetViewModelEntity()
	 		if( IsValid( modelEnt ) && EntHasModelSet( modelEnt ) )
				ArcCannon_Start( weapon )
		}
		else
		{
			ArcCannon_Start( weapon )
		}
	}
}

function OnWeaponDeactivate( deactivateParams )
{
	ArcCannon_ChargeEnd( self, self.s.weaponOwner )
	ArcCannon_Stop( self )
}

function OnWeaponReload( reloadParams )
{
	local reloadTime = self.GetWeaponInfoFileKeyField( "reload_time" )
	thread ArcCannon_HideIdleEffect( self, reloadTime ) //constant seems to help it sync up better
}

function OnWeaponOwnerChanged( changeParams )
{
	if ( IsClient() )
	{
		local viewPlayer = GetLocalViewPlayer()
		if ( changeParams.oldOwner != null && changeParams.oldOwner == viewPlayer )
		{
			ArcCannon_ChargeEnd( self, changeParams.oldOwner )
			ArcCannon_Stop( self, changeParams.oldOwner )
		}
		if ( changeParams.newOwner != null && changeParams.newOwner == viewPlayer )
			thread ArcCannon_HideIdleEffect( self, 0.25 )	
	}
	else
	{
		if ( changeParams.oldOwner != null )
		{
			ArcCannon_ChargeEnd( self, changeParams.oldOwner )
			ArcCannon_Stop( self, changeParams.oldOwner )
		}
		if ( changeParams.newOwner != null )
			thread ArcCannon_HideIdleEffect( self, 0.25 )			
	}
}

function OnWeaponChargeBegin( chargeParams )
{
	ArcCannon_ChargeBegin( self )
}

function OnWeaponChargeEnd( chargeParams )
{
	ArcCannon_ChargeEnd( self )
}

function OnWeaponPrimaryAttack( attackParams )
{
	if ( self.HasMod( "capacitor" ) && self.GetWeaponChargeFraction() < GetArcCannonChargeFraction( self ) )
		return 0

	if ( !attackParams.firstTimePredicted )
		return

	local fireRate = self.GetWeaponInfoFileKeyField( "fire_rate" )
	thread ArcCannon_HideIdleEffect( self, (1 / fireRate) )
	return FireArcCannon( self, attackParams )
}

function OnWeaponNpcPrimaryAttack( attackParams )
{
	local fireRate = self.GetWeaponInfoFileKeyField( "fire_rate" )
	thread ArcCannon_HideIdleEffect( self, fireRate )
	return FireArcCannon( self, attackParams )
}

function OnWeaponStartZoomIn()
{
	HandleWeaponSoundZoomIn( self, "Weapon_Titan_ArcCannon.ADS_In" )
}

function OnWeaponStartZoomOut()
{
	HandleWeaponSoundZoomOut( self, "Weapon_Titan_ArcCannon.ADS_Out" )
}

/*
function OnWeaponPrimaryAttackVMActivityToUse()
{
	local baseCharge = self.GetWeaponChargeFraction()
	local charge = clamp ( baseCharge * ( 1 / 0.7 ), 0.0, 1.0 )

	if ( charge > 0.25 )
		return 1
	else
		return 0
}*/