Ticket #3839: show_bartering_to_observers_v1.patch
File show_bartering_to_observers_v1.patch, 3.2 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/session/messages.js
var g_FormatChatMessage = { 48 48 "clientlist": msg => getUsernameList(), 49 49 "message": msg => formatChatCommand(msg), 50 50 "defeat": msg => formatDefeatMessage(msg), 51 51 "diplomacy": msg => formatDiplomacyMessage(msg), 52 52 "tribute": msg => formatTributeMessage(msg), 53 "barter": msg => formatBarterMessage(msg), 53 54 "attack": msg => formatAttackMessage(msg) 54 55 }; 55 56 56 57 /** 57 58 * Show a label and grey overlay or hide both on connection change. … … var g_NotificationsTypes = 216 217 "sourcePlayer": notification.donator, 217 218 "targetPlayer": player, 218 219 "amounts": notification.amounts 219 220 }); 220 221 }, 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 }, 221 233 "attack": function(notification, player) 222 234 { 223 235 if (player != g_ViewedPlayer) 224 236 return; 225 237 … … function formatTributeMessage(msg) 695 707 "player2": colorizePlayernameByID(msg.targetPlayer), 696 708 "amounts": getLocalizedResourceAmounts(msg.amounts) 697 709 }); 698 710 } 699 711 712 function 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 700 730 function formatAttackMessage(msg) 701 731 { 702 732 if (msg.player != g_ViewedPlayer) 703 733 return ""; 704 734 -
binaries/data/mods/public/simulation/components/Barter.js
Barter.prototype.ExchangeResources = fun 95 95 { 96 96 var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount); 97 97 cmpPlayer.AddResource(resourceToBuy, amountToAdd); 98 98 var numberOfDeals = Math.round(amount / 100); 99 99 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 100 112 var cmpStatisticsTracker = Engine.QueryInterface(playerEntity, IID_StatisticsTracker); 101 113 if (cmpStatisticsTracker) 102 114 { 103 115 cmpStatisticsTracker.IncreaseResourcesSoldCounter(resourceToSell, amount); 104 116 cmpStatisticsTracker.IncreaseResourcesBoughtCounter(resourceToBuy, amountToAdd);