Ticket #3477: ticket3477_metacheat_3.diff

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

Some more style improvements

  • 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
     
    2020    switch(input.action)
    2121    {
    2222    case "addresource":
    23         // force input.text to be an array
    24         input.text = [].concat(input.text);
    25         for each (var type in input.text)
    26             cmpPlayer.AddResource(type, input.parameter);
    27         break;
     23        cmpPlayer.AddResource(input.text, input.parameter);
     24        return;
    2825    case "revealmap":
    2926        var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    3027        cmpRangeManager.SetLosRevealAll(-1, true);
    31         break;
     28        return;
    3229    case "maxpopulation":
    3330        cmpPlayer.SetPopulationBonuses(500);
    34         break;
     31        return;
    3532    case "changemaxpopulation":
    3633        cmpPlayer.SetMaxPopulation(500);
    37         break;
     34        return;
    3835    case "convertunit":
    3936        for (let ent of input.selected)
    4037        {
     
    4239            if (cmpOwnership)
    4340                cmpOwnership.SetOwner(cmpPlayer.GetPlayerID());
    4441        }
    45         break;
     42        return;
    4643    case "killunits":
    4744        for (let ent of input.selected)
    4845        {
     
    5249            else
    5350                Engine.DestroyEntity(ent);
    5451        }
    55         break;
     52        return;
    5653    case "defeatplayer":
    5754        var playerEnt = cmpPlayerManager.GetPlayerByID(input.parameter);
    5855        if (playerEnt == INVALID_ENTITY)
    5956            return;
    60         Engine.PostMessage(playerEnt, MT_PlayerDefeated, { "playerId": input.parameter } );
    61         break;
     57        Engine.PostMessage(playerEnt, MT_PlayerDefeated, { "playerId": input.parameter });
     58        return;
    6259    case "createunits":
    6360        if (!input.selected[0])
    6461        {
    65             cmpGuiInterface.PushNotification({"type": "notification", "players": [input.player], "message": "You need to select a building that trains units."});
     62            cmpGuiInterface.PushNotification({ "type": "notification", "players": [input.player], "message": "You need to select a building that trains units." });
    6663            return;
    6764        }
    6865
     
    6966        var cmpProductionQueue = Engine.QueryInterface(input.selected[0], IID_ProductionQueue);
    7067        if (!cmpProductionQueue)
    7168        {
    72             cmpGuiInterface.PushNotification({"type": "notification", "players": [input.player], "message": "You need to select a building that trains units."});
     69            cmpGuiInterface.PushNotification({ "type": "notification", "players": [input.player], "message": "You need to select a building that trains units." });
    7370            return;
    7471        }
    7572        for (let i = 0; i < input.parameter; ++i)
    7673            cmpProductionQueue.SpawnUnits(input.templates[i % input.templates.length], 1, null);
    77         break;
     74        return;
    7875    case "fastactions":
    7976        cmpPlayer.SetCheatTimeMultiplier((cmpPlayer.GetCheatTimeMultiplier() == 1) ? 0.01 : 1);
    80         break;
     77        return;
    8178    case "changespeed":
    8279        cmpPlayer.SetCheatTimeMultiplier(input.parameter);
    83         break;
     80        return;
    8481    case "changephase":
    8582        var cmpTechnologyManager = Engine.QueryInterface(playerEnt, IID_TechnologyManager);
    8683        if (!cmpTechnologyManager)
     
    10299
    103100        // rewrite input and call function
    104101        input.action = "researchTechnology";
    105         Cheat(input);
    106         break;
     102        Cheat({ "player": input.player, "action": "researchTechnology", "parameter": input.parameter, "selected": input.selected });
     103        return;
    107104    case "researchTechnology":
    108105        // check, if name of technology is given
    109106        if (input.parameter.length == 0)
    110107        {
    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].)"});
     108            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].)" });
    112109            return;
    113110        }
    114111        var techname = input.parameter;
     
    137134                        var tech = techs[number-1];
    138135                        if (!tech)
    139136                        {
    140                             cmpGuiInterface.PushNotification({"type": "notification", "players": [input.player], "message": "You have already researched this technology."});
     137                            cmpGuiInterface.PushNotification({ "type": "notification", "players": [input.player], "message": "You have already researched this technology." });
    141138                            return;
    142139                        }
    143140                        // get name of tech
     
    148145                    }
    149146                    else
    150147                    {
    151                         cmpGuiInterface.PushNotification({"type": "notification", "players": [input.player], "message": "This building only has " + techs.length + " technologies."});
     148                        cmpGuiInterface.PushNotification({ "type": "notification", "players": [input.player], "message": "This building only has " + techs.length + " technologies." });
    152149                        return;
    153150                    }
    154151                }
     
    159156        var template = cmpTechnologyManager.GetTechnologyTemplate(techname);
    160157        if (!template)
    161158        {
    162             cmpGuiInterface.PushNotification({"type": "notification", "players": [input.player], "message": "Technology \"" + techname + "\" does not exist"});
     159            cmpGuiInterface.PushNotification({ "type": "notification", "players": [input.player], "message": "Technology \"" + techname + "\" does not exist" });
    163160            return;
    164161        }
    165162
     
    166163        // check, if technology is already researched
    167164        if (!cmpTechnologyManager.IsTechnologyResearched(techname))
    168165            cmpTechnologyManager.ResearchTechnology(techname);
    169         break;
     166        return;
     167        case "metaCheat":
     168        // resources
     169        Cheat({ "player": input.player, "action": "addresource", "text": "food", "parameter": input.parameter });
     170        Cheat({ "player": input.player, "action": "addresource", "text": "wood", "parameter": input.parameter });
     171        Cheat({ "player": input.player, "action": "addresource", "text": "stone", "parameter": input.parameter });
     172        Cheat({ "player": input.player, "action": "addresource", "text": "metal", "parameter": input.parameter });
     173
     174        // max population "the hive master"
     175        Cheat({ "player": input.player, "action": "maxpopulation" });
     176
     177        // change max pupulation "TARDIS"
     178        Cheat({ "player": input.player, "action": "changemaxpopulation" });
     179
     180        // fast actions "i am too busy"
     181        Cheat({ "player": input.player, "action": "fastactions" });
     182
     183        // change phase "back to the future" * 2
     184        Cheat({ "player": input.player, "action": "changephase", "selected": input.selected });
     185        Cheat({ "player": input.player, "action": "changephase", "selected": input.selected });
     186        return;
    170187    default:
    171188        warn("Cheat '" + input.action + "' is not implemented");
    172         break;
     189        return;
    173190    }
    174191}
    175192