mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-07-31 01:15:57 -04:00
more work on AI, added odb for object id(should hopefully fix object id duplicates), fixed tons of bugs
This commit is contained in:
@@ -32,16 +32,24 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import org.python.core.Py;
|
||||
|
||||
import resources.common.collidables.CollidableCircle;
|
||||
import resources.datatables.Options;
|
||||
import resources.datatables.PvpStatus;
|
||||
import resources.objects.cell.CellObject;
|
||||
import resources.objects.creature.CreatureObject;
|
||||
import resources.objects.tangible.TangibleObject;
|
||||
import resources.objects.weapon.WeaponObject;
|
||||
import services.ai.AIActor;
|
||||
import services.ai.LairActor;
|
||||
import engine.resources.container.CreatureContainerPermissions;
|
||||
import engine.resources.scene.Planet;
|
||||
import engine.resources.scene.Point3D;
|
||||
import engine.resources.scene.Quaternion;
|
||||
@@ -54,7 +62,8 @@ public class SpawnService {
|
||||
private Map<String, MobileTemplate> mobileTemplates = new ConcurrentHashMap<String, MobileTemplate>();
|
||||
private Map<String, LairGroupTemplate> lairGroupTemplates = new ConcurrentHashMap<String, LairGroupTemplate>();
|
||||
private Map<String, LairTemplate> lairTemplates = new ConcurrentHashMap<String, LairTemplate>();
|
||||
|
||||
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(4);
|
||||
|
||||
public SpawnService(NGECore core) {
|
||||
this.core = core;
|
||||
for(Planet planet : core.terrainService.getPlanetList()) {
|
||||
@@ -62,41 +71,169 @@ public class SpawnService {
|
||||
}
|
||||
}
|
||||
|
||||
public void spawnCreature(String template, float x, float y, float z) {
|
||||
spawnCreature(template, new Point3D(x, y, z));
|
||||
}
|
||||
|
||||
public void spawnCreature(String template, Point3D position) {
|
||||
public CreatureObject spawnCreature(String template, String planetName, long cellId, float x, float y, float z, float qW, float qX, float qY, float qZ, short level) {
|
||||
|
||||
Planet planet = core.terrainService.getPlanetByName(planetName);
|
||||
MobileTemplate mobileTemplate = mobileTemplates.get(template);
|
||||
if(planet == null || mobileTemplate == null)
|
||||
return null;
|
||||
|
||||
CellObject cell = null;
|
||||
|
||||
if(cellId != 0) {
|
||||
cell = (CellObject) core.objectService.getObject(cellId);
|
||||
if(cell == null)
|
||||
return null;
|
||||
}
|
||||
|
||||
CreatureObject creature = (CreatureObject) core.objectService.createObject(mobileTemplate.getTemplates().get(new Random().nextInt(mobileTemplate.getTemplates().size())), 0, planet, new Point3D(x, y, z), new Quaternion(qW, qX, qY, qZ));
|
||||
|
||||
if(creature == null)
|
||||
return null;
|
||||
|
||||
TangibleObject inventory = (TangibleObject) core.objectService.createObject("object/tangible/inventory/shared_character_inventory.iff", creature.getPlanet());
|
||||
inventory.setContainerPermissions(CreatureContainerPermissions.CREATURE_CONTAINER_PERMISSIONS);
|
||||
|
||||
|
||||
/*if(mobileTemplate.getCustomWeapon() != null) {
|
||||
creature.addObjectToEquipList(mobileTemplate.getCustomWeapon());
|
||||
creature.add(mobileTemplate.getCustomWeapon());
|
||||
creature.setWeaponId(mobileTemplate.getCustomWeapon().getObjectID());
|
||||
}*/
|
||||
|
||||
creature.setOptionsBitmask(mobileTemplate.getOptionBitmask());
|
||||
creature.setPvPBitmask(mobileTemplate.getPvpBitmask());
|
||||
int difficulty = mobileTemplate.getDifficulty();
|
||||
creature.setDifficulty((byte) difficulty);
|
||||
if(level != -1)
|
||||
creature.setLevel(level);
|
||||
else
|
||||
creature.setLevel(mobileTemplate.getLevel());
|
||||
WeaponObject defaultWeapon = (WeaponObject) core.objectService.createObject("object/weapon/creature/shared_creature_default_weapon.iff", creature.getPlanet());
|
||||
defaultWeapon.setAttackSpeed(2);
|
||||
defaultWeapon.setDamageType("@obj_attr_n:armor_eff_kinetic");
|
||||
defaultWeapon.setStringAttribute("cat_wpn_damage.damage", "0-0");
|
||||
if(mobileTemplate.getMaxDamage() != 0) {
|
||||
defaultWeapon.setMaxDamage(mobileTemplate.getMaxDamage());
|
||||
defaultWeapon.setMinDamage(mobileTemplate.getMinDamage());
|
||||
} else {
|
||||
defaultWeapon.setMaxDamage(creature.getLevel() * 24);
|
||||
defaultWeapon.setMinDamage(creature.getLevel() * 22);
|
||||
}
|
||||
creature.addObjectToEquipList(defaultWeapon);
|
||||
creature.add(defaultWeapon);
|
||||
creature.addObjectToEquipList(inventory);
|
||||
creature.add(inventory);
|
||||
|
||||
int customHealth = mobileTemplate.getHealth();
|
||||
if(difficulty > 0 && customHealth == 0) {
|
||||
if(difficulty == 1) {
|
||||
creature.setMaxHealth((int) (400 + level * 134 * 2.5));
|
||||
creature.setHealth((int) (400 + level * 134 * 2.5));
|
||||
creature.setMaxAction((int) (400 + level * 134 * 2.5));
|
||||
creature.setAction((int) (400 + level * 134 * 2.5));
|
||||
} else if(difficulty == 2) {
|
||||
creature.setMaxHealth((int) (400 + level * 134 * 10));
|
||||
creature.setHealth((int) (400 + level * 134 * 10));
|
||||
creature.setMaxAction((int) (400 + level * 134 * 10));
|
||||
creature.setAction((int) (400 + level * 134 * 10));
|
||||
}
|
||||
} else if(difficulty <= 0 && customHealth == 0) {
|
||||
creature.setMaxHealth((int) (400 + level * 134));
|
||||
creature.setHealth((int) (400 + level * 134));
|
||||
creature.setMaxAction((int) (400 + level * 134));
|
||||
creature.setAction((int) (400 + level * 134));
|
||||
} else {
|
||||
creature.setMaxHealth(customHealth);
|
||||
creature.setHealth(customHealth);
|
||||
creature.setMaxAction((int) (level * 128));
|
||||
creature.setAction((int) (level * 128));
|
||||
}
|
||||
|
||||
if(creature.getLevel() > 16) {
|
||||
int armor = (creature.getLevel() - 16) * 87;
|
||||
if(armor > 6000)
|
||||
armor = 6000;
|
||||
core.skillModService.addSkillMod(creature, "expertise_innate_protection_all", armor);
|
||||
}
|
||||
|
||||
AIActor actor = new AIActor(creature, creature.getPosition(), scheduler);
|
||||
creature.setAttachment("AI", actor);
|
||||
actor.setMobileTemplate(mobileTemplate);
|
||||
|
||||
|
||||
if(cell == null) {
|
||||
core.simulationService.add(creature, x, z, true);
|
||||
} else {
|
||||
creature.getPosition().setCell(cell);
|
||||
cell.add(creature);
|
||||
}
|
||||
return creature;
|
||||
}
|
||||
|
||||
public void spawnLair(String lairSpawnTemplate, Planet planet, Point3D position, int level) {
|
||||
public CreatureObject spawnCreature(String mobileTemplate, String planetName, long cellId, float x, float y, float z) {
|
||||
return spawnCreature(mobileTemplate, planetName, cellId, x, y, z, 1, 0, 0, 0, (short) -1);
|
||||
}
|
||||
|
||||
public CreatureObject spawnCreature(String mobileTemplate, String planetName, long cellId, float x, float y, float z, short level) {
|
||||
return spawnCreature(mobileTemplate, planetName, cellId, x, y, z, 1, 0, 0, 0, level);
|
||||
}
|
||||
|
||||
public CreatureObject spawnCreature(String mobileTemplate, String planetName, long cellId, float x, float z) {
|
||||
Planet planet = core.terrainService.getPlanetByName(planetName);
|
||||
return spawnCreature(mobileTemplate, planetName, cellId, x, core.terrainService.getHeight(planet.getID(), x, z), z, 1, 0, 0, 0, (short) -1);
|
||||
}
|
||||
|
||||
public CreatureObject spawnCreature(String mobileTemplate, String planetName, long cellId, float x, float z, short level) {
|
||||
Planet planet = core.terrainService.getPlanetByName(planetName);
|
||||
return spawnCreature(mobileTemplate, planetName, cellId, x, core.terrainService.getHeight(planet.getID(), x, z), z, 1, 0, 0, 0, level);
|
||||
}
|
||||
|
||||
|
||||
public LairActor spawnLair(String lairSpawnTemplate, Planet planet, Point3D position, short level) {
|
||||
|
||||
LairTemplate lairTemplate = lairTemplates.get(lairSpawnTemplate);
|
||||
if(lairTemplate == null)
|
||||
return;
|
||||
return null;
|
||||
TangibleObject lairObject = (TangibleObject) core.objectService.createObject(lairTemplate.getLairCRC(), 0, planet, position, new Quaternion(1, 0, 0, 0));
|
||||
|
||||
if(lairObject == null)
|
||||
return;
|
||||
return null;
|
||||
|
||||
lairObject.setOptionsBitmask(Options.ATTACKABLE);
|
||||
lairObject.setPvPBitmask(PvpStatus.Attackable);
|
||||
lairObject.setMaxDamage(1000 * level);
|
||||
|
||||
LairActor lairActor = new LairActor(lairObject, lairTemplate.getMobileName());
|
||||
LairActor lairActor = new LairActor(lairObject, lairTemplate.getMobileName(), 10, level);
|
||||
lairObject.setAttachment("AI", lairActor);
|
||||
|
||||
core.simulationService.add(lairObject, position.x, position.z, true);
|
||||
lairActor.spawnNewCreatures();
|
||||
|
||||
return lairActor;
|
||||
|
||||
}
|
||||
|
||||
public void loadMobileTemplates() {
|
||||
|
||||
Path p = Paths.get("scripts/mobiles");
|
||||
FileVisitor<Path> fv = new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
if(!file.toString().contains("lairs") && !file.toString().contains("spawnareas") && !file.toString().contains("lairgroups"))
|
||||
core.scriptService.callScript(file.toString().replace(file.getFileName().toString(), ""), file.getFileName().toString().replace(".py", ""), "addTemplate", core);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
};
|
||||
try {
|
||||
Files.walkFileTree(p, fv);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addMobileTemplate() {
|
||||
|
||||
public void addMobileTemplate(String template, MobileTemplate mobileTemplate) {
|
||||
mobileTemplates.put(template, mobileTemplate);
|
||||
}
|
||||
|
||||
public void loadLairTemplates() {
|
||||
|
||||
Reference in New Issue
Block a user