From 3cd1410c19cb7e17ff3987a45f2fe7fae1ff77e5 Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 5 Dec 2021 15:04:03 -0600 Subject: [PATCH] Added new ScriptDBCPlayer class for manipulating Dragon Block C attributes. Flying NPCs no longer chase you down if you're dead, or if they're dead. --- .../noppes/npcs/entity/EntityNPCFlying.java | 54 +++--- .../npcs/scripted/entity/ScriptDBCPlayer.java | 169 ++++++++++++++++++ .../npcs/scripted/entity/ScriptPlayer.java | 19 ++ 3 files changed, 213 insertions(+), 29 deletions(-) create mode 100644 src/main/java/noppes/npcs/scripted/entity/ScriptDBCPlayer.java diff --git a/src/main/java/noppes/npcs/entity/EntityNPCFlying.java b/src/main/java/noppes/npcs/entity/EntityNPCFlying.java index 93db80325..8c215191d 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCFlying.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCFlying.java @@ -45,40 +45,36 @@ public abstract class EntityNPCFlying extends EntityNPCInterface { this.motionY *= speed*speedMult; - Entity entity = this.getAttackTarget(); - if (!this.worldObj.isRemote) - { - if (entity != null) - { - if (this.posY < entity.posY) - { - if (this.motionY < 0.0D) - { - this.motionY = 0.0D; + if(isEntityAlive()) { + if (!this.worldObj.isRemote) { + Entity entity = this.getAttackTarget(); + if (entity != null && entity.isEntityAlive()) { + if (this.posY < entity.posY) { + if (this.motionY < 0.0D) { + this.motionY = 0.0D; + } + + this.motionY += (speed - this.motionY) * speed * speedMult; } - this.motionY += (speed - this.motionY) * speed*speedMult; + double d0 = entity.posX - this.posX; + double d1 = entity.posY - this.posY; + double d2 = entity.posZ - this.posZ; + double d3 = d0 * d0 + d2 * d2; + + if (d3 > 9.0D) { + double d5 = (double) MathHelper.sqrt_double(d3); + this.motionX += (d0 / d5 * speed - this.motionX) * speed * speedMult; + this.motionZ += (d2 / d5 * speed - this.motionZ) * speed * speedMult; + } + + this.rotationYaw = (float) ((Math.atan2(-d0, -d2) + Math.PI) * -(180F / Math.PI)); } - - double d0 = entity.posX - this.posX; - double d1 = entity.posY - this.posY; - double d2 = entity.posZ - this.posZ; - double d3 = d0 * d0 + d2 * d2; - - if (d3 > 9.0D) - { - double d5 = (double)MathHelper.sqrt_double(d3); - this.motionX += (d0 / d5 * speed - this.motionX) * speed*speedMult; - this.motionZ += (d2 / d5 * speed - this.motionZ) * speed*speedMult; - } - - this.rotationYaw = (float)((Math.atan2(-d0,-d2)+Math.PI)*-(180F/Math.PI)); } - } - if (this.motionX * this.motionX + this.motionZ * this.motionZ > 0.05000000074505806D && isEntityAlive()) - { - this.rotationYaw = (float)Math.atan2(this.motionZ, this.motionX) * (180F / (float)Math.PI) - 90.0F; + if (this.motionX * this.motionX + this.motionZ * this.motionZ > 0.05000000074505806D && isEntityAlive()) { + this.rotationYaw = (float) Math.atan2(this.motionZ, this.motionX) * (180F / (float) Math.PI) - 90.0F; + } } super.onLivingUpdate(); diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptDBCPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptDBCPlayer.java new file mode 100644 index 000000000..e796ba16e --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptDBCPlayer.java @@ -0,0 +1,169 @@ +package noppes.npcs.scripted.entity; + +import net.minecraft.entity.player.EntityPlayerMP; +import noppes.npcs.scripted.CustomNPCsException; + +public class ScriptDBCPlayer extends ScriptPlayer{ + public T player; + + public ScriptDBCPlayer(T player){ + super(player); + this.player = player; + } + + public void setStat(String stat, int value) { + stat = stat.toLowerCase().trim(); + switch (stat) { + case "str": + case "strength": + player.getEntityData().setInteger("jrmcStrI", value); + break; + case "dex": + case "dexterity": + player.getEntityData().setInteger("jrmcDexI", value); + break; + case "con": + case "constitution": + player.getEntityData().setInteger("jrmcCnsI", value); + break; + case "wil": + case "willpower": + player.getEntityData().setInteger("jrmcWilI", value); + break; + case "mnd": + case "mind": + player.getEntityData().setInteger("jrmcIntI", value); + break; + case "spi": + case "spirit": + player.getEntityData().setInteger("jrmcCncI", value); + break; + } + } + + public int getStat(String stat) { + stat = stat.toLowerCase().trim(); + switch (stat) { + case "str": + case "strength": + return player.getEntityData().getInteger("jrmcStrI"); + case "dex": + case "dexterity": + return player.getEntityData().getInteger("jrmcDexI"); + case "con": + case "constitution": + return player.getEntityData().getInteger("jrmcCnsI"); + case "wil": + case "willpower": + return player.getEntityData().getInteger("jrmcWilI"); + case "mnd": + case "mind": + return player.getEntityData().getInteger("jrmcIntI"); + case "spi": + case "spirit": + return player.getEntityData().getInteger("jrmcCncI"); + } + + throw new CustomNPCsException("Invalid stat name: " + stat + "\nValid stat names are:" + + "\nstr, dex, con, wil, mnd, spi\nstrength, dexterity, constitution, willpower, mind, spirit",new Object[0]); + } + + public void setRelease(byte release){ + player.getEntityData().setByte("jrmcRelease",release); + } + public byte getRelease(){ + return player.getEntityData().getByte("jrmcRelease"); + } + + public void setBody(int body){ + player.getEntityData().setInteger("jrmcBdy",body); + } + public int getBody(){ + return player.getEntityData().getInteger("jrmcBdy"); + } + + public void setStamina(int stamina){ + player.getEntityData().setInteger("jrmcStamina",stamina); + } + public int getStamina(){ + return player.getEntityData().getInteger("jrmcStamina"); + } + + public void setKi(int ki){ + player.getEntityData().setInteger("jrmcEnrgy",ki); + } + public int getKi(){ + return player.getEntityData().getInteger("jrmcEnrgy"); + } + + public void setTP(int tp){ + player.getEntityData().setInteger("jrmcTpint",tp); + } + public int getTP(){ + return player.getEntityData().getInteger("jrmcTpint"); + } + + public void setGravity(float gravity){ + player.getEntityData().setFloat("jrmcGravForce",gravity); + } + public float getGravity(){ + return player.getEntityData().getFloat("jrmcGravForce"); + } + + public void setForm(byte form){ + player.getEntityData().setByte("jrmcState",form); + } + public byte getForm(){ + return player.getEntityData().getByte("jrmcState"); + } + public void setForm2(byte form2){ + player.getEntityData().setByte("jrmcState2",form2); + } + public byte getForm2(){ + return player.getEntityData().getByte("jrmcState2"); + } + + public void setPowerPoints(int points){ + player.getEntityData().setInteger("jrmcArcRsrv",points); + } + public int getPowerPoints(){ + return player.getEntityData().getInteger("jrmcArcRsrv"); + } + + public void setAuraColor(int color){ + player.getEntityData().setInteger("jrmcAuraColor",color); + } + public int getAuraColor(){ + return player.getEntityData().getInteger("jrmcAuraColor"); + } + + public byte getDBCClass(){ + return player.getEntityData().getByte("jrmcClass"); + } + public int getRace(){ + return player.getEntityData().getByte("jrmcRace"); + } + public int getPowerType(){ + return player.getEntityData().getByte("jrmcPwrtyp"); + } + public int getKillCount(String type){ + type = type.toLowerCase().trim(); + + int evilKills = player.getEntityData().getInteger("jrmcKillCountEvil"); + int goodKills = player.getEntityData().getInteger("jrmcKillCountGood"); + int neutKills = player.getEntityData().getInteger("jrmcKillCountNeut"); + + switch (type) { + case "evil": + return evilKills; + case "good": + return goodKills; + case "neutral": + return neutKills; + case "all": + return evilKills + goodKills + neutKills; + } + + throw new CustomNPCsException("Invalid kill type: " + type + "\nValid kill types are: evil, good, neutral, all", new Object[0]); + } +} diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 55cfb4aed..345446be3 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -4,6 +4,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.stats.Achievement; import net.minecraft.stats.StatBase; import net.minecraft.stats.StatList; @@ -24,6 +26,7 @@ import noppes.npcs.controllers.PlayerQuestData; import noppes.npcs.controllers.Quest; import noppes.npcs.controllers.QuestController; import noppes.npcs.controllers.QuestData; +import noppes.npcs.scripted.CustomNPCsException; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.ScriptPixelmonPlayerData; @@ -32,6 +35,9 @@ import noppes.npcs.scripted.interfaces.IPlayer; import noppes.npcs.scripted.interfaces.ITimers; import noppes.npcs.util.ValueUtil; +import java.util.Iterator; +import java.util.Set; + public class ScriptPlayer extends ScriptLivingBase implements IPlayer { public T player; public ScriptPlayer(T player){ @@ -383,4 +389,17 @@ public class ScriptPlayer extends ScriptLivingBase PlayerData data = PlayerDataController.instance.getPlayerData(player); return data.getGUIOpen(); } + + public ScriptDBCPlayer getDBCPlayer() { + Set keySet = player.getEntityData().func_150296_c(); + Iterator iterator = keySet.iterator(); + + while (iterator.hasNext()) + { + String s = (String)iterator.next(); + if(s.contains("jrmc")) + return new ScriptDBCPlayer<>(this.player); + } + return null; + } }