View difference between Paste ID: vxcNbMRB and 357rmBuY
SHOW: | | - or go back to the newest paste.
1
function name PAShakeUpApplyChance(const out EffectAppliedData ApplyEffectParameters, XComGameState_BaseObject kNewTargetState, XComGameState NewGameState)
2
{
3
	//  this mimics the panic hit roll without actually BEING the panic hit roll
4-
	local XComGameState_Unit TargetUnit;
4+
	local XComGameState_Unit TargetUnit, SourceUnit;
5
	local name ImmuneName;
6
	local int TargetRoll, RandRoll;
7-
	local XMBValue_Visibility Value;
7+
	local int Value, BadGuysValue;
8-
	local int	BadGuysValue;
8+
9
	SourceUnit = XComGameState_Unit(`XCOMHISTORY.GetGameStateForObjectID(ApplyEffectParameters.SourceStateObjectRef.ObjectID));
10-
	Value = new class'XMBValue_Visibility';
10+
11-
	Value.bCountEnemies = true;
11+
12-
	Value.bSquadsight = true;
12+
	if (TargetUnit != none && SourceUnit != none)
13
	{
14
		Value = CountVisibleUnitsForUnit(SourceUnit);
15-
	if (TargetUnit != none)
15+
16
		foreach class'X2AbilityToHitCalc_PanicCheck'.default.PanicImmunityAbilities(ImmuneName)
17
		{
18
			if (TargetUnit.FindAbility(ImmuneName).ObjectID != 0)
19
			{
20
				return 'AA_UnitIsImmune';
21
			}
22
			if (default.PAShakeUp_BerserkerImmunity) 
23-
			if (default.PAShakeUp_BerserkerImmunity) {
23+
24
				if (TargetUnit.GetMyTemplate().CharacterGroupName == 'Berserker')
25
				{
26
					return 'AA_UnitIsImmune';
27
				}
28
			}
29
		}
30
31
		BadGuysValue = Value * default.PAShakeUp_DECREASE_PER_VISIBLE_ENEMY;
32
33
		TargetRoll = default.PAShakeUp_BASE_CHANCE - BadGuysValue;
34
		RandRoll = `SYNC_RAND(100);
35
		if (RandRoll < TargetRoll)
36
		{
37
			return 'AA_Success';
38
		}
39
	}
40
41
	return 'AA_EffectChanceFailed';
42
}
43
44
simulated function int CountVisibleUnitsForUnit(XComGameState_Unit SourceUnit, bool bSquadSight = false)
45
{
46
    local X2GameRulesetVisibilityManager VisibilityMgr;    
47
    local array<StateObjectReference> VisibleUnits;
48
	local array<X2Condition> RequiredConditions;
49
    local StateObjectReference UnitRef;
50
    local int Count;
51
52
    VisibilityMgr = `TACTICALRULES.VisibilityMgr;
53
54
	//Set default conditions (visible units need to be alive and game play visible) if no conditions were specified
55
	if( RequiredConditions.Length == 0 )
56
	{
57
		RequiredConditions = class'X2TacticalVisibilityHelpers'.default.LivingGameplayVisibleFilter;
58
	}
59
60
	if (bSquadSight)
61
	{
62
    		class'X2TacticalVisibilityHelpers'.static.GetAllVisibleObjectsForPlayer(SourceUnit.ControllingPlayer.ObjectID, VisibleUnits, RequiredConditions, -1);
63
	}
64
	else
65
	{
66
		VisibilityMgr.GetAllVisibleToSource(SourceUnit.ObjectID, VisibleUnits, class'XComGameState_Unit', -1, RequiredConditions);
67
	}
68
69
70
    foreach VisibleUnits(UnitRef)
71
    {
72
        if (SourceUnit.TargetIsEnemy(UnitRef.ObjectID, -1))
73
        {
74
            Count++;
75
        }
76
    }
77
78
    return Count;
79
}