mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-21 20:42:12 +00:00
- Familiar preparation for 1.0.7 (2nd)
- Introducing new Familiar AI - TODO: Target selection
This commit is contained in:
1 parent
2d4b5a7627
commit
4b8501abe1
11 files changed
+385
-80
No files matched your search
@@ -46,10 +46,10 @@ public class FamiliarHandlerClient {
|
||||
ExFamiliarData data = clientFamiliars.get(p.getCommandSenderName());
|
||||
if(data == null) return;
|
||||
PartialEntityFamiliar fam = data.familiar;
|
||||
float y = (float) fam.posY;
|
||||
if (!Minecraft.getMinecraft().thePlayer.getCommandSenderName().equals(pkt.owner)) {
|
||||
float y = (float) (fam.posY + 1.32F);
|
||||
/*if (!Minecraft.getMinecraft().thePlayer.getCommandSenderName().equals(pkt.owner)) {
|
||||
y += 1.32F;
|
||||
}
|
||||
}*/
|
||||
FXLightningBolt bolt = new FXLightningBolt(Minecraft.getMinecraft().theWorld, (float) fam.posX, y, (float) fam.posZ, pkt.targetX, pkt.targetY, pkt.targetZ, Minecraft.getMinecraft().theWorld.rand.nextLong(), 10, 4.0F, 5);
|
||||
bolt.defaultFractal();
|
||||
bolt.setType(pkt.type);
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package makeo.gadomancy.common.utils;
|
||||
package makeo.gadomancy.common.crafting;
|
||||
|
||||
import makeo.gadomancy.common.items.baubles.ItemFamiliar_Old;
|
||||
import makeo.gadomancy.common.registration.RegisteredItems;
|
||||
@@ -2,7 +2,9 @@ package makeo.gadomancy.common.data;
|
||||
|
||||
import baubles.api.BaublesApi;
|
||||
import makeo.gadomancy.client.util.FamiliarHandlerClient;
|
||||
import makeo.gadomancy.common.familiar.FamiliarAIController;
|
||||
import makeo.gadomancy.common.familiar.FamiliarAIController_Old;
|
||||
import makeo.gadomancy.common.familiar.FamiliarController;
|
||||
import makeo.gadomancy.common.items.baubles.ItemEtherealFamiliar;
|
||||
import makeo.gadomancy.common.items.baubles.ItemFamiliar_Old;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -28,7 +30,8 @@ import java.util.Map;
|
||||
public class DataFamiliar extends AbstractData {
|
||||
|
||||
private List<FamiliarData> playersWithFamiliar = new ArrayList<FamiliarData>();
|
||||
private Map<EntityPlayer, FamiliarAIController> familiarAI = new HashMap<EntityPlayer, FamiliarAIController>();
|
||||
private Map<EntityPlayer, FamiliarAIController_Old> familiarAI = new HashMap<EntityPlayer, FamiliarAIController_Old>();
|
||||
//private Map<EntityPlayer, FamiliarController> familiarControllers = new HashMap<EntityPlayer, FamiliarController>();
|
||||
|
||||
private List<FamiliarData> addClientQueue = new ArrayList<FamiliarData>();
|
||||
private List<FamiliarData> removeClientQueue = new ArrayList<FamiliarData>();
|
||||
@@ -51,10 +54,14 @@ public class DataFamiliar extends AbstractData {
|
||||
markDirty();
|
||||
|
||||
if(!familiarAI.containsKey(player)) {
|
||||
FamiliarAIController controller = new FamiliarAIController(player);
|
||||
FamiliarAIController_Old controller = new FamiliarAIController_Old(player);
|
||||
controller.registerDefaultTasks();
|
||||
familiarAI.put(player, controller);
|
||||
}
|
||||
/*if(!familiarControllers.containsKey(player)) {
|
||||
FamiliarController controller = new FamiliarController(player);
|
||||
familiarControllers.put(player, controller);
|
||||
}*/
|
||||
}
|
||||
|
||||
public void handleUnequip(World world, EntityPlayer player, Aspect aspect) {
|
||||
@@ -100,6 +107,12 @@ public class DataFamiliar extends AbstractData {
|
||||
handleEquip(p.worldObj, p, a);
|
||||
}
|
||||
}
|
||||
if(amulet.getItem() != null && amulet.getItem() instanceof ItemEtherealFamiliar) {
|
||||
Aspect a = ItemEtherealFamiliar.getFamiliarAspect(amulet);
|
||||
if(a != null) {
|
||||
handleEquip(p.worldObj, p, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,42 +1,29 @@
|
||||
package makeo.gadomancy.common.events;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import makeo.gadomancy.common.aura.AuraEffects;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileAuraPylon;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileBlockProtector;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.entities.EntityPermNoClipItem;
|
||||
import makeo.gadomancy.common.familiar.FamiliarAIController;
|
||||
import makeo.gadomancy.common.registration.RegisteredItems;
|
||||
import makeo.gadomancy.common.utils.ItemUtils;
|
||||
import makeo.gadomancy.common.familiar.FamiliarAIController_Old;
|
||||
import makeo.gadomancy.common.utils.MiscUtils;
|
||||
import makeo.gadomancy.common.utils.NBTHelper;
|
||||
import makeo.gadomancy.common.utils.Vector3;
|
||||
import makeo.gadomancy.common.utils.world.TCMazeHandler;
|
||||
import net.minecraft.entity.EnumCreatureType;
|
||||
import net.minecraft.entity.boss.IBossDisplayData;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.event.entity.living.EnderTeleportEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import thaumcraft.common.config.ConfigBlocks;
|
||||
import thaumcraft.common.items.armor.Hover;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -88,7 +75,7 @@ public class EventHandlerEntity {
|
||||
@SubscribeEvent
|
||||
public void on(LivingSetAttackTargetEvent targetEvent) {
|
||||
if (targetEvent.target instanceof EntityPlayer) {
|
||||
FamiliarAIController.notifyTargetEvent(targetEvent.entityLiving, (EntityPlayer) targetEvent.target);
|
||||
FamiliarAIController_Old.notifyTargetEvent(targetEvent.entityLiving, (EntityPlayer) targetEvent.target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-14
@@ -1,7 +1,7 @@
|
||||
package makeo.gadomancy.common.familiar;
|
||||
|
||||
import baubles.api.BaublesApi;
|
||||
import makeo.gadomancy.common.registration.RegisteredFamiliarAI;
|
||||
import makeo.gadomancy.common.registration.RegisteredFamiliarAI_Old;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -22,26 +22,26 @@ import java.util.Random;
|
||||
*
|
||||
* Created by HellFirePvP @ 31.10.2015 14:08
|
||||
*/
|
||||
public class FamiliarAIController {
|
||||
public class FamiliarAIController_Old {
|
||||
|
||||
private static final Random RAND = new Random();
|
||||
|
||||
private static Map<EntityPlayer, LinkedList<EntityLivingBase>> targetMap = new HashMap<EntityPlayer, LinkedList<EntityLivingBase>>();
|
||||
|
||||
private List<FamiliarAIProcess> availableTasks = new ArrayList<FamiliarAIProcess>();
|
||||
private Map<FamiliarAIProcess, Integer> cooldownProcesses = new HashMap<FamiliarAIProcess, Integer>();
|
||||
private LinkedList<FamiliarAIProcess> requestedLoop = new LinkedList<FamiliarAIProcess>();
|
||||
private FamiliarAIProcess runningTask;
|
||||
private List<FamiliarAIProcess_Old> availableTasks = new ArrayList<FamiliarAIProcess_Old>();
|
||||
private Map<FamiliarAIProcess_Old, Integer> cooldownProcesses = new HashMap<FamiliarAIProcess_Old, Integer>();
|
||||
private LinkedList<FamiliarAIProcess_Old> requestedLoop = new LinkedList<FamiliarAIProcess_Old>();
|
||||
private FamiliarAIProcess_Old runningTask;
|
||||
private int ticksInTask;
|
||||
private EntityPlayer owningPlayer;
|
||||
|
||||
public FamiliarAIController(EntityPlayer owningPlayer) {
|
||||
public FamiliarAIController_Old(EntityPlayer owningPlayer) {
|
||||
this.owningPlayer = owningPlayer;
|
||||
}
|
||||
|
||||
public void registerDefaultTasks() {
|
||||
this.availableTasks.add(RegisteredFamiliarAI.familiarAIIdle);
|
||||
this.availableTasks.add(RegisteredFamiliarAI.familiarAIZapAttackingMonsters);
|
||||
this.availableTasks.add(RegisteredFamiliarAI_Old.familiarAIIdle);
|
||||
this.availableTasks.add(RegisteredFamiliarAI_Old.familiarAIZapAttackingMonsters);
|
||||
}
|
||||
|
||||
public void scheduleTick() {
|
||||
@@ -63,9 +63,9 @@ public class FamiliarAIController {
|
||||
|
||||
private void selectNewTask() {
|
||||
if(!requestedLoop.isEmpty()) {
|
||||
Iterator<FamiliarAIProcess> it = requestedLoop.iterator();
|
||||
Iterator<FamiliarAIProcess_Old> it = requestedLoop.iterator();
|
||||
while(it.hasNext()) {
|
||||
FamiliarAIProcess process = it.next();
|
||||
FamiliarAIProcess_Old process = it.next();
|
||||
if(!cooldownProcesses.containsKey(process)) {
|
||||
runningTask = process;
|
||||
it.remove();
|
||||
@@ -77,7 +77,7 @@ public class FamiliarAIController {
|
||||
int randIndex = RAND.nextInt(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
int index = (randIndex + i) % size;
|
||||
FamiliarAIProcess process = availableTasks.get(index);
|
||||
FamiliarAIProcess_Old process = availableTasks.get(index);
|
||||
if(process.canRun(owningPlayer.worldObj, owningPlayer.posX, owningPlayer.posY, owningPlayer.posZ, owningPlayer, BaublesApi.getBaubles(owningPlayer).getStackInSlot(0)) &&
|
||||
!cooldownProcesses.containsKey(process)) {
|
||||
runningTask = process;
|
||||
@@ -86,9 +86,9 @@ public class FamiliarAIController {
|
||||
}
|
||||
|
||||
private void reduceRunningCooldowns() {
|
||||
Iterator<FamiliarAIProcess> itProcesses = cooldownProcesses.keySet().iterator();
|
||||
Iterator<FamiliarAIProcess_Old> itProcesses = cooldownProcesses.keySet().iterator();
|
||||
while(itProcesses.hasNext()) {
|
||||
FamiliarAIProcess process = itProcesses.next();
|
||||
FamiliarAIProcess_Old process = itProcesses.next();
|
||||
int cd = cooldownProcesses.get(process) - 1;
|
||||
if(cd <= 0) {
|
||||
itProcesses.remove();
|
||||
+3
-3
@@ -12,13 +12,13 @@ import net.minecraft.world.World;
|
||||
*
|
||||
* Created by HellFirePvP @ 31.10.2015 14:05
|
||||
*/
|
||||
public abstract class FamiliarAIProcess {
|
||||
public abstract class FamiliarAIProcess_Old {
|
||||
|
||||
private static int sessionProcessIdCounter = 0;
|
||||
private int id;
|
||||
private int duration;
|
||||
|
||||
public FamiliarAIProcess(int durationTicks) {
|
||||
public FamiliarAIProcess_Old(int durationTicks) {
|
||||
this.duration = durationTicks;
|
||||
this.id = sessionProcessIdCounter++;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public abstract class FamiliarAIProcess {
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
FamiliarAIProcess that = (FamiliarAIProcess) o;
|
||||
FamiliarAIProcess_Old that = (FamiliarAIProcess_Old) o;
|
||||
return id == that.id;
|
||||
|
||||
}
|
||||
+77
-24
@@ -1,6 +1,8 @@
|
||||
package makeo.gadomancy.common.items.baubles;
|
||||
package makeo.gadomancy.common.familiar;
|
||||
|
||||
import net.minecraft.util.StatCollector;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -20,27 +22,28 @@ public class FamiliarAugment {
|
||||
private static final String FORMAT_NAME = "familiar.augment.%s.name";
|
||||
|
||||
//Main effects
|
||||
public static final FamiliarAugment SHOCK = new FamiliarAugment("shock");
|
||||
public static final FamiliarAugment POISON = new FamiliarAugment("poison").addConflict(SHOCK);
|
||||
public static final FamiliarAugment FIRE = new FamiliarAugment("fire").addConflict(SHOCK, POISON);
|
||||
public static final FamiliarAugment WEAKNESS = new FamiliarAugment("weakness").addConflict(SHOCK, POISON, FIRE);
|
||||
public static final FamiliarAugment SHOCK = new FamiliarAugment("shock", new AspectList().add(Aspect.AIR, 3).add(Aspect.ENTROPY, 2));
|
||||
public static final FamiliarAugment POISON = new FamiliarAugment("poison", new AspectList().add(Aspect.WATER, 3).add(Aspect.ENTROPY, 4)).addConflict(SHOCK);
|
||||
public static final FamiliarAugment FIRE = new FamiliarAugment("fire", new AspectList().add(Aspect.FIRE, 4).add(Aspect.ORDER, 2)).addConflict(SHOCK, POISON);
|
||||
public static final FamiliarAugment WEAKNESS = new FamiliarAugment("weakness", new AspectList().add(Aspect.ENTROPY, 3).add(Aspect.EARTH, 3)).addConflict(SHOCK, POISON, FIRE);
|
||||
|
||||
//Side effects
|
||||
public static final FamiliarAugment DAMAGE_INCREASE = new FamiliarAugment("damage").addCondition(new PreconditionAny(SHOCK, POISON, FIRE, WEAKNESS));
|
||||
public static final FamiliarAugment RANGE_INCREASE = new FamiliarAugment("range").addConflict(DAMAGE_INCREASE).addCondition(new PreconditionAny(SHOCK, POISON, FIRE, WEAKNESS));
|
||||
public static final FamiliarAugment ATTACK_SPEED = new FamiliarAugment("speed").addConflict(DAMAGE_INCREASE, RANGE_INCREASE).addCondition(new PreconditionAny(SHOCK, POISON, FIRE, WEAKNESS));
|
||||
public static final FamiliarAugment DAMAGE_INCREASE = new FamiliarAugment("damage", new AspectList().add(Aspect.FIRE, 3)).addCondition(new PreconditionAny(SHOCK, POISON, FIRE, WEAKNESS));
|
||||
public static final FamiliarAugment RANGE_INCREASE = new FamiliarAugment("range", new AspectList().add(Aspect.AIR, 2).add(Aspect.ORDER, 1)).addConflict(DAMAGE_INCREASE).addCondition(new PreconditionAny(SHOCK, POISON, FIRE, WEAKNESS));
|
||||
public static final FamiliarAugment ATTACK_SPEED = new FamiliarAugment("speed", new AspectList().add(Aspect.ORDER, 2).add(Aspect.FIRE, 1)).addConflict(DAMAGE_INCREASE, RANGE_INCREASE).addCondition(new PreconditionAny(SHOCK, POISON, FIRE, WEAKNESS));
|
||||
|
||||
|
||||
private final String unlocalizedName;
|
||||
private List<FamiliarAugmentPrecondition> preconditions = new ArrayList<FamiliarAugmentPrecondition>();
|
||||
private boolean requiresPrevLevel = true;
|
||||
private AspectList costsPerLevel;
|
||||
private List<FamiliarAugment> conflicts = new ArrayList<FamiliarAugment>();
|
||||
|
||||
private static Map<String, FamiliarAugment> BY_NAME = new HashMap<String, FamiliarAugment>();
|
||||
|
||||
private FamiliarAugment(String unlocalizedName) {
|
||||
private FamiliarAugment(String unlocalizedName, AspectList costs) {
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
BY_NAME.put(this.unlocalizedName.toLowerCase(), this);
|
||||
this.costsPerLevel = costs;
|
||||
}
|
||||
|
||||
private FamiliarAugment setIgnorePreviousLevel() {
|
||||
@@ -67,12 +70,16 @@ public class FamiliarAugment {
|
||||
return this;
|
||||
}
|
||||
|
||||
public AspectList getCostsPerLevel() {
|
||||
return costsPerLevel;
|
||||
}
|
||||
|
||||
public String getUnlocalizedName() {
|
||||
return String.format(FORMAT_NAME, unlocalizedName);
|
||||
return unlocalizedName;
|
||||
}
|
||||
|
||||
public String getLocalizedName() {
|
||||
return StatCollector.translateToLocal(getUnlocalizedName());
|
||||
return StatCollector.translateToLocal(String.format(FORMAT_NAME, unlocalizedName));
|
||||
}
|
||||
|
||||
public static FamiliarAugment getByUnlocalizedName(String name) {
|
||||
@@ -80,7 +87,7 @@ public class FamiliarAugment {
|
||||
}
|
||||
|
||||
//Returns true, if the current conditions for application are fulfilled for a familiar with given augments.
|
||||
public boolean checkConditions(List<FamiliarAugment.FamiliarAugmentPair> currentAugments, int levelToSet) {
|
||||
public boolean checkConditions(FamiliarAugmentList currentAugments, int levelToSet) {
|
||||
if(levelToSet <= 0) return false;
|
||||
for(FamiliarAugmentPair current : currentAugments) {
|
||||
if(conflicts.contains(current.augment)) return false;
|
||||
@@ -107,9 +114,24 @@ public class FamiliarAugment {
|
||||
return true;
|
||||
}
|
||||
|
||||
static {
|
||||
addNameEntry(SHOCK, SHOCK.unlocalizedName);
|
||||
addNameEntry(FIRE, FIRE.unlocalizedName);
|
||||
addNameEntry(POISON, POISON.unlocalizedName);
|
||||
addNameEntry(WEAKNESS, WEAKNESS.unlocalizedName);
|
||||
|
||||
addNameEntry(DAMAGE_INCREASE, DAMAGE_INCREASE.unlocalizedName);
|
||||
addNameEntry(RANGE_INCREASE, RANGE_INCREASE.unlocalizedName);
|
||||
addNameEntry(ATTACK_SPEED, ATTACK_SPEED.unlocalizedName);
|
||||
}
|
||||
|
||||
private static void addNameEntry(FamiliarAugment augment, String name) {
|
||||
BY_NAME.put(name.toLowerCase(), augment);
|
||||
}
|
||||
|
||||
private abstract static class FamiliarAugmentPrecondition {
|
||||
|
||||
public abstract boolean isFulfilled(List<FamiliarAugmentPair> currentAugments, int levelToSet);
|
||||
public abstract boolean isFulfilled(FamiliarAugmentList currentAugments, int levelToSet);
|
||||
|
||||
}
|
||||
|
||||
@@ -122,13 +144,11 @@ public class FamiliarAugment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFulfilled(List<FamiliarAugmentPair> currentAugments, int levelToSet) {
|
||||
public boolean isFulfilled(FamiliarAugmentList currentAugments, int levelToSet) {
|
||||
if(anyPrevAugment == null) return true;
|
||||
for(FamiliarAugment augment : anyPrevAugment) {
|
||||
if(augment == null) continue;
|
||||
for(FamiliarAugmentPair pair : currentAugments) {
|
||||
if(pair.augment.equals(augment)) return true;
|
||||
}
|
||||
if(currentAugments.contains(augment)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -143,20 +163,36 @@ public class FamiliarAugment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFulfilled(List<FamiliarAugmentPair> currentAugments, int levelToSet) {
|
||||
public boolean isFulfilled(FamiliarAugmentList currentAugments, int levelToSet) {
|
||||
if(prevAugments == null) return true;
|
||||
for(FamiliarAugment augment : prevAugments) {
|
||||
if(augment == null) continue;
|
||||
boolean contains = false;
|
||||
for(FamiliarAugmentPair pair : currentAugments) {
|
||||
if(pair.augment.equals(augment)) contains = true;
|
||||
}
|
||||
if(!contains) return false;
|
||||
if(!currentAugments.contains(augment)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class FamiliarAugmentList extends ArrayList<FamiliarAugmentPair> {
|
||||
|
||||
public boolean contains(FamiliarAugment augment) {
|
||||
return getAugmentPair(augment) != null;
|
||||
}
|
||||
|
||||
public FamiliarAugmentPair getAugmentPair(FamiliarAugment augment) {
|
||||
for (FamiliarAugmentPair pair : this) {
|
||||
if(pair.augment.equals(augment)) return pair;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getLevel(FamiliarAugment augment) {
|
||||
if(!contains(augment)) return -1;
|
||||
return getAugmentPair(augment).level;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class FamiliarAugmentPair {
|
||||
|
||||
public final FamiliarAugment augment;
|
||||
@@ -166,6 +202,23 @@ public class FamiliarAugment {
|
||||
this.augment = augment;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
FamiliarAugmentPair that = (FamiliarAugmentPair) o;
|
||||
|
||||
return level == that.level && !(augment != null ? !augment.equals(that.augment) : that.augment != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = augment != null ? augment.hashCode() : 0;
|
||||
result = 31 * result + level;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
package makeo.gadomancy.common.familiar;
|
||||
|
||||
import baubles.api.BaublesApi;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import makeo.gadomancy.common.items.baubles.ItemEtherealFamiliar;
|
||||
import makeo.gadomancy.common.network.PacketHandler;
|
||||
import makeo.gadomancy.common.network.packets.PacketFamiliarBolt;
|
||||
import makeo.gadomancy.common.network.packets.PacketStartAnimation;
|
||||
import makeo.gadomancy.common.utils.MiscUtils;
|
||||
import makeo.gadomancy.common.utils.Vector3;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.monster.IMob;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import thaumcraft.common.config.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
*
|
||||
* Created by HellFirePvP @ 29.12.2015 18:12
|
||||
*/
|
||||
public class FamiliarController {
|
||||
|
||||
public static final double RANGE_DEF = 6;
|
||||
public static final int AS_DELAY_DEF = 32;
|
||||
public static final double DMG_DEF = 1;
|
||||
|
||||
public static final double RANGE_INC = 1.8;
|
||||
public static final int AS_INC = 6;
|
||||
public static final double DMG_INC = 1.1;
|
||||
|
||||
public static final double SHOCK_DMG_INC = 0.8;
|
||||
public static final double FIRE_DMG_INC = 0.5;
|
||||
public static final double POISON_RANGE_INC = 0.6;
|
||||
public static final double WEAKNESS_DMG_DEC = 0.3;
|
||||
|
||||
private static final Random RAND = new Random();
|
||||
private int tickLastEffect = 0;
|
||||
private final EntityPlayer owningPlayer;
|
||||
|
||||
public FamiliarController(EntityPlayer owner) {
|
||||
this.owningPlayer = owner;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
IInventory baubles = BaublesApi.getBaubles(owningPlayer);
|
||||
ItemStack stack = baubles.getStackInSlot(0);
|
||||
if(stack == null || !(stack.getItem() instanceof ItemEtherealFamiliar)) return;
|
||||
|
||||
if(tickLastEffect > 0) {
|
||||
tickLastEffect--;
|
||||
return;
|
||||
}
|
||||
|
||||
FamiliarAugment.FamiliarAugmentList augments = ItemEtherealFamiliar.getAugments(stack);
|
||||
if(augments == null) return;
|
||||
|
||||
if(augments.isEmpty()) {
|
||||
doDefaultAttack();
|
||||
tickLastEffect = AS_DELAY_DEF;
|
||||
} else {
|
||||
FamiliarAugment.FamiliarAugmentPair effectElement = null;
|
||||
for (FamiliarAugment.FamiliarAugmentPair pair : augments) {
|
||||
FamiliarAugment augment = pair.augment;
|
||||
if(augment.equals(FamiliarAugment.SHOCK) || augment.equals(FamiliarAugment.FIRE)
|
||||
|| augment.equals(FamiliarAugment.POISON) || augment.equals(FamiliarAugment.WEAKNESS)) {
|
||||
effectElement = pair;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int dmgLevel = augments.getLevel(FamiliarAugment.DAMAGE_INCREASE);
|
||||
int attackSpeedLevel = augments.getLevel(FamiliarAugment.ATTACK_SPEED);
|
||||
int rangeLevel = augments.getLevel(FamiliarAugment.RANGE_INCREASE);
|
||||
double damage = DMG_DEF + (dmgLevel != -1 ? DMG_INC * dmgLevel : 0);
|
||||
int ticksUntilNextAttack = AS_DELAY_DEF - (attackSpeedLevel != -1 ? AS_INC * attackSpeedLevel : 0);
|
||||
double range = RANGE_DEF + (rangeLevel != -1 ? RANGE_INC * rangeLevel : 0);
|
||||
if(effectElement == null) {
|
||||
if(doEnhancedDefaultAttack(damage, range)) tickLastEffect = ticksUntilNextAttack;
|
||||
} else {
|
||||
if(doAttack(effectElement, damage, range)) tickLastEffect = ticksUntilNextAttack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doAttack(FamiliarAugment.FamiliarAugmentPair element, double damage, double range) {
|
||||
int toSelect = 1;
|
||||
int effectLevel = element.level;
|
||||
FamiliarAugment augment = element.augment;
|
||||
int boltType = 6;
|
||||
if(augment.equals(FamiliarAugment.SHOCK)) {
|
||||
boltType = 1;
|
||||
damage += effectLevel * SHOCK_DMG_INC;
|
||||
} else if(augment.equals(FamiliarAugment.FIRE)) {
|
||||
boltType = 4;
|
||||
damage += effectLevel * FIRE_DMG_INC;
|
||||
} else if(augment.equals(FamiliarAugment.POISON)) {
|
||||
boltType = 3;
|
||||
range += effectLevel * POISON_RANGE_INC;
|
||||
} else if(augment.equals(FamiliarAugment.WEAKNESS)) {
|
||||
boltType = 5;
|
||||
damage -= effectLevel * WEAKNESS_DMG_DEC;
|
||||
if(effectLevel == 3) toSelect = 3;
|
||||
}
|
||||
|
||||
List<EntityLivingBase> toAttack = selectEntityToAttack(range, toSelect);
|
||||
if(toAttack == null || toAttack.isEmpty()) return false;
|
||||
for (EntityLivingBase entity : toAttack) {
|
||||
attack(entity, damage, boltType);
|
||||
}
|
||||
if(augment.equals(FamiliarAugment.SHOCK)) {
|
||||
for (EntityLivingBase entity : toAttack) {
|
||||
if(RAND.nextInt(3) == 0) {
|
||||
Vector3 vel = MiscUtils.getPositionVector(entity).subtract(MiscUtils.getPositionVector(owningPlayer))
|
||||
.normalize().divide(2).multiply(0.5 * effectLevel);
|
||||
entity.motionX += vel.getX();
|
||||
entity.motionY += vel.getY();
|
||||
entity.motionZ += vel.getZ();
|
||||
}
|
||||
}
|
||||
} else if(augment.equals(FamiliarAugment.FIRE)) {
|
||||
int fireDur = 14;
|
||||
for (int i = 0; i < effectLevel; i++) {
|
||||
fireDur *= 2;
|
||||
}
|
||||
for (EntityLivingBase entity : toAttack) {
|
||||
entity.setFire(fireDur);
|
||||
if(effectLevel == 3) {
|
||||
entity.addPotionEffect(new PotionEffect(Config.potionSunScornedID, MiscUtils.ticksForMinutes(1), 2));
|
||||
}
|
||||
}
|
||||
} else if(augment.equals(FamiliarAugment.POISON)) {
|
||||
int potionLvl = 0;
|
||||
if(effectLevel > 1) potionLvl += 1;
|
||||
for (EntityLivingBase entity : toAttack) {
|
||||
entity.addPotionEffect(new PotionEffect(Potion.poison.getId(), MiscUtils.ticksForSeconds(30), potionLvl));
|
||||
if(effectLevel == 3) {
|
||||
entity.addPotionEffect(new PotionEffect(Potion.hunger.getId(), MiscUtils.ticksForMinutes(2), 3));
|
||||
}
|
||||
}
|
||||
} else if(augment.equals(FamiliarAugment.WEAKNESS)) {
|
||||
int potionLvl = 0;
|
||||
if(effectLevel == 3) potionLvl++;
|
||||
int dur = MiscUtils.ticksForSeconds(30);
|
||||
for (EntityLivingBase entity : toAttack) {
|
||||
entity.addPotionEffect(new PotionEffect(Potion.weakness.getId(), dur, potionLvl));
|
||||
entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.getId(), dur, potionLvl));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean doEnhancedDefaultAttack(double damage, double range) {
|
||||
List<EntityLivingBase> toAttack = selectEntityToAttack(range, 1);
|
||||
if(toAttack == null || toAttack.isEmpty()) return false;
|
||||
|
||||
attack(toAttack.get(0), damage, 6);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean doDefaultAttack() {
|
||||
List<EntityLivingBase> toAttack = selectEntityToAttack(RANGE_DEF, 1);
|
||||
if(toAttack == null || toAttack.isEmpty()) return false;
|
||||
|
||||
attack(toAttack.get(0), DMG_DEF, 6);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void attack(EntityLivingBase toAttack, double damage, int boltType) {
|
||||
toAttack.attackEntityFrom(DamageSource.magic, (float) damage);
|
||||
toAttack.worldObj.playSoundEffect(toAttack.posX + 0.5, toAttack.posY + 0.5, toAttack.posZ + 0.5, "thaumcraft:zap", 0.8F, 1.0F);
|
||||
PacketFamiliarBolt bolt = new PacketFamiliarBolt(owningPlayer.getCommandSenderName(), (float) toAttack.posX, (float) toAttack.posY, (float) toAttack.posZ, boltType, true);
|
||||
PacketHandler.INSTANCE.sendToAllAround(bolt, new NetworkRegistry.TargetPoint(toAttack.worldObj.provider.dimensionId, owningPlayer.posX,
|
||||
owningPlayer.posY, owningPlayer.posZ, 16));
|
||||
}
|
||||
|
||||
private List<EntityLivingBase> selectEntityToAttack(double rad, int amountToSelectMax) {
|
||||
List<EntityLivingBase> attackable = getAttackableEntities(rad);
|
||||
if(attackable.size() <= 0) return null;
|
||||
List<EntityLivingBase> entities = new ArrayList<EntityLivingBase>();
|
||||
if(attackable.size() <= amountToSelectMax) {
|
||||
entities.addAll(attackable);
|
||||
} else {
|
||||
for (int i = 0; i < amountToSelectMax; i++) {
|
||||
entities.add(attackable.remove(RAND.nextInt(attackable.size())));
|
||||
}
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
private List<EntityLivingBase> getAttackableEntities(double rad) {
|
||||
double x = owningPlayer.posX;
|
||||
double y = owningPlayer.posY;
|
||||
double z = owningPlayer.posZ;
|
||||
List<EntityLivingBase> entities = owningPlayer.worldObj.getEntitiesWithinAABB(EntityLivingBase.class,
|
||||
AxisAlignedBB.getBoundingBox(x - 0.5, y - 0.5, z - 0.5, x + 0.5, y + 0.5, z + 0.5).expand(rad, rad, rad));
|
||||
|
||||
Iterator<EntityLivingBase> it = entities.iterator();
|
||||
while (it.hasNext()) {
|
||||
EntityLivingBase base = it.next();
|
||||
if(base == null || base.isDead || base instanceof EntityPlayer || !(base instanceof IMob)) it.remove();
|
||||
//TODO remove entities we don't want to attack...
|
||||
}
|
||||
|
||||
return entities;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import baubles.api.IBauble;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.data.DataFamiliar;
|
||||
import makeo.gadomancy.common.data.SyncDataHolder;
|
||||
import makeo.gadomancy.common.familiar.FamiliarAugment;
|
||||
import makeo.gadomancy.common.registration.RegisteredItems;
|
||||
import makeo.gadomancy.common.utils.MiscUtils;
|
||||
import makeo.gadomancy.common.utils.NBTHelper;
|
||||
@@ -49,6 +50,30 @@ public class ItemEtherealFamiliar extends Item implements IBauble {
|
||||
ItemStack stack = new ItemStack(item);
|
||||
setFamiliarAspect(stack, Aspect.MAGIC);
|
||||
list.add(stack);
|
||||
|
||||
stack = new ItemStack(item);
|
||||
setFamiliarAspect(stack, Aspect.FIRE);
|
||||
addAugmentUnsafe(stack, FamiliarAugment.FIRE, 3);
|
||||
addAugmentUnsafe(stack, FamiliarAugment.DAMAGE_INCREASE, 3);
|
||||
list.add(stack);
|
||||
|
||||
stack = new ItemStack(item);
|
||||
setFamiliarAspect(stack, Aspect.WEATHER);
|
||||
addAugmentUnsafe(stack, FamiliarAugment.SHOCK, 3);
|
||||
addAugmentUnsafe(stack, FamiliarAugment.ATTACK_SPEED, 2);
|
||||
list.add(stack);
|
||||
|
||||
stack = new ItemStack(item);
|
||||
setFamiliarAspect(stack, Aspect.POISON);
|
||||
addAugmentUnsafe(stack, FamiliarAugment.POISON, 3);
|
||||
addAugmentUnsafe(stack, FamiliarAugment.ATTACK_SPEED, 2);
|
||||
list.add(stack);
|
||||
|
||||
stack = new ItemStack(item);
|
||||
setFamiliarAspect(stack, Aspect.WEAPON);
|
||||
addAugmentUnsafe(stack, FamiliarAugment.WEAKNESS, 3);
|
||||
addAugmentUnsafe(stack, FamiliarAugment.DAMAGE_INCREASE, 3);
|
||||
list.add(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,12 +131,12 @@ public class ItemEtherealFamiliar extends Item implements IBauble {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<FamiliarAugment.FamiliarAugmentPair> getAugments(ItemStack stack) {
|
||||
if(stack == null || !(stack.getItem() instanceof ItemEtherealFamiliar)) return new ArrayList<FamiliarAugment.FamiliarAugmentPair>();
|
||||
public static FamiliarAugment.FamiliarAugmentList getAugments(ItemStack stack) {
|
||||
if(stack == null || !(stack.getItem() instanceof ItemEtherealFamiliar)) return new FamiliarAugment.FamiliarAugmentList();
|
||||
NBTTagCompound augmentTag = NBTHelper.getData(stack).getCompoundTag("augments");
|
||||
Set<String> strKeySet = augmentTag.func_150296_c();
|
||||
if(strKeySet == null || strKeySet.size() <= 0) return new ArrayList<FamiliarAugment.FamiliarAugmentPair>();
|
||||
List<FamiliarAugment.FamiliarAugmentPair> augmentList = new ArrayList<FamiliarAugment.FamiliarAugmentPair>();
|
||||
if(strKeySet == null || strKeySet.size() <= 0) return new FamiliarAugment.FamiliarAugmentList();
|
||||
FamiliarAugment.FamiliarAugmentList augmentList = new FamiliarAugment.FamiliarAugmentList();
|
||||
for(String key : strKeySet) {
|
||||
FamiliarAugment augment = FamiliarAugment.getByUnlocalizedName(key);
|
||||
int level = augmentTag.getInteger(key);
|
||||
@@ -122,7 +147,7 @@ public class ItemEtherealFamiliar extends Item implements IBauble {
|
||||
|
||||
public static boolean doesAcceptAugment(ItemStack stack, FamiliarAugment augment, int level) {
|
||||
if(stack == null || !(stack.getItem() instanceof ItemEtherealFamiliar)) return false;
|
||||
List<FamiliarAugment.FamiliarAugmentPair> currentAugments = getAugments(stack);
|
||||
FamiliarAugment.FamiliarAugmentList currentAugments = getAugments(stack);
|
||||
for(FamiliarAugment.FamiliarAugmentPair pair : currentAugments) {
|
||||
if(pair.augment.equals(augment)) return false;
|
||||
}
|
||||
@@ -146,8 +171,15 @@ public class ItemEtherealFamiliar extends Item implements IBauble {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWornTick(ItemStack itemStack, EntityLivingBase entityLivingBase) {
|
||||
//TODO get and tick AI controlling
|
||||
public void onWornTick(ItemStack itemStack, EntityLivingBase entity) {
|
||||
if(itemStack == null) return;
|
||||
if(entity instanceof EntityPlayer && itemStack.getItem() instanceof ItemEtherealFamiliar) {
|
||||
DataFamiliar familiarData = SyncDataHolder.getDataServer("FamiliarData");
|
||||
Aspect a = getFamiliarAspect(itemStack);
|
||||
if (a != null) {
|
||||
familiarData.equipTick(((EntityPlayer) entity).worldObj, (EntityPlayer) entity, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+9
-9
@@ -1,8 +1,8 @@
|
||||
package makeo.gadomancy.common.registration;
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import makeo.gadomancy.common.familiar.FamiliarAIController;
|
||||
import makeo.gadomancy.common.familiar.FamiliarAIProcess;
|
||||
import makeo.gadomancy.common.familiar.FamiliarAIController_Old;
|
||||
import makeo.gadomancy.common.familiar.FamiliarAIProcess_Old;
|
||||
import makeo.gadomancy.common.items.baubles.ItemFamiliar_Old;
|
||||
import makeo.gadomancy.common.network.PacketHandler;
|
||||
import makeo.gadomancy.common.network.packets.PacketFamiliarBolt;
|
||||
@@ -26,9 +26,9 @@ import java.util.List;
|
||||
*
|
||||
* Created by HellFirePvP @ 31.10.2015 14:12
|
||||
*/
|
||||
public class RegisteredFamiliarAI {
|
||||
public class RegisteredFamiliarAI_Old {
|
||||
|
||||
public static FamiliarAIProcess familiarAIIdle = new FamiliarAIProcess(1) {
|
||||
public static FamiliarAIProcess_Old familiarAIIdle = new FamiliarAIProcess_Old(1) {
|
||||
@Override
|
||||
public boolean canRun(World world, double x, double y, double z, EntityPlayer parent, ItemStack stackInSlot) {
|
||||
return true;
|
||||
@@ -43,7 +43,7 @@ public class RegisteredFamiliarAI {
|
||||
}
|
||||
};
|
||||
|
||||
public static FamiliarAIProcess familiarAIZapAttackingMonsters = new FamiliarAIProcess(1) {
|
||||
public static FamiliarAIProcess_Old familiarAIZapAttackingMonsters = new FamiliarAIProcess_Old(1) {
|
||||
|
||||
@Override
|
||||
public boolean canRun(World world, double x, double y, double z, EntityPlayer parent, ItemStack itemStack) {
|
||||
@@ -57,12 +57,12 @@ public class RegisteredFamiliarAI {
|
||||
|
||||
List<EntityLivingBase> lastTargetters = getPotentialTargets(world, parent, rangeInc);
|
||||
if(lastTargetters.size() == 0) {
|
||||
FamiliarAIController.cleanTargetterList(parent);
|
||||
FamiliarAIController_Old.cleanTargetterList(parent);
|
||||
return;
|
||||
}
|
||||
EntityLivingBase mob = lastTargetters.get(world.rand.nextInt(lastTargetters.size()));
|
||||
if(mob.isDead || mob instanceof EntityPlayer) {
|
||||
FamiliarAIController.cleanTargetterList(parent);
|
||||
FamiliarAIController_Old.cleanTargetterList(parent);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class RegisteredFamiliarAI {
|
||||
|
||||
PacketFamiliarBolt bolt = new PacketFamiliarBolt(parent.getCommandSenderName(), (float) mob.posX, (float) mob.posY, (float) mob.posZ, 6, true);
|
||||
PacketHandler.INSTANCE.sendToAllAround(bolt, new NetworkRegistry.TargetPoint(mob.worldObj.provider.dimensionId, mob.posX, mob.posY, mob.posZ, 32));
|
||||
FamiliarAIController.cleanTargetterList(parent);
|
||||
FamiliarAIController_Old.cleanTargetterList(parent);
|
||||
}
|
||||
|
||||
private List<EntityLivingBase> getPotentialTargets(World world, EntityPlayer player, int rangeInc) {
|
||||
@@ -93,7 +93,7 @@ public class RegisteredFamiliarAI {
|
||||
}
|
||||
|
||||
private List<EntityLivingBase> getCloseEnoughTargetters(World world, EntityPlayer parent, int rangeInc) {
|
||||
LinkedList<EntityLivingBase> lastTargetters = FamiliarAIController.getLastTargetters(parent);
|
||||
LinkedList<EntityLivingBase> lastTargetters = FamiliarAIController_Old.getLastTargetters(parent);
|
||||
if(lastTargetters == null || lastTargetters.isEmpty()) return new ArrayList<EntityLivingBase>();
|
||||
List<EntityLivingBase> closeEnoughLastTargetters = new ArrayList<EntityLivingBase>();
|
||||
int range = 8 + rangeInc;
|
||||
@@ -10,7 +10,6 @@ import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.items.ItemAuraCore;
|
||||
import makeo.gadomancy.common.items.baubles.ItemFamiliar_Old;
|
||||
import makeo.gadomancy.common.research.SimpleResearchItem;
|
||||
import makeo.gadomancy.common.utils.FamiliarUndoRecipe;
|
||||
import makeo.gadomancy.common.utils.RandomizedAspectList;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
|
||||
Reference in new issue
Block a user