Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chopping - Add tree destruction to tree removal action #140

Open
wants to merge 5 commits into
base: experimental
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ACE_Carrying_CarryUserAction : ScriptedUserAction
// Trying to carry while unit is ragdolling will break things
if (ownerChar.GetAnimationComponent().IsRagdollActive())
{
SetCannotPerformReason(ActionMenuFailReason.DEFAULT);
SetCannotPerformReason("#AR-UserActionUnavailable");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,46 @@
//! Tree deletion user action
class ACE_Chopping_UserAction : ACE_ShovelUserAction
{
//------------------------------------------------------------------------------------------------
//! Request deletion of the tree
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
{
SCR_PlayerController userCtrl = SCR_PlayerController.Cast(GetGame().GetPlayerController());
if (!userCtrl)
return;

ACE_Chopping_HelperEntity helper = ACE_Chopping_HelperEntity.Cast(GetOwner());
if (!helper)
return;

IEntity plant = helper.GetAssociatedPlant();
if (!plant)
return;

userCtrl.ACE_RequestDeleteEntity(plant);
protected static const int DELETE_FALLING_TREE_DELAY_MS = 10000;

//------------------------------------------------------------------------------------------------
//! Request deletion of the tree
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
{
SCR_PlayerController userCtrl = SCR_PlayerController.Cast(GetGame().GetPlayerController());
if (!userCtrl)
return;

ACE_Chopping_HelperEntity helper = ACE_Chopping_HelperEntity.Cast(GetOwner());
if (!helper)
return;

Tree plant = Tree.Cast(helper.GetAssociatedPlant());
if (!plant)
return;

bool enabled;
BaseContainer container = plant.GetPrefabData().GetPrefab();

if (container && container.Get("Enabled", enabled) && enabled)
{
vector transform[4];
pUserEntity.GetWorldTransform(transform);
userCtrl.ACE_RequestDestroyEntity(plant, EDamageType.MELEE, transform);
GetGame().GetCallqueue().CallLater(userCtrl.ACE_RequestDeleteEntity, DELETE_FALLING_TREE_DELAY_MS, false, plant);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to consider is that the tree won't be deleted if client disconnects before this happens. Not a big issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I should make a request to the server instead.

}
else
{
userCtrl.ACE_RequestDeleteEntity(plant);
}

delete helper;
}
}

//------------------------------------------------------------------------------------------------
//! For entities that have no RplComponent, only local scripts will work
override bool HasLocalEffectOnlyScript()
{
return true;
}
//------------------------------------------------------------------------------------------------
//! For entities that have no RplComponent, only local scripts will work
override bool HasLocalEffectOnlyScript()
{
return true;
}
}
22 changes: 22 additions & 0 deletions addons/core/scripts/Game/ACE_Core/Player/SCR_PlayerController.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ modded class SCR_PlayerController : PlayerController
//! Called from local player
void ACE_RequestDeleteEntity(IEntity entity)
{
if (!entity)
return;

Rpc(RpcAsk_ACE_DeleteEntityByBits, ACE_EntityIdHelper.ToInt(entity.GetID()));
}

Expand All @@ -19,4 +22,23 @@ modded class SCR_PlayerController : PlayerController

manager.DeleteEntitiesByIdGlobal({EntityID.FromInt(bits[0], bits[1])});
}

//------------------------------------------------------------------------------------------------
//! Request destruction of SCR_DestructibleEntity
//! Called from local player
void ACE_RequestDestroyEntity(SCR_DestructibleEntity entity, EDamageType damageType, vector hitPosDirNorm[4])
{
Rpc(RpcAsk_ACE_DestroyEntity, entity.GetID(), damageType, hitPosDirNorm);
}

//------------------------------------------------------------------------------------------------
[RplRpc(RplChannel.Reliable, RplRcver.Server)]
protected void RpcAsk_ACE_DestroyEntity(EntityID entityID, EDamageType damageType, vector hitPosDirNorm[4])
{
SCR_DestructibleEntity entity = SCR_DestructibleEntity.Cast(GetGame().GetWorld().FindEntityByID(entityID));
if (!entity)
return;

entity.HandleDamage(damageType, entity.GetCurrentHealth(), hitPosDirNorm);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ACE_GadgetUserAction : ScriptedUserAction
int itemActionId = pAnimationComponent.BindCommand("CMD_Item_Action");
CharacterCommandHandlerComponent cmdHandler = CharacterCommandHandlerComponent.Cast(pAnimationComponent.GetCommandHandler());
if (cmdHandler)
cmdHandler.FinishItemUse();
cmdHandler.FinishItemUse(true);
}
}

Expand All @@ -79,7 +79,8 @@ class ACE_GadgetUserAction : ScriptedUserAction
{
CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
CharacterCommandHandlerComponent cmdHandler = CharacterCommandHandlerComponent.Cast(pAnimationComponent.GetCommandHandler());
cmdHandler.FinishItemUse();
if (cmdHandler)
cmdHandler.FinishItemUse(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ modded class SCR_CharacterDamageManagerComponent : SCR_DamageManagerComponent

//-----------------------------------------------------------------------------------------------------------
//! Initialize member variables
override void OnInit(IEntity owner)
override void OnPostInit(IEntity owner)
{
super.OnInit(owner);
super.OnPostInit(owner);

m_pACE_Medical_HealthHitZone = GetHitZoneByName("Health");
if (!m_pACE_Medical_HealthHitZone)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ACE_Medical_ConsumableEpinephrine : SCR_ConsumableEffectHealthItems
return false;

// Check if epinephrine is in the system already
array<ref PersistentDamageEffect> effects = damageManager.GetAllPersistentEffectsOfType(ACE_Medical_EpinephrineDamageEffect);
array<ref SCR_PersistentDamageEffect> effects = damageManager.GetAllPersistentEffectsOfType(ACE_Medical_EpinephrineDamageEffect);
if (!effects.IsEmpty())
{
failReason = SCR_EConsumableFailReason.ALREADY_APPLIED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ACE_Medical_ConsumableMorphine : SCR_ConsumableEffectHealthItems
return false;

// Check if morphine is in the system already
array<ref PersistentDamageEffect> effects = damageManager.GetAllPersistentEffectsOfType(ACE_Medical_MorphineDamageEffect);
array<ref SCR_PersistentDamageEffect> effects = damageManager.GetAllPersistentEffectsOfType(ACE_Medical_MorphineDamageEffect);
if (!effects.IsEmpty())
{
failReason = SCR_EConsumableFailReason.ALREADY_APPLIED;
Expand Down