001package com.fs.starfarer.api.impl.campaign.eventide; 002 003import java.awt.Color; 004import java.util.LinkedHashMap; 005import java.util.Map; 006 007import org.lwjgl.util.vector.Vector2f; 008 009import com.fs.starfarer.api.Global; 010import com.fs.starfarer.api.graphics.SpriteAPI; 011 012public class Actor { 013 014 public AnimAction currAction; 015 public AnimAction nextAction; 016 public float facing = 1f; 017 public Vector2f loc = new Vector2f(); 018 019 public int maxHealth; 020 public int health; 021 022 public String texId; 023 024 public Map<String, String> actionRemap1 = new LinkedHashMap<String, String>(); 025 public Map<String, String> actionRemap2 = new LinkedHashMap<String, String>(); 026 public Map<String, Float> actionSpeedMult = new LinkedHashMap<String, Float>(); 027 028 029 public Actor() { 030 this(null); 031 } 032 public Actor(String texId) { 033 this.texId = texId; 034 } 035 036 public String getActionId() { 037 if (currAction == null) return ""; 038 return currAction.anim.action; 039 } 040 041 public void endCurrentAnimation() { 042 if (currAction != null) { 043 currAction.makeCurrentFrameLast = true; 044 } 045 } 046 047 protected float freeze = 0f; 048 public void freeze(float sec) { 049 freeze = sec; 050 } 051 public void advance(float amount) { 052 freeze -= amount; 053 if (freeze > 0) return; 054 055 //amount *= 0.25f; 056 if (currAction != null) { 057 Float mult = actionSpeedMult.get(currAction.anim.action); 058 if (mult == null) mult = 1f; 059 currAction.advance(amount * mult); 060 if (currAction.isDone()) { 061 currAction = null; 062 } 063 } 064 if (currAction == null) { 065 if (nextAction != null) { 066 currAction = nextAction; 067 nextAction = null; 068 } else { 069 //currAction = new AnimAction(this, Actions.IDLE); 070 doAction(Actions.IDLE, true); 071 } 072 currAction.advance(0f); 073 } 074 } 075 076 public CharAnimFrame getCurrentFrame() { 077 if (currAction == null) return null; 078 return currAction.curr; 079 } 080 081 public void doAction(String action, boolean forceInterruptCurrent) { 082 if (action == Actions.ATTACK && 083 currAction != null && (currAction.performedBlock)) { 084 action = Actions.RIPOSTE; 085 forceInterruptCurrent = true; 086 } else if (currAction != null && currAction.anim != null && currAction.anim.interruptableBy.contains(action)) { 087 forceInterruptCurrent = true; 088 } 089 090 if (actionRemap1.containsKey(action)) { 091 action = actionRemap1.get(action); 092 } 093 if (actionRemap2.containsKey(action)) { 094 action = actionRemap2.get(action); 095 } 096 097 if (forceInterruptCurrent) { 098 nextAction = null; 099 currAction = new AnimAction(this, action, getCurrentFrame()); 100 if (currAction.anim == null) { 101 currAction = null; 102 } else { 103 currAction.advance(0f); 104 } 105 } else { 106 if (nextAction == null || nextAction.anim == null) { 107 nextAction = null; 108 } 109 nextAction = new AnimAction(this, action, getCurrentFrame()); 110 } 111 } 112 113 public void render(float alphaMult) { 114 boolean renderShadow = true; 115 renderShadow = false; 116 if (renderShadow && currAction != null && currAction.anim != null && currAction.curr != null && 117 !currAction.curr.hittableArea.isEmpty()) { 118 HitArea area = currAction.curr.hittableArea.get(0); 119 area = area.getAdjustedForAction(currAction); 120 SpriteAPI shadow = Global.getSettings().getSprite("graphics/fx/hit_glow.png"); 121 shadow.setNormalBlend(); 122 shadow.setColor(Color.black); 123 124 float sw = currAction.curr.width * 1.25f; 125 if (sw > 200) { 126 sw = 200 + (sw - 200) * 0.33f; 127 } 128 shadow.setSize(sw, 40f); 129 130 shadow.setAlphaMult(0.5f); 131 shadow.renderAtCenter(area.x + area.w/2f, loc.y - currAction.anim.frameHeight / 2f + 5f); 132 } 133 134 currAction.render(alphaMult); 135 } 136} 137 138 139 140 141