1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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;i<trial;i++){
as+=1+rand.nextInt(max);
}
if(sim){
PlayerSanityEvent ev=new PlayerSanityEvent(player, isReversed?-as:as, 0, 0);
boolean hc= MinecraftForge.EVENT_BUS.post(ev);
if(!hc){
as=ev.newChangeSanity;
if(as>0){
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;i<trial;i++){
as+=1+rand.nextInt(max);
}
if(sim){
PlayerSanityEvent ev=new PlayerSanityEvent(player, isReversed?as:-as, 0, 0);
boolean hc=MinecraftForge.EVENT_BUS.post(ev);
if(!hc){
as=-ev.newChangeSanity; //新しい変化量
if(as>0){
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<FBSEntityProperties.WarpPosition> 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);
}
}
|