Browse Source

system to finish using powers with new UsePowerJob

feature-config-usage
FatBoy-DOTC 2 months ago
parent
commit
0c50cd9536
  1. 44
      src/engine/jobs/WpakUsePowerJob.java
  2. 62
      src/engine/wpak/WpakPowerManager.java
  3. 1
      src/engine/wpak/data/Power.java

44
src/engine/jobs/WpakUsePowerJob.java

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.jobs;
import engine.gameManager.PowersManager;
import engine.job.AbstractScheduleJob;
import engine.net.client.msg.PerformActionMsg;
import engine.objects.AbstractWorldObject;
import engine.objects.PlayerCharacter;
import engine.powers.PowersBase;
import engine.wpak.WpakPowerManager;
import engine.wpak.data.Power;
public class WpakUsePowerJob extends AbstractScheduleJob {
private final PlayerCharacter pc;
private final PerformActionMsg msg;
private AbstractWorldObject target;
public WpakUsePowerJob(PlayerCharacter pc, PerformActionMsg msg, AbstractWorldObject tar) {
super();
this.pc = pc;
this.msg = msg;
this.target = tar;
}
@Override
protected void doJob() {
WpakPowerManager.finishUsePower(this.msg, this.pc,this.target);
}
@Override
protected void _cancelJob() {
//cast stopped early, reset recycle timer
PowersManager.finishRecycleTime(this.msg, this.pc, true);
}
}

62
src/engine/wpak/WpakPowerManager.java

@ -1,10 +1,12 @@ @@ -1,10 +1,12 @@
package engine.wpak;
import engine.InterestManagement.WorldGrid;
import engine.gameManager.*;
import engine.job.JobContainer;
import engine.job.JobScheduler;
import engine.jobs.FinishRecycleTimeJob;
import engine.jobs.UsePowerJob;
import engine.jobs.WpakUsePowerJob;
import engine.math.Vector3fImmutable;
import engine.mbEnums;
import engine.net.Dispatch;
@ -16,14 +18,14 @@ import engine.net.client.msg.UpdateStateMsg; @@ -16,14 +18,14 @@ import engine.net.client.msg.UpdateStateMsg;
import engine.objects.*;
import engine.powers.PowersBase;
import engine.server.MBServerStatics;
import engine.util.Hasher;
import engine.wpak.data.*;
import engine.wpak.data.Effect;
import engine.wpak.data.EquipmentPreReq;
import engine.wpak.data.Power;
import engine.wpak.data.PowerAction;
import org.pmw.tinylog.Logger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import static engine.math.FastMath.sqr;
@ -34,8 +36,7 @@ public class WpakPowerManager { @@ -34,8 +36,7 @@ public class WpakPowerManager {
private static JobScheduler js;
public static void usePower(final PerformActionMsg msg, ClientConnection origin,
boolean sendCastToSelf) {
public static void usePower(final PerformActionMsg msg, ClientConnection origin, boolean sendCastToSelf) {
if (ConfigManager.MB_RULESET.getValue().equals("LORE")) {
PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerUsedID());
@ -90,7 +91,7 @@ public class WpakPowerManager { @@ -90,7 +91,7 @@ public class WpakPowerManager {
}
}
public static boolean castPower(final PerformActionMsg msg, ClientConnection origin, boolean sendCastToSelf) {
private static boolean castPower(final PerformActionMsg msg, ClientConnection origin, boolean sendCastToSelf) {
//check to see if the caster is valid
PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin);
@ -293,9 +294,9 @@ public class WpakPowerManager { @@ -293,9 +294,9 @@ public class WpakPowerManager {
// run timer job to end cast
if (time < 1) // run immediately
finishUsePower(copyMsg, playerCharacter, casterLiveCounter, targetLiveCounter);
finishUsePower(copyMsg, playerCharacter, target);
else {
UsePowerJob upj = new UsePowerJob(playerCharacter, copyMsg, copyMsg.getPowerUsedID(), powerCast, casterLiveCounter, targetLiveCounter);
WpakUsePowerJob upj = new WpakUsePowerJob(playerCharacter, copyMsg, target);
JobContainer jc = js.scheduleJob(upj, time);
// make lastPower
@ -306,8 +307,51 @@ public class WpakPowerManager { @@ -306,8 +307,51 @@ public class WpakPowerManager {
return false;
}
public static void finishUsePower(PerformActionMsg msg, int castCount, int targetCount){
public static void finishUsePower(PerformActionMsg msg, PlayerCharacter caster, AbstractWorldObject target){
Power powerUsed = powers.get(msg.getPowerUsedID());
if(powerUsed == null)
return;
if(powerUsed.maxMobTargets > 1 || powerUsed.maxPlayerTargets > 1){
AoeHandler(caster, target, powerUsed);
}else{
applyAllPowerEffects(powerUsed, target);
}
}
private static void AoeHandler(PlayerCharacter caster, AbstractWorldObject target, Power powerUsed){
HashSet<AbstractWorldObject> mobTargets = new HashSet<>();
HashSet<AbstractWorldObject> pcTargets = new HashSet<>();
if(powerUsed.maxMobTargets > 0)
mobTargets = WorldGrid.getObjectsInRangePartial(target.loc,powerUsed.areaRange, MBServerStatics.MASK_MOB);
if(powerUsed.maxPlayerTargets > 0)
pcTargets = WorldGrid.getObjectsInRangePartial(target.loc,powerUsed.areaRange, MBServerStatics.MASK_PLAYER);
int count = 1;
for(AbstractWorldObject mob : mobTargets){
if(count < powerUsed.maxMobTargets + 1){
applyAllPowerEffects(powerUsed,mob);
count ++;
}else{
break;
}
}
count = 1;
for(AbstractWorldObject pc : pcTargets){
if(count < powerUsed.maxPlayerTargets + 1){
applyAllPowerEffects(powerUsed,pc);
count ++;
}else{
break;
}
}
}
public static void applyAllPowerEffects(Power power, AbstractWorldObject target){
for(ActionEntry powerAction: power.actionEntries){
Effect eff = effect_data.get(Hasher.SBStringHash(powerAction.effect_id));
if(eff == null)
continue;
//TODO add in effect application
}
}
public static void sendPowerMsg(PlayerCharacter playerCharacter, int type, PerformActionMsg msg) {

1
src/engine/wpak/data/Power.java

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
package engine.wpak.data;
import engine.mbEnums;
import engine.objects.AbstractWorldObject;
import java.util.ArrayList;
import java.util.EnumSet;

Loading…
Cancel
Save