Files
7d2dXG/Mods/zzz_REBIRTH__Utils/Scripts/MinEvents/NPCs/MinEventActionNPCSoundTrigger.cs
Nathaniel Cosford 062dfab2cd Patched
2025-05-30 01:04:40 +09:30

315 lines
15 KiB
C#

using Audio;
using System.Collections.Generic;
using System.Xml.Linq;
public class MinEventActionNPCSoundTrigger : MinEventActionBuffModifierBase
{
string strAction = "";
public override void Execute(MinEventParams _params)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute strAction: " + strAction);
if (_params.Self is EntityNPCRebirth)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 1");
EntityNPCRebirth npc = (EntityNPCRebirth)_params.Self;
if (npc != null)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute npc: " + npc.EntityClass.entityClassName);
if (this.targets[0] != null)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 2");
if (strAction == "onOtherAttackedSelf")
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3");
if (this.targets[0].HasAllTags(FastTags<TagGroup.Global>.Parse("bandit,ranged")) &&
!npc.Buffs.HasBuff("FuriousRamsayNPCCanSeeTarget") &&
!npc.Buffs.HasBuff("FuriousRamsayNPCOtherDamagedSelf")
)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3a");
npc.Buffs.AddBuff("FuriousRamsayNPCOtherAttackedSelf");
List<string> myTags = npc.EntityTags.GetTagNames();
List<string> myRandomSounds = new List<string>();
foreach (string tag in myTags)
{
if (tag.Contains("-OAS-"))
{
myRandomSounds.Add(tag);
}
}
if (myRandomSounds.Count > 0)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3b");
int index = UnityEngine.Random.Range(0, myRandomSounds.Count - 1);
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsSinglePlayer)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3c");
if (npc.LeaderUtils.Owner != null)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3d");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
else
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3e");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
}
else
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3f");
if (npc.LeaderUtils.Owner != null)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3d");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
else
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3e");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
}
}
}
}
else if (strAction == "onOtherDamagedSelf")
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 4");
if (this.targets[0].HasAllTags(FastTags<TagGroup.Global>.Parse("bandit,ranged")) &&
!npc.Buffs.HasBuff("FuriousRamsayNPCCanSeeTarget") &&
!npc.Buffs.HasBuff("FuriousRamsayNPCOtherAttackedSelf") &&
!npc.Buffs.HasBuff("FuriousRamsayNPCOtherDamagedSelf")
)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 4a");
npc.Buffs.AddBuff("FuriousRamsayNPCOtherDamagedSelf");
List<string> myTags = npc.EntityTags.GetTagNames();
List<string> myRandomSounds = new List<string>();
foreach (string tag in myTags)
{
if (tag.Contains("-ODS-"))
{
myRandomSounds.Add(tag);
}
}
if (myRandomSounds.Count > 0)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 4b");
int index = UnityEngine.Random.Range(0, myRandomSounds.Count - 1);
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsSinglePlayer)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 4c");
if (npc.LeaderUtils.Owner != null)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 4d");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
//Manager.BroadcastPlay(leader.position, myRandomSounds[index], 0f);
}
else
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 4e");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
}
else
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 4f");
//var leader = EntityUtilities.GetLeaderOrOwner(npc.entityId) as EntityAlive;
if (npc.LeaderUtils.Owner != null)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3d");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
else
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3e");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
}
}
}
}
else if (strAction == "onSelfKilledOther" && !RebirthUtilities.IsHordeNight())
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 5");
if (!npc.Buffs.HasBuff("FuriousRamsayNPCCanSeeTarget") &&
!npc.Buffs.HasBuff("FuriousRamsayNPCSelfKilledOther")
)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 5a");
npc.Buffs.AddBuff("FuriousRamsayNPCSelfKilledOther");
npc.Buffs.AddBuff("FuriousRamsayNPCSelfKilledOtherKillingSpree");
List<string> myTags = npc.EntityTags.GetTagNames();
List<string> myRandomSounds = new List<string>();
foreach (string tag in myTags)
{
if (tag.Contains("-SKOD-"))
{
myRandomSounds.Add(tag);
}
}
if (myRandomSounds.Count > 0)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 5b");
int index = UnityEngine.Random.Range(0, myRandomSounds.Count - 1);
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsSinglePlayer)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 5c");
if (npc.LeaderUtils.Owner != null)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 5d");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
else
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 5e");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
}
else
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 5f");
if (npc.LeaderUtils.Owner != null)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3d");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
else
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3e");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
}
}
}
}
else if (strAction == "killingSpree")
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 6");
if (!npc.Buffs.HasBuff("FuriousRamsayNPCCanSeeTarget") &&
!(npc.Buffs.HasBuff("FuriousRamsayNPCKillingSpree") || npc.Buffs.HasBuff("FuriousRamsayNPCKillingSpreeHN") || npc.Buffs.HasBuff("FuriousRamsayNPCSelfKilledOtherKillingSpree"))
)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 6a");
npc.killingSpree = npc.killingSpree + 1;
//Log.Out("MinEventActionNPCSoundTrigger-Execute npc.killingSpree: " + npc.killingSpree);
if (npc.killingSpree < 3)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 6a1");
return;
}
if (RebirthUtilities.IsHordeNight())
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 6a2");
npc.Buffs.AddBuff("FuriousRamsayNPCKillingSpreeHN");
}
else
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 6a3");
npc.Buffs.AddBuff("FuriousRamsayNPCKillingSpree");
}
List<string> myTags = npc.EntityTags.GetTagNames();
List<string> myRandomSounds = new List<string>();
foreach (string tag in myTags)
{
if (tag.Contains("-KS-"))
{
myRandomSounds.Add(tag);
}
}
if (myRandomSounds.Count > 0)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 6b");
int index = UnityEngine.Random.Range(0, myRandomSounds.Count - 1);
if (SingletonMonoBehaviour<ConnectionManager>.Instance.IsSinglePlayer)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 6c");
if (npc.LeaderUtils.Owner != null)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 6d");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
else
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 6e");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
}
else
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 6f");
if (npc.LeaderUtils.Owner != null)
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3d");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
else
{
//Log.Out("MinEventActionNPCSoundTrigger-Execute 3e");
Manager.BroadcastPlay(npc.position, myRandomSounds[index], 0f);
}
}
}
npc.killingSpree = 0;
}
}
}
}
}
}
public override bool ParseXmlAttribute(XAttribute _attribute)
{
var flag = base.ParseXmlAttribute(_attribute);
if (flag) return true;
var name = _attribute.Name;
if (name == null)
{
return flag;
}
else if (name == "NPCAction")
{
strAction = _attribute.Value;
return true;
}
else
{
return false;
}
}
}