/** 取圆形战斗单位组 */ public void getCircleFightUnits(SList <Unit> list, PosData pos, float radius, float height, Unit selfUnit, bool[] influences) { list.clear(); ScenePosLogic posLogic = _scene.pos; float sq = radius * radius; Unit[] values; Unit k; for (int i = (values = _scene.getFightUnitDic().getValues()).Length - 1; i >= 0; --i) { if ((k = values[i]) != null) { PosData kPos = k.pos.getPos(); //高度合适 if (height <= 0 || posLogic.getDHeight(kPos, pos) <= height) { //在范围内 if (posLogic.calculatePosDistanceSq2D(kPos, pos) <= sq) { //符合影响类型 if (selfUnit.fight.checkTargetInfluence(k, influences)) { list.add(k); } } } } } }
/** 取矩形战斗单位组 */ public void getRectFightUnits(SList <Unit> list, PosData pos, DirData dir, float length, float width, float height, Unit selfUnit, bool[] influences) { list.clear(); ScenePosLogic posLogic = _scene.pos; PosData tempPos = _tempPos2; DirData tempDir = _tempDir2; //向后延伸 posLogic.polar2D(tempPos, Global.attackScopeBackLength, dir); posLogic.addPos2D(tempPos, pos); float halfWidth = width / 2f; float useLength = length + Global.attackScopeBackLength; float sq = halfWidth * halfWidth + useLength * useLength; Unit[] values; Unit k; for (int i = (values = _scene.getFightUnitDic().getValues()).Length - 1; i >= 0; --i) { if ((k = values[i]) != null) { PosData kPos = k.pos.getPos(); //高度值合适 if (height <= 0 || posLogic.getDHeight(kPos, pos) <= height) { float dq; //在圆形范围内 if ((dq = posLogic.calculatePosDistanceSq2D(kPos, pos)) <= sq) { //符合影响类型 if (selfUnit.fight.checkTargetInfluence(k, influences)) { float d = (float)Math.Sqrt(dq); posLogic.calculateDirByPos2D(tempDir, tempPos, kPos); float dirV = dir.direction - tempDir.direction; float h = (float)(Math.Cos(dirV) * d); float w = (float)(Math.Sin(dirV) * d); if (Math.Abs(w) <= halfWidth) { if (h >= 0 && h <= useLength) { list.add(k); } } } } } } } }
public override void dispose() { base.dispose(); _scenePosLogic = null; _d = null; _pos = null; _dir = null; _specialMoveConfig = null; _groundState = UnitActGroundStateType.Ground; _isSpasticity = false; _isBlowHurt = false; _isBlowDown = true; _specialMoveConfig = null; _moveType = MapMoveType.Land; if (_drive != null) { _drive.dispose(); } _moveTargetPos.clear(); _sendLastTime = 0; _moveType = MapMoveType.Land; _walkSpeedRatio = 1f; }
public override void init() { base.init(); _scenePosLogic = _scene.pos; _d = _data.pos; _posDir.pos = _pos = _d.pos; _posDir.dir = _dir = _d.dir; }
/** 注册逻辑体 */ protected virtual void registLogics() { if ((unitFactory = createUnitFactoryLogic()) != null) { addLogic(unitFactory); } if ((inout = createInOutLogic()) != null) { addLogic(inout); } if ((role = createRoleLogic()) != null) { addLogic(role); } if ((pos = createPosLogic()) != null) { addLogic(pos); } if ((show = createShowLogic()) != null) { addLogic(show); } //必须存在 addLogic(load = createLoadLogic()); if ((fight = createFightLogic()) != null) { addLogic(fight); } //必须存在 addLogic(camera = createCameraLogic()); //添加battle逻辑 if ((battle = createBattleLogic()) != null) { addLogic(battle); } //添加play逻辑 if ((method = createMethodLogic()) != null) { addLogic(method); } else { Ctrl.throwError("不能没有play"); } }
/** 取扇形战斗单位组(sectorAngle:角度值) */ public void getSectorFightUnits(SList <Unit> list, PosData pos, DirData dir, float radius, float sectorAngle, float height, Unit selfUnit, bool[] influences) { list.clear(); ScenePosLogic posLogic = _scene.pos; PosData tempPos = _tempPos2; DirData tempDir = _tempDir2; //向后延伸 posLogic.polar2D(tempPos, Global.attackScopeBackLength, dir); posLogic.addPos2D(tempPos, pos); //半角弧度 float halfDirection = MathUtils.angleToDirection(sectorAngle) / 2f; float useRadius = radius + Global.attackScopeBackLength; float sq = useRadius * useRadius; Unit[] values; Unit k; for (int i = (values = _scene.getFightUnitDic().getValues()).Length - 1; i >= 0; --i) { if ((k = values[i]) != null) { PosData kPos = k.pos.getPos(); //高度值合适 if (height <= 0 || posLogic.getDHeight(kPos, pos) <= height) { //在圆形范围内 if ((posLogic.calculatePosDistanceSq2D(kPos, pos)) <= sq) { //符合影响类型 if (selfUnit.fight.checkTargetInfluence(k, influences)) { posLogic.calculateDirByPos2D(tempDir, tempPos, kPos); float dirV = MathUtils.directionCut(dir.direction - tempDir.direction); if (Math.Abs(dirV) <= halfDirection) { list.add(k); } } } } } } }
public override void init() { base.init(); _scenePosLogic = _scene.pos; initPos(); refreshShowPos(); _maxLastTime = Global.bulletMaxLastTime * 1000; initBullet(); }
public override void dispose() { base.dispose(); _scenePosLogic = null; _d = null; _pos = null; _dir = null; _posDir.pos = null; _posDir.dir = null; tempSortKey = 0f; _moveBindUnits.clear(); _beMoveBindUnit = null; }
/** 取圆形范围内最近的一个单位 */ public Unit getNearestFightUnits(PosData pos, float radius, float height, Unit selfUnit, bool[] influences) { ScenePosLogic posLogic = _scene.pos; float sq = radius * radius; ScenePosLogic.FindCircleNearestTemp cTemp = _circleNearestTemp; cTemp.dis = float.MaxValue; cTemp.unit = null; Unit[] values; Unit k; for (int i = (values = _scene.getFightUnitDic().getValues()).Length - 1; i >= 0; --i) { if ((k = values[i]) != null) { PosData kPos = k.pos.getPos(); //高度值合适 if (height <= 0 || posLogic.getDHeight(kPos, pos) <= height) { float dq; //在范围内 if ((dq = posLogic.calculatePosDistanceSq2D(k.pos.getPos(), pos)) <= sq) { //符合影响类型 if (selfUnit.fight.checkTargetInfluence(k, influences)) { if (dq < cTemp.dis) { cTemp.dis = dq; cTemp.unit = k; } } } } } } Unit re = cTemp.unit; cTemp.unit = null; return(re); }
/** 取圆形范围内最近的一个可拾取单位 */ public Unit getNearestFieldItem(float radius) { ScenePosLogic posLogic = _scene.pos; float sq = radius * radius; FindCircleNearestTemp cTemp = _circleNearestTemp; cTemp.dis = float.MaxValue; cTemp.unit = null; Unit hero = _scene.hero; PosData pos = hero.pos.getPos(); Unit[] values; Unit k; for (int i = (values = _scene.getUnitDic().getValues()).Length - 1; i >= 0; --i) { if ((k = values[i]) != null) { //是掉落物品,并且可拾取 if (k.getType() == UnitType.FieldItem && hero.aiCommand.checkCanPickUpFieldItem(k)) { float dq; //在范围内 if ((dq = posLogic.calculatePosDistanceSq2D(k.pos.getPos(), pos)) <= sq) { if (dq < cTemp.dis) { cTemp.dis = dq; cTemp.unit = k; } } } } } Unit re = cTemp.unit; cTemp.unit = null; return(re); }
protected override ScenePosLogic createPosLogic() { if (!_g6) { _m6 = instance.Type.GetMethod("createPosLogic", 0); _g6 = true; } if (_m6 != null && !_b6) { _b6 = true; ScenePosLogic re = (ScenePosLogic)appdomain.Invoke(_m6, instance, null); _b6 = false; return(re); } else { return(base.createPosLogic()); } }
/** 取圆形最近的战斗单位组 */ public void getCircleNearFightUnits(SList <Unit> list, PosData pos, float radius, int max, float height, Unit selfUnit, bool[] influences) { list.clear(); ScenePosLogic posLogic = _scene.pos; float sq = radius * radius; Unit[] values; Unit k; for (int i = (values = _scene.getFightUnitDic().getValues()).Length - 1; i >= 0; --i) { if ((k = values[i]) != null) { PosData kPos = k.pos.getPos(); //高度值合适 if (height <= 0 || posLogic.getDHeight(kPos, pos) <= height) { float dq; //在范围内 if ((dq = posLogic.calculatePosDistanceSq2D(k.pos.getPos(), pos)) <= sq) { //符合影响类型 if (selfUnit.fight.checkTargetInfluence(k, influences)) { k.pos.tempSortKey = dq; list.add(k); } } } } } if (max > 0 && list.length() > max) { list.sort(_unitNearComparator); list.cutToLength(max); } }
public override void dispose() { base.dispose(); _scenePosLogic = null; _targetUnit = null; _targetPosSource = null; _attackConfig = null; _hitEnabled = true; _hitTimePass = 0; _hitDelay = 0; if (_hitTargetNums != null) { _hitTargetNums.clear(); } if (_tempUnitList != null) { _tempUnitList.clear(); } }
public override void init() { base.init(); _scenePosLogic = _scene.pos; _d = _data.move; _pos = _data.pos.pos; _dir = _data.pos.dir; //有战斗数据 if (_data.fight != null) { FightUnitConfig fightUnitConfig = _data.getFightIdentity().getFightUnitConfig(); _moveType = fightUnitConfig.mapMoveType; _walkSpeedRatio = fightUnitConfig.walkSpeedRatio; if (fightUnitConfig.needDrive) { if (_drive == null) { _drive = new DriveLogic(); } DriveLogic drive = _drive; drive.needDrive = true; drive.needDrive = fightUnitConfig.needDrive; drive.canDriveTurnAtPivot = fightUnitConfig.canDriveTurnAtPivot; drive.driveDirectionSpeed = fightUnitConfig.driveDirectionSpeedT; drive.driveTurnRadius = fightUnitConfig.driveTurnRadius; if (fightUnitConfig.driveAccelerateSpeed == 0) { drive.driveAccelerateSpeedM = 0f; drive.driveGroundFrictionM = 0f; } else { drive.driveAccelerateSpeedM = fightUnitConfig.driveAccelerateSpeed * Global.useMoveSpeedRatio / 1000000f; //先暂时取陆地的 drive.driveGroundFrictionM = MapBlockTypeConfig.get(MapBlockType.Land).groundFriction *Global.useMoveSpeedRatio / 1000000f; } } else { if (_drive != null) { _drive.needDrive = false; } } calculateUseMoveSpeed(); } else { if (_drive != null) { _drive.needDrive = false; } } }
/** 重新选择追击目标 */ private void reSelectPursueTarget() { Unit target = getPursueUnit(); if (target == null) { return; } Unit re = null; float reCost = 0f; bool[] influences = _fightUnitConfig.attackInfluenceTypeT; ScenePosLogic posLogic = _scene.pos; float sq = _fightUnitConfig.initiativeAttackRadiusT; PosData pos = _unit.pos.getPos(); Unit[] values; Unit k; for (int i = (values = _scene.getFightUnitDic().getValues()).Length - 1; i >= 0; --i) { if ((k = values[i]) != null) { PosData kPos = k.pos.getPos(); float q; //在范围内 if ((q = posLogic.calculatePosDistanceSq2D(kPos, pos)) <= sq) { //符合影响类型 if (_unit.fight.checkTargetInfluence(k, influences)) { float unitHateSwitchCost = getUnitHateSwitchCost(k); float dis = (float)Math.Sqrt(q); float distanceCost = 0f; if (dis < Global.unitSwitchBaseDistance) { distanceCost = Global.unitSwitchDistanceCost * (Global.unitSwitchBaseDistance - dis); } float switchCost = target == k ? 0f: Global.unitSwitchFixedCost; float cost = unitHateSwitchCost + distanceCost + switchCost; if (re == null || cost > reCost) { re = k; reCost = cost; } } } } } if (re != null) { //设置新的追击目标 setPursueUnit(re); } }