Ticket #3176: no_attack_notification_for_domestic_animals_r16549.diff

File no_attack_notification_for_domestic_animals_r16549.diff, 2.1 KB (added by fcxSanya, 9 years ago)

Another alternative patch; suspends the attack notification if the attacked entity has classes "Animal" and "Domestic"

  • 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);
     513        var targetEntState = GetExtendedEntityState(msg.target);
     514        var targetIdentityClasses = targetEntState.identity.classes;
     515        var targetIsDomesticAnimal = targetIdentityClasses.indexOf("Animal") != -1 && targetIdentityClasses.indexOf("Domestic") != -1;
     516        // Since livestock can be attacked/gathered by allied players
     517        // and generally not so valuable as other units/buildings,
     518        // we don't display the attack notification for it
     519        if (targetIsDomesticAnimal)
     520            return;
    512521        formatted = sprintf(translate("You have been attacked by %(attacker)s!"), { attacker: "[color=\"" + playerColor + "\"]" + username + "[/color]" });
    513522        break;
    514523    case "message":
  • 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