public ExtMarchUnit(ExtStep step, WCFMarchUnit wcfMarchUnit)
        {
            Step         = step;
            WCFMarchUnit = wcfMarchUnit;

            ExtUnit = Step.Game.ViewUnit.Single(p => p.WCFUnit.Id == WCFMarchUnit.Unit);
        }
Beispiel #2
0
 void UnitView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     _Unit = (ExtUnit)e.NewValue;
 }
        private bool UnitTypeDrop(DragEventArgs e)
        {
            ExtUnitType dropUnitType = (e.Data.GetData(typeof(ExtUnitType)) as ExtUnitType);

            if (dropUnitType == null)
            {
                return(false);
            }

            if (_Terrain.ExtGarrison != null && _Terrain.ExtHolderUser != _Terrain.Game.ClientGameUser)
            {
                return(true);
            }

            if (dropUnitType.WCFUnitType.Cost > (_Terrain.Game.SelectedOrder.ExtTerrain.WCFTerrain.Strength - _Terrain.Game.ClientStep.ExtMarch.SumCost))
            {
                App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_consolidate1"));
                return(true);
            }

            if (dropUnitType.WCFUnitType.Name != "Корабль" && _Terrain.Game.SelectedOrder.ExtTerrain != _Terrain)
            {
                App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_consolidate2"));
                return(true);
            }

            if (dropUnitType.WCFUnitType.Name == "Корабль")
            {
                if (!_Terrain.Game.SelectedOrder.ExtTerrain.JoinTerrainCol.Contains(_Terrain) || _Terrain.WCFTerrain.TerrainType == "Земля")
                {
                    App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_consolidate3"));
                    return(true);
                }
                if (_Terrain.ExtHolderUser != null && _Terrain.ExtHolderUser != _Terrain.Game.ClientGameUser)
                {
                    App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_consolidate4"));
                    return(true);
                }
            }

            WCFUnit unit = new WCFUnit();

            unit.UnitType = dropUnitType.WCFUnitType.Name;
            unit.Terrain  = _Terrain.WCFTerrain.Name;
            unit.Step     = _Terrain.Game.ClientStep.WCFStep.Id;

            ExtUnit extUnit = new ExtUnit(_Terrain.Game.ClientStep, unit);

            if (!CheckMove(extUnit, _Terrain))
            {
                return(true);
            }

            WCFMarchUnit wcfMarchUnit = new WCFMarchUnit();

            wcfMarchUnit.Unit     = extUnit.WCFUnit.Id;
            wcfMarchUnit.Terrain  = extUnit.TempTerrain.WCFTerrain.Name;
            wcfMarchUnit.UnitType = extUnit.TempUnitType.WCFUnitType.Name;

            _Terrain.Game.ClientStep.ExtGameUserInfo.ExtUnit.Add(extUnit);
            _Terrain.Game.ClientStep.ExtMarch.WCFMarch.MarchUnit.Add(wcfMarchUnit);
            _Terrain.Game.ClientStep.ExtMarch.SumCost += dropUnitType.WCFUnitType.Cost;
            return(true);
        }
        //Проверка марша
        private bool CheckMove(ExtUnit unit, ExtTerrain toTerrain)
        {
            if (!_Terrain.Game.ClientStep.WCFStep.StepType.Contains("Усиление_власти"))
            {
                //запрет движение в никуда
                if (unit.ExtTerrain == toTerrain)
                {
                    return(false);
                }

                if (unit.WCFUnit.UnitType == "Корабль" && toTerrain.WCFTerrain.TerrainType == "Земля")
                {
                    App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_move1"));
                    return(false);
                }

                if (unit.WCFUnit.UnitType != "Корабль" && toTerrain.WCFTerrain.TerrainType != "Земля")
                {
                    App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_move2"));
                    return(false);
                }

                if (!toTerrain.JoinTerrainCol.Contains(unit.ExtTerrain))
                {
                    if (unit.WCFUnit.UnitType == "Корабль")
                    {
                        App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_move3"));
                        return(false);
                    }
                    else
                    {
                        if (!rCheckTransfer(unit.ExtTerrain, toTerrain, new List <ExtTerrain>(), unit.Step.ExtGameUser))
                        {
                            App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_move4"));
                            return(false);
                        }
                    }
                }
            }

            if (toTerrain.WCFTerrain.TerrainType == "Порт")
            {
                if (toTerrain.TempUnit.Count(p => p != unit) == 3)
                {
                    App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_move5"));
                    return(false);
                }

                if (toTerrain.ExtHolderUser != unit.Step.ExtGameUser)
                {
                    App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_move6"));
                    return(false);
                }
            }

            if (toTerrain.TempUnit.Count(p => p.Step == unit.Step && p != unit) == 4)
            {
                App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_move7"));
                return(false);
            }


            if (_Terrain.Game.ClientStep.WCFStep.StepType == "Отступление" ||
                _Terrain.Game.ClientStep.WCFStep.StepType == "Робб_Старк")
            {
                if (_Terrain.Game.ClientStep.WCFStep.March.MarchUnit.Any(p => p.Terrain != toTerrain.WCFTerrain.Name))
                {
                    App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_move8"));
                    return(false);
                }

                if (_Terrain.Game.ViewGameInfo.ExtBattle.AttackUser.LastStep.WCFStep.StepType != "Робб_Старк" &&
                    toTerrain.WCFTerrain.Name == _Terrain.Game.ViewGameInfo.ExtBattle.WCFBattle.AttackTerrain)
                {
                    App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_move9"));
                    return(false);
                }

                if ((toTerrain.ExtHolderUser != null && unit.Step.ExtGameUser != toTerrain.ExtHolderUser) ||
                    (toTerrain.ExtHolderUser == null && _Terrain.ExtGarrison != null))
                {
                    App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("validation_move10"));
                    return(false);
                }
            }

            return(true);
        }