1package com.fs.starfarer.api.impl.campaign.eventide;
4import java.util.ArrayList;
5import java.util.Iterator;
8import org.lwjgl.input.Keyboard;
9import org.lwjgl.opengl.GL11;
10import org.lwjgl.util.vector.Vector2f;
12import com.fs.starfarer.api.Global;
13import com.fs.starfarer.api.campaign.BaseCustomUIPanelPlugin;
14import com.fs.starfarer.api.campaign.CustomVisualDialogDelegate.DialogCallbacks;
15import com.fs.starfarer.api.campaign.InteractionDialogAPI;
16import com.fs.starfarer.api.input.InputEventAPI;
17import com.fs.starfarer.api.ui.CustomPanelAPI;
18import com.fs.starfarer.api.ui.PositionAPI;
19import com.fs.starfarer.api.util.FaderUtil;
20import com.fs.starfarer.api.util.Misc;
22public class DuelPanel extends BaseCustomUIPanelPlugin {
24 public static enum AttackResult {
32 public static boolean DEBUG =
true;
35 protected InteractionDialogAPI
dialog;
38 protected PositionAPI
p;
42 protected List<QuadParticles>
particles =
new ArrayList<QuadParticles>();
52 protected FaderUtil
blinker =
new FaderUtil(0f, 0.25f, 0.25f,
true,
true);
113 panel.tutorialMode =
true;
133 actor.maxHealth = health;
134 actor.health = health;
159 CustomPanelAPI
p =
panel.createCustomPanel(450, 120,
prompt);
160 panel.addComponent(
p).inTL(10, 30);
183 float cx =
p.getCenterX();
184 float cy =
p.getCenterY();
194 float extra = width -
p.getWidth();
217 if (
p ==
null)
return;
221 float cx =
p.getCenterX();
222 float cy =
p.getCenterY();
223 float w =
p.getWidth();
224 float h =
p.getHeight();
226 GL11.glDisable(GL11.GL_TEXTURE_2D);
227 GL11.glEnable(GL11.GL_SCISSOR_TEST);
230 GL11.glScissor((
int)(x * s), (
int)(y * s), (
int)(w * s), (
int)(h * s));
237 if (
DEBUG &&
false) {
240 Misc.renderQuad(
player.
loc.x - w2/2f,
player.
loc.y - h2/2f, w2, h2,
new Color(50,50,50,255), alphaMult);
258 if (centerX < leftX) {
260 }
else if (centerX > rightX) {
271 GL11.glDisable(GL11.GL_TEXTURE_2D);
272 Misc.renderQuad(x, y, w, h, Color.black, alphaMult);
273 Misc.renderQuad(x, y, w, h,
new Color(50,50,50,255), alphaMult);
284 GL11.glTranslatef(offsetX, 0, 0);
289 p.render(alphaMult,
true);
293 boolean playerAttack = player.currAction !=
null && player.currAction.anim !=
null &&
311 p.render(alphaMult,
false);
325 GL11.glDisable(GL11.GL_SCISSOR_TEST);
331 float w =
p.getWidth();
332 float h =
p.getHeight();
335 float pipH = 20f / 1.6f;
339 GL11.glDisable(GL11.GL_TEXTURE_2D);
340 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
345 renderPip(x + opad + (pipW + pad) * i, y + h - opad - pipH,
346 pipW, pipH, Misc.getPositiveHighlightColor(), alphaMult,
352 renderPip(x + w - opad - (pipW + pad) * (i + 1), y + h - opad - pipH,
353 pipW, pipH, Misc.getNegativeHighlightColor(), alphaMult,
359 public void renderPip(
float x,
float y,
float w,
float h, Color c,
float a,
boolean filled) {
361 Misc.renderQuad(x, y, w, h, c, a);
363 Misc.renderQuad(x, y, w, 1, c, a);
364 Misc.renderQuad(x, y + h - 1, w, 1, c, a);
365 Misc.renderQuad(x, y + 1, 1, h - 2, c, a);
366 Misc.renderQuad(x + w - 1, y + 1, 1, h - 2, c, a);
368 Misc.renderQuad(x + w, y - 1, 1, h, Color.black, a);
369 Misc.renderQuad(x + 1, y - 1, w - 1, 1, Color.black, a);
376 public static List<String>
cycle =
new ArrayList<String>();
382 public static List<String>
cycleHigh =
new ArrayList<String>();
390 if (
p ==
null)
return;
420 float timeUntilAttack = 0f;
422 if (!f.attackArea.isEmpty())
break;
423 timeUntilAttack += f.dur;
427 player.currAction =
null;
445 blinker.advance(amount * 1.5f);
447 Iterator<QuadParticles> iter =
particles.iterator();
448 while (iter.hasNext()) {
505 public void doAI(
float amount) {
530 if (
p ==
null)
return;
532 for (InputEventAPI event : events) {
533 if (event.isConsumed())
continue;
535 event.isKeyDownEvent() &&
event.getEventValue() == Keyboard.KEY_ESCAPE) {
541 if (event.isKeyDownEvent() &&
542 (
event.getEventValue() == Keyboard.KEY_UP ||
543 event.getEventValue() == Keyboard.KEY_NUMPAD8 ||
544 event.getEventValue() == Keyboard.KEY_W)) {
550 if (event.isKeyDownEvent() &&
551 (
event.getEventValue() == Keyboard.KEY_LEFT ||
552 event.getEventValue() == Keyboard.KEY_NUMPAD4 ||
553 event.getEventValue() == Keyboard.KEY_A)) {
564 if (event.isKeyDownEvent() &&
565 (
event.getEventValue() == Keyboard.KEY_RIGHT ||
566 event.getEventValue() == Keyboard.KEY_NUMPAD6 ||
567 event.getEventValue() == Keyboard.KEY_D)) {
578 if (event.isKeyDownEvent() &&
579 event.getEventValue() == Keyboard.KEY_SPACE) {
586 event.getEventValue() == Keyboard.KEY_F) {
594 if (event.isKeyDownEvent() &&
595 event.getEventValue() == Keyboard.KEY_G) {
609 if (playerAttackResult == AttackResult.HIT && enemyAttackResult == AttackResult.HIT) {
610 if ((
float) Math.random() < 0.5f) {
611 playerAttackResult = AttackResult.NO_HIT;
613 enemyAttackResult = AttackResult.NO_HIT;
617 if (playerAttackResult == AttackResult.BLOCK) {
619 player.currAction.wasBlocked =
true;
621 enemy.currAction.performedBlock =
true;
624 }
else if (playerAttackResult == AttackResult.HIT) {
626 player.currAction.scoredHit =
true;
629 if (enemyAttackResult == AttackResult.BLOCK) {
631 enemy.currAction.wasBlocked =
true;
633 player.currAction.performedBlock =
true;
636 }
else if (enemyAttackResult == AttackResult.HIT) {
638 enemy.currAction.scoredHit =
true;
649 if (a.
scoredHit)
return AttackResult.NO_HIT;
652 attack = attack.getAdjustedForAction(a);
654 block = block.getAdjustedForAction(d);
655 if (attack.intersects(block)) {
656 return AttackResult.BLOCK;
662 attack = attack.getAdjustedForAction(a);
664 hit = hit.getAdjustedForAction(d);
665 if (attack.intersects(hit)) {
666 return AttackResult.HIT;
671 return AttackResult.NO_HIT;
684 p.additiveBlend =
true;
690 p.minColor =
new Color(255, 200, 100, 155);
691 p.maxColor =
new Color(255, 255, 150, 255);
694 Vector2f loc = Vector2f.add(attacker.
loc, defender.
loc,
new Vector2f());
700 if (block !=
null && block.
curr !=
null) {
704 Vector2f loc2 =
new Vector2f(loc);
705 loc2.x = area.x + area.w / 2f + block.actor.facing * area.w * 0.25f;
706 float dist1 = Misc.getDistance(defender.
loc, loc);
707 float dist2 = Misc.getDistance(defender.
loc, loc2);
716 int num = 30 + Misc.random.nextInt(10);
717 for (
int i = 0; i < num; i++) {
718 Vector2f pos = Misc.getPointWithinRadius(loc, 5f);
719 Vector2f vel = Misc.getPointWithinRadius(
new Vector2f(), 200f);
720 p.addParticle(pos.x, pos.y, vel.x, vel.y);
735 actor.health -= damage;
744 Vector2f loc =
new Vector2f(actor.
loc);
762 p.minColor =
new Color(136, 8, 8, 155);
763 p.maxColor =
new Color(238, 75, 43, 255);
768 base -= actor.health * 15;
769 if (base < 20) base = 20;
771 int num = base + Misc.random.nextInt((
int) (base * 0.5f));
773 for (
int i = 0; i < num; i++) {
774 Vector2f pos = Misc.getPointWithinRadius(loc, 15f);
775 Vector2f vel = Misc.getPointWithinRadius(
new Vector2f(), 150f);
776 p.addParticle(pos.x, pos.y, vel.x, vel.y);
781 p.floorFriction = 100f;
789 return h / 2f * 9.81f;
794 return anim.frameHeight * anim.
scale;
static SettingsAPI getSettings()
static SoundPlayerAPI getSoundPlayer()
static final String IDLE_HIGH
static final String MOVE_BACK
static final String BLOCK
static final String GOT_HIT
static void initActions()
static final String MOVE_FORWARD
static final String ATTACK
static final String ATTACK_HIGH_RECOVERY
static final String MOVE_BACK_HIGH
static Map< String, CharAnim > ANIMATIONS
static final String BLOCK_LOW
static final String RIPOSTE
static final String RIPOSTE_HIGH
static final String MOVE_FORWARD_HIGH
static final String ATTACK_HIGH
static final String ATTACK_RECOVERY
void render(float alphaMult)
void doAction(String action, boolean forceInterruptCurrent)
void advance(float amount)
Map< String, String > actionRemap2
Map< String, String > actionRemap1
List< HitArea > attackArea
List< HitArea > blockArea
List< HitArea > hittableArea
boolean hasAttackFrames()
List< CharAnimFrame > frames
void processInput(List< InputEventAPI > events)
void init(CustomPanelAPI panel, DialogCallbacks callbacks, InteractionDialogAPI dialog)
static Actor createActor(String tex, boolean skilled)
void render(float alphaMult)
void wasHit(Actor actor, Actor by)
PositionAPI getPosition()
void addBlood(Vector2f loc, Actor actor)
static boolean DO_CYCLE_HIGH
static List< String > cycleHigh
void renderBelow(float alphaMult)
void positionChanged(PositionAPI position)
static DuelPanel createTutorial(boolean playerSkilled, String ambienceLoopId)
float getCharacterHeight()
CustomPanelAPI getPanel()
void renderPip(float x, float y, float w, float h, Color c, float a, boolean filled)
void advance(float amount)
static List< String > cycle
void renderHealth(float alphaMult)
void addSparks(Actor attacker, Actor defender)
DialogCallbacks callbacks
DuelBackground background
void addBlood(Actor actor)
static DuelPanel createDefault(boolean playerSkilled, boolean enemySkilled, String ambienceLoopId)
static float SOUND_LOC_MULT
AttackResult checkAttackVsDefense(Actor attacker, Actor defender)
List< QuadParticles > particles
InteractionDialogAPI dialog
void checkBlocksAndHits()
DuelPanel(Actor player, Actor enemy, DuelEnemyAI ai, DuelBackground background)
CustomPanelAPI getPanel()
void init(CustomPanelAPI panel, DialogCallbacks callbacks, InteractionDialogAPI dialog)
void reportAction(String actionId)
HitArea getAdjustedForAction(AnimAction action)
void advance(float amount)
float getScreenScaleMult()
void playUILoop(String id, float pitch, float volume)
void setListenerPosOverrideOneFrame(Vector2f listenerPosOverrideOneFrame)
void renderForeground(DuelPanel panel, float xOffset, float yOffset, float alphaMult)
void render(DuelPanel panel, float xOffset, float yOffset, float alphaMult)
void advance(float amount)
void render(float alphaMult)
void advance(float amount, DuelPanel duel)