forked from FlipskiZ/BaseMod
-
Notifications
You must be signed in to change notification settings - Fork 114
/
CustomPlayer.java
344 lines (296 loc) · 9.58 KB
/
CustomPlayer.java
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
package basemod.abstracts;
import basemod.BaseMod;
import basemod.animations.AbstractAnimation;
import basemod.animations.G3DJAnimation;
import basemod.animations.SpineAnimation;
import basemod.interfaces.ModelRenderSubscriber;
import basemod.patches.com.megacrit.cardcrawl.unlock.UnlockTracker.CountModdedUnlockCards;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.evacipated.cardcrawl.modthespire.lib.SpireOverride;
import com.evacipated.cardcrawl.modthespire.lib.SpireSuper;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.cutscenes.CutscenePanel;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.helpers.CardLibrary;
import com.megacrit.cardcrawl.helpers.ImageMaster;
import com.megacrit.cardcrawl.helpers.Prefs;
import com.megacrit.cardcrawl.helpers.SaveHelper;
import com.megacrit.cardcrawl.localization.CharacterStrings;
import com.megacrit.cardcrawl.saveAndContinue.SaveAndContinue;
import com.megacrit.cardcrawl.screens.CharSelectInfo;
import com.megacrit.cardcrawl.screens.stats.CharStat;
import com.megacrit.cardcrawl.screens.stats.StatsScreen;
import com.megacrit.cardcrawl.ui.panels.energyorb.EnergyOrbInterface;
import com.megacrit.cardcrawl.unlock.UnlockTracker;
import com.megacrit.cardcrawl.vfx.AbstractGameEffect;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public abstract class CustomPlayer extends AbstractPlayer implements ModelRenderSubscriber
{
private static final Logger logger = LogManager.getLogger(CustomPlayer.class.getName());
protected AbstractAnimation animation;
protected EnergyOrbInterface energyOrb;
protected Prefs prefs;
protected CharStat charStat;
public CustomPlayer(String name, PlayerClass playerClass, String[] orbTextures, String orbVfxPath,
String model, String animation) {
this(name, playerClass, orbTextures, orbVfxPath, null, model, animation);
}
public CustomPlayer(String name, PlayerClass playerClass, EnergyOrbInterface energyOrbInterface,
String model, String animation) {
this(name, playerClass, energyOrbInterface, new G3DJAnimation(model, animation));
}
public CustomPlayer(String name, PlayerClass playerClass, String[] orbTextures, String orbVfxPath, float[] layerSpeeds,
String model, String animation) {
this(name, playerClass, orbTextures, orbVfxPath, layerSpeeds, new G3DJAnimation(model, animation));
}
public CustomPlayer(String name, PlayerClass playerClass, String[] orbTextures, String orbVfxPath, AbstractAnimation animation) {
this(name, playerClass, orbTextures, orbVfxPath, null, animation);
}
public CustomPlayer(String name, PlayerClass playerClass, String[] orbTextures, String orbVfxPath, float[] layerSpeeds,
AbstractAnimation animation) {
this(name, playerClass, new CustomEnergyOrb(orbTextures, orbVfxPath, layerSpeeds), animation);
}
public CustomPlayer(String name, PlayerClass playerClass, EnergyOrbInterface energyOrbInterface, AbstractAnimation animation) {
super(name, playerClass);
energyOrb = energyOrbInterface;
charStat = new CharStat(this);
this.dialogX = (this.drawX + 0.0F * Settings.scale);
this.dialogY = (this.drawY + 220.0F * Settings.scale);
this.animation = animation;
if (animation instanceof SpineAnimation) {
SpineAnimation spine = (SpineAnimation) animation;
loadAnimation(spine.atlasUrl, spine.skeletonUrl, spine.scale);
}
if (animation.type() != AbstractAnimation.Type.NONE) {
this.atlas = new TextureAtlas();
}
if (animation.type() == AbstractAnimation.Type.MODEL) {
BaseMod.subscribe(this);
}
}
@Override
public void receiveModelRender(ModelBatch batch, Environment env) {
if (this != AbstractDungeon.player) {
BaseMod.unsubscribeLater(this);
} else {
animation.renderModel(batch, env);
}
}
@Override
public void renderPlayerImage(SpriteBatch sb) {
switch (animation.type()) {
case NONE:
super.renderPlayerImage(sb);
break;
case MODEL:
BaseMod.publishAnimationRender(sb);
break;
case SPRITE:
animation.setFlip(flipHorizontal, flipVertical);
animation.renderSprite(sb, drawX + animX, drawY + animY + AbstractDungeon.sceneOffsetY);
break;
}
}
@Override
public String getAchievementKey()
{
// Returning null crashes the game, hopefully returning a fake key won't
return "MODDING";
}
@Override
public ArrayList<AbstractCard> getCardPool(ArrayList<AbstractCard> tmpPool)
{
AbstractCard.CardColor color = getCardColor();
for (Map.Entry<String, AbstractCard> c : CardLibrary.cards.entrySet()) {
AbstractCard card = c.getValue();
if (card.color.equals(color) && card.rarity != AbstractCard.CardRarity.BASIC &&
(!UnlockTracker.isCardLocked(c.getKey()) || Settings.isDailyRun)) {
tmpPool.add(card);
}
}
return tmpPool;
}
@Override
public String getLeaderboardCharacterName()
{
// This is never called
// The one place it's called is gated behind an isModded check
return null;
}
@Override
public Texture getEnergyImage()
{
if (energyOrb instanceof CustomEnergyOrb) {
return ((CustomEnergyOrb) energyOrb).getEnergyImage();
}
throw new RuntimeException();
}
@Override
public TextureAtlas.AtlasRegion getOrb()
{
return BaseMod.getCardEnergyOrbAtlasRegion(getCardColor());
}
@Override
public void renderOrb(SpriteBatch sb, boolean enabled, float current_x, float current_y)
{
energyOrb.renderOrb(sb, enabled, current_x, current_y);
}
@Override
public void updateOrb(int energyCount)
{
energyOrb.updateOrb(energyCount);
}
@Override
public String getSaveFilePath()
{
return SaveAndContinue.getPlayerSavePath(chosenClass);
}
@Override
public Prefs getPrefs()
{
if (prefs == null) {
logger.error("prefs need to be initialized first!");
}
return prefs;
}
@Override
public void loadPrefs()
{
if (prefs == null) {
prefs = SaveHelper.getPrefs(chosenClass.name());
}
}
@Override
public CharStat getCharStat()
{
return charStat;
}
@Override
public int getUnlockedCardCount()
{
return CountModdedUnlockCards.getUnlockedCardCount(chosenClass);
}
@Override
public int getSeenCardCount()
{
return BaseMod.getSeenCardCount(getCardColor());
}
@Override
public int getCardCount()
{
return BaseMod.getCardCount(getCardColor());
}
@Override
public boolean saveFileExists()
{
return SaveAndContinue.saveExistsAndNotCorrupted(this);
}
@Override
public String getWinStreakKey()
{
// The only places this is called then pass it to Steam integration
// I'm uncertain what Steam will do with these unofficial keys
return "win_streak_" + chosenClass.name();
}
@Override
public String getLeaderboardWinStreakKey()
{
// This is never called
// The one place it's called is gated behind an isModded check
return chosenClass.name() + "_CONSECUTIVE_WINS";
}
@Override
public void renderStatScreen(SpriteBatch sb, float screenX, float screenY)
{
StatsScreen.renderHeader(sb, BaseMod.colorString(getLocalizedCharacterName(), "#" + getCardRenderColor().toString()), screenX, screenY);
getCharStat().render(sb, screenX, screenY);
}
@Override
public Texture getCustomModeCharacterButtonImage()
{
if (BaseMod.getCustomModePlayerButton(chosenClass) != null) {
return ImageMaster.loadImage(BaseMod.getCustomModePlayerButton(chosenClass));
} else {
Pixmap pixmap = new Pixmap(Gdx.files.internal(BaseMod.getPlayerButton(chosenClass)));
Pixmap small = new Pixmap(128, 128, pixmap.getFormat());
small.drawPixmap(pixmap,
0, 0, pixmap.getWidth(), pixmap.getHeight(),
20, 20, small.getWidth() - 40, small.getHeight() - 40);
Texture texture = new Texture(small);
pixmap.dispose();
small.dispose();
return texture;
}
}
@Override
public CharacterStrings getCharacterString()
{
CharSelectInfo loadout = getLoadout();
CharacterStrings characterStrings = new CharacterStrings();
characterStrings.NAMES = new String[]{loadout.name};
characterStrings.TEXT = new String[]{loadout.flavorText};
return characterStrings;
}
@Override
public void refreshCharStat()
{
charStat = new CharStat(this);
}
@Override
public void movePosition(float x, float y)
{
float dialogOffsetX = dialogX - drawX;
float dialogOffsetY = dialogY - drawY;
drawX = x;
drawY = y;
dialogX = drawX + dialogOffsetX;
dialogY = drawY + dialogOffsetY;
animX = 0;
animY = 0;
refreshHitboxLocation();
}
@SpireOverride
protected void updateEscapeAnimation()
{
if (escapeTimer != 0) {
if (flipHorizontal) {
dialogX -= Gdx.graphics.getDeltaTime() * 400f * Settings.scale;
} else {
dialogX += Gdx.graphics.getDeltaTime() * 500f * Settings.scale;
}
}
SpireSuper.call();
}
public Texture getCutsceneBg()
{
return ImageMaster.loadImage("images/scenes/redBg.jpg");
}
public List<CutscenePanel> getCutscenePanels()
{
List<CutscenePanel> panels = new ArrayList<>();
panels.add(new CutscenePanel("images/scenes/ironclad1.png", "ATTACK_HEAVY"));
panels.add(new CutscenePanel("images/scenes/ironclad2.png"));
panels.add(new CutscenePanel("images/scenes/ironclad3.png"));
return panels;
}
public void updateVictoryVfx(ArrayList<AbstractGameEffect> effects)
{
}
@Override
public String getPortraitImageName()
{
return BaseMod.getPlayerPortrait(chosenClass);
}
}