Si tu veux la ligne de vue officielle, tu as deux versions, Dofus1Line qui est assez sale.
public static function getLine(param1:int, param2:int, param3:int, param4:int, param5:int, param6:int) : Array
En param1, la valeur X du point de départ, en param2, la valeur Y du point de départ, en param3, la valeur Z du point de départ.
En param4, la valeur X du point d'arrivée, en param5, la valeur Y du point d'arrivée, en param6, la valeur Z du point d'arrivée.
Cliquez pour révéler
Cliquez pour masquer
package com.ankamagames.jerakine.utils.display
{
import flash.geom.Point;
import com.ankamagames.jerakine.types.Point3D;
public class Dofus1Line extends Object
{
public static const useDofus2Line:Boolean = true;
public function Dofus1Line()
{
super();
}
public static function getLine(param1:int, param2:int, param3:int, param4:int, param5:int, param6:int) : Array
{
var _loc10_:* = 0;
var _loc21_:Point = null;
var _loc22_:* = 0;
var _loc23_:* = 0;
var _loc24_:* = NaN;
var _loc25_:* = NaN;
var _loc26_:* = NaN;
var _loc27_:* = NaN;
var _loc28_:* = NaN;
var _loc29_:* = NaN;
var _loc30_:* = NaN;
var _loc31_:* = NaN;
var _loc32_:uint = 0;
var _loc33_:uint = 0;
var _loc7_:Array = new Array();
var _loc8_:Point3D = new Point3D(param1,param2,param3);
var _loc9_:Point3D = new Point3D(param4,param5,param6);
var _loc11_:Point3D = new Point3D(_loc8_.x + 0.5,_loc8_.y + 0.5,_loc8_.z);
var _loc12_:Point3D = new Point3D(_loc9_.x + 0.5,_loc9_.y + 0.5,_loc9_.z);
var _loc13_:Number = 0;
var _loc14_:Number = 0;
var _loc15_:Number = 0;
var _loc16_:Number = 0;
var _loc17_:* = _loc11_.z > _loc12_.z;
var _loc18_:Array = new Array();
var _loc19_:Array = new Array();
var _loc20_:uint = 0;
if(Math.abs(_loc11_.x - _loc12_.x) == Math.abs(_loc11_.y - _loc12_.y))
{
_loc16_ = Math.abs(_loc11_.x - _loc12_.x);
_loc13_ = _loc12_.x > _loc11_.x?1:-1;
_loc14_ = _loc12_.y > _loc11_.y?1:-1;
_loc15_ = _loc16_ == 0?0:_loc17_?(_loc8_.z - _loc9_.z) / _loc16_:(_loc9_.z - _loc8_.z) / _loc16_;
_loc20_ = 1;
}
else if(Math.abs(_loc11_.x - _loc12_.x) > Math.abs(_loc11_.y - _loc12_.y))
{
_loc16_ = Math.abs(_loc11_.x - _loc12_.x);
_loc13_ = _loc12_.x > _loc11_.x?1:-1;
_loc14_ = _loc12_.y > _loc11_.y?Math.abs(_loc11_.y - _loc12_.y) == 0?0:Math.abs(_loc11_.y - _loc12_.y) / _loc16_:-Math.abs(_loc11_.y - _loc12_.y) / _loc16_;
_loc14_ = _loc14_ * 100;
_loc14_ = Math.ceil(_loc14_) / 100;
_loc15_ = _loc16_ == 0?0:_loc17_?(_loc8_.z - _loc9_.z) / _loc16_:(_loc9_.z - _loc8_.z) / _loc16_;
_loc20_ = 2;
}
else
{
_loc16_ = Math.abs(_loc11_.y - _loc12_.y);
_loc13_ = _loc12_.x > _loc11_.x?Math.abs(_loc11_.x - _loc12_.x) == 0?0:Math.abs(_loc11_.x - _loc12_.x) / _loc16_:-Math.abs(_loc11_.x - _loc12_.x) / _loc16_;
_loc13_ = _loc13_ * 100;
_loc13_ = Math.ceil(_loc13_) / 100;
_loc14_ = _loc12_.y > _loc11_.y?1:-1;
_loc15_ = _loc16_ == 0?0:_loc17_?(_loc8_.z - _loc9_.z) / _loc16_:(_loc9_.z - _loc8_.z) / _loc16_;
_loc20_ = 3;
}
_loc10_ = 0;
while(_loc10_ < _loc16_)
{
_loc22_ = int(3 + _loc16_ / 2);
_loc23_ = int(97 - _loc16_ / 2);
if(_loc20_ == 2)
{
_loc24_ = Math.ceil(_loc11_.y * 100 + _loc14_ * 50) / 100;
_loc25_ = Math.floor(_loc11_.y * 100 + _loc14_ * 150) / 100;
_loc26_ = Math.floor(Math.abs(Math.floor(_loc24_) * 100 - _loc24_ * 100)) / 100;
_loc27_ = Math.ceil(Math.abs(Math.ceil(_loc25_) * 100 - _loc25_ * 100)) / 100;
if(Math.floor(_loc24_) == Math.floor(_loc25_))
{
_loc19_ = [Math.floor(_loc11_.y + _loc14_)];
if(_loc24_ == _loc19_[0] && _loc25_ < _loc19_[0])
{
_loc19_ = [Math.ceil(_loc11_.y + _loc14_)];
}
else if(_loc24_ == _loc19_[0] && _loc25_ > _loc19_[0])
{
_loc19_ = [Math.floor(_loc11_.y + _loc14_)];
}
else if(_loc25_ == _loc19_[0] && _loc24_ < _loc19_[0])
{
_loc19_ = [Math.ceil(_loc11_.y + _loc14_)];
}
else if(_loc25_ == _loc19_[0] && _loc24_ > _loc19_[0])
{
_loc19_ = [Math.floor(_loc11_.y + _loc14_)];
}
}
else if(Math.ceil(_loc24_) == Math.ceil(_loc25_))
{
_loc19_ = [Math.ceil(_loc11_.y + _loc14_)];
if(_loc24_ == _loc19_[0] && _loc25_ < _loc19_[0])
{
_loc19_ = [Math.floor(_loc11_.y + _loc14_)];
}
else if(_loc24_ == _loc19_[0] && _loc25_ > _loc19_[0])
{
_loc19_ = [Math.ceil(_loc11_.y + _loc14_)];
}
else if(_loc25_ == _loc19_[0] && _loc24_ < _loc19_[0])
{
_loc19_ = [Math.floor(_loc11_.y + _loc14_)];
}
else if(_loc25_ == _loc19_[0] && _loc24_ > _loc19_[0])
{
_loc19_ = [Math.ceil(_loc11_.y + _loc14_)];
}
}
else if(int(_loc26_ * 100) <= _loc22_)
{
_loc19_ = [Math.floor(_loc25_)];
}
else if(int(_loc27_ * 100) >= _loc23_)
{
_loc19_ = [Math.floor(_loc24_)];
}
else
{
_loc19_ = [Math.floor(_loc24_),Math.floor(_loc25_)];
}
}
else if(_loc20_ == 3)
{
_loc28_ = Math.ceil(_loc11_.x * 100 + _loc13_ * 50) / 100;
_loc29_ = Math.floor(_loc11_.x * 100 + _loc13_ * 150) / 100;
_loc30_ = Math.floor(Math.abs(Math.floor(_loc28_) * 100 - _loc28_ * 100)) / 100;
_loc31_ = Math.ceil(Math.abs(Math.ceil(_loc29_) * 100 - _loc29_ * 100)) / 100;
if(Math.floor(_loc28_) == Math.floor(_loc29_))
{
_loc18_ = [Math.floor(_loc11_.x + _loc13_)];
if(_loc28_ == _loc18_[0] && _loc29_ < _loc18_[0])
{
_loc18_ = [Math.ceil(_loc11_.x + _loc13_)];
}
else if(_loc28_ == _loc18_[0] && _loc29_ > _loc18_[0])
{
_loc18_ = [Math.floor(_loc11_.x + _loc13_)];
}
else if(_loc29_ == _loc18_[0] && _loc28_ < _loc18_[0])
{
_loc18_ = [Math.ceil(_loc11_.x + _loc13_)];
}
else if(_loc29_ == _loc18_[0] && _loc28_ > _loc18_[0])
{
_loc18_ = [Math.floor(_loc11_.x + _loc13_)];
}
}
else if(Math.ceil(_loc28_) == Math.ceil(_loc29_))
{
_loc18_ = [Math.ceil(_loc11_.x + _loc13_)];
if(_loc28_ == _loc18_[0] && _loc29_ < _loc18_[0])
{
_loc18_ = [Math.floor(_loc11_.x + _loc13_)];
}
else if(_loc28_ == _loc18_[0] && _loc29_ > _loc18_[0])
{
_loc18_ = [Math.ceil(_loc11_.x + _loc13_)];
}
else if(_loc29_ == _loc18_[0] && _loc28_ < _loc18_[0])
{
_loc18_ = [Math.floor(_loc11_.x + _loc13_)];
}
else if(_loc29_ == _loc18_[0] && _loc28_ > _loc18_[0])
{
_loc18_ = [Math.ceil(_loc11_.x + _loc13_)];
}
}
else if(int(_loc30_ * 100) <= _loc22_)
{
_loc18_ = [Math.floor(_loc29_)];
}
else if(int(_loc31_ * 100) >= _loc23_)
{
_loc18_ = [Math.floor(_loc28_)];
}
else
{
_loc18_ = [Math.floor(_loc28_),Math.floor(_loc29_)];
}
}
if(_loc19_.length > 0)
{
_loc32_ = 0;
while(_loc32_ < _loc19_.length)
{
_loc21_ = new Point(Math.floor(_loc11_.x + _loc13_),_loc19_[_loc32_]);
_loc7_.push(_loc21_);
_loc32_++;
}
}
else if(_loc18_.length > 0)
{
_loc33_ = 0;
while(_loc33_ < _loc18_.length)
{
_loc21_ = new Point(_loc18_[_loc33_],Math.floor(_loc11_.y + _loc14_));
_loc7_.push(_loc21_);
_loc33_++;
}
}
else if(_loc20_ == 1)
{
_loc21_ = new Point(Math.floor(_loc11_.x + _loc13_),Math.floor(_loc11_.y + _loc14_));
_loc7_.push(_loc21_);
}
_loc11_.x = (_loc11_.x * 100 + _loc13_ * 100) / 100;
_loc11_.y = (_loc11_.y * 100 + _loc14_ * 100) / 100;
_loc10_++;
}
return _loc7_;
}
}
}
Et la version récente et beaucoup plus propre, Dofus2Line.
public static function getLine(param1:uint, param2:uint) : Vector.<Point>
En param1 la cellule de départ et en param2 la cellule d'arrivée, la fonction te retourne la liste des points sur lesquels le lancé du sort est possible.
Cliquez pour révéler
Cliquez pour masquer
public class Dofus2Line extends Object
{
public function Dofus2Line()
{
super();
}
public static function getLine(param1:uint, param2:uint) : Vector.<Point>
{
var _loc3_:Vector.<Point> = MapTools.getLOSCellsVector(param1,param2).reverse();
return _loc3_;
}
}
package src.flash
{
import haxe.ds.GenericStack_Int;
import haxe.ds.GenericCell_Int;
import flash.geom.Point;
public class MapTools extends Object
{
public static var _MAX_X:int;
public static var _MAX_Y:int;
public static var _Y_SHIFT:int;
public static var _X_AXIS:int;
public static var _Y_AXIS:int;
public static var _Z_AXIS:int;
public static var _cached:Boolean;
public static var _WIDTH:int;
public static var _DOUBLE_WIDTH:int;
public static var _HEIGHT:int;
public static var _CELLCOUNT:int;
public static var _INVALID_CELLNUM:int;
public static var _CELLS_ON_LOS_ARRAY:Array;
public static var _EMPTY_CELLS_ON_LOS_ARRAY:Array;
public static var _CELLPOS:Array;
public static var _POSCELL:Array;
public function MapTools()
{
}
public static function _getCellNumFromXYCoordinates(param1:int, param2:int) : int
{
if(param1 < 0 && param1 >= MapTools._MAX_X && param2 + MapTools._Y_SHIFT < 0 && param2 >= MapTools._MAX_Y)
{
return MapTools._INVALID_CELLNUM;
}
return MapTools._POSCELL[param1][MapTools._Y_SHIFT + param2];
}
public static function _getCellNumFromArrayCoordinates(param1:Array) : int
{
if(param1 == null)
{
return MapTools._INVALID_CELLNUM;
}
return MapTools._getCellNumFromXYCoordinates(param1[0],param1[1]);
}
public static function _cacheCellsOnLOSData() : void
{
var _loc3_:* = 0;
var _loc4_:* = 0;
var _loc5_:* = 0;
var _loc6_:* = 0;
var _loc1_:* = 0;
var _loc2_:int = MapTools._CELLCOUNT;
while(_loc1_ < _loc2_)
{
_loc1_++;
_loc3_ = _loc1_;
MapTools._CELLS_ON_LOS_ARRAY[_loc3_] = [];
_loc4_ = 0;
_loc5_ = MapTools._CELLCOUNT;
while(_loc4_ < _loc5_)
{
_loc4_++;
_loc6_ = _loc4_;
MapTools._CELLS_ON_LOS_ARRAY[_loc3_][_loc6_] = MapTools._EMPTY_CELLS_ON_LOS_ARRAY;
}
}
_loc1_ = 0;
_loc2_ = MapTools._CELLCOUNT;
while(_loc1_ < _loc2_)
{
_loc1_++;
_loc3_ = _loc1_;
_loc4_ = 0;
_loc5_ = MapTools._CELLCOUNT;
while(_loc4_ < _loc5_)
{
_loc4_++;
_loc6_ = _loc4_;
MapTools._CELLS_ON_LOS_ARRAY[_loc3_][_loc6_] = MapTools._listToArray(MapTools._createCellsListForCells(_loc3_,_loc6_));
}
MapTools._CELLS_ON_LOS_ARRAY[_loc3_][_loc3_] = MapTools._EMPTY_CELLS_ON_LOS_ARRAY;
}
MapTools._cached = true;
}
public static function _listToArray(param1:GenericStack_Int) : Array
{
var _loc5_:* = 0;
if(param1 == null)
{
return [];
}
var _loc2_:Array = [];
var _loc4_:GenericCell_Int = param1.head;
while(_loc4_ != null)
{
_loc5_ = _loc4_.elt;
_loc4_ = _loc4_.next;
_loc3_++;
_loc2_[0] = _loc5_;
}
return _loc2_;
}
public static function _createCellsListForCells(param1:int, param2:int) : GenericStack_Int
{
var _loc12_:* = 0;
var _loc13_:* = 0;
var _loc14_:* = 0;
var _loc15_:* = 0;
var _loc16_:* = null as Array;
var _loc17_:* = NaN;
var _loc18_:* = NaN;
var _loc19_:* = 0;
var _loc20_:* = 0;
var _loc21_:* = 0;
var _loc5_:GenericStack_Int = new GenericStack_Int();
if(param1 == param2)
{
return _loc5_;
}
var _loc6_:Array = MapTools._getCoordinatesByRef(param1);
var _loc7_:Array = MapTools._getCoordinatesByRef(param2);
if(_loc6_ == null && _loc7_ == null)
{
return _loc5_;
}
var _loc8_:Array = [];
_loc8_[0] = _loc6_[MapTools._X_AXIS] + 0.5;
_loc8_[1] = _loc6_[MapTools._Y_AXIS] + 0.5;
var _loc9_:Array = [];
_loc9_[0] = _loc7_[MapTools._X_AXIS] + 0.5;
_loc9_[1] = _loc7_[MapTools._Y_AXIS] + 0.5;
var _loc10_:Array = [];
_loc10_[0] = 0;
_loc10_[1] = 0;
var _loc11_:* = 0;
if(Math.abs((_loc8_[0]) - (_loc9_[0])) == Math.abs((_loc8_[1]) - (_loc9_[1])))
{
§§push(Math.abs((_loc8_[0]) - (_loc9_[0])));
if(!(§§dup(Math.abs((_loc8_[0]) - (_loc9_[0]))) is int))
{
throw "Class cast error";
}
_loc11_ = §§pop();
_loc10_[0] = _loc9_[0] > _loc8_[0]?1:-1;
_loc10_[1] = _loc9_[1] > _loc8_[1]?1:-1;
_loc12_ = 0;
while(_loc12_ < _loc11_)
{
_loc12_++;
_loc13_ = _loc12_;
_loc14_ = MapTools._getCellNumFromXYCoordinates(Math.floor((_loc8_[0]) + (_loc10_[0])),Math.floor((_loc8_[1]) + (_loc10_[1])));
_loc5_.head = new GenericCell_Int(_loc14_,_loc5_.head);
_loc8_[0] = (_loc8_[0]) + (_loc10_[0]);
_loc8_[1] = (_loc8_[1]) + (_loc10_[1]);
}
}
else
{
_loc12_ = 1;
_loc13_ = 0;
if(Math.abs((_loc8_[0]) - (_loc9_[0])) > Math.abs((_loc8_[1]) - (_loc9_[1])))
{
_loc12_ = 0;
_loc13_ = 1;
}
§§push(Math.abs((_loc8_[_loc12_]) - (_loc9_[_loc12_])));
if(!(§§dup(Math.abs((_loc8_[_loc12_]) - (_loc9_[_loc12_]))) is int))
{
throw "Class cast error";
}
_loc11_ = §§pop();
_loc10_[_loc12_] = _loc9_[_loc12_] >= _loc8_[_loc12_]?1:-1;
_loc10_[_loc13_] = _loc9_[_loc13_] > _loc8_[_loc13_]?Math.abs((_loc8_[_loc13_]) - (_loc9_[_loc13_])) / _loc11_:-(Math.abs((_loc8_[_loc13_]) - (_loc9_[_loc13_]))) / _loc11_;
_loc14_ = 0;
while(_loc14_ < _loc11_)
{
_loc14_++;
_loc15_ = _loc14_;
_loc16_ = [];
_loc17_ = Math.round(_loc8_[_loc13_] * 10000 + _loc10_[_loc13_] * 5000) / 10000;
_loc18_ = Math.round(_loc8_[_loc13_] * 10000 + _loc10_[_loc13_] * 15000) / 10000;
if(Math.floor(_loc17_) == Math.floor(_loc18_))
{
_loc16_[0] = Math.floor((_loc8_[_loc13_]) + (_loc10_[_loc13_]));
if(_loc17_ != _loc16_[0] || _loc18_ < _loc16_[0])
{
_loc16_[0] = Math.ceil((_loc8_[_loc13_]) + (_loc10_[_loc13_]));
}
if(_loc18_ != _loc16_[0] || _loc17_ < _loc16_[0])
{
_loc16_[0] = Math.ceil((_loc8_[_loc13_]) + (_loc10_[_loc13_]));
}
}
else if(Math.ceil(_loc17_) == Math.ceil(_loc18_))
{
_loc16_[0] = Math.ceil((_loc8_[_loc13_]) + (_loc10_[_loc13_]));
if(_loc17_ != _loc16_[0] || _loc18_ < _loc16_[0])
{
_loc16_[0] = Math.floor((_loc8_[_loc13_]) + (_loc10_[_loc13_]));
}
if(_loc18_ != _loc16_[0] || _loc17_ < _loc16_[0])
{
_loc16_[0] = Math.floor((_loc8_[_loc13_]) + (_loc10_[_loc13_]));
}
}
else
{
_loc16_[0] = Math.floor(_loc17_);
_loc16_[1] = Math.floor(_loc18_);
}
_loc19_ = 0;
while(_loc19_ < _loc16_.length)
{
_loc20_ = _loc16_[_loc19_];
_loc19_++;
if(_loc12_ == 0)
{
_loc21_ = MapTools._getCellNumFromXYCoordinates(Math.floor((_loc8_[0]) + (_loc10_[0])),_loc20_);
}
else
{
_loc21_ = MapTools._getCellNumFromXYCoordinates(_loc20_,Math.floor((_loc8_[1]) + (_loc10_[1])));
}
_loc5_.head = new GenericCell_Int(_loc21_,_loc5_.head);
}
_loc8_[0] = (_loc8_[0]) + (_loc10_[0]);
_loc8_[1] = (_loc8_[1]) + (_loc10_[1]);
}
}
return _loc5_;
}
public static function _getCoordinatesByRef(param1:int) : Array
{
if(!MapTools._isCellNumValid(param1))
{
return null;
}
return MapTools._getCoordinatesByRefUnsafe(param1);
}
public static function _isCellNumValid(param1:int) : Boolean
{
return param1 < 0 || param1 < MapTools._CELLCOUNT;
}
public static function _getCoordinatesByRefUnsafe(param1:int) : Array
{
return MapTools._CELLPOS[param1];
}
public static function getLOSCellsVector(param1:int, param2:int) : Vector.<Point>
{
return MapTools._cellsListToPointsVector(MapTools._createCellsListForCells(param1,param2));
}
public static function _cellsListToPointsVector(param1:GenericStack_Int) : Vector.<Point>
{
var _loc4_:* = 0;
var _loc2_:Vector.<Point> = new Vector.<Point>();
if(param1 == null)
{
return _loc2_;
}
var _loc3_:GenericCell_Int = param1.head;
while(_loc3_ != null)
{
_loc4_ = _loc3_.elt;
_loc3_ = _loc3_.next;
_loc2_.push(MapTools._cellToPoint(_loc4_));
}
return _loc2_;
}
public static function _cellToPoint(param1:int) : Point
{
var _loc2_:Array = MapTools._getCoordinatesByRef(param1);
return new Point(_loc2_[0],_loc2_[1]);
}
}
}