public override bool Enter(Func <int, int> _getRandomValueCallBack, BattleCore _t, bool _u, AiSummonData _v) { List <int> handCards = _u ? _t.mHandCards : _t.oHandCards; if (handCards.Count == 0) { return(false); } handCards = new List <int>(handCards); int index = _getRandomValueCallBack(handCards.Count); int uid = handCards[index]; int id = _t.GetCard(_u, uid); IUnitSDS sds = BattleCore.GetUnitData(id); if (sds.GetCost() > (_u ? _t.mMoney : _t.oMoney)) { return(false); } else { _v.uid = uid; return(true); } }
public static int GetUnitAttackTargetScore(BattleCore _battleCore, bool _isMine, int _id, int _pos, int _turrentScore, int _baseScore) { int score = 0; IUnitSDS unitSDS = BattleCore.GetUnitData(_id); for (int i = 0; i < unitSDS.GetPos().Length; i++) { int pos = _pos + unitSDS.GetPos()[i]; ITurrentSDS turrentSDS = unitSDS.GetTurrent()[i]; List <int> result = GetTurrentAttackTargetList(_battleCore, _isMine, turrentSDS, pos); if (result != null) { for (int m = 0; m < result.Count; m++) { int targetPos = result[m]; if (targetPos < 0) { score += _baseScore; } else { score += _turrentScore; } } } } return(score); }
private void AddUnit(int _time, bool _isMine, IUnitSDS _sds, int _pos) { Unit unit = new Unit(); unit.Init(this, _isMine, _sds, GetUnitUid(), _pos, _time); unitList.Add(unit); }
public override bool Enter(Func <int, int> _getRandomValueCallBack, BattleCore _t, bool _u, AiSummonData _v) { Turrent[] turrentArr = _u ? _t.mTurrent : _t.oTurrent; int id = _t.GetCard(_u, _v.uid); IUnitSDS unitSDS = BattleCore.GetUnitData(id); for (int i = 0; i < BattleConst.MAP_HEIGHT; i++) { if (Array.IndexOf(unitSDS.GetRow(), i) != -1) { for (int m = 0; m < BattleConst.MAP_WIDTH; m++) { int unitPos = i * BattleConst.MAP_WIDTH + m; bool canSet = true; for (int n = 0; n < unitSDS.GetPos().Length; n++) { int posFix = unitSDS.GetPos()[n]; int x = posFix % BattleConst.MAP_WIDTH; if (m + x < BattleConst.MAP_WIDTH) { int pos = unitPos + posFix; if (turrentArr[pos] != null) { canSet = false; break; } } else { canSet = false; break; } } if (canSet) { int score = BattlePublicTools.GetUnitAttackTargetScore(_t, _u, id, unitPos, turrentTargetScore, baseTargetScore); if (score > 0) { _v.summonPosList.Add(new KeyValuePair <int, int>(unitPos, score)); } } } } } return(_v.summonPosList.Count > 0); }
private void AddUnitToPool(bool _isMine, int _id) { IUnitSDS sds = getUnitCallBack(_id); Dictionary <int, int> pool = _isMine ? mUnitPool : oUnitPool; if (pool.ContainsKey(_id)) { pool[_id]++; } else { pool.Add(_id, 1); } }
private void Spawn() { Dictionary <int, int> .Enumerator enumerator = mUnitPool.GetEnumerator(); while (enumerator.MoveNext()) { int id = enumerator.Current.Key; int num = enumerator.Current.Value; IUnitSDS sds = getUnitCallBack(id); for (int i = 0; i < num; i++) { double posX = -gameConfig.GetSpawnX() + sds.GetQueuePos(); double posY = -gameConfig.GetSpawnY() + (i % 2 == 0 ? 1 : -1) * i * 0.1; Vector2 pos = new Vector2(posX, posY); AddUnitToBattle(true, id, false, pos); } } enumerator = oUnitPool.GetEnumerator(); while (enumerator.MoveNext()) { int id = enumerator.Current.Key; int num = enumerator.Current.Value; IUnitSDS sds = getUnitCallBack(id); for (int i = 0; i < num; i++) { double posX = gameConfig.GetSpawnX() - sds.GetQueuePos(); double posY = gameConfig.GetSpawnY() + (i % 2 == 0 ? -1 : 1) * i * 0.1; Vector2 pos = new Vector2(posX, posY); AddUnitToBattle(false, id, false, pos); } } }
private BattleSummonVO AddSummon(int _time, bool _isMine, int _uid, int _pos) { int unitID = GetCard(_isMine, _uid); IUnitSDS sds = GetUnitData(unitID); if (_isMine) { if (mMoney == BattleConst.MAX_MONEY) { mMoneyTime = _time + BattleConst.RECOVER_MONEY_TIME; } mMoney -= sds.GetCost(); mHandCards.Remove(_uid); mCards.Enqueue(_uid + mCardsArr.Length); mHandCards.Add(mCards.Dequeue()); } else { if (oMoney == BattleConst.MAX_MONEY) { oMoneyTime = _time + BattleConst.RECOVER_MONEY_TIME; } oMoney -= sds.GetCost(); oHandCards.Remove(_uid); oCards.Enqueue(_uid + oCardsArr.Length); oHandCards.Add(oCards.Dequeue()); } AddUnit(_time, _isMine, sds, _pos); return(new BattleSummonVO(_isMine, _uid, _pos)); }
internal void Init(Battle _battle, Simulator _simulator, bool _isMine, int _uid, int _id, bool _isBase, IUnitSDS _sds, Vector2 _pos) { battle = _battle; simulator = _simulator; isMine = _isMine; uid = _uid; id = _id; isBase = _isBase; sds = _sds; nowHp = sds.GetHp(); attackStep = 0; targetUid = -1; if (sds.GetSkill() != 0) { CastSkill(); } simulator.addAgent(uid, _pos); InitSds(); }
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); } }
private bool ReceiveCommand(int _roundNum, int _commandID, CommandData _commandData) { if (_commandData is UnitCommandData) { UnitCommandData command = _commandData as UnitCommandData; IUnitSDS sds = getUnitCallBack(command.id); if (!sds.GetIsHero()) { if (command.isMine) { if (sds.GetPrize() > mMoney) { return(false); } else { mMoney -= sds.GetPrize(); } } else { if (sds.GetPrize() > oMoney) { return(false); } else { oMoney -= sds.GetPrize(); } } } else { return(false); } Dictionary <int, Dictionary <int, UnitCommandData> > unitCommandPool = command.isMine ? mUnitCommandPool : oUnitCommandPool; if (unitCommandPool.ContainsKey(_roundNum)) { Dictionary <int, UnitCommandData> tmpDic = unitCommandPool[_roundNum]; if (!tmpDic.ContainsKey(_commandID)) { tmpDic.Add(_commandID, command); } } else { Dictionary <int, UnitCommandData> tmpDic = new Dictionary <int, UnitCommandData>(); unitCommandPool.Add(_roundNum, tmpDic); tmpDic.Add(_commandID, command); } } else if (_commandData is HeroCommandData) { HeroCommandData command = _commandData as HeroCommandData; IUnitSDS sds = getUnitCallBack(command.id); if (sds.GetIsHero()) { if (command.isMine) { if (mHeroCommandPool.ContainsKey(command.id) || mHeroPool.ContainsKey(command.id) || sds.GetPrize() > mMoney) { return(false); } else { mMoney -= sds.GetPrize(); } } else { if (oHeroCommandPool.ContainsKey(command.id) || oHeroPool.ContainsKey(command.id) || sds.GetPrize() > oMoney) { return(false); } else { oMoney -= sds.GetPrize(); } } } else { return(false); } if (commandPool.ContainsKey(_roundNum)) { Dictionary <int, CommandData> tmpDic = commandPool[_roundNum]; if (!tmpDic.ContainsKey(_commandID)) { tmpDic.Add(_commandID, _commandData); } } else { Dictionary <int, CommandData> tmpDic = new Dictionary <int, CommandData>(); commandPool.Add(_roundNum, tmpDic); tmpDic.Add(_commandID, _commandData); } Dictionary <int, HeroCommandData> tmpDic2 = _commandData.isMine ? mHeroCommandPool : oHeroCommandPool; tmpDic2.Add(command.id, command); } else if (_commandData is SkillCommandData) { SkillCommandData command = _commandData as SkillCommandData; Dictionary <int, SkillCommandData> skillDic = command.isMine ? mSkillCommandPool : oSkillCommandPool; Dictionary <int, Unit> heroDic = command.isMine ? mHeroPool : oHeroPool; if (heroDic.ContainsKey(command.id) && !skillDic.ContainsKey(command.id)) { Unit hero = heroDic[command.id]; if (hero.sds.GetSkill() == 0 || hero.skillCd > 0) { return(false); } if (commandPool.ContainsKey(_roundNum)) { Dictionary <int, CommandData> tmpDic = commandPool[_roundNum]; if (!tmpDic.ContainsKey(_commandID)) { tmpDic.Add(_commandID, _commandData); } } else { Dictionary <int, CommandData> tmpDic = new Dictionary <int, CommandData>(); commandPool.Add(_roundNum, tmpDic); tmpDic.Add(_commandID, _commandData); } skillDic.Add(command.id, command); } else { return(false); } } return(true); }
public int CheckAddSummon(bool _isMine, int _uid, int _pos) { List <int> handCards; int money; Turrent[] turrent; if (_isMine) { handCards = mHandCards; money = mMoney; turrent = mTurrent; } else { handCards = oHandCards; money = oMoney; turrent = oTurrent; } int handCardsIndex = handCards.IndexOf(_uid); if (handCardsIndex != -1) { int unitID = GetCard(_isMine, _uid); IUnitSDS sds = GetUnitData(unitID); if (sds.GetCost() > money) { return(1); } int row = _pos / BattleConst.MAP_WIDTH; if (Array.IndexOf(sds.GetRow(), row) != -1) { int x = _pos % BattleConst.MAP_WIDTH; for (int i = 0; i < sds.GetPos().Length; i++) { int pos = sds.GetPos()[i]; int offsetX = pos % BattleConst.MAP_WIDTH; if (x + offsetX < BattleConst.MAP_WIDTH) { if (turrent[_pos + pos] != null) { return(6); } } else { return(4); } } } else { return(3); } return(-1); } else { return(7); } }