Changeset 3545

Show
Ignore:
Timestamp:
02/14/10 19:05:17 (6 months ago)
Author:
Dexter
Message:

#483
update

Location:
trunk/twcore/src/twcore/bots/multibot/twar
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/twcore/src/twcore/bots/multibot/twar/twar.java

    r3538 r3545  
    44 * Author: Dexter 
    55 * Thanks to turban who gave the idea of ships promotion to turretwars event*/ 
     6import java.util.ArrayList; 
     7import java.util.Collections; 
     8 
    69import java.util.StringTokenizer; 
    710import java.util.TimerTask; 
     
    1619 
    1720/*--------------- Bot to any TURRETWARs event ------ 
    18         . it has !start command which uses *scorereset, *shipreset, !random2 and *lock 's commands before start. 
    19         . each ER+ has to *arena GO GO GO after the timertask(10 seconds) 
    20         . command to set terr is !terr name is before the !start command 
    21         . command to switch terr is !terr name1 newTerr is after !start command 
     21        . it has !start command which uses *scorereset, *shipreset and *lock 's commands before start. 
     22        . each ER+ has to MANUALLY *arena GO GO GO after the timertask(10 seconds) 
     23        . command to set everyone as a ship is !ship (old !setship) 
     24        . command to set terr is !terr name 
     25        . command to switch terr is !switch name:newTerr 
    2226        . command to warpback is !warp, so anyone who detaches terr will get warped and energy depleted. 
    23         . command to ships promotion is !prom, the line is: spider->lancaster->javelin->warbird (30 kills lanc, 45 kills jav and 60 kills warbird) 
    24         . command to stop game is !stop, so after game ends, it stops the game with 'turretWar = false;' 
     27        . command to ships promotion is !prom ship:kills 
     28        . command to stop game is !stop, so after game ends, it stops the game with 'turretWar = false;' and others booleans too. 
    2529        . command to ER+ guide to use this Bot to host is !guide 
    2630        . commands of others utilities/bots are OTHERS: !setupwarplist and !setupwarp to set safes warping before game starts and !setship #ship  
    27         if not using !prom, because you'll set #ship by your own. 
     31        if not using !prom, because you'll set #ship by your own with the old !setship command 
     32         
     33        . any player can type !lprom to bot so he'll get back the ship promotions list 
    2834        --------------- Turret War ---------------------- 
    2935*/ 
    3036public class twar extends MultiModule 
    3137{ 
     38         
    3239        private boolean promotion = false; 
    3340        private boolean turretWar = false; 
    3441        private boolean warpOn = false; 
     42        private boolean freq1Terr = false; 
     43        private boolean freq0Terr = false; 
     44         
     45        private int firstShip = 0; 
     46         
     47        private ArrayList<shipSettings> listShipSettings = new ArrayList() ; 
    3548         
    3649        //guide to ER+s 
    3750        private String guideER[] =  
    3851        { 
    39                         "This is a guide to any turretwar hosting", 
    40                         "1.!start command WILL: *SCORERESET, *SHIPRESET, *LOCK and !random 2(CREATES 2 TEAMS)", 
    41                         "2.You can host it with SHIP promotions or Not - use '!prom' to enable it", 
    42                         "3.Use !setship #ship if you're not using promotion, it will set EVERYONE into a ship.", 
    43                         "4.You should set two terrs BEFORE game starts - use '!terr <name>' to pick each terr", 
    44                         "5.You can switch terrs while the game is RUNNING - use '!terr <player1> <newTERR> <#ShipPlayer1>' to switch", 
    45                         "6.If you're using promotion, then just !terr <player1> <newTERR> to switch", 
    46                         "7.You can set warp on, so when someone DETACHES a terr, he gets warped - use !warp to enable warpback", 
    47                         "8.Use !setupwarplist and check what command warps freqs into safes.", 
    48                         "9.Use !stop to stop the game - it will UNLOCK arena and stop the game." 
     52                        "1.  Use !terr name to pick terr", 
     53                        "2.  Use !switch name:newTerr to switch terrs", 
     54                        "3.  Use !prom ship:kills to set a promotion", 
     55                        "4.  Use !ship number to set everyone in this ship", 
     56                        "5.  Use !start to: scorereset, shipreset and lock", 
     57                        "6.  Use !warp to make detachers get warped to spawn area - old !warpon command ", 
     58                        "7.  do manually the *arena GO GO GO and *timer <numberMinutes>", 
     59                        "8.  Use !setship #ship to set the starter ship (using promotions or not)", 
     60                        "9.  Use !setupwarplist to check the warp command", 
     61                        "10.  When you use !terr name at first time, it'll automatically !random 2, so don't worry about the old !random 2", 
     62                        "11. !prom ship:kills is AUTO-SORTED by KILLS in the LIST !lprom" 
    4963        }; 
    5064        public void handleEvent(TurretEvent event) 
     
    6377                        { 
    6478                        Player killer = m_botAction.getPlayer(event.getKillerID()); 
    65                         handlePromotion(killer.getPlayerName(), (int) killer.getWins()); 
     79                        handleCustomPromotion(killer.getPlayerName(), (int) killer.getWins()); 
    6680                        } 
    6781        } 
     
    7690                        if(opList.isER(name)) 
    7791                                handleCommand(name, message); 
    78                  
     92                        else 
     93                        { 
     94                                if(event.getMessage().toLowerCase().startsWith("!help")) 
     95                                { 
     96                                        if(promotion) 
     97                                                m_botAction.sendPrivateMessage(name,"!lprom           - to check ship promotions"); 
     98                                } 
     99                                else if(event.getMessage().toLowerCase().startsWith("!lprom")) 
     100                                        listPromotion(name, message); 
     101                        } 
    79102                } 
    80103        } 
     
    86109                        if(message.toLowerCase().startsWith("!start")) startTurretWar(name, message); 
    87110                        else if(message.toLowerCase().startsWith("!terr")) setTerr(name, message); 
    88                         else if(message.toLowerCase().startsWith("!prom")) promShip(name, message); 
     111                        else if(message.toLowerCase().startsWith("!ship")) setFirstShip(name, message); 
     112                        else if(message.toLowerCase().startsWith("!prom")) setPromotion(name, message); 
     113                        else if(message.toLowerCase().startsWith("!lprom")) listPromotion(name, message); 
    89114                        else if(message.toLowerCase().startsWith("!stop")) stopTurretWar(name, message); 
    90115                        else if(message.toLowerCase().startsWith("!warp")) warpDetachedPlayer(name, message); 
    91116                        else if(message.toLowerCase().startsWith("!guide")) showGuide(name, message); 
     117                        else if(message.toLowerCase().startsWith("!switch")) switchTerr(name, message); 
    92118                }catch(Exception e){} 
    93119        } 
    94         public void handlePromotion(String name, Integer kills) 
    95         { 
    96                 if(kills == 30) 
     120         
     121        public void handleCustomPromotion(String name, Integer kills) 
     122        { 
     123                for(int i = 0; i < listShipSettings.size() ; i++ )//loop to check promotions in the sorted list by kills 
     124                { 
     125                        shipSettings e = listShipSettings.get(i); 
     126                         
     127                        if(i == listShipSettings.size() - 1) 
    97128                        { 
    98                         m_botAction.setShip(name, 7); 
    99                         m_botAction.sendArenaMessage(name+" got promoted to lancaster, get 45 kills to next promotion!", 2); 
     129                                if(kills >= e.getKill()) //this is to the last ship promotion(the last limit of kills) 
     130                                        if(!m_botAction.getPlayer(name).isShip(e.getShip())) 
     131                                        { 
     132                                                m_botAction.setShip(name, e.getShip()); 
     133                                                m_botAction.sendArenaMessage(name+" is owning! He just got promoted to "+e.getShipName()+"!", 7); 
     134                                        } 
    100135                        } 
    101                 else if(kills == 45) 
    102                 { 
    103                          m_botAction.setShip(name, 2); 
    104                          m_botAction.sendArenaMessage(name+" got promoted to javelin, get 60 kills to next promotion!", 2); 
    105                 } 
    106                 else if(kills == 60)  
    107                 { 
    108                         m_botAction.setShip(name, 1); 
    109                         m_botAction.sendArenaMessage(name+" is owning! He just got promoted to warbird!", 2); 
    110                 } 
    111         } 
     136                         
     137                 else if(kills >= e.getKill() && kills < listShipSettings.get(i+1).getKill())//to any other promotion(needs 2 limits of kills) 
     138                                if(!m_botAction.getPlayer(name).isShip(e.getShip())) 
     139                                { 
     140                                        m_botAction.setShip(name, e.getShip()); 
     141                                        m_botAction.sendArenaMessage(name+" got promoted to "+e.getShipName()+"!", 21); 
     142                                } 
     143                } 
     144        } 
     145         
     146        public void setFirstShip(String name, String message) 
     147        { 
     148                if(!freq1Terr && !freq0Terr) 
     149                {//!ship 3 
     150                        this.firstShip = Integer.parseInt( message.substring(6) ); 
     151                        m_botAction.changeAllShips(firstShip); 
     152                } 
     153                else m_botAction.sendPrivateMessage(name, "Use !setship before the command !terr please. Now !stop and start all again."); 
     154        } 
     155         
    112156        public void startTurretWar(String name, String message) 
    113157        { 
    114                 m_botAction.sendArenaMessage("Locking in 10 seconds, get ready!", 2); 
     158                m_botAction.sendArenaMessage("Locking in 10 seconds, get ready!", 13); 
    115159                m_botAction.sendPrivateMessage(name, "locking arena in 10 seconds and it'll start."); 
    116160                m_botAction.sendPrivateMessage(name,"Please *arena GO after it"); 
     
    120164                        public void run(){ 
    121165                                        m_botAction.toggleLocked(); 
    122                                         m_botAction.createNumberOfTeams(2); 
    123166                                        m_botAction.scoreResetAll(); 
    124167                                        m_botAction.shipResetAll(); 
     
    128171        } 
    129172         
     173        public int getFreq( String player ) 
     174        { 
     175                return m_botAction.getPlayer(player).getFrequency(); 
     176        } 
     177         
    130178        public void setTerr(String name, String message) 
    131         { 
    132                 String terr1Name = null; 
    133                 String terr2Name = null; 
    134                 String ship = null; 
    135                 StringTokenizer terrNames = new StringTokenizer(message); 
    136                  
    137                 int shipn; 
    138                 boolean ok = false; //the ok to switch terrs 
    139                  
    140                 terrNames.nextToken(); //command !terr is first token 
    141                  
    142                 terr1Name = terrNames.nextToken(); //then it'll have the first name 
    143                  
    144                 if(terrNames.hasMoreTokens())//if there is another token, it should be the second name(then it is to SWITCH) 
    145                 { 
    146                         if(turretWar)//will switch just if game is ON 
    147                         { //switch... 
    148                                 terr2Name = terrNames.nextToken(); //second name 
    149                                 if(promotion)//If promotion is on, then the old terr will be SPIDER 
    150                                         { 
    151                                         m_botAction.setShip(terr1Name, 3); 
    152                                         ok = true; //ok switch 
    153                                         } 
    154                                          
    155                                 else //else, the host will need to choose a #ship to old terr 
     179        { //setting terrs 
     180                StringTokenizer st = new StringTokenizer(message); 
     181                String terrName; 
     182                st.nextToken(); 
     183                terrName = st.nextToken(); 
     184                 
     185                if(!freq1Terr && !freq0Terr) 
     186                        m_botAction.createNumberOfTeams(2); 
     187                 
     188                if(getFreq(terrName) == 1) 
     189                        if(!freq1Terr) 
    156190                                { 
    157                                         if(terrNames.hasMoreTokens()) //#ship 
    158                                         { 
    159                                                 ship = terrNames.nextToken(); 
    160                                                 shipn = Integer.parseInt(ship); //getting #ship 
    161                                                 m_botAction.setShip(terr1Name, shipn); //putting player to ship the host wanted 
    162                                                 ok = true; //ok switch 
    163                                         } 
    164                                         else //otherwise, he havent typed a #ship and its promotion is off. then he has to type a #ship 
    165                                                 m_botAction.sendPrivateMessage(name, "Type a ship number to "+terr1Name+" be!" ); 
    166                                 } 
    167                                  
    168                                 if(ok)//if switch ok, we'll arena it 
     191                                        m_botAction.setShip(terrName, 5); 
     192                                        m_botAction.sendArenaMessage(terrName+" is your the terr!",1); 
     193                                        freq1Terr = true; 
     194                                }else m_botAction.sendPrivateMessage(name, "Freq 1 has a terr already, try to use !switch please"); 
     195                 
     196                else if(getFreq(terrName) == 0) 
     197                        if(!freq0Terr) 
     198                        { 
     199                                m_botAction.setShip(terrName, 5); 
     200                                m_botAction.sendArenaMessage(terrName+ " is your the terr!", 1); 
     201                                freq0Terr = true; 
     202                        }else m_botAction.sendPrivateMessage(name, "Freq 0 has a terr already, try to use !switch please."); 
     203        } 
     204         
     205        public void switchTerr( String name, String message ) 
     206        { //switching terrs 
     207                if(turretWar){   
     208                        String oldTerr; 
     209                        String newTerr; 
     210                        String [] terr; 
     211                        terr = message.split(":", 2); 
     212                        oldTerr = terr[0].substring(8).toLowerCase(); 
     213                        newTerr = terr[1].toLowerCase(); 
     214                         
     215                        if(getFreq(oldTerr) == getFreq(newTerr)) 
    169216                                { 
    170                                 m_botAction.sendArenaMessage( terr1Name+", get back!"); 
    171                                 m_botAction.sendArenaMessage(terr2Name + " is your new terr!", 24); 
    172                                 m_botAction.setShip(terr2Name, 5); 
    173                                 } 
    174                                  
    175                         //resetting scores       
    176                         m_botAction.scoreReset(terr1Name); //score reseting old terr 
    177                         m_botAction.scoreReset(terr2Name); //score reseting new terr 
    178                  
    179                 }else m_botAction.sendPrivateMessage(name, "Just possible to switch while game is RUNNING!"); //if game isnt running, can't switch. 
    180                          
    181         }else //if it doesnt have any more turret, it is the pick before start !terr playername 
    182                 { 
    183                         if(!turretWar)//and it will just pick a terr before game starts 
    184                         { 
    185                         m_botAction.sendArenaMessage(terr1Name + " is your terr!", 5); 
    186                         m_botAction.setShip(terr1Name, 5); 
    187                         } 
    188                         else //can't use the command !terr player after game started. it should be the switch command !terr name1 newTerr 
    189                                 m_botAction.sendPrivateMessage(name, "type the complete command to switch. !terr player1 newterr #shipPlayer1"); 
    190                 } 
    191         } 
     217                                        m_botAction.setShip(newTerr, 5); 
     218                                        m_botAction.scoreReset(newTerr); 
     219                                        m_botAction.sendArenaMessage(newTerr+ " is the new terr to the freq "+getFreq(newTerr)+"!", 21); 
     220                                        m_botAction.setShip(oldTerr, firstShip); //set back to the first ship of !setship command 
     221                                        m_botAction.scoreReset(oldTerr); 
     222                                }else m_botAction.sendPrivateMessage(name, "Choose a new terr from the same frequence please."); 
     223                        }else m_botAction.sendPrivateMessage(name, "Game hasn't started. Start it first please."); 
     224                } 
    192225         
    193226        //setter of !warp 
     
    198231                        warpOn = true; 
    199232                        m_botAction.sendPrivateMessage(name, "Allright! any players dettaching will be warped!"); 
    200                 } 
    201         } 
    202          
    203         //setter of !prom 
    204         public void promShip(String name, String message) 
    205         { 
    206                 if(promotion && turretWar) //can cancel promotion while game running 
    207                         promotion = false; 
    208                 else if(!promotion && !turretWar) 
    209                 { //setting promotion on before game starts 
     233         
     234                } 
     235        } 
     236         
     237        public void setPromotion( String name, String message ) 
     238        { 
     239                if(!promotion) 
     240                { 
    210241                        promotion = true; 
    211                         m_botAction.sendArenaMessage("Promotion is on! First you'll be spiders. Get 30 kills to be promoted to lancaster!", 21 ); 
    212                         m_botAction.changeAllShips(3); 
    213                 } 
    214                 else if(!promotion && turretWar) //if game has started, can't start promotion after it. 
    215                         m_botAction.sendPrivateMessage(name, "Can't start promotion while game is running. Do it before game starts please."); 
    216         } 
     242                        m_botAction.sendArenaMessage("Yes! Ship Promotions ON!", 24); 
     243                } 
     244                 
     245                String messageSplit [] = message.split(":"); 
     246                 
     247                shipSettings object = new shipSettings(); 
     248                 
     249                object.setShip( Integer.parseInt(messageSplit[0].substring(6)) ); 
     250                object.setKill( Integer.parseInt(messageSplit[1]) ); 
     251                 
     252                listShipSettings.add(object); 
     253                Collections.sort(listShipSettings); 
     254                 
     255        }        
    217256        public void cancel() {} 
    218257 
     258        public void listPromotion(String name, String message) 
     259        { 
     260                m_botAction.sendPrivateMessage(name,"------------------------------------------"); 
     261                for(shipSettings e:listShipSettings) 
     262                        m_botAction.sendPrivateMessage(name, "| be a "+e.getShipName()+ " with "+e.getKill()+" kills"); 
     263                 
     264                m_botAction.sendPrivateMessage(name,"------------------------------------------");       
     265        } 
    219266        public String[] getModHelpMessage()  
    220267        { 
    221268                String erHelp [] = { 
    222                         "|      !guide                                                                                                                                                                   - A GUIDE TO HOST TURRETWAR", 
    223                         "|      !terr NAME                                                                                                                                                      - To pick a terr", 
    224                         "|      !terr name1 Terr                                                                                        - To switch terrs if promotion on", 
    225                         "|      !terr name1 Terr #ship1                                 - To switch terrs promotion if off", 
    226                         "|      !prom                                                                                                                                                                                           - to enable promotion",  
    227                         "|      !start                                                                                                                                                                                  - to start game (random 2, *scorereset, *shipreset and *lock commands)", 
    228                         "|      !warp                                                                                                                                                                                           - to enable warpback", 
     269                        "|      !guide                                                                                                                                                                                                                                                                                                                                                                                                                  - A GUIDE TO HOST TURRETWAR", 
     270                        "| !ship number                                                                                                                                                                                                                                                                                                                                                                                 - to set everyone in this ship",                                                                                                                                                                 
     271                        "|      !terr name                                                                                                                                                                                                                                                                                                                                                                                                      - to pick a terr", 
     272                        "|      !switch name:terr                                                                                                                                                                                                                                                                                                                                               - to switch terrs", 
     273                        "|      !prom   ship:kill                                                                                                                                                                                                                                                                                                                                                               - to enable promotion",  
     274                        "| !lprom                                                                                                                                                                                                                                                                                                                                                                                                                                       - to check the list of promotions", 
     275                        "|      !start                                                                                                                                                                                                                                                                                                                                                                                                                                  - to start game (*scorereset, *shipreset and *lock)", 
     276                        "|      !warp                                                                                                                                                                                                                                                                                                                                                                                                                                           - to enable warpback", 
    229277                        "|       OTHERS:", 
    230                         "|| !setship #ship                                                                                                              - to set everyone in a ship", 
    231                         "|| !setupwarplist                                                                                                              - to see warp safes list", 
     278                        "|| !setship #ship                                                                                                                                                                                                                                                                                                                                                              - to set everyone in a ship", 
     279                        "|| !setupwarplist                                                                                                                                                                                                                                                                                                                                                              - to see warp safes list", 
    232280                         
    233281                }; 
     
    254302                m_botAction.sendPrivateMessage(name, " "); 
    255303                m_botAction.sendPrivateMessage(name, guideER[8]); 
    256                 m_botAction.sendPrivateMessage(name, ""); 
     304                m_botAction.sendPrivateMessage(name, " "); 
    257305                m_botAction.sendPrivateMessage(name, guideER[9]); 
     306                m_botAction.sendPrivateMessage(name, " "); 
     307                m_botAction.sendPrivateMessage(name, guideER[10]); 
     308         
    258309        } 
    259310        //stopping game. 
    260311        public void stopTurretWar(String name, String message){ 
    261312                turretWar = false; 
     313                promotion = false; 
     314                warpOn = false; 
     315                freq1Terr = false; 
     316                freq0Terr = false; 
     317                listShipSettings.clear(); 
    262318                m_botAction.cancelTasks(); 
    263319                m_botAction.toggleLocked(); 
     
    273329        public void requestEvents(ModuleEventRequester eventRequester) { 
    274330                eventRequester.request(this, EventRequester.PLAYER_DEATH); 
    275           eventRequester.request(this, EventRequester.MESSAGE); 
    276331        } 
    277332