181 lines
5.8 KiB
C#
181 lines
5.8 KiB
C#
using System.Collections.Generic;
|
|
|
|
public class EAIBreakBlockRebirth : EAIBase
|
|
{
|
|
public override void Init(EntityAlive _theEntity)
|
|
{
|
|
base.Init(_theEntity);
|
|
this.MutexBits = 8;
|
|
this.executeDelay = 0.15f;
|
|
}
|
|
|
|
public bool NPCEAICanProceed()
|
|
{
|
|
bool result = true;
|
|
|
|
OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
|
|
|
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
|
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
|
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
|
)
|
|
{
|
|
//Log.Out("EAIBreakBlockRebirth-NPCEAICanProceed 1");
|
|
return false;
|
|
}
|
|
|
|
if (this.theEntity.emodel.IsRagdollActive)
|
|
{
|
|
//Log.Out("EAIBreakBlockRebirth-NPCEAICanProceed 3");
|
|
return false;
|
|
}
|
|
|
|
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
|
{
|
|
//Log.Out("EAIBreakBlockRebirth-NPCEAICanProceed 4");
|
|
return false;
|
|
}
|
|
|
|
if (OwnerID > 0 &&
|
|
this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Stay &&
|
|
this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.TempStay
|
|
)
|
|
{
|
|
//Log.Out("EAIBreakBlockRebirth-CanExecute IS NOT FOLLOWING");
|
|
return false;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public override bool CanExecute()
|
|
{
|
|
if (!NPCEAICanProceed())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//Log.Out("EAIBreakBlockRebirth-CanExecute START");
|
|
EntityMoveHelper moveHelper = this.theEntity.moveHelper;
|
|
if ((this.theEntity.Jumping && !moveHelper.IsDestroyArea) || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
|
{
|
|
//Log.Out("EAIBreakBlockRebirth-CanExecute 1");
|
|
return false;
|
|
}
|
|
//Log.Out("EAIBreakBlockRebirth-CanExecute moveHelper.BlockedTime: " + moveHelper.BlockedTime);
|
|
//Log.Out("EAIBreakBlockRebirth-CanExecute moveHelper.CanBreakBlocks: " + moveHelper.CanBreakBlocks);
|
|
if (moveHelper.BlockedTime > 0.35f && moveHelper.CanBreakBlocks)
|
|
{
|
|
//Log.Out("EAIBreakBlockRebirth-CanExecute 2");
|
|
RebirthUtilities.CheckForOpenDoor(this.theEntity);
|
|
|
|
float num = moveHelper.CalcBlockedDistanceSq();
|
|
float num2 = this.theEntity.m_characterController.GetRadius() + 0.6f;
|
|
if (num <= num2 * num2)
|
|
{
|
|
//Log.Out("EAIBreakBlockRebirth-CanExecute 8");
|
|
return true;
|
|
}
|
|
}
|
|
|
|
//Log.Out("EAIBreakBlockRebirth-CanExecute END");
|
|
return false;
|
|
}
|
|
|
|
public override void Start()
|
|
{
|
|
//Log.Out("EAIBreakBlockRebirth-Start START");
|
|
this.attackDelay = 1;
|
|
Vector3i blockPos = this.theEntity.moveHelper.HitInfo.hit.blockPos;
|
|
Block block = this.theEntity.world.GetBlock(blockPos).Block;
|
|
if (block.HasTag(BlockTags.Door) || block.HasTag(BlockTags.ClosetDoor))
|
|
{
|
|
this.theEntity.IsBreakingDoors = true;
|
|
}
|
|
}
|
|
|
|
public override bool Continue()
|
|
{
|
|
if (!NPCEAICanProceed())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None && this.theEntity.onGround && this.CanExecute();
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
//Log.Out("EAIBreakBlockRebirth-Update START");
|
|
if (!NPCEAICanProceed())
|
|
{
|
|
return;
|
|
}
|
|
|
|
EntityMoveHelper moveHelper = this.theEntity.moveHelper;
|
|
//Log.Out("EAIBreakBlockRebirth-Update attackDelay: " + this.attackDelay);
|
|
if (this.attackDelay > 0)
|
|
{
|
|
this.attackDelay--;
|
|
}
|
|
if (this.attackDelay <= 0)
|
|
{
|
|
this.AttackBlock();
|
|
}
|
|
}
|
|
|
|
public override void Reset()
|
|
{
|
|
//Log.Out("EAIBreakBlockRebirth-Reset START");
|
|
this.theEntity.IsBreakingBlocks = false;
|
|
this.theEntity.IsBreakingDoors = false;
|
|
}
|
|
|
|
private void AttackBlock()
|
|
{
|
|
this.theEntity.SetLookPosition(Vector3.zero);
|
|
ItemActionAttackData itemActionAttackData = this.theEntity.inventory.holdingItemData.actionData[0] as ItemActionAttackData;
|
|
if (itemActionAttackData == null)
|
|
{
|
|
return;
|
|
}
|
|
this.damageBoostPercent = 0f;
|
|
Bounds bb;
|
|
bb = new Bounds(this.theEntity.position, new Vector3(1.7f, 1.5f, 1.7f));
|
|
this.theEntity.world.GetEntitiesInBounds(typeof(EntityZombie), bb, this.allies);
|
|
for (int i = this.allies.Count - 1; i >= 0; i--)
|
|
{
|
|
if ((EntityZombie)this.allies[i] != this.theEntity)
|
|
{
|
|
this.damageBoostPercent += 0.2f;
|
|
}
|
|
}
|
|
this.allies.Clear();
|
|
if (this.theEntity.Attack(false))
|
|
{
|
|
this.theEntity.IsBreakingBlocks = true;
|
|
float num = 0.25f + base.RandomFloat * 0.8f;
|
|
if (this.theEntity.moveHelper.IsUnreachableAbove)
|
|
{
|
|
num *= 0.5f;
|
|
}
|
|
this.attackDelay = (int)((num + 0.75f) * 20f);
|
|
itemActionAttackData.hitDelegate = new ItemActionAttackData.HitDelegate(this.GetHitInfo);
|
|
this.theEntity.Attack(true);
|
|
}
|
|
}
|
|
|
|
private WorldRayHitInfo GetHitInfo(out float damageScale)
|
|
{
|
|
EntityMoveHelper moveHelper = this.theEntity.moveHelper;
|
|
damageScale = moveHelper.DamageScale + this.damageBoostPercent;
|
|
return moveHelper.HitInfo;
|
|
}
|
|
|
|
private const float cDamageBoostPerAlly = 0.2f;
|
|
private int OwnerID = 0;
|
|
private int attackDelay;
|
|
private float damageBoostPercent;
|
|
private List<Entity> allies = new List<Entity>();
|
|
}
|