private IEnumerator RemoveDieUnit(int _time, List <Turrent> _list) { for (int i = unitList.Count - 1; i > -1; i--) { Unit unit = unitList[i]; if (unit.hp < 1 || (unit.dieTime > 0 && _time >= unit.dieTime)) { unit.Die(_time); Turrent[] turrentArr = unit.isMine ? mTurrent : oTurrent; for (int m = 0; m < unit.turrentList.Count; m++) { Turrent turrent = unit.turrentList[m]; turrentArr[turrent.pos] = null; if (_list != null) { _list.Remove(turrent); } } unitList.RemoveAt(i); yield return(new BattleDeadVO(true, unit.uid)); } } }
private int DamageTurrent(Turrent _turrent) { int damage = sds.GetAttackDamage(); damage += GetDamageAdd(_turrent.parent.uid, _turrent.pos); switch (sds.GetAttackDamageType()) { case DamageType.PHYSIC: battleCore.eventListener.DispatchEvent(BattleConst.FIX_DO_PHYSIC_DAMAGE, ref damage, parent, _turrent.parent); battleCore.eventListener.DispatchEvent(BattleConst.DO_PHYSIC_DAMAGE, parent, _turrent.parent); return(_turrent.parent.BePhysicDamaged(parent, damage, time)); case DamageType.MAGIC: battleCore.eventListener.DispatchEvent(BattleConst.FIX_DO_MAGIC_DAMAGE, ref damage, parent, _turrent.parent); battleCore.eventListener.DispatchEvent(BattleConst.DO_MAGIC_DAMAGE, parent, _turrent.parent); return(_turrent.parent.BeMagicDamaged(parent, damage, time)); default: throw new Exception("unknown attackDamageType:" + sds.GetAttackDamageType()); } }
private static int SortTurrentList(Turrent _t0, Turrent _t1) { if (_t0.time > _t1.time) { return(1); } else if (_t0.time < _t1.time) { return(-1); } else { return(0); } }
private static void GetNeighbourUnit(Turrent[] _turrents, Unit _unit, int _pos, ref List <int> _result) { Turrent turrent = _turrents[_pos]; if (turrent != null && turrent.parent != _unit) { if (_result == null) { _result = new List <int>(); _result.Add(turrent.parent.uid); } else { if (!_result.Contains(turrent.parent.uid)) { _result.Add(turrent.parent.uid); } } } }
public void Init(BattleCore _battleCore, bool _isMine, IUnitSDS _sds, int _uid, int _pos, int _time) { battleCore = _battleCore; isMine = _isMine; sds = _sds; uid = _uid; pos = _pos; hp = sds.GetHp(); state = UnitState.CD; if (sds.GetLiveTime() > 0) { dieTime = _time + sds.GetLiveTime(); } Turrent[] turrentPos = isMine ? battleCore.mTurrent : battleCore.oTurrent; for (int i = 0; i < sds.GetPos().Length; i++) { int posFix = sds.GetPos()[i]; ITurrentSDS turrentSDS = sds.GetTurrent()[i]; Turrent turrent = new Turrent(); turrent.Init(battleCore, this, turrentSDS, pos + posFix, _time); turrentPos[pos + posFix] = turrent; turrentList.Add(turrent); } }
public string GetData() { string str = string.Empty; str += tick + "{"; for (int i = 0; i < mTurrent.Length; i++) { Turrent t = mTurrent[i]; if (t != null) { str += i + ":"; str += t.GetData(); str += "|"; } } for (int i = 0; i < oTurrent.Length; i++) { Turrent t = oTurrent[i]; if (t != null) { str += i + ":"; str += t.GetData(); str += "|"; } } str += "}"; return(str); }
private static bool CheckAuraTrigger(BattleCore _battleCore, Unit _unit, Unit _triggerUnit, IAuraSDS _sds) { switch (_sds.GetTrigger()) { case AuraTrigger.OWNER: return(_triggerUnit == _unit); case AuraTrigger.ENEMY: return(_triggerUnit.isMine != _unit.isMine); case AuraTrigger.COL_ENEMY: if (_triggerUnit.isMine != _unit.isMine) { Turrent[] turrents = _triggerUnit.isMine ? _battleCore.mTurrent : _battleCore.oTurrent; int x = _unit.pos % BattleConst.MAP_WIDTH; for (int i = 0; i < _unit.sds.GetPos().Length; i++) { int posFix = _unit.sds.GetPos()[i]; if (posFix >= BattleConst.MAP_WIDTH) { return(false); } int nowX = x + posFix % BattleConst.MAP_WIDTH; nowX = BattleConst.MAP_WIDTH - 1 - nowX; for (int m = 0; m < BattleConst.MAP_HEIGHT; m++) { int targetPos = m * BattleConst.MAP_WIDTH + nowX; Turrent turrent = turrents[targetPos]; if (turrent != null && turrent.parent == _triggerUnit) { return(true); } } } } return(false); case AuraTrigger.FRONT_ENEMY: if (_triggerUnit.isMine != _unit.isMine) { Turrent[] turrents = _triggerUnit.isMine ? _battleCore.mTurrent : _battleCore.oTurrent; int x = _unit.pos % BattleConst.MAP_WIDTH; for (int i = 0; i < _unit.sds.GetPos().Length; i++) { int posFix = _unit.sds.GetPos()[i]; if (posFix >= BattleConst.MAP_WIDTH) { return(false); } int nowX = x + posFix % BattleConst.MAP_WIDTH; nowX = BattleConst.MAP_WIDTH - 1 - nowX; for (int m = 0; m < BattleConst.MAP_HEIGHT; m++) { int targetPos = m * BattleConst.MAP_WIDTH + nowX; Turrent turrent = turrents[targetPos]; if (turrent != null) { if (turrent.parent == _triggerUnit) { return(true); } else { break; } } } } } return(false); case AuraTrigger.OWNER_NEIGHBOUR_ALLY: if (_triggerUnit != _unit && _triggerUnit.isMine == _unit.isMine) { Turrent[] turrents = _unit.isMine ? _battleCore.mTurrent : _battleCore.oTurrent; for (int i = 0; i < _unit.sds.GetPos().Length; i++) { int posFix = _unit.sds.GetPos()[i]; int nowPos = _unit.pos + posFix; int nowX = nowPos % BattleConst.MAP_WIDTH; int targetPos; if (nowX > 0) { targetPos = nowPos - 1; Turrent turrent = turrents[targetPos]; if (turrent != null && turrent.parent == _triggerUnit) { return(true); } } if (nowX < BattleConst.MAP_WIDTH - 1) { targetPos = nowPos + 1; Turrent turrent = turrents[targetPos]; if (turrent != null && turrent.parent == _triggerUnit) { return(true); } } targetPos = nowPos - BattleConst.MAP_WIDTH; if (targetPos >= 0) { Turrent turrent = turrents[targetPos]; if (turrent != null && turrent.parent == _triggerUnit) { return(true); } } targetPos = nowPos + BattleConst.MAP_WIDTH; if (targetPos < BattleConst.MAP_WIDTH * BattleConst.MAP_HEIGHT) { Turrent turrent = turrents[targetPos]; if (turrent != null && turrent.parent == _triggerUnit) { return(true); } } } } return(false); case AuraTrigger.OWNER_ALLY: return(_triggerUnit != _unit && _triggerUnit.isMine == _unit.isMine); case AuraTrigger.OWNER_ROW_ALLY: if (_triggerUnit != _unit && _triggerUnit.isMine == _unit.isMine) { Turrent[] turrents = _unit.isMine ? _battleCore.mTurrent : _battleCore.oTurrent; int y = _unit.pos / BattleConst.MAP_WIDTH; for (int i = 0; i < _unit.sds.GetPos().Length; i++) { int posFix = _unit.sds.GetPos()[i]; if (posFix % BattleConst.MAP_WIDTH != 0) { continue; } int nowY = y + posFix / BattleConst.MAP_WIDTH; for (int m = 0; m < BattleConst.MAP_WIDTH; m++) { int targetPos = nowY * BattleConst.MAP_WIDTH + m; Turrent turrent = turrents[targetPos]; if (turrent != null && turrent.parent == _triggerUnit) { return(true); } } } } return(false); case AuraTrigger.OWNER_COL_ALLY: if (_triggerUnit != _unit && _triggerUnit.isMine == _unit.isMine) { Turrent[] turrents = _unit.isMine ? _battleCore.mTurrent : _battleCore.oTurrent; int x = _unit.pos % BattleConst.MAP_WIDTH; for (int i = 0; i < _unit.sds.GetPos().Length; i++) { int posFix = _unit.sds.GetPos()[i]; if (posFix >= BattleConst.MAP_WIDTH) { return(false); } int nowX = x + posFix % BattleConst.MAP_WIDTH; for (int m = 0; m < BattleConst.MAP_HEIGHT; m++) { int targetPos = m * BattleConst.MAP_WIDTH + nowX; Turrent turrent = turrents[targetPos]; if (turrent != null && turrent.parent == _triggerUnit) { return(true); } } } } return(false); case AuraTrigger.OWNER_FRONT_ALLY: if (_triggerUnit != _unit && _triggerUnit.isMine == _unit.isMine) { Turrent[] turrents = _unit.isMine ? _battleCore.mTurrent : _battleCore.oTurrent; for (int i = 0; i < _unit.sds.GetPos().Length; i++) { int posFix = _unit.sds.GetPos()[i]; if (posFix >= BattleConst.MAP_WIDTH) { return(false); } int nowPos = _unit.pos + posFix; for (int m = 1; m < BattleConst.MAP_HEIGHT; m++) { int targetPos = nowPos - m * BattleConst.MAP_WIDTH; if (targetPos < 0) { break; } Turrent turrent = turrents[targetPos]; if (turrent != null) { if (turrent.parent == _triggerUnit) { return(true); } else { break; } } } } } return(false); case AuraTrigger.OWNER_BACK_ALLY: if (_triggerUnit != _unit && _triggerUnit.isMine == _unit.isMine) { Turrent[] turrents = _unit.isMine ? _battleCore.mTurrent : _battleCore.oTurrent; for (int i = 0; i < _unit.sds.GetPos().Length; i++) { int posFix = _unit.sds.GetPos()[i]; if (posFix >= BattleConst.MAP_WIDTH) { return(false); } int nowPos = _unit.pos + posFix; for (int m = 1; m < BattleConst.MAP_HEIGHT; m++) { int targetPos = nowPos + m * BattleConst.MAP_WIDTH; if (targetPos >= BattleConst.MAP_WIDTH * BattleConst.MAP_HEIGHT) { break; } Turrent turrent = turrents[targetPos]; if (turrent != null) { if (turrent.parent == _triggerUnit) { return(true); } else if (turrent.parent != _unit) { break; } } } } } return(false); case AuraTrigger.OWNER_BESIDE_ALLY: if (_triggerUnit != _unit && _triggerUnit.isMine == _unit.isMine) { Turrent[] turrents = _unit.isMine ? _battleCore.mTurrent : _battleCore.oTurrent; for (int i = 0; i < _unit.sds.GetPos().Length; i++) { int posFix = _unit.sds.GetPos()[i]; int nowPos = _unit.pos + posFix; int nowX = nowPos % BattleConst.MAP_WIDTH; if (nowX > 0) { int targetPos = nowPos - 1; Turrent turrent = turrents[targetPos]; if (turrent != null && turrent.parent == _triggerUnit) { return(true); } } if (nowX < BattleConst.MAP_WIDTH - 1) { int targetPos = nowPos + 1; Turrent turrent = turrents[targetPos]; if (turrent != null && turrent.parent == _triggerUnit) { return(true); } } } } return(false); case AuraTrigger.ROW_ENEMY: if (_triggerUnit.isMine != _unit.isMine) { Turrent[] turrents = _triggerUnit.isMine ? _battleCore.mTurrent : _battleCore.oTurrent; int y = _unit.pos / BattleConst.MAP_WIDTH; for (int i = 0; i < _unit.sds.GetPos().Length; i++) { int posFix = _unit.sds.GetPos()[i]; if (posFix % BattleConst.MAP_WIDTH != 0) { continue; } int nowY = y + posFix / BattleConst.MAP_WIDTH; for (int m = 0; m < BattleConst.MAP_WIDTH; m++) { int targetPos = nowY * BattleConst.MAP_WIDTH + m; Turrent turrent = turrents[targetPos]; if (turrent != null && turrent.parent == _triggerUnit) { return(true); } } } } return(false); case AuraTrigger.POS_ENEMY: if (_triggerUnit.isMine != _unit.isMine) { Turrent[] turrents = _triggerUnit.isMine ? _battleCore.mTurrent : _battleCore.oTurrent; for (int i = 0; i < _unit.sds.GetPos().Length; i++) { int posFix = _unit.sds.GetPos()[i]; int nowPos = _unit.pos + posFix; int nowX = nowPos % BattleConst.MAP_WIDTH; int nowY = nowPos / BattleConst.MAP_WIDTH; nowPos = BattleConst.MAP_WIDTH - 1 - nowPos; int targetPos = nowY * BattleConst.MAP_WIDTH + nowX; Turrent turrent = turrents[targetPos]; if (turrent != null && turrent.parent == _triggerUnit) { return(true); } } } return(false); default: throw new Exception("CheckAuraTrigger error:" + _sds.GetTrigger()); } }
public static List <int> GetTurrentAttackTargetList(BattleCore _battleCore, bool _isMine, ITurrentSDS _sds, int _pos) { List <int> result = null; int x = _pos % BattleConst.MAP_WIDTH; int oppX = BattleConst.MAP_WIDTH - 1 - x; Turrent[] oppTurrent = _isMine ? _battleCore.oTurrent : _battleCore.mTurrent; for (int i = 0; i < _sds.GetAttackTargetPos().Length; i++) { KeyValuePair <int, int>[] targetPosFixArr = _sds.GetAttackTargetPos()[i]; bool getTarget = false; for (int n = 0; n < targetPosFixArr.Length; n++) { KeyValuePair <int, int> targetPosFix = targetPosFixArr[n]; int targetX = oppX + targetPosFix.Key; if (targetX >= BattleConst.MAP_WIDTH || targetX < 0) { continue; } int targetY = targetPosFix.Value; int targetPos = targetY * BattleConst.MAP_WIDTH + targetX; Turrent targetTurrent = oppTurrent[targetPos]; if (targetTurrent != null) { if (!getTarget) { getTarget = true; result = new List <int>(); } result.Add(targetPos); } } if (getTarget) { KeyValuePair <int, int>[] arr = _sds.GetAttackSplashPos()[i]; for (int m = 0; m < arr.Length; m++) { KeyValuePair <int, int> targetPosFix = arr[m]; int targetX = oppX + targetPosFix.Key; if (targetX >= BattleConst.MAP_WIDTH || targetX < 0) { continue; } int targetY = targetPosFix.Value; int targetPos = targetY * BattleConst.MAP_WIDTH + targetX; Turrent targetTurrent = oppTurrent[targetPos]; if (targetTurrent != null) { result.Add(targetPos); } } return(result); } } if (_sds.GetCanAttackBase()) { result = new List <int>(); result.Add(-1); } return(result); }
private IEnumerator UpdateTurrent(int _time) { List <Turrent> list = new List <Turrent>(); for (int i = 0; i < mTurrent.Length; i++) { Turrent turrent = mTurrent[i]; if (turrent != null) { switch (turrent.sds.GetUpdateType()) { case UpdateType.ALWAYS_UPDATE: list.Add(turrent); break; case UpdateType.CD_UPDATE: if (turrent.parent.state == UnitState.CD) { list.Add(turrent); } break; } } } for (int i = 0; i < oTurrent.Length; i++) { Turrent turrent = oTurrent[i]; if (turrent != null) { switch (turrent.sds.GetUpdateType()) { case UpdateType.ALWAYS_UPDATE: list.Add(turrent); break; case UpdateType.CD_UPDATE: if (turrent.parent.state == UnitState.CD) { list.Add(turrent); } break; } } } int lastProcessTime = -1; BattleResult result = BattleResult.NOT_OVER; while (list.Count > 0) { list.Sort(SortTurrentList); Turrent turrent = list[0]; if (_time >= turrent.time) { if (lastProcessTime == -1) { lastProcessTime = turrent.time; eventListener.DispatchEvent(BattleConst.TIME_OVER, lastProcessTime); } else if (turrent.time > lastProcessTime) { lastProcessTime = turrent.time; eventListener.DispatchEvent(BattleConst.TIME_OVER, lastProcessTime); yield return(RemoveDieUnit(lastProcessTime, list)); } BattleAttackVO vo; bool b = turrent.Update(out vo); if (b) { yield return(vo); } else { list.RemoveAt(0); } } else { break; } } if (result == BattleResult.NOT_OVER) { eventListener.DispatchEvent(BattleConst.TIME_OVER, _time); yield return(RemoveDieUnit(_time, null)); result = GetBattleResult(_time); } yield return(new BattleResultVO(result)); }
private bool DoAction(out BattleAttackVO _vo) { Dictionary <KeyValuePair <int, int>, int> recDic = null; if (sds.GetAttackDamageAdd() > 0) { recDic = lastTargetDic; lastTargetDic = new Dictionary <KeyValuePair <int, int>, int>(); } List <int> result = BattlePublicTools.GetTurrentAttackTargetList(battleCore, parent.isMine, sds, pos); if (result != null) { Turrent[] oppTurrent = parent.isMine ? battleCore.oTurrent : battleCore.mTurrent; List <KeyValuePair <int, int> > damageDataList = new List <KeyValuePair <int, int> >(); for (int i = 0; i < result.Count; i++) { int targetPos = result[i]; if (targetPos < 0) { if (sds.GetAttackDamageAdd() > 0) { if (!lastTargetDic.ContainsKey(new KeyValuePair <int, int>(-1, -1))) { int lastTargetTime; if (recDic.TryGetValue(new KeyValuePair <int, int>(-1, -1), out lastTargetTime)) { lastTargetDic.Add(new KeyValuePair <int, int>(-1, -1), lastTargetTime); } else { lastTargetDic.Add(new KeyValuePair <int, int>(-1, -1), time); } } } int damage = DamageBase(); damageDataList.Add(new KeyValuePair <int, int>(-1, damage)); } else { Turrent targetTurrent = oppTurrent[targetPos]; if (sds.GetAttackDamageAdd() > 0) { if (!lastTargetDic.ContainsKey(new KeyValuePair <int, int>(targetTurrent.parent.uid, targetTurrent.pos))) { int lastTargetTime; if (recDic.TryGetValue(new KeyValuePair <int, int>(targetTurrent.parent.uid, targetTurrent.pos), out lastTargetTime)) { lastTargetDic.Add(new KeyValuePair <int, int>(targetTurrent.parent.uid, targetTurrent.pos), lastTargetTime); } else { lastTargetDic.Add(new KeyValuePair <int, int>(targetTurrent.parent.uid, targetTurrent.pos), time); } } } int damage = DamageTurrent(targetTurrent); damageDataList.Add(new KeyValuePair <int, int>(targetPos, damage)); } } _vo = new BattleAttackVO(parent.isMine, pos, damageDataList); return(true); } else { _vo = new BattleAttackVO(); return(false); } }