#CLASS {group} {kill};
#CLASS {group} {open};

#VARIABLE {group_shields} {};
#VARIABLE {group_shields_current} {};
#VARIABLE {groupshield_file} {logs/groupshields.log};

#ACTION {^Arcane protection for %1:-} {
    #var {group_shields_current} {%1};
}

#nop ======================================================;
#nop ===[ Detect shield printouts from 'group shields' ]===;
#nop ======================================================;

#nop EFF
#ACTION {^ * %1 is floating around {him|her|it|you}:$} {
    #if {"%2" == "you"} {
        #variable {group_shields[$GMCP[charinfo][capname]][eff]} {1};
    };
    #else {
        #variable {group_shields[$group_shields_current][eff]} {1};
    }
    /softwritegroupshieldstofile;
}

#nop TPA
#ACTION {^ * {She|He|It} is surrounded by a {(dull red |bright red |wobbling orange |flickering yellow |)?}magical impact shield\.$} {
    #if {"$group_shields_current" != ""} {
        #variable {group_shields[$group_shields_current][tpa]} {1};
        /softwritegroupshieldstofile;
    };
}

#nop CCC
#ACTION {^ * {Her|His|Its} skin {is|has been} {hardened|covered} {with|to}{a?} %4, although {the \w+|it} seems {weaker|not to be}} {
    #if {"$group_shields_current" != ""} {
        #variable {group_shields[$group_shields_current][ccc]} {1};
        /softwritegroupshieldstofile;
    };
}
#ACTION {^ * Your skin {is|has been} {hardened|covered} {with|to}{a?} %4, although {the \w+|it} seems {weaker|not to be}} {
    #variable {group_shields[$GMCP[charinfo][capname]][ccc]} {1};
        /softwritegroupshieldstofile;
};
#ACTION {^ * Tiny threads of metal run criss-cross all over {her|his|its} skin, although it seems weaker} {
    #if {"$group_shields_current" != ""} {
        #variable {group_shields[$group_shields_current][ccc]} {1};
        /softwritegroupshieldstofile;
    };
}

#nop MS
#ACTION {^ * {She|He|It} is {(really )?}protected by the power of {Pishe|Gufnork|Gapp|Sandelfon|Fish|Hat|Sek|Aegadon|Cubal|Reebox}} {
    #if {"$group_shields_current" != ""} {
        #variable {group_shields[$group_shields_current][ms]} {1};
        /softwritegroupshieldstofile;
    };
}
#ACTION {^ * You are {(really )?}protected by the power of {Pishe|Gufnork|Gapp|Sandelfon|Fish|Hat|Sek|Aegadon|Cubal|Reebox}} {
    #variable {group_shields[$GMCP[charinfo][capname]][ms]} {1};
    /softwritegroupshieldstofile;
}

#nop KII
#ACTION {^ * {You|She|He|It} {is|are} surrounded by a {handful|cloud|small swarm|large swarm|vast sawrm|plague} of} {
    #if {"%1" == "You"} {
        #variable {group_shields[$GMCP[charinfo][capname]][kii]} {1};
    };
    #else {
        #variable {group_shields[$group_shields_current][kii]} {1};
    };
    /softwritegroupshieldstofile;
};

#nop No shields at all
#ACTION {^{(\w+\b\W*?){1,8}} has no arcane protection.$} {
    #if {"$group_shields_current" != ""} {
        #if {"%1" != "%+ the %+ horse"} {
            #variable {group_shields[%1][ccc]} {0};
            #variable {group_shields[%1][tpa]} {0};
            #variable {group_shields[%1][eff]} {0};
            #variable {group_shields[%1][kii]} {0};
            #variable {group_shields[%1][ms]} {0};
            /softwritegroupshieldstofile;
        };
    };
};



#nop =========================================;
#nop ===[ Detect group join/leave actions ]===;
#nop =========================================;

#ACTION {[%1] {[A-Za-z]+} has left the group.} {
    #if {&group_shields[%2]} {
        #unvariable {group_shields[%2]};
        /writegroupshieldstofile;
    };
};
#ACTION {[%1] {[A-Za-z]+} has joined the group.} {
    #tab {%2};
    #variable {group_shields[%2]} {{tpa}{0}{ccc}{0}{eff}{0}{ms}{0}{kii}{0}};
    /softwritegroupshieldstofile;
};
#ACTION {[%1] You have left the group.} {
    #var {group_shields} {};
    /writegroupshieldstofile;
};
#ACTION {[%1] You have joined the group.} {
    #var {group_shields} {};
    #variable {group_shields[$GMCP[charinfo][capname]]} {{tpa}{0}{ccc}{0}{eff}{0}{ms}{0}{kii}{0}};
};


#nop =================================================;
#nop ===[ Detect shield drops/adds 'in the field' ]===;
#nop =================================================;

#nop EFF
#ACTION {{(?:\w+\b\w*?){1,6}} floating around {(?:\w+\b\W*?){1,8}} breaks!$} {
    #variable {gs_dropname} {%2};
    #replace {gs_dropname} { } {;};
    #foreach {$gs_dropname} {name} {
        #if {&group_shields[$name]} {
            #variable {group_shields[$name][eff]} {0};
            /writegroupshieldstofile;
        };
    };
};
#ACTION {^In blocking the attack {(?:.+)} floating around {(?:\w+\b\W*?){1,8}} is knocked out of orbit.$} {
    #nop Record room of drop even for non group mates... might come in handy;
    #variable {group_eff_item} {%1};
    #variable {group_eff_target} {%2};
    #variable {group_eff_room} {$GMCP[room][info][name]};

    #variable {gs_dropname} {%2};
    #replace {gs_dropname} { } {;};
    #foreach {$gs_dropname} {name} {
        #if {&group_shields[$name]} {
            #variable {group_shields[$name][eff]} {0};
            /writegroupshieldstofile;

            #if {"$gs_eff_alerts" == "1"} {
                #showme {\a};
            };

            #return @log_line_to_chat{};
        };
        #elseif {"$name" == "you"} {
            #variable {group_shields[$GMCP[charinfo][capname]][eff]} {0};
            /writegroupshieldstofile;

            #if {"$gs_eff_alerts" == "1"} {
                #showme {\a};
            };

            #return @log_line_to_chat{};
        };
    };
};
#ACTION {{(?:\w+\b\w*?){1,6}} begins to float around {(?:\w+\b\W*?){1,8}}.$} {
    #variable {gs_dropname} {%2};
    #replace {gs_dropname} { } {;};
    #foreach {$gs_dropname} {name} {
        #if {&group_shields[$name]} {
            #variable {group_shields[$name][eff]} {1};
            /writegroupshieldstofile;
        };
    };
};


#nop TPA
#ACTION {^There is a sudden white flash around {(?!a passing wizard)(\w+\b\W*?){1,8}}.$} {
    #showme {\a};

    #variable {gs_dropname} {%1};
    #replace {gs_dropname} { } {;};
    #foreach {$gs_dropname} {name} {
        #if {&group_shields[$name]} {
            #variable {group_shields[$name][tpa]} {0};
            /writegroupshieldstofile;
        };
    };

    #return @log_line_to_chat{};
};
#ACTION {^With a noise that sounds like "Plink!", the air around {(\w+\b\W*?){1,8}} flashes {yellow|red} for a moment.$} {
    #variable {gs_dropname} {%1};
    #replace {gs_dropname} { } {;};
    #foreach {$gs_dropname} {name} {
        #if {&group_shields[$name]} {
            #variable {group_shields[$name][tpa]} {1};
            /writegroupshieldstofile;
        };
    };
};


#nop CCC
#ACTION {^There is a brief flash of magic, and something falls away from {(\w+\b\W*?){1,8}}'s skin.$} {
    #variable {gs_dropname} {%1};
    #replace {gs_dropname} { } {;};
    #foreach {$gs_dropname} {name} {
        #if {&group_shields[$name]} {
            #variable {group_shields[$name][ccc]} {0};
            /writegroupshieldstofile;
        };
    };
};
#ACTION {^{(\w+\b\W*?){1,8}} scratches {himself|herself|itself}, and large pieces of skin flake off.$} {
    #variable {gs_dropname} {%1};
    #replace {gs_dropname} { } {;};
    #foreach {$gs_dropname} {name} {
        #if {&group_shields[$name]} {
            #variable {group_shields[$name][ccc]} {0};
            /writegroupshieldstofile;
        };
    };
};
#ACTION {^{(\w+\b\W*?){1,8}}'s skin is now as {elastic|thickly covered|hard} as it can get.$} {
    #variable {gs_dropname} {%1};
    #replace {gs_dropname} { } {;};
    #foreach {$gs_dropname} {name} {
        #if {&group_shields[$name]} {
            #variable {group_shields[$name][ccc]} {1};
            /writegroupshieldstofile;
        };
    };
};
#ACTION {^The metal powder fuses together into metal bands on {(\w+\b\W*?){1,8}}'s skin.$} {
    #variable {gs_dropname} {%1};
    #replace {gs_dropname} { } {;};
    #foreach {$gs_dropname} {name} {
        #if {&group_shields[$name]} {
            #variable {group_shields[$name][ccc]} {1};
            /writegroupshieldstofile;
        };
    };
};
#ACTION {^{(\w+\b\W*?){1,8}}'s skin becomes {elastic as rubber|rock hard}.$} {
    #variable {gs_dropname} {%1};
    #replace {gs_dropname} { } {;};
    #foreach {$gs_dropname} {name} {
        #if {&group_shields[$name]} {
            #variable {group_shields[$name][ccc]} {1};
            /writegroupshieldstofile;
        };
    };
};
#ACTION {^With a brief flash of magic, your %1 skin falls away.$} {
    #variable {group_shields[$GMCP[charinfo][capname]][ccc]} {0};
    /writegroupshieldstofile;
};
#ACTION {^Your skin is {already|now} as {elastic|thickly covered|hard} as it can get.$} {
    #variable {group_shields[$GMCP[charinfo][capname]][ccc]} {1};
    /writegroupshieldstofile;
};


#nop KII;
#ACTION {^The last of the injured {lacewings|stick insects|mayflies|praying mantids|butterflies|ladybirds|dragonflies|damselflies|moths|grasshoppers|winged termites|sandflies|mosquitoes|gnats|crickets|flying ants|locusts|horseflies|cicadas|bees|wasps|hornets|elephant beetles|assassin bugs} surrounding {(\w+\b\W*?){1,8}} crash to the ground.$} {
    #variable {gs_dropname} {%1};
    #replace {gs_dropname} { } {;};
    #foreach {$gs_dropname} {name} {
        #if {&group_shields[$name]} {
            #variable {group_shields[$name][kii]} {1};
            /writegroupshieldstofile;
        };
    };
};
#ACTION {^The {lacewings|stick insects|mayflies|praying mantids|butterflies|ladybirds|dragonflies|damselflies|moths|grasshoppers|winged termites|sandflies|mosquitoes|gnats|crickets|flying ants|locusts|horseflies|cicadas|bees|wasps|hornets|elephant beetles|assassin bugs} surrounding {(\w+\b\W*?){1,8}} scatter } {
    #variable {gs_dropname} {%1};
    #replace {gs_dropname} { } {;};
    #foreach {$gs_dropname} {name} {
        #if {&group_shields[$name]} {
            #variable {group_shields[$name][kii]} {1};
            /writegroupshieldstofile;
        };
    };
};
#ACTION {^{Buzzing drowsily, t|Buzzing loudly, t|Buzzing threateningly, t|Clicking and buzzing, t|Whirring gently, t|Rather clumsily, t|With a rasping noise, t|With a high-pitched whining noise, t|With a low, menacing buzzing, t|With a buzzing sound so loud and meaty it's almost like a dog growling, t|T}he {handful|cloud|small swarm|large swarm|vast swarm|plague} of {lacewings|stick insects|mayflies|praying mantids|butterflies|ladybirds|dragonflies|damselflies|moths|grasshoppers|winged termites|sandflies|mosquitoes|gnats|crickets|flying ants|locusts|horseflies|cicadas|bees|wasps|hornets|elephant beetles|assassin bugs} {flutters into a loosely-formed orbit around |forms a chaotic web of small white bodies around |starts to hover near |begins to circle |begins to circle around |begins to orbit |begins to cluster around |begins to buzz erratically around |begins to buzz around |flutters into a chaotic formation around }{(\w+\b\W*?){1,8}}{| happily| slowly|, chirping gently|, buzzing hungrily}.$} {
    #variable {gs_dropname} {%1};
    #replace {gs_dropname} { } {;};
    #foreach {$gs_dropname} {name} {
        #if {&group_shields[$name]} {
            #variable {group_shields[$name][kii]} {1};
            /writegroupshieldstofile;
        };
    };
};

#nop MS;
#ACTION {^You are protected by the power of {Pishe|Gufnork|Gapp|Sandelfon|Fish|Hat|Sek|Aegadon|Cubal|Reebox}.$} {
    #variable {group_shields[$GMCP[charinfo][capname]][ms]} {1};
    /writegroupshieldstofile;
};
#ACTION {^Your divine protection expires.$} {
    #variable {group_shields[$GMCP[charinfo][capname]][ms]} {0};
    /writegroupshieldstofile;
};



#nop ======================================;
#nop ===[ Aliases to show the data etc ]===;
#nop ======================================;

#ALIAS {rgs} {
    #variable {group_shields} {};
    #variable {group_shields_current} {};
    /writegroupshieldstofile;
    #send {group shields};
};

#ALIAS {sgs} {
    #showme {.:: Group Shields ::.};
    #foreach {*group_shields[]} {name} {
        #format {gs_namelength} {%L} {$name};
        #math {gs_namelength} {9 - $gs_namelength};
        #if {$gs_namelength < 0} { #var {gs_namelength} {0}; };
        #format {gs_displayline} { * %.9s:%+${gs_namelength}s } {$name};

        #foreach {tpa;ccc;eff;ms;kii} {shield} {
            #if {&group_shields[$name][$shield] && "$group_shields[$name][$shield]" == "1"} {
                #format {gs_displayline} {%s <fef>%u<099>} {$gs_displayline} {$shield};
            } {
                #format {gs_displayline} {%s <aaa>%u<099>} {$gs_displayline} {$shield};
            };
        };
        #showme {$gs_displayline};
    };
};
#VARIABLE {gs_eff_alerts} {1};
#ALIAS {^gs eff on$} {
    #VARIABLE {gs_eff_alerts} {1};
    #showme {<acf>[<fff>group<acf>] Group shield EFF bell alerts are <128>ON<acf>.<900>};
    #showme {<acf>[<fff>group<acf>] Syntax: 'gs eff <on|off>'.<900>};
};
#ALIAS {^gs eff off$} {
    #VARIABLE {gs_eff_alerts} {0};
    #showme {<acf>[<fff>group<acf>] Group shield EFF bell alerts are <118>OFF<acf>.<900>};
    #showme {<acf>[<fff>group<acf>] Syntax: 'gs eff <on|off>'.<900>};
};
#ALIAS {^gs eff$} {
    #IF {"$gs_eff_alerts" == "0"} {
        #showme {<acf>[<fff>group<acf>] Group shield EFF bell alerts are <118>OFF<acf>.<900>};
        #showme {<acf>[<fff>group<acf>] Syntax: 'gs eff <on|off>'.<900>};
    } {
        #showme {<acf>[<fff>group<acf>] Group shield EFF bell alerts are <128>ON<acf>.<900>};
        #showme {<acf>[<fff>group<acf>] Syntax: 'gs eff <on|off>'.<900>};
    };
};

#FORMAT {shieldfile_lastwrite} {%T};
#MATH {shieldfile_lastwrite} {$shieldfile_lastwrite - 10};
#ALIAS {/softwritegroupshieldstofile} {
    #format {current_time} {%T};
    #math {shieldfile_lastdelta} {$current_time - $shieldfile_lastwrite};
    #if {$shieldfile_lastdelta < 2} {
        #nop Don't bother writing if its been less than 5 seconds;
        #delay {swgstf} {/softwritegroupshieldstofile;} {2};
        #return;
    };

    /writegroupshieldstofile;
    #format {shieldfile_lastwrite} {%T};
};

#ALIAS {/writegroupshieldstofile} {
    #nop Delete and recreate an empty file;
    #system {rm $groupshield_file && touch $groupshield_file};

    #nop Log a title then iterate over group members to display line by line;
    #line {log} {$groupshield_file} {.:: Group Shields ::.};
    #foreach {*group_shields[]} {name} {
        #format {gs_namelength} {%L} {$name};
        #math {gs_namelength} {6 - $gs_namelength};
        #format {gs_displayline} {%.6s: } {$name};
        #format {gs_displayline} {%-8s} {$gs_displayline};

        #foreach {tpa;ccc;eff;kii;ms} {shield} {
            #if {&group_shields[$name][$shield] && "$group_shields[$name][$shield]" == "1"} {
                #format {gs_displayline} {%s <eee>%u<099>} {$gs_displayline} {$shield};
            } {
                #format {gs_displayline} {%s <bbb>%u<099>} {$gs_displayline} {$shield};
            };
        };
        #line {log} {$groupshield_file} {$gs_displayline};
    };
    #format {shieldfile_lastwrite} {%T};
};


#nop =======================================================;
#nop ===[ Capture incidents and be able to report them ]===;
#nop =======================================================;
#ACTION {^The %1 grabs your %2.  You struggle briefly but {she|he|it} wrests it from your grip and makes for a hasty retreat.} {
    #variable {group_snatch_target} {%1};
    #variable {group_snatch_victim} {$GMCP[charinfo][capname]};
    #variable {group_snatch_item} {%2};
};
#ACTION {^The %1 and %2 struggle briefly over %3 before the %4 wrests it free%5$} {
    #variable {group_snatch_target} {%1};
    #variable {group_snatch_victim} {%2};
    #variable {group_snatch_item} {%3};
};
#ACTION {^The %1 suddenly snatches %2 from %3 and makes a run for it.$} {
    #variable {group_snatch_target} {%1};
    #variable {group_snatch_victim} {%3};
    #variable {group_snatch_item} {%2};
};
#ALIAS {gssnatch} {
    #if {"$group_snatch_target" != "0"} {
        #send {group say [snatch] $group_snatch_victim's "$group_snatch_item" was stolen by \{$group_snatch_target\}};
    } {
        #showme {<188><acf>[snatch] No recent snatch to report.<900>};
    };
};
#ALIAS {gseff} {
    #if {"$group_eff_target" != "0"} {
        #send {group say [eff] $group_eff_target's floating "$group_eff_item" was dropped in \{$group_eff_room\}};
    } {
        #showme {<188><acf>[eff] No recent EFF drops to report.<900>};
    };
};


#VARIABLE {group_snatch_target} {0};
#VARIABLE {group_snatch_victim} {0};
#VARIABLE {group_snatch_item} {0};
#VARIABLE {group_eff_item} {0};
#VARIABLE {group_eff_target} {0};
#VARIABLE {group_eff_room} {0};

#CLASS {group} {close};
