Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Override TargetedAttackWeightsHero to return multiplied
- --KillHero values rather than setting to fixed amounts
- function TargetedAttackWeightsHero( action, aiBrain, agent, initialAgent )
- if not agent.WorldStateData.CanUseAbilities then
- return false
- end
- local actionBp = HeroAIActionTemplates[action.ActionName]
- if not action.Ability then
- return false
- end
- if not TestEnergy( agent, action.Ability ) then
- return false
- end
- local range = Ability[action.Ability].RangeMax * 1.5
- if not initialAgent.GOAP.NearbyEnemyHeroes.ClosestDistance or initialAgent.GOAP.NearbyEnemyHeroes.ClosestDistance > range then
- return false
- end
- local returnValue = table.copy(actionBp.GoalWeights)
- --Mithy: Defaulted to -1 to prevent errors
- if not returnValue.KillHero then
- returnValue.KillHero = -1
- end
- if initialAgent.GOAP.NearbyEnemyHeroes and not actionBp.ForceGoalWeights then
- local damage = GetAbilityDamage(actionBp, action.Ability)
- if damage then
- local enemyHps = initialAgent.GOAP.NearbyEnemyHeroes.WeakestHealth
- local damageRatio = enemyHps / damage
- --Mithy: Now multiplicative instead of hard-set
- if damageRatio < 1.0 then
- returnValue.KillHero = returnValue.KillHero * 3
- elseif damageRatio < 1.5 then
- returnValue.KillHero = returnValue.KillHero * 2
- elseif actionBp.KillShot then
- return false
- elseif damageRatio < 2.0 then
- returnValue.KillHero = returnValue.KillHero * 1.5
- else
- returnValue.KillHero = returnValue.KillHero * 0.5
- end
- end
- end
- if actionBp.WeakHeroNearbyAdd and agent.WorldStateData.WeakHeroNearby then
- returnValue.KillHero = returnValue.KillHero + actionBp.WeakHeroNearbyAdd
- end
- if actionBp.BonusGoalFunction then
- local addValue = actionBp.BonusGoalFunction(action.Ability)
- for k,v in returnValue do
- returnValue[k] = v + addValue
- end
- end
- local ringRange = math.ceil( Ability[action.Ability].RangeMax / 16 )
- local heroThreat = aiBrain:GetThreatAtPosition( agent.Position, ringRange, 'Hero', 'Enemy' )
- if heroThreat > 0 then
- return returnValue, actionBp.WeightTime or Ability[action.Ability].CastingTime or 0
- end
- return false
- end
- --Override TargetedAbilitySquadTargetWeights to return multiplied
- --KillSquadTarget values rather than setting to fixed amounts
- function TargetedAbilitySquadTargetWeights( action, aiBrain, agent, initialAgent )
- if not agent.WorldStateData.CanUseAbilities then
- return false
- end
- local actionBp = HeroAIActionTemplates[action.ActionName]
- if not action.Ability then
- return false
- end
- if not TestEnergy( agent, action.Ability ) then
- return false
- end
- if not Ability[action.Ability].RangeMax then
- WARN('*AI ERROR: No RangeMax found for AI Action - ' .. action.ActionName)
- return false
- end
- local range = Ability[action.Ability].RangeMax * 1.5
- local target = initialAgent.GOAP.AttackTarget
- if not target or VDist3XZSq( agent.Position, target.Position ) > range * range then
- return false
- end
- local returnValue = table.copy(actionBp.GoalWeights)
- --Mithy: Defaulted to -1 to prevent errors
- if not returnValue.KillSquadTarget then
- returnValue.KillSquadTarget = -1
- end
- if not actionBp.ForceGoalWeights and initialAgent.GOAP.SquadTargetHealth then
- local damage = GetAbilityDamage(actionBp, action.Ability)
- if damage then
- local enemyHps = initialAgent.GOAP.SquadTargetHealth
- local damageRatio = enemyHps / damage
- --Mithy: Now multiplicative instead of hard-set
- if damageRatio < 1.0 then
- returnValue.KillSquadTarget = returnValue.KillSquadTarget * 3
- elseif damageRatio < 1.5 then
- returnValue.KillSquadTarget = returnValue.KillSquadTarget * 2
- elseif actionBp.KillShot then
- return false
- elseif damageRatio < 2.0 then
- returnValue.KillSquadTarget = returnValue.KillSquadTarget * 1.5
- else
- returnValue.KillSquadTarget = returnValue.KillSquadTarget * 0.5
- end
- end
- end
- if actionBp.SquadTargetNearbyAdd then
- returnValue.KillSquadTarget = returnValue.KillSquadTarget + actionBp.SquadTargetNearbyAdd
- end
- if actionBp.BonusGoalFunction then
- local addValue = actionBp.BonusGoalFunction(action.Ability)
- for k,v in returnValue do
- returnValue[k] = v + addValue
- end
- end
- return returnValue, actionBp.WeightTime or Ability[action.Ability].CastingTime or 0
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement