Ticket #3839: show_bartering_to_observers_v1.patch

File show_bartering_to_observers_v1.patch, 3.2 KB (added by elexis, 8 years ago)
  • binaries/data/mods/public/gui/session/messages.js

    var g_FormatChatMessage = {  
    4848    "clientlist": msg => getUsernameList(),
    4949    "message": msg => formatChatCommand(msg),
    5050    "defeat": msg => formatDefeatMessage(msg),
    5151    "diplomacy": msg => formatDiplomacyMessage(msg),
    5252    "tribute": msg => formatTributeMessage(msg),
     53    "barter": msg => formatBarterMessage(msg),
    5354    "attack": msg => formatAttackMessage(msg)
    5455};
    5556
    5657/**
    5758 * Show a label and grey overlay or hide both on connection change.
    var g_NotificationsTypes =  
    216217            "sourcePlayer": notification.donator,
    217218            "targetPlayer": player,
    218219            "amounts": notification.amounts
    219220        });
    220221    },
     222    "barter": function(notification, player)
     223    {
     224        addChatMessage({
     225            "type": "barter",
     226            "player": player,
     227            "amountsSold": notification.amountsSold,
     228            "amountsBought": notification.amountsBought,
     229            "resourceSold": notification.resourceSold,
     230            "resourceBought": notification.resourceBought
     231        });
     232    },
    221233    "attack": function(notification, player)
    222234    {
    223235        if (player != g_ViewedPlayer)
    224236            return;
    225237
    function formatTributeMessage(msg)  
    695707        "player2": colorizePlayernameByID(msg.targetPlayer),
    696708        "amounts": getLocalizedResourceAmounts(msg.amounts)
    697709    });
    698710}
    699711
     712function formatBarterMessage(msg)
     713{
     714    if (!g_IsObserver)
     715        return "";
     716
     717    let amountsSold = {};
     718    amountsSold[msg.resourceSold] = msg.amountsSold;
     719
     720    let amountsBought = {};
     721    amountsBought[msg.resourceBought] = msg.amountsBought;
     722
     723    return sprintf(translate("%(player)s bartered %(amountsBought)s for %(amountsSold)s."), {
     724        "player": colorizePlayernameByID(msg.player),
     725        "amountsBought": getLocalizedResourceAmounts(amountsBought),
     726        "amountsSold": getLocalizedResourceAmounts(amountsSold)
     727    });
     728}
     729
    700730function formatAttackMessage(msg)
    701731{
    702732    if (msg.player != g_ViewedPlayer)
    703733        return "";
    704734
  • binaries/data/mods/public/simulation/components/Barter.js

    Barter.prototype.ExchangeResources = fun  
    9595    {
    9696        var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount);
    9797        cmpPlayer.AddResource(resourceToBuy, amountToAdd);
    9898        var numberOfDeals = Math.round(amount / 100);
    9999
     100        // Display chat message to observers
     101        var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     102        if (cmpGUIInterface)
     103            cmpGUIInterface.PushNotification({
     104                "type": "barter",
     105                "players": [cmpPlayer.GetPlayerID()],
     106                "amountsSold": amount,
     107                "amountsBought": amountToAdd,
     108                "resourceSold": resourceToSell,
     109                "resourceBought": resourceToBuy
     110            });
     111
    100112        var cmpStatisticsTracker = Engine.QueryInterface(playerEntity, IID_StatisticsTracker);
    101113        if (cmpStatisticsTracker)
    102114        {
    103115            cmpStatisticsTracker.IncreaseResourcesSoldCounter(resourceToSell, amount);
    104116            cmpStatisticsTracker.IncreaseResourcesBoughtCounter(resourceToBuy, amountToAdd);