Ticket #1555: cheats.patch

File cheats.patch, 3.7 KB (added by O.Davoodi, 12 years ago)
  • gui/session/messages.js

     
    99const MAX_NUM_NOTIFICATION_LINES = 3;
    1010var notifications = [];
    1111var notificationsTimers = [];
     12var cheatList = parseJSONData("simulation/data/cheats.json").Cheats;
    1213
    1314// Notifications
    1415function handleNotifications()
     
    195196    }
    196197
    197198    var message = escapeText(msg.text);
    198 
     199   
    199200    var formatted;
    200201
     202    var isCheat = false;
     203   
    201204    switch (msg.type)
    202205    {
    203206    case "connect":
     
    207210        formatted = "[color=\"" + playerColor + "\"]" + username + "[/color] has left the game.";
    208211        break;
    209212    case "message":
    210         console.write("<" + username + "> " + message);
    211         formatted = "<[color=\"" + playerColor + "\"]" + username + "[/color]> " + message;
     213        if (!g_IsNetworked)
     214        {
     215            for (var i = 0; i < cheatList.length; i++)
     216            {
     217                if (message.indexOf(cheatList[i].Name)>-1)
     218                {
     219                    if (cheatList[i].IsNumbered)
     220                    {
     221                        var number = message.substr(cheatList[i].Name.length+1, message.length-1).valueOf();
     222                        if (!(number > 0))
     223                            number=cheatList[i].DefaultNumber;
     224                    }
     225                    else
     226                    {
     227                        var number = undefined;
     228                    }
     229                    Engine.PostNetworkCommand({"type": "cheat", "action": cheatList[i].Action, "number": number , "player": n});
     230                    isCheat = true;
     231                }
     232            }
     233        }
     234        if (!isCheat)
     235        {
     236            console.write("<" + username + "> " + message);
     237            formatted = "<[color=\"" + playerColor + "\"]" + username + "[/color]> " + message;
     238        }
    212239        break;
    213240    default:
    214241        error("Invalid chat message '" + uneval(msg) + "'");
  • simulation/data/cheats.json

     
     1{
     2    "Cheats":
     3    [
     4        {
     5            "Name": "iwantpizza",
     6            "Action": "addfood",
     7            "IsNumbered": true,
     8            "DefaultNumber": 1000
     9        },
     10        {
     11            "Name": "bringmemyaxe",
     12            "Action": "addwood",
     13            "IsNumbered": true,
     14            "DefaultNumber": 1000
     15        },
     16        {
     17            "Name": "yourmoneyoryourlife",
     18            "Action": "addmetal",
     19            "IsNumbered": true,
     20            "DefaultNumber": 1000
     21        },
     22        {
     23            "Name": "iseeamountainhere",
     24            "Action": "addstone",
     25            "IsNumbered": true,
     26            "DefaultNumber": 1000
     27        },
     28        {
     29            "Name": "jamejam",
     30            "Action": "revealmap",
     31            "IsNumbered": false
     32        }
     33    ]
     34}
  • simulation/helpers/Commands.js

     
    3131    case "debug-print":
    3232        print(cmd.message);
    3333        break;
    34 
     34   
    3535    case "chat":
    3636        var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
    3737        cmpGuiInterface.PushNotification({"type": "chat", "player": player, "message": cmd.message});
    3838        break;
    3939       
     40    case "cheat":
     41        if (cmd.action == "addfood")
     42        {
     43            cmpPlayer.AddResource("food", cmd.number);
     44        }
     45        else if (cmd.action == "addwood")
     46        {
     47            cmpPlayer.AddResource("wood", cmd.number);
     48        }
     49        else if (cmd.action == "addmetal")
     50        {
     51            cmpPlayer.AddResource("metal", cmd.number);
     52        }
     53        else if (cmd.action == "addstone")
     54        {
     55            cmpPlayer.AddResource("stone", cmd.number);
     56        }
     57        else if (cmd.action == "revealmap")
     58        {
     59            var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     60            cmpRangeManager.SetLosRevealAll(-1, true);
     61        }
     62        break;
     63       
    4064    case "quit":
    4165        // Let the AI exit the game for testing purposes
    4266        var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);