public bool TryInsert(T item) { bool isInsertable = true; foreach (IListFilter <T> filter in _filterList) { if (!filter.IsInsertable(item)) { isInsertable = false; break; } } if (isInsertable) { _list.AddItem(item); } return(isInsertable); }
public void RunAction(Actor source, Actor target, Card card, BattleContext manager) { if (target is PlayerInstance) { PlayerInstance player = (PlayerInstance)target; ListenableList <ElementCardInstance> handheldSet = player.HandheldSet; ListenableList <ElementCardInstance> cardDeck = player.CardDeck; List <ElementCardInstance> filteredList = null; // filter if (null != _element) { filteredList = cardDeck.GetAll().FindAll(item => item.Element.Equals(_element)); } else { filteredList = cardDeck.GetAll(); } // random List <ElementCardInstance> drawList = new List <ElementCardInstance>(); if (filteredList.Count > 0) { for (int cnt = 0; cnt < _drawCount; cnt++) { int random = Random.Range(0, filteredList.Count - 1); drawList.Add(filteredList[random]); filteredList.RemoveAt(random); } } // update foreach (ElementCardInstance instance in drawList) { cardDeck.RemoveItem(instance); handheldSet.AddItem(instance); } } }
// 敵人AI public override void StartTurn(BattleContext mgr) { base.StartTurn(mgr); if (this._postpone > 0) { this._postpone -= 1; return; } // get Card MonsterCardInstance card = null; // try to get card from queue if (_cardQueue.GetCount() > 0) { card = _cardQueue.Pop(1)[0]; } else { // try to get card from strategy card = this._strategy.RunStrategy(this, mgr); //postpone card if (card.Postpone > 0) { _postpone += card.Postpone; _cardQueue.AddItem(card); return; } } if (null != card) { // run card if (card.IsAgainstEnemy) { List <Actor> enemy = new List <Actor>(); enemy.Add(mgr.Player); if (card.IsAOE) { card.Play(this, enemy, mgr); } else { List <Actor> singleTarget = new List <Actor>(); singleTarget.Add(enemy[Random.Range(0, enemy.Count)]); card.Play(this, singleTarget, mgr); } } else { if (card.IsAOE) { List <Actor> partners = new List <Actor>(); foreach (Actor partner in mgr.EnemyList.GetAll()) { partners.Add(partner); } card.Play(this, partners, mgr); } else { List <Actor> singleTarget = new List <Actor>(); singleTarget.Add(this); card.Play(this, singleTarget, mgr); } } } }