Ticket #2273: 0AD_Taunts.patch

File 0AD_Taunts.patch, 3.8 KB (added by AlThePhoenix, 8 years ago)

Implement taunt functionality. Taunts are put in simulation/data/taunts and can use any sound in the game. Includes a sample taunt.

  • binaries/data/config/default.cfg

     
    4141; Persist settings after leaving the game setup screen
    4242persistmatchsettings = true
    4343
     44; Enable playing sounds when a taunt is used in chat
     45enabletaunts = true
     46
    4447; Default player name to use in multiplayer
    4548; playername = "anonymous"
    4649
  • binaries/data/mods/public/gui/options/options.json

     
    9696            "label": "Chat Timestamp",
    9797            "tooltip": "Show time that messages are posted in the lobby, gamesetup and ingame chat.",
    9898            "parameters": { "config": "chat.timestamp" }
     99        },
     100        {
     101            "type": "boolean",
     102            "label": "Enable Taunts",
     103            "tooltip": "Enable / Disable playing sounds when a taunt is used in a chat",
     104            "parameters": { "config": "enabletaunts" }
    99105        }
    100106    ],
    101107    "graphicsSetting":
  • binaries/data/mods/public/gui/session/messages.js

     
    11/**
     2 * All known taunt commands.
     3 * @type {Object}
     4 */
     5const g_Taunts = getTauntsData();
     6
     7/**
    28 * All known cheat commands.
    39 * @type {Object}
    410 */
     
    429435};
    430436
    431437/**
     438 * Loads all known taunt commands.
     439 *
     440 * @returns {Object}
     441 */
     442function getTauntsData()
     443{
     444    let taunts = {};
     445    for (let fileName of getJSONFileList("simulation/data/taunts/"))
     446    {
     447        let currentTaunt = Engine.ReadJSONFile("simulation/data/taunts/"+fileName+".json");
     448        if (!currentTaunt)
     449            continue;
     450        if (Object.keys(taunts).indexOf(currentTaunt.Name) !== -1)
     451            warn("Taunt name '" + currentTaunt.Name + "' is already present");
     452        else
     453            taunts[currentTaunt.Name] = currentTaunt.File;
     454    }
     455    return taunts;
     456}
     457
     458/**
    432459 * Loads all known cheat commands.
    433460 *
    434461 * @returns {Object}
     
    450477}
    451478
    452479/**
     480 * Reads userinput from the chat and plays a sound in case it is a known taunt.
     481 *
     482 * @returns {boolean} - True if a taunt was executed.
     483 */
     484function executeTaunt(text)
     485{
     486    // Find the cheat code that is a prefix of the user input
     487    let tauntCode = Object.keys(g_Taunts).find(tauntCode => text.indexOf(tauntCode) == 0);
     488    if (!tauntCode)
     489        return;
     490
     491    let taunt = g_Taunts[tauntCode];
     492    Engine.PlayUISound("audio/"+taunt, false);
     493}
     494
     495/**
    453496 * Reads userinput from the chat and sends a simulation command in case it is a known cheat.
    454497 *
    455498 * @returns {boolean} - True if a cheat was executed.
     
    945988
    946989        if (userName != g_PlayerAssignments[msg.guid].name)
    947990            notifyUser(userName, msg.text);
     991        if (Engine.ConfigDB_GetValue("user", "enabletaunts") == "true")
     992            executeTaunt(msg.text);
    948993    }
    949994
    950995    // GUID for players, playerID for AIs
  • binaries/data/mods/public/simulation/data/taunts/asd.json

     
     1{
     2    "Name": "asd?",
     3    "File": "voice/greek/civ/civ_male_yes_1.ogg"
     4}
  • binaries/data/mods/public/simulation/data/taunts/asd.json

     
     1{
     2    "Name": "asd?",
     3    "File": "voice/greek/civ/civ_male_yes_1.ogg"
     4}