Help with Ability (Again)

For technical discussions and help
Post Reply
lynx54321
Posts: 15
Joined: Mon Jul 04, 2016 9:52 pm

Help with Ability (Again)

Post by lynx54321 »

Hello I am hoping I can get some advice with an ability I've made.

Basically I've got an ability that gives a unit a 25% chance of taking an overwatch shot in certain circumstances.

I want to create an ability that alters this chance to 50% but I don't really know where to start. I've looked at Suppression and Run And Gun in LW but I can't see how I could use these to increase a % chance.
lynx54321
Posts: 15
Joined: Mon Jul 04, 2016 9:52 pm

Re: Help with Ability (Again)

Post by lynx54321 »

I think I've made some progress. Having had a look at how Extra Conditioning affects Run and Gun I've made a new "X2AbilityToHitCalc" file which I want to insert the % values depending on whether the second ability is present or not. Only problem now is that I'm getting an error when building...

Code: Select all

class X2AbilityToHitCalc_QuickTarget extends X2AbilityToHitCalc_PercentChance config(GameData_SoldierSkills);

var config int OP_POINTMAN_CHANCE;
var config int OP_POINTMAN2_CHANCE;

function RollForAbilityHit(XComGameState_Ability kAbility, AvailableTarget kTarget, out AbilityResultContext ResultContext)
{
	if (XComGameState_Unit(AffectState).HasSoldierAbility('Op_QuickTarget'))
	{
		return default.OP_POINTMAN2_CHANCE;
	}
	return default.OP_POINTMAN_CHANCE;
}
And the error I get is:

Code: Select all

\X2AbilityToHitCalc_QuickTarget.uc(8) : Error, Bad or missing expression for token: XComGameState_Unit, in 'If'
Any ideas?
shiremct
Posts: 7
Joined: Wed Apr 26, 2017 3:07 pm

Re: Help with Ability (Again)

Post by shiremct »

Code: Select all

XComGameState_Unit(AffectState).HasSoldierAbility('Op_QuickTarget')
This line above is referencing a passed variable that is not present in this function (AffectState). This function is passing in an abilitystate though, so we can pull the source from that. Try the following: (sorry the format spacing is all messed up...)

Code: Select all

function RollForAbilityHit(XComGameState_Ability kAbility, AvailableTarget kTarget, out AbilityResultContext ResultContext)
{
	local XComGameStateHistory History;
	local XComGameState_Unit SourceUnit;
	local int iRoll, iHitTarget;
   	
   	History = `XCOMHISTORY;
   	SourceUnit = XComGameState_Unit(History.GetGameStateForObjectID(kAbility.OwnerStateObject.ObjectID));
   	
 	if (SourceUnit.HasSoldierAbility('Op_QuickTarget'))
 		iHitTarget = default.OP_POINTMAN_CHANCE2;
 	else
 		iHitTarget = default.OP_POINTMAN_CHANCE;
	
   	iRoll = `SYNC_RAND(100);
   	ResultContext.HitResult = eHit_Miss;
	if (iRoll > iHitTarget)
		ResultContext.HitResult = eHit_Success;

	return;
}
shiremct
Posts: 7
Joined: Wed Apr 26, 2017 3:07 pm

Re: Help with Ability (Again)

Post by shiremct »

Try replacing the whole X2AbilityToHitCalc_QuickTarget class with the code below. I got this working with your abilities using fixed values of 0 and 100 and the config variables you have setup look correct, so it should work. Let me know how it goes:

Code: Select all

class X2AbilityToHitCalc_QuickTarget extends X2AbilityToHitCalc config(GameData_SoldierSkills);

var config int OP_POINTMAN_CHANCE;
var config int OP_POINTMAN2_CHANCE;

protected function int GetHitChance(XComGameState_Ability kAbility, AvailableTarget kTarget, optional bool bDebugLog=false)
{
	local XComGameStateHistory History;
	local XComGameState_Unit SourceUnit;

	History = `XCOMHISTORY;
	SourceUnit = XComGameState_Unit(History.GetGameStateForObjectID(kAbility.OwnerStateObject.ObjectID));

	if (SourceUnit.HasSoldierAbility('Op_QuickTarget'))
		return default.OP_POINTMAN2_CHANCE;
	else
		return default.OP_POINTMAN_CHANCE;
}


function RollForAbilityHit(XComGameState_Ability kAbility, AvailableTarget kTarget, out AbilityResultContext ResultContext)
{
	local int MultiIndex, RandRoll, PercentToHit;
	local ArmorMitigationResults NoArmor;

	PercentToHit = GetHitChance(kAbility, kTarget);

	RandRoll = `SYNC_RAND_TYPED(100, ESyncRandType_Generic);
	ResultContext.HitResult = RandRoll <= PercentToHit ? eHit_Success : eHit_Miss;
	ResultContext.ArmorMitigation = NoArmor;
	ResultContext.CalculatedHitChance = PercentToHit;

	for (MultiIndex = 0; MultiIndex < kTarget.AdditionalTargets.Length; ++MultiIndex)
	{
		RandRoll = `SYNC_RAND_TYPED(100, ESyncRandType_Generic);
		ResultContext.MultiTargetHitResults.AddItem(RandRoll < PercentToHit ? eHit_Success : eHit_Miss);
		ResultContext.MultiTargetArmorMitigation.AddItem(NoArmor);
		ResultContext.MultiTargetStatContestResult.AddItem(0);
	}
}
BTW, I have no idea what the armor mitigation stuff is doing. You could try commenting it out and seeing what happens and possibly get rid of it if it's actually giving the attacks armor mitigation (I just copied this straight from the original X2AbilityToHitCalc_PercentChance and modified the parts handling the hit chance).
shiremct
Posts: 7
Joined: Wed Apr 26, 2017 3:07 pm

Re: Help with Ability (Again)

Post by shiremct »

Use this for the damage modifying effect:

Code: Select all

class X2Effect_Spearhead extends X2Effect_Persistent config (GameData_SoldierSkills);

var config float OP_SPEARHEAD_DAMAGE_BONUS;

function int GetAttackingDamageModifier(XComGameState_Effect EffectState, XComGameState_Unit Attacker, Damageable TargetDamageable, XComGameState_Ability AbilityState, const out EffectAppliedData AppliedData, const int CurrentDamage, optional XComGameState NewGameState)
{
    local XComGameState_Item SourceWeapon;
    local XComGameState_Unit TargetUnit;

	if (AbilityState.GetMyTemplateName() == 'Op_PointmanShot')
	{
		if (AppliedData.AbilityResultContext.HitResult == eHit_success)
		{
			SourceWeapon = AbilityState.GetSourceWeapon();
			if (SourceWeapon != none) 
			{
				TargetUnit = XComGameState_Unit(TargetDamageable);
				if (TargetUnit != none)
				{
					return int(CurrentDamage * (default.OP_SPEARHEAD_DAMAGE_BONUS / 100));
				}
			}
		}
	}
	return 0;
}
Remove the instance of this effect in the Op_PointmanShot ability itself and add this persistent effect to Op_Spearhead. Use the MayhemBonuses ability in the X2Ability_PerkPackAbilitySet as a reference point.
Post Reply