Exemplo n.º 1
0
        /// <summary>
        /// obtm todas as fleets que se podem mover
        /// </summary>
        /// <returns>ArrayList com as fleets que se podem mover</returns>
        private ArrayList getMoveableFleets()
        {
            IDictionaryEnumerator iter;
            ArrayList             names = new ArrayList();

            foreach (Planet planet in _ruler.Planets)
            {
                iter = planet.Fleets.GetEnumerator();
                while (iter.MoveNext())
                {
                    Chronos.Core.Fleet f = (Chronos.Core.Fleet)iter.Value;
                    if (f.CanBeMoved)
                    {
                        names.Add(f.Name);
                    }
                }
            }

            iter = _ruler.UniverseFleets.GetEnumerator();
            while (iter.MoveNext())
            {
                Chronos.Core.Fleet f = (Chronos.Core.Fleet)iter.Value;
                if (f.CanBeMoved)
                {
                    names.Add(f.Name);
                }
            }

            names.Sort();

            return(names);
        }
Exemplo n.º 2
0
        protected void FleetCreated(object src, EventArgs args)
        {
            Chronos.Core.Fleet fleet = ((FleetEventArgs)args).Fleet;
            Tournament         tour  = new Tournament(TournamentType, fleet);

            Universe.instance.PersistenceServices.Register(TournamentType, tour);
        }
Exemplo n.º 3
0
        private void WriteHeader(HtmlTextWriter writer, Chronos.Core.Fleet fleet)
        {
            writer.WriteLine("<table class='frame' width='400' cellpadding='0' cellspacing='0'><tr>");

            writer.WriteLine(
                @"<td class='smallPadding' width='360'>
					<img src='{0}' onClick="                     + "\"" + "show('fleet_{1}',this);\"" + @"/>
					<b><span class='fleetName'>{2}</b>
				</td>
				"                , OrionGlobals.getCommonImagePath("plus.gif"), fleet.Id, GetFleetName(fleet)
                );

            if (fleet.CanBeRemoved)
            {
                writer.WriteLine(@"
					<td align='left' width='40'>
						{0}					
					</td>
				"                , GetRemoveCode(fleet.Name));
            }
            else
            {
                writer.WriteLine("<td></td>");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// evento para mover a fleet
        /// </summary>
        private void moveFleet_Click(object sender, ImageClickEventArgs e)
        {
            int index = itemsTable.SelectedIndex;

            Chronos.Core.Fleet fleet = _ruler.getFleet(itemsTable.getSpecificText(index, 0));

            if (fleet == null)
            {
                throw new AlnitakException("Fleet é null no evento de Click @ MoveFleet::moveFleet_Click");
            }

            Coordinate coordinate = travel.Coordinate;

            if (fleet.Coordinate.CompareTo(coordinate) == 0)
            {
                _message = info.getContent("fleet_alreadAtCoordinate");
            }
            else
            {
                if (!fleet.startMoving(coordinate))
                {
                    _message = string.Format(info.getContent("fleet_cantMove"), coordinate.ToString());
                }
                else
                {
                    updateTable();
                }
            }
        }
Exemplo n.º 5
0
        private void submit_Click(object sender, ImageClickEventArgs e)
        {
            string fleetName = _itemsTable.getSpecificText(_itemsTable.SelectedIndex, 0);

            Chronos.Core.Fleet fleet = _ruler.getFleet(fleetName);
            if (fleet == null)
            {
                throw new AlnitakException("Fleet é null no evento de Click @ ReadyForBattle::toBattle_Click");
            }

            Chronos.Core.Planet currentPlanet = Universe.instance.getPlanet(fleet.Coordinate);
            if (currentPlanet == null)
            {
                throw new AlnitakException("O planeta é null no evento de Click @ ReadyForBattle::toBattle_Click");
            }

            Ruler enemy = currentPlanet.Owner as Ruler;

            if (enemy == null)
            {
                throw new AlnitakException("O planeta onde a fleet " + fleetName + " está não tem dono");
            }

            if (!currentPlanet.IsInBattle)
            {
                Universe.instance.CreateBattle(_ruler, fleet, enemy, currentPlanet, BattleType.BATTLE, "totalannihilation");
                updateTable();
            }
        }
Exemplo n.º 6
0
        protected void remove(string name)
        {
            Chronos.Core.Fleet srcFleet = ruler.getFleet(name);

            if (srcFleet != null)
            {
                if (srcFleet.Owner != ruler)
                {
                    Planet                p        = (Planet)srcFleet.Owner;
                    Chronos.Core.Fleet    dstFleet = p.getPlanetFleet();
                    IDictionaryEnumerator iter     = srcFleet.Ships.GetEnumerator();
                    while (iter.MoveNext())
                    {
                        dstFleet.swapShips(srcFleet, iter.Key.ToString(), int.Parse(iter.Value.ToString()));
                        iter = srcFleet.Ships.GetEnumerator();
                    }

                    p.removeFleet(srcFleet);
                    Information.AddInformation(info.getContent("fleet_removeOk"));
                }
                else
                {
                    if (!srcFleet.HasShips)
                    {
                        ruler.removeUniverseFleet(srcFleet.Id);
                        Information.AddInformation(info.getContent("fleet_removeOkUniverse"));
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void WriteShips(HtmlTextWriter writer, Chronos.Core.Fleet fleet)
        {
            foreach (DictionaryEntry ship in fleet.Ships)
            {
                string name = string.Empty, quant = string.Empty;
                if (ship.Key != null)
                {
                    name = ship.Key.ToString();
                }
                if (ship.Value != null)
                {
                    quant = ship.Value.ToString();
                }

                writer.WriteLine(
                    @"<tr height='40'>
						<td width='80' align='center' class='borderTop'>
							<img src='{0}.gif' />
						</td>
						<td width='120' align='center' class='borderTop'>
							{1}
						</td>
						<td width='200' align='center' class='borderTop smallPadding'>
							{2}
						</td>
					</tr>"                    ,
                    OrionGlobals.getCommonImagePath(name.ToLower()),
                    quant,
                    info.getContent(name)
                    );
            }
        }
Exemplo n.º 8
0
 private string FleetUniverseName(Chronos.Core.Fleet fleet)
 {
     if (fleet.IsInBattle)
     {
         return(fleet.Name + " - " + info.getContent("fleet_inBattle"));
     }
     return(fleet.Name);
 }
Exemplo n.º 9
0
        private void WriteFleetInformation(HtmlTextWriter writer, Chronos.Core.Fleet fleet)
        {
            string state       = info.getContent("fleet_state");
            string information = string.Empty;

            if (fleet.IsMoving)
            {
                state += info.getContent("fleet_inMovement");
                string arrival = string.Format(info.getContent("fleet_turnsToGo"), fleet.HoursToArrive);
                information = string.Format("<b>{0}:</b> {1}<br/>{2}", info.getContent("fleet_coordinate"), fleet.DestinyCoordinate.ToString(), arrival);
            }
            else
            {
                if (fleet.IsInBattle)
                {
                    state      += info.getContent("fleet_inBattle");
                    information = info.getContent("fleet_battleCoordinate") + fleet.Coordinate.ToString();
                }
                else
                {
                    if (fleet.IsMoveable)
                    {
                        state += info.getContent("fleet_stopped");
                        if (fleet.Owner is Planet)
                        {
                            Planet p    = ((Planet)fleet.Owner);
                            string link = OrionGlobals.getSectionBaseUrl("Fleet") + "?id=" + p.Id;
                            information = string.Format("{0}<a href='{1}'>{2}</a>", info.getContent("fleet_location"), link, p.Name);
                        }
                        else
                        {
                            information = info.getContent("fleet_location") + fleet.Coordinate.ToString();
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }

            writer.WriteLine(@"
				<tr>
					<td class='borderTop' colspan='3' style='padding: 5px 0px 5px 0px;'>
						{0}<br/>
						{1}
					</td>
				</tr>"                , state, information
                             );
        }
Exemplo n.º 10
0
        private string GetFleetName(Chronos.Core.Fleet fleet)
        {
            if (fleet.IsDefenseFleet)
            {
                return(info.getContent("defenseFleet"));
            }

            Planet planet = fleet.Owner as Planet;

            if (planet != null)
            {
                return(FleetPlanetName(planet, fleet.Name));
            }
            else
            {
                return(FleetUniverseName(fleet));
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// obtém as todas as fleets do utilizador
        /// </summary>
        /// <returns></returns>
        override protected ArrayList getAllFleets()
        {
            ArrayList fleetsArray = new ArrayList();

            foreach (Planet planet in ruler.Planets)
            {
                IDictionaryEnumerator iter = planet.Fleets.GetEnumerator();
                while (iter.MoveNext())
                {
                    Chronos.Core.Fleet f = (Chronos.Core.Fleet)iter.Value;
                    if (f.IsMoveable)
                    {
                        fleetsArray.Add(f);
                    }
                }
            }
            return(fleetsArray);
        }
Exemplo n.º 12
0
        private bool CheckShips()
        {
            Chronos.Core.Fleet f1 = new Chronos.Core.Fleet("fleet",null,_ruler);

            string[] types = new string[]{"light","medium","heavy","animal"};
            for( int i = 0; i < tables.Count ; ++i ) {
                if( allUnits.ContainsKey( types[i] )) {
                    ItemsTable table = (ItemsTable)tables[i];
                    if( !FillFleet( table, f1, types[i] ) ) {
                        return false;
                    }
                }
            }
            if( f1.HasShips ) {
                notify(FleetCreated,new FleetEventArgs(f1) );
                return true;
            }
            return false;
        }
Exemplo n.º 13
0
        private void conquerPlanet_Click(object sender, ImageClickEventArgs e)
        {
            if (_ruler.Planets.Length >= _ruler.MaxPlanets)
            {
                Information.AddError(info.getContent("conquerplanet_maxPlanetsError"));
                return;
            }

            int    index         = _itemsTable.SelectedIndex;
            string fleetName     = _itemsTable.getSpecificText(index, 0);
            string planetNewName = GetPlanetNewName(index);

            Chronos.Core.Fleet fleet = _ruler.getFleet(fleetName);
            if (fleet == null)
            {
                throw new Exception("There is no fleet!");
            }

            Coordinate c = Coordinate.translateCoordinate(_itemsTable.getSpecificText(index, 1));

            //Planet p = Universe.instance.getPlanet( c );

            if (!fleet.isQuantityAvailable("ColonyShip", 1))
            {
                Information.AddError(info.getContent("conquerplanet_thereisnoColonyShip"));
                return;
            }

            if (Regex.IsMatch(planetNewName, @"(\w|( )|[.!?])+") && !_ruler.hasFleet(planetNewName))
            {
                Universe.instance.conquerPlanet(c, planetNewName, fleet);
                updateTable();
                buttonClicked = true;
            }
            else
            {
                Information.AddError(info.getContent("conquerplanet_invalidName"));
            }
        }
Exemplo n.º 14
0
        private bool CheckShips()
        {
            Chronos.Core.Fleet f1 = new Chronos.Core.Fleet("fleet", null, _ruler);

            string[] types = new string[] { "light", "medium", "heavy", "animal" };
            for (int i = 0; i < tables.Count; ++i)
            {
                if (allUnits.ContainsKey(types[i]))
                {
                    ItemsTable table = (ItemsTable)tables[i];
                    if (!FillFleet(table, f1, types[i]))
                    {
                        return(false);
                    }
                }
            }
            if (f1.HasShips)
            {
                notify(FleetCreated, new FleetEventArgs(f1));
                return(true);
            }
            return(false);
        }
Exemplo n.º 15
0
        private bool FillFleet(ItemsTable table, Chronos.Core.Fleet f1, string type)
        {
            ArrayList unitNames = (ArrayList)allUnits[type];

            for (int i = 0; i < unitNames.Count; ++i)
            {
                string textBoxText = table.getSpecificText(i, 2);
                if (string.Empty == textBoxText)
                {
                    continue;
                }

                string unit = unitNames[i].ToString( );

                try {
                    if (OrionGlobals.isInt(textBoxText.ToString()))
                    {
                        //Resource r = GetUnitResource(unit,"Unit");
                        int quant = int.Parse(textBoxText.ToString());
                        if (0 == quant)
                        {
                            continue;
                        }
                        f1.addShip(unit, quant);
                    }
                    else
                    {
                        Information.AddError(info.getContent("battle_noInt"));
                        return(false);
                    }
                }catch (OverflowException) {
                    Information.AddError(string.Format(info.getContent("battle_IntToBig"), unit));
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 16
0
        protected void createBattle_Click(object sender, EventArgs e)
        {
            if (rulers.SelectedIndex == -1)
            {
                Information.AddError(info.getContent("battle_noRulerSelected"));
                return;
            }
            Ruler enemy = Universe.instance.getRuler(int.Parse(rulers.SelectedValue));

            if (!CanCreateBattle(enemy))
            {
                Information.AddError(info.getContent("battle_enemycanthave"));
                return;
            }

            Chronos.Core.Fleet f1 = ((FleetEventArgs )e).Fleet;
            Chronos.Core.Fleet f2 = f1.Clone() as Chronos.Core.Fleet;
            f2.Owner = enemy;

            int count = int.Parse(OrionGlobals.getConfigurationValue("alnitak", "shipsCount"));

            if (f1.Ships.Count > count)
            {
                Information.AddError(string.Format(info.getContent("battle_toMuchUnits"), count));
                return;
            }
            if (f1.HasShips)
            {
                Universe.instance.CreateBattle(_ruler, f1, enemy, f2, BattleType.FRIENDLY, battleTypes.SelectedValue);
                Information.AddInformation(info.getContent("battle_friendlyCreated"));
            }
            else
            {
                Information.AddError(info.getContent("battle_noUnitSelected"));
            }
        }
Exemplo n.º 17
0
        private void WriteHiddenContent(HtmlTextWriter writer, Chronos.Core.Fleet fleet)
        {
            writer.WriteLine("<tr><td colspan='2' ><table border='0' id='fleet_{0}' cellpadding='0' cellspacing='0' style='display:none;'>", fleet.Id);

            WriteFleetInformation(writer, fleet);

            writer.WriteLine(
                @"<tr>
					<td align='center' class='borderTop'>
						&nbsp;
					</td>
					<td align='center' class='borderTop'>
						{0}
					</td>
					<td align='center' class='borderTop'>
						{1}
					</td>
				</tr>"                , info.getContent("fleet_quant"), info.getContent("fleet_type")
                );

            WriteShips(writer, fleet);

            writer.WriteLine("</table></td></tr>");
        }
Exemplo n.º 18
0
 private Tournament GenerateSampleTournament()
 {
     Chronos.Core.Fleet fleet = new Chronos.Core.Fleet("TournamentFleet", Coordinate.First, null, false);
     fleet.addShip("Rain", 100 );
     return new Tournament(TournamentType, fleet);
 }
Exemplo n.º 19
0
        private void CreateFleets()
        {
            Hashtable universeFleets = _ruler.UniverseFleets;

            _itemsTable.Title         = info.getContent("battle_fleetsReadyToBattle");
            _itemsTable.TitleCssClass = "planetInfoZoneTitle";
            _itemsTable.TableCssClass = "planetFrame";

            createTitle(_itemsTable);
            bool isOneReady = false;

            if (universeFleets != null && universeFleets.Count > 0)
            {
                IDictionaryEnumerator iter = universeFleets.GetEnumerator();

                while (iter.MoveNext())
                {
                    Chronos.Core.Fleet f = (Chronos.Core.Fleet)iter.Value;
                    Planet             p = Universe.instance.getPlanet(f.Coordinate);

                    if (f.GoodForBattle)
                    {
                        ItemsTableLine line = new ItemsTableLine();

                        ItemsTableText fleet = new ItemsTableText(f.Name, "resource");
                        ItemsTableText coord = new ItemsTableText(f.Coordinate.ToString(), "resource");

                        ItemsTableText rulerName;
                        if (p.Owner != null)
                        {
                            rulerName = new ItemsTableText(OrionGlobals.getLink((Ruler)p.Owner), "resource");
                        }
                        else
                        {
                            rulerName = new ItemsTableText(info.getContent("conquerplanet_none"), "resource");
                        }

                        ItemsTableItem action;

                        if (p.IsInBattle)
                        {
                            action = new ItemsTableText(info.getContent("battle_isInBattle"), "resource");
                        }
                        else
                        {
                            if (p.HasImmunity)
                            {
                                action = new ItemsTableText(string.Format(info.getContent("BattleImmunity"), p.Immunity), "resource");
                            }
                            else
                            {
                                if (p.Owner != null && Ruler.IsSameAlliance((Ruler)p.Owner, (Ruler)f.Owner))
                                {
                                    action = new ItemsTableText(info.getContent("battle_sameAlliance"), "resource");
                                }
                                else
                                {
                                    if (!p.HasProtection)
                                    {
                                        action = new ItemsTableText(info.getContent("planet_not_protected"), "resource");
                                    }
                                    else
                                    {
                                        action = new ItemsTableImageButton(OrionGlobals.getCommonImagePath("ok.gif"), fleet.ID);
                                        ((ItemsTableImageButton)action).Click += new ImageClickEventHandler(submit_Click);
                                    }
                                }
                            }
                        }

                        line.add(fleet);
                        line.add(coord);
                        line.add(rulerName);
                        line.add(action);

                        _itemsTable.addLine(line);

                        isOneReady = true;
                    }
                }
            }

            if (!isOneReady)
            {
                insertNoFleets();
            }
        }
Exemplo n.º 20
0
 private Tournament GenerateSampleTournament()
 {
     Chronos.Core.Fleet fleet = new Chronos.Core.Fleet("TournamentFleet", Coordinate.First, null, false);
     fleet.addShip("Rain", 100);
     return(new Tournament(TournamentType, fleet));
 }