Ticket #3477: ticket3477_metacheat_2.diff

File ticket3477_metacheat_2.diff, 7.2 KB (added by bb, 9 years ago)

Improved style of "Cheat.js"

  • binaries/data/mods/public/simulation/data/cheats/metaCheat.json

     
     1{
     2    "Name": "gift from the gods",
     3    "Data": {
     4        "Action": "metacheat",
     5        "DefaultParameter": 100000,
     6        "IsNumeric": true
     7    }
     8}
  • binaries/data/mods/public/simulation/helpers/Cheat.js

     
    1313    var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
    1414    if (!cmpPlayer.GetCheatsEnabled())
    1515    {
    16         cmpGuiInterface.PushNotification({"type": "chat", "players": [input.player], "message": "Cheats are disbaled in this match"});
     16        cmpGuiInterface.PushNotification({ "type": "chat", "players": [input.player], "message": "Cheats are disbaled in this match" });
    1717        return;
    1818    }
    1919
     
    2222    case "addresource":
    2323        // force input.text to be an array
    2424        input.text = [].concat(input.text);
    25         for each (var type in input.text)
     25        for each (let type in input.text)
    2626            cmpPlayer.AddResource(type, input.parameter);
    27         break;
     27        return;
    2828    case "revealmap":
    2929        var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    3030        cmpRangeManager.SetLosRevealAll(-1, true);
    31         break;
     31        return;
    3232    case "maxpopulation":
    3333        cmpPlayer.SetPopulationBonuses(500);
    34         break;
     34        return;
    3535    case "changemaxpopulation":
    3636        cmpPlayer.SetMaxPopulation(500);
    37         break;
     37        return;
    3838    case "convertunit":
    3939        for (let ent of input.selected)
    4040        {
     
    4242            if (cmpOwnership)
    4343                cmpOwnership.SetOwner(cmpPlayer.GetPlayerID());
    4444        }
    45         break;
     45        return;
    4646    case "killunits":
    4747        for (let ent of input.selected)
    4848        {
     
    5252            else
    5353                Engine.DestroyEntity(ent);
    5454        }
    55         break;
     55        return;
    5656    case "defeatplayer":
    5757        var playerEnt = cmpPlayerManager.GetPlayerByID(input.parameter);
    5858        if (playerEnt == INVALID_ENTITY)
    5959            return;
    60         Engine.PostMessage(playerEnt, MT_PlayerDefeated, { "playerId": input.parameter } );
    61         break;
     60        Engine.PostMessage(playerEnt, MT_PlayerDefeated, { "playerId": input.parameter });
     61        return;
    6262    case "createunits":
    6363        if (!input.selected[0])
    6464        {
    65             cmpGuiInterface.PushNotification({"type": "notification", "players": [input.player], "message": "You need to select a building that trains units."});
     65            cmpGuiInterface.PushNotification({ "type": "notification", "players": [input.player], "message": "You need to select a building that trains units." });
    6666            return;
    6767        }
    6868
     
    6969        var cmpProductionQueue = Engine.QueryInterface(input.selected[0], IID_ProductionQueue);
    7070        if (!cmpProductionQueue)
    7171        {
    72             cmpGuiInterface.PushNotification({"type": "notification", "players": [input.player], "message": "You need to select a building that trains units."});
     72            cmpGuiInterface.PushNotification({ "type": "notification", "players": [input.player], "message": "You need to select a building that trains units." });
    7373            return;
    7474        }
    7575        for (let i = 0; i < input.parameter; ++i)
    7676            cmpProductionQueue.SpawnUnits(input.templates[i % input.templates.length], 1, null);
    77         break;
     77        return;
    7878    case "fastactions":
    7979        cmpPlayer.SetCheatTimeMultiplier((cmpPlayer.GetCheatTimeMultiplier() == 1) ? 0.01 : 1);
    80         break;
     80        return;
    8181    case "changespeed":
    8282        cmpPlayer.SetCheatTimeMultiplier(input.parameter);
    83         break;
     83        return;
    8484    case "changephase":
    8585        var cmpTechnologyManager = Engine.QueryInterface(playerEnt, IID_TechnologyManager);
    8686        if (!cmpTechnologyManager)
     
    102102
    103103        // rewrite input and call function
    104104        input.action = "researchTechnology";
    105         Cheat(input);
    106         break;
     105        Cheat({ "player": input.player, "action": "researchTechnology", "parameter": input.parameter, "selected": input.selected });
     106        return;
    107107    case "researchTechnology":
    108108        // check, if name of technology is given
    109109        if (input.parameter.length == 0)
    110110        {
    111             cmpGuiInterface.PushNotification({"type": "notification", "players": [input.player], "message": "You have to enter the name of a technology or select a building and enter the number of the technology (brainiac number [top|paired].)"});
     111            cmpGuiInterface.PushNotification({ "type": "notification", "players": [input.player], "message": "You have to enter the name of a technology or select a building and enter the number of the technology (brainiac number [top|paired].)" });
    112112            return;
    113113        }
    114114        var techname = input.parameter;
     
    137137                        var tech = techs[number-1];
    138138                        if (!tech)
    139139                        {
    140                             cmpGuiInterface.PushNotification({"type": "notification", "players": [input.player], "message": "You have already researched this technology."});
     140                            cmpGuiInterface.PushNotification({ "type": "notification", "players": [input.player], "message": "You have already researched this technology." });
    141141                            return;
    142142                        }
    143143                        // get name of tech
     
    148148                    }
    149149                    else
    150150                    {
    151                         cmpGuiInterface.PushNotification({"type": "notification", "players": [input.player], "message": "This building only has " + techs.length + " technologies."});
     151                        cmpGuiInterface.PushNotification({ "type": "notification", "players": [input.player], "message": "This building only has " + techs.length + " technologies." });
    152152                        return;
    153153                    }
    154154                }
     
    159159        var template = cmpTechnologyManager.GetTechnologyTemplate(techname);
    160160        if (!template)
    161161        {
    162             cmpGuiInterface.PushNotification({"type": "notification", "players": [input.player], "message": "Technology \"" + techname + "\" does not exist"});
     162            cmpGuiInterface.PushNotification({ "type": "notification", "players": [input.player], "message": "Technology \"" + techname + "\" does not exist" });
    163163            return;
    164164        }
    165165
     
    166166        // check, if technology is already researched
    167167        if (!cmpTechnologyManager.IsTechnologyResearched(techname))
    168168            cmpTechnologyManager.ResearchTechnology(techname);
    169         break;
     169        return;
     170        case "metacheat":
     171        // resources
     172        Cheat({ "player": input.player, "action": "addresource", "text": "food", "parameter": input.parameter })
     173        Cheat({ "player": input.player, "action": "addresource", "text": "wood", "parameter": input.parameter })
     174        Cheat({ "player": input.player, "action": "addresource", "text": "stone", "parameter": input.parameter })
     175        Cheat({ "player": input.player, "action": "addresource", "text": "metal", "parameter": input.parameter })
     176
     177        // max population "the hive master"
     178        Cheat({ "player": input.player, "action": "maxpopulation" });
     179
     180        // change max pupulation "TARDIS"
     181        Cheat({ "player": input.player, "action": "changemaxpopulation" });
     182
     183        // fast actions "i am too busy"
     184        Cheat({ "player": input.player, "action": "fastactions" });
     185
     186        // change phase "back to the future" * 2
     187        Cheat({ "player": input.player, "action": "changephase", "selected": input.selected });
     188        Cheat({ "player": input.player, "action": "changephase", "selected": input.selected });
     189        return;
    170190    default:
    171191        warn("Cheat '" + input.action + "' is not implemented");
    172         break;
     192        return;
    173193    }
    174194}
    175195