public void SetScreenEffect(ActionArguments args, WarUnit doer, Point2 center, IEnumerable<Point2> areaPoints, IEnumerable<Point2> validAreaPoints, int times, Action<int, int> callbackFunc) { args.Model.SetFrameAnimationOnScreen(_surfaces, 150, () => { for (int i = 1; i <= times; i++) callbackFunc(i, times); }); }
public void RemovedConditonTable(Situation situation, WarUnit unit) { // 追加したデリゲートは全て削除する unit.ReviseStatus -= ReviseStatus; unit.DamageEvent -= WakeUpCheck; Phases.TurnPhase.Start -= AutoRecoveryCheck; }
/// <summary> /// Очистить цели у себя и врагов /// </summary> public void ClearTarget() { target = null; meleeTarget = null; WarUnit warUnit = this as WarUnit; var allUnits = meleeUnits.Concat(rangeUnits); Unit[] enemies = new Unit[0]; if (warUnit != null) { WarTower warTower = warUnit.tower; var warriors = warTower.warriors; enemies = allUnits.Where(u => warriors.Contains(u.target) || warriors.Contains(u.meleeTarget)).ToArray(); } else { enemies = allUnits.Where(u => u.target == this || u.meleeTarget == this).ToArray(); } if (enemies.Length == 0) { return; } foreach (var enemy in enemies) { enemy.target = null; enemy.meleeTarget = null; } }
public override void Boot(ActionArguments args, WarUnit doer, Action finished) { var situation = args.Situation; var movableArea = situation.Map.MoveCalculator.CalcMovableArea(situation.Map, doer, doer.Location); _scope.CurrentMovableArea = movableArea; base.Boot(args, doer, finished); }
private void WakeUpCheck(Situation situation, WarUnit unit, WarUnit doer, int value) { // 攻撃者がいた場合のみ、復帰処理を行う if (doer != null && WarGlobal.Random.NextUnfairBool(1.0 / 3)) { unit.Conditions.Remove(((IAbnormalCondition)this).ID, situation); } }
public PrintableScope(IScope scope, IList<Point2> rangePoints, IList<Point2> validRangePoints, Situation situation, WarUnit doer) { this.scope = scope; this.situation = situation; this.doer = doer; this.RangeChips = rangePoints; this.ValidRangeChips = validRangePoints; }
public Stoune(double x, double y, double width, double height, WarUnit thrower, int range, int TakeLife, int timeOut, SpriteType spriteType, Magics magicType, Vector2 dir, double speed ) : base(x, y, width, height, thrower, range, TakeLife, timeOut, spriteType, magicType) { this.Direction = dir; this.Speed = speed; }
public PrintableScope(IScope scope, Situation situation, WarUnit doer) { this.scope = scope; this.situation = situation; this.doer = doer; IEnumerable<Point2> rangeScope; this.ValidRangeChips = scope.GetValidRangeScope(situation, doer, out rangeScope).ToArray(); this.RangeChips = rangeScope.ToArray(); }
public override IEnumerable<Point2> GetAreaScope(Situation situation, WarUnit doer, Point2 center) { var v = ScopeUtil.GetDirectionalVector(center - doer.Location); var p = doer.Location; for (int i = 0; i < _range; i++) { p += v; yield return p; } }
public void AddedConditonTable(Situation situation, WarUnit unit) { _unit = unit; // 麻痺時のコマンドテーブル変化を適用する unit.ReviseCommands += CommandEnableTableRevise; // ターン開始時に状態異常が自動回復するかの判定処理を追加する Phases.TurnPhase.Start += AutoRecoveryCheck; }
public decimal TryTakeEnemmyUnitQuantity(WarUnit unit) { foreach (var playerUnit in this.playerUnits) { if (playerUnit.Key == unit) { return(playerUnit.Value); } } return(0); }
public decimal TryTakeFriendUnitQuantity(WarUnit unit) { foreach (var enemyUnit in this.enemyUnits) { if (enemyUnit.Key == unit) { return(enemyUnit.Value); } } return(0m); }
public static int GetDamage(WarUnit doer, WarUnit taker, int power, AttackType type, out AdditionalEffect effect) { Contract.Requires(AttackTypes.Attack.Contains(type)); // 状態異常の結果を初期化 effect = AdditionalEffect.なし; if (!IsHit(doer, taker)) return 0; // Attack=(攻撃力+30+random(8))*攻撃値/80 var atk = (doer.Status.Atk + 30 + WarGlobal.Random.Next(8)) * power / 80; // Defense=防御力+30 var def = taker.Status.Def + 30; // 状態異常の判定 var resType = taker.Resistivity[type]; if (AttackTypes.AbnormalCondition.Contains(type)) { if (resType == ResistivityType.弱い || (resType == ResistivityType.普通 && IsHit(doer, taker))) { effect = type - AttackType.毒 + AdditionalEffect.毒; } else if (resType == ResistivityType.強い || resType == ResistivityType.吸収) { // ダメージの処理は通常攻撃扱い resType = taker.Resistivity[AttackType.物理]; } } else if (type == AttackType.吸収) { // 吸収属性の吸収はミス if (resType == ResistivityType.吸収) return 0; // 吸収属性があれば、ここでマイナスに反転。 effect = AdditionalEffect.吸収; } // 相手に「強い」属性が有る場合はここでDefense*2、「弱い」の場合はAttack*2。 if (resType == ResistivityType.弱い) atk *= 2; else if (resType == ResistivityType.強い) def *= 2; // ダメージ期待値=Attack^0.7*Attack/(Defense+10+random(10))*(20+random(5))/35 var point = (int)(Math.Pow(atk, 0.7) * atk / (def + 10 + WarGlobal.Random.Next(10)) * (20 + WarGlobal.Random.Next(5)) / 35); // ダメージが1以下なら1、999以上なら999。 point = XMath.Center(point, 1, 999); return point; }
public virtual void Boot(ActionArguments args, WarUnit doer, Action finished) { var warAdapter = args.Model; IEnumerable<Point2> rangePoints; var validRangePoints = Scope.GetValidRangeScope(args.Situation, doer, out rangePoints).ToArray(); if (validRangePoints.Length <= 0) { // HACK: メッセージボックス表示ルーチンの記述場所 MessageBox.Show("射程内に有効な対象が存在しません."); args.Model.InvokeCancelEvent(); return; } // スコープの位置に選択肢があれば、ユーザーに選択させる if (Scope.ExistChoice) { var pScope = new PrintableScope(Scope, rangePoints.ToArray(), validRangePoints, args.Situation, doer); // スコープを選択した際のイベント Action<Point2> selectMapChip = null; // スコープ選択状態を解除するデリゲート Action resetSelectScopeMode = () => { warAdapter.Scope = null; warAdapter.SelectMapChipEvent -= selectMapChip; }; // スコープを選択した際のイベントの定義 selectMapChip = p => { if (warAdapter.Scope.ValidRangeChips.Contains(p)) { // スコープ選択状態を解除 resetSelectScopeMode(); Execute(args, doer, p, finished); } }; // スコープの表示 warAdapter.Scope = pScope; // スコープを選択した際のイベントを追加 warAdapter.SelectMapChipEvent += selectMapChip; // キャンセルをした際のイベントを追加 warAdapter.CancelCommandStack.Push(delegate { resetSelectScopeMode(); return false; // 次のキャンセル処理へ続く }); } else { Execute(args, doer, validRangePoints[0], finished); } }
public void AddedConditonTable(Situation situation, WarUnit unit) { _unit = unit; // 睡眠中は行動不可能 unit.ReviseStatus += ReviseStatus; // 攻撃を受けたときの復帰処理を追加する unit.DamageEvent += WakeUpCheck; // ターン開始時に状態異常が自動回復するかの判定処理を追加する Phases.TurnPhase.Start += AutoRecoveryCheck; }
public static bool HaveCollisonBetweenTwoObj(WarUnit target, Arrow arrow) { bool collisionByX = (arrow.DrawCoords.X > target.DrawCoord.X && arrow.DrawCoords.X < (target.DrawCoord.X + target.CropWidth)) || ((arrow.DrawCoords.X + arrow.CropWidth) > target.DrawCoord.X && (arrow.DrawCoords.X + arrow.CropWidth) < (target.DrawCoord.X + target.CropWidth)); bool collisionByY = arrow.DrawCoords.Y > target.DrawCoord.Y && arrow.DrawCoords.Y < (target.DrawCoord.Y + target.CropHeight); return(collisionByX);//&& collisionByY; }
public bool AddingConditonTable(Situation situation, WarUnit unit, IAbnormalCondition oldCond) { Contract.Requires(oldCond.GetType() == GetType()); var cond = (AttackCountChangeCondition)oldCond; var newCount = cond._changeAttackCount + _changeAttackCount; // 変化量が0ならば削除、そうでなければ値を更新 if (newCount == 0) unit.Conditions.Remove(ID, situation); else cond._changeAttackCount = _changeAttackCount; return false; }
protected override IEnumerable<int> GetCoroutine(ActionArguments args, WarUnit doer, Point2 center, Action finished, Action doCoroutine) { // 行為のキャンセルの不許可 args.Model.CancelCommandStack.Clear(); // コストの消費 _cost.Expend(args.Situation, doer); // 攻撃アニメーションとその後の処理を予約する IEnumerable<Point2> areaPoints; var validPoints = _scope.GetValidAreaScope(args.Situation, doer, center, out areaPoints); _screenEffect.SetScreenEffect(args, doer, center, areaPoints, validPoints, doCoroutine); yield return 0; // エフェクト表示 // 洪水処理 var map = args.Situation.Map; var width = map.Width; var height = map.Height; var enableDamageAnimation = false; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var land = map[x, y]; if (land.Height <= TARGET_HEIGHT) { var taker = land.Unit; if (taker != null && _attackType != AttackType.なし) { AdditionalEffect cond; var damage = BattleActionUtil.GetMagicDamage(doer, taker, _power, _attackType, out cond); BattleActionUtil.RunAttackRoutine(args, doer, taker, damage, cond, doCoroutine); enableDamageAnimation = true; } // マップの更新 if (brinkNames.Contains(land.Info.Name)) { map[x, y] = new Land(land.Height - TARGET_HEIGHT, land.Landform, null); } else { map[x, y] = new Land(land.Height - TARGET_HEIGHT, _brinkLandform, null); } } } } if (enableDamageAnimation) yield return 0; // ダメージ表示 finished(); }
/// <summary> /// Создать воина /// </summary> void CreateWarrior() { resurrectionTimeCount = 0; Transform warriorInst = Instantiate(warUnitPrefab, ammoSpawnPoint.transform.position, Quaternion.identity); warriorInst.parent = parentGameObject.transform; WarUnit warUnit = warriorInst.GetComponent <WarUnit>(); warUnit.tower = this; warriors.Add(warUnit); OpenGate(); }
public virtual IEnumerable<Point2> GetValidAreaScope(Situation situation, WarUnit doer, Point2 center, out IEnumerable<Point2> areaScope) { var validAreaPoints = new List<Point2>(); areaScope = GetAreaScope(situation, doer, center); foreach (var p in areaScope) { if (IsValidPoint(situation, doer, p)) { validAreaPoints.Add(p); } } return validAreaPoints; }
public virtual void AddCreature(WarUnit newUnit) { this.supportUnitForAdding = this.availableCreatures.Keys.FirstOrDefault(x => x.GetStrengthLevel == newUnit.GetStrengthLevel); if (this.supportUnitForAdding == null) { this.availableCreatures.Add(newUnit, 1); } else { this.availableCreatures[supportUnitForAdding]++; } }
public void SetScreenEffect(ActionArguments args, WarUnit doer, Point2 center, IEnumerable<Point2> areaPoints, IEnumerable<Point2> validAreaPoints, int times, Action<int, int> callbackFunc) { var model = args.Model; int delay = 0; for (int i = 1; i <= times; i++) { foreach (var p in areaPoints) { var anime = model.CreateDirectedUniformMotionAnimationOnMap(_surfaces, doer.Location, p, 0.125f); anime = new ExtendTimeAnimationSprite(anime, delay, 0); model.ChipAnimations.Add(anime, callbackFunc.GetCurrying(i, times)); delay += 300; } } }
public static void ShowWindow(IWin32Window window, WarUnit unit) { Contract.Requires(window != null, "window"); Contract.Requires(unit != null, "unit"); if (!IsInitialized) { instance = new UnitInfoWindow(); } if (!instance.Visible) { instance.Show(window); } instance.Unit = unit; }
public override IList<Point2> GetValidRangeScope(Situation situation, WarUnit doer, out IEnumerable<Point2> rangeScope) { var validRangePoints = new List<Point2>(); rangeScope = new[] { doer.Location }; foreach (var p in situation.Map.ValidPoints) { if (IsValidPoint(situation, doer, p)) { validRangePoints.Add(doer.Location); break; } } return validRangePoints; }
/// <summary> /// Поиск свободной вершины /// </summary> void SearchVortex() { var vortexs = placePoint.vortexs; foreach (var vortex in vortexs) { WarUnit warrior = vortex.warrior; if (warrior == null || warrior != null && warrior.isDied) { vortex.warrior = this; currentVortex = vortex; break; } } stayPosition = currentVortex.ownTransform.position; }
private void LivingCreaturesLifeRegen(WarUnit unit) { if (unit.Life < unit.MaxLife) { healPerSec++; if (healPerSec == 10) { unit.Life += 1; healPerSec = 0; } } else { healPerSec = 0; } }
public static int GetMagicDamage(WarUnit doer, WarUnit taker, int power, AttackType type, out AdditionalEffect effect) { // Attack=((魔力*0.8+Random(8)+60)*(魔法威力+30))/40 var atk = (doer.Status.Mag * 0.8 + WarGlobal.Random.Next(8) + 60) * (power + 30) / 40; // Defense=抵抗*0.8+70 var def = taker.Status.Res * 0.8 + 70; // 状態異常の結果を初期化 effect = AdditionalEffect.なし; // 状態異常の判定 var resType = taker.Resistivity[type]; if (AttackTypes.AbnormalCondition.Contains(type)) { if (resType == ResistivityType.弱い || (resType == ResistivityType.普通 && IsMagicConditionHit(doer, taker))) { effect = type - AttackType.毒 + AdditionalEffect.毒; } else if (resType == ResistivityType.強い || resType == ResistivityType.吸収) { // ダメージの処理は通常攻撃扱い resType = taker.Resistivity[AttackType.物理]; } } else if (type == AttackType.吸収) { // 吸収属性の吸収はミス if (resType == ResistivityType.吸収) return 0; // 吸収属性があれば、ここでマイナスに反転。 effect = AdditionalEffect.吸収; } // 相手に弱い属性が有ればAttack*2、強い属性ならばDefense*2。 if (resType == ResistivityType.弱い) atk *= 2; else if (resType == ResistivityType.強い) def *= 2; // ダメージ期待値=(Attack^0.4)*(Attack/(Defense+random(10))+.6)*(30+random(5))/35 var point = (int)(Math.Pow(atk, 0.4) * (atk / (def + WarGlobal.Random.Next(10)) + 0.6) * (30 + WarGlobal.Random.Next(5)) / 35); // ダメージが1以下なら1、999以上なら999。 point = XMath.Center(point, 1, 999); return point; }
/// <summary> /// Обновить юниты /// </summary> void RefreshUnits() { var warTowers = FindObjectsOfType <WarTower>(); foreach (var warTower in warTowers) { var warriors = warTower.warriors; foreach (var warrior in warriors) { if (warrior != null) { WarUnit warUnit = warrior.GetComponent <WarUnit>(); warUnit.health.FullHeal(); warUnit.ResetSkillsCounters(); } } } }
/// <summary> /// ユニットに状態異常が追加される直前に呼び出される。 /// </summary> /// <param name="situation"></param> /// <param name="unit"></param> /// <param name="oldCond"></param> public bool AddingConditonTable(Situation situation, WarUnit unit, IAbnormalCondition oldCond) { Contract.Requires(oldCond.GetType() == GetType()); var cond = (StatusChangeCondition)oldCond; // 効果がお互いに反対であった場合は状態異常を消す if (_changeStatusValue * cond._changeStatusValue < 0) { unit.Conditions.Remove(ID, situation); } // そうでない場合は、効果が大きいほうで上書きする else if (Math.Abs(_changeStatusValue) > Math.Abs(cond._changeStatusValue)) { cond._changeStatusValue = _changeStatusValue; } return false; }
private void InitialHero() { this.hero = new Characters.Characters(100, 100, 110, 100, 100, 2, 5, 30, 10, 20, new Vector2(0, 0), SpriteType.Mage, Shared.HeroHumanName, Shared.HeroHumanMaxLife); this.boss = new Characters.Characters(150, 300, 110, 110, 200, 2, 5, 30, 10, 10, new Vector2(0, 0), SpriteType.Ghoul, Shared.BossMonsterName, Shared.BossMonsterMaxLife); this.bossOne = new Characters.Characters(450, 150, 110, 110, 200, 2, 5, 30, 10, 10, new Vector2(0, 0), SpriteType.Ghoul, Shared.BossMonsterName, Shared.BossMonsterMaxLife); this.bossTwo = new Characters.Characters(800, 300, 110, 110, 200, 2, 5, 30, 10, 10, new Vector2(0, 0), SpriteType.Ghoul, Shared.BossMonsterName, Shared.BossMonsterMaxLife); this.stone = new Characters.Characters(350, 250, 310, 110, 200, 2, 5, 30, 10, 10, new Vector2(0, 0), SpriteType.Wall, Shared.BossMonsterName, Shared.BossMonsterMaxLife); this.fireItem = new FireBallMagic(500, 40, 30, 30, SpriteType.FireMagic, 1, 1, 5); this.stoneItem = new StoneMagic(890, 515, 30, 30, SpriteType.StoneMagic, 1, 2, 10); this.lifeItem = new StoneMagic(50, 130, 30, 30, SpriteType.LifeMagic, 50, 2, 1); this.charmItem = new StoneMagic(110, 400, 30, 30, SpriteType.CharmMagic, 5, 5, 5); DrawerDevice.AddObject(this.stoneItem); DrawerDevice.AddObject(this.fireItem); DrawerDevice.AddObject(this.lifeItem); DrawerDevice.AddObject(this.charmItem); DrawerDevice.AddObject(this.hero); DrawerDevice.AddObject(this.boss); DrawerDevice.AddObject(this.bossOne); DrawerDevice.AddObject(this.bossTwo); DrawerDevice.AddObject(this.stone); warUnits.Add(this.stone); warUnits.Add(this.boss); warUnits.Add(this.bossOne); warUnits.Add(this.bossTwo); items.Add(this.fireItem); items.Add(this.lifeItem); items.Add(this.charmItem); items.Add(this.stoneItem); }
public virtual IList<Point2> GetValidRangeScope(Situation situation, WarUnit doer, out IEnumerable<Point2> rangeScope) { var validRangePoints = new List<Point2>(); rangeScope = GetRangeScope(situation, doer); // 対象が存在するかどうかチェック foreach (var rangePoint in rangeScope) { foreach (var p in GetAreaScope(situation, doer, rangePoint)) { if (IsValidPoint(situation, doer, p)) { validRangePoints.Add(rangePoint); break; } } } return validRangePoints; }
/// <summary> /// このウインドウを表示する /// </summary> /// <param name="model"></param> /// <param name="doer"></param> /// <param name="finished"></param> /// <param name="index">魔法の属性を示すインデックス値</param> public void Show(WarPresentationModel model, WarUnit doer, Action finished, int index) { Debug.Assert(0 <= index && index <= 5, "予期せぬindex値を受け取りました: " + index); _model = model; var situation = model.Situation; // ボタンの全消去 flowButtonPanel.Controls.Clear(); // ボタンの追加 var magicDatasList = _magicCommands[index, doer.MagicLevels[magicAttributes[index]]]; for (int j = 0; j < magicDatasList.Count; j++) { var magicDatas = magicDatasList[j]; for (int i = 0; i < magicDatas.Count; i++) { var magicData = magicDatas[i]; var arc = new ActionArguments(situation, model); var button = new Button { Enabled = magicData.Action.CanBoot(arc, doer), Text = magicData.Name + (i + 1), }; button.Click += (sender_, e_) => { Visible = false; model.CancelCommandStack.Push(delegate { Visible = true; return true; // キャンセル処理の完了 }); magicData.Action.Boot(arc, doer, finished); }; button.MouseEnter += delegate { PointingMagic = magicData; }; button.MouseLeave += delegate { PointingMagic = null; }; flowButtonPanel.Controls.Add(button); } } SetDetail(null); Text = doer.Name; Visible = true; }
public void AttackPlayerUnit(WarUnit defender, int damage, WarUnit attacker, int counterDamage) { int unitsToRemoveFromDefender = damage / defender.GetDefaultHeаlth(); int remainingDamageToDefender = damage - (defender.GetDefaultHeаlth() * unitsToRemoveFromDefender); unitsToRemoveFromDefender += defender.DecreaseHealth(remainingDamageToDefender); this.supportRemoveKilledUnitsFromPlayerArmy.Enqueue(new KeyValuePair <WarUnit, decimal>(defender, unitsToRemoveFromDefender)); // counter-attack if (!attacker.AmIArcherOrMage) { int unitsToRemoveFromAttacker = counterDamage / attacker.GetDefaultHeаlth(); int remainingDamageToAttacker = counterDamage - (unitsToRemoveFromAttacker * attacker.GetDefaultHeаlth()); unitsToRemoveFromAttacker += attacker.DecreaseHealth(remainingDamageToAttacker); this.supportRemoveKilledUnitsFromEnemyArmy.Enqueue(new KeyValuePair <WarUnit, decimal>(attacker, unitsToRemoveFromAttacker)); } }
protected override IEnumerable<int> GetCoroutine(ActionArguments args, WarUnit doer, Point2 center, Action finished, Action doCoroutine) { // 行為のキャンセルの不許可 args.Model.CancelCommandStack.Clear(); // コストの消費 _cost.Expend(args.Situation, doer); // 攻撃アニメーションとその後の処理を予約する IEnumerable<Point2> areaPoints; var validPoints = _scope.GetValidAreaScope(args.Situation, doer, center, out areaPoints); _screenEffect.SetScreenEffect(args, doer, center, areaPoints, validPoints, doCoroutine); yield return 0; // エフェクト表示 foreach (var p in validPoints) { var taker = args.Situation.Map[p].Unit; taker.Conditions.Add(_cond, args.Situation); } finished(); }
public static bool IsBehindOrInFrontUsForAttack(WarUnit currentUnit, WarUnit targetUnit) { bool isBehind = IsNear(currentUnit.DrawCoord.X + currentUnit.CropWidth, targetUnit.DrawCoord.X, currentUnit.MinAttackDistance); bool inFront = IsNear(currentUnit.DrawCoord.X, targetUnit.DrawCoord.X + targetUnit.CropWidth, currentUnit.MinAttackDistance); bool nearUsByY = currentUnit.DrawCoord.Y >= targetUnit.DrawCoord.Y && currentUnit.DrawCoord.Y <= targetUnit.DrawCoord.Y + targetUnit.CropHeight; bool nearUsByYCrop = currentUnit.DrawCoord.Y + currentUnit.CropHeight >= targetUnit.DrawCoord.Y && currentUnit.DrawCoord.Y + currentUnit.CropHeight <= targetUnit.DrawCoord.Y + targetUnit.CropHeight; bool byY = nearUsByY || nearUsByYCrop; bool result = (isBehind && byY) || (inFront && byY); return(result); }
public WarUnit TryTakeNearestEnemyUnit(WarUnit enemyUnit, int radius) { this.supportUnit = null; double minDistance = double.MaxValue; foreach (var unit in this.enemyUnits) { double currentDistance = CollisionDetection.CalculateDistanceTravelled(unit.Key.DrawCoord, enemyUnit.DrawCoord); if ((currentDistance < minDistance) && ((int)currentDistance < radius)) { this.supportUnit = unit.Key; minDistance = currentDistance; } } return(this.supportUnit); }
public void EndCurrentTurn() { this.supportUnit = this.playerUnits.FirstOrDefault(x => x.Key.isChoosen == true).Key; if (this.supportUnit != null) { this.supportUnit.inBattleTurn = false; } else { this.supportUnit = this.playerUnits.FirstOrDefault( x => x.Key.GetStrengthLevel == unitStreghtLevelIndex && x.Key.inBattleTurn == true).Key; if (this.supportUnit != null) { this.supportUnit.inBattleTurn = false; } } this.TrySwitchTurn(); }
public void Show(WarPresentationModel model, WarUnit doer, Action finished) { // ボタンクリックイベントのためにフィールドを設定する _model = model; _doer = doer; _finished = finished; for (int i = 0; i < _buttonTable.Length; i++) { _buttonTable[i].Enabled = doer.MagicLevels[_magicAttributes[i]] > 0; } // キャンセル処理の登録 model.CancelCommandStack.Push(delegate { Visible = false; return false; // 次のキャンセル処理へ続く }); // ウィンドウの表示 Visible = true; }
protected virtual bool IsValidPoint(Situation situation, WarUnit doer, Point2 p) { var unit = situation.Map[p].Unit; // チップの情報からターゲットタイプの値を算出 TargetType type; if (unit == null) { type = TargetType.NONE; } else { if (doer.IsOpponent(unit)) type = TargetType.ENEMY; else type = TargetType.FRIEND; } // スコープのターゲットタイプに内包されるかチェック return (_targetType & type) != 0; }
protected override IEnumerable<int> GetCoroutine(ActionArguments args, WarUnit doer, Point2 center, Action finished, Action doCoroutine) { // 行為のキャンセルの不許可 args.Model.CancelCommandStack.Clear(); Debug.Assert(args.Situation.Map[center].Unit != null, "選択位置にユニットが存在しません."); var taker = args.Situation.Map[center].Unit; var doerAttack = doer.Status.DefaultAttacks.Select(atk => new { Doer = doer, Taker = taker, atk.Type, atk.Power }); var takerAttack = taker.Status.DefaultAttacks.Select(atk => new { Doer = taker, Taker = doer, atk.Type, atk.Power }); var source = doerAttack.AlternatelyConcat(takerAttack) .Where(info => info.Type != AttackType.なし); foreach (var info in source) { // ローカル変数にも代入しておく(ごっちゃにならないように) doer = info.Doer; taker = info.Taker; // アニメーション中は、マップ上のユニット表示をオフにする doer.Visible = false; // 攻撃アニメーションとその後の処理を予約する args.Model.SetContinuouslyMovingAnimationOnMap( doer.ChipImage, new[] { doer.Location, taker.Location, doer.Location }, args.Model.ATTACK_EFFECT_TIME, 0, doCoroutine); yield return 0; // エフェクト表示 doer.Visible = true; AdditionalEffect cond; var damage = BattleActionUtil.GetDamage(doer, taker, info.Power, info.Type, out cond); BattleActionUtil.RunAttackRoutine(args, doer, taker, damage, cond, doCoroutine); yield return 0; // ダメージ表示 // どちらかが死亡したら処理を中断 if (!doer.Alive || !taker.Alive) break; } finished(); }
protected override IEnumerable<int> GetCoroutine(ActionArguments args, WarUnit doer, Point2 center, Action finished, Action doCoroutine) { // 行為のキャンセルの不許可 args.Model.CancelCommandStack.Clear(); // コストの消費 _cost.Expend(args.Situation, doer); IEnumerable<Point2> areaPoints; var validPoints = _scope.GetValidAreaScope(args.Situation, doer, center, out areaPoints); var times = XMath.Center(doer.SkillTimes, 1, _maxTimes); _screenEffect.SetScreenEffect(args, doer, center, areaPoints, validPoints, times, (times_, maxTimes_) => { foreach (var p in validPoints) { var taker = args.Situation.Map[p].Unit; AdditionalEffect cond; var value = BattleActionUtil.GetSkillValue(doer, taker, _power, _attackType, _atkDependency, _defDependency, out cond); var action = times_ < maxTimes_ ? doCoroutine.GetNOP() : doCoroutine; if (_attackType != AttackType.体力回復 && _attackType != AttackType.魔力回復) { BattleActionUtil.RunAttackRoutine(args, doer, taker, value, cond, action); } else { if (_attackType == AttackType.体力回復) taker.HealHP(args.Situation, doer, value); else taker.HealMP(args.Situation, doer, value); // 回復値の表示 args.Model.SetHealAnimationOnMap(value, doer.Location, action); } } }); yield return 0; // 最後のダメージ表示 finished(); }
private void AttackEnemyUnit(WarUnit player, int playerDamage, WarUnit enemy, int enemyDamage) { int unitsToRemoveFromDefender = playerDamage / enemy.GetDefaultHeаlth(); int remainingDamageToDefender = playerDamage - (enemy.GetDefaultHeаlth() * unitsToRemoveFromDefender); unitsToRemoveFromDefender += enemy.DecreaseHealth(remainingDamageToDefender); this.supportRemoveKilledUnitsFromEnemyArmy.Enqueue(new KeyValuePair <WarUnit, decimal>(enemy, unitsToRemoveFromDefender)); // counter-attack if (!player.AmIArcherOrMage) { int unitsToRemoveFromAttacker = enemyDamage / player.GetDefaultHeаlth(); int remainingDamageToAttacker = enemyDamage - (unitsToRemoveFromAttacker * player.GetDefaultHeаlth()); unitsToRemoveFromAttacker += player.DecreaseHealth(remainingDamageToAttacker); this.supportRemoveKilledUnitsFromPlayerArmy.Enqueue(new KeyValuePair <WarUnit, decimal>(player, unitsToRemoveFromAttacker)); } }
protected override IEnumerable<int> GetCoroutine(ActionArguments args, WarUnit doer, Point2 center, Action finished, Action doCoroutine) { // 行為のキャンセルの不許可 args.Model.CancelCommandStack.Clear(); // コストの消費 _cost.Expend(args.Situation, doer); // 攻撃アニメーションとその後の処理を予約する IEnumerable<Point2> areaPoints; var validPoints = _scope.GetValidAreaScope(args.Situation, doer, center, out areaPoints); _screenEffect.SetScreenEffect(args, doer, center, areaPoints, validPoints, doCoroutine); yield return 0; // エフェクト表示 foreach (var p in validPoints) { Debug.Assert(args.Situation.Map[p].Unit == null); var unit = WarGlobal.UnitBuilder.Create(new Unit(_unit), doer.Side, null); args.Situation.Units.AddUnit(unit); args.Situation.Map.Deploy(unit, p); } finished(); }
public void TryToAttackEnemyUnit(WarUnit player, WarUnit enemy, Weapon weapon) { int weaponDamage = 0; if (weapon != null) { weaponDamage = weapon.Damage; } decimal playerQuantity = MapManager.Instance.Battlefield.TryTakeEnemmyUnitQuantity(player); int playerDamage = (player.Damage + weaponDamage) * (int)playerQuantity; decimal enemyQuantity = MapManager.Instance.Battlefield.TryTakeFriendUnitQuantity(enemy); int enemyDamage = (int)(enemy.Damage * enemyQuantity); //if (player.inBattleTurn) //{ // this.AttackEnemyUnit(player, playerDamage, enemy, enemyDamage); //} //player.inBattleTurn = false; this.AttackEnemyUnit(player, playerDamage, enemy, enemyDamage); }
protected override IEnumerable<int> GetCoroutine(ActionArguments args, WarUnit doer, Point2 center, Action finished, Action doCoroutine) { // 行為のキャンセルの不許可 args.Model.CancelCommandStack.Clear(); // コストの消費 _cost.Expend(args.Situation, doer); // 攻撃アニメーションとその後の処理を予約する IEnumerable<Point2> areaPoints; var validPoints = _scope.GetValidAreaScope(args.Situation, doer, center, out areaPoints); _screenEffect.SetScreenEffect(args, doer, center, areaPoints, validPoints, doCoroutine); yield return 0; // エフェクト表示 // 対象内の壁を破壊 var map = args.Situation.Map; var enableDamageAnimation = false; foreach (var p in areaPoints) { var land = map[p]; if (land.Construct != null && land.Construct.Info.Name == "壁") { map[p] = new Land(land.Height, land.Landform, null); if (land.Unit != null && _attackType != AttackType.なし) { var taker = land.Unit; AdditionalEffect cond; var damage = BattleActionUtil.GetMagicDamage(doer, taker, _power, _attackType, out cond); BattleActionUtil.RunAttackRoutine(args, doer, taker, damage, cond, doCoroutine); enableDamageAnimation = true; } } } if (enableDamageAnimation) yield return 0; // ダメージ表示 finished(); }
protected override IEnumerable<int> GetCoroutine(ActionArguments args, WarUnit doer, Point2 center, Action finished, Action doCoroutine) { // 行為のキャンセルの不許可 args.Model.CancelCommandStack.Clear(); // コストの消費 _cost.Expend(args.Situation, doer); // 攻撃アニメーションとその後の処理を予約する IEnumerable<Point2> areaPoints; var validPoints = _scope.GetValidAreaScope(args.Situation, doer, center, out areaPoints); _screenEffect.SetScreenEffect(args, doer, center, areaPoints, validPoints, doCoroutine); yield return 0; // エフェクト表示 foreach (var p in validPoints) { var taker = args.Situation.Map[p].Unit; if (!AttackTypes.Heal.Contains(_attackType)) { AdditionalEffect cond; var damage = BattleActionUtil.GetMagicDamage(doer, taker, _power, _attackType, out cond); BattleActionUtil.RunAttackRoutine(args, doer, taker, damage, cond, doCoroutine); } else { var value = BattleActionUtil.GetMagicHeal(doer, taker, _power); if (_attackType == AttackType.体力回復) taker.HealHP(args.Situation, doer, value); else taker.HealMP(args.Situation, doer, value); // 回復値の表示 args.Model.SetHealAnimationOnMap(value, doer.Location, doCoroutine); } } yield return 0; // ダメージ表示 finished(); }
private void QueryControler2(IControlerable controler, WarUnit unit) { controler.MoveUp += (sender, args) => { MoveHeroToRight(unit); }; controler.MoveDown += (sender, args) => { MoveHeroDown(unit); }; controler.MoveToLeft += (sender, args) => { MoveHeroToRight(unit); }; controler.MoveToRight += (sender, args) => { MoveHeroUp(unit); }; controler.ThrowMagic += (sender, args) => { var magicArgs = args as CastEventArgs; HeroThrowMgic(magicArgs.mx, magicArgs.my); }; }
protected override IEnumerable<int> GetCoroutine(ActionArguments args, WarUnit doer, Point2 center, Action finished, Action doCoroutine) { // キャンセル処理のために記憶する var oldLocation = doer.Location; var resetCommandState = doer.SaveCommandState(); // 移動アニメーション用に経路を生成する var movePoints = new Stack<Point2>(); var movePoint = _scope.CurrentMovableArea.Find(p => p.Point == center); while (movePoint != null) { movePoints.Push(movePoint.Point); movePoint = movePoint.From; } // アニメーション中は、マップ上のユニット表示をオフにする doer.Visible = false; // 移動アニメーションのセット args.Model.SetContinuouslyMovingAnimationOnMap(doer.ChipImage, movePoints, 150, 20, doCoroutine); yield return 0; // 移動アニメーションの表示 // アニメーション後に元に戻す doer.Visible = true; args.Situation.Map.MoveUnit(doer, center); // アクション終了の通知 finished(); // 移動前に戻すキャンセル処理の追加 args.Model.CancelCommandStack.Push( () => { args.Situation.Map.MoveUnit(doer, oldLocation); resetCommandState(); return false; // キャンセル処理の続行 }); }
private void CheckAndTakActionOnClickedButton(StrenghtLevel strengthCreatureLevel, int index, int minY, int maxY, GameTime gameTime) { MouseExtended.Current.GetState(gameTime); // if mouse over PLUS button if (MouseExtended.Current.CurrentState.Position.X > this.minXPlusButton && MouseExtended.Current.CurrentState.Position.X < this.maxXPlusButton && MouseExtended.Current.CurrentState.Position.Y > minY && MouseExtended.Current.CurrentState.Position.Y < maxY) { // if click on button if (this.newMouseState.LeftButton == ButtonState.Pressed && this.oldMouseState.LeftButton == ButtonState.Released) { // if there are enough creatures if (this.gadini.FirstOrDefault(x => x.Key.GetStrengthLevel == strengthCreatureLevel).Value - this.creatureCounter[index] >= 1) { this.creatureCounter[index]++; this.SendClickRequest(); } } } // if mouse is over check/purchase button if (MouseExtended.Current.CurrentState.Position.X > this.minXCheckButton && MouseExtended.Current.CurrentState.Position.X < this.maxXCheckButton && MouseExtended.Current.CurrentState.Position.Y > minY && MouseExtended.Current.CurrentState.Position.Y < maxY) { // purchase a creature if (this.newMouseState.LeftButton == ButtonState.Pressed && this.oldMouseState.LeftButton == ButtonState.Released) { int a = 0; this.SendClickRequest(); for (int i = 0; i < this.creatureCounter[index]; i++) { // add creature to Player / remove creature from Castle this.RemoveCreature( this.gadini.FirstOrDefault(x => x.Key.GetStrengthLevel == strengthCreatureLevel).Key); WarUnit unit = this.gadini.FirstOrDefault(x => x.Key.GetStrengthLevel == strengthCreatureLevel).Key; CharacterManager.barbarian.AddCreature(unit); } this.creatureCounter[index] = 0; } } // if mouse is over minus button if (MouseExtended.Current.CurrentState.Position.X > this.minXMinusButton && MouseExtended.Current.CurrentState.Position.X < this.maxXMinusButton && MouseExtended.Current.CurrentState.Position.Y > minY && MouseExtended.Current.CurrentState.Position.Y < maxY) { if (this.newMouseState.LeftButton == ButtonState.Pressed && this.oldMouseState.LeftButton == ButtonState.Released) { if (this.creatureCounter[index] > 0) { this.creatureCounter[index]--; this.SendClickRequest(); } } } }
private void UnsubscribeFromSoundEvent(WarUnit unit) { unit.OnEvent -= ScreenManager.Instance.SoundEffectManager.ExecuteQuery; }
private void TestPoint(WarUnit movableObject) { double tempX = movableObject.X; double tempY = movableObject.Y; double tempHeroX = hero.X; double tempHeroY = hero.Y; double tempBossX = boss.X; double tempBossY = boss.Y; double tempBoss1X = bossOne.X; double tempBoss1Y = bossOne.Y; double tempBoss2X = bossTwo.X; double tempBoss2Y = bossTwo.Y; movableObject.Move(); if (movableObject.X < 0 || movableObject.X + movableObject.Width > space.Width) { movableObject.X = tempX; } if (movableObject.Y < infoPanel.Height || movableObject.Y + movableObject.Height > space.Height) { movableObject.Y = tempY; //amovableObject.Direction = new Vector2(0, 0); } if (IsInRange(movableObject, stone)) { movableObject.X = tempX; movableObject.Y = tempY; } if (IsInRange(hero, boss)) { boss.X = tempBossX; boss.Y = tempBossY; hero.X = tempHeroX; hero.Y = tempHeroY; hero.Life = hero.Life - 30; } if (IsInRange(hero, bossOne)) { bossOne.X = tempBoss1X; bossOne.Y = tempBoss1Y; hero.X = tempHeroX; hero.Y = tempHeroY; hero.Life = hero.Life - 30; } if (IsInRange(hero, bossTwo)) { bossTwo.X = tempBoss2X; bossTwo.Y = tempBoss2Y; hero.X = tempHeroX; hero.Y = tempHeroY; hero.Life = hero.Life - 30; } if (IsInRange(bossOne, bossTwo)) { bossOne.X = tempBoss2X; bossOne.Y = tempBoss2Y; bossTwo.X = tempBoss1X; bossTwo.Y = tempBoss1Y; } if (IsInRange(bossOne, bossTwo)) { bossOne.X = tempBoss2X; bossOne.Y = tempBoss2Y; bossTwo.X = tempBoss1X; bossTwo.Y = tempBoss1Y; } if (IsInRange(boss, bossOne)) { boss.X = tempBoss1X; boss.Y = tempBoss1Y; bossTwo.X = tempBossX; bossTwo.Y = tempBossY; } if (IsInRange(boss, bossTwo)) { boss.X = tempBoss2X; boss.Y = tempBoss2Y; bossTwo.X = tempBossX; bossTwo.Y = tempBossY; } foreach (Interfaces.Items item in items) { if (IsInRange(hero, item)) { item.X = 0; item.Y = -10; DrawerDevice.RedrawObject(item); inventory.AddItem(item); hero.Life += inventory.GiveLifeSkill; if (hero.Life > hero.MaxLife) { hero.Life = hero.MaxLife; } inventory.GiveLifeSkill = 0; hero.Defence += inventory.GiveDefenceSkill; inventory.GiveDefenceSkill = 0; hero.TakeLIfe += inventory.GiveAttackSkill; inventory.GiveAttackSkill = 0; } } }
protected void RemoveCreature(WarUnit warUnit) { this.gadini[warUnit]--; }
private void MoveHeroUp(WarUnit unit) { unit.Direction = new Vector2(0, -1); TestPoint(unit); }
private void MoveHeroToLeft(WarUnit unit) { unit.Direction = new Vector2(1, 0); TestPoint(unit); }
public FireBall(double x, double y, double width, double height, WarUnit thrower, int range, int TakeLife, int timeOut, SpriteType spriteType, Magics magicType ) : base(x, y, width, height, thrower, range, TakeLife, timeOut, spriteType, magicType) { }
private Image GetImageByDirection(IRenderable renderableObject) { Image image; WarUnit u = (WarUnit)renderableObject; switch (renderableObject.SpriteType) { case SpriteType.Mage: if (u.Direction.X == 1 && u.Direction.Y == 0) { image = this.mageImageR; } else if (u.Direction.X == -1 && u.Direction.Y == 0) { image = this.mageImageL; } else if (u.Direction.X == 0 && u.Direction.Y == -1) { image = this.mageImageU; } else if (u.Direction.X == 0 && u.Direction.Y == 1) { image = this.mageImageD; } else { image = this.mageImage; } break; case SpriteType.Fire: image = this.fireImage; break; case SpriteType.Ghoul: if (u.Direction.X == 1 && u.Direction.Y == 0) { image = this.ghoulImageL; } else if (u.Direction.X == -1 && u.Direction.Y == 0) { image = this.ghoulImageR; } else if (u.Direction.X == 0 && u.Direction.Y == -1) { image = this.ghoulImageU; } else if (u.Direction.X == 0 && u.Direction.Y == 1) { image = this.ghoulImageD; } else { image = this.ghoulImageD; } break; case SpriteType.FireMagic: image = this.fireItem; break; case SpriteType.StoneMagic: image = this.stoneItem; break; case SpriteType.LifeMagic: image = this.lifeItem; break; case SpriteType.CharmMagic: image = this.charmItem; break; case SpriteType.Stone: image = this.stoneOnThrow; break; case SpriteType.Spit: image = this.spitImage; break; default: image = this.wallImage; break; } return(image); }
protected void AddCreature(WarUnit warUnit) { this.gadini[warUnit]++; }