Suggested Trap Module

Benjamin Amos

New Member
Traps module:
Purpose:
The purpose of the traps module is to provide traps to damage and ensnare both player and non-player characters. In this instance, a trap is a block which stops or slows the triggering entity as well as in some cases dealing damage over time to it or damaging it when movement is made.

Potential traps:

Quicksand: when this is entered the triggering entity becomes stuck and slowly sinks downwards. The trap deals no damage but it is a pain to get out of (jump at a rapid pace to escape).
Animal trap: if caught in this, an animal will be stuck as it takes damage from it (even more if it tries to escape). This trap can also however trap the player if they are not careful.
Glue (or any sticky substance): if an entity is stuck in this then they will not be able to move for 2 seconds.
Hanging trap: a nasty trap where if an entity falls into it then they will gradually lose health over time (1 heart every second) until death.

Structure:
Components:
TrapComponent:
Variables:
public int damageInterval
public bool damageOnStruggle
public bool paralysis
public int trapDuration​
Notes:
  • If you do not want any harm to be caused at intervals then set damageInterval to -1.
  • If you do not want the trappable entity to be harmed by struggling against the trap then set damageOnStruggle to false.
  • If the variable paralysis is true then the player will be paralysed until the duration specifed in trapDuration has elasped.
  • The variable trapDuration is how long in seconds the entity will be stuck in the trap. Set it to -1 to make them be stuck there forever (until death).

DamageOnMovementComponent:
Variables:
private Vector3f originalPosition​
Notes:
The originalPosition variable is for applying total paralysis to the trapped entity based on the paralysis variable in the trap component as well as allowing the changes in position to be tracked.​

Systems:
TrapSystem:
Variables:

Methods:

Notes:
  • This system controls the traps and when they are triggered.
  • The tracking of trappable entities and when they have entered a trap can be done with the OnEnterBlock event.​
  • When a trap is triggered by an entity then an immediate effect may be applied to it as well as some components being added for effects over a longer duration (if there are any). One of the components added could be the DamageOverTimeComponent from the AlterationEffects module. Another one could be the DamageOnMovementComponent (in this module).​
  • This system will handle the DamageOnMovementComponents by sending a OnDamage event when the player moves (unless he is immobile).​

Events:
TriggerTrap:
Variables:
TrapComponent trapToTrigger​
Notes:
This can be called to force a trap on a player regardless of where they are.​

(Optional: a ReleaseTrap event could be added)​

Extensibility:

This module could be extended by adding more traps through the usage of the TrapComponent on prefabs.
Any existing prefab could become a trap just by adding a TrapComponent to it.

Example:
Code:
{
   "name": "HangingTrap"
   "Trap": {
     "damageInterval": 1,
     "damageOnStruggle": true,
     "paralysis": true,
     "trapDuration": -1
   }
}
 
Top