Skip to content

Commit

Permalink
Merge pull request IEMod#76 from SiliconMage/master
Browse files Browse the repository at this point in the history
Updated Code (Note, I have a more up to date version that fixes the version number issue by removing the hardcoding in the mod)
  • Loading branch information
tjayharvey committed Feb 29, 2016
2 parents 108299a + 18c470c commit 3df0da0
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 64 deletions.
1 change: 1 addition & 0 deletions IEMod/IEMod.pw.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<Compile Include="Mods\ConsoleMod\mod_UIConsole.cs" />
<Compile Include="Mods\DropButtonMod\DropButton.cs" />
<Compile Include="Mods\FastSneak\mod_PartyMemberAI.cs" />
<Compile Include="Mods\HideAnticlassSpells\mod_UIAbilityBarButtonSet.cs" />
<Compile Include="Mods\MaxAdventurers\mod_PartyMemberAI.cs" />
<Compile Include="Mods\NoEngagement\Mod_NoEngagement_HudEngagementIndicator.cs" />
<Compile Include="Mods\Targeting\mod_AIController.cs" />
Expand Down
81 changes: 81 additions & 0 deletions IEMod/Mods/HideAnticlassSpells/mod_UIAbilityBarButtonSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using IEMod.Helpers;
using IEMod.Mods.Options;
using Patchwork.Attributes;
using UnityEngine;

namespace IEMod.Mods.HideAntiClassSpells
{
[ModifiesType]
public class mod_UIAbilityBarButtonSet : UIAbilityBarButtonSet
{
[ModifiesMember(nameof(SetButtonsAnticlassSpells))]
public void mod_SetButtonsAnticlassSpells(CharacterStats stats)
{
this.Label = null;
int num = 0;
foreach (GenericAbility current in stats.Abilities)
{
if (current is GenericSpell)
{
CharacterStats.Class spellClass = ((GenericSpell)current).SpellClass;
if (spellClass != stats.CharacterClass || !CharacterStats.IsPlayableClass(spellClass))
{

if ((stats.CharacterClass == CharacterStats.Class.Wizard ||
stats.CharacterClass == CharacterStats.Class.Priest ||
stats.CharacterClass == CharacterStats.Class.Druid ||
stats.CharacterClass == CharacterStats.Class.Chanter ||
stats.CharacterClass == CharacterStats.Class.Cipher) && IEModOptions.HideAnticlassSpells)
{

}

else
{
this.SetButton(num, current.gameObject, UIAbilityBarButtonSet.AbilityButtonAction.CAST_SPELL_ABILITY, current.Icon);
num++;
}
}
}
}
this.HideButtons(num);
this.m_DoRefresh = true;
}

[ModifiesMember(nameof(ShowOnSpellBar))]
public static bool mod_ShowOnSpellBar(GenericAbility ability, CharacterStats stats, int spellLevel)
{
if (ability.Passive)
{
return false;
}
GenericSpell genericSpell = ability as GenericSpell;
GenericCipherAbility genericCipherAbility = ability as GenericCipherAbility;
if (!genericSpell)
{
return genericCipherAbility && (spellLevel <= 0 || genericCipherAbility.SpellLevel == spellLevel);
}

if (genericSpell.SpellClass != stats.CharacterClass && spellLevel > 0 && genericSpell.SpellLevel == spellLevel && IEModOptions.HideAnticlassSpells)
{
return true;
}

if (genericSpell.SpellClass != stats.CharacterClass || (spellLevel > 0 && genericSpell.SpellLevel != spellLevel))
{
return false;
}
if (stats.CharacterClass != CharacterStats.Class.Wizard || !genericSpell.NeedsGrimoire)
{
return true;
}
Equipment component = stats.GetComponent<Equipment>();
if (component == null || component.CurrentItems == null || component.CurrentItems.Grimoire == null)
{
return false;
}
Grimoire component2 = component.CurrentItems.Grimoire.GetComponent<Grimoire>();
return !(component2 == null) && component2.HasSpell(genericSpell);
}
}
}
91 changes: 89 additions & 2 deletions IEMod/Mods/Targeting/mod_AttackAOE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,93 @@ namespace IEMod.Mods.Targeting {
public class mod_AttackAOE : AttackAOE {

[ModifiesMember("FindAoeTargets")]
public virtual List<GameObject> FindAoeTargetsNew(GameObject caster, Vector3 parentForward, Vector3 hitPosition, bool forUI) {
public virtual List<GameObject> FindAoeTargetsNew(GameObject caster, Vector3 parentForward, Vector3 hitPosition, bool forUi)
{
bool flag;
bool flag1;
List<GameObject> gameObjects = new List<GameObject>();
float adjustedBlastRadius = this.AdjustedBlastRadius;
float single = adjustedBlastRadius;
if (this.ValidTargets == AttackBase.TargetType.All && this.BlastRadius < this.AdjustedBlastRadius)
{
adjustedBlastRadius = this.BlastRadius;
}
foreach (Faction activeFactionComponent in Faction.ActiveFactionComponents)
{
if (activeFactionComponent != null)
{
if (!(activeFactionComponent.gameObject == base.Owner) || this.DamageAngleDegrees <= 0f || this.DamageAngleDegrees >= 360f)
{
Vector3 vector3 = activeFactionComponent.transform.position - hitPosition;
float single1 = vector3.sqrMagnitude;
if (this.ExcludeTarget && single1 <= 1.401298E-45f)
{
continue;
}
float cachedRadius = activeFactionComponent.CachedRadius;
float single2 = (adjustedBlastRadius + cachedRadius) * (adjustedBlastRadius + cachedRadius);
float single3 = (single + cachedRadius) * (single + cachedRadius);
Vector3 vector31 = vector3.normalized;
if (this.TargetAngle > 0f)
{
vector31 = Quaternion.Euler(0f, this.TargetAngle, 0f) * vector31;
}
float single4 = Vector3.Angle(parentForward, vector31);
bool damageAngleDegrees = single4 <= this.DamageAngleDegrees * 0.5f;
if (single1 < 1.401298E-45f)
{
flag = true;
}
else
{
flag = (!damageAngleDegrees ? false : single1 <= single3);
}
bool flag2 = flag;
if (single1 < 1.401298E-45f)
{
flag1 = true;
}
else
{
flag1 = (!damageAngleDegrees ? false : single1 <= single2);
}
bool flag3 = flag1;
if (!flag2 || !GameUtilities.LineofSight(hitPosition, activeFactionComponent.gameObject.transform.position, 1f, false, true))
{
continue;
}
if (this.ValidTargets != AttackBase.TargetType.All || !base.IsValidTarget(activeFactionComponent.gameObject, caster, AttackBase.TargetType.Hostile))
{
if (!flag3 || !base.IsValidTarget(activeFactionComponent.gameObject, caster))
{
continue;
}

var casterFaction = caster.GetComponent<Faction>();
if (IEModOptions.DisableFriendlyFire && ValidTargets == TargetType.All && mod_AttackBase.FriendlyRightNowAndAlsoWhenConfused(activeFactionComponent.gameObject, caster))
{
continue;
}

gameObjects.Add(activeFactionComponent.gameObject);
}
else
{
gameObjects.Add(activeFactionComponent.gameObject);
}
}
}
}
int num = gameObjects.IndexOf(base.Owner);
if (num > 0)
{
gameObjects[num] = gameObjects[0];
gameObjects[0] = base.Owner;
}
return gameObjects;
}
/*
public virtual List<GameObject> FindAoeTargetsNew(GameObject caster, Vector3 parentForward, Vector3 hitPosition, bool forUI) {
List<GameObject> gameObjects = new List<GameObject>();
float blastRadius = AdjustedBlastRadius;
float adjBlastRadius = blastRadius;
Expand Down Expand Up @@ -65,6 +151,7 @@ public virtual List<GameObject> FindAoeTargetsNew(GameObject caster, Vector3 par
}
return gameObjects;
}
}
*/
}

}
42 changes: 41 additions & 1 deletion IEMod/Mods/Targeting/mod_AttackBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,47 @@ public bool mod_IsValidTarget(GameObject target, GameObject caster, TargetType v
}
break;
}
}

case AttackBase.TargetType.SpiritOrSummonedCreature:
{
if (characterStat && characterStat.CharacterRace == CharacterStats.Race.Spirit || aIController && aIController.SummonType == AIController.AISummonType.Summoned)
{
return true;
}
break;
}
case AttackBase.TargetType.OwnAnimalCompanion:
{
if (aIController.SummonType == AIController.AISummonType.AnimalCompanion && aIController.Summoner == caster)
{
return true;
}
break;
}
case AttackBase.TargetType.HostileWithNpcAppearance:
{
NPCAppearance nPCAppearance = target.GetComponent<NPCAppearance>();
if (nPCAppearance && nPCAppearance.isActiveAndEnabled && this.IsValidTarget(target, caster, AttackBase.TargetType.Hostile))
{
return true;
}
break;
}
case AttackBase.TargetType.OwnerOfPairedAbility:
{
PairedAbility pairedAbility = base.GetComponent<PairedAbility>();
if (!pairedAbility)
{
UIDebug.Instance.LogOnScreenWarning(string.Concat("Ability '", base.name, "' must have a PairedAbility component to use OwnerOfPairedAbility target type."), UIDebug.Department.Design, 10f);
return false;
}
return (!pairedAbility.OtherAbility ? false : target == pairedAbility.OtherAbility.Owner);
}
case AttackBase.TargetType.AnyWithResonance:
{
return characterStat.CountStatusEffects("resonance", caster) > 0;
}
}
//!+END MODIFICATIONS
return false;
}
Expand Down
25 changes: 15 additions & 10 deletions IEMod/Mods/Targeting/mod_CharacterStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,23 @@ public void mod_AdjustDamageDealt(GameObject enemy, DamageInfo damage, bool test
if (damage.DefendedBy != CharacterStats.DefenseType.None)
{
this.ComputeHitAdjustment(attackerToHitRollOverride + num - num1, component, damage);

//!+ ADDED CODE
if (IEModOptions.DisableFriendlyFire) {
var faction = enemy.Component<Faction>();
if (mod_AttackBase.FriendlyRightNowAndAlsoWhenConfused(enemy, this.gameObject)) {
damage.IsCriticalHit = false;
damage.Interrupts = false;
damage.IsGraze = false;
damage.IsKillingBlow = false;
damage.IsMiss = true;
}
}
if (IEModOptions.DisableFriendlyFire)
{
var faction = enemy.Component<Faction>();
if (mod_AttackBase.FriendlyRightNowAndAlsoWhenConfused(enemy, this.gameObject))
{
damage.IsCriticalHit = false;
damage.Interrupts = false;
damage.IsGraze = false;
damage.IsKillingBlow = false;
damage.IsMiss = true;
}
}
//!+ END ADD


if (!testing && this.OnAttackRollCalculated != null)
{
this.OnAttackRollCalculated(base.gameObject, new CombatEventArgs(damage, base.gameObject, enemy));
Expand Down
50 changes: 3 additions & 47 deletions IEMod/Mods/Targeting/mod_Trap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ public class mod_Trap : Trap
[NewMember]
[DuplicatesBody(nameof(CanActivate))]
private bool orig_CanActivate(GameObject victim) {
return false;
}

return false;
}

[ModifiesMember(nameof(CanActivate))]
public bool mod_CanActivate(GameObject victim) {
Expand All @@ -29,50 +30,5 @@ public bool mod_CanActivate(GameObject victim) {
}
return orig_CanActivate(victim);
}


//[ModifiesMember("CanActivate")]
private bool CanActivateNew(GameObject victim) {
bool disableFriendlyFire = IEModOptions.DisableFriendlyFire;

if (!this.m_trap_initialized)
{
Debug.LogError("Cannot activate uninitialized trap!");
return false;
}

if (disableFriendlyFire)
{
Faction victimFaction = victim.GetComponent<Faction>();

if (victimFaction.isPartyMember && this.IsPlayerOwnedTrap)
{
return false;
}
}

if (this.Disarmed || this.m_triggerVictim != null)
{
return false;
}
if (this.MaxHitCount > 0 && this.m_numHits >= this.MaxHitCount)
{
return false;
}
if (GameUtilities.IsAnimalCompanion(victim))
{
return false;
}
if (this.m_ocl != null)
{
return true;
}
if (this.ActivatesForAnyone)
{
return true;
}
Faction component = victim.GetComponent<Faction>();
return component != null && (component.IsHostile(base.gameObject) || this.m_trap_faction.IsHostile(victim));
}
}
}
2 changes: 1 addition & 1 deletion IEMod/Mods/VersionNumber/mod_UIVersionNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void mod_ctor() {
alias_MonoBehavior_ctor();
var ieModVersion = IEMod.IEModVersion.Version;
//GR 29/8 - there has to be some const for the version, but I haven't found it :/
this.FormatString = $"v2.03.{{0}} {{1}} - IEMod {ieModVersion}";
this.FormatString = $"v3.01.977 - IEMod {ieModVersion}";
this.m_stringBuilder = new StringBuilder();
}
}
Expand Down
7 changes: 6 additions & 1 deletion IEMod/Options/Definitions/IEModOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,12 @@ public static bool EnableCustomUi {
[Description("Engagement begone. You need to exit to main menu and reload to reenable engagement.")]
public static bool DisableEngagement;

private static AutoSaveSetting _autoSaveSetting;
[Save]
[Label("Hide Anticlass Spells from Ability Bar")]
[Description("Hides Anticlass spells from showing up on the ability bar and adds them to a spell submenu of an existing class. For example, if you add Druid spells to your Wizard, the added Druid spells will show up under the Wizard spells submenu of the appropriate level.")]
public static bool HideAnticlassSpells;

private static AutoSaveSetting _autoSaveSetting;
private static Dictionary<string, PropertyInfo> _propertyCache;

public static void LoadFromPrefs() {
Expand Down
5 changes: 5 additions & 0 deletions IEMod/Options/UI/mod_UIOptionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class Mod4_MappedInput {
private QuickDropdown<IEModOptions.AutoSaveSetting> _autosaveCmb;
[NewMember]
private QuickDropdown<IEModOptions.MaxAdventurersOptions> _maxAdventurersCmb;
[NewMember]
private QuickCheckbox _hideAntiClassSpells;

[NewMember]
private QuickCheckbox _disableBackerDialog;
Expand Down Expand Up @@ -220,6 +222,9 @@ private void mod_Start() {
_enableCustomUI = quickFactory.Checkbox(() => IEModOptions.EnableCustomUi);
_enableCustomUI.LocalPosition = column2Top.Plus(y: -210);

_hideAntiClassSpells = quickFactory.Checkbox(() => IEModOptions.HideAnticlassSpells);
_hideAntiClassSpells.LocalPosition = column2Top.Plus(y: -240);

var centerCmbTop = new Vector3(-80, -40, 0);
const int cmbLabelWidth = 300;
const int cmbWidth = 515;
Expand Down
4 changes: 2 additions & 2 deletions IEMod/Properties/IEMod.Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace IEMod {
/// </summary>
[NewType]
public static class IEModVersion {
public const string StupidVersion = "5.2.0";
public const string Version = "5.2.0-beta";
public const string StupidVersion = "5.2.1";
public const string Version = "5.2.1-beta";
}
}

0 comments on commit 3df0da0

Please sign in to comment.