Hi
I’m trying to implement an attack system into sim-eth-es and wondering how to go about this. I’m not looking for actual code examples, I’d like to try to figure that out myself. I am however, wondering about the architecture:
I figure it would be reasonable to implement, much in the same manner as shipdriver, a shipattacker, to keep track of each players attacks (could be cooldowns, buffs and what-nots). However, I am stumped trying to figure out how the update-method of shipdriver fits into the mechanisms of the network systems. I can see that’s the method that actually does stuff, so my own new system would have a different signature and would be called by a different kind of service. Any idea how you would go about doing this or just sketchy thoughts?
PlayerMovementState.java
@Override
public void valueChanged( FunctionId func, InputState value, double tpf ) {
// Change the speed based on the current run mode
// Another option would have been to use the value
// directly:
// speed = 3 + value.asNumber() * 5
//...but I felt it was slightly less clear here.
boolean b = value == InputState.Positive;
if( func == PlayerMovementFunctions.F_BOOST ) {
if( b ) {
speed = 10;
} else {
speed = 3;
}
} else if (func == ShipFunctions.F_SHOOT) {
if (b) {
session.shoot(spatial.getLocalRotation(), spatial.getLocalTranslation());
}
}
}
I figure the only thing to send from the client, in the controlstate, is a ‘shoot’-command to the server session, sending the position and rotation of the player. Then the server (to avoid cheating) would apply buffs/debuffs/cooldowns etc that may be in effect (or even block the attack entirely if no attack is possible) and create the attack.The attack would generate a (potentially projectile) entity (carrying information on player-origin, model, damage, velocity, rotation, position) that defines the attack.
GameSessionHostedService.java
@Override
public void shoot( Quaternion rotation, Vector3f position ){
if (log.isTraceEnabled()) {
log.trace("shoot(" + rotation+"," + position +")");
}
//Forward to game world
shipAttacker.applyAttack(rotation, position);
}
Any thoughts are appreciated