From 70c1354a4a96698758a88c032866288f79de6f5a Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Sat, 24 Aug 2024 08:16:37 -0400 Subject: Initial commit --- .../exprop/FBSEntityProperties$WarpPosition.class | Bin 0 -> 3337 bytes .../plusplus/fbs/exprop/FBSEntityProperties.class | Bin 0 -> 9431 bytes .../plusplus/fbs/exprop/FBSEntityProperties.java | 341 +++++++++++++++++++++ .../jp/plusplus/fbs/exprop/SanityManager.class | Bin 0 -> 7577 bytes .../java/jp/plusplus/fbs/exprop/SanityManager.java | 216 +++++++++++++ 5 files changed, 557 insertions(+) create mode 100644 src/main/java/jp/plusplus/fbs/exprop/FBSEntityProperties$WarpPosition.class create mode 100644 src/main/java/jp/plusplus/fbs/exprop/FBSEntityProperties.class create mode 100644 src/main/java/jp/plusplus/fbs/exprop/FBSEntityProperties.java create mode 100644 src/main/java/jp/plusplus/fbs/exprop/SanityManager.class create mode 100644 src/main/java/jp/plusplus/fbs/exprop/SanityManager.java (limited to 'src/main/java/jp/plusplus/fbs/exprop') diff --git a/src/main/java/jp/plusplus/fbs/exprop/FBSEntityProperties$WarpPosition.class b/src/main/java/jp/plusplus/fbs/exprop/FBSEntityProperties$WarpPosition.class new file mode 100644 index 0000000..82fc851 Binary files /dev/null and b/src/main/java/jp/plusplus/fbs/exprop/FBSEntityProperties$WarpPosition.class differ diff --git a/src/main/java/jp/plusplus/fbs/exprop/FBSEntityProperties.class b/src/main/java/jp/plusplus/fbs/exprop/FBSEntityProperties.class new file mode 100644 index 0000000..1c75121 Binary files /dev/null and b/src/main/java/jp/plusplus/fbs/exprop/FBSEntityProperties.class differ diff --git a/src/main/java/jp/plusplus/fbs/exprop/FBSEntityProperties.java b/src/main/java/jp/plusplus/fbs/exprop/FBSEntityProperties.java new file mode 100644 index 0000000..417cdde --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/exprop/FBSEntityProperties.java @@ -0,0 +1,341 @@ +package jp.plusplus.fbs.exprop; + +import jp.plusplus.fbs.block.BlockCore; +import jp.plusplus.fbs.spirit.ISpiritTool; +import jp.plusplus.fbs.spirit.SpiritManager; +import jp.plusplus.fbs.spirit.SpiritStatus; +import jp.plusplus.fbs.tileentity.TileEntityMagicCore; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.WorldProvider; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.common.IExtendedEntityProperties; + +import java.util.ArrayList; + +/** + * Createdby pluslus_Fon 2015/06/05. + */ +public class FBSEntityProperties implements IExtendedEntityProperties { + public final static String EXT_PROP_NAME = "FBSPlayerData"; + + /** + * 魔術レベルの最大値 + */ + public static final int MAGIC_LEVEL_MAX=50; + + /** + * 一般人の魔術レベル最大値 + */ + public static final int MAGIC_LEVEL_BASIC_MAX=25; + + private int san=99; + private int lvMagic=1; + private double exp=0; + private double next=30; + + private String spiritToolName=""; + private int spiritToolLv=-1; + + private ArrayList positions=new ArrayList(); + private ArrayList decodedBooks=new ArrayList(); + + + private ItemStack[] bindInventory=new ItemStack[40]; + private ItemStack[] pocketInventory=new ItemStack[72]; + + public static void register(EntityPlayer player) { + player.registerExtendedProperties(EXT_PROP_NAME, new FBSEntityProperties()); + } + public static FBSEntityProperties get(EntityPlayer player) { + return (FBSEntityProperties)player.getExtendedProperties(EXT_PROP_NAME); + } + + @Override + public void saveNBTData(NBTTagCompound compound) { + NBTTagCompound nbt=new NBTTagCompound(); + nbt.setInteger("SAN", san); + nbt.setInteger("LvMagic", lvMagic); + nbt.setDouble("EXP", exp); + nbt.setDouble("Next", next); + nbt.setString("SpiritToolName", spiritToolName); + nbt.setInteger("SpiritToolLevel", spiritToolLv); + + NBTTagList tags=new NBTTagList(); + for(WarpPosition pos : positions){ + NBTTagCompound n=new NBTTagCompound(); + pos.writeToNBT(n); + tags.appendTag(n); + } + nbt.setTag("WarpPositions", tags); + + tags=new NBTTagList(); + for (int i=0;i=0 && b0=0 && b0(); + nbttaglist=(NBTTagList)nbt.getTag("DecodedBooks"); + for(int i=0;i5?m:5):99; + } + public int getSanity(){ return san; } + public void setSanity(int s){ + san=s; + if(san>getMaxSanity()){ + san=getMaxSanity(); + } + if(san<0){ + san=0; + } + } + public int getMagicLevel(){ return lvMagic; } + public void setMagicLevel(int s){ + if(s<1) s=1; + + lvMagic=s; + exp=0; + if(lvMagic==1) next=10; + else next=MathHelper.ceiling_double_int(10+Math.exp(0.25*(lvMagic-1))); + } + public double getEXP(){ + return exp; + } + public double getNext(){ + return next; + } + public void addEXP(double s){ + if(s<=0) return; + exp+=s; + while(exp>=next && lvMagicgetMaxSanity()){ + san=getMaxSanity(); + } + exp-=next; + //next=MathHelper.ceiling_double_int(10+Math.exp(0.25*(lvMagic-1))); + next+=15*(lvMagic+1); + } + + public String getSpiritToolName(){ return spiritToolName; } + public void setSpiritToolName(String s){ spiritToolName=s; } + public int getSpiritToolLevel(){ return spiritToolLv; } + public void setSpiritToolLevel(int l){ + if(l<=0 || l>SpiritStatus.LEVEL_MAX) return; + spiritToolLv =l; + } + + public void bindPlayerInventory(EntityPlayer player, boolean spiritOnly){ + bindInventory=new ItemStack[player.inventory.getSizeInventory()]; + + if(spiritOnly && SpiritManager.findSpiritToolIndex(player)!=-1){ + for(int i=0;i getDecodedBooks(){ + return decodedBooks; + } + + public ArrayList getDestinations(){ + return positions; + } + public boolean addDestination(int dimId, int x, int y, int z){ + WarpPosition wp=new WarpPosition(dimId, x, y, z); + if(!positions.contains(wp)){ + positions.add(wp); + return true; + } + return false; + } + + public static class WarpPosition{ + public String name; + public int dimId; + public int x,y,z; + + public WarpPosition(NBTTagCompound nbt){ + readFromNBT(nbt); + } + public WarpPosition(int dimId, int x, int y, int z){ + this.dimId=dimId; + this.x=x; + this.y=y; + this.z=z; + name=getDimName()+"("+x+","+y+","+z+")"; + } + + public void setName(String n){ + name=n; + } + public String getName(){ return name; } + + public boolean canWarp(){ + World w=DimensionManager.getWorld(dimId); + if(w==null) return false; + + Block b=w.getBlock(x,y,z); + if(b!=BlockCore.magicCore) return false; + + TileEntity te=w.getTileEntity(x,y,z); + if(!(te instanceof TileEntityMagicCore)) return false; + + return "fbs.warp".equals(((TileEntityMagicCore) te).getCircleName()); + } + + public String getDimName(){ + WorldProvider wp=WorldProvider.getProviderForDimension(dimId); + if(wp==null) return ""; + return wp.getDimensionName(); + } + + public void writeToNBT(NBTTagCompound nbt){ + nbt.setString("Name", name); + nbt.setInteger("Dim", dimId); + nbt.setInteger("x", x); + nbt.setInteger("y", y); + nbt.setInteger("z", z); + } + public void readFromNBT(NBTTagCompound nbt){ + name=nbt.getString("Name"); + dimId=nbt.getInteger("Dim"); + x=nbt.getInteger("x"); + y=nbt.getInteger("y"); + z=nbt.getInteger("z"); + } + @Override + public boolean equals(Object obj){ + if(!(obj instanceof WarpPosition)) return false; + WarpPosition wp=(WarpPosition)obj; + return dimId==wp.dimId && x==wp.x && y==wp.y && z==wp.z; + } + } +} diff --git a/src/main/java/jp/plusplus/fbs/exprop/SanityManager.class b/src/main/java/jp/plusplus/fbs/exprop/SanityManager.class new file mode 100644 index 0000000..d398019 Binary files /dev/null and b/src/main/java/jp/plusplus/fbs/exprop/SanityManager.class differ diff --git a/src/main/java/jp/plusplus/fbs/exprop/SanityManager.java b/src/main/java/jp/plusplus/fbs/exprop/SanityManager.java new file mode 100644 index 0000000..5804c30 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/exprop/SanityManager.java @@ -0,0 +1,216 @@ +package jp.plusplus.fbs.exprop; + +import jp.plusplus.fbs.AchievementRegistry; +import jp.plusplus.fbs.FBS; +import jp.plusplus.fbs.api.event.PlayerSanityEvent; +import jp.plusplus.fbs.api.event.PlayerSanityRollEvent; +import jp.plusplus.fbs.packet.MessagePlayerProperties; +import jp.plusplus.fbs.packet.PacketHandler; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.DamageSource; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.MinecraftForge; + +import java.util.ArrayList; +import java.util.Random; + +/** + * Createdby pluslus_Fon 2015/06/05. + * 正気度および魔術レベル・経験値の管理クラス + * 外部からこのクラスを呼び出してプレイヤーをいじる + * 基本的に正気度は XdY で変化する。Xはダイスを振る回数を、Yはダイスの面数を表す。 + */ +public class SanityManager { + private static SanityManager instance = new SanityManager(); + public static final String STATUS = "san"; + private static Random rand=new Random(); + + private static void addSAN(EntityPlayer player, FBSEntityProperties prop, int san){ + prop.setSanity(prop.getSanity()+san); + player.addChatComponentMessage(new ChatComponentText(String.format(StatCollector.translateToLocal("info.fbs.san.0"), san))); + } + private static void loseSAN(EntityPlayer player, FBSEntityProperties prop, int san){ + int pre=prop.getSanity(); + prop.setSanity(pre-san); + player.addChatComponentMessage(new ChatComponentText(String.format(StatCollector.translateToLocal("info.fbs.san.1"), san))); + player.triggerAchievement(AchievementRegistry.insanity); + + if(prop.getSanity()<=0){ + //死亡判定 + player.attackEntityFrom(new DamageSource("fbs.madness."+rand.nextInt(3)), 10000); + player.triggerAchievement(AchievementRegistry.death); + } + else if(san>=2 && 100*san/pre>=20){ + //発狂判定 + player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("info.fbs.san.2"))); + player.addPotionEffect(new PotionEffect(Potion.confusion.getId(), 20 * 15, 2)); + player.addPotionEffect(new PotionEffect(Potion.hunger.getId(), 20*15, 1)); + player.triggerAchievement(AchievementRegistry.madness); + } + } + + /** + * 正気度を与える + * @param player + * @param trial ダイスを振る回数 + * @param max 何面ダイス? + * @param sim 実際に結果を反映させるか否か + * @return 変化量 + */ + public static int addSanity(EntityPlayer player, int trial, int max, boolean sim){ + if(max<=0 || trial<=0 || player==null) return 0; + FBSEntityProperties prop=FBSEntityProperties.get(player); + if(prop==null) return 0; + + int as=0; + if(player instanceof EntityPlayerMP && !player.worldObj.isRemote){ + PlayerSanityRollEvent psre=new PlayerSanityRollEvent(player, trial, max); + if(MinecraftForge.EVENT_BUS.post(psre) || psre.newTrial<=0 || psre.newMax==0) return 0; + + //符号の反転 + boolean isReversed=psre.newMax<0; + trial=psre.newTrial; + max=isReversed?-psre.newMax:psre.newMax; + for(int i=0;i0){ + addSAN(player, prop, as); + } + else{ + loseSAN(player, prop, as); + } + + sendPacket(player); + } + } + } + return as; + } + + /** + * 正気度を失わせる + * @param player + * @param trial ダイスを振る回数 + * @param max 何面ダイス? + * @param sim 実際に結果を反映させるか否か + * @return 変化量 + */ + public static int loseSanity(EntityPlayer player, int trial, int max, boolean sim){ + //FMLLog.info("called lose!"); + if(max<=0 || trial<=0 || player==null) return 0; + FBSEntityProperties prop=FBSEntityProperties.get(player); + if(prop==null) return 0; + + int as=0; + if(player instanceof EntityPlayerMP && !player.worldObj.isRemote){ + PlayerSanityRollEvent psre=new PlayerSanityRollEvent(player, trial, -max); + if(MinecraftForge.EVENT_BUS.post(psre) || psre.newTrial<=0 || psre.newMax==0) return 0; + + //符号の反転 + boolean isReversed=psre.newMax>0; + trial=psre.newTrial; + max=isReversed?psre.newMax:-psre.newMax; + for(int i=0;i0){ + loseSAN(player, prop, as); + } + else if(as<0){ + //SAN値が増える場合 + addSAN(player, prop, as); + } + + sendPacket(player); + } + } + } + return as; + } + + /** + * 魔術経験値を与える。レベルアップの判定と処理もここ + * @param player + * @param exp + * @param sim 実際に結果を反映させるか否か + * @return 経験値の変化量 + */ + public static double addExp(EntityPlayer player, double exp, boolean sim){ + if(exp<=0 || player==null) return 0; + FBSEntityProperties prop=FBSEntityProperties.get(player); + if(prop==null) return 0; + + if(player instanceof EntityPlayerMP && !player.worldObj.isRemote){ + if(sim){ + PlayerSanityEvent ev=new PlayerSanityEvent(player, 0, exp, 0); + boolean hc= MinecraftForge.EVENT_BUS.post(ev); + if(!hc){ + int lv=prop.getMagicLevel(); + exp=ev.newChangeExp; + if(exp>0){ + //経験値が増える場合のみ + prop.addEXP(exp); + if(lv!=prop.getMagicLevel()) { + player.addChatComponentMessage(new ChatComponentText(String.format(StatCollector.translateToLocal("info.fbs.lv.0"), prop.getMagicLevel()))); + } + } + sendPacket(player); + } + } + } + return exp; + } + + public static void addDestination(EntityPlayer player, int dimId, int x, int y, int z){ + FBSEntityProperties prop=FBSEntityProperties.get(player); + if(prop.addDestination(dimId, x, y,z)){ + //狭間生成用が追加されたとき,名前の変更 + if(dimId==FBS.dimensionCrackId && x==-1 && y==-1 && z==-1){ + ArrayList list=prop.getDestinations(); + list.get(list.size()-1).setName("???"); + } + } + sendPacket(player); + } + + public static void setSpirit(EntityPlayer player, String name, int lv){ + FBSEntityProperties prop=FBSEntityProperties.get(player); + prop.setSpiritToolName(name); + prop.setSpiritToolLevel(lv); + sendPacket(player); + } + public static void setSpiritName(EntityPlayer entityPlayer, String name){ + FBSEntityProperties prop=FBSEntityProperties.get(entityPlayer); + prop.setSpiritToolName(name); + sendPacket(entityPlayer); + } + public static void setSpiritLevel(EntityPlayer entityPlayer, int lv){ + FBSEntityProperties prop=FBSEntityProperties.get(entityPlayer); + prop.setSpiritToolLevel(lv); + sendPacket(entityPlayer); + } + + public static void loadProxyData(EntityPlayer player) { + PacketHandler.INSTANCE.sendTo(new MessagePlayerProperties(player), (EntityPlayerMP)player); + } + public static void sendPacket(EntityPlayer player) { + PacketHandler.INSTANCE.sendTo(new MessagePlayerProperties(player), (EntityPlayerMP)player); + } +} -- cgit v1.2.3