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

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

@ -306,68 +306,6 @@ public class CombatUtilities { @@ -306,68 +306,6 @@ public class CombatUtilities {
swingIsBlock(agent, target, passiveAnim);
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);
if (agent.getWeaponPower() != null)

Loading…
Cancel
Save