Skip to content

Commit

Permalink
Add ACE Explosives (#80)
Browse files Browse the repository at this point in the history
* Demining Action for Landmines

Adds a Shovel prompt to disassemble landmines placed by players. Also makes landmines immune to Gunfire, in favor of this new change.

* Update - Minor Tweaks

Tweaked the UserActions to appropriately reflect the new Class

Tweaked the Radius of the Action

Moved "HasLocalEffectOnlyScript" to Chopping_UserAction from ShovelDestroyUserAction

* String table

String Table and Localization addition for the Mine Disarming action

* Minor Script Optimizations

Removed some unnecessary lines from each Script

* Update AUTHORS

Added my name to the list of Authors

* Create explosives.mdx

Add Documentation

* Create ACE_WrenchDestroyUserAction.c

* Built String Table

* Added ACE_GadgetUserAction

Changed ShovelDestroyUserAction to ShovelUserAction

Changed WrenchDestroyUserAction to WrenchUserAction

* Updated Documentation

* Removed unnecessary Script

* Optimized Prefabs and Intarg params

* Refactor code

* Revise disarming

* Rename localization files and add German translation

* Rename localization key

* Update AUTHORS

Alphabetic order

* Update explosives.mdx

Fix capitalization

* Only show action for activated mines

* Add license and thumbnail

* Change mod title

---------

Co-authored-by: Kex <[email protected]>
  • Loading branch information
DerivenLoki and Kexanone authored Dec 11, 2024
1 parent f1f0cd9 commit 2213241
Show file tree
Hide file tree
Showing 56 changed files with 776 additions and 146 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ OverlordZorn
PuFu
Skamdrept
Smith <[email protected]>
TraceSnowOwl
Zelik
1 change: 1 addition & 0 deletions addons/chopping/Prefabs/Helpers/ACE_Chopping_BaseHelper.et
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ACE_Chopping_HelperEntity {
}
UIInfo UIInfo "{611A26EA9DC95817}" {
}
m_iAnimationIndex 2
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,150 +1,31 @@
//------------------------------------------------------------------------------------------------
//! Tree deletion user action
class ACE_Chopping_UserAction : ScriptedUserAction
class ACE_Chopping_UserAction : ACE_ShovelUserAction
{
protected SCR_GadgetManagerComponent m_GadgetManager;
protected IEntity m_pUser;

//------------------------------------------------------------------------------------------------
//! 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_DeleteEntityAtPosition(plant.GetOrigin());
SCR_EntityHelper.DeleteEntityAndChildren(helper);
}

//------------------------------------------------------------------------------------------------
//! Start E-tool animation
override void OnActionStart(IEntity pUserEntity)
{
super.OnActionStart(pUserEntity);

ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
if (!character)
return;

CharacterControllerComponent charController = character.GetCharacterController();
if (charController)
{

CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
int itemActionId = pAnimationComponent.BindCommand("CMD_Item_Action");
ItemUseParameters params = new ItemUseParameters();
params.SetEntity(GetBuildingTool(pUserEntity));
params.SetAllowMovementDuringAction(false);
params.SetKeepInHandAfterSuccess(true);
params.SetCommandID(itemActionId);
params.SetCommandIntArg(2);

charController.TryUseItemOverrideParams(params);
}

m_pUser = pUserEntity;
}

//------------------------------------------------------------------------------------------------
//! End E-tool animation
override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
{
super.OnActionCanceled(pOwnerEntity, pUserEntity);

ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
if (!character)
return;

CharacterControllerComponent charController = character.GetCharacterController();
if (charController)
{
CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
int itemActionId = pAnimationComponent.BindCommand("CMD_Item_Action");
CharacterCommandHandlerComponent cmdHandler = CharacterCommandHandlerComponent.Cast(pAnimationComponent.GetCommandHandler());
if (cmdHandler)
cmdHandler.FinishItemUse();
}
}

//------------------------------------------------------------------------------------------------
//! End E-tool animation
void CancelPlayerAnimation(IEntity entity)
{
if (!entity)
return;

ChimeraCharacter character = ChimeraCharacter.Cast(entity);
if (!character)
return;

CharacterControllerComponent charController = character.GetCharacterController();
if (charController)
{
CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
CharacterCommandHandlerComponent cmdHandler = CharacterCommandHandlerComponent.Cast(pAnimationComponent.GetCommandHandler());
cmdHandler.FinishItemUse();
}
}

//------------------------------------------------------------------------------------------------
//! Get building tool entity
IEntity GetBuildingTool(notnull IEntity ent)
{
SCR_GadgetManagerComponent gadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(ent);
if (!gadgetManager)
return null;

return gadgetManager.GetHeldGadget();
}

//------------------------------------------------------------------------------------------------
//! Sets a new gadget manager. Controlled by an event when the controlled entity has changed.
void SetNewGadgetManager(IEntity from, IEntity to)
{
m_GadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(to);
}

//------------------------------------------------------------------------------------------------
//! User needs to equip the shovel for the action to show up
override bool CanBeShownScript(IEntity user)
{
if (!m_GadgetManager)
{
m_GadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(user);

SCR_PlayerController playerController = SCR_PlayerController.Cast(GetGame().GetPlayerController());
if (playerController)
playerController.m_OnControlledEntityChanged.Insert(SetNewGadgetManager);

return false;
};

if (!SCR_CampaignBuildingGadgetToolComponent.Cast(m_GadgetManager.GetHeldGadgetComponent()))
return false;

return true;
}

//------------------------------------------------------------------------------------------------
//! Trees have no RplComponent, hence only local scripts will work
override bool HasLocalEffectOnlyScript()
{
return true;
}

//------------------------------------------------------------------------------------------------
//! Destructor - End E-tool animation
void ~ACE_Chopping_UserAction()
{
CancelPlayerAnimation(m_pUser);
}
//------------------------------------------------------------------------------------------------
//! 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_DeleteEntityAtPosition(plant.GetOrigin());
SCR_EntityHelper.DeleteEntityAndChildren(helper);
}

//------------------------------------------------------------------------------------------------
//! For entities that have no RplComponent, only local scripts will work
override bool HasLocalEffectOnlyScript()
{
return true;
}
}
103 changes: 103 additions & 0 deletions addons/core/scripts/Game/ACE_Core/UserActions/ACE_GadgetUserAction.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//------------------------------------------------------------------------------------------------
//! Gadget Entity user action
class ACE_GadgetUserAction : ScriptedUserAction
{
[Attribute(defvalue: "1", desc: "Index of the gadget animation to play")]
protected int m_iAnimationIndex;

protected IEntity m_pUser;

//------------------------------------------------------------------------------------------------
//! Stop animation when action is completed
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
{
CancelPlayerAnimation(pUserEntity);
}

//------------------------------------------------------------------------------------------------
//! Start gadget animation
override void OnActionStart(IEntity pUserEntity)
{
super.OnActionStart(pUserEntity);

ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
if (!character)
return;

CharacterControllerComponent charController = character.GetCharacterController();
if (charController)
{
CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
int itemActionId = pAnimationComponent.BindCommand("CMD_Item_Action");
ItemUseParameters params = new ItemUseParameters();
params.SetEntity(GetHeldGadget(pUserEntity));
params.SetAllowMovementDuringAction(false);
params.SetKeepInHandAfterSuccess(true);
params.SetCommandID(itemActionId);
params.SetCommandIntArg(m_iAnimationIndex);

charController.TryUseItemOverrideParams(params);
}

m_pUser = pUserEntity;
}

//------------------------------------------------------------------------------------------------
//! End gadget animation
override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
{
super.OnActionCanceled(pOwnerEntity, pUserEntity);

ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
if (!character)
return;

CharacterControllerComponent charController = character.GetCharacterController();
if (charController)
{
CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
int itemActionId = pAnimationComponent.BindCommand("CMD_Item_Action");
CharacterCommandHandlerComponent cmdHandler = CharacterCommandHandlerComponent.Cast(pAnimationComponent.GetCommandHandler());
if (cmdHandler)
cmdHandler.FinishItemUse();
}
}

//------------------------------------------------------------------------------------------------
//! End gadget animation
void CancelPlayerAnimation(IEntity entity)
{
if (!entity)
return;

ChimeraCharacter character = ChimeraCharacter.Cast(entity);
if (!character)
return;

CharacterControllerComponent charController = character.GetCharacterController();
if (charController)
{
CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
CharacterCommandHandlerComponent cmdHandler = CharacterCommandHandlerComponent.Cast(pAnimationComponent.GetCommandHandler());
cmdHandler.FinishItemUse();
}
}

//------------------------------------------------------------------------------------------------
//! Get gadget entity
IEntity GetHeldGadget(notnull IEntity ent)
{
SCR_GadgetManagerComponent gadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(ent);
if (!gadgetManager)
return null;

return gadgetManager.GetHeldGadget();
}

//------------------------------------------------------------------------------------------------
//! Destructor - End Gadget animation
void ~ACE_GadgetUserAction()
{
CancelPlayerAnimation(m_pUser);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//------------------------------------------------------------------------------------------------
//! Shovel Entity user action
class ACE_ShovelUserAction : ACE_GadgetUserAction
{
//------------------------------------------------------------------------------------------------
//! User needs to equip the shovel for the action to show up
override bool CanBeShownScript(IEntity user)
{
IEntity gadget = GetHeldGadget(user);
if (!gadget)
return false;

if (!gadget.FindComponent(SCR_CampaignBuildingGadgetToolComponent))
return false;

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//------------------------------------------------------------------------------------------------
//! Wrench Entity user action
class ACE_WrenchUserAction : ACE_GadgetUserAction
{
//------------------------------------------------------------------------------------------------
//! User needs to equip the wrench for the action to show up
override bool CanBeShownScript(IEntity user)
{
IEntity gadget = GetHeldGadget(user);
if (!gadget)
return false;

if (!gadget.FindComponent(SCR_RepairSupportStationComponent))
return false;

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
StringTableRuntime {
Ids {
"ACE-Explosives_DisarmUserAction_Name"
}
Texts {
"Disarm"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
StringTableRuntime {
Ids {
"ACE-Explosives_DisarmUserAction_Name"
}
Texts {
"Entschärfen"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
StringTableRuntime {
Ids {
"ACE-Explosives_DisarmUserAction_Name"
}
Texts {
"Disarm"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
StringTableRuntime {
Ids {
"ACE-Explosives_DisarmUserAction_Name"
}
Texts {
"Disarm"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
StringTableRuntime {
Ids {
"ACE-Explosives_DisarmUserAction_Name"
}
Texts {
"Disarm"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
StringTableRuntime {
Ids {
"ACE-Explosives_DisarmUserAction_Name"
}
Texts {
"Disarm"
}
}
Loading

0 comments on commit 2213241

Please sign in to comment.