Наследование: Objective
Пример #1
0
        protected override bool Confront(int relX, int relY)
        {
            ITile moveTarget = Map[X, Y][relX, relY];
            City  city       = moveTarget.City;

            if (city == null || city == Home || (city.Owner == Owner && Home != null && moveTarget.DistanceTo(Home) < 10))
            {
                Movement       = new MoveUnit(relX, relY);
                Movement.Done += MoveEnd;
                GameTask.Insert(Movement);
                return(true);
            }

            if (city.Owner != Owner)
            {
                EstablishTradeRoute(moveTarget.City);
                return(true);
            }

            if (Game.Human == Owner)
            {
                GameTask.Enqueue(Show.CaravanChoice(this, city));
            }

            return(true);
        }
Пример #2
0
    // 合体完成
    private void FinishCombination()
    {
        _combineUnitList.Clear();        // 清空合体列表
        _touchModel.TouchEnabled = true; // 开启触摸

        // Current升级
        CurrentUnit.SetData(CurrentUnit.NextLevel, CurrentUnit.Special);

        // 更新分数
        ScoreManager.Instance.UpdateScore = true;

        // 产生下一个物体
        GenerateUnit();

        // 检测移动物体是否移动
        foreach (var unit in _unitList)
        {
            MoveUnit moveUnit = unit.GetComponent <MoveUnit>();
            if (moveUnit != null && moveUnit.IsAlive)
            {
                bool isSurrounded = WanderAround(moveUnit);
                if (isSurrounded)
                {
                    moveUnit.SetAlive(false);
                }
            }
        }
    }
Пример #3
0
 protected void MovementTo(int relX, int relY)
 {
     MovementStart(Tile);
     Movement       = new MoveUnit(relX, relY);
     Movement.Done += MoveEnd;
     GameTask.Insert(Movement);
 }
Пример #4
0
 void Start()
 {
     if (selfAuto == null)
     {
         selfAuto = GetComponent <autoMovement>();
     }
     if (selfMove == null)
     {
         selfMove = GetComponent <MoveUnit>();
     }
     if (selfSend == null)
     {
         selfSend = GetComponent <sendUnit>();
     }
     if (hexa == null)
     {
         hexa = Hexasphere.GetInstance("Hexasphere");
     }
     //set height adjustment to keep object flush with surface
     heightAdjust = GetComponent <Renderer>().bounds.size.y;
     //get current tile at position, parent and set object alignment
     currentTile = hexa.GetTileAtLocalPos(transform.position);
     //hexa.ParentAndAlignToTile(gameObject, currentTile, heightAdjust, true, false, 1);
     //set initial state as idle
     stateMachine.ChangeState(new Idle(this));
 }
Пример #5
0
    // 单次合并(递归)
    private void DoLink(Tile tile)
    {
        GF.MyPrint("----------- DoLink Began");
        int start_x = tile.X - 1;
        int end_x   = tile.X + 1;

        start_x = start_x < 0 ? tile.X : start_x;
        end_x   = end_x > _row - 1 ? tile.X : end_x;
        for (int x = start_x; x <= end_x; x++)
        {
            int offset_y = 1 - Mathf.Abs(x - tile.X);
            int start_y  = tile.Y - offset_y;
            int end_y    = tile.Y + offset_y;
            start_y = start_y < 0 ? tile.Y : start_y;
            end_y   = end_y > _col - 1 ? tile.Y : end_y;

            for (int y = start_y; y <= end_y; y++)
            {
                if (x == tile.X && y == tile.Y)
                {
                    continue;                               // 不检测自身
                }
                Tile surroundTile = GetTile(x, y);
                if (surroundTile.IsEmpty())
                {
                    GF.MyPrint(surroundTile.name + " is Empty");
                    continue;       // 如果是空的,跳过
                }
                Unit unit = surroundTile.Unit;
                if (CheckIsInCombineList(unit) || unit == CurrentUnit)
                {
                    GF.MyPrint(unit.name + " is already added");
                    continue;       // 已加入列表,跳过
                }
                if (unit.Level != CurrentUnit.NextLevel)
                {
                    GF.MyPrint(string.Format("Level not match: {0}/Current : {1}/{2}", unit.name, unit.Level, CurrentUnit.NextLevel));
                    continue;   // 等级不一样,跳过
                }
                if (unit.Type != CurrentUnit.Type)
                {
                    GF.MyPrint(string.Format("Type not match: {0}/Current : {1}/{2}", unit.name, unit.Type, CurrentUnit.Type));
                    continue;   // 类型不一样,跳过
                }
                MoveUnit moveUnit = unit.GetComponent <MoveUnit>();
                if (moveUnit != null && moveUnit.IsAlive)
                {
                    GF.MyPrint(string.Format("{0} is still alive", moveUnit.name));
                    continue;   // 移动物体还活着
                }
                GF.MyPrint(unit.name + " will be added");
                _combineUnitList.Add(unit);
                _singleCombineUnitList.Add(unit);
                // 递归检测下一个邻位
                DoLink(surroundTile);
            }
        }
        GF.MyPrint("----------- DoLink Ended");
    }
Пример #6
0
 public void PreCalculate()
 {
     if (ownerMove == null)
     {
         ownerMove = owner.GetComponent <MoveUnit>();
     }
     Enter();
 }
Пример #7
0
    // 创建移动Unit
    private MoveUnit CreateMovableUnit(Tile tile)
    {
        Transform moveUnitTr = Instantiate(moveUnitPrefab);
        MoveUnit  moveUnit   = moveUnitTr.GetComponent <MoveUnit>();

        moveUnit.SetParent(tile);
        moveUnit.SetData(1);
        moveUnit.SetAlive(true);
        return(moveUnit);
    }
Пример #8
0
        private void MoveEnd(object sender, EventArgs args)
        {
            ITile previousTile = Map[_x, _y];

            X       += Movement.RelX;
            Y       += Movement.RelY;
            Movement = null;

            Explore();
            MovementDone(previousTile);
            Game.UpdateResources(Tile, false);
        }
Пример #9
0
        private void MoveEnd(object sender, EventArgs args)
        {
            ITile previousTile = Map[_x, _y];

            X += Movement.RelX;
            Y += Movement.RelY;
            if (X == Goto.X && Y == Goto.Y)
            {
                Goto = Point.Empty;
            }
            Movement = null;

            Explore();
            MovementDone(previousTile);
        }
Пример #10
0
    // 移动物体
    private bool WanderAround(MoveUnit moveUnit)
    {
        List <Tile> emptyList    = new List <Tile>();
        bool        isSurrounded = true;
        Tile        currentTile  = moveUnit.Tile;

        // 检测上下左右是否有空位可以移动
        int start_x = currentTile.X - 1;
        int end_x   = currentTile.X + 1;

        start_x = start_x < 0 ? currentTile.X : start_x;
        end_x   = end_x > _row - 1 ? currentTile.X : end_x;
        for (int x = start_x; x <= end_x; x++)
        {
            int offset_y = 1 - Mathf.Abs(x - currentTile.X);
            int start_y  = currentTile.Y - offset_y;
            int end_y    = currentTile.Y + offset_y;
            start_y = start_y < 0 ? currentTile.Y : start_y;
            end_y   = end_y > _col - 1 ? currentTile.Y : end_y;

            for (int y = start_y; y <= end_y; y++)
            {
                if (x == currentTile.X && y == currentTile.Y)
                {
                    continue;                                             // 不检测自身
                }
                Tile surroundTile = GetTile(x, y);
                if (surroundTile.IsEmpty())
                {
                    // 如果有一个是空的,那么MoveUnit就不会被围死
                    isSurrounded = false;
                    emptyList.Add(surroundTile);
                }
            }
        }

        // 如果有空位,随机选一个作为移动的目标
        if (emptyList.Count > 0)
        {
            int  pickOne = Random.Range(0, emptyList.Count);
            Tile target  = emptyList[pickOne];
            moveUnit.MoveToTile(target);
        }

        return(isSurrounded);
    }
Пример #11
0
        protected override bool Confront(int relX, int relY)
        {
            ITile moveTarget = Map[X, Y][relX, relY];

            if (moveTarget.City != null)
            {
                if (Human == Owner)
                {
                    GameTask.Enqueue(Show.DiplomatCity(moveTarget.City, this));
                    return(true);
                }
                else
                {
                    if (moveTarget.City.Player == Human)
                    {
                        GameTask.Enqueue(Tasks.Show.DiplomatSabotage(moveTarget.City, this));
                    }
                    else
                    {
                        Sabotage(moveTarget.City);
                    }

                    return(true);
                }
            }

            IUnit[] units = moveTarget.Units;

            if (units.Length == 1)
            {
                IUnit unit = units[0];

                if (unit.Owner != Owner && unit is BaseUnitLand)
                {
                    GameTask.Enqueue(Show.DiplomatBribe(unit as BaseUnitLand, this));
                    return(true);
                }
            }

            Movement       = new MoveUnit(relX, relY);
            Movement.Done += MoveEnd;
            GameTask.Insert(Movement);
            return(true);
        }
Пример #12
0
        internal virtual bool Confront(int relX, int relY)
        {
            Goto = Point.Empty;                         // Cancel any goto mode when Confronting

            if (Class == UnitClass.Land && (this is Diplomat || this is Caravan))
            {
                // TODO fire-eggs this should never happen? Diplomat/Caravan have overloads
                return(false);
            }

            Movement = new MoveUnit(relX, relY);

            ITile moveTarget = Map[X, Y][relX, relY];

            if (moveTarget == null)
            {
                return(false);
            }
            if (moveTarget.Units.Length == 0 && moveTarget.City != null && moveTarget.City.Owner != Owner)
            {
                if (Class != UnitClass.Land)                 // can't occupy city with sea/air unit
                {
                    GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText($"ERROR/OCCUPY")));
                    Movement = null;
                    return(false);
                }

                City capturedCity = moveTarget.City;
                Movement.Done += (s, a) =>
                {
                    Action changeOwner = delegate()
                    {
                        Player previousOwner = Game.GetPlayer(capturedCity.Owner);

                        if (capturedCity.HasBuilding <Palace>())
                        {
                            capturedCity.RemoveBuilding <Palace>();
                        }
                        capturedCity.Food    = 0;
                        capturedCity.Shields = 0;
                        while (capturedCity.Units.Length > 0)
                        {
                            Game.DisbandUnit(capturedCity.Units[0]);
                        }
                        capturedCity.Owner = Owner;

                        if (!capturedCity.HasBuilding <CityWalls>())
                        {
                            capturedCity.Size--;
                        }

                        previousOwner.IsDestroyed();
                    };

                    IList <IAdvance> advancesToSteal = GetAdvancesToSteal(capturedCity.Player);

                    if (Human == capturedCity.Owner || Human == Owner)
                    {
                        Player cityOwner = Game.GetPlayer(capturedCity.Owner);
                        float  totalSize = cityOwner.Cities.Sum(x => x.Size);
                        int    totalGold = cityOwner.Gold;

                        // Issue #56 : Gold formula from CivFanatics
                        int captureGold = (int)(totalGold * ((float)capturedCity.Size / totalSize));

                        Game.GetPlayer(capturedCity.Owner).Gold -= (short)captureGold;
                        Game.CurrentPlayer.Gold += (short)captureGold;

                        string[] lines = { $"{Game.CurrentPlayer.TribeNamePlural} capture",
                                           $"{capturedCity.Name}. {captureGold} gold",
                                           "pieces plundered." };

                        EventHandler doneCapture = (s1, a1) =>
                        {
                            changeOwner();

                            if (capturedCity.Size == 0 || Human != Owner)
                            {
                                return;
                            }
                            GameTask.Insert(Show.CityManager(capturedCity));

                            // fire-eggs 20190628 no 'select advance' dialog when non-human is doing the capturing!
                            if (advancesToSteal.Any() && Human == Owner)
                            {
                                GameTask.Enqueue(Show.SelectAdvanceAfterCityCapture(Player, advancesToSteal));
                            }
                        };

                        if (Game.Animations)
                        {
                            Show captureCity = Show.CaptureCity(capturedCity, lines);
                            captureCity.Done += doneCapture;
                            GameTask.Insert(captureCity);
                        }
                        else
                        {
                            IScreen captureNews = new Newspaper(capturedCity, lines, false);
                            captureNews.Closed += doneCapture;
                            Common.AddScreen(captureNews);
                        }
                    }
                    else
                    {
                        changeOwner();
                        if (advancesToSteal.Any())
                        {
                            Player.AddAdvance(advancesToSteal.First());
                        }
                    }
                    MoveEnd(s, a);
                };
            }
            else if (this is Nuclear)
            {
                int  xx   = (X - Common.GamePlay.X + relX) * 16;
                int  yy   = (Y - Common.GamePlay.Y + relY) * 16;
                Show nuke = Show.Nuke(xx, yy);

                if (Map[X, Y][relX, relY].City != null)
                {
                    PlaySound("airnuke");
                }
                else
                {
                    PlaySound("s_nuke");
                }

                nuke.Done += (s, a) =>
                {
                    foreach (ITile tile in Map.QueryMapPart(X + relX - 1, Y + relY - 1, 3, 3))
                    {
                        while (tile.Units.Length > 0)
                        {
                            Game.DisbandUnit(tile.Units[0]);
                        }
                    }
                };
                GameTask.Enqueue(nuke);
            }
            else if (AttackOutcome(this, Map[X, Y][relX, relY]))
            {
                Movement.Done += (s, a) =>
                {
                    if (this is Cannon)
                    {
                        PlaySound("cannon");
                    }
                    else if (this is Musketeers || this is Riflemen || this is Armor || this is Artillery || this is MechInf)
                    {
                        PlaySound("s_land");
                    }
                    else
                    {
                        PlaySound("they_die");
                    }

                    // fire-eggs 20190702 capture barbarian leader, get ransom
                    IUnit[] attackedUnits = moveTarget.Units;
                    if (attackedUnits.Length > 0 && attackedUnits.All(x => x is Diplomat) &&
                        attackedUnits[0] is Diplomat &&
                        ((BaseUnit)attackedUnits[0]).Player.Civilization is Barbarian)
                    {
                        Player.Gold += 100;
                        if (Human == Player)
                        {
                            Common.AddScreen(new MessageBox("Barbarian leader captured!", "100$ ransom paid."));
                        }
                    }

                    IUnit unit = attackedUnits.FirstOrDefault();
                    if (unit != null)
                    {
                        var task = Show.DestroyUnit(unit, true);

                        // fire-eggs 20190729 when destroying last city, check for civ destruction ASAP
                        if (unit.Owner != 0)
                        {
                            task.Done += (s1, a1) => { Game.GetPlayer(unit.Owner).IsDestroyed(); }
                        }
                        ;

                        GameTask.Insert(task);
                        //GameTask.Insert(Show.DestroyUnit(unit, true));
                    }

                    if (MovesLeft == 0)
                    {
                        PartMoves = 0;
                    }
                    else if (MovesLeft > 0)
                    {
                        if (this is Bomber)
                        {
                            SkipTurn();
                        }
                        else
                        {
                            MovesLeft--;
                        }
                    }
                    Movement = null;
                    if (Map[X, Y][relX, relY].City != null)
                    {
                        if (!Map[X, Y][relX, relY].City.HasBuilding <CityWalls>())
                        {
                            Map[X, Y][relX, relY].City.Size--;
                        }
                    }
                };
            }
            else
            {
                Movement.Done += (s, a) =>
                {
                    if (this is Cannon)
                    {
                        PlaySound("cannon");
                    }
                    else if (this is Musketeers || this is Riflemen || this is Armor || this is Artillery || this is MechInf)
                    {
                        PlaySound("s_land");
                    }
                    else
                    {
                        PlaySound("we_die");
                    }
                    GameTask.Insert(Show.DestroyUnit(this, false));
                    Movement = null;
                };
            }
            GameTask.Insert(Movement);
            return(false);
        }
Пример #13
0
        public virtual bool MoveTo(int relX, int relY)
        {
            if (Movement != null)
            {
                return(false);
            }

            ITile moveTarget = Map[X, Y][relX, relY];

            if (moveTarget == null)
            {
                return(false);
            }
            if (moveTarget.Units.Any(u => u.Owner != Owner))
            {
                if (Class == UnitClass.Land && Tile.IsOcean)
                {
                    GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText($"ERROR/AMPHIB")));
                    return(false);
                }
                return(Confront(relX, relY));
            }
            if (Class == UnitClass.Land && !(this is Diplomat || this is Caravan) && !new ITile[] { Map[X, Y], moveTarget }.Any(t => t.IsOcean || t.City != null) && moveTarget.GetBorderTiles().SelectMany(t => t.Units).Any(u => u.Owner != Owner))
            {
                if (!moveTarget.Units.Any(x => x.Owner == Owner))
                {
                    IUnit[] targetUnits = moveTarget.GetBorderTiles().SelectMany(t => t.Units).Where(u => u.Owner != Owner).ToArray();
                    IUnit[] borderUnits = Map[X, Y].GetBorderTiles().SelectMany(t => t.Units).Where(u => u.Owner != Owner).ToArray();

                    if (borderUnits.Any(u => targetUnits.Any(t => t.X == u.X && t.Y == u.Y)))
                    {
                        if (Human == Owner)
                        {
                            GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText($"ERROR/ZOC")));
                        }
                        return(false);
                    }
                }
            }
            if (moveTarget.City != null && Map[X, Y][relX, relY].City.Owner != Owner)
            {
                return(Confront(relX, relY));
            }

            if (!MoveTargets.Any(t => t.X == moveTarget.X && t.Y == moveTarget.Y))
            {
                // Target tile is invalid
                // TODO: For some tiles, display a message detailing why the move is illegal
                return(false);
            }

            // TODO: This implementation was done by observation, may need a revision
            if (MovesLeft == 0 && !moveTarget.Road && moveTarget.Movement > 1)
            {
                bool success;
                if (PartMoves >= 2)
                {
                    // 2/3 moves left? 50% chance of success
                    success = (Common.Random.Next(0, 2) == 0);
                }
                else
                {
                    // 2/3 moves left? 33% chance of success
                    success = (Common.Random.Next(0, 3) == 0);
                }

                if (!success)
                {
                    PartMoves = 0;
                    return(false);
                }
            }

            Movement       = new MoveUnit(relX, relY);
            Movement.Done += MoveEnd;
            GameTask.Insert(Movement);

            return(true);
        }
Пример #14
0
        protected virtual bool Confront(int relX, int relY)
        {
            if (Class == UnitClass.Land && (this is Diplomat || this is Caravan))
            {
                // TODO: Perform other unit action (confront)
                return(false);
            }

            Movement = new MoveUnit(relX, relY);

            ITile moveTarget = Map[X, Y][relX, relY];

            if (moveTarget == null)
            {
                return(false);
            }
            if (!moveTarget.Units.Any(u => u.Owner != Owner) && moveTarget.City != null)
            {
                if (Class != UnitClass.Land)
                {
                    GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText($"ERROR/OCCUPY")));
                    Movement = null;
                    return(false);
                }

                City capturedCity = moveTarget.City;
                if (!capturedCity.HasBuilding <CityWalls>())
                {
                    capturedCity.Size--;
                }
                Movement.Done += (s, a) =>
                {
                    Show captureCity = Show.CaptureCity(capturedCity);
                    captureCity.Done += (s1, a1) =>
                    {
                        Player previousOwner = Game.GetPlayer(capturedCity.Owner);

                        if (capturedCity.HasBuilding <Palace>())
                        {
                            capturedCity.RemoveBuilding <Palace>();
                        }
                        capturedCity.Food    = 0;
                        capturedCity.Shields = 0;
                        while (capturedCity.Units.Length > 0)
                        {
                            Game.DisbandUnit(capturedCity.Units[0]);
                        }
                        capturedCity.Owner = Owner;

                        if (previousOwner.IsDestroyed)
                        {
                            GameTask.Enqueue(Message.Advisor(Advisor.Defense, false, previousOwner.Civilization.Name, "civilization", "destroyed", $"by {Game.GetPlayer(Owner).Civilization.NamePlural}!"));
                        }

                        if (capturedCity.Size == 0)
                        {
                            return;
                        }
                        GameTask.Insert(Show.CityManager(capturedCity));
                    };
                    GameTask.Insert(captureCity);
                    MoveEnd(s, a);
                };
            }
            else if (AttackOutcome(this, Map[X, Y][relX, relY]))
            {
                Movement.Done += (s, a) =>
                {
                    GameTask.Insert(Show.DestroyUnit(Map[X, Y][relX, relY].Units.First(), true));
                    if (MovesLeft == 0)
                    {
                        PartMoves = 0;
                    }
                    else if (MovesLeft > 0)
                    {
                        if (this is Bomber)
                        {
                            SkipTurn();
                        }
                        else
                        {
                            MovesLeft--;
                        }
                    }
                    Movement = null;
                };
            }
            else
            {
                Movement.Done += (s, a) =>
                {
                    GameTask.Insert(Show.DestroyUnit(this, false));
                    Movement = null;
                };
            }
            GameTask.Insert(Movement);
            return(false);
        }
Пример #15
0
        protected override bool HasUpdate(uint gameTick)
        {
            if (!(_update || _fullRedraw))
            {
                return(false);
            }
            if (Game.MovingUnit == null && (gameTick % 2 == 1))
            {
                return(false);
            }

            Player renderPlayer = Settings.RevealWorld ? null : Human;

            IUnit activeUnit = ActiveUnit;

            if (Game.MovingUnit != null && !_fullRedraw)
            {
                IUnit movingUnit = Game.MovingUnit;
                ITile tile       = movingUnit.Tile;
                int   dx         = GetX(tile);
                int   dy         = GetY(tile);
                if (dx < _tilesX && dy < _tilesY)
                {
                    dx *= 16; dy *= 16;

                    MoveUnit movement = movingUnit.Movement;
                    this.FillRectangle(dx - 16, dy - 16, 48, 48, 5)
                    .AddLayer(Map[movingUnit.X - 1, movingUnit.Y - 1, 3, 3].ToBitmap(player: renderPlayer), dx - 16, dy - 16, dispose: true);
                    Bytemap unitPicture = movingUnit.ToBitmap();
                    this.AddLayer(unitPicture, dx + movement.X, dy + movement.Y);
                    if (movingUnit is IBoardable && tile.Units.Any(u => u.Class == UnitClass.Land && (tile.City == null || (tile.City != null && u.Sentry))))
                    {
                        this.AddLayer(unitPicture, dx + movement.X - 1, dy + movement.Y - 1);
                    }
                    return(true);
                }
            }
            else if (_fullRedraw)
            {
                _fullRedraw = false;
                this.Clear(5)
                .AddLayer(Tiles.ToBitmap(player: renderPlayer), dispose: true);
            }

            if (activeUnit != null && Game.CurrentPlayer == Human && !GameTask.Any())
            {
                ITile tile = activeUnit.Tile;
                int   dx   = GetX(tile);
                int   dy   = GetY(tile);
                if (dx < _tilesX && dy < _tilesY)
                {
                    dx *= 16; dy *= 16;

                    // blink status
                    TileSettings setting = ((gameTick % 4) < 2) ? TileSettings.BlinkOn : TileSettings.BlinkOff;
                    this.AddLayer(tile.ToBitmap(setting), dx, dy, dispose: true);

                    DrawHelperArrows(dx, dy);
                }
                return(true);
            }

            _update = false;
            return(true);
        }
Пример #16
0
        public static ClientBasePacket HandlePacket(byte[] data, int offset, GameSession client)
        {
            // Calculate message size
            var size = (short)((data[offset + 1] << 8) + data[offset]);

            // Copy the packet to a new byte array
            // Skipping the header
            var packet = new byte[size];

            Array.Copy(data, offset, packet, 0, size);

            ClientBasePacket msg;

            // Get the id
            var id = packet[2];

            // Handle the packet
            // TODO: Can we group these into login / game / etc?
            switch (id)
            {
            case 0x00:
                msg = new ProtocolVersion(packet, client);
                break;

            case 0x01:
                msg = new ValidateClient(packet, client);
                break;

            case 0x03:
                msg = new ConnectClient(packet, client);
                break;

            case 0x04:
                msg = new ConnectSwitch(packet, client);
                break;

            case 0x05:
                msg = new SwitchServer(packet, client);
                break;

            case 0x06:
                msg = new ServerTime(packet, client);
                break;

            case 0x07:
                msg = new Message(packet, client);
                break;

            case 0x0d:
                msg = new Log(packet, client);
                break;

            case 0x0c:
                msg = new SyncMoney(packet, client);
                break;

            case 0x11:
                msg = new FactoryModifyUnit(packet, client);
                break;

            case 0x12:
                msg = new FactoryModifyEnd(packet, client);
                break;

            case 0x16:
                msg = new IsValidName(packet, client);
                break;

            case 0x17:
                msg = new FactoryChangeUnitName(packet, client);
                break;

            case 0x18:
                msg = new RequestInventory(packet, client);
                break;

            case 0x19:
                msg = new RequestSearchGame(packet, client);
                break;

            case 0x1b:
                msg = new CreateGame(packet, client);
                break;

            case 0x1c:
                msg = new EnterGame(packet, client);
                break;

            case 0x1f:
                msg = new ListUser(packet, client);
                break;

            case 0x20:
                msg = new Ready(packet, client);
                break;

            case 0x21:
                msg = new Exit(packet, client);
                break;

            case 0x22:
                msg = new StartGame(packet, client);
                break;

            case 0x2b:
                msg = new SelectBase(packet, client);
                break;

            case 0x2c:
                msg = new ReadyGame(packet, client);
                break;

            case 0x2e:
                msg = new RequestPalette(packet, client);
                break;

            case 0x2f:
                msg = new MoveUnit(packet, client);
                break;

            case 0x30:
                msg = new AimUnit(packet, client);
                break;

            case 0x31:
                msg = new StartAttack(packet, client);
                break;

            case 0x32:
                msg = new StopAttack(packet, client);
                break;

            case 0x35:
                msg = new RequestRegain(packet, client);
                break;

            case 0x38:
                msg = new ModeSniper(packet, client);
                break;

            case 0x3a:
                msg = new RequestChangeWeaponset(packet, client);
                break;

            case 0x3b:
                msg = new RequestQuitBattle(packet, client);
                break;

            case 0x3f:
                msg = new BuyList(packet, client);
                break;

            case 0x40:
                msg = new RequestGoodsData(packet, client);
                break;

            case 0x46:
                msg = new RequestAvatarInfo(packet, client);
                break;

            case 0x47:
            case 0x48:
            case 0x49:
            case 0x4a:
            case 0x4b:
            case 0x4c:
            case 0x4d:
                msg = new RequestStatsInfo(packet, client);
                break;

            case 0x4e:
                msg = new RequestBestInfo(packet, client);
                break;

            case 0x57:
                msg = new TutorialSelect(packet, client);
                break;

            case 0x5a:
                msg = new UnAimUnit(packet, client);
                break;

            case 0x63:
                msg = new MsgConnect(packet, client);
                break;

            case 0x64:
                msg = new MsgUserStateInfo(packet, client);
                break;

            case 0x66:
                msg = new MsgUserClanInfo(packet, client);
                break;

            case 0x67:
                msg = new MsgGetBuddyList(packet, client);
                break;

            case 0x69:
                msg = new MsgGetChannelList(packet, client);
                break;

            case 0x6a:
                msg = new MsgJoinChannel(packet, client);
                break;

            case 0x6b:
                msg = new MsgLeaveChannel(packet, client);
                break;

            case 0x6c:
                msg = new MsgChannelChatting(packet, client);
                break;

            case 0x71:
                msg = new RequestOperator(packet, client);
                break;

            case 0x72:
                msg = new SelectOperator(packet, client);
                break;

            default:
                msg = new UnknownPacket(packet, client);
                //Console.WriteLine("Unknown packet id [{0}] from user {1}", id, client.GetUserName());
                break;
            }

            return(msg);
        }
Пример #17
0
 /// <summary>
 /// Expand the current range to that partial units are completely contained.
 /// </summary>
 /// <param name="ExpandTo"></param>
 /// <returns></returns>
 public bool ExpandRange(MoveUnit ExpandTo)
 {
     return(range.Expand(Enum.GetName(typeof(MoveUnit), ExpandTo).ToLower()));
 }
Пример #18
0
        protected virtual bool Confront(int relX, int relY)
        {
            if (Class == UnitClass.Land && (this is Diplomat || this is Caravan))
            {
                // TODO: Perform other unit action (confront)
                return(false);
            }

            Movement = new MoveUnit(relX, relY);

            ITile moveTarget = Map[X, Y][relX, relY];

            if (moveTarget == null)
            {
                return(false);
            }
            if (!moveTarget.Units.Any(u => u.Owner != Owner) && moveTarget.City != null && moveTarget.City.Owner != Owner)
            {
                if (Class != UnitClass.Land)
                {
                    GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText($"ERROR/OCCUPY")));
                    Movement = null;
                    return(false);
                }

                City capturedCity = moveTarget.City;
                Movement.Done += (s, a) =>
                {
                    Action changeOwner = delegate()
                    {
                        Player previousOwner = Game.GetPlayer(capturedCity.Owner);

                        if (capturedCity.HasBuilding <Palace>())
                        {
                            capturedCity.RemoveBuilding <Palace>();
                        }
                        capturedCity.Food    = 0;
                        capturedCity.Shields = 0;
                        while (capturedCity.Units.Length > 0)
                        {
                            Game.DisbandUnit(capturedCity.Units[0]);
                        }
                        capturedCity.Owner = Owner;

                        if (!capturedCity.HasBuilding <CityWalls>())
                        {
                            capturedCity.Size--;
                        }

                        previousOwner.IsDestroyed();
                    };

                    IList <IAdvance> advancesToSteal = GetAdvancesToSteal(capturedCity.Player);

                    if (Human == capturedCity.Owner || Human == Owner)
                    {
                        Show captureCity = Show.CaptureCity(capturedCity);
                        captureCity.Done += (s1, a1) =>
                        {
                            changeOwner();

                            if (capturedCity.Size == 0 || Human != Owner)
                            {
                                return;
                            }
                            GameTask.Insert(Show.CityManager(capturedCity));
                        };
                        GameTask.Insert(captureCity);

                        if (advancesToSteal.Any())
                        {
                            GameTask.Enqueue(Tasks.Show.SelectAdvanceAfterCityCapture(Player, advancesToSteal));
                        }
                    }
                    else
                    {
                        changeOwner();
                        if (advancesToSteal.Any())
                        {
                            Player.AddAdvance(advancesToSteal.First());
                        }
                    }
                    MoveEnd(s, a);
                };
            }
            else if (this is Nuclear)
            {
                int  xx   = (X - Common.GamePlay.X + relX) * 16;
                int  yy   = (Y - Common.GamePlay.Y + relY) * 16;
                Show nuke = Show.Nuke(xx, yy);

                if (Map[X, Y][relX, relY].City != null)
                {
                    PlaySound("airnuke");
                }
                else
                {
                    PlaySound("s_nuke");
                }

                nuke.Done += (s, a) =>
                {
                    foreach (ITile tile in Map.QueryMapPart(X + relX - 1, Y + relY - 1, 3, 3))
                    {
                        while (tile.Units.Length > 0)
                        {
                            Game.DisbandUnit(tile.Units[0]);
                        }
                    }
                };
                GameTask.Enqueue(nuke);
            }
            else if (AttackOutcome(this, Map[X, Y][relX, relY]))
            {
                Movement.Done += (s, a) =>
                {
                    if (this is Cannon)
                    {
                        PlaySound("cannon");
                    }
                    else if (this is Musketeers || this is Riflemen || this is Armor || this is Artillery || this is MechInf)
                    {
                        PlaySound("s_land");
                    }
                    else
                    {
                        PlaySound("they_die");
                    }

                    IUnit unit = Map[X, Y][relX, relY].Units.FirstOrDefault();
                    if (unit != null)
                    {
                        GameTask.Insert(Show.DestroyUnit(unit, true));
                    }

                    if (MovesLeft == 0)
                    {
                        PartMoves = 0;
                    }
                    else if (MovesLeft > 0)
                    {
                        if (this is Bomber)
                        {
                            SkipTurn();
                        }
                        else
                        {
                            MovesLeft--;
                        }
                    }
                    Movement = null;
                    if (Map[X, Y][relX, relY].City != null)
                    {
                        if (!Map[X, Y][relX, relY].City.HasBuilding <CityWalls>())
                        {
                            Map[X, Y][relX, relY].City.Size--;
                        }
                    }
                };
            }
            else
            {
                Movement.Done += (s, a) =>
                {
                    if (this is Cannon)
                    {
                        PlaySound("cannon");
                    }
                    else if (this is Musketeers || this is Riflemen || this is Armor || this is Artillery || this is MechInf)
                    {
                        PlaySound("s_land");
                    }
                    else
                    {
                        PlaySound("we_die");
                    }
                    GameTask.Insert(Show.DestroyUnit(this, false));
                    Movement = null;
                };
            }
            GameTask.Insert(Movement);
            return(false);
        }
Пример #19
0
 internal void KeepMoving(IUnit unit)
 {
     Movement       = new MoveUnit(unit.X - X, unit.Y - Y);
     Movement.Done += MoveEnd;
     GameTask.Enqueue(Movement);
 }
Пример #20
0
 internal void KeepMoving(City city)
 {
     Movement       = new MoveUnit(city.X - X, city.Y - Y);
     Movement.Done += MoveEnd;
     GameTask.Enqueue(Movement);
 }