Browse Source

mob casting logic upgrade

master
FatBoy-DOTC 2 years ago
parent
commit
15580f478f
  1. 62
      src/engine/ai/MobileFSM.java
  2. 62
      src/engine/ai/utilities/CombatUtilities.java

62
src/engine/ai/MobileFSM.java

@ -30,11 +30,8 @@ import engine.powers.PowersBase;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -477,7 +474,12 @@ public class MobileFSM {
aiAgent.setState(STATE.Patrol); aiAgent.setState(STATE.Patrol);
return; return;
} }
if(canCast(aiAgent) == true){
if(MobCast(aiAgent) == false) {
attack(aiAgent, targetID);
}
}
else
if (CombatUtilities.inRangeToAttack(aiAgent, aggroTarget)) { if (CombatUtilities.inRangeToAttack(aiAgent, aggroTarget)) {
aiAgent.setState(STATE.Attack); aiAgent.setState(STATE.Attack);
attack(aiAgent, targetID); attack(aiAgent, targetID);
@ -602,7 +604,9 @@ public class MobileFSM {
return; return;
} }
if(canCast(aiAgent) == true){ if(canCast(aiAgent) == true){
MobCast(aiAgent); if(MobCast(aiAgent) == false) {
handlePlayerAttackForMob(aiAgent, player);
}
} }
else { else {
handlePlayerAttackForMob(aiAgent, player); handlePlayerAttackForMob(aiAgent, player);
@ -1665,7 +1669,9 @@ public class MobileFSM {
return; return;
} }
if(canCast(aiAgent) == true){ if(canCast(aiAgent) == true){
MobCast(aiAgent); if(MobCast(aiAgent) == false) {
handlePlayerAttackForMob(aiAgent, player);
}
} }
else { else {
handlePlayerAttackForMob(aiAgent, player); handlePlayerAttackForMob(aiAgent, player);
@ -1753,32 +1759,42 @@ public class MobileFSM {
} }
public static boolean canCast(Mob mob){ public static boolean canCast(Mob mob){
if(mob == null || mob.mobPowers.isEmpty() || mob.nextCastTime > System.currentTimeMillis()){ if(mob == null || mob.mobPowers.isEmpty() == true || mob.nextCastTime > System.currentTimeMillis()){
return false; return false;
} }
else{ else{
return true; return true;
} }
} }
public static void MobCast(Mob mob){ public static boolean MobCast(Mob mob){
if(mob.getMobBase().getFlags().contains(Enum.MobFlagType.CALLSFORHELP)){ if(mob.getMobBase().getFlags().contains(Enum.MobFlagType.CALLSFORHELP)){
MobCallForHelp(mob); MobCallForHelp(mob);
} }
PlayerCharacter target = (PlayerCharacter)mob.getCombatTarget(); PlayerCharacter target = (PlayerCharacter)mob.getCombatTarget();
Random rand = new Random(); int random = ThreadLocalRandom.current().nextInt(mob.mobPowers.size() * 2);
int powerPos = rand.nextInt(mob.mobPowers.size()); int powerToken = 0;
int spellId = mob.mobPowers.get(powerPos); int powerRank = 0;
PowersBase mobPower = PowersManager.getPowerByToken(spellId); Map<Integer,Integer> entries = mob.mobPowers;
if(CombatUtilities.inRangeToCast2D(mob, mob.getCombatTarget(),mobPower)) { int count = -1;
PerformActionMsg msg = PowersManager.createPowerMsg(mobPower, 40, mob, target); for(Map.Entry<Integer,Integer> entry : entries.entrySet())
msg.setUnknown04(2); {
PowersManager.finishUseMobPower(msg, mob, 0, 0); count += 1;
mob.setLastMobPowerToken(0); if(count == random)
mob.setIsCasting(false); {
mob.nextCastTime = System.currentTimeMillis() + mobPower.getCooldown(); powerToken = entry.getKey();
}else{ powerRank = entry.getValue();
MovementUtilities.moveToLocation(mob,mob.getCombatTarget().getLoc(),mobPower.getRange()); PowersBase mobPower = PowersManager.getPowerByToken(powerToken);
if(CombatUtilities.inRangeToCast2D(mob, mob.getCombatTarget(),mobPower)) {
//PowersManager.useMobPower(mob,(AbstractCharacter)mob.getCombatTarget(),mobPower,powerRank);
PerformActionMsg msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, target);
msg.setUnknown04(2);
PowersManager.finishUseMobPower(msg, mob, 0, 0);
mob.nextCastTime = System.currentTimeMillis() + (mobPower.getCooldown() * 1000);
return true;
}
} }
}
return false;
} }
public static void MobCallForHelp(Mob mob){ public static void MobCallForHelp(Mob mob){
Zone mobCamp = mob.getParentZone(); Zone mobCamp = mob.getParentZone();

62
src/engine/ai/utilities/CombatUtilities.java

@ -306,68 +306,6 @@ public class CombatUtilities {
swingIsBlock(agent, target, passiveAnim); swingIsBlock(agent, target, passiveAnim);
return; return;
} }
else
//check for a cast here?
//agent.mobPowers = DbManager.MobBaseQueries.LOAD_STATIC_POWERS(agent.getMobBaseID());
if(agent.mobPowers.size() > 0 && agent.mobPowers != null)
{
//get cast chance 33% cast 67% mele
int random = ThreadLocalRandom.current().nextInt(agent.mobPowers.size() * 10);
//allow casting of spell
if(random <= agent.mobPowers.size())
{
int powerToken;
int powerRank;
//cast a spell
Map<Integer,Integer> entries = agent.mobPowers;
int count = 0;
for(Map.Entry<Integer,Integer> entry : entries.entrySet())
{
count += 1;
if(count == random)
{
powerToken = entry.getKey();
//powerRank = entry.getValue();
switch(agent.getLevel())
{
default:
powerRank = 1;
break;
case 10:
powerRank = 5;
break;
case 20:
powerRank = 10;
break;
case 30:
powerRank = 15;
break;
case 40:
powerRank = 25;
break;
case 50:
powerRank = 30;
break;
case 60:
powerRank = 35;
break;
case 70:
powerRank = 40;
break;
}
//System.out.println(agent.getMobBase().getFirstName() + " is casting: " + PowersManager.getPowerByToken(powerToken).skillName);
PowersManager.applyPower(agent,target,target.getLoc(),powerToken,powerRank, false);
//PerformActionMsg msg = new PerformActionMsg();
//PowersManager.sendPowerMsg((PlayerCharacter)target,0,msg);
//return;
}
}
return;
}
}
//finished with casting check
swingIsDamage(agent,target, determineDamage(agent,target, mainHand, speed, dt), anim); swingIsDamage(agent,target, determineDamage(agent,target, mainHand, speed, dt), anim);
if (agent.getWeaponPower() != null) if (agent.getWeaponPower() != null)

Loading…
Cancel
Save