Ticket #2019: cheatMod.patch

File cheatMod.patch, 12.0 KB (added by lsdh, 11 years ago)

Patch proposal

  • binaries/data/mods/public/gui/session/messages.js

     
    99const MAX_NUM_NOTIFICATION_LINES = 3;
    1010var notifications = [];
    1111var notificationsTimers = [];
    12 var cheatList = parseJSONData("simulation/data/cheats.json").Cheats;
     12var cheats = getCheatsData();
    1313
     14// Gets cheats from the cheats folder
     15function getCheatsData()
     16{
     17    var cheats = new Object();
     18    var cheatFileList = getJSONFileList("simulation/data/cheats/");
     19    for each (var fileName in cheatFileList)
     20    {
     21        var currentCheat = parseJSONData("simulation/data/cheats/"+fileName+".json");
     22        if (Object.keys(cheats).indexOf(currentCheat.Name) !== -1)
     23            warn("Cheat name '"+currentCheat.Name+"' is already present");
     24        else {
     25            cheats[currentCheat.Name] = currentCheat.Data;
     26        }
     27    }
     28    return cheats;
     29}
     30   
    1431// Notifications
    1532function handleNotifications()
    1633{
     
    219236    var isCheat = false;
    220237    if (text.length)
    221238    {
    222         for (var i = 0; i < cheatList.length; i++)
     239        if (g_Players[Engine.GetPlayerID()].cheatsEnabled)
    223240        {
    224             var cheat = cheatList[i];
     241            for each (var cheat in Object.keys(cheats))
     242            {
    225243
    226             // Line must start with the cheat.
    227             if (text.indexOf(cheat.Name) == 0)
    228             {
    229                 var number;
    230                 if (cheat.IsNumeric)
     244                // Line must start with the cheat.
     245                if (text.indexOf(cheat) == 0)
    231246                {
    232                     // Match the first word in the substring.
    233                     var match = text.substr(cheat.Name.length).match(/\S+/);
    234                     if (match && match[0])
    235                         number = Math.floor(match[0]);
     247                    var number;
     248                    if (cheats[cheat].DefaultNumber !== undefined)
     249                    {
     250                        // Match the first word in the substring.
     251                        var match = text.substr(cheat.length).match(/\S+/);
     252                        if (match && match[0])
     253                            number = Math.floor(match[0]);
    236254
    237                     if (number <= 0 || isNaN(number))
    238                         number = cheat.DefaultNumber;
     255                        if (number <= 0 || isNaN(number))
     256                            number = cheats[cheat].DefaultNumber;
     257                    }
     258
     259                    Engine.PostNetworkCommand({
     260                        "type": "cheat",
     261                        "action": cheats[cheat].Action,
     262                        "number": number,
     263                        "text": cheats[cheat].Type,
     264                        "selected": g_Selection.toList(),
     265                        "templates": cheats[cheat].Templates,
     266                        "player": Engine.GetPlayerID()});
     267                    isCheat = true;
     268                    break;
    239269                }
    240 
    241                 Engine.PostNetworkCommand({
    242                     "type": "cheat",
    243                     "action": cheat.Action,
    244                     "number": number,
    245                     "text": cheat.Type,
    246                     "selected": g_Selection.toList(),
    247                     "templates": cheat.Templates,
    248                     "player": Engine.GetPlayerID()});
    249                 isCheat = true;
    250                 break;
    251270            }
    252271        }
    253272
     
    427446            recurse = true;
    428447            break;
    429448        case "/team":
    430             var playerData = getPlayerData();
    431449            if (hasAllies(sender, playerData))
    432450            {
    433                 if (playerData[Engine.GetPlayerID()].team != playerData[sender].team)
     451                if (g_Players[Engine.GetPlayerID()].team != g_Players[sender].team)
    434452                    msg.hide = true;
    435453                else
    436454                    msg.prefix = "(Team) ";
     
    440458            recurse = true;
    441459            break;
    442460        case "/enemy":
    443             var playerData = getPlayerData();
    444             if (hasAllies(sender, playerData))
     461            if (hasAllies(sender, g_Players))
    445462            {
    446                 if (playerData[Engine.GetPlayerID()].team == playerData[sender].team && sender != Engine.GetPlayerID())
     463                if (g_Players[Engine.GetPlayerID()].team == g_Players[sender].team && sender != Engine.GetPlayerID())
    447464                    msg.hide = true;
    448465                else
    449466                    msg.prefix = "(Enemy) ";
  • binaries/data/mods/public/gui/session/utility_functions.js

     
    6060            "color": color,
    6161            "team": playerState.team,
    6262            "teamsLocked": playerState.teamsLocked,
     63            "cheatsEnabled": playerState.cheatsEnabled,
    6364            "state": playerState.state,
    6465            "isAlly": playerState.isAlly,
    6566            "isMutualAlly": playerState.isMutualAlly,
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    8787            "state": cmpPlayer.GetState(),
    8888            "team": cmpPlayer.GetTeam(),
    8989            "teamsLocked": cmpPlayer.GetLockTeams(),
     90            "cheatsEnabled": cmpPlayer.GetCheatsEnabled(),
    9091            "phase": phase,
    9192            "isAlly": allies,
    9293            "isMutualAlly": mutualAllies,
  • binaries/data/mods/public/simulation/components/Player.js

     
    3131    this.controlAllUnits = false;
    3232    this.isAI = false;
    3333    this.gatherRateMultiplier = 1;
    34     this.cheatsEnabled = true;
     34    this.cheatsEnabled = false;
    3535    this.cheatTimeMultiplier = 1;
    3636    this.heroes = [];
    3737};
     
    550550    this.UpdateSharedLos();
    551551};
    552552
    553 Player.prototype.SetCheatEnabled = function(flag)
     553Player.prototype.SetCheatsEnabled = function(flag)
    554554{
    555555    this.cheatsEnabled = flag;
    556556};
    557557
    558 Player.prototype.GetCheatEnabled = function()
     558Player.prototype.GetCheatsEnabled = function()
    559559{
    560560    return this.cheatsEnabled;
    561561};
  • binaries/data/mods/public/simulation/data/cheats/changeMaxPopulation.json

     
     1{
     2    "Name": "TARDIS",
     3    "Data": {
     4        "Action": "changemaxpopulation"
     5    }
     6}
  • binaries/data/mods/public/simulation/data/cheats/convertUnit.json

     
     1{
     2    "Name": "wololo",
     3    "Data": {
     4        "Action": "convertunit"
     5    }
     6}
  • binaries/data/mods/public/simulation/data/cheats/createHeros.json

     
     1{
     2    "Name": "iwanttopwnthem",
     3    "Data": {
     4        "Action": "createunits",
     5        "DefaultNumber": 1,
     6        "Templates": ["units/cart_hero_hamilcar", "units/cart_hero_hannibal", "units/cart_hero_maharbal", "units/rome_hero_marcellus", "units/rome_hero_maximus", "units/rome_hero_scipio", "units/pers_hero_cyrus", "units/pers_hero_darius", "units/pers_hero_xerxes"]
     7    }
     8}
  • binaries/data/mods/public/simulation/data/cheats/createPlane.json

     
     1{
     2    "Name": "how do you turn this on?",
     3    "Data": {
     4        "Action": "createunits",
     5        "DefaultNumber": 1,
     6        "Templates": ["other/plane"]
     7    }
     8}
  • binaries/data/mods/public/simulation/data/cheats/createUnits.json

     
     1{
     2    "Name": "salad bowl",
     3    "Data": {
     4        "Action": "createunits",
     5        "DefaultNumber": 10,
     6        "Templates": ["units/athen_infantry_spearman_b", "units/brit_infantry_spearman_b", "units/cart_infantry_spearman_b", "units/gaul_infantry_spearman_b", "units/iber_infantry_spearman_b",
     7        "units/mace_infantry_spearman_b", "units/maur_infantry_spearman_b", "units/pers_infantry_spearman_b", "units/rome_infantry_spearman_b", "units/spart_infantry_spearman_b"]
     8    }
     9}
  • binaries/data/mods/public/simulation/data/cheats/defeatPlayer.json

     
     1{
     2    "Name": "exodia",
     3    "Data": {
     4        "Action": "defeatplayer",
     5        "DefaultNumber": 2
     6    }
     7}
  • binaries/data/mods/public/simulation/data/cheats/fastActions.json

     
     1{
     2    "Name": "i am too busy",
     3    "Data": {
     4        "Action": "fastactions"
     5    }
     6}
  • binaries/data/mods/public/simulation/data/cheats/food.json

     
     1{
     2    "Name": "i want pizza",
     3    "Data": {
     4        "Action": "addresource",
     5        "Type": "food",
     6        "DefaultNumber": 1000
     7    }
     8}
  • binaries/data/mods/public/simulation/data/cheats/killUnits.json

     
     1{
     2    "Name": "black death",
     3    "Data": {
     4        "Action": "killunits"
     5    }
     6}
  • binaries/data/mods/public/simulation/data/cheats/maxPopulation.json

     
     1{
     2    "Name": "the hive master",
     3    "Data": {
     4        "Action": "maxpopulation"
     5    }
     6}
  • binaries/data/mods/public/simulation/data/cheats/metal.json

     
     1{
     2    "Name": "your money or your life",
     3    "Data": {
     4        "Action": "addresource",
     5        "Type": "metal",
     6        "DefaultNumber": 1000
     7    }
     8}
  • binaries/data/mods/public/simulation/data/cheats/revealMap.json

     
     1{
     2    "Name": "jame jam",
     3    "Data": {
     4        "Action": "revealmap"
     5    }
     6}
  • binaries/data/mods/public/simulation/data/cheats/stone.json

     
     1{
     2    "Name": "i see a mountain here",
     3    "Data": {
     4        "Action": "addresource",
     5        "Type": "stone",
     6        "DefaultNumber": 1000
     7    }
     8}
  • binaries/data/mods/public/simulation/data/cheats/wood.json

     
     1{
     2    "Name": "bring me my axe",
     3    "Data": {
     4        "Action": "addresource",
     5        "Type": "wood",
     6        "DefaultNumber": 1000
     7    }
     8}