Ticket #3176: livestock_attack_notification_r16549.diff

File livestock_attack_notification_r16549.diff, 2.2 KB (added by fcxSanya, 9 years ago)

In this patch a different "Your livestock have been attacked by %(attacker)s!" notification is displayed if the attacked entity has the ResourceSupply component; this file differs from the previous version of the same patch by adding a code comment

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

     
    119119        addChatMessage({
    120120            "type": "attack",
    121121            "player": player,
    122             "attacker": notification.attacker
     122            "attacker": notification.attacker,
     123            "target": notification.target
    123124        });
    124125    },
    125126    "dialog": function(notification, player)
     
    509510            return;
    510511
    511512        [username, playerColor] = getUsernameAndColor(msg.attacker);
    512         formatted = sprintf(translate("You have been attacked by %(attacker)s!"), { attacker: "[color=\"" + playerColor + "\"]" + username + "[/color]" });
     513        var targetEntState = GetExtendedEntityState(msg.target);
     514        // Since livestock can be attacked/gathered by allied players,
     515        // we display a more specific notification in this case to not confuse the player
     516        if (targetEntState.resourceSupply)
     517            var message = translate("Your livestock have been attacked by %(attacker)s!");
     518        else
     519            var message = translate("You have been attacked by %(attacker)s!");
     520        formatted = sprintf(message, { attacker: "[color=\"" + playerColor + "\"]" + username + "[/color]" });
    513521        break;
    514522    case "message":
    515523        // May have been hidden by the 'team' command.
  • binaries/data/mods/public/simulation/components/AttackDetection.js

     
    7878    this.AddSuppression(event);
    7979    Engine.PostMessage(this.entity, MT_AttackDetected, { "player": cmpPlayer.GetPlayerID(), "event": event });
    8080    var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
    81     cmpGuiInterface.PushNotification({"type": "attack", "players": [cmpPlayer.GetPlayerID()], "attacker": cmpAttackerOwnership.GetOwner() });
     81    cmpGuiInterface.PushNotification({"type": "attack", "players": [cmpPlayer.GetPlayerID()], "attacker": cmpAttackerOwnership.GetOwner(), "target": target });
    8282    PlaySound("attacked", target);
    8383};
    8484