package classes.weapons { import flash.geom.Point import classes.data.*; public class Animset { public static var ID:int = 0; public static var CENTREANGLE:int = 1;//Angle of a line pointing down the centre of attack cone. public static var ARCLENGTH:int = 2;//Total angle of the melee arc, centred on the centreangle public static var FRAME:int = 3;//The frame of the character that the animation is on./**/ public static var ANIMLENGTH:int = 4;//Time in seconds before another animation can be used public static var IMPACTPOINT:int = 5;//Time into the animation that the melee arc hits, or that bullet fires. if -1, there will be no event public static var IMPACTDURATION:int = 6;//lifespan of the melee arc, in seconds. public static var DAMAGEMULT:int = 7; public static var STATES:int = 8;//Moving, Sprinting, Crouching, Onground public static var WEAPONHIDE:int = 9;//boolean. if true, we hide the melee weapon during this attack public static var anims:Array = new Array(); anims[0] = [0.25, 0.5, 30, 1.5, 0.75, 0.5, 1.0 [-1,0,0,1]]; public var owner:*;//The weapon that this instance is linked to public var actorReference;//The actor using the weapon that this instance is linked to public var actorPhysicsID; public var containerReference;//The container holding the actor using the weapon that this instance is linked to public var active:Boolean = false;//true when all necessary things are validated and we're ready to work. var physics; var target:Point = new Point(); var targetOffset:Point = new Point(); var targetDirection:Number; var actorData:Array; var validAnims:Array = new Array();//a temporary variable used during animation finding. This will hold a list of animations that are deemed valid var validAnims2:Array = new Array();//similar to the above, this holds anims that pass the second stage of testing. var lastused:int = 0;//the animation ID of the last used animation. We will not reuse the last one twice in a row, IF that's possible. public function Animset(ownerObject:*) { //The input to this constructor is the object that this animset is registered to/being used by //usually, this will be the weapon that the animset is for. //From the ownerobject, we fetch the references of other objects that are relevant: trace("Animset starting 0"); owner = ownerObject; trace("Animset starting 1"); if (owner != null) { actorReference = owner.actorReference; trace("Animset starting 2"); containerReference = owner.containerReference; trace("Animset starting 3"); actorPhysicsID = actorReference.physicsID; trace("Animset starting 4"); physics = globals.physicsReference; active = true; } } public function getAnim(input:Array):Array { target = input[0]; actorData = input[1]; var ourPosition:Point = physics.getGlobalPosition(actorReference); targetOffset = target.subtract(ourPosition); targetDirection = Math.atan2(targetOffset.y, targetOffset.x); validAnims = new Array(); //input values will be: Target point, actor statearray checkStates(); checkAngles(targetDirection); var returnvalue; if (validAnims2.length > 0) { return chooseAnim(); } else { return null; } } function clone(itemToCopy):* { //just return a copy of any non-arrays if (!(itemToCopy is Array)) return itemToCopy; //but if it's an array, duplicate the contents // into a new one and return that. var newArray = new Array(); for(var i = itemToCopy.length - 1; i >= 0; i--) newArray[i] = clone(itemToCopy[i]); return newArray; } function chooseAnim() { if (validAnims2.length == 1) { return clone(validAnims2[0]); } } public function flipAngle(input:Number) { //This function takes in an angle, in radians, and flips it horizontally. //Under this system, the direction 0 is represented as X:1 Y:0 //AKA, forward/right is zero. TO the left is Tau/2 or Pi //First we unrotate the angle so that zero is up input -= globals.TAU/4; //Then we flip the angle, vertically input *= -1; //then we re-rotate the angle input += globals.TAU/4; } public function checkStates() { var currentElement:Array; var states:Array; for (var i = 0; i < anims.length; i++) { currentElement = anims[i]; states = currentElement[STATES]; var isValid:Boolean = true; for (var j = 0; j < 4; j++) { if (states[j] != -1) { if (states[j] != actorData[j]) { isValid = false; } } } if (isValid == true) { validAnims.push(currentElement); } } } public function checkAngles(targetAngle:Number) { var currentElement:Array; var currentAngle:Number; for (var i = 0; i < anims.length; i++) { currentElement = anims[i]; var centre:Number = currentElement[CENTREANGLE]; var arclength:Number = currentElement[ARCLENGTH]; var isValid:Boolean = false; if (actorReference.facing == -1) { centre = flipAngle(centre); } if (targetAngle >= (centre - arclength*0.5) || targetAngle <= (centre + arclength*0.5)) { isValid = true } if (isValid == true) { validAnims2.push(currentElement); } } } } }