Implemented target entity id and Vector2 into casting events

This commit is contained in:
Collin Smith
2020-08-29 01:47:08 -07:00
parent 51de82df58
commit d7c4d478a8
8 changed files with 73 additions and 38 deletions

View File

@ -83,11 +83,11 @@ public class CursorMovementSystem extends BaseSystem {
if (Gdx.input.isButtonPressed(Input.Buttons.LEFT) && UIUtils.shift()) {
setTarget(renderer.getSrc(), Engine.INVALID_ENTITY);
iso.agg(tmpVec2.set(Gdx.input.getX(), Gdx.input.getY())).unproject().toWorld();
actioneer.cast(renderer.getSrc(), Riiablo.charData.getAction(Input.Buttons.LEFT), tmpVec2);
actioneer.cast(renderer.getSrc(), Riiablo.charData.getAction(Input.Buttons.LEFT), Engine.INVALID_ENTITY, tmpVec2);
} else if (Gdx.input.isButtonPressed(Input.Buttons.RIGHT)) {
setTarget(renderer.getSrc(), Engine.INVALID_ENTITY);
iso.agg(tmpVec2.set(Gdx.input.getX(), Gdx.input.getY())).unproject().toWorld();
actioneer.cast(renderer.getSrc(), Riiablo.charData.getAction(Input.Buttons.RIGHT), tmpVec2);
actioneer.cast(renderer.getSrc(), Riiablo.charData.getAction(Input.Buttons.RIGHT), Engine.INVALID_ENTITY, tmpVec2);
} else {
updateLeft();
}
@ -134,7 +134,7 @@ public class CursorMovementSystem extends BaseSystem {
interactable.interactor.interact(src, targetId);
} else if (interactable == null) { // TODO: change to check targetability of targetId
setTarget(src, Engine.INVALID_ENTITY);
actioneer.cast(src, Riiablo.charData.getAction(Input.Buttons.LEFT), targetId);
actioneer.cast(src, Riiablo.charData.getAction(Input.Buttons.LEFT), targetId, targetPos);
}
}
}

View File

@ -22,7 +22,8 @@ public class SkillCastHandler extends PassiveSystem {
@Subscribe
public void srvstfunc(SkillStartEvent event) {
log.traceEntry("srvstfunc(entityId: {}, srvstfunc: {})", event.entityId, event.srvstfunc);
log.traceEntry("srvstfunc(entityId: {}, srvstfunc: {}, targetId: {}, targetVec: {})",
event.entityId, event.srvstfunc, event.targetId, event.targetVec);
switch (event.srvstfunc) {
case 0:
break;
@ -34,7 +35,8 @@ public class SkillCastHandler extends PassiveSystem {
@Subscribe
public void srvdofunc(SkillDoEvent event) {
log.traceEntry("srvdofunc(entityId: {}, srvdofunc: {})", event.entityId, event.srvdofunc);
log.traceEntry("srvdofunc(entityId: {}, srvdofunc: {}, targetId: {}, targetVec: {})",
event.entityId, event.srvdofunc, event.targetId, event.targetVec);
switch (event.srvdofunc) {
case 0:
break;
@ -51,7 +53,8 @@ public class SkillCastHandler extends PassiveSystem {
@Subscribe
public void cltstfunc(SkillStartEvent event) {
log.traceEntry("cltstfunc(entityId: {}, cltstfunc: {})", event.entityId, event.cltstfunc);
log.traceEntry("cltstfunc(entityId: {}, cltstfunc: {}, targetId: {}, targetVec: {})",
event.entityId, event.cltstfunc, event.targetId, event.targetVec);
final Skills.Entry skill = Riiablo.files.skills.get(event.skillId);
Riiablo.audio.play(skill.stsound, true);
@ -76,7 +79,8 @@ public class SkillCastHandler extends PassiveSystem {
@Subscribe
public void cltdofunc(SkillDoEvent event) {
log.traceEntry("cltdofunc(entityId: {}, cltdofunc: {})", event.entityId, event.cltdofunc);
log.traceEntry("cltdofunc(entityId: {}, cltdofunc: {}, targetId: {}, targetVec: {})",
event.entityId, event.cltdofunc, event.targetId, event.targetVec);
final Skills.Entry skill = Riiablo.files.skills.get(event.skillId);
Riiablo.audio.play(skill.dosound, true);

View File

@ -47,11 +47,13 @@ public class Actioneer extends PassiveSystem {
return true;
}
public void cast(int entityId, int skillId, Vector2 targetVec) {
public void cast(int entityId, int skillId, int targetId, Vector2 targetVec) {
if (!canCast(entityId)) return;
final Skills.Entry skill = Riiablo.files.skills.get(skillId);
log.traceEntry("cast(entityId: {}, skillId: {} ({}))", entityId, skillId, skill);
log.traceEntry("cast(entityId: {}, skillId: {} ({}), targetId: {}, targetVec: {})",
entityId, skillId, skill, targetId, targetVec);
targetVec = targetVec != null ? targetVec.cpy() : Vector2.Zero;
final Class.Type type = mClass.get(entityId).type;
byte mode = (byte) type.getMode(skill.anim);
log.trace("mode: {}", mode);
@ -60,32 +62,28 @@ public class Actioneer extends PassiveSystem {
log.trace("mode changed to {} because it was invalid", mode);
}
if (!targetVec.isZero()) {
Vector2 entityPos = mPosition.get(entityId).position;
mAngle.get(entityId).target.set(targetVec).sub(entityPos).nor();
}
mSequence.create(entityId).sequence(mode, mMovementModes.get(entityId).NU);
mCasting.create(entityId).set(skillId, targetVec);
events.dispatch(SkillCastEvent.obtain(entityId, skillId));
mCasting.create(entityId).set(skillId, targetId, targetVec);
events.dispatch(SkillCastEvent.obtain(entityId, skillId, targetId, targetVec));
srvstfunc(entityId, skill.srvstfunc, targetVec);
events.dispatch(SkillStartEvent.obtain(entityId, skillId, skill.srvstfunc, skill.cltstfunc));
}
public void cast(int entityId, int skillId, int targetId) {
Vector2 targetVec = mPosition.get(targetId).position;
cast(entityId, skillId, targetVec);
srvstfunc(entityId, skill.srvstfunc, targetId, targetVec);
events.dispatch(SkillStartEvent.obtain(entityId, skillId, targetId, targetVec, skill.srvstfunc, skill.cltstfunc));
}
@Subscribe
public void onAnimDataKeyframe(AnimDataKeyframeEvent event) {
if (!mCasting.has(event.entityId)) return;
log.traceEntry("onAnimDataKeyframe(entityId: {}, keyframe: {} ({}))", event.entityId, event.keyframe, Engine.getKeyframe(event.keyframe));
log.traceEntry("onAnimDataKeyframe(entityId: {}, keyframe: {} ({}))",
event.entityId, event.keyframe, Engine.getKeyframe(event.keyframe));
final Casting casting = mCasting.get(event.entityId);
final Skills.Entry skill = Riiablo.files.skills.get(casting.skillId);
srvdofunc(event.entityId, skill.srvdofunc, casting.target);
events.dispatch(SkillDoEvent.obtain(event.entityId, casting.skillId, skill.srvdofunc, skill.cltdofunc));
srvdofunc(event.entityId, skill.srvdofunc, casting.targetId, casting.targetVec);
events.dispatch(SkillDoEvent.obtain(
event.entityId, casting.skillId,
casting.targetId, casting.targetVec,
skill.srvdofunc, skill.cltdofunc));
}
@Subscribe
@ -95,8 +93,9 @@ public class Actioneer extends PassiveSystem {
mCasting.remove(event.entityId);
}
private void srvstfunc(int entityId, int srvstfunc, Vector2 target) {
log.traceEntry("srvstfunc(entityId: {}, srvstfunc: {})", entityId, srvstfunc);
private void srvstfunc(int entityId, int srvstfunc, int targetId, Vector2 targetVec) {
log.traceEntry("srvstfunc(entityId: {}, srvstfunc: {}, targetId: {}, targetVec: {})",
entityId, srvstfunc, targetId, targetVec);
switch (srvstfunc) {
case 0:
break;
@ -109,17 +108,18 @@ public class Actioneer extends PassiveSystem {
}
}
private void srvdofunc(int entityId, int srvdofunc, Vector2 target) {
log.traceEntry("srvdofunc(entityId: {}, srvdofunc: {})", entityId, srvdofunc);
private void srvdofunc(int entityId, int srvdofunc, int targetId, Vector2 targetVec) {
log.traceEntry("srvdofunc(entityId: {}, srvdofunc: {}, targetId: {}, targetVec: {})",
entityId, srvdofunc, targetId, targetVec);
switch (srvdofunc) {
case 0:
break;
case 1: // attack
break;
case 27: // teleport
mPosition.get(entityId).position.set(target);
mPosition.get(entityId).position.set(targetVec);
Box2DBody box2dWrapper = mBox2DBody.get(entityId);
if (box2dWrapper != null) box2dWrapper.body.setTransform(target, 0);
if (box2dWrapper != null) box2dWrapper.body.setTransform(targetVec, 0);
break;
default:
log.warn("Unsupported srvdofunc({}) for {}", srvdofunc, entityId);

View File

@ -1,24 +1,31 @@
package com.riiablo.engine.server.component;
import com.artemis.PooledComponent;
import com.artemis.annotations.EntityId;
import com.artemis.annotations.PooledWeaver;
import com.badlogic.gdx.math.Vector2;
import com.riiablo.engine.Engine;
@PooledWeaver
public class Casting extends PooledComponent {
public final Vector2 target = new Vector2();
public int skillId = -1;
@EntityId
public int targetId;
public final Vector2 targetVec = new Vector2();
public Casting set(int skillId, Vector2 target) {
public Casting set(int skillId, int targetId, Vector2 targetVec) {
this.skillId = skillId;
this.target.set(target);
this.targetId = targetId;
this.targetVec.set(targetVec);
return this;
}
@Override
protected void reset() {
skillId = -1;
target.setZero();
targetId = Engine.INVALID_ENTITY;
targetVec.setZero();
}
}

View File

@ -3,15 +3,22 @@ package com.riiablo.engine.server.event;
import com.artemis.annotations.EntityId;
import net.mostlyoriginal.api.event.common.Event;
import com.badlogic.gdx.math.Vector2;
public class SkillCastEvent implements Event {
@EntityId
public int entityId;
public int skillId;
@EntityId
public int targetId;
public Vector2 targetVec;
public static SkillCastEvent obtain(int entityId, int skillId) {
public static SkillCastEvent obtain(int entityId, int skillId, int targetId, Vector2 targetVec) {
SkillCastEvent event = new SkillCastEvent();
event.entityId = entityId;
event.skillId = skillId;
event.targetId = targetId;
event.targetVec = targetVec;
return event;
}
}

View File

@ -3,17 +3,25 @@ package com.riiablo.engine.server.event;
import com.artemis.annotations.EntityId;
import net.mostlyoriginal.api.event.common.Event;
import com.badlogic.gdx.math.Vector2;
public class SkillDoEvent implements Event {
@EntityId
public int entityId;
public int skillId;
@EntityId
public int targetId;
public Vector2 targetVec;
public int srvdofunc;
public int cltdofunc;
public static SkillDoEvent obtain(int entityId, int skillId, int srvdofunc, int cltdofunc) {
public static SkillDoEvent obtain(
int entityId, int skillId, int targetId, Vector2 targetVec, int srvdofunc, int cltdofunc) {
SkillDoEvent event = new SkillDoEvent();
event.entityId = entityId;
event.skillId = skillId;
event.targetId = targetId;
event.targetVec = targetVec;
event.srvdofunc = srvdofunc;
event.cltdofunc = cltdofunc;
return event;

View File

@ -3,17 +3,25 @@ package com.riiablo.engine.server.event;
import com.artemis.annotations.EntityId;
import net.mostlyoriginal.api.event.common.Event;
import com.badlogic.gdx.math.Vector2;
public class SkillStartEvent implements Event {
@EntityId
public int entityId;
public int skillId;
@EntityId
public int targetId;
public Vector2 targetVec;
public int srvstfunc;
public int cltstfunc;
public static SkillStartEvent obtain(int entityId, int skillId, int srvstfunc, int cltstfunc) {
public static SkillStartEvent obtain(
int entityId, int skillId, int targetId, Vector2 targetVec, int srvstfunc, int cltstfunc) {
SkillStartEvent event = new SkillStartEvent();
event.entityId = entityId;
event.skillId = skillId;
event.targetId = targetId;
event.targetVec = targetVec;
event.srvstfunc = srvstfunc;
event.cltstfunc = cltstfunc;
return event;

View File

@ -16,6 +16,7 @@ import com.badlogic.gdx.utils.Disposable;
import com.riiablo.Riiablo;
import com.riiablo.codec.DC6;
import com.riiablo.engine.Engine;
import com.riiablo.engine.client.event.InteractEvent;
import com.riiablo.engine.server.Actioneer;
import com.riiablo.widget.Button;
@ -92,7 +93,7 @@ public class MobileControls extends WidgetGroup implements Disposable {
HotkeyButton actor = (HotkeyButton) event.getListenerActor();
final int skillId = actor.getSkill();
if (skillId == -1) return;
actioneer.cast(Riiablo.game.player, skillId, Vector2.Zero);
actioneer.cast(Riiablo.game.player, skillId, Engine.INVALID_ENTITY, Vector2.Zero);
// TODO: above target is placeholder
}
};